[MNG-6300] Multi module release creates empty directories in war file instead of jars

This commit is contained in:
rfscholte 2017-12-22 14:25:46 +01:00
parent eee06f7d7c
commit 98af937bc6
13 changed files with 417 additions and 164 deletions

View File

@ -22,14 +22,17 @@ package org.apache.maven;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.ArtifactProperties;
import org.eclipse.aether.artifact.ArtifactType;
@ -44,6 +47,8 @@ import org.eclipse.aether.repository.Authentication;
import org.eclipse.aether.repository.Proxy;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.repository.RepositoryPolicy;
import org.eclipse.aether.repository.WorkspaceReader;
import org.eclipse.aether.repository.WorkspaceRepository;
import org.eclipse.aether.util.repository.AuthenticationBuilder;
/**
@ -364,4 +369,68 @@ public class RepositoryUtils
}
return artifacts;
}
public static WorkspaceRepository getWorkspace( RepositorySystemSession session )
{
WorkspaceReader reader = session.getWorkspaceReader();
return ( reader != null ) ? reader.getRepository() : null;
}
public static boolean repositoriesEquals( List<RemoteRepository> r1, List<RemoteRepository> r2 )
{
if ( r1.size() != r2.size() )
{
return false;
}
for ( Iterator<RemoteRepository> it1 = r1.iterator(), it2 = r2.iterator(); it1.hasNext(); )
{
if ( !repositoryEquals( it1.next(), it2.next() ) )
{
return false;
}
}
return true;
}
public static int repositoriesHashCode( List<RemoteRepository> repositories )
{
int result = 17;
for ( RemoteRepository repository : repositories )
{
result = 31 * result + repositoryHashCode( repository );
}
return result;
}
private static int repositoryHashCode( RemoteRepository repository )
{
int result = 17;
Object obj = repository.getUrl();
result = 31 * result + ( obj != null ? obj.hashCode() : 0 );
return result;
}
private static boolean policyEquals( RepositoryPolicy p1, RepositoryPolicy p2 )
{
if ( p1 == p2 )
{
return true;
}
// update policy doesn't affect contents
return p1.isEnabled() == p2.isEnabled() && Objects.equals( p1.getChecksumPolicy(), p2.getChecksumPolicy() );
}
private static boolean repositoryEquals( RemoteRepository r1, RemoteRepository r2 )
{
if ( r1 == r2 )
{
return true;
}
return Objects.equals( r1.getId(), r2.getId() ) && Objects.equals( r1.getUrl(), r2.getUrl() )
&& policyEquals( r1.getPolicy( false ), r2.getPolicy( false ) )
&& policyEquals( r1.getPolicy( true ), r2.getPolicy( true ) );
}
}

View File

@ -19,6 +19,8 @@ package org.apache.maven.lifecycle.internal;
* under the License.
*/
import java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@ -37,13 +39,13 @@ import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.eventspy.internal.EventSpyDispatcher;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.plugin.ProjectArtifactsCache;
import org.apache.maven.project.DefaultDependencyResolutionRequest;
import org.apache.maven.project.DependencyResolutionException;
import org.apache.maven.project.DependencyResolutionResult;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectDependenciesResolver;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.artifact.ProjectArtifactsCache;
import org.codehaus.plexus.logging.Logger;
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.graph.DependencyFilter;
@ -128,7 +130,7 @@ public class LifecycleDependencyResolver
}
}
Set<Artifact> artifacts;
Set<Artifact> resolvedArtifacts;
ProjectArtifactsCache.Key cacheKey = projectArtifactsCache.createKey( project, scopesToCollect,
scopesToResolve, aggregating, session.getRepositorySession() );
ProjectArtifactsCache.CacheRecord recordArtifacts;
@ -136,15 +138,15 @@ public class LifecycleDependencyResolver
if ( recordArtifacts != null )
{
artifacts = recordArtifacts.artifacts;
resolvedArtifacts = recordArtifacts.artifacts;
}
else
{
try
{
artifacts = getDependencies( project, scopesToCollect, scopesToResolve, session, aggregating,
projectArtifacts );
recordArtifacts = projectArtifactsCache.put( cacheKey, artifacts );
resolvedArtifacts = getDependencies( project, scopesToCollect, scopesToResolve, session,
aggregating, projectArtifacts );
recordArtifacts = projectArtifactsCache.put( cacheKey, resolvedArtifacts );
}
catch ( LifecycleExecutionException e )
{
@ -155,13 +157,31 @@ public class LifecycleDependencyResolver
}
projectArtifactsCache.register( project, cacheKey, recordArtifacts );
project.setResolvedArtifacts( artifacts );
Map<Artifact, File> reactorProjects = new HashMap<>( session.getProjects().size() );
for ( MavenProject reactorProject : session.getProjects() )
{
reactorProjects.put( reactorProject.getArtifact(), reactorProject.getArtifact().getFile() );
}
Map<String, Artifact> map = new HashMap<>();
for ( Artifact artifact : artifacts )
for ( Artifact artifact : resolvedArtifacts )
{
/**
* MNG-6300: resolvedArtifacts can be cache result; this ensures reactor files are always up to date
* During lifecycle the Artifact.getFile() can change from target/classes to the actual jar.
* This clearly shows that target/classes should not be abused as artifactFile just for the classpath
*/
File reactorProjectFile = reactorProjects.get( artifact );
if ( reactorProjectFile != null )
{
artifact.setFile( reactorProjectFile );
}
map.put( artifact.getDependencyConflictId(), artifact );
}
project.setResolvedArtifacts( resolvedArtifacts );
for ( Artifact artifact : project.getDependencyArtifacts() )
{
if ( artifact.getFile() == null )

View File

@ -25,11 +25,6 @@ import java.util.List;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Exclusion;
import org.apache.maven.model.Plugin;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.repository.RepositoryPolicy;
import org.eclipse.aether.repository.WorkspaceReader;
import org.eclipse.aether.repository.WorkspaceRepository;
/**
* @author Benjamin Bentmann
@ -47,63 +42,6 @@ class CacheUtils
return obj != null ? obj.hashCode() : 0;
}
public static int repositoriesHashCode( List<RemoteRepository> repositories )
{
int result = 17;
for ( RemoteRepository repository : repositories )
{
result = 31 * result + repositoryHashCode( repository );
}
return result;
}
private static int repositoryHashCode( RemoteRepository repository )
{
int result = 17;
result = 31 * result + hash( repository.getUrl() );
return result;
}
private static boolean repositoryEquals( RemoteRepository r1, RemoteRepository r2 )
{
if ( r1 == r2 )
{
return true;
}
return eq( r1.getId(), r2.getId() ) && eq( r1.getUrl(), r2.getUrl() )
&& policyEquals( r1.getPolicy( false ), r2.getPolicy( false ) )
&& policyEquals( r1.getPolicy( true ), r2.getPolicy( true ) );
}
private static boolean policyEquals( RepositoryPolicy p1, RepositoryPolicy p2 )
{
if ( p1 == p2 )
{
return true;
}
// update policy doesn't affect contents
return p1.isEnabled() == p2.isEnabled() && eq( p1.getChecksumPolicy(), p2.getChecksumPolicy() );
}
public static boolean repositoriesEquals( List<RemoteRepository> r1, List<RemoteRepository> r2 )
{
if ( r1.size() != r2.size() )
{
return false;
}
for ( Iterator<RemoteRepository> it1 = r1.iterator(), it2 = r2.iterator(); it1.hasNext(); )
{
if ( !repositoryEquals( it1.next(), it2.next() ) )
{
return false;
}
}
return true;
}
public static int pluginHashCode( Plugin plugin )
{
int hash = 17;
@ -202,10 +140,4 @@ class CacheUtils
return true;
}
public static WorkspaceRepository getWorkspace( RepositorySystemSession session )
{
WorkspaceReader reader = session.getWorkspaceReader();
return ( reader != null ) ? reader.getRepository() : null;
}
}

View File

@ -23,9 +23,11 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.lang3.Validate;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject;
@ -48,7 +50,6 @@ public class DefaultPluginArtifactsCache
protected static class CacheKey
implements Key
{
private final Plugin plugin;
private final WorkspaceRepository workspace;
@ -65,7 +66,7 @@ public class DefaultPluginArtifactsCache
RepositorySystemSession session )
{
this.plugin = plugin.clone();
workspace = CacheUtils.getWorkspace( session );
workspace = RepositoryUtils.getWorkspace( session );
this.localRepo = session.getLocalRepository();
this.repositories = new ArrayList<>( repositories.size() );
for ( RemoteRepository repository : repositories )
@ -83,10 +84,10 @@ public class DefaultPluginArtifactsCache
int hash = 17;
hash = hash * 31 + CacheUtils.pluginHashCode( plugin );
hash = hash * 31 + hash( workspace );
hash = hash * 31 + hash( localRepo );
hash = hash * 31 + CacheUtils.repositoriesHashCode( repositories );
hash = hash * 31 + hash( extensionFilter );
hash = hash * 31 + Objects.hashCode( workspace );
hash = hash * 31 + Objects.hashCode( localRepo );
hash = hash * 31 + RepositoryUtils.repositoriesHashCode( repositories );
hash = hash * 31 + Objects.hashCode( extensionFilter );
this.hashCode = hash;
}
@ -102,11 +103,6 @@ public class DefaultPluginArtifactsCache
return hashCode;
}
private static int hash( Object obj )
{
return obj != null ? obj.hashCode() : 0;
}
@Override
public boolean equals( Object o )
{
@ -122,16 +118,12 @@ public class DefaultPluginArtifactsCache
CacheKey that = (CacheKey) o;
return CacheUtils.pluginEquals( plugin, that.plugin ) && eq( workspace, that.workspace )
&& eq( localRepo, that.localRepo ) && CacheUtils.repositoriesEquals( repositories, that.repositories )
&& eq( filter, that.filter );
return CacheUtils.pluginEquals( plugin, that.plugin )
&& Objects.equals( workspace, that.workspace )
&& Objects.equals( localRepo, that.localRepo )
&& RepositoryUtils.repositoriesEquals( repositories, that.repositories )
&& Objects.equals( filter, that.filter );
}
private static <T> boolean eq( T s1, T s2 )
{
return s1 != null ? s1.equals( s2 ) : s2 == null;
}
}
protected final Map<Key, CacheRecord> cache = new ConcurrentHashMap<>();

View File

@ -24,6 +24,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
@ -146,7 +147,7 @@ public class DefaultPluginDescriptorCache
artifactId = plugin.getArtifactId();
version = plugin.getVersion();
workspace = CacheUtils.getWorkspace( session );
workspace = RepositoryUtils.getWorkspace( session );
localRepo = session.getLocalRepository();
this.repositories = new ArrayList<>( repositories.size() );
for ( RemoteRepository repository : repositories )
@ -167,7 +168,7 @@ public class DefaultPluginDescriptorCache
hash = hash * 31 + version.hashCode();
hash = hash * 31 + hash( workspace );
hash = hash * 31 + localRepo.hashCode();
hash = hash * 31 + CacheUtils.repositoriesHashCode( repositories );
hash = hash * 31 + RepositoryUtils.repositoriesHashCode( repositories );
this.hashCode = hash;
}
@ -195,7 +196,7 @@ public class DefaultPluginDescriptorCache
return eq( this.artifactId, that.artifactId ) && eq( this.groupId, that.groupId )
&& eq( this.version, that.version ) && eq( this.localRepo, that.localRepo )
&& eq( this.workspace, that.workspace )
&& CacheUtils.repositoriesEquals( this.repositories, that.repositories );
&& RepositoryUtils.repositoriesEquals( this.repositories, that.repositories );
}
@Override

View File

@ -23,9 +23,11 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.lang3.Validate;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject;
@ -72,7 +74,7 @@ public class DefaultPluginRealmCache
RepositorySystemSession session )
{
this.plugin = plugin.clone();
this.workspace = CacheUtils.getWorkspace( session );
this.workspace = RepositoryUtils.getWorkspace( session );
this.localRepo = session.getLocalRepository();
this.repositories = new ArrayList<>( repositories.size() );
for ( RemoteRepository repository : repositories )
@ -93,12 +95,12 @@ public class DefaultPluginRealmCache
int hash = 17;
hash = hash * 31 + CacheUtils.pluginHashCode( plugin );
hash = hash * 31 + hash( workspace );
hash = hash * 31 + hash( localRepo );
hash = hash * 31 + CacheUtils.repositoriesHashCode( repositories );
hash = hash * 31 + hash( parentRealm );
hash = hash * 31 + Objects.hashCode( workspace );
hash = hash * 31 + Objects.hashCode( localRepo );
hash = hash * 31 + RepositoryUtils.repositoriesHashCode( repositories );
hash = hash * 31 + Objects.hashCode( parentRealm );
hash = hash * 31 + this.foreignImports.hashCode();
hash = hash * 31 + hash( dependencyFilter );
hash = hash * 31 + Objects.hashCode( dependencyFilter );
this.hashCode = hash;
}
@ -114,11 +116,6 @@ public class DefaultPluginRealmCache
return hashCode;
}
private static int hash( Object obj )
{
return obj != null ? obj.hashCode() : 0;
}
@Override
public boolean equals( Object o )
{
@ -134,17 +131,14 @@ public class DefaultPluginRealmCache
CacheKey that = (CacheKey) o;
return parentRealm == that.parentRealm && CacheUtils.pluginEquals( plugin, that.plugin )
&& eq( workspace, that.workspace ) && eq( localRepo, that.localRepo )
&& CacheUtils.repositoriesEquals( this.repositories, that.repositories ) && eq( filter, that.filter )
&& eq( foreignImports, that.foreignImports );
return parentRealm == that.parentRealm
&& CacheUtils.pluginEquals( plugin, that.plugin )
&& Objects.equals( workspace, that.workspace )
&& Objects.equals( localRepo, that.localRepo )
&& RepositoryUtils.repositoriesEquals( this.repositories, that.repositories )
&& Objects.equals( filter, that.filter )
&& Objects.equals( foreignImports, that.foreignImports );
}
private static <T> boolean eq( T s1, T s2 )
{
return s1 != null ? s1.equals( s2 ) : s2 == null;
}
}
protected final Map<Key, CacheRecord> cache = new ConcurrentHashMap<>();

View File

@ -1,4 +1,4 @@
package org.apache.maven.plugin;
package org.apache.maven.project.artifact;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@ -25,13 +25,14 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.lang3.Validate;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Component;
import org.eclipse.aether.RepositorySystemSession;
@ -94,7 +95,7 @@ public class DefaultProjectArtifactsCache
}
dependencyArtifacts = Collections.unmodifiableSet( deps );
workspace = CacheUtils.getWorkspace( session );
workspace = RepositoryUtils.getWorkspace( session );
this.localRepo = session.getLocalRepository();
this.repositories = new ArrayList<>( repositories.size() );
for ( RemoteRepository repository : repositories )
@ -117,16 +118,16 @@ public class DefaultProjectArtifactsCache
this.aggregating = aggregating;
int hash = 17;
hash = hash * 31 + hash( groupId );
hash = hash * 31 + hash( artifactId );
hash = hash * 31 + hash( version );
hash = hash * 31 + hash( dependencyArtifacts );
hash = hash * 31 + hash( workspace );
hash = hash * 31 + hash( localRepo );
hash = hash * 31 + CacheUtils.repositoriesHashCode( repositories );
hash = hash * 31 + hash( collect );
hash = hash * 31 + hash( resolve );
hash = hash * 31 + hash( aggregating );
hash = hash * 31 + Objects.hashCode( groupId );
hash = hash * 31 + Objects.hashCode( artifactId );
hash = hash * 31 + Objects.hashCode( version );
hash = hash * 31 + Objects.hashCode( dependencyArtifacts );
hash = hash * 31 + Objects.hashCode( workspace );
hash = hash * 31 + Objects.hashCode( localRepo );
hash = hash * 31 + RepositoryUtils.repositoriesHashCode( repositories );
hash = hash * 31 + Objects.hashCode( collect );
hash = hash * 31 + Objects.hashCode( resolve );
hash = hash * 31 + Objects.hashCode( aggregating );
this.hashCode = hash;
}
@ -142,11 +143,6 @@ public class DefaultProjectArtifactsCache
return hashCode;
}
private static int hash( Object obj )
{
return obj != null ? obj.hashCode() : 0;
}
@Override
public boolean equals( Object o )
{
@ -162,22 +158,21 @@ public class DefaultProjectArtifactsCache
CacheKey that = (CacheKey) o;
return eq( groupId, that.groupId ) && eq( artifactId, that.artifactId ) && eq( version, that.version )
&& eq( dependencyArtifacts, that.dependencyArtifacts )
&& eq( workspace, that.workspace ) && eq( localRepo, that.localRepo )
&& CacheUtils.repositoriesEquals( repositories, that.repositories ) && eq( collect, that.collect )
&& eq( resolve, that.resolve ) && aggregating == that.aggregating;
return Objects.equals( groupId, that.groupId ) && Objects.equals( artifactId, that.artifactId )
&& Objects.equals( version, that.version )
&& Objects.equals( dependencyArtifacts, that.dependencyArtifacts )
&& Objects.equals( workspace, that.workspace )
&& Objects.equals( localRepo, that.localRepo )
&& RepositoryUtils.repositoriesEquals( repositories, that.repositories )
&& Objects.equals( collect, that.collect )
&& Objects.equals( resolve, that.resolve )
&& aggregating == that.aggregating;
}
private static <T> boolean eq( T s1, T s2 )
{
return s1 != null ? s1.equals( s2 ) : s2 == null;
}
}
protected final Map<Key, CacheRecord> cache = new ConcurrentHashMap<>();
@Override
public Key createKey( MavenProject project, Collection<String> scopesToCollect,
Collection<String> scopesToResolve, boolean aggregating, RepositorySystemSession session )
{
@ -185,6 +180,7 @@ public class DefaultProjectArtifactsCache
aggregating, session );
}
@Override
public CacheRecord get( Key key )
throws LifecycleExecutionException
{
@ -198,6 +194,7 @@ public class DefaultProjectArtifactsCache
return cacheRecord;
}
@Override
public CacheRecord put( Key key, Set<Artifact> projectArtifacts )
{
Validate.notNull( projectArtifacts, "projectArtifacts cannot be null" );
@ -220,6 +217,7 @@ public class DefaultProjectArtifactsCache
}
}
@Override
public CacheRecord put( Key key, LifecycleExecutionException exception )
{
Validate.notNull( exception, "exception cannot be null" );
@ -233,21 +231,13 @@ public class DefaultProjectArtifactsCache
return record;
}
@Override
public void flush()
{
cache.clear();
}
protected static int pluginHashCode( Plugin plugin )
{
return CacheUtils.pluginHashCode( plugin );
}
protected static boolean pluginEquals( Plugin a, Plugin b )
{
return CacheUtils.pluginEquals( a, b );
}
@Override
public void register( MavenProject project, Key cacheKey, CacheRecord record )
{
// default cache does not track record usage

View File

@ -1,4 +1,4 @@
package org.apache.maven.plugin;
package org.apache.maven.project.artifact;
/*
* Licensed to the Apache Software Foundation (ASF) under one

View File

@ -20,6 +20,7 @@ package org.apache.maven;
*/
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
@ -128,6 +129,12 @@ public abstract class AbstractCoreMavenComponentTestCase
}
protected MavenSession createMavenSession( File pom, Properties executionProperties )
throws Exception
{
return createMavenSession( pom, executionProperties, false );
}
protected MavenSession createMavenSession( File pom, Properties executionProperties, boolean includeModules )
throws Exception
{
MavenExecutionRequest request = createMavenExecutionRequest( pom );
@ -138,17 +145,32 @@ public abstract class AbstractCoreMavenComponentTestCase
.setPluginArtifactRepositories( request.getPluginArtifactRepositories() )
.setSystemProperties( executionProperties );
MavenProject project = null;
List<MavenProject> projects = new ArrayList<>();
if ( pom != null )
{
project = projectBuilder.build( pom, configuration ).getProject();
MavenProject project = projectBuilder.build( pom, configuration ).getProject();
projects.add( project );
if ( includeModules )
{
for( String module : project.getModules() )
{
File modulePom = new File( pom.getParentFile(), module );
if( modulePom.isDirectory() )
{
modulePom = new File( modulePom, "pom.xml" );
}
projects.add( projectBuilder.build( modulePom, configuration ).getProject() );
}
}
}
else
{
project = createStubMavenProject();
MavenProject project = createStubMavenProject();
project.setRemoteArtifactRepositories( request.getRemoteRepositories() );
project.setPluginArtifactRepositories( request.getPluginArtifactRepositories() );
projects.add( project );
}
initRepoSession( configuration );
@ -156,7 +178,7 @@ public abstract class AbstractCoreMavenComponentTestCase
MavenSession session =
new MavenSession( getContainer(), configuration.getRepositorySession(), request,
new DefaultMavenExecutionResult() );
session.setProjects( Arrays.asList( project ) );
session.setProjects( projects );
session.setAllProjects( session.getProjects() );
return session;

View File

@ -0,0 +1,90 @@
package org.apache.maven.lifecycle.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 java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import org.apache.maven.AbstractCoreMavenComponentTestCase;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Requirement;
import org.junit.Test;
public class LifecycleDependencyResolverTest extends AbstractCoreMavenComponentTestCase
{
@Requirement
private LifecycleDependencyResolver resolver;
@Override
protected String getProjectsDirectory()
{
return null;
}
@Override
protected void setUp()
throws Exception
{
super.setUp();
resolver = lookup( LifecycleDependencyResolver.class );
}
@Test
public void testCachedReactorProjectDependencies() throws Exception
{
MavenSession session = createMavenSession( new File( "src/test/projects/lifecycle-dependency-resolver/pom.xml" ), new Properties(), true );
Collection<String> scopesToCollect = null;
Collection<String> scopesToResolve = Collections.singletonList( "compile" );
boolean aggregating = false;
Set<Artifact> reactorArtifacts = new HashSet<>( 3 );
for ( MavenProject reactorProject : session.getProjects() )
{
reactorProject.setArtifactFilter( new ArtifactFilter()
{
@Override
public boolean include( Artifact artifact )
{
return true;
}
} );
resolver.resolveProjectDependencies( reactorProject, scopesToCollect, scopesToResolve, session, aggregating, reactorArtifacts );
reactorArtifacts.add( reactorProject.getArtifact() );
}
MavenProject lib = session.getProjects().get( 1 );
MavenProject war = session.getProjects().get( 2 );
assertEquals( null , war.getArtifactMap().get("org.apache.maven.its.mng6300:mng6300-lib").getFile() );
lib.getArtifact().setFile( new File( "lib.jar" ) );
resolver.resolveProjectDependencies( war, scopesToCollect, scopesToResolve, session, aggregating, reactorArtifacts );
assertEquals( new File( "lib.jar" ) , war.getArtifactMap().get("org.apache.maven.its.mng6300:mng6300-lib").getFile() );
}
}

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven.its.mng6300</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
</parent>
<artifactId>mng6300-lib</artifactId>
</project>

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng6300</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>Maven Integration Test :: MNG-6300</name>
<description>
Check that war packages the jar instead of a directory
</description>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<reportSets>
<reportSet>
<reports>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
<modules>
<module>lib</module>
<module>war</module>
</modules>
</project>

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven.its.mng6300</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
</parent>
<artifactId>mng6300-war</artifactId>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.maven.its.mng6300</groupId>
<artifactId>mng6300-lib</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>