Skip to content

Commit

Permalink
Use ArtifactCoords API in the devtools instead of AppArtifactCoords
Browse files Browse the repository at this point in the history
  • Loading branch information
aloubyansky committed Apr 7, 2021
1 parent f30ecda commit c2b3d59
Show file tree
Hide file tree
Showing 31 changed files with 239 additions and 251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import org.gradle.api.Project;

import io.quarkus.bootstrap.model.AppArtifactCoords;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.maven.ArtifactCoords;
import io.quarkus.registry.catalog.ExtensionCatalog;

public class GradleGroovyProjectBuildFile extends GradleProjectBuildFile {
Expand All @@ -26,7 +26,7 @@ String getBuildGradlePath() {
}

@Override
protected boolean addDependency(AppArtifactCoords coords, boolean managed) {
protected boolean addDependency(ArtifactCoords coords, boolean managed) {
return addDependencyInModel(getModel(), coords, managed);
}

Expand All @@ -35,7 +35,7 @@ public BuildTool getBuildTool() {
return BuildTool.GRADLE;
}

static boolean addDependencyInModel(Model model, AppArtifactCoords coords, boolean managed) {
static boolean addDependencyInModel(Model model, ArtifactCoords coords, boolean managed) {
return addDependencyInModel(model,
String.format(" implementation %s%n", createDependencyCoordinatesString(coords, managed, '\'')));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import org.gradle.api.Project;

import io.quarkus.bootstrap.model.AppArtifactCoords;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.maven.ArtifactCoords;
import io.quarkus.registry.catalog.ExtensionCatalog;

public class GradleKotlinProjectBuildFile extends GradleProjectBuildFile {
Expand All @@ -26,7 +26,7 @@ String getBuildGradlePath() {
}

@Override
protected boolean addDependency(AppArtifactCoords coords, boolean managed) {
protected boolean addDependency(ArtifactCoords coords, boolean managed) {
return addDependencyInModel(getModel(), coords, managed);
}

Expand All @@ -35,7 +35,7 @@ public BuildTool getBuildTool() {
return BuildTool.GRADLE_KOTLIN_DSL;
}

static boolean addDependencyInModel(Model model, AppArtifactCoords coords, boolean managed) {
static boolean addDependencyInModel(Model model, ArtifactCoords coords, boolean managed) {
return addDependencyInModel(model,
String.format(" implementation(%s)%n", createDependencyCoordinatesString(coords, managed, '"')));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.gradle.api.plugins.JavaPlugin;

import io.quarkus.bootstrap.BootstrapConstants;
import io.quarkus.bootstrap.model.AppArtifactCoords;
import io.quarkus.maven.ArtifactCoords;
import io.quarkus.registry.catalog.ExtensionCatalog;
import io.quarkus.registry.util.PlatformArtifacts;

Expand All @@ -31,19 +31,19 @@ public GradleProjectBuildFile(Project project, ExtensionCatalog catalog) {
}

@Override
protected List<AppArtifactCoords> getDependencies() throws IOException {
protected List<ArtifactCoords> getDependencies() throws IOException {

final List<Dependency> boms = boms();

final Set<ResolvedArtifact> resolvedArtifacts = project.getConfigurations()
.getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME).getResolvedConfiguration()
.getResolvedArtifacts();
final List<AppArtifactCoords> coords = new ArrayList<>(boms.size() + resolvedArtifacts.size());
final List<ArtifactCoords> coords = new ArrayList<>(boms.size() + resolvedArtifacts.size());
boms.forEach(d -> {
coords.add(new AppArtifactCoords(d.getGroup(), d.getName(), null, "pom", d.getVersion()));
coords.add(new ArtifactCoords(d.getGroup(), d.getName(), null, "pom", d.getVersion()));
});
resolvedArtifacts.forEach(a -> {
coords.add(new AppArtifactCoords(a.getModuleVersion().getId().getGroup(), a.getName(),
coords.add(new ArtifactCoords(a.getModuleVersion().getId().getGroup(), a.getName(),
a.getClassifier(), a.getExtension(), a.getModuleVersion().getId().getVersion()));
});
return coords;
Expand All @@ -69,19 +69,19 @@ private List<Dependency> boms() {
}

@Override
public List<AppArtifactCoords> getInstalledPlatforms() throws IOException {
public List<ArtifactCoords> getInstalledPlatforms() throws IOException {
final List<Dependency> bomDeps = boms();
if (bomDeps.isEmpty()) {
return Collections.emptyList();
}
final Configuration boms = project.getConfigurations()
.detachedConfiguration(bomDeps.toArray(new org.gradle.api.artifacts.Dependency[0]));
final List<AppArtifactCoords> platforms = new ArrayList<>();
final List<ArtifactCoords> platforms = new ArrayList<>();
boms.getResolutionStrategy().eachDependency(d -> {
if (!d.getTarget().getName().endsWith(BootstrapConstants.PLATFORM_DESCRIPTOR_ARTIFACT_ID_SUFFIX)) {
return;
}
final AppArtifactCoords platform = new AppArtifactCoords(d.getTarget().getGroup(),
final ArtifactCoords platform = new ArtifactCoords(d.getTarget().getGroup(),
PlatformArtifacts.ensureBomArtifactId(d.getTarget().getName()), null, "pom", d.getTarget().getVersion());
platforms.add(platform);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Model;

import io.quarkus.bootstrap.model.AppArtifactCoords;
import io.quarkus.bootstrap.model.AppArtifactKey;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.devtools.project.buildfile.BuildFile;
import io.quarkus.maven.utilities.MojoUtils;
Expand All @@ -36,9 +34,9 @@ public class MavenProjectBuildFile extends BuildFile {
private Supplier<List<org.eclipse.aether.graph.Dependency>> projectDepsSupplier;
private Supplier<List<org.eclipse.aether.graph.Dependency>> projectManagedDepsSupplier;
private Properties projectProps;
protected List<AppArtifactCoords> dependencies;
protected List<AppArtifactCoords> managedDependencies;
protected List<AppArtifactCoords> importedPlatforms;
protected List<ArtifactCoords> dependencies;
protected List<ArtifactCoords> managedDependencies;
protected List<ArtifactCoords> importedPlatforms;
protected Model model;

public MavenProjectBuildFile(Path projectDirPath, ExtensionCatalog extensionsCatalog, Supplier<Model> model,
Expand All @@ -58,7 +56,7 @@ public BuildTool getBuildTool() {
}

@Override
protected boolean addDependency(AppArtifactCoords coords, boolean managed) {
protected boolean addDependency(ArtifactCoords coords, boolean managed) {
final Dependency d = new Dependency();
d.setGroupId(coords.getGroupId());
d.setArtifactId(coords.getArtifactId());
Expand Down Expand Up @@ -101,11 +99,11 @@ protected boolean addDependency(AppArtifactCoords coords, boolean managed) {
}

@Override
protected void removeDependency(AppArtifactKey key) throws IOException {
protected void removeDependency(ArtifactKey key) throws IOException {
if (model() != null) {
final Iterator<AppArtifactCoords> i = getDependencies().iterator();
final Iterator<ArtifactCoords> i = getDependencies().iterator();
while (i.hasNext()) {
final AppArtifactCoords a = i.next();
final ArtifactCoords a = i.next();
if (a.getKey().equals(key)) {
i.remove();
break;
Expand All @@ -116,29 +114,29 @@ protected void removeDependency(AppArtifactKey key) throws IOException {
}

@Override
protected List<AppArtifactCoords> getDependencies() {
protected List<ArtifactCoords> getDependencies() {
if (dependencies == null) {
final List<org.eclipse.aether.graph.Dependency> projectDeps = projectDepsSupplier.get();
projectDepsSupplier = null;
dependencies = new ArrayList<>(projectDeps.size());
for (org.eclipse.aether.graph.Dependency dep : projectDeps) {
org.eclipse.aether.artifact.Artifact a = dep.getArtifact();
dependencies.add(new AppArtifactCoords(a.getGroupId(), a.getArtifactId(), a.getClassifier(),
dependencies.add(new ArtifactCoords(a.getGroupId(), a.getArtifactId(), a.getClassifier(),
a.getExtension(), a.getVersion()));
}
}
return dependencies;
}

@Override
public final Collection<AppArtifactCoords> getInstalledPlatforms() throws IOException {
public final Collection<ArtifactCoords> getInstalledPlatforms() throws IOException {
if (importedPlatforms == null) {
final List<AppArtifactCoords> tmp = new ArrayList<>(4);
for (AppArtifactCoords c : getManagedDependencies()) {
final List<ArtifactCoords> tmp = new ArrayList<>(4);
for (ArtifactCoords c : getManagedDependencies()) {
if (!PlatformArtifacts.isCatalogArtifactId(c.getArtifactId())) {
continue;
}
tmp.add(new AppArtifactCoords(c.getGroupId(),
tmp.add(new ArtifactCoords(c.getGroupId(),
c.getArtifactId().substring(0,
c.getArtifactId().length() - Constants.PLATFORM_DESCRIPTOR_ARTIFACT_ID_SUFFIX.length()),
null, "pom", c.getVersion()));
Expand All @@ -148,14 +146,14 @@ public final Collection<AppArtifactCoords> getInstalledPlatforms() throws IOExce
return importedPlatforms;
}

protected List<AppArtifactCoords> getManagedDependencies() {
protected List<ArtifactCoords> getManagedDependencies() {
if (managedDependencies == null) {
final List<org.eclipse.aether.graph.Dependency> managedDeps = projectManagedDepsSupplier.get();
projectManagedDepsSupplier = null;
managedDependencies = new ArrayList<>(managedDeps.size());
for (org.eclipse.aether.graph.Dependency dep : managedDeps) {
org.eclipse.aether.artifact.Artifact a = dep.getArtifact();
managedDependencies.add(new AppArtifactCoords(a.getGroupId(), a.getArtifactId(), a.getClassifier(),
managedDependencies.add(new ArtifactCoords(a.getGroupId(), a.getArtifactId(), a.getClassifier(),
a.getExtension(), a.getVersion()));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.quarkus.devtools.codestarts.jbang;

import io.quarkus.bootstrap.model.AppArtifactCoords;
import io.quarkus.devtools.codestarts.CodestartProjectInput;
import io.quarkus.maven.ArtifactCoords;
import java.util.Collection;

public final class QuarkusJBangCodestartProjectInput extends CodestartProjectInput {
private final Collection<AppArtifactCoords> extensions;
private final Collection<ArtifactCoords> extensions;
private final boolean noJBangWrapper;

public QuarkusJBangCodestartProjectInput(QuarkusJBangCodestartProjectInputBuilder builder) {
Expand All @@ -22,7 +22,7 @@ public boolean noJBangWrapper() {
return noJBangWrapper;
}

public Collection<AppArtifactCoords> getExtensions() {
public Collection<ArtifactCoords> getExtensions() {
return extensions;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package io.quarkus.devtools.codestarts.jbang;

import io.quarkus.bootstrap.model.AppArtifactCoords;
import io.quarkus.bootstrap.model.AppArtifactKey;
import io.quarkus.devtools.codestarts.CodestartProjectInputBuilder;
import io.quarkus.devtools.codestarts.DataKey;
import io.quarkus.devtools.messagewriter.MessageWriter;
import io.quarkus.devtools.project.extensions.Extensions;
import io.quarkus.maven.ArtifactCoords;
import io.quarkus.maven.ArtifactKey;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.stream.Collectors;

public class QuarkusJBangCodestartProjectInputBuilder extends CodestartProjectInputBuilder {
public Collection<AppArtifactCoords> extensions = new ArrayList<>();
public Collection<ArtifactCoords> extensions = new ArrayList<>();

public QuarkusJBangCodestartProjectInputBuilder setNoJBangWrapper(boolean noJBangWrapper) {
this.noJBangWrapper = noJBangWrapper;
Expand All @@ -26,17 +26,17 @@ public QuarkusJBangCodestartProjectInputBuilder setNoJBangWrapper(boolean noJBan
super();
}

public QuarkusJBangCodestartProjectInputBuilder addExtensions(Collection<AppArtifactCoords> extensions) {
public QuarkusJBangCodestartProjectInputBuilder addExtensions(Collection<ArtifactCoords> extensions) {
this.extensions.addAll(extensions);
super.addDependencies(extensions.stream().map(Extensions::toGAV).collect(Collectors.toList()));
return this;
}

public QuarkusJBangCodestartProjectInputBuilder addExtension(AppArtifactCoords extension) {
public QuarkusJBangCodestartProjectInputBuilder addExtension(ArtifactCoords extension) {
return this.addExtensions(Collections.singletonList(extension));
}

public QuarkusJBangCodestartProjectInputBuilder addExtension(AppArtifactKey extension) {
public QuarkusJBangCodestartProjectInputBuilder addExtension(ArtifactKey extension) {
return this.addExtension(Extensions.toCoords(extension, null));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import static java.util.Objects.requireNonNull;

import io.quarkus.bootstrap.model.AppArtifactCoords;
import io.quarkus.devtools.codestarts.CodestartProjectInput;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.maven.ArtifactCoords;
import java.util.Collection;
import java.util.Set;

public final class QuarkusCodestartProjectInput extends CodestartProjectInput {
private final BuildTool buildTool;
private final Collection<AppArtifactCoords> extensions;
private final Collection<ArtifactCoords> extensions;
private final Set<String> overrideExamples;
private final boolean noExamples;
private final boolean noDockerfiles;
Expand All @@ -30,7 +30,7 @@ public static QuarkusCodestartProjectInputBuilder builder() {
return new QuarkusCodestartProjectInputBuilder();
}

public Collection<AppArtifactCoords> getExtensions() {
public Collection<ArtifactCoords> getExtensions() {
return extensions;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import static java.util.Objects.requireNonNull;

import io.quarkus.bootstrap.model.AppArtifactCoords;
import io.quarkus.bootstrap.model.AppArtifactKey;
import io.quarkus.devtools.codestarts.CodestartProjectInputBuilder;
import io.quarkus.devtools.messagewriter.MessageWriter;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.devtools.project.extensions.Extensions;
import io.quarkus.maven.ArtifactCoords;
import io.quarkus.maven.ArtifactKey;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -17,7 +17,7 @@
import java.util.stream.Collectors;

public class QuarkusCodestartProjectInputBuilder extends CodestartProjectInputBuilder {
Collection<AppArtifactCoords> extensions = new ArrayList<>();
Collection<ArtifactCoords> extensions = new ArrayList<>();
Set<String> overrideExamples = new HashSet<>();
boolean noExamples;
boolean noDockerfiles;
Expand All @@ -28,17 +28,17 @@ public class QuarkusCodestartProjectInputBuilder extends CodestartProjectInputBu
super();
}

public QuarkusCodestartProjectInputBuilder addExtensions(Collection<AppArtifactCoords> extensions) {
public QuarkusCodestartProjectInputBuilder addExtensions(Collection<ArtifactCoords> extensions) {
this.extensions.addAll(extensions);
super.addDependencies(extensions.stream().map(Extensions::toGAV).collect(Collectors.toList()));
return this;
}

public QuarkusCodestartProjectInputBuilder addExtension(AppArtifactCoords extension) {
public QuarkusCodestartProjectInputBuilder addExtension(ArtifactCoords extension) {
return this.addExtensions(Collections.singletonList(extension));
}

public QuarkusCodestartProjectInputBuilder addExtension(AppArtifactKey extension) {
public QuarkusCodestartProjectInputBuilder addExtension(ArtifactKey extension) {
return this.addExtension(Extensions.toCoords(extension, null));
}

Expand Down
Loading

0 comments on commit c2b3d59

Please sign in to comment.