Skip to content

Commit

Permalink
Use conventional artifact file naming for the generated platform prop…
Browse files Browse the repository at this point in the history
…erties and descriptor files
  • Loading branch information
aloubyansky committed Nov 4, 2020
1 parent b549c5a commit 7ea402b
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 14 deletions.
4 changes: 2 additions & 2 deletions devtools/cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
<execution>
<goals>
<goal>build</goal>
<goal>prepare</goal>
<goal>prepare-tests</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
</goals>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import io.quarkus.bootstrap.BootstrapConstants;
import io.quarkus.bootstrap.resolver.maven.workspace.LocalWorkspace;
import io.quarkus.bootstrap.resolver.maven.workspace.ModelUtils;
import io.quarkus.bootstrap.util.IoUtils;
import io.quarkus.bootstrap.util.ZipUtils;
import io.quarkus.dependencies.Extension;
import io.quarkus.platform.tools.ToolsConstants;
Expand All @@ -85,7 +87,7 @@ public class GenerateExtensionsJsonMojo extends AbstractMojo {
@Parameter(property = "overridesFile", defaultValue = "${project.basedir}/src/main/resources/extensions-overrides.json")
private String overridesFile;

@Parameter(property = "outputFile", defaultValue = "${project.build.directory}/extensions.json")
@Parameter(property = "outputFile", defaultValue = "${project.build.directory}/${project.artifactId}-${project.version}-${project.version}.json")
private File outputFile;

@Component
Expand Down Expand Up @@ -270,7 +272,16 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
info("Extensions file written to %s", outputFile);

projectHelper.attachArtifact(project, jsonArtifact.getExtension(), jsonArtifact.getClassifier(), outputFile);
// this is necessary to sometimes be able to resolve the artifacts from the workspace
final File published = new File(project.getBuild().getDirectory(), LocalWorkspace.getFileName(jsonArtifact));
if (!outputDir.equals(published)) {
try {
IoUtils.copy(outputFile.toPath(), published.toPath());
} catch (IOException e) {
throw new MojoExecutionException("Failed to copy " + outputFile + " to " + published);
}
}
projectHelper.attachArtifact(project, jsonArtifact.getExtension(), jsonArtifact.getClassifier(), published);
}

private List<Dependency> dependencyManagementFromDescriptor(Artifact bomArtifact) throws MojoExecutionException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.apache.maven.project.MavenProjectHelper;

import io.quarkus.bootstrap.BootstrapConstants;
import io.quarkus.bootstrap.util.IoUtils;

@Mojo(name = "platform-properties", threadSafe = true)
public class PlatformPropertiesMojo extends AbstractMojo {
Expand Down Expand Up @@ -83,7 +84,16 @@ public void execute() throws MojoExecutionException, MojoFailureException {
assertPlatformPropertiesInBom();
}

projectHelper.attachArtifact(project, "properties", propsFile);
// this is necessary to sometimes be able to resolve the artifacts from the workspace
final File published = new File(project.getBuild().getDirectory(),
project.getArtifactId() + "-" + project.getVersion() + ".properties");
try {
IoUtils.copy(propsFile.toPath(), published.toPath());
} catch (IOException e) {
throw new MojoExecutionException("Failed to copy " + propsFile + " to " + published, e);
}

projectHelper.attachArtifact(project, "properties", published);
}

private void assertPlatformPropertiesInBom() throws MojoExecutionException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ public boolean visitLeave(DependencyNode node) {
managedDeps = mergedManagedDeps;
}

collectPlatformProperties(appBuilder, managedDeps);

final List<RemoteRepository> repos = mvn.aggregateRepositories(managedRepos,
mvn.newResolutionRepositories(appArtifactDescr.getRepositories()));

Expand All @@ -254,7 +252,8 @@ public boolean visitLeave(DependencyNode node) {
} catch (RepositoryException e) {
throw new AppModelResolverException("Failed to normalize the dependency graph", e);
}
final BuildDependencyGraphVisitor buildDepsVisitor = new BuildDependencyGraphVisitor(appDeps, buildTreeConsumer);
final BuildDependencyGraphVisitor buildDepsVisitor = new BuildDependencyGraphVisitor(appDeps, buildTreeConsumer,
repos);
buildDepsVisitor.visit(resolvedDeps);
final List<ArtifactRequest> requests = buildDepsVisitor.getArtifactRequests();
if (!requests.isEmpty()) {
Expand All @@ -275,6 +274,8 @@ public boolean visitLeave(DependencyNode node) {
}
}

collectPlatformProperties(appBuilder, managedDeps, repos);

List<AppDependency> fullDeploymentDeps = new ArrayList<>(userDeps.size() + deploymentDeps.size());
fullDeploymentDeps.addAll(userDeps);
fullDeploymentDeps.addAll(deploymentDeps);
Expand All @@ -291,7 +292,8 @@ public boolean visitLeave(DependencyNode node) {
.build();
}

private void collectPlatformProperties(AppModel.Builder appBuilder, List<Dependency> managedDeps)
private void collectPlatformProperties(AppModel.Builder appBuilder, List<Dependency> managedDeps,
List<RemoteRepository> repos)
throws AppModelResolverException {
final Set<AppArtifactKey> descriptorKeys = new HashSet<>(4);
final Set<AppArtifactKey> propertyKeys = new HashSet<>(2);
Expand All @@ -307,7 +309,7 @@ private void collectPlatformProperties(AppModel.Builder appBuilder, List<Depende
artifact.getVersion()));
} else if ("properties".equals(artifact.getExtension())
&& artifactId.endsWith(BootstrapConstants.PLATFORM_PROPERTIES_ARTIFACT_ID_SUFFIX)) {
final Path propsPath = resolve(toAppArtifact(artifact));
final Path propsPath = mvn.resolve(artifact).getArtifact().getFile().toPath();
final Properties props = new Properties();
try (InputStream is = Files.newInputStream(propsPath)) {
props.load(is);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public class BootstrapMavenContext {
private static final String DEFAULT_REMOTE_REPO_URL = "https://repo.maven.apache.org/maven2";
private static final String MAVEN_DOT_HOME = "maven.home";
private static final String MAVEN_HOME = "MAVEN_HOME";
private static final String MAVEN_PROJECTBASEDIR = "MAVEN_PROJECTBASEDIR";
private static final String MAVEN_SETTINGS = "maven.settings";
private static final String SETTINGS_XML = "settings.xml";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.graph.DependencyNode;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.ArtifactRequest;

public class BuildDependencyGraphVisitor {
Expand All @@ -19,6 +20,7 @@ public class BuildDependencyGraphVisitor {
private final StringBuilder buf;
private final Consumer<String> buildTreeConsumer;
private final List<Boolean> depth;
private final List<RemoteRepository> repos;

private DependencyNode deploymentNode;
private DependencyNode runtimeNode;
Expand All @@ -30,7 +32,8 @@ public class BuildDependencyGraphVisitor {
private final List<DependencyNode> deploymentDepNodes = new ArrayList<>();
private final List<ArtifactRequest> requests = new ArrayList<>();

public BuildDependencyGraphVisitor(Set<AppArtifactKey> appDeps, Consumer<String> buildTreeConsumer) {
public BuildDependencyGraphVisitor(Set<AppArtifactKey> appDeps, Consumer<String> buildTreeConsumer,
List<RemoteRepository> repos) {
this.appDeps = appDeps;
this.buildTreeConsumer = buildTreeConsumer;
if (buildTreeConsumer == null) {
Expand All @@ -40,6 +43,7 @@ public BuildDependencyGraphVisitor(Set<AppArtifactKey> appDeps, Consumer<String>
buf = new StringBuilder();
depth = new ArrayList<>();
}
this.repos = repos;
}

public List<DependencyNode> getDeploymentNodes() {
Expand Down Expand Up @@ -131,7 +135,7 @@ private void visitLeave(DependencyNode node) {
}
final Artifact artifact = dep.getArtifact();
if (artifact.getFile() == null) {
requests.add(new ArtifactRequest(node));
requests.add(new ArtifactRequest(node).setRepositories(repos));
}
if (deploymentNode != null) {
if (runtimeNode == null && !appDeps.contains(new AppArtifactKey(artifact.getGroupId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ public File findArtifact(Artifact artifact) {
if (pom.exists()) {
return pom;
}
} else {
// check whether the artifact exists in the project's output dir
final Path path = lp.getOutputDir().resolve(getFileName(artifact));
if (Files.exists(path)) {
return path.toFile();
}
}
return null;
}
Expand All @@ -171,7 +177,7 @@ private boolean isFoundInLocalRepo(Artifact artifact) {
return Files.exists(p);
}

private static String getFileName(Artifact artifact) {
public static String getFileName(Artifact artifact) {
final StringBuilder fileName = new StringBuilder();
fileName.append(artifact.getArtifactId()).append('-').append(artifact.getVersion());
if (!artifact.getClassifier().isEmpty()) {
Expand Down

0 comments on commit 7ea402b

Please sign in to comment.