mirror of https://github.com/apache/maven.git
move maven-archiver to shared
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@413922 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
11650b65db
commit
f4906ec9cd
|
@ -1,28 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?><project>
|
||||
<parent>
|
||||
<artifactId>maven</artifactId>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>maven-archiver</artifactId>
|
||||
<name>Maven Archiver</name>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-project</artifactId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-archiver</artifactId>
|
||||
<version>1.0-alpha-6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-artifact</artifactId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -1,78 +0,0 @@
|
|||
package org.apache.maven.archiver;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Capture common manifest configuration.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
* @todo is this general enough to be in Plexus Archiver?
|
||||
*/
|
||||
public class ManifestConfiguration
|
||||
{
|
||||
private String mainClass;
|
||||
|
||||
private String packageName;
|
||||
|
||||
/**
|
||||
* @todo boolean instead
|
||||
*/
|
||||
private String addClasspath;
|
||||
|
||||
/**
|
||||
* @todo boolean instead
|
||||
*/
|
||||
private String addExtensions;
|
||||
|
||||
/**
|
||||
* This gets prefixed to all classpath entries.
|
||||
*/
|
||||
private String classpathPrefix = "";
|
||||
|
||||
public String getMainClass()
|
||||
{
|
||||
return mainClass;
|
||||
}
|
||||
|
||||
public boolean isAddClasspath()
|
||||
{
|
||||
return addClasspath != null ? Boolean.valueOf( addClasspath ).booleanValue() : false;
|
||||
}
|
||||
|
||||
public boolean isAddExtensions()
|
||||
{
|
||||
return addExtensions != null ? Boolean.valueOf( addExtensions ).booleanValue() : false;
|
||||
}
|
||||
|
||||
public String getPackageName()
|
||||
{
|
||||
return packageName;
|
||||
}
|
||||
|
||||
public String getClasspathPrefix()
|
||||
{
|
||||
String cpp = classpathPrefix.replaceAll( "\\\\", "/" );
|
||||
|
||||
if ( cpp.length() != 0 && !cpp.endsWith("/") )
|
||||
{
|
||||
cpp += "/";
|
||||
}
|
||||
|
||||
return cpp;
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package org.apache.maven.archiver;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ManifestSection {
|
||||
|
||||
private String name = null;
|
||||
|
||||
private Map manifestEntries = new HashMap();
|
||||
|
||||
public void setName( String name ) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void addManifestEntry( Object key, Object value )
|
||||
{
|
||||
manifestEntries.put( key, value );
|
||||
}
|
||||
|
||||
public void addManifestEntries( Map map )
|
||||
{
|
||||
manifestEntries.putAll( map );
|
||||
}
|
||||
|
||||
public boolean isManifestEntriesEmpty()
|
||||
{
|
||||
return manifestEntries.isEmpty();
|
||||
}
|
||||
|
||||
public Map getManifestEntries()
|
||||
{
|
||||
return manifestEntries;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,137 +0,0 @@
|
|||
package org.apache.maven.archiver;
|
||||
|
||||
/*
|
||||
* 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 java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Capture common archive configuration.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
* @todo is this general enough to be in Plexus Archiver?
|
||||
*/
|
||||
public class MavenArchiveConfiguration
|
||||
{
|
||||
private boolean compress = true;
|
||||
|
||||
private boolean index;
|
||||
|
||||
private boolean addMavenDescriptor = true;
|
||||
|
||||
private File manifestFile;
|
||||
|
||||
private ManifestConfiguration manifest;
|
||||
|
||||
private Map manifestEntries = new HashMap();
|
||||
|
||||
private List manifestSections = new ArrayList();
|
||||
|
||||
public boolean isCompress()
|
||||
{
|
||||
return compress;
|
||||
}
|
||||
|
||||
public boolean isIndex()
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
public boolean isAddMavenDescriptor()
|
||||
{
|
||||
return addMavenDescriptor;
|
||||
}
|
||||
|
||||
public File getManifestFile()
|
||||
{
|
||||
return manifestFile;
|
||||
}
|
||||
|
||||
public ManifestConfiguration getManifest()
|
||||
{
|
||||
if ( manifest == null )
|
||||
{
|
||||
manifest = new ManifestConfiguration();
|
||||
}
|
||||
return manifest;
|
||||
}
|
||||
|
||||
public void setCompress( boolean compress )
|
||||
{
|
||||
this.compress = compress;
|
||||
}
|
||||
|
||||
public void setIndex( boolean index )
|
||||
{
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public void setAddMavenDescriptor( boolean addMavenDescriptor )
|
||||
{
|
||||
this.addMavenDescriptor = addMavenDescriptor;
|
||||
}
|
||||
|
||||
public void setManifestFile( File manifestFile )
|
||||
{
|
||||
this.manifestFile = manifestFile;
|
||||
}
|
||||
|
||||
public void setManifest( ManifestConfiguration manifest )
|
||||
{
|
||||
this.manifest = manifest;
|
||||
}
|
||||
|
||||
public void addManifestEntry( Object key, Object value )
|
||||
{
|
||||
manifestEntries.put( key, value );
|
||||
}
|
||||
|
||||
public void addManifestEntries( Map map )
|
||||
{
|
||||
manifestEntries.putAll( map );
|
||||
}
|
||||
|
||||
public boolean isManifestEntriesEmpty()
|
||||
{
|
||||
return manifestEntries.isEmpty();
|
||||
}
|
||||
|
||||
public Map getManifestEntries()
|
||||
{
|
||||
return manifestEntries;
|
||||
}
|
||||
|
||||
public void addManifestSection( ManifestSection section ) {
|
||||
manifestSections.add( section );
|
||||
}
|
||||
|
||||
public void addManifestSections( List list ) {
|
||||
manifestSections.addAll( list );
|
||||
}
|
||||
|
||||
public boolean isManifestSectionsEmpty() {
|
||||
return manifestSections.isEmpty();
|
||||
}
|
||||
|
||||
public List getManifestSections() {
|
||||
return manifestSections;
|
||||
}
|
||||
}
|
|
@ -1,355 +0,0 @@
|
|||
package org.apache.maven.archiver;
|
||||
|
||||
/*
|
||||
* 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.DependencyResolutionRequiredException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.archiver.ArchiverException;
|
||||
import org.codehaus.plexus.archiver.jar.JarArchiver;
|
||||
import org.codehaus.plexus.archiver.jar.Manifest;
|
||||
import org.codehaus.plexus.archiver.jar.ManifestException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
public class MavenArchiver
|
||||
{
|
||||
private JarArchiver archiver;
|
||||
|
||||
private File archiveFile;
|
||||
|
||||
/**
|
||||
* Return a pre-configured manifest
|
||||
*
|
||||
* @todo Add user attributes list and user groups list
|
||||
*/
|
||||
public Manifest getManifest( MavenProject project, ManifestConfiguration config )
|
||||
throws ManifestException, DependencyResolutionRequiredException
|
||||
{
|
||||
// Added basic entries
|
||||
Manifest m = new Manifest();
|
||||
Manifest.Attribute buildAttr = new Manifest.Attribute( "Built-By", System.getProperty( "user.name" ) );
|
||||
m.addConfiguredAttribute( buildAttr );
|
||||
Manifest.Attribute createdAttr = new Manifest.Attribute( "Created-By", "Apache Maven" );
|
||||
m.addConfiguredAttribute( createdAttr );
|
||||
|
||||
/* TODO: rethink this, it wasn't working
|
||||
Artifact projectArtifact = project.getArtifact();
|
||||
|
||||
if ( projectArtifact.isSnapshot() )
|
||||
{
|
||||
Manifest.Attribute buildNumberAttr = new Manifest.Attribute( "Build-Number", "" +
|
||||
project.getSnapshotDeploymentBuildNumber() );
|
||||
m.addConfiguredAttribute( buildNumberAttr );
|
||||
}
|
||||
|
||||
*/
|
||||
if ( config.getPackageName() != null )
|
||||
{
|
||||
Manifest.Attribute packageAttr = new Manifest.Attribute( "Package", config.getPackageName() );
|
||||
m.addConfiguredAttribute( packageAttr );
|
||||
}
|
||||
|
||||
Manifest.Attribute buildJdkAttr = new Manifest.Attribute( "Build-Jdk", System.getProperty( "java.version" ) );
|
||||
m.addConfiguredAttribute( buildJdkAttr );
|
||||
|
||||
if ( config.isAddClasspath() )
|
||||
{
|
||||
StringBuffer classpath = new StringBuffer();
|
||||
List artifacts = project.getRuntimeClasspathElements();
|
||||
String classpathPrefix = config.getClasspathPrefix();
|
||||
|
||||
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
|
||||
{
|
||||
File f = new File( (String) iter.next() );
|
||||
if ( f.isFile() )
|
||||
{
|
||||
if ( classpath.length() > 0 )
|
||||
{
|
||||
classpath.append( " " );
|
||||
}
|
||||
|
||||
classpath.append( classpathPrefix );
|
||||
classpath.append( f.getName() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( classpath.length() > 0 )
|
||||
{
|
||||
Manifest.Attribute classpathAttr = new Manifest.Attribute( "Class-Path", classpath.toString() );
|
||||
m.addConfiguredAttribute( classpathAttr );
|
||||
}
|
||||
}
|
||||
|
||||
// Added supplementary entries
|
||||
Manifest.Attribute extensionNameAttr = new Manifest.Attribute( "Extension-Name", project.getArtifactId() );
|
||||
m.addConfiguredAttribute( extensionNameAttr );
|
||||
|
||||
if ( project.getDescription() != null )
|
||||
{
|
||||
Manifest.Attribute specificationTitleAttr = new Manifest.Attribute( "Specification-Title",
|
||||
project.getDescription() );
|
||||
m.addConfiguredAttribute( specificationTitleAttr );
|
||||
}
|
||||
|
||||
if ( project.getOrganization() != null )
|
||||
{
|
||||
Manifest.Attribute specificationVendor = new Manifest.Attribute( "Specification-Vendor",
|
||||
project.getOrganization().getName() );
|
||||
m.addConfiguredAttribute( specificationVendor );
|
||||
Manifest.Attribute implementationVendorAttr = new Manifest.Attribute( "Implementation-Vendor",
|
||||
project.getOrganization().getName() );
|
||||
m.addConfiguredAttribute( implementationVendorAttr );
|
||||
}
|
||||
|
||||
Manifest.Attribute implementationTitleAttr = new Manifest.Attribute( "Implementation-Title",
|
||||
project.getArtifactId() );
|
||||
m.addConfiguredAttribute( implementationTitleAttr );
|
||||
Manifest.Attribute implementationVersionAttr = new Manifest.Attribute( "Implementation-Version",
|
||||
project.getVersion() );
|
||||
m.addConfiguredAttribute( implementationVersionAttr );
|
||||
|
||||
String mainClass = config.getMainClass();
|
||||
if ( mainClass != null && !"".equals( mainClass ) )
|
||||
{
|
||||
Manifest.Attribute mainClassAttr = new Manifest.Attribute( "Main-Class", mainClass );
|
||||
m.addConfiguredAttribute( mainClassAttr );
|
||||
}
|
||||
|
||||
// Added extensions
|
||||
if ( config.isAddExtensions() )
|
||||
{
|
||||
StringBuffer extensionsList = new StringBuffer();
|
||||
Set artifacts = project.getArtifacts();
|
||||
|
||||
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() ) )
|
||||
{
|
||||
if ( extensionsList.length() > 0 )
|
||||
{
|
||||
extensionsList.append( " " );
|
||||
}
|
||||
extensionsList.append( artifact.getArtifactId() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( extensionsList.length() > 0 )
|
||||
{
|
||||
Manifest.Attribute extensionsListAttr = new Manifest.Attribute( "Extension-List",
|
||||
extensionsList.toString() );
|
||||
m.addConfiguredAttribute( extensionsListAttr );
|
||||
}
|
||||
|
||||
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
|
||||
{
|
||||
Artifact artifact = (Artifact) iter.next();
|
||||
if ( "jar".equals( artifact.getType() ) )
|
||||
{
|
||||
Manifest.Attribute archExtNameAttr = new Manifest.Attribute(
|
||||
artifact.getArtifactId() + "-Extension-Name", artifact.getArtifactId() );
|
||||
m.addConfiguredAttribute( archExtNameAttr );
|
||||
String name = artifact.getArtifactId() + "-Implementation-Version";
|
||||
Manifest.Attribute archImplVersionAttr = new Manifest.Attribute( name, artifact.getVersion() );
|
||||
m.addConfiguredAttribute( archImplVersionAttr );
|
||||
|
||||
if ( artifact.getRepository() != null )
|
||||
{
|
||||
// TODO: is this correct
|
||||
name = artifact.getArtifactId() + "-Implementation-URL";
|
||||
String url = artifact.getRepository().getUrl() + "/" + artifact.toString();
|
||||
Manifest.Attribute archImplUrlAttr = new Manifest.Attribute( name, url );
|
||||
m.addConfiguredAttribute( archImplUrlAttr );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
public JarArchiver getArchiver()
|
||||
{
|
||||
return archiver;
|
||||
}
|
||||
|
||||
public void setArchiver( JarArchiver archiver )
|
||||
{
|
||||
this.archiver = archiver;
|
||||
}
|
||||
|
||||
public void setOutputFile( File outputFile )
|
||||
{
|
||||
archiveFile = outputFile;
|
||||
}
|
||||
|
||||
public void createArchive( MavenProject project, MavenArchiveConfiguration archiveConfiguration )
|
||||
throws ArchiverException, ManifestException, IOException, DependencyResolutionRequiredException
|
||||
{
|
||||
// we have to clone the project instance so we can write out the pom with the deployment version,
|
||||
// without impacting the main project instance...
|
||||
MavenProject workingProject = new MavenProject( project );
|
||||
|
||||
File pomPropertiesFile = new File( workingProject.getFile().getParentFile(), "pom.properties" );
|
||||
|
||||
if ( archiveConfiguration.isAddMavenDescriptor() )
|
||||
{
|
||||
// ----------------------------------------------------------------------
|
||||
// We want to add the metadata for the project to the JAR in two forms:
|
||||
//
|
||||
// The first form is that of the POM itself. Applications that wish to
|
||||
// access the POM for an artifact using maven tools they can.
|
||||
//
|
||||
// The second form is that of a properties file containing the basic
|
||||
// top-level POM elements so that applications that wish to access
|
||||
// POM information without the use of maven tools can do so.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
if ( workingProject.getArtifact().isSnapshot() )
|
||||
{
|
||||
workingProject.setVersion( workingProject.getArtifact().getVersion() );
|
||||
}
|
||||
|
||||
String groupId = workingProject.getGroupId();
|
||||
|
||||
String artifactId = workingProject.getArtifactId();
|
||||
|
||||
archiver.addFile( project.getFile(), "META-INF/maven/" + groupId + "/" + artifactId + "/pom.xml" );
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Create pom.properties file
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
Properties p = new Properties();
|
||||
|
||||
p.setProperty( "groupId", workingProject.getGroupId() );
|
||||
|
||||
p.setProperty( "artifactId", workingProject.getArtifactId() );
|
||||
|
||||
p.setProperty( "version", workingProject.getVersion() );
|
||||
|
||||
OutputStream os = new FileOutputStream( pomPropertiesFile );
|
||||
|
||||
p.store( os, "Generated by Maven" );
|
||||
|
||||
os.close(); // stream is flushed but not closed by Properties.store()
|
||||
|
||||
archiver.addFile( pomPropertiesFile, "META-INF/maven/" + groupId + "/" + artifactId + "/pom.properties" );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Create the manifest
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
File manifestFile = archiveConfiguration.getManifestFile();
|
||||
|
||||
if ( manifestFile != null )
|
||||
{
|
||||
archiver.setManifest( manifestFile );
|
||||
}
|
||||
|
||||
Manifest manifest = getManifest( workingProject, archiveConfiguration.getManifest() );
|
||||
|
||||
// any custom manifest entries in the archive configuration manifest?
|
||||
if ( !archiveConfiguration.isManifestEntriesEmpty() )
|
||||
{
|
||||
Map entries = archiveConfiguration.getManifestEntries();
|
||||
Set keys = entries.keySet();
|
||||
for ( Iterator iter = keys.iterator(); iter.hasNext(); )
|
||||
{
|
||||
String key = (String) iter.next();
|
||||
String value = (String) entries.get( key );
|
||||
Manifest.Attribute attr = new Manifest.Attribute( key, value );
|
||||
manifest.addConfiguredAttribute( attr );
|
||||
}
|
||||
}
|
||||
|
||||
// any custom manifest sections in the archive configuration manifest?
|
||||
if ( !archiveConfiguration.isManifestSectionsEmpty() )
|
||||
{
|
||||
List sections = archiveConfiguration.getManifestSections();
|
||||
for ( Iterator iter = sections.iterator(); iter.hasNext(); )
|
||||
{
|
||||
ManifestSection section = (ManifestSection) iter.next();
|
||||
Manifest.Section theSection = new Manifest.Section();
|
||||
theSection.setName( section.getName() );
|
||||
|
||||
if( !section.isManifestEntriesEmpty() ) {
|
||||
Map entries = section.getManifestEntries();
|
||||
Set keys = entries.keySet();
|
||||
for ( Iterator it = keys.iterator(); it.hasNext(); )
|
||||
{
|
||||
String key = (String) it.next();
|
||||
String value = (String) entries.get( key );
|
||||
Manifest.Attribute attr = new Manifest.Attribute( key, value );
|
||||
theSection.addConfiguredAttribute( attr );
|
||||
}
|
||||
}
|
||||
|
||||
manifest.addConfiguredSection( theSection );
|
||||
}
|
||||
}
|
||||
|
||||
// Configure the jar
|
||||
archiver.addConfiguredManifest( manifest );
|
||||
|
||||
archiver.setCompress( archiveConfiguration.isCompress() );
|
||||
|
||||
archiver.setIndex( archiveConfiguration.isIndex() );
|
||||
|
||||
archiver.setDestFile( archiveFile );
|
||||
|
||||
// make the archiver index the jars on the classpath, if we are adding that to the manifest
|
||||
if ( archiveConfiguration.getManifest().isAddClasspath() )
|
||||
{
|
||||
List artifacts = project.getRuntimeClasspathElements();
|
||||
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
|
||||
{
|
||||
File f = new File( (String) iter.next() );
|
||||
archiver.addConfiguredIndexJars(f);
|
||||
}
|
||||
}
|
||||
|
||||
// create archive
|
||||
archiver.createArchive();
|
||||
|
||||
// Cleanup
|
||||
if ( archiveConfiguration.isAddMavenDescriptor() )
|
||||
{
|
||||
pomPropertiesFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,134 +0,0 @@
|
|||
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" ) );
|
||||
}
|
||||
}
|
|
@ -1,309 +0,0 @@
|
|||
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.
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue