maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r649858 - in /maven/plugins/trunk/maven-invoker-plugin: ./ src/main/java/org/apache/maven/plugin/invoker/ src/test/java/org/apache/maven/plugin/invoker/
Date Sat, 19 Apr 2008 22:09:37 GMT
Author: olamy
Date: Sat Apr 19 15:09:36 2008
New Revision: 649858

URL: http://svn.apache.org/viewvc?rev=649858&view=rev
Log:
interpolate settings file
add a new key/value localRepository with value settings.localRepository (will help to fix
MINVOKER-26)


Modified:
    maven/plugins/trunk/maven-invoker-plugin/pom.xml
    maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java
    maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InterpolationTest.java
    maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java

Modified: maven/plugins/trunk/maven-invoker-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/pom.xml?rev=649858&r1=649857&r2=649858&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-invoker-plugin/pom.xml Sat Apr 19 15:09:36 2008
@@ -70,6 +70,11 @@
       <version>2.0</version>
     </dependency>
     <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-settings</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
       <groupId>org.apache.maven.shared</groupId>
       <artifactId>file-management</artifactId>
       <version>1.1</version>

Modified: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java?rev=649858&r1=649857&r2=649858&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java
(original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java
Sat Apr 19 15:09:36 2008
@@ -46,6 +46,7 @@
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.settings.Settings;
 import org.apache.maven.shared.invoker.CommandLineConfigurationException;
 import org.apache.maven.shared.invoker.DefaultInvocationRequest;
 import org.apache.maven.shared.invoker.InvocationRequest;
@@ -334,6 +335,18 @@
      * @since 1.2
      */
     private String encoding;
+    
+    /**
+     * The current user system settings for use in Maven.
+     *
+     * @parameter expression="${settings}"
+     * @required
+     * @readonly
+     * @since 1.2
+     */
+    private Settings settings;    
+    
+    
 
     public void execute()
         throws MojoExecutionException, MojoFailureException
@@ -609,7 +622,7 @@
 
         File pomFile = new File( projectsDir, pom );
         final File basedir = pomFile.getParentFile();
-        File interpolatedPomFile = buildInterpolatedPomFile( pomFile, basedir );
+        File interpolatedPomFile = buildInterpolatedFile( pomFile, basedir, "interpolated-pom.xml"
);
         FileLogger logger = null;
         try
         {
@@ -732,7 +745,10 @@
 
             if ( settingsFile != null )
             {
-                request.setUserSettingsFile( settingsFile );
+                buildInterpolatedFile( settingsFile, settingsFile.getParentFile(), settingsFile.getName()
+                    + ".interpolated" );
+                request.setUserSettingsFile( new File( settingsFile.getParentFile(), settingsFile.getName()
+                    + ".interpolated" ) );
             }
             
             if ( mavenOpts != null )
@@ -1123,39 +1139,47 @@
         return result;
     }
 
-    protected File buildInterpolatedPomFile( File pomFile, File targetDirectory )
+    protected File buildInterpolatedFile( File originalFile, File targetDirectory, String
targetFileName )
         throws MojoExecutionException
     {
-        File interpolatedPomFile = new File( targetDirectory, "interpolated-pom.xml" );
-        if (interpolatedPomFile.exists())
+        File interpolatedFile = new File( targetDirectory, targetFileName );
+        if (interpolatedFile.exists())
+        {
+            interpolatedFile.delete();
+        }
+        interpolatedFile.deleteOnExit();
+        if ( settings.getLocalRepository() != null )
         {
-            interpolatedPomFile.delete();
+            if (this.interpolationsProperties == null)
+            {
+                this.interpolationsProperties = new Properties();
+            }
+            this.interpolationsProperties.put( "localRepository", settings.getLocalRepository()
);
         }
-        interpolatedPomFile.deleteOnExit();
         Map composite = new CompositeMap( this.project, this.interpolationsProperties );
 
         try
         {
-            boolean created = interpolatedPomFile.createNewFile();
+            boolean created = interpolatedFile.createNewFile();
             if ( !created )
             {
-                throw new MojoExecutionException( "fail to create file " + interpolatedPomFile.getPath()
);
+                throw new MojoExecutionException( "fail to create file " + interpolatedFile.getPath()
);
             }
         }
         catch ( IOException e )
         {
-            throw new MojoExecutionException( "fail to create file " + interpolatedPomFile.getPath()
);
+            throw new MojoExecutionException( "fail to create file " + interpolatedFile.getPath()
);
         }
-        getLog().debug( "interpolate it pom to create interpolated in " + interpolatedPomFile.getPath()
);
+        getLog().debug( "interpolate it pom to create interpolated in " + interpolatedFile.getPath()
);
 
         BufferedReader reader = null;
         Writer writer = null;
         try
         {
-            // pom interpolation with token @...@
-            reader = new BufferedReader( new InterpolationFilterReader( ReaderFactory.newXmlReader(
pomFile ), composite, "@",
+            // interpolation with token @...@
+            reader = new BufferedReader( new InterpolationFilterReader( ReaderFactory.newXmlReader(
originalFile ), composite, "@",
                                                                         "@" ) );
-            writer = WriterFactory.newXmlWriter( interpolatedPomFile );
+            writer = WriterFactory.newXmlWriter( interpolatedFile );
             String line = null;
             while ( ( line = reader.readLine() ) != null )
             {
@@ -1175,12 +1199,12 @@
             IOUtil.close( writer );
         }
 
-        if ( interpolatedPomFile == null )
+        if ( interpolatedFile == null )
         {
             // null check : normally impossibe but :-)
             throw new MojoExecutionException( "pom file is null after interpolation" );
         }
-        return interpolatedPomFile;
+        return interpolatedFile;
     }
 
     protected List getProfiles( File projectDirectory )

Modified: maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InterpolationTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InterpolationTest.java?rev=649858&r1=649857&r2=649858&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InterpolationTest.java
(original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InterpolationTest.java
Sat Apr 19 15:09:36 2008
@@ -27,6 +27,7 @@
 import org.apache.maven.model.Scm;
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+import org.apache.maven.settings.Settings;
 import org.codehaus.plexus.util.IOUtil;
 
 /**
@@ -74,6 +75,7 @@
         InvokerMojo invokerMojo = new InvokerMojo();
         setVariableValueToObject( invokerMojo, "goalsFile", "goals.txt" );
         setVariableValueToObject( invokerMojo, "project", buildMavenProjectStub() );
+        setVariableValueToObject( invokerMojo, "settings", new Settings() );
         Properties properties = new Properties();
         properties.put( "cleanProps", "clean" );
         properties.put( "version", "2.0-SNAPSHOT" );
@@ -96,23 +98,24 @@
             InvokerMojo invokerMojo = new InvokerMojo();
             setVariableValueToObject( invokerMojo, "goalsFile", "goals.txt" );
             setVariableValueToObject( invokerMojo, "project", buildMavenProjectStub() );
+            setVariableValueToObject( invokerMojo, "settings", new Settings() );
             Properties properties = new Properties();
             properties.put( "foo", "bar" );
             properties.put( "version", "2.0-SNAPSHOT" );
             setVariableValueToObject( invokerMojo, "interpolationsProperties", properties
);
             String dirPath = getBasedir() + File.separatorChar + "src" + File.separatorChar
+ "test"
                 + File.separatorChar + "resources" + File.separatorChar + "unit" + File.separatorChar
+ "interpolation";
-            interpolatedPomFile = invokerMojo.buildInterpolatedPomFile( new File( dirPath,
"pom.xml" ),
+            interpolatedPomFile = invokerMojo.buildInterpolatedFile( new File( dirPath, "pom.xml"
),
                                                                         new File( getBasedir()
+ File.separatorChar
-                                                                            + "target" )
);
+                                                                            + "target" ),
"interpolated-pom.xml"  );
             fileReader = new FileReader( interpolatedPomFile );
             String content = IOUtil.toString( fileReader );
             assertTrue( content.indexOf( "<interpolateValue>bar</interpolateValue>"
) > 0 );
             fileReader.close();
             // recreate it to test delete if exists before creation
-            interpolatedPomFile = invokerMojo.buildInterpolatedPomFile( new File( dirPath,
"pom.xml" ),
+            interpolatedPomFile = invokerMojo.buildInterpolatedFile( new File( dirPath, "pom.xml"
),
                                                                         new File( getBasedir()
+ File.separatorChar
-                                                                            + "target" )
);
+                                                                            + "target" ),
"interpolated-pom.xml"  );
             fileReader = new FileReader( interpolatedPomFile );
             content = IOUtil.toString( fileReader );
             assertTrue( content.indexOf( "<interpolateValue>bar</interpolateValue>"
) > 0 );
@@ -149,6 +152,7 @@
         InvokerMojo invokerMojo = new InvokerMojo();
         setVariableValueToObject( invokerMojo, "profiles", Arrays.asList( new String[] {
"zloug" } ) );
         setVariableValueToObject( invokerMojo, "profilesFile", "emptyProfiles.txt" );
+        setVariableValueToObject( invokerMojo, "settings", new Settings() );
         String dirPath = getBasedir() + File.separatorChar + "src" + File.separatorChar +
"test" + File.separatorChar
             + "resources" + File.separatorChar + "unit" + File.separatorChar + "profiles-from-file";
         List profiles = invokerMojo.getProfiles( new File( dirPath ) );
@@ -164,6 +168,7 @@
         InvokerMojo invokerMojo = new InvokerMojo();
         setVariableValueToObject( invokerMojo, "profiles", Arrays.asList( new String[] {
"zloug" } ) );
         setVariableValueToObject( invokerMojo, "profilesFile", "zorglubProfiles.txt" );
+        setVariableValueToObject( invokerMojo, "settings", new Settings() );
         String dirPath = getBasedir() + File.separatorChar + "src" + File.separatorChar +
"test" + File.separatorChar
             + "resources" + File.separatorChar + "unit" + File.separatorChar + "profiles-from-file";
         List profiles = invokerMojo.getProfiles( new File( dirPath ) );

Modified: maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java?rev=649858&r1=649857&r2=649858&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java
(original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java
Sat Apr 19 15:09:36 2008
@@ -25,6 +25,7 @@
 import java.util.List;
 
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.apache.maven.settings.Settings;
 import org.apache.maven.shared.invoker.Invoker;
 import org.codehaus.plexus.util.FileUtils;
 
@@ -73,6 +74,7 @@
         //cloneProjectsTo.getParent()
         setVariableValueToObject( invokerMojo, "cloneProjectsTo", cloneProjectsTo );
         setVariableValueToObject( invokerMojo, "postBuildHookScript", "verify.bsh" );
+        setVariableValueToObject( invokerMojo, "settings", new Settings() );
         invokerMojo.execute();
     }
 



Mime
View raw message