Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps-to-build quarkus cli app and bunch of fixes #155

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions deps-to-build/api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-platform-bom-deps-to-build</artifactId>
<version>0.0.66-SNAPSHOT</version>
</parent>

<artifactId>quarkus-platform-bom-deps-to-build-api</artifactId>
<name>Quarkus - Platform BOM Tools - Dependencies to build tool - API</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-platform-bom-decomposer</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ public Builder setValidateCodeRepoTags(boolean validateTags) {
return this;
}

public Builder setWarnOnResolutionErrors(boolean warn) {
warnOnResolutionErrors = warn;
return this;
}

public DependenciesToBuildReportGenerator build() {
if (resolver == null) {
try {
Expand Down Expand Up @@ -303,6 +308,11 @@ private DependenciesToBuildReportGenerator() {
*/
private boolean includeTestJars;

/*
* Whether to warn about errors not being able to resolve top level artifacts or fail the process
*/
private boolean warnOnResolutionErrors;

private Set<String> excludeGroupIds = Set.of();
private Set<ArtifactKey> excludeKeys = Set.of();
private Set<ArtifactCoords> excludeArtifacts = Set.of();
Expand Down Expand Up @@ -370,13 +380,7 @@ public void generate() {
detectCircularRepoDeps();
codeReposTotal = releaseRepos.size();

final List<ReleaseRepo> sorted = new ArrayList<>(codeReposTotal);
for (ReleaseRepo r : releaseRepos.values()) {
if (r.isRoot()) {
sort(r, new HashSet<>(codeReposTotal), sorted);
}
}

final List<ReleaseRepo> sorted = sortReleaseRepos();
for (ReleaseRepo e : sorted) {
logComment("repo-url " + e.id().origin());
logComment("tag " + e.id().version().asString());
Expand Down Expand Up @@ -465,11 +469,24 @@ public void generate() {
}
} finally {
if (fileOutput != null) {
log.info("Saving the report in " + outputFile.getAbsolutePath());
fileOutput.close();
}
}
}

private List<ReleaseRepo> sortReleaseRepos() {
final int codeReposTotal = releaseRepos.size();
final List<ReleaseRepo> sorted = new ArrayList<>(codeReposTotal);
final Set<ReleaseId> processedRepos = new HashSet<>(codeReposTotal);
for (ReleaseRepo r : releaseRepos.values()) {
if (r.isRoot()) {
sort(r, processedRepos, sorted);
}
}
return sorted;
}

private void removeProductizedDeps() {
final Set<ArtifactKey> alreadyBuiltKeys = allDepsToBuild.stream()
.filter(c -> RhVersionPattern.isRhVersion(c.getVersion()))
Expand Down Expand Up @@ -516,8 +533,13 @@ private void processTopLevelArtifact(List<Dependency> managedDeps, ArtifactCoord
if (root.getChildren().isEmpty()) {
resolver.resolve(a);
}
} catch (Exception e1) {
throw new RuntimeException("Failed to collect dependencies of " + topLevelArtifact.toCompactCoords(), e1);
} catch (Exception e) {
if (warnOnResolutionErrors) {
log.warn(e.getCause() == null ? e.getLocalizedMessage() : e.getCause().getLocalizedMessage());
allDepsToBuild.remove(topLevelArtifact);
return;
}
throw new RuntimeException("Failed to collect dependencies of " + topLevelArtifact.toCompactCoords(), e);
}

if (logTrees) {
Expand All @@ -540,6 +562,9 @@ private void processTopLevelArtifact(List<Dependency> managedDeps, ArtifactCoord
extDep.logBomImportsAndParents();
}
for (DependencyNode d : root.getChildren()) {
if (d.getDependency().isOptional()) {
continue;
}
processNodes(extDep, d, 1, false);
}
} else if (logRemaining) {
Expand Down Expand Up @@ -749,14 +774,6 @@ public static void main(String[] args) throws Exception {
.setLogTrees(true)
.build()
.generate();

/*
* ReleaseIdResolver idResolver = newReleaseIdResolver(MavenArtifactResolver.builder().build(), MessageWriter.info(),
* true);
* ReleaseId releaseId = idResolver
* .releaseId(new DefaultArtifact("org.ow2.asm", "asm", "pom", "9.3"));
* System.out.println("RELEASE ID " + releaseId);
*/
}

private void sort(ReleaseRepo repo, Set<ReleaseId> processed, List<ReleaseRepo> sorted) {
Expand Down Expand Up @@ -804,7 +821,7 @@ private PrintStream getOutput() {
return System.out;
}
if (fileOutput == null) {
outputFile.getParentFile().mkdirs();
outputFile.getAbsoluteFile().getParentFile().mkdirs();
try {
fileOutput = new PrintStream(new FileOutputStream(outputFile, appendOutput), false);
} catch (FileNotFoundException e) {
Expand Down Expand Up @@ -1135,10 +1152,14 @@ private void detectCircularRepoDeps() {
}

private void detectCircularRepoDeps(ReleaseRepo r, List<ReleaseId> chain) {
if (chain.contains(r.id)) {
chain.add(r.id);
circularRepoDeps.computeIfAbsent(new HashSet<>(chain), k -> new ArrayList<>(chain));
chain.remove(chain.size() - 1);
final int i = chain.indexOf(r.id);
if (i >= 0) {
final List<ReleaseId> loop = new ArrayList<>(chain.size() - i + 1);
for (int j = i; j < chain.size(); ++j) {
loop.add(chain.get(j));
}
loop.add(r.id);
circularRepoDeps.computeIfAbsent(new HashSet<>(loop), k -> loop);
return;
}
chain.add(r.id);
Expand Down
99 changes: 99 additions & 0 deletions deps-to-build/app/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-platform-bom-deps-to-build</artifactId>
<version>0.0.66-SNAPSHOT</version>
</parent>
<artifactId>deps-to-build</artifactId>
<name>Quarkus - Platform BOM Tools - Dependencies to build tool - App</name>
<properties>
<skipITs>true</skipITs>
<quarkus.package.type>uber-jar</quarkus.package.type>
<quarkus.package.add-runner-suffix>false</quarkus.package.add-runner-suffix>
</properties>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-platform-bom-deps-to-build-api</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-picocli</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.version}</version>
<extensions>true</extensions>
<configuration>
<finalName>deps-to-build</finalName>
</configuration>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<properties>
<skipITs>false</skipITs>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package io.quarkus.platform.depstobuild;

import io.quarkus.bom.decomposer.maven.DependenciesToBuildReportGenerator;
import io.quarkus.maven.dependency.ArtifactCoords;
import java.io.File;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import picocli.CommandLine;

@CommandLine.Command
public class DepsToBuildMain implements Runnable {

@CommandLine.Option(names = {
"--bom" }, description = "BOM whose constraints should be used as top level artifacts to be built")
public String bom;

@CommandLine.Option(names = { "--include-non-managed" }, description = "Include non-managed dependencies")
public boolean includeNonManaged;

@CommandLine.Option(names = {
"--root-artifacts" }, description = "Root artifacts whose dependencies should be built from source")
public Collection<String> rootArtifacts = List.of();

@CommandLine.Option(names = {
"--level" }, description = "Dependency tree depth level to which the dependencies should be analyzed. If a level is not specified, there is no limit on the level.")
public int level = -1;

@CommandLine.Option(names = {
"--log-artifacts-to-build" }, description = "Whether to log the coordinates of the artifacts captured down to the depth specified. The default is true.")
public boolean logArtifactsToBuild = true;

@CommandLine.Option(names = {
"--log-modules-to-build" }, description = "Whether to log the module GAVs the artifacts to be built belongs to instead of all the complete artifact coordinates to be built. If this option is enabled, it overrides {@link #logArtifactsToBuild}")
public boolean logModulesToBuild;

@CommandLine.Option(names = {
"--log-trees" }, description = "Whether to log the dependency trees walked down to the depth specified. The default is false.")
public boolean logTrees;

@CommandLine.Option(names = {
"--log-remaining" }, description = "Whether to log the coordinates of the artifacts below the depth specified. The default is false.")
public boolean logRemaining;

@CommandLine.Option(names = {
"--log-summary" }, description = "Whether to log the summary at the end. The default is true.")
public boolean logSummary = true;

@CommandLine.Option(names = {
"--log-non-managed-visited" }, description = "Whether to log the summary at the end. The default is true.")
public boolean logNonManagedVisited;

@CommandLine.Option(names = {
"--output-file" }, description = "If specified, this parameter will cause the output to be written to the path specified, instead of writing to the console.")
public File outputFile;

@CommandLine.Option(names = {
"--append-output" }, description = "Whether to append outputs into the output file or overwrite it.")
public boolean appendOutput;

@CommandLine.Option(names = {
"--log-code-repos" }, description = "Whether to log code repository info for the artifacts to be built from source")
public boolean logCodeRepos;

@CommandLine.Option(names = { "--log-code-repo-graph" }, description = "Whether to log code repository dependency graph.")
public boolean logCodeRepoGraph;

@CommandLine.Option(names = {
"--exclude-parent-poms" }, description = "Whether to exclude parent POMs from the list of artifacts to be built from source")
public boolean excludeParentPoms;

@CommandLine.Option(names = {
"--exclude-bom-imports" }, description = "Whether to exclude BOMs imported in the POMs of artifacts to be built from the list of artifacts to be built from source")
public boolean excludeBomImports;

@CommandLine.Option(names = {
"--validate-code-repo-tags" }, description = "Whether to validate the discovered code repo and tags that are included in the report")
public boolean validateCodeRepoTags;

@CommandLine.Option(names = {
"--warn-on-resolution-errors" }, description = "Whether to warn about artifact resolution errors instead of failing the process")
public Boolean warnOnResolutionErrors;

@Override
public void run() {
DependenciesToBuildReportGenerator.Builder builder = DependenciesToBuildReportGenerator.builder();

if (warnOnResolutionErrors != null) {
builder.setWarnOnResolutionErrors(warnOnResolutionErrors);
} else if (bom != null) {
builder.setWarnOnResolutionErrors(true);
}

builder.setAppendOutput(appendOutput)
.setBom(bom == null ? null : ArtifactCoords.fromString(bom))
.setExcludeArtifacts(Set.of()) // TODO
.setExcludeBomImports(excludeBomImports)
.setExcludeGroupIds(Set.of()) // TODO
.setExcludeKeys(Set.of()) // TODO
.setExcludeParentPoms(excludeParentPoms)
.setIncludeArtifacts(Set.of()) // TODO
.setIncludeGroupIds(Set.of()) // TODO
.setIncludeKeys(Set.of()) // TODO
.setIncludeNonManaged(includeNonManaged)
.setLevel(level)
.setLogArtifactsToBuild(logArtifactsToBuild)
.setLogCodeRepoGraph(logCodeRepoGraph)
.setLogCodeRepos(logCodeRepos)
.setLogModulesToBuild(logModulesToBuild)
.setLogNonManagedVisited(logNonManagedVisited)
.setLogRemaining(logRemaining)
.setLogSummary(logSummary)
.setLogTrees(logTrees)
.setOutputFile(outputFile)
.setTopLevelArtifactsToBuild(
rootArtifacts.stream().map(ArtifactCoords::fromString).collect(Collectors.toList()))
.setValidateCodeRepoTags(validateCodeRepoTags)
.build().generate();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
quarkus.banner.enabled=false
Loading