mirror of https://github.com/apache/maven.git
o moving artifact request transformation mechanism inside the resolver
package as they artifact transformations will be utilized from within the resolver. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163456 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fe4cb5e0bb
commit
0c42b64caf
|
@ -1,26 +0,0 @@
|
|||
package org.apache.maven.artifact.request;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class ArtifactRequest
|
||||
{
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package org.apache.maven.artifact.resolver;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.resolver.transform.ArtifactRequestTransformation;
|
||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
|
@ -50,5 +51,6 @@ public interface ArtifactResolver
|
|||
ArtifactFilter filter )
|
||||
throws ArtifactResolutionException;
|
||||
|
||||
void addArtifactRequestTransformation( org.apache.maven.artifact.resolver.transform.ArtifactRequestTransformation requestTransformation );
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.apache.maven.artifact.resolver;
|
|||
|
||||
import org.apache.maven.artifact.AbstractArtifactComponent;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.resolver.transform.ArtifactRequestTransformation;
|
||||
import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
|
||||
import org.apache.maven.artifact.manager.WagonManager;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||
|
@ -22,8 +23,22 @@ public class DefaultArtifactResolver
|
|||
extends AbstractArtifactComponent
|
||||
implements ArtifactResolver
|
||||
{
|
||||
// ----------------------------------------------------------------------
|
||||
// Fields
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private List requestTransformations;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Components
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private WagonManager wagonManager;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public Artifact resolve( Artifact artifact,
|
||||
Set remoteRepositories,
|
||||
ArtifactRepository localRepository )
|
||||
|
@ -284,16 +299,8 @@ public class DefaultArtifactResolver
|
|||
conflicts.add( newArtifact );
|
||||
}
|
||||
|
||||
protected boolean includeArtifact( String artifactId, String[] artifactExcludes )
|
||||
public void addArtifactRequestTransformation( ArtifactRequestTransformation requestTransformation )
|
||||
{
|
||||
for ( int b = 0; b < artifactExcludes.length; b++ )
|
||||
{
|
||||
if ( artifactId.equals( artifactExcludes[b] ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
package org.apache.maven.artifact.request;
|
||||
package org.apache.maven.artifact.resolver.transform;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
|
@ -16,12 +22,6 @@ package org.apache.maven.artifact.request;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
* @version $Id$
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.artifact.request;
|
||||
package org.apache.maven.artifact.resolver.transform;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
|
@ -0,0 +1,180 @@
|
|||
package org.apache.maven.artifact.resolver.transform;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:mmaczka@interia.pl">Michal Maczka</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class SnapshotRequestTransformation
|
||||
implements ArtifactRequestTransformation
|
||||
{
|
||||
private ArtifactResolver artifactResolver;
|
||||
|
||||
public Artifact transform( Artifact artifact,
|
||||
ArtifactRepository localRepository,
|
||||
Set repositories,
|
||||
Map parameters )
|
||||
throws Exception
|
||||
{
|
||||
Date localVersion = getLocalVersion( artifact, localRepository );
|
||||
|
||||
Date remoteVersion = getRemoteVersion( artifact, repositories, localRepository );
|
||||
|
||||
if ( remoteVersion != null )
|
||||
{
|
||||
//if local version is unknown (null) it means that
|
||||
//we don't have this file locally. so we will be happy
|
||||
// to have any snapshot.
|
||||
// we wil download in two cases:
|
||||
// a) we don't have any snapot in local repo
|
||||
// b) we have found newer version in remote repository
|
||||
if ( localVersion == null || localVersion.before( remoteVersion ) )
|
||||
{
|
||||
// here we know that we have artifact like foo-1.2-SNAPSHOT.jar
|
||||
// and the remote timestamp is something like 20010304.121212
|
||||
// so we might as well fetch foo-1.2-20010304.121212.jar
|
||||
// but we are just going to fetch foo-1.2-SNAPSHOT.jar.
|
||||
// We can change the strategy which is used here later on
|
||||
|
||||
// @todo we will delete old file first.
|
||||
//it is not really a right thing to do. Artifact Dowloader should
|
||||
// fetch to temprary file and replace the old file with the new
|
||||
// one once download was finished
|
||||
|
||||
artifact.getFile().delete();
|
||||
|
||||
artifactResolver.resolve( artifact, repositories, localRepository );
|
||||
|
||||
File snapshotVersionFile = getSnapshotVersionFile( artifact, localRepository );
|
||||
|
||||
String timestamp = getTimestamp( remoteVersion );
|
||||
|
||||
// delete old one
|
||||
if ( snapshotVersionFile.exists() )
|
||||
{
|
||||
snapshotVersionFile.delete();
|
||||
}
|
||||
|
||||
FileUtils.fileWrite( snapshotVersionFile.getPath(), timestamp );
|
||||
}
|
||||
}
|
||||
|
||||
return artifact;
|
||||
}
|
||||
|
||||
private File getSnapshotVersionFile( Artifact artifact, ArtifactRepository localRepository )
|
||||
{
|
||||
return null;
|
||||
//return new File( localRepository.fullArtifactPath( artifact ) );
|
||||
}
|
||||
|
||||
private Date getRemoteVersion( Artifact artifact, Set remoteRepositories, ArtifactRepository localRepository )
|
||||
throws Exception
|
||||
{
|
||||
Date retValue = null;
|
||||
|
||||
artifactResolver.resolve( artifact, remoteRepositories, localRepository );
|
||||
|
||||
String timestamp = FileUtils.fileRead( artifact.getPath() );
|
||||
|
||||
retValue = parseTimestamp( timestamp );
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
private Date getLocalVersion( Artifact artifact, ArtifactRepository localRepository )
|
||||
{
|
||||
//assert artifact.exists();
|
||||
|
||||
Date retValue = null;
|
||||
|
||||
try
|
||||
{
|
||||
File file = getSnapshotVersionFile( artifact, localRepository );
|
||||
|
||||
if ( file.exists() )
|
||||
{
|
||||
String timestamp = FileUtils.fileRead( file );
|
||||
|
||||
retValue = parseTimestamp( timestamp );
|
||||
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
if ( retValue == null )
|
||||
{
|
||||
//try "traditional method" used in maven1 for obtaining snapshot version
|
||||
|
||||
File file = artifact.getFile();
|
||||
|
||||
if ( file.exists() )
|
||||
{
|
||||
retValue = new Date( file.lastModified() );
|
||||
|
||||
//@todo we should "normalize" the time.
|
||||
|
||||
/*TimeZone gmtTimeZone = TimeZone.getTimeZone( "GMT" );
|
||||
|
||||
TimeZone userTimeZone = TimeZone.getDefault();
|
||||
|
||||
long diff =
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
private final static String DATE_FORMAT = "yyyyMMdd.HHmmss";
|
||||
|
||||
private static SimpleDateFormat getFormatter()
|
||||
{
|
||||
SimpleDateFormat formatter = new SimpleDateFormat( DATE_FORMAT );
|
||||
|
||||
formatter.setTimeZone( TimeZone.getTimeZone( "GMT" ) );
|
||||
|
||||
return formatter;
|
||||
}
|
||||
|
||||
public static String getTimestamp()
|
||||
{
|
||||
Date now = new Date();
|
||||
|
||||
SimpleDateFormat formatter = getFormatter();
|
||||
|
||||
String retValue = formatter.format( now );
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
public static Date parseTimestamp ( String timestamp )
|
||||
throws ParseException
|
||||
{
|
||||
Date retValue = getFormatter().parse( timestamp );
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
public static String getTimestamp ( Date snapshotVersion )
|
||||
{
|
||||
String retValue = getFormatter().format( snapshotVersion );
|
||||
|
||||
return retValue;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue