mirror of https://github.com/apache/maven.git
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:
parent
8077fb59ac
commit
4925ac9702
|
@ -61,7 +61,6 @@ 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;
|
||||
|
@ -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
|
||||
|
|
|
@ -63,17 +63,6 @@ public interface PluginManager
|
|||
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,
|
||||
MavenSession session )
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 ) );
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue