Skip to content

Commit

Permalink
init custom gradle tooling model
Browse files Browse the repository at this point in the history
  • Loading branch information
glefloch committed Jul 21, 2020
1 parent 29cc50b commit 4503657
Show file tree
Hide file tree
Showing 48 changed files with 1,439 additions and 354 deletions.
21 changes: 6 additions & 15 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
<webjars-locator-core.version>0.46</webjars-locator-core.version>
<log4j2-jboss-logmanager.version>1.0.0.Beta1</log4j2-jboss-logmanager.version>
<avro.version>1.10.0</avro.version>
<gradle-tooling.version>6.5</gradle-tooling.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -805,16 +806,6 @@
<artifactId>quarkus-kafka-streams-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-avro</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-avro-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-health</artifactId>
Expand Down Expand Up @@ -2662,11 +2653,6 @@
<artifactId>kafka-clients</artifactId>
<version>${kafka2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>${avro.version}</version>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
Expand Down Expand Up @@ -4243,6 +4229,11 @@
<artifactId>quarkus-bootstrap-maven-resolver</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-gradle-resolver</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package io.quarkus.deployment.dev;

import java.io.File;
import java.nio.file.Path;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;

import org.jboss.logging.Logger;

import io.quarkus.bootstrap.BootstrapGradleException;
import io.quarkus.bootstrap.app.CuratedApplication;
import io.quarkus.bootstrap.model.AppArtifactKey;
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenException;
import io.quarkus.bootstrap.resolver.AppModelResolverException;
import io.quarkus.bootstrap.resolver.QuarkusGradleModelFactory;
import io.quarkus.bootstrap.resolver.maven.workspace.LocalProject;
import io.quarkus.bootstrap.resolver.model.QuarkusModel;
import io.quarkus.bootstrap.resolver.model.Workspace;
import io.quarkus.bootstrap.util.QuarkusModelHelper;
import io.quarkus.bootstrap.utils.BuildToolHelper;

@SuppressWarnings("unused")
public class IDEDevModeMain implements BiConsumer<CuratedApplication, Map<String, Object>> {
Expand All @@ -23,30 +32,67 @@ public void accept(CuratedApplication curatedApplication, Map<String, Object> st
DevModeContext devModeContext = new DevModeContext();
devModeContext.setArgs((String[]) stringObjectMap.get("args"));
try {
LocalProject project = LocalProject.loadWorkspace(appClasses);
DevModeContext.ModuleInfo root = toModule(project);
devModeContext.setApplicationRoot(root);
for (Map.Entry<AppArtifactKey, LocalProject> module : project.getWorkspace().getProjects().entrySet()) {
if (module.getKey().equals(project.getKey())) {
continue;
if (BuildToolHelper.isMavenProject(appClasses)) {
LocalProject project = LocalProject.loadWorkspace(appClasses);
DevModeContext.ModuleInfo root = toModule(project);
devModeContext.setApplicationRoot(root);
for (Map.Entry<AppArtifactKey, LocalProject> module : project.getWorkspace().getProjects().entrySet()) {
if (module.getKey().equals(project.getKey())) {
continue;
}
devModeContext.getAdditionalModules().add(toModule(module.getValue()));
}
} else {
// TODO find a way to reuse the previously model instead of building a new one.
QuarkusModel quarkusModel = QuarkusGradleModelFactory.createForTasks(
BuildToolHelper.getBuildFile(appClasses, BuildToolHelper.BuildTool.GRADLE).toFile(),
QuarkusModelHelper.DEVMODE_REQUIRED_TASKS);
DevModeContext.ModuleInfo root = toModule(quarkusModel.getWorkspace());
devModeContext.setApplicationRoot(root);
for (Workspace additionalWorkspace : quarkusModel.getAdditionalWorkspace()) {
devModeContext.getAdditionalModules().add(toModule(additionalWorkspace));
}
devModeContext.getAdditionalModules().add(toModule(module.getValue()));
}
} catch (BootstrapMavenException e) {

} catch (AppModelResolverException e) {
log.error("Failed to load workspace, hot reload will not be available", e);
}

new IsolatedDevModeMain().accept(curatedApplication,
Collections.singletonMap(DevModeContext.class.getName(), devModeContext));
}

private DevModeContext.ModuleInfo toModule(Workspace model) throws BootstrapGradleException {
AppArtifactKey key = new AppArtifactKey(model.getArtifactCoords().getGroupId(),
model.getArtifactCoords().getArtifactId(), model.getArtifactCoords().getClassifier());

Set<String> sourceDirectories = new HashSet<>();
Set<String> sourceParents = new HashSet<>();
for (File srcDir : model.getSourceSourceSet().getSourceDirectories()) {
sourceDirectories.add(srcDir.getPath());
sourceParents.add(srcDir.getParent());
}

return new DevModeContext.ModuleInfo(key,
model.getArtifactCoords().getArtifactId(),
model.getProjectRoot().getPath(),
sourceDirectories,
QuarkusModelHelper.getClassPath(model).toAbsolutePath().toString(),
model.getSourceSourceSet().getResourceDirectory().toString(),
model.getSourceSet().getResourceDirectory().getPath(),
sourceParents,
model.getBuildDir().toPath().resolve("generated-sources").toAbsolutePath().toString(),
model.getBuildDir().toString());
}

private DevModeContext.ModuleInfo toModule(LocalProject project) {
return new DevModeContext.ModuleInfo(project.getKey(), project.getArtifactId(),
project.getDir().toAbsolutePath().toString(),
Collections.singleton(project.getSourcesSourcesDir().toAbsolutePath().toString()),
project.getClassesDir().toAbsolutePath().toString(),
project.getResourcesSourcesDir().toAbsolutePath().toString(),
project.getSourcesDir().toString(), project.getCodeGenOutputDir().toString(),
project.getSourcesDir().toString(),
project.getCodeGenOutputDir().toString(),
project.getOutputDir().toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.Map;
import java.util.function.Consumer;

import io.quarkus.bootstrap.BootstrapConstants;

/**
* IDE entry point.
* <p>
Expand All @@ -24,7 +26,6 @@
public class QuarkusLauncher {

public static void launch(String callingClass, String quarkusApplication, Consumer<Integer> exitHandler, String... args) {

try {
String classResource = callingClass.replace(".", "/") + ".class";
URL resource = Thread.currentThread().getContextClassLoader().getResource(classResource);
Expand All @@ -43,11 +44,14 @@ public static void launch(String callingClass, String quarkusApplication, Consum

IDEClassLoader loader = new IDEClassLoader(QuarkusLauncher.class.getClassLoader());
Thread.currentThread().setContextClassLoader(loader);

Class<?> launcher = loader.loadClass("io.quarkus.bootstrap.IDELauncherImpl");
launcher.getDeclaredMethod("launch", Path.class, Map.class).invoke(null, appClasses, context);

} catch (Exception e) {
throw new RuntimeException(e);
} finally {
System.clearProperty(BootstrapConstants.SERIALIZED_APP_MODEL);
}
}

Expand Down
Loading

0 comments on commit 4503657

Please sign in to comment.