Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
aloubyansky committed Jan 29, 2024
1 parent e4f7ca3 commit d3a936a
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,27 @@ protected QuarkusBootstrap.Builder initBootstrapBuilder() throws Exception {
.setAppModelResolver(resolver)
.setTest(isBootstrapForTestMode());

if (createWorkspace()) {
if (createWorkspace() || !wsModules.isEmpty()) {
System.setProperty("basedir", ws.toAbsolutePath().toString());
final Model appPom = appJar.getPomModel();

final List<Dependency> bomModules = (appPom.getDependencyManagement() == null ? List.<Dependency> of()
: appPom.getDependencyManagement().getDependencies()).stream()
.filter(d -> "import".equals(d.getScope())
&& d.getGroupId().equals(appPom.getGroupId()))
.collect(Collectors.toList());

final List<Dependency> depModules = appPom.getDependencies().stream()
.filter(d -> d.getGroupId().equals(appPom.getGroupId()) &&
(d.getType().isEmpty() || ArtifactCoords.TYPE_JAR.equals(d.getType())))
.collect(Collectors.toList());
List<Dependency> bomModules = List.of();
List<Dependency> depModules = List.of();
if (createWorkspace()) {
bomModules = (appPom.getDependencyManagement() == null ? List.<Dependency> of()
: appPom.getDependencyManagement().getDependencies()).stream()
.filter(d -> "import".equals(d.getScope())
&& d.getGroupId().equals(appPom.getGroupId()))
.collect(Collectors.toList());
depModules = appPom.getDependencies().stream()
.filter(d -> d.getGroupId().equals(appPom.getGroupId()) &&
(d.getType().isEmpty() || ArtifactCoords.TYPE_JAR.equals(d.getType())))
.collect(Collectors.toList());
}

final Path appModule;
final Path appPomXml;
if (depModules.isEmpty() && bomModules.isEmpty() || appPom.getParent() != null) {
if (depModules.isEmpty() && bomModules.isEmpty() && wsModules.isEmpty() || appPom.getParent() != null) {
appModule = ws;
appPomXml = ws.resolve("pom.xml");
ModelUtils.persistModel(appPomXml, appPom);
Expand Down Expand Up @@ -130,31 +133,32 @@ protected QuarkusBootstrap.Builder initBootstrapBuilder() throws Exception {
ModelUtils.persistModel(appPomXml, appPom);

// dependency modules
final Map<ArtifactKey, String> managedVersions = new HashMap<>();
collectManagedDeps(appPom, managedVersions);
for (Dependency moduleDep : depModules) {
parentPom.getModules().add(moduleDep.getArtifactId());
final String moduleVersion = moduleDep.getVersion() == null
? managedVersions.get(ArtifactKey.of(moduleDep.getGroupId(), moduleDep.getArtifactId(),
moduleDep.getClassifier(), moduleDep.getType()))
: moduleDep.getVersion();
Model modulePom = ModelUtils.readModel(resolver
.resolve(ArtifactCoords.pom(moduleDep.getGroupId(), moduleDep.getArtifactId(), moduleVersion))
.getResolvedPaths().getSinglePath());
modulePom.setParent(parent);
final Path moduleDir = IoUtils.mkdirs(ws.resolve(modulePom.getArtifactId()));
ModelUtils.persistModel(moduleDir.resolve("pom.xml"), modulePom);
final Path resolvedJar = resolver
.resolve(ArtifactCoords.of(modulePom.getGroupId(), modulePom.getArtifactId(),
moduleDep.getClassifier(), moduleDep.getType(), modulePom.getVersion()))
.getResolvedPaths()
.getSinglePath();
final Path moduleTargetDir = moduleDir.resolve("target");
ZipUtils.unzip(resolvedJar, moduleTargetDir.resolve("classes"));
IoUtils.copy(resolvedJar,
moduleTargetDir.resolve(modulePom.getArtifactId() + "-" + modulePom.getVersion() + ".jar"));
if (!depModules.isEmpty()) {
final Map<ArtifactKey, String> managedVersions = new HashMap<>();
collectManagedDeps(appPom, managedVersions);
for (Dependency moduleDep : depModules) {
parentPom.getModules().add(moduleDep.getArtifactId());
final String moduleVersion = moduleDep.getVersion() == null
? managedVersions.get(ArtifactKey.of(moduleDep.getGroupId(), moduleDep.getArtifactId(),
moduleDep.getClassifier(), moduleDep.getType()))
: moduleDep.getVersion();
Model modulePom = ModelUtils.readModel(resolver
.resolve(ArtifactCoords.pom(moduleDep.getGroupId(), moduleDep.getArtifactId(), moduleVersion))
.getResolvedPaths().getSinglePath());
modulePom.setParent(parent);
final Path moduleDir = IoUtils.mkdirs(ws.resolve(modulePom.getArtifactId()));
ModelUtils.persistModel(moduleDir.resolve("pom.xml"), modulePom);
final Path resolvedJar = resolver
.resolve(ArtifactCoords.of(modulePom.getGroupId(), modulePom.getArtifactId(),
moduleDep.getClassifier(), moduleDep.getType(), modulePom.getVersion()))
.getResolvedPaths()
.getSinglePath();
final Path moduleTargetDir = moduleDir.resolve("target");
ZipUtils.unzip(resolvedJar, moduleTargetDir.resolve("classes"));
IoUtils.copy(resolvedJar,
moduleTargetDir.resolve(modulePom.getArtifactId() + "-" + modulePom.getVersion() + ".jar"));
}
}

for (TsArtifact module : wsModules) {
parentPom.getModules().add(module.getArtifactId());
Model modulePom = module.getPomModel();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package io.quarkus.deployment.runnerjar;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Set;
import java.util.stream.Collectors;

import org.eclipse.aether.util.artifact.JavaScopes;

import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.bootstrap.resolver.TsArtifact;
import io.quarkus.bootstrap.resolver.TsQuarkusExt;
import io.quarkus.bootstrap.workspace.WorkspaceModule;
import io.quarkus.bootstrap.workspace.WorkspaceModuleId;
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.maven.dependency.ArtifactDependency;
import io.quarkus.maven.dependency.Dependency;
import io.quarkus.maven.dependency.DependencyFlags;

public class ReloadableFlagsTest extends BootstrapFromOriginalJarTestBase {

@Override
protected TsArtifact composeApplication() {

System.setProperty("parallel", "true");

var transitive = TsArtifact.jar("acme-transitive");
addWorkspaceModule(transitive);
addToExpectedLib(transitive);

var common = TsArtifact.jar("acme-common");
common.addDependency(transitive);
addWorkspaceModule(common);
addToExpectedLib(common);

var lib = TsArtifact.jar("acme-lib");
lib.addDependency(common);
addWorkspaceModule(lib);
addToExpectedLib(lib);

var externalLib = TsArtifact.jar("external-lib");
externalLib.addDependency(common);
addToExpectedLib(externalLib);

var myExt = new TsQuarkusExt("my-ext");
addToExpectedLib(myExt.getRuntime());

return TsArtifact.jar("app")
.addManagedDependency(platformDescriptor())
.addManagedDependency(platformProperties())
.addDependency(common)
.addDependency(lib)
.addDependency(externalLib)
.addDependency(myExt);
}

@Override
protected void assertAppModel(ApplicationModel model) {
assertThat(model.getWorkspaceModules().stream().map(WorkspaceModule::getId).collect(Collectors.toSet()))
.isEqualTo(Set.of(
WorkspaceModuleId.of(TsArtifact.DEFAULT_GROUP_ID, "acme-transitive", TsArtifact.DEFAULT_VERSION),
WorkspaceModuleId.of(TsArtifact.DEFAULT_GROUP_ID, "acme-common", TsArtifact.DEFAULT_VERSION),
WorkspaceModuleId.of(TsArtifact.DEFAULT_GROUP_ID, "acme-lib", TsArtifact.DEFAULT_VERSION),
WorkspaceModuleId.of(TsArtifact.DEFAULT_GROUP_ID, "app", TsArtifact.DEFAULT_VERSION)));

final Set<Dependency> expected = Set.of(
new ArtifactDependency(ArtifactCoords.jar("io.quarkus.bootstrap.test", "acme-lib", "1"), JavaScopes.COMPILE,
DependencyFlags.RUNTIME_CP, DependencyFlags.DEPLOYMENT_CP, DependencyFlags.DIRECT,
DependencyFlags.RELOADABLE, DependencyFlags.WORKSPACE_MODULE));

assertThat(getDependenciesWithFlag(model, DependencyFlags.RELOADABLE)).isEqualTo(expected);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.quarkus.maven.dependency;

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

import io.quarkus.bootstrap.workspace.WorkspaceModule;
import io.quarkus.paths.PathCollection;
Expand All @@ -15,6 +17,7 @@ public static ResolvedDependencyBuilder newInstance() {
PathCollection resolvedPaths;
WorkspaceModule workspaceModule;
private volatile ArtifactCoords coords;
private Collection<ArtifactKey> deps = List.of();

public PathCollection getResolvedPaths() {
return resolvedPaths;
Expand Down Expand Up @@ -46,6 +49,15 @@ public ArtifactCoords getArtifactCoords() {
return coords == null ? coords = ArtifactCoords.of(groupId, artifactId, classifier, type, version) : coords;
}

public Collection<ArtifactKey> getDependencies() {
return deps;
}

public ResolvedDependencyBuilder setDependencies(Collection<ArtifactKey> deps) {
this.deps = deps;
return this;
}

@Override
public ResolvedDependency build() {
return new ResolvedArtifactDependency(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ private ApplicationModel buildAppModel(ResolvedDependency appArtifact,
}
directDeps = filtered;
}
var parallel = true;// Boolean.getBoolean("parallel");
var parallel = true; //Boolean.getBoolean("parallel");
var collectRtDepsRequest = MavenArtifactResolver.newCollectRequest(artifact, directDeps, managedDeps, List.of(), repos);
try {
if (parallel) {
Expand Down
Loading

0 comments on commit d3a936a

Please sign in to comment.