Skip to content

Commit

Permalink
Revert "Remove deprecated classes from app-model"
Browse files Browse the repository at this point in the history
This reverts commit 700f48d.
  • Loading branch information
gastaldi committed Jul 22, 2024
1 parent 65e7336 commit 515c232
Show file tree
Hide file tree
Showing 10 changed files with 674 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.jboss.jandex.IndexView;

import io.quarkus.bootstrap.model.AppArtifactKey;
import io.quarkus.bootstrap.model.PathsCollection;
import io.quarkus.maven.dependency.ArtifactKey;
import io.quarkus.maven.dependency.ResolvedDependency;
Expand Down Expand Up @@ -71,6 +72,12 @@ public interface ApplicationArchive {
*/
PathCollection getResolvedPaths();

/**
* @deprecated in favor of {@link #getKey()}
* @return the artifact key or null if not available
*/
AppArtifactKey getArtifactKey();

/**
*
* @return the artifact key or null if not available
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.jboss.jandex.IndexView;

import io.quarkus.bootstrap.model.AppArtifactKey;
import io.quarkus.bootstrap.model.PathsCollection;
import io.quarkus.builder.item.MultiBuildItem;
import io.quarkus.maven.dependency.ArtifactKey;
Expand Down Expand Up @@ -61,6 +62,21 @@ public PathCollection getResolvedPaths() {
return PathList.from(openTree.getOriginalTree().getRoots());
}

@Override
@Deprecated
/**
* @deprecated in favor of {@link #getKey()}
* @return archive key
*/
public AppArtifactKey getArtifactKey() {
if (resolvedDependency == null) {
return null;
}
ArtifactKey artifactKey = resolvedDependency.getKey();
return new AppArtifactKey(artifactKey.getGroupId(), artifactKey.getArtifactId(), artifactKey.getClassifier(),
artifactKey.getType());
}

@Override
public ArtifactKey getKey() {
return resolvedDependency != null ? resolvedDependency.getKey() : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;

Expand All @@ -37,13 +36,14 @@
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import io.quarkus.bootstrap.BootstrapConstants;
import io.quarkus.bootstrap.model.AppArtifactCoords;
import io.quarkus.bootstrap.model.AppArtifactKey;
import io.quarkus.bootstrap.model.ApplicationModelBuilder;
import io.quarkus.devtools.project.extensions.ScmInfoProvider;
import io.quarkus.extension.gradle.QuarkusExtensionConfiguration;
import io.quarkus.extension.gradle.dsl.Capability;
import io.quarkus.extension.gradle.dsl.RemovedResource;
import io.quarkus.fs.util.ZipUtils;
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.maven.dependency.ArtifactKey;
import io.quarkus.maven.dependency.GACT;

Expand Down Expand Up @@ -113,9 +113,9 @@ private void generateQuarkusExtensionProperties(Path metaInfDir) {
if (conditionalDependencies != null && !conditionalDependencies.isEmpty()) {
final StringBuilder buf = new StringBuilder();
int i = 0;
buf.append(ArtifactCoords.fromString(conditionalDependencies.get(i++)));
buf.append(AppArtifactCoords.fromString(conditionalDependencies.get(i++)).toString());
while (i < conditionalDependencies.size()) {
buf.append(' ').append(ArtifactCoords.fromString(conditionalDependencies.get(i++)));
buf.append(' ').append(AppArtifactCoords.fromString(conditionalDependencies.get(i++)).toString());
}
props.setProperty(BootstrapConstants.CONDITIONAL_DEPENDENCIES, buf.toString());
}
Expand Down Expand Up @@ -315,7 +315,7 @@ private void computeArtifactCoords(ObjectNode extObject) {
}
}
if (artifactNode == null || groupId == null || artifactId == null || version == null) {
final ArtifactCoords coords = ArtifactCoords.of(
final AppArtifactCoords coords = new AppArtifactCoords(
groupId == null ? projectInfo.get("group") : groupId,
artifactId == null ? projectInfo.get("name") : artifactId,
null,
Expand Down Expand Up @@ -363,7 +363,7 @@ private void computeQuarkusExtensions(ObjectNode extObject) {
ObjectNode metadataNode = getMetadataNode(extObject);
Set<ResolvedArtifact> extensions = new HashSet<>();
for (ResolvedArtifact resolvedArtifact : getClasspath().getResolvedConfiguration().getResolvedArtifacts()) {
if (Objects.equals(resolvedArtifact.getExtension(), "jar")) {
if (resolvedArtifact.getExtension().equals("jar")) {
Path p = resolvedArtifact.getFile().toPath();
if (Files.isDirectory(p) && isExtension(p)) {
extensions.add(resolvedArtifact);
Expand All @@ -382,7 +382,7 @@ private void computeQuarkusExtensions(ObjectNode extObject) {
for (ResolvedArtifact extension : extensions) {
ModuleVersionIdentifier id = extension.getModuleVersion().getId();
extensionArray
.add(ArtifactKey.of(id.getGroup(), id.getName(), extension.getClassifier(), extension.getExtension())
.add(new AppArtifactKey(id.getGroup(), id.getName(), extension.getClassifier(), extension.getExtension())
.toGacString());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.TaskAction;

import io.quarkus.bootstrap.model.AppArtifactKey;
import io.quarkus.extension.gradle.QuarkusExtensionConfiguration;
import io.quarkus.gradle.tooling.dependency.ArtifactExtensionDependency;
import io.quarkus.gradle.tooling.dependency.DependencyUtils;
import io.quarkus.gradle.tooling.dependency.ExtensionDependency;
import io.quarkus.gradle.tooling.dependency.ProjectExtensionDependency;
import io.quarkus.maven.dependency.ArtifactKey;

public class ValidateExtensionTask extends DefaultTask {

Expand Down Expand Up @@ -59,12 +59,12 @@ public void setDeploymentModuleClasspath(Configuration deploymentModuleClasspath
public void validateExtension() {
Set<ResolvedArtifact> runtimeArtifacts = getRuntimeModuleClasspath().getResolvedConfiguration().getResolvedArtifacts();

List<ArtifactKey> deploymentModuleKeys = collectRuntimeExtensionsDeploymentKeys(runtimeArtifacts);
List<ArtifactKey> invalidRuntimeArtifacts = findExtensionInConfiguration(runtimeArtifacts, deploymentModuleKeys);
List<AppArtifactKey> deploymentModuleKeys = collectRuntimeExtensionsDeploymentKeys(runtimeArtifacts);
List<AppArtifactKey> invalidRuntimeArtifacts = findExtensionInConfiguration(runtimeArtifacts, deploymentModuleKeys);

Set<ResolvedArtifact> deploymentArtifacts = getDeploymentModuleClasspath().getResolvedConfiguration()
.getResolvedArtifacts();
List<ArtifactKey> existingDeploymentModuleKeys = findExtensionInConfiguration(deploymentArtifacts,
List<AppArtifactKey> existingDeploymentModuleKeys = findExtensionInConfiguration(deploymentArtifacts,
deploymentModuleKeys);
deploymentModuleKeys.removeAll(existingDeploymentModuleKeys);

Expand All @@ -81,60 +81,64 @@ public void validateExtension() {
}
}

private List<ArtifactKey> collectRuntimeExtensionsDeploymentKeys(Set<ResolvedArtifact> runtimeArtifacts) {
List<ArtifactKey> runtimeExtensions = new ArrayList<>();
private List<AppArtifactKey> collectRuntimeExtensionsDeploymentKeys(Set<ResolvedArtifact> runtimeArtifacts) {
List<AppArtifactKey> runtimeExtensions = new ArrayList<>();
for (ResolvedArtifact resolvedArtifact : runtimeArtifacts) {
ExtensionDependency<?> extension = DependencyUtils.getExtensionInfoOrNull(getProject(), resolvedArtifact);
if (extension != null) {
if (extension instanceof ProjectExtensionDependency ped) {
if (extension instanceof ProjectExtensionDependency) {
final ProjectExtensionDependency ped = (ProjectExtensionDependency) extension;

runtimeExtensions
.add(ArtifactKey.ga(ped.getDeploymentModule().getGroup().toString(),
.add(new AppArtifactKey(ped.getDeploymentModule().getGroup().toString(),
ped.getDeploymentModule().getName()));
} else if (extension instanceof ArtifactExtensionDependency aed) {
runtimeExtensions.add(ArtifactKey.ga(aed.getDeploymentModule().getGroupId(),
} else if (extension instanceof ArtifactExtensionDependency) {
final ArtifactExtensionDependency aed = (ArtifactExtensionDependency) extension;

runtimeExtensions.add(new AppArtifactKey(aed.getDeploymentModule().getGroupId(),
aed.getDeploymentModule().getArtifactId()));
}
}
}
return runtimeExtensions;
}

private List<ArtifactKey> findExtensionInConfiguration(Set<ResolvedArtifact> deploymentArtifacts,
List<ArtifactKey> extensions) {
List<ArtifactKey> foundExtensions = new ArrayList<>();
private List<AppArtifactKey> findExtensionInConfiguration(Set<ResolvedArtifact> deploymentArtifacts,
List<AppArtifactKey> extensions) {
List<AppArtifactKey> foundExtensions = new ArrayList<>();

for (ResolvedArtifact deploymentArtifact : deploymentArtifacts) {
ArtifactKey key = toArtifactKey(deploymentArtifact.getModuleVersion());
AppArtifactKey key = toAppArtifactKey(deploymentArtifact.getModuleVersion());
if (extensions.contains(key)) {
foundExtensions.add(key);
}
}
return foundExtensions;
}

private void printValidationErrors(List<ArtifactKey> invalidRuntimeArtifacts,
List<ArtifactKey> missingDeploymentArtifacts) {
private void printValidationErrors(List<AppArtifactKey> invalidRuntimeArtifacts,
List<AppArtifactKey> missingDeploymentArtifacts) {
Logger log = getLogger();
log.error("Quarkus Extension Dependency Verification Error");

if (!invalidRuntimeArtifacts.isEmpty()) {
log.error("The following deployment artifact(s) appear on the runtime classpath: ");
for (ArtifactKey invalidRuntimeArtifact : invalidRuntimeArtifacts) {
for (AppArtifactKey invalidRuntimeArtifact : invalidRuntimeArtifacts) {
log.error("- " + invalidRuntimeArtifact);
}
}

if (!missingDeploymentArtifacts.isEmpty()) {
log.error("The following deployment artifact(s) were found to be missing in the deployment module: ");
for (ArtifactKey missingDeploymentArtifact : missingDeploymentArtifacts) {
for (AppArtifactKey missingDeploymentArtifact : missingDeploymentArtifacts) {
log.error("- " + missingDeploymentArtifact);
}
}

throw new GradleException("Quarkus Extension Dependency Verification Error. See logs below");
}

private static ArtifactKey toArtifactKey(ResolvedModuleVersion artifactId) {
return ArtifactKey.ga(artifactId.getId().getGroup(), artifactId.getId().getName());
private static AppArtifactKey toAppArtifactKey(ResolvedModuleVersion artifactId) {
return new AppArtifactKey(artifactId.getId().getGroup(), artifactId.getId().getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package io.quarkus.bootstrap.model;

import java.io.Serializable;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;

import io.quarkus.bootstrap.workspace.WorkspaceModule;
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.maven.dependency.ResolvedDependency;
import io.quarkus.paths.PathCollection;
import io.quarkus.paths.PathList;

/**
* Represents an application (or its dependency) artifact.
*
* @deprecated in favor of {@link ResolvedDependency} and {@link io.quarkus.maven.dependency.Dependency}.
*
* @author Alexey Loubyansky
*/
@Deprecated(forRemoval = true, since = "3.11.0")
public class AppArtifact extends AppArtifactCoords implements ResolvedDependency, Serializable {

private static final long serialVersionUID = -6226544163467103712L;

protected PathsCollection paths;
private final WorkspaceModule module;
private final String scope;
private final int flags;

public AppArtifact(AppArtifactCoords coords) {
this(coords, null);
}

public AppArtifact(AppArtifactCoords coords, WorkspaceModule module) {
this(coords.getGroupId(), coords.getArtifactId(), coords.getClassifier(), coords.getType(), coords.getVersion(),
module, "compile", 0);
}

public AppArtifact(String groupId, String artifactId, String version) {
super(groupId, artifactId, version);
module = null;
scope = "compile";
flags = 0;
}

public AppArtifact(String groupId, String artifactId, String classifier, String type, String version) {
super(groupId, artifactId, classifier, type, version);
module = null;
scope = "compile";
flags = 0;
}

public AppArtifact(String groupId, String artifactId, String classifier, String type, String version,
WorkspaceModule module, String scope, int flags) {
super(groupId, artifactId, classifier, type, version);
this.module = module;
this.scope = scope;
this.flags = flags;
}

/**
* @deprecated in favor of {@link #getResolvedPaths()}
*/
@Deprecated
public Path getPath() {
return paths.getSinglePath();
}

/**
* Associates the artifact with the given path
*
* @param path artifact location
*/
public void setPath(Path path) {
setPaths(PathsCollection.of(path));
}

/**
* Collection of the paths that collectively constitute the artifact's content.
* Normally, especially in the Maven world, an artifact is resolved to a single path,
* e.g. a JAR or a project's output directory. However, in Gradle, depending on the build/test phase,
* artifact's content may need to be represented as a collection of paths.
*
* @return collection of paths that constitute the artifact's content
*/
public PathsCollection getPaths() {
return paths;
}

/**
* Associates the artifact with a collection of paths that constitute its content.
*
* @param paths collection of paths that constitute the artifact's content.
*/
public void setPaths(PathsCollection paths) {
this.paths = paths;
}

/**
* Whether the artifact has been resolved, i.e. associated with paths
* that constitute its content.
*
* @return true if the artifact has been resolved, otherwise - false
*/
@Override
public boolean isResolved() {
return paths != null && !paths.isEmpty();
}

@Override
public PathCollection getResolvedPaths() {
return paths == null ? null : PathList.from(paths);
}

@Override
public WorkspaceModule getWorkspaceModule() {
return module;
}

@Override
public String getScope() {
return scope;
}

@Override
public int getFlags() {
return flags;
}

@Override
public Collection<ArtifactCoords> getDependencies() {
return List.of();
}
}
Loading

0 comments on commit 515c232

Please sign in to comment.