use of org.wildfly.swarm.spi.meta.SimpleLogger in project wildfly-swarm by wildfly-swarm.
the class PackageMojo method executeSpecific.
@SuppressWarnings("deprecation")
@Override
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;
}
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 wildfly-swarm: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).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.additionalFractions.stream().map(f -> FractionDescriptor.fromGav(FractionList.get(), f)).map(ArtifactSpec::fromFractionDescriptor).forEach(tool::fraction);
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"))) {
// ignore anything but compile and runtime
continue;
}
Set<ArtifactSpec> transientDeps = buckets.get(directDep);
if (transientDeps.isEmpty()) {
declaredDependencies.add(directDep);
} else {
for (ArtifactSpec transientDep : transientDeps) {
declaredDependencies.add(directDep, transientDep);
}
}
}
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 {
File jar = tool.build(finalName + (this.hollow ? "-hollow" : ""), Paths.get(this.projectBuildDir));
ArtifactHandler handler = new DefaultArtifactHandler("jar");
Artifact swarmJarArtifact = new DefaultArtifact(primaryArtifact.getGroupId(), primaryArtifact.getArtifactId(), primaryArtifact.getBaseVersion(), primaryArtifact.getScope(), "jar", (this.hollow ? "hollow" : "") + "swarm", handler);
swarmJarArtifact.setFile(jar);
this.project.addAttachedArtifact(swarmJarArtifact);
if (this.project.getPackaging().equals("war")) {
tool.repackageWar(primaryArtifactFile);
}
} catch (Exception e) {
throw new MojoFailureException("Unable to create -swarm.jar", e);
}
}
use of org.wildfly.swarm.spi.meta.SimpleLogger in project wildfly-swarm by wildfly-swarm.
the class PackageTask method packageForSwarm.
@TaskAction
public void packageForSwarm() throws Exception {
final Project project = getProject();
GradleArtifactResolvingHelper resolvingHelper = new GradleArtifactResolvingHelper(project);
Properties propertiesFromExtension = getPropertiesFromExtension();
List<File> moduleDirs = getModuleDirs();
if (moduleDirs.isEmpty()) {
Path resourcesOutputDir = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().findByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput().getResourcesDir().toPath().resolve(MODULE_DIR_NAME);
if (Files.isDirectory(resourcesOutputDir)) {
File moduleDir = resourcesOutputDir.toFile();
moduleDirs.add(moduleDir);
}
}
this.tool = new BuildTool(resolvingHelper).projectArtifact(this.jarTask.getGroup().toString(), this.jarTask.getBaseName(), this.jarTask.getVersion(), getPackaging(), getProjectArtifactFile()).mainClass(getMainClassName()).bundleDependencies(getBundleDependencies()).executable(getExecutable()).executableScript(getExecutableScript()).properties(propertiesFromExtension).properties(getPropertiesFromFile()).properties(PropertiesUtil.filteredSystemProperties(propertiesFromExtension, false)).fractionDetectionMode(getSwarmExtension().getFractionDetectMode()).hollow(getHollow()).additionalModules(moduleDirs.stream().filter(File::exists).map(File::getAbsolutePath).collect(Collectors.toList())).logger(new SimpleLogger() {
@Override
public void debug(String msg) {
getLogger().debug(msg);
}
@Override
public void info(String msg) {
getLogger().info(msg);
}
@Override
public void error(String msg) {
getLogger().error(msg);
}
@Override
public void error(String msg, Throwable t) {
getLogger().error(msg, t);
}
});
DeclaredDependencies declaredDependencies = new DeclaredDependencies();
List<ArtifactSpec> explicitDependencies = new ArrayList<>();
/* project.getConfigurations()
.getByName("compile")
.getAllDependencies()
.forEach((artifact) -> {
String groupId = artifact.getGroup();
String artifactId = artifact.getName();
explicitDependencies.add(new ArtifactSpec("compile", groupId, artifactId, null, "jar", null, null));
});
project.getConfigurations()
.getByName("compile")
.getResolvedConfiguration()
.getResolvedArtifacts()
.forEach(e -> addDependency(declaredDependencies, explicitDependencies, e));*/
ResolvedConfiguration resolvedConfiguration = project.getConfigurations().getByName("default").getResolvedConfiguration();
Set<ResolvedDependency> directDeps = resolvedConfiguration.getFirstLevelModuleDependencies();
for (ResolvedDependency directDep : directDeps) {
assert directDep.getModuleArtifacts().iterator().hasNext() : "Expected module artifacts";
ArtifactSpec parent = new ArtifactSpec("compile", directDep.getModule().getId().getGroup(), directDep.getModule().getId().getName(), directDep.getModule().getId().getVersion(), directDep.getModuleArtifacts().iterator().next().getExtension(), null, null);
Set<ArtifactSpec> artifactSpecs = resolvingHelper.resolveAll(new HashSet<>(Collections.singletonList(parent)));
artifactSpecs.forEach(a -> declaredDependencies.add(parent, a));
}
tool.declaredDependencies(declaredDependencies);
final Boolean bundleDependencies = getBundleDependencies();
if (bundleDependencies != null) {
this.tool.bundleDependencies(bundleDependencies);
}
this.tool.build(getBaseName(), getOutputDirectory());
}
Aggregations