maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krosenv...@apache.org
Subject svn commit: r1075071 - in /maven/surefire/trunk: ./ maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ maven-surefire-common/src/test/java/org/apache/...
Date Sun, 27 Feb 2011 14:58:33 GMT
Author: krosenvold
Date: Sun Feb 27 14:58:32 2011
New Revision: 1075071

URL: http://svn.apache.org/viewvc?rev=1075071&view=rev
Log:
[SUREFIRE-700] Added support for fully shaded provider

The shaded provider is created as the first module of the build itself and
thereafter used to test surefire itself.

Please note that this feature requires a release before it can be activated
properly.

Added:
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/Relocator.java
  (with props)
    maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/RelocatorTest.java
  (with props)
    maven/surefire/trunk/surefire-shadefire/
    maven/surefire/trunk/surefire-shadefire/pom.xml   (with props)
    maven/surefire/trunk/surefire-shadefire/src/
    maven/surefire/trunk/surefire-shadefire/src/main/
    maven/surefire/trunk/surefire-shadefire/src/main/resources/
    maven/surefire/trunk/surefire-shadefire/src/main/resources/META-INF/
    maven/surefire/trunk/surefire-shadefire/src/main/resources/META-INF/services/
    maven/surefire/trunk/surefire-shadefire/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider
Modified:
    maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
    maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java
    maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
    maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
    maven/surefire/trunk/pom.xml
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/StartupConfiguration.java

Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java?rev=1075071&r1=1075070&r2=1075071&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
(original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
Sun Feb 27 14:58:32 2011
@@ -54,6 +54,7 @@ import org.apache.maven.surefire.testset
 import org.apache.maven.surefire.testset.TestArtifactInfo;
 import org.apache.maven.surefire.testset.TestRequest;
 import org.apache.maven.surefire.util.NestedRuntimeException;
+import org.apache.maven.surefire.util.Relocator;
 import org.apache.maven.toolchain.Toolchain;
 import org.codehaus.plexus.util.StringUtils;
 
@@ -99,47 +100,45 @@ public abstract class AbstractSurefireMo
         if ( verifyParameters() && !hasExecutedBefore() )
         {
             logReportsDirectory();
-        	executeAfterPreconditionsChecked();
+            executeAfterPreconditionsChecked();
         }
     }
 
     protected boolean verifyParameters()
         throws MojoFailureException
-	{
-	    if ( isSkipExecution() )
-	    {
-	        getLog().info( "Tests are skipped." );
-	        return false;
-	    }
-	
-	    if ( !getTestClassesDirectory().exists() )
-	    {
-	        if ( Boolean.TRUE.equals(getFailIfNoTests()) )
-	        {
-	            throw new MojoFailureException( "No tests to run!" );
-	        }
-	        getLog().info( "No tests to run." );
-	    }
-	    else
-	    {
-	        ensureWorkingDirectoryExists();
-	        ensureParallelRunningCompatibility();
-	        warnIfUselessUseSystemClassLoaderParameter();
-	    }
-	
-	    return true;
-	}
-    
+    {
+        if ( isSkipExecution() )
+        {
+            getLog().info( "Tests are skipped." );
+            return false;
+        }
+
+        if ( !getTestClassesDirectory().exists() )
+        {
+            if ( Boolean.TRUE.equals( getFailIfNoTests() ) )
+            {
+                throw new MojoFailureException( "No tests to run!" );
+            }
+            getLog().info( "No tests to run." );
+        }
+        else
+        {
+            ensureWorkingDirectoryExists();
+            ensureParallelRunningCompatibility();
+            warnIfUselessUseSystemClassLoaderParameter();
+        }
+
+        return true;
+    }
+
     protected abstract boolean isSkipExecution();
-    
+
     protected abstract void executeAfterPreconditionsChecked()
         throws MojoExecutionException, MojoFailureException;
 
     private Artifact surefireArtifact;
 
 
