maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1143463 - in /maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/test: ArchetyperRoundtripTest.java ArchetyperRoundtripWithProxyTest.java RoundtripMultiModuleTest.java
Date Wed, 06 Jul 2011 15:27:36 GMT
Author: olamy
Date: Wed Jul  6 15:27:35 2011
New Revision: 1143463

URL: http://svn.apache.org/viewvc?rev=1143463&view=rev
Log:
[ARCHETYPE-376] port used in unit test is hardcoded so can cause port allocation issue on
ci machine

Modified:
    maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/test/ArchetyperRoundtripTest.java
    maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/test/ArchetyperRoundtripWithProxyTest.java
    maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/test/RoundtripMultiModuleTest.java

Modified: maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/test/ArchetyperRoundtripTest.java
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/test/ArchetyperRoundtripTest.java?rev=1143463&r1=1143462&r2=1143463&view=diff
==============================================================================
--- maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/test/ArchetyperRoundtripTest.java
(original)
+++ maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/test/ArchetyperRoundtripTest.java
Wed Jul  6 15:27:35 2011
@@ -32,31 +32,23 @@ import org.apache.maven.archetype.common
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.MavenProjectBuilder;
-import org.codehaus.cargo.container.deployable.DeployableType;
-import org.codehaus.cargo.container.deployable.WAR;
-import org.codehaus.cargo.container.deployer.Deployer;
-import org.codehaus.cargo.container.deployer.URLDeployableMonitor;
-import org.codehaus.cargo.container.jetty.Jetty6xEmbeddedLocalContainer;
-import org.codehaus.cargo.container.jetty.Jetty6xEmbeddedLocalDeployer;
-import org.codehaus.cargo.container.jetty.Jetty6xEmbeddedStandaloneLocalConfiguration;
-import org.codehaus.cargo.container.property.ServletPropertySet;
-import org.codehaus.cargo.generic.deployable.DefaultDeployableFactory;
-import org.codehaus.cargo.generic.deployable.DeployableFactory;
 import org.codehaus.plexus.PlexusTestCase;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.StringUtils;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.webapp.WebAppContext;
 
 import java.io.File;
 import java.io.FileWriter;
 import java.io.Writer;
-import java.net.URL;
 import java.util.Properties;
 
-/** @author Jason van Zyl */
+/**
+ * @author Jason van Zyl
+ */
 public class ArchetyperRoundtripTest
     extends PlexusTestCase
 {
-    private Jetty6xEmbeddedLocalContainer container;
 
     public void testArchetyper()
         throws Exception
@@ -68,15 +60,23 @@ public class ArchetyperRoundtripTest
 
         MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE
);
 
-        ArtifactRepository localRepository =
-            registryManager.createRepository( new File( getBasedir(), "target" + File.separator
+ "test-classes"
-                + File.separator + "repositories" + File.separator + "local" ).toURI().toURL().toExternalForm(),
-                                              "local-repo" );
-
-        ArtifactRepository centralRepository =
-            registryManager.createRepository( new File( getBasedir(), "target" + File.separator
+ "test-classes"
-                + File.separator + "repositories" + File.separator + "central" ).toURI().toURL().toExternalForm(),
-                                              "central-repo" );
+        ArtifactRepository localRepository = registryManager.createRepository( new File(
getBasedir(),
+                                                                                        
"target" + File.separator
+                                                                                        
    + "test-classes"
+                                                                                        
    + File.separator
+                                                                                        
    + "repositories"
+                                                                                        
    + File.separator
+                                                                                        
    + "local" ).toURI().toURL().toExternalForm(),
+                                                                               "local-repo"
);
+
+        ArtifactRepository centralRepository = registryManager.createRepository( new File(
getBasedir(),
+                                                                                        
  "target" + File.separator
+                                                                                        
      + "test-classes"
+                                                                                        
      + File.separator
+                                                                                        
      + "repositories"
+                                                                                        
      + File.separator
+                                                                                        
      + "central" ).toURI().toURL().toExternalForm(),
+                                                                                 "central-repo"
);
 
         // (1) create a project from scratch
         // (2) create an archetype from the project
@@ -90,9 +90,9 @@ public class ArchetyperRoundtripTest
         // (1) create a project from scratch
 //        File sourceProject = new File( getBasedir(  ), "target/test-classes/projects/roundtrip-1-project"
);
 
-        File workingProject =
-            new File( getBasedir(), "target" + File.separator + "test-classes" + File.separator
+ "projects"
-                + File.separator + "roundtrip-1-project" );
+        File workingProject = new File( getBasedir(),
+                                        "target" + File.separator + "test-classes" + File.separator
+ "projects"
+                                            + File.separator + "roundtrip-1-project" );
         FileUtils.forceDelete( new File( workingProject, "target" ) );
 
         // (2) create an archetype from the project
@@ -101,10 +101,9 @@ public class ArchetyperRoundtripTest
         MavenProject project = projectBuilder.build( pom, localRepository, null );
 
         Properties properties = new Properties();
-        properties.setProperty("someProperty", "someValue");
+        properties.setProperty( "someProperty", "someValue" );
         ArchetypeCreationRequest acr = new ArchetypeCreationRequest().setProject( project
).
-            setLocalRepository( localRepository ).setProperties(properties)
-            .setPostPhase( "package" );
+            setLocalRepository( localRepository ).setProperties( properties ).setPostPhase(
"package" );
 
         ArchetypeCreationResult creationResult = archetype.createArchetypeFromProject( acr
);
 
