From bee6e222ee66704a5249365dba4ef37e6851094c Mon Sep 17 00:00:00 2001 From: Emmanuel Venisse Date: Fri, 18 Nov 2005 00:18:20 +0000 Subject: [PATCH] [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 --- .../archiver/MavenArchiveConfiguration.java | 12 +++ .../apache/maven/archiver/MavenArchiver.java | 97 ++++++++++--------- 2 files changed, 62 insertions(+), 47 deletions(-) diff --git a/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiveConfiguration.java b/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiveConfiguration.java index b4d101d6b9..5654dd3a58 100644 --- a/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiveConfiguration.java +++ b/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiveConfiguration.java @@ -35,6 +35,8 @@ public class MavenArchiveConfiguration private boolean index; + private boolean addMavenDescriptor = true; + private File manifestFile; private ManifestConfiguration manifest; @@ -53,6 +55,11 @@ public class MavenArchiveConfiguration return index; } + public boolean isAddMavenDescriptor() + { + return addMavenDescriptor; + } + public File getManifestFile() { return manifestFile; @@ -77,6 +84,11 @@ public class MavenArchiveConfiguration this.index = index; } + public void setAddMavenDescriptor( boolean addMavenDescriptor ) + { + this.addMavenDescriptor = addMavenDescriptor; + } + public void setManifestFile( File manifestFile ) { this.manifestFile = manifestFile; diff --git a/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiver.java b/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiver.java index cd500a2074..783b78cbb1 100644 --- a/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiver.java +++ b/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiver.java @@ -216,56 +216,59 @@ public class MavenArchiver public void createArchive( MavenProject project, MavenArchiveConfiguration archiveConfiguration ) throws ArchiverException, ManifestException, IOException, DependencyResolutionRequiredException { - // ---------------------------------------------------------------------- - // 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() ) + if ( archiveConfiguration.isAddMavenDescriptor() ) { - 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 // ----------------------------------------------------------------------