in src/main/java/org/apache/maven/archiver/MavenArchiver.java [529:622]
public void createArchive(
MavenSession session, MavenProject project, MavenArchiveConfiguration archiveConfiguration)
throws 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 = project.clone();
boolean forced = archiveConfiguration.isForced();
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
// ----------------------------------------------------------------------
File customPomPropertiesFile = archiveConfiguration.getPomPropertiesFile();
File dir = new File(workingProject.getBuild().getDirectory(), "maven-archiver");
File pomPropertiesFile = new File(dir, "pom.properties");
new PomPropertiesUtil()
.createPomProperties(
session, workingProject, archiver, customPomPropertiesFile, pomPropertiesFile, forced);
}
// ----------------------------------------------------------------------
// Create the manifest
// ----------------------------------------------------------------------
archiver.setMinimalDefaultManifest(true);
File manifestFile = archiveConfiguration.getManifestFile();
if (manifestFile != null) {
archiver.setManifest(manifestFile);
}
Manifest manifest = getManifest(session, workingProject, archiveConfiguration);
// Configure the jar
archiver.addConfiguredManifest(manifest);
archiver.setCompress(archiveConfiguration.isCompress());
archiver.setRecompressAddedZips(archiveConfiguration.isRecompressAddedZips());
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<String> artifacts = project.getRuntimeClasspathElements();
for (String artifact : artifacts) {
File f = new File(artifact);
archiver.addConfiguredIndexJars(f);
}
}
archiver.setForced(forced);
if (!archiveConfiguration.isForced() && archiver.isSupportingForced()) {
// TODO Should issue a warning here, but how do we get a logger?
// TODO getLog().warn(
// "Forced build is disabled, but disabling the forced mode isn't supported by the archiver." );
}
String automaticModuleName = manifest.getMainSection().getAttributeValue("Automatic-Module-Name");
if (automaticModuleName != null) {
if (!isValidModuleName(automaticModuleName)) {
throw new ManifestException("Invalid automatic module name: '" + automaticModuleName + "'");
}
}
// create archive
archiver.createArchive();
}