use of org.wildfly.swarm.tools.ArtifactSpec in project wildfly-swarm by wildfly-swarm.
the class GradleArtifactResolvingHelper method doResolve.
private Collection<ResolvedArtifact> doResolve(final Collection<ArtifactSpec> deps, boolean transitive) {
final Configuration config = this.project.getConfigurations().detachedConfiguration().setTransitive(transitive);
final DependencySet dependencySet = config.getDependencies();
deps.forEach(spec -> {
if (projects.containsKey(spec.groupId() + ":" + spec.artifactId() + ":" + spec.version())) {
dependencySet.add(new DefaultProjectDependency((ProjectInternal) projects.get(spec.groupId() + ":" + spec.artifactId() + ":" + spec.version()), new DefaultProjectAccessListener(), false));
} else {
final DefaultExternalModuleDependency d = new DefaultExternalModuleDependency(spec.groupId(), spec.artifactId(), spec.version());
final DefaultDependencyArtifact da = new DefaultDependencyArtifact(spec.artifactId(), spec.type(), spec.type(), spec.classifier(), null);
d.addArtifact(da);
dependencySet.add(d);
}
});
if (transitive) {
return config.getResolvedConfiguration().getResolvedArtifacts();
}
return config.getResolvedConfiguration().getFirstLevelModuleDependencies().stream().map(dep -> dep.getModuleArtifacts()).flatMap(artifacts -> artifacts.stream()).collect(Collectors.toList());
}
use of org.wildfly.swarm.tools.ArtifactSpec 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());
}
use of org.wildfly.swarm.tools.ArtifactSpec in project wildfly-swarm by wildfly-swarm.
the class ShrinkwrapArtifactResolvingHelper method resolveAll.
@Override
public Set<ArtifactSpec> resolveAll(final Collection<ArtifactSpec> specs, boolean transitive, boolean defaultExcludes) {
if (specs.isEmpty()) {
return Collections.emptySet();
}
MavenResolutionStrategy transitivityStrategy = (transitive ? TransitiveStrategy.INSTANCE : NonTransitiveStrategy.INSTANCE);
resetListeners();
final MavenResolvedArtifact[] artifacts = withResolver(r -> {
specs.forEach(spec -> r.addDependency(createMavenDependency(spec)));
return r.resolve().using(transitivityStrategy).as(MavenResolvedArtifact.class);
});
return Arrays.stream(artifacts).map(artifact -> {
final MavenCoordinate coord = artifact.getCoordinate();
return new ArtifactSpec(artifact.getScope().toString(), coord.getGroupId(), coord.getArtifactId(), coord.getVersion(), coord.getPackaging().getId(), coord.getClassifier(), artifact.asFile());
}).collect(Collectors.toSet());
}
Aggregations