brett 2005/03/22 23:23:23
Modified: maven-artifact/src/main/java/org/apache/maven/artifact/resolver
ArtifactResolver.java DefaultArtifactResolver.java
maven-artifact/src/main/java/org/apache/maven/artifact
AbstractArtifactComponent.java
maven-artifact/src/main/resources/META-INF/plexus
components.xml
Added: maven-artifact/src/main/java/org/apache/maven/artifact/transform
ArtifactTransformation.java
SnapshotTransformation.java
Removed:
maven-artifact/src/main/java/org/apache/maven/artifact/resolver/transform
ArtifactRequestTransformation.java
ArtifactRequestTransformationException.java
SnapshotRequestTransformation.java
Log:
move artifact transformations out of the resolver so they can be used on any
artifact component
Revision Changes Path
1.6 +1 -5
maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolver.java
Index: ArtifactResolver.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolver.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ArtifactResolver.java 23 Mar 2005 03:40:13 -0000 1.5
+++ ArtifactResolver.java 23 Mar 2005 07:23:23 -0000 1.6
@@ -54,8 +54,4 @@
ArtifactRepository
localRepository, ArtifactMetadataSource source,
ArtifactFilter filter )
throws ArtifactResolutionException;
-
- void addArtifactRequestTransformation(
-
org.apache.maven.artifact.resolver.transform.ArtifactRequestTransformation
requestTransformation );
-
}
\ No newline at end of file
1.23 +0 -12
maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
Index: DefaultArtifactResolver.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- DefaultArtifactResolver.java 23 Mar 2005 03:40:13 -0000 1.22
+++ DefaultArtifactResolver.java 23 Mar 2005 07:23:23 -0000 1.23
@@ -25,7 +25,6 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import
org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
-import
org.apache.maven.artifact.resolver.transform.ArtifactRequestTransformation;
import org.apache.maven.wagon.TransferFailedException;
import org.codehaus.plexus.logging.Logger;
@@ -47,12 +46,6 @@
implements ArtifactResolver
{
// ----------------------------------------------------------------------
- // Fields
- // ----------------------------------------------------------------------
-
- private List requestTransformations;
-
- // ----------------------------------------------------------------------
// Components
// ----------------------------------------------------------------------
@@ -331,9 +324,4 @@
conflicts.add( newArtifact );
}
-
- public void addArtifactRequestTransformation(
ArtifactRequestTransformation requestTransformation )
- {
-
- }
}
\ No newline at end of file
1.1
maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/transform/ArtifactTransformation.java
Index: ArtifactTransformation.java
===================================================================
package org.apache.maven.artifact.transform;
/*
* Copyright 2001-2005 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.
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import java.util.List;
import java.util.Map;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl </a>
* @version $Id: ArtifactTransformation.java,v 1.1 2005/03/03 15:37:25
* jvanzyl Exp $
*/
public interface ArtifactTransformation
{
static String ROLE = ArtifactTransformation.class.getName();
/**
* Take in a artifact and return the transformed artifact. If no
* transformation has occured the original artifact is returned.
*
* @param artifact Artifact to be transformed.
* @return The transformed Artifact
*/
Artifact transform( Artifact artifact, ArtifactRepository
localRepository, List remoteRepositories, Map parameters )
throws Exception;
}
1.1
maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java
Index: SnapshotTransformation.java
===================================================================
package org.apache.maven.artifact.transform;
/*
* Copyright 2001-2005 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.
*/
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.List;
import java.util.Map;
import java.util.TimeZone;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Michal Maczka </a>
* @version $Id: SnapshotTransformation.java,v 1.1 2005/03/03 15:37:25
* jvanzyl Exp $
*/
public class SnapshotTransformation
implements ArtifactTransformation
{
private ArtifactResolver artifactResolver;
public Artifact transform( Artifact artifact, ArtifactRepository
localRepository, List 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, List
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;
}
}
1.7 +9 -3
maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/AbstractArtifactComponent.java
Index: AbstractArtifactComponent.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/AbstractArtifactComponent.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AbstractArtifactComponent.java 21 Mar 2005 08:18:33 -0000 1.6
+++ AbstractArtifactComponent.java 23 Mar 2005 07:23:23 -0000 1.7
@@ -23,23 +23,29 @@
import
org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
+import java.util.List;
+
/**
- * @todo refactor away
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl </a>
* @version $Id: AbstractArtifactComponent.java,v 1.4 2005/03/08 05:34:52
brett
* Exp $
+ * @todo refactor away
*/
public class AbstractArtifactComponent
extends AbstractLogEnabled
{
+ private List artifactTransformations;
+
private ArtifactHandlerManager artifactHandlerManager;
- protected ArtifactHandler getArtifactHandler( String type ) throws
ArtifactHandlerNotFoundException
+ protected ArtifactHandler getArtifactHandler( String type )
+ throws ArtifactHandlerNotFoundException
{
return artifactHandlerManager.getArtifactHandler( type );
}
- protected String path( Artifact artifact, ArtifactRepository
remoteRepository ) throws ArtifactPathFormatException
+ protected String path( Artifact artifact, ArtifactRepository
remoteRepository )
+ throws ArtifactPathFormatException
{
return remoteRepository.pathOf( artifact );
}
1.12 +14 -2
maven-components/maven-artifact/src/main/resources/META-INF/plexus/components.xml
Index: components.xml
===================================================================
RCS file:
/home/cvs/maven-components/maven-artifact/src/main/resources/META-INF/plexus/components.xml,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- components.xml 23 Mar 2005 04:53:30 -0000 1.11
+++ components.xml 23 Mar 2005 07:23:23 -0000 1.12
@@ -16,6 +16,10 @@
<requirement>
<role>org.apache.maven.artifact.handler.manager.ArtifactHandlerManager</role>
</requirement>
+ <requirement>
+
<role>org.apache.maven.artifact.transform.ArtifactTransformation</role>
+ <field-name>artifactTransformations</field-name>
+ </requirement>
</requirements>
</component>
@@ -46,6 +50,10 @@
<requirement>
<role>org.apache.maven.artifact.handler.manager.ArtifactHandlerManager</role>
</requirement>
+ <requirement>
+
<role>org.apache.maven.artifact.transform.ArtifactTransformation</role>
+ <field-name>artifactTransformations</field-name>
+ </requirement>
</requirements>
</component>
@@ -64,6 +72,10 @@
<requirement>
<role>org.apache.maven.artifact.handler.manager.ArtifactHandlerManager</role>
</requirement>
+ <requirement>
+
<role>org.apache.maven.artifact.transform.ArtifactTransformation</role>
+ <field-name>artifactTransformations</field-name>
+ </requirement>
</requirements>
</component>
@@ -71,7 +83,7 @@
<role>org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout</role>
<role-hint>default</role-hint>
<implementation>org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout</implementation>
- <requirements>
+ <requirements>
<requirement>
<role>org.apache.maven.artifact.handler.manager.ArtifactHandlerManager</role>
</requirement>
@@ -104,7 +116,7 @@
</requirement>
</requirements>
</component>
-
+
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>ejb</role-hint>