Skip to content

Commit

Permalink
feat: Auto create Quarkus run config while importing project
Browse files Browse the repository at this point in the history
Fixes #1233

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Nov 13, 2023
1 parent 95f8798 commit 122dcb3
Show file tree
Hide file tree
Showing 26 changed files with 620 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import com.intellij.openapi.util.Key;
import com.redhat.devtools.intellij.quarkus.projectWizard.QuarkusExtensionsModel;
import com.redhat.devtools.intellij.quarkus.projectWizard.QuarkusModel;
import com.redhat.devtools.intellij.quarkus.tool.ToolDelegate;
import com.redhat.devtools.intellij.quarkus.buildtool.BuildToolDelegate;

public class QuarkusConstants {
public final static Key<ToolDelegate> WIZARD_TOOL_KEY = Key.create(QuarkusConstants.class.getPackage().getName() + ".tool");
public final static Key<BuildToolDelegate> WIZARD_TOOL_KEY = Key.create(QuarkusConstants.class.getPackage().getName() + ".tool");
public final static Key<Boolean> WIZARD_EXAMPLE_KEY = Key.create(QuarkusConstants.class.getPackage().getName() + ".example");
public final static Key<String> WIZARD_GROUPID_KEY = Key.create(QuarkusConstants.class.getPackage().getName() + ".groupId");
public final static Key<String> WIZARD_ARTIFACTID_KEY = Key.create(QuarkusConstants.class.getPackage().getName() + ".artifactId");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import com.intellij.util.messages.MessageBusConnection;
import com.redhat.devtools.intellij.lsp4mp4ij.classpath.ClasspathResourceChangedManager;
import com.redhat.devtools.intellij.quarkus.search.QuarkusModuleComponent;
import com.redhat.devtools.intellij.quarkus.tool.ToolDelegate;
import com.redhat.devtools.intellij.quarkus.buildtool.BuildToolDelegate;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
Expand Down Expand Up @@ -94,7 +94,7 @@ public static void updateClasspathWithQuarkusDeployment(Module module, ProgressI
return;
LOGGER.info("Ensuring library to " + module.getName());
long start = System.currentTimeMillis();
ToolDelegate toolDelegate = ToolDelegate.getDelegate(module);
BuildToolDelegate toolDelegate = BuildToolDelegate.getDelegate(module);
if (toolDelegate != null) {
LOGGER.info("Tool delegate found for " + module.getName());
if (isQuarkusModule(module)) {
Expand Down Expand Up @@ -190,11 +190,11 @@ private static void addLibrary(ModifiableRootModel model, List<VirtualFile>[] qu
LibraryEx.ModifiableModelEx libraryModel = library.getModifiableModel();

// Add quarkus deployment dependencies binaries
for (VirtualFile rootFile : quarkusDeploymentDependencies[ToolDelegate.BINARY]) {
for (VirtualFile rootFile : quarkusDeploymentDependencies[BuildToolDelegate.BINARY]) {
libraryModel.addRoot(rootFile, OrderRootType.CLASSES);
}
// Add quarkus deployment dependencies sources
for (VirtualFile rootFile : quarkusDeploymentDependencies[ToolDelegate.SOURCES]) {
for (VirtualFile rootFile : quarkusDeploymentDependencies[BuildToolDelegate.SOURCES]) {
libraryModel.addRoot(rootFile, OrderRootType.SOURCES);
}

Expand Down Expand Up @@ -235,7 +235,7 @@ private static boolean isQuarkusDeploymentLibrary(@NotNull LibraryOrderEntry lib
private static boolean isQuarkusExtensionWithDeploymentArtifact(@Nullable Library library) {
if (library != null) {
for (VirtualFile vFile : library.getFiles(OrderRootType.CLASSES)) {
if (vFile.isDirectory() && ToolDelegate.hasExtensionProperties(VfsUtilCore.virtualToIoFile(vFile))) {
if (vFile.isDirectory() && BuildToolDelegate.hasExtensionProperties(VfsUtilCore.virtualToIoFile(vFile))) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,25 @@
package com.redhat.devtools.intellij.quarkus;

import com.intellij.facet.FacetManager;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.DependencyScope;
import com.intellij.openapi.roots.LibraryOrderEntry;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.ModuleRootModificationUtil;
import com.intellij.openapi.roots.OrderEnumerator;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.RootPolicy;
import com.intellij.openapi.roots.impl.OrderEntryUtil;
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.core.ls.PsiUtilsLSImpl;
import com.redhat.devtools.intellij.quarkus.facet.QuarkusFacet;
import com.redhat.devtools.intellij.quarkus.search.QuarkusModuleComponent;
import com.redhat.devtools.intellij.quarkus.tool.ToolDelegate;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
import com.intellij.openapi.startup.StartupActivity;
import com.redhat.devtools.intellij.lsp4mp4ij.classpath.ClasspathResourceChangedManager;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.project.PsiMicroProfileProjectManager;
import com.redhat.devtools.intellij.quarkus.run.QuarkusRunConfigurationManager;
import org.jetbrains.annotations.NotNull;

public class QuarkusPostStartupActivity implements StartupActivity, DumbAware {
@Override
public void runActivity(@NotNull Project project) {
QuarkusRunConfigurationManager.getInstance(project);
ClasspathResourceChangedManager.getInstance(project);
// Force the instantiation of the manager to be sure that classpath listener
// are registered before QuarkusLanguageClient classpath listener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package com.redhat.devtools.intellij.quarkus.tool;
package com.redhat.devtools.intellij.quarkus.buildtool;

import com.intellij.execution.RunnerAndConfigurationSettings;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.messages.MessageBusConnection;
import com.redhat.devtools.intellij.quarkus.run.QuarkusRunConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.maven.model.MavenId;
Expand All @@ -36,7 +38,7 @@
import static com.redhat.devtools.intellij.quarkus.QuarkusConstants.QUARKUS_DEPLOYMENT_PROPERTY_NAME;
import static com.redhat.devtools.intellij.quarkus.QuarkusConstants.QUARKUS_EXTENSION_PROPERTIES;

public interface ToolDelegate {
public interface BuildToolDelegate {

static boolean shouldResolveArtifactTransitively(MavenId deploymentId) {
// The kubernetes support is only available if quarkus-kubernetes artifact is
Expand Down Expand Up @@ -88,8 +90,8 @@ static String getQuarkusExtension(Reader r) throws IOException {
return p.getProperty(QUARKUS_DEPLOYMENT_PROPERTY_NAME);
}

public static ToolDelegate getDelegate(Module module) {
for(ToolDelegate toolDelegate : getDelegates()) {
public static BuildToolDelegate getDelegate(Module module) {
for(BuildToolDelegate toolDelegate : getDelegates()) {
if (toolDelegate.isValid(module)) {
return toolDelegate;
}
Expand Down Expand Up @@ -161,7 +163,7 @@ default VirtualFile getJarFile(File file) {
return virtualFile != null? JarFileSystem.getInstance().getJarRootForLocalFile(virtualFile):null;
}

static final ExtensionPointName<ToolDelegate> EP_NAME = ExtensionPointName.create("com.redhat.devtools.intellij.quarkus.toolDelegate");
static final ExtensionPointName<BuildToolDelegate> EP_NAME = ExtensionPointName.create("com.redhat.devtools.intellij.quarkus.toolDelegate");

@NotNull
static List<VirtualFile>[] initDeploymentFiles() {
Expand All @@ -171,11 +173,20 @@ static List<VirtualFile>[] initDeploymentFiles() {
return result;
}

public static ToolDelegate[] getDelegates() {
ToolDelegate[] delegates = EP_NAME.getExtensions();
public static BuildToolDelegate[] getDelegates() {
BuildToolDelegate[] delegates = EP_NAME.getExtensions();
Arrays.sort(delegates, (a,b) -> a.getOrder() - b.getOrder());
return delegates;
}

RunnerAndConfigurationSettings getConfigurationDelegate(Module module, QuarkusRunConfiguration configuration);

/**
* Add project import listener.
*
* @param project the project.
* @param connection the project connection used to subscribe maven, gradle listener which tracks project import.
* @param listener the project import listener.
*/
void addProjectImportListener(@NotNull Project project, @NotNull MessageBusConnection connection, @NotNull ProjectImportListener listener);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2023 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
* and is available at https://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package com.redhat.devtools.intellij.quarkus.buildtool;

import com.intellij.openapi.module.Module;
import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
* Project import listener API.
*
*/
public interface ProjectImportListener {

/**
* On import finished.
*
* @param modules imported modules.
*/
void importFinished(@NotNull List<Module> modules);

}
Loading

0 comments on commit 122dcb3

Please sign in to comment.