-    private ProviderList wellKnownProviders;
-
     protected List initialize()
         throws MojoFailureException
     {
@@ -150,10 +149,11 @@ public abstract class AbstractSurefireMo
         try
         {
             final Artifact junitDepArtifact = getJunitDepArtifact();
-            wellKnownProviders = new ProviderList( new ProviderInfo[]{ new TestNgProviderInfo(
getTestNgArtifact() ),
-                new JUnitCoreProviderInfo( getJunitArtifact(), junitDepArtifact ),
-                new JUnit4ProviderInfo( getJunitArtifact(), junitDepArtifact ), new JUnit3ProviderInfo()
},
-                                                   new DynamicProviderInfo( null ) );
+            ProviderList wellKnownProviders = new ProviderList(
+                new ProviderInfo[]{ new TestNgProviderInfo( getTestNgArtifact() ),
+                    new JUnitCoreProviderInfo( getJunitArtifact(), junitDepArtifact ),
+                    new JUnit4ProviderInfo( getJunitArtifact(), junitDepArtifact ), new JUnit3ProviderInfo()
},
+                new DynamicProviderInfo( null ) );
 
             return wellKnownProviders.resolve( getLog() );
         }
@@ -265,45 +265,28 @@ public abstract class AbstractSurefireMo
         return ForkConfiguration.FORK_NEVER.equals( getForkMode() );
     }
 
-    protected ProviderConfiguration createProviderConfiguration( ForkConfiguration forkConfiguration
)
+    protected ProviderConfiguration createProviderConfiguration( ForkConfiguration forkConfiguration,
+                                                                 boolean shadefire )
         throws MojoExecutionException, MojoFailureException
     {
 
         List reports = getReporters( forkConfiguration.isForking() );
+        reports = shadefire ? new Relocator().relocateReports( reports ) : reports;
         Integer timeoutSet =
             getForkedProcessTimeoutInSeconds() > 0 ? Integer.valueOf( getForkedProcessTimeoutInSeconds()
) : null;
         ReporterConfiguration reporterConfiguration =
             new ReporterConfiguration( reports, getReportsDirectory(), Boolean.valueOf( isTrimStackTrace()
),
                                        timeoutSet );
 
-        surefireArtifact = (Artifact) getPluginArtifactMap().get( "org.apache.maven.surefire:surefire-booter"
);
-        if ( surefireArtifact == null )
-        {
-            throw new MojoExecutionException( "Unable to locate surefire-booter in the list
of plugin artifacts" );
-        }
-
-        surefireArtifact.isSnapshot(); // MNG-2961: before Maven 2.0.8, fixes getBaseVersion
to be -SNAPSHOT if needed
-
         Artifact testNgArtifact;
         try
         {
-            addArtifact( forkConfiguration.getBootClasspath(), surefireArtifact );
-
             testNgArtifact = getTestNgArtifact();
         }
-        catch ( ArtifactNotFoundException e )
-        {
-            throw new MojoExecutionException(
-                "Unable to locate required surefire provider dependency: " + e.getMessage(),
e );
-        }
         catch ( InvalidVersionSpecificationException e )
         {
             throw new MojoExecutionException( "Error determining the TestNG version requested:
" + e.getMessage(), e );
         }
-        catch ( ArtifactResolutionException e )
-        {
-            throw new MojoExecutionException( "Error to resolving surefire provider dependency:
" + e.getMessage(), e );
-        }
 
         DirectoryScannerParameters directoryScannerParameters = null;
         final boolean isTestNg = testNgArtifact != null;
@@ -377,19 +360,9 @@ public abstract class AbstractSurefireMo
         final ClasspathConfiguration classpathConfiguration =
             new ClasspathConfiguration( isEnableAssertions(), isChildDelegation() );
 
-        surefireArtifact = (Artifact) getPluginArtifactMap().get( "org.apache.maven.surefire:surefire-booter"
);
-        if ( surefireArtifact == null )
-        {
-            throw new MojoExecutionException( "Unable to locate surefire-booter in the list
of plugin artifacts" );
-        }
-
-        surefireArtifact.isSnapshot(); // MNG-2961: before Maven 2.0.8, fixes getBaseVersion
to be -SNAPSHOT if needed
-
         String providerName;
         try
         {
-            addArtifact( forkConfiguration.getBootClasspath(), surefireArtifact );
-
             provider.addProviderProperties();
             provider.addProviderArtifactToSurefireClasspath( classpathConfiguration );
             providerName = provider.getProviderName();
@@ -426,12 +399,13 @@ public abstract class AbstractSurefireMo
             throw new MojoExecutionException( "Unable to generate test classpath: " + e,
e );
         }
 
-        addClasspathElementsToClasspathConfiguration(classpathElements, classpathConfiguration);
+        addClasspathElementsToClasspathConfiguration( classpathElements, classpathConfiguration
);
         return new StartupConfiguration( providerName, classpathConfiguration, classLoaderConfiguration,
                                          forkConfiguration.isForking(), false, isRedirectTestOutputToFile()
);
     }
 
-    private void addClasspathElementsToClasspathConfiguration(List classpathElements, ClasspathConfiguration
classpathConfiguration)
+    private void addClasspathElementsToClasspathConfiguration( List classpathElements,
+                                                               ClasspathConfiguration classpathConfiguration
)
     {
         getLog().debug( "Test classpath:" );
         for ( Iterator i = classpathElements.iterator(); i.hasNext(); )
@@ -439,7 +413,7 @@ public abstract class AbstractSurefireMo
             String classpathElement = (String) i.next();
             if ( classpathElement == null )
             {
-                getLog().warn("The test classpath contains a null element.");
+                getLog().warn( "The test classpath contains a null element." );
             }
             else
             {
@@ -537,8 +511,8 @@ public abstract class AbstractSurefireMo
             if ( !range.containsVersion( new DefaultArtifactVersion( artifact.getVersion()
) ) )
             {
                 throw new MojoFailureException(
-                    "TestNG support requires version 4.7 or above. You have declared version
" +
-                        artifact.getVersion() );
+                    "TestNG support requires version 4.7 or above. You have declared version
"
+                        + artifact.getVersion() );
             }
         }
         return artifact;
@@ -561,7 +535,8 @@ public abstract class AbstractSurefireMo
     {
         StartupConfiguration startupConfiguration =
             createStartupConfiguration( forkConfiguration, provider, classLoaderConfiguration
);
-        ProviderConfiguration providerConfiguration = createProviderConfiguration( forkConfiguration
);
+        ProviderConfiguration providerConfiguration =
+            createProviderConfiguration( forkConfiguration, startupConfiguration.isShadefire()
);
         return new ForkStarter( providerConfiguration, startupConfiguration, getReportsDirectory(),
forkConfiguration,
                                 getForkedProcessTimeoutInSeconds(), isPrintSummary() );
     }
@@ -572,7 +547,18 @@ public abstract class AbstractSurefireMo
         //noinspection ResultOfMethodCallIgnored
         tmpDir.mkdirs();
 
-        final Classpath bootClasspathConfiguration = new Classpath();
+        Artifact shadeFire = (Artifact) getPluginArtifactMap().get( "org.apache.maven.surefire:surefire-shadefire"
);
+
+        surefireArtifact = (Artifact) getPluginArtifactMap().get( "org.apache.maven.surefire:surefire-booter"
);
+        if ( surefireArtifact == null )
+        {
+            throw new RuntimeException( "Unable to locate surefire-booter in the list of
plugin artifacts" );
+        }
+
+        surefireArtifact.isSnapshot(); // MNG-2961: before Maven 2.0.8, fixes getBaseVersion
to be -SNAPSHOT if needed
+
+        final Classpath bootClasspathConfiguration =
+            getArtifactClasspath( shadeFire != null ? shadeFire : surefireArtifact );
 
         ForkConfiguration fork = new ForkConfiguration( bootClasspathConfiguration, getForkMode(),
tmpDir );
 
@@ -852,7 +838,6 @@ public abstract class AbstractSurefireMo
 
 
     private ArtifactResolutionResult resolveArtifact( Artifact filteredArtifact, Artifact
providerArtifact )
-        throws ArtifactResolutionException, ArtifactNotFoundException
     {
         ArtifactFilter filter = null;
         if ( filteredArtifact != null )
@@ -863,26 +848,38 @@ public abstract class AbstractSurefireMo
 
         Artifact originatingArtifact = getArtifactFactory().createBuildArtifact( "dummy",
"dummy", "1.0", "jar" );
 
-        return getArtifactResolver().resolveTransitively( Collections.singleton( providerArtifact
),
-                                                          originatingArtifact, getLocalRepository(),
-                                                          getRemoteRepositories(), getMetadataSource(),
filter );
+        try
+        {
+            return getArtifactResolver().resolveTransitively( Collections.singleton( providerArtifact
),
+                                                              originatingArtifact, getLocalRepository(),
+                                                              getRemoteRepositories(), getMetadataSource(),
filter );
+        }
+        catch ( ArtifactResolutionException e )
+        {
+            throw new NestedRuntimeException( e );
+        }
+        catch ( ArtifactNotFoundException e )
+        {
+            throw new NestedRuntimeException( e );
+        }
     }
 
-    private void addArtifact( Classpath bootClasspath, Artifact surefireArtifact )
-        throws ArtifactNotFoundException, ArtifactResolutionException
+    private Classpath getArtifactClasspath( Artifact surefireArtifact )
     {
         ArtifactResolutionResult result = resolveArtifact( null, surefireArtifact );
 
+        List items = new ArrayList();
         for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); )
         {
             Artifact artifact = (Artifact) i.next();
 
             getLog().debug(
-                "Adding to " + getPluginName() + " booter test classpath: " + artifact.getFile().getAbsolutePath()
+
-                    " Scope: " + artifact.getScope() );
+                "Adding to " + getPluginName() + " booter test classpath: " + artifact.getFile().getAbsolutePath()
+                    + " Scope: " + artifact.getScope() );
 
-            bootClasspath.addClassPathElementUrl( artifact.getFile().getAbsolutePath() );
+            items.add( artifact.getFile().getAbsolutePath() );
         }
+        return new Classpath( items );
     }
 
     protected void processSystemProperties( boolean setInSystem )
@@ -956,8 +953,8 @@ public abstract class AbstractSurefireMo
         }
         catch ( Exception e )
         {
-            String msg = "Build uses Maven 2.0.x, cannot propagate system properties" +
-                " from command line to tests (cf. SUREFIRE-121)";
+            String msg = "Build uses Maven 2.0.x, cannot propagate system properties"
+                + " from command line to tests (cf. SUREFIRE-121)";
             if ( getLog().isDebugEnabled() )
             {
                 getLog().warn( msg, e );
@@ -1012,7 +1009,6 @@ public abstract class AbstractSurefireMo
         return reports;
     }
 
-
     /**
      * Returns the reporter that will write to the console
      *

Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java?rev=1075071&r1=1075070&r2=1075071&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java
(original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java
Sun Feb 27 14:58:32 2011
@@ -23,6 +23,7 @@ import org.apache.maven.surefire.booter.
 import org.apache.maven.surefire.booter.Classpath;
 import org.apache.maven.surefire.booter.ForkedBooter;
 import org.apache.maven.surefire.booter.SurefireBooterForkException;
+import org.apache.maven.surefire.util.Relocator;
 import org.apache.maven.surefire.util.UrlUtils;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.cli.Commandline;
@@ -159,17 +160,19 @@ public class ForkConfiguration
     /**
      * @param classPath              cla the classpath arguments
      * @param classpathConfiguration the classpath configuration
+     * @param shadefire true if running shadefire
      * @return A commandline
      * @throws org.apache.maven.surefire.booter.SurefireBooterForkException
      *          when unable to perform the fork
      */
-    public Commandline createCommandLine( List classPath, ClassLoaderConfiguration classpathConfiguration
)
+    public Commandline createCommandLine( List classPath, ClassLoaderConfiguration classpathConfiguration,
+                                          boolean shadefire )
         throws SurefireBooterForkException
     {
-        return createCommandLine( classPath, classpathConfiguration.isManifestOnlyJarRequestedAndUsable()
);
+        return createCommandLine( classPath, classpathConfiguration.isManifestOnlyJarRequestedAndUsable(),
shadefire );
     }
 
-    public Commandline createCommandLine( List classPath, boolean useJar )
+    public Commandline createCommandLine( List classPath, boolean useJar, boolean shadefire
)
         throws SurefireBooterForkException
     {
         Commandline cli = new Commandline();
@@ -222,7 +225,9 @@ public class ForkConfiguration
 
             cli.createArg().setValue( StringUtils.join( classPath.iterator(), File.pathSeparator
) );
 
-            cli.createArg().setValue( ForkedBooter.class.getName() );
+            final String forkedBooter = ForkedBooter.class.getName();
+
+            cli.createArg().setValue( shadefire ? new Relocator( ).relocate( forkedBooter
) : forkedBooter);
         }
 
         cli.setWorkingDirectory( workingDirectory.getAbsolutePath() );

Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java?rev=1075071&r1=1075070&r2=1075071&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
(original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
Sun Feb 27 14:58:32 2011
@@ -191,7 +191,7 @@ public class ForkStarter
             throw new SurefireBooterForkException( "Error creating properties files for forking",
e );
         }
 
-        final Classpath bootClasspathConfiguration = forkConfiguration.getBootClasspath();
+        final Classpath bootClasspathConfiguration =  forkConfiguration.getBootClasspath();
         final Classpath additionlClassPathUrls = startupConfiguration.useSystemClassLoader()
             ? startupConfiguration.getClasspathConfiguration().getTestClasspath()
             : null;
@@ -199,7 +199,8 @@ public class ForkStarter
         Classpath bootClasspath = Classpath.join( bootClasspathConfiguration, additionlClassPathUrls
);
 
         Commandline cli = forkConfiguration.createCommandLine( bootClasspath.getClassPath(),
-                                                               startupConfiguration.getClassLoaderConfiguration()
);
+                                                               startupConfiguration.getClassLoaderConfiguration(),
+                                                               startupConfiguration.isShadefire()
);
 
         cli.createArg().setFile( surefireProperties );
 

Modified: maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java?rev=1075071&r1=1075070&r2=1075071&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
(original)
+++ maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
Sun Feb 27 14:58:32 2011
@@ -40,7 +40,8 @@ public class ForkConfigurationTest
         File cpElement = getTempClasspathFile();
         config.setJvmExecutable( "java" );
 
-        Commandline cli = config.createCommandLine( Collections.singletonList( cpElement.getAbsolutePath()
), true );
+        Commandline cli = config.createCommandLine( Collections.singletonList( cpElement.getAbsolutePath()
), true,
+                                                    false );
 
         String line = StringUtils.join( cli.getCommandline(), " " );
         assertTrue( line.indexOf( "-jar" ) > -1 );
@@ -56,7 +57,8 @@ public class ForkConfigurationTest
         forkConfiguration.setArgLine( "abc\ndef" );
 
         final Commandline commandLine =
-            forkConfiguration.createCommandLine( Collections.singletonList( cpElement.getAbsolutePath()
), false );
+            forkConfiguration.createCommandLine( Collections.singletonList( cpElement.getAbsolutePath()
), false,
+                                                 false );
         assertTrue( commandLine.toString().contains( "abc def" ) );
     }
 

Modified: maven/surefire/trunk/pom.xml
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/pom.xml?rev=1075071&r1=1075070&r2=1075071&view=diff
==============================================================================
--- maven/surefire/trunk/pom.xml (original)
+++ maven/surefire/trunk/pom.xml Sun Feb 27 14:58:32 2011
@@ -87,6 +87,7 @@
   </contributors>
 
   <modules>
+    <module>surefire-shadefire</module>
     <module>surefire-api</module>
     <module>surefire-booter</module>
     <module>surefire-providers</module>
@@ -109,6 +110,7 @@
   
   <properties>
     <mavenVersion>2.0.9</mavenVersion>
+    <shadedVersion>2.7.2</shadedVersion>
   </properties>
 
   <dependencyManagement>
@@ -233,7 +235,7 @@
       <plugins>
         <plugin>
           <artifactId>maven-surefire-plugin</artifactId>
-          <version>2.7.2</version>
+          <version>${shadedVersion}</version>
           <configuration>
             <!-- NOTE: Be sure to isolate the Surefire version under test from the version
running the tests! -->
             <useSystemClassLoader>false</useSystemClassLoader>

Added: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/Relocator.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/Relocator.java?rev=1075071&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/Relocator.java
(added)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/Relocator.java
Sun Feb 27 14:58:32 2011
@@ -0,0 +1,76 @@
+package org.apache.maven.surefire.util;
+
+/*
+ * 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.
+ */
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Relocates class names when running with relocated provider
+ *
+ * @author Kristian Rosenvold
+ */
+public class Relocator
+{
+    private final String relocation;
+
+    private static final String relocationBase = "org.apache.maven.surefire.";
+
+
+    public Relocator( String relocation )
+    {
+        this.relocation = relocation;
+    }
+
+    public Relocator()
+    {
+        relocation = "shadefire";
+    }
+
+    public List relocateReports( List original )
+    {
+        List result = new ArrayList();
+        for ( Iterator iter = original.iterator(); iter.hasNext(); )
+        {
+            result.add( relocate( (String) iter.next() ) );
+        }
+        return result;
+    }
+
+    private String getRelocation()
+    {
+        return relocation;
+    }
+
+    public String relocate( String className )
+    {
+        if ( relocation == null )
+        {
+            return className;
+        }
+        if (className.indexOf( relocation) >= 0){
+            return className;
+        }
+        String rest = className.substring( "org.apache.maven.surefire.".length() );
+        final String s = relocationBase + getRelocation() + ".";
+        return s + rest;
+    }
+}

