package com.perforce.maven.scm.provider.p4; /* * Copyright (c) 2010 Perforce Software. All rights reserved. */ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import org.apache.maven.settings.Server; import org.apache.maven.settings.Settings; import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.cli.CommandLineException; import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.cli.Commandline; import org.codehaus.plexus.util.cli.StreamConsumer; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import com.perforce.maven.scm.provider.p4.util.P4Utils; public final class P4ScmTestUtils { private static String scmTckUrl = null; private P4ScmTestUtils() { } public static void initRepo() throws IOException { // during tck test we dont want p4maven-settings.xml get involved, we have a separate test for it P4Utils.setP4MavenSettingsDirecotry( new File( "some-where-very-bogus" ) ); if ( scmTckUrl != null ) { return; } scmTckUrl = System.getProperty( "scmTckUrl" ); if ( scmTckUrl == null ) { // try the default one with user/password from settings.xml Settings settings = readMavenSettings(); Server server = settings.getServer( "localhost:1666" ); if ( server != null ) { StringBuffer buff = new StringBuffer(); buff.append( "scm:p4:" ).append( server.getUsername() ).append( ":" ).append( server.getPassword() ).append( "@" ).append( "localhost:1666://scmtck/p4maven-tck" ); scmTckUrl = buff.toString(); } if ( scmTckUrl == null ) { throw new IllegalArgumentException( "Please configure system property for scmTckUrl" ); } } } public static void populateOriginalData( String baseDir, File workingCopy ) throws IOException { FileUtils.copyDirectoryStructure( new File( baseDir, "src/it/initial-data/src/data/p4maven-tck" ), workingCopy ); } public static String getScmUrl() { return scmTckUrl; } public static void executeCommandLine( Commandline cl, StreamConsumer stdout, StreamConsumer stderr ) throws CommandLineException { if ( CommandLineUtils.executeCommandLine( cl, stdout, stderr ) != 0 ) { throw new CommandLineException( cl.toString() + " exits with none zero code." ); } } private static final String[] ADDED_FILES = { "project.xml", "src/main/java/Foo.java", "src/main/java/org/Foo.java" }; public static String getAddedIncludes() { StringBuffer buffer = new StringBuffer(); for ( String file : ADDED_FILES ) { buffer.append( file ); if ( !file.equals( ADDED_FILES[ADDED_FILES.length - 1] ) ) { buffer.append( "," ); } } return buffer.toString(); } private static final String[] TEST_FILES = { "pom.xml", "readme.txt", "src/main/java/Application.java", "src/test/java/Test.java" }; public static String getTestIncludes() { StringBuffer buffer = new StringBuffer(); for ( String file : TEST_FILES ) { buffer.append( file ); if ( !file.equals( TEST_FILES[TEST_FILES.length - 1] ) ) { buffer.append( "," ); } } return buffer.toString(); } private static Settings readMavenSettings() { File settingsFile = new File( System.getProperty( "user.home" ), ".m2/settings.xml" ); Settings settings = new Settings(); if ( settingsFile.exists() ) { SettingsXpp3Reader reader = new SettingsXpp3Reader(); try { settings = reader.read( ReaderFactory.newXmlReader( settingsFile ) ); } catch ( FileNotFoundException e ) { // nop } catch ( IOException e ) { // nop } catch ( XmlPullParserException e ) { String message = settingsFile.getAbsolutePath() + " isn't well formed. SKIPPED." + e.getMessage(); System.err.println( message ); } } return settings; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 10055 | Matt Attaway | Pull over numerous changes from @dantran's branch. | ||
//guest/dantran/p4maven/p4maven-provider/src/test/java/com/perforce/maven/scm/provider/p4/P4ScmTestUtils.java | |||||
#6 | 9678 | dantran | add p4maven-settings test | ||
#5 | 9538 | dantran |
rename it/template to it/initial-data. It is much more meaningful |
||
#4 | 9536 | dantran | Add current client discovery test | ||
#3 | 9525 | dantran | isolate the location of initial dataset into one place | ||
#2 | 9524 | dantran | switch default tck's depot from //depot to //scmtck to be very specific since user may have a //depot in production | ||
#1 | 9519 | dantran | folder rename to match with its artifactId | ||
//guest/dantran/p4maven/com.perforce.maven/src/test/java/com/perforce/maven/scm/provider/p4/P4ScmTestUtils.java | |||||
#3 | 9514 | dantran |
- Remove support to pick up p4port and its credential from ENV and System properties. These setttings has no use since Maven requires user to provide the required URL which has both p4port and credential. Also user can always fall back to settings.xml to store credential - Rewrite URL parser and also support password as part of URL - TCK test now has default URL and its credential is store under settings.xml - User can also issue her how scmTckUrl system properties ( to be doc as part of maven site) |
||
#2 | 9422 | dantran | add update, changelog TCK | ||
#1 | 9259 | dantran |
hookup with maven-scm-test. Pickup user/password from system properties |