mirror of https://github.com/apache/maven.git
add artifact metadata on installation of snapshot in a local repository
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163676 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5e2caf89c7
commit
2727721b11
|
@ -16,8 +16,14 @@ package org.apache.maven.artifact;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadata;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Description of an artifact.
|
||||
*/
|
||||
public interface Artifact
|
||||
{
|
||||
// TODO: into scope handler
|
||||
|
@ -61,4 +67,8 @@ public interface Artifact
|
|||
String getId();
|
||||
|
||||
String getConflictId();
|
||||
|
||||
void addMetadata( ArtifactMetadata metadata );
|
||||
|
||||
List getMetadataList();
|
||||
}
|
|
@ -16,9 +16,13 @@ package org.apache.maven.artifact;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadata;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
|
||||
|
@ -46,6 +50,8 @@ public class DefaultArtifact
|
|||
|
||||
private String path;
|
||||
|
||||
private List metadataList;
|
||||
|
||||
/**
|
||||
* @todo this should be replaced by type handler
|
||||
* !!! WARNING !!! Never put <classifier/> in the POM. It is for mojo use
|
||||
|
@ -161,6 +167,20 @@ public class DefaultArtifact
|
|||
return getGroupId() + ":" + getArtifactId() + ":" + getType();
|
||||
}
|
||||
|
||||
public void addMetadata( ArtifactMetadata metadata )
|
||||
{
|
||||
if ( metadataList == null )
|
||||
{
|
||||
metadataList = new ArrayList();
|
||||
}
|
||||
metadataList.add( metadata );
|
||||
}
|
||||
|
||||
public List getMetadataList()
|
||||
{
|
||||
return metadataList == null ? Collections.EMPTY_LIST : metadataList;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Object overrides
|
||||
// ----------------------------------------------------------------------
|
||||
|
|
|
@ -82,7 +82,6 @@ public class DefaultArtifactHandlerManager
|
|||
// TODO: perform transformation
|
||||
}
|
||||
|
||||
String artifactPath = localRepository.getBasedir() + "/" + localRepository.pathOf( artifact );
|
||||
return artifactPath;
|
||||
return localRepository.getBasedir() + "/" + localRepository.pathOf( artifact );
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@ package org.apache.maven.artifact.installer;
|
|||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
|
||||
import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadata;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
|
@ -26,6 +27,7 @@ import org.codehaus.plexus.util.FileUtils;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class DefaultArtifactInstaller
|
||||
extends AbstractLogEnabled
|
||||
|
@ -65,6 +67,13 @@ public class DefaultArtifactInstaller
|
|||
getLogger().info( "Installing " + source.getPath() + " to " + artifact.getPath() );
|
||||
|
||||
FileUtils.copyFile( source, artifact.getFile() );
|
||||
|
||||
// must be after the artifact is installed
|
||||
for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )
|
||||
{
|
||||
ArtifactMetadata metadata = (ArtifactMetadata) i.next();
|
||||
metadata.storeInLocalRepository( localRepository );
|
||||
}
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package org.apache.maven.artifact.metadata;
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Common elements of artifact metadata.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public abstract class AbstractArtifactMetadata
|
||||
implements ArtifactMetadata
|
||||
{
|
||||
protected final String filename;
|
||||
|
||||
protected final Artifact artifact;
|
||||
|
||||
protected AbstractArtifactMetadata( Artifact artifact, String filename )
|
||||
{
|
||||
this.artifact = artifact;
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
public Artifact getArtifact()
|
||||
{
|
||||
return artifact;
|
||||
}
|
||||
|
||||
public String getFilename()
|
||||
{
|
||||
return filename;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package org.apache.maven.artifact.metadata;
|
||||
|
||||
/*
|
||||
* 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.repository.layout.ArtifactPathFormatException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Contains metadata about an artifact, and methods to retrieve/store it from an artifact repository.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
* @todo naming is too close to ArtifactMetadataSource which refers to a POM. A POM is sometimes an artifact itself,
|
||||
* so that naming may no longer be appropriate.
|
||||
*/
|
||||
public interface ArtifactMetadata
|
||||
{
|
||||
/**
|
||||
* Store the metadata in the local repository.
|
||||
*
|
||||
* @param localRepository the local repository
|
||||
*/
|
||||
void storeInLocalRepository( ArtifactRepository localRepository )
|
||||
throws IOException, ArtifactPathFormatException;
|
||||
|
||||
/**
|
||||
* Get the associated artifact.
|
||||
*
|
||||
* @return the artifact
|
||||
*/
|
||||
Artifact getArtifact();
|
||||
|
||||
/**
|
||||
* Get the filename of this metadata.
|
||||
*
|
||||
* @return the filename
|
||||
*/
|
||||
String getFilename();
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
package org.apache.maven.artifact.metadata;
|
||||
|
||||
/*
|
||||
* 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.repository.layout.ArtifactPathFormatException;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Contains the information stored for a snapshot.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class SnapshotArtifactMetadata
|
||||
extends AbstractArtifactMetadata
|
||||
{
|
||||
private String timestamp = null;
|
||||
|
||||
private int buildNumber = 1;
|
||||
|
||||
private static final String SNAPSHOT_VERSION_LOCAL_FILE = "version-local.txt";
|
||||
|
||||
private static final String SNAPSHOT_VERSION_FILE = "version.txt";
|
||||
|
||||
private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
|
||||
|
||||
private SnapshotArtifactMetadata( Artifact artifact, String filename )
|
||||
{
|
||||
super( artifact, filename );
|
||||
}
|
||||
|
||||
public static SnapshotArtifactMetadata createLocalSnapshotMetadata( Artifact artifact )
|
||||
{
|
||||
return new SnapshotArtifactMetadata( artifact, SNAPSHOT_VERSION_LOCAL_FILE );
|
||||
}
|
||||
|
||||
public void storeInLocalRepository( ArtifactRepository localRepository )
|
||||
throws IOException, ArtifactPathFormatException
|
||||
{
|
||||
FileUtils.fileWrite( localRepository.getBasedir() + "/" + localRepository.pathOfMetadata( this ),
|
||||
getTimestamp() + "-" + buildNumber );
|
||||
}
|
||||
|
||||
public String getTimestamp()
|
||||
{
|
||||
if ( timestamp == null )
|
||||
{
|
||||
timestamp = getUtcDateFormatter().format( new Date() );
|
||||
}
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public DateFormat getUtcDateFormatter()
|
||||
{
|
||||
DateFormat utcDateFormatter = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
|
||||
utcDateFormatter.setTimeZone( UTC_TIME_ZONE );
|
||||
return utcDateFormatter;
|
||||
}
|
||||
}
|
|
@ -17,6 +17,7 @@ package org.apache.maven.artifact.repository;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadata;
|
||||
import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
|
||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
||||
import org.apache.maven.wagon.authentication.AuthenticationInfo;
|
||||
|
@ -55,4 +56,10 @@ public class ArtifactRepository
|
|||
return layout.pathOf( artifact );
|
||||
}
|
||||
|
||||
public String pathOfMetadata( ArtifactMetadata artifactMetadata )
|
||||
throws ArtifactPathFormatException
|
||||
{
|
||||
return layout.pathOfMetadata( artifactMetadata );
|
||||
}
|
||||
|
||||
}
|
|
@ -20,35 +20,27 @@ import org.apache.maven.artifact.Artifact;
|
|||
import org.apache.maven.artifact.handler.ArtifactHandler;
|
||||
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
|
||||
import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadata;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author jdcasey
|
||||
*/
|
||||
public abstract class AbstractArtifactRepositoryLayout
|
||||
extends AbstractLogEnabled
|
||||
implements ArtifactRepositoryLayout
|
||||
{
|
||||
|
||||
private ArtifactHandlerManager artifactHandlerManager;
|
||||
|
||||
protected abstract String layoutPattern();
|
||||
|
||||
protected abstract String metadataLayoutPattern();
|
||||
|
||||
protected abstract String groupIdAsPath( String groupId );
|
||||
|
||||
public String pathOf( Artifact artifact )
|
||||
throws ArtifactPathFormatException
|
||||
{
|
||||
String path = layoutPattern();
|
||||
|
||||
String groupPath = groupIdAsPath( artifact.getGroupId() );
|
||||
|
||||
path = StringUtils.replace( path, "${groupPath}", groupPath );
|
||||
|
||||
path = StringUtils.replace( path, "${artifactId}", artifact.getArtifactId() );
|
||||
|
||||
path = StringUtils.replace( path, "${version}", artifact.getVersion() );
|
||||
String path = basicPathOf( artifact, layoutPattern() );
|
||||
|
||||
if ( artifact.hasClassifier() )
|
||||
{
|
||||
|
@ -59,6 +51,32 @@ public abstract class AbstractArtifactRepositoryLayout
|
|||
path = StringUtils.replace( path, "-${classifier}", "" );
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public String pathOfMetadata( ArtifactMetadata metadata )
|
||||
throws ArtifactPathFormatException
|
||||
{
|
||||
String path = basicPathOf( metadata.getArtifact(), metadataLayoutPattern() );
|
||||
|
||||
path = StringUtils.replace( path, "${metadataFilename}", metadata.getFilename() );
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
private String basicPathOf( Artifact artifact, String pattern )
|
||||
throws ArtifactPathFormatException
|
||||
{
|
||||
String path = pattern;
|
||||
|
||||
String groupPath = groupIdAsPath( artifact.getGroupId() );
|
||||
|
||||
path = StringUtils.replace( path, "${groupPath}", groupPath );
|
||||
|
||||
path = StringUtils.replace( path, "${artifactId}", artifact.getArtifactId() );
|
||||
|
||||
path = StringUtils.replace( path, "${version}", artifact.getVersion() );
|
||||
|
||||
ArtifactHandler artifactHandler = null;
|
||||
try
|
||||
{
|
||||
|
@ -73,7 +91,6 @@ public abstract class AbstractArtifactRepositoryLayout
|
|||
path = StringUtils.replace( path, "${directory}", artifactHandler.directory() );
|
||||
|
||||
path = StringUtils.replace( path, "${extension}", artifactHandler.extension() );
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ package org.apache.maven.artifact.repository.layout;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadata;
|
||||
|
||||
/**
|
||||
* @author jdcasey
|
||||
|
@ -29,4 +30,6 @@ public interface ArtifactRepositoryLayout
|
|||
String pathOf( Artifact artifact )
|
||||
throws ArtifactPathFormatException;
|
||||
|
||||
String pathOfMetadata( ArtifactMetadata metadata )
|
||||
throws ArtifactPathFormatException;
|
||||
}
|
|
@ -28,6 +28,11 @@ public class DefaultRepositoryLayout
|
|||
return "${groupPath}/${artifactId}/${version}/${artifactId}-${version}-${classifier}.${extension}";
|
||||
}
|
||||
|
||||
protected String metadataLayoutPattern()
|
||||
{
|
||||
return "${groupPath}/${artifactId}/${version}/${metadataFilename}";
|
||||
}
|
||||
|
||||
protected String groupIdAsPath( String groupId )
|
||||
{
|
||||
return groupId.replace( '.', '/' );
|
||||
|
|
|
@ -28,6 +28,11 @@ public class LegacyRepositoryLayout
|
|||
return "${groupPath}/${directory}/${artifactId}-${version}-${classifier}.${extension}";
|
||||
}
|
||||
|
||||
protected String metadataLayoutPattern()
|
||||
{
|
||||
return "${groupPath}/${directory}/${artifactId}-${version}-${metadataFilename}";
|
||||
}
|
||||
|
||||
protected String groupIdAsPath( String groupId )
|
||||
{
|
||||
return groupId;
|
||||
|
|
|
@ -17,6 +17,8 @@ package org.apache.maven.artifact.transform;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadata;
|
||||
import org.apache.maven.artifact.metadata.SnapshotArtifactMetadata;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
|
||||
/**
|
||||
|
@ -185,7 +187,17 @@ public class SnapshotTransformation
|
|||
*/
|
||||
public Artifact transformLocalArtifact( Artifact artifact, ArtifactRepository localRepository )
|
||||
{
|
||||
// TODO: implement
|
||||
if ( isSnapshot( artifact ) && "pom".equals( artifact.getType() ) )
|
||||
{
|
||||
// only store the snapshot-version-local.txt file for POMs as every file has an associated POM
|
||||
ArtifactMetadata metadata = SnapshotArtifactMetadata.createLocalSnapshotMetadata( artifact );
|
||||
artifact.addMetadata( metadata );
|
||||
}
|
||||
return artifact;
|
||||
}
|
||||
|
||||
private static boolean isSnapshot( Artifact artifact )
|
||||
{
|
||||
return artifact.getVersion().endsWith( "SNAPSHOT" );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue