continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r670751 - in /continuum/trunk: continuum-api/src/main/java/org/apache/maven/continuum/execution/ continuum-core/src/main/java/org/apache/maven/continuum/buildcontroller/ continuum-core/src/main/java/org/apache/maven/continuum/execution/ con...
Date Mon, 23 Jun 2008 20:59:11 GMT
Author: evenisse
Date: Mon Jun 23 13:59:11 2008
New Revision: 670751

URL: http://svn.apache.org/viewvc?rev=670751&view=rev
Log:
[CONTINUUM-1807] Remove lot of build cycle by checking if changes are on current project or
only on sub-modules

Modified:
    continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/execution/ContinuumBuildExecutor.java
    continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/buildcontroller/DefaultBuildController.java
    continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/AbstractBuildExecutor.java
    continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m2/MavenTwoBuildExecutor.java

Modified: continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/execution/ContinuumBuildExecutor.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/execution/ContinuumBuildExecutor.java?rev=670751&r1=670750&r2=670751&view=diff
==============================================================================
--- continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/execution/ContinuumBuildExecutor.java
(original)
+++ continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/execution/ContinuumBuildExecutor.java
Mon Jun 23 13:59:11 2008
@@ -21,6 +21,7 @@
 
 import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.model.scm.ChangeSet;
 
 import java.io.File;
 import java.util.List;
@@ -51,4 +52,8 @@
 
     //TODO: Move as a plugin
     void backupTestFiles( Project project, int buildId );
+
+    boolean shouldBuild( List<ChangeSet> changes, Project continuumProject, File workingDirectory,
+                         BuildDefinition buildDefinition )
+        throws ContinuumBuildExecutorException;
 }

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/buildcontroller/DefaultBuildController.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/buildcontroller/DefaultBuildController.java?rev=670751&r1=670750&r2=670751&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/buildcontroller/DefaultBuildController.java
(original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/buildcontroller/DefaultBuildController.java
Mon Jun 23 13:59:11 2008
@@ -20,6 +20,8 @@
  */
 
 import org.apache.maven.continuum.core.action.AbstractContinuumAction;
+import org.apache.maven.continuum.execution.ContinuumBuildExecutor;
+import org.apache.maven.continuum.execution.manager.BuildExecutorManager;
 import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.model.project.BuildResult;
 import org.apache.maven.continuum.model.project.Project;
@@ -76,6 +78,11 @@
      */
     private WorkingDirectoryService workingDirectoryService;
 
+    /**
+     * @plexus.requirement
+     */
+    private BuildExecutorManager buildExecutorManager;
+
     // ----------------------------------------------------------------------
     // BuildController Implementation
     // ----------------------------------------------------------------------
@@ -155,7 +162,7 @@
             {
                 try
                 {
-                    context.setBuildResult( store.getBuildResult( Integer.valueOf( s ).intValue()
) );
+                    context.setBuildResult( store.getBuildResult( Integer.valueOf( s ) )
);
                 }
                 catch ( NumberFormatException e )
                 {
@@ -201,7 +208,7 @@
 
                     if ( s != null )
                     {
-                        BuildResult buildResult = store.getBuildResult( Integer.valueOf(
s ).intValue() );
+                        BuildResult buildResult = store.getBuildResult( Integer.valueOf(
s ) );
                         project.setState( buildResult.getState() );
                     }
                     else
@@ -342,18 +349,17 @@
 
         Map actionContext = context.getActionContext();
 
-        actionContext.put( AbstractContinuumAction.KEY_PROJECT_ID, new Integer( projectId
) );
+        actionContext.put( AbstractContinuumAction.KEY_PROJECT_ID, projectId );
 
         actionContext.put( AbstractContinuumAction.KEY_PROJECT, context.getProject() );
 
-        actionContext.put( AbstractContinuumAction.KEY_BUILD_DEFINITION_ID, new Integer(
buildDefinitionId ) );
+        actionContext.put( AbstractContinuumAction.KEY_BUILD_DEFINITION_ID, buildDefinitionId
);
 
         actionContext.put( AbstractContinuumAction.KEY_BUILD_DEFINITION, context.getBuildDefinition()
);
 
-        actionContext.put( AbstractContinuumAction.KEY_TRIGGER, new Integer( trigger ) );
+        actionContext.put( AbstractContinuumAction.KEY_TRIGGER, trigger );
 
-        actionContext.put( AbstractContinuumAction.KEY_FIRST_RUN,
-                           Boolean.valueOf( context.getOldBuildResult() == null ) );
+        actionContext.put( AbstractContinuumAction.KEY_FIRST_RUN, context.getOldBuildResult()
== null );
 
         return context;
     }
@@ -532,32 +538,43 @@
             }
         }
 
+        // Check changes
+        if ( !shouldBuild && !context.getScmResult().getChanges().isEmpty() )
+        {
+            try
+            {
+                ContinuumBuildExecutor executor = buildExecutorManager.getBuildExecutor(
project.getExecutorId() );
+                shouldBuild = executor.shouldBuild( context.getScmResult().getChanges(),
project,
+                                                    workingDirectoryService.getWorkingDirectory(
project ),
+                                                    context.getBuildDefinition() );
+            }
+            catch ( Exception e )
+            {
+                //nothing to do
+            }
+        }
+
         if ( shouldBuild )
         {
-            getLogger().info( "Changes found, building" );
+            getLogger().info( "Changes found in the current project, building" );
         }
         else
         {
-            getLogger().info( "No changes, not building" );
+            getLogger().info( "No changes in the current project, not building" );
 
         }
+
         return shouldBuild;
     }
 
-    private boolean checkAllChangesUnknown( List changes )
+    private boolean checkAllChangesUnknown( List<ChangeSet> changes )
     {
-        for ( Iterator iterChanges = changes.iterator(); iterChanges.hasNext(); )
+        for ( ChangeSet changeSet : changes )
         {
-            ChangeSet changeSet = (ChangeSet) iterChanges.next();
-
-            List changeFiles = changeSet.getFiles();
-
-            Iterator iterFiles = changeFiles.iterator();
+            List<ChangeFile> changeFiles = changeSet.getFiles();
 
-            while ( iterFiles.hasNext() )
+            for ( ChangeFile changeFile : changeFiles )
             {
-                ChangeFile changeFile = (ChangeFile) iterFiles.next();
-
                 if ( !"unknown".equalsIgnoreCase( changeFile.getStatus() ) )
                 {
                     return false;
@@ -578,7 +595,7 @@
         {
             for ( Iterator<String> i = messages.iterator(); i.hasNext(); )
             {
-                message.append( (String) i.next() );
+                message.append( i.next() );
 
                 if ( i.hasNext() )
                 {
@@ -599,11 +616,11 @@
         try
         {
             Project project = store.getProjectWithAllDetails( context.getProject().getId()
);
-            List dependencies = project.getDependencies();
+            List<ProjectDependency> dependencies = project.getDependencies();
 
             if ( dependencies == null )
             {
-                dependencies = new ArrayList();
+                dependencies = new ArrayList<ProjectDependency>();
             }
 
             if ( project.getParent() != null )
@@ -616,11 +633,10 @@
                 return;
             }
 
-            List modifiedDependencies = new ArrayList();
+            List<ProjectDependency> modifiedDependencies = new ArrayList<ProjectDependency>();
 
-            for ( Iterator i = dependencies.iterator(); i.hasNext(); )
+            for ( ProjectDependency dep : dependencies )
             {
-                ProjectDependency dep = (ProjectDependency) i.next();
                 Project dependencyProject = store.getProject( dep.getGroupId(), dep.getArtifactId(),
dep.getVersion() );
 
                 if ( dependencyProject != null )
@@ -746,28 +762,24 @@
 
     private ScmResult getOldScmResult( int projectId, long fromDate )
     {
-        List results = store.getBuildResultsForProject( projectId, fromDate );
+        List<BuildResult> results = store.getBuildResultsForProject( projectId, fromDate
);
 
         ScmResult res = new ScmResult();
 
         if ( results != null )
         {
-            for ( Iterator i = results.iterator(); i.hasNext(); )
+            for ( BuildResult result : results )
             {
-                BuildResult result = (BuildResult) i.next();
-
                 ScmResult scmResult = result.getScmResult();
 
                 if ( scmResult != null )
                 {
-                    List changes = scmResult.getChanges();
+                    List<ChangeSet> changes = scmResult.getChanges();
 
                     if ( changes != null )
                     {
-                        for ( Iterator j = changes.iterator(); j.hasNext(); )
+                        for ( ChangeSet changeSet : changes )
                         {
-                            ChangeSet changeSet = (ChangeSet) j.next();
-
                             if ( changeSet.getDate() < fromDate )
                             {
                                 continue;
@@ -788,6 +800,8 @@
 
     /**
      * Merges scm results so we'll have all changes since last execution of current build
definition
+     *
+     * @param context The build context
      */
     private void mergeScmResults( BuildContext context )
     {
@@ -802,14 +816,12 @@
             }
             else
             {
-                List oldChanges = oldScmResult.getChanges();
+                List<ChangeSet> oldChanges = oldScmResult.getChanges();
 
-                List newChanges = newScmResult.getChanges();
+                List<ChangeSet> newChanges = newScmResult.getChanges();
 
-                for ( Iterator i = newChanges.iterator(); i.hasNext(); )
+                for ( ChangeSet change : newChanges )
                 {
-                    ChangeSet change = (ChangeSet) i.next();
-
                     if ( !oldChanges.contains( change ) )
                     {
                         oldChanges.add( change );
@@ -824,6 +836,8 @@
     /**
      * Check to see if there was a error while checking out/updating the project
      *
+     * @param context The build context
+     * @return true if scm result is ok
      * @throws TaskExecutionException
      */
     private boolean checkScmResult( BuildContext context )

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/AbstractBuildExecutor.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/AbstractBuildExecutor.java?rev=670751&r1=670750&r2=670751&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/AbstractBuildExecutor.java
(original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/AbstractBuildExecutor.java
Mon Jun 23 13:59:11 2008
@@ -22,6 +22,7 @@
 import org.apache.maven.continuum.installation.InstallationService;
 import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.model.scm.ChangeSet;
 import org.apache.maven.continuum.model.system.Installation;
 import org.apache.maven.continuum.model.system.Profile;
 import org.apache.maven.continuum.project.ContinuumProjectState;
@@ -52,6 +53,7 @@
     implements ContinuumBuildExecutor, Initializable
 {
     private static final String SUDO_EXECUTABLE = "sudo";
+
     private static final String CHROOT_EXECUTABLE = "chroot";
 
     // ----------------------------------------------------------------------
@@ -177,9 +179,12 @@
 
     /**
      * Find the actual executable path to be used
-     * @param defaultExecutable 
+     *
+     * @param defaultExecutable
+     * @return The executable path
      */
-    protected String findExecutable( Project project, String executable, String defaultExecutable,
boolean resolveExecutable, File workingDirectory )
+    protected String findExecutable( Project project, String executable, String defaultExecutable,
+                                     boolean resolveExecutable, File workingDirectory )
     {
         // ----------------------------------------------------------------------
         // If we're not searching the path for the executable, prefix the
@@ -230,7 +235,7 @@
         {
             actualExecutable = executable;
         }
-        
+
         return actualExecutable;
     }
 
@@ -255,9 +260,6 @@
             {
                 StringBuilder sb = new StringBuilder();
                 sb.append( CHROOT_EXECUTABLE );
-                // TODO see CONTINUUM-1731
-                //sb.append( "su" );
-                //sb.append( username );
                 sb.append( " " );
                 sb.append( new File( chrootJailDirectory, project.getGroupId() ) );
                 sb.append( " " );
@@ -274,9 +276,9 @@
                 workingDirectory = chrootJailDirectory; // not really used but must exist
             }
 
-            ExecutionResult result =
-                getShellCommandHelper().executeShellCommand( workingDirectory, actualExecutable,
arguments, output,
-                                                             project.getId(), environments
);
+            ExecutionResult result = getShellCommandHelper().executeShellCommand( workingDirectory,
actualExecutable,
+                                                                                  arguments,
output, project.getId(),
+                                                                                  environments
);
 
             getLogger().info( "Exit code: " + result.getExitCode() );
 
@@ -312,8 +314,8 @@
         }
         else
         {
-            throw new IllegalArgumentException( "Working directory is not inside the chroot
jail " + chrootBase +
-                " , " + path );
+            throw new IllegalArgumentException(
+                "Working directory is not inside the chroot jail " + chrootBase + " , " +
path );
         }
     }
 
@@ -339,6 +341,16 @@
         //Nothing to do, by default
     }
 
+    /**
+     * By default, we return true because with a change, the projet must be rebuilt.
+     */
+    public boolean shouldBuild( List<ChangeSet> changes, Project continuumProject,
File workingDirectory,
+                                BuildDefinition buildDefinition )
+        throws ContinuumBuildExecutorException
+    {
+        return true;
+    }
+
     protected Map<String, String> getEnvironmentVariables( BuildDefinition buildDefinition
)
     {
         Profile profile = buildDefinition.getProfile();
@@ -352,9 +364,8 @@
         {
             return envVars;
         }
-        for ( Iterator<Installation> iterator = environmentVariables.iterator(); iterator.hasNext();
)
+        for ( Installation installation : environmentVariables )
         {
-            Installation installation = iterator.next();
             envVars.put( installation.getVarName(), installation.getVarValue() );
         }
         return envVars;
@@ -388,7 +399,8 @@
 
     public boolean isBuilding( Project project )
     {
-        return project.getState() == ContinuumProjectState.BUILDING || getShellCommandHelper().isRunning(
project.getId() );
+        return project.getState() == ContinuumProjectState.BUILDING ||
+            getShellCommandHelper().isRunning( project.getId() );
     }
 
     public void killProcess( Project project )

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m2/MavenTwoBuildExecutor.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m2/MavenTwoBuildExecutor.java?rev=670751&r1=670750&r2=670751&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m2/MavenTwoBuildExecutor.java
(original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m2/MavenTwoBuildExecutor.java
Mon Jun 23 13:59:11 2008
@@ -31,6 +31,8 @@
 import org.apache.maven.continuum.installation.InstallationService;
 import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.model.scm.ChangeFile;
+import org.apache.maven.continuum.model.scm.ChangeSet;
 import org.apache.maven.continuum.model.system.Installation;
 import org.apache.maven.continuum.model.system.Profile;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
@@ -47,7 +49,6 @@
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -207,28 +208,12 @@
         return f;
     }
 
+    @Override
     public List getDeployableArtifacts( Project continuumProject, File workingDirectory,
                                         BuildDefinition buildDefinition )
         throws ContinuumBuildExecutorException
     {
-        File f = getPomFile( getBuildFileForProject( continuumProject, buildDefinition ),
workingDirectory );
-
-        if ( !f.exists() )
-        {
-            throw new ContinuumBuildExecutorException( "Could not find Maven project descriptor
'" + f + "'." );
-        }
-
-        MavenProject project;
-
-        ContinuumProjectBuildingResult result = new ContinuumProjectBuildingResult();
-
-        project = builderHelper.getMavenProject( result, f );
-
-        if ( result.hasErrors() )
-        {
-            throw new ContinuumBuildExecutorException(
-                "Unable to read the Maven project descriptor '" + f + "': " + result.getErrorsAsString()
);
-        }
+        MavenProject project = getMavenProject( continuumProject, workingDirectory, buildDefinition
);
 
         // Maven could help us out a lot more here by knowing how to get the deployment artifacts
from a project.
         // TODO: this is currently quite lame
@@ -301,24 +286,47 @@
             }
         }
 
-        List attachedArtifacts = project.getAttachedArtifacts();
+        List<Artifact> attachedArtifacts = project.getAttachedArtifacts();
 
-        List artifacts = new ArrayList( attachedArtifacts.size() + 1 );
+        List<Artifact> artifacts = new ArrayList<Artifact>( attachedArtifacts.size()
+ 1 );
 
         if ( artifact.getFile().exists() )
         {
             artifacts.add( artifact );
         }
 
-        for ( Iterator iterator = attachedArtifacts.iterator(); iterator.hasNext(); )
+        for ( Artifact attachedArtifact : attachedArtifacts )
         {
-            Artifact attachedArtifact = (Artifact) iterator.next();
             artifacts.add( attachedArtifact );
         }
 
         return artifacts;
     }
 
+    private MavenProject getMavenProject( Project continuumProject, File workingDirectory,
+                                          BuildDefinition buildDefinition )
+        throws ContinuumBuildExecutorException
+    {
+        ContinuumProjectBuildingResult result = new ContinuumProjectBuildingResult();
+
+        File f = getPomFile( getBuildFileForProject( continuumProject, buildDefinition ),
workingDirectory );
+
+        if ( !f.exists() )
+        {
+            throw new ContinuumBuildExecutorException( "Could not find Maven project descriptor
'" + f + "'." );
+        }
+
+        MavenProject project = builderHelper.getMavenProject( result, f );
+
+        if ( result.hasErrors() )
+        {
+            throw new ContinuumBuildExecutorException(
+                "Unable to read the Maven project descriptor '" + f + "': " + result.getErrorsAsString()
);
+        }
+        return project;
+    }
+
+    @Override
     public void backupTestFiles( Project project, int buildId )
     {
         File backupDirectory = null;
@@ -367,6 +375,76 @@
         }
     }
 
+    /**
+     * @return true if changes are in the current project, not only in sub-modules and in
non-recursive mode
+     * @see org.apache.maven.continuum.execution.ContinuumBuildExecutor#shouldBuild(java.util.List,
org.apache.maven.continuum.model.project.Project, java.io.File, org.apache.maven.continuum.model.project.BuildDefinition)
+     */
+    @Override
+    public boolean shouldBuild( List<ChangeSet> changes, Project continuumProject,
File workingDirectory,
+                                BuildDefinition buildDefinition )
+        throws ContinuumBuildExecutorException
+    {
+        //Check if it's a recursive build
+        boolean isRecursive = StringUtils.isNotEmpty( buildDefinition.getArguments() ) &&
!(
+            buildDefinition.getArguments().indexOf( "-N" ) < 0 ||
+                buildDefinition.getArguments().indexOf( "--non-recursive" ) < 0 );
+
+        if ( isRecursive )
+        {
+            if ( getLogger().isDebugEnabled() )
+            {
+                getLogger().debug( "isRecursive --> shouldBuild = true" );
+            }
+            return true;
+        }
+
+        //check if changes are only in sub-modules or not
+        MavenProject project = getMavenProject( continuumProject, workingDirectory, buildDefinition
);
+        List<String> modules = project.getModules();
+
+        List<ChangeFile> files = new ArrayList<ChangeFile>();
+        for ( ChangeSet changeSet : changes )
+        {
+            files.addAll( changeSet.getFiles() );
+        }
+        int i = 0;
+        while ( i <= files.size() - 1 )
+        {
+            ChangeFile file = files.get( i );
+            boolean found = false;
+            for ( String module : modules )
+            {
+                if ( file.getName().indexOf( module ) > 0 )
+                {
+                    files.remove( file );
+                    found = true;
+                    break;
+                }
+            }
+            if ( !found )
+            {
+                i++;
+            }
+            else
+            {
+                break;
+            }
+        }
+
+        boolean shouldBuild = !files.isEmpty();
+
+        if ( !shouldBuild )
+        {
+            getLogger().info( "Changes are only in sub-modules." );
+        }
+        if ( getLogger().isDebugEnabled() )
+        {
+            getLogger().debug( "shoulbuild = " + shouldBuild );
+        }
+        return shouldBuild;
+    }
+
+    @Override
     protected Map<String, String> getEnvironments( BuildDefinition buildDefinition
)
     {
         Profile profile = buildDefinition.getProfile();



Mime
View raw message