maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdca...@apache.org
Subject svn commit: r422907 [3/3] - in /maven/plugins/branches/MASSEMBLY-124: ./ src/functional-tests/ src/functional-tests/java/org/apache/maven/plugin/assembly/ src/main/java/org/apache/maven/plugin/assembly/ src/main/java/org/apache/maven/plugin/assembly/ar...
Date Mon, 17 Jul 2006 22:35:00 GMT
Copied: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/DirectoryInlineMojo.java
(from r421932, maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/DirectoryInlineMojo.java)
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/DirectoryInlineMojo.java?p2=maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/DirectoryInlineMojo.java&p1=maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/DirectoryInlineMojo.java&r1=421932&r2=422907&rev=422907&view=diff
==============================================================================
--- maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/DirectoryInlineMojo.java
(original)
+++ maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/DirectoryInlineMojo.java
Mon Jul 17 15:34:58 2006
@@ -1,4 +1,4 @@
-package org.apache.maven.plugin.assembly;
+package org.apache.maven.plugin.assembly.mojos;
 
 /*
  * Copyright 2001-2005 The Apache Software Foundation.
@@ -30,7 +30,14 @@
 public class DirectoryInlineMojo
     extends AbstractDirectoryMojo
 {
-    protected MavenProject getExecutedProject()
+    /**
+     * @parameter default-value="${project}"
+     * @required
+     * @readonly
+     */
+    private MavenProject project;
+    
+    public MavenProject getProject()
     {
         return project;
     }

Copied: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/DirectoryMojo.java
(from r421932, maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/DirectoryMojo.java)
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/DirectoryMojo.java?p2=maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/DirectoryMojo.java&p1=maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/DirectoryMojo.java&r1=421932&r2=422907&rev=422907&view=diff
==============================================================================
--- maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/DirectoryMojo.java
(original)
+++ maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/DirectoryMojo.java
Mon Jul 17 15:34:58 2006
@@ -1,4 +1,4 @@
-package org.apache.maven.plugin.assembly;
+package org.apache.maven.plugin.assembly.mojos;
 
 /*
  * Copyright 2001-2005 The Apache Software Foundation.
@@ -36,7 +36,7 @@
      */
     private MavenProject executedProject;
 
-    protected MavenProject getExecutedProject()
+    public MavenProject getProject()
     {
         return executedProject;
     }

Propchange: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/DirectoryMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/DirectoryMojo.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Copied: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/SingleAssemblyMojo.java
(from r421932, maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/SingleAssemblyMojo.java)
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/SingleAssemblyMojo.java?p2=maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/SingleAssemblyMojo.java&p1=maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/SingleAssemblyMojo.java&r1=421932&r2=422907&rev=422907&view=diff
==============================================================================
--- maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/SingleAssemblyMojo.java
(original)
+++ maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/SingleAssemblyMojo.java
Mon Jul 17 15:34:58 2006
@@ -1,4 +1,4 @@
-package org.apache.maven.plugin.assembly;
+package org.apache.maven.plugin.assembly.mojos;
 
 /*
  * Copyright 2001-2005 The Apache Software Foundation.
@@ -32,7 +32,14 @@
 public class SingleAssemblyMojo
     extends AbstractAssemblyMojo
 {
-    protected MavenProject getExecutedProject()
+    /**
+     * @parameter default-value="${project}"
+     * @required
+     * @readonly
+     */
+    private MavenProject project;
+    
+    public MavenProject getProject()
     {
         return project;
     }

Propchange: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/SingleAssemblyMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/SingleAssemblyMojo.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/UnpackMojo.java
(from r421932, maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/UnpackMojo.java)
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/UnpackMojo.java?p2=maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/UnpackMojo.java&p1=maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/UnpackMojo.java&r1=421932&r2=422907&rev=422907&view=diff
==============================================================================
--- maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/UnpackMojo.java
(original)
+++ maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/UnpackMojo.java
Mon Jul 17 15:34:58 2006
@@ -1,4 +1,4 @@
-package org.apache.maven.plugin.assembly;
+package org.apache.maven.plugin.assembly.mojos;
 
 /*
  * Copyright 2001-2005 The Apache Software Foundation.
@@ -17,10 +17,14 @@
  */
 
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.assembly.archive.ArchiveAssemblyUtils;
+import org.apache.maven.plugin.assembly.archive.ArchiveExpansionException;
 import org.apache.maven.plugin.assembly.utils.ProjectUtils;
 import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.archiver.manager.ArchiverManager;
 import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
 
 import java.io.File;
@@ -34,12 +38,28 @@
  * @requiresDependencyResolution test
  */
 public class UnpackMojo
-    extends AbstractUnpackingMojo
+    extends AbstractMojo
 {
-    protected MavenProject getExecutedProject()
-    {
-        return project;
-    }
+    
+    /**
+     * @parameter default-value="${project}"
+     * @required
+     * @readonly
+     */
+    private MavenProject project;
+    
+    /**
+     * @component
+     */
+    private ArchiverManager archiverManager;
+
+    /**
+     * Directory to unpack JARs into if needed
+     *
+     * @parameter expression="${project.build.directory}/assembly/work"
+     * @required
+     */
+    protected File workDirectory;
 
     /**
      * Unpacks the archive file.
@@ -72,11 +92,15 @@
                 File file = artifact.getFile();
                 try
                 {
-                    unpack( file, tempLocation );
+                    ArchiveAssemblyUtils.unpack( file, tempLocation, archiverManager );
                 }
                 catch ( NoSuchArchiverException e )
                 {
                     this.getLog().info( "Skip unpacking dependency file with unknown extension:
" + file.getPath() );
+                }
+                catch ( ArchiveExpansionException e )
+                {
+                    throw new MojoExecutionException( "Error unpacking dependency file: "
+ file, e );
                 }
             }
         }

Propchange: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/UnpackMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/mojos/UnpackMojo.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/repository/DefaultRepositoryAssembler.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/repository/DefaultRepositoryAssembler.java?rev=422907&r1=422906&r2=422907&view=diff
==============================================================================
--- maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/repository/DefaultRepositoryAssembler.java
(original)
+++ maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/repository/DefaultRepositoryAssembler.java
Mon Jul 17 15:34:58 2006
@@ -51,6 +51,7 @@
 import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
 import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
+import org.apache.maven.plugin.assembly.AssemblerConfigurationSource;
 import org.apache.maven.plugin.assembly.filter.AssemblyExcludesArtifactFilter;
 import org.apache.maven.plugin.assembly.filter.AssemblyIncludesArtifactFilter;
 import org.apache.maven.plugin.assembly.utils.DigestUtils;
@@ -93,10 +94,12 @@
 
     private DigestUtils digester = new DigestUtils();
 
-    public void assemble( File repositoryDirectory, Repository repository, MavenProject project,
-                          ArtifactRepository localRepository )
+    public void assemble( File repositoryDirectory, Repository repository, AssemblerConfigurationSource
configSource )
         throws RepositoryAssemblyException
     {
+        MavenProject project = configSource.getProject();
+        ArtifactRepository localRepository = configSource.getLocalRepository();
+        
         createGroupVersionAlignments( repository.getGroupVersionAlignments() );
 
         ArtifactRepository targetRepository = createLocalRepository( repositoryDirectory
);

Modified: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/repository/RepositoryAssembler.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/repository/RepositoryAssembler.java?rev=422907&r1=422906&r2=422907&view=diff
==============================================================================
--- maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/repository/RepositoryAssembler.java
(original)
+++ maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/repository/RepositoryAssembler.java
Mon Jul 17 15:34:58 2006
@@ -16,10 +16,8 @@
  * limitations under the License.
  */
 
-import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.plugin.assembly.AssemblerConfigurationSource;
 import org.apache.maven.plugins.assembly.model.Repository;
-import org.apache.maven.project.MavenProject;
-
 import java.io.File;
 
 /**
@@ -29,7 +27,6 @@
 {
     String ROLE = RepositoryAssembler.class.getName();
 
-    public void assemble( File repositoryDirectory, Repository repository, MavenProject project,
-                          ArtifactRepository localRepository )
+    public void assemble( File repositoryDirectory, Repository repository, AssemblerConfigurationSource
configSource )
         throws RepositoryAssemblyException;
 }

Added: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFileUtils.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFileUtils.java?rev=422907&view=auto
==============================================================================
--- maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFileUtils.java
(added)
+++ maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFileUtils.java
Mon Jul 17 15:34:58 2006
@@ -0,0 +1,87 @@
+package org.apache.maven.plugin.assembly.utils;
+
+import org.apache.maven.plugin.assembly.format.AssemblyFormattingException;
+import org.codehaus.plexus.util.IOUtil;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Reader;
+
+public final class AssemblyFileUtils
+{
+
+    private AssemblyFileUtils()
+    {
+    }
+
+    /**
+     * NOTE: It is the responsibility of the caller to close the source Reader instance.
+     */
+    public static void convertLineEndings( Reader source, File dest, String lineEndings )
+        throws IOException
+    {
+        BufferedWriter out = null;
+        BufferedReader bufferedSource = null;
+        try
+        {
+            if ( !( source instanceof BufferedReader ) )
+            {
+                bufferedSource = new BufferedReader( source );
+            }
+            else
+            {
+                bufferedSource = (BufferedReader) source;
+            }
+            
+            out = new BufferedWriter( new FileWriter( dest ) );
+
+            String line;
+
+            do
+            {
+                line = bufferedSource.readLine();
+                if ( line != null )
+                {
+                    out.write( line );
+                    out.write( lineEndings );
+                }
+            } while ( line != null );
+
+            out.flush();
+        }
+        finally
+        {
+            IOUtil.close( out );
+        }
+    }
+
+    public static String getLineEndingCharacters( String lineEnding )
+        throws AssemblyFormattingException
+    {
+        String value = lineEnding;
+        if ( lineEnding != null )
+        {
+            if ( "keep".equals( lineEnding ) )
+            {
+                value = null;
+            }
+            else if ( "dos".equals( lineEnding ) || "crlf".equals( lineEnding ) )
+            {
+                value = "\r\n";
+            }
+            else if ( "unix".equals( lineEnding ) || "lf".equals( lineEnding ) )
+            {
+                value = "\n";
+            }
+            else
+            {
+                throw new AssemblyFormattingException( "Illlegal lineEnding specified: '"
+ lineEnding + "'" );
+            }
+        }
+
+        return value;
+    }
+}

Propchange: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFileUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFileUtils.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFormatUtils.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFormatUtils.java?rev=422907&view=auto
==============================================================================
--- maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFormatUtils.java
(added)
+++ maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFormatUtils.java
Mon Jul 17 15:34:58 2006
@@ -0,0 +1,172 @@
+package org.apache.maven.plugin.assembly.utils;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.model.Build;
+import org.apache.maven.plugin.assembly.AssemblerConfigurationSource;
+import org.apache.maven.plugin.assembly.format.AssemblyFormattingException;
+import org.apache.maven.plugins.assembly.model.Assembly;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.introspection.ReflectionValueExtractor;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public final class AssemblyFormatUtils
+{
+
+    private AssemblyFormatUtils()
+    {
+    }
+
+    /**
+     * Get the full name of the distribution artifact
+     *
+     * @param assembly
+     * @return the distribution name
+     */
+    public static String getDistributionName( Assembly assembly, AssemblerConfigurationSource
configSource )
+    {
+        String finalName = configSource.getFinalName();
+        boolean appendAssemblyId = configSource.isAssemblyIdAppended();
+        String classifier = configSource.getClassifier();
+        
+        String distributionName = finalName;
+        if ( appendAssemblyId )
+        {
+            if ( !StringUtils.isEmpty( assembly.getId() ) )
+            {
+                distributionName = finalName + "-" + assembly.getId();
+            }
+        }
+        else if ( classifier != null )
+        {
+            distributionName = finalName + "-" + classifier;
+        }
+        
+        return distributionName;
+    }
+    
+    public static String getOutputDirectory( String output, MavenProject project, String
finalName,
+                                             boolean includeBaseDirectory )
+    {
+        String value = output;
+        if ( value == null )
+        {
+            value = "";
+        }
+        
+        if ( !value.endsWith( "/" ) && !value.endsWith( "\\" ) )
+        {
+            // TODO: shouldn't archiver do this?
+            value += '/';
+        }
+
+        if ( includeBaseDirectory )
+        {
+            if ( value.startsWith( "/" ) )
+            {
+                value = finalName + value;
+            }
+            else
+            {
+                value = finalName + "/" + value;
+            }
+        }
+        else
+        {
+            if ( value.startsWith( "/" ) )
+            {
+                value = value.substring( 1 );
+            }
+        }
+
+        if ( project != null )
+        {
+            value = StringUtils.replace( value, "${groupId}", project.getGroupId() );
+            value = StringUtils.replace( value, "${artifactId}", project.getArtifactId()
);
+            value = StringUtils.replace( value, "${version}", project.getVersion() );
+
+            Build build = project.getBuild();
+            value = StringUtils.replace( value, "${build.finalName}", build.getFinalName()
);
+            value = StringUtils.replace( value, "${finalName}", build.getFinalName() );
+        }
+
+        return value;
+    }
+
+    /**
+     * Evaluates Filename Mapping
+     * 
+     * @param expression
+     * @param artifact
+     * @return expression
+     * @throws AssemblyFormattingException 
+     * @throws org.apache.maven.plugin.MojoExecutionException
+     */
+    public static String evaluateFileNameMapping( String expression, Artifact artifact )
+        throws AssemblyFormattingException
+    {
+        String value = expression;
+
+        // insert the classifier if exist
+        if ( !StringUtils.isEmpty( artifact.getClassifier() ) )
+        {
+            int dotIdx = value.lastIndexOf( "." );
+
+            if ( dotIdx >= 0 )
+            {
+                String extension = value.substring( dotIdx + 1, value.length() );
+                String artifactWithoutExt = value.substring( 0, dotIdx );
+
+                value = artifactWithoutExt + "-" + artifact.getClassifier() + "." + extension;
+            }
+            else
+            {
+                value = value + "-" + artifact.getClassifier();
+            }
+        }
+
+        // this matches the last ${...} string
+        Pattern pat = Pattern.compile( "^(.*)\\$\\{([^\\}]+)\\}(.*)$" );
+        Matcher mat = pat.matcher( expression );
+
+        if ( mat.matches() )
+        {
+            Object middle;
+            String left = evaluateFileNameMapping( mat.group( 1 ), artifact );
+            try
+            {
+                middle = ReflectionValueExtractor.evaluate( mat.group( 2 ), artifact, false
);
+            }
+            catch ( Exception e )
+            {
+                throw new AssemblyFormattingException( "Cannot evaluate filenameMapping:
'" + mat.group( 2 ) + "': "
+                    + e.getMessage(), e );
+            }
+            String right = mat.group( 3 );
+
+            if ( middle == null )
+            {
+                // TODO: There should be a more generic way dealing with that.
+                // Having magic words is not good at all.
+                // probe for magic word
+                if ( "extension".equals( mat.group( 2 ).trim() ) )
+                {
+                    ArtifactHandler artifactHandler = artifact.getArtifactHandler();
+                    middle = artifactHandler.getExtension();
+                }
+                else
+                {
+                    middle = "${" + mat.group( 2 ) + "}";
+                }
+            }
+
+            value = left + middle + right;
+        }
+
+        return value;
+    }
+
+}

