use of org.wildfly.swarm.tools.ArtifactSpec in project wildfly-swarm by wildfly-swarm.
the class GradleDependencyAdapter method parseDependencies.
public DeclaredDependencies parseDependencies(Configuration configuration) {
System.out.println(rootPath);
GradleConnector connector = GradleConnector.newConnector().forProjectDirectory(rootPath.toFile());
ProjectConnection connection = connector.connect();
GradleProject project = connection.getModel(GradleProject.class);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
connection.newBuild().withArguments("dependencies", "--configuration", configuration.literal).setStandardOutput(bout).run();
connection.close();
// parse
DeclaredDependencies declaredDependencies = new DeclaredDependencies();
String deps = new String(bout.toByteArray());
Scanner scanner = new Scanner(deps);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
// top level deps
if (line.startsWith(PREFIX1) || line.startsWith(PREFIX2)) {
if (stack.size() > 0) {
stack.pop();
}
// parse
line = parseLine(line);
String coord = parseCoordinate(line);
ArtifactSpec parent = DeclaredDependencies.createSpec(coord);
declaredDependencies.add(parent);
stack.push(parent);
} else if (line.contains(PREFIX)) {
// transient
line = parseLine(line);
if (line.startsWith(PROJECT)) {
// Always skip 'project' dependencies.
continue;
}
String coord = parseCoordinate(line);
declaredDependencies.add(stack.peek(), DeclaredDependencies.createSpec(coord));
}
}
scanner.close();
return declaredDependencies;
}
use of org.wildfly.swarm.tools.ArtifactSpec in project wildfly-swarm by wildfly-swarm.
the class MavenDependencyDeclarationFactory method create.
@Override
public DeclaredDependencies create(FileSystemLayout ignored, ShrinkwrapArtifactResolvingHelper resolvingHelper) {
final DeclaredDependencies declaredDependencies = new DeclaredDependencies();
final PomEquippedResolveStage pom = MavenProfileLoader.loadPom(resolvingHelper.getResolver());
// NonTransitiveStrategy
final MavenResolvedArtifact[] explicitDeps = resolvingHelper.withResolver(r -> pom.importRuntimeAndTestDependencies().resolve().withoutTransitivity().asResolvedArtifact());
// TransitiveStrategy
for (MavenResolvedArtifact directDep : explicitDeps) {
ArtifactSpec parent = new ArtifactSpec(directDep.getScope().toString(), directDep.getCoordinate().getGroupId(), directDep.getCoordinate().getArtifactId(), directDep.getCoordinate().getVersion(), directDep.getCoordinate().getPackaging().toString(), directDep.getCoordinate().getClassifier(), directDep.asFile());
MavenResolvedArtifact[] bucket = resolvingHelper.withResolver(r -> {
r.addDependency(resolvingHelper.createMavenDependency(parent));
return pom.resolve().withTransitivity().asResolvedArtifact();
});
for (MavenResolvedArtifact dep : bucket) {
ArtifactSpec child = new ArtifactSpec(dep.getScope().toString(), dep.getCoordinate().getGroupId(), dep.getCoordinate().getArtifactId(), dep.getCoordinate().getVersion(), dep.getCoordinate().getPackaging().toString(), dep.getCoordinate().getClassifier(), dep.asFile());
declaredDependencies.add(parent, child);
}
}
return declaredDependencies;
}
use of org.wildfly.swarm.tools.ArtifactSpec in project wildfly-swarm by wildfly-swarm.
the class MavenArtifactResolvingHelper method resolveAll.
@Override
public Set<ArtifactSpec> resolveAll(Collection<ArtifactSpec> specs, boolean transitive, boolean defaultExcludes) throws Exception {
if (specs.isEmpty()) {
return Collections.emptySet();
}
List<DependencyNode> nodes;
if (transitive) {
final CollectRequest request = new CollectRequest();
request.setRepositories(this.remoteRepositories);
// SWARM-1031
if (this.dependencyManagement != null) {
List<Dependency> managedDependencies = this.dependencyManagement.getDependencies().stream().map(mavenDep -> {
DefaultArtifact artifact = new DefaultArtifact(mavenDep.getGroupId(), mavenDep.getArtifactId(), mavenDep.getType(), mavenDep.getVersion());
return new Dependency(artifact, mavenDep.getScope());
}).collect(Collectors.toList());
request.setManagedDependencies(managedDependencies);
}
specs.forEach(spec -> request.addDependency(new Dependency(new DefaultArtifact(spec.groupId(), spec.artifactId(), spec.classifier(), spec.type(), spec.version()), "compile")));
RepositorySystemSession tempSession = new RepositorySystemSessionWrapper(this.session, new ConflictResolver(new NearestVersionSelector(), new JavaScopeSelector(), new SimpleOptionalitySelector(), new JavaScopeDeriver()), defaultExcludes);
CollectResult result = this.system.collectDependencies(tempSession, request);
PreorderNodeListGenerator gen = new PreorderNodeListGenerator();
result.getRoot().accept(gen);
nodes = gen.getNodes();
} else {
nodes = new ArrayList<>();
for (ArtifactSpec spec : specs) {
Dependency dependency = new Dependency(new DefaultArtifact(spec.groupId(), spec.artifactId(), spec.classifier(), spec.type(), spec.version()), "compile");
DefaultDependencyNode node = new DefaultDependencyNode(dependency);
nodes.add(node);
}
}
List<DependencyNode> extraDependencies = ExtraArtifactsHandler.getExtraDependencies(nodes);
nodes.addAll(extraDependencies);
resolveDependenciesInParallel(nodes);
return nodes.stream().filter(node -> !"system".equals(node.getDependency().getScope())).map(node -> {
final Artifact artifact = node.getArtifact();
return new ArtifactSpec(node.getDependency().getScope(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getExtension(), artifact.getClassifier(), null);
}).map(this::resolve).filter(Objects::nonNull).collect(Collectors.toSet());
}
use of org.wildfly.swarm.tools.ArtifactSpec 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.tools.ArtifactSpec in project wildfly-swarm by wildfly-swarm.
the class StartMojo method findNeededFractions.
List<Path> findNeededFractions(final Set<Artifact> existingDeps, final Path source, final boolean scanDeps) throws MojoFailureException {
getLog().info("Scanning for needed WildFly Swarm fractions with mode: " + fractionDetectMode);
final Set<String> existingDepGASet = existingDeps.stream().map(d -> String.format("%s:%s", d.getGroupId(), d.getArtifactId())).collect(Collectors.toSet());
final Set<FractionDescriptor> fractions;
final FractionUsageAnalyzer analyzer = new FractionUsageAnalyzer(FractionList.get()).source(source);
if (scanDeps) {
existingDeps.forEach(d -> analyzer.source(d.getFile()));
}
final Predicate<FractionDescriptor> notExistingDep = d -> !existingDepGASet.contains(String.format("%s:%s", d.getGroupId(), d.getArtifactId()));
try {
fractions = analyzer.detectNeededFractions().stream().filter(notExistingDep).collect(Collectors.toSet());
} catch (IOException e) {
throw new MojoFailureException("failed to scan for fractions", e);
}
getLog().info("Detected fractions: " + String.join(", ", fractions.stream().map(FractionDescriptor::av).sorted().collect(Collectors.toList())));
fractions.addAll(this.additionalFractions.stream().map(f -> FractionDescriptor.fromGav(FractionList.get(), f)).collect(Collectors.toSet()));
final Set<FractionDescriptor> allFractions = new HashSet<>(fractions);
allFractions.addAll(fractions.stream().flatMap(f -> f.getDependencies().stream()).filter(notExistingDep).collect(Collectors.toSet()));
getLog().info("Using fractions: " + String.join(", ", allFractions.stream().map(FractionDescriptor::gavOrAv).sorted().collect(Collectors.toList())));
final Set<ArtifactSpec> specs = new HashSet<>();
specs.addAll(existingDeps.stream().map(this::artifactToArtifactSpec).collect(Collectors.toList()));
specs.addAll(allFractions.stream().map(ArtifactSpec::fromFractionDescriptor).collect(Collectors.toList()));
try {
return mavenArtifactResolvingHelper().resolveAll(specs).stream().map(s -> s.file.toPath()).collect(Collectors.toList());
} catch (Exception e) {
throw new MojoFailureException("failed to resolve fraction dependencies", e);
}
}
Aggregations