in src/main/java/org/apache/maven/archiver/MavenArchiver.java [249:378]
protected Manifest getManifest(
MavenSession session, MavenProject project, ManifestConfiguration config, Map<String, String> entries)
throws ManifestException, DependencyResolutionRequiredException {
// TODO: Should we replace "map" with a copy? Note, that we modify it!
Manifest m = new Manifest();
if (config.isAddDefaultEntries()) {
handleDefaultEntries(m, entries);
}
if (config.isAddBuildEnvironmentEntries()) {
handleBuildEnvironmentEntries(session, m, entries);
}
if (config.isAddClasspath()) {
StringBuilder classpath = new StringBuilder();
List<String> artifacts = project.getRuntimeClasspathElements();
String classpathPrefix = config.getClasspathPrefix();
String layoutType = config.getClasspathLayoutType();
String layout = config.getCustomClasspathLayout();
Interpolator interpolator = new StringSearchInterpolator();
for (String artifactFile : artifacts) {
File f = new File(artifactFile);
if (f.getAbsoluteFile().isFile()) {
Artifact artifact = findArtifactWithFile(project.getArtifacts(), f);
if (classpath.length() > 0) {
classpath.append(" ");
}
classpath.append(classpathPrefix);
// NOTE: If the artifact or layout type (from config) is null, give up and use the file name by
// itself.
if (artifact == null || layoutType == null) {
classpath.append(f.getName());
} else {
List<ValueSource> valueSources = new ArrayList<>();
handleExtraExpression(artifact, valueSources);
for (ValueSource vs : valueSources) {
interpolator.addValueSource(vs);
}
RecursionInterceptor recursionInterceptor =
new PrefixAwareRecursionInterceptor(ARTIFACT_EXPRESSION_PREFIXES);
try {
switch (layoutType) {
case CLASSPATH_LAYOUT_TYPE_SIMPLE:
if (config.isUseUniqueVersions()) {
classpath.append(interpolator.interpolate(SIMPLE_LAYOUT, recursionInterceptor));
} else {
classpath.append(interpolator.interpolate(
SIMPLE_LAYOUT_NONUNIQUE, recursionInterceptor));
}
break;
case CLASSPATH_LAYOUT_TYPE_REPOSITORY:
// we use layout /$groupId[0]/../${groupId[n]/$artifactId/$version/{fileName}
// here we must find the Artifact in the project Artifacts
// to create the maven layout
if (config.isUseUniqueVersions()) {
classpath.append(
interpolator.interpolate(REPOSITORY_LAYOUT, recursionInterceptor));
} else {
classpath.append(interpolator.interpolate(
REPOSITORY_LAYOUT_NONUNIQUE, recursionInterceptor));
}
break;
case CLASSPATH_LAYOUT_TYPE_CUSTOM:
if (layout == null) {
throw new ManifestException(CLASSPATH_LAYOUT_TYPE_CUSTOM
+ " layout type was declared, but custom layout expression was not"
+ " specified. Check your <archive><manifest><customLayout/>"
+ " element.");
}
classpath.append(interpolator.interpolate(layout, recursionInterceptor));
break;
default:
throw new ManifestException("Unknown classpath layout type: '" + layoutType
+ "'. Check your <archive><manifest><layoutType/> element.");
}
} catch (InterpolationException e) {
ManifestException error = new ManifestException(
"Error interpolating artifact path for classpath entry: " + e.getMessage());
error.initCause(e);
throw error;
} finally {
for (ValueSource vs : valueSources) {
interpolator.removeValuesSource(vs);
}
}
}
}
}
if (classpath.length() > 0) {
// Class-Path is special and should be added to manifest even if
// it is specified in the manifestEntries section
addManifestAttribute(m, "Class-Path", classpath.toString());
}
}
if (config.isAddDefaultSpecificationEntries()) {
handleSpecificationEntries(project, entries, m);
}
if (config.isAddDefaultImplementationEntries()) {
handleImplementationEntries(project, entries, m);
}
String mainClass = config.getMainClass();
if (mainClass != null && !"".equals(mainClass)) {
addManifestAttribute(m, entries, "Main-Class", mainClass);
}
if (config.isAddExtensions()) {
handleExtensions(project, entries, m);
}
addCustomEntries(m, entries, config);
return m;
}