Resolving: MNG-1021

o Added AttachedArtifact, and changed the DefaultMavenProjectHelper to create and attach artifacts of this type. AttachedArtifact uses a parent artifact (constructor parameter) for versioning and basic identity attributes, but requires the user to specify a type and classifier specific to the new artifact. We may want to add flexibility for artifactId, too...though I have reservations on that score.

o See it0079 for a test.



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@293497 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-10-04 02:54:49 +00:00
parent 7fd4c749fb
commit 53ccb4ffb0
16 changed files with 162 additions and 60 deletions

View File

@ -214,6 +214,9 @@ it0078: Test that configuration for maven-compiler-plugin is injected from
PluginManagement section even when it's not explicitly defined in the
plugins section.
it0079: Test that source attachments have the same build number as the main
artifact when deployed.
-------------------------------------------------------------------------------
- generated sources

View File

@ -1,3 +1,4 @@
it0079
it0078
it0077
it0076

View File

@ -0,0 +1,2 @@
target/test-repo/org/apache/maven/it/maven-core-it0079/SNAPSHOT/maven-core-it0079-*-1.jar
target/test-repo/org/apache/maven/it/maven-core-it0079/SNAPSHOT/maven-core-it0079-*-1-sources.jar

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.it</groupId>
<artifactId>maven-core-it0079</artifactId>
<version>SNAPSHOT</version>
<distributionManagement>
<snapshotRepository>
<id>test</id>
<name>Test Repo</name>
<url>file:target/test-repo</url>
</snapshotRepository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,6 @@
package org.apache.maven.it0079;
public class Person
{
String name;
}

View File

@ -1,3 +0,0 @@
This should be defined as a 00-series IT, but it takes WAY too long to run, so
I'm putting it in the 20-series. You should use the same method for running this
test as you would any single test in the 00 series.

View File

@ -1 +0,0 @@
--settings ${basedir}/settings.xml

View File

@ -1,2 +0,0 @@
target/test-repo/org/apache/maven/it/maven-core-it2003/1.0-SNAPSHOT/maven-core-it2003-1.0-*-1.jar
target/test-repo/org/apache/maven/it/maven-core-it2003/1.0-SNAPSHOT/maven-core-it2003-1.0-*-1-sources.jar

View File

@ -1,31 +0,0 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.it</groupId>
<artifactId>maven-core-it2003</artifactId>
<version>1.0-SNAPSHOT</version>
<distributionManagement>
<snapshotRepository>
<id>test-repo</id>
<url>file:target/test-repo</url>
</snapshotRepository>
</distributionManagement>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,3 +0,0 @@
<settings>
<localRepository>file:target/local-repo</localRepository>
</settings>

View File

@ -1,6 +0,0 @@
package org.apache.maven.it2003;
public class Person
{
private String name;
}

View File

@ -1 +0,0 @@
use.mavenRepoLocal=false

View File

@ -17,8 +17,8 @@ package org.apache.maven.project;
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.model.Resource;
import org.apache.maven.project.artifact.AttachedArtifact;
import java.io.File;
import java.util.List;
@ -26,16 +26,10 @@ import java.util.List;
public class DefaultMavenProjectHelper
implements MavenProjectHelper
{
// requirement.
private ArtifactFactory artifactFactory;
public void attachArtifact( MavenProject project, String artifactType, String artifactClassifier, File artifactFile )
{
Artifact artifact = artifactFactory.createArtifactWithClassifier( project.getGroupId(),
project.getArtifactId(),
project.getVersion(),
artifactType,
artifactClassifier );
Artifact artifact = new AttachedArtifact( project.getArtifact(), artifactType, artifactClassifier );
artifact.setFile( artifactFile );
artifact.setResolved( true );

View File

@ -0,0 +1,115 @@
package org.apache.maven.project.artifact;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.InvalidArtifactRTException;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.versioning.VersionRange;
import java.util.List;
public class AttachedArtifact
extends DefaultArtifact
{
private final Artifact parent;
public AttachedArtifact ( Artifact parent, String type, String classifier )
{
super( parent.getGroupId(), parent.getArtifactId(), parent.getVersionRange(), parent.getScope(), type, classifier, parent.getArtifactHandler(), parent.isOptional() );
this.parent = parent;
if ( type == null || type.trim().length() < 1 )
{
throw new InvalidArtifactRTException( getGroupId(), getArtifactId(), getVersion(), type, "Attached artifacts must specify a type." );
}
if ( classifier == null || classifier.trim().length() < 1 )
{
throw new InvalidArtifactRTException( getGroupId(), getArtifactId(), getVersion(), type, "Attached artifacts must specify a classifier." );
}
}
public ArtifactHandler getArtifactHandler()
{
return parent.getArtifactHandler();
}
public String getArtifactId()
{
return parent.getArtifactId();
}
public List getAvailableVersions()
{
return parent.getAvailableVersions();
}
public String getBaseVersion()
{
return parent.getBaseVersion();
}
public ArtifactFilter getDependencyFilter()
{
return parent.getDependencyFilter();
}
public List getDependencyTrail()
{
return parent.getDependencyTrail();
}
public String getDownloadUrl()
{
return parent.getDownloadUrl();
}
public String getGroupId()
{
return parent.getGroupId();
}
public ArtifactRepository getRepository()
{
return parent.getRepository();
}
public String getScope()
{
return parent.getScope();
}
public String getType()
{
return parent.getType();
}
public String getVersion()
{
return parent.getVersion();
}
public VersionRange getVersionRange()
{
return parent.getVersionRange();
}
public boolean isOptional()
{
return parent.isOptional();
}
public boolean isRelease()
{
return parent.isRelease();
}
public boolean isSnapshot()
{
return parent.isSnapshot();
}
}

View File

@ -8,11 +8,6 @@
<component>
<role>org.apache.maven.project.MavenProjectHelper</role>
<implementation>org.apache.maven.project.DefaultMavenProjectHelper</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
</requirement>
</requirements>
</component>
<!--
|