in swarmtool/src/main/java/org/wildfly/swarm/swarmtool/Main.java [185:263]
protected static File generateSwarmJar(final String[] args) throws Exception {
OptionSet foundOptions = null;
try {
foundOptions = OPT_PARSER.parse(args);
} catch (OptionException e) {
exit(e.getMessage(), true);
}
if (foundOptions.has(HELP_OPT)) {
exit(null, 0, true);
}
if (foundOptions.has(VERSION_OPT)) {
exit("swarmtool v" + VERSION, 0);
}
final List<File> nonOptArgs = foundOptions.valuesOf(SOURCE_OPT);
if (nonOptArgs.isEmpty()) {
exit("No source artifact specified.", true);
}
if (nonOptArgs.size() > 1) {
exit("Too many source artifacts provided (" + nonOptArgs + ")", true);
}
final File source = nonOptArgs.get(0);
if (!source.exists()) {
exit("File " + source.getAbsolutePath() + " does not exist.");
}
final Properties properties = new Properties();
if (foundOptions.has(SYSPROPS_FILE_OPT)) {
try (InputStream in = new FileInputStream(foundOptions.valueOf(SYSPROPS_FILE_OPT))) {
properties.load(in);
}
}
foundOptions.valuesOf(SYSPROPS_OPT)
.forEach(prop -> {
final String[] parts = prop.split("=");
properties.put(parts[0], parts[1]);
});
final DeclaredDependencies dependencies = new DeclaredDependencies();
foundOptions.valuesOf(DEPENDENCIES_OPT).stream()
.map(DeclaredDependencies::createSpec)
.forEach(dependencies::add);
final String[] parts = source.getName().split("\\.(?=[^\\.]+$)");
final String baseName = parts[0];
final String type = parts[1] == null ? "jar" : parts[1];
final String jarName = foundOptions.has(NAME_OPT) ? foundOptions.valueOf(NAME_OPT) : baseName;
final String outDir = new File(foundOptions.valueOf(OUTPUT_DIR_OPT)).getCanonicalPath();
final String suffix = foundOptions.has(HOLLOW_OPT) ? "-hollow-swarm" : "-swarm";
final BuildTool tool = new BuildTool(getResolvingHelper(foundOptions.valuesOf(REPOS_OPT)))
.projectArtifact("", baseName, "", type, source)
.declaredDependencies(dependencies)
.fractionDetectionMode(foundOptions.has(DISABLE_AUTO_DETECT_OPT) ?
BuildTool.FractionDetectionMode.never :
BuildTool.FractionDetectionMode.force)
.bundleDependencies(!foundOptions.has(DISABLE_BUNDLE_DEPS_OPT))
.executable(foundOptions.has(EXECUTABLE_OPT))
.properties(properties)
.hollow(foundOptions.has(HOLLOW_OPT));
if (foundOptions.has(MAIN_OPT)) {
tool.mainClass(foundOptions.valueOf(MAIN_OPT));
}
if (foundOptions.has(MODULES_OPT)) {
tool.additionalModules(foundOptions.valuesOf(MODULES_OPT));
}
if (foundOptions.has(DEBUG_LOGGING)) {
tool.logger(BuildTool.STD_LOGGER_WITH_DEBUG);
}
addSwarmFractions(tool, foundOptions.valuesOf(FRACTIONS_OPT));
System.err.println(String.format("Building %s/%s%s.jar", outDir, jarName, suffix));
return tool.build(jarName, Paths.get(outDir));
}