Propchange: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/Relocator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/RelocatorTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/RelocatorTest.java?rev=1075071&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/RelocatorTest.java
(added)
+++ maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/RelocatorTest.java
Sun Feb 27 14:58:32 2011
@@ -0,0 +1,41 @@
+package org.apache.maven.surefire.util;
+
+/*
+ * 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.
+ */
+
+import junit.framework.TestCase;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class RelocatorTest
+    extends TestCase
+{
+
+    public void testFoo(){
+        Relocator relocator = new Relocator( "shadefire" );
+        String cn = "org.apache.maven.surefire.report.ForkingConsoleReporter";
+        assertEquals( "org.apache.maven.surefire.shadefire.report.ForkingConsoleReporter",
relocator.relocate( cn ));
+    }
+    public void testRelocation(){
+        Relocator relocator = new Relocator( "shadefire" );
+        String org1 = "org.apache.maven.surefire.fooz.Baz";
+        assertEquals( "org.apache.maven.surefire.shadefire.fooz.Baz", relocator.relocate(
org1 ));
+    }
+}

Propchange: maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/RelocatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java?rev=1075071&r1=1075070&r2=1075071&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
(original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
Sun Feb 27 14:58:32 2011
@@ -56,7 +56,7 @@ public class Classpath
     {
     }
 
-    private Classpath( Collection elements )
+    public Classpath( List elements )
     {
         this();
         addElements( elements );

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/StartupConfiguration.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/StartupConfiguration.java?rev=1075071&r1=1075070&r2=1075071&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/StartupConfiguration.java
(original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/StartupConfiguration.java
Sun Feb 27 14:58:32 2011
@@ -89,4 +89,8 @@ public class StartupConfiguration
     {
         return classLoaderConfiguration;
     }
+
+    public boolean isShadefire(){
+        return providerClassName.startsWith( "org.apache.maven.surefire.shadefire");
+    }
 }

Added: maven/surefire/trunk/surefire-shadefire/pom.xml
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-shadefire/pom.xml?rev=1075071&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-shadefire/pom.xml (added)
+++ maven/surefire/trunk/surefire-shadefire/pom.xml Sun Feb 27 14:58:32 2011
@@ -0,0 +1,104 @@
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.maven.surefire</groupId>
+    <artifactId>surefire</artifactId>
+    <version>2.7.3-SNAPSHOT</version>
+    <relativePath>../pom.xml</relativePath>
+  </parent>
+
+  <artifactId>surefire-shadefire</artifactId>
+  <description>A super-shaded junit3 provider that is used by surefire to build itself,
+    that basically has ALL classes relocated to facilitate no API-conflict whatsover with
ourself.
+    The only remaining point of conflict is around the booter properties file format
+  </description>
+  <name>surefire-shadefire</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-utils</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.surefire</groupId>
+      <artifactId>surefire-junit3</artifactId>
+      <version>${shadedVersion}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.surefire</groupId>
+      <artifactId>surefire-api</artifactId>
+      <version>${shadedVersion}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.surefire</groupId>
+      <artifactId>surefire-booter</artifactId>
+      <version>${shadedVersion}</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-shade-plugin</artifactId>
+        <version>1.4</version>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals>
+              <goal>shade</goal>
+            </goals>
+            <configuration>
+              <!-- minimizeJar>true</minimizeJar -->
+              <artifactSet>
+                <includes>
+                  <include>org.apache.maven.surefire:surefire-api</include>
+                  <include>org.apache.maven.surefire:surefire-booter</include>
+                  <include>org.apache.maven.surefire:surefire-junit3</include>
+                  <include>org.codehaus.plexus:plexus-utils</include>
+                </includes>
+              </artifactSet>
+              <relocations>
+                <relocation>
+                  <pattern>org.codehaus.plexus.util</pattern>
+                  <shadedPattern>org.apache.maven.shadefire.org.codehaus.plexus.util</shadedPattern>
+                </relocation>
+                <relocation>
+                  <pattern>org.apache.maven.surefire</pattern>
+                  <shadedPattern>org.apache.maven.surefire.shadefire</shadedPattern>
+                </relocation>
+              </relocations>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <skip>true</skip>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: maven/surefire/trunk/surefire-shadefire/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/surefire/trunk/surefire-shadefire/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-shadefire/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider?rev=1075071&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-shadefire/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider
(added)
+++ maven/surefire/trunk/surefire-shadefire/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider
Sun Feb 27 14:58:32 2011
@@ -0,0 +1 @@
+org.apache.maven.surefire.shadefire.junit.JUnit3Provider



Mime
View raw message