Skip to content

Commit

Permalink
let's test the first iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
cdsap committed Oct 26, 2024
1 parent e81fa0c commit aaa8a89
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,11 @@ private static void configureApplicationModelTask(Project project, QuarkusApplic
task.getLaunchMode().set(launchMode);
task.getOriginalClasspath().setFrom(classpath.getOriginalRuntimeClasspathAsInput());
task.getAppClasspath().configureFrom(classpath.getRuntimeConfigurationWithoutResolvingDeployment());
task.getPlatformConfiguration().configureFrom(classpath.getPlatformConfiguration());
task.getDeploymentClasspath().configureFrom(classpath.getDeploymentConfiguration());
task.getDeploymentResolvedWorkaround().from(classpath.getDeploymentConfiguration().getIncoming().getFiles());
task.getPlatformImportProperties().set(classpath.getPlatformImportsWithoutResolvingPlatform().getPlatformProperties());
task.getPlatformConfiguration().configureFrom(classpath.getPlatformConfiguration());
task.getOriginalC().from(classpath.getPlatformConfiguration());
task.getPlatformImportProperties().set(classpath.getPlatformImportsWithoutResolvingPlatform2().getPlatformProperties());
task.getPlatformImport2().set(classpath.getPlatformImportsWithoutResolvingPlatform());
task.getApplicationModel().set(project.getLayout().getBuildDirectory().file(quarkusModelFile));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,17 @@
import static io.quarkus.maven.dependency.ArtifactCoords.DEFAULT_CLASSIFIER;
import static java.util.stream.Collectors.toList;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.io.UncheckedIOException;
import java.io.*;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import javax.inject.Inject;

import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.artifacts.ArtifactCollection;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ModuleVersionIdentifier;
Expand All @@ -46,22 +34,12 @@
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.CompileClasspath;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.Nested;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.*;

import com.google.common.base.Preconditions;

import io.quarkus.bootstrap.BootstrapConstants;
import io.quarkus.bootstrap.model.ApplicationModelBuilder;
import io.quarkus.bootstrap.model.CapabilityContract;
import io.quarkus.bootstrap.model.PlatformImportsImpl;
import io.quarkus.bootstrap.resolver.AppModelResolverException;
import io.quarkus.bootstrap.model.*;
import io.quarkus.bootstrap.workspace.ArtifactSources;
import io.quarkus.bootstrap.workspace.DefaultArtifactSources;
import io.quarkus.bootstrap.workspace.DefaultSourceDir;
Expand Down Expand Up @@ -109,7 +87,7 @@ public abstract class QuarkusApplicationModelTask extends DefaultTask {
public abstract ConfigurableFileCollection getOriginalClasspath();

@InputFiles
public abstract ConfigurableFileCollection getDeploymentResolvedWorkaround();
public abstract ConfigurableFileCollection getOriginalC();

@Nested
public abstract QuarkusResolvedClasspath getPlatformConfiguration();
Expand All @@ -123,7 +101,10 @@ public abstract class QuarkusApplicationModelTask extends DefaultTask {
@Input
public abstract Property<LaunchMode> getLaunchMode();

@Input
@Internal
public abstract Property<PlatformImports> getPlatformImport2();

@Internal
public abstract MapProperty<String, String> getPlatformImportProperties();

/**
Expand All @@ -139,43 +120,27 @@ public QuarkusApplicationModelTask() {
getProjectBuildFile().set(getProject().getBuildFile());
}

private void collectPlatforms(ResolvedDependencyResult resolvedDependency,
Map<ComponentIdentifier, List<QuarkusResolvedArtifact>> artifactsByCapability,
PlatformImportsImpl platformImports) {
List<QuarkusResolvedArtifact> artifacts = findArtifacts(resolvedDependency, artifactsByCapability);
ModuleVersionIdentifier moduleVersionIdentifier = resolvedDependency.getSelected().getModuleVersion();
for (QuarkusResolvedArtifact artifact : artifacts) {
if (artifact != null && artifact.file.getName().endsWith(".properties")) {
try {
platformImports.addPlatformProperties(moduleVersionIdentifier.getGroup(), moduleVersionIdentifier.getName(),
null, "properties", moduleVersionIdentifier.getVersion(), artifact.file.toPath());
} catch (AppModelResolverException e) {
throw new GradleException("Failed to import platform properties " + artifact.file, e);
}
} else if (artifact != null && artifact.file.getName().endsWith(".json")) {
platformImports.addPlatformDescriptor(moduleVersionIdentifier.getGroup(), moduleVersionIdentifier.getName(),
moduleVersionIdentifier.getVersion(), "json", moduleVersionIdentifier.getVersion());
}
}
}

@TaskAction
public void execute() throws IOException {
final ResolvedDependencyBuilder appArtifact = getProjectArtifact();
PlatformImportsImpl platformImports = new PlatformImportsImpl();
platformImports.setPlatformProperties(getPlatformImportProperties().get());
Map<ComponentIdentifier, List<QuarkusResolvedArtifact>> artifactsByCapability = getPlatformConfiguration()
.resolvedArtifactsByComponentIdentifier();
getPlatformConfiguration().getRoot().get().getDependencies().forEach(d -> {
if (d instanceof ResolvedDependencyResult) {
collectPlatforms((ResolvedDependencyResult) d, artifactsByCapability, platformImports);
PlatformImportsImpl x = new PlatformImportsImpl();
x.setPlatformProperties(getPlatformImportProperties().get());
getPlatformImport2().get().getImportedPlatformBoms().stream().forEach(new Consumer<ArtifactCoords>() {
@Override
public void accept(ArtifactCoords artifactCoords) {
x.addPlatformDescriptor(artifactCoords.getGroupId(),
artifactCoords.getArtifactId() + "-quarkus-platform-descriptor", artifactCoords.getVersion(), "json",
artifactCoords.getVersion());
}
});
Map<ComponentIdentifier, List<QuarkusResolvedArtifact>> artifactsByCapability = getPlatformConfiguration()
.resolvedArtifactsByComponentIdentifier();
PlatformImportsImpl platformImports = new PlatformImportsImpl();
platformImports.setPlatformProperties(getPlatformImport2().get().getPlatformProperties());
final ResolvedDependencyBuilder appArtifact = getProjectArtifact();
final ApplicationModelBuilder modelBuilder = new ApplicationModelBuilder()
.setAppArtifact(appArtifact)
.setPlatformImports(platformImports)
.setPlatformImports(x)
.addReloadableWorkspaceModule(appArtifact.getKey());

collectDependencies(getAppClasspath(), modelBuilder, appArtifact.getWorkspaceModule().mutable());
collectExtensionDependencies(getDeploymentClasspath(), modelBuilder);
ToolingUtils.serializeAppModel(modelBuilder.build(), getApplicationModel().get().getAsFile().toPath());
Expand Down Expand Up @@ -241,13 +206,19 @@ private static void collectDependencies(QuarkusResolvedClasspath classpath, Appl
Map<ComponentIdentifier, List<QuarkusResolvedArtifact>> artifacts = classpath.resolvedArtifactsByComponentIdentifier();

Set<File> alreadyCollectedFiles = new HashSet<>(artifacts.size());

Set<ResolvedDependencyResult> directDependencies = classpath.getRoot().get().getDependencies().stream()
.filter(d -> d instanceof ResolvedDependencyResult)
.map(d -> (ResolvedDependencyResult) d)
.collect(Collectors.toSet());
classpath.getRoot().get().getDependencies().forEach(d -> {
if (d instanceof ResolvedDependencyResult) {
byte flags = (byte) (COLLECT_TOP_EXTENSION_RUNTIME_NODES | COLLECT_DIRECT_DEPS | COLLECT_RELOADABLE_MODULES);
collectDependencies((ResolvedDependencyResult) d, modelBuilder, artifacts, wsModule, alreadyCollectedFiles,
new HashSet<>(), flags);
new HashSet<>(), flags, directDependencies);
}
});

Set<File> fileDependencies = new HashSet<>(classpath.getAllResolvedFiles().getFiles());

fileDependencies.removeAll(alreadyCollectedFiles);
Expand Down Expand Up @@ -297,7 +268,9 @@ private static void collectDependencies(
WorkspaceModule.Mutable parentModule,
Set<File> collectedArtifactFiles,
Set<ArtifactKey> processedModules,
byte flags) {
byte flags,
Set<ResolvedDependencyResult> directDependencies) {
Integer b = new Random().nextInt();
WorkspaceModule.Mutable projectModule = null;
List<QuarkusResolvedArtifact> artifacts = findArtifacts(resolvedDependency, resolvedArtifacts);
if (artifacts.isEmpty()) {
Expand All @@ -310,7 +283,8 @@ private static void collectDependencies(
collectDependencies((ResolvedDependencyResult) dependencyResult, modelBuilder, resolvedArtifacts,
projectModule,
collectedArtifactFiles,
processedModules, finalFlags);
processedModules, finalFlags,
directDependencies);
}
}
});
Expand Down Expand Up @@ -368,9 +342,22 @@ private static void collectDependencies(
ModuleVersionIdentifier dependencyId = Preconditions
.checkNotNull(((ResolvedDependencyResult) dependency).getSelected().getModuleVersion());
if (!processedModules.contains(new GACT(dependencyId.getGroup(), dependencyId.getName()))) {
collectDependencies((ResolvedDependencyResult) dependency, modelBuilder, resolvedArtifacts, projectModule,
collectedArtifactFiles,
processedModules, flags);
List<DependencyResult> s = directDependencies.stream()
.filter(d -> d.getSelected().getModuleVersion().getName()
.equals(((ResolvedDependencyResult) dependency).getSelected().getModuleVersion().getName())
&& d.getSelected().getModuleVersion().getGroup().equals(
((ResolvedDependencyResult) dependency).getSelected().getModuleVersion().getGroup())
&& d.getSelected().getModuleVersion().getVersion()
.equals(((ResolvedDependencyResult) dependency).getSelected().getModuleVersion()
.getVersion()))
.collect(Collectors.toList());
if (s.isEmpty()) {
collectDependencies((ResolvedDependencyResult) dependency, modelBuilder, resolvedArtifacts,
projectModule,
collectedArtifactFiles,
processedModules, flags,
directDependencies);
}
}
}
}
Expand Down Expand Up @@ -486,6 +473,9 @@ public static abstract class QuarkusResolvedClasspath {
@Internal
public abstract ConfigurableFileCollection getProjectDescriptors();

@InputFiles
public abstract ConfigurableFileCollection getForcedWorkaroundResolution();

private FileCollection getAllResolvedFiles() {
return getResolvedArtifactCollection().get().getArtifactFiles();
}
Expand All @@ -508,6 +498,7 @@ private QuarkusResolvedArtifact toResolvedArtifact(ResolvedArtifactResult result
}

public void configureFrom(Configuration configuration) {
getForcedWorkaroundResolution().from(configuration.getIncoming().getFiles());
ResolvableDependencies resolvableDependencies = configuration.getIncoming();
getRoot().set(resolvableDependencies.getResolutionResult().getRootComponent());
getResolvedArtifactCollection().set(resolvableDependencies.getArtifacts());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import io.quarkus.gradle.tooling.ToolingUtils;
import io.quarkus.gradle.tooling.dependency.DependencyUtils;
import io.quarkus.gradle.tooling.dependency.ExtensionDependency;
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.runtime.LaunchMode;

public class ApplicationDeploymentClasspathBuilder {
Expand Down Expand Up @@ -175,11 +176,21 @@ private void setUpPlatformConfiguration() {
// Configures PlatformImportsImpl once the platform configuration is resolved
configuration.getResolutionStrategy().eachDependency(d -> {
ModuleIdentifier identifier = d.getTarget().getModule();

final String group = identifier.getGroup();
final String name = identifier.getName();
if (name.endsWith(BootstrapConstants.PLATFORM_DESCRIPTOR_ARTIFACT_ID_SUFFIX)) {
platformImports.addPlatformDescriptor(group, name, d.getTarget().getVersion(), "json",
ArtifactCoords bomCoords = ArtifactCoords.pom(group,
name.substring(0, name.length() - "-quarkus-platform-descriptor".length()),
d.getTarget().getVersion());
List<ArtifactCoords> existingBoms = platformImports.getImportedPlatformBoms().stream()
.filter(cd -> cd.toGACTVString().equals(bomCoords.toGACTVString()))
.collect(Collectors.toList());

if (existingBoms.isEmpty()) {
platformImports.addPlatformDescriptor(group, name, d.getTarget().getVersion(), "json",
d.getTarget().getVersion());
}
} else if (name.endsWith(BootstrapConstants.PLATFORM_PROPERTIES_ARTIFACT_ID_SUFFIX)) {
final DefaultDependencyArtifact dep = new DefaultDependencyArtifact();
dep.setExtension("properties");
Expand Down Expand Up @@ -316,6 +327,10 @@ public PlatformImports getPlatformImportsWithoutResolvingPlatform() {
return platformImports.get(this.platformImportName);
}

public PlatformImportsImpl getPlatformImportsWithoutResolvingPlatform2() {
return platformImports.get(this.platformImportName);
}

private Set<ExtensionDependency<?>> collectFirstMetQuarkusExtensions(Configuration configuration,
Collection<ExtensionDependency<?>> knownExtensions) {

Expand Down

0 comments on commit aaa8a89

Please sign in to comment.