mirror of https://github.com/apache/maven.git
o reverting fix for MNG-1323, breaks trunk horribly when everything is clean. I ran the ITs after Piotr did but doing so with everything clean doesn't work. Time for Hudson.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@578582 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
71aa8e7f51
commit
bf8d692a15
|
@ -105,8 +105,6 @@ public class DefaultPluginManager
|
|||
|
||||
RESERVED_GROUP_IDS = rgids;
|
||||
}
|
||||
|
||||
protected PluginRealmManager pluginRealmManager;
|
||||
|
||||
protected PlexusContainer container;
|
||||
|
||||
|
@ -379,70 +377,67 @@ public class DefaultPluginManager
|
|||
{
|
||||
// TODO When/if we go to project-level plugin instances (like for plugin-level deps in the
|
||||
// POM), we need to undo this somehow.
|
||||
ClassRealm pluginRealm = container.getComponentRealm( projectPlugin.getKey() );
|
||||
|
||||
ClassRealm componentRealm = pluginRealmManager.getOrCreateRealm(projectPlugin, pluginArtifact, artifacts);
|
||||
|
||||
// ClassRealm pluginRealm = container.getComponentRealm( projectPlugin.getKey()+":"+projectPlugin.getVersion() );
|
||||
if ( ( pluginRealm != null ) && ( pluginRealm != container.getContainerRealm() ) )
|
||||
{
|
||||
getLogger().debug(
|
||||
"Realm already exists for: " + projectPlugin.getKey()
|
||||
+ ". Skipping addition..." );
|
||||
// we've already discovered this plugin, and configured it, so skip it this time.
|
||||
|
||||
// if ( ( pluginRealm != null ) && ( pluginRealm != container.getContainerRealm() ) )
|
||||
// {
|
||||
// getLogger().debug(
|
||||
// "Realm already exists for: " + projectPlugin.getKey()
|
||||
// + ". Skipping addition..." );
|
||||
// // we've already discovered this plugin, and configured it, so skip it this time.
|
||||
//
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // ----------------------------------------------------------------------------
|
||||
// // Realm creation for a plugin
|
||||
// // ----------------------------------------------------------------------------
|
||||
//
|
||||
// ClassRealm componentRealm = null;
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// List jars = new ArrayList();
|
||||
//
|
||||
// for ( Iterator i = artifacts.iterator(); i.hasNext(); )
|
||||
// {
|
||||
// Artifact artifact = (Artifact) i.next();
|
||||
//
|
||||
// jars.add( artifact.getFile() );
|
||||
// }
|
||||
//
|
||||
// jars.add( pluginArtifact.getFile() );
|
||||
//
|
||||
// // Now here we need the artifact coreArtifactFilter stuff
|
||||
//
|
||||
// componentRealm = container.createComponentRealm( projectPlugin.getKey()+projectPlugin.getVersion(), jars );
|
||||
//
|
||||
// // adding for MNG-3012 to try to work around problems with Xpp3Dom (from plexus-utils)
|
||||
// // spawning a ClassCastException when a mojo calls plugin.getConfiguration() from maven-model...
|
||||
// componentRealm.importFrom( componentRealm.getParentRealm().getId(),
|
||||
// Xpp3Dom.class.getName() );
|
||||
// componentRealm.importFrom( componentRealm.getParentRealm().getId(),
|
||||
// "org.codehaus.plexus.util.xml.pull" );
|
||||
//
|
||||
// // Adding for MNG-2878, since maven-reporting-impl was removed from the
|
||||
// // internal list of artifacts managed by maven, the classloader is different
|
||||
// // between maven-reporting-impl and maven-reporting-api...so this resource
|
||||
// // is not available from the AbstractMavenReport since it uses:
|
||||
// // getClass().getResourceAsStream( "/default-report.xml" )
|
||||
// // (maven-reporting-impl version 2.0; line 134; affects: checkstyle plugin, and probably others)
|
||||
// componentRealm.importFrom( componentRealm.getParentRealm().getId(), "/default-report.xml" );
|
||||
// }
|
||||
// catch ( PlexusContainerException e )
|
||||
// {
|
||||
// throw new PluginManagerException( "Failed to create realm for plugin '" + projectPlugin
|
||||
// + ".", e );
|
||||
// }
|
||||
// catch ( NoSuchRealmException e )
|
||||
// {
|
||||
// throw new PluginManagerException(
|
||||
// "Failed to import Xpp3Dom from parent realm for plugin: '"
|
||||
// + projectPlugin + ".", e );
|
||||
// }
|
||||
return;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Realm creation for a plugin
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
ClassRealm componentRealm = null;
|
||||
|
||||
try
|
||||
{
|
||||
List jars = new ArrayList();
|
||||
|
||||
for ( Iterator i = artifacts.iterator(); i.hasNext(); )
|
||||
{
|
||||
Artifact artifact = (Artifact) i.next();
|
||||
|
||||
jars.add( artifact.getFile() );
|
||||
}
|
||||
|
||||
jars.add( pluginArtifact.getFile() );
|
||||
|
||||
// Now here we need the artifact coreArtifactFilter stuff
|
||||
|
||||
componentRealm = container.createComponentRealm( projectPlugin.getKey(), jars );
|
||||
|
||||
// adding for MNG-3012 to try to work around problems with Xpp3Dom (from plexus-utils)
|
||||
// spawning a ClassCastException when a mojo calls plugin.getConfiguration() from maven-model...
|
||||
componentRealm.importFrom( componentRealm.getParentRealm().getId(),
|
||||
Xpp3Dom.class.getName() );
|
||||
componentRealm.importFrom( componentRealm.getParentRealm().getId(),
|
||||
"org.codehaus.plexus.util.xml.pull" );
|
||||
|
||||
// Adding for MNG-2878, since maven-reporting-impl was removed from the
|
||||
// internal list of artifacts managed by maven, the classloader is different
|
||||
// between maven-reporting-impl and maven-reporting-api...so this resource
|
||||
// is not available from the AbstractMavenReport since it uses:
|
||||
// getClass().getResourceAsStream( "/default-report.xml" )
|
||||
// (maven-reporting-impl version 2.0; line 134; affects: checkstyle plugin, and probably others)
|
||||
componentRealm.importFrom( componentRealm.getParentRealm().getId(), "/default-report.xml" );
|
||||
}
|
||||
catch ( PlexusContainerException e )
|
||||
{
|
||||
throw new PluginManagerException( "Failed to create realm for plugin '" + projectPlugin
|
||||
+ ".", e );
|
||||
}
|
||||
catch ( NoSuchRealmException e )
|
||||
{
|
||||
throw new PluginManagerException(
|
||||
"Failed to import Xpp3Dom from parent realm for plugin: '"
|
||||
+ projectPlugin + ".", e );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// The PluginCollector will now know about the plugin we are trying to load
|
||||
|
|
|
@ -1,153 +0,0 @@
|
|||
package org.apache.maven.plugin;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.PlexusContainerException;
|
||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||
import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:piotr@tabor.waw.pl">Piotr Tabor</a>
|
||||
*/
|
||||
public class DefaultPluginRealmManager
|
||||
extends AbstractLogEnabled
|
||||
implements PluginRealmManager
|
||||
{
|
||||
private PlexusContainer container;
|
||||
|
||||
public ClassRealm getOrCreateRealm( Plugin projectPlugin, Artifact pluginArtifact, Set artifacts )
|
||||
throws PluginManagerException
|
||||
{
|
||||
Set allArtifacts = new HashSet( artifacts );
|
||||
allArtifacts.add( pluginArtifact );
|
||||
|
||||
List/* <URL> */pluginJars = generateJarsListForArtifacts( allArtifacts );
|
||||
|
||||
String realmKey = generateChildContainerName( projectPlugin, allArtifacts );
|
||||
ClassRealm pluginRealm = container.getComponentRealm( realmKey );
|
||||
|
||||
if ( ( pluginRealm != null ) && ( pluginRealm != container.getContainerRealm() ) )
|
||||
{
|
||||
getLogger().debug( "Realm already exists for: " + realmKey + ". Skipping addition..." );
|
||||
/*
|
||||
* we've already discovered this plugin, and configured it, so skip it this time.
|
||||
*/
|
||||
return pluginRealm;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Realm creation for a plugin
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
ClassRealm componentRealm = null;
|
||||
|
||||
try
|
||||
{
|
||||
// Now here we need the artifact coreArtifactFilter
|
||||
// stuff
|
||||
|
||||
componentRealm = container.createComponentRealm( realmKey, pluginJars );
|
||||
|
||||
/*
|
||||
* adding for MNG-3012 to try to work around problems with Xpp3Dom (from plexus-utils spawning a
|
||||
* ClassCastException when a mojo calls plugin.getConfiguration() from maven-model...
|
||||
*/
|
||||
componentRealm.importFrom( componentRealm.getParentRealm().getId(), Xpp3Dom.class.getName() );
|
||||
componentRealm.importFrom( componentRealm.getParentRealm().getId(), "org.codehaus.plexus.util.xml.pull" );
|
||||
|
||||
/*
|
||||
* Adding for MNG-2878, since maven-reporting-impl was removed from the internal list of artifacts managed
|
||||
* by maven, the classloader is different between maven-reporting-impl and maven-reporting-api...so this
|
||||
* resource is not available from the AbstractMavenReport since it uses: getClass().getResourceAsStream(
|
||||
* "/default-report.xml" ) (maven-reporting-impl version 2.0; line 134; affects: checkstyle plugin, and
|
||||
* probably others)
|
||||
*/
|
||||
componentRealm.importFrom( componentRealm.getParentRealm().getId(), "/default-report.xml" );
|
||||
|
||||
}
|
||||
catch ( PlexusContainerException e )
|
||||
{
|
||||
throw new PluginManagerException( "Failed to create realm for plugin '" + projectPlugin + ".", e );
|
||||
}
|
||||
catch ( NoSuchRealmException e )
|
||||
{
|
||||
throw new PluginManagerException( "Failed to import Xpp3Dom from parent realm for plugin: '" +
|
||||
projectPlugin + ".", e );
|
||||
}
|
||||
|
||||
getLogger().debug( "Realm for plugin: " + realmKey + ":\n" + componentRealm );
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// The PluginCollector will now know about the plugin we
|
||||
// are trying to load
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
return componentRealm;
|
||||
}
|
||||
|
||||
List/* <URL> */generateJarsListForArtifacts( Set/* <Artifact> */artifacts )
|
||||
{
|
||||
List/* <URL> */jars = new ArrayList();
|
||||
|
||||
for ( Iterator i = artifacts.iterator(); i.hasNext(); )
|
||||
{
|
||||
Artifact artifact = (Artifact) i.next();
|
||||
|
||||
jars.add( artifact.getFile() );
|
||||
}
|
||||
|
||||
return jars;
|
||||
}
|
||||
|
||||
|
||||
private static String generateChildContainerName( Plugin plugin, Set artifacts )
|
||||
{
|
||||
return plugin.getKey() + ":" + plugin.getVersion() + ":" + getHashOfArtifacts( artifacts );
|
||||
}
|
||||
|
||||
static long getHashOfArtifacts( Set a )
|
||||
{
|
||||
long i = 1;
|
||||
Iterator/* <Artifact> */iterator = a.iterator();
|
||||
while ( iterator.hasNext() )
|
||||
{
|
||||
Artifact artifact = (Artifact) iterator.next();
|
||||
i = ( i * artifact.hashCode() ) % 2147483647 /* big prime */;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
|
@ -31,26 +31,18 @@ import java.util.HashSet;
|
|||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class MavenPluginCollector
|
||||
extends AbstractLogEnabled
|
||||
implements ComponentDiscoveryListener
|
||||
{
|
||||
/**
|
||||
* Map from pluginDescriptor.getKey (groupId:artifactId) into (ordered) map from version into pluginDescriptor
|
||||
* Internal map is ordered to make sure that builds are determinic (used pluginVersion is determined)
|
||||
*/
|
||||
private Map/* <String,OrderedMap<String,PluginDescriptor>> */pluginDescriptors = new HashMap();
|
||||
|
||||
private Map/* <String,OrderedMap<String,PluginDescriptor>> */pluginIdsByPrefix = new HashMap();
|
||||
private Set pluginsInProcess = new HashSet();
|
||||
|
||||
private Map pluginDescriptors = new HashMap();
|
||||
|
||||
private Map pluginIdsByPrefix = new HashMap();
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return "maven-plugin-collector";
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Mojo discovery
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -61,125 +53,66 @@ public class MavenPluginCollector
|
|||
if ( componentSetDescriptor instanceof PluginDescriptor )
|
||||
{
|
||||
PluginDescriptor pluginDescriptor = (PluginDescriptor) componentSetDescriptor;
|
||||
|
||||
// TODO: see comment in getPluginDescriptor
|
||||
String key = Plugin.constructKey( pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId() );
|
||||
|
||||
putIntoPluginDescriptors( pluginDescriptor );
|
||||
putIntoPluginIdsByPrefix( pluginDescriptor );
|
||||
if ( !pluginsInProcess.contains( key ) )
|
||||
{
|
||||
pluginsInProcess.add( key );
|
||||
|
||||
getLogger().debug( this + ": Discovered plugin: " + key );
|
||||
|
||||
pluginDescriptors.put( key, pluginDescriptor );
|
||||
|
||||
// TODO: throw an (not runtime) exception if there is a prefix overlap - means doing so elsewhere
|
||||
// we also need to deal with multiple versions somehow - currently, first wins
|
||||
if ( !pluginIdsByPrefix.containsKey( pluginDescriptor.getGoalPrefix() ) )
|
||||
{
|
||||
pluginIdsByPrefix.put( pluginDescriptor.getGoalPrefix(), pluginDescriptor );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return "maven-plugin-collector";
|
||||
}
|
||||
|
||||
public PluginDescriptor getPluginDescriptor( Plugin plugin )
|
||||
{
|
||||
SortedMap/* <String,PluginDescriptor> */pluginVersions = (SortedMap) pluginDescriptors.get( plugin.getKey() );
|
||||
if ( pluginVersions != null )
|
||||
{
|
||||
PluginDescriptor res;
|
||||
if ( plugin.getVersion() != null )
|
||||
{
|
||||
res = (PluginDescriptor) pluginVersions.get( plugin.getVersion() );
|
||||
}
|
||||
else
|
||||
{
|
||||
res = getDefaultPluginDescriptorVersion( pluginVersions );
|
||||
}
|
||||
return res;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private PluginDescriptor getDefaultPluginDescriptorVersion( SortedMap pluginVersions )
|
||||
{
|
||||
if ( pluginVersions.size() > 0 )
|
||||
{
|
||||
return (PluginDescriptor) pluginVersions.get( pluginVersions.lastKey() );
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
// TODO: include version, but can't do this in the plugin manager as it is not resolved to the right version
|
||||
// at that point. Instead, move the duplication check to the artifact container, or store it locally based on
|
||||
// the unresolved version?
|
||||
return (PluginDescriptor) pluginDescriptors.get( plugin.getKey() );
|
||||
}
|
||||
|
||||
public boolean isPluginInstalled( Plugin plugin )
|
||||
{
|
||||
// TODO: see comment in getPluginDescriptor
|
||||
return getPluginDescriptor( plugin ) != null;
|
||||
return pluginDescriptors.containsKey( plugin.getKey() );
|
||||
}
|
||||
|
||||
public PluginDescriptor getPluginDescriptorForPrefix( String prefix )
|
||||
{
|
||||
return getPluginDescriptorForPrefix( prefix, null );
|
||||
return (PluginDescriptor) pluginIdsByPrefix.get( prefix );
|
||||
}
|
||||
|
||||
public PluginDescriptor getPluginDescriptorForPrefix( String prefix, String version )
|
||||
public void flushPluginDescriptor( Plugin plugin )
|
||||
{
|
||||
SortedMap/* <String,PluginDescriptor> */pluginVersions = (SortedMap) pluginIdsByPrefix.get( prefix );
|
||||
if ( pluginVersions != null )
|
||||
pluginsInProcess.remove( plugin.getKey() );
|
||||
pluginDescriptors.remove( plugin.getKey() );
|
||||
|
||||
for ( Iterator it = pluginIdsByPrefix.entrySet().iterator(); it.hasNext(); )
|
||||
{
|
||||
PluginDescriptor res;
|
||||
if ( version != null )
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
|
||||
if ( plugin.getKey().equals( entry.getValue() ) )
|
||||
{
|
||||
res = (PluginDescriptor) pluginVersions.get( version );
|
||||
it.remove();
|
||||
}
|
||||
else
|
||||
{
|
||||
res = getDefaultPluginDescriptorVersion( pluginVersions );
|
||||
}
|
||||
return res;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// public void flushPluginDescriptor( Plugin plugin )
|
||||
// {
|
||||
// getPluginDescriptor( plugin ).cleanPluginDescriptor();
|
||||
// }
|
||||
|
||||
/**
|
||||
* Puts given pluginDescriptor into pluginDescriptors map (if the map does not contains plugin for specified maven
|
||||
* version)
|
||||
*
|
||||
* @param pluginDescriptor
|
||||
*/
|
||||
protected void putIntoPluginDescriptors( PluginDescriptor pluginDescriptor )
|
||||
{
|
||||
String key = Plugin.constructKey( pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId() );
|
||||
|
||||
SortedMap/* <String,PluginDescriptor> */descriptorsVersions = (SortedMap) pluginDescriptors.get( key );
|
||||
if ( descriptorsVersions == null )
|
||||
{
|
||||
descriptorsVersions = new TreeMap();
|
||||
pluginDescriptors.put( key, descriptorsVersions );
|
||||
}
|
||||
|
||||
putIntoVersionsMap( descriptorsVersions, pluginDescriptor );
|
||||
}
|
||||
|
||||
protected void putIntoVersionsMap( SortedMap/* <String(version),PluginDescriptor> */pluginVersions,
|
||||
PluginDescriptor pluginDescriptor )
|
||||
{
|
||||
if ( !pluginVersions.containsKey( pluginDescriptor.getVersion() ) )
|
||||
{
|
||||
pluginVersions.put( pluginDescriptor.getVersion(), pluginDescriptor );
|
||||
}
|
||||
}
|
||||
|
||||
protected void putIntoPluginIdsByPrefix( PluginDescriptor pluginDescriptor )
|
||||
{
|
||||
String goalPrefix = pluginDescriptor.getGoalPrefix();
|
||||
|
||||
SortedMap/* <String,PluginDescriptor> */descriptorsVersions = (SortedMap) pluginIdsByPrefix.get( goalPrefix );
|
||||
if ( descriptorsVersions == null )
|
||||
{
|
||||
descriptorsVersions = new TreeMap();
|
||||
pluginIdsByPrefix.put( goalPrefix, descriptorsVersions );
|
||||
}
|
||||
|
||||
putIntoVersionsMap( descriptorsVersions, pluginDescriptor );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
package org.apache.maven.plugin;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:piotr@tabor.waw.pl">Piotr Tabor</a>
|
||||
*/
|
||||
public interface PluginRealmManager
|
||||
{
|
||||
public static final String ROLE=PluginRealmManager.class.getName();
|
||||
|
||||
public ClassRealm getOrCreateRealm( Plugin projectPlugin, Artifact pluginArtifact, Set artifacts ) throws PluginManagerException;
|
||||
}
|
|
@ -64,10 +64,7 @@ under the License.
|
|||
<requirement>
|
||||
<role>org.apache.maven.plugin.MavenPluginCollector</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.plugin.PluginRealmManager</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.plugin.version.PluginVersionManager</role>
|
||||
<role-hint>default</role-hint>
|
||||
</requirement>
|
||||
|
@ -731,14 +728,5 @@ under the License.
|
|||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
<component>
|
||||
<role>org.apache.maven.plugin.PluginRealmManager</role>
|
||||
<implementation>org.apache.maven.plugin.DefaultPluginRealmManager</implementation>
|
||||
<requirements>
|
||||
<requirement>
|
||||
<role>org.codehaus.plexus.PlexusContainer</role>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
</components>
|
||||
</component-set>
|
||||
|
|
|
@ -1,130 +0,0 @@
|
|||
package org.apache.maven.plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
import org.codehaus.plexus.PlexusTestCase;
|
||||
|
||||
public class DefaultPluginRealmManagerTest
|
||||
extends PlexusTestCase
|
||||
{
|
||||
public void testCreateComponent()
|
||||
throws Exception
|
||||
{
|
||||
assertNotNull( "Cannot lookup component: " + PluginRealmManager.ROLE, lookup( PluginRealmManager.ROLE ) );
|
||||
}
|
||||
|
||||
public void testGenerateJarsListForArtifactsEmpty()
|
||||
throws Exception
|
||||
{
|
||||
DefaultPluginRealmManager defaultPluginRealmManager = new DefaultPluginRealmManager();
|
||||
|
||||
assertEquals( "List of jars generated by empty set should be empty", 0,
|
||||
defaultPluginRealmManager.generateJarsListForArtifacts( Collections.EMPTY_SET ).size() );
|
||||
}
|
||||
|
||||
public void testGenerateJarsListForArtifacts()
|
||||
throws Exception
|
||||
{
|
||||
DefaultPluginRealmManager defaultPluginRealmManager = new DefaultPluginRealmManager();
|
||||
|
||||
/*Different artifactId*/
|
||||
List/* <Artifact> */result =
|
||||
defaultPluginRealmManager.generateJarsListForArtifacts( createArtifactSet( HashSet.class, 5 ) );
|
||||
checkListOfNumeredFiles( 5, result );
|
||||
|
||||
/*Different groups*/
|
||||
result =
|
||||
defaultPluginRealmManager.generateJarsListForArtifacts( createArtifactSetGroups( HashSet.class, 6 ) );
|
||||
checkListOfNumeredFiles( 6, result );
|
||||
|
||||
/*Different versions*/
|
||||
result =
|
||||
defaultPluginRealmManager.generateJarsListForArtifacts( createArtifactSetVersions( HashSet.class, 4 ) );
|
||||
checkListOfNumeredFiles( 4, result );
|
||||
}
|
||||
|
||||
public void testGetHashOfArtifacts() throws Exception
|
||||
{
|
||||
assertEquals("Hash code of empty set should be always the same", DefaultPluginRealmManager.getHashOfArtifacts( Collections.EMPTY_SET), DefaultPluginRealmManager.getHashOfArtifacts( Collections.EMPTY_SET));
|
||||
assertEquals("Hash code should be the same for the same content of artifacts list",DefaultPluginRealmManager.getHashOfArtifacts(createArtifactSet(HashSet.class,5)),DefaultPluginRealmManager.getHashOfArtifacts(createArtifactSet(HashSet.class,5)));
|
||||
assertEquals("Hash code should not depend on set implementation",DefaultPluginRealmManager.getHashOfArtifacts(createArtifactSet(HashSet.class,5)),DefaultPluginRealmManager.getHashOfArtifacts(createArtifactSet(TreeSet.class,5)));
|
||||
|
||||
assertTrue( "Hash should be different for different content", DefaultPluginRealmManager.getHashOfArtifacts(createArtifactSet(HashSet.class,5))!=DefaultPluginRealmManager.getHashOfArtifacts(createArtifactSet(TreeSet.class,6)));
|
||||
}
|
||||
|
||||
|
||||
// =========================== Helpers ====================================================
|
||||
|
||||
private void checkListOfNumeredFiles( int count, List/* <File> */result )
|
||||
throws MalformedURLException
|
||||
{
|
||||
assertEquals( "Unexpected size of created urls list: ", count, result.size() );
|
||||
for ( int i = 0; i < count; i++ )
|
||||
{
|
||||
File expectedFile = createNumberedFile( i );
|
||||
assertTrue( "Expected url not found: " + expectedFile + " in: " + result, result.contains( expectedFile ) );
|
||||
}
|
||||
}
|
||||
|
||||
protected Artifact createArtifact( String groupId, String artifactId, String version )
|
||||
throws Exception
|
||||
{
|
||||
ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
|
||||
|
||||
// TODO: used to be SCOPE_COMPILE, check
|
||||
return artifactFactory.createBuildArtifact( groupId, artifactId, version, "jar" );
|
||||
}
|
||||
|
||||
protected Set/* <Artifact> */createArtifactSet( Class/* <? extends Set> */setClass, int count )
|
||||
throws Exception
|
||||
{
|
||||
Set/* <Artifact> */artifactSet = (Set) setClass.newInstance();
|
||||
for ( int i = 0; i < count; i++ )
|
||||
{
|
||||
Artifact artifact = createArtifact( "testGroup", "testArtifact_" + i, "1.0" );
|
||||
artifact.setFile( createNumberedFile( i ) );
|
||||
artifactSet.add( artifact );
|
||||
}
|
||||
return artifactSet;
|
||||
}
|
||||
|
||||
protected Set/* <Artifact> */createArtifactSetVersions( Class/* <? extends Set> */setClass, int count )
|
||||
throws Exception
|
||||
{
|
||||
Set/* <Artifact> */artifactSet = (Set) setClass.newInstance();
|
||||
for ( int i = 0; i < count; i++ )
|
||||
{
|
||||
Artifact artifact = createArtifact( "testGroup", "testArtifact", i + ".0" );
|
||||
artifact.setFile( createNumberedFile( i ) );
|
||||
artifactSet.add( artifact );
|
||||
}
|
||||
return artifactSet;
|
||||
}
|
||||
|
||||
protected Set/* <Artifact> */createArtifactSetGroups( Class/* <? extends Set> */setClass, int count )
|
||||
throws Exception
|
||||
{
|
||||
Set/* <Artifact> */artifactSet = (Set) setClass.newInstance();
|
||||
for ( int i = 0; i < count; i++ )
|
||||
{
|
||||
Artifact artifact = createArtifact( "testGroup" + i, "testArtifact_", "1.0" );
|
||||
artifact.setFile( createNumberedFile( i ) );
|
||||
artifactSet.add( artifact );
|
||||
}
|
||||
return artifactSet;
|
||||
}
|
||||
|
||||
protected File createNumberedFile( int i )
|
||||
{
|
||||
return new File( "/not_existing_file_" + i + ".jar" );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue