o removing deprecated code in the plugin mechanism

o removing dead code
o examining how plugin version resolution is done, and we have a mix of a desire to use snapshots locally and pull releases
  remotely. if the repositories are mixed a snapshot will be pull automagically. this doesn't happen in practice but snapshots
  for plugin versions should be limited to a local search only.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@572872 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2007-09-05 04:38:49 +00:00
parent 8077fb59ac
commit 4925ac9702
6 changed files with 71 additions and 360 deletions

View File

@ -19,79 +19,78 @@
* under the License.
*/
import org.apache.maven.ArtifactFilterManager;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.metadata.ResolutionGroup;
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.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.context.BuildContextManager;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.RuntimeInformation;
import org.apache.maven.lifecycle.LifecycleExecutionContext;
import org.apache.maven.lifecycle.statemgmt.StateManagementUtils;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
import org.apache.maven.monitor.logging.DefaultLog;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugin.version.PluginVersionManager;
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.artifact.MavenMetadataSource;
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.reporting.MavenReport;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.PlexusConstants;
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.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.component.configurator.ComponentConfigurator;
import org.codehaus.plexus.component.configurator.ConfigurationListener;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.apache.maven.ArtifactFilterManager;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.metadata.ResolutionGroup;
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.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.context.BuildContextManager;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.RuntimeInformation;
import org.apache.maven.lifecycle.LifecycleExecutionContext;
import org.apache.maven.lifecycle.statemgmt.StateManagementUtils;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
import org.apache.maven.monitor.logging.DefaultLog;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugin.version.PluginVersionManager;
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.artifact.MavenMetadataSource;
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.reporting.MavenReport;
import org.codehaus.plexus.PlexusConstants;
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.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.component.configurator.ComponentConfigurator;
import org.codehaus.plexus.component.configurator.ConfigurationListener;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class DefaultPluginManager
extends AbstractLogEnabled
@ -164,28 +163,6 @@ public class DefaultPluginManager
session.getLocalRepository() );
}
/**
* @deprecated
*/
public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
PluginVersionNotFoundException
{
// TODO: this should be possibly outside
// All version-resolution logic has been moved to DefaultPluginVersionManager.
if ( plugin.getVersion() == null )
{
getLogger().debug( "Resolving version for plugin: " + plugin.getKey() );
String version = pluginVersionManager.resolvePluginVersion( plugin.getGroupId(), plugin.getArtifactId(),
project, localRepository );
plugin.setVersion( version );
}
return verifyVersionedPlugin( plugin, project, localRepository );
}
public PluginDescriptor verifyPlugin( Plugin plugin,
MavenProject project,
MavenSession session )
@ -250,9 +227,6 @@ public class DefaultPluginManager
artifactResolver.resolve( pluginArtifact, project.getPluginArtifactRepositories(), localRepository );
// if ( !pluginCollector.isPluginInstalled( plugin ) )
// {
// }
addPlugin( plugin, pluginArtifact, project, localRepository );
}
else

View File

@ -62,17 +62,6 @@ public interface PluginManager
Plugin getPluginDefinitionForPrefix( String prefix,
MavenSession session,
MavenProject project );
/**
* @deprecated
*/
PluginDescriptor verifyPlugin( Plugin plugin,
MavenProject project,
Settings settings,
ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
PluginVersionNotFoundException;
PluginDescriptor verifyPlugin( Plugin plugin,
MavenProject project,

View File

@ -58,9 +58,6 @@ public class DefaultPluginVersionManager
private RuntimeInformation runtimeInformation;
// TODO: Revisit to remove this piece of state. PLUGIN REGISTRY MAY BE UPDATED ON DISK OUT-OF-PROCESS!
private Map resolvedMetaVersions = new HashMap();
public String resolvePluginVersion( String groupId,
String artifactId,
MavenProject project,
@ -186,10 +183,6 @@ public class DefaultPluginVersionManager
Artifact artifact = artifactFactory.createProjectArtifact( groupId, artifactId, metaVersionId );
String key = artifact.getDependencyConflictId();
if ( resolvedMetaVersions.containsKey( key ) )
{
return (String) resolvedMetaVersions.get( key );
}
String version = null;
@ -283,7 +276,6 @@ public class DefaultPluginVersionManager
if ( !metaVersionId.equals( artifactVersion ) )
{
version = artifactVersion;
resolvedMetaVersions.put( key, version );
}
return version;

View File

@ -1,132 +0,0 @@
package org.apache.maven.plugin.version;
/*
* 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.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class IntervalUtils
{
private static final String PERIOD_PART_PATTERN = "[0-9]+[WwDdHhMm]?";
private static final Map PART_TYPE_CONTRIBUTIONS;
static
{
Map contributions = new HashMap();
contributions.put( "w", new Long( 7 * 24 * 60 * 60 * 1000 ) );
contributions.put( "d", new Long( 24 * 60 * 60 * 1000 ) );
contributions.put( "h", new Long( 60 * 60 * 1000 ) );
contributions.put( "m", new Long( 60 * 1000 ) );
PART_TYPE_CONTRIBUTIONS = contributions;
}
private IntervalUtils()
{
// don't allow construction
}
public static boolean isExpired( String intervalSpec, Date lastChecked )
{
if( "never".equalsIgnoreCase( intervalSpec ) )
{
return false;
}
else if( "always".equalsIgnoreCase( intervalSpec ) )
{
return true;
}
else if( intervalSpec != null && intervalSpec.toLowerCase().startsWith("interval:") && intervalSpec.length() > "interval:".length())
{
String intervalPart = intervalSpec.substring( "interval:".length() );
// subtract the specified period from now() and see if it's still after the lastChecked date.
long period = IntervalUtils.parseInterval(intervalPart);
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis( System.currentTimeMillis() - period );
Date test = cal.getTime();
return lastChecked == null || test.after( lastChecked );
}
else
{
throw new IllegalArgumentException( "Invalid interval specification: \'" + intervalSpec + "\'" );
}
}
public static long parseInterval( String interval )
{
Matcher partMatcher = Pattern.compile(PERIOD_PART_PATTERN).matcher(interval);
long period = 0;
while( partMatcher.find() )
{
String part = partMatcher.group();
period += getPartPeriod( part );
}
return period;
}
private static long getPartPeriod( String part )
{
char type = part.charAt( part.length() - 1 );
String coefficientPart;
if( Character.isLetter(type))
{
coefficientPart = part.substring( 0, part.length() - 1);
}
else
{
// if the interval doesn't specify a resolution, assume minutes.
coefficientPart = part;
type = 'm';
}
int coefficient = Integer.parseInt( coefficientPart );
Long period = (Long) PART_TYPE_CONTRIBUTIONS.get( "" + Character.toLowerCase( type ) );
long result = 0;
if( period != null )
{
result = coefficient * period.longValue();
}
return result;
}
}

View File

@ -28,12 +28,6 @@ public interface PluginVersionManager
{
String ROLE = PluginVersionManager.class.getName();
/**
* @deprecated
*/
String resolvePluginVersion( String groupId, String artifactId, MavenProject project, ArtifactRepository localRepository )
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException;
String resolvePluginVersion( String groupId, String artifactId, MavenProject project, MavenSession session )
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException;

View File

@ -1,106 +0,0 @@
package org.apache.maven.plugin.version;
/*
* 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 junit.framework.TestCase;
import java.util.Calendar;
import java.util.Date;
public class IntervalUtilsTest
extends TestCase
{
private static final long ONE_MINUTE = 60 * 1000;
private static final long ONE_HOUR = 60 * ONE_MINUTE;
private static final long ONE_DAY = 24 * ONE_HOUR;
private static final long ONE_WEEK = 7 * ONE_DAY;
public void testOneWeek()
{
assertEquals( ONE_WEEK, IntervalUtils.parseInterval( "1w" ) );
}
public void testTwoWeeks()
{
assertEquals( ( 2 * ONE_WEEK ), IntervalUtils.parseInterval( "2w" ) );
}
public void testOneDay()
{
assertEquals( ONE_DAY, IntervalUtils.parseInterval( "1d" ) );
}
public void testOneHour()
{
assertEquals( ONE_HOUR, IntervalUtils.parseInterval( "1h" ) );
}
public void testOneMinute()
{
assertEquals( ONE_MINUTE, IntervalUtils.parseInterval( "1m" ) );
}
public void testTwoDaysThreeHoursAndOneMinute()
{
assertEquals( 2 * ONE_DAY + 3 * ONE_HOUR + ONE_MINUTE, IntervalUtils.parseInterval( "2d 3h 1m" ) );
}
public void testTwoDaysThreeHoursAndOneMinuteCondensed()
{
assertEquals( 2 * ONE_DAY + 3 * ONE_HOUR + ONE_MINUTE, IntervalUtils.parseInterval( "2d3h1m" ) );
}
public void testTwoDaysThreeHoursAndOneMinuteCommaSeparated()
{
assertEquals( 2 * ONE_DAY + 3 * ONE_HOUR + ONE_MINUTE, IntervalUtils.parseInterval( "2d,3h,1m" ) );
}
public void testTwoDaysThreeHoursAndOneMinuteRearranged()
{
assertEquals( 2 * ONE_DAY + 3 * ONE_HOUR + ONE_MINUTE, IntervalUtils.parseInterval( "1m 2d 3h" ) );
}
public void testThreeDaysPoorlySpecified()
{
assertEquals( 3 * ONE_DAY, IntervalUtils.parseInterval( "1d 2d" ) );
}
public void testNeverInterval()
{
assertFalse( IntervalUtils.isExpired( "never", null ) );
}
public void testAlwaysInterval()
{
assertTrue( IntervalUtils.isExpired( "always", null ) );
}
public void testOneMinuteIntervalShouldBeExpired()
{
Calendar cal = Calendar.getInstance();
cal.add( Calendar.MINUTE, -2 );
Date lastChecked = cal.getTime();
assertTrue( IntervalUtils.isExpired( "interval:1m", lastChecked ) );
}
}