You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2011/08/17 17:41:55 UTC
svn commit: r1158775 - in
/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin: ./
src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/
Author: lu4242
Date: Wed Aug 17 15:41:55 2011
New Revision: 1158775
URL: http://svn.apache.org/viewvc?rev=1158775&view=rev
Log:
MYFACES-3282 Update myfaces-builder-plugin unpack goal to maven 3
Modified:
myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/pom.xml
myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/AbstractDependencyMojo.java
myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/AbstractFromConfigurationMojo.java
myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/ArtifactItem.java
myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/UnpackMojo.java
Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/pom.xml?rev=1158775&r1=1158774&r2=1158775&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/pom.xml (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/pom.xml Wed Aug 17 15:41:55 2011
@@ -44,6 +44,12 @@
<url>http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin</url>
</scm>
+ <properties>
+ <mavenVersion>2.0.9</mavenVersion>
+ <doxiaVersion>1.0</doxiaVersion>
+ <pluginTestingVersion>1.2</pluginTestingVersion>
+ </properties>
+
<build>
<plugins>
<!-- required for plexus, but we are not using this right now
@@ -96,19 +102,19 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
- <version>2.0.6</version>
+ <version>${mavenVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
- <version>2.0.6</version>
+ <version>${mavenVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
- <version>2.1</version>
+ <version>2.3</version>
</dependency>
<dependency>
@@ -209,13 +215,13 @@
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-sink-api</artifactId>
- <version>1.0</version>
+ <version>${doxiaVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-site-renderer</artifactId>
- <version>1.0</version>
+ <version>${doxiaVersion}</version>
</dependency>
<dependency>
@@ -227,7 +233,7 @@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
- <version>1.5.15</version>
+ <version>3.0</version>
</dependency>
<!-- End Reporting required API -->
Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/AbstractDependencyMojo.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/AbstractDependencyMojo.java?rev=1158775&r1=1158774&r2=1158775&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/AbstractDependencyMojo.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/AbstractDependencyMojo.java Wed Aug 17 15:41:55 2011
@@ -23,8 +23,11 @@ import java.io.File;
import java.lang.reflect.Field;
import java.util.List;
+import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactCollector;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.dependency.utils.DependencySilentLog;
@@ -49,25 +52,21 @@ public abstract class AbstractDependency
{
/**
* Used to look up Artifacts in the remote repository.
- *
- * @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}"
- * @required
- * @readonly
+ *
+ * @component
*/
- protected org.apache.maven.artifact.factory.ArtifactFactory factory;
+ protected ArtifactFactory factory;
/**
* Used to look up Artifacts in the remote repository.
- *
- * @parameter expression="${component.org.apache.maven.artifact.resolver.ArtifactResolver}"
- * @required
- * @readonly
+ *
+ * @component
*/
- protected org.apache.maven.artifact.resolver.ArtifactResolver resolver;
+ protected ArtifactResolver resolver;
/**
* Artifact collector, needed to resolve dependencies.
- *
+ *
* @component role="org.apache.maven.artifact.resolver.ArtifactCollector"
* @required
* @readonly
@@ -84,34 +83,32 @@ public abstract class AbstractDependency
/**
* Location of the local repository.
- *
+ *
* @parameter expression="${localRepository}"
* @readonly
* @required
*/
- protected org.apache.maven.artifact.repository.ArtifactRepository local;
+ private ArtifactRepository local;
/**
* List of Remote Repositories used by the resolver
- *
+ *
* @parameter expression="${project.remoteArtifactRepositories}"
* @readonly
* @required
*/
- protected java.util.List remoteRepos;
+ protected List<ArtifactRepository> remoteRepos;
/**
* To look up Archiver/UnArchiver implementations
- *
- * @parameter expression="${component.org.codehaus.plexus.archiver.manager.ArchiverManager}"
- * @required
- * @readonly
+ *
+ * @component
*/
protected ArchiverManager archiverManager;
/**
* POM
- *
+ *
* @parameter expression="${project}"
* @readonly
* @required
@@ -120,16 +117,16 @@ public abstract class AbstractDependency
/**
* Contains the full list of projects in the reactor.
- *
+ *
* @parameter expression="${reactorProjects}"
* @required
* @readonly
*/
- protected List reactorProjects;
+ protected List<MavenProject> reactorProjects;
/**
* If the plugin should be silent.
- *
+ *
* @optional
* @since 2.0
* @parameter expression="${silent}"
@@ -139,7 +136,7 @@ public abstract class AbstractDependency
/**
* Output absolute filename for resolved artifacts
- *
+ *
* @optional
* @since 2.0
* @parameter expression="${outputAbsoluteArtifactFilename}"
@@ -152,7 +149,7 @@ public abstract class AbstractDependency
/**
* @return Returns the log.
*/
- public Log getLog ()
+ public Log getLog()
{
if ( silent )
{
@@ -169,21 +166,21 @@ public abstract class AbstractDependency
/**
* @return Returns the archiverManager.
*/
- public ArchiverManager getArchiverManager ()
+ public ArchiverManager getArchiverManager()
{
return this.archiverManager;
}
/**
* Does the actual copy of the file and logging.
- *
+ *
* @param artifact represents the file to copy.
* @param destFile file name of destination file.
- *
+ *
* @throws MojoExecutionException with a message if an
* error occurs.
*/
- protected void copyFile ( File artifact, File destFile )
+ protected void copyFile( File artifact, File destFile )
throws MojoExecutionException
{
Log theLog = this.getLog();
@@ -201,7 +198,7 @@ public abstract class AbstractDependency
}
}
- protected void unpack ( File file, File location )
+ protected void unpack( File file, File location )
throws MojoExecutionException
{
unpack( file, location, null, null );
@@ -209,25 +206,20 @@ public abstract class AbstractDependency
/**
* Unpacks the archive file.
- *
+ *
* @param file File to be unpacked.
- * @param location Location where to put the unpacked
- * files.
- * @param includes Comma separated list of file patterns
- * to include i.e. **\/*.xml,
- * **\/*.properties
- * @param excludes Comma separated list of file patterns
- * to exclude i.e. **\/*.xml,
- * **\/*.properties
+ * @param location Location where to put the unpacked files.
+ * @param includes Comma separated list of file patterns to include i.e. <code>**/.xml,
+ * **/*.properties</code>
+ * @param excludes Comma separated list of file patterns to exclude i.e. <code>**/*.xml,
+ * **/*.properties</code>
*/
- protected void unpack ( File file, File location, String includes, String excludes )
+ protected void unpack( File file, File location, String includes, String excludes )
throws MojoExecutionException
{
try
{
- getLog().info(
- "Unpacking " + file.getPath() + "to\n " + location.getPath()
- + "\nwith Includes " + includes + " and excludes:" + excludes );
+ logUnpack( file, location, includes, excludes );
location.mkdirs();
@@ -244,10 +236,7 @@ public abstract class AbstractDependency
// Create the selectors that will filter
// based on include/exclude parameters
// MDEP-47
- IncludeExcludeFileSelector[] selectors = new IncludeExcludeFileSelector[]
- {
- new IncludeExcludeFileSelector()
- };
+ IncludeExcludeFileSelector[] selectors = new IncludeExcludeFileSelector[] { new IncludeExcludeFileSelector() };
if ( StringUtils.isNotEmpty( excludes ) )
{
@@ -280,11 +269,9 @@ public abstract class AbstractDependency
}
}
- private void silenceUnarchiver ( UnArchiver unArchiver )
+ private void silenceUnarchiver( UnArchiver unArchiver )
{
- // dangerous but handle any errors. It's the only
- // way to silence the
- // unArchiver.
+ // dangerous but handle any errors. It's the only way to silence the unArchiver.
try
{
Field field = ReflectionUtils.getFieldByNameIncludingSuperclasses( "logger", unArchiver.getClass() );
@@ -295,15 +282,14 @@ public abstract class AbstractDependency
}
catch ( Exception e )
{
- // was a nice try. Don't bother logging because
- // the log is silent.
+ // was a nice try. Don't bother logging because the log is silent.
}
}
/**
* @return Returns the factory.
*/
- public org.apache.maven.artifact.factory.ArtifactFactory getFactory ()
+ public ArtifactFactory getFactory()
{
return this.factory;
}
@@ -311,7 +297,7 @@ public abstract class AbstractDependency
/**
* @param factory The factory to set.
*/
- public void setFactory ( org.apache.maven.artifact.factory.ArtifactFactory factory )
+ public void setFactory( ArtifactFactory factory )
{
this.factory = factory;
}
@@ -319,7 +305,7 @@ public abstract class AbstractDependency
/**
* @return Returns the project.
*/
- public MavenProject getProject ()
+ public MavenProject getProject()
{
return this.project;
}
@@ -327,7 +313,7 @@ public abstract class AbstractDependency
/**
* @return Returns the local.
*/
- public org.apache.maven.artifact.repository.ArtifactRepository getLocal ()
+ protected ArtifactRepository getLocal()
{
return this.local;
}
@@ -335,7 +321,7 @@ public abstract class AbstractDependency
/**
* @param local The local to set.
*/
- public void setLocal ( org.apache.maven.artifact.repository.ArtifactRepository local )
+ public void setLocal( ArtifactRepository local )
{
this.local = local;
}
@@ -343,7 +329,7 @@ public abstract class AbstractDependency
/**
* @return Returns the remoteRepos.
*/
- public java.util.List getRemoteRepos ()
+ public List<ArtifactRepository> getRemoteRepos()
{
return this.remoteRepos;
}
@@ -351,7 +337,7 @@ public abstract class AbstractDependency
/**
* @param remoteRepos The remoteRepos to set.
*/
- public void setRemoteRepos ( java.util.List remoteRepos )
+ public void setRemoteRepos( List<ArtifactRepository> remoteRepos )
{
this.remoteRepos = remoteRepos;
}
@@ -359,7 +345,7 @@ public abstract class AbstractDependency
/**
* @return Returns the resolver.
*/
- public org.apache.maven.artifact.resolver.ArtifactResolver getResolver ()
+ public org.apache.maven.artifact.resolver.ArtifactResolver getResolver()
{
return this.resolver;
}
@@ -367,7 +353,7 @@ public abstract class AbstractDependency
/**
* @param resolver The resolver to set.
*/
- public void setResolver ( org.apache.maven.artifact.resolver.ArtifactResolver resolver )
+ public void setResolver( ArtifactResolver resolver )
{
this.resolver = resolver;
}
@@ -375,7 +361,7 @@ public abstract class AbstractDependency
/**
* @param archiverManager The archiverManager to set.
*/
- public void setArchiverManager ( ArchiverManager archiverManager )
+ public void setArchiverManager( ArchiverManager archiverManager )
{
this.archiverManager = archiverManager;
}
@@ -383,16 +369,15 @@ public abstract class AbstractDependency
/**
* @return Returns the artifactCollector.
*/
- public ArtifactCollector getArtifactCollector ()
+ public ArtifactCollector getArtifactCollector()
{
return this.artifactCollector;
}
/**
- * @param theArtifactCollector The artifactCollector to
- * set.
+ * @param theArtifactCollector The artifactCollector to set.
*/
- public void setArtifactCollector ( ArtifactCollector theArtifactCollector )
+ public void setArtifactCollector( ArtifactCollector theArtifactCollector )
{
this.artifactCollector = theArtifactCollector;
}
@@ -400,17 +385,53 @@ public abstract class AbstractDependency
/**
* @return Returns the artifactMetadataSource.
*/
- public ArtifactMetadataSource getArtifactMetadataSource ()
+ public ArtifactMetadataSource getArtifactMetadataSource()
{
return this.artifactMetadataSource;
}
/**
- * @param theArtifactMetadataSource The
- * artifactMetadataSource to set.
+ * @param theArtifactMetadataSource The artifactMetadataSource to set.
*/
- public void setArtifactMetadataSource ( ArtifactMetadataSource theArtifactMetadataSource )
+ public void setArtifactMetadataSource( ArtifactMetadataSource theArtifactMetadataSource )
{
this.artifactMetadataSource = theArtifactMetadataSource;
}
+
+ private void logUnpack( File file, File location, String includes, String excludes )
+ {
+ if ( !getLog().isInfoEnabled() )
+ {
+ return;
+ }
+
+ StringBuffer msg = new StringBuffer();
+ msg.append( "Unpacking " );
+ msg.append( file );
+ msg.append( " to " );
+ msg.append( location );
+
+ if ( includes != null && excludes != null )
+ {
+ msg.append( " with includes \"" );
+ msg.append( includes );
+ msg.append( "\" and excludes \"" );
+ msg.append( excludes );
+ msg.append( "\"" );
+ }
+ else if ( includes != null )
+ {
+ msg.append( " with includes \"" );
+ msg.append( includes );
+ msg.append( "\"" );
+ }
+ else if ( excludes != null )
+ {
+ msg.append( " with excludes \"" );
+ msg.append( excludes );
+ msg.append( "\"" );
+ }
+
+ getLog().info( msg.toString() );
+ }
}
Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/AbstractFromConfigurationMojo.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/AbstractFromConfigurationMojo.java?rev=1158775&r1=1158774&r2=1158775&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/AbstractFromConfigurationMojo.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/AbstractFromConfigurationMojo.java Wed Aug 17 15:41:55 2011
@@ -20,41 +20,49 @@
package org.apache.myfaces.buildtools.maven2.plugin.builder.unpack;
import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.Collections;
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.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.MojoExecutionException;
-//import org.apache.maven.plugin.dependency.fromConfiguration.ArtifactItem;
import org.apache.maven.plugin.dependency.utils.DependencyUtil;
import org.apache.maven.plugin.dependency.utils.filters.ArtifactItemFilter;
+import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
import org.codehaus.plexus.util.StringUtils;
/**
- * Abstract Parent class used by mojos that get Artifact information from the
- * plugin configuration as an ArrayList of ArtifactItems
+ * Abstract Parent class used by mojos that get Artifact information from the plugin configuration as an ArrayList of
+ * ArtifactItems
*
* @see ArtifactItem
* @author <a href="mailto:brianf@apache.org">Brian Fox</a>
* @version $Id$
- *
*/
public abstract class AbstractFromConfigurationMojo
extends AbstractDependencyMojo
{
+ /**
+ * Skip the execution
+ *
+ * @optional
+ * @since 2.2
+ * @parameter expression="${mdep.skip}" default-value="false"
+ */
+ private boolean skip;
/**
* Default location used for mojo unless overridden in ArtifactItem
*
- * @parameter expression="${outputDirectory}"
- * default-value="${project.build.directory}/dependency"
+ * @parameter expression="${outputDirectory}" default-value="${project.build.directory}/dependency"
* @optional
* @since 1.0
*/
@@ -88,33 +96,58 @@ public abstract class AbstractFromConfig
private boolean overWriteIfNewer;
/**
- * Collection of ArtifactItems to work on. (ArtifactItem contains groupId,
- * artifactId, version, type, classifier, location, destFile, markerFile and overwrite.)
- * See "Usage" and "Javadoc" for details.
+ * To search for artifacts within the reactor and ensure consistent behaviour between Maven 2 and Maven 3.
+ *
+ * @parameter expression="${reactorProjects}"
+ * @required
+ * @readonly
+ */
+ protected List<MavenProject> reactorProjects;
+
+ /**
+ * Collection of ArtifactItems to work on. (ArtifactItem contains groupId, artifactId, version, type, classifier,
+ * location, destFileName, markerFile and overwrite.) See <a href="./usage.html">Usage</a> for details.
*
* @parameter
* @required
* @since 1.0
*/
- private ArrayList artifactItems;
+ private List<ArtifactItem> artifactItems;
+
+ /**
+ * To look up ArtifactRepository implementation
+ *
+ * @component
+ * @readonly
+ */
+ private ArtifactRepositoryFactory artifactRepositoryManager;
+
+ /**
+ * Path to override default local repository during plugin's execution. To remove all downloaded artifacts as part
+ * of the build, set this value to a location under your project's target directory
+ *
+ * @parameter
+ * @since 2.2
+ */
+ private File localRepositoryDirectory;
+
+ /**
+ * To host and cache localRepositoryDirectory
+ */
+ private ArtifactRepository overrideLocalRepository;
abstract ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item );
/**
- * Preprocesses the list of ArtifactItems. This method defaults the
- * outputDirectory if not set and creates the output Directory if it doesn't
- * exist.
+ * Preprocesses the list of ArtifactItems. This method defaults the outputDirectory if not set and creates the
+ * output Directory if it doesn't exist.
*
- * @param removeVersion
- * remove the version from the filename.
+ * @param removeVersion remove the version from the filename.
* @return An ArrayList of preprocessed ArtifactItems
- *
- * @throws MojoExecutionException
- * with a message if an error occurs.
- *
+ * @throws MojoExecutionException with a message if an error occurs.
* @see ArtifactItem
*/
- protected ArrayList getProcessedArtifactItems( boolean removeVersion )
+ protected List<ArtifactItem> getProcessedArtifactItems( boolean removeVersion )
throws MojoExecutionException
{
if ( artifactItems == null || artifactItems.size() < 1 )
@@ -122,10 +155,8 @@ public abstract class AbstractFromConfig
throw new MojoExecutionException( "There are no artifactItems configured." );
}
- Iterator iter = artifactItems.iterator();
- while ( iter.hasNext() )
+ for ( ArtifactItem artifactItem : artifactItems )
{
- ArtifactItem artifactItem = (ArtifactItem) iter.next();
this.getLog().info( "Configured Artifact: " + artifactItem.toString() );
if ( artifactItem.getOutputDirectory() == null )
@@ -154,7 +185,7 @@ public abstract class AbstractFromConfig
}
catch ( ArtifactFilterException e )
{
- throw new MojoExecutionException (e.getMessage(),e);
+ throw new MojoExecutionException( e.getMessage(), e );
}
}
return artifactItems;
@@ -177,18 +208,12 @@ public abstract class AbstractFromConfig
}
/**
- * Resolves the Artifact from the remote repository if nessessary. If no
- * version is specified, it will be retrieved from the dependency list or
- * from the DependencyManagement section of the pom.
- *
- * @param artifactItem
- * containing information about artifact from plugin
- * configuration.
- * @return Artifact object representing the specified file.
+ * Resolves the Artifact from the remote repository if necessary. If no version is specified, it will be retrieved
+ * from the dependency list or from the DependencyManagement section of the pom.
*
- * @throws MojoExecutionException
- * with a message if the version can't be found in
- * DependencyManagement.
+ * @param artifactItem containing information about artifact from plugin configuration.
+ * @return Artifact object representing the specified file.
+ * @throws MojoExecutionException with a message if the version can't be found in DependencyManagement.
*/
protected Artifact getArtifact( ArtifactItem artifactItem )
throws MojoExecutionException
@@ -211,35 +236,38 @@ public abstract class AbstractFromConfig
if ( StringUtils.isEmpty( artifactItem.getClassifier() ) )
{
- artifact = factory.createDependencyArtifact( artifactItem.getGroupId(), artifactItem.getArtifactId(), vr,
- artifactItem.getType(), null, Artifact.SCOPE_COMPILE );
+ artifact =
+ factory.createDependencyArtifact( artifactItem.getGroupId(), artifactItem.getArtifactId(), vr,
+ artifactItem.getType(), null, Artifact.SCOPE_COMPILE );
}
else
{
- artifact = factory.createDependencyArtifact( artifactItem.getGroupId(), artifactItem.getArtifactId(), vr,
- artifactItem.getType(), artifactItem.getClassifier(),
- Artifact.SCOPE_COMPILE );
+ artifact =
+ factory.createDependencyArtifact( artifactItem.getGroupId(), artifactItem.getArtifactId(), vr,
+ artifactItem.getType(), artifactItem.getClassifier(),
+ Artifact.SCOPE_COMPILE );
}
+ // Maven 3 will search the reactor for the artifact but Maven 2 does not
+ // to keep consistent behaviour, we search the reactor ourselves.
+ Artifact result = getArtifactFomReactor( artifact );
+ if ( result != null )
+ {
+ return result;
+ }
try
{
- // mdep-50 - rolledback for now because it's breaking some
- // functionality.
+ // mdep-50 - rolledback for now because it's breaking some functionality.
/*
- * List listeners = new ArrayList();
- *
- * Set theSet = new HashSet(); theSet.add( artifact );
- * ArtifactResolutionResult artifactResolutionResult =
- * artifactCollector.collect( theSet, project .getArtifact(),
- * managedVersions, this.local,
- * project.getRemoteArtifactRepositories(), artifactMetadataSource,
- * null, listeners ); Iterator iter =
- * artifactResolutionResult.getArtifactResolutionNodes().iterator();
- * while ( iter.hasNext() ) { ResolutionNode node = (ResolutionNode)
- * iter.next(); artifact = node.getArtifact(); }
+ * List listeners = new ArrayList(); Set theSet = new HashSet(); theSet.add( artifact );
+ * ArtifactResolutionResult artifactResolutionResult = artifactCollector.collect( theSet, project
+ * .getArtifact(), managedVersions, this.local, project.getRemoteArtifactRepositories(),
+ * artifactMetadataSource, null, listeners ); Iterator iter =
+ * artifactResolutionResult.getArtifactResolutionNodes().iterator(); while ( iter.hasNext() ) {
+ * ResolutionNode node = (ResolutionNode) iter.next(); artifact = node.getArtifact(); }
*/
- resolver.resolve( artifact, remoteRepos, local );
+ resolver.resolve( artifact, remoteRepos, getLocal() );
}
catch ( ArtifactResolutionException e )
{
@@ -254,24 +282,90 @@ public abstract class AbstractFromConfig
}
/**
- * Tries to find missing version from dependancy list and dependency
- * management. If found, the artifact is updated with the correct version.
+ * Checks to see if the specified artifact is available from the reactor.
+ * @param artifact The artifact we are looking for.
+ * @return The resolved artifact that is the same as the one we were looking for or <code>null</code> if one could
+ * not be found.
+ */
+ private Artifact getArtifactFomReactor( Artifact artifact )
+ {
+ // check project dependencies first off
+ for ( Artifact a : (Set<Artifact>) project.getArtifacts() )
+ {
+ if ( equals( artifact, a ) && hasFile( a ) )
+ {
+ return a;
+ }
+ }
+ // check reactor projects
+ for ( MavenProject p : reactorProjects == null ? Collections.<MavenProject>emptyList() : reactorProjects )
+ {
+ // check the main artifact
+ if ( equals( artifact, p.getArtifact() ) && hasFile( p.getArtifact() ) )
+ {
+ return p.getArtifact();
+ }
+ // check any side artifacts
+ for ( Artifact a : (List<Artifact>) p.getAttachedArtifacts() )
+ {
+ if ( equals( artifact, a ) && hasFile( a ) )
+ {
+ return a;
+ }
+ }
+ }
+ // not available
+ return null;
+ }
+
+ /**
+ * Returns <code>true</code> if the artifact has a file.
+ * @param artifact the artifact (may be null)
+ * @return <code>true</code> if and only if the artifact is non-null and has a file.
+ */
+ private static boolean hasFile( Artifact artifact )
+ {
+ return artifact != null && artifact.getFile() != null && artifact.getFile().isFile();
+ }
+
+ /**
+ * Null-safe compare of two artifacts based on groupId, artifactId, version, type and classifier.
+ * @param a the first artifact.
+ * @param b the second artifact.
+ * @return <code>true</code> if and only if the two artifacts have the same groupId, artifactId, version,
+ * type and classifier.
+ */
+ private static boolean equals( Artifact a, Artifact b )
+ {
+ return a == b
+ || !( a == null || b == null )
+ && StringUtils.equals( a.getGroupId(), b.getGroupId() )
+ && StringUtils.equals( a.getArtifactId(), b.getArtifactId() )
+ && StringUtils.equals( a.getVersion(), b.getVersion() )
+ && StringUtils.equals( a.getType(), b.getType() )
+ && StringUtils.equals( a.getClassifier(), b.getClassifier() );
+ }
+
+ /**
+ * Tries to find missing version from dependency list and dependency management. If found, the artifact is updated
+ * with the correct version. It will first look for an exact match on artifactId/groupId/classifier/type and if it
+ * doesn't find a match, it will try again looking for artifactId and groupId only.
*
- * It will first look for an exact match on artifactId/groupId/classifier/type and if it doesn't find
- * a match, it will try again looking for artifactId and groupId only.
- * @param artifact
- * representing configured file.
+ * @param artifact representing configured file.
* @throws MojoExecutionException
*/
private void fillMissingArtifactVersion( ArtifactItem artifact )
throws MojoExecutionException
{
- if ( !findDependencyVersion( artifact, project.getDependencies(), false )
- && ( project.getDependencyManagement() == null || !findDependencyVersion( artifact, project
- .getDependencyManagement().getDependencies(), false ) )
- && !findDependencyVersion( artifact, project.getDependencies(), true )
- && ( project.getDependencyManagement() == null || !findDependencyVersion( artifact, project
- .getDependencyManagement().getDependencies(), true ) ) )
+ List<Dependency> deps = project.getDependencies();
+ List<Dependency> depMngt = project.getDependencyManagement() == null
+ ? Collections.<Dependency>emptyList()
+ : project.getDependencyManagement().getDependencies();
+
+ if ( !findDependencyVersion( artifact, deps, false )
+ && ( project.getDependencyManagement() == null || !findDependencyVersion( artifact, depMngt, false ) )
+ && !findDependencyVersion( artifact, deps, true )
+ && ( project.getDependencyManagement() == null || !findDependencyVersion( artifact, depMngt, true ) ) )
{
throw new MojoExecutionException( "Unable to find artifact version of " + artifact.getGroupId() + ":"
+ artifact.getArtifactId() + " in either dependency list or in project's dependency management." );
@@ -279,87 +373,88 @@ public abstract class AbstractFromConfig
}
/**
- * Tries to find missing version from a list of dependencies. If found, the
- * artifact is updated with the correct version.
+ * Tries to find missing version from a list of dependencies. If found, the artifact is updated with the correct
+ * version.
*
- * @param artifact
- * representing configured file.
- * @param list
- * list of dependencies to search.
- * @param looseMatch
- * only look at artifactId and groupId
+ * @param artifact representing configured file.
+ * @param dependencies list of dependencies to search.
+ * @param looseMatch only look at artifactId and groupId
* @return the found dependency
*/
- private boolean findDependencyVersion( ArtifactItem artifact, List list, boolean looseMatch )
+ private boolean findDependencyVersion( ArtifactItem artifact, List<Dependency> dependencies, boolean looseMatch )
{
- boolean result = false;
-
- for ( int i = 0; i < list.size(); i++ )
+ for ( Dependency dependency : dependencies )
{
- Dependency dependency = (Dependency) list.get( i );
if ( StringUtils.equals( dependency.getArtifactId(), artifact.getArtifactId() )
&& StringUtils.equals( dependency.getGroupId(), artifact.getGroupId() )
&& ( looseMatch || StringUtils.equals( dependency.getClassifier(), artifact.getClassifier() ) )
&& ( looseMatch || StringUtils.equals( dependency.getType(), artifact.getType() ) ) )
{
-
artifact.setVersion( dependency.getVersion() );
- result = true;
- break;
+ return true;
}
}
- return result;
+ return false;
}
- /* private Map createManagedVersionMap( ArtifactFactory artifactFactory, String projectId,
- DependencyManagement dependencyManagement )
- throws MojoExecutionException
+ /*
+ * private Map createManagedVersionMap( ArtifactFactory artifactFactory, String projectId, DependencyManagement
+ * dependencyManagement ) throws MojoExecutionException { Map map; if ( dependencyManagement != null &&
+ * dependencyManagement.getDependencies() != null ) { map = new HashMap(); for ( Iterator i =
+ * dependencyManagement.getDependencies().iterator(); i.hasNext(); ) { Dependency d = (Dependency) i.next(); try {
+ * VersionRange versionRange = VersionRange.createFromVersionSpec( d.getVersion() ); Artifact artifact =
+ * artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(), versionRange, d.getType(), d
+ * .getClassifier(), d.getScope(), d .isOptional() ); map.put( d.getManagementKey(), artifact ); } catch (
+ * InvalidVersionSpecificationException e ) { throw new MojoExecutionException( "Unable to parse version", e ); } }
+ * } else { map = Collections.EMPTY_MAP; } return map; }
+ */
+
+ /**
+ * Override the base to
+ *
+ * @return Returns the local.
+ */
+ protected ArtifactRepository getLocal()
{
- Map map;
- if ( dependencyManagement != null && dependencyManagement.getDependencies() != null )
+ if ( this.overrideLocalRepository != null )
{
- map = new HashMap();
- for ( Iterator i = dependencyManagement.getDependencies().iterator(); i.hasNext(); )
- {
- Dependency d = (Dependency) i.next();
+ return this.overrideLocalRepository;
+ }
- try
- {
- VersionRange versionRange = VersionRange.createFromVersionSpec( d.getVersion() );
- Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(),
- versionRange, d.getType(), d
- .getClassifier(), d.getScope(), d
- .isOptional() );
- map.put( d.getManagementKey(), artifact );
- }
- catch ( InvalidVersionSpecificationException e )
- {
- throw new MojoExecutionException( "Unable to parse version", e );
- }
- }
+ ArtifactRepository local = super.getLocal();
+
+ if ( this.localRepositoryDirectory != null )
+ {
+ // create a new local repo using existing layout, snapshots, and releases policy
+ String url = "file://" + this.localRepositoryDirectory.getAbsolutePath();
+ this.overrideLocalRepository =
+ artifactRepositoryManager.createArtifactRepository( local.getId(), url, local.getLayout(),
+ local.getSnapshots(), local.getReleases() );
+
+ this.getLog().debug( "Execution local repository is at: " + this.overrideLocalRepository.getBasedir() );
}
else
{
- map = Collections.EMPTY_MAP;
+ this.overrideLocalRepository = local;
}
- return map;
- }*/
+
+ return this.overrideLocalRepository;
+ }
/**
* @return Returns the artifactItems.
*/
- public ArrayList getArtifactItems()
+ public List<ArtifactItem> getArtifactItems()
{
return this.artifactItems;
}
/**
- * @param theArtifactItems
- * The artifactItems to set.
+ * @param theArtifactItems The artifactItems to set.
*/
- public void setArtifactItems( ArrayList theArtifactItems )
+ public void setArtifactItems( List<ArtifactItem> theArtifactItems )
{
this.artifactItems = theArtifactItems;
}
@@ -373,8 +468,7 @@ public abstract class AbstractFromConfig
}
/**
- * @param theOutputDirectory
- * The outputDirectory to set.
+ * @param theOutputDirectory The outputDirectory to set.
*/
public void setOutputDirectory( File theOutputDirectory )
{
@@ -390,8 +484,7 @@ public abstract class AbstractFromConfig
}
/**
- * @param theOverWriteIfNewer
- * The overWriteIfNewer to set.
+ * @param theOverWriteIfNewer The overWriteIfNewer to set.
*/
public void setOverWriteIfNewer( boolean theOverWriteIfNewer )
{
@@ -407,8 +500,7 @@ public abstract class AbstractFromConfig
}
/**
- * @param theOverWriteReleases
- * The overWriteReleases to set.
+ * @param theOverWriteReleases The overWriteReleases to set.
*/
public void setOverWriteReleases( boolean theOverWriteReleases )
{
@@ -424,11 +516,25 @@ public abstract class AbstractFromConfig
}
/**
- * @param theOverWriteSnapshots
- * The overWriteSnapshots to set.
+ * @param theOverWriteSnapshots The overWriteSnapshots to set.
*/
public void setOverWriteSnapshots( boolean theOverWriteSnapshots )
{
this.overWriteSnapshots = theOverWriteSnapshots;
}
+
+ public void setLocalRepositoryDirectory( File localRepositoryDirectory )
+ {
+ this.localRepositoryDirectory = localRepositoryDirectory;
+ }
+
+ public boolean isSkip()
+ {
+ return skip;
+ }
+
+ public void setSkip( boolean skip )
+ {
+ this.skip = skip;
+ }
}
Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/ArtifactItem.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/ArtifactItem.java?rev=1158775&r1=1158774&r2=1158775&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/ArtifactItem.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/ArtifactItem.java Wed Aug 17 15:41:55 2011
@@ -22,12 +22,13 @@ package org.apache.myfaces.buildtools.ma
import java.io.File;
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.dependency.utils.DependencyUtil;
import org.codehaus.plexus.util.StringUtils;
/**
* ArtifactItem represents information specified in the plugin configuration
* section for each artifact.
- *
+ *
* @since 1.0
* @author <a href="mailto:brianf@apache.org">Brian Fox</a>
* @version $Id$
@@ -36,7 +37,7 @@ public class ArtifactItem extends org.ap
{
/**
* Group Id of Artifact
- *
+ *
* @parameter
* @required
*/
@@ -44,7 +45,7 @@ public class ArtifactItem extends org.ap
/**
* Name of Artifact
- *
+ *
* @parameter
* @required
*/
@@ -52,14 +53,14 @@ public class ArtifactItem extends org.ap
/**
* Version of Artifact
- *
+ *
* @parameter
*/
private String version = null;
/**
* Type of Artifact (War,Jar,etc)
- *
+ *
* @parameter
* @required
*/
@@ -67,21 +68,21 @@ public class ArtifactItem extends org.ap
/**
* Classifier for Artifact (tests,sources,etc)
- *
+ *
* @parameter
*/
private String classifier;
/**
* Location to use for this Artifact. Overrides default location.
- *
+ *
* @parameter
*/
private File outputDirectory;
/**
* Provides ability to change destination file name
- *
+ *
* @parameter
*/
private String destFileName;
@@ -100,7 +101,7 @@ public class ArtifactItem extends org.ap
* Artifact Item
*/
private Artifact artifact;
-
+
/**
* A comma separated list of file patterns to include when unpacking the
* artifact.
@@ -130,14 +131,11 @@ public class ArtifactItem extends org.ap
private String filterEmptyString( String in )
{
- if ( in == null || in.equals( "" ) )
+ if ( "".equals( in ) )
{
return null;
}
- else
- {
- return in;
- }
+ return in;
}
/**
@@ -322,37 +320,37 @@ public class ArtifactItem extends org.ap
{
this.artifact = artifact;
}
-
+
/**
* @return Returns a comma separated list of excluded items
*/
public String getExcludes ()
{
- return this.excludes;
+ return DependencyUtil.cleanToBeTokenizedString( this.excludes );
}
-
+
/**
- * @param excludes
- * A comma seperated list of items to exclude
- * i.e. **\/*.xml, **\/*.properties
+ * @param excludes
+ * A comma separated list of items to exclude
+ * i.e. <code>**\/*.xml, **\/*.properties</code>
*/
public void setExcludes ( String excludes )
{
this.excludes = excludes;
}
-
+
/**
- * @return Returns a comma seperated list of included items
+ * @return Returns a comma separated list of included items
*/
public String getIncludes()
{
- return this.includes;
+ return DependencyUtil.cleanToBeTokenizedString( this.includes );
}
/**
* @param includes
- * A comma seperated list of items to inmclude
- * i.e. **\/*.xml, **\/*.properties
+ * A comma separated list of items to include
+ * i.e. <code>**\/*.xml, **\/*.properties</code>
*/
public void setIncludes ( String includes )
{
Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/UnpackMojo.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/UnpackMojo.java?rev=1158775&r1=1158774&r2=1158775&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/UnpackMojo.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/UnpackMojo.java Wed Aug 17 15:41:55 2011
@@ -108,30 +108,32 @@ public class UnpackMojo extends Abstract
* @parameter expression="${project.build.directory}/dependency-maven-plugin-markers"
*/
private File markersDirectory;
-
+
/**
- * A comma separated list of file patterns to include when unpacking the
- * artifact. i.e. **\/*.xml,**\/*.properties
- * @since 2.0-alpha-5
+ * A comma separated list of file patterns to include when unpacking the artifact. i.e. **\/*.xml,**\/*.properties
+ * NOTE: Excludes patterns override the includes. (component code = return isIncluded( name ) AND !isExcluded( name
+ * );)
+ *
+ * @since 2.0-alpha-5
* @parameter expression="${mdep.unpack.includes}"
*/
private String includes;
/**
- * A comma separated list of file patterns to exclude when unpacking the
- * artifact. i.e. **\/*.xml,**\/*.properties
+ * A comma separated list of file patterns to exclude when unpacking the artifact. i.e. **\/*.xml,**\/*.properties
+ * NOTE: Excludes patterns override the includes. (component code = return isIncluded( name ) AND !isExcluded( name
+ * );)
+ *
* @since 2.0-alpha-5
* @parameter expression="${mdep.unpack.excludes}"
*/
private String excludes;
/**
- * Main entry into mojo. This method gets the ArtifactItems and iterates
- * through each one passing it to unpackArtifact.
- *
- * @throws MojoExecutionException
- * with a message if an error occurs.
+ * Main entry into mojo. This method gets the ArtifactItems and iterates through each one passing it to
+ * unpackArtifact.
*
+ * @throws MojoExecutionException with a message if an error occurs.
* @see ArtifactItem
* @see #getArtifactItems
* @see #unpackArtifact(ArtifactItem)
@@ -139,17 +141,19 @@ public class UnpackMojo extends Abstract
public void execute()
throws MojoExecutionException
{
+ if ( isSkip() )
+ {
+ return;
+ }
+
String existingFiles = scanAndAddExistingFilesAsExcluded(
baseDirectory1, baseDirectory2);
String excludedFiles = null;
- ArrayList processedItems = getProcessedArtifactItems( false );
- Iterator iter = processedItems.iterator();
- while ( iter.hasNext() )
+ List<ArtifactItem> processedItems = getProcessedArtifactItems( false );
+ for ( ArtifactItem artifactItem : processedItems )
{
- ArtifactItem artifactItem = (ArtifactItem) iter.next();
-
if ( artifactItem.isNeedsProcessing() )
{
if (scanModel)
@@ -184,26 +188,18 @@ public class UnpackMojo extends Abstract
/**
* This method gets the Artifact object and calls DependencyUtil.unpackFile.
*
- * @param artifactItem
- * containing the information about the Artifact to unpack.
- *
- * @throws MojoExecutionException
- * with a message if an error occurs.
- *
+ * @param artifactItem containing the information about the Artifact to unpack.
+ * @throws MojoExecutionException with a message if an error occurs.
* @see #getArtifact
- * @see DependencyUtil#unpackFile(Artifact, File, File, ArchiverManager,
- * Log)
+ * @see DependencyUtil#unpackFile(Artifact, File, File, ArchiverManager, Log)
*/
private void unpackArtifact( ArtifactItem artifactItem )
throws MojoExecutionException
{
MarkerHandler handler = new UnpackFileMarkerHandler( artifactItem, this.markersDirectory );
-
- unpack(
- artifactItem.getArtifact().getFile(),
- artifactItem.getOutputDirectory(),
- artifactItem.getIncludes(),
- artifactItem.getExcludes());
+
+ unpack( artifactItem.getArtifact().getFile(), artifactItem.getOutputDirectory(), artifactItem.getIncludes(),
+ artifactItem.getExcludes() );
handler.setMarker();
}
@@ -214,20 +210,18 @@ public class UnpackMojo extends Abstract
return new MarkerFileFilter( this.isOverWriteReleases(), this.isOverWriteSnapshots(),
this.isOverWriteIfNewer(), handler );
}
-
- protected ArrayList getProcessedArtifactItems(boolean removeVersion)
- throws MojoExecutionException
+
+ protected List<ArtifactItem> getProcessedArtifactItems( boolean removeVersion )
+ throws MojoExecutionException
{
- ArrayList items = super.getProcessedArtifactItems( removeVersion );
- Iterator iter = items.iterator();
- while ( iter.hasNext() )
+ List<ArtifactItem> items = super.getProcessedArtifactItems( removeVersion );
+ for ( ArtifactItem artifactItem : items )
{
- ArtifactItem artifactItem = (ArtifactItem) iter.next();
- if ( StringUtils.isEmpty(artifactItem.getIncludes()) )
+ if ( StringUtils.isEmpty( artifactItem.getIncludes() ) )
{
artifactItem.setIncludes( getIncludes() );
}
- if ( StringUtils.isEmpty(artifactItem.getExcludes()) )
+ if ( StringUtils.isEmpty( artifactItem.getExcludes() ) )
{
artifactItem.setExcludes( getExcludes() );
}
@@ -426,33 +420,29 @@ public class UnpackMojo extends Abstract
}
/**
- * @param theMarkersDirectory
- * The markersDirectory to set.
+ * @param theMarkersDirectory The markersDirectory to set.
*/
public void setMarkersDirectory( File theMarkersDirectory )
{
this.markersDirectory = theMarkersDirectory;
}
-
-
+
/**
* @return Returns a comma separated list of excluded items
*/
- public String getExcludes ()
+ public String getExcludes()
{
return this.excludes;
}
-
+
/**
- * @param excludes
- * A comma separated list of items to exclude
- * i.e. **\/*.xml, **\/*.properties
+ * @param excludes A comma separated list of items to exclude i.e. **\/*.xml, **\/*.properties
*/
- public void setExcludes ( String excludes )
+ public void setExcludes( String excludes )
{
this.excludes = excludes;
}
-
+
/**
* @return Returns a comma separated list of included items
*/
@@ -462,11 +452,9 @@ public class UnpackMojo extends Abstract
}
/**
- * @param includes
- * A comma separated list of items to include
- * i.e. **\/*.xml, **\/*.properties
+ * @param includes A comma separated list of items to include i.e. **\/*.xml, **\/*.properties
*/
- public void setIncludes ( String includes )
+ public void setIncludes( String includes )
{
this.includes = includes;
}