@@ -120,31 +119,25 @@ public class ArchetyperRoundtripTest
         File catalogFile = new File( catalogDirectory, "archetype-catalog.xml" );
 
         // (5) install the archetype we just created
-        File generatedArchetypeDirectory =
-            new File( project.getBasedir(), "target" + File.separator + "generated-sources"
+ File.separator
-                + "archetype" );
+        File generatedArchetypeDirectory = new File( project.getBasedir(),
+                                                     "target" + File.separator + "generated-sources"
+ File.separator
+                                                         + "archetype" );
         File generatedArchetypePom = new File( generatedArchetypeDirectory, "pom.xml" );
-        MavenProject generatedArchetypeProject = projectBuilder.build( generatedArchetypePom,
-            localRepository, null );
+        MavenProject generatedArchetypeProject = projectBuilder.build( generatedArchetypePom,
localRepository, null );
 
         File archetypeDirectory =
             new File( generatedArchetypeDirectory, "src" + File.separator + "main" + File.separator
+ "resources" );
 
-        File archetypeArchive = archetype.archiveArchetype( archetypeDirectory,
-            new File( generatedArchetypeProject.getBuild().getDirectory() ),
-            generatedArchetypeProject.getBuild().getFinalName() );
-
-        String baseName = StringUtils.replace( generatedArchetypeProject.getGroupId(), ".",
File.separator )
-                + File.separator
-                + generatedArchetypeProject.getArtifactId()
-                + File.separator
-                + generatedArchetypeProject.getVersion()
-                + File.separator
-                + generatedArchetypeProject.getBuild().getFinalName();
-        File archetypeInRepository =
-            new File( centralRepository.getBasedir(), baseName + ".jar" );
-        File archetypePomInRepository =
-            new File( centralRepository.getBasedir(), baseName + ".pom" );
+        File archetypeArchive = archetype.archiveArchetype( archetypeDirectory, new File(
+            generatedArchetypeProject.getBuild().getDirectory() ),
+                                                            generatedArchetypeProject.getBuild().getFinalName()
);
+
+        String baseName =
+            StringUtils.replace( generatedArchetypeProject.getGroupId(), ".", File.separator
) + File.separator
+                + generatedArchetypeProject.getArtifactId() + File.separator + generatedArchetypeProject.getVersion()
+                + File.separator + generatedArchetypeProject.getBuild().getFinalName();
+        File archetypeInRepository = new File( centralRepository.getBasedir(), baseName +
".jar" );
+        File archetypePomInRepository = new File( centralRepository.getBasedir(), baseName
+ ".pom" );
         archetypeInRepository.getParentFile().mkdirs();
         FileUtils.copyFile( archetypeArchive, archetypeInRepository );
         FileUtils.copyFile( generatedArchetypePom, archetypePomInRepository );
@@ -155,7 +148,7 @@ public class ArchetyperRoundtripTest
         generatedArchetype.setGroupId( generatedArchetypeProject.getGroupId() );
         generatedArchetype.setArtifactId( generatedArchetypeProject.getArtifactId() );
         generatedArchetype.setVersion( generatedArchetypeProject.getVersion() );
-        generatedArchetype.setRepository( "http://localhost:18881/repo" );
+        generatedArchetype.setRepository( "http://localhost:" + port + "/repo" );
         catalog.addArchetype( generatedArchetype );
 
         ArchetypeCatalogXpp3Writer catalogWriter = new ArchetypeCatalogXpp3Writer();
@@ -164,20 +157,19 @@ public class ArchetyperRoundtripTest
         IOUtils.closeQuietly( writer );
 
         // (6) create a project form the archetype we just created
-        String outputDirectory =
-            new File( getBasedir(), "target" + File.separator + "test-classes" + File.separator
+ "projects"
-                + File.separator + "roundtrip-1-recreatedproject" ).getAbsolutePath();
+        String outputDirectory = new File( getBasedir(),
+                                           "target" + File.separator + "test-classes" + File.separator
+ "projects"
+                                               + File.separator + "roundtrip-1-recreatedproject"
).getAbsolutePath();
         FileUtils.forceDelete( outputDirectory );
 
         ArchetypeGenerationRequest agr =
-            new ArchetypeGenerationRequest().setArchetypeGroupId(
-            generatedArchetypeProject.getGroupId() ).
-            setArchetypeArtifactId( generatedArchetypeProject.getArtifactId() ).
-            setArchetypeVersion( generatedArchetypeProject.getVersion() ).
-            setGroupId( "com.mycompany" ).setArtifactId( "myapp" ).setVersion( "1.0-SNAPSHOT"
).
-            setPackage( "com.mycompany.myapp" ).setProperties(properties).
-            setOutputDirectory( outputDirectory ).setLocalRepository( localRepository ).
-            setArchetypeRepository( "http://localhost:18881/repo/" );
+            new ArchetypeGenerationRequest().setArchetypeGroupId( generatedArchetypeProject.getGroupId()
).
+                setArchetypeArtifactId( generatedArchetypeProject.getArtifactId() ).
+                setArchetypeVersion( generatedArchetypeProject.getVersion() ).
+                setGroupId( "com.mycompany" ).setArtifactId( "myapp" ).setVersion( "1.0-SNAPSHOT"
).
+                setPackage( "com.mycompany.myapp" ).setProperties( properties ).
+                setOutputDirectory( outputDirectory ).setLocalRepository( localRepository
).
+                setArchetypeRepository( "http://localhost:" + port + "/repo/" );
         ArchetypeGenerationResult generationResult = archetype.generateProjectFromArchetype(
agr );
 
         if ( generationResult.getCause() != null )
@@ -187,10 +179,9 @@ public class ArchetyperRoundtripTest
 
         //ASSERT symbol_pound replacement (archetype-180 archetype-183)
         String content = FileUtils.fileRead(
-                outputDirectory + File.separator + "myapp" + File.separator +
-                "src" + File.separator + "main" + File.separator + "java" +
-                File.separator + "com" + File.separator + "mycompany" +
-                File.separator + "myapp" + File.separator + "App.java");
+            outputDirectory + File.separator + "myapp" + File.separator + "src" + File.separator
+ "main"
+                + File.separator + "java" + File.separator + "com" + File.separator + "mycompany"
+ File.separator
+                + "myapp" + File.separator + "App.java" );
         System.err.println( "content=" + content );
         assertTrue( content.indexOf( "//A   #\\{some}" ) > 0 );
         assertTrue( content.indexOf( "//B   #{some}" ) > 0 );
@@ -212,33 +203,29 @@ public class ArchetyperRoundtripTest
         //Assert symbol_dollar archetype-138
     }
 
+    private Server server;
+
+    int port;
+
     public void setUp()
         throws Exception
     {
         super.setUp();
-        //        Start Cargo
-
-        Jetty6xEmbeddedStandaloneLocalConfiguration configuration =
-            new Jetty6xEmbeddedStandaloneLocalConfiguration( "target/repository-webapp" );
-        configuration.setProperty( ServletPropertySet.PORT, "18881" );
+        // Start Jetty
 
         System.setProperty( "org.apache.maven.archetype.repository.directory",
-            getTestPath( "target/test-classes/repositories/central" ) );
-        container = new Jetty6xEmbeddedLocalContainer( configuration );
-        container.setTimeout( 180000L );
-        container.start();
-
-        DeployableFactory factory = new DefaultDeployableFactory();
-        WAR war = (WAR) factory.createDeployable( container.getId(),
-            "target/wars/archetype-repository.war",
-            DeployableType.WAR );
-
-        war.setContext( "/repo" );
-
-        Deployer deployer = new Jetty6xEmbeddedLocalDeployer( container );
-        deployer.deploy( war,
-            new URLDeployableMonitor( new URL( "http://localhost:18881/repo/dummy" ) ) );
-        deployer.start( war );
+                            getTestPath( "target/test-classes/repositories/central" ) );
+
+        server = new Server( 0 );
+
+        WebAppContext webapp = new WebAppContext();
+        webapp.setContextPath( "/repo" );
+        webapp.setWar( "target/wars/archetype-repository.war" );
+        server.setHandler( webapp );
+
+        server.start();
+
+        port = server.getConnectors()[0].getLocalPort();
 
     }
 
@@ -246,8 +233,8 @@ public class ArchetyperRoundtripTest
         throws Exception
     {
         super.tearDown();
-        //        Stop Cargo
+        // Stop Jetty
 
-        container.stop();
+        server.stop();
     }
 }

Modified: maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/test/ArchetyperRoundtripWithProxyTest.java
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/test/ArchetyperRoundtripWithProxyTest.java?rev=1143463&r1=1143462&r2=1143463&view=diff
==============================================================================
--- maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/test/ArchetyperRoundtripWithProxyTest.java
(original)
+++ maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/test/ArchetyperRoundtripWithProxyTest.java
Wed Jul  6 15:27:35 2011
@@ -33,34 +33,32 @@ import org.apache.maven.artifact.manager
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.MavenProjectBuilder;
-import org.codehaus.cargo.container.deployable.DeployableType;
-import org.codehaus.cargo.container.deployable.WAR;
-import org.codehaus.cargo.container.deployer.Deployer;
-import org.codehaus.cargo.container.deployer.URLDeployableMonitor;
-import org.codehaus.cargo.container.jetty.Jetty6xEmbeddedLocalContainer;
-import org.codehaus.cargo.container.jetty.Jetty6xEmbeddedLocalDeployer;
-import org.codehaus.cargo.container.jetty.Jetty6xEmbeddedStandaloneLocalConfiguration;
-import org.codehaus.cargo.container.property.ServletPropertySet;
-import org.codehaus.cargo.generic.deployable.DefaultDeployableFactory;
-import org.codehaus.cargo.generic.deployable.DeployableFactory;
 import org.codehaus.plexus.PlexusTestCase;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.StringUtils;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.webapp.WebAppContext;
 
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.OutputStream;
 import java.io.Writer;
-import java.net.URL;
 import java.util.Properties;
 
-/** @author Jason van Zyl */
+/**
+ * @author Jason van Zyl
+ */
 public class ArchetyperRoundtripWithProxyTest
     extends PlexusTestCase
 {
-    Jetty6xEmbeddedLocalContainer jettyContainer;
-    Jetty6xEmbeddedLocalContainer jettyContainer2;
+    Server proxyServer;
+
+    int proxyPort;
+
+    Server server;
+
+    int port;
 
     public void testArchetyper()
         throws Exception
@@ -71,14 +69,22 @@ public class ArchetyperRoundtripWithProx
 
         MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE
);
 
