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 9, 2023
1 parent 95f8798 commit 5a3d283
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
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.AutoCreateQuarkusRunConfigurationManager;
import org.jetbrains.annotations.NotNull;

public class QuarkusPostStartupActivity implements StartupActivity, DumbAware {
@Override
public void runActivity(@NotNull Project project) {
AutoCreateQuarkusRunConfigurationManager.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
@@ -0,0 +1,79 @@
/*******************************************************************************
* Copyright (c) 2023 Red Hat Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.devtools.intellij.quarkus.run;

import com.intellij.execution.RunManager;
import com.intellij.execution.RunnerAndConfigurationSettings;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.util.messages.MessageBusConnection;
import com.redhat.devtools.intellij.lsp4mp4ij.classpath.ClasspathResourceChangedManager;
import com.redhat.microprofile.psi.quarkus.PsiQuarkusUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.maven.project.MavenImportListener;
import org.jetbrains.idea.maven.project.MavenProject;

import java.util.Collection;
import java.util.List;

public class AutoCreateQuarkusRunConfigurationManager implements Disposable {

public static AutoCreateQuarkusRunConfigurationManager getInstance(Project project) {
return ServiceManager.getService(project, AutoCreateQuarkusRunConfigurationManager.class);
}

private final Project project;
private final MessageBusConnection projectConnection;

public AutoCreateQuarkusRunConfigurationManager(Project project) {
this.project = project;
projectConnection = project.getMessageBus().connect();
projectConnection.subscribe(MavenImportListener.TOPIC, new MavenImportListener() {
@Override
public void importFinished(@NotNull Collection<MavenProject> importedProjects, @NotNull List<Module> newModules) {
// TODO manage a settings to auto create Quarkus run config
for (Module module : newModules) {
if (PsiQuarkusUtils.isQuarkusProject(module)) {
Project project = module.getProject();
// Find existing Quarkus run configuration
RunnerAndConfigurationSettings quarkusSettings = null;
List<RunnerAndConfigurationSettings> list = RunManager.getInstance(project).getConfigurationSettingsList(QuarkusRunConfigurationType.class);
if (!list.isEmpty()) {
for (RunnerAndConfigurationSettings settings : list) {
QuarkusRunConfiguration configuration = (QuarkusRunConfiguration) settings.getConfiguration();
if (module.equals(configuration.getModule())) {
quarkusSettings = settings;
break;
}
}
}
if (quarkusSettings == null) {
// No Quarkus run configuration for the module, create it and save it in the .idea/workspace.xml file
quarkusSettings = RunManager.getInstance(project).createConfiguration(module.getName(), QuarkusRunConfigurationType.class);
((QuarkusRunConfiguration) quarkusSettings.getConfiguration()).setModule(module);
quarkusSettings.storeInLocalWorkspace();
}
}
}
}
});
}

@Override
public void dispose() {
projectConnection.disconnect();
}
}
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@
<projectService serviceImplementation="com.redhat.devtools.intellij.lsp4mp4ij.classpath.ClasspathResourceChangedManager"/>
<projectService serviceImplementation="com.redhat.devtools.intellij.lsp4mp4ij.psi.core.project.PsiMicroProfileProjectManager"/>
<projectService serviceImplementation="com.redhat.devtools.intellij.quarkus.QuarkusDeploymentSupport"/>
<projectService serviceImplementation="com.redhat.devtools.intellij.quarkus.run.AutoCreateQuarkusRunConfigurationManager" />
<configurationType implementation="com.redhat.devtools.intellij.quarkus.run.QuarkusRunConfigurationType"/>
<consoleActionsPostProcessor implementation="com.redhat.devtools.intellij.quarkus.run.QuarkusRunConsolePostProcessor"/>

Expand Down

0 comments on commit 5a3d283

Please sign in to comment.