You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kr...@apache.org on 2015/06/14 19:09:05 UTC
svn commit: r1685427 [2/3] - in /maven/shared/trunk:
maven-common-artifact-filters/src/main/java/org/apache/maven/shared/artifact/filter/resolve/
maven-common-artifact-filters/src/main/java/org/apache/maven/shared/artifact/filter/resolve/transform/
mav...
Modified: maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java?rev=1685427&r1=1685426&r2=1685427&view=diff
==============================================================================
--- maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java (original)
+++ maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java Sun Jun 14 17:09:05 2015
@@ -1,234 +1,234 @@
-package org.apache.maven.shared.dependency.graph.internal;
-
-/*
- * 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.resolver.filter.ArtifactFilter;
-import org.apache.maven.artifact.versioning.VersionRange;
-import org.apache.maven.project.DefaultDependencyResolutionRequest;
-import org.apache.maven.project.DependencyResolutionException;
-import org.apache.maven.project.DependencyResolutionRequest;
-import org.apache.maven.project.DependencyResolutionResult;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.project.ProjectDependenciesResolver;
-import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder;
-import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException;
-import org.apache.maven.shared.dependency.graph.DependencyNode;
-import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.component.annotations.Requirement;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-import org.eclipse.aether.RepositorySystemSession;
-import org.eclipse.aether.graph.Dependency;
-import org.eclipse.aether.version.VersionConstraint;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Wrapper around Eclipse Aether dependency resolver, used in Maven 3.1.
- *
- * @see ProjectDependenciesResolver
- * @author Hervé Boutemy
- * @since 2.1
- */
-@Component( role = DependencyGraphBuilder.class, hint = "maven31" )
-public class Maven31DependencyGraphBuilder
- extends AbstractLogEnabled
- implements DependencyGraphBuilder
-{
- @Requirement
- private ProjectDependenciesResolver resolver;
-
- @Requirement
- private ArtifactFactory factory;
-
- /**
- * Builds the dependency graph for Maven 3.1+.
- *
- * @param project the project
- * @param filter artifact filter (can be <code>null</code>)
- * @return DependencyNode containing the dependency graph.
- * @throws DependencyGraphBuilderException if some of the dependencies could not be resolved.
- */
- @Override
- public DependencyNode buildDependencyGraph( MavenProject project, ArtifactFilter filter )
- throws DependencyGraphBuilderException
- {
- return buildDependencyGraph( project, filter, null );
- }
-
- /**
- * Builds the dependency graph for Maven 3.1+, eventually hacking for collecting projects from
- * reactor not yet built.
- *
- * @param project the project
- * @param filter artifact filter (can be <code>null</code>)
- * @param reactorProjects Collection of those projects contained in the reactor (can be <code>null</code>).
- * @return DependencyNode containing the dependency graph.
- * @throws DependencyGraphBuilderException if some of the dependencies could not be resolved.
- */
- @Override
- public DependencyNode buildDependencyGraph( MavenProject project, ArtifactFilter filter,
- Collection<MavenProject> reactorProjects )
- throws DependencyGraphBuilderException
- {
- ProjectBuildingRequest projectBuildingRequest =
- (ProjectBuildingRequest) Invoker.invoke( project, "getProjectBuildingRequest" );
-
- RepositorySystemSession session =
- (RepositorySystemSession) Invoker.invoke( projectBuildingRequest, "getRepositorySession" );
-
- /*
- * if ( Boolean.TRUE != ( (Boolean) session.getConfigProperties().get(
- * DependencyManagerUtils.NODE_DATA_PREMANAGED_VERSION ) ) ) { DefaultRepositorySystemSession newSession = new
- * DefaultRepositorySystemSession( session ); newSession.setConfigProperty(
- * DependencyManagerUtils.NODE_DATA_PREMANAGED_VERSION, true ); session = newSession; }
- */
-
- final DependencyResolutionRequest request = new DefaultDependencyResolutionRequest();
- request.setMavenProject( project );
- Invoker.invoke( request, "setRepositorySession", RepositorySystemSession.class, session );
-
- final DependencyResolutionResult result = resolveDependencies( request, reactorProjects );
- org.eclipse.aether.graph.DependencyNode graph =
- (org.eclipse.aether.graph.DependencyNode) Invoker.invoke( DependencyResolutionResult.class, result,
- "getDependencyGraph" );
-
- return buildDependencyNode( null, graph, project.getArtifact(), filter );
- }
-
- private DependencyResolutionResult resolveDependencies( DependencyResolutionRequest request,
- Collection<MavenProject> reactorProjects )
- throws DependencyGraphBuilderException
- {
- try
- {
- return resolver.resolve( request );
- }
- catch ( DependencyResolutionException e )
- {
- if ( reactorProjects == null )
- {
- throw new DependencyGraphBuilderException( "Could not resolve following dependencies: "
- + e.getResult().getUnresolvedDependencies(), e );
- }
-
- // try collecting from reactor
- return collectDependenciesFromReactor( e, reactorProjects );
- }
- }
-
- private DependencyResolutionResult collectDependenciesFromReactor( DependencyResolutionException e,
- Collection<MavenProject> reactorProjects )
- throws DependencyGraphBuilderException
- {
- DependencyResolutionResult result = e.getResult();
-
- List<Dependency> reactorDeps = getReactorDependencies( reactorProjects, result.getUnresolvedDependencies() );
- result.getUnresolvedDependencies().removeAll( reactorDeps );
- Invoker.invoke( result.getResolvedDependencies(), "addAll", Collection.class, reactorDeps );
-
- if ( !result.getUnresolvedDependencies().isEmpty() )
- {
- throw new DependencyGraphBuilderException( "Could not resolve nor collect following dependencies: "
- + result.getUnresolvedDependencies(), e );
- }
-
- return result;
- }
-
- private List<Dependency> getReactorDependencies( Collection<MavenProject> reactorProjects, List<?> dependencies )
- {
- Set<ArtifactKey> reactorProjectsIds = new HashSet<ArtifactKey>();
- for ( MavenProject project : reactorProjects )
- {
- reactorProjectsIds.add( new ArtifactKey( project ) );
- }
-
- List<Dependency> reactorDeps = new ArrayList<Dependency>();
- for ( Object untypedDependency : dependencies )
- {
- Dependency dependency = (Dependency) untypedDependency;
- org.eclipse.aether.artifact.Artifact depArtifact = dependency.getArtifact();
-
- ArtifactKey key =
- new ArtifactKey( depArtifact.getGroupId(), depArtifact.getArtifactId(), depArtifact.getVersion() );
-
- if ( reactorProjectsIds.contains( key ) )
- {
- reactorDeps.add( dependency );
- }
- }
-
- return reactorDeps;
- }
-
- private Artifact getDependencyArtifact( Dependency dep )
- {
- org.eclipse.aether.artifact.Artifact artifact = dep.getArtifact();
-
- return factory.createDependencyArtifact( artifact.getGroupId(), artifact.getArtifactId(),
- VersionRange.createFromVersion( artifact.getVersion() ),
- artifact.getProperty( "type", artifact.getExtension() ),
- artifact.getClassifier(), dep.getScope(), dep.isOptional() );
- }
-
- private DependencyNode buildDependencyNode( DependencyNode parent, org.eclipse.aether.graph.DependencyNode node,
- Artifact artifact, ArtifactFilter filter )
- {
- String premanagedVersion = null; // DependencyManagerUtils.getPremanagedVersion( node );
- String premanagedScope = null; // DependencyManagerUtils.getPremanagedScope( node );
-
- DefaultDependencyNode current =
- new DefaultDependencyNode( parent, artifact, premanagedVersion, premanagedScope,
- getVersionSelectedFromRange( node.getVersionConstraint() ) );
-
- List<DependencyNode> nodes = new ArrayList<DependencyNode>( node.getChildren().size() );
- for ( org.eclipse.aether.graph.DependencyNode child : node.getChildren() )
- {
- Artifact childArtifact = getDependencyArtifact( child.getDependency() );
-
- if ( ( filter == null ) || filter.include( childArtifact ) )
- {
- nodes.add( buildDependencyNode( current, child, childArtifact, filter ) );
- }
- }
-
- current.setChildren( Collections.unmodifiableList( nodes ) );
-
- return current;
- }
-
- private String getVersionSelectedFromRange( VersionConstraint constraint )
- {
- if ( ( constraint == null ) || ( constraint.getVersion() != null ) )
- {
- return null;
- }
-
- return constraint.getRange().toString();
- }
-}
+package org.apache.maven.shared.dependency.graph.internal;
+
+/*
+ * 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.resolver.filter.ArtifactFilter;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.project.DefaultDependencyResolutionRequest;
+import org.apache.maven.project.DependencyResolutionException;
+import org.apache.maven.project.DependencyResolutionRequest;
+import org.apache.maven.project.DependencyResolutionResult;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.maven.project.ProjectDependenciesResolver;
+import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder;
+import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException;
+import org.apache.maven.shared.dependency.graph.DependencyNode;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.graph.Dependency;
+import org.eclipse.aether.version.VersionConstraint;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Wrapper around Eclipse Aether dependency resolver, used in Maven 3.1.
+ *
+ * @see ProjectDependenciesResolver
+ * @author Hervé Boutemy
+ * @since 2.1
+ */
+@Component( role = DependencyGraphBuilder.class, hint = "maven31" )
+public class Maven31DependencyGraphBuilder
+ extends AbstractLogEnabled
+ implements DependencyGraphBuilder
+{
+ @Requirement
+ private ProjectDependenciesResolver resolver;
+
+ @Requirement
+ private ArtifactFactory factory;
+
+ /**
+ * Builds the dependency graph for Maven 3.1+.
+ *
+ * @param project the project
+ * @param filter artifact filter (can be <code>null</code>)
+ * @return DependencyNode containing the dependency graph.
+ * @throws DependencyGraphBuilderException if some of the dependencies could not be resolved.
+ */
+ @Override
+ public DependencyNode buildDependencyGraph( MavenProject project, ArtifactFilter filter )
+ throws DependencyGraphBuilderException
+ {
+ return buildDependencyGraph( project, filter, null );
+ }
+
+ /**
+ * Builds the dependency graph for Maven 3.1+, eventually hacking for collecting projects from
+ * reactor not yet built.
+ *
+ * @param project the project
+ * @param filter artifact filter (can be <code>null</code>)
+ * @param reactorProjects Collection of those projects contained in the reactor (can be <code>null</code>).
+ * @return DependencyNode containing the dependency graph.
+ * @throws DependencyGraphBuilderException if some of the dependencies could not be resolved.
+ */
+ @Override
+ public DependencyNode buildDependencyGraph( MavenProject project, ArtifactFilter filter,
+ Collection<MavenProject> reactorProjects )
+ throws DependencyGraphBuilderException
+ {
+ ProjectBuildingRequest projectBuildingRequest =
+ (ProjectBuildingRequest) Invoker.invoke( project, "getProjectBuildingRequest" );
+
+ RepositorySystemSession session =
+ (RepositorySystemSession) Invoker.invoke( projectBuildingRequest, "getRepositorySession" );
+
+ /*
+ * if ( Boolean.TRUE != ( (Boolean) session.getConfigProperties().get(
+ * DependencyManagerUtils.NODE_DATA_PREMANAGED_VERSION ) ) ) { DefaultRepositorySystemSession newSession = new
+ * DefaultRepositorySystemSession( session ); newSession.setConfigProperty(
+ * DependencyManagerUtils.NODE_DATA_PREMANAGED_VERSION, true ); session = newSession; }
+ */
+
+ final DependencyResolutionRequest request = new DefaultDependencyResolutionRequest();
+ request.setMavenProject( project );
+ Invoker.invoke( request, "setRepositorySession", RepositorySystemSession.class, session );
+
+ final DependencyResolutionResult result = resolveDependencies( request, reactorProjects );
+ org.eclipse.aether.graph.DependencyNode graph =
+ (org.eclipse.aether.graph.DependencyNode) Invoker.invoke( DependencyResolutionResult.class, result,
+ "getDependencyGraph" );
+
+ return buildDependencyNode( null, graph, project.getArtifact(), filter );
+ }
+
+ private DependencyResolutionResult resolveDependencies( DependencyResolutionRequest request,
+ Collection<MavenProject> reactorProjects )
+ throws DependencyGraphBuilderException
+ {
+ try
+ {
+ return resolver.resolve( request );
+ }
+ catch ( DependencyResolutionException e )
+ {
+ if ( reactorProjects == null )
+ {
+ throw new DependencyGraphBuilderException( "Could not resolve following dependencies: "
+ + e.getResult().getUnresolvedDependencies(), e );
+ }
+
+ // try collecting from reactor
+ return collectDependenciesFromReactor( e, reactorProjects );
+ }
+ }
+
+ private DependencyResolutionResult collectDependenciesFromReactor( DependencyResolutionException e,
+ Collection<MavenProject> reactorProjects )
+ throws DependencyGraphBuilderException
+ {
+ DependencyResolutionResult result = e.getResult();
+
+ List<Dependency> reactorDeps = getReactorDependencies( reactorProjects, result.getUnresolvedDependencies() );
+ result.getUnresolvedDependencies().removeAll( reactorDeps );
+ Invoker.invoke( result.getResolvedDependencies(), "addAll", Collection.class, reactorDeps );
+
+ if ( !result.getUnresolvedDependencies().isEmpty() )
+ {
+ throw new DependencyGraphBuilderException( "Could not resolve nor collect following dependencies: "
+ + result.getUnresolvedDependencies(), e );
+ }
+
+ return result;
+ }
+
+ private List<Dependency> getReactorDependencies( Collection<MavenProject> reactorProjects, List<?> dependencies )
+ {
+ Set<ArtifactKey> reactorProjectsIds = new HashSet<ArtifactKey>();
+ for ( MavenProject project : reactorProjects )
+ {
+ reactorProjectsIds.add( new ArtifactKey( project ) );
+ }
+
+ List<Dependency> reactorDeps = new ArrayList<Dependency>();
+ for ( Object untypedDependency : dependencies )
+ {
+ Dependency dependency = (Dependency) untypedDependency;
+ org.eclipse.aether.artifact.Artifact depArtifact = dependency.getArtifact();
+
+ ArtifactKey key =
+ new ArtifactKey( depArtifact.getGroupId(), depArtifact.getArtifactId(), depArtifact.getVersion() );
+
+ if ( reactorProjectsIds.contains( key ) )
+ {
+ reactorDeps.add( dependency );
+ }
+ }
+
+ return reactorDeps;
+ }
+
+ private Artifact getDependencyArtifact( Dependency dep )
+ {
+ org.eclipse.aether.artifact.Artifact artifact = dep.getArtifact();
+
+ return factory.createDependencyArtifact( artifact.getGroupId(), artifact.getArtifactId(),
+ VersionRange.createFromVersion( artifact.getVersion() ),
+ artifact.getProperty( "type", artifact.getExtension() ),
+ artifact.getClassifier(), dep.getScope(), dep.isOptional() );
+ }
+
+ private DependencyNode buildDependencyNode( DependencyNode parent, org.eclipse.aether.graph.DependencyNode node,
+ Artifact artifact, ArtifactFilter filter )
+ {
+ String premanagedVersion = null; // DependencyManagerUtils.getPremanagedVersion( node );
+ String premanagedScope = null; // DependencyManagerUtils.getPremanagedScope( node );
+
+ DefaultDependencyNode current =
+ new DefaultDependencyNode( parent, artifact, premanagedVersion, premanagedScope,
+ getVersionSelectedFromRange( node.getVersionConstraint() ) );
+
+ List<DependencyNode> nodes = new ArrayList<DependencyNode>( node.getChildren().size() );
+ for ( org.eclipse.aether.graph.DependencyNode child : node.getChildren() )
+ {
+ Artifact childArtifact = getDependencyArtifact( child.getDependency() );
+
+ if ( ( filter == null ) || filter.include( childArtifact ) )
+ {
+ nodes.add( buildDependencyNode( current, child, childArtifact, filter ) );
+ }
+ }
+
+ current.setChildren( Collections.unmodifiableList( nodes ) );
+
+ return current;
+ }
+
+ private String getVersionSelectedFromRange( VersionConstraint constraint )
+ {
+ if ( ( constraint == null ) || ( constraint.getVersion() != null ) )
+ {
+ return null;
+ }
+
+ return constraint.getRange().toString();
+ }
+}
Modified: maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/AbstractInterpolatorFilterReaderLineEndingTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/AbstractInterpolatorFilterReaderLineEndingTest.java?rev=1685427&r1=1685426&r2=1685427&view=diff
==============================================================================
--- maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/AbstractInterpolatorFilterReaderLineEndingTest.java (original)
+++ maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/AbstractInterpolatorFilterReaderLineEndingTest.java Sun Jun 14 17:09:05 2015
@@ -1,122 +1,122 @@
-package org.apache.maven.shared.filtering;
-
-/*
- * 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 static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Matchers.isA;
-import static org.mockito.Mockito.when;
-
-import java.io.Reader;
-import java.io.StringReader;
-
-import org.codehaus.plexus.interpolation.Interpolator;
-import org.codehaus.plexus.interpolation.RecursionInterceptor;
-import org.codehaus.plexus.util.IOUtil;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-public abstract class AbstractInterpolatorFilterReaderLineEndingTest
-{
-
- @Mock
- private Interpolator interpolator;
-
- @Before
- public void onSetup()
- {
- MockitoAnnotations.initMocks( this );
- }
-
- @Test
- public void testDefaults()
- throws Exception
- {
- when( interpolator.interpolate( eq( "${a}" ), eq( "" ), isA( RecursionInterceptor.class ) ) ).thenReturn( "DONE_A" );
-
- Reader in = new StringReader( "text without expression" );
- Reader reader = getDollarBracesReader( in, interpolator, "\\" );
- assertEquals( "text without expression", IOUtil.toString( reader ) );
-
- in = new StringReader( "valid expression ${a}" );
- reader = getDollarBracesReader( in, interpolator, null );
- assertEquals( "valid expression DONE_A", IOUtil.toString( reader ) );
-
- in = new StringReader( "empty expression ${}" );
- reader = getDollarBracesReader( in, interpolator, null );
- assertEquals( "empty expression ${}", IOUtil.toString( reader ) );
-
- in = new StringReader( "dollar space expression $ {a}" );
- reader = getDollarBracesReader( in, interpolator, "\\" );
- assertEquals( "dollar space expression $ {a}", IOUtil.toString( reader ) );
-
- in = new StringReader( "space in expression ${ a}" );
- reader = getDollarBracesReader( in, interpolator, "\\" );
- assertEquals( "space in expression ${ a}", IOUtil.toString( reader ) );
-
- in = new StringReader( "escape dollar with expression \\${a}" );
- reader = getDollarBracesReader( in, interpolator, "\\" );
- assertEquals( "escape dollar with expression ${a}", IOUtil.toString( reader ) );
-
- in = new StringReader( "unknown expression ${unknown}" );
- reader = getDollarBracesReader( in, interpolator, "\\" );
- assertEquals( "unknown expression ${unknown}", IOUtil.toString( reader ) );
- }
-
- // MSHARED-198: custom delimiters doesn't work as expected
- @Test
- public void testCustomDelimiters()
- throws Exception
- {
- when( interpolator.interpolate( eq( "aaaFILTER.a.MEaaa" ), eq( "" ), isA( RecursionInterceptor.class ) ) ).thenReturn( "DONE" );
- when( interpolator.interpolate( eq( "abcFILTER.a.MEabc" ), eq( "" ), isA( RecursionInterceptor.class ) ) ).thenReturn( "DONE" );
-
- Reader in = new StringReader( "aaaFILTER.a.MEaaa" );
- Reader reader = getAaa_AaaReader( in, interpolator );
-
- assertEquals( "DONE", IOUtil.toString( reader ) );
-
- in = new StringReader( "abcFILTER.a.MEabc" );
- reader = getAbc_AbcReader( in, interpolator );
- assertEquals( "DONE", IOUtil.toString( reader ) );
- }
-
- // MSHARED-235: reader exceeds readAheadLimit
- @Test
- public void testMarkInvalid()
- throws Exception
- {
- Reader in = new StringReader( "@\").replace(p,\"]\").replace(q,\"" );
- Reader reader = getAtReader( in, interpolator, "\\" );
-
- assertEquals( "@\").replace(p,\"]\").replace(q,\"", IOUtil.toString( reader ) );
- }
-
- protected abstract Reader getAbc_AbcReader( Reader in, Interpolator interpolator );
-
- protected abstract Reader getAaa_AaaReader( Reader in, Interpolator interpolator );
-
- protected abstract Reader getDollarBracesReader( Reader in, Interpolator interpolator, String escapeString );
-
- protected abstract Reader getAtReader( Reader in, Interpolator interpolator, String escapeString );
-
+package org.apache.maven.shared.filtering;
+
+/*
+ * 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 static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.isA;
+import static org.mockito.Mockito.when;
+
+import java.io.Reader;
+import java.io.StringReader;
+
+import org.codehaus.plexus.interpolation.Interpolator;
+import org.codehaus.plexus.interpolation.RecursionInterceptor;
+import org.codehaus.plexus.util.IOUtil;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+public abstract class AbstractInterpolatorFilterReaderLineEndingTest
+{
+
+ @Mock
+ private Interpolator interpolator;
+
+ @Before
+ public void onSetup()
+ {
+ MockitoAnnotations.initMocks( this );
+ }
+
+ @Test
+ public void testDefaults()
+ throws Exception
+ {
+ when( interpolator.interpolate( eq( "${a}" ), eq( "" ), isA( RecursionInterceptor.class ) ) ).thenReturn( "DONE_A" );
+
+ Reader in = new StringReader( "text without expression" );
+ Reader reader = getDollarBracesReader( in, interpolator, "\\" );
+ assertEquals( "text without expression", IOUtil.toString( reader ) );
+
+ in = new StringReader( "valid expression ${a}" );
+ reader = getDollarBracesReader( in, interpolator, null );
+ assertEquals( "valid expression DONE_A", IOUtil.toString( reader ) );
+
+ in = new StringReader( "empty expression ${}" );
+ reader = getDollarBracesReader( in, interpolator, null );
+ assertEquals( "empty expression ${}", IOUtil.toString( reader ) );
+
+ in = new StringReader( "dollar space expression $ {a}" );
+ reader = getDollarBracesReader( in, interpolator, "\\" );
+ assertEquals( "dollar space expression $ {a}", IOUtil.toString( reader ) );
+
+ in = new StringReader( "space in expression ${ a}" );
+ reader = getDollarBracesReader( in, interpolator, "\\" );
+ assertEquals( "space in expression ${ a}", IOUtil.toString( reader ) );
+
+ in = new StringReader( "escape dollar with expression \\${a}" );
+ reader = getDollarBracesReader( in, interpolator, "\\" );
+ assertEquals( "escape dollar with expression ${a}", IOUtil.toString( reader ) );
+
+ in = new StringReader( "unknown expression ${unknown}" );
+ reader = getDollarBracesReader( in, interpolator, "\\" );
+ assertEquals( "unknown expression ${unknown}", IOUtil.toString( reader ) );
+ }
+
+ // MSHARED-198: custom delimiters doesn't work as expected
+ @Test
+ public void testCustomDelimiters()
+ throws Exception
+ {
+ when( interpolator.interpolate( eq( "aaaFILTER.a.MEaaa" ), eq( "" ), isA( RecursionInterceptor.class ) ) ).thenReturn( "DONE" );
+ when( interpolator.interpolate( eq( "abcFILTER.a.MEabc" ), eq( "" ), isA( RecursionInterceptor.class ) ) ).thenReturn( "DONE" );
+
+ Reader in = new StringReader( "aaaFILTER.a.MEaaa" );
+ Reader reader = getAaa_AaaReader( in, interpolator );
+
+ assertEquals( "DONE", IOUtil.toString( reader ) );
+
+ in = new StringReader( "abcFILTER.a.MEabc" );
+ reader = getAbc_AbcReader( in, interpolator );
+ assertEquals( "DONE", IOUtil.toString( reader ) );
+ }
+
+ // MSHARED-235: reader exceeds readAheadLimit
+ @Test
+ public void testMarkInvalid()
+ throws Exception
+ {
+ Reader in = new StringReader( "@\").replace(p,\"]\").replace(q,\"" );
+ Reader reader = getAtReader( in, interpolator, "\\" );
+
+ assertEquals( "@\").replace(p,\"]\").replace(q,\"", IOUtil.toString( reader ) );
+ }
+
+ protected abstract Reader getAbc_AbcReader( Reader in, Interpolator interpolator );
+
+ protected abstract Reader getAaa_AaaReader( Reader in, Interpolator interpolator );
+
+ protected abstract Reader getDollarBracesReader( Reader in, Interpolator interpolator, String escapeString );
+
+ protected abstract Reader getAtReader( Reader in, Interpolator interpolator, String escapeString );
+
}
\ No newline at end of file
Modified: maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/InterpolatorFilterReaderLineEndingTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/InterpolatorFilterReaderLineEndingTest.java?rev=1685427&r1=1685426&r2=1685427&view=diff
==============================================================================
--- maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/InterpolatorFilterReaderLineEndingTest.java (original)
+++ maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/InterpolatorFilterReaderLineEndingTest.java Sun Jun 14 17:09:05 2015
@@ -1,58 +1,58 @@
-package org.apache.maven.shared.filtering;
-
-/*
- * 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.Reader;
-
-import org.codehaus.plexus.interpolation.Interpolator;
-
-public class InterpolatorFilterReaderLineEndingTest
- extends AbstractInterpolatorFilterReaderLineEndingTest
-{
- @Override
- protected Reader getAaa_AaaReader( Reader in, Interpolator interpolator )
- {
- return new InterpolatorFilterReaderLineEnding( in, interpolator, "aaa", "aaa", true );
- }
-
- @Override
- protected Reader getAbc_AbcReader( Reader in, Interpolator interpolator )
- {
- return new InterpolatorFilterReaderLineEnding( in, interpolator, "abc", "abc", true );
- }
-
- @Override
- protected Reader getDollarBracesReader( Reader in, Interpolator interpolator, String escapeString )
- {
- InterpolatorFilterReaderLineEnding reader =
- new InterpolatorFilterReaderLineEnding( in, interpolator, "${", "}", true );
- reader.setEscapeString( escapeString );
- return reader;
- }
-
- @Override
- protected Reader getAtReader( Reader in, Interpolator interpolator, String escapeString )
- {
- InterpolatorFilterReaderLineEnding reader =
- new InterpolatorFilterReaderLineEnding( in, interpolator, "@", "@", true );
- reader.setEscapeString( escapeString );
- return reader;
- }
-}
+package org.apache.maven.shared.filtering;
+
+/*
+ * 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.Reader;
+
+import org.codehaus.plexus.interpolation.Interpolator;
+
+public class InterpolatorFilterReaderLineEndingTest
+ extends AbstractInterpolatorFilterReaderLineEndingTest
+{
+ @Override
+ protected Reader getAaa_AaaReader( Reader in, Interpolator interpolator )
+ {
+ return new InterpolatorFilterReaderLineEnding( in, interpolator, "aaa", "aaa", true );
+ }
+
+ @Override
+ protected Reader getAbc_AbcReader( Reader in, Interpolator interpolator )
+ {
+ return new InterpolatorFilterReaderLineEnding( in, interpolator, "abc", "abc", true );
+ }
+
+ @Override
+ protected Reader getDollarBracesReader( Reader in, Interpolator interpolator, String escapeString )
+ {
+ InterpolatorFilterReaderLineEnding reader =
+ new InterpolatorFilterReaderLineEnding( in, interpolator, "${", "}", true );
+ reader.setEscapeString( escapeString );
+ return reader;
+ }
+
+ @Override
+ protected Reader getAtReader( Reader in, Interpolator interpolator, String escapeString )
+ {
+ InterpolatorFilterReaderLineEnding reader =
+ new InterpolatorFilterReaderLineEnding( in, interpolator, "@", "@", true );
+ reader.setEscapeString( escapeString );
+ return reader;
+ }
+}
Modified: maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/MultiDelimiterInterpolatorFilterReaderLineEndingTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/MultiDelimiterInterpolatorFilterReaderLineEndingTest.java?rev=1685427&r1=1685426&r2=1685427&view=diff
==============================================================================
--- maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/MultiDelimiterInterpolatorFilterReaderLineEndingTest.java (original)
+++ maven/shared/trunk/maven-filtering/src/test/java/org/apache/maven/shared/filtering/MultiDelimiterInterpolatorFilterReaderLineEndingTest.java Sun Jun 14 17:09:05 2015
@@ -1,124 +1,124 @@
-package org.apache.maven.shared.filtering;
-
-/*
- * 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 static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Matchers.isA;
-import static org.mockito.Mockito.when;
-
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-
-import org.codehaus.plexus.interpolation.Interpolator;
-import org.codehaus.plexus.interpolation.RecursionInterceptor;
-import org.codehaus.plexus.util.IOUtil;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-public class MultiDelimiterInterpolatorFilterReaderLineEndingTest
- extends AbstractInterpolatorFilterReaderLineEndingTest
-{
-
- @Mock
- private Interpolator interpolator;
-
- @Before
- public void onSetup()
- {
- MockitoAnnotations.initMocks( this );
- }
-
- @Override
- protected Reader getAaa_AaaReader( Reader in, Interpolator interpolator )
- {
- MultiDelimiterInterpolatorFilterReaderLineEnding reader =
- new MultiDelimiterInterpolatorFilterReaderLineEnding( in, interpolator, true );
- reader.setDelimiterSpecs( Collections.singleton( "aaa*aaa" ) );
- return reader;
- }
-
- @Override
- protected Reader getAbc_AbcReader( Reader in, Interpolator interpolator )
- {
- MultiDelimiterInterpolatorFilterReaderLineEnding reader =
- new MultiDelimiterInterpolatorFilterReaderLineEnding( in, interpolator, true );
- reader.setDelimiterSpecs( Collections.singleton( "abc*abc" ) );
- return reader;
- }
-
- @Override
- protected Reader getDollarBracesReader( Reader in, Interpolator interpolator, String escapeString )
- {
- MultiDelimiterInterpolatorFilterReaderLineEnding reader =
- new MultiDelimiterInterpolatorFilterReaderLineEnding( in, interpolator, true );
- reader.setDelimiterSpecs( Collections.singleton( "${*}" ) );
- reader.setEscapeString( escapeString );
- return reader;
- }
-
- @Override
- protected Reader getAtReader( Reader in, Interpolator interpolator, String escapeString )
- {
- MultiDelimiterInterpolatorFilterReaderLineEnding reader =
- new MultiDelimiterInterpolatorFilterReaderLineEnding( in, interpolator, true );
- reader.setDelimiterSpecs( Collections.singleton( "@" ) );
- reader.setEscapeString( escapeString );
- return reader;
- }
-
- // MSHARED-199: Filtering doesn't work if 2 delimiters are used on the same line, the first one being left open
- @Test
- public void testLineWithSingleAtAndExpression()
- throws Exception
- {
- when( interpolator.interpolate( eq( "${foo}" ), eq( "" ), isA( RecursionInterceptor.class ) ) ).thenReturn( "bar" );
-
- Reader in = new StringReader( "toto@titi.com ${foo}" );
- MultiDelimiterInterpolatorFilterReaderLineEnding reader =
- new MultiDelimiterInterpolatorFilterReaderLineEnding( in, interpolator, true );
- reader.setDelimiterSpecs( new HashSet<String>( Arrays.asList( "${*}", "@" ) ) );
-
- assertEquals( "toto@titi.com bar", IOUtil.toString( reader ) );
- }
-
- // http://stackoverflow.com/questions/21786805/maven-war-plugin-customize-filter-delimitters-in-webresources/
- @Test
- public void testAtDollarExpression()
- throws Exception
- {
- when( interpolator.interpolate( eq( "${db.server}" ), eq( "" ), isA( RecursionInterceptor.class ) ) ).thenReturn( "DB_SERVER" );
- when( interpolator.interpolate( eq( "${db.port}" ), eq( "" ), isA( RecursionInterceptor.class ) ) ).thenReturn( "DB_PORT" );
- when( interpolator.interpolate( eq( "${db.name}" ), eq( "" ), isA( RecursionInterceptor.class ) ) ).thenReturn( "DB_NAME" );
-
- Reader in = new StringReader( " url=\"jdbc:oracle:thin:\\@${db.server}:${db.port}:${db.name}\"" );
- MultiDelimiterInterpolatorFilterReaderLineEnding reader =
- new MultiDelimiterInterpolatorFilterReaderLineEnding( in, interpolator, true );
- reader.setEscapeString( "\\" );
- reader.setDelimiterSpecs( new HashSet<String>( Arrays.asList( "${*}", "@" ) ) );
-
- assertEquals( " url=\"jdbc:oracle:thin:@DB_SERVER:DB_PORT:DB_NAME\"", IOUtil.toString( reader ) );
- }
-}
+package org.apache.maven.shared.filtering;
+
+/*
+ * 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 static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.isA;
+import static org.mockito.Mockito.when;
+
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+
+import org.codehaus.plexus.interpolation.Interpolator;
+import org.codehaus.plexus.interpolation.RecursionInterceptor;
+import org.codehaus.plexus.util.IOUtil;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+public class MultiDelimiterInterpolatorFilterReaderLineEndingTest
+ extends AbstractInterpolatorFilterReaderLineEndingTest
+{
+
+ @Mock
+ private Interpolator interpolator;
+
+ @Before
+ public void onSetup()
+ {
+ MockitoAnnotations.initMocks( this );
+ }
+
+ @Override
+ protected Reader getAaa_AaaReader( Reader in, Interpolator interpolator )
+ {
+ MultiDelimiterInterpolatorFilterReaderLineEnding reader =
+ new MultiDelimiterInterpolatorFilterReaderLineEnding( in, interpolator, true );
+ reader.setDelimiterSpecs( Collections.singleton( "aaa*aaa" ) );
+ return reader;
+ }
+
+ @Override
+ protected Reader getAbc_AbcReader( Reader in, Interpolator interpolator )
+ {
+ MultiDelimiterInterpolatorFilterReaderLineEnding reader =
+ new MultiDelimiterInterpolatorFilterReaderLineEnding( in, interpolator, true );
+ reader.setDelimiterSpecs( Collections.singleton( "abc*abc" ) );
+ return reader;
+ }
+
+ @Override
+ protected Reader getDollarBracesReader( Reader in, Interpolator interpolator, String escapeString )
+ {
+ MultiDelimiterInterpolatorFilterReaderLineEnding reader =
+ new MultiDelimiterInterpolatorFilterReaderLineEnding( in, interpolator, true );
+ reader.setDelimiterSpecs( Collections.singleton( "${*}" ) );
+ reader.setEscapeString( escapeString );
+ return reader;
+ }
+
+ @Override
+ protected Reader getAtReader( Reader in, Interpolator interpolator, String escapeString )
+ {
+ MultiDelimiterInterpolatorFilterReaderLineEnding reader =
+ new MultiDelimiterInterpolatorFilterReaderLineEnding( in, interpolator, true );
+ reader.setDelimiterSpecs( Collections.singleton( "@" ) );
+ reader.setEscapeString( escapeString );
+ return reader;
+ }
+
+ // MSHARED-199: Filtering doesn't work if 2 delimiters are used on the same line, the first one being left open
+ @Test
+ public void testLineWithSingleAtAndExpression()
+ throws Exception
+ {
+ when( interpolator.interpolate( eq( "${foo}" ), eq( "" ), isA( RecursionInterceptor.class ) ) ).thenReturn( "bar" );
+
+ Reader in = new StringReader( "toto@titi.com ${foo}" );
+ MultiDelimiterInterpolatorFilterReaderLineEnding reader =
+ new MultiDelimiterInterpolatorFilterReaderLineEnding( in, interpolator, true );
+ reader.setDelimiterSpecs( new HashSet<String>( Arrays.asList( "${*}", "@" ) ) );
+
+ assertEquals( "toto@titi.com bar", IOUtil.toString( reader ) );
+ }
+
+ // http://stackoverflow.com/questions/21786805/maven-war-plugin-customize-filter-delimitters-in-webresources/
+ @Test
+ public void testAtDollarExpression()
+ throws Exception
+ {
+ when( interpolator.interpolate( eq( "${db.server}" ), eq( "" ), isA( RecursionInterceptor.class ) ) ).thenReturn( "DB_SERVER" );
+ when( interpolator.interpolate( eq( "${db.port}" ), eq( "" ), isA( RecursionInterceptor.class ) ) ).thenReturn( "DB_PORT" );
+ when( interpolator.interpolate( eq( "${db.name}" ), eq( "" ), isA( RecursionInterceptor.class ) ) ).thenReturn( "DB_NAME" );
+
+ Reader in = new StringReader( " url=\"jdbc:oracle:thin:\\@${db.server}:${db.port}:${db.name}\"" );
+ MultiDelimiterInterpolatorFilterReaderLineEnding reader =
+ new MultiDelimiterInterpolatorFilterReaderLineEnding( in, interpolator, true );
+ reader.setEscapeString( "\\" );
+ reader.setDelimiterSpecs( new HashSet<String>( Arrays.asList( "${*}", "@" ) ) );
+
+ assertEquals( " url=\"jdbc:oracle:thin:@DB_SERVER:DB_PORT:DB_NAME\"", IOUtil.toString( reader ) );
+ }
+}
Modified: maven/shared/trunk/maven-project-utils/src/it/setup-plugin/src/main/java/org/apache/maven/shared/project/utils/it/ResolveProjectMojo.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-project-utils/src/it/setup-plugin/src/main/java/org/apache/maven/shared/project/utils/it/ResolveProjectMojo.java?rev=1685427&r1=1685426&r2=1685427&view=diff
==============================================================================
--- maven/shared/trunk/maven-project-utils/src/it/setup-plugin/src/main/java/org/apache/maven/shared/project/utils/it/ResolveProjectMojo.java (original)
+++ maven/shared/trunk/maven-project-utils/src/it/setup-plugin/src/main/java/org/apache/maven/shared/project/utils/it/ResolveProjectMojo.java Sun Jun 14 17:09:05 2015
@@ -1,40 +1,40 @@
-package org.apache.maven.shared.project.utils.it;
-
-/*
- * 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.plugin.AbstractMojo;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.shared.project.utils.ProjectUtils;
-
-@Mojo( name="resolve-project" )
-public class ResolveProjectMojo
- extends AbstractMojo
-{
- @Parameter( defaultValue = "${project}", required = true, readonly = true )
- private MavenProject project;
-
- public void execute()
- {
- getLog().info( project.getId() + " is root project: " + ProjectUtils.isRootProject( project ) );
- getLog().info( project.getId() + " is aggregator: " + ProjectUtils.isAggregator( project ) );
- }
-}
+package org.apache.maven.shared.project.utils.it;
+
+/*
+ * 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.plugin.AbstractMojo;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.project.utils.ProjectUtils;
+
+@Mojo( name="resolve-project" )
+public class ResolveProjectMojo
+ extends AbstractMojo
+{
+ @Parameter( defaultValue = "${project}", required = true, readonly = true )
+ private MavenProject project;
+
+ public void execute()
+ {
+ getLog().info( project.getId() + " is root project: " + ProjectUtils.isRootProject( project ) );
+ getLog().info( project.getId() + " is aggregator: " + ProjectUtils.isAggregator( project ) );
+ }
+}
Modified: maven/shared/trunk/maven-project-utils/src/it/setup-plugin/src/main/java/org/apache/maven/shared/project/utils/it/ResolveScmMojo.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-project-utils/src/it/setup-plugin/src/main/java/org/apache/maven/shared/project/utils/it/ResolveScmMojo.java?rev=1685427&r1=1685426&r2=1685427&view=diff
==============================================================================
--- maven/shared/trunk/maven-project-utils/src/it/setup-plugin/src/main/java/org/apache/maven/shared/project/utils/it/ResolveScmMojo.java (original)
+++ maven/shared/trunk/maven-project-utils/src/it/setup-plugin/src/main/java/org/apache/maven/shared/project/utils/it/ResolveScmMojo.java Sun Jun 14 17:09:05 2015
@@ -1,40 +1,40 @@
-package org.apache.maven.shared.project.utils.it;
-
-/*
- * 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.plugin.AbstractMojo;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.shared.project.utils.ScmUtils;
-
-@Mojo( name="resolve-scm" )
-public class ResolveScmMojo
- extends AbstractMojo
-{
- @Parameter( defaultValue = "${project}", required = true, readonly = true )
- private MavenProject project;
-
- public void execute()
- {
- getLog().info( "Resolved scm connection for " + project.getId() + ": " + ScmUtils.resolveScmConnection( project ) );
- getLog().info( "Resolved scm developer connection for " + project.getId() + ": " + ScmUtils.resolveScmDeveloperConnection( project ) );
- }
-}
+package org.apache.maven.shared.project.utils.it;
+
+/*
+ * 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.plugin.AbstractMojo;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.project.utils.ScmUtils;
+
+@Mojo( name="resolve-scm" )
+public class ResolveScmMojo
+ extends AbstractMojo
+{
+ @Parameter( defaultValue = "${project}", required = true, readonly = true )
+ private MavenProject project;
+
+ public void execute()
+ {
+ getLog().info( "Resolved scm connection for " + project.getId() + ": " + ScmUtils.resolveScmConnection( project ) );
+ getLog().info( "Resolved scm developer connection for " + project.getId() + ": " + ScmUtils.resolveScmDeveloperConnection( project ) );
+ }
+}
Modified: maven/shared/trunk/maven-project-utils/src/it/setup-plugin/src/main/java/org/apache/maven/shared/project/utils/it/ResolveSiteMojo.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-project-utils/src/it/setup-plugin/src/main/java/org/apache/maven/shared/project/utils/it/ResolveSiteMojo.java?rev=1685427&r1=1685426&r2=1685427&view=diff
==============================================================================
--- maven/shared/trunk/maven-project-utils/src/it/setup-plugin/src/main/java/org/apache/maven/shared/project/utils/it/ResolveSiteMojo.java (original)
+++ maven/shared/trunk/maven-project-utils/src/it/setup-plugin/src/main/java/org/apache/maven/shared/project/utils/it/ResolveSiteMojo.java Sun Jun 14 17:09:05 2015
@@ -1,39 +1,39 @@
-package org.apache.maven.shared.project.utils.it;
-
-/*
- * 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.plugin.AbstractMojo;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.shared.project.utils.SiteUtils;
-
-@Mojo( name="resolve-site" )
-public class ResolveSiteMojo
- extends AbstractMojo
-{
- @Parameter( defaultValue = "${project}", required = true, readonly = true )
- private MavenProject project;
-
- public void execute()
- {
- getLog().info( "Resolved distributionManagement site URL for " + project.getId() + ": " + SiteUtils.resolveDistributionManagementSiteUrl( project ) );
- }
-}
+package org.apache.maven.shared.project.utils.it;
+
+/*
+ * 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.plugin.AbstractMojo;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.project.utils.SiteUtils;
+
+@Mojo( name="resolve-site" )
+public class ResolveSiteMojo
+ extends AbstractMojo
+{
+ @Parameter( defaultValue = "${project}", required = true, readonly = true )
+ private MavenProject project;
+
+ public void execute()
+ {
+ getLog().info( "Resolved distributionManagement site URL for " + project.getId() + ": " + SiteUtils.resolveDistributionManagementSiteUrl( project ) );
+ }
+}
Modified: maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/shared/project/runtime/MavenUtils.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/shared/project/runtime/MavenUtils.java?rev=1685427&r1=1685426&r2=1685427&view=diff
==============================================================================
--- maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/shared/project/runtime/MavenUtils.java (original)
+++ maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/shared/project/runtime/MavenUtils.java Sun Jun 14 17:09:05 2015
@@ -1,64 +1,64 @@
-package org.apache.maven.shared.project.runtime;
-
-/*
- * 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.io.InputStream;
-import java.util.Properties;
-
-import org.apache.maven.project.MavenProject;
-import org.codehaus.plexus.util.IOUtil;
-
-/**
- *
- */
-public final class MavenUtils
-{
-
- private MavenUtils()
- {
- }
-
- public static String getMavenVersion()
- {
- // This relies on the fact that MavenProject is the in core classloader
- // and that the core classloader is for the maven-core artifact
- // and that should have a pom.properties file
- // if this ever changes, we will have to revisit this code.
- final Properties properties = new Properties();
- final InputStream in =
- MavenProject.class.getClassLoader().getResourceAsStream( "META-INF/maven/org.apache.maven/maven-core/"
- + "pom.properties" );
- try
- {
- properties.load( in );
- }
- catch ( IOException ioe )
- {
- return "";
- }
- finally
- {
- IOUtil.close( in );
- }
-
- return properties.getProperty( "version" ).trim();
- }
-}
+package org.apache.maven.shared.project.runtime;
+
+/*
+ * 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.io.InputStream;
+import java.util.Properties;
+
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.IOUtil;
+
+/**
+ *
+ */
+public final class MavenUtils
+{
+
+ private MavenUtils()
+ {
+ }
+
+ public static String getMavenVersion()
+ {
+ // This relies on the fact that MavenProject is the in core classloader
+ // and that the core classloader is for the maven-core artifact
+ // and that should have a pom.properties file
+ // if this ever changes, we will have to revisit this code.
+ final Properties properties = new Properties();
+ final InputStream in =
+ MavenProject.class.getClassLoader().getResourceAsStream( "META-INF/maven/org.apache.maven/maven-core/"
+ + "pom.properties" );
+ try
+ {
+ properties.load( in );
+ }
+ catch ( IOException ioe )
+ {
+ return "";
+ }
+ finally
+ {
+ IOUtil.close( in );
+ }
+
+ return properties.getProperty( "version" ).trim();
+ }
+}
Modified: maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/shared/project/utils/ProjectUtils.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/shared/project/utils/ProjectUtils.java?rev=1685427&r1=1685426&r2=1685427&view=diff
==============================================================================
--- maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/shared/project/utils/ProjectUtils.java (original)
+++ maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/shared/project/utils/ProjectUtils.java Sun Jun 14 17:09:05 2015
@@ -1,310 +1,310 @@
-package org.apache.maven.shared.project.utils;
-
-/*
- * 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.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.Stack;
-
-import org.apache.maven.model.Model;
-import org.apache.maven.model.Profile;
-import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
-import org.apache.maven.project.MavenProject;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-
-/**
- *
- */
-public final class ProjectUtils
-{
- // This instance is often used, including in recursive methods, so initiate it for general usage
- private static final MavenXpp3Reader POM_READER = new MavenXpp3Reader();
-
- private ProjectUtils()
- {
- }
-
- /**
- * Returns {@code true} if this project has no parent, or it has a parent but isn't one of its modules.
- *
- * @param project the project to verify
- * @return {@code true} if this is a root project, otherwise {@code false}
- */
- public static boolean isRootProject( MavenProject project )
- {
- if ( !project.hasParent() )
- {
- return true;
- }
-
- MavenProject parent = project.getParent();
-
- // (not) being a rootProject must never depend on reactor projects or active profiles
- for ( String module : getAllModules( parent ).keySet() )
- {
- File moduleFile = getModuleFile( parent, module );
-
- if ( moduleFile.equals( project.getFile() ) )
- {
- // project is a module of its parent
- return false;
- }
- }
-
- // project isn't a module of its parent
- return true;
- }
-
- /**
- * Go through the ancestors to find the rootProject of this project.
- *
- * @param project the project
- * @return the root project
- * @see ProjectUtils#isRootProject(MavenProject)
- */
- public static MavenProject getRootProject( MavenProject project )
- {
- if ( project == null )
- {
- return null;
- }
-
- MavenProject current = project;
-
- while ( !isRootProject( current ) )
- {
- current = current.getParent();
- }
-
- return current;
- }
-
- /**
- * Return {@code true} if this project has modules, but is <strong>never</strong> the parent of one of them.<br/>
- *
- * Return {@code false} if this project has no modules, or if 1 or more modules have this project as its parent.
- *
- * @param project
- * @return {@code true} if project is an aggregator, {@code false} if project is standalone or hybrid
- */
- public static boolean isAggregator( MavenProject project )
- {
- // (not) being an aggregator must never depend on reactor projects or active profiles
- Set<String> modules = getAllModules( project ).keySet();
-
- if ( modules.isEmpty() )
- {
- return false;
- }
-
- for ( String module : modules )
- {
- File moduleFile = getModuleFile( project, module );
-
- Model model = null;
- try
- {
- model = readModel( moduleFile );
- }
- catch ( IOException e )
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- catch ( XmlPullParserException e )
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- if ( model.getParent() != null && model.getParent().getId().equals( project.getId() ) )
- {
- return false;
- }
-
- }
- return true;
- }
-
- private static Model readModel( File moduleFile ) throws IOException, XmlPullParserException
- {
- FileReader moduleReader = null;
-
- Model model = null;
-
- try
- {
- moduleReader = new FileReader( moduleFile );
-
- model = POM_READER.read( moduleReader );
- }
- finally
- {
- IOUtil.close( moduleReader );
- }
-
- return model;
- }
-
- public static File getModuleFile( MavenProject project, String module )
- {
- return getModuleFile( project.getBasedir(), module );
- }
-
- private static File getModuleFile( File basedir, String module )
- {
- File moduleFile = new File( basedir, module );
-
- if ( moduleFile.isDirectory() )
- {
- moduleFile = new File( moduleFile, "pom.xml" );
- }
- return moduleFile;
- }
-
-
- /**
- * Returns all modules of a project, including does specified in profiles, both active and inactive. The key of the
- * returned Map is the name of the module, the value refers to the source of the module (the project or a specific
- * profile).
- *
- * @param project the project
- * @return all modules, never {@code null}
- */
- public static Map<String, String> getAllModules( MavenProject project )
- {
- Model model = project.getModel();
-
- return getAllModules( model );
- }
-
- private static Map<String, String> getAllModules( Model model )
- {
- Map<String, String> modules = new LinkedHashMap<String, String>();
-
- for ( String module : model.getModules() )
- {
- modules.put( module, "project" ); // id?
- }
-
- for ( Profile profile : model.getProfiles() )
- {
- for ( String module : profile.getModules() )
- {
- modules.put( module, "profile(id:" + profile.getId() + ")" );
- }
- }
-
- return Collections.unmodifiableMap( modules );
- }
-
- /**
- * Returns the upper most folder of this projects and all of its descendants (i.e. modules, their modules, etc.).
- *
- * @param project the project
- * @return the shared folder
- */
- public static File getJoinedFolder( MavenProject project )
- {
- if ( project == null )
- {
- return null;
- }
-
- try
- {
- return getJoinedFolder( project.getBasedir(), project.getModel() );
- }
- catch ( IOException e )
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- catch ( XmlPullParserException e )
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- return null; //@todo fix exception handling
- }
-
- private static File getJoinedFolder( File baseDirectory, Model model )
- throws IOException, XmlPullParserException
- {
- File joinedFolder = baseDirectory;
-
- for ( String module : getAllModules( model ).keySet() )
- {
- File moduleFile = getModuleFile( baseDirectory, module );
-
- Model submodel = readModel( moduleFile );
-
- File modulesJoinedFolder = getJoinedFolder( moduleFile.getParentFile(), submodel );
-
- joinedFolder = getJoinedFolder( joinedFolder, modulesJoinedFolder );
- }
-
- return joinedFolder;
- }
-
- // Don't make this method public, it has nothing to do with a MavenProject.
- // If required on more places, create a separate Utils-class
- protected static File getJoinedFolder( File lhs, File rhs )
- {
- File joinedFolder = null;
-
- Stack<File> lhsStack = new Stack<File>();
-
- File lhsAncestor = lhs;
-
- while ( lhsAncestor != null )
- {
- lhsAncestor = lhsStack.push( lhsAncestor ).getParentFile();
- }
-
- Stack<File> rhsStack = new Stack<File>();
-
- File rhsAncestor = rhs;
-
- while ( rhsAncestor != null )
- {
- rhsAncestor = rhsStack.push( rhsAncestor ).getParentFile();
- }
-
- while ( !lhsStack.isEmpty() && !rhsStack.isEmpty() )
- {
- File nextFile = lhsStack.pop();
-
- if ( nextFile.isDirectory() && nextFile.equals( rhsStack.pop() ) )
- {
- joinedFolder = nextFile;
- }
- }
-
- return joinedFolder;
- }
-}
+package org.apache.maven.shared.project.utils;
+
+/*
+ * 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.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.Stack;
+
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Profile;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+/**
+ *
+ */
+public final class ProjectUtils
+{
+ // This instance is often used, including in recursive methods, so initiate it for general usage
+ private static final MavenXpp3Reader POM_READER = new MavenXpp3Reader();
+
+ private ProjectUtils()
+ {
+ }
+
+ /**
+ * Returns {@code true} if this project has no parent, or it has a parent but isn't one of its modules.
+ *
+ * @param project the project to verify
+ * @return {@code true} if this is a root project, otherwise {@code false}
+ */
+ public static boolean isRootProject( MavenProject project )
+ {
+ if ( !project.hasParent() )
+ {
+ return true;
+ }
+
+ MavenProject parent = project.getParent();
+
+ // (not) being a rootProject must never depend on reactor projects or active profiles
+ for ( String module : getAllModules( parent ).keySet() )
+ {
+ File moduleFile = getModuleFile( parent, module );
+
+ if ( moduleFile.equals( project.getFile() ) )
+ {
+ // project is a module of its parent
+ return false;
+ }
+ }
+
+ // project isn't a module of its parent
+ return true;
+ }
+
+ /**
+ * Go through the ancestors to find the rootProject of this project.
+ *
+ * @param project the project
+ * @return the root project
+ * @see ProjectUtils#isRootProject(MavenProject)
+ */
+ public static MavenProject getRootProject( MavenProject project )
+ {
+ if ( project == null )
+ {
+ return null;
+ }
+
+ MavenProject current = project;
+
+ while ( !isRootProject( current ) )
+ {
+ current = current.getParent();
+ }
+
+ return current;
+ }
+
+ /**
+ * Return {@code true} if this project has modules, but is <strong>never</strong> the parent of one of them.<br/>
+ *
+ * Return {@code false} if this project has no modules, or if 1 or more modules have this project as its parent.
+ *
+ * @param project
+ * @return {@code true} if project is an aggregator, {@code false} if project is standalone or hybrid
+ */
+ public static boolean isAggregator( MavenProject project )
+ {
+ // (not) being an aggregator must never depend on reactor projects or active profiles
+ Set<String> modules = getAllModules( project ).keySet();
+
+ if ( modules.isEmpty() )
+ {
+ return false;
+ }
+
+ for ( String module : modules )
+ {
+ File moduleFile = getModuleFile( project, module );
+
+ Model model = null;
+ try
+ {
+ model = readModel( moduleFile );
+ }
+ catch ( IOException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch ( XmlPullParserException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ if ( model.getParent() != null && model.getParent().getId().equals( project.getId() ) )
+ {
+ return false;
+ }
+
+ }
+ return true;
+ }
+
+ private static Model readModel( File moduleFile ) throws IOException, XmlPullParserException
+ {
+ FileReader moduleReader = null;
+
+ Model model = null;
+
+ try
+ {
+ moduleReader = new FileReader( moduleFile );
+
+ model = POM_READER.read( moduleReader );
+ }
+ finally
+ {
+ IOUtil.close( moduleReader );
+ }
+
+ return model;
+ }
+
+ public static File getModuleFile( MavenProject project, String module )
+ {
+ return getModuleFile( project.getBasedir(), module );
+ }
+
+ private static File getModuleFile( File basedir, String module )
+ {
+ File moduleFile = new File( basedir, module );
+
+ if ( moduleFile.isDirectory() )
+ {
+ moduleFile = new File( moduleFile, "pom.xml" );
+ }
+ return moduleFile;
+ }
+
+
+ /**
+ * Returns all modules of a project, including does specified in profiles, both active and inactive. The key of the
+ * returned Map is the name of the module, the value refers to the source of the module (the project or a specific
+ * profile).
+ *
+ * @param project the project
+ * @return all modules, never {@code null}
+ */
+ public static Map<String, String> getAllModules( MavenProject project )
+ {
+ Model model = project.getModel();
+
+ return getAllModules( model );
+ }
+
+ private static Map<String, String> getAllModules( Model model )
+ {
+ Map<String, String> modules = new LinkedHashMap<String, String>();
+
+ for ( String module : model.getModules() )
+ {
+ modules.put( module, "project" ); // id?
+ }
+
+ for ( Profile profile : model.getProfiles() )
+ {
+ for ( String module : profile.getModules() )
+ {
+ modules.put( module, "profile(id:" + profile.getId() + ")" );
+ }
+ }
+
+ return Collections.unmodifiableMap( modules );
+ }
+
+ /**
+ * Returns the upper most folder of this projects and all of its descendants (i.e. modules, their modules, etc.).
+ *
+ * @param project the project
+ * @return the shared folder
+ */
+ public static File getJoinedFolder( MavenProject project )
+ {
+ if ( project == null )
+ {
+ return null;
+ }
+
+ try
+ {
+ return getJoinedFolder( project.getBasedir(), project.getModel() );
+ }
+ catch ( IOException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch ( XmlPullParserException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return null; //@todo fix exception handling
+ }
+
+ private static File getJoinedFolder( File baseDirectory, Model model )
+ throws IOException, XmlPullParserException
+ {
+ File joinedFolder = baseDirectory;
+
+ for ( String module : getAllModules( model ).keySet() )
+ {
+ File moduleFile = getModuleFile( baseDirectory, module );
+
+ Model submodel = readModel( moduleFile );
+
+ File modulesJoinedFolder = getJoinedFolder( moduleFile.getParentFile(), submodel );
+
+ joinedFolder = getJoinedFolder( joinedFolder, modulesJoinedFolder );
+ }
+
+ return joinedFolder;
+ }
+
+ // Don't make this method public, it has nothing to do with a MavenProject.
+ // If required on more places, create a separate Utils-class
+ protected static File getJoinedFolder( File lhs, File rhs )
+ {
+ File joinedFolder = null;
+
+ Stack<File> lhsStack = new Stack<File>();
+
+ File lhsAncestor = lhs;
+
+ while ( lhsAncestor != null )
+ {
+ lhsAncestor = lhsStack.push( lhsAncestor ).getParentFile();
+ }
+
+ Stack<File> rhsStack = new Stack<File>();
+
+ File rhsAncestor = rhs;
+
+ while ( rhsAncestor != null )
+ {
+ rhsAncestor = rhsStack.push( rhsAncestor ).getParentFile();
+ }
+
+ while ( !lhsStack.isEmpty() && !rhsStack.isEmpty() )
+ {
+ File nextFile = lhsStack.pop();
+
+ if ( nextFile.isDirectory() && nextFile.equals( rhsStack.pop() ) )
+ {
+ joinedFolder = nextFile;
+ }
+ }
+
+ return joinedFolder;
+ }
+}