-        ArtifactRepository localRepository =
-            registryManager.createRepository( new File( getBasedir(), "target" + File.separator
+ "test-classes"
-                + File.separator + "repositories" + File.separator + "local" ).toURI().toURL().toExternalForm(),
-                                              "local-repo" );
-        ArtifactRepository centralRepository =
-            registryManager.createRepository( new File( getBasedir(), "target" + File.separator
+ "test-classes"
-                + File.separator + "repositories" + File.separator + "central" ).toURI().toURL().toExternalForm(),
-                                              "central-repo" );
+        ArtifactRepository localRepository = registryManager.createRepository( new File(
getBasedir(),
+                                                                                        
"target" + File.separator
+                                                                                        
    + "test-classes"
+                                                                                        
    + File.separator
+                                                                                        
    + "repositories"
+                                                                                        
    + File.separator
+                                                                                        
    + "local" ).toURI().toURL().toExternalForm(),
+                                                                               "local-repo"
);
+        ArtifactRepository centralRepository = registryManager.createRepository( new File(
getBasedir(),
+                                                                                        
  "target" + File.separator
+                                                                                        
      + "test-classes"
+                                                                                        
      + File.separator
+                                                                                        
      + "repositories"
+                                                                                        
      + File.separator
+                                                                                        
      + "central" ).toURI().toURL().toExternalForm(),
+                                                                                 "central-repo"
);
 
         // (1) create a project from scratch
         // (2) create an archetype from the project
@@ -92,9 +98,9 @@ public class ArchetyperRoundtripWithProx
         // (1) create a project from scratch
 //        File sourceProject = new File( getBasedir(  ), "target/test-classes/projects/roundtrip-1-project"
);
 
-        File workingProject =
-            new File( getBasedir(), "target" + File.separator + "test-classes" + File.separator
+ "projects"
-                + File.separator + "roundtrip-2-project" );
+        File workingProject = new File( getBasedir(),
+                                        "target" + File.separator + "test-classes" + File.separator
+ "projects"
+                                            + File.separator + "roundtrip-2-project" );
         FileUtils.forceDelete( new File( workingProject, "target" ) );
 
         // (2) create an archetype from the project
@@ -103,8 +109,7 @@ public class ArchetyperRoundtripWithProx
         MavenProject project = projectBuilder.build( pom, localRepository, null );
 
         ArchetypeCreationRequest acr = new ArchetypeCreationRequest().setProject( project
).
-            setLocalRepository( localRepository )
-            .setPostPhase( "package" );
+            setLocalRepository( localRepository ).setPostPhase( "package" );
 
         ArchetypeCreationResult creationResult = archetype.createArchetypeFromProject( acr
);
 
@@ -118,8 +123,7 @@ public class ArchetyperRoundtripWithProx
 
         File catalogFile = new File( catalogDirectory, "archetype-catalog.xml" );
 
-        File catalogProperties = new File( catalogDirectory,
-            "archetype-catalog.properties" );
+        File catalogProperties = new File( catalogDirectory, "archetype-catalog.properties"
);
 
         catalogDirectory.mkdirs();
 
@@ -130,31 +134,25 @@ public class ArchetyperRoundtripWithProx
         p.store( os, "Generated catalog properties" );
 
         // (5) install the archetype we just created
-        File generatedArchetypeDirectory =
-            new File( project.getBasedir(), "target" + File.separator + "generated-sources"
+ File.separator
-                + "archetype" );
+        File generatedArchetypeDirectory = new File( project.getBasedir(),
+                                                     "target" + File.separator + "generated-sources"
+ File.separator
+                                                         + "archetype" );
         File generatedArchetypePom = new File( generatedArchetypeDirectory, "pom.xml" );
-        MavenProject generatedArchetypeProject = projectBuilder.build( generatedArchetypePom,
-            localRepository, null );
+        MavenProject generatedArchetypeProject = projectBuilder.build( generatedArchetypePom,
localRepository, null );
 
         File archetypeDirectory =
             new File( generatedArchetypeDirectory, "src" + File.separator + "main" + File.separator
+ "resources" );
 
-        File archetypeArchive = archetype.archiveArchetype( archetypeDirectory,
-            new File( generatedArchetypeProject.getBuild().getDirectory() ),
-            generatedArchetypeProject.getBuild().getFinalName() );
-
-        String baseName = StringUtils.replace( generatedArchetypeProject.getGroupId(), ".",
File.separator )
-                        + File.separator
-                        + generatedArchetypeProject.getArtifactId()
-                        + File.separator
-                        + generatedArchetypeProject.getVersion()
-                        + File.separator
-                        + generatedArchetypeProject.getBuild().getFinalName();
-        File archetypeInRepository =
-            new File( centralRepository.getBasedir(), baseName + ".jar" );
-        File archetypePomInRepository =
-            new File( centralRepository.getBasedir(), baseName + ".pom" );
+        File archetypeArchive = archetype.archiveArchetype( archetypeDirectory, new File(
+            generatedArchetypeProject.getBuild().getDirectory() ),
+                                                            generatedArchetypeProject.getBuild().getFinalName()
);
+
+        String baseName =
+            StringUtils.replace( generatedArchetypeProject.getGroupId(), ".", File.separator
) + File.separator
+                + generatedArchetypeProject.getArtifactId() + File.separator + generatedArchetypeProject.getVersion()
+                + File.separator + generatedArchetypeProject.getBuild().getFinalName();
+        File archetypeInRepository = new File( centralRepository.getBasedir(), baseName +
".jar" );
+        File archetypePomInRepository = new File( centralRepository.getBasedir(), baseName
+ ".pom" );
         archetypeInRepository.getParentFile().mkdirs();
         FileUtils.copyFile( archetypeArchive, archetypeInRepository );
         FileUtils.copyFile( generatedArchetypePom, archetypePomInRepository );
@@ -165,7 +163,7 @@ public class ArchetyperRoundtripWithProx
         generatedArchetype.setGroupId( generatedArchetypeProject.getGroupId() );
         generatedArchetype.setArtifactId( generatedArchetypeProject.getArtifactId() );
         generatedArchetype.setVersion( generatedArchetypeProject.getVersion() );
-        generatedArchetype.setRepository( "http://127.0.0.2:18881/" );
+        generatedArchetype.setRepository( "http://127.0.0.2:" + port + "/" );
         catalog.addArchetype( generatedArchetype );
 
         ArchetypeCatalogXpp3Writer catalogWriter = new ArchetypeCatalogXpp3Writer();
@@ -174,22 +172,21 @@ public class ArchetyperRoundtripWithProx
         IOUtils.closeQuietly( writer );
 
         // (6) create a project form the archetype we just created
-        String outputDirectory =
-            new File( getBasedir(), "target" + File.separator + "test-classes" + File.separator
+ "projects"
-                + File.separator + "roundtrip-2-recreatedproject" ).getAbsolutePath();
+        String outputDirectory = new File( getBasedir(),
+                                           "target" + File.separator + "test-classes" + File.separator
+ "projects"
+                                               + File.separator + "roundtrip-2-recreatedproject"
).getAbsolutePath();
         FileUtils.forceDelete( outputDirectory );
 
         WagonManager manager = (WagonManager) lookup( WagonManager.class.getName() );
-        manager.addProxy( "http", "localhost", 18882, null, null, null );
+        manager.addProxy( "http", "localhost", proxyPort, null, null, null );
 
         ArchetypeGenerationRequest agr =
-            new ArchetypeGenerationRequest().setArchetypeGroupId(
-            generatedArchetypeProject.getGroupId() ).
-            setArchetypeArtifactId( generatedArchetypeProject.getArtifactId() ).
-            setArchetypeVersion( generatedArchetypeProject.getVersion() ).
-            setGroupId( "com.mycompany" ).setArtifactId( "myapp" ).setVersion( "1.0-SNAPSHOT"
).
-            setPackage( "com.mycompany.myapp" ).setOutputDirectory( outputDirectory ).
-            setLocalRepository( localRepository ).setArchetypeRepository( "http://127.0.0.2:18881/"
);
+            new ArchetypeGenerationRequest().setArchetypeGroupId( generatedArchetypeProject.getGroupId()
).
+                setArchetypeArtifactId( generatedArchetypeProject.getArtifactId() ).
+                setArchetypeVersion( generatedArchetypeProject.getVersion() ).
+                setGroupId( "com.mycompany" ).setArtifactId( "myapp" ).setVersion( "1.0-SNAPSHOT"
).
+                setPackage( "com.mycompany.myapp" ).setOutputDirectory( outputDirectory ).
+                setLocalRepository( localRepository ).setArchetypeRepository( "http://127.0.0.2:"
+ port + "/" );
         ArchetypeGenerationResult generationResult = archetype.generateProjectFromArchetype(
agr );
 
         if ( generationResult.getCause() != null )
@@ -203,52 +200,32 @@ public class ArchetyperRoundtripWithProx
         throws Exception
     {
         super.setUp();
-        //        Start Cargo
-
-        Jetty6xEmbeddedStandaloneLocalConfiguration configuration =
-            new Jetty6xEmbeddedStandaloneLocalConfiguration( "target/proxy-webapp" );
-        configuration.setProperty( ServletPropertySet.PORT, "18882" );
+        // Start Proxy Jetty
 
         System.setProperty( "org.apache.maven.archetype.repository.directory",
-            getTestPath( "target/test-classes/repositories/central" ) );
-        jettyContainer = new Jetty6xEmbeddedLocalContainer( configuration );
-        jettyContainer.setTimeout( 180000L );
-        jettyContainer.start();
-
-        DeployableFactory factory = new DefaultDeployableFactory();
-        WAR war = (WAR) factory.createDeployable( jettyContainer.getId(),
-            "target/wars/archetype-proxy.war",
-            DeployableType.WAR );
-
-        war.setContext( "/" );
-
-        Deployer deployer = new Jetty6xEmbeddedLocalDeployer( jettyContainer  );
-        deployer.deploy( war,
-            new URLDeployableMonitor( new URL( "http://localhost:18882/dummy" ) ) );
-        deployer.start( war );
-
-
-        Jetty6xEmbeddedStandaloneLocalConfiguration configuration2 =
-            new Jetty6xEmbeddedStandaloneLocalConfiguration( "target/repository-webapp" );
-        configuration2.setProperty( ServletPropertySet.PORT, "18881" );
+                            getTestPath( "target/test-classes/repositories/central" ) );
 
-        System.setProperty( "org.apache.maven.archetype.repository.directory",
-            getTestPath( "target/test-classes/repositories/central" ) );
-        jettyContainer2 = new Jetty6xEmbeddedLocalContainer( configuration2 );
-        jettyContainer2.setTimeout( 180000L );
-        jettyContainer2.start();
-
-        DeployableFactory factory2 = new DefaultDeployableFactory();
-        WAR war2 = (WAR) factory2.createDeployable( jettyContainer2.getId(),
-            "target/wars/archetype-repository.war",
-            DeployableType.WAR );
-
-        war2.setContext( "/" );
-
-        Deployer deployer2 = new Jetty6xEmbeddedLocalDeployer( jettyContainer2 );
-        deployer2.deploy( war2,
-            new URLDeployableMonitor( new URL( "http://localhost:18881/repo/dummy" ) ) );
-        deployer2.start( war );
+        proxyServer = new Server( 0 );
+
+        WebAppContext webappProxy = new WebAppContext();
+        webappProxy.setContextPath( "/" );
+        webappProxy.setWar( "target/wars/archetype-proxy.war" );
+        proxyServer.setHandler( webappProxy );
+
+        proxyServer.start();
+
+        proxyPort = proxyServer.getConnectors()[0].getLocalPort();
+
+        server = new Server( 0 );
+
+        WebAppContext webapp = new WebAppContext();
+        webapp.setContextPath( "/repo" );
+        webapp.setWar( "target/wars/archetype-repository.war" );
+        server.setHandler( webapp );
+
+        server.start();
+
+        port = server.getConnectors()[0].getLocalPort();
 
     }
 
@@ -256,9 +233,9 @@ public class ArchetyperRoundtripWithProx
         throws Exception
     {
         super.tearDown();
-        //        Stop Cargo
+        // Stop Jettys
 
-        jettyContainer.stop();
-        jettyContainer2.stop();
+        proxyServer.stop();
+        server.stop();
     }
 }

Modified: maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/test/RoundtripMultiModuleTest.java
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/test/RoundtripMultiModuleTest.java?rev=1143463&r1=1143462&r2=1143463&view=diff
==============================================================================
--- maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/test/RoundtripMultiModuleTest.java
(original)
+++ maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/test/RoundtripMultiModuleTest.java
Wed Jul  6 15:27:35 2011
@@ -33,35 +33,26 @@ import org.apache.maven.archetype.common
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.MavenProjectBuilder;
-import org.codehaus.cargo.container.deployable.DeployableType;
-import org.codehaus.cargo.container.deployable.WAR;
-import org.codehaus.cargo.container.deployer.Deployer;
-import org.codehaus.cargo.container.deployer.URLDeployableMonitor;
-import org.codehaus.cargo.container.jetty.Jetty6xEmbeddedLocalContainer;
-import org.codehaus.cargo.container.jetty.Jetty6xEmbeddedLocalDeployer;
-import org.codehaus.cargo.container.jetty.Jetty6xEmbeddedStandaloneLocalConfiguration;
-import org.codehaus.cargo.container.property.ServletPropertySet;
-import org.codehaus.cargo.generic.deployable.DefaultDeployableFactory;
-import org.codehaus.cargo.generic.deployable.DeployableFactory;
 import org.codehaus.plexus.PlexusTestCase;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.StringUtils;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.webapp.WebAppContext;
 
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.OutputStream;
 import java.io.Writer;
-import java.net.URL;
 import java.util.Iterator;
 import java.util.Properties;
 
-/** @author Jason van Zyl */
+/**
+ * @author Jason van Zyl
+ */
 public class RoundtripMultiModuleTest
     extends PlexusTestCase
 {
-    private Jetty6xEmbeddedLocalContainer jettyContainer;
-
     public void testArchetyper()
         throws Exception
     {
@@ -73,14 +64,22 @@ public class RoundtripMultiModuleTest
         MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE
);
 
         ArtifactRepository localRepository = registryManager.createRepository( new File(
getBasedir(),
-            "target" + File.separator + "test-classes" + File.separator + "repositories"
+ File.separator + "local" )
-            .toURI().toURL().toExternalForm(),
-            "local-repo" );
+                                                                                        
"target" + File.separator
+                                                                                        
    + "test-classes"
+                                                                                        
    + File.separator
+                                                                                        
    + "repositories"
+                                                                                        
    + File.separator
+                                                                                        
    + "local" ).toURI().toURL().toExternalForm(),
+                                                                               "local-repo"
);
 
         ArtifactRepository centralRepository = registryManager.createRepository( new File(
getBasedir(),
-            "target" + File.separator + "test-classes" + File.separator + "repositories"
+ File.separator + "central" )
-            .toURI().toURL().toExternalForm(),
-            "central-repo" );
+                                                                                        
  "target" + File.separator
+                                                                                        
      + "test-classes"
+                                                                                        
      + File.separator
+                                                                                        
      + "repositories"
+                                                                                        
      + File.separator
+                                                                                        
      + "central" ).toURI().toURL().toExternalForm(),
+                                                                                 "central-repo"
);
 
         // (1) create a project from scratch
         // (2) create an archetype from the project
@@ -95,7 +94,8 @@ public class RoundtripMultiModuleTest
 //        File sourceProject = new File( getBasedir(  ), "target/test-classes/projects/roundtrip-1-project"
);
 
         File workingProject = new File( getBasedir(),
-            "target" + File.separator + "test-classes" + File.separator + "projects" + File.separator
+ "roundtrip-multi" );
+                                        "target" + File.separator + "test-classes" + File.separator
+ "projects"
+                                            + File.separator + "roundtrip-multi" );
         FileUtils.forceDelete( new File( workingProject, "target" ) );
 
         // (2) create an archetype from the project
@@ -103,12 +103,10 @@ public class RoundtripMultiModuleTest
 
         MavenProject project = projectBuilder.build( pom, localRepository, null );
 
