[MJAR-6] Fixing pollution of Extensions-List by test-scoped dependencies.

Submitted By: Jerome Lacoste

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@394684 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2006-04-17 14:45:47 +00:00
parent a5a6226e53
commit 857c6e7b41
3 changed files with 447 additions and 0 deletions

View File

@ -151,6 +151,10 @@ public class MavenArchiver
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{
Artifact artifact = (Artifact) iter.next();
if ( "test".equals( artifact.getScope() ) )
{
continue;
}
// TODO: type of ejb should be added too?
if ( "jar".equals( artifact.getType() ) )
{

View File

@ -0,0 +1,134 @@
package org.apache.maven.archiver;
/*
* Copyright 2001-2006 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 junit.framework.TestCase;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.archiver.jar.Manifest;
import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;
public class MavenArchiverTest
extends TestCase
{
static class ArtifactComparator implements Comparator {
public int compare( Object o1, Object o2 )
{
return ((Artifact) o1).getArtifactId().compareTo(((Artifact) o2).getArtifactId());
}
public boolean equals(Object o) { return false; }
}
public void testGetManifestExtensionList() throws Exception
{
MavenArchiver archiver = new MavenArchiver();
Model model = new Model();
model.setArtifactId( "dummy" );
MavenProject project = new MavenProject( model );
// we need to sort the artifacts for test purposes
Set artifacts = new TreeSet( new ArtifactComparator() );
project.setArtifacts( artifacts );
// there should be a mock or a setter for this field.
ManifestConfiguration config = new ManifestConfiguration()
{
public boolean isAddExtensions()
{
return true;
}
};
Manifest manifest;
manifest = archiver.getManifest( project, config );
assertNotNull( manifest.getMainSection() );
java.util.Enumeration enume = manifest.getSectionNames();
while (enume.hasMoreElements()) {
Manifest.Section section = manifest.getSection(enume.nextElement().toString());
System.out.println( section + " " + section.getAttributeValue( "Extension-List" ) );
}
assertEquals( null,
manifest.getMainSection().getAttributeValue( "Extension-List" ) );
MockArtifact artifact1 = new MockArtifact();
artifact1.setGroupId( "org.apache.dummy" );
artifact1.setArtifactId( "dummy1" );
artifact1.setVersion( "1.0" );
artifact1.setType( "dll" );
artifact1.setScope( "compile" );
artifacts.add( artifact1 );
manifest = archiver.getManifest( project, config );
assertEquals( null,
manifest.getMainSection().getAttributeValue( "Extension-List" ) );
MockArtifact artifact2 = new MockArtifact();
artifact2.setGroupId( "org.apache.dummy" );
artifact2.setArtifactId( "dummy2" );
artifact2.setVersion( "1.0" );
artifact2.setType( "jar" );
artifact2.setScope( "compile" );
artifacts.add( artifact2 );
manifest = archiver.getManifest( project, config );
assertEquals( "dummy2",
manifest.getMainSection().getAttributeValue( "Extension-List" ) );
MockArtifact artifact3 = new MockArtifact();
artifact3.setGroupId( "org.apache.dummy" );
artifact3.setArtifactId( "dummy3" );
artifact3.setVersion( "1.0" );
artifact3.setScope( "test" );
artifact3.setType( "jar" );
artifacts.add( artifact3 );
manifest = archiver.getManifest( project, config );
assertEquals( "dummy2",
manifest.getMainSection().getAttributeValue( "Extension-List" ) );
MockArtifact artifact4 = new MockArtifact();
artifact4.setGroupId( "org.apache.dummy" );
artifact4.setArtifactId( "dummy4" );
artifact4.setVersion( "1.0" );
artifact4.setType( "jar" );
artifact4.setScope( "compile" );
artifacts.add( artifact4 );
manifest = archiver.getManifest( project, config );
assertEquals( "dummy2 dummy4",
manifest.getMainSection().getAttributeValue( "Extension-List" ) );
}
}

View File

@ -0,0 +1,309 @@
package org.apache.maven.archiver;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
import org.apache.maven.artifact.versioning.VersionRange;
import java.io.File;
import java.util.Collection;
import java.util.List;
/**
* @todo move to maven-artifact-test
*/
class MockArtifact
implements Artifact
{
private String groupId;
private String artifactId;
private String version;
private File file;
private String scope;
private String type;
private String classifier;
private String baseVersion;
public String getGroupId()
{
return groupId;
}
public String getArtifactId()
{
return artifactId;
}
public String getVersion()
{
return version;
}
public void setVersion( String string )
{
this.version = string;
}
public String getScope()
{
return scope;
}
public String getType()
{
return type;
}
public String getClassifier()
{
return classifier;
}
public boolean hasClassifier()
{
return classifier != null;
}
public File getFile()
{
return file;
}
public void setFile( File file )
{
this.file = file;
}
public String getBaseVersion()
{
return baseVersion;
}
public void setBaseVersion( String string )
{
this.baseVersion = string;
}
public String getId()
{
// TODO
return null;
}
public String getDependencyConflictId()
{
// TODO
return null;
}
public void addMetadata( ArtifactMetadata artifactMetadata )
{
// TODO
}
public Collection getMetadataList()
{
// TODO
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public void setRepository( ArtifactRepository artifactRepository )
{
//To change body of implemented methods use File | Settings | File Templates.
// TODO
}
public ArtifactRepository getRepository()
{
// TODO
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public void updateVersion( String string, ArtifactRepository artifactRepository )
{
//To change body of implemented methods use File | Settings | File Templates.
// TODO
}
public String getDownloadUrl()
{
// TODO
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public void setDownloadUrl( String string )
{
//To change body of implemented methods use File | Settings | File Templates.
// TODO
}
public ArtifactFilter getDependencyFilter()
{
// TODO
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public void setDependencyFilter( ArtifactFilter artifactFilter )
{
// TODO
//To change body of implemented methods use File | Settings | File Templates.
}
public ArtifactHandler getArtifactHandler()
{
// TODO
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public List getDependencyTrail()
{
// TODO
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public void setDependencyTrail( List list )
{
//To change body of implemented methods use File | Settings | File Templates.
// TODO
}
public VersionRange getVersionRange()
{
// TODO
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public void setVersionRange( VersionRange versionRange )
{
// TODO
//To change body of implemented methods use File | Settings | File Templates.
}
public void selectVersion( String string )
{
// TODO
//To change body of implemented methods use File | Settings | File Templates.
}
public boolean isSnapshot()
{
// TODO
return false; //To change body of implemented methods use File | Settings | File Templates.
}
public void setResolved( boolean b )
{
// TODO
//To change body of implemented methods use File | Settings | File Templates.
}
public boolean isResolved()
{
// TODO
return false; //To change body of implemented methods use File | Settings | File Templates.
}
public void setResolvedVersion( String string )
{
// TODO
//To change body of implemented methods use File | Settings | File Templates.
}
public void setArtifactHandler( ArtifactHandler artifactHandler )
{
// TODO
//To change body of implemented methods use File | Settings | File Templates.
}
public boolean isRelease()
{
// TODO
return false; //To change body of implemented methods use File | Settings | File Templates.
}
public void setRelease( boolean b )
{
// TODO
//To change body of implemented methods use File | Settings | File Templates.
}
public List getAvailableVersions()
{
// TODO
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public void setAvailableVersions( List list )
{
// TODO
//To change body of implemented methods use File | Settings | File Templates.
}
public boolean isOptional()
{
return false; //To change body of implemented methods use File | Settings | File Templates.
// TODO
}
public void setOptional( boolean b )
{
// TODO
//To change body of implemented methods use File | Settings | File Templates.
}
public ArtifactVersion getSelectedVersion()
throws OverConstrainedVersionException
{
// TODO
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public boolean isSelectedVersionKnown()
throws OverConstrainedVersionException
{
return false; //To change body of implemented methods use File | Settings | File Templates.
// TODO
}
public void setGroupId( String groupId )
{
this.groupId = groupId;
}
public void setArtifactId( String artifactId )
{
this.artifactId = artifactId;
}
public void setType( String type )
{
this.type = type;
}
public void setClassifier( String classifier )
{
this.classifier = classifier;
}
public void setScope( String string )
{
this.scope = string;
}
public int compareTo( Object o )
{
// TODO
return 0; //To change body of implemented methods use File | Settings | File Templates.
}
}