Propchange: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFormatUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFormatUtils.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/utils/ProjectUtils.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/utils/ProjectUtils.java?rev=422907&r1=422906&r2=422907&view=diff
==============================================================================
--- maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/utils/ProjectUtils.java
(original)
+++ maven/plugins/branches/MASSEMBLY-124/src/main/java/org/apache/maven/plugin/assembly/utils/ProjectUtils.java
Mon Jul 17 15:34:58 2006
@@ -1,14 +1,13 @@
 package org.apache.maven.plugin.assembly.utils;
 
-import java.util.ArrayList;
+import org.apache.maven.project.MavenProject;
+
+import java.io.IOException;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.project.MavenProject;
-
 public final class ProjectUtils
 {
     
@@ -37,6 +36,55 @@
         }
 
         return dependenciesSet;
+    }
+
+    public static Set getProjectModules( MavenProject project, List reactorProjects ) throws
IOException
+    {
+        Set moduleCandidates = new HashSet( reactorProjects );
+        
+        Set modules = new HashSet();
+        
+        // we temporarily add the master project to the modules set, since this set is pulling
double duty as a set of
+        // potential module parents in the tree rooted at the master project...this allows
us to use the same looping
+        // algorithm below to discover both direct modules of the master project AND modules
of those direct modules.
+        modules.add( project );
+
+        int changed = -1;
+        
+        while( changed != 0 )
+        {
+            changed = 0;
+            
+            for ( Iterator candidateIterator = moduleCandidates.iterator(); candidateIterator.hasNext();
)
+            {
+                MavenProject moduleCandidate = (MavenProject) candidateIterator.next();
+                
+                for ( Iterator parentIterator = modules.iterator(); parentIterator.hasNext();
)
+                {
+                    MavenProject potentialParent = (MavenProject) parentIterator.next();
+                    
+                    // if this parent has an entry for the module candidate in the path adjustments
map, it's a direct
+                    // module of that parent.
+                    if ( potentialParent.getModulePathAdjustment( moduleCandidate ) != null
)
+                    {
+                        // add the candidate to the list of modules (and potential parents)
+                        modules.add( moduleCandidate );
+                        
+                        // remove the candidate from the candidate pool, because it's been
verified.
+                        candidateIterator.remove();
+                        
+                        // increment the change counter, to show that we verified a new module
on this pass.
+                        changed++;
+                    }
+                }
+            }
+        }
+        
+        // remove the master project from the modules set, now that we're done using it as
a set of potential module
+        // parents...
+        modules.remove( project );
+
+        return modules;
     }
 
 }



Mime
View raw message