-        ArchetypeCreationRequest acr = new ArchetypeCreationRequest()
-            .setProject( project )
-            .setLocalRepository( localRepository )
-            .setFiltereds(Constants.DEFAULT_FILTERED_EXTENSIONS)
-            .setLanguages(Constants.DEFAULT_LANGUAGES)
-            .setPostPhase( "package" );
+        ArchetypeCreationRequest acr =
+            new ArchetypeCreationRequest().setProject( project ).setLocalRepository( localRepository
).setFiltereds(
+                Constants.DEFAULT_FILTERED_EXTENSIONS ).setLanguages( Constants.DEFAULT_LANGUAGES
).setPostPhase(
+                "package" );
 
         ArchetypeCreationResult creationResult = archetype.createArchetypeFromProject( acr
);
 
@@ -137,30 +135,25 @@ public class RoundtripMultiModuleTest
         p.store( os, "Generated catalog properties" );
 
         // (5) install the archetype we just created
-        File generatedArchetypeDirectory =
-            new File( project.getBasedir(), "target" + File.separator + "generated-sources"
+ File.separator
-                + "archetype" );
+        File generatedArchetypeDirectory = new File( project.getBasedir(),
+                                                     "target" + File.separator + "generated-sources"
+ File.separator
+                                                         + "archetype" );
         File generatedArchetypePom = new File( generatedArchetypeDirectory, "pom.xml" );
         MavenProject generatedArchetypeProject = projectBuilder.build( generatedArchetypePom,
localRepository, null );
 
         File archetypeDirectory =
             new File( generatedArchetypeDirectory, "src" + File.separator + "main" + File.separator
+ "resources" );
 
-        File archetypeArchive = archetype.archiveArchetype( archetypeDirectory,
-            new File( generatedArchetypeProject.getBuild().getDirectory() ),
-            generatedArchetypeProject.getBuild().getFinalName() );
-
-        String baseName = StringUtils.replace( generatedArchetypeProject.getGroupId(), ".",
File.separator )
-                        + File.separator
-                        + generatedArchetypeProject.getArtifactId()
-                        + File.separator
-                        + generatedArchetypeProject.getVersion()
-                        + File.separator
-                        + generatedArchetypeProject.getBuild().getFinalName();
-        File archetypeInRepository =
-            new File( centralRepository.getBasedir(), baseName + ".jar" );
-        File archetypePomInRepository =
-            new File( centralRepository.getBasedir(), baseName + ".pom" );
+        File archetypeArchive = archetype.archiveArchetype( archetypeDirectory, new File(
+            generatedArchetypeProject.getBuild().getDirectory() ),
+                                                            generatedArchetypeProject.getBuild().getFinalName()
);
+
+        String baseName =
+            StringUtils.replace( generatedArchetypeProject.getGroupId(), ".", File.separator
) + File.separator
+                + generatedArchetypeProject.getArtifactId() + File.separator + generatedArchetypeProject.getVersion()
+                + File.separator + generatedArchetypeProject.getBuild().getFinalName();
+        File archetypeInRepository = new File( centralRepository.getBasedir(), baseName +
".jar" );
+        File archetypePomInRepository = new File( centralRepository.getBasedir(), baseName
+ ".pom" );
         archetypeInRepository.getParentFile().mkdirs();
         FileUtils.copyFile( archetypeArchive, archetypeInRepository );
         FileUtils.copyFile( generatedArchetypePom, archetypePomInRepository );
@@ -171,7 +164,7 @@ public class RoundtripMultiModuleTest
         generatedArchetype.setGroupId( generatedArchetypeProject.getGroupId() );
         generatedArchetype.setArtifactId( generatedArchetypeProject.getArtifactId() );
         generatedArchetype.setVersion( generatedArchetypeProject.getVersion() );
-        generatedArchetype.setRepository( "http://localhost:18881/repo" );
+        generatedArchetype.setRepository( "http://localhost:" + port + "/repo" );
         catalog.addArchetype( generatedArchetype );
 
         ArchetypeCatalogXpp3Writer catalogWriter = new ArchetypeCatalogXpp3Writer();
@@ -180,23 +173,18 @@ public class RoundtripMultiModuleTest
         IOUtils.closeQuietly( writer );
 
         // (6) create a project form the archetype we just created
-        String outputDirectory =
-            new File( getBasedir(), "target" + File.separator + "test-classes" + File.separator
+ "projects"
-                + File.separator + "roundtrip-multi-recreated" ).getAbsolutePath();
-        FileUtils.forceDelete(outputDirectory);
-
-        ArchetypeGenerationRequest agr =
-            new ArchetypeGenerationRequest()
-            .setArchetypeGroupId( generatedArchetypeProject.getGroupId() )
-            .setArchetypeArtifactId( generatedArchetypeProject.getArtifactId() )
-            .setArchetypeVersion( generatedArchetypeProject.getVersion() )
-            .setGroupId( "com.mycompany" )
-            .setArtifactId( "myapp" )
-            .setVersion( "1.0-SNAPSHOT" )
-            .setPackage( "com.mycompany.myapp" )
-            .setOutputDirectory( outputDirectory )
-            .setLocalRepository( localRepository )
-            .setArchetypeRepository( "http://localhost:18881/repo/" );
+        String outputDirectory = new File( getBasedir(),
+                                           "target" + File.separator + "test-classes" + File.separator
+ "projects"
+                                               + File.separator + "roundtrip-multi-recreated"
).getAbsolutePath();
+        FileUtils.forceDelete( outputDirectory );
+
+        ArchetypeGenerationRequest agr = new ArchetypeGenerationRequest().setArchetypeGroupId(
+            generatedArchetypeProject.getGroupId() ).setArchetypeArtifactId(
+            generatedArchetypeProject.getArtifactId() ).setArchetypeVersion(
+            generatedArchetypeProject.getVersion() ).setGroupId( "com.mycompany" ).setArtifactId(
"myapp" ).setVersion(
+            "1.0-SNAPSHOT" ).setPackage( "com.mycompany.myapp" ).setOutputDirectory(
+            outputDirectory ).setLocalRepository( localRepository ).setArchetypeRepository(
+            "http://localhost:" + port + "/repo/" );
         ArchetypeGenerationResult generationResult = archetype.generateProjectFromArchetype(
agr );
 
         if ( generationResult.getCause() != null )
