in plugins/maven/src/main/java/org/wildfly/swarm/plugin/maven/PackageMojo.java [110:250]
public void executeSpecific() throws MojoExecutionException, MojoFailureException {
if (this.skip) {
getLog().info("Skipping packaging");
return;
}
if (this.project.getPackaging().equals("pom")) {
getLog().info("Not processing project with pom packaging");
return;
}
boolean doRepackageWar = Boolean.parseBoolean(filterWebInfLib);
boolean doFilterWebInfLib = doRepackageWar || REPACKAGE_WAR_ONLY_IN_UBERJAR.equalsIgnoreCase(filterWebInfLib);
initProperties(false);
final Artifact primaryArtifact = this.project.getArtifact();
final String finalName = this.project.getBuild().getFinalName();
final String type = primaryArtifact.getType();
final File primaryArtifactFile = divineFile();
if (primaryArtifactFile == null) {
throw new MojoExecutionException("Cannot package without a primary artifact; please `mvn package` prior to invoking thorntail:package from the command-line");
}
final DeclaredDependencies declaredDependencies = new DeclaredDependencies();
final BuildTool tool = new BuildTool(mavenArtifactResolvingHelper())
.projectArtifact(primaryArtifact.getGroupId(),
primaryArtifact.getArtifactId(),
primaryArtifact.getBaseVersion(),
type,
primaryArtifactFile,
finalName.endsWith("." + type) ?
finalName :
String.format("%s.%s", finalName, type))
.properties(this.properties)
.mainClass(this.mainClass)
.bundleDependencies(this.bundleDependencies)
.filterWebInfLib(doFilterWebInfLib)
.executable(executable)
.executableScript(executableScript)
.fractionDetectionMode(fractionDetectMode)
.hollow(hollow)
.logger(new SimpleLogger() {
@Override
public void debug(String msg) {
getLog().debug(msg);
}
@Override
public void info(String msg) {
getLog().info(msg);
}
@Override
public void error(String msg) {
getLog().error(msg);
}
@Override
public void error(String msg, Throwable t) {
getLog().error(msg, t);
}
});
this.fractions.forEach(f -> {
if (f.startsWith(EXCLUDE_PREFIX)) {
tool.excludeFraction(ArtifactSpec.fromFractionDescriptor(FractionDescriptor.fromGav(FractionList.get(), f.substring(1))));
} else {
tool.fraction(ArtifactSpec.fromFractionDescriptor(FractionDescriptor.fromGav(FractionList.get(), f)));
}
});
Map<ArtifactSpec, Set<ArtifactSpec>> buckets = createBuckets(this.project.getArtifacts(), this.project.getDependencies());
for (ArtifactSpec directDep : buckets.keySet()) {
if (!(directDep.scope.equals("compile") || directDep.scope.equals("runtime"))) {
continue; // ignore anything but compile and runtime
}
Set<ArtifactSpec> transientDeps = buckets.get(directDep);
if (transientDeps.isEmpty()) {
declaredDependencies.add(directDep);
} else {
for (ArtifactSpec transientDep : transientDeps) {
declaredDependencies.add(directDep, transientDep);
}
}
declaredDependencies.markComplete(directDep);
}
tool.declaredDependencies(declaredDependencies);
this.project.getResources()
.forEach(r -> tool.resourceDirectory(r.getDirectory()));
Path uberjarResourcesDir = null;
if (this.uberjarResources == null) {
uberjarResourcesDir = Paths.get(this.project.getBasedir().toString()).resolve("src").resolve("main").resolve("uberjar");
} else {
uberjarResourcesDir = Paths.get(this.uberjarResources);
}
tool.uberjarResourcesDirectory(uberjarResourcesDir);
this.additionalModules.stream()
.map(m -> new File(this.project.getBuild().getOutputDirectory(), m))
.filter(File::exists)
.map(File::getAbsolutePath)
.forEach(tool::additionalModule);
try {
String jarFinalName;
if (this.finalName != null) {
jarFinalName = this.finalName;
} else {
jarFinalName = finalName + "-" + (this.hollow ? HOLLOWJAR_SUFFIX : UBERJAR_SUFFIX);
}
jarFinalName += JAR_FILE_EXTENSION;
File jar = tool.build(jarFinalName, Paths.get(this.projectBuildDir));
ArtifactHandler handler = new DefaultArtifactHandler(JAR);
Artifact swarmJarArtifact = new DefaultArtifact(
primaryArtifact.getGroupId(),
primaryArtifact.getArtifactId(),
primaryArtifact.getBaseVersion(),
primaryArtifact.getScope(),
JAR,
(this.hollow ? HOLLOWJAR_SUFFIX : UBERJAR_SUFFIX),
handler
);
swarmJarArtifact.setFile(jar);
this.project.addAttachedArtifact(swarmJarArtifact);
if (this.project.getPackaging().equals(WAR) && doRepackageWar) {
tool.repackageWar(primaryArtifactFile);
}
} catch (Exception e) {
throw new MojoFailureException("Unable to create " + UBERJAR_SUFFIX + JAR_FILE_EXTENSION, e);
}
}