[MNG-1598] Allow user to not include META-INF/maven in jars

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@345380 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Emmanuel Venisse 2005-11-18 00:18:20 +00:00
parent f936cfd675
commit bee6e222ee
2 changed files with 62 additions and 47 deletions

View File

@ -35,6 +35,8 @@ public class MavenArchiveConfiguration
private boolean index; private boolean index;
private boolean addMavenDescriptor = true;
private File manifestFile; private File manifestFile;
private ManifestConfiguration manifest; private ManifestConfiguration manifest;
@ -53,6 +55,11 @@ public class MavenArchiveConfiguration
return index; return index;
} }
public boolean isAddMavenDescriptor()
{
return addMavenDescriptor;
}
public File getManifestFile() public File getManifestFile()
{ {
return manifestFile; return manifestFile;
@ -77,6 +84,11 @@ public class MavenArchiveConfiguration
this.index = index; this.index = index;
} }
public void setAddMavenDescriptor( boolean addMavenDescriptor )
{
this.addMavenDescriptor = addMavenDescriptor;
}
public void setManifestFile( File manifestFile ) public void setManifestFile( File manifestFile )
{ {
this.manifestFile = manifestFile; this.manifestFile = manifestFile;

View File

@ -216,56 +216,59 @@ public class MavenArchiver
public void createArchive( MavenProject project, MavenArchiveConfiguration archiveConfiguration ) public void createArchive( MavenProject project, MavenArchiveConfiguration archiveConfiguration )
throws ArchiverException, ManifestException, IOException, DependencyResolutionRequiredException throws ArchiverException, ManifestException, IOException, DependencyResolutionRequiredException
{ {
// ---------------------------------------------------------------------- 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.
// ----------------------------------------------------------------------
// 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 );
if ( workingProject.getArtifact().isSnapshot() )
{ {
workingProject.setVersion( workingProject.getArtifact().getVersion() ); // ----------------------------------------------------------------------
// 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.
// ----------------------------------------------------------------------
// 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 );
if ( workingProject.getArtifact().isSnapshot() )
{
workingProject.setVersion( workingProject.getArtifact().getVersion() );
}
String groupId = workingProject.getGroupId();
String artifactId = workingProject.getArtifactId();
File exportReadyPom = writeExportReadyPom( workingProject );
archiver.addFile( exportReadyPom, "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() );
File pomPropertiesFile = new File( workingProject.getFile().getParentFile(), "pom.properties" );
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" );
} }
String groupId = workingProject.getGroupId();
String artifactId = workingProject.getArtifactId();
File exportReadyPom = writeExportReadyPom( workingProject );
archiver.addFile( exportReadyPom, "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() );
File pomPropertiesFile = new File( workingProject.getFile().getParentFile(), "pom.properties" );
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 // Create the manifest
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------