continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmcconn...@apache.org
Subject svn commit: r470896 - in /maven/continuum/trunk/continuum-core/src/main: java/org/apache/maven/continuum/execution/maven/m2/ java/org/apache/maven/continuum/project/builder/maven/ resources/META-INF/plexus/
Date Fri, 03 Nov 2006 16:45:50 GMT
Author: jmcconnell
Date: Fri Nov  3 08:45:49 2006
New Revision: 470896

URL: http://svn.apache.org/viewvc?view=rev&rev=470896
Log:
continuum-992 John Didion submitted a patch to continuum-core that adds the ability for the
projects during the mapping process to make sure of the settings.xml file server declaration
for retrieving the scm username and password, which I think is a pretty good way to go about
this.  this was handy since I was about to dig in and look at doing this same thing but putting
the username and password that are passed in that scm down into this method and using, which
might still happen but this addresses the immediate issue of scm user/password being available
there.  I'll look at maybe applying this up at that top screen as well as an allowable method
of attaching scm info to the pom that might be added to the Add m2 project link.

Modified:
    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/execution/maven/m2/MavenBuilderHelper.java
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilder.java
    maven/continuum/trunk/continuum-core/src/main/resources/META-INF/plexus/components.xml

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=470896&r1=470895&r2=470896
==============================================================================
--- 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
Fri Nov  3 08:45:49 2006
@@ -46,6 +46,11 @@
 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;
@@ -101,6 +106,11 @@
      */
     private String localRepository;
 
+    /**
+     * @plexus.requirement
+     */
+    private ScmManager scmManager;
+
     private PlexusContainer container;
 
     private Settings settings;
@@ -128,6 +138,7 @@
     }
     
     public void mapMavenProjectToContinuumProject( ContinuumProjectBuildingResult result,
MavenProject mavenProject, Project continuumProject, boolean groupPom )
+        throws MavenBuilderHelperException
     {
     
         // ----------------------------------------------------------------------
@@ -140,13 +151,55 @@
         // SCM Url
         // ----------------------------------------------------------------------
 
-        continuumProject.setScmUrl( getScmUrl( mavenProject ) );
+        String scmUrl = getScmUrl( mavenProject );
+
+        continuumProject.setScmUrl( scmUrl );
 
         if ( !"HEAD".equals( mavenProject.getScm().getTag() ) )
         {
             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 ) );
 
         // ----------------------------------------------------------------------
@@ -456,6 +509,18 @@
         }
 
         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/execution/maven/m2/MavenBuilderHelper.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m2/MavenBuilderHelper.java?view=diff&rev=470896&r1=470895&r2=470896
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m2/MavenBuilderHelper.java
(original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m2/MavenBuilderHelper.java
Fri Nov  3 08:45:49 2006
@@ -56,7 +56,8 @@
      * @param groupPom map this project as if it is being used to initialize a project group
      */
     void mapMavenProjectToContinuumProject( ContinuumProjectBuildingResult result, MavenProject
mavenProject,
-                                            Project continuumProject, boolean groupPom );
+                                            Project continuumProject, boolean groupPom )
+        throws MavenBuilderHelperException;
 
     ArtifactRepository getLocalRepository();
 }

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=470896&r1=470895&r2=470896
==============================================================================
--- 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
Fri Nov  3 08:45:49 2006
@@ -18,6 +18,7 @@
 
 import org.apache.maven.continuum.execution.maven.m2.MavenBuilderHelper;
 import org.apache.maven.continuum.execution.maven.m2.MavenTwoBuildExecutor;
+import org.apache.maven.continuum.execution.maven.m2.MavenBuilderHelperException;
 import org.apache.maven.continuum.initialization.DefaultContinuumInitializer;
 import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.model.project.Project;
@@ -184,7 +185,16 @@
         {
             Project continuumProject = new Project();
 
-            builderHelper.mapMavenProjectToContinuumProject( result, mavenProject, continuumProject,
groupPom );
+            try
+            {
+                builderHelper.mapMavenProjectToContinuumProject( result, mavenProject, continuumProject,
groupPom );
+            }
+            catch ( MavenBuilderHelperException e )
+            {
+                getLogger().info( "Error adding project: Unknown error mapping project "
+ url, e );
+                result.addError( ContinuumProjectBuildingResult.ERROR_MISSING_SCM_CONNECTION
);
+                return;
+            }
 
             result.addProject( continuumProject, MavenTwoBuildExecutor.ID );
         }

Modified: maven/continuum/trunk/continuum-core/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/resources/META-INF/plexus/components.xml?view=diff&rev=470896&r1=470895&r2=470896
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/resources/META-INF/plexus/components.xml
(original)
+++ maven/continuum/trunk/continuum-core/src/main/resources/META-INF/plexus/components.xml
Fri Nov  3 08:45:49 2006
@@ -269,6 +269,9 @@
         <requirement>
           <role>org.apache.maven.settings.MavenSettingsBuilder</role>
         </requirement>
+        <requirement>
+          <role>org.apache.maven.scm.manager.ScmManager</role>
+        </requirement>
       </requirements>
       <configuration>
         <local-repository>${plexus.home}/local-repository</local-repository>



Mime
View raw message