@@ -211,44 +199,44 @@ public class RoundtripMultiModuleTest
         assertTrue( new File( myapp + "myapp-model", ".classpath" ).exists() );
         assertTrue( new File( myapp + File.separator + "myapp-stores" + File.separator +
"myapp-store-memory",
                               ".classpath" ).exists() );
-        assertTrue( new File( myapp + "myapp-stores" + File.separator + "myapp-store-xstream",
".classpath" ).exists() );
+        assertTrue(
+            new File( myapp + "myapp-stores" + File.separator + "myapp-store-xstream", ".classpath"
).exists() );
 
         assertTrue( new File( myapp + "myapp-api", ".checkstyle" ).exists() );
         assertTrue( new File( myapp + "myapp-cli", ".checkstyle" ).exists() );
         assertTrue( new File( myapp + "myapp-core", ".checkstyle" ).exists() );
         assertTrue( new File( myapp + "myapp-model", ".checkstyle" ).exists() );
-        assertTrue( new File( myapp + "myapp-stores" + File.separator + "myapp-store-memory",
".checkstyle" ).exists() );
-        assertTrue( new File( myapp + "myapp-stores" + File.separator + "myapp-store-xstream",
".checkstyle" ).exists() );
+        assertTrue(
+            new File( myapp + "myapp-stores" + File.separator + "myapp-store-memory", ".checkstyle"
).exists() );
+        assertTrue(
+            new File( myapp + "myapp-stores" + File.separator + "myapp-store-xstream", ".checkstyle"
).exists() );
 
     }
 
+    private Server server;
+
+    int port;
+
     public void setUp()
         throws Exception
     {
         super.setUp();
-        //        Start Cargo
-
-        Jetty6xEmbeddedStandaloneLocalConfiguration configuration =
-            new Jetty6xEmbeddedStandaloneLocalConfiguration( "target/repository-webapp" );
-        configuration.setProperty( ServletPropertySet.PORT, "18881" );
+        // Start Jetty
 
         System.setProperty( "org.apache.maven.archetype.repository.directory",
-            getTestPath( "target/test-classes/repositories/central" ) );
-        jettyContainer = new Jetty6xEmbeddedLocalContainer( configuration );
-        jettyContainer.setTimeout( 180000L );
-        jettyContainer.start();
-
-        DeployableFactory factory = new DefaultDeployableFactory();
-        WAR war = (WAR) factory.createDeployable( jettyContainer.getId(),
-            "target/wars/archetype-repository.war",
-            DeployableType.WAR );
-
-        war.setContext( "/repo" );
-
-        Deployer deployer = new Jetty6xEmbeddedLocalDeployer( jettyContainer );
-        deployer.deploy( war,
-            new URLDeployableMonitor( new URL( "http://localhost:18881/repo/dummy" ) ) );
-        deployer.start( war );
+                            getTestPath( "target/test-classes/repositories/central" ) );
+
+        server = new Server( 0 );
+
+        WebAppContext webapp = new WebAppContext();
+        webapp.setContextPath( "/repo" );
+        webapp.setWar( "target/wars/archetype-repository.war" );
+        server.setHandler( webapp );
+
+        server.start();
+
+        port = server.getConnectors()[0].getLocalPort();
+
 
     }
 
@@ -256,9 +244,9 @@ public class RoundtripMultiModuleTest
         throws Exception
     {
         super.tearDown();
-        //        Stop Cargo
+        // Stop Jetty
 
-        jettyContainer.stop();
+        server.stop();
     }
 
     private void assertArchetypeCreated( File workingProject )
@@ -296,11 +284,11 @@ public class RoundtripMultiModuleTest
         assertExistDirectory( stores );
         assertExistFile( FileUtils.resolveFile( stores, "pom.xml" ) );
         assertExistDirectory( FileUtils.resolveFile( stores, "__rootArtifactId__-store-memory"
) );
-        assertExistFile( FileUtils.resolveFile( FileUtils.resolveFile( stores, "__rootArtifactId__-store-memory"
),
-                                                "pom.xml" ) );
+        assertExistFile(
+            FileUtils.resolveFile( FileUtils.resolveFile( stores, "__rootArtifactId__-store-memory"
), "pom.xml" ) );
         assertExistDirectory( FileUtils.resolveFile( stores, "__rootArtifactId__-store-xstream"
) );
-        assertExistFile( FileUtils.resolveFile( FileUtils.resolveFile( stores, "__rootArtifactId__-store-xstream"
),
-                                                "pom.xml" ) );
+        assertExistFile(
+            FileUtils.resolveFile( FileUtils.resolveFile( stores, "__rootArtifactId__-store-xstream"
), "pom.xml" ) );
         assertExistFile( FileUtils.resolveFile( archetypeResourcesDirectory, "pom.xml" )
);
 
         assertExistDirectory( archetypeMetadataDirectory );



Mime
View raw message