Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init custom gradle tooling model #10459

Merged
merged 1 commit into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4290,6 +4290,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.WorkspaceModule;
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,70 @@ 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);
final WorkspaceModule launchingModule = quarkusModel.getWorkspace().getMainModule();
DevModeContext.ModuleInfo root = toModule(quarkusModel.getWorkspace().getMainModule());
devModeContext.setApplicationRoot(root);
for (WorkspaceModule additionalModule : quarkusModel.getWorkspace().getAllModules()) {
if (!additionalModule.getArtifactCoords().equals(launchingModule.getArtifactCoords())) {
devModeContext.getAdditionalModules().add(toModule(additionalModule));
}
}
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(WorkspaceModule module) throws BootstrapGradleException {
AppArtifactKey key = new AppArtifactKey(module.getArtifactCoords().getGroupId(),
module.getArtifactCoords().getArtifactId(), module.getArtifactCoords().getClassifier());

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

return new DevModeContext.ModuleInfo(key,
module.getArtifactCoords().getArtifactId(),
module.getProjectRoot().getPath(),
sourceDirectories,
QuarkusModelHelper.getClassPath(module).toAbsolutePath().toString(),
module.getSourceSourceSet().getResourceDirectory().toString(),
module.getSourceSet().getResourceDirectory().getPath(),
sourceParents,
module.getBuildDir().toPath().resolve("generated-sources").toAbsolutePath().toString(),
module.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