continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmcconn...@apache.org
Subject svn commit: r475457 - in /maven/continuum/trunk/continuum-core/src: main/java/org/apache/maven/continuum/core/action/ main/java/org/apache/maven/continuum/execution/maven/m2/ main/java/org/apache/maven/continuum/project/builder/maven/ test/java/org/apa...
Date Wed, 15 Nov 2006 22:08:23 GMT
Author: jmcconnell
Date: Wed Nov 15 14:08:22 2006
New Revision: 475457

URL: http://svn.apache.org/viewvc?view=rev&rev=475457
Log:
working through a new strategy of loading up projects that require authentication, since the
CreateProjectsFromMetadata class is where we deal with authentication and the mungedUrl https
format I figured this is also the place to pull information from the settings.xml file should
it exist and attempt to use that as well.  This moves around something that I patched in last
week from john didion that didn't sit well with me after looking at it a day or two, so I
removed that and have it worked out this way now.  I also added in the MavenTwoContinuumProjectBuilder
that if we get a scm username/password from the calling code (create action here) then we
will persist that into the database for each project.  I'll add that to the MavenOne builder
once I have all this sorted out, but I think the builders and executors could stand a bit
of flow refactoring, but there is a jira ticket for that, to move them together under the
same package space.

Modified:
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataAction.java
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m2/DefaultMavenBuilderHelper.java
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilder.java
    maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java

Modified: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataAction.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataAction.java?view=diff&rev=475457&r1=475456&r2=475457
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataAction.java
(original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataAction.java
Wed Nov 15 14:08:22 2006
@@ -17,18 +17,33 @@
  */
 
 import org.apache.maven.continuum.ContinuumException;
+import org.apache.maven.continuum.execution.maven.m2.SettingsConfigurationException;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuilder;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuilderException;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
 import org.apache.maven.continuum.project.builder.manager.ContinuumProjectBuilderManager;
 import org.apache.maven.continuum.project.builder.manager.ContinuumProjectBuilderManagerException;
+import org.apache.maven.settings.MavenSettingsBuilder;
+import org.apache.maven.settings.Server;
+import org.apache.maven.settings.Settings;
 import org.codehaus.plexus.formica.util.MungedHttpsURL;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
+import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Map;
 
 /**
+ * Resolve the project url being passed in and gather authentication information
+ * if the url is so configured, then create the projects
+ *
+ * Supports:
+ *
+ * - standard maven-scm url
+ * - MungedUrl https://username:password@host
+ * - maven settings based, server = host and scm info set to username and password
+ *
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
  * @version $Id$
  *
@@ -43,6 +58,13 @@
      * @plexus.requirement
      */
     private ContinuumProjectBuilderManager projectBuilderManager;
+    
+    /**
+     * @plexus.requirement
+     */
+    private MavenSettingsBuilder mavenSettingsBuilder;
+
+    private Settings settings;
 
     public static final String KEY_URL = "url";
 
@@ -50,52 +72,73 @@
 
     public static final String KEY_PROJECT_BUILDING_RESULT = "projectBuildingResult";
 
-    public void setProjectBuilderManager( ContinuumProjectBuilderManager projectBuilderManager
)
-    {
-        this.projectBuilderManager = projectBuilderManager;
-    }
-
-    public ContinuumProjectBuilderManager getProjectBuilderManager()
-    {
-        return projectBuilderManager;
-    }
-
     public void execute( Map context )
         throws ContinuumException, ContinuumProjectBuilderManagerException, ContinuumProjectBuilderException
     {
         String projectBuilderId = getString( context, KEY_PROJECT_BUILDER_ID );
 
-        String u = getString( context, KEY_URL );
+        String curl = getString( context, KEY_URL );
 
         URL url;
 
-        ContinuumProjectBuilder projectBuilder = getProjectBuilderManager().getProjectBuilder(
projectBuilderId );
+        ContinuumProjectBuilder projectBuilder = projectBuilderManager.getProjectBuilder(
projectBuilderId );
 
         ContinuumProjectBuildingResult result;
 
         try
         {
-            if ( !u.startsWith( "http" ) )
+            if ( !curl.startsWith( "http" ) )
             {
-                url = new URL( u );
+                url = new URL( curl );
 
                 result = projectBuilder.buildProjectsFromMetadata( url, null, null );
             }
             else
             {
-                MungedHttpsURL mungedURL = new MungedHttpsURL( u );
+                url = new URL ( curl );
+                String username = null;
+                String password = null;
+
+                try
+                {
+                    settings = getSettings();
+
+                    if ( settings != null && settings.getServer( url.getHost() )
!= null )
+                    {
+                        Server server = settings.getServer( url.getHost() );
+
+                        username = server.getUsername();
+                        password = server.getPassword();
+                    }
+                }
+                catch ( SettingsConfigurationException se )
+                {
+                    getLogger().warn( "problem with settings file, disabling scm resolution
of username and password" );
+                }
+
+                MungedHttpsURL mungedURL;
+                
+                if ( username == null )
+                {
+                    mungedURL = new MungedHttpsURL( curl );
+                    username = mungedURL.getUsername();
+                    password = mungedURL.getPassword();
+                }
+                else
+                {
+                   mungedURL = new MungedHttpsURL( curl, username, password );
+                }
 
                 if ( mungedURL.isValid() )
                 {
                     url = mungedURL.getURL();
 
-                    result = projectBuilder.buildProjectsFromMetadata( url, mungedURL.getUsername(),
mungedURL
-                        .getPassword() );
+                    result = projectBuilder.buildProjectsFromMetadata( url, username, password
);
                 }
                 else
                 {
                     result = new ContinuumProjectBuildingResult();
-                    getLogger().info( "Malformed URL (MungedHttpsURL is not valid): " + u
);
+                    getLogger().info( "Malformed URL (MungedHttpsURL is not valid): " + curl
);
                     result.addError( ContinuumProjectBuildingResult.ERROR_MALFORMED_URL );
                 }
             }
@@ -103,11 +146,51 @@
         }
         catch ( MalformedURLException e )
         {
-            getLogger().info( "Malformed URL: " + u, e );
+            getLogger().info( "Malformed URL: " + curl, e );
             result = new ContinuumProjectBuildingResult();
             result.addError( ContinuumProjectBuildingResult.ERROR_MALFORMED_URL );
         }
 
+
         context.put( KEY_PROJECT_BUILDING_RESULT, result );
+    }
+
+    private Settings getSettings()
+        throws SettingsConfigurationException
+    {
+        try
+        {
+            return mavenSettingsBuilder.buildSettings();
+        }
+        catch ( IOException e )
+        {
+            throw new SettingsConfigurationException( "Error reading settings file", e );
+        }
+        catch ( XmlPullParserException e )
+        {
+            throw new SettingsConfigurationException( e.getMessage(), e.getDetail(), e.getLineNumber(),
+                                                      e.getColumnNumber() );
+        }
+    }
+
+
+    public ContinuumProjectBuilderManager getProjectBuilderManager()
+    {
+        return projectBuilderManager;
+    }
+
+    public void setProjectBuilderManager( ContinuumProjectBuilderManager projectBuilderManager
)
+    {
+        this.projectBuilderManager = projectBuilderManager;
+    }
+
+    public MavenSettingsBuilder getMavenSettingsBuilder()
+    {
+        return mavenSettingsBuilder;
+    }
+
+    public void setMavenSettingsBuilder( MavenSettingsBuilder mavenSettingsBuilder )
+    {
+        this.mavenSettingsBuilder = mavenSettingsBuilder;
     }
 }

Modified: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m2/DefaultMavenBuilderHelper.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m2/DefaultMavenBuilderHelper.java?view=diff&rev=475457&r1=475456&r2=475457
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m2/DefaultMavenBuilderHelper.java
(original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m2/DefaultMavenBuilderHelper.java
Wed Nov 15 14:08:22 2006
@@ -40,17 +40,13 @@
 import org.apache.maven.project.MavenProjectBuilder;
 import org.apache.maven.project.ProjectBuildingException;
 import org.apache.maven.project.validation.ModelValidationResult;
+import org.apache.maven.scm.manager.ScmManager;
 import org.apache.maven.settings.MavenSettingsBuilder;
 import org.apache.maven.settings.Mirror;
 import org.apache.maven.settings.Proxy;
 import org.apache.maven.settings.Server;
 import org.apache.maven.settings.Settings;
 import org.apache.maven.settings.io.xpp3.SettingsXpp3Writer;
-import org.apache.maven.scm.repository.ScmRepository;
-import org.apache.maven.scm.repository.ScmRepositoryException;
-import org.apache.maven.scm.provider.ScmProviderRepositoryWithHost;
-import org.apache.maven.scm.manager.NoSuchScmProviderException;
-import org.apache.maven.scm.manager.ScmManager;
 import org.codehaus.plexus.PlexusConstants;
 import org.codehaus.plexus.PlexusContainer;
 import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
@@ -164,46 +160,6 @@
             continuumProject.setScmTag( mavenProject.getScm().getTag() );
         }
 
-        try
-        {
-            // this has the bonus of validating the scm url
-            ScmRepository repos = getScmRepository( scmUrl );
-
-            if ( repos.getProviderRepository() instanceof ScmProviderRepositoryWithHost )
-            {
-                String host = ( (ScmProviderRepositoryWithHost) repos.getProviderRepository()
).getHost();
-
-                if ( settings != null && settings.getServer( host ) != null )
-                {
-                    Server server = settings.getServer( host );
-
-                    if ( StringUtils.isEmpty( continuumProject.getScmUsername() ) &&
-                        !StringUtils.isEmpty( server.getUsername() ) )
-                    {
-
-                        continuumProject.setScmUsername( server.getUsername() );
-
-                        if ( !StringUtils.isEmpty( server.getPassword() ) )
-                        {
-                            continuumProject.setScmPassword( server.getPassword() );
-                        }
-                        else
-                        {
-                            continuumProject.setScmPassword( "" );
-                        }
-                    }
-                }
-            }
-        }
-        catch ( ScmRepositoryException e )
-        {
-            throw new MavenBuilderHelperException( "Malformed SCM URL " + scmUrl );
-        }
-        catch ( NoSuchScmProviderException e )
-        {
-            throw new MavenBuilderHelperException( "Malformed SCM URL " + scmUrl );
-        }
-
         continuumProject.setVersion( getVersion( mavenProject ) );
 
         // ----------------------------------------------------------------------
@@ -513,18 +469,6 @@
         }
 
         return name;
-    }
-
-
-    private ScmRepository getScmRepository( String scmUrl )
-        throws ScmRepositoryException, NoSuchScmProviderException
-    {
-        ScmRepository repos = scmManager.makeScmRepository( scmUrl );
-        if ( repos == null )
-        {
-            throw new ScmRepositoryException( "Unable to make repository for url " + scmUrl
);
-        }
-        return repos;
     }
 
     private String getScmUrl( MavenProject project )

Modified: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilder.java?view=diff&rev=475457&r1=475456&r2=475457
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilder.java
(original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilder.java
Wed Nov 15 14:08:22 2006
@@ -189,6 +189,20 @@
         {
             Project continuumProject = new Project();
 
+            /*
+            We are interested in having the scm username and password being passed into this
method be taken into
+            account during project mapping so make sure we set it to the continuum project
instance.
+             */
+            if ( username != null && StringUtils.isNotEmpty( username ) )
+            {
+                continuumProject.setScmUsername( username );
+                
+                if ( password != null && StringUtils.isNotEmpty( password ) )
+                {
+                    continuumProject.setScmPassword( password );
+                }
+            }
+
             try
             {
                 builderHelper.mapMavenProjectToContinuumProject( result, mavenProject, continuumProject,
groupPom );

Modified: maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java?view=diff&rev=475457&r1=475456&r2=475457
==============================================================================
--- maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java
(original)
+++ maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java
Wed Nov 15 14:08:22 2006
@@ -16,24 +16,26 @@
  * limitations under the License.
  */
 
-import java.util.HashMap;
-import java.util.Map;
-
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuilder;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
 import org.apache.maven.continuum.project.builder.manager.ContinuumProjectBuilderManager;
+import org.apache.maven.settings.MavenSettingsBuilder;
+import org.apache.maven.settings.Settings;
 import org.codehaus.plexus.logging.Logger;
 import org.codehaus.plexus.logging.console.ConsoleLogger;
 import org.jmock.Mock;
 import org.jmock.MockObjectTestCase;
 
+import java.util.HashMap;
+import java.util.Map;
+
 public class CreateProjectsFromMetadataTest
     extends MockObjectTestCase
 {
 
     private CreateProjectsFromMetadataAction action;
 
-    private Mock projectBuilderManagerMock, projectBuilder;
+    private Mock projectBuilderManagerMock, projectBuilder, mavenSettingsBuilderMock;
 
     protected void setUp()
         throws Exception
@@ -41,14 +43,20 @@
         action = new CreateProjectsFromMetadataAction();
         action.enableLogging( new ConsoleLogger( Logger.LEVEL_DEBUG, "" ) );
         projectBuilderManagerMock = mock( ContinuumProjectBuilderManager.class );
+        mavenSettingsBuilderMock = mock ( MavenSettingsBuilder.class );
         action.setProjectBuilderManager( (ContinuumProjectBuilderManager) projectBuilderManagerMock.proxy()
);
+        action.setMavenSettingsBuilder( (MavenSettingsBuilder) mavenSettingsBuilderMock.proxy()
);
 
         projectBuilder = mock( ContinuumProjectBuilder.class );
 
+
         projectBuilderManagerMock.expects( once() ).method( "getProjectBuilder" )
             .will(returnValue( projectBuilder.proxy() ) );
         projectBuilder.expects( once() ).method( "buildProjectsFromMetadata" )
             .will( returnValue( new ContinuumProjectBuildingResult() ) );
+
+        mavenSettingsBuilderMock.expects( once() ).method( "buildSettings" )
+            .will(returnValue( new Settings() ) );
     }
 
     public void testExecute()



Mime
View raw message