maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdca...@apache.org
Subject svn commit: r501576 - in /maven/shared/trunk/maven-plugin-testing-tools/src: main/java/org/apache/maven/shared/test/plugin/ test/java/org/apache/maven/shared/test/plugin/
Date Tue, 30 Jan 2007 21:34:59 GMT
Author: jdcasey
Date: Tue Jan 30 13:34:58 2007
New Revision: 501576

URL: http://svn.apache.org/viewvc?view=rev&rev=501576
Log:
Adding pomFile (for the POM to be staged) to the API to avoid problems with multimodule builds,
and adding new tool, ComponentTestTool, which is essentially the same as the PluginTestTool,
except with generalized naming, to make it intuitive for any Maven component artifact.

Added:
    maven/shared/trunk/maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/ComponentTestTool.java
  (with props)
Modified:
    maven/shared/trunk/maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/PluginTestTool.java
    maven/shared/trunk/maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/RepositoryTool.java
    maven/shared/trunk/maven-plugin-testing-tools/src/test/java/org/apache/maven/shared/test/plugin/RepositoryToolTest.java

Added: maven/shared/trunk/maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/ComponentTestTool.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/ComponentTestTool.java?view=auto&rev=501576
==============================================================================
--- maven/shared/trunk/maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/ComponentTestTool.java
(added)
+++ maven/shared/trunk/maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/ComponentTestTool.java
Tue Jan 30 13:34:58 2007
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.shared.test.plugin;
+
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Test tool that provides a single point of access for staging a maven component artifact
- along with its
+ * POM lineage - into a clean test-time local repository. This involves modifying the component
POM to 
+ * provide a stable test-time version for test-build POMs to reference, then installing the
component
+ * jar and associated POMs (including those ancestors that are reachable using <relativePath>)
+ * into the test local repository.
+ * 
+ * <p>
+ * <b>WARNING:</b> Currently, the <code>RepositoryTool</code> will
not 
+ * resolve parent POMs that exist <b>only</b> in your normal local repository,
and are not reachable 
+ * using the relativePath element. This may result in failed test builds, as one or more
of the 
+ * component's ancestor POMs cannot be resolved.
+ * </p>
+ * 
+ * @plexus.component role="org.apache.maven.shared.test.plugin.ComponentTestTool" role-hint="default"
+ * @author jdcasey
+ *
+ */
+public class ComponentTestTool
+{
+    public static final String ROLE = ComponentTestTool.class.getName();
+
+    /**
+     * @plexus.requirement role-hint="default"
+     */
+    private ProjectTool projectTool;
+
+    /**
+     * @plexus.requirement role-hint="default"
+     */
+    private RepositoryTool repositoryTool;
+
+    /**
+     * Stage the component, using a stable version, into a temporary local-repository directory
that is
+     * generated by this method. When the component is staged, return the local repository
base directory
+     * for use in test builds.
+     * 
+     * @param testVersion The test version for the component, used for reference in test-build
POMs and
+     *   fully-qualified goals
+     * @return The base-directory location of the generated local repository
+     */
+    public File prepareComponentForIntegrationTesting( File pomFile, String testVersion )
+        throws TestToolsException
+    {
+        return prepareForTesting( pomFile, testVersion, false, null );
+    }
+
+    /**
+     * Stage the component, using a stable version, into a temporary local-repository directory
that is
+     * generated by this method. When the component is staged, return the local repository
base directory
+     * for use in test builds. This method also skips unit testing during component jar production,

+     * since it is assumed that executing these tests would lead to a recursive test-and-build
loop.
+     * 
+     * @param testVersion The test version for the component, used for reference in test-build
POMs and
+     *   fully-qualified goals
+     * @return The base-directory location of the generated local repository
+     */
+    public File prepareComponentForUnitTestingWithMavenBuilds( File pomFile, String testVersion
)
+        throws TestToolsException
+    {
+        return prepareForTesting( pomFile, testVersion, true, null );
+    }
+
+    /**
+     * Stage the component, using a stable version, into the specified local-repository directory.

+     * When the component is staged, return the local repository base directory for verification.
+     * 
+     * @param testVersion The test version for the component, used for reference in test-build
POMs and
+     *   fully-qualified goals
+     * @param localRepositoryDir The base-directory location of the test local repository,
into which
+     *   the component's test version should be staged.
+     * @return The base-directory location of the generated local repository
+     */
+    public File prepareComponentForIntegrationTesting( File pomFile, String testVersion,
File localRepositoryDir )
+        throws TestToolsException
+    {
+        return prepareForTesting( pomFile, testVersion, false, localRepositoryDir );
+    }
+
+    /**
+     * Stage the component, using a stable version, into the specified local-repository directory.

+     * When the component is staged, return the local repository base directory for verification.
This 
+     * method also skips unit testing during component jar production, since it is assumed
that 
+     * executing these tests would lead to a recursive test-and-build loop.
+     * 
+     * @param testVersion The test version for the component, used for reference in test-build
POMs and
+     *   fully-qualified goals
+     * @param localRepositoryDir The base-directory location of the test local repository,
into which
+     *   the component's test version should be staged.
+     * @return The base-directory location of the generated local repository
+     */
+    public File prepareComponentForUnitTestingWithMavenBuilds( File pomFile, String testVersion,
File localRepositoryDir )
+        throws TestToolsException
+    {
+        return prepareForTesting( pomFile, testVersion, true, localRepositoryDir );
+    }
+
+    private File prepareForTesting( File pomFile, String testVersion, boolean skipUnitTests,
File localRepositoryDir )
+        throws TestToolsException
+    {
+        File realProjectDir = pomFile.getParentFile();
+        try
+        {
+            realProjectDir = realProjectDir.getCanonicalFile();
+        }
+        catch ( IOException e )
+        {
+            throw new TestToolsException( "Failed to stage component for testing.", e );
+        }
+        
+        try
+        {
+            final File tmpDir = File.createTempFile( "component-IT-staging-project", "" );
+
+            tmpDir.delete();
+
+            tmpDir.mkdirs();
+
+            Runtime.getRuntime().addShutdownHook( new Thread( new Runnable()
+            {
+
+                public void run()
+                {
+                    try
+                    {
+                        FileUtils.deleteDirectory( tmpDir );
+                    }
+                    catch ( IOException e )
+                    {
+                        // it'll get cleaned up when the temp dir is purged next...
+                    }
+                }
+
+            } ) );
+
+            FileUtils.copyDirectoryStructure( realProjectDir, tmpDir );
+        }
+        catch ( IOException e )
+        {
+            throw new TestToolsException( "Failed to create temporary staging directory for
component project.", e );
+        }
+
+        File buildLog = new File( "target/test-build-logs/setup.build.log" );
+        
+        buildLog.getParentFile().mkdirs();
+
+        File localRepoDir = localRepositoryDir;
+
+        if ( localRepoDir == null )
+        {
+            localRepoDir = new File( "target/test-local-repository" );
+        }
+
+        MavenProject project = projectTool.packageProjectArtifact( pomFile, testVersion,
skipUnitTests, buildLog );
+        
+        repositoryTool.createLocalRepositoryFromComponentProject( project, new File( realProjectDir,
"pom.xml" ), localRepoDir );
+
+        return localRepoDir;
+    }
+
+}

Propchange: maven/shared/trunk/maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/ComponentTestTool.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/shared/trunk/maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/ComponentTestTool.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/shared/trunk/maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/PluginTestTool.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/PluginTestTool.java?view=diff&rev=501576&r1=501575&r2=501576
==============================================================================
--- maven/shared/trunk/maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/PluginTestTool.java
(original)
+++ maven/shared/trunk/maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/PluginTestTool.java
Tue Jan 30 13:34:58 2007
@@ -65,10 +65,10 @@
      *   fully-qualified goals
      * @return The base-directory location of the generated local repository
      */
-    public File preparePluginForIntegrationTesting( String testVersion )
+    public File preparePluginForIntegrationTesting( File pomFile, String testVersion )
         throws TestToolsException
     {
-        return prepareForTesting( testVersion, false, null );
+        return prepareForTesting( pomFile, testVersion, false, null );
     }
 
     /**
@@ -81,10 +81,10 @@
      *   fully-qualified goals
      * @return The base-directory location of the generated local repository
      */
-    public File preparePluginForUnitTestingWithMavenBuilds( String testVersion )
+    public File preparePluginForUnitTestingWithMavenBuilds( File pomFile, String testVersion
)
         throws TestToolsException
     {
-        return prepareForTesting( testVersion, true, null );
+        return prepareForTesting( pomFile, testVersion, true, null );
     }
 
     /**
@@ -97,10 +97,10 @@
      *   the plugin's test version should be staged.
      * @return The base-directory location of the generated local repository
      */
-    public File preparePluginForIntegrationTesting( String testVersion, File localRepositoryDir
)
+    public File preparePluginForIntegrationTesting( File pomFile, String testVersion, File
localRepositoryDir )
         throws TestToolsException
     {
-        return prepareForTesting( testVersion, false, localRepositoryDir );
+        return prepareForTesting( pomFile, testVersion, false, localRepositoryDir );
     }
 
     /**
@@ -115,26 +115,26 @@
      *   the plugin's test version should be staged.
      * @return The base-directory location of the generated local repository
      */
-    public File preparePluginForUnitTestingWithMavenBuilds( String testVersion, File localRepositoryDir
)
+    public File preparePluginForUnitTestingWithMavenBuilds( File pomFile, String testVersion,
File localRepositoryDir )
         throws TestToolsException
     {
-        return prepareForTesting( testVersion, true, localRepositoryDir );
+        return prepareForTesting( pomFile, testVersion, true, localRepositoryDir );
     }
 
-    private File prepareForTesting( String testVersion, boolean skipUnitTests, File localRepositoryDir
)
+    private File prepareForTesting( File pomFile, String testVersion, boolean skipUnitTests,
File localRepositoryDir )
         throws TestToolsException
     {
-        File realProjectDir;
+        File realProjectDir = pomFile.getParentFile();
+        
         try
         {
-            realProjectDir = new File( "." ).getCanonicalFile();
+            realProjectDir = realProjectDir.getCanonicalFile();
         }
         catch ( IOException e )
         {
             throw new TestToolsException( "Failed to stage plugin for testing.", e );
         }
         
-        File pomFile;
         try
         {
             final File tmpDir = File.createTempFile( "plugin-IT-staging-project", "" );
@@ -143,26 +143,24 @@
 
             tmpDir.mkdirs();
 
-            Runtime.getRuntime().addShutdownHook( new Thread( new Runnable()
-            {
-
-                public void run()
-                {
-                    try
-                    {
-                        FileUtils.deleteDirectory( tmpDir );
-                    }
-                    catch ( IOException e )
-                    {
-                        // it'll get cleaned up when the temp dir is purged next...
-                    }
-                }
-
-            } ) );
+//            Runtime.getRuntime().addShutdownHook( new Thread( new Runnable()
+//            {
+//
+//                public void run()
+//                {
+//                    try
+//                    {
+//                        FileUtils.deleteDirectory( tmpDir );
+//                    }
+//                    catch ( IOException e )
+//                    {
+//                        // it'll get cleaned up when the temp dir is purged next...
+//                    }
+//                }
+//
+//            } ) );
 
             FileUtils.copyDirectoryStructure( realProjectDir, tmpDir );
-
-            pomFile = new File( tmpDir, "pom.xml" );
         }
         catch ( IOException e )
         {
@@ -182,7 +180,7 @@
 
         MavenProject project = projectTool.packageProjectArtifact( pomFile, testVersion,
skipUnitTests, buildLog );
         
-        repositoryTool.createLocalRepositoryFromPlugin( project, new File( realProjectDir,
"pom.xml" ), localRepoDir );
+        repositoryTool.createLocalRepositoryFromComponentProject( project, new File( realProjectDir,
"pom.xml" ), localRepoDir );
 
         return localRepoDir;
     }

Modified: maven/shared/trunk/maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/RepositoryTool.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/RepositoryTool.java?view=diff&rev=501576&r1=501575&r2=501576
==============================================================================
--- maven/shared/trunk/maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/RepositoryTool.java
(original)
+++ maven/shared/trunk/maven-plugin-testing-tools/src/main/java/org/apache/maven/shared/test/plugin/RepositoryTool.java
Tue Jan 30 13:34:58 2007
@@ -107,10 +107,16 @@
         {
             throw new TestToolsException( "Error building Maven settings.", e );
         }
-
-        return settings == null || settings.getLocalRepository() == null
-            ? new File( new File( System.getProperty( "user.home" ) ), ".m2/repository" )
-            : new File( settings.getLocalRepository() );
+        
+        if ( settings == null || settings.getLocalRepository() == null
+            || settings.getLocalRepository().trim().length() < 1 )
+        {
+            return new File( System.getProperty( "user.home" ), ".m2/repository" );
+        }
+        else
+        {
+            return new File( settings.getLocalRepository() );
+        }
     }
 
     /**
@@ -164,14 +170,15 @@
      * result in failed test builds, as one or more of the plugin's ancestor POMs cannot
be resolved.
      * </p>
      *
-     * @param pluginProject
+     * @param project
      * @param targetLocalRepoBasedir
      * @throws TestToolsException
      */
-    public void createLocalRepositoryFromPlugin( MavenProject pluginProject, File realPomFile,
File targetLocalRepoBasedir )
+    public void createLocalRepositoryFromComponentProject( MavenProject project, File realPomFile,
File targetLocalRepoBasedir )
         throws TestToolsException
     {
-        Artifact artifact = pluginProject.getArtifact();
+        Artifact artifact = project.getArtifact();
+        
         ArtifactRepository localRepository = createLocalArtifactRepositoryInstance( targetLocalRepoBasedir
);
 
         String localPath = localRepository.pathOf( artifact );

Modified: maven/shared/trunk/maven-plugin-testing-tools/src/test/java/org/apache/maven/shared/test/plugin/RepositoryToolTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-plugin-testing-tools/src/test/java/org/apache/maven/shared/test/plugin/RepositoryToolTest.java?view=diff&rev=501576&r1=501575&r2=501576
==============================================================================
--- maven/shared/trunk/maven-plugin-testing-tools/src/test/java/org/apache/maven/shared/test/plugin/RepositoryToolTest.java
(original)
+++ maven/shared/trunk/maven-plugin-testing-tools/src/test/java/org/apache/maven/shared/test/plugin/RepositoryToolTest.java
Tue Jan 30 13:34:58 2007
@@ -75,7 +75,7 @@
 
         File targetLocalRepoBasedir = fileManager.createTempDir();
 
-        repoTool.createLocalRepositoryFromPlugin( pluginProject, pom, targetLocalRepoBasedir
);
+        repoTool.createLocalRepositoryFromComponentProject( pluginProject, pom, targetLocalRepoBasedir
);
 
         fileManager.assertFileExistence( targetLocalRepoBasedir, "group/artifact/test/artifact-test.pom",
true );
         fileManager.assertFileContents( targetLocalRepoBasedir, "group/artifact/test/artifact-test.jar",
jarContent );



Mime
View raw message