deploy/install POMs as a type of metadata so they are done atomically

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163687 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-03-24 10:30:58 +00:00
parent 7573893dac
commit e697f5bd8c
10 changed files with 124 additions and 40 deletions

View File

@ -30,7 +30,7 @@ public interface ArtifactInstaller
String ROLE = ArtifactInstaller.class.getName();
/**
* Install an artifact from a particular directory. The artifact handler is used to determine the filename
* Install an artifact from a particular directory. The artifact handler is used to determine the filenameSuffix
* of the source file.
*
* @param basedir the directory where the artifact is stored

View File

@ -27,14 +27,19 @@ import org.apache.maven.artifact.Artifact;
public abstract class AbstractArtifactMetadata
implements ArtifactMetadata
{
protected final String filename;
protected final String filenameSuffix;
protected final Artifact artifact;
protected Artifact artifact;
protected AbstractArtifactMetadata( Artifact artifact, String filename )
{
this.artifact = artifact;
this.filename = filename;
this.filenameSuffix = filename;
}
public void setArtifact( Artifact artifact )
{
this.artifact = artifact;
}
public Artifact getArtifact()
@ -42,8 +47,8 @@ public abstract class AbstractArtifactMetadata
return artifact;
}
public String getFilename()
public String getFilenameSuffix()
{
return filename;
return filenameSuffix;
}
}

View File

@ -56,9 +56,18 @@ public interface ArtifactMetadata
Artifact getArtifact();
/**
* Get the filename of this metadata.
* Get the filenameSuffix of this metadata.
*
* @return the filename
* @return the filenameSuffix
*/
String getFilename();
String getFilenameSuffix();
/**
* Set the associated artifact.
*
* @param artifact the artifact
* @todo prefer not to have this, and just modify the artifacts as they are transformed
*/
void setArtifact( Artifact artifact );
}

View File

@ -0,0 +1,66 @@
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.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
import java.io.IOException;
/**
* Attach a POM to an artifact.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class ModelMetadata
extends AbstractArtifactMetadata
{
private final File file;
public ModelMetadata( Artifact artifact, File file )
{
super( artifact, "pom" );
this.file = file;
}
public void storeInLocalRepository( ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException
{
try
{
FileUtils.copyFile( file, new File( localRepository.getBasedir(), localRepository.pathOfMetadata( this ) ) );
}
catch ( ArtifactPathFormatException e )
{
throw new ArtifactMetadataRetrievalException( "Unable to install POM", e );
}
catch ( IOException e )
{
throw new ArtifactMetadataRetrievalException( "Unable to install POM", e );
}
}
public void retrieveFromRemoteRepository( ArtifactRepository remoteRepository, WagonManager wagonManager )
{
// not used - TODO: again indicates bad design?
}
}

View File

@ -59,7 +59,7 @@ public abstract class AbstractArtifactRepositoryLayout
{
String path = basicPathOf( metadata.getArtifact(), metadataLayoutPattern() );
path = StringUtils.replace( path, "${metadataFilename}", metadata.getFilename() );
path = StringUtils.replace( path, "${metadataSuffix}", metadata.getFilenameSuffix() );
return path;
}

View File

@ -30,7 +30,7 @@ public class DefaultRepositoryLayout
protected String metadataLayoutPattern()
{
return "${groupPath}/${artifactId}/${version}/${metadataFilename}";
return "${groupPath}/${artifactId}/${version}/${artifactId}-${version}.${metadataSuffix}";
}
protected String groupIdAsPath( String groupId )

View File

@ -30,7 +30,7 @@ public class LegacyRepositoryLayout
protected String metadataLayoutPattern()
{
return "${groupPath}/poms/${artifactId}-${version}-${metadataFilename}";
return "${groupPath}/poms/${artifactId}-${version}.${metadataSuffix}";
}
protected String groupIdAsPath( String groupId )

View File

@ -24,6 +24,9 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.SnapshotArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import java.util.Iterator;
import java.util.List;
/**
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @author <a href="mailto:mmaczka@interia.pl">Michal Maczka</a>
@ -218,8 +221,15 @@ public class SnapshotTransformation
// TODO: note, we could currently transform this in place, as it is only used through the deploy mojo,
// which creates the artifact and then disposes of it
List list = artifact.getMetadataList();
artifact = new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(), metadata.getVersion(),
artifact.getScope(), artifact.getType(), artifact.getClassifier() );
for ( Iterator i = list.iterator(); i.hasNext(); )
{
ArtifactMetadata m = (ArtifactMetadata) i.next();
m.setArtifact( artifact );
artifact.addMetadata( m );
}
artifact.addMetadata( metadata );
}
return artifact;

View File

@ -20,6 +20,8 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.deployer.ArtifactDeployer;
import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ModelMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.AbstractPlugin;
import org.apache.maven.plugin.PluginExecutionException;
@ -85,24 +87,19 @@ public class DeployMojo
}
// Deploy the POM
Artifact pomArtifact = new DefaultArtifact( project.getGroupId(), project.getArtifactId(),
project.getVersion(), "pom" );
Artifact artifact = new DefaultArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(),
project.getPackaging() );
if ( !"pom".equals( project.getPackaging() ) )
{
File pom = new File( project.getFile().getParentFile(), "pom.xml" );
ArtifactMetadata metadata = new ModelMetadata( artifact, pom );
artifact.addMetadata( metadata );
}
try
{
deployer.deploy( pom, pomArtifact, deploymentRepository, localRepository );
//Deploy artifact
if ( !"pom".equals( project.getPackaging() ) )
{
Artifact artifact = new DefaultArtifact( project.getGroupId(), project.getArtifactId(),
project.getVersion(), project.getPackaging() );
deployer.deploy( project.getBuild().getDirectory(), artifact, deploymentRepository, localRepository );
}
}
catch ( ArtifactDeploymentException e )
{
// TODO: deployment exception that does not give a trace

View File

@ -20,6 +20,8 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.installer.ArtifactInstallationException;
import org.apache.maven.artifact.installer.ArtifactInstaller;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ModelMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.AbstractPlugin;
import org.apache.maven.plugin.PluginExecutionException;
@ -63,25 +65,20 @@ public class InstallMojo
public void execute()
throws PluginExecutionException
{
// Install the POM
Artifact pomArtifact = new DefaultArtifact( project.getGroupId(), project.getArtifactId(),
project.getVersion(), "pom" );
Artifact artifact = new DefaultArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(),
project.getPackaging() );
if ( !"pom".equals( project.getPackaging() ) )
{
File pom = new File( project.getFile().getParentFile(), "pom.xml" );
ArtifactMetadata metadata = new ModelMetadata( artifact, pom );
artifact.addMetadata( metadata );
}
try
{
installer.install( pom, pomArtifact, localRepository );
//Install artifact
if ( !"pom".equals( project.getPackaging() ) )
{
Artifact artifact = new DefaultArtifact( project.getGroupId(), project.getArtifactId(),
project.getVersion(), project.getPackaging() );
installer.install( project.getBuild().getDirectory(), artifact, localRepository );
}
}
catch ( ArtifactInstallationException e )
{
// TODO: install exception that does not give a trace