You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2007/12/05 00:49:01 UTC

svn commit: r601151 - in /incubator/tuscany/java/sca/tools/maven: ./ maven-incremental-build/ maven-incremental-build/src/main/java/org/apache/tuscany/sca/ maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/ maven-incremental-build/src/...

Author: jsdelfino
Date: Tue Dec  4 15:48:56 2007
New Revision: 601151

URL: http://svn.apache.org/viewvc?rev=601151&view=rev
Log:
Added a plugin to help run incremental builds.

Added:
    incubator/tuscany/java/sca/tools/maven/maven-incremental-build/
      - copied from r598683, incubator/tuscany/java/sca/tools/maven/maven-ant-generator/
    incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/
    incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/
    incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/
    incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/
    incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/
    incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/IncrementalBuildMojo.java   (with props)
Removed:
    incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/tools/
Modified:
    incubator/tuscany/java/sca/tools/maven/maven-incremental-build/pom.xml
    incubator/tuscany/java/sca/tools/maven/pom.xml

Modified: incubator/tuscany/java/sca/tools/maven/maven-incremental-build/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tools/maven/maven-incremental-build/pom.xml?rev=601151&r1=598683&r2=601151&view=diff
==============================================================================
--- incubator/tuscany/java/sca/tools/maven/maven-incremental-build/pom.xml (original)
+++ incubator/tuscany/java/sca/tools/maven/maven-incremental-build/pom.xml Tue Dec  4 15:48:56 2007
@@ -25,39 +25,51 @@
         <version>1.1-incubating-SNAPSHOT</version>
         <relativePath>../pom.xml</relativePath>
     </parent>
-    <artifactId>tuscany-maven-ant-generator</artifactId>
+    <artifactId>tuscany-maven-incremental-build</artifactId>
     <packaging>maven-plugin</packaging>
-    <name>Apache Tuscany SCA Ant Build Generator Maven Plugin</name>
+    <name>Apache Tuscany SCA Incremental Build Generator Maven Plugin</name>
 
     <dependencies>
         <dependency>
             <groupId>org.apache.maven</groupId>
             <artifactId>maven-plugin-api</artifactId>
-            <version>2.0.4</version>
+            <version>2.0.5</version>
         </dependency>
         
         <dependency>
             <groupId>org.apache.maven</groupId>
             <artifactId>maven-project</artifactId>
-            <version>2.0.4</version>
+            <version>2.0.5</version>
         </dependency>
         
         <dependency>
             <groupId>org.apache.maven</groupId>
             <artifactId>maven-settings</artifactId>
-            <version>2.0.4</version>
+            <version>2.0.5</version>
         </dependency>
         
         <dependency>
             <groupId>org.apache.maven</groupId>
             <artifactId>maven-artifact</artifactId>
-            <version>2.0.4</version>
+            <version>2.0.5</version>
         </dependency>
         
         <dependency>
             <groupId>org.apache.maven</groupId>
             <artifactId>maven-model</artifactId>
-            <version>2.0.4</version>
+            <version>2.0.5</version>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-core</artifactId>
+            <version>2.0.5</version>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.maven.shared</groupId>
+            <artifactId>maven-invoker</artifactId>
+            <version>2.0.5</version>
         </dependency>
         
     </dependencies>

Added: incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/IncrementalBuildMojo.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/IncrementalBuildMojo.java?rev=601151&view=auto
==============================================================================
--- incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/IncrementalBuildMojo.java (added)
+++ incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/IncrementalBuildMojo.java Tue Dec  4 15:48:56 2007
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.sca.tools.incremental.build.plugin;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.settings.Settings;
+import org.apache.maven.shared.invoker.DefaultInvocationRequest;
+import org.apache.maven.shared.invoker.InvocationRequest;
+import org.apache.maven.shared.invoker.InvocationResult;
+import org.apache.maven.shared.invoker.Invoker;
+import org.apache.maven.shared.invoker.MavenInvocationException;
+import org.codehaus.plexus.util.cli.CommandLineException;
+
+/**
+ * @version $Rev$ $Date$
+ * @goal build
+ * @phase validate
+ * @requiresDependencyResolution test
+ * @description Incrementally build project modules that depend on modified modules.
+ */
+public class IncrementalBuildMojo extends AbstractMojo {
+    /**
+     * The project to create a build for.
+     *
+     * @parameter expression="${project}"
+     * @required
+     */
+    private MavenProject project;
+
+    /**
+     * The local repository where the artifacts are located
+     *
+     * @parameter expression="${localRepository}"
+     * @required
+     */
+    private ArtifactRepository localRepository;
+
+    /**
+     * The current user system settings for use in Maven.
+     *
+     * @parameter expression="${settings}"
+     * @required
+     * @readonly
+     */
+    private Settings settings;
+
+    /**
+     * Used to invoke Maven builds.
+     *
+     * @component
+     */
+    private Invoker invoker;
+
+    /**
+     * Keep track of modified projects.
+     */
+    private static Set<String> modifiedProjectIDs = new HashSet<String>();
+
+    /**
+     * Returns the qualified id of a project.
+     * @param p a Maven project
+     * @return a qualified id
+     */
+    private static String id(MavenProject p) {
+        return p.getGroupId() + ':' + p.getArtifactId();
+    }
+    
+    /**
+     * Returns the qualified id of an artifact .
+     * @param p a Maven artifact
+     * @return a qualified id
+     */
+    private static String id(Artifact a) {
+        return a.getGroupId() + ':' + a.getArtifactId();
+    }
+    
+    public void execute() throws MojoExecutionException {
+        String projectID = id(project);
+
+        // Determine if the project has been modified
+        // For now look for a .modified marker file but eventually we
+        // should use "svn st" to detect modifications
+        String marker = project.getBasedir().getPath()+ "/.modified";
+        if (new File(marker).exists()) {
+            getLog().info("Project: " + projectID + " has been modified.");
+            modifiedProjectIDs.add(projectID);
+        }
+
+        // Check if a project has compile dependencies on the modified projects
+        // and will need to be recompiled, or has runtime or test dependencies
+        // on the modified projects and needs to be retested
+        List<String> goals = new ArrayList<String>();
+
+        for (Artifact artifact: (List<Artifact>)project.getCompileArtifacts()) {
+            String artifactID = id(artifact);
+            if (modifiedProjectIDs.contains(artifactID)) {
+                getLog().info("Project " + projectID + " depends on modified project " + artifactID + " and will be recompiled.");
+                goals.add("clean");
+                goals.add("install");
+                break;
+            }
+        }
+        
+        if (goals.isEmpty()) {
+            List<Artifact> artifacts = new ArrayList<Artifact>();
+            artifacts.addAll(project.getRuntimeArtifacts());
+            artifacts.addAll(project.getTestArtifacts());
+            for (Artifact artifact: artifacts) {
+                String artifactID = id(artifact);
+                if (modifiedProjectIDs.contains(artifactID)) {
+                    getLog().info("Project " + projectID + " depends on modified project " + artifactID + " and will be retested.");
+                    goals.add("test");
+                    break;
+                }
+            }
+        }
+
+        // Invoke Maven with the necessary goals
+        if (!goals.isEmpty()) {
+            InvocationRequest request = new DefaultInvocationRequest();
+            request.setGoals(goals);
+            request.setLocalRepositoryDirectory(new File(localRepository.getBasedir()));
+            request.setInteractive(false);
+            request.setShowErrors(false);
+            request.setOffline(settings.isOffline());
+            request.setBaseDirectory(project.getBasedir());
+            request.setPomFile(new File(project.getBasedir().getPath() + "/pom.xml"));
+            
+            try {
+                InvocationResult result = invoker.execute(request);
+                
+                CommandLineException cle = result.getExecutionException();
+                if (cle != null) {
+                    throw new MojoExecutionException(cle.getMessage(), cle);
+                }
+                
+                int ec = result.getExitCode();
+                if (ec != 0) {
+                    throw new MojoExecutionException("Maven invocation exit code: " + ec);
+                }
+            } catch (MavenInvocationException e) {
+                throw new MojoExecutionException(e.getMessage(), e);
+            }
+        }
+    }
+
+}
\ No newline at end of file

Propchange: incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/IncrementalBuildMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/IncrementalBuildMojo.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/tools/maven/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tools/maven/pom.xml?rev=601151&r1=601150&r2=601151&view=diff
==============================================================================
--- incubator/tuscany/java/sca/tools/maven/pom.xml (original)
+++ incubator/tuscany/java/sca/tools/maven/pom.xml Tue Dec  4 15:48:56 2007
@@ -40,6 +40,7 @@
                 <module>maven-java2wsdl</module>
                 <module>maven-wsdl2java</module>
                 <module>maven-ant-generator</module>
+                <module>maven-incremental-build</module>
             </modules>
         </profile>
     </profiles>



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org