diff --git a/maven-core-it-runner/pom.xml b/maven-core-it-runner/pom.xml
index b0c71a02e1..943f43f363 100644
--- a/maven-core-it-runner/pom.xml
+++ b/maven-core-it-runner/pom.xml
@@ -38,7 +38,7 @@ under the License.
org.apache.maven.itscore-integration-tests
- ${project.version}
+ 2.1-SNAPSHOTteststest
diff --git a/maven-core/src/main/java/org/apache/maven/ProjectCycleException.java b/maven-core/src/main/java/org/apache/maven/ProjectCycleException.java
index 97baaabd1e..149f9d0d90 100644
--- a/maven-core/src/main/java/org/apache/maven/ProjectCycleException.java
+++ b/maven-core/src/main/java/org/apache/maven/ProjectCycleException.java
@@ -1,7 +1,6 @@
package org.apache.maven;
import org.apache.maven.execution.ReactorManager;
-import org.apache.maven.project.ProjectSorter;
import org.codehaus.plexus.util.dag.CycleDetectedException;
import java.util.List;
@@ -9,7 +8,7 @@ import java.util.List;
/**
* Exception which occurs when creating a new {@link ReactorManager} instance,
* due to failure to sort the current projects. The embedded {@link CycleDetectedException}
- * is thrown by the {@link ProjectSorter}, and context of this wrapped exception
+ * is thrown by the ProjectSorter and context of this wrapped exception
* includes the list of projects that contain the cycle, along with a friendly
* rendering of the cycle message indicating that it comes from the current projects list.
*
diff --git a/maven-core/src/main/java/org/apache/maven/errors/CoreErrorReporter.java b/maven-core/src/main/java/org/apache/maven/errors/CoreErrorReporter.java
index 4f91fe4f55..7176d86522 100644
--- a/maven-core/src/main/java/org/apache/maven/errors/CoreErrorReporter.java
+++ b/maven-core/src/main/java/org/apache/maven/errors/CoreErrorReporter.java
@@ -36,7 +36,7 @@ import org.apache.maven.project.DuplicateArtifactAttachmentException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
-import org.apache.maven.project.error.ProjectErrorReporter;
+import org.apache.maven.errors.ProjectErrorReporter;
import org.apache.maven.project.interpolation.ModelInterpolationException;
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.reactor.MavenExecutionException;
diff --git a/maven-core/src/main/java/org/apache/maven/errors/CoreReporterManager.java b/maven-core/src/main/java/org/apache/maven/errors/CoreReporterManager.java
index 85da13c9af..523c9964e6 100644
--- a/maven-core/src/main/java/org/apache/maven/errors/CoreReporterManager.java
+++ b/maven-core/src/main/java/org/apache/maven/errors/CoreReporterManager.java
@@ -1,6 +1,6 @@
package org.apache.maven.errors;
-import org.apache.maven.project.error.ProjectReporterManager;
+import org.apache.maven.errors.ProjectReporterManager;
public final class CoreReporterManager
{
diff --git a/maven-core/src/main/java/org/apache/maven/errors/DefaultCoreErrorReporter.java b/maven-core/src/main/java/org/apache/maven/errors/DefaultCoreErrorReporter.java
index df48069c79..40493481cb 100644
--- a/maven-core/src/main/java/org/apache/maven/errors/DefaultCoreErrorReporter.java
+++ b/maven-core/src/main/java/org/apache/maven/errors/DefaultCoreErrorReporter.java
@@ -41,9 +41,9 @@ import org.apache.maven.project.DuplicateArtifactAttachmentException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
-import org.apache.maven.project.error.DefaultProjectErrorReporter;
-import org.apache.maven.project.error.ProjectErrorReporter;
-import org.apache.maven.project.error.ProjectReporterManager;
+import org.apache.maven.errors.DefaultProjectErrorReporter;
+import org.apache.maven.errors.ProjectErrorReporter;
+import org.apache.maven.errors.ProjectReporterManager;
import org.apache.maven.project.interpolation.ModelInterpolationException;
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.reactor.MavenExecutionException;
diff --git a/maven-project/src/main/java/org/apache/maven/project/error/DefaultProjectErrorReporter.java b/maven-core/src/main/java/org/apache/maven/errors/DefaultProjectErrorReporter.java
similarity index 94%
rename from maven-project/src/main/java/org/apache/maven/project/error/DefaultProjectErrorReporter.java
rename to maven-core/src/main/java/org/apache/maven/errors/DefaultProjectErrorReporter.java
index e3a4da071e..a9de64688f 100644
--- a/maven-project/src/main/java/org/apache/maven/project/error/DefaultProjectErrorReporter.java
+++ b/maven-core/src/main/java/org/apache/maven/errors/DefaultProjectErrorReporter.java
@@ -1,4 +1,4 @@
-package org.apache.maven.project.error;
+package org.apache.maven.errors;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -20,7 +20,7 @@ import org.apache.maven.project.InvalidProjectVersionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilderConfiguration;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
-import org.apache.maven.project.build.model.ModelAndFile;
+import org.apache.maven.project.ModelAndFile;
import org.apache.maven.project.interpolation.ModelInterpolationException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@@ -62,7 +62,7 @@ public class DefaultProjectErrorReporter
}
/**
- * @see org.apache.maven.project.error.ProjectErrorReporter#clearErrors()
+ * @see ProjectErrorReporter#clearErrors()
*/
public void clearErrors()
{
@@ -76,7 +76,7 @@ public class DefaultProjectErrorReporter
}
/**
- * @see org.apache.maven.project.error.ProjectErrorReporter#hasInformationFor(java.lang.Throwable)
+ * @see ProjectErrorReporter#hasInformationFor(java.lang.Throwable)
*/
public Throwable findReportedException( Throwable error )
{
@@ -93,7 +93,7 @@ public class DefaultProjectErrorReporter
}
/**
- * @see org.apache.maven.project.error.ProjectErrorReporter#getFormattedMessage(java.lang.Throwable)
+ * @see ProjectErrorReporter#getFormattedMessage(java.lang.Throwable)
*/
public String getFormattedMessage( Throwable error )
{
@@ -101,7 +101,7 @@ public class DefaultProjectErrorReporter
}
/**
- * @see org.apache.maven.project.error.ProjectErrorReporter#getRealCause(java.lang.Throwable)
+ * @see ProjectErrorReporter#getRealCause(java.lang.Throwable)
*/
public Throwable getRealCause( Throwable error )
{
@@ -140,7 +140,7 @@ public class DefaultProjectErrorReporter
}
/**
- * @see org.apache.maven.project.error.ProjectErrorReporter#reportActivatorErrorWhileApplyingProfiles(org.apache.maven.profiles.activation.ProfileActivator, org.apache.maven.model.Model, java.io.File, org.apache.maven.model.Profile, org.apache.maven.profiles.activation.ProfileActivationContext, org.apache.maven.profiles.activation.ProfileActivationException)
+ * @see ProjectErrorReporter#reportActivatorErrorWhileApplyingProfiles(org.apache.maven.profiles.activation.ProfileActivator, org.apache.maven.model.Model, java.io.File, org.apache.maven.model.Profile, org.apache.maven.profiles.activation.ProfileActivationContext, org.apache.maven.profiles.activation.ProfileActivationException)
*/
public void reportActivatorError( ProfileActivator activator,
Model model,
@@ -179,7 +179,7 @@ public class DefaultProjectErrorReporter
}
/**
- * @see org.apache.maven.project.error.ProjectErrorReporter#reportActivatorLookupError(java.lang.String, java.io.File, org.apache.maven.model.Profile, org.codehaus.plexus.component.repository.exception.ComponentLookupException)
+ * @see ProjectErrorReporter#reportActivatorLookupError(java.lang.String, java.io.File, org.apache.maven.model.Profile, org.codehaus.plexus.component.repository.exception.ComponentLookupException)
*/
public void reportActivatorLookupError( Model model,
File pomFile,
@@ -213,7 +213,7 @@ public class DefaultProjectErrorReporter
}
/**
- * @see org.apache.maven.project.error.ProjectErrorReporter#reportErrorLoadingExternalProfilesFromFile(org.apache.maven.model.Model, java.io.File, java.io.File, java.io.IOException)
+ * @see ProjectErrorReporter#reportErrorLoadingExternalProfilesFromFile(org.apache.maven.model.Model, java.io.File, java.io.File, java.io.IOException)
*/
public void reportErrorLoadingExternalProfilesFromFile( Model model,
File pomFile,
@@ -242,7 +242,7 @@ public class DefaultProjectErrorReporter
}
/**
- * @see org.apache.maven.project.error.ProjectErrorReporter#reportErrorLoadingExternalProfilesFromFile(org.apache.maven.model.Model, java.io.File, java.io.File, org.codehaus.plexus.util.xml.pull.XmlPullParserException)
+ * @see ProjectErrorReporter#reportErrorLoadingExternalProfilesFromFile(org.apache.maven.model.Model, java.io.File, java.io.File, org.codehaus.plexus.util.xml.pull.XmlPullParserException)
*/
public void reportErrorLoadingExternalProfilesFromFile( Model model,
File pomFile,
@@ -278,7 +278,7 @@ public class DefaultProjectErrorReporter
}
/**
- * @see org.apache.maven.project.error.ProjectErrorReporter#reportInvalidRepositoryWhileGettingRepositoriesFromProfiles(org.apache.maven.model.Repository, java.lang.String, java.io.File, org.apache.maven.artifact.InvalidRepositoryException)
+ * @see ProjectErrorReporter#reportInvalidRepositoryWhileGettingRepositoriesFromProfiles(org.apache.maven.model.Repository, java.lang.String, java.io.File, org.apache.maven.artifact.InvalidRepositoryException)
*/
public void reportInvalidRepositoryWhileGettingRepositoriesFromProfiles( Repository repo,
Model model,
diff --git a/maven-project/src/main/java/org/apache/maven/project/error/ProjectErrorReporter.java b/maven-core/src/main/java/org/apache/maven/errors/ProjectErrorReporter.java
similarity index 99%
rename from maven-project/src/main/java/org/apache/maven/project/error/ProjectErrorReporter.java
rename to maven-core/src/main/java/org/apache/maven/errors/ProjectErrorReporter.java
index 927240538e..f229b3a4c8 100644
--- a/maven-project/src/main/java/org/apache/maven/project/error/ProjectErrorReporter.java
+++ b/maven-core/src/main/java/org/apache/maven/errors/ProjectErrorReporter.java
@@ -1,4 +1,4 @@
-package org.apache.maven.project.error;
+package org.apache.maven.errors;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
@@ -17,7 +17,7 @@ import org.apache.maven.project.InvalidProjectVersionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilderConfiguration;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
-import org.apache.maven.project.build.model.ModelAndFile;
+import org.apache.maven.project.ModelAndFile;
import org.apache.maven.project.interpolation.ModelInterpolationException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
diff --git a/maven-project/src/main/java/org/apache/maven/project/error/ProjectErrorTips.java b/maven-core/src/main/java/org/apache/maven/errors/ProjectErrorTips.java
similarity index 99%
rename from maven-project/src/main/java/org/apache/maven/project/error/ProjectErrorTips.java
rename to maven-core/src/main/java/org/apache/maven/errors/ProjectErrorTips.java
index 4ea20237d6..2b9aacc6c5 100644
--- a/maven-project/src/main/java/org/apache/maven/project/error/ProjectErrorTips.java
+++ b/maven-core/src/main/java/org/apache/maven/errors/ProjectErrorTips.java
@@ -1,4 +1,4 @@
-package org.apache.maven.project.error;
+package org.apache.maven.errors;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.model.Dependency;
diff --git a/maven-project/src/main/java/org/apache/maven/project/error/ProjectReporterManager.java b/maven-core/src/main/java/org/apache/maven/errors/ProjectReporterManager.java
similarity index 93%
rename from maven-project/src/main/java/org/apache/maven/project/error/ProjectReporterManager.java
rename to maven-core/src/main/java/org/apache/maven/errors/ProjectReporterManager.java
index a51b19742b..b8b164682c 100644
--- a/maven-project/src/main/java/org/apache/maven/project/error/ProjectReporterManager.java
+++ b/maven-core/src/main/java/org/apache/maven/errors/ProjectReporterManager.java
@@ -1,4 +1,4 @@
-package org.apache.maven.project.error;
+package org.apache.maven.errors;
public final class ProjectReporterManager
{
diff --git a/maven-core/src/main/java/org/apache/maven/execution/ReactorManager.java b/maven-core/src/main/java/org/apache/maven/execution/ReactorManager.java
index 095f10e7da..fb8b13a367 100644
--- a/maven-core/src/main/java/org/apache/maven/execution/ReactorManager.java
+++ b/maven-core/src/main/java/org/apache/maven/execution/ReactorManager.java
@@ -24,14 +24,15 @@ import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.DuplicateProjectException;
import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.ProjectSorter;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.ReportPlugin;
+import org.apache.maven.model.Extension;
import org.codehaus.plexus.util.dag.CycleDetectedException;
+import org.codehaus.plexus.util.dag.DAG;
+import org.codehaus.plexus.util.dag.TopologicalSorter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
public class ReactorManager
{
@@ -188,4 +189,210 @@ public class ReactorManager
{
return buildFailuresByProject.size() + buildSuccessesByProject.size() > 1;
}
+
+ protected static class ProjectSorter
+ {
+ private final DAG dag;
+
+ private final List sortedProjects;
+
+ private MavenProject topLevelProject;
+
+ /**
+ * Sort a list of projects.
+ *
+ *
collect all the vertices for the projects that we want to build.
+ *
iterate through the deps of each project and if that dep is within
+ * the set of projects we want to build then add an edge, otherwise throw
+ * the edge away because that dependency is not within the set of projects
+ * we are trying to build. we assume a closed set.
- */
- after( List allProjectInstances ) throwing( DuplicateProjectException err ):
- execution( ProjectSorter.new( List ) )
- && args( allProjectInstances )
- {
- getReporter().reportProjectCollision( allProjectInstances, err );
- }
-
-}
diff --git a/maven-project/src/main/aspect/org/apache/maven/project/aspect/ProjectDebugAspect.aj b/maven-project/src/main/aspect/org/apache/maven/project/aspect/ProjectDebugAspect.aj
deleted file mode 100644
index 31fc4d058d..0000000000
--- a/maven-project/src/main/aspect/org/apache/maven/project/aspect/ProjectDebugAspect.aj
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.apache.maven.project.aspect;
-
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.DefaultMavenProjectBuilder;
-import org.codehaus.plexus.util.StringUtils;
-
-import java.util.List;
-
-public privileged aspect ProjectDebugAspect
-{
-
-// before( String dir, MavenProject project ):
-// cflow( execution( * DefaultMavenProjectBuilder.buildInternal( .. ) ) )
-// && call( void MavenProject.addScriptSourceRoot( String ) )
-// && args( dir )
-// && target( project )
-// {
-// System.out.println( "Setting script-source-root from POM to: " + dir + " in project: " + project.getId() );
-// }
-//
-// after( MavenProject project ) returning( List scriptSourceRoots ):
-// execution( List MavenProject.getScriptSourceRoots() )
-// && this( project )
-// {
-// System.out.println( "Using script-source-roots:\n\n" + StringUtils.join( scriptSourceRoots.iterator(), "\nfrom project: " + project.getId() ) );
-// }
-
-}
diff --git a/maven-project/src/main/aspect/org/apache/maven/project/aspect/ProjectIOErrorReporterAspect.aj b/maven-project/src/main/aspect/org/apache/maven/project/aspect/ProjectIOErrorReporterAspect.aj
deleted file mode 100644
index 88b0ba1872..0000000000
--- a/maven-project/src/main/aspect/org/apache/maven/project/aspect/ProjectIOErrorReporterAspect.aj
+++ /dev/null
@@ -1,173 +0,0 @@
-package org.apache.maven.project.aspect;
-
-import org.apache.maven.project.ProjectBuildingException;
-import org.apache.maven.model.Model;
-import org.apache.maven.project.DefaultMavenProjectBuilder;
-import org.apache.maven.project.build.model.ModelAndFile;
-import org.apache.maven.project.build.model.DefaultModelLineageBuilder;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-
-import java.io.File;
-import java.io.IOException;
-
-public privileged aspect ProjectIOErrorReporterAspect
- extends AbstractProjectErrorReporterAspect
-{
-
- private pointcut pbldr_readModel( String projectId, File pomFile ):
- execution( Model DefaultMavenProjectBuilder.readModel( String, File, boolean ) )
- && args( projectId, pomFile, * );
-
- private pointcut within_pbldr_readModel( String projectId, File pomFile ):
- within( DefaultMavenProjectBuilder )
- && cflow( pbldr_readModel( projectId, pomFile ) )
- && !cflowbelow( pbldr_readModel( String, File ) )
- && notWithinAspect();
-
- // =========================================================================
- // Call Stack:
- // =========================================================================
- // ...
- // --> DefaultMavenProjectBuilder.buildFromRepository(..)
- // --> DefaultMavenProjectBuilder.findModelFromRepository(..) (private)
- // DefaultMavenProjectBuilder.build(..)
- // --> DefaultMavenProjectBuilder.buildFromSourceFileInternal(..) (private)
- // --> DefaultMavenProjectBuilder.readModel(..) (private)
- // --> thrown XmlPullParserException
- // <------ InvalidProjectModelException
- // =========================================================================
- before( String projectId, File pomFile, XmlPullParserException cause ):
- within_pbldr_readModel( projectId, pomFile )
- && call( ProjectBuildingException.new( .., XmlPullParserException ))
- && args( .., cause )
- {
- getReporter().reportErrorParsingProjectModel( projectId, pomFile, cause );
- }
-
- // =========================================================================
- // Call Stack:
- // =========================================================================
- // ...
- // --> DefaultMavenProjectBuilder.buildFromRepository(..)
- // --> DefaultMavenProjectBuilder.findModelFromRepository(..) (private)
- // DefaultMavenProjectBuilder.build(..)
- // --> DefaultMavenProjectBuilder.buildFromSourceFileInternal(..) (private)
- // --> DefaultMavenProjectBuilder.readModel(..) (private)
- // --> thrown IOException
- // <------ InvalidProjectModelException
- // =========================================================================
- before( String projectId, File pomFile, IOException cause ):
- within_pbldr_readModel( projectId, pomFile )
- && call( ProjectBuildingException.new( .., IOException ))
- && args( .., cause )
- {
- getReporter().reportErrorParsingProjectModel( projectId, pomFile, cause );
- }
-
- private pointcut mlbldr_resolveParentPom( ModelAndFile childInfo ):
- execution( ModelAndFile DefaultModelLineageBuilder.resolveParentPom( ModelAndFile, .. ) )
- && args( childInfo, .. );
-
- private pointcut mlbldr_readModel( File pomFile ):
- execution( * DefaultModelLineageBuilder.readModel( File ) )
- && args( pomFile );
-
- private pointcut within_mlbldr_readModel( File pomFile ):
- cflow( mlbldr_readModel( pomFile ) )
- && within( DefaultModelLineageBuilder )
- && notWithinAspect();
-
- private pointcut mlbldr_errorParsingParentPom( ModelAndFile childInfo, File parentPomFile, XmlPullParserException cause ):
- cflowbelow( mlbldr_resolveParentPom( childInfo ) )
- && within_mlbldr_readModel( parentPomFile )
- && call( ProjectBuildingException.new( .., XmlPullParserException ) )
- && args( .., cause );
-
- // =========================================================================
- // Call Stack:
- // =========================================================================
- // ...
- // --> DefaultModelLineageBuilder.buildModelLineage(..)
- // --> DefaultModelLineageBuilder.resumeBuildingModelLineage(..)
- // --> DefaultModelLineageBuilder.resolveParentPom(..) (private)
- // [--> DefaultModelLineageBuilder.resolveParentWithRelativePath(..) (private)
- // --> DefaultModelLineageBuilder.readModel(..) (private)
- // --> thrown XmlPullParserException
- // <---------- ProjectBuildingException
- // =========================================================================
- before( ModelAndFile childInfo, File parentPomFile, XmlPullParserException cause ):
- mlbldr_errorParsingParentPom( childInfo, parentPomFile, cause )
- {
- getReporter().reportErrorParsingParentProjectModel( childInfo, parentPomFile, cause );
- }
-
- private pointcut mlbldr_errorReadingParentPom( ModelAndFile childInfo, File parentPomFile, IOException cause ):
- cflow( mlbldr_resolveParentPom( childInfo ) )
- && within_mlbldr_readModel( parentPomFile )
- && call( ProjectBuildingException.new( .., IOException ))
- && args( .., cause );
-
- // =========================================================================
- // Call Stack:
- // =========================================================================
- // ...
- // --> DefaultModelLineageBuilder.buildModelLineage(..)
- // --> DefaultModelLineageBuilder.resumeBuildingModelLineage(..)
- // --> DefaultModelLineageBuilder.resolveParentPom(..) (private)
- // [--> DefaultModelLineageBuilder.resolveParentWithRelativePath(..) (private)
- // --> DefaultModelLineageBuilder.readModel(..) (private)
- // --> thrown XmlPullParserException
- // <---------- ProjectBuildingException
- // =========================================================================
- before( ModelAndFile childInfo, File parentPomFile, IOException cause ):
- mlbldr_errorReadingParentPom( childInfo, parentPomFile, cause )
- {
- getReporter().reportErrorParsingParentProjectModel( childInfo, parentPomFile, cause );
- }
-
- private pointcut mlbldr_errorParsingNonParentPom( File pomFile, XmlPullParserException cause ):
- !cflow( mlbldr_resolveParentPom( ModelAndFile ) )
- && cflow( mlbldr_readModel( pomFile ) )
- && call( ProjectBuildingException.new( .., XmlPullParserException ))
- && args( .., cause )
- && within( DefaultModelLineageBuilder )
- && notWithinAspect();
-
- // =========================================================================
- // Call Stack:
- // =========================================================================
- // ...
- // --> DefaultModelLineageBuilder.buildModelLineage(..)
- // --> DefaultModelLineageBuilder.readModel(..) (private)
- // --> thrown XmlPullParserException
- // <------ ProjectBuildingException
- // =========================================================================
- before( File pomFile, XmlPullParserException cause ):
- mlbldr_errorParsingNonParentPom( pomFile, cause )
- {
- getReporter().reportErrorParsingProjectModel( "unknown", pomFile, cause );
- }
-
- private pointcut mlbldr_errorReadingNonParentPom( File pomFile, IOException cause ):
- !cflow( mlbldr_resolveParentPom( ModelAndFile ) )
- && cflow( mlbldr_readModel( pomFile ) )
- && call( ProjectBuildingException.new( .., IOException ))
- && args( .., cause )
- && within( DefaultModelLineageBuilder )
- && notWithinAspect();
-
- // =========================================================================
- // Call Stack:
- // =========================================================================
- // ...
- // --> DefaultModelLineageBuilder.buildModelLineage(..)
- // --> DefaultModelLineageBuilder.readModel(..) (private)
- // --> thrown XmlPullParserException
- // <------ ProjectBuildingException
- // =========================================================================
- before( File pomFile, IOException cause ):
- mlbldr_errorReadingNonParentPom( pomFile, cause )
- {
- getReporter().reportErrorParsingProjectModel( "unknown", pomFile, cause );
- }
-}
diff --git a/maven-project/src/main/aspect/org/apache/maven/project/aspect/ProjectReporterDebugAspect.aj b/maven-project/src/main/aspect/org/apache/maven/project/aspect/ProjectReporterDebugAspect.aj
deleted file mode 100644
index 36d6f00e1f..0000000000
--- a/maven-project/src/main/aspect/org/apache/maven/project/aspect/ProjectReporterDebugAspect.aj
+++ /dev/null
@@ -1,34 +0,0 @@
-package org.apache.maven.project.aspect;
-
-import org.apache.maven.project.error.ProjectErrorReporter;
-import org.apache.maven.project.error.DefaultProjectErrorReporter;
-import org.aspectj.lang.reflect.SourceLocation;
-
-public privileged aspect ProjectReporterDebugAspect
-{
-
-// before( Throwable key, String message, DefaultProjectErrorReporter reporter ):
-// call( void DefaultProjectErrorReporter.registerBuildError( Throwable, String, .. ) )
-// && args( key, message, .. )
-// && target( reporter )
-// {
-// SourceLocation location = thisJoinPoint.getSourceLocation();
-// System.out.println( "Registering: " + key + "\nfrom: " + location.getFileName() + ", line: " + location.getLine() + "\nreporter is: " + reporter + "\n\nMessage:\n\n" + message );
-// }
-//
-// before():
-// execution( void DefaultProjectErrorReporter.clearErrors() )
-// {
-// System.out.println( "WARNING: CLEARING ALL ERROR REPORTS." );
-// }
-//
-// after() returning( Throwable key ):
-// execution( Throwable ProjectErrorReporter+.findReportedException( Throwable ) )
-// {
-// if ( key != null )
-// {
-// System.out.println( "Found reported exception: " + key );
-// }
-// }
-
-}
diff --git a/maven-project/src/main/aspect/org/apache/maven/project/aspect/compat/Maven20xProjectCompatAspect.aj b/maven-project/src/main/aspect/org/apache/maven/project/aspect/compat/Maven20xProjectCompatAspect.aj
deleted file mode 100644
index 1bc9070ae6..0000000000
--- a/maven-project/src/main/aspect/org/apache/maven/project/aspect/compat/Maven20xProjectCompatAspect.aj
+++ /dev/null
@@ -1,114 +0,0 @@
-package org.apache.maven.project.aspect.compat;
-
-import org.apache.maven.model.Model;
-import org.apache.maven.project.build.model.ModelLineage;
-import org.apache.maven.project.build.model.ModelLineageIterator;
-import org.apache.maven.project.build.model.ModelLineageBuilder;
-import org.apache.maven.project.DefaultMavenProjectBuilder;
-import org.apache.maven.project.artifact.MavenMetadataSource;
-import org.apache.maven.profiles.build.DefaultProfileAdvisor;
-import org.apache.maven.model.Profile;
-import org.apache.maven.profiles.ProfileManager;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.Map;
-
-public privileged aspect Maven20xProjectCompatAspect
-{
-
- // FIXME: Re-enable this when we're closer to a 2.1 release.
-// private pointcut reactorProjectBuilds():
-// cflow( execution( * DefaultMavenProjectBuilder.buildFromSourceFileInternal( .. ) ) )
-// && !cflow( execution( * MavenMetadataSource.*( .. ) ) );
-//
-// private pointcut lineageBuildResumed( DefaultMavenProjectBuilder projectBuilder, ModelLineage lineage ):
-// call( * ModelLineageBuilder.resumeBuildingModelLineage( ModelLineage, .. ) )
-// && this( projectBuilder )
-// && args( lineage, .. );
-//
-// after( DefaultMavenProjectBuilder projectBuilder, ModelLineage lineage ):
-// reactorProjectBuilds()
-// && lineageBuildResumed( projectBuilder, lineage )
-// {
-// for ( ModelLineageIterator it = lineage.lineageIterator(); it.hasNext(); )
-// {
-// Model model = (Model) it.next();
-// List pluginRepos = model.getPluginRepositories();
-//
-// if ( pluginRepos != null && !pluginRepos.isEmpty() )
-// {
-// StringBuffer message = new StringBuffer();
-// message.append( "The section of the POM has been deprecated. Please update your POM (" );
-// message.append( model.getId() );
-// message.append( ")." );
-//
-// projectBuilder.logger.warn( message.toString() );
-// }
-// }
-// }
-//
-// private pointcut externalProfilesApplied( DefaultProfileAdvisor advisor, ProfileManager profileManager ):
-// execution( * DefaultProfileAdvisor.applyActivatedExternalProfiles( .., ProfileManager+ ) )
-// && this( advisor )
-// && args( .., profileManager );
-//
-//
-// private boolean settingsProfilesChecked = false;
-//
-// before( DefaultProfileAdvisor advisor, ProfileManager profileManager ):
-// reactorProjectBuilds()
-// && externalProfilesApplied( advisor, profileManager )
-// {
-// if ( profileManager == null )
-// {
-// return;
-// }
-//
-// Map profilesById = profileManager.getProfilesById();
-// Set invalidProfiles = new HashSet();
-//
-// boolean settingsProfilesEncountered = false;
-// for ( Iterator it = profilesById.values().iterator(); it.hasNext(); )
-// {
-// Profile profile = (Profile) it.next();
-//
-// if ( "settings.xml".equals( profile.getSource() ) )
-// {
-// settingsProfilesEncountered = true;
-//
-// if ( settingsProfilesChecked )
-// {
-// continue;
-// }
-// }
-//
-// List pluginRepos = profile.getPluginRepositories();
-// if ( pluginRepos != null && !pluginRepos.isEmpty() )
-// {
-// invalidProfiles.add( profile );
-// }
-// }
-//
-// if ( !invalidProfiles.isEmpty() )
-// {
-// StringBuffer message = new StringBuffer();
-// message.append( "The section of the POM has been deprecated. Please update the following profiles:\n" );
-//
-// for ( Iterator it = invalidProfiles.iterator(); it.hasNext(); )
-// {
-// Profile profile = (Profile) it.next();
-// message.append( "\n- " ).append( profile.getId() ).append( " (source: " ).append( profile.getSource() ).append( ")" );
-// }
-//
-// message.append( "\n" );
-//
-// advisor.logger.warn( message.toString() );
-// }
-//
-// settingsProfilesChecked = settingsProfilesChecked || settingsProfilesEncountered;
-// }
-
-}
diff --git a/maven-project/src/main/java/org/apache/maven/DefaultMavenTools.java b/maven-project/src/main/java/org/apache/maven/DefaultMavenTools.java
index 0855811881..736603495d 100644
--- a/maven-project/src/main/java/org/apache/maven/DefaultMavenTools.java
+++ b/maven-project/src/main/java/org/apache/maven/DefaultMavenTools.java
@@ -32,7 +32,9 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-/** @author Jason van Zyl */
+/**
+ * @author Jason van Zyl
+ */
public class DefaultMavenTools
implements MavenTools
{
@@ -94,7 +96,8 @@ public class DefaultMavenTools
if ( url == null || url.trim().length() < 1 )
{
- throw new MissingRepositoryElementException( "Repository URL must not be empty (ID is: " + id + ").", id );
+ throw new MissingRepositoryElementException( "Repository URL must not be empty (ID is: " + id + ").",
+ id );
}
ArtifactRepositoryPolicy snapshots = buildArtifactRepositoryPolicy( repo.getSnapshots() );
diff --git a/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java b/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java
index f8f297e717..d11c2d3ada 100644
--- a/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java
+++ b/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java
@@ -54,7 +54,6 @@ public class DefaultProfileManager
/**
* the properties passed to the profile manager are the props that
* are passed to maven, possibly containing profile activator properties
- *
*/
public DefaultProfileManager( PlexusContainer container, ProfileActivationContext profileActivationContext )
{
@@ -185,7 +184,7 @@ public class DefaultProfileManager
public List getActiveProfiles()
throws ProfileActivationException
{
- return getActiveProfiles( null );
+ return getActiveProfiles( null );
}
public List getActiveProfiles( Model model )
@@ -198,7 +197,8 @@ public class DefaultProfileManager
if ( ( model != null ) && ( realmManager != null ) )
{
- projectRealm = realmManager.getProjectRealm( ModelUtils.getGroupId( model ), model.getArtifactId(), ModelUtils.getVersion( model ) );
+ projectRealm = realmManager.getProjectRealm( ModelUtils.getGroupId( model ), model.getArtifactId(),
+ ModelUtils.getVersion( model ) );
oldLookupRealm = container.setLookupRealm( projectRealm );
}
@@ -241,18 +241,18 @@ public class DefaultProfileManager
{
List defaultIds = profileActivationContext.getActiveByDefaultProfileIds();
- List deactivatedIds = profileActivationContext.getExplicitlyInactiveProfileIds();
-
+ List deactivatedIds = profileActivationContext.getExplicitlyInactiveProfileIds();
+
for ( Iterator it = defaultIds.iterator(); it.hasNext(); )
{
String profileId = (String) it.next();
-
- // If this profile was excluded, don't add it back in
- // Fixes MNG-3545
- if (deactivatedIds.contains(profileId))
- {
- continue;
- }
+
+ // If this profile was excluded, don't add it back in
+ // Fixes MNG-3545
+ if ( deactivatedIds.contains( profileId ) )
+ {
+ continue;
+ }
Profile profile = (Profile) profilesById.get( profileId );
if ( profile != null )
@@ -295,7 +295,8 @@ public class DefaultProfileManager
{
if ( activator.isActive( profile, context ) )
{
- container.getLogger().debug( "Profile: " + profile.getId() + " is active. (source: " + profile.getSource() + ")" );
+ container.getLogger().debug(
+ "Profile: " + profile.getId() + " is active. (source: " + profile.getSource() + ")" );
return true;
}
}
@@ -309,7 +310,7 @@ public class DefaultProfileManager
}
finally
{
- container.getContext().put("SystemProperties", null);
+ container.getContext().put( "SystemProperties", null );
if ( activators != null )
{
try
diff --git a/maven-project/src/main/java/org/apache/maven/profiles/activation/CustomActivator.java b/maven-project/src/main/java/org/apache/maven/profiles/activation/CustomActivator.java
index 0316b22d15..fae9ede650 100644
--- a/maven-project/src/main/java/org/apache/maven/profiles/activation/CustomActivator.java
+++ b/maven-project/src/main/java/org/apache/maven/profiles/activation/CustomActivator.java
@@ -90,8 +90,9 @@ public class CustomActivator
{
if ( !context.isCustomActivatorFailureSuppressed() )
{
- throw new ProfileActivationException( "Cannot find custom ProfileActivator: " + type
- + ". \nPerhaps you're missing a build extension?", e );
+ throw new ProfileActivationException(
+ "Cannot find custom ProfileActivator: " + type + ". \nPerhaps you're missing a build extension?",
+ e );
}
}
@@ -107,8 +108,7 @@ public class CustomActivator
{
if ( !context.isCustomActivatorFailureSuppressed() )
{
- throw new ProfileActivationException( "Failed to configure custom ProfileActivator: " + type
- + ".", e );
+ throw new ProfileActivationException( "Failed to configure custom ProfileActivator: " + type + ".", e );
}
}
diff --git a/maven-project/src/main/java/org/apache/maven/profiles/activation/DefaultProfileActivationContext.java b/maven-project/src/main/java/org/apache/maven/profiles/activation/DefaultProfileActivationContext.java
index da1d05498d..fd3b9adf5d 100644
--- a/maven-project/src/main/java/org/apache/maven/profiles/activation/DefaultProfileActivationContext.java
+++ b/maven-project/src/main/java/org/apache/maven/profiles/activation/DefaultProfileActivationContext.java
@@ -1,5 +1,24 @@
package org.apache.maven.profiles.activation;
+/*
+ * 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.
+ */
+
import org.apache.maven.realm.MavenRealmManager;
import java.util.ArrayList;
@@ -12,13 +31,19 @@ public class DefaultProfileActivationContext
{
private boolean isCustomActivatorFailureSuppressed;
+
private final Properties executionProperties;
+
List explicitlyActive;
+
List explicitlyInactive;
+
private final MavenRealmManager realmManager;
+
private List activeByDefault;
- public DefaultProfileActivationContext( MavenRealmManager realmManager, Properties executionProperties, boolean isCustomActivatorFailureSuppressed )
+ public DefaultProfileActivationContext( MavenRealmManager realmManager, Properties executionProperties,
+ boolean isCustomActivatorFailureSuppressed )
{
this.realmManager = realmManager;
this.executionProperties = executionProperties;
diff --git a/maven-project/src/main/java/org/apache/maven/profiles/activation/FileProfileActivator.java b/maven-project/src/main/java/org/apache/maven/profiles/activation/FileProfileActivator.java
index 86504664f4..5f96ed13d2 100644
--- a/maven-project/src/main/java/org/apache/maven/profiles/activation/FileProfileActivator.java
+++ b/maven-project/src/main/java/org/apache/maven/profiles/activation/FileProfileActivator.java
@@ -76,11 +76,13 @@ public class FileProfileActivator
{
if ( logger.isDebugEnabled() )
{
- logger.debug( "Failed to interpolate exists file location for profile activator: " + fileString, e );
+ logger.debug( "Failed to interpolate exists file location for profile activator: " + fileString,
+ e );
}
else
{
- logger.warn( "Failed to interpolate exists file location for profile activator: " + fileString + ". Run in debug mode (-X) for more information." );
+ logger.warn( "Failed to interpolate exists file location for profile activator: " + fileString +
+ ". Run in debug mode (-X) for more information." );
}
}
@@ -88,7 +90,8 @@ public class FileProfileActivator
if ( logger != null )
{
- logger.debug( "FileProfileActivator: Checking file existence for: " + fileString + ". Result: " + result );
+ logger.debug(
+ "FileProfileActivator: Checking file existence for: " + fileString + ". Result: " + result );
}
return result;
@@ -107,11 +110,13 @@ public class FileProfileActivator
{
if ( logger.isDebugEnabled() )
{
- logger.debug( "Failed to interpolate missing file location for profile activator: " + fileString, e );
+ logger.debug(
+ "Failed to interpolate missing file location for profile activator: " + fileString, e );
}
else
{
- logger.warn( "Failed to interpolate missing file location for profile activator: " + fileString + ". Run in debug mode (-X) for more information." );
+ logger.warn( "Failed to interpolate missing file location for profile activator: " +
+ fileString + ". Run in debug mode (-X) for more information." );
}
}
@@ -119,7 +124,8 @@ public class FileProfileActivator
if ( logger != null )
{
- logger.debug( "FileProfileActivator: Checking file is missing for: " + fileString + ". Result: " + result );
+ logger.debug(
+ "FileProfileActivator: Checking file is missing for: " + fileString + ". Result: " + result );
}
return result;
diff --git a/maven-project/src/main/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivator.java b/maven-project/src/main/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivator.java
index 26df4854fb..8137851b36 100644
--- a/maven-project/src/main/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivator.java
+++ b/maven-project/src/main/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivator.java
@@ -43,7 +43,8 @@ public class JdkPrefixProfileActivator
String javaVersion = props.getProperty( JDK_VERSION );
if ( javaVersion == null )
{
- getLogger().warn( "Cannot locate java version property: " + JDK_VERSION + ". NOT enabling profile: " + profile.getId() );
+ getLogger().warn(
+ "Cannot locate java version property: " + JDK_VERSION + ". NOT enabling profile: " + profile.getId() );
return false;
}
@@ -100,7 +101,8 @@ public class JdkPrefixProfileActivator
}
}
- /** This method transforms a string like "1.5.0_06" into
+ /**
+ * This method transforms a string like "1.5.0_06" into
* new int[]{1, 5, 0, 6}.
*/
private static int[] asIntArray( String pVersion )
@@ -129,7 +131,8 @@ public class JdkPrefixProfileActivator
return result;
}
- /** This method compares to integer arrays, as created
+ /**
+ * This method compares to integer arrays, as created
* by {@link #asIntArray(String)}.
*/
private static int compareTo( int[] pVersion1, int[] pVersion2 )
diff --git a/maven-project/src/main/java/org/apache/maven/profiles/activation/OperatingSystemProfileActivator.java b/maven-project/src/main/java/org/apache/maven/profiles/activation/OperatingSystemProfileActivator.java
index efcb0d367c..46af7a49a4 100644
--- a/maven-project/src/main/java/org/apache/maven/profiles/activation/OperatingSystemProfileActivator.java
+++ b/maven-project/src/main/java/org/apache/maven/profiles/activation/OperatingSystemProfileActivator.java
@@ -62,7 +62,8 @@ public class OperatingSystemProfileActivator
private boolean ensureAtLeastOneNonNull( ActivationOS os )
{
- return ( os.getArch() != null ) || ( os.getFamily() != null ) || ( os.getName() != null ) || ( os.getVersion() != null );
+ return ( os.getArch() != null ) || ( os.getFamily() != null ) || ( os.getName() != null ) ||
+ ( os.getVersion() != null );
}
private boolean determineVersionMatch( String version )
diff --git a/maven-project/src/main/java/org/apache/maven/profiles/activation/ProfileActivationContext.java b/maven-project/src/main/java/org/apache/maven/profiles/activation/ProfileActivationContext.java
index b38fb79f2d..caba207687 100644
--- a/maven-project/src/main/java/org/apache/maven/profiles/activation/ProfileActivationContext.java
+++ b/maven-project/src/main/java/org/apache/maven/profiles/activation/ProfileActivationContext.java
@@ -1,5 +1,24 @@
package org.apache.maven.profiles.activation;
+/*
+ * 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.
+ */
+
import org.apache.maven.realm.MavenRealmManager;
import java.util.List;
diff --git a/maven-project/src/main/java/org/apache/maven/profiles/activation/ProfileActivator.java b/maven-project/src/main/java/org/apache/maven/profiles/activation/ProfileActivator.java
index 25d92e36c2..b6562bbece 100644
--- a/maven-project/src/main/java/org/apache/maven/profiles/activation/ProfileActivator.java
+++ b/maven-project/src/main/java/org/apache/maven/profiles/activation/ProfileActivator.java
@@ -25,8 +25,10 @@ public interface ProfileActivator
{
static final String ROLE = ProfileActivator.class.getName();
- boolean canDetermineActivation( Profile profile, ProfileActivationContext context ) throws ProfileActivationException;
+ boolean canDetermineActivation( Profile profile, ProfileActivationContext context )
+ throws ProfileActivationException;
- boolean isActive( Profile profile, ProfileActivationContext context ) throws ProfileActivationException;
+ boolean isActive( Profile profile, ProfileActivationContext context )
+ throws ProfileActivationException;
}
diff --git a/maven-project/src/main/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivator.java b/maven-project/src/main/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivator.java
index 3b35c4602f..c1781762fd 100644
--- a/maven-project/src/main/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivator.java
+++ b/maven-project/src/main/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivator.java
@@ -46,7 +46,7 @@ public class SystemPropertyProfileActivator
String name = property.getName();
boolean reverseName = false;
- if ( name.startsWith("!") )
+ if ( name.startsWith( "!" ) )
{
reverseName = true;
name = name.substring( 1 );
diff --git a/maven-project/src/main/java/org/apache/maven/profiles/build/DefaultProfileAdvisor.java b/maven-project/src/main/java/org/apache/maven/profiles/build/DefaultProfileAdvisor.java
index 6b813187b0..cb7b496474 100644
--- a/maven-project/src/main/java/org/apache/maven/profiles/build/DefaultProfileAdvisor.java
+++ b/maven-project/src/main/java/org/apache/maven/profiles/build/DefaultProfileAdvisor.java
@@ -67,25 +67,18 @@ public class DefaultProfileAdvisor
private Logger logger;
- public List applyActivatedProfiles( Model model,
- File pomFile,
- boolean useProfilesXml,
+ public List applyActivatedProfiles( Model model, File pomFile, boolean useProfilesXml,
ProfileActivationContext activationContext )
throws ProjectBuildingException
{
// logger.debug( "Building profile manager for model: " + model.getId() + " with pom file: "
// + pomFile );
- ProfileManager profileManager = buildProfileManager( model,
- pomFile,
- useProfilesXml,
- activationContext );
+ ProfileManager profileManager = buildProfileManager( model, pomFile, useProfilesXml, activationContext );
return applyActivatedProfiles( model, pomFile, profileManager );
}
- public List applyActivatedExternalProfiles( Model model,
- File projectDir,
- ProfileManager externalProfileManager )
+ public List applyActivatedExternalProfiles( Model model, File projectDir, ProfileManager externalProfileManager )
throws ProjectBuildingException
{
if ( externalProfileManager == null )
@@ -99,9 +92,7 @@ public class DefaultProfileAdvisor
return applyActivatedProfiles( model, projectDir, externalProfileManager );
}
- private List applyActivatedProfiles( Model model,
- File pomFile,
- ProfileManager profileManager )
+ private List applyActivatedProfiles( Model model, File pomFile, ProfileManager profileManager )
throws ProjectBuildingException
{
List activeProfiles;
@@ -146,9 +137,7 @@ public class DefaultProfileAdvisor
return activeProfiles;
}
- private ProfileManager buildProfileManager( Model model,
- File pomFile,
- boolean useProfilesXml,
+ private ProfileManager buildProfileManager( Model model, File pomFile, boolean useProfilesXml,
ProfileActivationContext profileActivationContext )
throws ProjectBuildingException
{
@@ -164,8 +153,7 @@ public class DefaultProfileAdvisor
return profileManager;
}
- public LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model,
- File pomFile,
+ public LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model, File pomFile,
ProfileManager profileManager )
throws ProjectBuildingException
{
@@ -183,8 +171,7 @@ public class DefaultProfileAdvisor
}
catch ( ProfileActivationException e )
{
- throw new ProjectBuildingException(
- model.getId(),
+ throw new ProjectBuildingException( model.getId(),
"Failed to compute active profiles for repository aggregation.",
pomFile, e );
}
@@ -196,7 +183,8 @@ public class DefaultProfileAdvisor
Profile externalProfile = (Profile) i.next();
if ( externalProfile.getRepositories() != null )
{
- for ( Iterator repoIterator = externalProfile.getRepositories().iterator(); repoIterator.hasNext(); )
+ for ( Iterator repoIterator = externalProfile.getRepositories().iterator();
+ repoIterator.hasNext(); )
{
Repository mavenRepo = (Repository) repoIterator.next();
@@ -219,23 +207,16 @@ public class DefaultProfileAdvisor
}
}
- public LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model,
- File pomFile,
- boolean useProfilesXml,
+ public LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model, File pomFile, boolean useProfilesXml,
ProfileActivationContext activationContext )
throws ProjectBuildingException
{
- ProfileManager profileManager = buildProfileManager( model,
- pomFile,
- useProfilesXml,
- activationContext );
+ ProfileManager profileManager = buildProfileManager( model, pomFile, useProfilesXml, activationContext );
return getArtifactRepositoriesFromActiveProfiles( model, pomFile, profileManager );
}
- private void loadExternalProjectProfiles( ProfileManager profileManager,
- Model model,
- File pomFile )
+ private void loadExternalProjectProfiles( ProfileManager profileManager, Model model, File pomFile )
throws ProjectBuildingException
{
if ( pomFile != null )
@@ -268,14 +249,14 @@ public class DefaultProfileAdvisor
catch ( IOException e )
{
throw new ProjectBuildingException( model.getId(),
- "Cannot read profiles.xml resource from directory: "
- + projectDir, pomFile, e );
+ "Cannot read profiles.xml resource from directory: " + projectDir,
+ pomFile, e );
}
catch ( XmlPullParserException e )
{
throw new ProjectBuildingException( model.getId(),
- "Cannot parse profiles.xml resource from directory: "
- + projectDir, pomFile, e );
+ "Cannot parse profiles.xml resource from directory: " + projectDir,
+ pomFile, e );
}
}
}
diff --git a/maven-project/src/main/java/org/apache/maven/profiles/build/ProfileAdvisor.java b/maven-project/src/main/java/org/apache/maven/profiles/build/ProfileAdvisor.java
index 37c8e20441..7ec4f05828 100644
--- a/maven-project/src/main/java/org/apache/maven/profiles/build/ProfileAdvisor.java
+++ b/maven-project/src/main/java/org/apache/maven/profiles/build/ProfileAdvisor.java
@@ -29,35 +29,25 @@ import java.util.LinkedHashSet;
import java.util.List;
/**
- *
* @author jdcasey
- *
*/
public interface ProfileAdvisor
{
String ROLE = ProfileAdvisor.class.getName();
- LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model,
- File pomFile,
- ProfileManager profileManager )
+ LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model, File pomFile, ProfileManager profileManager )
throws ProjectBuildingException;
- LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model,
- File pomFile,
- boolean useProfilesXml,
+ LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model, File pomFile, boolean useProfilesXml,
ProfileActivationContext profileActivationContext )
throws ProjectBuildingException;
- List applyActivatedProfiles( Model model,
- File pomFile,
- boolean useProfilesXml,
+ List applyActivatedProfiles( Model model, File pomFile, boolean useProfilesXml,
ProfileActivationContext activationContext )
throws ProjectBuildingException;
- List applyActivatedExternalProfiles( Model model,
- File pomFile,
- ProfileManager externalProfileManager )
+ List applyActivatedExternalProfiles( Model model, File pomFile, ProfileManager externalProfileManager )
throws ProjectBuildingException;
}
diff --git a/maven-project/src/main/java/org/apache/maven/profiles/injection/DefaultProfileInjector.java b/maven-project/src/main/java/org/apache/maven/profiles/injection/DefaultProfileInjector.java
index c3822f5b2e..b87dea5cfb 100644
--- a/maven-project/src/main/java/org/apache/maven/profiles/injection/DefaultProfileInjector.java
+++ b/maven-project/src/main/java/org/apache/maven/profiles/injection/DefaultProfileInjector.java
@@ -49,11 +49,11 @@ import java.util.Properties;
/**
* Inject profile data into a Model, using the profile as the dominant data source, and
* persisting results of the injection in the Model.
- *
+ *
* This will look similar to the ModelUtils/DefaultModelInheritanceAssembler code, but
* they are distinct. In model inheritance, the child provides data dominance AND persists
* the results of the merge...sort of a 'merge-out' system.
- *
+ *
* In this system, the profile is dominant, but the model receives the merge result...sort
* of a 'merge-in' system. The two pieces of code look like they could be combined with a
* set of flags to determine which direction to merge 'to', but there are enough differences
@@ -142,15 +142,15 @@ public class DefaultProfileInjector
/**
* This should be the resulting ordering of plugins after injection:
- *
+ *
* Given:
- *
- * model: X -> A -> B -> D -> E
- * profile: Y -> A -> C -> D -> F
- *
+ *
+ * model: X -> A -> B -> D -> E
+ * profile: Y -> A -> C -> D -> F
+ *
* Result:
- *
- * X -> Y -> A -> B -> C -> D -> E -> F
+ *
+ * X -> Y -> A -> B -> C -> D -> E -> F
*/
protected void injectPlugins( PluginContainer profileContainer, PluginContainer modelContainer )
{
@@ -214,7 +214,8 @@ public class DefaultProfileInjector
modelPlugin.setVersion( profilePlugin.getVersion() );
}
- modelPlugin.setDependencies( injectDependencies( profilePlugin.getDependencies(), modelPlugin.getDependencies() ) );
+ modelPlugin.setDependencies(
+ injectDependencies( profilePlugin.getDependencies(), modelPlugin.getDependencies() ) );
// merge the lists of goals that are not attached to an
injectConfigurationContainer( profilePlugin, modelPlugin );
@@ -297,13 +298,13 @@ public class DefaultProfileInjector
/**
* Merge two DOMs. Copy the dominant DOM so the original one is left unchanged.
- *
+ *
* Use this method instead of a direct call to {@link Xpp3Dom#mergeXpp3Dom(Xpp3Dom, Xpp3Dom)}.
* Profiles are dominant, thus they are merge targets, but they may be merged in several times
* (e.g. if they are inherited). So with the second merge, you don't get the profile's original
* DOM, but an already merged one.
*
- * @param dominant Dominant DOM
+ * @param dominant Dominant DOM
* @param recessive Recessive DOM
* @return Merged DOM
*/
diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
index 37759c6bbc..adb1ffdf01 100644
--- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
+++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
@@ -21,36 +21,23 @@ package org.apache.maven.project;
import org.apache.maven.MavenTools;
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.ArtifactStatus;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.InvalidRepositoryException;
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.repository.ArtifactRepositoryPolicy;
-import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
-import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver;
-import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
-import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
-import org.apache.maven.artifact.versioning.ManagedVersionMap;
-import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.model.Build;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
-import org.apache.maven.model.DistributionManagement;
-import org.apache.maven.model.Exclusion;
-import org.apache.maven.model.Extension;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginManagement;
-import org.apache.maven.model.Parent;
-import org.apache.maven.model.ReportPlugin;
-import org.apache.maven.model.Repository;
-import org.apache.maven.model.Resource;
+import org.apache.maven.model.Profile;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.profiles.MavenProfilesBuilder;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
@@ -58,32 +45,37 @@ import org.apache.maven.profiles.activation.ProfileActivationContext;
import org.apache.maven.profiles.activation.ProfileActivationException;
import org.apache.maven.profiles.build.ProfileAdvisor;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
-import org.apache.maven.project.build.model.DefaultModelLineage;
-import org.apache.maven.project.build.model.ModelLineage;
-import org.apache.maven.project.build.model.ModelLineageBuilder;
-import org.apache.maven.project.build.model.ModelLineageIterator;
-import org.apache.maven.project.inheritance.ModelInheritanceAssembler;
-import org.apache.maven.project.injection.ModelDefaultsInjector;
+import org.apache.maven.project.builder.PomArtifactResolver;
+import org.apache.maven.project.builder.ProjectBuilder;
import org.apache.maven.project.interpolation.ModelInterpolationException;
import org.apache.maven.project.interpolation.ModelInterpolator;
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.project.validation.ModelValidationResult;
import org.apache.maven.project.validation.ModelValidator;
import org.apache.maven.project.workspace.ProjectWorkspace;
-import org.apache.maven.project.builder.PomArtifactResolver;
-import org.apache.maven.project.builder.ProjectBuilder;
-import org.apache.maven.project.builder.PomClassicDomainModel;
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.WriterFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-import java.io.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.Writer;
import java.net.URL;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
/*:apt
@@ -123,10 +115,9 @@ Notes
* @version $Id$
*/
public class DefaultMavenProjectBuilder
- implements MavenProjectBuilder,
- Initializable, LogEnabled
+ implements MavenProjectBuilder, Initializable, LogEnabled
{
- protected MavenProfilesBuilder profilesBuilder;
+ protected MavenProfilesBuilder profilesBuilder;
protected ArtifactResolver artifactResolver;
@@ -134,8 +125,6 @@ public class DefaultMavenProjectBuilder
private ArtifactFactory artifactFactory;
- private ModelInheritanceAssembler modelInheritanceAssembler;
-
private ModelValidator validator;
// TODO: make it a component
@@ -143,12 +132,8 @@ public class DefaultMavenProjectBuilder
private PathTranslator pathTranslator;
- private ModelDefaultsInjector modelDefaultsInjector;
-
private ModelInterpolator modelInterpolator;
- private ModelLineageBuilder modelLineageBuilder;
-
private ProfileAdvisor profileAdvisor;
private MavenTools mavenTools;
@@ -157,14 +142,18 @@ public class DefaultMavenProjectBuilder
private ProjectBuilder projectBuilder;
+ private RepositoryHelper repositoryHelper;
+
+ private Logger logger;
+
//DO NOT USE, it is here only for backward compatibility reasons. The existing
// maven-assembly-plugin (2.2-beta-1) is accessing it via reflection.
-// the aspect weaving seems not to work for reflection from plugin.
+ // the aspect weaving seems not to work for reflection from plugin.
+
private Map processedProjectCache = new HashMap();
-
- public static final String MAVEN_MODEL_VERSION = "4.0.0";
+ private static final String MAVEN_MODEL_VERSION = "4.0.0";
public void initialize()
{
@@ -175,30 +164,52 @@ public class DefaultMavenProjectBuilder
// MavenProjectBuilder Implementation
// ----------------------------------------------------------------------
- public MavenProject build( File projectDescriptor,
- ArtifactRepository localRepository,
+ public MavenProject build( File projectDescriptor, ArtifactRepository localRepository,
ProfileManager profileManager )
throws ProjectBuildingException
{
- ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository )
- .setGlobalProfileManager( profileManager );
+ ProjectBuilderConfiguration config =
+ new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository )
+ .setGlobalProfileManager( profileManager );
- return buildFromSourceFileInternal( projectDescriptor, config );
+ return build( projectDescriptor, config );
}
- public MavenProject build( File projectDescriptor,
- ProjectBuilderConfiguration config )
+ public MavenProject build( File projectDescriptor, ProjectBuilderConfiguration config )
throws ProjectBuildingException
{
- return buildFromSourceFileInternal( projectDescriptor, config );
+ MavenProject project = projectWorkspace.getProject( projectDescriptor );
+
+ if ( project == null )
+ {
+ project = readModelFromLocalPath( "unknown", projectDescriptor, new PomArtifactResolver(
+ config.getLocalRepository(), repositoryHelper.buildArtifactRepositories(
+ getSuperProject( config, projectDescriptor, true ).getModel() ), artifactResolver ), config );
+
+ project.setFile( projectDescriptor );
+ project = buildInternal( project.getModel(), config, projectDescriptor, project.getParentFile(), true );
+
+ Build build = project.getBuild();
+ // NOTE: setting this script-source root before path translation, because
+ // the plugin tools compose basedir and scriptSourceRoot into a single file.
+ project.addScriptSourceRoot( build.getScriptSourceDirectory() );
+ project.addCompileSourceRoot( build.getSourceDirectory() );
+ project.addTestCompileSourceRoot( build.getTestSourceDirectory() );
+ project.setFile( projectDescriptor );
+
+ setBuildOutputDirectoryOnParent( project );
+
+ }
+ return project;
}
- /** @deprecated */
+
+ /**
+ * @deprecated
+ */
@Deprecated
- public MavenProject buildFromRepository( Artifact artifact,
- List remoteArtifactRepositories,
- ArtifactRepository localRepository,
- boolean allowStub )
+ public MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories,
+ ArtifactRepository localRepository, boolean allowStub )
throws ProjectBuildingException
{
@@ -206,41 +217,41 @@ public class DefaultMavenProjectBuilder
}
- public MavenProject buildFromRepository( Artifact artifact,
- List remoteArtifactRepositories,
+ public MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories,
ArtifactRepository localRepository )
throws ProjectBuildingException
{
- String artifactKey = artifact.getId();
-
MavenProject project = null;
- if ( !Artifact.LATEST_VERSION.equals( artifact.getVersion() ) && !Artifact.RELEASE_VERSION.equals( artifact.getVersion() ) )
+ if ( !Artifact.LATEST_VERSION.equals( artifact.getVersion() ) &&
+ !Artifact.RELEASE_VERSION.equals( artifact.getVersion() ) )
{
-// getLogger().debug( "Checking cache for project (in buildFromRepository): " + artifactKey );
- project = projectWorkspace.getProject( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() );
+ project =
+ projectWorkspace.getProject( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() );
}
-
+ File f = artifact.getFile();
if ( project == null )
{
-// getLogger().debug( "Allowing buildFromRepository to proceed for: " + artifactKey );
+ repositoryHelper.findModelFromRepository( artifact, remoteArtifactRepositories, localRepository );
- Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository );
+ ProjectBuilderConfiguration config =
+ new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository );
- ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository );
+ List artifactRepositories =
+ new ArrayList( remoteArtifactRepositories );
+ artifactRepositories.addAll( repositoryHelper.buildArtifactRepositories(
+ getSuperProject( config, artifact.getFile(), false ).getModel() ) );
- project = buildInternal( model, config, remoteArtifactRepositories, artifact.getFile(),
- false, false, false );
+ project = readModelFromLocalPath( "unknown", artifact.getFile(), new PomArtifactResolver(
+ config.getLocalRepository(), artifactRepositories, artifactResolver ), config );
+ project = buildInternal( project.getModel(), config, artifact.getFile(), project.getParentFile(), false );
}
-// else
-// {
-// getLogger().debug( "Returning cached project: " + project );
-// }
+
+ artifact.setFile( f );
+ project.setVersion( artifact.getVersion() );
return project;
}
- private Logger logger;
-
// what is using this externally? jvz.
public MavenProject buildStandaloneSuperProject()
throws ProjectBuildingException
@@ -253,7 +264,8 @@ public class DefaultMavenProjectBuilder
throws ProjectBuildingException
{
//TODO mkleint - use the (Container, Properties) constructor to make system properties embeddable
- return buildStandaloneSuperProject( new DefaultProjectBuilderConfiguration().setGlobalProfileManager( profileManager ) );
+ return buildStandaloneSuperProject(
+ new DefaultProjectBuilderConfiguration().setGlobalProfileManager( profileManager ) );
}
public MavenProject buildStandaloneSuperProject( ProjectBuilderConfiguration config )
@@ -274,7 +286,8 @@ public class DefaultMavenProjectBuilder
List activeProfiles = new ArrayList();
if ( profileManager != null )
{
- List activated = profileAdvisor.applyActivatedProfiles( superModel, null, false, profileManager.getProfileActivationContext() );
+ List activated = profileAdvisor.applyActivatedProfiles( superModel, null, false,
+ profileManager.getProfileActivationContext() );
if ( !activated.isEmpty() )
{
activeProfiles.addAll( activated );
@@ -287,112 +300,92 @@ public class DefaultMavenProjectBuilder
}
}
- MavenProject project = new MavenProject( superModel );
-
- String projectId = safeVersionlessKey( STANDALONE_SUPERPOM_GROUPID, STANDALONE_SUPERPOM_ARTIFACTID );
-
- project.setManagedVersionMap(
- createManagedVersionMap( projectId, superModel.getDependencyManagement(), null ) );
-
- getLogger().debug( "Activated the following profiles for standalone super-pom: " + activeProfiles );
- project.setActiveProfiles( activeProfiles );
-
-
+ MavenProject project;
try
{
- processProjectLogic( project, null, config, null, true, true );
-
- project.setRemoteArtifactRepositories( mavenTools.buildArtifactRepositories( superModel.getRepositories() ) );
- project.setPluginArtifactRepositories( mavenTools.buildArtifactRepositories( superModel.getRepositories() ) );
+ project = new MavenProject( superModel, artifactFactory, mavenTools, repositoryHelper, this, config );
}
catch ( InvalidRepositoryException e )
{
- // we shouldn't be swallowing exceptions, no matter how unlikely.
- // or, if we do, we should pay attention to the one coming from getSuperModel()...
- throw new ProjectBuildingException( STANDALONE_SUPERPOM_GROUPID + ":"
- + STANDALONE_SUPERPOM_ARTIFACTID,
- "Maven super-POM contains an invalid repository!",
- e );
+ throw new ProjectBuildingException( STANDALONE_SUPERPOM_GROUPID + ":" + STANDALONE_SUPERPOM_ARTIFACTID,
+ "Maven super-POM contains an invalid repository!", e );
+ }
+
+ getLogger().debug( "Activated the following profiles for standalone super-pom: " + activeProfiles );
+
+ try
+ {
+ project = interpolateModelAndInjectDefault( project.getModel(), null, null, config );
+ project.setActiveProfiles( activeProfiles );
+ project.setRemoteArtifactRepositories(
+ mavenTools.buildArtifactRepositories( superModel.getRepositories() ) );
+ project.setPluginArtifactRepositories(
+ mavenTools.buildArtifactRepositories( superModel.getRepositories() ) );
+ }
+ catch ( InvalidRepositoryException e )
+ {
+ throw new ProjectBuildingException( STANDALONE_SUPERPOM_GROUPID + ":" + STANDALONE_SUPERPOM_ARTIFACTID,
+ "Maven super-POM contains an invalid repository!", e );
}
catch ( ModelInterpolationException e )
{
- // we shouldn't be swallowing exceptions, no matter how unlikely.
- // or, if we do, we should pay attention to the one coming from getSuperModel()...
- throw new ProjectBuildingException( STANDALONE_SUPERPOM_GROUPID + ":"
- + STANDALONE_SUPERPOM_ARTIFACTID,
- "Maven super-POM contains an invalid expressions!",
- e );
+ throw new ProjectBuildingException( STANDALONE_SUPERPOM_GROUPID + ":" + STANDALONE_SUPERPOM_ARTIFACTID,
+ "Maven super-POM contains an invalid expressions!", e );
}
- project.setOriginalModel( superModel );
-
project.setExecutionRoot( true );
return project;
}
- /** @since 2.0.x */
- public MavenProject buildWithDependencies( File projectDescriptor,
- ArtifactRepository localRepository,
+ /**
+ * @since 2.0.x
+ */
+ public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepository localRepository,
ProfileManager profileManager )
throws ProjectBuildingException
{
return buildProjectWithDependencies( projectDescriptor, localRepository, profileManager ).getProject();
}
- /** @since 2.1 */
+ /**
+ * @since 2.1
+ */
public MavenProjectBuildingResult buildProjectWithDependencies( File projectDescriptor,
- ArtifactRepository localRepository,
- ProfileManager profileManager )
+ ArtifactRepository localRepository,
+ ProfileManager profileManager )
throws ProjectBuildingException
{
- ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository )
- .setGlobalProfileManager( profileManager );
+ ProjectBuilderConfiguration config =
+ new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository )
+ .setGlobalProfileManager( profileManager );
return buildProjectWithDependencies( projectDescriptor, config );
}
public MavenProjectBuildingResult buildProjectWithDependencies( File projectDescriptor,
ProjectBuilderConfiguration config )
- throws ProjectBuildingException
- {
+ throws ProjectBuildingException
+ {
MavenProject project = build( projectDescriptor, config );
- // ----------------------------------------------------------------------
- // Typically when the project builder is being used from maven proper
- // the transitive dependencies will not be resolved here because this
- // requires a lot of work when we may only be interested in running
- // something simple like 'm2 clean'. So the artifact collector is used
- // in the dependency resolution phase if it is required by any of the
- // goals being executed. But when used as a component in another piece
- // of code people may just want to build maven projects and have the
- // dependencies resolved for whatever reason: this is why we keep
- // this snippet of code here.
- // ----------------------------------------------------------------------
-
- Artifact projectArtifact = project.getArtifact();
-
- String projectId = safeVersionlessKey( project.getGroupId(), project.getArtifactId() );
-
- Map managedVersions = project.getManagedVersionMap();
-
try
{
project.setDependencyArtifacts( project.createArtifacts( artifactFactory, null, null ) );
}
catch ( InvalidDependencyVersionException e )
{
- throw new ProjectBuildingException( projectId,
- "Unable to build project due to an invalid dependency version: " +
- e.getMessage(), projectDescriptor, e );
+ throw new ProjectBuildingException( safeVersionlessKey( project.getGroupId(), project.getArtifactId() ),
+ "Unable to build project due to an invalid dependency version: " +
+ e.getMessage(), projectDescriptor, e );
}
ArtifactResolutionRequest request = new ArtifactResolutionRequest()
- .setArtifact( projectArtifact )
+ .setArtifact( project.getArtifact() )
.setArtifactDependencies( project.getDependencyArtifacts() )
.setLocalRepository( config.getLocalRepository() )
.setRemoteRepostories( project.getRemoteArtifactRepositories() )
- .setManagedVersionMap( managedVersions )
+ .setManagedVersionMap( project.getManagedVersionMap() )
.setMetadataSource( artifactMetadataSource );
ArtifactResolutionResult result = artifactResolver.resolve( request );
@@ -402,290 +395,37 @@ public class DefaultMavenProjectBuilder
return new MavenProjectBuildingResult( project, result );
}
- // ----------------------------------------------------------------------
- //
- // ----------------------------------------------------------------------
-
- private Map createManagedVersionMap( String projectId,
- DependencyManagement dependencyManagement, File pomFile )
- throws ProjectBuildingException
+ public void calculateConcreteState( MavenProject project, ProjectBuilderConfiguration config )
+ throws ModelInterpolationException
{
- Map map = null;
- List deps;
- if ( ( dependencyManagement != null ) && ( ( deps = dependencyManagement.getDependencies() ) != null ) && ( deps.size() > 0 ) )
- {
- map = new ManagedVersionMap( map );
-
- if ( getLogger().isDebugEnabled() )
- {
- getLogger().debug( "Adding managed dependencies for " + projectId );
- }
-
- 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() );
-
- if ( Artifact.SCOPE_SYSTEM.equals( d.getScope() ) && ( d.getSystemPath() != null ) )
- {
- artifact.setFile( new File( d.getSystemPath() ) );
- }
-
- if ( getLogger().isDebugEnabled() )
- {
- getLogger().debug( " " + artifact );
- }
-
- // If the dependencyManagement section listed exclusions,
- // add them to the managed artifacts here so that transitive
- // dependencies will be excluded if necessary.
-
- if ( ( null != d.getExclusions() ) && !d.getExclusions().isEmpty() )
- {
- List exclusions = new ArrayList();
-
- for ( Iterator j = d.getExclusions().iterator(); j.hasNext(); )
- {
- Exclusion e = (Exclusion) j.next();
-
- exclusions.add( e.getGroupId() + ":" + e.getArtifactId() );
- }
-
- ExcludesArtifactFilter eaf = new ExcludesArtifactFilter( exclusions );
-
- artifact.setDependencyFilter( eaf );
- }
- else
- {
- artifact.setDependencyFilter( null );
- }
-
- map.put( d.getManagementKey(), artifact );
- }
- catch ( InvalidVersionSpecificationException e )
- {
- throw new InvalidDependencyVersionException( projectId, d, pomFile, e );
- }
- }
- }
- else if ( map == null )
- {
- map = Collections.EMPTY_MAP;
- }
- return map;
+ new MavenProjectRestorer( pathTranslator, modelInterpolator, getLogger() ).calculateConcreteState( project,
+ config );
}
- private MavenProject buildFromSourceFileInternal( File projectDescriptor,
- ProjectBuilderConfiguration config )
- throws ProjectBuildingException
+ public void restoreDynamicState( MavenProject project, ProjectBuilderConfiguration config )
+ throws ModelInterpolationException
{
-// getLogger().debug( "Checking cache-hit on project (in build*): " + projectDescriptor );
-
- MavenProject project = projectWorkspace.getProject( projectDescriptor );
-
- if ( project == null )
- {
- Model model = readModelFromLocalPath( "unknown", projectDescriptor, new PomArtifactResolver(config.getLocalRepository(),
- buildArtifactRepositories( getSuperModel() ), artifactResolver) );
- project = buildInternal(model,
- config,
- buildArtifactRepositories( getSuperModel() ),
- projectDescriptor,
- STRICT_MODEL_PARSING,
- true,
- true );
- }
- return project;
+ new MavenProjectRestorer( pathTranslator, modelInterpolator, getLogger() ).restoreDynamicState( project,
+ config );
}
- private Model findModelFromRepository( Artifact artifact,
- List remoteArtifactRepositories,
- ArtifactRepository localRepository )
- throws ProjectBuildingException
+ public void enableLogging( Logger logger )
{
-
- String projectId = safeVersionlessKey( artifact.getGroupId(), artifact.getArtifactId() );
- remoteArtifactRepositories = normalizeToArtifactRepositories( remoteArtifactRepositories, projectId );
-
- Artifact projectArtifact;
-
- // if the artifact is not a POM, we need to construct a POM artifact based on the artifact parameter given.
- if ( "pom".equals( artifact.getType() ) )
- {
- projectArtifact = artifact;
- }
- else
- {
- getLogger().warn( "Attempting to build MavenProject instance for Artifact (" + artifact.getGroupId() + ":"
- + artifact.getArtifactId() + ":" + artifact.getVersion() + ") of type: "
- + artifact.getType() + "; constructing POM artifact instead." );
-
- projectArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(),
- artifact.getArtifactId(),
- artifact.getVersion(),
- artifact.getScope() );
- }
-
- Model legacy_model;
- try
- {
- artifactResolver.resolve( projectArtifact, remoteArtifactRepositories, localRepository );
-
- File file = projectArtifact.getFile();
-
- legacy_model = readModelLegacy( projectId, file, STRICT_MODEL_PARSING );
-
- String downloadUrl = null;
-
- ArtifactStatus status = ArtifactStatus.NONE;
-
- DistributionManagement distributionManagement = legacy_model.getDistributionManagement();
-
- if ( distributionManagement != null )
- {
- downloadUrl = distributionManagement.getDownloadUrl();
-
- status = ArtifactStatus.valueOf( distributionManagement.getStatus() );
- }
-
- checkStatusAndUpdate( projectArtifact, status, file, remoteArtifactRepositories, localRepository );
-
- // TODO: this is gross. Would like to give it the whole model, but maven-artifact shouldn't depend on that
- // Can a maven-core implementation of the Artifact interface store it, and be used in the exceptions?
- if ( downloadUrl != null )
- {
- projectArtifact.setDownloadUrl( downloadUrl );
- }
- else
- {
- projectArtifact.setDownloadUrl( legacy_model.getUrl() );
- }
- }
- catch ( ArtifactResolutionException e )
- {
- throw new ProjectBuildingException( projectId, "Error getting POM for '" + projectId + "' from the repository: " + e.getMessage(), e );
- }
- catch ( ArtifactNotFoundException e )
- {
- throw new ProjectBuildingException( projectId, "POM '" + projectId + "' not found in repository: " + e.getMessage(), e );
- }
-
- return legacy_model;
+ this.logger = logger;
}
- private List normalizeToArtifactRepositories( List remoteArtifactRepositories,
- String projectId )
- throws ProjectBuildingException
+ private Logger getLogger()
{
- List normalized = new ArrayList( remoteArtifactRepositories.size() );
-
- boolean normalizationNeeded = false;
- for ( Iterator it = remoteArtifactRepositories.iterator(); it.hasNext(); )
- {
- Object item = it.next();
-
- if ( item instanceof ArtifactRepository )
- {
- normalized.add( item );
- }
- else if ( item instanceof Repository )
- {
- Repository repo = (Repository) item;
- try
- {
- item = mavenTools.buildArtifactRepository( repo );
-
- normalized.add( item );
- normalizationNeeded = true;
- }
- catch ( InvalidRepositoryException e )
- {
- throw new ProjectBuildingException( projectId, "Error building artifact repository for id: " + repo.getId(), e );
- }
- }
- else
- {
- throw new ProjectBuildingException( projectId, "Error building artifact repository from non-repository information item: " + item );
- }
- }
-
- if ( normalizationNeeded )
- {
- return normalized;
- }
- else
- {
- return remoteArtifactRepositories;
- }
+ return logger;
}
- private void checkStatusAndUpdate( Artifact projectArtifact,
- ArtifactStatus status,
- File file,
- List remoteArtifactRepositories,
- ArtifactRepository localRepository )
- throws ArtifactNotFoundException
- {
- // TODO: configurable actions dependant on status
- if ( !projectArtifact.isSnapshot() && ( status.compareTo( ArtifactStatus.DEPLOYED ) < 0 ) )
- {
- // use default policy (enabled, daily update, warn on bad checksum)
- ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy();
- // TODO: re-enable [MNG-798/865]
- policy.setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER );
-
- if ( policy.checkOutOfDate( new Date( file.lastModified() ) ) )
- {
- getLogger().info(
- projectArtifact.getArtifactId() + ": updating metadata due to status of '" + status + "'" );
- try
- {
- projectArtifact.setResolved( false );
- artifactResolver.resolveAlways( projectArtifact, remoteArtifactRepositories, localRepository );
- }
- catch ( ArtifactResolutionException e )
- {
- getLogger().warn( "Error updating POM - using existing version" );
- getLogger().debug( "Cause", e );
- }
- catch ( ArtifactNotFoundException e )
- {
- getLogger().warn( "Error updating POM - not found. Removing local copy." );
- getLogger().debug( "Cause", e );
- file.delete();
- throw e;
- }
- }
- }
- }
-
- // jvz:note
- // We've got a mixture of things going in the USD and from the repository, sometimes the descriptor
- // is a real file and sometimes null which makes things confusing.
- private MavenProject buildInternal( Model model,
- ProjectBuilderConfiguration config,
- List parentSearchRepositories,
- File projectDescriptor,
- boolean strict,
- boolean isReactorProject,
- boolean fromSourceTree )
+ private MavenProject buildInternal( Model model, ProjectBuilderConfiguration config, File projectDescriptor,
+ File parentDescriptor, boolean isReactorProject )
throws ProjectBuildingException
{
- Model superModel = getSuperModel();
-
- MavenProject superProject = new MavenProject( superModel );
-
String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
- // FIXME: Find a way to pass in this context, so it's never null!
ProfileActivationContext profileActivationContext;
-
ProfileManager externalProfileManager = config.getGlobalProfileManager();
if ( externalProfileManager != null )
{
@@ -696,9 +436,9 @@ public class DefaultMavenProjectBuilder
}
catch ( ProfileActivationException e )
{
- throw new ProjectBuildingException( projectId, "Failed to activate external profiles.", projectDescriptor, e );
+ throw new ProjectBuildingException( projectId, "Failed to activate external profiles.",
+ projectDescriptor, e );
}
-
profileActivationContext = externalProfileManager.getProfileActivationContext();
}
else
@@ -706,96 +446,10 @@ public class DefaultMavenProjectBuilder
profileActivationContext = new DefaultProfileActivationContext( config.getExecutionProperties(), false );
}
- LinkedHashSet activeInSuperPom = new LinkedHashSet();
- List activated = profileAdvisor.applyActivatedProfiles( superModel, projectDescriptor, isReactorProject, profileActivationContext );
- if ( !activated.isEmpty() )
- {
- activeInSuperPom.addAll( activated );
- }
-
- activated = profileAdvisor.applyActivatedExternalProfiles( superModel, projectDescriptor, externalProfileManager );
- if ( !activated.isEmpty() )
- {
- activeInSuperPom.addAll( activated );
- }
-
- superProject.setActiveProfiles( activated );
-
- //noinspection CollectionDeclaredAsConcreteClass
- LinkedList lineage = new LinkedList();
-
- LinkedHashSet aggregatedRemoteWagonRepositories = collectInitialRepositories( model, superModel,
- parentSearchRepositories,
- projectDescriptor,
- isReactorProject,
- profileActivationContext );
-
- Model originalModel = ModelUtils.cloneModel( model );
-
MavenProject project;
-
try
{
- project = assembleLineage( model, lineage, config, projectDescriptor, aggregatedRemoteWagonRepositories, strict, isReactorProject );
- }
- catch ( InvalidRepositoryException e )
- {
- throw new ProjectBuildingException( projectId, e.getMessage(), e );
- }
-
- project.setOriginalModel( originalModel );
-
- // we don't have to force the collision exception for superModel here, it's already been done in getSuperModel()
- MavenProject previousProject = superProject;
-
- Model previous = superProject.getModel();
-
- for ( Iterator i = lineage.iterator(); i.hasNext(); )
- {
- MavenProject currentProject = (MavenProject) i.next();
-
- Model current = currentProject.getModel();
-
- String pathAdjustment = null;
-
- try
- {
- pathAdjustment = previousProject.getModulePathAdjustment( currentProject );
- }
- catch ( IOException e )
- {
- getLogger().debug(
- "Cannot determine whether " + currentProject.getId() + " is a module of " + previousProject.getId() + ". Reason: " + e.getMessage(),
- e );
- }
-
- modelInheritanceAssembler.assembleModelInheritance( current, previous, pathAdjustment );
-
- previous = current;
- previousProject = currentProject;
- }
-
- // only add the super repository if it wasn't overridden by a profile or project
- List repositories = new ArrayList( aggregatedRemoteWagonRepositories );
-
- List superRepositories = buildArtifactRepositories( superModel );
-
- for ( Iterator i = superRepositories.iterator(); i.hasNext(); )
- {
- ArtifactRepository repository = (ArtifactRepository) i.next();
-
- if ( !repositories.contains( repository ) )
- {
- repositories.add( repository );
- }
- }
-
- // merge any duplicated plugin definitions together, using the first appearance as the dominant one.
- ModelUtils.mergeDuplicatePluginDefinitions( project.getModel().getBuild() );
-
- try
- {
- project = processProjectLogic( project, projectDescriptor, config, repositories, strict, false );
+ project = interpolateModelAndInjectDefault( model, projectDescriptor, parentDescriptor, config );
}
catch ( ModelInterpolationException e )
{
@@ -806,256 +460,60 @@ public class DefaultMavenProjectBuilder
throw new InvalidProjectModelException( projectId, e.getMessage(), projectDescriptor, e );
}
- if ( fromSourceTree )
- {
- Build build = project.getBuild();
-
- // NOTE: setting this script-source root before path translation, because
- // the plugin tools compose basedir and scriptSourceRoot into a single file.
- project.addScriptSourceRoot( build.getScriptSourceDirectory() );
-
- project.addCompileSourceRoot( build.getSourceDirectory() );
-
- project.addTestCompileSourceRoot( build.getTestSourceDirectory() );
-
- // Only track the file of a POM in the source tree
- project.setFile( projectDescriptor );
- }
-
-// getLogger().debug( "Caching project: " + project.getId() + " (also keyed by file: " + project.getFile() + ")" );
-
+ List projectProfiles = new ArrayList();
+ projectProfiles.addAll( profileAdvisor.applyActivatedProfiles( project.getModel(), project.getFile(),
+ isReactorProject, profileActivationContext ) );
+ projectProfiles.addAll( profileAdvisor.applyActivatedExternalProfiles( project.getModel(), project.getFile(),
+ externalProfileManager ) );
+ project.setActiveProfiles( projectProfiles );
projectWorkspace.storeProjectByCoordinate( project );
projectWorkspace.storeProjectByFile( project );
- project.setManagedVersionMap( createManagedVersionMap( projectId, project.getDependencyManagement(), projectDescriptor ) );
-
return project;
}
- /*
- * Order is:
- *
- * 1. model profile repositories
- * 2. model repositories
- * 3. superModel profile repositories
- * 4. superModel repositories
- * 5. parentSearchRepositories
- */
- private LinkedHashSet collectInitialRepositories( Model model,
- Model superModel,
- List parentSearchRepositories,
- File pomFile,
- boolean validProfilesXmlLocation,
- ProfileActivationContext profileActivationContext )
- throws ProjectBuildingException
- {
- LinkedHashSet collected = new LinkedHashSet();
-
- collectInitialRepositoriesFromModel( collected, model, pomFile, validProfilesXmlLocation, profileActivationContext );
-
- collectInitialRepositoriesFromModel( collected, superModel, null, validProfilesXmlLocation, profileActivationContext );
-
- if ( ( parentSearchRepositories != null ) && !parentSearchRepositories.isEmpty() )
- {
- collected.addAll( parentSearchRepositories );
- }
-
- return collected;
- }
-
- private void collectInitialRepositoriesFromModel( LinkedHashSet collected,
- Model model,
- File pomFile,
- boolean validProfilesXmlLocation,
- ProfileActivationContext profileActivationContext )
- throws ProjectBuildingException
- {
- Set reposFromProfiles = profileAdvisor.getArtifactRepositoriesFromActiveProfiles( model, pomFile, validProfilesXmlLocation, profileActivationContext );
-
- if ( ( reposFromProfiles != null ) && !reposFromProfiles.isEmpty() )
- {
- collected.addAll( reposFromProfiles );
- }
-
- List modelRepos = model.getRepositories();
-
- if ( ( modelRepos != null ) && !modelRepos.isEmpty() )
- {
- try
- {
- collected.addAll( mavenTools.buildArtifactRepositories( modelRepos ) );
- }
- catch ( InvalidRepositoryException e )
- {
- throw new ProjectBuildingException( safeVersionlessKey( model.getGroupId(), model.getArtifactId() ),
- "Failed to construct ArtifactRepository instances for repositories declared in: " +
- model.getId(), e );
- }
- }
- }
-
- private String safeVersionlessKey( String groupId,
- String artifactId )
- {
- String gid = groupId;
-
- if ( StringUtils.isEmpty( gid ) )
- {
- gid = "unknown";
- }
-
- String aid = artifactId;
-
- if ( StringUtils.isEmpty( aid ) )
- {
- aid = "unknown";
- }
-
- return ArtifactUtils.versionlessKey( gid, aid );
- }
-
- private List buildArtifactRepositories( Model model )
- throws ProjectBuildingException
- {
- try
- {
- return mavenTools.buildArtifactRepositories( model.getRepositories() );
- }
- catch ( InvalidRepositoryException e )
- {
- String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
-
- throw new ProjectBuildingException( projectId, e.getMessage(), e );
- }
- }
-
- /**
- * @todo can this take in a model instead of a project and still be successful?
- * @todo In fact, does project REALLY need a MavenProject as a parent? Couldn't it have just a wrapper around a
- * model that supported parents which were also the wrapper so that inheritence was assembled. We don't really need
- * the resolved source roots, etc for the parent - that occurs for the parent when it is constructed independently
- * and projects are not cached or reused
- */
- private MavenProject processProjectLogic( MavenProject project,
- File pomFile,
- ProjectBuilderConfiguration config,
- List remoteRepositories,
- boolean strict,
- boolean isSuperPom )
+ private MavenProject interpolateModelAndInjectDefault( Model model, File pomFile, File parentFile,
+ ProjectBuilderConfiguration config )
throws ProjectBuildingException, ModelInterpolationException, InvalidRepositoryException
{
- Model model = project.getModel();
-
- List activeProfiles = project.getActiveProfiles();
-
File projectDir = null;
-
if ( pomFile != null )
{
projectDir = pomFile.getAbsoluteFile().getParentFile();
}
Build dynamicBuild = model.getBuild();
- model.setBuild( ModelUtils.cloneBuild( dynamicBuild ) );
-
+ if ( dynamicBuild != null )
+ {
+ model.setBuild( ModelUtils.cloneBuild( dynamicBuild ) );
+ }
model = modelInterpolator.interpolate( model, projectDir, config, getLogger().isDebugEnabled() );
- mergeDeterministicBuildElements( model.getBuild(), dynamicBuild );
- model.setBuild( dynamicBuild );
-
- // We must inject any imported dependencyManagement information ahead of the defaults injection.
- if ( !isSuperPom )
+ if ( dynamicBuild != null && model.getBuild() != null )
{
- // TODO: [jdcasey] This line appears to be part of the problem for MNG-3391...
- // the same line is in 2.0.x, so this is related to caching changes too...need to figure out how the two interact.
- mergeManagedDependencies( model, config.getLocalRepository(), remoteRepositories );
+ mergeDeterministicBuildElements( model.getBuild(), dynamicBuild );
+ model.setBuild( dynamicBuild );
}
// interpolation is before injection, because interpolation is off-limits in the injected variables
- modelDefaultsInjector.injectDefaults( model );
-
- MavenProject parentProject = project.getParent();
-
- Model originalModel = project.getOriginalModel();
-
- Artifact parentArtifact = project.getParentArtifact();
+ new DefaultModelDefaultsInjector().injectDefaults( model );
// We will return a different project object using the new model (hence the need to return a project, not just modify the parameter)
- project = new MavenProject( model );
+ MavenProject project = new MavenProject( model, artifactFactory, mavenTools, repositoryHelper, this, config );
- project.setOriginalModel( originalModel );
-
- project.setActiveProfiles( activeProfiles );
-
- // TODO: such a call in MavenMetadataSource too - packaging not really the intention of type
- // TODO: maybe not strictly correct, while we should enfore that packaging has a type handler of the same id, we don't
Artifact projectArtifact = artifactFactory.createBuildArtifact( project.getGroupId(), project.getArtifactId(),
- project.getVersion(), project.getPackaging() );
+ project.getVersion(), project.getPackaging() );
project.setArtifact( projectArtifact );
-
-// project.setPluginArtifactRepositories( mavenTools.buildArtifactRepositories( model.getPluginRepositories() ) );
-
- DistributionManagement dm = model.getDistributionManagement();
-
- if ( dm != null )
- {
- ArtifactRepository repo = mavenTools.buildDeploymentArtifactRepository( dm.getRepository() );
- project.setReleaseArtifactRepository( repo );
-
- if ( dm.getSnapshotRepository() != null )
- {
- repo = mavenTools.buildDeploymentArtifactRepository( dm.getSnapshotRepository() );
- project.setSnapshotArtifactRepository( repo );
- }
- }
-
- project.setParent( parentProject );
-
- if ( parentProject != null )
- {
- project.setParentArtifact( parentArtifact );
- }
+ project.setParentFile( parentFile );
validateModel( model, pomFile );
-
- try
- {
- LinkedHashSet repoSet = new LinkedHashSet();
- if ( ( model.getRepositories() != null ) && !model.getRepositories().isEmpty() )
- {
- repoSet.addAll( model.getRepositories() );
- }
-
- if ( ( model.getPluginRepositories() != null ) && !model.getPluginRepositories().isEmpty() )
- {
- repoSet.addAll( model.getPluginRepositories() );
- }
-
- project.setRemoteArtifactRepositories(
- mavenTools.buildArtifactRepositories( new ArrayList( repoSet ) ) );
- }
- catch( Exception e )
- {
- e.printStackTrace();
- }
-
- String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
-
- // TODO: these aren't taking active project artifacts into consideration in the reactor
- project.setPluginArtifacts( createPluginArtifacts( projectId, project.getBuildPlugins(), pomFile ) );
-
- project.setReportArtifacts( createReportArtifacts( projectId, project.getReportPlugins(), pomFile ) );
-
- project.setExtensionArtifacts( createExtensionArtifacts( projectId, project.getBuildExtensions(), pomFile ) );
-
return project;
}
// TODO: Remove this!
@SuppressWarnings("unchecked")
- private void mergeDeterministicBuildElements( Build interpolatedBuild,
- Build dynamicBuild )
+ private void mergeDeterministicBuildElements( Build interpolatedBuild, Build dynamicBuild )
{
List dPlugins = dynamicBuild.getPlugins();
@@ -1071,7 +529,7 @@ public class DefaultMavenProjectBuilder
dPlugin.setGroupId( iPlugin.getGroupId() );
dPlugin.setArtifactId( iPlugin.getArtifactId() );
dPlugin.setVersion( iPlugin.getVersion() );
-
+
dPlugin.setDependencies( iPlugin.getDependencies() );
}
}
@@ -1094,7 +552,7 @@ public class DefaultMavenProjectBuilder
dPlugin.setGroupId( iPlugin.getGroupId() );
dPlugin.setArtifactId( iPlugin.getArtifactId() );
dPlugin.setVersion( iPlugin.getVersion() );
-
+
dPlugin.setDependencies( iPlugin.getDependencies() );
}
}
@@ -1106,550 +564,39 @@ public class DefaultMavenProjectBuilder
}
}
- public void calculateConcreteState( MavenProject project, ProjectBuilderConfiguration config )
- throws ModelInterpolationException
+ private MavenProject getSuperProject( ProjectBuilderConfiguration config, File projectDescriptor,
+ boolean isReactorProject )
+ throws ProjectBuildingException
{
- if ( project.isConcrete() )
+
+ MavenProject superProject;
+ Model model = getSuperModel();
+ try
{
- return;
+ superProject = new MavenProject( model, artifactFactory, mavenTools, repositoryHelper, this, config );
}
-
- Build build = project.getBuild();
- if ( build != null )
+ catch ( InvalidRepositoryException e )
{
- initResourceMergeIds( build.getResources() );
- initResourceMergeIds( build.getTestResources() );
+ throw new ProjectBuildingException( STANDALONE_SUPERPOM_GROUPID + ":" + STANDALONE_SUPERPOM_ARTIFACTID,
+ "Maven super-POM contains an invalid repository!", e );
}
- Model model = ModelUtils.cloneModel( project.getModel() );
-
- File basedir = project.getBasedir();
-
- model = modelInterpolator.interpolate( model, basedir, config, getLogger().isDebugEnabled() );
-
- List originalInterpolatedCompileSourceRoots = interpolateListOfStrings( project.getCompileSourceRoots(),
- model,
- project.getBasedir(),
- config );
-
- project.preserveCompileSourceRoots( originalInterpolatedCompileSourceRoots );
-
- project.setCompileSourceRoots( originalInterpolatedCompileSourceRoots == null ? null
- : translateListOfPaths( originalInterpolatedCompileSourceRoots, basedir ) );
-
- List originalInterpolatedTestCompileSourceRoots = interpolateListOfStrings( project.getTestCompileSourceRoots(),
- model,
- project.getBasedir(),
- config );
-
- project.preserveTestCompileSourceRoots( originalInterpolatedTestCompileSourceRoots );
- project.setTestCompileSourceRoots( originalInterpolatedTestCompileSourceRoots == null ? null
- : translateListOfPaths( originalInterpolatedTestCompileSourceRoots, basedir ) );
-
- List originalInterpolatedScriptSourceRoots = interpolateListOfStrings( project.getScriptSourceRoots(),
- model,
- project.getBasedir(),
- config );
-
- project.preserveScriptSourceRoots( originalInterpolatedScriptSourceRoots );
- project.setScriptSourceRoots( originalInterpolatedScriptSourceRoots == null ? null
- : translateListOfPaths( originalInterpolatedScriptSourceRoots, basedir ) );
-
- Model model2 = ModelUtils.cloneModel( model );
-
- pathTranslator.alignToBaseDirectory( model, basedir );
-
- project.preserveBuild( model2.getBuild() );
- project.setBuild( model.getBuild() );
-
- calculateConcreteProjectReferences( project, config );
-
- MavenProject executionProject = project.getExecutionProject();
- if ( executionProject != null && executionProject != project )
- {
- calculateConcreteState( executionProject, config );
- }
-
- project.setConcrete( true );
- }
-
- private void initResourceMergeIds( List resources )
- {
- if ( resources != null )
- {
- for ( Resource resource : resources )
- {
- resource.initMergeId();
- }
- }
- }
-
- private void calculateConcreteProjectReferences( MavenProject project,
- ProjectBuilderConfiguration config )
- throws ModelInterpolationException
- {
- Map projectRefs = project.getProjectReferences();
-
- if ( projectRefs != null )
- {
- for ( Iterator it = projectRefs.values().iterator(); it.hasNext(); )
- {
- MavenProject reference = (MavenProject) it.next();
- calculateConcreteState( reference, config );
- }
- }
- }
-
- private List translateListOfPaths( List paths, File basedir )
- {
- if ( paths == null )
- {
- return null;
- }
- else if ( basedir == null )
- {
- return paths;
- }
-
- List result = new ArrayList( paths.size() );
- for ( Iterator it = paths.iterator(); it.hasNext(); )
- {
- String path = (String) it.next();
-
- String aligned = pathTranslator.alignToBaseDirectory( path, basedir );
-
- result.add( aligned );
- }
-
- return result;
- }
-
- public void restoreDynamicState( MavenProject project, ProjectBuilderConfiguration config )
- throws ModelInterpolationException
- {
- if ( !project.isConcrete() )
- {
- return;
- }
-
- restoreBuildRoots( project, config );
- restoreModelBuildSection( project, config );
-
- restoreDynamicProjectReferences( project, config );
-
- MavenProject executionProject = project.getExecutionProject();
- if ( executionProject != null && executionProject != project )
- {
- restoreDynamicState( executionProject, config );
- }
-
- project.setConcrete( false );
- }
-
- private void restoreDynamicProjectReferences( MavenProject project,
- ProjectBuilderConfiguration config )
- throws ModelInterpolationException
- {
- Map projectRefs = project.getProjectReferences();
- if ( projectRefs != null )
- {
- for ( Iterator it = projectRefs.values().iterator(); it.hasNext(); )
- {
- MavenProject projectRef = (MavenProject) it.next();
- restoreDynamicState( projectRef, config );
- }
- }
- }
-
- private void restoreBuildRoots( MavenProject project,
- ProjectBuilderConfiguration config )
- throws ModelInterpolationException
- {
- project.setCompileSourceRoots( restoreListOfStrings( project.getDynamicCompileSourceRoots(),
- project.getOriginalInterpolatedCompileSourceRoots(),
- project.getCompileSourceRoots(),
- project,
- config ) );
-
- project.setTestCompileSourceRoots( restoreListOfStrings( project.getDynamicTestCompileSourceRoots(),
- project.getOriginalInterpolatedTestCompileSourceRoots(),
- project.getTestCompileSourceRoots(),
- project,
- config ) );
-
- project.setScriptSourceRoots( restoreListOfStrings( project.getDynamicScriptSourceRoots(),
- project.getOriginalInterpolatedScriptSourceRoots(),
- project.getScriptSourceRoots(),
- project,
- config ) );
-
- project.clearRestorableRoots();
- }
-
- private void restoreModelBuildSection( MavenProject project,
- ProjectBuilderConfiguration config )
- throws ModelInterpolationException
- {
- Build changedBuild = project.getBuild();
- Build dynamicBuild = project.getDynamicBuild();
- Build originalInterpolatedBuild = project.getOriginalInterpolatedBuild();
-
- dynamicBuild.setResources( restoreResources( dynamicBuild.getResources(),
- originalInterpolatedBuild.getResources(),
- changedBuild.getResources(),
- project,
- config ) );
-
- dynamicBuild.setTestResources( restoreResources( dynamicBuild.getTestResources(),
- originalInterpolatedBuild.getTestResources(),
- changedBuild.getTestResources(),
- project,
- config ) );
-
- dynamicBuild.setFilters( restoreListOfStrings( dynamicBuild.getFilters(),
- originalInterpolatedBuild.getFilters(),
- changedBuild.getFilters(),
- project,
- config ) );
-
- dynamicBuild.setFinalName( restoreString( dynamicBuild.getFinalName(),
- originalInterpolatedBuild.getFinalName(),
- changedBuild.getFinalName(),
- project,
- config ) );
-
- dynamicBuild.setDefaultGoal( restoreString( dynamicBuild.getDefaultGoal(),
- originalInterpolatedBuild.getDefaultGoal(),
- changedBuild.getDefaultGoal(),
- project,
- config ) );
-
- dynamicBuild.setSourceDirectory( restoreString( dynamicBuild.getSourceDirectory(),
- originalInterpolatedBuild.getSourceDirectory(),
- changedBuild.getSourceDirectory(),
- project,
- config ) );
-
- dynamicBuild.setTestSourceDirectory( restoreString( dynamicBuild.getTestSourceDirectory(),
- originalInterpolatedBuild.getTestSourceDirectory(),
- changedBuild.getTestSourceDirectory(),
- project,
- config ) );
-
- dynamicBuild.setScriptSourceDirectory( restoreString( dynamicBuild.getScriptSourceDirectory(),
- originalInterpolatedBuild.getScriptSourceDirectory(),
- changedBuild.getScriptSourceDirectory(),
- project,
- config ) );
-
- dynamicBuild.setOutputDirectory( restoreString( dynamicBuild.getOutputDirectory(),
- originalInterpolatedBuild.getOutputDirectory(),
- changedBuild.getOutputDirectory(),
- project,
- config ) );
-
- dynamicBuild.setTestOutputDirectory( restoreString( dynamicBuild.getTestOutputDirectory(),
- originalInterpolatedBuild.getTestOutputDirectory(),
- changedBuild.getTestOutputDirectory(),
- project,
- config ) );
-
- dynamicBuild.setDirectory( restoreString( dynamicBuild.getDirectory(),
- originalInterpolatedBuild.getDirectory(),
- changedBuild.getDirectory(),
- project,
- config ) );
-
- project.setBuild( dynamicBuild );
-
- project.clearRestorableBuild();
- }
-
- private List interpolateListOfStrings( List originalStrings,
- Model model,
- File projectDir,
- ProjectBuilderConfiguration config )
- throws ModelInterpolationException
- {
- if ( originalStrings == null )
- {
- return null;
- }
-
- List result = new ArrayList();
-
- for ( Iterator it = originalStrings.iterator(); it.hasNext(); )
- {
- String original = (String) it.next();
- String interpolated = modelInterpolator.interpolate( original, model, projectDir, config, getLogger().isDebugEnabled() );
-
- result.add( interpolated );
- }
-
- return result;
- }
-
- private String restoreString( String originalString,
- String originalInterpolatedString,
- String changedString,
- MavenProject project,
- ProjectBuilderConfiguration config )
- throws ModelInterpolationException
- {
- if ( originalString == null )
- {
- return changedString;
- }
- else if ( changedString == null )
- {
- return originalString;
- }
-
- Model model = project.getModel();
-
- String relativeChangedString;
- if ( project.getBasedir() != null )
- {
- relativeChangedString = pathTranslator.unalignFromBaseDirectory( changedString, project.getBasedir() );
- }
- else
- {
- relativeChangedString = changedString;
- }
-
- String interpolatedOriginal = modelInterpolator.interpolate( originalString, model, project.getBasedir(), config, getLogger().isDebugEnabled() );
- String interpolatedOriginal2 = modelInterpolator.interpolate( originalInterpolatedString,
- model,
- project.getBasedir(), config, getLogger().isDebugEnabled() );
-
- String interpolatedChanged = modelInterpolator.interpolate( changedString, model, project.getBasedir(), config, getLogger().isDebugEnabled() );
- String relativeInterpolatedChanged = modelInterpolator.interpolate( relativeChangedString, model, project.getBasedir(), config, getLogger().isDebugEnabled() );
-
- if ( interpolatedOriginal.equals( interpolatedChanged )
- || interpolatedOriginal2.equals( interpolatedChanged ) )
- {
- return originalString;
- }
- else if ( interpolatedOriginal.equals( relativeInterpolatedChanged )
- || interpolatedOriginal2.equals( relativeInterpolatedChanged ) )
- {
- return originalString;
- }
-
- return relativeChangedString;
- }
-
- private List restoreListOfStrings( List originalStrings,
- List originalInterpolatedStrings,
- List changedStrings,
- MavenProject project,
- ProjectBuilderConfiguration config )
- throws ModelInterpolationException
- {
- if ( originalStrings == null )
- {
- return changedStrings;
- }
- else if ( changedStrings == null )
- {
- return originalStrings;
- }
-
- List result = new ArrayList();
-
- Map orig = new HashMap();
- for ( int idx = 0; idx < originalStrings.size(); idx++ )
- {
- String[] permutations = new String[2];
-
- permutations[0] = (String) originalInterpolatedStrings.get( idx );
- permutations[1] = (String) originalStrings.get( idx );
-
- orig.put( permutations[0], permutations );
- }
-
- for ( Iterator it = changedStrings.iterator(); it.hasNext(); )
- {
- String changedString = (String) it.next();
- String relativeChangedString;
- if ( project.getBasedir() != null )
- {
- relativeChangedString = pathTranslator.unalignFromBaseDirectory( changedString, project.getBasedir() );
- }
- else
- {
- relativeChangedString = changedString;
- }
-
- String interpolated = modelInterpolator.interpolate( changedString,
- project.getModel(),
- project.getBasedir(),
- config,
- getLogger().isDebugEnabled() );
-
- String relativeInterpolated = modelInterpolator.interpolate( relativeChangedString,
- project.getModel(),
- project.getBasedir(),
- config,
- getLogger().isDebugEnabled() );
-
- String[] original = (String[]) orig.get( interpolated );
- if ( original == null )
- {
- original = (String[]) orig.get( relativeInterpolated );
- }
-
- if ( original == null )
- {
- result.add( relativeChangedString );
- }
- else
- {
- result.add( original[1] );
- }
- }
-
- return result;
- }
-
- // TODO: Convert this to use the mergeId on each resource...
- private List restoreResources( List originalResources,
- List originalInterpolatedResources,
- List changedResources,
- MavenProject project,
- ProjectBuilderConfiguration config )
- throws ModelInterpolationException
- {
- if ( originalResources == null || changedResources == null )
- {
- return originalResources;
- }
-
- List result = new ArrayList();
-
- Map originalResourcesByMergeId = new HashMap();
- for ( int idx = 0; idx < originalResources.size(); idx++ )
- {
- Resource[] permutations = new Resource[2];
-
- permutations[0] = originalInterpolatedResources.get( idx );
- permutations[1] = originalResources.get( idx );
-
- originalResourcesByMergeId.put( permutations[0].getMergeId(), permutations );
- }
-
- for ( Resource resource : changedResources )
- {
- String mergeId = resource.getMergeId();
- if ( mergeId == null || !originalResourcesByMergeId.containsKey( mergeId ) )
- {
- result.add( resource );
- }
- else
- {
- Resource originalInterpolatedResource = originalResourcesByMergeId.get( mergeId )[0];
- Resource originalResource = originalResourcesByMergeId.get( mergeId )[1];
-
- String dir = modelInterpolator.interpolate( resource.getDirectory(), project.getModel(), project.getBasedir(), config, getLogger().isDebugEnabled() );
- String oDir = originalInterpolatedResource.getDirectory();
-
- if ( !dir.equals( oDir ) )
- {
- originalResource.setDirectory( pathTranslator.unalignFromBaseDirectory( dir, project.getBasedir() ) );
- }
-
- if ( resource.getTargetPath() != null )
- {
- String target = modelInterpolator.interpolate( resource.getTargetPath(), project.getModel(), project.getBasedir(), config, getLogger().isDebugEnabled() );
-
- String oTarget = originalInterpolatedResource.getTargetPath();
-
- if ( !target.equals( oTarget ) )
- {
- originalResource.setTargetPath( pathTranslator.unalignFromBaseDirectory( target, project.getBasedir() ) );
- }
- }
-
- originalResource.setFiltering( resource.isFiltering() );
-
- originalResource.setExcludes( collectRestoredListOfPatterns( resource.getExcludes(),
- originalResource.getExcludes(),
- originalInterpolatedResource.getExcludes() ) );
-
- originalResource.setIncludes( collectRestoredListOfPatterns( resource.getIncludes(),
- originalResource.getIncludes(),
- originalInterpolatedResource.getIncludes() ) );
-
- result.add( originalResource );
- }
- }
-
- return result;
- }
-
- private List collectRestoredListOfPatterns( List patterns,
- List originalPatterns,
- List originalInterpolatedPatterns )
- {
- LinkedHashSet collectedPatterns = new LinkedHashSet();
-
- collectedPatterns.addAll( originalPatterns );
-
- for ( String pattern : patterns )
- {
- if ( !originalInterpolatedPatterns.contains( pattern ) )
- {
- collectedPatterns.add( pattern );
- }
- }
-
- return (List) ( collectedPatterns.isEmpty() ? Collections.emptyList()
- : new ArrayList( collectedPatterns ) );
- }
-
- private void validateModel( Model model,
- File pomFile )
- throws InvalidProjectModelException
- {
- // Must validate before artifact construction to make sure dependencies are good
- ModelValidationResult validationResult = validator.validate( model );
-
String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
- if ( validationResult.getMessageCount() > 0 )
- {
- throw new InvalidProjectModelException( projectId, "Failed to validate POM", pomFile,
- validationResult );
- }
- }
-
- /**
- * @param isReactorProject
- * @noinspection CollectionDeclaredAsConcreteClass
- * @todo We need to find an effective way to unit test parts of this method!
- * @todo Refactor this into smaller methods with discrete purposes.
- */
- private MavenProject assembleLineage( Model model,
- LinkedList lineage,
- ProjectBuilderConfiguration config,
- File pomFile,
- Set aggregatedRemoteWagonRepositories,
- boolean strict,
- boolean isReactorProject )
- throws ProjectBuildingException, InvalidRepositoryException
- {
- ModelLineage modelLineage = new DefaultModelLineage();
-
- modelLineage.setOrigin( model, pomFile, new ArrayList( aggregatedRemoteWagonRepositories ), isReactorProject );
-
- modelLineageBuilder.resumeBuildingModelLineage( modelLineage, config, !strict, isReactorProject );
-
- // FIXME: Find a way to pass in this context, so it's never null!
ProfileActivationContext profileActivationContext;
ProfileManager externalProfileManager = config.getGlobalProfileManager();
-
if ( externalProfileManager != null )
{
+ // used to trigger the caching of SystemProperties in the container context...
+ try
+ {
+ externalProfileManager.getActiveProfiles();
+ }
+ catch ( ProfileActivationException e )
+ {
+ throw new ProjectBuildingException( projectId, "Failed to activate external profiles.",
+ projectDescriptor, e );
+ }
profileActivationContext = externalProfileManager.getProfileActivationContext();
}
else
@@ -1657,368 +604,16 @@ public class DefaultMavenProjectBuilder
profileActivationContext = new DefaultProfileActivationContext( config.getExecutionProperties(), false );
}
- MavenProject lastProject = null;
- for ( ModelLineageIterator it = modelLineage.lineageIterator(); it.hasNext(); )
- {
- Model currentModel = (Model) it.next();
+ List superProjectProfiles = new ArrayList();
+ superProjectProfiles.addAll( profileAdvisor.applyActivatedProfiles( model, projectDescriptor, isReactorProject,
+ profileActivationContext ) );
+ superProjectProfiles.addAll(
+ profileAdvisor.applyActivatedExternalProfiles( model, projectDescriptor, externalProfileManager ) );
+ superProject.setActiveProfiles( superProjectProfiles );
- File currentPom = it.getPOMFile();
-
- MavenProject project = new MavenProject( currentModel );
- project.setFile( currentPom );
-
- if ( lastProject != null )
- {
- // TODO: Use cached parent project here, and stop looping, if possible...
- lastProject.setParent( project );
- project = lastProject.getParent();
-
- lastProject.setParentArtifact( artifactFactory.createParentArtifact( project.getGroupId(), project
- .getArtifactId(), project.getVersion() ) );
- }
-
- // NOTE: the caching aspect may replace the parent project instance, so we apply profiles here.
- // TODO: Review this...is that a good idea, to allow application of profiles when other profiles could have been applied already?
- project.setActiveProfiles( profileAdvisor.applyActivatedProfiles( project.getModel(), project.getFile(), isReactorProject, profileActivationContext ) );
-
- lineage.addFirst( project );
-
- lastProject = project;
- }
-
- MavenProject result = (MavenProject) lineage.getLast();
-
- if ( externalProfileManager != null )
- {
- LinkedHashSet active = new LinkedHashSet();
-
- List existingActiveProfiles = result.getActiveProfiles();
- if ( ( existingActiveProfiles != null ) && !existingActiveProfiles.isEmpty() )
- {
- active.addAll( existingActiveProfiles );
- }
-
- profileAdvisor.applyActivatedExternalProfiles( result.getModel(), pomFile, externalProfileManager );
- }
-
- return result;
+ return superProject;
}
- private void mergeManagedDependencies(Model model, ArtifactRepository localRepository, List parentSearchRepositories)
- throws ProjectBuildingException
- {
- DependencyManagement modelDepMgmt = model.getDependencyManagement();
-
- if (modelDepMgmt != null)
- {
- Map depsMap = new TreeMap();
- Iterator iter = modelDepMgmt.getDependencies().iterator();
- boolean doInclude = false;
- while (iter.hasNext())
- {
- Dependency dep = (Dependency) iter.next();
- depsMap.put( dep.getManagementKey(), dep );
-
- // MNG-3391: SEE BELOW.
- if (dep.getType().equals("pom") && Artifact.SCOPE_IMPORT.equals( dep.getScope() ) )
- {
- doInclude = true;
- }
- }
- Map newDeps = new TreeMap(depsMap);
- iter = modelDepMgmt.getDependencies().iterator();
- if (doInclude)
- {
- while (iter.hasNext())
- {
- Dependency dep = (Dependency)iter.next();
-
- // MNG-3391: The check for scope == 'import' to limit the StackOverflowExceptions caused
- // when importing from the parent and the import-target is a module that declares the
- // current pom as a parent.
- //
- // Also, dependencies with type == 'pom' are the best way we currently have to
- // aggregate multiple other dependencies without messing with the issues caused by using
- // an assembly (ClassCastException if a second-level dep is also part of the maven core,
- // for instance)
- if (dep.getType().equals("pom") && Artifact.SCOPE_IMPORT.equals( dep.getScope() ) )
- {
- Artifact artifact = artifactFactory.createProjectArtifact( dep.getGroupId(), dep.getArtifactId(),
- dep.getVersion(), dep.getScope() );
- MavenProject project = buildFromRepository(artifact, parentSearchRepositories, localRepository, false);
-
- DependencyManagement depMgmt = project.getDependencyManagement();
-
- if (depMgmt != null)
- {
- if ( getLogger().isDebugEnabled() )
- {
- getLogger().debug( "Importing managed dependencies for " + dep.toString() );
- }
-
- for ( Iterator it = depMgmt.getDependencies().iterator(); it.hasNext(); )
- {
- Dependency includedDep = (Dependency) it.next();
- String key = includedDep.getManagementKey();
- if (!newDeps.containsKey(key))
- {
- newDeps.put( includedDep.getManagementKey(), includedDep );
- }
- }
- newDeps.remove(dep.getManagementKey());
- }
- }
- }
- List deps = new ArrayList(newDeps.values());
- modelDepMgmt.setDependencies(deps);
- }
- }
- }
-
- private Model readModelLegacy( String projectId,
- File file,
- boolean strict )
- throws ProjectBuildingException
- {
- Reader reader = null;
- try
- {
- reader = ReaderFactory.newXmlReader( file );
-
- String modelSource = IOUtil.toString( reader );
-
- checkModelVersion( modelSource, projectId, file );
-
- StringReader sReader = new StringReader( modelSource );
-
- try
- {
- return modelReader.read( sReader, strict );
- }
- catch ( XmlPullParserException e )
- {
- throw new InvalidProjectModelException( projectId, "Parse error reading POM. Reason: " + e.getMessage(),
- file, e );
- }
- }
- catch ( FileNotFoundException e )
- {
- throw new ProjectBuildingException( projectId,
- "Could not find the model file '" + file.getAbsolutePath() + "'.", file, e );
- }
- catch ( IOException e )
- {
- throw new ProjectBuildingException( projectId, "Failed to build model from file '" +
- file.getAbsolutePath() + "'.\nError: \'" + e.getLocalizedMessage() + "\'", file, e );
- }
- finally
- {
- IOUtil.close( reader );
- }
- }
-
- private void checkModelVersion( String modelSource,
- String projectId,
- File file )
- throws InvalidProjectModelException
- {
- if ( modelSource.indexOf( "" + MAVEN_MODEL_VERSION ) < 0 )
- {
- throw new InvalidProjectModelException( projectId, "Not a v" + MAVEN_MODEL_VERSION + " POM.", file );
- }
- }
-
- /**
- * @deprecated use {@link #createPluginArtifacts(String, List, File)}
- * @param projectId
- * @param plugins
- * @param pomLocation absolute path of pom file
- * @return
- * @throws ProjectBuildingException
- */
- @Deprecated
- protected Set createPluginArtifacts( String projectId,
- List plugins, String pomLocation )
- throws ProjectBuildingException
- {
- return createPluginArtifacts( projectId, plugins, new File( pomLocation ) );
- }
-
- /**
- *
- * @param projectId
- * @param plugins
- * @param pomLocation pom file
- * @return
- * @throws ProjectBuildingException
- */
- protected Set createPluginArtifacts( String projectId,
- List plugins, File pomLocation )
- throws ProjectBuildingException
- {
- Set pluginArtifacts = new HashSet();
-
- for ( Iterator i = plugins.iterator(); i.hasNext(); )
- {
- Plugin p = (Plugin) i.next();
-
- String version;
- if ( StringUtils.isEmpty( p.getVersion() ) )
- {
- version = "RELEASE";
- }
- else
- {
- version = p.getVersion();
- }
-
- Artifact artifact;
- try
- {
- artifact = artifactFactory.createPluginArtifact( p.getGroupId(), p.getArtifactId(),
- VersionRange.createFromVersionSpec( version ) );
- }
- catch ( InvalidVersionSpecificationException e )
- {
- throw new InvalidProjectVersionException( projectId, "Plugin: " + p.getKey(), version, pomLocation, e );
- }
-
- if ( artifact != null )
- {
- pluginArtifacts.add( artifact );
- }
- }
-
- return pluginArtifacts;
- }
-
- /**
- * @deprecated use {@link #createReportArtifacts(String, List, File)}
- * @param projectId
- * @param reports
- * @param pomLocation absolute path of pom file
- * @return
- * @throws ProjectBuildingException
- */
- @Deprecated
- protected Set createReportArtifacts( String projectId,
- List reports, String pomLocation )
- throws ProjectBuildingException
- {
- return createReportArtifacts( projectId, reports, new File( pomLocation ) );
- }
-
- // TODO: share with createPluginArtifacts?
- protected Set createReportArtifacts( String projectId,
- List reports, File pomLocation )
- throws ProjectBuildingException
- {
- Set pluginArtifacts = new HashSet();
-
- if ( reports != null )
- {
- for ( Iterator i = reports.iterator(); i.hasNext(); )
- {
- ReportPlugin p = (ReportPlugin) i.next();
-
- String version;
- if ( StringUtils.isEmpty( p.getVersion() ) )
- {
- version = "RELEASE";
- }
- else
- {
- version = p.getVersion();
- }
-
- Artifact artifact;
- try
- {
- artifact = artifactFactory.createPluginArtifact( p.getGroupId(), p.getArtifactId(),
- VersionRange.createFromVersionSpec( version ) );
- }
- catch ( InvalidVersionSpecificationException e )
- {
- throw new InvalidProjectVersionException( projectId, "Report plugin: " + p.getKey(), version, pomLocation, e );
- }
-
- if ( artifact != null )
- {
- pluginArtifacts.add( artifact );
- }
- }
- }
-
- return pluginArtifacts;
- }
-
- /**
- * @deprecated use {@link #createExtensionArtifacts(String, List, File)}
- * @param projectId
- * @param extensions
- * @param pomLocation absolute path of pom file
- * @return
- * @throws ProjectBuildingException
- */
- @Deprecated
- protected Set createExtensionArtifacts( String projectId,
- List extensions, String pomLocation )
- throws ProjectBuildingException
- {
- return createExtensionArtifacts( projectId, extensions, new File( pomLocation ) );
- }
-
- // TODO: share with createPluginArtifacts?
- protected Set createExtensionArtifacts( String projectId,
- List extensions, File pomFile )
- throws ProjectBuildingException
- {
- Set extensionArtifacts = new HashSet();
-
- if ( extensions != null )
- {
- for ( Iterator i = extensions.iterator(); i.hasNext(); )
- {
- Extension ext = (Extension) i.next();
-
- String version;
- if ( StringUtils.isEmpty( ext.getVersion() ) )
- {
- version = "RELEASE";
- }
- else
- {
- version = ext.getVersion();
- }
-
- Artifact artifact;
- try
- {
- VersionRange versionRange = VersionRange.createFromVersionSpec( version );
- artifact =
- artifactFactory.createExtensionArtifact( ext.getGroupId(), ext.getArtifactId(), versionRange );
- }
- catch ( InvalidVersionSpecificationException e )
- {
- String key = ArtifactUtils.versionlessKey( ext.getGroupId(), ext.getArtifactId() );
- throw new InvalidProjectVersionException( projectId, "Extension: " + key,
- version, pomFile, e );
- }
-
- if ( artifact != null )
- {
- extensionArtifacts.add( artifact );
- }
- }
- }
-
- return extensionArtifacts;
- }
-
- // ----------------------------------------------------------------------
- //
- // ----------------------------------------------------------------------
-
private Model superModel;
private Model getSuperModel()
@@ -2030,7 +625,6 @@ public class DefaultMavenProjectBuilder
}
URL url = DefaultMavenProjectBuilder.class.getResource( "pom-" + MAVEN_MODEL_VERSION + ".xml" );
-
String projectId = safeVersionlessKey( STANDALONE_SUPERPOM_GROUPID, STANDALONE_SUPERPOM_ARTIFACTID );
Reader reader = null;
@@ -2039,15 +633,21 @@ public class DefaultMavenProjectBuilder
reader = ReaderFactory.newXmlReader( url.openStream() );
String modelSource = IOUtil.toString( reader );
- checkModelVersion( modelSource, projectId, null );
+ if ( modelSource.indexOf( "" + MAVEN_MODEL_VERSION ) < 0 )
+ {
+ throw new InvalidProjectModelException( projectId, "Not a v" + MAVEN_MODEL_VERSION + " POM.",
+ new File( "." ) );
+ }
StringReader sReader = new StringReader( modelSource );
- return modelReader.read( sReader, STRICT_MODEL_PARSING );
+ superModel = modelReader.read( sReader, STRICT_MODEL_PARSING );
+ return superModel;
}
catch ( XmlPullParserException e )
{
- throw new InvalidProjectModelException( projectId, "Parse error reading POM. Reason: " + e.getMessage(), e );
+ throw new InvalidProjectModelException( projectId, "Parse error reading POM. Reason: " + e.getMessage(),
+ e );
}
catch ( IOException e )
{
@@ -2060,40 +660,197 @@ public class DefaultMavenProjectBuilder
}
}
- protected Logger getLogger()
+ private MavenProject readModelFromLocalPath( String projectId, File projectDescriptor, PomArtifactResolver resolver,
+ ProjectBuilderConfiguration config )
+ throws ProjectBuildingException
{
- return logger;
+ if ( projectDescriptor == null )
+ {
+ throw new IllegalArgumentException( "projectDescriptor: null, Project Id =" + projectId );
+ }
+
+ if ( projectBuilder == null )
+ {
+ throw new IllegalArgumentException( "projectBuilder: not initialized" );
+ }
+
+ MavenProject mavenProject;
+ try
+ {
+ mavenProject = projectBuilder.buildFromLocalPath( new FileInputStream( projectDescriptor ), Arrays.asList(
+ getSuperProject( config, projectDescriptor, true ).getModel() ), null, null, resolver,
+ projectDescriptor.getParentFile(),
+ config );
+ }
+ catch ( IOException e )
+ {
+ throw new ProjectBuildingException( projectId, "File = " + projectDescriptor.getAbsolutePath(), e );
+ }
+
+ return mavenProject;
+
}
- public void enableLogging( Logger logger )
+ private void validateModel( Model model, File pomFile )
+ throws InvalidProjectModelException
{
- this.logger = logger;
+ // Must validate before artifact construction to make sure dependencies are good
+ ModelValidationResult validationResult = validator.validate( model );
+
+ String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
+
+ if ( validationResult.getMessageCount() > 0 )
+ {
+ for ( String s : (List) validationResult.getMessages() )
+ {
+ System.out.println( s );
+ }
+ try
+ {
+ Writer out = WriterFactory.newXmlWriter( System.out );
+ MavenXpp3Writer writer = new MavenXpp3Writer();
+ writer.write( out, model );
+ out.close();
+ }
+ catch ( IOException e )
+ {
+
+ }
+ throw new InvalidProjectModelException( projectId, "Failed to validate POM", pomFile, validationResult );
+ }
}
- private Model readModelFromLocalPath( String projectId,
- File projectDescriptor,
- PomArtifactResolver resolver )
- throws ProjectBuildingException
- {
- if(projectDescriptor == null) {
- throw new IllegalArgumentException("projectDescriptor: null, Project Id =" + projectId);
- }
+ private static String safeVersionlessKey( String groupId, String artifactId )
+ {
+ String gid = groupId;
- if(projectBuilder == null) {
- throw new IllegalArgumentException("projectBuilder: not initialized");
- }
+ if ( StringUtils.isEmpty( gid ) )
+ {
+ gid = "unknown";
+ }
- MavenProject mavenProject;
- try {
- mavenProject = projectBuilder.buildFromLocalPath(new FileInputStream(projectDescriptor),
- null, null, resolver,
- projectDescriptor.getParentFile());
- } catch (IOException e) {
- e.printStackTrace();
- throw new ProjectBuildingException(projectId, "File = " + projectDescriptor.getAbsolutePath() , e);
- }
+ String aid = artifactId;
- return mavenProject.getModel();
+ if ( StringUtils.isEmpty( aid ) )
+ {
+ aid = "unknown";
+ }
- }
+ return ArtifactUtils.versionlessKey( gid, aid );
+ }
+
+ private static void setBuildOutputDirectoryOnParent( MavenProject project )
+ {
+ MavenProject parent = project.getParent();
+ if ( parent != null )
+ {
+ parent.getModel().getBuild().setDirectory( parent.getFile().getAbsolutePath() );
+ setBuildOutputDirectoryOnParent( parent );
+ }
+ }
+
+ private static class DefaultModelDefaultsInjector
+ {
+ public void injectDefaults( Model model )
+ {
+ injectDependencyDefaults( model.getDependencies(), model.getDependencyManagement() );
+ if ( model.getBuild() != null )
+ {
+ injectPluginDefaults( model.getBuild(), model.getBuild().getPluginManagement() );
+ }
+ }
+
+ private static void injectPluginDefaults( Build build, PluginManagement pluginManagement )
+ {
+ if ( pluginManagement == null )
+ {
+ // nothing to inject.
+ return;
+ }
+
+ List buildPlugins = build.getPlugins();
+
+ if ( buildPlugins != null && !buildPlugins.isEmpty() )
+ {
+ Map pmPlugins = pluginManagement.getPluginsAsMap();
+
+ if ( pmPlugins != null && !pmPlugins.isEmpty() )
+ {
+ for ( Iterator it = buildPlugins.iterator(); it.hasNext(); )
+ {
+ Plugin buildPlugin = (Plugin) it.next();
+
+ Plugin pmPlugin = (Plugin) pmPlugins.get( buildPlugin.getKey() );
+
+ if ( pmPlugin != null )
+ {
+ ModelUtils.mergePluginDefinitions( buildPlugin, pmPlugin, false );
+ }
+ }
+ }
+ }
+
+ }
+
+ private static void injectDependencyDefaults( List dependencies, DependencyManagement dependencyManagement )
+ {
+ if ( dependencyManagement != null )
+ {
+ // a given project's dependencies should be smaller than the
+ // group-defined defaults set...
+ // in other words, the project's deps will probably be a subset of
+ // those specified in defaults.
+ Map depsMap = new TreeMap();
+ for ( Iterator it = dependencies.iterator(); it.hasNext(); )
+ {
+ Dependency dep = (Dependency) it.next();
+ depsMap.put( dep.getManagementKey(), dep );
+ }
+
+ List managedDependencies = dependencyManagement.getDependencies();
+
+ for ( Iterator it = managedDependencies.iterator(); it.hasNext(); )
+ {
+ Dependency def = (Dependency) it.next();
+ String key = def.getManagementKey();
+
+ Dependency dep = (Dependency) depsMap.get( key );
+ if ( dep != null )
+ {
+ mergeDependencyWithDefaults( dep, def );
+ }
+ }
+ }
+ }
+
+ private static void mergeDependencyWithDefaults( Dependency dep, Dependency def )
+ {
+ if ( dep.getScope() == null && def.getScope() != null )
+ {
+ dep.setScope( def.getScope() );
+ dep.setSystemPath( def.getSystemPath() );
+ }
+
+ if ( dep.getVersion() == null && def.getVersion() != null )
+ {
+ dep.setVersion( def.getVersion() );
+ }
+
+ if ( dep.getClassifier() == null && def.getClassifier() != null )
+ {
+ dep.setClassifier( def.getClassifier() );
+ }
+
+ if ( dep.getType() == null && def.getType() != null )
+ {
+ dep.setType( def.getType() );
+ }
+
+ List exclusions = dep.getExclusions();
+ if ( exclusions == null || exclusions.isEmpty() )
+ {
+ dep.setExclusions( def.getExclusions() );
+ }
+ }
+ }
}
diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectHelper.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectHelper.java
index 583c85b193..df35f3a6c5 100644
--- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectHelper.java
+++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectHelper.java
@@ -20,13 +20,19 @@ package org.apache.maven.project;
*/
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.InvalidArtifactRTException;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.model.Resource;
-import org.apache.maven.project.artifact.AttachedArtifact;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
import java.util.List;
public class DefaultMavenProjectHelper
@@ -36,7 +42,8 @@ public class DefaultMavenProjectHelper
private ArtifactHandlerManager artifactHandlerManager;
- public void attachArtifact( MavenProject project, String artifactType, String artifactClassifier, File artifactFile )
+ public void attachArtifact( MavenProject project, String artifactType, String artifactClassifier,
+ File artifactFile )
{
String type = artifactType;
@@ -57,7 +64,7 @@ public class DefaultMavenProjectHelper
artifact.setFile( artifactFile );
artifact.setResolved( true );
- attachArtifact(project, artifact);
+ attachArtifact( project, artifact );
}
public void attachArtifact( MavenProject project, String artifactType, File artifactFile )
@@ -69,33 +76,34 @@ public class DefaultMavenProjectHelper
artifact.setFile( artifactFile );
artifact.setResolved( true );
- attachArtifact(project, artifact);
+ attachArtifact( project, artifact );
}
public void attachArtifact( MavenProject project, File artifactFile, String artifactClassifier )
{
Artifact projectArtifact = project.getArtifact();
- Artifact artifact = new AttachedArtifact( projectArtifact, projectArtifact.getType(), artifactClassifier, projectArtifact.getArtifactHandler() );
+ Artifact artifact = new AttachedArtifact( projectArtifact, projectArtifact.getType(), artifactClassifier,
+ projectArtifact.getArtifactHandler() );
artifact.setFile( artifactFile );
artifact.setResolved( true );
- attachArtifact(project, artifact);
+ attachArtifact( project, artifact );
}
- public void attachArtifact(MavenProject project, Artifact artifact)
+ public void attachArtifact( MavenProject project, Artifact artifact )
{
try
{
- project.addAttachedArtifact( artifact );
+ project.addAttachedArtifact( artifact );
}
- catch (DuplicateArtifactAttachmentException dae)
+ catch ( DuplicateArtifactAttachmentException dae )
{
- getLogger().warn(dae.getMessage());
+ getLogger().warn( dae.getMessage() );
- // We can throw this because it's unchecked, and won't change the MavenProjectHelper API, which would break backward compat if it did.
- throw dae;
+ // We can throw this because it's unchecked, and won't change the MavenProjectHelper API, which would break backward compat if it did.
+ throw dae;
}
}
@@ -119,4 +127,140 @@ public class DefaultMavenProjectHelper
project.addTestResource( resource );
}
+ private static class AttachedArtifact
+ extends DefaultArtifact
+ {
+
+ private final Artifact parent;
+
+ public AttachedArtifact( Artifact parent, String type, String classifier, ArtifactHandler artifactHandler )
+ {
+ super( parent.getGroupId(), parent.getArtifactId(), parent.getVersionRange(), parent.getScope(), type,
+ classifier, artifactHandler, parent.isOptional() );
+
+ setDependencyTrail( Collections.singletonList( parent.getId() ) );
+
+ this.parent = parent;
+
+ if ( getId().equals( parent.getId() ) )
+ {
+ throw new InvalidArtifactRTException( parent.getGroupId(), parent.getArtifactId(), parent.getVersion(),
+ parent.getType(),
+ "An attached artifact must have a different ID than its corresponding main artifact." );
+ }
+ }
+
+ public AttachedArtifact( Artifact parent, String type, ArtifactHandler artifactHandler )
+ {
+ this( parent, type, null, artifactHandler );
+ }
+
+ public void setArtifactId( String artifactId )
+ {
+ // ignore this. We should ALWAYS use the information from the parent artifact.
+ }
+
+ public List getAvailableVersions()
+ {
+ return parent.getAvailableVersions();
+ }
+
+ public void setAvailableVersions( List availableVersions )
+ {
+ // ignore this. We should ALWAYS use the information from the parent artifact.
+ }
+
+ public String getBaseVersion()
+ {
+ return parent.getBaseVersion();
+ }
+
+ public void setBaseVersion( String baseVersion )
+ {
+ // ignore this. We should ALWAYS use the information from the parent artifact.
+ }
+
+ public String getDownloadUrl()
+ {
+ return parent.getDownloadUrl();
+ }
+
+ public void setDownloadUrl( String downloadUrl )
+ {
+ // ignore this. We should ALWAYS use the information from the parent artifact.
+ }
+
+ public void setGroupId( String groupId )
+ {
+ // ignore this. We should ALWAYS use the information from the parent artifact.
+ }
+
+ public ArtifactRepository getRepository()
+ {
+ return parent.getRepository();
+ }
+
+ public void setRepository( ArtifactRepository repository )
+ {
+ // ignore this. We should ALWAYS use the information from the parent artifact.
+ }
+
+ public String getScope()
+ {
+ return parent.getScope();
+ }
+
+ public void setScope( String scope )
+ {
+ // ignore this. We should ALWAYS use the information from the parent artifact.
+ }
+
+ public String getVersion()
+ {
+ return parent.getVersion();
+ }
+
+ public void setVersion( String version )
+ {
+ // ignore this. We should ALWAYS use the information from the parent artifact.
+ }
+
+ public VersionRange getVersionRange()
+ {
+ return parent.getVersionRange();
+ }
+
+ public void setVersionRange( VersionRange range )
+ {
+ // ignore this. We should ALWAYS use the information from the parent artifact.
+ }
+
+ public boolean isRelease()
+ {
+ return parent.isRelease();
+ }
+
+ public void setRelease( boolean release )
+ {
+ // ignore this. We should ALWAYS use the information from the parent artifact.
+ }
+
+ public boolean isSnapshot()
+ {
+ return parent.isSnapshot();
+ }
+
+ public void addMetadata( ArtifactMetadata metadata )
+ {
+ // ignore. The parent artifact will handle metadata.
+ // we must fail silently here to avoid problems with the artifact transformers.
+ }
+
+ public Collection getMetadataList()
+ {
+ return Collections.EMPTY_LIST;
+ }
+
+ }
+
}
diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultProjectBuilderConfiguration.java b/maven-project/src/main/java/org/apache/maven/project/DefaultProjectBuilderConfiguration.java
index 77fb4b7738..3f28035391 100644
--- a/maven-project/src/main/java/org/apache/maven/project/DefaultProjectBuilderConfiguration.java
+++ b/maven-project/src/main/java/org/apache/maven/project/DefaultProjectBuilderConfiguration.java
@@ -1,5 +1,24 @@
package org.apache.maven.project;
+/*
+ * 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.
+ */
+
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.profiles.ProfileManager;
diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultRepositoryHelper.java b/maven-project/src/main/java/org/apache/maven/project/DefaultRepositoryHelper.java
new file mode 100644
index 0000000000..56af83ffbb
--- /dev/null
+++ b/maven-project/src/main/java/org/apache/maven/project/DefaultRepositoryHelper.java
@@ -0,0 +1,405 @@
+package org.apache.maven.project;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.MavenTools;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.ArtifactStatus;
+import org.apache.maven.artifact.ArtifactUtils;
+import org.apache.maven.artifact.InvalidRepositoryException;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.model.DistributionManagement;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Repository;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.profiles.activation.ProfileActivationContext;
+import org.apache.maven.profiles.build.ProfileAdvisor;
+import org.codehaus.plexus.logging.LogEnabled;
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * This is a temporary class. These methods are originally from the DefaultMavenProjectHelper. This class will be
+ * eliminated when Mercury is integrated.
+ */
+public class DefaultRepositoryHelper
+ implements RepositoryHelper, Initializable, LogEnabled
+{
+
+ private Logger logger;
+
+ public static final String MAVEN_MODEL_VERSION = "4.0.0";
+
+ private ArtifactFactory artifactFactory;
+
+ private ArtifactResolver artifactResolver;
+
+ private MavenTools mavenTools;
+
+ private ProfileAdvisor profileAdvisor;
+
+ private MavenXpp3Reader modelReader;
+
+ private Logger getLogger()
+ {
+ return logger;
+ }
+
+ public Model findModelFromRepository( Artifact artifact, List remoteArtifactRepositories,
+ ArtifactRepository localRepository )
+ throws ProjectBuildingException
+ {
+
+ String projectId = safeVersionlessKey( artifact.getGroupId(), artifact.getArtifactId() );
+ remoteArtifactRepositories = normalizeToArtifactRepositories( remoteArtifactRepositories, projectId );
+
+ Artifact projectArtifact;
+
+ // if the artifact is not a POM, we need to construct a POM artifact based on the artifact parameter given.
+ if ( "pom".equals( artifact.getType() ) )
+ {
+ projectArtifact = artifact;
+ }
+ else
+ {
+ getLogger().warn( "Attempting to build MavenProject instance for Artifact (" + artifact.getGroupId() + ":" +
+ artifact.getArtifactId() + ":" + artifact.getVersion() + ") of type: " + artifact.getType() +
+ "; constructing POM artifact instead." );
+
+ projectArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(),
+ artifact.getVersion(), artifact.getScope() );
+ }
+
+ Model legacy_model;
+ try
+ {
+ artifactResolver.resolve( projectArtifact, remoteArtifactRepositories, localRepository );
+
+ File file = projectArtifact.getFile();
+ artifact.setFile( file );
+ legacy_model = readModelLegacy( projectId, file, false );
+
+ String downloadUrl = null;
+
+ ArtifactStatus status = ArtifactStatus.NONE;
+
+ DistributionManagement distributionManagement = legacy_model.getDistributionManagement();
+
+ if ( distributionManagement != null )
+ {
+ downloadUrl = distributionManagement.getDownloadUrl();
+
+ status = ArtifactStatus.valueOf( distributionManagement.getStatus() );
+ }
+
+ checkStatusAndUpdate( projectArtifact, status, file, remoteArtifactRepositories, localRepository );
+
+ // TODO: this is gross. Would like to give it the whole model, but maven-artifact shouldn't depend on that
+ // Can a maven-core implementation of the Artifact interface store it, and be used in the exceptions?
+ if ( downloadUrl != null )
+ {
+ projectArtifact.setDownloadUrl( downloadUrl );
+ }
+ else
+ {
+ projectArtifact.setDownloadUrl( legacy_model.getUrl() );
+ }
+ }
+ catch ( ArtifactResolutionException e )
+ {
+ throw new ProjectBuildingException( projectId, "Error getting POM for '" + projectId +
+ "' from the repository: " + e.getMessage(), e );
+ }
+ catch ( ArtifactNotFoundException e )
+ {
+ throw new ProjectBuildingException( projectId,
+ "POM '" + projectId + "' not found in repository: " + e.getMessage(),
+ e );
+ }
+
+ return legacy_model;
+ }
+
+ public List buildArtifactRepositories( Model model )
+ throws ProjectBuildingException
+ {
+ try
+ {
+ return mavenTools.buildArtifactRepositories( model.getRepositories() );
+ }
+ catch ( InvalidRepositoryException e )
+ {
+ String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
+
+ throw new ProjectBuildingException( projectId, e.getMessage(), e );
+ }
+ }
+
+ /*
+ * Order is:
+ *
+ * 1. model profile repositories
+ * 2. model repositories
+ * 3. superModel profile repositories
+ * 4. superModel repositories
+ * 5. parentSearchRepositories
+ */
+ public LinkedHashSet collectInitialRepositories( Model model, Model superModel, List parentSearchRepositories,
+ File pomFile, boolean validProfilesXmlLocation,
+ ProfileActivationContext profileActivationContext )
+ throws ProjectBuildingException
+ {
+ LinkedHashSet collected = new LinkedHashSet();
+
+ collectInitialRepositoriesFromModel( collected, model, pomFile, validProfilesXmlLocation,
+ profileActivationContext );
+
+ collectInitialRepositoriesFromModel( collected, superModel, null, validProfilesXmlLocation,
+ profileActivationContext );
+
+ if ( ( parentSearchRepositories != null ) && !parentSearchRepositories.isEmpty() )
+ {
+ collected.addAll( parentSearchRepositories );
+ }
+
+ return collected;
+ }
+
+ private List normalizeToArtifactRepositories( List remoteArtifactRepositories, String projectId )
+ throws ProjectBuildingException
+ {
+ List normalized = new ArrayList( remoteArtifactRepositories.size() );
+
+ boolean normalizationNeeded = false;
+ for ( Iterator it = remoteArtifactRepositories.iterator(); it.hasNext(); )
+ {
+ Object item = it.next();
+
+ if ( item instanceof ArtifactRepository )
+ {
+ normalized.add( item );
+ }
+ else if ( item instanceof Repository )
+ {
+ Repository repo = (Repository) item;
+ try
+ {
+ item = mavenTools.buildArtifactRepository( repo );
+
+ normalized.add( item );
+ normalizationNeeded = true;
+ }
+ catch ( InvalidRepositoryException e )
+ {
+ throw new ProjectBuildingException( projectId,
+ "Error building artifact repository for id: " + repo.getId(),
+ e );
+ }
+ }
+ else
+ {
+ throw new ProjectBuildingException( projectId,
+ "Error building artifact repository from non-repository information item: " +
+ item );
+ }
+ }
+
+ if ( normalizationNeeded )
+ {
+ return normalized;
+ }
+ else
+ {
+ return remoteArtifactRepositories;
+ }
+ }
+
+ private String safeVersionlessKey( String groupId, String artifactId )
+ {
+ String gid = groupId;
+
+ if ( StringUtils.isEmpty( gid ) )
+ {
+ gid = "unknown";
+ }
+
+ String aid = artifactId;
+
+ if ( StringUtils.isEmpty( aid ) )
+ {
+ aid = "unknown";
+ }
+
+ return ArtifactUtils.versionlessKey( gid, aid );
+ }
+
+ private void checkModelVersion( String modelSource, String projectId, File file )
+ throws InvalidProjectModelException
+ {
+ if ( modelSource.indexOf( "4.0.0" ) < 0 )
+ {
+ throw new InvalidProjectModelException( projectId, "Not a v" + MAVEN_MODEL_VERSION + " POM.", file );
+ }
+ }
+
+ private Model readModelLegacy( String projectId, File file, boolean strict )
+ throws ProjectBuildingException
+ {
+ Reader reader = null;
+ try
+ {
+ reader = ReaderFactory.newXmlReader( file );
+
+ String modelSource = IOUtil.toString( reader );
+
+ checkModelVersion( modelSource, projectId, file );
+
+ StringReader sReader = new StringReader( modelSource );
+
+ try
+ {
+ return new MavenXpp3Reader().read( sReader, strict );
+ }
+ catch ( XmlPullParserException e )
+ {
+ throw new InvalidProjectModelException( projectId, "Parse error reading POM. Reason: " + e.getMessage(),
+ file, e );
+ }
+ }
+ catch ( FileNotFoundException e )
+ {
+ throw new ProjectBuildingException( projectId,
+ "Could not find the model file '" + file.getAbsolutePath() + "'.", file,
+ e );
+ }
+ catch ( IOException e )
+ {
+ throw new ProjectBuildingException( projectId, "Failed to build model from file '" +
+ file.getAbsolutePath() + "'.\nError: \'" + e.getLocalizedMessage() + "\'", file, e );
+ }
+ finally
+ {
+ IOUtil.close( reader );
+ }
+ }
+
+ private void collectInitialRepositoriesFromModel( LinkedHashSet collected, Model model, File pomFile,
+ boolean validProfilesXmlLocation,
+ ProfileActivationContext profileActivationContext )
+ throws ProjectBuildingException
+ {
+
+ Set reposFromProfiles = profileAdvisor.getArtifactRepositoriesFromActiveProfiles( model, pomFile,
+ validProfilesXmlLocation,
+ profileActivationContext );
+
+ if ( ( reposFromProfiles != null ) && !reposFromProfiles.isEmpty() )
+ {
+ collected.addAll( reposFromProfiles );
+ }
+
+ List modelRepos = model.getRepositories();
+
+ if ( ( modelRepos != null ) && !modelRepos.isEmpty() )
+ {
+ try
+ {
+ collected.addAll( mavenTools.buildArtifactRepositories( modelRepos ) );
+ }
+ catch ( InvalidRepositoryException e )
+ {
+ throw new ProjectBuildingException( safeVersionlessKey( model.getGroupId(), model.getArtifactId() ),
+ "Failed to construct ArtifactRepository instances for repositories declared in: " +
+ model.getId(), e );
+ }
+ }
+ }
+
+ private void checkStatusAndUpdate( Artifact projectArtifact, ArtifactStatus status, File file,
+ List remoteArtifactRepositories, ArtifactRepository localRepository )
+ throws ArtifactNotFoundException
+ {
+ // TODO: configurable actions dependant on status
+ if ( !projectArtifact.isSnapshot() && ( status.compareTo( ArtifactStatus.DEPLOYED ) < 0 ) )
+ {
+ // use default policy (enabled, daily update, warn on bad checksum)
+ ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy();
+ // TODO: re-enable [MNG-798/865]
+ policy.setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER );
+
+ if ( policy.checkOutOfDate( new Date( file.lastModified() ) ) )
+ {
+ getLogger().info(
+ projectArtifact.getArtifactId() + ": updating metadata due to status of '" + status + "'" );
+ try
+ {
+ projectArtifact.setResolved( false );
+ artifactResolver.resolveAlways( projectArtifact, remoteArtifactRepositories, localRepository );
+ }
+ catch ( ArtifactResolutionException e )
+ {
+ getLogger().warn( "Error updating POM - using existing version" );
+ getLogger().debug( "Cause", e );
+ }
+ catch ( ArtifactNotFoundException e )
+ {
+ getLogger().warn( "Error updating POM - not found. Removing local copy." );
+ getLogger().debug( "Cause", e );
+ file.delete();
+ throw e;
+ }
+ }
+ }
+ }
+
+
+ public void initialize()
+ throws InitializationException
+ {
+ modelReader = new MavenXpp3Reader();
+ }
+
+ public void enableLogging( Logger logger )
+ {
+ this.logger = logger;
+ }
+}
\ No newline at end of file
diff --git a/maven-project/src/main/java/org/apache/maven/project/DuplicateArtifactAttachmentException.java b/maven-project/src/main/java/org/apache/maven/project/DuplicateArtifactAttachmentException.java
index cddf1dcfe6..6121473da3 100644
--- a/maven-project/src/main/java/org/apache/maven/project/DuplicateArtifactAttachmentException.java
+++ b/maven-project/src/main/java/org/apache/maven/project/DuplicateArtifactAttachmentException.java
@@ -27,9 +27,8 @@ import org.apache.maven.artifact.Artifact;
*
* @author pgier
* @author jdcasey
- *
* @todo Make this a checked exception, and modify the API of MavenProjectHelper.
- * Currently, this modification would create compatibility problems for existing plugins.
+ * Currently, this modification would create compatibility problems for existing plugins.
*/
public class DuplicateArtifactAttachmentException
extends RuntimeException
@@ -48,8 +47,7 @@ public class DuplicateArtifactAttachmentException
this.artifact = artifact;
}
- private static String constructMessage( MavenProject project,
- Artifact artifact )
+ private static String constructMessage( MavenProject project, Artifact artifact )
{
return DEFAULT_MESSAGE + " (project: " + project.getId() + "; illegal attachment: " + artifact.getId() + ")";
}
diff --git a/maven-project/src/main/java/org/apache/maven/project/DuplicateProjectException.java b/maven-project/src/main/java/org/apache/maven/project/DuplicateProjectException.java
index 501992ff52..42f66c3575 100644
--- a/maven-project/src/main/java/org/apache/maven/project/DuplicateProjectException.java
+++ b/maven-project/src/main/java/org/apache/maven/project/DuplicateProjectException.java
@@ -43,7 +43,7 @@ public class DuplicateProjectException
{
this( null, null, null, message );
}
-
+
/**
* @deprecated use {@link #DuplicateProjectException(String, File, File, String)}
*/
@@ -55,9 +55,7 @@ public class DuplicateProjectException
this.conflictingProjectFile = null;
}
- public DuplicateProjectException( String projectId,
- File existingProjectFile,
- File conflictingProjectFile,
+ public DuplicateProjectException( String projectId, File existingProjectFile, File conflictingProjectFile,
String message )
{
super( message );
diff --git a/maven-project/src/main/java/org/apache/maven/project/InvalidProjectModelException.java b/maven-project/src/main/java/org/apache/maven/project/InvalidProjectModelException.java
index fb55891f19..7cb667c925 100644
--- a/maven-project/src/main/java/org/apache/maven/project/InvalidProjectModelException.java
+++ b/maven-project/src/main/java/org/apache/maven/project/InvalidProjectModelException.java
@@ -37,11 +37,11 @@ public class InvalidProjectModelException
}
/**
- * @deprecated use {@link File} constructor for pomLocation
* @param projectId
- * @param pomLocation absolute path of the pom file
+ * @param pomLocation absolute path of the pom file
* @param message
* @param validationResult
+ * @deprecated use {@link File} constructor for pomLocation
*/
public InvalidProjectModelException( String projectId, String pomLocation, String message,
ModelValidationResult validationResult )
@@ -58,10 +58,10 @@ public class InvalidProjectModelException
}
/**
- * @deprecated use {@link File} constructor for pomLocation
* @param projectId
* @param pomLocation absolute path of the pom file
* @param message
+ * @deprecated use {@link File} constructor for pomLocation
*/
public InvalidProjectModelException( String projectId, String pomLocation, String message )
{
diff --git a/maven-project/src/main/java/org/apache/maven/project/InvalidProjectVersionException.java b/maven-project/src/main/java/org/apache/maven/project/InvalidProjectVersionException.java
index e8e8979171..ade7198378 100644
--- a/maven-project/src/main/java/org/apache/maven/project/InvalidProjectVersionException.java
+++ b/maven-project/src/main/java/org/apache/maven/project/InvalidProjectVersionException.java
@@ -1,5 +1,24 @@
package org.apache.maven.project;
+/*
+ * 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.
+ */
+
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import java.io.File;
@@ -9,21 +28,22 @@ public class InvalidProjectVersionException
{
private final String locationInPom;
+
private final String offendingVersion;
- public InvalidProjectVersionException( String projectId, String locationInPom, String offendingVersion, File pomFile, InvalidVersionSpecificationException cause )
+ public InvalidProjectVersionException( String projectId, String locationInPom, String offendingVersion,
+ File pomFile, InvalidVersionSpecificationException cause )
{
super( projectId, formatMessage( projectId, locationInPom, offendingVersion, cause ), pomFile, cause );
this.locationInPom = locationInPom;
this.offendingVersion = offendingVersion;
}
- private static String formatMessage( String projectId,
- String locationInPom,
- String offendingVersion,
+ private static String formatMessage( String projectId, String locationInPom, String offendingVersion,
InvalidVersionSpecificationException cause )
{
- return "Invalid version: " + offendingVersion + " found for: " + locationInPom + " in project: " + projectId + ". Reason: " + cause.getMessage();
+ return "Invalid version: " + offendingVersion + " found for: " + locationInPom + " in project: " + projectId +
+ ". Reason: " + cause.getMessage();
}
public String getOffendingVersion()
diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
index cb95d52355..dbb62a3af3 100644
--- a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
+++ b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java
@@ -19,13 +19,18 @@ package org.apache.maven.project;
* under the License.
*/
+import org.apache.maven.MavenTools;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.ManagedVersionMap;
+import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.model.Build;
import org.apache.maven.model.CiManagement;
import org.apache.maven.model.Contributor;
@@ -33,11 +38,14 @@ import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Developer;
import org.apache.maven.model.DistributionManagement;
+import org.apache.maven.model.Exclusion;
+import org.apache.maven.model.Extension;
import org.apache.maven.model.IssueManagement;
import org.apache.maven.model.License;
import org.apache.maven.model.MailingList;
import org.apache.maven.model.Model;
import org.apache.maven.model.Organization;
+import org.apache.maven.model.Parent;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.PluginManagement;
@@ -51,6 +59,7 @@ import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.project.artifact.ActiveProjectArtifact;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.artifact.MavenMetadataSource;
+import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import java.io.File;
@@ -59,7 +68,9 @@ import java.io.Writer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -153,6 +164,28 @@ public class MavenProject
private Stack previousExecutionProjects = new Stack();
+ private ArtifactFactory artifactFactory;
+
+ private MavenTools mavenTools;
+
+ private RepositoryHelper repositoryHelper;
+
+ private MavenProjectBuilder mavenProjectBuilder;
+
+ private ProjectBuilderConfiguration projectBuilderConfiguration;
+
+ private File parentFile;
+
+ public File getParentFile()
+ {
+ return parentFile;
+ }
+
+ public void setParentFile( File parentFile )
+ {
+ this.parentFile = parentFile;
+ }
+
public MavenProject()
{
Model model = new Model();
@@ -169,6 +202,53 @@ public class MavenProject
setModel( model );
}
+ public MavenProject( Model model, ArtifactFactory artifactFactory, MavenTools mavenTools,
+ RepositoryHelper repositoryHelper, MavenProjectBuilder mavenProjectBuilder,
+ ProjectBuilderConfiguration projectBuilderConfiguration )
+ throws InvalidRepositoryException
+ {
+ setModel( model );
+ this.artifactFactory = artifactFactory;
+ this.mavenTools = mavenTools;
+ this.repositoryHelper = repositoryHelper;
+ this.mavenProjectBuilder = mavenProjectBuilder;
+ this.projectBuilderConfiguration = projectBuilderConfiguration;
+ originalModel = ModelUtils.cloneModel( model );
+ DistributionManagement dm = model.getDistributionManagement();
+
+ if ( dm != null )
+ {
+ ArtifactRepository repo = mavenTools.buildDeploymentArtifactRepository( dm.getRepository() );
+ setReleaseArtifactRepository( repo );
+
+ if ( dm.getSnapshotRepository() != null )
+ {
+ repo = mavenTools.buildDeploymentArtifactRepository( dm.getSnapshotRepository() );
+ setSnapshotArtifactRepository( repo );
+ }
+ }
+
+ try
+ {
+ LinkedHashSet repoSet = new LinkedHashSet();
+ if ( ( model.getRepositories() != null ) && !model.getRepositories().isEmpty() )
+ {
+ repoSet.addAll( model.getRepositories() );
+ }
+
+ if ( ( model.getPluginRepositories() != null ) && !model.getPluginRepositories().isEmpty() )
+ {
+ repoSet.addAll( model.getPluginRepositories() );
+ }
+
+ setRemoteArtifactRepositories( mavenTools.buildArtifactRepositories( new ArrayList( repoSet ) ) );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+
/**
* @deprecated use {@link #clone()} so subclasses can provide a copy of the same class
*/
@@ -178,7 +258,8 @@ public class MavenProject
deepCopy( project );
}
- private final void deepCopy(MavenProject project){
+ private final void deepCopy( MavenProject project )
+ {
// disown the parent
// copy fields
@@ -196,11 +277,16 @@ public class MavenProject
setArtifacts( Collections.unmodifiableSet( project.getArtifacts() ) );
}
- if ( project.getPluginArtifacts() != null )
+ if ( project.getParentFile() != null )
{
- setPluginArtifacts( Collections.unmodifiableSet( project.getPluginArtifacts() ) );
+ parentFile = new File( project.getParentFile().getAbsolutePath() );
}
+ // if ( project.getPluginArtifacts() != null )
+ // {
+ // setPluginArtifacts( Collections.unmodifiableSet( project.getPluginArtifacts() ) );
+ // }
+
if ( project.getReportArtifacts() != null )
{
setReportArtifacts( Collections.unmodifiableSet( project.getReportArtifacts() ) );
@@ -220,7 +306,8 @@ public class MavenProject
if ( project.getPluginArtifactRepositories() != null )
{
- setPluginArtifactRepositories( ( Collections.unmodifiableList( project.getPluginArtifactRepositories() ) ) );
+ setPluginArtifactRepositories(
+ ( Collections.unmodifiableList( project.getPluginArtifactRepositories() ) ) );
}
if ( project.getCollectedProjects() != null )
@@ -293,24 +380,24 @@ public class MavenProject
if ( dynamicRoots != null )
{
setDynamicCompileSourceRoots( new ArrayList( dynamicRoots ) );
- setOriginalInterpolatedCompileSourceRoots( new ArrayList(
- project.getOriginalInterpolatedCompileSourceRoots() ) );
+ setOriginalInterpolatedCompileSourceRoots(
+ new ArrayList( project.getOriginalInterpolatedCompileSourceRoots() ) );
}
dynamicRoots = project.getDynamicTestCompileSourceRoots();
if ( dynamicRoots != null )
{
setDynamicTestCompileSourceRoots( new ArrayList( dynamicRoots ) );
- setOriginalInterpolatedTestCompileSourceRoots( new ArrayList(
- project.getOriginalInterpolatedTestCompileSourceRoots() ) );
+ setOriginalInterpolatedTestCompileSourceRoots(
+ new ArrayList( project.getOriginalInterpolatedTestCompileSourceRoots() ) );
}
dynamicRoots = project.getDynamicScriptSourceRoots();
if ( dynamicRoots != null )
{
setDynamicScriptSourceRoots( new ArrayList( dynamicRoots ) );
- setOriginalInterpolatedScriptSourceRoots( new ArrayList(
- project.getOriginalInterpolatedScriptSourceRoots() ) );
+ setOriginalInterpolatedScriptSourceRoots(
+ new ArrayList( project.getOriginalInterpolatedScriptSourceRoots() ) );
}
}
@@ -319,7 +406,8 @@ public class MavenProject
// TODO: Find a way to use here...it's tricky, because the moduleProject
// usually doesn't have a file associated with it yet.
- public String getModulePathAdjustment( MavenProject moduleProject ) throws IOException
+ public String getModulePathAdjustment( MavenProject moduleProject )
+ throws IOException
{
// FIXME: This is hacky. What if module directory doesn't match artifactid, and parent
// is coming from the repository??
@@ -396,6 +484,43 @@ public class MavenProject
public MavenProject getParent()
{
+ if ( parent == null )
+ {
+ if ( parentFile != null )
+ {
+ try
+ {
+ parent = mavenProjectBuilder.build( parentFile, projectBuilderConfiguration );
+ }
+ catch ( ProjectBuildingException e )
+ {
+ e.printStackTrace();
+ }
+ }
+ else if ( model.getParent() != null )
+ {
+ try
+ {
+ parent = mavenProjectBuilder.buildFromRepository( getParentArtifact(),
+ this.remoteArtifactRepositories,
+ projectBuilderConfiguration.getLocalRepository() );
+ }
+ catch ( ProjectBuildingException e )
+ {
+ e.printStackTrace();
+ }
+ }
+ /*
+ else
+ {
+ try {
+ parent = mavenProjectBuilder.buildStandaloneSuperProject(projectBuilderConfiguration);
+ } catch (ProjectBuildingException e) {
+ e.printStackTrace();
+ }
+ }
+ */
+ }
return parent;
}
@@ -1144,6 +1269,7 @@ public class MavenProject
* All dependencies that this project has, including transitive ones.
* Contents are lazily populated, so depending on what phases have run dependencies in some scopes won't be included.
* eg. if only compile phase has run, dependencies with scope test won't be included.
+ *
* @return {@link Set} < {@link Artifact} >
* @see #getDependencyArtifacts() to get only direct dependencies
*/
@@ -1162,25 +1288,55 @@ public class MavenProject
return artifactMap;
}
- public void setPluginArtifacts( Set pluginArtifacts )
- {
- this.pluginArtifacts = pluginArtifacts;
-
- pluginArtifactMap = null;
- }
-
public Set getPluginArtifacts()
{
+ if ( pluginArtifacts != null )
+ {
+ return pluginArtifacts;
+ }
+ Set pa = new HashSet();
+ if ( artifactFactory != null )
+ {
+ List plugins = getBuildPlugins();
+ for ( Iterator i = plugins.iterator(); i.hasNext(); )
+ {
+ Plugin p = (Plugin) i.next();
+
+ String version;
+ if ( StringUtils.isEmpty( p.getVersion() ) )
+ {
+ version = "RELEASE";
+ }
+ else
+ {
+ version = p.getVersion();
+ }
+
+ Artifact artifact;
+ try
+ {
+ artifact = artifactFactory.createPluginArtifact( p.getGroupId(), p.getArtifactId(),
+ VersionRange.createFromVersionSpec( version ) );
+ }
+ catch ( InvalidVersionSpecificationException e )
+ {
+ return pa;
+ }
+
+ if ( artifact != null )
+ {
+ pa.add( artifact );
+ }
+ }
+ }
+ pluginArtifacts = pa;
+ pluginArtifactMap = null;
return pluginArtifacts;
}
public Map getPluginArtifactMap()
{
- if ( pluginArtifactMap == null )
- {
- pluginArtifactMap = ArtifactUtils.artifactMapByVersionlessId( getPluginArtifacts() );
- }
-
+ pluginArtifactMap = ArtifactUtils.artifactMapByVersionlessId( getPluginArtifacts() );
return pluginArtifactMap;
}
@@ -1193,6 +1349,42 @@ public class MavenProject
public Set getReportArtifacts()
{
+ Set pluginArtifacts = new HashSet();
+ List reports = getReportPlugins();
+ if ( reports != null )
+ {
+ for ( Iterator i = reports.iterator(); i.hasNext(); )
+ {
+ ReportPlugin p = (ReportPlugin) i.next();
+
+ String version;
+ if ( StringUtils.isEmpty( p.getVersion() ) )
+ {
+ version = "RELEASE";
+ }
+ else
+ {
+ version = p.getVersion();
+ }
+
+ Artifact artifact = null;
+ try
+ {
+ artifact = artifactFactory.createPluginArtifact( p.getGroupId(), p.getArtifactId(),
+ VersionRange.createFromVersionSpec( version ) );
+ }
+ catch ( InvalidVersionSpecificationException e )
+ {
+ //throw new InvalidProjectVersionException( projectId, "Report plugin: " + p.getKey(), version, pomLocation, e );
+ }
+
+ if ( artifact != null )
+ {
+ pluginArtifacts.add( artifact );
+ }
+ }
+ }
+ reportArtifactMap = null;
return reportArtifacts;
}
@@ -1215,6 +1407,43 @@ public class MavenProject
public Set getExtensionArtifacts()
{
+ Set extensionArtifacts = new HashSet();
+ List extensions = getBuildExtensions();
+ if ( extensions != null )
+ {
+ for ( Iterator i = extensions.iterator(); i.hasNext(); )
+ {
+ Extension ext = (Extension) i.next();
+
+ String version;
+ if ( StringUtils.isEmpty( ext.getVersion() ) )
+ {
+ version = "RELEASE";
+ }
+ else
+ {
+ version = ext.getVersion();
+ }
+
+ Artifact artifact = null;
+ try
+ {
+ VersionRange versionRange = VersionRange.createFromVersionSpec( version );
+ artifact =
+ artifactFactory.createExtensionArtifact( ext.getGroupId(), ext.getArtifactId(), versionRange );
+ }
+ catch ( InvalidVersionSpecificationException e )
+ {
+
+ }
+
+ if ( artifact != null )
+ {
+ extensionArtifacts.add( artifact );
+ }
+ }
+ }
+ extensionArtifactMap = null;
return extensionArtifacts;
}
@@ -1235,6 +1464,11 @@ public class MavenProject
public Artifact getParentArtifact()
{
+ if ( parentArtifact == null && model.getParent() != null )
+ {
+ Parent p = model.getParent();
+ parentArtifact = artifactFactory.createParentArtifact( p.getGroupId(), p.getArtifactId(), p.getVersion() );
+ }
return parentArtifact;
}
@@ -1357,7 +1591,8 @@ public class MavenProject
public ArtifactRepository getDistributionManagementArtifactRepository()
{
- return getArtifact().isSnapshot() && ( getSnapshotArtifactRepository() != null ) ? getSnapshotArtifactRepository()
+ return getArtifact().isSnapshot() && ( getSnapshotArtifactRepository() != null )
+ ? getSnapshotArtifactRepository()
: getReleaseArtifactRepository();
}
@@ -1527,6 +1762,7 @@ public class MavenProject
/**
* Direct dependencies that this project has.
+ *
* @return {@link Set} < {@link Artifact} >
* @see #getArtifacts() to get all transitive dependencies
*/
@@ -1567,6 +1803,77 @@ public class MavenProject
public Map getManagedVersionMap()
{
+ if ( managedVersionMap != null )
+ {
+ return managedVersionMap;
+ }
+
+ Map map = null;
+ if ( artifactFactory != null )
+ {
+
+ List deps;
+ DependencyManagement dependencyManagement = getDependencyManagement();
+ if ( ( dependencyManagement != null ) && ( ( deps = dependencyManagement.getDependencies() ) != null ) &&
+ ( deps.size() > 0 ) )
+ {
+ map = new ManagedVersionMap( map );
+ 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() );
+
+ if ( Artifact.SCOPE_SYSTEM.equals( d.getScope() ) && ( d.getSystemPath() != null ) )
+ {
+ artifact.setFile( new File( d.getSystemPath() ) );
+ }
+
+ // If the dependencyManagement section listed exclusions,
+ // add them to the managed artifacts here so that transitive
+ // dependencies will be excluded if necessary.
+
+ if ( ( null != d.getExclusions() ) && !d.getExclusions().isEmpty() )
+ {
+ List exclusions = new ArrayList();
+
+ for ( Iterator j = d.getExclusions().iterator(); j.hasNext(); )
+ {
+ Exclusion e = (Exclusion) j.next();
+
+ exclusions.add( e.getGroupId() + ":" + e.getArtifactId() );
+ }
+
+ ExcludesArtifactFilter eaf = new ExcludesArtifactFilter( exclusions );
+
+ artifact.setDependencyFilter( eaf );
+ }
+ else
+ {
+ artifact.setDependencyFilter( null );
+ }
+
+ map.put( d.getManagementKey(), artifact );
+ }
+ catch ( InvalidVersionSpecificationException e )
+ {
+ map = Collections.EMPTY_MAP;
+ }
+ }
+ }
+ else if ( map == null )
+ {
+ map = Collections.EMPTY_MAP;
+ }
+ }
+ managedVersionMap = map;
return managedVersionMap;
}
@@ -1609,8 +1916,8 @@ public class MavenProject
}
/**
- * @todo the lazy initialisation of this makes me uneasy.
* @return {@link Set} < {@link Artifact} >
+ * @todo the lazy initialisation of this makes me uneasy.
*/
public Set createArtifacts( ArtifactFactory artifactFactory, String inheritedScope,
ArtifactFilter dependencyFilter )
@@ -1622,7 +1929,8 @@ public class MavenProject
public void addProjectReference( MavenProject project )
{
- projectReferences.put( getProjectReferenceId( project.getGroupId(), project.getArtifactId(), project.getVersion() ), project );
+ projectReferences.put(
+ getProjectReferenceId( project.getGroupId(), project.getArtifactId(), project.getVersion() ), project );
}
private static String getProjectReferenceId( String groupId, String artifactId, String version )
@@ -1708,7 +2016,8 @@ public class MavenProject
{
if ( ( getProjectReferences() != null ) && !getProjectReferences().isEmpty() )
{
- String refId = getProjectReferenceId( pluginArtifact.getGroupId(), pluginArtifact.getArtifactId(), pluginArtifact.getVersion() );
+ String refId = getProjectReferenceId( pluginArtifact.getGroupId(), pluginArtifact.getArtifactId(),
+ pluginArtifact.getVersion() );
MavenProject ref = (MavenProject) getProjectReferences().get( refId );
if ( ( ref != null ) && ( ref.getArtifact() != null ) )
{
@@ -1732,9 +2041,11 @@ public class MavenProject
}
Iterator itr = ref.getAttachedArtifacts().iterator();
- while(itr.hasNext()) {
+ while ( itr.hasNext() )
+ {
Artifact attached = (Artifact) itr.next();
- if( attached.getDependencyConflictId().equals(pluginArtifact.getDependencyConflictId()) ) {
+ if ( attached.getDependencyConflictId().equals( pluginArtifact.getDependencyConflictId() ) )
+ {
/* TODO: if I use the original, I get an exception below:
java.lang.UnsupportedOperationException: Cannot change the download information for an attached artifact. It is derived from the main artifact.
at org.apache.maven.project.artifact.AttachedArtifact.setDownloadUrl(AttachedArtifact.java:89)
@@ -1756,8 +2067,8 @@ public class MavenProject
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:256)
*/
- Artifact resultArtifact=ArtifactUtils.copyArtifact(attached);
- resultArtifact.setScope(pluginArtifact.getScope());
+ Artifact resultArtifact = ArtifactUtils.copyArtifact( attached );
+ resultArtifact.setScope( pluginArtifact.getScope() );
return resultArtifact;
}
}
@@ -1780,9 +2091,7 @@ public class MavenProject
( pluginArtifact.getType().equals( "ejb-client" ) ) &&
( ( ref.getArtifact().getFile() != null ) && ref.getArtifact().getFile().exists() ) )
{
- pluginArtifact = new ActiveProjectArtifact(
- ref,
- pluginArtifact );
+ pluginArtifact = new ActiveProjectArtifact( ref, pluginArtifact );
return pluginArtifact;
}
}
@@ -1790,7 +2099,8 @@ public class MavenProject
return pluginArtifact;
}
- private void addArtifactPath(Artifact a, List list) throws DependencyResolutionRequiredException
+ private void addArtifactPath( Artifact a, List list )
+ throws DependencyResolutionRequiredException
{
String refId = getProjectReferenceId( a.getGroupId(), a.getArtifactId(), a.getVersion() );
MavenProject project = (MavenProject) projectReferences.get( refId );
@@ -1798,7 +2108,7 @@ public class MavenProject
boolean projectDirFound = false;
if ( project != null )
{
- if (a.getType().equals("test-jar"))
+ if ( a.getType().equals( "test-jar" ) )
{
File testOutputDir = new File( project.getBuild().getTestOutputDirectory() );
if ( testOutputDir.exists() )
@@ -1813,7 +2123,7 @@ public class MavenProject
projectDirFound = true;
}
}
- if ( ! projectDirFound )
+ if ( !projectDirFound )
{
File file = a.getFile();
if ( file == null )
@@ -1840,13 +2150,14 @@ public class MavenProject
{
return (Plugin) getBuild().getPluginsAsMap().get( pluginKey );
}
+
/**
* Default toString
*/
@Override
public String toString()
{
- StringBuffer sb = new StringBuffer(30);
+ StringBuffer sb = new StringBuffer( 30 );
sb.append( "MavenProject: " );
sb.append( getGroupId() );
sb.append( ":" );
@@ -1859,7 +2170,7 @@ public class MavenProject
{
sb.append( getFile().getPath() );
}
- catch (NullPointerException e)
+ catch ( NullPointerException e )
{
//don't log it.
}
diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java
index f65963901c..9653e9b533 100644
--- a/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java
+++ b/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java
@@ -43,21 +43,17 @@ public interface MavenProjectBuilder
* @deprecated Use {@link MavenProjectBuilder#build(File, ProjectBuilderConfiguration)} instead.
*/
@Deprecated
- MavenProject build( File project,
- ArtifactRepository localRepository,
- ProfileManager globalProfileManager )
+ MavenProject build( File project, ArtifactRepository localRepository, ProfileManager globalProfileManager )
throws ProjectBuildingException;
MavenProject build( File project, ProjectBuilderConfiguration configuration )
throws ProjectBuildingException;
- MavenProject buildWithDependencies( File project,
- ArtifactRepository localRepository,
+ MavenProject buildWithDependencies( File project, ArtifactRepository localRepository,
ProfileManager globalProfileManager )
throws ProjectBuildingException;
- MavenProjectBuildingResult buildProjectWithDependencies( File project,
- ProjectBuilderConfiguration config )
+ MavenProjectBuildingResult buildProjectWithDependencies( File project, ProjectBuilderConfiguration config )
throws ProjectBuildingException;
@@ -65,23 +61,21 @@ public interface MavenProjectBuilder
* @deprecated Use {@link MavenProjectBuilder#buildProjectWithDependencies(File, ProjectBuilderConfiguration)} instead.
*/
@Deprecated
- MavenProjectBuildingResult buildProjectWithDependencies( File project,
- ArtifactRepository localRepository,
+ MavenProjectBuildingResult buildProjectWithDependencies( File project, ArtifactRepository localRepository,
ProfileManager globalProfileManager )
throws ProjectBuildingException;
- MavenProject buildFromRepository( Artifact artifact,
- List remoteArtifactRepositories,
+ MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories,
ArtifactRepository localRepository )
throws ProjectBuildingException;
- /** @deprecated We do not want to allow projects to not have POMs. Maven 1.x repositories be damned. */
+ /**
+ * @deprecated We do not want to allow projects to not have POMs. Maven 1.x repositories be damned.
+ */
@Deprecated
- MavenProject buildFromRepository( Artifact artifact,
- List remoteArtifactRepositories,
- ArtifactRepository localRepository,
- boolean allowStub )
+ MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories,
+ ArtifactRepository localRepository, boolean allowStub )
throws ProjectBuildingException;
/**
@@ -105,11 +99,9 @@ public interface MavenProjectBuilder
// API BELOW IS USED TO PRESERVE DYNAMISM IN THE BUILD SECTION OF THE POM.
// ----------------------------------------------------------------------------
- void calculateConcreteState( MavenProject project,
- ProjectBuilderConfiguration config )
+ void calculateConcreteState( MavenProject project, ProjectBuilderConfiguration config )
throws ModelInterpolationException;
- void restoreDynamicState( MavenProject project,
- ProjectBuilderConfiguration config )
+ void restoreDynamicState( MavenProject project, ProjectBuilderConfiguration config )
throws ModelInterpolationException;
}
diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuildingResult.java b/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuildingResult.java
index bbf8e73f9e..ea39f2bf7e 100644
--- a/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuildingResult.java
+++ b/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuildingResult.java
@@ -31,8 +31,7 @@ public class MavenProjectBuildingResult
private ArtifactResolutionResult artifactResolutionResult;
- public MavenProjectBuildingResult( MavenProject project,
- ArtifactResolutionResult artifactResolutionResult )
+ public MavenProjectBuildingResult( MavenProject project, ArtifactResolutionResult artifactResolutionResult )
{
this.project = project;
diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProjectHelper.java b/maven-project/src/main/java/org/apache/maven/project/MavenProjectHelper.java
index 0da5bf6c0a..c652661b05 100644
--- a/maven-project/src/main/java/org/apache/maven/project/MavenProjectHelper.java
+++ b/maven-project/src/main/java/org/apache/maven/project/MavenProjectHelper.java
@@ -23,17 +23,17 @@ import java.io.File;
import java.util.List;
public interface MavenProjectHelper
-{
+{
String ROLE = MavenProjectHelper.class.getName();
void attachArtifact( MavenProject project, File artifactFile, String artifactClassifier );
-
+
void attachArtifact( MavenProject project, String artifactType, File artifactFile );
-
+
void attachArtifact( MavenProject project, String artifactType, String artifactClassifier, File artifactFile );
-
+
void addResource( MavenProject project, String resourceDirectory, List includes, List excludes );
-
+
void addTestResource( MavenProject project, String resourceDirectory, List includes, List excludes );
-
+
}
diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProjectRestorer.java b/maven-project/src/main/java/org/apache/maven/project/MavenProjectRestorer.java
new file mode 100644
index 0000000000..b74495293b
--- /dev/null
+++ b/maven-project/src/main/java/org/apache/maven/project/MavenProjectRestorer.java
@@ -0,0 +1,527 @@
+package org.apache.maven.project;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.model.Build;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Resource;
+import org.apache.maven.project.interpolation.ModelInterpolationException;
+import org.apache.maven.project.interpolation.ModelInterpolator;
+import org.apache.maven.project.path.PathTranslator;
+import org.codehaus.plexus.logging.Logger;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+
+final class MavenProjectRestorer
+{
+
+ private ModelInterpolator modelInterpolator;
+
+ private PathTranslator pathTranslator;
+
+ private Logger logger;
+
+ MavenProjectRestorer( PathTranslator pathTranslator, ModelInterpolator modelInterpolator, Logger logger )
+ {
+ this.pathTranslator = pathTranslator;
+ this.modelInterpolator = modelInterpolator;
+ this.logger = logger;
+ }
+
+ Logger getLogger()
+ {
+ return logger;
+ }
+
+ void restoreDynamicState( MavenProject project, ProjectBuilderConfiguration config )
+ throws ModelInterpolationException
+ {
+ if ( !project.isConcrete() )
+ {
+ return;
+ }
+
+ restoreBuildRoots( project, config );
+ if ( project.getBuild() != null )
+ {
+ restoreModelBuildSection( project, config );
+ }
+ restoreDynamicProjectReferences( project, config );
+
+ MavenProject executionProject = project.getExecutionProject();
+ if ( executionProject != null && executionProject != project )
+ {
+ restoreDynamicState( executionProject, config );
+ }
+
+ project.setConcrete( false );
+ }
+
+ void calculateConcreteState( MavenProject project, ProjectBuilderConfiguration config )
+ throws ModelInterpolationException
+ {
+ if ( project.isConcrete() )
+ {
+ return;
+ }
+
+ Build build = project.getBuild();
+ if ( build != null )
+ {
+ initResourceMergeIds( build.getResources() );
+ initResourceMergeIds( build.getTestResources() );
+ }
+
+ Model model = ModelUtils.cloneModel( project.getModel() );
+
+ File basedir = project.getBasedir();
+
+ model = modelInterpolator.interpolate( model, basedir, config, getLogger().isDebugEnabled() );
+
+ List originalInterpolatedCompileSourceRoots =
+ interpolateListOfStrings( project.getCompileSourceRoots(), model, project.getBasedir(), config );
+
+ project.preserveCompileSourceRoots( originalInterpolatedCompileSourceRoots );
+
+ project.setCompileSourceRoots( originalInterpolatedCompileSourceRoots == null
+ ? null
+ : translateListOfPaths( originalInterpolatedCompileSourceRoots, basedir ) );
+
+ List originalInterpolatedTestCompileSourceRoots =
+ interpolateListOfStrings( project.getTestCompileSourceRoots(), model, project.getBasedir(), config );
+
+ project.preserveTestCompileSourceRoots( originalInterpolatedTestCompileSourceRoots );
+ project.setTestCompileSourceRoots( originalInterpolatedTestCompileSourceRoots == null
+ ? null
+ : translateListOfPaths( originalInterpolatedTestCompileSourceRoots, basedir ) );
+
+ List originalInterpolatedScriptSourceRoots =
+ interpolateListOfStrings( project.getScriptSourceRoots(), model, project.getBasedir(), config );
+
+ project.preserveScriptSourceRoots( originalInterpolatedScriptSourceRoots );
+ project.setScriptSourceRoots( originalInterpolatedScriptSourceRoots == null
+ ? null
+ : translateListOfPaths( originalInterpolatedScriptSourceRoots, basedir ) );
+
+ Model model2 = ModelUtils.cloneModel( model );
+
+ pathTranslator.alignToBaseDirectory( model, basedir );
+
+ project.preserveBuild( model2.getBuild() );
+ project.setBuild( model.getBuild() );
+
+ calculateConcreteProjectReferences( project, config );
+
+ MavenProject executionProject = project.getExecutionProject();
+ if ( executionProject != null && executionProject != project )
+ {
+ calculateConcreteState( executionProject, config );
+ }
+
+ project.setConcrete( true );
+ }
+
+
+ private void restoreDynamicProjectReferences( MavenProject project, ProjectBuilderConfiguration config )
+ throws ModelInterpolationException
+ {
+ Map projectRefs = project.getProjectReferences();
+ if ( projectRefs != null )
+ {
+ for ( Iterator it = projectRefs.values().iterator(); it.hasNext(); )
+ {
+ MavenProject projectRef = (MavenProject) it.next();
+ restoreDynamicState( projectRef, config );
+ }
+ }
+ }
+
+ private void restoreBuildRoots( MavenProject project, ProjectBuilderConfiguration config )
+ throws ModelInterpolationException
+ {
+ project.setCompileSourceRoots( restoreListOfStrings( project.getDynamicCompileSourceRoots(),
+ project.getOriginalInterpolatedCompileSourceRoots(),
+ project.getCompileSourceRoots(), project, config ) );
+
+ project.setTestCompileSourceRoots( restoreListOfStrings( project.getDynamicTestCompileSourceRoots(),
+ project.getOriginalInterpolatedTestCompileSourceRoots(),
+ project.getTestCompileSourceRoots(), project,
+ config ) );
+
+ project.setScriptSourceRoots( restoreListOfStrings( project.getDynamicScriptSourceRoots(),
+ project.getOriginalInterpolatedScriptSourceRoots(),
+ project.getScriptSourceRoots(), project, config ) );
+
+ project.clearRestorableRoots();
+ }
+
+ private void restoreModelBuildSection( MavenProject project, ProjectBuilderConfiguration config )
+ throws ModelInterpolationException
+ {
+ Build changedBuild = project.getBuild();
+ Build dynamicBuild = project.getDynamicBuild();
+ Build originalInterpolatedBuild = project.getOriginalInterpolatedBuild();
+
+ dynamicBuild.setResources( restoreResources( dynamicBuild.getResources(),
+ originalInterpolatedBuild.getResources(),
+ changedBuild.getResources(), project, config ) );
+
+ dynamicBuild.setTestResources( restoreResources( dynamicBuild.getTestResources(),
+ originalInterpolatedBuild.getTestResources(),
+ changedBuild.getTestResources(), project, config ) );
+
+ dynamicBuild.setFilters( restoreListOfStrings( dynamicBuild.getFilters(),
+ originalInterpolatedBuild.getFilters(),
+ changedBuild.getFilters(), project, config ) );
+
+ dynamicBuild.setFinalName( restoreString( dynamicBuild.getFinalName(), originalInterpolatedBuild.getFinalName(),
+ changedBuild.getFinalName(), project, config ) );
+
+ dynamicBuild.setDefaultGoal( restoreString( dynamicBuild.getDefaultGoal(),
+ originalInterpolatedBuild.getDefaultGoal(),
+ changedBuild.getDefaultGoal(), project, config ) );
+
+ dynamicBuild.setSourceDirectory( restoreString( dynamicBuild.getSourceDirectory(),
+ originalInterpolatedBuild.getSourceDirectory(),
+ changedBuild.getSourceDirectory(), project, config ) );
+
+ dynamicBuild.setTestSourceDirectory( restoreString( dynamicBuild.getTestSourceDirectory(),
+ originalInterpolatedBuild.getTestSourceDirectory(),
+ changedBuild.getTestSourceDirectory(), project, config ) );
+
+ dynamicBuild.setScriptSourceDirectory( restoreString( dynamicBuild.getScriptSourceDirectory(),
+ originalInterpolatedBuild.getScriptSourceDirectory(),
+ changedBuild.getScriptSourceDirectory(), project,
+ config ) );
+
+ dynamicBuild.setOutputDirectory( restoreString( dynamicBuild.getOutputDirectory(),
+ originalInterpolatedBuild.getOutputDirectory(),
+ changedBuild.getOutputDirectory(), project, config ) );
+
+ dynamicBuild.setTestOutputDirectory( restoreString( dynamicBuild.getTestOutputDirectory(),
+ originalInterpolatedBuild.getTestOutputDirectory(),
+ changedBuild.getTestOutputDirectory(), project, config ) );
+
+ dynamicBuild.setDirectory( restoreString( dynamicBuild.getDirectory(), originalInterpolatedBuild.getDirectory(),
+ changedBuild.getDirectory(), project, config ) );
+
+ project.setBuild( dynamicBuild );
+
+ project.clearRestorableBuild();
+ }
+
+ private List interpolateListOfStrings( List originalStrings, Model model, File projectDir,
+ ProjectBuilderConfiguration config )
+ throws ModelInterpolationException
+ {
+ if ( originalStrings == null )
+ {
+ return null;
+ }
+
+ List result = new ArrayList();
+
+ for ( Iterator it = originalStrings.iterator(); it.hasNext(); )
+ {
+ String original = (String) it.next();
+ String interpolated =
+ modelInterpolator.interpolate( original, model, projectDir, config, getLogger().isDebugEnabled() );
+
+ result.add( interpolated );
+ }
+
+ return result;
+ }
+
+ private String restoreString( String originalString, String originalInterpolatedString, String changedString,
+ MavenProject project, ProjectBuilderConfiguration config )
+ throws ModelInterpolationException
+ {
+ if ( originalString == null )
+ {
+ return changedString;
+ }
+ else if ( changedString == null )
+ {
+ return originalString;
+ }
+
+ Model model = project.getModel();
+
+ String relativeChangedString;
+ if ( project.getBasedir() != null )
+ {
+ relativeChangedString = pathTranslator.unalignFromBaseDirectory( changedString, project.getBasedir() );
+ }
+ else
+ {
+ relativeChangedString = changedString;
+ }
+
+ String interpolatedOriginal = modelInterpolator.interpolate( originalString, model, project.getBasedir(),
+ config, getLogger().isDebugEnabled() );
+ String interpolatedOriginal2 = modelInterpolator.interpolate( originalInterpolatedString, model,
+ project.getBasedir(), config,
+ getLogger().isDebugEnabled() );
+
+ String interpolatedChanged = modelInterpolator.interpolate( changedString, model, project.getBasedir(), config,
+ getLogger().isDebugEnabled() );
+ String relativeInterpolatedChanged = modelInterpolator.interpolate( relativeChangedString, model,
+ project.getBasedir(), config,
+ getLogger().isDebugEnabled() );
+
+ if ( interpolatedOriginal.equals( interpolatedChanged ) || interpolatedOriginal2.equals( interpolatedChanged ) )
+ {
+ return originalString;
+ }
+ else if ( interpolatedOriginal.equals( relativeInterpolatedChanged ) ||
+ interpolatedOriginal2.equals( relativeInterpolatedChanged ) )
+ {
+ return originalString;
+ }
+
+ return relativeChangedString;
+ }
+
+ private List restoreListOfStrings( List originalStrings, List originalInterpolatedStrings, List changedStrings,
+ MavenProject project, ProjectBuilderConfiguration config )
+ throws ModelInterpolationException
+ {
+ if ( originalStrings == null )
+ {
+ return changedStrings;
+ }
+ else if ( changedStrings == null )
+ {
+ return originalStrings;
+ }
+
+ List result = new ArrayList();
+
+ Map orig = new HashMap();
+ for ( int idx = 0; idx < originalStrings.size(); idx++ )
+ {
+ String[] permutations = new String[2];
+
+ permutations[0] = (String) originalInterpolatedStrings.get( idx );
+ permutations[1] = (String) originalStrings.get( idx );
+
+ orig.put( permutations[0], permutations );
+ }
+
+ for ( Iterator it = changedStrings.iterator(); it.hasNext(); )
+ {
+ String changedString = (String) it.next();
+ String relativeChangedString;
+ if ( project.getBasedir() != null )
+ {
+ relativeChangedString = pathTranslator.unalignFromBaseDirectory( changedString, project.getBasedir() );
+ }
+ else
+ {
+ relativeChangedString = changedString;
+ }
+
+ String interpolated = modelInterpolator.interpolate( changedString, project.getModel(),
+ project.getBasedir(), config,
+ getLogger().isDebugEnabled() );
+
+ String relativeInterpolated = modelInterpolator.interpolate( relativeChangedString, project.getModel(),
+ project.getBasedir(), config,
+ getLogger().isDebugEnabled() );
+
+ String[] original = (String[]) orig.get( interpolated );
+ if ( original == null )
+ {
+ original = (String[]) orig.get( relativeInterpolated );
+ }
+
+ if ( original == null )
+ {
+ result.add( relativeChangedString );
+ }
+ else
+ {
+ result.add( original[1] );
+ }
+ }
+
+ return result;
+ }
+
+ // TODO: Convert this to use the mergeId on each resource...
+ private List restoreResources( List originalResources, List originalInterpolatedResources,
+ List changedResources, MavenProject project,
+ ProjectBuilderConfiguration config )
+ throws ModelInterpolationException
+ {
+ if ( originalResources == null || changedResources == null )
+ {
+ return originalResources;
+ }
+
+ List result = new ArrayList();
+
+ Map originalResourcesByMergeId = new HashMap();
+ for ( int idx = 0; idx < originalResources.size(); idx++ )
+ {
+ Resource[] permutations = new Resource[2];
+
+ permutations[0] = originalInterpolatedResources.get( idx );
+ permutations[1] = originalResources.get( idx );
+
+ originalResourcesByMergeId.put( permutations[0].getMergeId(), permutations );
+ }
+
+ for ( Resource resource : changedResources )
+ {
+ String mergeId = resource.getMergeId();
+ if ( mergeId == null || !originalResourcesByMergeId.containsKey( mergeId ) )
+ {
+ result.add( resource );
+ }
+ else
+ {
+ Resource originalInterpolatedResource = originalResourcesByMergeId.get( mergeId )[0];
+ Resource originalResource = originalResourcesByMergeId.get( mergeId )[1];
+
+ String dir = modelInterpolator.interpolate( resource.getDirectory(), project.getModel(),
+ project.getBasedir(), config,
+ getLogger().isDebugEnabled() );
+ String oDir = originalInterpolatedResource.getDirectory();
+
+ if ( !dir.equals( oDir ) )
+ {
+ originalResource.setDirectory(
+ pathTranslator.unalignFromBaseDirectory( dir, project.getBasedir() ) );
+ }
+
+ if ( resource.getTargetPath() != null )
+ {
+ String target = modelInterpolator.interpolate( resource.getTargetPath(), project.getModel(),
+ project.getBasedir(), config,
+ getLogger().isDebugEnabled() );
+
+ String oTarget = originalInterpolatedResource.getTargetPath();
+
+ if ( !target.equals( oTarget ) )
+ {
+ originalResource.setTargetPath(
+ pathTranslator.unalignFromBaseDirectory( target, project.getBasedir() ) );
+ }
+ }
+
+ originalResource.setFiltering( resource.isFiltering() );
+
+ originalResource.setExcludes( collectRestoredListOfPatterns( resource.getExcludes(),
+ originalResource.getExcludes(),
+ originalInterpolatedResource.getExcludes() ) );
+
+ originalResource.setIncludes( collectRestoredListOfPatterns( resource.getIncludes(),
+ originalResource.getIncludes(),
+ originalInterpolatedResource.getIncludes() ) );
+
+ result.add( originalResource );
+ }
+ }
+
+ return result;
+ }
+
+ private List collectRestoredListOfPatterns( List patterns, List originalPatterns,
+ List originalInterpolatedPatterns )
+ {
+ LinkedHashSet collectedPatterns = new LinkedHashSet();
+
+ collectedPatterns.addAll( originalPatterns );
+
+ for ( String pattern : patterns )
+ {
+ if ( !originalInterpolatedPatterns.contains( pattern ) )
+ {
+ collectedPatterns.add( pattern );
+ }
+ }
+
+ return (List) ( collectedPatterns.isEmpty()
+ ? Collections.emptyList()
+ : new ArrayList( collectedPatterns ) );
+ }
+
+
+ private void initResourceMergeIds( List resources )
+ {
+ if ( resources != null )
+ {
+ for ( Resource resource : resources )
+ {
+ resource.initMergeId();
+ }
+ }
+ }
+
+ private void calculateConcreteProjectReferences( MavenProject project, ProjectBuilderConfiguration config )
+ throws ModelInterpolationException
+ {
+ Map projectRefs = project.getProjectReferences();
+
+ if ( projectRefs != null )
+ {
+ for ( Iterator it = projectRefs.values().iterator(); it.hasNext(); )
+ {
+ MavenProject reference = (MavenProject) it.next();
+ calculateConcreteState( reference, config );
+ }
+ }
+ }
+
+ private List translateListOfPaths( List paths, File basedir )
+ {
+ if ( paths == null )
+ {
+ return null;
+ }
+ else if ( basedir == null )
+ {
+ return paths;
+ }
+
+ List result = new ArrayList( paths.size() );
+ for ( Iterator it = paths.iterator(); it.hasNext(); )
+ {
+ String path = (String) it.next();
+
+ String aligned = pathTranslator.alignToBaseDirectory( path, basedir );
+
+ result.add( aligned );
+ }
+
+ return result;
+ }
+
+
+}
diff --git a/maven-project/src/main/java/org/apache/maven/project/MissingRepositoryElementException.java b/maven-project/src/main/java/org/apache/maven/project/MissingRepositoryElementException.java
index 0f1e5c2fef..17c267e3a9 100644
--- a/maven-project/src/main/java/org/apache/maven/project/MissingRepositoryElementException.java
+++ b/maven-project/src/main/java/org/apache/maven/project/MissingRepositoryElementException.java
@@ -1,13 +1,31 @@
package org.apache.maven.project;
+/*
+ * 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.
+ */
+
import org.apache.maven.artifact.InvalidRepositoryException;
public class MissingRepositoryElementException
extends InvalidRepositoryException
{
- public MissingRepositoryElementException( String message,
- String repositoryId )
+ public MissingRepositoryElementException( String message, String repositoryId )
{
super( message, repositoryId );
}
diff --git a/maven-project/src/main/java/org/apache/maven/project/ModelAndFile.java b/maven-project/src/main/java/org/apache/maven/project/ModelAndFile.java
new file mode 100644
index 0000000000..915986ebd3
--- /dev/null
+++ b/maven-project/src/main/java/org/apache/maven/project/ModelAndFile.java
@@ -0,0 +1,62 @@
+package org.apache.maven.project;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.model.Model;
+
+import java.io.File;
+
+public class ModelAndFile
+{
+
+ private final Model model;
+
+ private final File file;
+
+ private final boolean validProfilesXmlLocation;
+
+ public ModelAndFile( Model model, File file, boolean validProfilesXmlLocation )
+ {
+ this.model = model;
+ this.file = file;
+ this.validProfilesXmlLocation = validProfilesXmlLocation;
+ }
+
+ public Model getModel()
+ {
+ return model;
+ }
+
+ public File getFile()
+ {
+ return file;
+ }
+
+ public boolean isValidProfilesXmlLocation()
+ {
+ return validProfilesXmlLocation;
+ }
+
+ public String toString()
+ {
+ return model.getId() + "@" + file;
+ }
+
+}
diff --git a/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java b/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java
index b453f0dfa7..7c6057e069 100644
--- a/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java
+++ b/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java
@@ -61,65 +61,17 @@ import java.util.TreeMap;
public final class ModelUtils
{
- /**
- * Given this plugin list:
- *
- * A1 -> B -> C -> A2 -> D
- *
- * Rearrange it to this:
- *
- * A(A1 + A2) -> B -> C -> D
- *
- * In cases of overlapping definitions, A1 is overridden by A2
- *
- */
- public static void mergeDuplicatePluginDefinitions( PluginContainer pluginContainer )
- {
- if ( pluginContainer == null )
- {
- return;
- }
-
- List originalPlugins = pluginContainer.getPlugins();
-
- if ( ( originalPlugins == null ) || originalPlugins.isEmpty() )
- {
- return;
- }
-
- List normalized = new ArrayList( originalPlugins.size() );
-
- for ( Iterator it = originalPlugins.iterator(); it.hasNext(); )
- {
- Plugin currentPlugin = (Plugin) it.next();
-
- if ( normalized.contains( currentPlugin ) )
- {
- int idx = normalized.indexOf( currentPlugin );
- Plugin firstPlugin = (Plugin) normalized.get( idx );
-
- mergePluginDefinitions( firstPlugin, currentPlugin, false );
- }
- else
- {
- normalized.add( currentPlugin );
- }
- }
-
- pluginContainer.setPlugins( normalized );
- }
-
/**
* This should be the resulting ordering of plugins after merging:
- *
+ *
* Given:
- *
- * parent: X -> A -> B -> D -> E
- * child: Y -> A -> C -> D -> F
- *
+ *
+ * parent: X -> A -> B -> D -> E
+ * child: Y -> A -> C -> D -> F
+ *
* Result:
- *
- * X -> Y -> A -> B -> C -> D -> E -> F
+ *
+ * X -> Y -> A -> B -> C -> D -> E -> F
*/
public static void mergePluginLists( PluginContainer childContainer, PluginContainer parentContainer,
boolean handleAsInheritance )
@@ -194,9 +146,8 @@ public final class ModelUtils
// very important to use the parentPlugins List, rather than parentContainer.getPlugins()
// since this list is a local one, and may have been modified during processing.
- List results = ModelUtils.orderAfterMerge( assembledPlugins, parentPlugins,
- childContainer.getPlugins() );
-
+ List results =
+ ModelUtils.orderAfterMerge( assembledPlugins, parentPlugins, childContainer.getPlugins() );
childContainer.setPlugins( results );
@@ -262,67 +213,6 @@ public final class ModelUtils
return results;
}
- public static void mergeReportPluginLists( Reporting child, Reporting parent, boolean handleAsInheritance )
- {
- if ( ( child == null ) || ( parent == null ) )
- {
- // nothing to do.
- return;
- }
-
- List parentPlugins = parent.getPlugins();
-
- if ( ( parentPlugins != null ) && !parentPlugins.isEmpty() )
- {
- Map assembledPlugins = new TreeMap();
-
- Map childPlugins = child.getReportPluginsAsMap();
-
- for ( Iterator it = parentPlugins.iterator(); it.hasNext(); )
- {
- ReportPlugin parentPlugin = (ReportPlugin) it.next();
-
- String parentInherited = parentPlugin.getInherited();
-
- if ( !handleAsInheritance || ( parentInherited == null ) ||
- Boolean.valueOf( parentInherited ).booleanValue() )
- {
-
- ReportPlugin assembledPlugin = parentPlugin;
-
- ReportPlugin childPlugin = (ReportPlugin) childPlugins.get( parentPlugin.getKey() );
-
- if ( childPlugin != null )
- {
- assembledPlugin = childPlugin;
-
- mergeReportPluginDefinitions( childPlugin, parentPlugin, handleAsInheritance );
- }
-
- if ( handleAsInheritance && ( parentInherited == null ) )
- {
- assembledPlugin.unsetInheritanceApplied();
- }
-
- assembledPlugins.put( assembledPlugin.getKey(), assembledPlugin );
- }
- }
-
- for ( Iterator it = childPlugins.values().iterator(); it.hasNext(); )
- {
- ReportPlugin childPlugin = (ReportPlugin) it.next();
-
- if ( !assembledPlugins.containsKey( childPlugin.getKey() ) )
- {
- assembledPlugins.put( childPlugin.getKey(), childPlugin );
- }
- }
-
- child.setPlugins( new ArrayList( assembledPlugins.values() ) );
-
- child.flushReportPluginMap();
- }
- }
public static void mergePluginDefinitions( Plugin child, Plugin parent, boolean handleAsInheritance )
{
@@ -372,7 +262,8 @@ public final class ModelUtils
String inherited = parentExecution.getInherited();
- boolean parentExecInherited = parentIsInherited && ( ( inherited == null ) || Boolean.valueOf( inherited ).booleanValue() );
+ boolean parentExecInherited =
+ parentIsInherited && ( ( inherited == null ) || Boolean.valueOf( inherited ).booleanValue() );
if ( !handleAsInheritance || parentExecInherited )
{
@@ -392,98 +283,27 @@ public final class ModelUtils
}
assembledExecutions.put( assembled.getId(), assembled );
- mergedExecutions.add(assembled);
+ mergedExecutions.add( assembled );
}
}
for ( Iterator it = child.getExecutions().iterator(); it.hasNext(); )
{
- PluginExecution childExecution = (PluginExecution)it.next();
+ PluginExecution childExecution = (PluginExecution) it.next();
if ( !assembledExecutions.containsKey( childExecution.getId() ) )
{
- mergedExecutions.add(childExecution);
+ mergedExecutions.add( childExecution );
}
}
- child.setExecutions(mergedExecutions);
+ child.setExecutions( mergedExecutions );
child.flushExecutionMap();
}
}
- public static void mergeReportPluginDefinitions( ReportPlugin child, ReportPlugin parent,
- boolean handleAsInheritance )
- {
- if ( ( child == null ) || ( parent == null ) )
- {
- // nothing to do.
- return;
- }
-
- if ( ( child.getVersion() == null ) && ( parent.getVersion() != null ) )
- {
- child.setVersion( parent.getVersion() );
- }
-
- // from here to the end of the method is dealing with merging of the section.
- String parentInherited = parent.getInherited();
-
- boolean parentIsInherited = ( parentInherited == null ) || Boolean.valueOf( parentInherited ).booleanValue();
-
- List parentReportSets = parent.getReportSets();
-
- if ( ( parentReportSets != null ) && !parentReportSets.isEmpty() )
- {
- Map assembledReportSets = new TreeMap();
-
- Map childReportSets = child.getReportSetsAsMap();
-
- for ( Iterator it = parentReportSets.iterator(); it.hasNext(); )
- {
- ReportSet parentReportSet = (ReportSet) it.next();
-
- if ( !handleAsInheritance || parentIsInherited )
- {
- ReportSet assembledReportSet = parentReportSet;
-
- ReportSet childReportSet = (ReportSet) childReportSets.get( parentReportSet.getId() );
-
- if ( childReportSet != null )
- {
- mergeReportSetDefinitions( childReportSet, parentReportSet );
-
- assembledReportSet = childReportSet;
- }
- else if ( handleAsInheritance && ( parentInherited == null ) )
- {
- parentReportSet.unsetInheritanceApplied();
- }
-
- assembledReportSets.put( assembledReportSet.getId(), assembledReportSet );
- }
- }
-
- for ( Iterator it = childReportSets.entrySet().iterator(); it.hasNext(); )
- {
- Map.Entry entry = (Map.Entry) it.next();
-
- String id = (String) entry.getKey();
-
- if ( !assembledReportSets.containsKey( id ) )
- {
- assembledReportSets.put( id, entry.getValue() );
- }
- }
-
- child.setReportSets( new ArrayList( assembledReportSets.values() ) );
-
- child.flushReportSetMap();
- }
-
- }
-
private static void mergePluginExecutionDefinitions( PluginExecution child, PluginExecution parent )
{
if ( child.getPhase() == null )
@@ -524,41 +344,6 @@ public final class ModelUtils
child.setConfiguration( childConfiguration );
}
- private static void mergeReportSetDefinitions( ReportSet child, ReportSet parent )
- {
- List parentReports = parent.getReports();
- List childReports = child.getReports();
-
- List reports = new ArrayList();
-
- if ( ( childReports != null ) && !childReports.isEmpty() )
- {
- reports.addAll( childReports );
- }
-
- if ( parentReports != null )
- {
- for ( Iterator i = parentReports.iterator(); i.hasNext(); )
- {
- String report = (String) i.next();
-
- if ( !reports.contains( report ) )
- {
- reports.add( report );
- }
- }
- }
-
- child.setReports( reports );
-
- Xpp3Dom childConfiguration = (Xpp3Dom) child.getConfiguration();
- Xpp3Dom parentConfiguration = (Xpp3Dom) parent.getConfiguration();
-
- childConfiguration = Xpp3Dom.mergeXpp3Dom( childConfiguration, parentConfiguration );
-
- child.setConfiguration( childConfiguration );
- }
-
public static Model cloneModel( Model model )
{
// TODO: would be nice for the modello:java code to generate this as a copy constructor
diff --git a/maven-project/src/main/java/org/apache/maven/project/ProjectBuildingException.java b/maven-project/src/main/java/org/apache/maven/project/ProjectBuildingException.java
index 6f0d5d7c97..819993a211 100644
--- a/maven-project/src/main/java/org/apache/maven/project/ProjectBuildingException.java
+++ b/maven-project/src/main/java/org/apache/maven/project/ProjectBuildingException.java
@@ -49,10 +49,10 @@ public class ProjectBuildingException
}
/**
- * @deprecated use {@link File} constructor for pomLocation
* @param projectId
* @param message
* @param pomLocation absolute path of the pom file
+ * @deprecated use {@link File} constructor for pomLocation
*/
protected ProjectBuildingException( String projectId, String message, String pomLocation )
{
@@ -62,10 +62,9 @@ public class ProjectBuildingException
}
/**
- *
* @param projectId
* @param message
- * @param pomFile pom file location
+ * @param pomFile pom file location
*/
public ProjectBuildingException( String projectId, String message, File pomFile )
{
@@ -77,7 +76,7 @@ public class ProjectBuildingException
/**
* @param projectId
* @param message
- * @param pomFile pom file location
+ * @param pomFile pom file location
* @param cause
*/
protected ProjectBuildingException( String projectId, String message, File pomFile, Throwable cause )
@@ -98,8 +97,7 @@ public class ProjectBuildingException
pomFile = new File( pomLocation );
}
- public ProjectBuildingException( String projectId, String message, File pomFile,
- ProfileActivationException cause )
+ public ProjectBuildingException( String projectId, String message, File pomFile, ProfileActivationException cause )
{
super( message, cause );
this.projectId = projectId;
@@ -133,7 +131,8 @@ public class ProjectBuildingException
/**
* @deprecated use {@link File} constructor for pomLocation
*/
- public ProjectBuildingException( String projectId, String message, String pomLocation, XmlPullParserException cause )
+ public ProjectBuildingException( String projectId, String message, String pomLocation,
+ XmlPullParserException cause )
{
super( message, cause );
this.projectId = projectId;
@@ -178,8 +177,7 @@ public class ProjectBuildingException
this.projectId = projectId;
}
- public ProjectBuildingException( String projectId, String message, File pomFile,
- ArtifactResolutionException cause )
+ public ProjectBuildingException( String projectId, String message, File pomFile, ArtifactResolutionException cause )
{
super( message, cause );
this.projectId = projectId;
@@ -269,12 +267,10 @@ public class ProjectBuildingException
{
super( message, cause );
this.projectId = projectId;
- pomFile = new File ( pomLocation );
+ pomFile = new File( pomLocation );
}
- public ProjectBuildingException( String projectId,
- String message,
- ModelInterpolationException cause )
+ public ProjectBuildingException( String projectId, String message, ModelInterpolationException cause )
{
super( message, cause );
this.projectId = projectId;
@@ -288,7 +284,7 @@ public class ProjectBuildingException
/**
* @deprecated use {@link #getPomFile()}
*/
- public String getPomLocation ()
+ public String getPomLocation()
{
if ( getPomFile() != null )
{
@@ -307,7 +303,7 @@ public class ProjectBuildingException
public String getMessage()
{
- return super.getMessage() + " for project " + projectId
- + ( ( getPomFile() == null ? "" : " at " + getPomFile().getAbsolutePath() ) );
+ return super.getMessage() + " for project " + projectId +
+ ( ( getPomFile() == null ? "" : " at " + getPomFile().getAbsolutePath() ) );
}
}
diff --git a/maven-project/src/main/java/org/apache/maven/project/ProjectSorter.java b/maven-project/src/main/java/org/apache/maven/project/ProjectSorter.java
deleted file mode 100644
index 308e8ca20b..0000000000
--- a/maven-project/src/main/java/org/apache/maven/project/ProjectSorter.java
+++ /dev/null
@@ -1,248 +0,0 @@
-package org.apache.maven.project;
-
-/*
- * 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.
- */
-
-import org.apache.maven.artifact.ArtifactUtils;
-import org.apache.maven.model.Dependency;
-import org.apache.maven.model.Extension;
-import org.apache.maven.model.Plugin;
-import org.apache.maven.model.ReportPlugin;
-import org.codehaus.plexus.util.dag.CycleDetectedException;
-import org.codehaus.plexus.util.dag.DAG;
-import org.codehaus.plexus.util.dag.TopologicalSorter;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Sort projects by dependencies.
- *
- * @author Brett Porter
- * @version $Id$
- */
-public class ProjectSorter
-{
- private final DAG dag;
-
- private final List sortedProjects;
-
- private MavenProject topLevelProject;
-
- /**
- * Sort a list of projects.
- *
- *
collect all the vertices for the projects that we want to build.
- *
iterate through the deps of each project and if that dep is within
- * the set of projects we want to build then add an edge, otherwise throw
- * the edge away because that dependency is not within the set of projects
- * we are trying to build. we assume a closed set.
- *
do a topo sort on the graph that remains.
- *
- * @throws DuplicateProjectException if any projects are duplicated by id
- */
- // MAVENAPI FIXME: the DAG used is NOT only used to represent the dependency relation,
- // but also for , , . We need multiple DAG's
- // since a DAG can only handle 1 type of relationship properly.
- // Usecase: This is detected as a cycle:
- // org.apache.maven:maven-plugin-api -(PARENT)->
- // org.apache.maven:maven -(inherited REPORTING)->
- // org.apache.maven.plugins:maven-checkstyle-plugin -(DEPENDENCY)->
- // org.apache.maven:maven-plugin-api
- // In this case, both the verify and the report goals are called
- // in a different lifecycle. Though the compiler-plugin has a valid usecase, although
- // that seems to work fine. We need to take versions and lifecycle into account.
- public ProjectSorter( List projects )
- throws CycleDetectedException, DuplicateProjectException
- {
- dag = new DAG();
-
- Map projectMap = new HashMap();
-
- for ( Iterator i = projects.iterator(); i.hasNext(); )
- {
- MavenProject project = (MavenProject) i.next();
-
- String id = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
-
- if ( dag.getVertex( id ) != null )
- {
- MavenProject conflictingProject = (MavenProject) projectMap.get( id );
-
- throw new DuplicateProjectException( id,
- conflictingProject.getFile(),
- project.getFile(),
- "Project '"
- + id
- + "' is duplicated in the reactor" );
- }
-
- dag.addVertex( id );
-
- projectMap.put( id, project );
- }
-
- for ( Iterator i = projects.iterator(); i.hasNext(); )
- {
- MavenProject project = (MavenProject) i.next();
-
- String id = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
-
- for ( Iterator j = project.getDependencies().iterator(); j.hasNext(); )
- {
- Dependency dependency = (Dependency) j.next();
-
- String dependencyId = ArtifactUtils
- .versionlessKey( dependency.getGroupId(), dependency.getArtifactId() );
-
- if ( dag.getVertex( dependencyId ) != null )
- {
- project.addProjectReference( (MavenProject) projectMap.get( dependencyId ) );
-
- dag.addEdge( id, dependencyId );
- }
- }
-
- MavenProject parent = project.getParent();
- if ( parent != null )
- {
- String parentId = ArtifactUtils.versionlessKey( parent.getGroupId(), parent.getArtifactId() );
- if ( dag.getVertex( parentId ) != null )
- {
- // Parent is added as an edge, but must not cause a cycle - so we remove any other edges it has in conflict
- if ( dag.hasEdge( parentId, id ) )
- {
- dag.removeEdge( parentId, id );
- }
- dag.addEdge( id, parentId );
- }
- }
-
- List buildPlugins = project.getBuildPlugins();
- if ( buildPlugins != null )
- {
- for ( Iterator j = buildPlugins.iterator(); j.hasNext(); )
- {
- Plugin plugin = (Plugin) j.next();
- String pluginId = ArtifactUtils.versionlessKey( plugin.getGroupId(), plugin.getArtifactId() );
- if ( ( dag.getVertex( pluginId ) != null ) && !pluginId.equals( id ) )
- {
- addEdgeWithParentCheck( projectMap, pluginId, project, id );
- }
- }
- }
-
- List reportPlugins = project.getReportPlugins();
- if ( reportPlugins != null )
- {
- for ( Iterator j = reportPlugins.iterator(); j.hasNext(); )
- {
- ReportPlugin plugin = (ReportPlugin) j.next();
- String pluginId = ArtifactUtils.versionlessKey( plugin.getGroupId(), plugin.getArtifactId() );
- if ( ( dag.getVertex( pluginId ) != null ) && !pluginId.equals( id ) )
- {
- addEdgeWithParentCheck( projectMap, pluginId, project, id );
- }
- }
- }
-
- for ( Iterator j = project.getBuildExtensions().iterator(); j.hasNext(); )
- {
- Extension extension = (Extension) j.next();
- String extensionId = ArtifactUtils.versionlessKey( extension.getGroupId(), extension.getArtifactId() );
- if ( dag.getVertex( extensionId ) != null )
- {
- addEdgeWithParentCheck( projectMap, extensionId, project, id );
- }
- }
- }
-
- List sortedProjects = new ArrayList();
-
- for ( Iterator i = TopologicalSorter.sort( dag ).iterator(); i.hasNext(); )
- {
- String id = (String) i.next();
-
- sortedProjects.add( projectMap.get( id ) );
- }
-
- this.sortedProjects = Collections.unmodifiableList( sortedProjects );
- }
-
- private void addEdgeWithParentCheck( Map projectMap, String projectRefId, MavenProject project, String id )
- throws CycleDetectedException
- {
- MavenProject extProject = (MavenProject) projectMap.get( projectRefId );
-
- if ( extProject == null )
- {
- return;
- }
-
- project.addProjectReference( extProject );
-
- MavenProject extParent = extProject.getParent();
- if ( extParent != null )
- {
- String parentId = ArtifactUtils.versionlessKey( extParent.getGroupId(), extParent.getArtifactId() );
- // Don't add edge from parent to extension if a reverse edge already exists
- if ( !dag.hasEdge( projectRefId, id ) || !parentId.equals( id ) )
- {
- dag.addEdge( id, projectRefId );
- }
- }
- }
-
- // TODO: !![jc; 28-jul-2005] check this; if we're using '-r' and there are aggregator tasks, this will result in weirdness.
- public MavenProject getTopLevelProject()
- {
- if ( topLevelProject == null )
- {
- for ( Iterator i = sortedProjects.iterator(); i.hasNext() && ( topLevelProject == null ); )
- {
- MavenProject project = (MavenProject) i.next();
- if ( project.isExecutionRoot() )
- {
- topLevelProject = project;
- }
- }
- }
-
- return topLevelProject;
- }
-
- public List getSortedProjects()
- {
- return sortedProjects;
- }
-
- public boolean hasMultipleProjects()
- {
- return sortedProjects.size() > 1;
- }
-
- public List getDependents( String id )
- {
- return dag.getParentLabels( id );
- }
-}
diff --git a/maven-project/src/main/java/org/apache/maven/project/ProjectUtils.java b/maven-project/src/main/java/org/apache/maven/project/ProjectUtils.java
index 644265bba4..134929eaea 100644
--- a/maven-project/src/main/java/org/apache/maven/project/ProjectUtils.java
+++ b/maven-project/src/main/java/org/apache/maven/project/ProjectUtils.java
@@ -97,7 +97,8 @@ public final class ProjectUtils
if ( url == null || url.trim().length() < 1 )
{
- throw new MissingRepositoryElementException( "Repository URL must not be empty (ID is: " + id + ").", id );
+ throw new MissingRepositoryElementException( "Repository URL must not be empty (ID is: " + id + ").",
+ id );
}
ArtifactRepositoryPolicy snapshots = buildArtifactRepositoryPolicy( repo.getSnapshots() );
diff --git a/maven-project/src/main/java/org/apache/maven/project/RepositoryHelper.java b/maven-project/src/main/java/org/apache/maven/project/RepositoryHelper.java
new file mode 100644
index 0000000000..b960c1091e
--- /dev/null
+++ b/maven-project/src/main/java/org/apache/maven/project/RepositoryHelper.java
@@ -0,0 +1,32 @@
+package org.apache.maven.project;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.model.Model;
+import org.apache.maven.profiles.activation.ProfileActivationContext;
+
+import java.io.File;
+import java.util.LinkedHashSet;
+import java.util.List;
+
+/**
+ * This is a temporary class. These methods are originally from the DefaultMavenProjectHelper. This class will be
+ * eliminated when Mercury is integrated.
+ */
+public interface RepositoryHelper
+{
+
+ String ROLE = RepositoryHelper.class.getName();
+
+ Model findModelFromRepository( Artifact artifact, List remoteArtifactRepositories,
+ ArtifactRepository localRepository )
+ throws ProjectBuildingException;
+
+ List buildArtifactRepositories( Model model )
+ throws ProjectBuildingException;
+
+ LinkedHashSet collectInitialRepositories( Model model, Model superModel, List parentSearchRepositories,
+ File pomFile, boolean validProfilesXmlLocation,
+ ProfileActivationContext profileActivationContext )
+ throws ProjectBuildingException;
+}
diff --git a/maven-project/src/main/java/org/apache/maven/project/artifact/ActiveProjectArtifact.java b/maven-project/src/main/java/org/apache/maven/project/artifact/ActiveProjectArtifact.java
index 7e4f0bd926..ef060be34a 100644
--- a/maven-project/src/main/java/org/apache/maven/project/artifact/ActiveProjectArtifact.java
+++ b/maven-project/src/main/java/org/apache/maven/project/artifact/ActiveProjectArtifact.java
@@ -58,293 +58,389 @@ public class ActiveProjectArtifact
artifact.setResolved( true );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public File getFile()
{
// we need to get the latest file for the project, not the artifact that was created at one point in time
return project.getArtifact().getFile();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public String getGroupId()
{
return artifact.getGroupId();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public String getArtifactId()
{
return artifact.getArtifactId();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public String getVersion()
{
return artifact.getVersion();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void setVersion( String version )
{
artifact.setVersion( version );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public String getScope()
{
return artifact.getScope();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public String getType()
{
return artifact.getType();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public String getClassifier()
{
return artifact.getClassifier();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public boolean hasClassifier()
{
return artifact.hasClassifier();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void setFile( File destination )
{
artifact.setFile( destination );
project.getArtifact().setFile( destination );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public String getBaseVersion()
{
return artifact.getBaseVersion();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void setBaseVersion( String baseVersion )
{
artifact.setBaseVersion( baseVersion );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public String getId()
{
return artifact.getId();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public String getDependencyConflictId()
{
return artifact.getDependencyConflictId();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void addMetadata( ArtifactMetadata metadata )
{
artifact.addMetadata( metadata );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public Collection getMetadataList()
{
return artifact.getMetadataList();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void setRepository( ArtifactRepository remoteRepository )
{
artifact.setRepository( remoteRepository );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public ArtifactRepository getRepository()
{
return artifact.getRepository();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void updateVersion( String version, ArtifactRepository localRepository )
{
artifact.updateVersion( version, localRepository );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public String getDownloadUrl()
{
return artifact.getDownloadUrl();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void setDownloadUrl( String downloadUrl )
{
artifact.setDownloadUrl( downloadUrl );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public ArtifactFilter getDependencyFilter()
{
return artifact.getDependencyFilter();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void setDependencyFilter( ArtifactFilter artifactFilter )
{
artifact.setDependencyFilter( artifactFilter );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public ArtifactHandler getArtifactHandler()
{
return artifact.getArtifactHandler();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public List getDependencyTrail()
{
return artifact.getDependencyTrail();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void setDependencyTrail( List dependencyTrail )
{
artifact.setDependencyTrail( dependencyTrail );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void setScope( String scope )
{
artifact.setScope( scope );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public VersionRange getVersionRange()
{
return artifact.getVersionRange();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void setVersionRange( VersionRange newRange )
{
artifact.setVersionRange( newRange );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void selectVersion( String version )
{
artifact.selectVersion( version );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void setGroupId( String groupId )
{
artifact.setGroupId( groupId );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void setArtifactId( String artifactId )
{
artifact.setArtifactId( artifactId );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public boolean isSnapshot()
{
return artifact.isSnapshot();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public int compareTo( Object o )
{
return artifact.compareTo( o );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void setResolved( boolean resolved )
{
artifact.setResolved( resolved );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public boolean isResolved()
{
return artifact.isResolved();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void setResolvedVersion( String version )
{
artifact.setResolvedVersion( version );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void setArtifactHandler( ArtifactHandler handler )
{
artifact.setArtifactHandler( handler );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public String toString()
{
return "active project artifact:\n\tartifact = " + artifact + ";\n\tproject: " + project;
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public boolean isRelease()
{
return artifact.isRelease();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void setRelease( boolean release )
{
artifact.setRelease( release );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public List getAvailableVersions()
{
return artifact.getAvailableVersions();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void setAvailableVersions( List versions )
{
artifact.setAvailableVersions( versions );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public boolean isOptional()
{
return artifact.isOptional();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public ArtifactVersion getSelectedVersion()
throws OverConstrainedVersionException
{
return artifact.getSelectedVersion();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public boolean isSelectedVersionKnown()
throws OverConstrainedVersionException
{
return artifact.isSelectedVersionKnown();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void setOptional( boolean optional )
{
artifact.setOptional( optional );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public int hashCode()
{
int result = 17;
@@ -361,7 +457,9 @@ public class ActiveProjectArtifact
return result;
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public boolean equals( Object o )
{
if ( o == this )
diff --git a/maven-project/src/main/java/org/apache/maven/project/artifact/AttachedArtifact.java b/maven-project/src/main/java/org/apache/maven/project/artifact/AttachedArtifact.java
deleted file mode 100644
index b17378abb3..0000000000
--- a/maven-project/src/main/java/org/apache/maven/project/artifact/AttachedArtifact.java
+++ /dev/null
@@ -1,166 +0,0 @@
-package org.apache.maven.project.artifact;
-
-/*
- * 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.
- */
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.DefaultArtifact;
-import org.apache.maven.artifact.InvalidArtifactRTException;
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.metadata.ArtifactMetadata;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.versioning.VersionRange;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-public class AttachedArtifact
- extends DefaultArtifact
-{
-
- private final Artifact parent;
-
- public AttachedArtifact( Artifact parent, String type, String classifier, ArtifactHandler artifactHandler )
- {
- super( parent.getGroupId(), parent.getArtifactId(), parent.getVersionRange(), parent.getScope(), type,
- classifier, artifactHandler, parent.isOptional() );
-
- setDependencyTrail( Collections.singletonList( parent.getId() ) );
-
- this.parent = parent;
-
- if ( getId().equals( parent.getId() ) )
- {
- throw new InvalidArtifactRTException( parent.getGroupId(), parent.getArtifactId(), parent.getVersion(), parent.getType(), "An attached artifact must have a different ID than its corresponding main artifact." );
- }
- }
-
- public AttachedArtifact( Artifact parent, String type, ArtifactHandler artifactHandler )
- {
- this( parent, type, null, artifactHandler );
- }
-
- public void setArtifactId( String artifactId )
- {
- // ignore this. We should ALWAYS use the information from the parent artifact.
- }
-
- public List getAvailableVersions()
- {
- return parent.getAvailableVersions();
- }
-
- public void setAvailableVersions( List availableVersions )
- {
- // ignore this. We should ALWAYS use the information from the parent artifact.
- }
-
- public String getBaseVersion()
- {
- return parent.getBaseVersion();
- }
-
- public void setBaseVersion( String baseVersion )
- {
- // ignore this. We should ALWAYS use the information from the parent artifact.
- }
-
- public String getDownloadUrl()
- {
- return parent.getDownloadUrl();
- }
-
- public void setDownloadUrl( String downloadUrl )
- {
- // ignore this. We should ALWAYS use the information from the parent artifact.
- }
-
- public void setGroupId( String groupId )
- {
- // ignore this. We should ALWAYS use the information from the parent artifact.
- }
-
- public ArtifactRepository getRepository()
- {
- return parent.getRepository();
- }
-
- public void setRepository( ArtifactRepository repository )
- {
- // ignore this. We should ALWAYS use the information from the parent artifact.
- }
-
- public String getScope()
- {
- return parent.getScope();
- }
-
- public void setScope( String scope )
- {
- // ignore this. We should ALWAYS use the information from the parent artifact.
- }
-
- public String getVersion()
- {
- return parent.getVersion();
- }
-
- public void setVersion( String version )
- {
- // ignore this. We should ALWAYS use the information from the parent artifact.
- }
-
- public VersionRange getVersionRange()
- {
- return parent.getVersionRange();
- }
-
- public void setVersionRange( VersionRange range )
- {
- // ignore this. We should ALWAYS use the information from the parent artifact.
- }
-
- public boolean isRelease()
- {
- return parent.isRelease();
- }
-
- public void setRelease( boolean release )
- {
- // ignore this. We should ALWAYS use the information from the parent artifact.
- }
-
- public boolean isSnapshot()
- {
- return parent.isSnapshot();
- }
-
- public void addMetadata( ArtifactMetadata metadata )
- {
- // ignore. The parent artifact will handle metadata.
- // we must fail silently here to avoid problems with the artifact transformers.
- }
-
- public Collection getMetadataList()
- {
- return Collections.EMPTY_LIST;
- }
-
-}
diff --git a/maven-project/src/main/java/org/apache/maven/project/artifact/InvalidDependencyVersionException.java b/maven-project/src/main/java/org/apache/maven/project/artifact/InvalidDependencyVersionException.java
index 7a4f562076..0d04d6e81d 100644
--- a/maven-project/src/main/java/org/apache/maven/project/artifact/InvalidDependencyVersionException.java
+++ b/maven-project/src/main/java/org/apache/maven/project/artifact/InvalidDependencyVersionException.java
@@ -37,7 +37,8 @@ public class InvalidDependencyVersionException
{
private Dependency dependency;
- public InvalidDependencyVersionException( String projectId, Dependency dependency, File pomFile, InvalidVersionSpecificationException cause )
+ public InvalidDependencyVersionException( String projectId, Dependency dependency, File pomFile,
+ InvalidVersionSpecificationException cause )
{
super( projectId, formatLocationInPom( dependency ), dependency.getVersion(), pomFile, cause );
this.dependency = dependency;
diff --git a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
index f419e70d6a..385291ead4 100644
--- a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
+++ b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
@@ -85,14 +85,15 @@ public class MavenMetadataSource
private PlexusContainer container;
- /** Unfortunately we have projects that are still sending us JARs without the accompanying POMs. */
+ /**
+ * Unfortunately we have projects that are still sending us JARs without the accompanying POMs.
+ */
private boolean strictlyEnforceThePresenceOfAValidMavenPOM = false;
/**
* Resolve all relocations in the POM for this artifact, and return the new artifact coordinate.
*/
- public Artifact retrieveRelocatedArtifact( Artifact artifact,
- ArtifactRepository localRepository,
+ public Artifact retrieveRelocatedArtifact( Artifact artifact, ArtifactRepository localRepository,
List remoteRepositories )
throws ArtifactMetadataRetrievalException
{
@@ -102,20 +103,19 @@ public class MavenMetadataSource
}
ProjectRelocation rel = retrieveRelocatedProject( artifact, localRepository, remoteRepositories );
-
+
if ( rel == null )
{
return artifact;
}
-
+
MavenProject project = rel.project;
if ( project == null || getRelocationKey( artifact ).equals( getRelocationKey( project.getArtifact() ) ) )
{
return artifact;
}
-
- // NOTE: Using artifact information here, since some POMs are deployed
+ // NOTE: Using artifact information here, since some POMs are deployed
// to central with one version in the filename, but another in the string!
// Case in point: org.apache.ws.commons:XmlSchema:1.1:pom.
//
@@ -124,11 +124,14 @@ public class MavenMetadataSource
Artifact result = null;
if ( artifact.getClassifier() != null )
{
- result = artifactFactory.createArtifactWithClassifier( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), artifact.getClassifier() );
+ result = artifactFactory.createArtifactWithClassifier( artifact.getGroupId(), artifact.getArtifactId(),
+ artifact.getVersion(), artifact.getType(),
+ artifact.getClassifier() );
}
else
{
- result = artifactFactory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getScope(), artifact.getType() );
+ result = artifactFactory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(),
+ artifact.getVersion(), artifact.getScope(), artifact.getType() );
}
result.setScope( artifact.getScope() );
@@ -146,9 +149,8 @@ public class MavenMetadataSource
return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion();
}
- private ProjectRelocation retrieveRelocatedProject( Artifact artifact,
- ArtifactRepository localRepository,
- List remoteRepositories )
+ private ProjectRelocation retrieveRelocatedProject( Artifact artifact, ArtifactRepository localRepository,
+ List remoteRepositories )
throws ArtifactMetadataRetrievalException
{
if ( remoteRepositories == null )
@@ -162,7 +164,8 @@ public class MavenMetadataSource
}
catch ( ComponentLookupException e )
{
- throw new ArtifactMetadataRetrievalException( "Cannot lookup MavenProjectBuilder component instance: " + e.getMessage(), e );
+ throw new ArtifactMetadataRetrievalException(
+ "Cannot lookup MavenProjectBuilder component instance: " + e.getMessage(), e );
}
MavenProject project = null;
@@ -183,7 +186,8 @@ public class MavenMetadataSource
{
try
{
- project = mavenProjectBuilder.buildFromRepository( pomArtifact, remoteRepositories, localRepository );
+ project =
+ mavenProjectBuilder.buildFromRepository( pomArtifact, remoteRepositories, localRepository );
}
catch ( InvalidProjectModelException e )
{
@@ -215,7 +219,7 @@ public class MavenMetadataSource
catch ( ProjectBuildingException e )
{
handleInvalidOrMissingMavenPOM( artifact, e );
-
+
project = null;
}
@@ -261,8 +265,8 @@ public class MavenMetadataSource
List available = artifact.getAvailableVersions();
if ( available != null && !available.isEmpty() )
{
- artifact.setAvailableVersions( retrieveAvailableVersions( artifact, localRepository,
- remoteRepositories ) );
+ artifact.setAvailableVersions(
+ retrieveAvailableVersions( artifact, localRepository, remoteRepositories ) );
}
@@ -274,7 +278,8 @@ public class MavenMetadataSource
message += " " + relocation.getMessage() + "\n";
}
- if ( ( artifact.getDependencyTrail() != null ) && ( artifact.getDependencyTrail().size() == 1 ) )
+ if ( ( artifact.getDependencyTrail() != null ) &&
+ ( artifact.getDependencyTrail().size() == 1 ) )
{
getLogger().warn( "While downloading " + artifact.getGroupId() + ":" +
artifact.getArtifactId() + ":" + artifact.getVersion() + message + "\n" );
@@ -342,8 +347,8 @@ public class MavenMetadataSource
// or used the inherited scope (should that be passed to the buildFromRepository method above?)
try
{
- artifacts = project.createArtifacts( artifactFactory, artifact.getScope(),
- artifact.getDependencyFilter() );
+ artifacts =
+ project.createArtifacts( artifactFactory, artifact.getScope(), artifact.getDependencyFilter() );
}
catch ( InvalidDependencyVersionException e )
{
@@ -365,17 +370,16 @@ public class MavenMetadataSource
{
if ( strictlyEnforceThePresenceOfAValidMavenPOM )
{
- throw new ArtifactMetadataRetrievalException( "Invalid POM file for artifact: '" +
- artifact.getDependencyConflictId() + "': " + e.getMessage(), e, artifact );
+ throw new ArtifactMetadataRetrievalException(
+ "Invalid POM file for artifact: '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e,
+ artifact );
}
else
{
- getLogger().warn(
- "\n\tDEPRECATION: The POM for the artifact '"
- + artifact.getDependencyConflictId()
- + "' was invalid or not found on any repositories.\n"
- + "\tThis may not be supported by future versions of Maven and should be corrected as soon as possible.\n"
- + "\tError given: " + e.getMessage() + "\n" );
+ getLogger().warn( "\n\tDEPRECATION: The POM for the artifact '" + artifact.getDependencyConflictId() +
+ "' was invalid or not found on any repositories.\n" +
+ "\tThis may not be supported by future versions of Maven and should be corrected as soon as possible.\n" +
+ "\tError given: " + e.getMessage() + "\n" );
}
}
@@ -446,11 +450,12 @@ public class MavenMetadataSource
}
/**
- * @todo desperately needs refactoring. It's just here because it's implementation is maven-project specific
* @return {@link Set} < {@link Artifact} >
+ * @todo desperately needs refactoring. It's just here because it's implementation is maven-project specific
*/
- public static Set createArtifacts( ArtifactFactory artifactFactory, List dependencies, String inheritedScope,
- ArtifactFilter dependencyFilter, MavenProject project )
+ public static Set createArtifacts( ArtifactFactory artifactFactory, List dependencies,
+ String inheritedScope, ArtifactFilter dependencyFilter,
+ MavenProject project )
throws InvalidDependencyVersionException
{
Set projectArtifacts = new LinkedHashSet( dependencies.size() );
@@ -545,8 +550,7 @@ public class MavenMetadataSource
return retrieveAvailableVersionsFromMetadata( metadata.getMetadata() );
}
- public List retrieveAvailableVersionsFromDeploymentRepository(
- Artifact artifact,
+ public List retrieveAvailableVersionsFromDeploymentRepository( Artifact artifact,
ArtifactRepository localRepository,
ArtifactRepository deploymentRepository )
throws ArtifactMetadataRetrievalException
@@ -578,7 +582,7 @@ public class MavenMetadataSource
}
else
{
- versions = Collections. emptyList();
+ versions = Collections.emptyList();
}
return versions;
@@ -593,6 +597,7 @@ public class MavenMetadataSource
private static final class ProjectRelocation
{
private MavenProject project;
+
private Artifact pomArtifact;
}
diff --git a/maven-project/src/main/java/org/apache/maven/project/artifact/PomMetadataSource.java b/maven-project/src/main/java/org/apache/maven/project/artifact/PomMetadataSource.java
deleted file mode 100644
index 00751f0660..0000000000
--- a/maven-project/src/main/java/org/apache/maven/project/artifact/PomMetadataSource.java
+++ /dev/null
@@ -1,206 +0,0 @@
-package org.apache.maven.project.artifact;
-
-/*
- * 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.
- */
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.resolver.metadata.ArtifactMetadata;
-import org.apache.maven.artifact.resolver.metadata.MetadataResolution;
-import org.apache.maven.artifact.resolver.metadata.MetadataRetrievalException;
-import org.apache.maven.artifact.resolver.metadata.MetadataSource;
-import org.apache.maven.model.Dependency;
-import org.apache.maven.project.InvalidProjectModelException;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.MavenProjectBuilder;
-import org.apache.maven.project.ProjectBuildingException;
-import org.codehaus.plexus.PlexusConstants;
-import org.codehaus.plexus.PlexusContainer;
-import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
-import org.codehaus.plexus.context.Context;
-import org.codehaus.plexus.context.ContextException;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-/**
- * @author Jason van Zyl
- * @version $Id$
- */
-public class PomMetadataSource
- extends AbstractLogEnabled
- implements MetadataSource,
- Contextualizable
-{
- public static final String ROLE_HINT = "default";
-
- private MavenProjectBuilder mavenProjectBuilder;
-
- private ArtifactFactory artifactFactory;
-
- // lazily instantiated and cached.
- private MavenProject superProject;
-
- private PlexusContainer container;
-
- /** Unfortunately we have projects that are still sending us JARs without the accompanying POMs. */
- private boolean strictlyEnforceThePresenceOfAValidMavenPOM = true;
-
- public MetadataResolution retrieve( ArtifactMetadata artifactMetadata,
- ArtifactRepository localRepository,
- List remoteRepositories )
- throws MetadataRetrievalException
- {
- try
- {
- loadProjectBuilder();
- }
- catch ( ComponentLookupException e )
- {
- throw new MetadataRetrievalException(
- "Cannot lookup MavenProjectBuilder component instance: " + e.getMessage(), e );
- }
-
- MavenProject project = null;
-
- Artifact pomArtifact = artifactFactory.createProjectArtifact(
- artifactMetadata.getGroupId()
- , artifactMetadata.getArtifactId()
- , artifactMetadata.getVersion()
- );
-
- try
- {
- project = mavenProjectBuilder.buildFromRepository( pomArtifact, remoteRepositories, localRepository );
- if ( pomArtifact.getFile() != null )
- {
- artifactMetadata.setArtifactUri( pomArtifact.getFile().toURI().toString() );
- }
- }
- catch ( InvalidProjectModelException e )
- {
- // We want to capture this in the graph so that we can display the error to the user
- artifactMetadata.setError( e.getMessage() );
- }
- catch ( ProjectBuildingException e )
- {
- if ( strictlyEnforceThePresenceOfAValidMavenPOM )
- {
- throw new MetadataRetrievalException(
- "Unable to read the metadata file for artifactMetadata '" +
- artifactMetadata.getDependencyConflictId() + "': " + e.getMessage(), e, artifactMetadata );
- }
- }
-
- Set artifacts = new HashSet();
-
- for ( Iterator i = project.getDependencies().iterator(); i.hasNext(); )
- {
- Dependency d = (Dependency) i.next();
-
- artifacts.add( new ArtifactMetadata( d.getGroupId(), d.getArtifactId(), d.getVersion(), d.getType(),
- d.getScope(), d.getClassifier(), null, null, false, null ) );
- }
-
- // The remote repositories is intentially null here while working in the graph in the least invasive way
- // and making sure repositories added for a POM are scope only for a particular POM. We don't want
- // repositories lingering around or being aggregated after they are used. jvz
-
- artifactMetadata.setDependencies( artifacts );
-
- return new MetadataResolution( artifactMetadata );
- }
-
- private void loadProjectBuilder()
- throws ComponentLookupException
- {
- if ( mavenProjectBuilder == null )
- {
- mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.class );
- }
- }
-
- private List aggregateRepositoryLists( List remoteRepositories,
- List remoteArtifactRepositories )
- throws ArtifactMetadataRetrievalException
- {
- if ( superProject == null )
- {
- try
- {
- superProject = mavenProjectBuilder.buildStandaloneSuperProject();
- }
- catch ( ProjectBuildingException e )
- {
- throw new ArtifactMetadataRetrievalException(
- "Unable to parse the Maven built-in model: " + e.getMessage(), e );
- }
- }
-
- List repositories = new ArrayList();
-
- repositories.addAll( remoteRepositories );
-
- // ensure that these are defined
- for ( Iterator it = superProject.getRemoteArtifactRepositories().iterator(); it.hasNext(); )
- {
- ArtifactRepository superRepo = (ArtifactRepository) it.next();
-
- for ( Iterator aggregatedIterator = repositories.iterator(); aggregatedIterator.hasNext(); )
- {
- ArtifactRepository repo = (ArtifactRepository) aggregatedIterator.next();
-
- // if the repository exists in the list and was introduced by another POM's super-pom,
- // remove it...the repository definitions from the super-POM should only be at the end of
- // the list.
- // if the repository has been redefined, leave it.
- if ( repo.getId().equals( superRepo.getId() ) && repo.getUrl().equals( superRepo.getUrl() ) )
- {
- aggregatedIterator.remove();
- }
- }
- }
-
- // this list should contain the super-POM repositories, so we don't have to explicitly add them back.
- for ( Iterator it = remoteArtifactRepositories.iterator(); it.hasNext(); )
- {
- ArtifactRepository repository = (ArtifactRepository) it.next();
-
- if ( !repositories.contains( repository ) )
- {
- repositories.add( repository );
- }
- }
-
- return repositories;
- }
-
- public void contextualize( Context context )
- throws ContextException
- {
- container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
- }
-}
\ No newline at end of file
diff --git a/maven-project/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java b/maven-project/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java
index 35a3b28351..225f8c7c55 100644
--- a/maven-project/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java
+++ b/maven-project/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java
@@ -45,8 +45,7 @@ public class ProjectArtifactMetadata
this( artifact, null );
}
- public ProjectArtifactMetadata( Artifact artifact,
- File file )
+ public ProjectArtifactMetadata( Artifact artifact, File file )
{
super( artifact );
this.file = file;
@@ -67,8 +66,7 @@ public class ProjectArtifactMetadata
return getArtifactId() + "-" + artifact.getVersion() + ".pom";
}
- public void storeInLocalRepository( ArtifactRepository localRepository,
- ArtifactRepository remoteRepository )
+ public void storeInLocalRepository( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
throws RepositoryMetadataStoreException
{
File destination = new File( localRepository.getBasedir(),
@@ -90,7 +88,7 @@ public class ProjectArtifactMetadata
throw new RepositoryMetadataStoreException( "Error copying POM to the local repository.", e );
}
}
-
+
public String toString()
{
return "project information for " + artifact.getArtifactId() + " " + artifact.getVersion();
diff --git a/maven-project/src/main/java/org/apache/maven/project/build/model/ModelAndFile.java b/maven-project/src/main/java/org/apache/maven/project/build/model/ModelAndFile.java
deleted file mode 100644
index 6795fc50f8..0000000000
--- a/maven-project/src/main/java/org/apache/maven/project/build/model/ModelAndFile.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package org.apache.maven.project.build.model;
-
-import org.apache.maven.model.Model;
-
-import java.io.File;
-
-public class ModelAndFile
-{
-
- private final Model model;
-
- private final File file;
-
- private final boolean validProfilesXmlLocation;
-
- public ModelAndFile( Model model,
- File file,
- boolean validProfilesXmlLocation )
- {
- this.model = model;
- this.file = file;
- this.validProfilesXmlLocation = validProfilesXmlLocation;
- }
-
- public Model getModel()
- {
- return model;
- }
-
- public File getFile()
- {
- return file;
- }
-
- public boolean isValidProfilesXmlLocation()
- {
- return validProfilesXmlLocation;
- }
-
- public String toString()
- {
- return model.getId() + "@" + file;
- }
-
-}
diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java b/maven-project/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java
index 1f56ea5a0a..c5abe3f0b6 100644
--- a/maven-project/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java
+++ b/maven-project/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java
@@ -72,26 +72,40 @@ public final class ArtifactModelContainerFactory
private List properties;
+ private static String findBaseUriFrom( List modelProperties )
+ {
+ String baseUri = null;
+ for ( ModelProperty mp : modelProperties )
+ {
+ if ( baseUri == null || mp.getUri().length() < baseUri.length() )
+ {
+ baseUri = mp.getUri();
+ }
+ }
+ return baseUri;
+ }
+
private ArtifactModelContainer( List properties )
{
this.properties = new ArrayList( properties );
this.properties = Collections.unmodifiableList( this.properties );
+ String uri = findBaseUriFrom( this.properties );
- for ( ModelProperty mp : properties )
+ for ( ModelProperty mp : this.properties )
{
- if ( mp.getUri().endsWith( "version" ) )
+ if ( version == null && mp.getUri().equals( uri + "/version" ) )
{
this.version = mp.getValue();
}
- else if ( mp.getUri().endsWith( "artifactId" ) )
+ else if ( artifactId == null && mp.getUri().equals( uri + "/artifactId" ) )
{
this.artifactId = mp.getValue();
}
- else if ( mp.getUri().endsWith( "groupId" ) )
+ else if ( groupId == null && mp.getUri().equals( uri + "/groupId" ) )
{
this.groupId = mp.getValue();
}
- else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.type ) )
+ else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.type ) && type == null )
{
this.type = mp.getValue();
}
@@ -105,8 +119,13 @@ public final class ArtifactModelContainerFactory
if ( artifactId == null )
{
- throw new IllegalArgumentException(
- "Properties does not contain artifact id. Group ID = " + groupId + ", Version = " + version );
+ StringBuffer sb = new StringBuffer();
+ for ( ModelProperty mp : properties )
+ {
+ sb.append( mp ).append( "\r\n" );
+ }
+ throw new IllegalArgumentException( "Properties does not contain artifact id. Group ID = " + groupId +
+ ", Version = " + version + ":" + sb );
}
if ( type == null )
diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java b/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java
index 3b00b80390..01b8be5374 100644
--- a/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java
+++ b/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java
@@ -31,6 +31,8 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
@@ -59,6 +61,10 @@ public final class PomClassicDomainModel
private String id;
+ private File file;
+
+ private File parentFile;
+
/**
* Constructor
*
@@ -73,10 +79,20 @@ public final class PomClassicDomainModel
throw new IllegalArgumentException( "model: null" );
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Writer out = WriterFactory.newXmlWriter( baos );
+ Writer out = null;
MavenXpp3Writer writer = new MavenXpp3Writer();
- writer.write( out, model );
- out.close();
+ try
+ {
+ out = WriterFactory.newXmlWriter( baos );
+ writer.write( out, model );
+ }
+ finally
+ {
+ if ( out != null )
+ {
+ out.close();
+ }
+ }
inputBytes = baos.toByteArray();
}
@@ -96,6 +112,22 @@ public final class PomClassicDomainModel
this.inputBytes = IOUtil.toByteArray( inputStream );
}
+ public PomClassicDomainModel( File file )
+ throws IOException
+ {
+ this( new FileInputStream( file ) );
+ this.file = file;
+ }
+
+ public File getParentFile()
+ {
+ return parentFile;
+ }
+
+ public void setParentFile( File parentFile )
+ {
+ this.parentFile = parentFile;
+ }
/**
* Returns true if groupId.equals(a.groupId) && artifactId.equals(a.artifactId) && version.equals(a.version),
@@ -140,10 +172,15 @@ public final class PomClassicDomainModel
return "";
}
}
- String groupId = ( model.getGroupId() == null ) ? model.getParent().getGroupId() : model.getGroupId();
- String artifactId =
- ( model.getArtifactId() == null ) ? model.getParent().getArtifactId() : model.getArtifactId();
- String version = ( model.getVersion() == null ) ? model.getParent().getVersion() : model.getVersion();
+ String groupId = ( model.getGroupId() == null && model.getParent() != null )
+ ? model.getParent().getGroupId()
+ : model.getGroupId();
+ String artifactId = ( model.getArtifactId() == null && model.getParent() != null )
+ ? model.getParent().getArtifactId()
+ : model.getArtifactId();
+ String version = ( model.getVersion() == null && model.getParent() != null )
+ ? model.getParent().getVersion()
+ : model.getVersion();
id = groupId + ":" + artifactId + ":" + version;
}
@@ -211,6 +248,14 @@ public final class PomClassicDomainModel
return new ByteArrayInputStream( copy );
}
+ /**
+ * @return file of pom. May be null.
+ */
+ public File getFile()
+ {
+ return file;
+ }
+
/**
* @see org.apache.maven.shared.model.DomainModel#getEventHistory()
*/
diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java b/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java
index da31261a1d..041dbdb527 100644
--- a/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java
+++ b/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java
@@ -22,6 +22,7 @@ package org.apache.maven.project.builder;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.shared.model.DomainModel;
import org.apache.maven.shared.model.ModelContainer;
+import org.apache.maven.shared.model.ModelContainerAction;
import org.apache.maven.shared.model.ModelDataSource;
import org.apache.maven.shared.model.ModelMarshaller;
import org.apache.maven.shared.model.ModelProperty;
@@ -33,11 +34,12 @@ import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
-import java.util.Set;
import java.util.Map;
-import java.util.HashMap;
+import java.util.Set;
/**
* Provides methods for transforming model properties into a domain model for the pom classic format and vice versa.
@@ -49,71 +51,77 @@ public final class PomClassicTransformer
/**
* The URIs this tranformer supports
*/
- private final Set uris;
+ private static Set uris = new HashSet( Arrays.asList( ProjectUri.Build.Extensions.xUri,
+ ProjectUri.Build.PluginManagement.Plugins.xUri,
+ ProjectUri.Build.PluginManagement.Plugins.Plugin.configuration,
+ ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.xUri,
+ ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.Exclusions.xUri,
+ ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.xUri,
+
+ ProjectUri.Build.Plugins.xUri,
+ ProjectUri.Build.Plugins.Plugin.configuration,
+ ProjectUri.Build.Plugins.Plugin.Dependencies.xUri,
+ ProjectUri.Build.Plugins.Plugin.Executions.xUri,
+ ProjectUri.Build.Resources.xUri,
+ ProjectUri.Build.Resources.Resource.includes,
+ ProjectUri.Build.Resources.Resource.excludes,
+ ProjectUri.Build.TestResources.xUri,
+
+ ProjectUri.CiManagement.Notifiers.xUri,
+
+ ProjectUri.Contributors.xUri,
+
+ ProjectUri.Dependencies.xUri,
+ ProjectUri.Dependencies.Dependency.Exclusions.xUri,
+
+ ProjectUri.DependencyManagement.Dependencies.xUri,
+ ProjectUri.DependencyManagement.Dependencies.Dependency.Exclusions.xUri,
+
+ ProjectUri.Developers.xUri,
+ ProjectUri.Developers.Developer.roles,
+ ProjectUri.Licenses.xUri,
+ ProjectUri.MailingLists.xUri,
+ ProjectUri.Modules.xUri,
+ ProjectUri.PluginRepositories.xUri,
+
+ ProjectUri.Profiles.xUri,
+ ProjectUri.Profiles.Profile.Build.Plugins.xUri,
+ ProjectUri.Profiles.Profile.Build.Plugins.Plugin.Dependencies.xUri,
+ ProjectUri.Profiles.Profile.Build.Resources.xUri,
+ ProjectUri.Profiles.Profile.Build.TestResources.xUri,
+ ProjectUri.Profiles.Profile.Dependencies.xUri,
+ ProjectUri.Profiles.Profile.Dependencies.Dependency.Exclusions.xUri,
+ ProjectUri.Profiles.Profile.DependencyManagement.Dependencies.xUri,
+ ProjectUri.Profiles.Profile.PluginRepositories.xUri,
+ ProjectUri.Profiles.Profile.Reporting.Plugins.xUri,
+ ProjectUri.Profiles.Profile.Repositories.xUri,
+
+ ProjectUri.Reporting.Plugins.xUri,
+ ProjectUri.Reporting.Plugins.Plugin.ReportSets.xUri,
+
+ ProjectUri.Repositories.xUri,
+
+ "http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins/plugin/dependencies#collection",
+ "http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins/plugin/dependencies/dependency/exclusions#collection",
+ "http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins/plugin/executions#collection",
+ "http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins#collection",
+ "http://apache.org/maven/project/profiles/profile/build/plugins/plugin/dependencies/dependency/exclusions#collection",
+ "http://apache.org/maven/project/profiles/profile/dependencyManagement/dependencies/dependency/exclusions#collection",
+ "http://apache.org/maven/project/profiles/profile/reporting/plugins/plugin/reportSets#collection",
+ "http://apache.org/maven/project/profiles/profile/build/plugins/plugin/executions#collection" ) );
private static Map> cache = new HashMap>();
+ private Collection profiles;
+
//private static List cache = new ArrayList();
/**
* Default constructor
*/
- public PomClassicTransformer()
+ public PomClassicTransformer( Collection profiles )
{
- this.uris = new HashSet( Arrays.asList( ProjectUri.Build.Extensions.xUri,
- ProjectUri.Build.PluginManagement.Plugins.xUri,
- ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.xUri,
- ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.Exclusions.xUri,
- ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.xUri,
- ProjectUri.Build.Plugins.xUri,
- ProjectUri.Build.Plugins.Plugin.configuration,
- ProjectUri.Build.Plugins.Plugin.Dependencies.xUri,
- ProjectUri.Build.Plugins.Plugin.Executions.xUri,
- ProjectUri.Build.Resources.xUri,
- ProjectUri.Build.Resources.Resource.includes,
- ProjectUri.Build.Resources.Resource.excludes,
- ProjectUri.Build.TestResources.xUri,
-
- ProjectUri.CiManagement.Notifiers.xUri,
-
- ProjectUri.Contributors.xUri,
-
- ProjectUri.Dependencies.xUri,
- ProjectUri.Dependencies.Dependency.Exclusions.xUri,
-
- ProjectUri.DependencyManagement.Dependencies.xUri,
- ProjectUri.DependencyManagement.Dependencies.Dependency.Exclusions.xUri,
-
- ProjectUri.Developers.xUri,
- ProjectUri.Developers.Developer.roles, ProjectUri.Licenses.xUri,
- ProjectUri.MailingLists.xUri, ProjectUri.Modules.xUri,
- ProjectUri.PluginRepositories.xUri,
-
- ProjectUri.Profiles.xUri,
- ProjectUri.Profiles.Profile.Build.Plugins.xUri,
- ProjectUri.Profiles.Profile.Build.Plugins.Plugin.Dependencies.xUri,
- ProjectUri.Profiles.Profile.Build.Resources.xUri,
- ProjectUri.Profiles.Profile.Build.TestResources.xUri,
- ProjectUri.Profiles.Profile.Dependencies.xUri,
- ProjectUri.Profiles.Profile.Dependencies.Dependency.Exclusions.xUri,
- ProjectUri.Profiles.Profile.DependencyManagement.Dependencies.xUri,
- ProjectUri.Profiles.Profile.PluginRepositories.xUri,
- ProjectUri.Profiles.Profile.Reporting.Plugins.xUri,
- ProjectUri.Profiles.Profile.Repositories.xUri,
-
- ProjectUri.Reporting.Plugins.xUri,
- ProjectUri.Reporting.Plugins.Plugin.ReportSets.xUri,
-
- ProjectUri.Repositories.xUri,
-
- "http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins/plugin/dependencies#collection",
- "http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins/plugin/dependencies/dependency/exclusions#collection",
- "http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins/plugin/executions#collection",
- "http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins#collection",
- "http://apache.org/maven/project/profiles/profile/build/plugins/plugin/dependencies/dependency/exclusions#collection",
- "http://apache.org/maven/project/profiles/profile/dependencyManagement/dependencies/dependency/exclusions#collection",
- "http://apache.org/maven/project/profiles/profile/reporting/plugins/plugin/reportSets#collection",
- "http://apache.org/maven/project/profiles/profile/build/plugins/plugin/executions#collection" ) );
+ this.profiles = profiles;
}
/**
@@ -140,6 +148,102 @@ public final class PomClassicTransformer
}
}
+ //dependency management
+ ModelDataSource source = new DefaultModelDataSource();
+ source.init( props, Arrays.asList( new ArtifactModelContainerFactory(), new IdModelContainerFactory() ) );
+
+ for ( ModelContainer dependencyContainer : source.queryFor( ProjectUri.Dependencies.Dependency.xUri ) )
+ {
+ for ( ModelContainer managementContainer : source.queryFor(
+ ProjectUri.DependencyManagement.Dependencies.Dependency.xUri ) )
+ {
+ managementContainer = new ArtifactModelContainerFactory().create(
+ transformDependencyManagement( managementContainer.getProperties() ) );
+ ModelContainerAction action = dependencyContainer.containerAction( managementContainer );
+ if ( action.equals( ModelContainerAction.JOIN ) || action.equals( ModelContainerAction.DELETE ) )
+ {
+ source.join( dependencyContainer, managementContainer );
+ }
+ }
+ }
+
+ for ( ModelContainer dependencyContainer : source.queryFor( ProjectUri.Build.Plugins.Plugin.xUri ) )
+ {
+ for ( ModelContainer managementContainer : source.queryFor(
+ ProjectUri.Build.PluginManagement.Plugins.Plugin.xUri ) )
+ {
+ managementContainer = new ArtifactModelContainerFactory().create(
+ transformPluginManagement( managementContainer.getProperties() ) );
+
+ //Remove duplicate executions tags
+ boolean hasExecutionsTag = false;
+ for ( ModelProperty mp : dependencyContainer.getProperties() )
+ {
+ if ( mp.getUri().equals( ProjectUri.Build.Plugins.Plugin.Executions.xUri ) )
+ {
+ hasExecutionsTag = true;
+ break;
+ }
+ }
+ List pList = new ArrayList();
+ if ( !hasExecutionsTag )
+ {
+ pList = managementContainer.getProperties();
+ }
+ else
+ {
+ for ( ModelProperty mp : managementContainer.getProperties() )
+ {
+ if ( !mp.getUri().equals( ProjectUri.Build.Plugins.Plugin.Executions.xUri ) )
+ {
+ pList.add( mp );
+ }
+ }
+ }
+ managementContainer = new ArtifactModelContainerFactory().create( pList );
+
+ ModelContainerAction action = dependencyContainer.containerAction( managementContainer );
+ if ( action.equals( ModelContainerAction.JOIN ) || action.equals( ModelContainerAction.DELETE ) )
+ {
+ source.join( dependencyContainer, managementContainer );
+ }
+ }
+ }
+
+ props = source.getModelProperties();
+
+ //Rule: Do not join plugin executions without ids
+ Set removeProperties = new HashSet();
+ ModelDataSource dataSource = new DefaultModelDataSource();
+ dataSource.init( props, Arrays.asList( new ArtifactModelContainerFactory(), new IdModelContainerFactory() ) );
+ List containers = dataSource.queryFor( ProjectUri.Build.Plugins.Plugin.xUri );
+ for ( ModelContainer pluginContainer : containers )
+ {
+ ModelDataSource executionSource = new DefaultModelDataSource();
+ executionSource.init( pluginContainer.getProperties(),
+ Arrays.asList( new ArtifactModelContainerFactory(), new IdModelContainerFactory() ) );
+ List executionContainers =
+ executionSource.queryFor( ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri );
+ if ( executionContainers.size() < 2 )
+ {
+ continue;
+ }
+
+ boolean hasAtLeastOneWithoutId = true;
+ for ( ModelContainer executionContainer : executionContainers )
+ {
+ if ( hasAtLeastOneWithoutId )
+ {
+ hasAtLeastOneWithoutId = hasExecutionId( executionContainer );
+ }
+ if ( !hasAtLeastOneWithoutId && !hasExecutionId( executionContainer ) &&
+ executionContainers.indexOf( executionContainer ) > 0 )
+ {
+ removeProperties.addAll( executionContainer.getProperties() );
+ }
+ }
+ }
+ props.removeAll( removeProperties );
String xml = null;
try
{
@@ -150,7 +254,7 @@ public final class PomClassicTransformer
{
throw new IOException( e + ":\r\n" + xml );
}
- }
+ }
/**
* @see ModelTransformer#transformToModelProperties(java.util.List)
@@ -168,6 +272,11 @@ public final class PomClassicTransformer
StringBuffer scmUrl = new StringBuffer();
StringBuffer scmConnectionUrl = new StringBuffer();
StringBuffer scmDeveloperUrl = new StringBuffer();
+
+ boolean containsBuildResources = false;
+ boolean containsTestResources = false;
+ boolean containsPluginRepositories = false;
+
for ( DomainModel domainModel : domainModels )
{
if ( !( domainModel instanceof PomClassicDomainModel ) )
@@ -185,6 +294,7 @@ public final class PomClassicTransformer
List tmp = ModelMarshaller.marshallXmlToModelProperties(
( (PomClassicDomainModel) domainModel ).getInputStream(), ProjectUri.baseUri, uris );
+
List clearedProperties = new ArrayList();
//Missing Version Rule
@@ -219,7 +329,7 @@ public final class PomClassicTransformer
}
- //Not inherited plugin execution rule
+ //Not inherited plugin execution rule
if ( domainModels.indexOf( domainModel ) > 0 )
{
List removeProperties = new ArrayList();
@@ -320,25 +430,62 @@ public final class PomClassicTransformer
tmp.add( index, new ModelProperty( ProjectUri.Scm.developerConnection, scmDeveloperUrl.toString() ) );
}
-
- //Remove Plugin Repository Inheritance Rule
//Project Name Inheritance Rule
//Packaging Inheritance Rule
- //Build Resources Inheritence Rule
- //Build Test Resources Inheritance Rule
//Profiles not inherited rule
for ( ModelProperty mp : tmp )
{
String uri = mp.getUri();
if ( domainModels.indexOf( domainModel ) > 0 && ( uri.equals( ProjectUri.name ) ||
- uri.equals( ProjectUri.packaging ) || uri.startsWith( ProjectUri.Profiles.xUri ) ||
- uri.startsWith( ProjectUri.Build.Resources.xUri ) ||
- uri.startsWith( ProjectUri.Build.TestResources.xUri ) ||
- uri.startsWith( ProjectUri.PluginRepositories.xUri ) ) )
+ uri.equals( ProjectUri.packaging ) || uri.startsWith( ProjectUri.Profiles.xUri ) ) )
{
clearedProperties.add( mp );
}
}
+
+ //Remove Plugin Repository Inheritance Rule
+ //Build Resources Inheritence Rule
+ //Build Test Resources Inheritance Rule
+ //Only inherit IF: the above is contained in super pom (domainModels.size() -1) && the child doesn't has it's own respective field
+ if ( domainModels.indexOf( domainModel ) == 0 )
+ {
+ containsBuildResources = hasProjectUri( ProjectUri.Build.Resources.xUri, tmp );
+ containsTestResources = hasProjectUri( ProjectUri.Build.TestResources.xUri, tmp );
+ containsPluginRepositories = hasProjectUri( ProjectUri.PluginRepositories.xUri, tmp );
+ }
+ for ( ModelProperty mp : tmp )
+ {
+ if ( domainModels.indexOf( domainModel ) > 0 )
+ {
+ String uri = mp.getUri();
+ boolean isNotSuperPom = domainModels.indexOf( domainModel ) != ( domainModels.size() - 1 );
+ if ( isNotSuperPom )
+ {
+ if ( uri.startsWith( ProjectUri.Build.Resources.xUri ) ||
+ uri.startsWith( ProjectUri.Build.TestResources.xUri ) ||
+ uri.startsWith( ProjectUri.PluginRepositories.xUri ) )
+ {
+ clearedProperties.add( mp );
+ }
+ }
+ else
+ {
+ if ( containsBuildResources && uri.startsWith( ProjectUri.Build.Resources.xUri ) )
+ {
+ clearedProperties.add( mp );
+ }
+ else if ( containsTestResources && uri.startsWith( ProjectUri.Build.TestResources.xUri ) )
+ {
+ clearedProperties.add( mp );
+ }
+ else if ( containsPluginRepositories && uri.startsWith( ProjectUri.PluginRepositories.xUri ) )
+ {
+ clearedProperties.add( mp );
+ }
+ }
+ }
+ }
+
ModelProperty artifactId = getPropertyFor( ProjectUri.artifactId, tmp );
if ( artifactId != null )
{
@@ -347,8 +494,9 @@ public final class PomClassicTransformer
tmp.removeAll( clearedProperties );
modelProperties.addAll( tmp );
+ modelProperties.removeAll( clearedProperties );
- if ( domainModels.indexOf( domainModel ) > 0 )
+ if ( domainModels.indexOf( domainModel ) == 0 )
{
//cache.put( pomDomainModel.getId(), modelProperties );
}
@@ -362,9 +510,22 @@ public final class PomClassicTransformer
}
*/
}
+
return modelProperties;
}
+ private static boolean hasExecutionId( ModelContainer executionContainer )
+ {
+ for ( ModelProperty mp : executionContainer.getProperties() )
+ {
+ if ( mp.getUri().equals( ProjectUri.Build.Plugins.Plugin.Executions.Execution.id ) )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* Returns the base uri of all model properties: http://apache.org/maven/project/
*
@@ -375,6 +536,18 @@ public final class PomClassicTransformer
return ProjectUri.baseUri;
}
+ private static boolean hasProjectUri( String projectUri, List modelProperties )
+ {
+ for ( ModelProperty mp : modelProperties )
+ {
+ if ( mp.getUri().equals( projectUri ) )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* Returns all model properties containing the specified uri from the specified properties list.
*
@@ -414,5 +587,34 @@ public final class PomClassicTransformer
}
return null;
}
+
+ private static List transformDependencyManagement( List modelProperties )
+ {
+ List transformedProperties = new ArrayList();
+ for ( ModelProperty mp : modelProperties )
+ {
+ if ( mp.getUri().startsWith( ProjectUri.DependencyManagement.xUri ) )
+ {
+ transformedProperties.add( new ModelProperty(
+ mp.getUri().replace( ProjectUri.DependencyManagement.xUri, ProjectUri.xUri ), mp.getValue() ) );
+ }
+ }
+ return transformedProperties;
+ }
+
+ public static List transformPluginManagement( List modelProperties )
+ {
+ List transformedProperties = new ArrayList();
+ for ( ModelProperty mp : modelProperties )
+ {
+ if ( mp.getUri().startsWith( ProjectUri.Build.PluginManagement.xUri ) )
+ {
+ transformedProperties.add( new ModelProperty(
+ mp.getUri().replace( ProjectUri.Build.PluginManagement.xUri, ProjectUri.Build.xUri ),
+ mp.getValue() ) );
+ }
+ }
+ return transformedProperties;
+ }
}
diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/Profile.java b/maven-project/src/main/java/org/apache/maven/project/builder/Profile.java
new file mode 100644
index 0000000000..2dfd38cc89
--- /dev/null
+++ b/maven-project/src/main/java/org/apache/maven/project/builder/Profile.java
@@ -0,0 +1,26 @@
+package org.apache.maven.project.builder;
+
+/*
+ * 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.
+ */
+
+public class Profile
+{
+
+
+}
diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java
index 484b299933..a60e63c77d 100644
--- a/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java
+++ b/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java
@@ -21,6 +21,8 @@ package org.apache.maven.project.builder;
import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuilderConfiguration;
+import org.apache.maven.shared.model.ImportModel;
import org.apache.maven.shared.model.InterpolatorProperty;
import java.io.File;
@@ -40,17 +42,19 @@ public interface ProjectBuilder
/**
* Returns a maven project for the specified input stream.
*
- * @param pom input stream of the model
- * @param inheritedModels list of models containing additional parent models in order from most to least specialized
- * @param interpolatorProperties properties used for interpolation of properties within the model
- * @param resolver artifact resolver used in resolving artifacts
- * @param baseDirectory the base directory of the model
+ * @param pom input stream of the model
+ * @param inheritedModels list of models containing additional parent models in order from most to least specialized
+ * @param interpolatorProperties properties used for interpolation of properties within the model
+ * @param resolver artifact resolver used in resolving artifacts
+ * @param baseDirectory the base directory of the model
+ * @param projectBuilderConfiguration
* @return a maven project for the specified input stream
* @throws IOException if there is a problem in the construction of the maven project
*/
- MavenProject buildFromLocalPath( InputStream pom, List inheritedModels,
+ MavenProject buildFromLocalPath( InputStream pom, List inheritedModels, Collection importModels,
Collection interpolatorProperties,
- PomArtifactResolver resolver, File baseDirectory )
+ PomArtifactResolver resolver, File baseDirectory,
+ ProjectBuilderConfiguration projectBuilderConfiguration )
throws IOException;
}
diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/ProjectUri.java b/maven-project/src/main/java/org/apache/maven/project/builder/ProjectUri.java
index c2b05bff7e..4e4f3b1f4a 100644
--- a/maven-project/src/main/java/org/apache/maven/project/builder/ProjectUri.java
+++ b/maven-project/src/main/java/org/apache/maven/project/builder/ProjectUri.java
@@ -372,27 +372,27 @@ public class ProjectUri
public static class Executions
{
public static String xUri =
- "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions";
+ "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions#collection";
public static class Execution
{
public static String xUri =
- "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions/execution";
+ "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions#collection/execution";
public static String id =
- "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions/execution/id";
+ "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions#collection/execution/id";
public static String phase =
- "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions/execution/phase";
+ "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions#collection/execution/phase";
public static String goals =
- "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions/execution/goals";
+ "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions#collection/execution/goals";
public static String inherited =
- "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions/execution/inherited";
+ "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions#collection/execution/inherited";
public static String configuration =
- "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions/execution/configuration";
+ "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/execution#collections/execution/configuration";
}
}
diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultImportModel.java b/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultImportModel.java
new file mode 100644
index 0000000000..19b572cdc7
--- /dev/null
+++ b/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultImportModel.java
@@ -0,0 +1,86 @@
+package org.apache.maven.project.builder.impl;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.shared.model.ImportModel;
+import org.apache.maven.shared.model.ModelProperty;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public final class DefaultImportModel
+ implements ImportModel
+{
+
+ private final String id;
+
+ private final List modelProperties;
+
+ public DefaultImportModel( String id, List modelProperties )
+ {
+ if ( id == null )
+ {
+ throw new IllegalArgumentException( "id: null" );
+ }
+
+ if ( modelProperties == null )
+ {
+ throw new IllegalArgumentException( "modelProperties: null" );
+ }
+ this.id = id;
+ this.modelProperties = new ArrayList( modelProperties );
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public List getModelProperties()
+ {
+ return new ArrayList( modelProperties );
+ }
+
+ public boolean equals( Object o )
+ {
+ if ( this == o )
+ {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() )
+ {
+ return false;
+ }
+
+ ImportModel that = (ImportModel) o;
+
+ if ( id != null ? !id.equals( that.getId() ) : that.getId() != null )
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ return ( id != null ? id.hashCode() : 0 );
+ }
+}
diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java
index ed37d7a430..bf68ff022f 100644
--- a/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java
+++ b/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java
@@ -19,11 +19,15 @@ package org.apache.maven.project.builder.impl;
* under the License.
*/
+import org.apache.maven.MavenTools;
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuilderConfiguration;
+import org.apache.maven.project.RepositoryHelper;
import org.apache.maven.project.builder.ArtifactModelContainerFactory;
import org.apache.maven.project.builder.IdModelContainerFactory;
import org.apache.maven.project.builder.PomArtifactResolver;
@@ -33,13 +37,13 @@ import org.apache.maven.project.builder.ProjectBuilder;
import org.apache.maven.project.validation.ModelValidationResult;
import org.apache.maven.project.validation.ModelValidator;
import org.apache.maven.shared.model.DomainModel;
+import org.apache.maven.shared.model.ImportModel;
import org.apache.maven.shared.model.InterpolatorProperty;
import org.apache.maven.shared.model.ModelTransformerContext;
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
@@ -64,6 +68,10 @@ public final class DefaultProjectBuilder
private ModelValidator validator;
+ private MavenTools mavenTools;
+
+ private RepositoryHelper repositoryHelper;
+
/**
* Default constructor
*/
@@ -86,11 +94,13 @@ public final class DefaultProjectBuilder
}
/**
- * @see ProjectBuilder#buildFromLocalPath(java.io.InputStream, java.util.List, java.util.Collection, org.apache.maven.project.builder.PomArtifactResolver, java.io.File)
+ * @see ProjectBuilder#buildFromLocalPath(java.io.InputStream, java.util.List, java.util.Collection, java.util.Collection, org.apache.maven.project.builder.PomArtifactResolver, java.io.File, org.apache.maven.project.ProjectBuilderConfiguration)
*/
public MavenProject buildFromLocalPath( InputStream pom, List inheritedModels,
+ Collection importModels,
Collection interpolatorProperties,
- PomArtifactResolver resolver, File projectDirectory )
+ PomArtifactResolver resolver, File projectDirectory,
+ ProjectBuilderConfiguration projectBuilderConfiguration )
throws IOException
{
if ( pom == null )
@@ -132,16 +142,30 @@ public final class DefaultProjectBuilder
List domainModels = new ArrayList();
domainModels.add( domainModel );
+ File parentFile = null;
if ( domainModel.getModel().getParent() != null )
{
+ List mavenParents;
if ( isParentLocal( domainModel.getModel().getParent(), projectDirectory ) )
{
- domainModels.addAll( getDomainModelParentsFromLocalPath( domainModel, resolver, projectDirectory ) );
+ mavenParents = getDomainModelParentsFromLocalPath( domainModel, resolver, projectDirectory );
}
else
{
- domainModels.addAll( getDomainModelParentsFromRepository( domainModel, resolver ) );
+ mavenParents = getDomainModelParentsFromRepository( domainModel, resolver );
}
+
+ if ( mavenParents.size() > 0 )
+ {
+ PomClassicDomainModel dm = (PomClassicDomainModel) mavenParents.get( 0 );
+ parentFile = dm.getFile();
+ domainModel.setParentFile( parentFile );
+ // mavenParent = buildFromLocalPath( dm.getInputStream(), inheritedModels,
+ // importModels, interpolatorProperties, resolver, projectDirectory);
+ // mavenParent.setFile(dm.getFile());
+ }
+
+ domainModels.addAll( mavenParents );
}
for ( Model model : inheritedModels )
@@ -149,16 +173,37 @@ public final class DefaultProjectBuilder
domainModels.add( new PomClassicDomainModel( model ) );
}
- PomClassicTransformer transformer = new PomClassicTransformer();
+ PomClassicTransformer transformer = new PomClassicTransformer( null );
ModelTransformerContext ctx = new ModelTransformerContext(
Arrays.asList( new ArtifactModelContainerFactory(), new IdModelContainerFactory() ) );
- PomClassicDomainModel transformedDomainModel =
- ( (PomClassicDomainModel) ctx.transform( domainModels, transformer, transformer, null, properties ) );
- Model model = transformedDomainModel.getModel();
- return new MavenProject( model );
+ PomClassicDomainModel transformedDomainModel = ( (PomClassicDomainModel) ctx.transform( domainModels,
+ transformer,
+ transformer,
+ importModels,
+ properties ) );
+ // System.out.println(transformedDomainModel.asString());
+ try
+ {
+ MavenProject mavenProject = new MavenProject( transformedDomainModel.getModel(), artifactFactory,
+ mavenTools, repositoryHelper, null,
+ projectBuilderConfiguration );
+ mavenProject.setParentFile( parentFile );
+ return mavenProject;
+ }
+ catch ( InvalidRepositoryException e )
+ {
+ throw new IOException( e.getMessage() );
+ }
}
+ /**
+ * Returns true if the relative path of the specified parent references a pom, otherwise returns false.
+ *
+ * @param parent the parent model info
+ * @param projectDirectory the project directory of the child pom
+ * @return true if the relative path of the specified parent references a pom, otherwise returns fals
+ */
private boolean isParentLocal( Parent parent, File projectDirectory )
{
try
@@ -199,11 +244,11 @@ public final class DefaultProjectBuilder
artifactFactory.createParentArtifact( parent.getGroupId(), parent.getArtifactId(), parent.getVersion() );
artifactResolver.resolve( artifactParent );
- PomClassicDomainModel parentDomainModel =
- new PomClassicDomainModel( new FileInputStream( artifactParent.getFile() ) );
+ PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( artifactParent.getFile() );
if ( !parentDomainModel.matchesParent( domainModel.getModel().getParent() ) )
{
- logger.warn( "Parent pom ids do not match: File = " + artifactParent.getFile().getAbsolutePath() );
+ logger.warn( "Parent pom ids do not match: Parent File = " + artifactParent.getFile().getAbsolutePath() +
+ ": Child ID = " + domainModel.getModel().getId() );
return domainModels;
}
else
@@ -217,7 +262,15 @@ public final class DefaultProjectBuilder
return domainModels;
}
-
+ /**
+ * Returns list of domain model parents of the specified domain model. The parent domain models are part
+ *
+ * @param domainModel
+ * @param artifactResolver
+ * @param projectDirectory
+ * @return
+ * @throws IOException
+ */
private List getDomainModelParentsFromLocalPath( PomClassicDomainModel domainModel,
PomArtifactResolver artifactResolver,
File projectDirectory )
@@ -248,13 +301,14 @@ public final class DefaultProjectBuilder
if ( !parentFile.exists() )
{
- throw new IOException( "File does not exist: File =" + parentFile.getAbsolutePath() );
+ throw new IOException( "File does not exist: File = " + parentFile.getAbsolutePath() );
}
- PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( new FileInputStream( parentFile ) );
+ PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( parentFile );
if ( !parentDomainModel.matchesParent( domainModel.getModel().getParent() ) )
{
- logger.warn( "Parent pom ids do not match: File = " + parentFile.getAbsolutePath() );
+ logger.warn( "Parent pom ids do not match: Parent File = " + parentFile.getAbsolutePath() +
+ ": Child ID = " + domainModel.getModel().getId() );
}
domainModels.add( parentDomainModel );
@@ -290,6 +344,4 @@ public final class DefaultProjectBuilder
throw new IOException( "Failed to validate: " + validationResult.toString() );
}
}
-
-
}
diff --git a/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java b/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java
index ce45ad50f3..c9ff9ec1b9 100644
--- a/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java
+++ b/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java
@@ -26,12 +26,15 @@ import org.apache.maven.model.DeploymentRepository;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.Model;
import org.apache.maven.model.PluginManagement;
+import org.apache.maven.model.ReportPlugin;
+import org.apache.maven.model.ReportSet;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.Resource;
import org.apache.maven.model.Scm;
import org.apache.maven.model.Site;
import org.apache.maven.project.ModelUtils;
import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
import java.util.ArrayList;
import java.util.Iterator;
@@ -52,21 +55,131 @@ import java.util.TreeMap;
public class DefaultModelInheritanceAssembler
implements ModelInheritanceAssembler
{
+
+ // TODO: Remove this!
+ @SuppressWarnings("unchecked")
+ public void assembleBuildInheritance( Build childBuild, Build parentBuild, boolean handleAsInheritance )
+ {
+ // The build has been set but we want to step in here and fill in
+ // values that have not been set by the child.
+
+ if ( childBuild.getSourceDirectory() == null )
+ {
+ childBuild.setSourceDirectory( parentBuild.getSourceDirectory() );
+ }
+
+ if ( childBuild.getScriptSourceDirectory() == null )
+ {
+ childBuild.setScriptSourceDirectory( parentBuild.getScriptSourceDirectory() );
+ }
+
+ if ( childBuild.getTestSourceDirectory() == null )
+ {
+ childBuild.setTestSourceDirectory( parentBuild.getTestSourceDirectory() );
+ }
+
+ if ( childBuild.getOutputDirectory() == null )
+ {
+ childBuild.setOutputDirectory( parentBuild.getOutputDirectory() );
+ }
+
+ if ( childBuild.getTestOutputDirectory() == null )
+ {
+ childBuild.setTestOutputDirectory( parentBuild.getTestOutputDirectory() );
+ }
+
+ // Extensions are accumlated
+ ModelUtils.mergeExtensionLists( childBuild, parentBuild );
+
+ if ( childBuild.getDirectory() == null )
+ {
+ childBuild.setDirectory( parentBuild.getDirectory() );
+ }
+
+ if ( childBuild.getDefaultGoal() == null )
+ {
+ childBuild.setDefaultGoal( parentBuild.getDefaultGoal() );
+ }
+
+ if ( childBuild.getFinalName() == null )
+ {
+ childBuild.setFinalName( parentBuild.getFinalName() );
+ }
+
+ ModelUtils.mergeFilterLists( childBuild.getFilters(), parentBuild.getFilters() );
+
+ List resources = childBuild.getResources();
+ if ( ( resources == null ) || resources.isEmpty() )
+ {
+ childBuild.setResources( parentBuild.getResources() );
+ }
+
+ resources = childBuild.getTestResources();
+ if ( ( resources == null ) || resources.isEmpty() )
+ {
+ childBuild.setTestResources( parentBuild.getTestResources() );
+ }
+
+ // Plugins are aggregated if Plugin.inherit != false
+ ModelUtils.mergePluginLists( childBuild, parentBuild, handleAsInheritance );
+
+ // Plugin management :: aggregate
+ PluginManagement dominantPM = childBuild.getPluginManagement();
+ PluginManagement recessivePM = parentBuild.getPluginManagement();
+
+ if ( ( dominantPM == null ) && ( recessivePM != null ) )
+ {
+ // FIXME: Filter out the inherited == false stuff!
+ childBuild.setPluginManagement( recessivePM );
+ }
+ else
+ {
+ ModelUtils.mergePluginLists( childBuild.getPluginManagement(), parentBuild.getPluginManagement(), false );
+ }
+ }
+
+ private void assembleScmInheritance( Model child, Model parent, String childPathAdjustment, boolean appendPaths )
+ {
+ if ( parent.getScm() != null )
+ {
+ Scm parentScm = parent.getScm();
+
+ Scm childScm = child.getScm();
+
+ if ( childScm == null )
+ {
+ childScm = new Scm();
+
+ child.setScm( childScm );
+ }
+
+ if ( StringUtils.isEmpty( childScm.getConnection() ) && !StringUtils.isEmpty( parentScm.getConnection() ) )
+ {
+ childScm.setConnection(
+ appendPath( parentScm.getConnection(), child.getArtifactId(), childPathAdjustment, appendPaths ) );
+ }
+
+ if ( StringUtils.isEmpty( childScm.getDeveloperConnection() ) &&
+ !StringUtils.isEmpty( parentScm.getDeveloperConnection() ) )
+ {
+ childScm
+ .setDeveloperConnection( appendPath( parentScm.getDeveloperConnection(), child.getArtifactId(),
+ childPathAdjustment, appendPaths ) );
+ }
+
+ if ( StringUtils.isEmpty( childScm.getUrl() ) && !StringUtils.isEmpty( parentScm.getUrl() ) )
+ {
+ childScm.setUrl(
+ appendPath( parentScm.getUrl(), child.getArtifactId(), childPathAdjustment, appendPaths ) );
+ }
+ }
+ }
+
public void copyModel( Model dest, Model source )
{
assembleModelInheritance( dest, source, null, false );
}
- public void assembleModelInheritance( Model child, Model parent, String childPathAdjustment )
- {
- assembleModelInheritance( child, parent, childPathAdjustment, true );
- }
-
- public void assembleModelInheritance( Model child, Model parent )
- {
- assembleModelInheritance( child, parent, null, true );
- }
-
private void assembleModelInheritance( Model child, Model parent, String childPathAdjustment, boolean appendPaths )
{
// cannot inherit from null parent.
@@ -243,10 +356,179 @@ public class DefaultModelInheritanceAssembler
childReporting.setOutputDirectory( parentReporting.getOutputDirectory() );
}
- ModelUtils.mergeReportPluginLists( childReporting, parentReporting, true );
+ mergeReportPluginLists( childReporting, parentReporting, true );
}
}
+ private static void mergeReportPluginLists( Reporting child, Reporting parent, boolean handleAsInheritance )
+ {
+ if ( ( child == null ) || ( parent == null ) )
+ {
+ // nothing to do.
+ return;
+ }
+
+ List parentPlugins = parent.getPlugins();
+
+ if ( ( parentPlugins != null ) && !parentPlugins.isEmpty() )
+ {
+ Map assembledPlugins = new TreeMap();
+
+ Map childPlugins = child.getReportPluginsAsMap();
+
+ for ( Iterator it = parentPlugins.iterator(); it.hasNext(); )
+ {
+ ReportPlugin parentPlugin = (ReportPlugin) it.next();
+
+ String parentInherited = parentPlugin.getInherited();
+
+ if ( !handleAsInheritance || ( parentInherited == null ) ||
+ Boolean.valueOf( parentInherited ).booleanValue() )
+ {
+
+ ReportPlugin assembledPlugin = parentPlugin;
+
+ ReportPlugin childPlugin = (ReportPlugin) childPlugins.get( parentPlugin.getKey() );
+
+ if ( childPlugin != null )
+ {
+ assembledPlugin = childPlugin;
+
+ mergeReportPluginDefinitions( childPlugin, parentPlugin, handleAsInheritance );
+ }
+
+ if ( handleAsInheritance && ( parentInherited == null ) )
+ {
+ assembledPlugin.unsetInheritanceApplied();
+ }
+
+ assembledPlugins.put( assembledPlugin.getKey(), assembledPlugin );
+ }
+ }
+
+ for ( Iterator it = childPlugins.values().iterator(); it.hasNext(); )
+ {
+ ReportPlugin childPlugin = (ReportPlugin) it.next();
+
+ if ( !assembledPlugins.containsKey( childPlugin.getKey() ) )
+ {
+ assembledPlugins.put( childPlugin.getKey(), childPlugin );
+ }
+ }
+
+ child.setPlugins( new ArrayList( assembledPlugins.values() ) );
+
+ child.flushReportPluginMap();
+ }
+ }
+
+ private static void mergeReportSetDefinitions( ReportSet child, ReportSet parent )
+ {
+ List parentReports = parent.getReports();
+ List childReports = child.getReports();
+
+ List reports = new ArrayList();
+
+ if ( ( childReports != null ) && !childReports.isEmpty() )
+ {
+ reports.addAll( childReports );
+ }
+
+ if ( parentReports != null )
+ {
+ for ( Iterator i = parentReports.iterator(); i.hasNext(); )
+ {
+ String report = (String) i.next();
+
+ if ( !reports.contains( report ) )
+ {
+ reports.add( report );
+ }
+ }
+ }
+
+ child.setReports( reports );
+
+ Xpp3Dom childConfiguration = (Xpp3Dom) child.getConfiguration();
+ Xpp3Dom parentConfiguration = (Xpp3Dom) parent.getConfiguration();
+
+ childConfiguration = Xpp3Dom.mergeXpp3Dom( childConfiguration, parentConfiguration );
+
+ child.setConfiguration( childConfiguration );
+ }
+
+
+ public static void mergeReportPluginDefinitions( ReportPlugin child, ReportPlugin parent,
+ boolean handleAsInheritance )
+ {
+ if ( ( child == null ) || ( parent == null ) )
+ {
+ // nothing to do.
+ return;
+ }
+
+ if ( ( child.getVersion() == null ) && ( parent.getVersion() != null ) )
+ {
+ child.setVersion( parent.getVersion() );
+ }
+
+ // from here to the end of the method is dealing with merging of the section.
+ String parentInherited = parent.getInherited();
+
+ boolean parentIsInherited = ( parentInherited == null ) || Boolean.valueOf( parentInherited ).booleanValue();
+
+ List parentReportSets = parent.getReportSets();
+
+ if ( ( parentReportSets != null ) && !parentReportSets.isEmpty() )
+ {
+ Map assembledReportSets = new TreeMap();
+
+ Map childReportSets = child.getReportSetsAsMap();
+
+ for ( Iterator it = parentReportSets.iterator(); it.hasNext(); )
+ {
+ ReportSet parentReportSet = (ReportSet) it.next();
+
+ if ( !handleAsInheritance || parentIsInherited )
+ {
+ ReportSet assembledReportSet = parentReportSet;
+
+ ReportSet childReportSet = (ReportSet) childReportSets.get( parentReportSet.getId() );
+
+ if ( childReportSet != null )
+ {
+ mergeReportSetDefinitions( childReportSet, parentReportSet );
+
+ assembledReportSet = childReportSet;
+ }
+ else if ( handleAsInheritance && ( parentInherited == null ) )
+ {
+ parentReportSet.unsetInheritanceApplied();
+ }
+
+ assembledReportSets.put( assembledReportSet.getId(), assembledReportSet );
+ }
+ }
+
+ for ( Iterator it = childReportSets.entrySet().iterator(); it.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry) it.next();
+
+ String id = (String) entry.getKey();
+
+ if ( !assembledReportSets.containsKey( id ) )
+ {
+ assembledReportSets.put( id, entry.getValue() );
+ }
+ }
+
+ child.setReportSets( new ArrayList( assembledReportSets.values() ) );
+
+ child.flushReportSetMap();
+ }
+
+ }
+
// TODO: Remove this!
@SuppressWarnings("unchecked")
private void assembleDependencyInheritance( Model child, Model parent )
@@ -295,129 +577,8 @@ public class DefaultModelInheritanceAssembler
}
}
- // TODO: Remove this!
- @SuppressWarnings("unchecked")
- public void assembleBuildInheritance( Build childBuild,
- Build parentBuild,
- boolean handleAsInheritance )
- {
- // The build has been set but we want to step in here and fill in
- // values that have not been set by the child.
-
- if ( childBuild.getSourceDirectory() == null )
- {
- childBuild.setSourceDirectory( parentBuild.getSourceDirectory() );
- }
-
- if ( childBuild.getScriptSourceDirectory() == null )
- {
- childBuild.setScriptSourceDirectory( parentBuild.getScriptSourceDirectory() );
- }
-
- if ( childBuild.getTestSourceDirectory() == null )
- {
- childBuild.setTestSourceDirectory( parentBuild.getTestSourceDirectory() );
- }
-
- if ( childBuild.getOutputDirectory() == null )
- {
- childBuild.setOutputDirectory( parentBuild.getOutputDirectory() );
- }
-
- if ( childBuild.getTestOutputDirectory() == null )
- {
- childBuild.setTestOutputDirectory( parentBuild.getTestOutputDirectory() );
- }
-
- // Extensions are accumlated
- ModelUtils.mergeExtensionLists( childBuild, parentBuild );
-
- if ( childBuild.getDirectory() == null )
- {
- childBuild.setDirectory( parentBuild.getDirectory() );
- }
-
- if ( childBuild.getDefaultGoal() == null )
- {
- childBuild.setDefaultGoal( parentBuild.getDefaultGoal() );
- }
-
- if ( childBuild.getFinalName() == null )
- {
- childBuild.setFinalName( parentBuild.getFinalName() );
- }
-
- ModelUtils.mergeFilterLists( childBuild.getFilters(), parentBuild.getFilters() );
-
- List resources = childBuild.getResources();
- if ( ( resources == null ) || resources.isEmpty() )
- {
- childBuild.setResources( parentBuild.getResources() );
- }
-
- resources = childBuild.getTestResources();
- if ( ( resources == null ) || resources.isEmpty() )
- {
- childBuild.setTestResources( parentBuild.getTestResources() );
- }
-
- // Plugins are aggregated if Plugin.inherit != false
- ModelUtils.mergePluginLists( childBuild, parentBuild, handleAsInheritance );
-
- // Plugin management :: aggregate
- PluginManagement dominantPM = childBuild.getPluginManagement();
- PluginManagement recessivePM = parentBuild.getPluginManagement();
-
- if ( ( dominantPM == null ) && ( recessivePM != null ) )
- {
- // FIXME: Filter out the inherited == false stuff!
- childBuild.setPluginManagement( recessivePM );
- }
- else
- {
- ModelUtils.mergePluginLists( childBuild.getPluginManagement(), parentBuild.getPluginManagement(),
- false );
- }
- }
-
- private void assembleScmInheritance( Model child, Model parent, String childPathAdjustment, boolean appendPaths )
- {
- if ( parent.getScm() != null )
- {
- Scm parentScm = parent.getScm();
-
- Scm childScm = child.getScm();
-
- if ( childScm == null )
- {
- childScm = new Scm();
-
- child.setScm( childScm );
- }
-
- if ( StringUtils.isEmpty( childScm.getConnection() ) && !StringUtils.isEmpty( parentScm.getConnection() ) )
- {
- childScm.setConnection(
- appendPath( parentScm.getConnection(), child.getArtifactId(), childPathAdjustment, appendPaths ) );
- }
-
- if ( StringUtils.isEmpty( childScm.getDeveloperConnection() ) &&
- !StringUtils.isEmpty( parentScm.getDeveloperConnection() ) )
- {
- childScm
- .setDeveloperConnection( appendPath( parentScm.getDeveloperConnection(), child.getArtifactId(),
- childPathAdjustment, appendPaths ) );
- }
-
- if ( StringUtils.isEmpty( childScm.getUrl() ) && !StringUtils.isEmpty( parentScm.getUrl() ) )
- {
- childScm.setUrl(
- appendPath( parentScm.getUrl(), child.getArtifactId(), childPathAdjustment, appendPaths ) );
- }
- }
- }
-
- private void assembleDistributionInheritence( Model child, Model parent, String childPathAdjustment, boolean appendPaths )
+ private void assembleDistributionInheritence( Model child, Model parent, String childPathAdjustment,
+ boolean appendPaths )
{
if ( parent.getDistributionManagement() != null )
{
@@ -570,7 +731,6 @@ public class DefaultModelInheritanceAssembler
}
}
-
StringBuffer cleanedPath = new StringBuffer();
while ( !pathElements.isEmpty() )
diff --git a/maven-project/src/main/java/org/apache/maven/project/inheritance/ModelInheritanceAssembler.java b/maven-project/src/main/java/org/apache/maven/project/inheritance/ModelInheritanceAssembler.java
index 6f6f076bca..a2e3a7b329 100644
--- a/maven-project/src/main/java/org/apache/maven/project/inheritance/ModelInheritanceAssembler.java
+++ b/maven-project/src/main/java/org/apache/maven/project/inheritance/ModelInheritanceAssembler.java
@@ -30,13 +30,7 @@ public interface ModelInheritanceAssembler
{
String ROLE = ModelInheritanceAssembler.class.getName();
- void assembleModelInheritance( Model child, Model parent, String childPathAdjustment );
-
- void assembleModelInheritance( Model child, Model parent );
-
- void assembleBuildInheritance( Build childBuild,
- Build parentBuild,
- boolean handleAsInheriance );
+ void assembleBuildInheritance( Build childBuild, Build parentBuild, boolean handleAsInheriance );
void copyModel( Model dest, Model source );
}
diff --git a/maven-project/src/main/java/org/apache/maven/project/interpolation/ModelInterpolator.java b/maven-project/src/main/java/org/apache/maven/project/interpolation/ModelInterpolator.java
index f9795bfba9..83a6a5ff16 100644
--- a/maven-project/src/main/java/org/apache/maven/project/interpolation/ModelInterpolator.java
+++ b/maven-project/src/main/java/org/apache/maven/project/interpolation/ModelInterpolator.java
@@ -42,29 +42,20 @@ public interface ModelInterpolator
* @deprecated Use {@link ModelInterpolator#interpolate(Model, File, ProjectBuilderConfiguration, boolean)} instead.
*/
@Deprecated
- Model interpolate( Model project,
- Map context )
+ Model interpolate( Model project, Map context )
throws ModelInterpolationException;
/**
* @deprecated Use {@link ModelInterpolator#interpolate(Model, File, ProjectBuilderConfiguration, boolean)} instead.
*/
@Deprecated
- Model interpolate( Model model,
- Map context,
- boolean strict )
+ Model interpolate( Model model, Map context, boolean strict )
throws ModelInterpolationException;
- Model interpolate( Model model,
- File projectDir,
- ProjectBuilderConfiguration config,
- boolean debugEnabled )
+ Model interpolate( Model model, File projectDir, ProjectBuilderConfiguration config, boolean debugEnabled )
throws ModelInterpolationException;
- String interpolate( String src,
- Model model,
- File projectDir,
- ProjectBuilderConfiguration config,
+ String interpolate( String src, Model model, File projectDir, ProjectBuilderConfiguration config,
boolean debugEnabled )
throws ModelInterpolationException;
}
\ No newline at end of file
diff --git a/maven-project/src/main/java/org/apache/maven/project/interpolation/PathTranslatingPostProcessor.java b/maven-project/src/main/java/org/apache/maven/project/interpolation/PathTranslatingPostProcessor.java
index 9561942392..00efe48599 100644
--- a/maven-project/src/main/java/org/apache/maven/project/interpolation/PathTranslatingPostProcessor.java
+++ b/maven-project/src/main/java/org/apache/maven/project/interpolation/PathTranslatingPostProcessor.java
@@ -20,15 +20,12 @@ package org.apache.maven.project.interpolation;
*/
import org.apache.maven.project.path.PathTranslator;
-import org.codehaus.plexus.interpolation.AbstractFunctionValueSourceWrapper;
import org.codehaus.plexus.interpolation.InterpolationPostProcessor;
-import org.codehaus.plexus.interpolation.ValueSource;
import java.io.File;
import java.util.List;
/**
- *
* @version $Id: PathTranslatingPostProcessor.java 677447 2008-07-16 22:15:57Z jdcasey $
*/
public class PathTranslatingPostProcessor
@@ -36,7 +33,9 @@ public class PathTranslatingPostProcessor
{
private final List unprefixedPathKeys;
+
private final File projectDir;
+
private final PathTranslator pathTranslator;
public PathTranslatingPostProcessor( List unprefixedPathKeys, File projectDir, PathTranslator pathTranslator )
@@ -46,8 +45,7 @@ public class PathTranslatingPostProcessor
this.pathTranslator = pathTranslator;
}
- public Object execute( String expression,
- Object value )
+ public Object execute( String expression, Object value )
{
if ( projectDir != null && value != null && unprefixedPathKeys.contains( expression ) )
{
diff --git a/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java b/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java
index b2fb498a29..8d6750a166 100644
--- a/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java
+++ b/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java
@@ -61,7 +61,8 @@ public class RegexBasedModelInterpolator
implements ModelInterpolator
{
- private static final List PROJECT_PREFIXES = Arrays.asList( new String[]{ "pom.", "project." } );
+ private static final List PROJECT_PREFIXES = Arrays.asList( new String[]{"pom.", "project."} );
+
private static final List TRANSLATED_PATH_EXPRESSIONS;
static
@@ -88,7 +89,7 @@ public class RegexBasedModelInterpolator
throws IOException
{
}
-
+
// for testing.
protected RegexBasedModelInterpolator( PathTranslator pathTranslator )
{
@@ -101,9 +102,7 @@ public class RegexBasedModelInterpolator
Properties props = new Properties();
props.putAll( context );
- return interpolate( model,
- null,
- new DefaultProjectBuilderConfiguration().setExecutionProperties( props ),
+ return interpolate( model, null, new DefaultProjectBuilderConfiguration().setExecutionProperties( props ),
true );
}
@@ -113,9 +112,7 @@ public class RegexBasedModelInterpolator
Properties props = new Properties();
props.putAll( context );
- return interpolate( model,
- null,
- new DefaultProjectBuilderConfiguration().setExecutionProperties( props ),
+ return interpolate( model, null, new DefaultProjectBuilderConfiguration().setExecutionProperties( props ),
true );
}
@@ -125,14 +122,14 @@ public class RegexBasedModelInterpolator
*
* NOTE: This will result in a different instance of Model being returned!!!
*
- * @param model The inbound Model instance, to serialize and reference for expression resolution
- * @param context The other context map to be used during resolution
+ * @param model The inbound Model instance, to serialize and reference for expression resolution
+ * @param context The other context map to be used during resolution
* @param overrideContext The context map which should be used to OVERRIDE
* values from everything else. This will come from the CLI
* or userProperties in the execution request.
- * @param projectDir The directory from which the current model's pom was read.
- * @param strict This parameter is ignored!
- * @param debugMessages If true, print any feedback from the interpolator out to the DEBUG log-level.
+ * @param projectDir The directory from which the current model's pom was read.
+ * @param strict This parameter is ignored!
+ * @param debugMessages If true, print any feedback from the interpolator out to the DEBUG log-level.
* @return The resolved instance of the inbound Model. This is a different instance!
*/
public Model interpolate( Model model, File projectDir, ProjectBuilderConfiguration config, boolean debugMessages )
@@ -176,23 +173,21 @@ public class RegexBasedModelInterpolator
/**
* Interpolates all expressions in the src parameter.
- *
+ *
* The algorithm used for each expression is:
*
- *
If it starts with either "pom." or "project.", the expression is evaluated against the model.
- *
If the value is null, get the value from the context.
- *
If the value is null, but the context contains the expression, don't replace the expression string
- * with the value, and continue to find other expressions.
- *
If the value is null, get it from the model properties.
- *
+ *
If it starts with either "pom." or "project.", the expression is evaluated against the model.
+ *
If the value is null, get the value from the context.
+ *
If the value is null, but the context contains the expression, don't replace the expression string
+ * with the value, and continue to find other expressions.
+ *
If the value is null, get it from the model properties.
+ *
+ *
* @param overrideContext
* @param debugMessages
*/
- public String interpolate( String src,
- Model model,
- final File projectDir,
- ProjectBuilderConfiguration config,
- boolean debugMessages )
+ public String interpolate( String src, Model model, final File projectDir, ProjectBuilderConfiguration config,
+ boolean debugMessages )
throws ModelInterpolationException
{
Logger logger = getLogger();
@@ -208,7 +203,8 @@ public class RegexBasedModelInterpolator
ValueSource modelValueSource1 = new PrefixedObjectValueSource( PROJECT_PREFIXES, model, false );
ValueSource modelValueSource2 = new ObjectBasedValueSource( model );
- ValueSource basedirValueSource = new PrefixedValueSourceWrapper( new ValueSource(){
+ ValueSource basedirValueSource = new PrefixedValueSourceWrapper( new ValueSource()
+ {
public Object getValue( String expression )
{
if ( projectDir != null && "basedir".equals( expression ) )
@@ -218,8 +214,7 @@ public class RegexBasedModelInterpolator
return null;
}
- },
- PROJECT_PREFIXES, true );
+ }, PROJECT_PREFIXES, true );
RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
@@ -228,13 +223,14 @@ public class RegexBasedModelInterpolator
interpolator.addValueSource( new BuildTimestampValueSource( config.getBuildStartTime(), timestampFormat ) );
interpolator.addValueSource( new MapBasedValueSource( config.getExecutionProperties() ) );
interpolator.addValueSource( modelValueSource1 );
- interpolator.addValueSource( new PrefixedValueSourceWrapper( new MapBasedValueSource( modelProperties ), PROJECT_PREFIXES, true ) );
+ interpolator.addValueSource(
+ new PrefixedValueSourceWrapper( new MapBasedValueSource( modelProperties ), PROJECT_PREFIXES, true ) );
interpolator.addValueSource( modelValueSource2 );
interpolator.addValueSource( new MapBasedValueSource( config.getUserProperties() ) );
-
+
PathTranslatingPostProcessor pathTranslatingPostProcessor =
new PathTranslatingPostProcessor( TRANSLATED_PATH_EXPRESSIONS, projectDir, pathTranslator );
-
+
interpolator.addPostProcessor( pathTranslatingPostProcessor );
RecursionInterceptor recursionInterceptor = new PrefixAwareRecursionInterceptor( PROJECT_PREFIXES );
@@ -244,7 +240,7 @@ public class RegexBasedModelInterpolator
{
result = interpolator.interpolate( result, "", recursionInterceptor );
}
- catch( InterpolationException e )
+ catch ( InterpolationException e )
{
throw new ModelInterpolationException( e.getMessage(), e );
}
diff --git a/maven-project/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java b/maven-project/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java
index 710b941d1c..370e38e055 100644
--- a/maven-project/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java
+++ b/maven-project/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java
@@ -31,11 +31,7 @@ import java.util.List;
public class DefaultPathTranslator
implements PathTranslator
{
- private static final String[] BASEDIR_EXPRESSIONS = {
- "${basedir}",
- "${pom.basedir}",
- "${project.basedir}"
- };
+ private static final String[] BASEDIR_EXPRESSIONS = {"${basedir}", "${pom.basedir}", "${project.basedir}"};
private String FILE_SEPARATOR = "/";
diff --git a/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java b/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java
index 6c69aadc1c..01a650747d 100644
--- a/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java
+++ b/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java
@@ -63,14 +63,14 @@ public class DefaultModelValidator
if ( !model.getModules().isEmpty() && !"pom".equals( model.getPackaging() ) )
{
result.addMessage( "Packaging '" + model.getPackaging() + "' is invalid. Aggregator projects " +
- "require 'pom' as packaging." );
+ "require 'pom' as packaging." );
}
Parent parent = model.getParent();
if ( parent != null )
{
if ( parent.getGroupId().equals( model.getGroupId() ) &&
- parent.getArtifactId().equals( model.getArtifactId() ) )
+ parent.getArtifactId().equals( model.getArtifactId() ) )
{
result.addMessage( "The parent element cannot have the same ID as the project." );
}
@@ -88,7 +88,8 @@ public class DefaultModelValidator
validateStringNotEmpty( "dependencies.dependency.type", result, d.getType(), dependencySourceHint( d ) );
- validateStringNotEmpty( "dependencies.dependency.version", result, d.getVersion(), dependencySourceHint( d ) );
+ validateStringNotEmpty( "dependencies.dependency.version", result, d.getVersion(),
+ dependencySourceHint( d ) );
if ( Artifact.SCOPE_SYSTEM.equals( d.getScope() ) )
{
@@ -100,10 +101,10 @@ public class DefaultModelValidator
}
else
{
- if ( ! new File( systemPath ).isAbsolute() )
+ if ( !new File( systemPath ).isAbsolute() )
{
result.addMessage( "For dependency " + d + ": system-scoped dependency must " +
- "specify an absolute path systemPath." );
+ "specify an absolute path systemPath." );
}
}
}
@@ -133,14 +134,15 @@ public class DefaultModelValidator
if ( StringUtils.isEmpty( systemPath ) )
{
- result.addMessage( "For managed dependency " + d + ": system-scoped dependency must specify systemPath." );
+ result.addMessage(
+ "For managed dependency " + d + ": system-scoped dependency must specify systemPath." );
}
else
{
- if ( ! new File( systemPath ).isAbsolute() )
+ if ( !new File( systemPath ).isAbsolute() )
{
result.addMessage( "For managed dependency " + d + ": system-scoped dependency must " +
- "specify an absolute path systemPath." );
+ "specify an absolute path systemPath." );
}
}
}
@@ -258,7 +260,6 @@ public class DefaultModelValidator
}
}
-
// ----------------------------------------------------------------------
// Field validation
// ----------------------------------------------------------------------
@@ -289,7 +290,8 @@ public class DefaultModelValidator
*
string.length > 0
*
*/
- private boolean validateStringNotEmpty( String fieldName, ModelValidationResult result, String string, String sourceHint )
+ private boolean validateStringNotEmpty( String fieldName, ModelValidationResult result, String string,
+ String sourceHint )
{
if ( !validateNotNull( fieldName, result, string, sourceHint ) )
{
@@ -310,7 +312,6 @@ public class DefaultModelValidator
result.addMessage( "'" + fieldName + "' is missing." );
}
-
return false;
}
diff --git a/maven-project/src/main/java/org/apache/maven/project/workspace/DefaultProjectWorkspace.java b/maven-project/src/main/java/org/apache/maven/project/workspace/DefaultProjectWorkspace.java
index bf026234d1..90c790720a 100644
--- a/maven-project/src/main/java/org/apache/maven/project/workspace/DefaultProjectWorkspace.java
+++ b/maven-project/src/main/java/org/apache/maven/project/workspace/DefaultProjectWorkspace.java
@@ -1,9 +1,28 @@
package org.apache.maven.project.workspace;
+/*
+ * 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.
+ */
+
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.build.model.ModelAndFile;
+import org.apache.maven.project.ModelAndFile;
import org.apache.maven.workspace.MavenWorkspaceStore;
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
@@ -16,6 +35,7 @@ public class DefaultProjectWorkspace
{
private MavenWorkspaceStore workspaceStore;
+
private Logger logger;
public DefaultProjectWorkspace()
@@ -28,9 +48,7 @@ public class DefaultProjectWorkspace
this.logger = logger;
}
- public ModelAndFile getModelAndFile( String groupId,
- String artifactId,
- String version )
+ public ModelAndFile getModelAndFile( String groupId, String artifactId, String version )
{
Map cache = workspaceStore.getWorkspaceCache( ProjectWorkspace.MODEL_AND_FILE_BYGAV_KEY );
@@ -70,9 +88,7 @@ public class DefaultProjectWorkspace
return (MavenProject) cache.get( pathKey );
}
- public MavenProject getProject( String groupId,
- String artifactId,
- String version )
+ public MavenProject getProject( String groupId, String artifactId, String version )
{
Map cache = workspaceStore.getWorkspaceCache( ProjectWorkspace.PROJECT_INSTANCE_BYGAV_KEY );
@@ -131,7 +147,8 @@ public class DefaultProjectWorkspace
public void storeProjectByFile( MavenProject project )
{
- if ( project.getFile() == null ){
+ if ( project.getFile() == null )
+ {
return;
}
diff --git a/maven-project/src/main/java/org/apache/maven/project/workspace/ProjectWorkspace.java b/maven-project/src/main/java/org/apache/maven/project/workspace/ProjectWorkspace.java
index ddbc4fe1f0..2a3e696980 100644
--- a/maven-project/src/main/java/org/apache/maven/project/workspace/ProjectWorkspace.java
+++ b/maven-project/src/main/java/org/apache/maven/project/workspace/ProjectWorkspace.java
@@ -1,7 +1,26 @@
package org.apache.maven.project.workspace;
+/*
+ * 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.
+ */
+
import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.build.model.ModelAndFile;
+import org.apache.maven.project.ModelAndFile;
import java.io.File;
diff --git a/maven-project/src/main/java/org/apache/maven/realm/DefaultMavenRealmManager.java b/maven-project/src/main/java/org/apache/maven/realm/DefaultMavenRealmManager.java
index 6b3eaf8f59..30191a7a85 100644
--- a/maven-project/src/main/java/org/apache/maven/realm/DefaultMavenRealmManager.java
+++ b/maven-project/src/main/java/org/apache/maven/realm/DefaultMavenRealmManager.java
@@ -50,14 +50,16 @@ public class DefaultMavenRealmManager
{
private Map pluginArtifacts = new HashMap();
+
private Set managedRealmIds = new HashSet();
private final ClassWorld world;
+
private final PlexusContainer container;
+
private final Logger logger;
- public DefaultMavenRealmManager( PlexusContainer container,
- Logger logger )
+ public DefaultMavenRealmManager( PlexusContainer container, Logger logger )
{
world = container.getContainerRealm().getWorld();
this.container = container;
@@ -114,8 +116,7 @@ public class DefaultMavenRealmManager
}
}
- public ClassRealm createExtensionRealm( Artifact extensionArtifact,
- List artifacts )
+ public ClassRealm createExtensionRealm( Artifact extensionArtifact, List artifacts )
throws RealmManagementException
{
String id = RealmUtils.createExtensionRealmId( extensionArtifact );
@@ -127,8 +128,7 @@ public class DefaultMavenRealmManager
}
catch ( DuplicateRealmException e )
{
- throw new RealmManagementException( id, "Extension realm: " + id + " already exists.",
- e );
+ throw new RealmManagementException( id, "Extension realm: " + id + " already exists.", e );
}
populateRealm( id, realm, extensionArtifact, artifacts, null );
@@ -136,24 +136,25 @@ public class DefaultMavenRealmManager
return realm;
}
- public void importExtensionsIntoProjectRealm( String projectGroupId,
- String projectArtifactId,
- String projectVersion,
- Artifact extensionArtifact )
+ public void importExtensionsIntoProjectRealm( String projectGroupId, String projectArtifactId,
+ String projectVersion, Artifact extensionArtifact )
throws RealmManagementException
{
String extensionRealmId = RealmUtils.createExtensionRealmId( extensionArtifact );
if ( extensionArtifact.getFile() == null )
{
- throw new RealmManagementException( extensionRealmId, "Cannot import project extensions; extension artifact has no associated file that can be scanned for extension components (extension: " + extensionArtifact.getId() + ")" );
+ throw new RealmManagementException( extensionRealmId,
+ "Cannot import project extensions; extension artifact has no associated file that can be scanned for extension components (extension: " +
+ extensionArtifact.getId() + ")" );
}
-
ComponentDiscoverer discoverer = new DefaultComponentDiscoverer();
discoverer.setManager( RealmScanningUtils.getDummyComponentDiscovererManager() );
- List componentSetDescriptors = RealmScanningUtils.scanForComponentSetDescriptors( extensionArtifact, discoverer, container.getContext(), extensionRealmId );
+ List componentSetDescriptors = RealmScanningUtils.scanForComponentSetDescriptors( extensionArtifact, discoverer,
+ container.getContext(),
+ extensionRealmId );
ClassRealm realm = getProjectRealm( projectGroupId, projectArtifactId, projectVersion, true );
@@ -168,7 +169,9 @@ public class DefaultMavenRealmManager
try
{
- logger.debug( "Importing: " + implementation + "\nwith role: " + comp.getRole() + "\nand hint: " + comp.getRoleHint() + "\nfrom extension realm: " + extensionRealmId + "\nto project realm: " + realm.getId() );
+ logger.debug( "Importing: " + implementation + "\nwith role: " + comp.getRole() + "\nand hint: " +
+ comp.getRoleHint() + "\nfrom extension realm: " + extensionRealmId + "\nto project realm: " +
+ realm.getId() );
// Import the extension component's implementation class into the project-level
// realm.
@@ -187,12 +190,17 @@ public class DefaultMavenRealmManager
}
catch ( NoSuchRealmException e )
{
- throw new RealmManagementException( extensionRealmId, "Failed to create import for component: " + implementation + " from extension realm: " + extensionRealmId + " to project realm: " + realm.getId(), e );
+ throw new RealmManagementException( extensionRealmId, "Failed to create import for component: " +
+ implementation + " from extension realm: " + extensionRealmId + " to project realm: " +
+ realm.getId(), e );
}
catch ( ComponentRepositoryException e )
{
String projectId = RealmUtils.createProjectId( projectGroupId, projectArtifactId, projectVersion );
- throw new RealmManagementException( extensionRealmId, "Unable to discover components from imports to project: " + projectId + " from extension artifact: " + extensionArtifact.getId(), e );
+ throw new RealmManagementException( extensionRealmId,
+ "Unable to discover components from imports to project: " +
+ projectId + " from extension artifact: " +
+ extensionArtifact.getId(), e );
}
}
}
@@ -203,7 +211,8 @@ public class DefaultMavenRealmManager
return getProjectRealm( projectGroupId, projectArtifactId, projectVersion, false );
}
- private ClassRealm getProjectRealm( String projectGroupId, String projectArtifactId, String projectVersion, boolean create )
+ private ClassRealm getProjectRealm( String projectGroupId, String projectArtifactId, String projectVersion,
+ boolean create )
{
String id = RealmUtils.createProjectId( projectGroupId, projectArtifactId, projectVersion );
@@ -266,10 +275,8 @@ public class DefaultMavenRealmManager
pluginArtifacts.remove( id );
}
- public ClassRealm createPluginRealm( Plugin plugin,
- Artifact pluginArtifact,
- List artifacts,
- ArtifactFilter coreArtifactFilter )
+ public ClassRealm createPluginRealm( Plugin plugin, Artifact pluginArtifact, List artifacts,
+ ArtifactFilter coreArtifactFilter )
throws RealmManagementException
{
String id = RealmUtils.createPluginRealmId( plugin );
@@ -284,8 +291,7 @@ public class DefaultMavenRealmManager
}
catch ( DuplicateRealmException e )
{
- throw new RealmManagementException( id, "Plugin realm: " + id + " already exists.",
- e );
+ throw new RealmManagementException( id, "Plugin realm: " + id + " already exists.", e );
}
populateRealm( id, realm, pluginArtifact, artifacts, coreArtifactFilter );
@@ -296,10 +302,7 @@ public class DefaultMavenRealmManager
return realm;
}
- private void populateRealm( String id,
- ClassRealm realm,
- Artifact mainArtifact,
- List artifacts,
+ private void populateRealm( String id, ClassRealm realm, Artifact mainArtifact, List artifacts,
ArtifactFilter coreArtifactFilter )
throws RealmManagementException
{
@@ -311,10 +314,8 @@ public class DefaultMavenRealmManager
}
catch ( MalformedURLException e )
{
- throw new RealmManagementException( id, mainArtifact, "Invalid URL for artifact file: "
- + mainArtifact.getFile()
- + " to be used in realm: " + id
- + ".", e );
+ throw new RealmManagementException( id, mainArtifact, "Invalid URL for artifact file: " +
+ mainArtifact.getFile() + " to be used in realm: " + id + ".", e );
}
}
@@ -330,15 +331,14 @@ public class DefaultMavenRealmManager
}
catch ( MalformedURLException e )
{
- throw new RealmManagementException( id, artifact, "Invalid URL for artifact file: "
- + artifact.getFile()
- + " to be used in realm: " + id
- + ".", e );
+ throw new RealmManagementException( id, artifact, "Invalid URL for artifact file: " +
+ artifact.getFile() + " to be used in realm: " + id + ".", e );
}
}
else
{
- logger.debug( "Excluding artifact: " + artifact.getArtifactId() + " from plugin realm; it's already included in Maven's core." );
+ logger.debug( "Excluding artifact: " + artifact.getArtifactId() +
+ " from plugin realm; it's already included in Maven's core." );
}
}
}
@@ -361,8 +361,7 @@ public class DefaultMavenRealmManager
return null;
}
- public void setPluginArtifacts( Plugin plugin,
- List artifacts )
+ public void setPluginArtifacts( Plugin plugin, List artifacts )
{
String id = RealmUtils.createPluginRealmId( plugin );
diff --git a/maven-project/src/main/java/org/apache/maven/realm/MavenRealmManager.java b/maven-project/src/main/java/org/apache/maven/realm/MavenRealmManager.java
index e735c6e43e..5ce1aebf1b 100644
--- a/maven-project/src/main/java/org/apache/maven/realm/MavenRealmManager.java
+++ b/maven-project/src/main/java/org/apache/maven/realm/MavenRealmManager.java
@@ -14,32 +14,24 @@ public interface MavenRealmManager
boolean hasExtensionRealm( Artifact extensionArtifact );
- ClassRealm createExtensionRealm( Artifact extensionArtifact,
- List artifacts )
+ ClassRealm createExtensionRealm( Artifact extensionArtifact, List artifacts )
throws RealmManagementException;
- void importExtensionsIntoProjectRealm( String projectGroupId,
- String projectArtifactId,
- String projectVersion,
+ void importExtensionsIntoProjectRealm( String projectGroupId, String projectArtifactId, String projectVersion,
Artifact extensionArtifact )
throws RealmManagementException;
- ClassRealm getProjectRealm( String groupId,
- String artifactId,
- String version );
+ ClassRealm getProjectRealm( String groupId, String artifactId, String version );
ClassRealm getPluginRealm( Plugin plugin );
List getPluginArtifacts( Plugin plugin );
- ClassRealm createPluginRealm( Plugin plugin,
- Artifact pluginArtifact,
- List artifacts,
+ ClassRealm createPluginRealm( Plugin plugin, Artifact pluginArtifact, List artifacts,
ArtifactFilter coreArtifactFilter )
throws RealmManagementException;
void disposePluginRealm( Plugin plugin );
- void setPluginArtifacts( Plugin plugin,
- List artifacts );
+ void setPluginArtifacts( Plugin plugin, List artifacts );
}
diff --git a/maven-project/src/main/java/org/apache/maven/realm/RealmManagementException.java b/maven-project/src/main/java/org/apache/maven/realm/RealmManagementException.java
index 06586710d1..0617292546 100644
--- a/maven-project/src/main/java/org/apache/maven/realm/RealmManagementException.java
+++ b/maven-project/src/main/java/org/apache/maven/realm/RealmManagementException.java
@@ -13,8 +13,11 @@ public class RealmManagementException
{
private final String realmId;
+
private String offendingGroupId;
+
private String offendingArtifactId;
+
private String offendingVersion;
public RealmManagementException( String realmId, String message, DuplicateRealmException cause )
@@ -23,7 +26,8 @@ public class RealmManagementException
this.realmId = realmId;
}
- public RealmManagementException( String realmId, Artifact offendingArtifact, String message, MalformedURLException cause )
+ public RealmManagementException( String realmId, Artifact offendingArtifact, String message,
+ MalformedURLException cause )
{
super( message, cause );
this.realmId = realmId;
@@ -32,25 +36,19 @@ public class RealmManagementException
offendingVersion = offendingArtifact.getVersion();
}
- public RealmManagementException( String realmId,
- String message,
- NoSuchRealmException cause )
+ public RealmManagementException( String realmId, String message, NoSuchRealmException cause )
{
super( message, cause );
this.realmId = realmId;
}
- public RealmManagementException( String realmId,
- String message,
- ComponentRepositoryException cause )
+ public RealmManagementException( String realmId, String message, ComponentRepositoryException cause )
{
super( message, cause );
this.realmId = realmId;
}
- public RealmManagementException( String realmId,
- String message,
- PlexusConfigurationException cause )
+ public RealmManagementException( String realmId, String message, PlexusConfigurationException cause )
{
super( message, cause );
this.realmId = realmId;
diff --git a/maven-project/src/main/java/org/apache/maven/realm/RealmScanningUtils.java b/maven-project/src/main/java/org/apache/maven/realm/RealmScanningUtils.java
index 4360c0cb5f..55cb10ae53 100644
--- a/maven-project/src/main/java/org/apache/maven/realm/RealmScanningUtils.java
+++ b/maven-project/src/main/java/org/apache/maven/realm/RealmScanningUtils.java
@@ -23,10 +23,8 @@ public class RealmScanningUtils
private static final String DISCOVERY_REALM_ID = "discovery realm";
- public static List scanForComponentSetDescriptors( Artifact artifact,
- ComponentDiscoverer discoverer,
- Context context,
- String discoveryContextId )
+ public static List scanForComponentSetDescriptors( Artifact artifact, ComponentDiscoverer discoverer,
+ Context context, String discoveryContextId )
throws RealmManagementException
{
ClassWorld discoveryWorld = new ClassWorld();
@@ -44,7 +42,9 @@ public class RealmScanningUtils
}
catch ( DuplicateRealmException e )
{
- throw new RealmManagementException( discoveryContextId, "Unable to create temporary ClassRealm for local-component discovery.", e );
+ throw new RealmManagementException( discoveryContextId,
+ "Unable to create temporary ClassRealm for local-component discovery.",
+ e );
}
try
@@ -53,7 +53,9 @@ public class RealmScanningUtils
}
catch ( MalformedURLException e )
{
- throw new RealmManagementException( discoveryContextId, artifact, "Unable to generate URL from artifact file: " + artifact.getFile() + " for local-component discovery.", e );
+ throw new RealmManagementException( discoveryContextId, artifact,
+ "Unable to generate URL from artifact file: " + artifact.getFile() +
+ " for local-component discovery.", e );
}
try
@@ -65,7 +67,9 @@ public class RealmScanningUtils
}
catch ( PlexusConfigurationException e )
{
- throw new RealmManagementException( discoveryContextId, "Unable to discover components in artifact: " + artifact.getId(), e );
+ throw new RealmManagementException( discoveryContextId,
+ "Unable to discover components in artifact: " + artifact.getId(),
+ e );
}
}
finally
@@ -92,7 +96,8 @@ public class RealmScanningUtils
return new DummyDiscovererManager();
}
- private static final class DummyDiscovererManager implements ComponentDiscovererManager
+ private static final class DummyDiscovererManager
+ implements ComponentDiscovererManager
{
public void fireComponentDiscoveryEvent( ComponentDiscoveryEvent arg0 )
diff --git a/maven-project/src/main/java/org/apache/maven/realm/RealmUtils.java b/maven-project/src/main/java/org/apache/maven/realm/RealmUtils.java
index 9de80cc634..c1082824c0 100644
--- a/maven-project/src/main/java/org/apache/maven/realm/RealmUtils.java
+++ b/maven-project/src/main/java/org/apache/maven/realm/RealmUtils.java
@@ -36,27 +36,25 @@ public final class RealmUtils
public static String createExtensionRealmId( Artifact extensionArtifact )
{
- return "/extensions/" + extensionArtifact.getGroupId() + ":"
- + extensionArtifact.getArtifactId() + ":" + extensionArtifact.getVersion() +
- "/thread:" + Thread.currentThread().getName(); //add thread to the mix to prevent clashes in paralel execution
+ return "/extensions/" + extensionArtifact.getGroupId() + ":" + extensionArtifact.getArtifactId() + ":" +
+ extensionArtifact.getVersion() + "/thread:" +
+ Thread.currentThread().getName(); //add thread to the mix to prevent clashes in paralel execution
}
- public static String createProjectId( String projectGroupId,
- String projectArtifactId,
- String projectVersion )
+ public static String createProjectId( String projectGroupId, String projectArtifactId, String projectVersion )
{
- return "/projects/" + projectGroupId + ":" + projectArtifactId + ":" + projectVersion +
- "/thread:" + Thread.currentThread().getName(); //add thread to the mix to prevent clashes in paralel execution
+ return "/projects/" + projectGroupId + ":" + projectArtifactId + ":" + projectVersion + "/thread:" +
+ Thread.currentThread().getName(); //add thread to the mix to prevent clashes in paralel execution
}
public static String createPluginRealmId( Plugin plugin )
{
StringBuffer id = new StringBuffer().append( "/plugins/" )
- .append( plugin.getGroupId() )
- .append( ':' )
- .append( plugin.getArtifactId() )
- .append( ':' )
- .append( plugin.getVersion() );
+ .append( plugin.getGroupId() )
+ .append( ':' )
+ .append( plugin.getArtifactId() )
+ .append( ':' )
+ .append( plugin.getVersion() );
StringBuffer depId = new StringBuffer();
@@ -70,10 +68,10 @@ public final class RealmUtils
Dependency dep = (Dependency) it.next();
depId.append( dep.getGroupId() )
- .append( ':' )
- .append( dep.getArtifactId() )
- .append( ';' )
- .append( dep.getVersion() );
+ .append( ':' )
+ .append( dep.getArtifactId() )
+ .append( ';' )
+ .append( dep.getVersion() );
if ( it.hasNext() )
{
@@ -87,7 +85,8 @@ public final class RealmUtils
}
id.append( '@' ).append( depId.toString().hashCode() )
- .append( "/thread:" ).append( Thread.currentThread().getName() ); //add thread to the mix to prevent clashes in paralel execution
+ .append( "/thread:" ).append(
+ Thread.currentThread().getName() ); //add thread to the mix to prevent clashes in paralel execution
return id.toString();
}
diff --git a/maven-project/src/main/resources/META-INF/plexus/components.xml b/maven-project/src/main/resources/META-INF/plexus/components.xml
index 3728658765..efdc4fdf62 100644
--- a/maven-project/src/main/resources/META-INF/plexus/components.xml
+++ b/maven-project/src/main/resources/META-INF/plexus/components.xml
@@ -36,29 +36,6 @@ under the License.
-
- org.apache.maven.project.build.model.ModelLineageBuilder
- default
- org.apache.maven.project.build.model.DefaultModelLineageBuilder
-
-
- org.apache.maven.project.workspace.ProjectWorkspace
-
-
- org.apache.maven.profiles.build.ProfileAdvisor
- default
-
-
- org.apache.maven.artifact.factory.ArtifactFactory
-
-
- org.apache.maven.MavenTools
-
-
- org.apache.maven.artifact.resolver.ArtifactResolver
-
-
-
-
- org.apache.maven.project.injection.ModelDefaultsInjector
- org.apache.maven.project.injection.DefaultModelDefaultsInjector
-
+
+
+ org.apache.maven.project.RepositoryHelper
+ org.apache.maven.project.DefaultRepositoryHelper
+
+
+ org.apache.maven.profiles.build.ProfileAdvisor
+
+
+ org.apache.maven.artifact.factory.ArtifactFactory
+
+
+ org.apache.maven.artifact.resolver.ArtifactResolver
+ default
+
+
+ org.apache.maven.MavenTools
+
+
+
p0 --> super model
- //
- // ----------------------------------------------------------------------
-
- public void testDependencyManagementImportsVersions() throws Exception
- {
- File localRepo = getLocalRepositoryPath();
-
- File pom0 = new File( localRepo, "p0/pom.xml" );
- File pom0Basedir = pom0.getParentFile();
- System.out.println("basedir " + pom0Basedir.getAbsolutePath());
- File pom1 = new File( pom0Basedir, "p1/pom.xml" );
- File pom2 = new File( pom0Basedir, "p2/pom.xml" );
- File pom3 = new File( pom0Basedir, "p3/pom.xml" );
- File pom4 = new File( pom0Basedir, "p4/pom.xml" );
-
- getProjectWithDependencies( pom0 );
- // load the child project, which inherits from p0...
- // MavenProject project0 = getProjectWithDependencies( pom0 );
- MavenProject project1 = getProjectWithDependencies( pom1 );
-
- assertEquals( pom0Basedir, project1.getParent().getBasedir().getCanonicalFile() );
-
- Map map = project1.getArtifactMap();
- assertNotNull("No artifacts", map);
- assertTrue("No Artifacts", map.size() > 0);
- assertTrue("Set size should be 2, is " + map.size(), map.size() == 2);
-
- Artifact a = (Artifact) map.get("maven-test:maven-test-a");
- Artifact b = (Artifact) map.get("maven-test:maven-test-b");
-
- assertTrue("Incorrect version for " + a.getDependencyConflictId(), a.getVersion().equals("1.0"));
- assertTrue("Incorrect version for " + b.getDependencyConflictId(), b.getVersion().equals("1.0"));
-
- // load the child project, which inherits from p0...
- // MavenProject project0 = getProjectWithDependencies( pom0 );
- MavenProject project2 = getProjectWithDependencies( pom2 );
-
- map = project2.getArtifactMap();
- assertNotNull("No artifacts", map);
- assertTrue("No Artifacts", map.size() > 0);
- assertTrue("Set size should be 3, is " + map.size(), map.size() == 3);
-
- a = (Artifact) map.get("maven-test:maven-test-a");
- b = (Artifact) map.get("maven-test:maven-test-b");
- Artifact c = (Artifact) map.get("maven-test:maven-test-c");
-
- assertTrue("Incorrect version for " + a.getDependencyConflictId(), a.getVersion().equals("1.0"));
- assertTrue("Incorrect version for " + b.getDependencyConflictId(), b.getVersion().equals("1.0"));
- assertTrue("Incorrect version for " + c.getDependencyConflictId(), c.getVersion().equals("1.0"));
-
- // load the child project, which inherits from p0...
- // MavenProject project0 = getProjectWithDependencies( pom0 );
- MavenProject project3 = getProjectWithDependencies( pom3 );
-
- map = project3.getArtifactMap();
- assertNotNull("No artifacts", map);
- assertTrue("No Artifacts", map.size() > 0);
- assertTrue("Set size should be 3, is " + map.size(), map.size() == 3);
-
- a = (Artifact) map.get("maven-test:maven-test-a");
- c = (Artifact) map.get("maven-test:maven-test-c");
- Artifact d = (Artifact) map.get("maven-test:maven-test-d");
-
- assertTrue("Incorrect version for " + a.getDependencyConflictId(), a.getVersion().equals("1.1"));
- assertTrue("Incorrect version for " + c.getDependencyConflictId(), c.getVersion().equals("1.1"));
- assertTrue("Incorrect version for " + d.getDependencyConflictId(), d.getVersion().equals("1.0"));
-
- // load the child project, which inherits from p0...
- // MavenProject project0 = getProjectWithDependencies( pom0 );
- MavenProject project4 = getProjectWithDependencies( pom4 );
-
- map = project4.getArtifactMap();
- assertNotNull("No artifacts", map);
- assertTrue("No Artifacts", map.size() > 0);
- assertTrue("Set size should be 4, is " + map.size(), map.size() == 4);
-
- a = (Artifact) map.get("maven-test:maven-test-a");
- b = (Artifact) map.get("maven-test:maven-test-b");
- c = (Artifact) map.get("maven-test:maven-test-c");
- d = (Artifact) map.get("maven-test:maven-test-d");
-
- assertTrue("Incorrect version for " + a.getDependencyConflictId(), a.getVersion().equals("1.0"));
- assertTrue("Incorrect version for " + b.getDependencyConflictId(), b.getVersion().equals("1.1"));
- assertTrue("Incorrect version for " + c.getDependencyConflictId(), c.getVersion().equals("1.0"));
- assertTrue("Incorrect version for " + d.getDependencyConflictId(), d.getVersion().equals("1.0"));
- }
-}
\ No newline at end of file
diff --git a/maven-project/src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java b/maven-project/src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java
deleted file mode 100644
index 7d286b51db..0000000000
--- a/maven-project/src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java
+++ /dev/null
@@ -1,1101 +0,0 @@
-package org.apache.maven.project.inheritance;
-
-/*
- * 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.
- */
-
-import org.apache.maven.model.Build;
-import org.apache.maven.model.Dependency;
-import org.apache.maven.model.DependencyManagement;
-import org.apache.maven.model.DeploymentRepository;
-import org.apache.maven.model.DistributionManagement;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.Parent;
-import org.apache.maven.model.Plugin;
-import org.apache.maven.model.PluginExecution;
-import org.apache.maven.model.Relocation;
-import org.apache.maven.model.ReportPlugin;
-import org.apache.maven.model.ReportSet;
-import org.apache.maven.model.Reporting;
-import org.apache.maven.model.Repository;
-import org.apache.maven.model.RepositoryBase;
-import org.apache.maven.model.Resource;
-import org.apache.maven.model.Scm;
-import org.apache.maven.model.Site;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-/**
- * @author jdcasey
- */
-public class DefaultModelInheritanceAssemblerTest
- extends TestCase
-{
- private ModelInheritanceAssembler assembler = new DefaultModelInheritanceAssembler();
-
- public void testShouldAdjustChildUrlBasedOnParentAndModulePathInSiblingDir()
- {
- Model parent = makeBaseModel( "parent" );
-
- parent.setUrl( "http://www.google.com/parent" );
-
- Model child = makeBaseModel( "child" );
-
- // TODO: this is probably what we should be appending...
-// child.setUrl( "/child.dir" );
-
- parent.addModule( "../child" );
-
- assembler.assembleModelInheritance( child, parent, ".." );
-
- String resultingUrl = child.getUrl();
-
- System.out.println( resultingUrl );
-
- assertEquals( "http://www.google.com/child", resultingUrl );
- }
-
- public void testShouldAdjustPathsThreeLevelsDeepAncestryInRepoAndNonStandardModulePaths()
- {
- Model top = makeBaseModel( "top" );
-
- top.setUrl( "http://www.google.com/top" );
-
- Model middle = makeBaseModel( "middle" );
-
- top.addModule( "../middle" );
-
- Model bottom = makeBaseModel( "bottom" );
-
- middle.addModule( "../bottom" );
-
- assembler.assembleModelInheritance( middle, top, ".." );
- assembler.assembleModelInheritance( bottom, middle, ".." );
-
- String resultingUrl = bottom.getUrl();
-
- System.out.println( resultingUrl );
-
- assertEquals( "http://www.google.com/bottom", resultingUrl );
- }
-
- public void testShouldMergeSuccessiveDependencyManagementSectionsOverThreeLevels()
- {
- Model top = makeBaseModel( "top" );
-
- DependencyManagement topMgmt = new DependencyManagement();
-
- topMgmt.addDependency( makeDep( "top-dep" ) );
-
- top.setDependencyManagement( topMgmt );
-
- Model mid = makeBaseModel( "mid" );
-
- DependencyManagement midMgmt = new DependencyManagement();
-
- midMgmt.addDependency( makeDep( "mid-dep" ) );
-
- mid.setDependencyManagement( midMgmt );
-
- Model bottom = makeBaseModel( "bottom" );
-
- DependencyManagement bottomMgmt = new DependencyManagement();
-
- bottomMgmt.addDependency( makeDep( "bottom-dep" ) );
-
- bottom.setDependencyManagement( bottomMgmt );
-
- assembler.assembleModelInheritance( mid, top );
-
- assembler.assembleModelInheritance( bottom, mid );
-
- DependencyManagement result = bottom.getDependencyManagement();
-
- List resultDeps = result.getDependencies();
-
- assertEquals( 3, resultDeps.size() );
- }
-
- public void testShouldMergeDependencyManagementSectionsFromTopTwoLevelsToBottomLevel()
- {
- Model top = makeBaseModel( "top" );
-
- DependencyManagement topMgmt = new DependencyManagement();
-
- topMgmt.addDependency( makeDep( "top-dep" ) );
-
- top.setDependencyManagement( topMgmt );
-
- Model mid = makeBaseModel( "mid" );
-
- DependencyManagement midMgmt = new DependencyManagement();
-
- midMgmt.addDependency( makeDep( "mid-dep" ) );
-
- mid.setDependencyManagement( midMgmt );
-
- Model bottom = makeBaseModel( "bottom" );
-
- assembler.assembleModelInheritance( mid, top );
-
- assembler.assembleModelInheritance( bottom, mid );
-
- DependencyManagement result = bottom.getDependencyManagement();
-
- List resultDeps = result.getDependencies();
-
- assertEquals( 2, resultDeps.size() );
- }
-
- private Dependency makeDep( String artifactId )
- {
- Dependency dep = new Dependency();
-
- dep.setGroupId( "maven" );
- dep.setArtifactId( artifactId );
- dep.setVersion( "1.0" );
-
- return dep;
- }
-
- public void testShouldAppendChildPathAdjustmentWithNoChildPartAndNoParentPart()
- {
- String parentPath = "";
- String childPath = null;
- String pathAdjustment = "../file-management";
-
- String result =
- ( (DefaultModelInheritanceAssembler) assembler ).appendPath( parentPath, childPath, pathAdjustment, true );
-
- System.out.println( "Resulting path is: \'" + result + "\'" );
-
- assertEquals( "Append with path adjustment failed.", "/file-management", result );
- }
-
- public void testShouldAppendChildPathAdjustmentWithNoChildPart()
- {
- String parentPath = "http://maven.apache.org/shared/maven-shared-parent";
- String childPath = null;
- String pathAdjustment = "../file-management";
-
- String result =
- ( (DefaultModelInheritanceAssembler) assembler ).appendPath( parentPath, childPath, pathAdjustment, true );
-
- System.out.println( "Resulting path is: \'" + result + "\'" );
-
- assertEquals( "Append with path adjustment failed.", "http://maven.apache.org/shared/file-management", result );
- }
-
- public void testShouldAppendPathWithChildPathAdjustment()
- {
- String parentPath = "http://maven.apache.org/shared/maven-shared-parent";
- String childPath = "file-management";
- String pathAdjustment = "..";
-
- String result =
- ( (DefaultModelInheritanceAssembler) assembler ).appendPath( parentPath, childPath, pathAdjustment, true );
-
- System.out.println( "Resulting path is: \'" + result + "\'" );
-
- assertEquals( "Append with path adjustment failed.", "http://maven.apache.org/shared/file-management", result );
- }
-
- public void testDistributionManagementInheritance()
- {
- Model parent = makeBaseModel( "parent" );
- Model child = makeBaseModel( "child" );
-
- DistributionManagement distributionManagement = new DistributionManagement();
- distributionManagement.setDownloadUrl( "downloadUrl" );
- distributionManagement.setRelocation( new Relocation() );
- distributionManagement.setStatus( "deployed" );
-
- DeploymentRepository repository = new DeploymentRepository();
- repository.setId( "apache.releases" );
- repository.setUrl( "scp://minotaur.apache.org/www/www.apache.org/dist/java-repository" );
- repository.setName( "name" );
- repository.setLayout( "legacy" );
- distributionManagement.setRepository( repository );
-
- DeploymentRepository snapshotRepository = new DeploymentRepository();
- snapshotRepository.setId( "apache.snapshots" );
- snapshotRepository.setUrl( "scp://minotaur.apache.org/www/cvs.apache.org/repository" );
- snapshotRepository.setName( "name" );
- snapshotRepository.setLayout( "legacy" );
- snapshotRepository.setUniqueVersion( false );
- distributionManagement.setSnapshotRepository( snapshotRepository );
-
- Site site = new Site();
- site.setId( "apache.website" );
- site.setUrl( "scp://minotaur.apache.org/www/maven.apache.org/" );
- site.setName( "name3" );
- distributionManagement.setSite( site );
-
- parent.setDistributionManagement( distributionManagement );
-
- assembler.assembleModelInheritance( child, parent );
-
- DistributionManagement childDistMgmt = child.getDistributionManagement();
- assertNotNull( "Check distMgmt inherited", childDistMgmt );
- assertNull( "Check status NOT inherited", childDistMgmt.getStatus() );
- assertNull( "Check relocation NOT inherited", childDistMgmt.getRelocation() );
- assertEquals( "Check downloadUrl inherited", distributionManagement.getDownloadUrl(),
- childDistMgmt.getDownloadUrl() );
-
- Site childSite = childDistMgmt.getSite();
- assertNotNull( "Check site inherited", childSite );
- assertEquals( "Check id matches", site.getId(), childSite.getId() );
- assertEquals( "Check name matches", site.getName(), childSite.getName() );
- assertEquals( "Check url matches with appended path", site.getUrl() + "child", childSite.getUrl() );
-
- assertRepositoryBase( childDistMgmt.getRepository(), repository );
- assertRepositoryBase( childDistMgmt.getSnapshotRepository(), snapshotRepository );
- assertEquals( "Check uniqueVersion is inherited", snapshotRepository.isUniqueVersion(),
- childDistMgmt.getSnapshotRepository().isUniqueVersion() );
- }
-
- public void testThreeLevelDistributionManagementInheritance()
- {
- Model gpar = makeBaseModel( "gpar" );
- Model parent = makeBaseModel( "parent" );
- Model child = makeBaseModel( "child" );
-
- DistributionManagement distributionManagement = new DistributionManagement();
- distributionManagement.setDownloadUrl( "downloadUrl" );
- distributionManagement.setRelocation( new Relocation() );
- distributionManagement.setStatus( "deployed" );
-
- DeploymentRepository repository = new DeploymentRepository();
- repository.setId( "apache.releases" );
- repository.setUrl( "scp://minotaur.apache.org/www/www.apache.org/dist/java-repository" );
- repository.setName( "name" );
- repository.setLayout( "legacy" );
- distributionManagement.setRepository( repository );
-
- DeploymentRepository snapshotRepository = new DeploymentRepository();
- snapshotRepository.setId( "apache.snapshots" );
- snapshotRepository.setUrl( "scp://minotaur.apache.org/www/cvs.apache.org/repository" );
- snapshotRepository.setName( "name" );
- snapshotRepository.setLayout( "legacy" );
- snapshotRepository.setUniqueVersion( false );
- distributionManagement.setSnapshotRepository( snapshotRepository );
-
- Site site = new Site();
- site.setId( "apache.website" );
- site.setUrl( "scp://minotaur.apache.org/www/maven.apache.org/" );
- site.setName( "name3" );
- distributionManagement.setSite( site );
-
- gpar.setDistributionManagement( distributionManagement );
-
- assembler.assembleModelInheritance( parent, gpar );
- assembler.assembleModelInheritance( child, parent );
-
- DistributionManagement childDistMgmt = child.getDistributionManagement();
- assertNotNull( "Check distMgmt inherited", childDistMgmt );
- assertNull( "Check status NOT inherited", childDistMgmt.getStatus() );
- assertNull( "Check relocation NOT inherited", childDistMgmt.getRelocation() );
- assertEquals( "Check downloadUrl inherited", distributionManagement.getDownloadUrl(),
- childDistMgmt.getDownloadUrl() );
-
- Site childSite = childDistMgmt.getSite();
- assertNotNull( "Check site inherited", childSite );
- assertEquals( "Check id matches", site.getId(), childSite.getId() );
- assertEquals( "Check name matches", site.getName(), childSite.getName() );
- assertEquals( "Check url matches with appended path", site.getUrl() + "parent/child", childSite.getUrl() );
-
- assertRepositoryBase( childDistMgmt.getRepository(), repository );
- assertRepositoryBase( childDistMgmt.getSnapshotRepository(), snapshotRepository );
- assertEquals( "Check uniqueVersion is inherited", snapshotRepository.isUniqueVersion(),
- childDistMgmt.getSnapshotRepository().isUniqueVersion() );
- }
-
- private static void assertRepositoryBase( RepositoryBase childRepository, RepositoryBase repository )
- {
- assertNotNull( "Check repository inherited", childRepository );
- assertEquals( "Check id matches", repository.getId(), childRepository.getId() );
- assertEquals( "Check name matches", repository.getName(), childRepository.getName() );
- assertEquals( "Check url matches", repository.getUrl(), childRepository.getUrl() );
- assertEquals( "Check layout matches", repository.getLayout(), childRepository.getLayout() );
- }
-
- public void testShouldOverrideUnitTestExcludesOnly()
- {
- Model parent = new Model();
-
- parent.setGroupId( "test" );
- parent.setArtifactId( "test" );
- parent.setVersion( "0.0" );
-
- Build parentBuild = new Build();
-
- parentBuild.setSourceDirectory( "src/main/java" );
- parentBuild.setTestSourceDirectory( "src/test/java" );
-
- Resource parentResource = new Resource();
-
- parentResource.setDirectory( "src/main/resources" );
-
- parentBuild.addResource( parentResource );
-
- Resource parentUTResource = new Resource();
-
- parentUTResource.setDirectory( "src/test/resources" );
-
- parentBuild.addTestResource( parentUTResource );
-
- parent.setBuild( parentBuild );
-
- Model child = new Model();
-
- Parent parentElement = new Parent();
- parentElement.setArtifactId( parent.getArtifactId() );
- parentElement.setGroupId( parent.getGroupId() );
- parentElement.setVersion( parent.getVersion() );
- child.setParent( parentElement );
-
- child.setPackaging( "plugin" );
-
- Build childBuild = new Build();
- child.setBuild( childBuild );
-
- assembler.assembleModelInheritance( child, parent );
-
- assertEquals( "source directory should be from parent", "src/main/java",
- child.getBuild().getSourceDirectory() );
- assertEquals( "unit test source directory should be from parent", "src/test/java",
- child.getBuild().getTestSourceDirectory() );
-
-// TODO: test inheritence/super pom?
-// List childExcludesTest = child.getBuild().getUnitTest().getExcludes();
-//
-// assertTrue( "unit test excludes should have **/*AspectTest.java", childExcludesTest
-// .contains( "**/*AspectTest.java" ) );
-// assertTrue( "unit test excludes should have **/*Abstract*.java", childExcludesTest
-// .contains( "**/*Abstract*.java" ) );
-//
-
- List resources = child.getBuild().getResources();
-
- assertEquals( "build resources inherited from parent should be of size 1", 1, resources.size() );
- assertEquals( "first resource should have dir == src/main/resources", "src/main/resources",
- ( (Resource) resources.get( 0 ) ).getDirectory() );
-
- List utResources = child.getBuild().getTestResources();
-
- assertEquals( "UT resources inherited from parent should be of size 1", 1, utResources.size() );
- assertEquals( "first UT resource should have dir == src/test/resources", "src/test/resources",
- ( (Resource) utResources.get( 0 ) ).getDirectory() );
-
- assertEquals( "plugin", child.getPackaging() );
- assertEquals( "jar", parent.getPackaging() );
- }
-
- /**
- *
- * root
- * |--artifact1
- * | |
- * | |--artifact1-1
- * |
- * |--artifact2 (in another directory called a2 so it has it's own scm section)
- * |
- * |--artifact2-1
- *
- */
- public void testScmInheritance()
- throws Exception
- {
- // Make the models
- Model root = makeScmModel( "root", "scm:foo:/scm-root", "scm:foo:/scm-dev-root", null );
-
- Model artifact1 = makeScmModel( "artifact1" );
-
- Model artifact1_1 = makeScmModel( "artifact1-1" );
-
- Model artifact2 =
- makeScmModel( "artifact2", "scm:foo:/scm-root/yay-artifact2", "scm:foo:/scm-dev-root/yay-artifact2", null );
-
- Model artifact2_1 = makeScmModel( "artifact2-1" );
-
- // Assemble
- assembler.assembleModelInheritance( artifact1, root );
-
- assembler.assembleModelInheritance( artifact1_1, artifact1 );
-
- assembler.assembleModelInheritance( artifact2, root );
-
- assembler.assembleModelInheritance( artifact2_1, artifact2 );
-
- // --- -- -
-
- assertConnection( "scm:foo:/scm-root/artifact1", "scm:foo:/scm-dev-root/artifact1", artifact1 );
-
- assertConnection( "scm:foo:/scm-root/artifact1/artifact1-1", "scm:foo:/scm-dev-root/artifact1/artifact1-1",
- artifact1_1 );
-
- assertConnection( "scm:foo:/scm-root/yay-artifact2", "scm:foo:/scm-dev-root/yay-artifact2", artifact2 );
-
- assertConnection( "scm:foo:/scm-root/yay-artifact2/artifact2-1",
- "scm:foo:/scm-dev-root/yay-artifact2/artifact2-1", artifact2_1 );
- }
-
- public void testScmInheritanceWhereParentHasConnectionAndTheChildDoesnt()
- {
- Model parent = makeScmModel( "parent", "scm:foo:bar:/scm-root", null, null );
-
- Model child = makeScmModel( "child" );
-
- assembler.assembleModelInheritance( child, parent );
-
- assertScm( "scm:foo:bar:/scm-root/child", null, null, child.getScm() );
- }
-
- public void testScmInheritanceWhereParentHasConnectionAndTheChildDoes()
- {
- Model parent = makeScmModel( "parent", "scm:foo:bar:/scm-root", null, null );
-
- Model child = makeScmModel( "child", "scm:foo:bar:/another-root", null, null );
-
- assembler.assembleModelInheritance( child, parent );
-
- assertScm( "scm:foo:bar:/another-root", null, null, child.getScm() );
- }
-
- public void testScmInheritanceWhereParentHasDeveloperConnectionAndTheChildDoesnt()
- {
- Model parent = makeScmModel( "parent", null, "scm:foo:bar:/scm-dev-root", null );
-
- Model child = makeScmModel( "child" );
-
- assembler.assembleModelInheritance( child, parent );
-
- assertScm( null, "scm:foo:bar:/scm-dev-root/child", null, child.getScm() );
- }
-
- public void testScmInheritanceWhereParentHasDeveloperConnectionAndTheChildDoes()
- {
- Model parent = makeScmModel( "parent", null, "scm:foo:bar:/scm-dev-root", null );
-
- Model child = makeScmModel( "child", null, "scm:foo:bar:/another-dev-root", null );
-
- assembler.assembleModelInheritance( child, parent );
-
- assertScm( null, "scm:foo:bar:/another-dev-root", null, child.getScm() );
- }
-
- public void testScmInheritanceWhereParentHasUrlAndTheChildDoesnt()
- {
- Model parent = makeScmModel( "parent", null, null, "http://foo/bar" );
-
- Model child = makeScmModel( "child" );
-
- assembler.assembleModelInheritance( child, parent );
-
- assertScm( null, null, "http://foo/bar/child", child.getScm() );
- }
-
- public void testScmInheritanceWhereParentHasUrlAndTheChildDoes()
- {
- Model parent = makeScmModel( "parent", null, null, "http://foo/bar/" );
-
- Model child = makeScmModel( "child", null, null, "http://bar/foo/" );
-
- assembler.assembleModelInheritance( child, parent );
-
- assertScm( null, null, "http://bar/foo/", child.getScm() );
- }
-
- public void testRepositoryInheritenceWhereParentHasRepositoryAndTheChildDoesnt()
- {
- Model parent = makeRepositoryModel( "parent", "central", "http://repo1.maven.org/maven/" );
-
- List repos = new ArrayList( parent.getRepositories() );
-
- Model child = makeBaseModel( "child" );
-
- assembler.assembleModelInheritance( child, parent );
-
- // TODO: a lot easier if modello generated equals() :)
- assertRepositories( repos, child.getRepositories() );
- }
-
- public void testRepositoryInheritenceWhereParentHasRepositoryAndTheChildHasDifferent()
- {
- Model parent = makeRepositoryModel( "parent", "central", "http://repo1.maven.org/maven/" );
-
- List repos = new ArrayList( parent.getRepositories() );
-
- Model child = makeRepositoryModel( "child", "workplace", "http://repository.mycompany.com/maven/" );
-
- repos.addAll( child.getRepositories() );
-
- assembler.assembleModelInheritance( child, parent );
-
- // TODO: a lot easier if modello generated equals() :)
- assertRepositories( repos, child.getRepositories() );
- }
-
- public void testRepositoryInheritenceWhereParentHasRepositoryAndTheChildHasSameId()
- {
- Model parent = makeRepositoryModel( "parent", "central", "http://repo1.maven.org/maven/" );
-
- Model child = makeRepositoryModel( "child", "central", "http://repo2.maven.org/maven/" );
-
- // We want to get the child repository here.
- List repos = new ArrayList( child.getRepositories() );
-
- assembler.assembleModelInheritance( child, parent );
-
- // TODO: a lot easier if modello generated equals() :)
- assertRepositories( repos, child.getRepositories() );
- }
-
- public void testPluginInheritanceWhereParentPluginWithoutInheritFlagAndChildHasNoPlugins()
- {
- Model parent = makeBaseModel( "parent" );
-
- Model child = makeBaseModel( "child" );
-
- Plugin parentPlugin = new Plugin();
- parentPlugin.setArtifactId( "maven-testInheritance-plugin" );
- parentPlugin.setGroupId( "org.apache.maven.plugins" );
- parentPlugin.setVersion( "1.0" );
-
- List parentPlugins = Collections.singletonList( parentPlugin );
-
- Build parentBuild = new Build();
- parentBuild.setPlugins( parentPlugins );
-
- parent.setBuild( parentBuild );
-
- assembler.assembleModelInheritance( child, parent );
-
- assertPlugins( parentPlugins, child );
- }
-
- public void testPluginInheritanceWhereParentPluginWithTrueInheritFlagAndChildHasNoPlugins()
- {
- Model parent = makeBaseModel( "parent" );
-
- Model child = makeBaseModel( "child" );
-
- Plugin parentPlugin = new Plugin();
- parentPlugin.setArtifactId( "maven-testInheritance2-plugin" );
- parentPlugin.setGroupId( "org.apache.maven.plugins" );
- parentPlugin.setVersion( "1.0" );
- parentPlugin.setInherited( "true" );
-
- List parentPlugins = Collections.singletonList( parentPlugin );
-
- Build parentBuild = new Build();
- parentBuild.setPlugins( parentPlugins );
-
- parent.setBuild( parentBuild );
-
- assembler.assembleModelInheritance( child, parent );
-
- assertPlugins( parentPlugins, child );
- }
-
- public void testPluginInheritanceWhereParentPluginWithFalseInheritFlagAndChildHasNoPlugins()
- {
- Model parent = makeBaseModel( "parent" );
-
- Model child = makeBaseModel( "child" );
-
- Plugin parentPlugin = new Plugin();
- parentPlugin.setArtifactId( "maven-testInheritance3-plugin" );
- parentPlugin.setGroupId( "org.apache.maven.plugins" );
- parentPlugin.setVersion( "1.0" );
- parentPlugin.setInherited( "false" );
-
- List parentPlugins = Collections.singletonList( parentPlugin );
-
- Build parentBuild = new Build();
- parentBuild.setPlugins( parentPlugins );
-
- parent.setBuild( parentBuild );
-
- assembler.assembleModelInheritance( child, parent );
-
- assertPlugins( new ArrayList(), child );
- }
-
- private void assertPlugins( List expectedPlugins, Model child )
- {
- Build childBuild = child.getBuild();
-
- if ( ( expectedPlugins != null ) && !expectedPlugins.isEmpty() )
- {
- assertNotNull( childBuild );
-
- Map childPluginsMap = childBuild.getPluginsAsMap();
-
- if ( childPluginsMap != null )
- {
- assertEquals( expectedPlugins.size(), childPluginsMap.size() );
-
- for ( Iterator it = expectedPlugins.iterator(); it.hasNext(); )
- {
- Plugin expectedPlugin = (Plugin) it.next();
-
- Plugin childPlugin = (Plugin) childPluginsMap.get( expectedPlugin.getKey() );
-
- assertPluginsEqual( expectedPlugin, childPlugin );
- }
- }
- else
- {
- fail( "child plugins collection is null, but expectations map is not." );
- }
- }
- else
- {
- assertTrue( ( childBuild == null ) || ( childBuild.getPlugins() == null ) || childBuild.getPlugins().isEmpty() );
- }
- }
-
- private void assertPluginsEqual( Plugin reference, Plugin test )
- {
- assertEquals( "Plugin keys don't match", reference.getKey(), test.getKey() );
- assertEquals( "Plugin configurations don't match", reference.getConfiguration(), test.getConfiguration() );
-
- List referenceExecutions = reference.getExecutions();
- Map testExecutionsMap = test.getExecutionsAsMap();
-
- if ( ( referenceExecutions != null ) && !referenceExecutions.isEmpty() )
- {
- assertTrue( "Missing goals specification", ( ( testExecutionsMap != null ) && !testExecutionsMap.isEmpty() ) );
-
- for ( Iterator it = referenceExecutions.iterator(); it.hasNext(); )
- {
- PluginExecution referenceExecution = (PluginExecution) it.next();
- PluginExecution testExecution = (PluginExecution) testExecutionsMap.get( referenceExecution.getId() );
-
- assertNotNull( "Goal from reference not found in test", testExecution );
-
- assertEquals( "Goal IDs don't match", referenceExecution.getId(), testExecution.getId() );
- assertEquals( "Goal configurations don't match", referenceExecution.getConfiguration(),
- testExecution.getConfiguration() );
- assertEquals( "Goal lists don't match", referenceExecution.getGoals(), testExecution.getGoals() );
- }
- }
- else
- {
- assertTrue( "Unexpected goals specification",
- ( ( testExecutionsMap == null ) || testExecutionsMap.isEmpty() ) );
- }
- }
-
- public void testReportingExcludeDefaultsInheritance()
- {
- Model parent = makeBaseModel( "parent" );
-
- Model child = makeBaseModel( "child" );
-
- Reporting parentBuild = new Reporting();
- parentBuild.setExcludeDefaults( false );
- parent.setReporting( parentBuild );
-
- assembler.assembleModelInheritance( child, parent );
-
- assertFalse( "Check excludeDefaults is inherited", child.getReporting().isExcludeDefaults() );
-
- child = makeBaseModel( "child" );
-
- parentBuild.setExcludeDefaults( true );
-
- assembler.assembleModelInheritance( child, parent );
-
- assertTrue( "Check excludeDefaults is inherited", child.getReporting().isExcludeDefaults() );
- }
-
- public void testReportInheritanceWhereParentReportWithoutInheritFlagAndChildHasNoReports()
- {
- Model parent = makeBaseModel( "parent" );
-
- Model child = makeBaseModel( "child" );
-
- ReportPlugin parentReport = new ReportPlugin();
- parentReport.setArtifactId( "maven-testInheritance-report-plugin" );
- parentReport.setGroupId( "org.apache.maven.plugins" );
- parentReport.setVersion( "1.0" );
-
- List parentPlugins = Collections.singletonList( parentReport );
-
- Reporting parentBuild = new Reporting();
- parentBuild.setPlugins( parentPlugins );
-
- parent.setReporting( parentBuild );
-
- assembler.assembleModelInheritance( child, parent );
-
- assertReports( parentPlugins, child );
- }
-
- public void testReportInheritanceWhereParentReportWithTrueInheritFlagAndChildHasNoReports()
- {
- Model parent = makeBaseModel( "parent" );
-
- Model child = makeBaseModel( "child" );
-
- ReportPlugin parentPlugin = new ReportPlugin();
- parentPlugin.setArtifactId( "maven-testInheritance2-report-plugin" );
- parentPlugin.setGroupId( "org.apache.maven.plugins" );
- parentPlugin.setVersion( "1.0" );
- parentPlugin.setInherited( "true" );
-
- List parentPlugins = Collections.singletonList( parentPlugin );
-
- Reporting parentBuild = new Reporting();
- parentBuild.setPlugins( parentPlugins );
-
- parent.setReporting( parentBuild );
-
- assembler.assembleModelInheritance( child, parent );
-
- assertReports( parentPlugins, child );
- }
-
- public void testReportInheritanceWhereParentReportWithFalseInheritFlagAndChildHasNoReports()
- {
- Model parent = makeBaseModel( "parent" );
-
- Model child = makeBaseModel( "child" );
-
- ReportPlugin parentPlugin = new ReportPlugin();
- parentPlugin.setArtifactId( "maven-testInheritance3-report-plugin" );
- parentPlugin.setGroupId( "org.apache.maven.plugins" );
- parentPlugin.setVersion( "1.0" );
- parentPlugin.setInherited( "false" );
-
- List parentPlugins = Collections.singletonList( parentPlugin );
-
- Reporting parentBuild = new Reporting();
- parentBuild.setPlugins( parentPlugins );
-
- parent.setReporting( parentBuild );
-
- assembler.assembleModelInheritance( child, parent );
-
- assertReports( new ArrayList(), child );
- }
-
- public void testPluginExecInheritanceWhereExecInheritedSetToFalse()
- {
- String testId = "test";
- String gid = "group";
- String aid = "artifact";
- String ver = "1";
-
- Model child = makeBaseModel( "child" );
-
- Plugin pChild = new Plugin();
- pChild.setGroupId( gid );
- pChild.setArtifactId( aid );
- pChild.setVersion( ver );
-
- PluginExecution eChild = new PluginExecution();
- eChild.setId( "normal" );
- eChild.addGoal( "run" );
-
- pChild.addExecution( eChild );
-
- Build bChild = new Build();
- bChild.addPlugin( pChild );
-
- child.setBuild( bChild );
-
- Model parent = makeBaseModel( "parent" );
-
- Plugin pParent = new Plugin();
- pParent.setGroupId( gid );
- pParent.setArtifactId( aid );
- pParent.setVersion( ver );
-
- pParent.setInherited( Boolean.toString( true ) );
-
- PluginExecution eParent = new PluginExecution();
- eParent.setId( testId );
- eParent.addGoal( "test" );
- eParent.setInherited( Boolean.toString( false ) );
-
- pParent.addExecution( eParent );
-
- Build bParent = new Build();
- bParent.addPlugin( pParent );
-
- parent.setBuild( bParent );
-
- assembler.assembleModelInheritance( child, parent );
-
- Map pluginMap = bChild.getPluginsAsMap();
- assertNotNull( pluginMap );
-
- Plugin plugin = (Plugin) pluginMap.get( gid + ":" + aid );
- assertNotNull( plugin );
-
- Map executionMap = plugin.getExecutionsAsMap();
- assertNotNull( executionMap );
-
- assertNull( "test execution with inherited == false should NOT be inherited to child model.", executionMap.get( testId ) );
- }
-
- public void testPluginExecInheritanceWhereExecInheritedSetToFalseAndPluginInheritedNotSet()
- {
- String testId = "test";
- String gid = "group";
- String aid = "artifact";
- String ver = "1";
-
- Model child = makeBaseModel( "child" );
-
- Plugin pChild = new Plugin();
- pChild.setGroupId( gid );
- pChild.setArtifactId( aid );
- pChild.setVersion( ver );
-
- PluginExecution eChild = new PluginExecution();
- eChild.setId( "normal" );
- eChild.addGoal( "run" );
-
- pChild.addExecution( eChild );
-
- Build bChild = new Build();
- bChild.addPlugin( pChild );
-
- child.setBuild( bChild );
-
- Model parent = makeBaseModel( "parent" );
-
- Plugin pParent = new Plugin();
- pParent.setGroupId( gid );
- pParent.setArtifactId( aid );
- pParent.setVersion( ver );
-
- PluginExecution eParent = new PluginExecution();
- eParent.setId( testId );
- eParent.addGoal( "test" );
- eParent.setInherited( Boolean.toString( false ) );
-
- pParent.addExecution( eParent );
-
- Build bParent = new Build();
- bParent.addPlugin( pParent );
-
- parent.setBuild( bParent );
-
- assembler.assembleModelInheritance( child, parent );
-
- Map pluginMap = bChild.getPluginsAsMap();
- assertNotNull( pluginMap );
-
- Plugin plugin = (Plugin) pluginMap.get( gid + ":" + aid );
- assertNotNull( plugin );
-
- Map executionMap = plugin.getExecutionsAsMap();
- assertNotNull( executionMap );
-
- assertNull( "test execution with inherited == false should NOT be inherited to child model.", executionMap.get( testId ) );
- }
-
- private void assertReports( List expectedPlugins, Model child )
- {
- Reporting childBuild = child.getReporting();
-
- if ( ( expectedPlugins != null ) && !expectedPlugins.isEmpty() )
- {
- assertNotNull( childBuild );
-
- Map childPluginsMap = childBuild.getReportPluginsAsMap();
-
- if ( childPluginsMap != null )
- {
- assertEquals( expectedPlugins.size(), childPluginsMap.size() );
-
- for ( Iterator it = expectedPlugins.iterator(); it.hasNext(); )
- {
- ReportPlugin expectedPlugin = (ReportPlugin) it.next();
-
- ReportPlugin childPlugin = (ReportPlugin) childPluginsMap.get( expectedPlugin.getKey() );
-
- assertReportsEqual( expectedPlugin, childPlugin );
- }
- }
- else
- {
- fail( "child plugins collection is null, but expectations map is not." );
- }
- }
- else
- {
- assertTrue( ( childBuild == null ) || ( childBuild.getPlugins() == null ) || childBuild.getPlugins().isEmpty() );
- }
- }
-
- private void assertReportsEqual( ReportPlugin reference, ReportPlugin test )
- {
- assertEquals( "Plugin keys don't match", reference.getKey(), test.getKey() );
- assertEquals( "Plugin configurations don't match", reference.getConfiguration(), test.getConfiguration() );
-
- List referenceReportSets = reference.getReportSets();
- Map testReportSetsMap = test.getReportSetsAsMap();
-
- if ( ( referenceReportSets != null ) && !referenceReportSets.isEmpty() )
- {
- assertTrue( "Missing goals specification", ( ( testReportSetsMap != null ) && !testReportSetsMap.isEmpty() ) );
-
- for ( Iterator it = referenceReportSets.iterator(); it.hasNext(); )
- {
- ReportSet referenceReportSet = (ReportSet) it.next();
- ReportSet testReportSet = (ReportSet) testReportSetsMap.get( referenceReportSet.getId() );
-
- assertNotNull( "Goal from reference not found in test", testReportSet );
-
- assertEquals( "Goal IDs don't match", referenceReportSet.getId(), testReportSet.getId() );
- assertEquals( "Goal configurations don't match", referenceReportSet.getConfiguration(),
- testReportSet.getConfiguration() );
- assertEquals( "Reports don't match", referenceReportSet.getReports(), testReportSet.getReports() );
- }
- }
- else
- {
- assertTrue( "Unexpected goals specification",
- ( ( testReportSetsMap == null ) || testReportSetsMap.isEmpty() ) );
- }
- }
-
- // ----------------------------------------------------------------------
- //
- // ----------------------------------------------------------------------
-
- private void assertConnection( String expectedConnection, String expectedDeveloperConnection, Model model )
- {
- String connection = model.getScm().getConnection();
-
- assertNotNull( connection );
-
- assertEquals( expectedConnection, connection );
-
- String developerConnection = model.getScm().getDeveloperConnection();
-
- assertNotNull( developerConnection );
-
- assertEquals( expectedDeveloperConnection, developerConnection );
- }
-
- public void assertScm( String connection, String developerConnection, String url, Scm scm )
- {
- assertNotNull( scm );
-
- assertEquals( connection, scm.getConnection() );
-
- assertEquals( developerConnection, scm.getDeveloperConnection() );
-
- assertEquals( url, scm.getUrl() );
- }
-
- private static Model makeScmModel( String artifactId )
- {
- return makeScmModel( artifactId, null, null, null );
- }
-
- private static Model makeScmModel( String artifactId, String connection, String developerConnection, String url )
- {
- Model model = makeBaseModel( artifactId );
-
- if ( ( connection != null ) || ( developerConnection != null ) || ( url != null ) )
- {
- Scm scm = new Scm();
-
- scm.setConnection( connection );
-
- scm.setDeveloperConnection( developerConnection );
-
- scm.setUrl( url );
-
- model.setScm( scm );
- }
-
- return model;
- }
-
- private static Model makeBaseModel( String artifactId )
- {
- Model model = new Model();
-
- model.setModelVersion( "4.0.0" );
-
- model.setGroupId( "maven" );
-
- model.setArtifactId( artifactId );
-
- model.setVersion( "1.0" );
- return model;
- }
-
- private static Model makeRepositoryModel( String artifactId, String id, String url )
- {
- Model model = makeBaseModel( artifactId );
-
- Repository repository = makeRepository( id, url );
-
- model.setRepositories( new ArrayList( Collections.singletonList( repository ) ) );
-
- return model;
- }
-
- private static Repository makeRepository( String id, String url )
- {
- Repository repository = new Repository();
- repository.setId( id );
- repository.setUrl( url );
- return repository;
- }
-
- private void assertRepositories( List expected, List actual )
- {
- assertEquals( "Repository list sizes don't match", expected.size(), actual.size() );
-
- for ( Iterator i = expected.iterator(); i.hasNext(); )
- {
- Repository expectedRepository = (Repository) i.next();
- boolean found = false;
- for ( Iterator j = actual.iterator(); j.hasNext() && !found; )
- {
- Repository actualRepository = (Repository) j.next();
-
- if ( actualRepository.getId().equals( expectedRepository.getId() ) )
- {
- assertEquals( "Repository URLs don't match", expectedRepository.getUrl(),
- actualRepository.getUrl() );
- found = true;
- }
- }
- assertTrue( "Repository with ID " + expectedRepository.getId() + " not found", found );
- }
- }
-
-}
diff --git a/maven-project/src/test/java/org/apache/maven/project/inheritance/t09/ProjectInheritanceTest.java b/maven-project/src/test/java/org/apache/maven/project/inheritance/t09/ProjectInheritanceTest.java
index ad5dddc45c..352bb7b8fc 100644
--- a/maven-project/src/test/java/org/apache/maven/project/inheritance/t09/ProjectInheritanceTest.java
+++ b/maven-project/src/test/java/org/apache/maven/project/inheritance/t09/ProjectInheritanceTest.java
@@ -70,6 +70,7 @@ public class ProjectInheritanceTest
MavenProject project0 = getProjectWithDependencies( pom0 );
MavenProject project1 = getProjectWithDependencies( pom1 );
+ assertNotNull("Parent is null", project1.getParent());
assertEquals( pom0Basedir, project1.getParent().getBasedir().getCanonicalFile() );
Map map = project1.getArtifactMap();
diff --git a/maven-project/src/test/java/org/apache/maven/project/injection/DefaultModelDefaultsInjectorTest.java b/maven-project/src/test/java/org/apache/maven/project/injection/DefaultModelDefaultsInjectorTest.java
index a2b970799f..b868d1ff62 100644
--- a/maven-project/src/test/java/org/apache/maven/project/injection/DefaultModelDefaultsInjectorTest.java
+++ b/maven-project/src/test/java/org/apache/maven/project/injection/DefaultModelDefaultsInjectorTest.java
@@ -24,6 +24,7 @@ import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Exclusion;
import org.apache.maven.model.Model;
+import org.apache.maven.project.artifact.TestModelDefaultsInjector;
import java.util.List;
@@ -35,7 +36,7 @@ public class DefaultModelDefaultsInjectorTest
{
public void testShouldConstructWithNoParams()
{
- new DefaultModelDefaultsInjector();
+ new TestModelDefaultsInjector();
}
public void testShouldMergeManagedDependencyOfTypeEJBToDependencyList()
@@ -66,7 +67,7 @@ public class DefaultModelDefaultsInjectorTest
model.addDependency( dep );
- new DefaultModelDefaultsInjector().injectDefaults( model );
+ new TestModelDefaultsInjector().injectDefaults( model );
List resultingDeps = model.getDependencies();
@@ -99,7 +100,7 @@ public class DefaultModelDefaultsInjectorTest
model.setDependencyManagement( depMgmt );
- new DefaultModelDefaultsInjector().injectDefaults( model );
+ new TestModelDefaultsInjector().injectDefaults( model );
List deps = model.getDependencies();
assertEquals( 1, deps.size() );
@@ -136,7 +137,7 @@ public class DefaultModelDefaultsInjectorTest
model.setDependencyManagement( depMgmt );
- new DefaultModelDefaultsInjector().injectDefaults( model );
+ new TestModelDefaultsInjector().injectDefaults( model );
List deps = model.getDependencies();
assertEquals( 1, deps.size() );
@@ -174,7 +175,7 @@ public class DefaultModelDefaultsInjectorTest
model.setDependencyManagement( depMgmt );
- new DefaultModelDefaultsInjector().injectDefaults( model );
+ new TestModelDefaultsInjector().injectDefaults( model );
List deps = model.getDependencies();
assertEquals( 1, deps.size() );
@@ -204,7 +205,7 @@ public class DefaultModelDefaultsInjectorTest
model.setDependencyManagement( depMgmt );
- new DefaultModelDefaultsInjector().injectDefaults( model );
+ new TestModelDefaultsInjector().injectDefaults( model );
List deps = model.getDependencies();
assertEquals( 1, deps.size() );
@@ -234,7 +235,7 @@ public class DefaultModelDefaultsInjectorTest
model.setDependencyManagement( depMgmt );
- new DefaultModelDefaultsInjector().injectDefaults( model );
+ new TestModelDefaultsInjector().injectDefaults( model );
List deps = model.getDependencies();
assertEquals( 1, deps.size() );
@@ -261,7 +262,7 @@ public class DefaultModelDefaultsInjectorTest
model.setDependencyManagement( depMgmt );
- new DefaultModelDefaultsInjector().injectDefaults( model );
+ new TestModelDefaultsInjector().injectDefaults( model );
List deps = model.getDependencies();
assertEquals( 1, deps.size() );
@@ -289,7 +290,7 @@ public class DefaultModelDefaultsInjectorTest
model.setDependencyManagement( depMgmt );
- new DefaultModelDefaultsInjector().injectDefaults( model );
+ new TestModelDefaultsInjector().injectDefaults( model );
List deps = model.getDependencies();
assertEquals( 1, deps.size() );
@@ -322,7 +323,7 @@ public class DefaultModelDefaultsInjectorTest
model.setDependencyManagement( depMgmt );
- new DefaultModelDefaultsInjector().injectDefaults( model );
+ new TestModelDefaultsInjector().injectDefaults( model );
List deps = model.getDependencies();
assertEquals( 1, deps.size() );
@@ -353,7 +354,7 @@ public class DefaultModelDefaultsInjectorTest
// try
// {
- new DefaultModelDefaultsInjector().injectDefaults( model );
+ new TestModelDefaultsInjector().injectDefaults( model );
Dependency dependency = (Dependency) model.getDependencies().get( 0 );
assertNull( "check version is null", dependency.getVersion() );
// fail("Should fail to validate dependency without a version.");
diff --git a/maven-project/src/test/java/org/apache/maven/project/workspace/DefaultProjectWorkspaceTest.java b/maven-project/src/test/java/org/apache/maven/project/workspace/DefaultProjectWorkspaceTest.java
deleted file mode 100644
index 19cfbcf408..0000000000
--- a/maven-project/src/test/java/org/apache/maven/project/workspace/DefaultProjectWorkspaceTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-package org.apache.maven.project.workspace;
-
-import org.apache.maven.model.Model;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.build.model.ModelAndFile;
-import org.apache.maven.workspace.DefaultMavenWorkspaceStore;
-import org.codehaus.plexus.logging.Logger;
-import org.codehaus.plexus.logging.console.ConsoleLogger;
-
-import java.io.File;
-
-import junit.framework.TestCase;
-
-public class DefaultProjectWorkspaceTest
- extends TestCase
-{
-
- public void testStoreAndRetrieveModelAndFile()
- {
- ModelAndFile maf = newModelAndFile( "group", "artifact", "1" );
-
- DefaultProjectWorkspace ws = newWorkspace();
- ws.storeModelAndFile( maf );
-
- ModelAndFile r1 = ws.getModelAndFile( maf.getFile() );
-
- assertSame( maf, r1 );
-
- ModelAndFile r2 = ws.getModelAndFile( maf.getModel().getGroupId(), maf.getModel().getArtifactId(), maf.getModel().getVersion() );
-
- assertSame( maf, r2 );
- }
-
- private DefaultProjectWorkspace newWorkspace()
- {
- DefaultProjectWorkspace ws = new DefaultProjectWorkspace( new DefaultMavenWorkspaceStore(), new ConsoleLogger( Logger.LEVEL_INFO, "test" ) );
- return ws;
- }
-
- public void testStoreAndRetrieveProjectByFile_CoordinateRetrievalReturnsNull()
- {
- MavenProject project = newProject( "group", "artifact", "1" );
-
- DefaultProjectWorkspace ws = newWorkspace();
- ws.storeProjectByFile( project );
-
- assertSame( project, ws.getProject( project.getFile() ) );
- assertNull( ws.getProject( project.getGroupId(), project.getArtifactId(), project.getVersion() ) );
- }
-
- public void testStoreAndRetrieveProjectByCoordinate_FileRetrievalReturnsNull()
- {
- MavenProject project = newProject( "group", "artifact", "1" );
-
- DefaultProjectWorkspace ws = newWorkspace();
- ws.storeProjectByCoordinate( project );
-
- assertNull( ws.getProject( project.getFile() ) );
- assertSame( project, ws.getProject( project.getGroupId(), project.getArtifactId(), project.getVersion() ) );
- }
-
- private MavenProject newProject( String gid,
- String aid,
- String ver )
- {
- File f = new File( "test-project" );
- Model model = new Model();
- model.setGroupId( gid );
- model.setArtifactId( aid );
- model.setVersion( ver );
-
- MavenProject project = new MavenProject( model );
- project.setFile( f );
- return project;
- }
-
- private ModelAndFile newModelAndFile( String gid,
- String aid,
- String ver )
- {
- File f = new File( "test-modelAndFile" );
- Model model = new Model();
- model.setGroupId( gid );
- model.setArtifactId( aid );
- model.setVersion( ver );
-
- ModelAndFile maf = new ModelAndFile( model, f, false );
- return maf;
- }
-
-}
diff --git a/maven-project/src/test/java/org/apache/maven/project/workspace/ModelAndFileCachingTest.java b/maven-project/src/test/java/org/apache/maven/project/workspace/ModelAndFileCachingTest.java
deleted file mode 100644
index 5da0042441..0000000000
--- a/maven-project/src/test/java/org/apache/maven/project/workspace/ModelAndFileCachingTest.java
+++ /dev/null
@@ -1,241 +0,0 @@
-package org.apache.maven.project.workspace;
-
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
-import org.apache.maven.model.Model;
-import org.apache.maven.profiles.DefaultProfileManager;
-import org.apache.maven.profiles.ProfileManager;
-import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
-import org.apache.maven.project.DefaultProjectBuilderConfiguration;
-import org.apache.maven.project.ProjectBuildingException;
-import org.apache.maven.project.build.model.ModelAndFile;
-import org.apache.maven.project.build.model.ModelLineage;
-import org.apache.maven.project.build.model.ModelLineageBuilder;
-import org.apache.maven.workspace.MavenWorkspaceStore;
-import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.logging.Logger;
-import org.codehaus.plexus.util.FileUtils;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-public class ModelAndFileCachingTest
- extends PlexusTestCase
-{
-
- private static final String MY_PKG = ModelAndFileCachingTest.class.getPackage().getName().replace( '.', '/' );
-
- private static final String MY_PATH = ModelAndFileCachingTest.class.getName()
- .replace( '.', '/' )
- + ".class";
-
- private ProjectWorkspace projectWorkspace;
-
- private MavenWorkspaceStore workspaceStore;
-
- private ModelLineageBuilder lineageBuilder;
-
- private ArtifactRepositoryFactory repoFactory;
-
- private ProfileManager profileManager;
-
- private ArtifactRepository localRepo;
-
- private ArtifactFactory artifactFactory;
-
- private List dirsToDelete = new ArrayList();
-
- public void setUp()
- throws Exception
- {
- super.setUp();
- getContainer().getLoggerManager().setThresholds( Logger.LEVEL_DEBUG );
-
- projectWorkspace = (ProjectWorkspace) lookup( ProjectWorkspace.class );
- workspaceStore = (MavenWorkspaceStore) lookup( MavenWorkspaceStore.class );
- lineageBuilder = (ModelLineageBuilder) lookup( ModelLineageBuilder.class );
- repoFactory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.class );
- artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.class );
-
- File localRepoDir = File.createTempFile( "local-repo.", ".tmp" );
- localRepoDir.delete();
- localRepoDir.mkdirs();
-
- dirsToDelete.add( localRepoDir );
-
- localRepo = repoFactory.createLocalRepository( localRepoDir );
- profileManager = new DefaultProfileManager(
- getContainer(),
- new DefaultProfileActivationContext(
- System.getProperties(),
- true ) );
- }
-
- public void tearDown()
- throws Exception
- {
- workspaceStore.clear();
-
- if ( !dirsToDelete.isEmpty() )
- {
- for ( Iterator it = dirsToDelete.iterator(); it.hasNext(); )
- {
- File dir = (File) it.next();
- try
- {
- FileUtils.deleteDirectory( dir );
- }
- catch ( IOException e )
- {
- // ignore.
- }
- }
- }
-
- super.tearDown();
- }
-
- public void testResolveParentPom_PreferCachedInstance()
- throws IOException, ProjectBuildingException
- {
- File childPomFile = getFile( "resolveParentPom/pom.xml" );
-
- String gid = "tests";
- String aid = "resolve-parent-pom-parent";
- String ver = "1";
-
- ModelAndFile maf = newModelAndFile( gid, aid, ver );
- projectWorkspace.storeModelAndFile( maf );
-
- ModelLineage lineage = lineageBuilder.buildModelLineage( childPomFile,
- new DefaultProjectBuilderConfiguration().setLocalRepository( localRepo ).setGlobalProfileManager( profileManager ),
- Collections.EMPTY_LIST,
- false,
- false );
-
- assertSame( maf.getModel(), lineage.getDeepestAncestorModel() );
- }
-
- public void testResolveParentPom_StoreByFileAndGAVIfUncached()
- throws IOException, ProjectBuildingException
- {
- File childPomFile = getFile( "resolveParentPom/childAndParent/child/pom.xml" );
- File parentPomFile = new File( childPomFile.getParentFile().getParentFile(), "pom.xml" );
-
- String gid = "tests";
- String aid = "childAndParent-parent";
- String ver = "1";
-
- ModelLineage lineage = lineageBuilder.buildModelLineage( childPomFile,
- new DefaultProjectBuilderConfiguration().setLocalRepository( localRepo ).setGlobalProfileManager( profileManager ),
- Collections.EMPTY_LIST,
- false,
- true );
-
- assertEquals( parentPomFile.getCanonicalPath(), lineage.getDeepestAncestorFile()
- .getCanonicalPath() );
-
- ModelAndFile maf1 = projectWorkspace.getModelAndFile( gid, aid, ver );
- assertNotNull( maf1 );
- assertSame( maf1.getModel(), lineage.getDeepestAncestorModel() );
-
- ModelAndFile maf2 = projectWorkspace.getModelAndFile( parentPomFile );
- assertNotNull( maf2 );
- assertSame( maf2.getModel(), lineage.getDeepestAncestorModel() );
- }
-
- public void testReadModel_PreferModelInstanceCachedByFile()
- throws IOException, ProjectBuildingException
- {
- File pomFile = new File( "test/pom.xml" );
-
- String gid = "tests";
- String aid = "read-model";
- String ver = "1";
-
- ModelAndFile maf = newModelAndFile( gid, aid, ver, pomFile );
- projectWorkspace.storeModelAndFile( maf );
-
- ModelLineage lineage = lineageBuilder.buildModelLineage( pomFile,
- new DefaultProjectBuilderConfiguration().setLocalRepository( localRepo ).setGlobalProfileManager( profileManager ),
- Collections.EMPTY_LIST,
- false,
- false );
-
- assertSame( maf.getModel(), lineage.getOriginatingModel() );
- }
-
- public void testBuildModelLineage_StoreByFileAndGAVIfUncached()
- throws IOException, ProjectBuildingException
- {
- File pomFile = getFile( "buildModelLineage/pom.xml" );
-
- String gid = "tests";
- String aid = "build-model-lineage";
- String ver = "1";
-
- ModelLineage lineage = lineageBuilder.buildModelLineage( pomFile,
- new DefaultProjectBuilderConfiguration().setLocalRepository( localRepo ).setGlobalProfileManager( profileManager ),
- Collections.EMPTY_LIST,
- false,
- false );
-
- assertEquals( pomFile.getCanonicalPath(), lineage.getOriginatingPOMFile()
- .getCanonicalPath() );
-
- ModelAndFile maf1 = projectWorkspace.getModelAndFile( gid, aid, ver );
- assertNotNull( maf1 );
- assertSame( maf1.getModel(), lineage.getOriginatingModel() );
-
- ModelAndFile maf2 = projectWorkspace.getModelAndFile( pomFile );
- assertNotNull( maf2 );
- assertSame( maf2.getModel(), lineage.getOriginatingModel() );
- }
-
- private ModelAndFile newModelAndFile( String gid,
- String aid,
- String ver )
- throws IOException
- {
- return newModelAndFile( gid, aid, ver, File.createTempFile( "model-and-file.", ".tmp" ) );
- }
-
- private ModelAndFile newModelAndFile( String gid,
- String aid,
- String ver,
- File file )
- {
- Model model = new Model();
- model.setGroupId( gid );
- model.setArtifactId( aid );
- model.setVersion( ver );
-
- ModelAndFile maf = new ModelAndFile( model, file, false );
-
- return maf;
- }
-
- private File getFile( String path )
- {
- ClassLoader cloader = Thread.currentThread().getContextClassLoader();
- URL res = cloader.getResource( MY_PATH );
-
- File myFile = new File( res.getPath() );
-
- File result = new File( myFile.getParentFile(), path );
-
- if ( !result.exists() )
- {
- result = new File( "src/test/resources", MY_PKG + "/" + path );
- }
-
- return result;
- }
-
-}
diff --git a/maven-project/src/test/java/org/apache/maven/project/workspace/ProjectCachingTest.java b/maven-project/src/test/java/org/apache/maven/project/workspace/ProjectCachingTest.java
deleted file mode 100644
index 9280d5fced..0000000000
--- a/maven-project/src/test/java/org/apache/maven/project/workspace/ProjectCachingTest.java
+++ /dev/null
@@ -1,286 +0,0 @@
-package org.apache.maven.project.workspace;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.InvalidRepositoryException;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
-import org.apache.maven.model.Model;
-import org.apache.maven.profiles.DefaultProfileManager;
-import org.apache.maven.profiles.ProfileManager;
-import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.MavenProjectBuilder;
-import org.apache.maven.project.ProjectBuildingException;
-import org.apache.maven.project.build.model.ModelLineageBuilder;
-import org.apache.maven.workspace.MavenWorkspaceStore;
-import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.logging.Logger;
-import org.codehaus.plexus.util.FileUtils;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-// TODO: Add conversion/tests for modelAndFileCache -> projectWorkspace stuff in simple cases.
-// TODO: Add tests for project parents from cache (using model-and-file stuff, maybe?)
-public class ProjectCachingTest
- extends PlexusTestCase
-{
-
- private static final String MY_PATH = ProjectCachingTest.class.getName().replace( '.', '/' )
- + ".class";
-
- private ProjectWorkspace projectWorkspace;
-
- private MavenWorkspaceStore workspaceStore;
-
- private MavenProjectBuilder projectBuilder;
-
- private ModelLineageBuilder lineageBuilder;
-
- private ArtifactRepositoryFactory repoFactory;
-
- private ProfileManager profileManager;
-
- private ArtifactRepository localRepo;
-
- private ArtifactFactory artifactFactory;
-
- private List dirsToDelete = new ArrayList();
-
- public void setUp()
- throws Exception
- {
- super.setUp();
- getContainer().getLoggerManager().setThresholds( Logger.LEVEL_DEBUG );
-
- projectWorkspace = (ProjectWorkspace) lookup( ProjectWorkspace.class );
- workspaceStore = (MavenWorkspaceStore) lookup( MavenWorkspaceStore.class );
- projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.class );
- lineageBuilder = (ModelLineageBuilder) lookup( ModelLineageBuilder.class );
- repoFactory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.class );
- artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.class );
-
- File localRepoDir = File.createTempFile( "local-repo.", ".tmp" );
- localRepoDir.delete();
- localRepoDir.mkdirs();
-
- dirsToDelete.add( localRepoDir );
-
- localRepo = repoFactory.createLocalRepository( localRepoDir );
- profileManager = new DefaultProfileManager(
- getContainer(),
- new DefaultProfileActivationContext(
- System.getProperties(),
- true ) );
- }
-
- public void tearDown()
- throws Exception
- {
- workspaceStore.clear();
-
- if ( !dirsToDelete.isEmpty() )
- {
- for ( Iterator it = dirsToDelete.iterator(); it.hasNext(); )
- {
- File dir = (File) it.next();
- try
- {
- FileUtils.deleteDirectory( dir );
- }
- catch ( IOException e )
- {
- // ignore.
- }
- }
- }
-
- super.tearDown();
- }
-
- public void testBuildFromRepository_PreferCachedProject()
- throws ProjectBuildingException
- {
- String gid = "org.apache.maven.tests";
- String aid = "buildFromRepo-checkCacheFirst";
- String ver = "1";
-
- MavenProject project = newProject( gid, aid, ver );
- projectWorkspace.storeProjectByCoordinate( project );
-
- Artifact artifact = artifactFactory.createProjectArtifact( gid, aid, ver );
-
- MavenProject result = projectBuilder.buildFromRepository( artifact,
- Collections.EMPTY_LIST,
- localRepo );
-
- assertSame( project, result );
- }
-
- public void testBuildFromRepository_StoreProjectByCoordOnlyIfUncached()
- throws ProjectBuildingException, InvalidRepositoryException
- {
- File lrDir = getFile( "buildFromRepo" );
- File pomFile = new File( lrDir, "tests/project-caching/1/project-caching-1.pom" );
-
- String gid = "tests";
- String aid = "project-caching";
- String ver = "1";
-
- Artifact artifact = artifactFactory.createProjectArtifact( gid, aid, ver );
-
- ArtifactRepository localRepo = repoFactory.createLocalRepository( lrDir );
-
- MavenProject project = projectBuilder.buildFromRepository( artifact,
- Collections.EMPTY_LIST,
- localRepo );
-
- MavenProject r1 = projectWorkspace.getProject( pomFile );
-
- MavenProject r2 = projectWorkspace.getProject( gid, aid, ver );
-
- assertNull( r1 );
-
- assertSame( project, r2 );
- }
-
- public void testBuildFromRepository_DontCheckCacheForRELEASEMetaVersion()
- throws ProjectBuildingException, InvalidRepositoryException
- {
- File lrDir = getFile( "buildFromRepo" );
- File pomFile = new File( lrDir, "tests/project-caching/1/project-caching-1.pom" );
-
- String gid = "tests";
- String aid = "project-caching";
- String ver = "1";
-
- MavenProject seed = newProject( gid, aid, ver );
-
- Artifact artifact = artifactFactory.createProjectArtifact( gid,
- aid,
- Artifact.RELEASE_VERSION );
-
- ArtifactRepository localRepo = repoFactory.createLocalRepository( lrDir );
-
- MavenProject project = projectBuilder.buildFromRepository( artifact,
- Collections.EMPTY_LIST,
- localRepo );
-
- assertNotSame( seed, project );
-
- MavenProject r1 = projectWorkspace.getProject( pomFile );
-
- MavenProject r2 = projectWorkspace.getProject( gid, aid, ver );
-
- assertNull( r1 );
-
- assertSame( project, r2 );
- }
-
- public void testBuildFromRepository_DontCheckCacheForLATESTMetaVersion()
- throws ProjectBuildingException, InvalidRepositoryException
- {
- File lrDir = getFile( "buildFromRepo" );
- File pomFile = new File( lrDir, "tests/project-caching/1/project-caching-1.pom" );
-
- String gid = "tests";
- String aid = "project-caching";
- String ver = "1";
-
- MavenProject seed = newProject( gid, aid, ver );
- projectWorkspace.storeProjectByCoordinate( seed );
-
- Artifact artifact = artifactFactory.createProjectArtifact( gid,
- aid,
- Artifact.RELEASE_VERSION );
-
- ArtifactRepository localRepo = repoFactory.createLocalRepository( lrDir );
-
- MavenProject project = projectBuilder.buildFromRepository( artifact,
- Collections.EMPTY_LIST,
- localRepo );
-
- assertNotSame( seed, project );
-
- MavenProject r1 = projectWorkspace.getProject( pomFile );
-
- MavenProject r2 = projectWorkspace.getProject( gid, aid, ver );
-
- assertNull( r1 );
-
- assertSame( project, r2 );
- }
-
- public void testBuildFromFile_PreferProjectCachedByFile()
- throws ProjectBuildingException, InvalidRepositoryException
- {
- File pomFile = getFile( "buildFromFile/pom.xml" );
-
- String gid = "org.apache.maven.tests";
- String aid = "build-from-file";
- String ver = "1";
-
- MavenProject seed = newProject( gid, aid, ver );
- seed.setFile( pomFile );
-
- projectWorkspace.storeProjectByFile( seed );
-
- MavenProject project = projectBuilder.build( pomFile, localRepo, profileManager );
-
- assertSame( seed, project );
-
- assertNull( projectWorkspace.getProject( gid, aid, ver ) );
- }
-
- public void testBuildFromFile_StoreByCoordAndFileIfUncached()
- throws ProjectBuildingException, InvalidRepositoryException
- {
- File pomFile = getFile( "buildFromFile/pom.xml" );
-
- String gid = "org.apache.maven.tests";
- String aid = "build-from-file";
- String ver = "1";
-
- assertNull( projectWorkspace.getProject( pomFile ) );
- assertNull( projectWorkspace.getProject( gid, aid, ver ) );
-
- MavenProject project = projectBuilder.build( pomFile, localRepo, profileManager );
-
- MavenProject byFile = projectWorkspace.getProject( pomFile );
- MavenProject byCoord = projectWorkspace.getProject( gid, aid, ver );
-
- assertSame( project, byFile );
- assertSame( project, byCoord );
- }
-
- private MavenProject newProject( String gid,
- String aid,
- String ver )
- {
- Model model = new Model();
- model.setGroupId( gid );
- model.setArtifactId( aid );
- model.setVersion( ver );
-
- MavenProject project = new MavenProject( model );
-
- return project;
- }
-
- private File getFile( String path )
- {
- ClassLoader cloader = Thread.currentThread().getContextClassLoader();
- URL myRes = cloader.getResource( MY_PATH );
-
- File myFile = new File( myRes.getPath() );
-
- return new File( myFile.getParentFile(), path );
- }
-
-}
diff --git a/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml b/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml
index 9e24d8da1f..838e3459a4 100644
--- a/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml
+++ b/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml
@@ -19,6 +19,27 @@ under the License.
+
+
+ org.apache.maven.project.RepositoryHelper
+ org.apache.maven.project.DefaultRepositoryHelper
+
+
+ org.apache.maven.profiles.build.ProfileAdvisor
+ default
+
+
+ org.apache.maven.artifact.factory.ArtifactFactory
+
+
+ org.apache.maven.artifact.resolver.ArtifactResolver
+ default
+
+
+ org.apache.maven.MavenTools
+
+
+
-
+
+
+ org.apache.maven.project.RepositoryHelper
+ org.apache.maven.project.DefaultRepositoryHelper
+
+
+ org.apache.maven.profiles.build.ProfileAdvisor
+
+
+ org.apache.maven.artifact.factory.ArtifactFactory
+
+
+ org.apache.maven.artifact.resolver.ArtifactResolver
+ default
+
+
+ org.apache.maven.MavenTools
+
+
+
+
+
+
+ 4.0.0
+
+ org.apache.maven.shared
+ maven-shared-components
+ 9
+
+ maven-shared-model
+ 1.0-SNAPSHOT
+ maven-shared-model
+
+
+ org.codehaus.woodstox
+ wstx-asl
+ 3.2.6
+
+
+ javax.xml.stream
+ stax-api
+ 1.0-2
+
+
+ junit
+ junit
+ 4.4
+ test
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 1.5
+
+
+
+
+
+ scm:svn:http://svn.apache.org/repos/asf/maven/shared/trunk/maven-shared-model
+ scm:svn:https://svn.apache.org/repos/asf/maven/shared/trunk/maven-shared-model
+ http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-model
+
+
diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/DataSourceException.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/DataSourceException.java
new file mode 100644
index 0000000000..c33cf3059b
--- /dev/null
+++ b/maven-shared-model/src/main/java/org/apache/maven/shared/model/DataSourceException.java
@@ -0,0 +1,50 @@
+package org.apache.maven.shared.model;
+
+/*
+ * 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.
+ */
+
+import java.io.IOException;
+
+/**
+ * Exception class whose instance is thrown if there is an illegal state within a data source.
+ */
+public class DataSourceException
+ extends IOException
+{
+ static final long serialVersionUID = 8738495672439L;
+
+ /**
+ * Default constructor
+ */
+ public DataSourceException()
+ {
+ super();
+ }
+
+ /**
+ * Constructor
+ *
+ * @param message exception message
+ */
+ public DataSourceException( String message )
+ {
+ super( message );
+ }
+
+}
diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/DomainModel.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/DomainModel.java
new file mode 100644
index 0000000000..db5cf740f3
--- /dev/null
+++ b/maven-shared-model/src/main/java/org/apache/maven/shared/model/DomainModel.java
@@ -0,0 +1,43 @@
+package org.apache.maven.shared.model;
+
+/*
+ * 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.
+ */
+
+/**
+ * Extensions or implementations of this interface can be used to provide wrappers around existing models or can be
+ * used to expose model elements directly. Each respective ModelTransformer implementation should know how to cast to
+ * the appropriate domain model type(s).
+ */
+public interface DomainModel
+{
+
+ /**
+ * Returns event history of joins and deletes used in constructing this domain model.
+ *
+ * @return event history of joins and deletes used in constructing this domain model
+ */
+ String getEventHistory();
+
+ /**
+ * Sets event history of joins and deletes used in constructing this domain model
+ *
+ * @param history history of joins and deletes used in constructing this domain model
+ */
+ void setEventHistory( String history );
+}
diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ImportModel.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ImportModel.java
new file mode 100644
index 0000000000..12d966a492
--- /dev/null
+++ b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ImportModel.java
@@ -0,0 +1,29 @@
+package org.apache.maven.shared.model;
+
+/*
+ * 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.
+ */
+
+import java.util.List;
+
+public interface ImportModel {
+
+ String getId();
+
+ List getModelProperties();
+}
diff --git a/maven-project/src/main/java/org/apache/maven/project/injection/ModelDefaultsInjector.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/InputStreamDomainModel.java
similarity index 69%
rename from maven-project/src/main/java/org/apache/maven/project/injection/ModelDefaultsInjector.java
rename to maven-shared-model/src/main/java/org/apache/maven/shared/model/InputStreamDomainModel.java
index cc40aebdb7..ca888a95bd 100644
--- a/maven-project/src/main/java/org/apache/maven/project/injection/ModelDefaultsInjector.java
+++ b/maven-shared-model/src/main/java/org/apache/maven/shared/model/InputStreamDomainModel.java
@@ -1,4 +1,4 @@
-package org.apache.maven.project.injection;
+package org.apache.maven.shared.model;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -19,17 +19,19 @@ package org.apache.maven.project.injection;
* under the License.
*/
-import org.apache.maven.model.Model;
-import org.apache.maven.model.Plugin;
+import java.io.InputStream;
/**
- * @author jdcasey Created on Feb 1, 2005
+ * Provides service for obtaining input stream of domain model.
*/
-public interface ModelDefaultsInjector
+public interface InputStreamDomainModel
+ extends DomainModel
{
- String ROLE = ModelDefaultsInjector.class.getName();
- void injectDefaults( Model model );
-
- void mergePluginWithDefaults( Plugin plugin, Plugin def );
-}
\ No newline at end of file
+ /**
+ * Returns input stream of domain model.
+ *
+ * @return input stream of domain model
+ */
+ InputStream getInputStream();
+}
diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/InterpolatorProperty.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/InterpolatorProperty.java
new file mode 100644
index 0000000000..0cea576b5e
--- /dev/null
+++ b/maven-shared-model/src/main/java/org/apache/maven/shared/model/InterpolatorProperty.java
@@ -0,0 +1,115 @@
+package org.apache.maven.shared.model;
+
+/*
+ * 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.
+ */
+
+/**
+ * Provides interpolator property information.
+ */
+public final class InterpolatorProperty
+{
+ /**
+ * The key (or name) of the property
+ */
+ private final String key;
+
+ /**
+ * The value of the property
+ */
+ private final String value;
+
+ /**
+ * Constructor
+ *
+ * @param key the key (or name) of the property. May not be null
+ * @param value the value of the property. May not be null.
+ */
+ public InterpolatorProperty( String key, String value )
+ {
+ if ( key == null )
+ {
+ throw new IllegalArgumentException( "key: null" );
+ }
+
+ if ( value == null )
+ {
+ throw new IllegalArgumentException( "value: null" );
+ }
+ this.key = key;
+ this.value = value;
+ }
+
+ /**
+ * Returns key (or name) of property.
+ *
+ * @return key (or name) of property
+ */
+ public String getKey()
+ {
+ return key;
+ }
+
+ /**
+ * Returns value of property.
+ *
+ * @return value of property
+ */
+ public String getValue()
+ {
+ return value;
+ }
+
+ /**
+ * Returns true if key values match, otherwise returns false.
+ *
+ * @param o interpolator property to compare
+ * @return true if key values match, otherwise returns false
+ */
+ public boolean equals( Object o )
+ {
+ if ( this == o )
+ {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() )
+ {
+ return false;
+ }
+
+ InterpolatorProperty that = (InterpolatorProperty) o;
+
+ if ( !key.equals( that.key ) )
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns hash code of interpolator property key.
+ *
+ * @return hash code of interpolator property key
+ */
+ public int hashCode()
+ {
+ return key.hashCode();
+ }
+
+}
diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelContainer.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelContainer.java
new file mode 100644
index 0000000000..e9e362405e
--- /dev/null
+++ b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelContainer.java
@@ -0,0 +1,59 @@
+package org.apache.maven.shared.model;
+
+/*
+ * 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.
+ */
+
+import java.util.List;
+
+/**
+ * Provides services for determining actions to take: noop, delete, join. For example, say containers with the same ids
+ * are joined, otherwise one must be deleted.
+ *
+ * then ModelContainerA.containerAction(ModelContainerB) would return delete action for ModelContainerB.
+ */
+public interface ModelContainer
+{
+
+ /**
+ * Returns the model properties contained within the model container. This list must be unmodifiable.
+ *
+ * @return the model properties contained within the model container
+ */
+ List getProperties();
+
+ /**
+ * Returns model container action (noop, delete, join) for the specified model container.
+ *
+ * @param modelContainer the model container to determine the action of
+ * @return model container action (noop, delete, join) for the specified model container
+ */
+ ModelContainerAction containerAction( ModelContainer modelContainer );
+
+ /**
+ * Creates new instance of model container.
+ *
+ * @param modelProperties
+ * @return new instance of model container
+ */
+ ModelContainer createNewInstance( List modelProperties );
+
+}
diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelContainerAction.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelContainerAction.java
new file mode 100644
index 0000000000..95a6717261
--- /dev/null
+++ b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelContainerAction.java
@@ -0,0 +1,41 @@
+package org.apache.maven.shared.model;
+
+/*
+ * 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.
+ */
+
+/**
+ * Model container actions
+ */
+public enum ModelContainerAction
+{
+ /**
+ * Join two containers
+ */
+ JOIN,
+
+ /**
+ * Delete container
+ */
+ DELETE,
+
+ /**
+ * No operation
+ */
+ NOP
+}
diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelContainerFactory.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelContainerFactory.java
new file mode 100644
index 0000000000..abb2d6b107
--- /dev/null
+++ b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelContainerFactory.java
@@ -0,0 +1,48 @@
+package org.apache.maven.shared.model;
+
+/*
+ * 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.
+ */
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Factory for returning model container instances. Unlike most factories, implementations of this class are meant to
+ * create only one type of model container instance.
+ */
+public interface ModelContainerFactory
+{
+
+ /**
+ * Returns collection of URIs associated with this factory.
+ *
+ * @return collection of URIs associated with this factory
+ */
+ Collection getUris();
+
+ /**
+ * Creates a model container instance that contains the specified model properties. The implementing class instance may
+ * modify, add, delete or reorder the list of model properties before placing them into the returned model
+ * container.
+ *
+ * @param modelProperties the model properties to be contained within the model container
+ * @return the model container
+ */
+ ModelContainer create( List modelProperties );
+}
diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelDataSource.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelDataSource.java
new file mode 100644
index 0000000000..16eff4b1f7
--- /dev/null
+++ b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelDataSource.java
@@ -0,0 +1,81 @@
+package org.apache.maven.shared.model;
+
+/*
+ * 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.
+ */
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Provides services for joining, deleting and querying model containers.
+ */
+public interface ModelDataSource
+{
+
+ /**
+ * Join model properties of the specified container a with the specified container b. Any elements of model container
+ * a must take precedence over model container b. All elements of model container A must exist in the data source;
+ * elements of model container b may or may not exist.
+ *
+ * @param a model container with precedence
+ * @param b model container without precedence
+ * @return joined model container
+ */
+ ModelContainer join( ModelContainer a, ModelContainer b )
+ throws DataSourceException;
+
+ /**
+ * Deletes properties of the specified model container from the data source.
+ *
+ * @param modelContainer the model container that holds the properties to be deleted
+ */
+ void delete( ModelContainer modelContainer );
+
+
+ /**
+ * Return copy of underlying model properties. No changes in this list will be reflected in the data source.
+ *
+ * @return copy of underlying model properties
+ */
+ List getModelProperties();
+
+ /**
+ * Returns model containers for the specified URI.
+ *
+ * @param uri
+ * @return
+ */
+ List queryFor( String uri )
+ throws DataSourceException;
+
+
+ /**
+ * Initializes the object with model properties.
+ *
+ * @param modelProperties the model properties that back the data source
+ */
+ void init( List modelProperties, Collection modelContainerFactories );
+
+ /**
+ * Return history of all joins and deletes
+ *
+ * @return history of all joins and deletes
+ */
+ String getEventHistory();
+}
diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelMarshaller.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelMarshaller.java
new file mode 100644
index 0000000000..b88e79eb61
--- /dev/null
+++ b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelMarshaller.java
@@ -0,0 +1,409 @@
+package org.apache.maven.shared.model;
+
+/*
+ * 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.
+ */
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Provides methods for marshalling and unmarshalling XML that does not contain attributes.
+ */
+public final class ModelMarshaller
+{
+
+ /**
+ * Private Constructor
+ */
+ private ModelMarshaller()
+ {
+ }
+
+ /**
+ * Returns list of model properties transformed from the specified input stream.
+ *
+ * @param inputStream input stream containing the xml document. May not be null.
+ * @param baseUri the base uri of every model property. May not be null or empty.
+ * @param collections set of uris that are to be treated as a collection (multiple entries). May be null.
+ * @return list of model properties transformed from the specified input stream.
+ * @throws IOException if there was a problem doing the transform
+ */
+ public static List marshallXmlToModelProperties( InputStream inputStream, String baseUri,
+ Set collections )
+ throws IOException
+ {
+ if ( inputStream == null )
+ {
+ throw new IllegalArgumentException( "inputStream: null" );
+ }
+
+ if ( baseUri == null || baseUri.trim().length() == 0 )
+ {
+ throw new IllegalArgumentException( "baseUri: null" );
+ }
+
+ if ( collections == null )
+ {
+ collections = Collections.emptySet();
+ }
+
+ List modelProperties = new ArrayList();
+ XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
+ xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, "false");
+ xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, "false");
+
+ Uri uri = new Uri( baseUri );
+ String tagName = baseUri;
+ String tagValue = null;
+
+ int depth = 0;
+ XMLStreamReader xmlStreamReader = null;
+ try
+ {
+ xmlStreamReader = xmlInputFactory.createXMLStreamReader( inputStream );
+
+ Map attributes = new HashMap();
+ for ( ; ; xmlStreamReader.next() )
+ {
+ int type = xmlStreamReader.getEventType();
+ switch ( type )
+ {
+
+ case XMLStreamConstants.CHARACTERS:
+ {
+ String tmp = xmlStreamReader.getText();
+ if ( tmp != null && tmp.trim().length() != 0 )
+ {
+ tagValue = tmp;
+ }
+ break;
+ }
+
+ case XMLStreamConstants.START_ELEMENT:
+ {
+ depth++;
+ if ( !tagName.equals( baseUri ) )
+ {
+ modelProperties.add( new ModelProperty( tagName, tagValue ) );
+ if ( !attributes.isEmpty() )
+ {
+ for ( Map.Entry e : attributes.entrySet() )
+ {
+ modelProperties.add( new ModelProperty( e.getKey(), e.getValue() ) );
+ }
+ attributes.clear();
+ }
+ }
+
+ tagName = uri.getUriFor( xmlStreamReader.getName().getLocalPart(), depth );
+ if ( collections.contains( tagName + "#collection" ) )
+ {
+ tagName = tagName + "#collection";
+ uri.addTag( xmlStreamReader.getName().getLocalPart() + "#collection" );
+ }
+ else if(collections.contains( tagName + "#set" ))
+ {
+ tagName = tagName + "#set";
+ uri.addTag( xmlStreamReader.getName().getLocalPart() + "#set" );
+ }
+ else
+ {
+ uri.addTag( xmlStreamReader.getName().getLocalPart() );
+ }
+ tagValue = null;
+
+ }
+ case XMLStreamConstants.ATTRIBUTE:
+ {
+ for ( int i = 0; i < xmlStreamReader.getAttributeCount(); i++ )
+ {
+
+ attributes.put(
+ tagName + "#property/" + xmlStreamReader.getAttributeName( i ).getLocalPart(),
+ xmlStreamReader.getAttributeValue( i ) );
+ }
+ break;
+ }
+ case XMLStreamConstants.END_ELEMENT:
+ {
+ depth--;
+ if ( tagValue == null )
+ {
+ tagValue = "";
+ }
+ break;
+ }
+ case XMLStreamConstants.END_DOCUMENT:
+ {
+ modelProperties.add( new ModelProperty( tagName, tagValue ) );
+ if ( !attributes.isEmpty() )
+ {
+ for ( Map.Entry e : attributes.entrySet() )
+ {
+ modelProperties.add( new ModelProperty( e.getKey(), e.getValue() ) );
+ }
+ attributes.clear();
+ }
+ return modelProperties;
+ }
+ }
+ }
+ }
+ catch ( XMLStreamException e )
+ {
+ throw new IOException( ":" + e.toString() );
+ }
+ finally
+ {
+ if ( xmlStreamReader != null )
+ {
+ try
+ {
+ xmlStreamReader.close();
+ }
+ catch ( XMLStreamException e )
+ {
+ e.printStackTrace();
+ }
+ }
+ try
+ {
+ inputStream.close();
+ }
+ catch ( IOException e )
+ {
+
+ }
+ }
+ }
+
+ /**
+ * Returns XML string unmarshalled from the specified list of model properties
+ *
+ * @param modelProperties the model properties to unmarshal. May not be null or empty
+ * @param baseUri the base uri of every model property. May not be null or empty.
+ * @return XML string unmarshalled from the specified list of model properties
+ * @throws IOException if there was a problem with unmarshalling
+ */
+ public static String unmarshalModelPropertiesToXml( List modelProperties, String baseUri )
+ throws IOException
+ {
+ if ( modelProperties == null || modelProperties.isEmpty() )
+ {
+ throw new IllegalArgumentException( "modelProperties: null or empty" );
+ }
+
+ if ( baseUri == null || baseUri.trim().length() == 0 )
+ {
+ throw new IllegalArgumentException( "baseUri: null or empty" );
+ }
+
+ final int basePosition = baseUri.length();
+
+ StringBuffer sb = new StringBuffer();
+ List lastUriTags = new ArrayList();
+ int n = 1;
+ for ( ModelProperty mp : modelProperties )
+ {
+ String uri = mp.getUri();
+ if ( uri.contains( "#property" ) )
+ {
+ continue;
+ }
+
+ //String val = (mp.getValue() != null) ? "\"" + mp.getValue() + "\"" : null;
+ // System.out.println("new ModelProperty(\"" + mp.getUri() +"\" , " + val +"),");
+ if ( !uri.startsWith( baseUri ) )
+ {
+ throw new IllegalArgumentException(
+ "Passed in model property that does not match baseUri: Property URI = " + uri + ", Base URI = " +
+ baseUri );
+ }
+ List tagNames = getTagNamesFromUri( basePosition, uri );
+ if ( lastUriTags.size() > tagNames.size() )
+ {
+ for ( int i = lastUriTags.size() - 1; i >= tagNames.size(); i-- )
+ {
+ sb.append( toEndTag( lastUriTags.get( i - 1 ) ) );
+ }
+ }
+ String tag = tagNames.get( tagNames.size() - 1 );
+
+ List attributes = new ArrayList();
+ for(int peekIndex = modelProperties.indexOf( mp ) + 1; peekIndex < modelProperties.size(); peekIndex++)
+ {
+ if ( peekIndex <= modelProperties.size() - 1 )
+ {
+ ModelProperty peekProperty = modelProperties.get( peekIndex );
+ if ( peekProperty.getUri().contains( "#property" ) )
+ {
+ attributes.add(peekProperty);
+ }
+ else
+ {
+ break;
+ }
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ sb.append( toStartTag( tag, attributes ) );
+ if ( mp.getResolvedValue() != null )
+ {
+ sb.append( mp.getResolvedValue() );
+ sb.append( toEndTag( tag ) );
+ n = 2;
+ }
+ else if(!attributes.isEmpty())
+ {
+ int pi = modelProperties.indexOf( mp ) + attributes.size() + 1;
+ if ( pi <= modelProperties.size() - 1 )
+ {
+ ModelProperty peekProperty = modelProperties.get( pi );
+ if ( !peekProperty.getUri().startsWith(mp.getUri()) )
+ {
+ if( mp.getResolvedValue() != null )
+ {
+ sb.append( mp.getResolvedValue() );
+ }
+ sb.append( toEndTag( tag ) );
+ n = 2;
+ }
+ }
+ }
+ else
+ {
+ n = 1;
+ }
+ lastUriTags = tagNames;
+ }
+ for ( int i = lastUriTags.size() - n; i >= 1; i-- )
+ {
+ sb.append( toEndTag( lastUriTags.get( i ) ) );
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Returns list of tag names parsed from the specified uri. All #collection parts of the tag are removed from the
+ * tag names.
+ *
+ * @param basePosition the base position in the specified URI to start the parse
+ * @param uri the uri to parse for tag names
+ * @return list of tag names parsed from the specified uri
+ */
+ private static List getTagNamesFromUri( int basePosition, String uri )
+ {
+ return Arrays.asList( uri.substring( basePosition ).replaceAll( "#collection", "" )
+ .replaceAll("#set", "").split( "/" ) );
+ }
+
+ /**
+ * Returns the XML formatted start tag for the specified value and the specified attribute.
+ *
+ * @param value the value to use for the start tag
+ * @param attributes the attribute to use in constructing of start tag
+ * @return the XML formatted start tag for the specified value and the specified attribute
+ */
+ private static String toStartTag( String value, List attributes )
+ {
+ StringBuffer sb = new StringBuffer(); //TODO: Support more than one attribute
+ sb.append( "\r\n<" ).append( value );
+ if ( attributes != null )
+ {
+ for(ModelProperty attribute : attributes)
+ {
+ sb.append( " " ).append(
+ attribute.getUri().substring( attribute.getUri().indexOf( "#property/" ) + 10 ) ).append( "=\"" )
+ .append( attribute.getValue() ).append( "\" " );
+ }
+ }
+ sb.append( ">" );
+ return sb.toString();
+ }
+
+ /**
+ * Returns XML formatted end tag for the specified value.
+ *
+ * @param value the value to use for the end tag
+ * @return xml formatted end tag for the specified value
+ */
+ private static String toEndTag( String value )
+ {
+ if ( value.trim().length() == 0 )
+ {
+ return "";
+ }
+ StringBuffer sb = new StringBuffer();
+ sb.append( "" ).append( value ).append( ">" );
+ return sb.toString();
+ }
+
+ /**
+ * Class for storing information about URIs.
+ */
+ private static class Uri
+ {
+
+ List uris;
+
+ Uri( String baseUri )
+ {
+ uris = new LinkedList();
+ uris.add( baseUri );
+ }
+
+ String getUriFor( String tag, int depth )
+ {
+ setUrisToDepth( depth );
+ StringBuffer sb = new StringBuffer();
+ for ( String tagName : uris )
+ {
+ sb.append( tagName ).append( "/" );
+ }
+ sb.append( tag );
+ return sb.toString();
+ }
+
+ void addTag( String tag )
+ {
+ uris.add( tag );
+ }
+
+ void setUrisToDepth( int depth )
+ {
+ uris = new LinkedList( uris.subList( 0, depth ) );
+ }
+ }
+}
diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelProperty.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelProperty.java
new file mode 100644
index 0000000000..5385918177
--- /dev/null
+++ b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelProperty.java
@@ -0,0 +1,239 @@
+package org.apache.maven.shared.model;
+
+/*
+ * 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.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Maps a URI to a string value, which may be null. This class is immutable.
+ */
+public final class ModelProperty
+{
+
+ /**
+ * A pattern used for finding pom, project and env properties
+ */
+ private static final Pattern EXPRESSION_PATTERN = Pattern.compile( "\\$\\{(pom\\.|project\\.|env\\.)?([^}]+)\\}" );
+
+ /**
+ * URI of the resource
+ */
+ private final String uri;
+
+ /**
+ * Value associated with the uri
+ */
+ private final String value;
+
+ /**
+ * The count of '/' within this model property's uri, which is the depth of its XML nodes.
+ */
+ private final int depth;
+
+ /**
+ * Value of this model property after interpolation
+ */
+ private String resolvedValue;
+
+ /**
+ * List of unresolved expressions within this model property's value
+ */
+ private final List unresolvedExpressions;
+
+ /**
+ * Constructor
+ *
+ * @param uri URI of the resource. May not be null
+ * @param value Value associated with specified uri. Value may be null if uri does not map to primitive type.
+ */
+ public ModelProperty( String uri, String value )
+ {
+ if ( uri == null )
+ {
+ throw new IllegalArgumentException( "uri" );
+ }
+ this.uri = uri;
+ this.value = value;
+ resolvedValue = value;
+
+ unresolvedExpressions = new ArrayList();
+ if ( value != null )
+ {
+ Matcher matcher = EXPRESSION_PATTERN.matcher( value );
+ while ( matcher.find() )
+ {
+ unresolvedExpressions.add( matcher.group( 0 ) );
+ }
+ }
+
+ String uriWithoutProperty;
+ int index = uri.lastIndexOf( "/" );
+ if(index > -1) {
+ uriWithoutProperty = uri.substring( 0, uri.lastIndexOf( "/" ) );
+ if(uriWithoutProperty.endsWith("#property") || uriWithoutProperty.endsWith("combine.children") )
+ {
+ uriWithoutProperty = uriWithoutProperty.substring( 0, uriWithoutProperty.lastIndexOf( "/" ) );
+ }
+ }
+ else
+ {
+ uriWithoutProperty = uri;
+ }
+
+ depth = uriWithoutProperty.split( "/" ).length;
+ }
+
+ /**
+ * Returns URI key
+ *
+ * @return URI key
+ */
+ public String getUri()
+ {
+ return uri;
+ }
+
+ /**
+ * Returns value for the URI key. Value may be null.
+ *
+ * @return value for the URI key. Value may be null
+ */
+ public String getValue()
+ {
+ return value;
+ }
+
+ /**
+ * Value of this model property after interpolation.
+ *
+ * @return value of this model property after interpolation
+ */
+ public String getResolvedValue()
+ {
+ return resolvedValue;
+ }
+
+ /**
+ * Returns true if model property is completely interpolated, otherwise returns false.
+ *
+ * @return true if model property is completely interpolated, otherwise returns false
+ */
+ public boolean isResolved()
+ {
+ return unresolvedExpressions.isEmpty();
+ }
+
+ /**
+ * Returns copy of the uninterpolated model property
+ *
+ * @return copy of the uninterpolated model property
+ */
+ public ModelProperty createCopyOfOriginal()
+ {
+ return new ModelProperty( uri, value );
+ }
+
+ /**
+ * Returns the count of '/' within this model property's uri, which is the depth of its XML nodes.
+ *
+ * @return the count of '/' within this model property's uri, which is the depth of its XML nodes
+ */
+ public int getDepth()
+ {
+ return depth;
+ }
+
+ /**
+ * Returns true if this model property is a direct parent of the specified model property, otherwise returns false.
+ *
+ * @param modelProperty the model property
+ * @return true if this model property is a direct parent of the specified model property, otherwise returns false
+ */
+ public boolean isParentOf( ModelProperty modelProperty )
+ {
+ if ( Math.abs( depth - modelProperty.getDepth() ) > 1 )
+ {
+ return false;
+ }
+ if ( uri.equals( modelProperty.getUri() ) || uri.startsWith( modelProperty.getUri() ) )
+ {
+ return false;
+ }
+ return ( modelProperty.getUri().startsWith( uri ) );
+ }
+
+ /**
+ * Returns this model property as an interpolator property, allowing the interpolation of model elements within
+ * other model elements.
+ *
+ * @param baseUri the base uri of the model property
+ * @return this model property as an interpolator property, allowing the interpolation of model elements within
+ * other model elements
+ */
+ public InterpolatorProperty asInterpolatorProperty( String baseUri )
+ {
+ if ( uri.contains( "#collection" ) || uri.contains("#set") || value == null )
+ {
+ return null;
+ }
+ String key = "${" + uri.replace( baseUri + "/", "" ).replace( "/", "." ) + "}";
+ return new InterpolatorProperty( key, value );
+ }
+
+ /**
+ * Resolves any unresolved model property expressions using the specified interpolator property
+ *
+ * @param property the interpolator property used to resolve
+ */
+ public void resolveWith( InterpolatorProperty property )
+ {
+ if ( property == null )
+ {
+ throw new IllegalArgumentException( "property: null" );
+ }
+ if ( isResolved() )
+ {
+ return;
+ }
+ for ( String expression : unresolvedExpressions )
+ {
+ if ( property.getKey().equals( expression ) )
+ {
+ resolvedValue = resolvedValue.replace( property.getKey(), property.getValue() );
+ unresolvedExpressions.clear();
+ Matcher matcher = EXPRESSION_PATTERN.matcher( resolvedValue );
+ while ( matcher.find() )
+ {
+ unresolvedExpressions.add( matcher.group( 0 ) );
+ }
+ break;
+ }
+ }
+ }
+
+ public String toString()
+ {
+ return "Uri = " + uri + ", Value = " + value + ", Resolved Value = " + resolvedValue + ", Hash = " +
+ this.hashCode();
+ }
+}
diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelPropertyTransformer.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelPropertyTransformer.java
new file mode 100644
index 0000000000..8ed0073502
--- /dev/null
+++ b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelPropertyTransformer.java
@@ -0,0 +1,29 @@
+package org.apache.maven.shared.model;
+
+/*
+ * 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.
+ */
+
+import java.util.List;
+
+public interface ModelPropertyTransformer {
+
+ List transform(List modelProperties);
+
+ String getBaseUri();
+}
diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformer.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformer.java
new file mode 100644
index 0000000000..bb95d2dead
--- /dev/null
+++ b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformer.java
@@ -0,0 +1,55 @@
+package org.apache.maven.shared.model;
+
+/*
+ * 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.
+ */
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Provides services for transforming domain models to property lists and vice versa.
+ * ModelTransformer.transformToDomainModel == ModelTransformer.transformToModelProperties if list of model
+ * properties specified in transformToDomainModel contains only one property with a uri of http://apache.org/model/project.
+ */
+public interface ModelTransformer
+{
+
+ String getBaseUri();
+
+ /**
+ * Transforms specified list of model properties into a single domain model. The list may contain a hierarchy (inheritance) of
+ * model information.
+ *
+ * @param properties list of model properties to transform into domain model. List may not be null.
+ * @return domain model
+ */
+ DomainModel transformToDomainModel( List properties )
+ throws IOException;
+
+ /**
+ * Transforms specified list of domain models to a property list. The list of domain models should be in order of
+ * most specialized to least specialized model.
+ *
+ * @param domainModels list of domain models to transform to a list of model properties. List may not be null.
+ * @return list of model properties
+ */
+ List transformToModelProperties( List domainModels )
+ throws IOException;
+
+}
diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformerContext.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformerContext.java
new file mode 100644
index 0000000000..c79789a7c0
--- /dev/null
+++ b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformerContext.java
@@ -0,0 +1,353 @@
+package org.apache.maven.shared.model;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.shared.model.impl.DefaultModelDataSource;
+
+import java.io.IOException;
+import java.util.*;
+
+
+/**
+ * Primary context for this package. Provides methods for doing transforms.
+ */
+public final class ModelTransformerContext
+{
+ /**
+ * Factories to use for construction of model containers
+ */
+ private final Collection factories;
+
+ /**
+ * List of system and environmental properties to use during interpolation
+ */
+ private final static List systemInterpolatorProperties =
+ new ArrayList();
+
+ static
+ {
+ for ( Map.Entry
+ 4.0.0
+ org.apache.mavenmaven3.0-SNAPSHOTpom
@@ -257,6 +258,7 @@
maven-reporting-apimaven-embeddermaven-workspace
+ maven-shared-modelmaven-toolchain