Skip to content

Commit

Permalink
fix: java.lang.IllegalArgumentException: Argument for @NotNull parameter
Browse files Browse the repository at this point in the history
'project' of com/intellij/execution/ui/RunContentManager.getInstance
must not be null

Fixes #1379

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Aug 30, 2024
1 parent bb9c0ce commit 66f8c8e
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 279 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.redhat.devtools.intellij.lsp4mp4ij.classpath.ClasspathResourceChangedManager;
import com.redhat.devtools.intellij.quarkus.QuarkusPluginDisposable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Set;

Expand Down Expand Up @@ -61,7 +62,7 @@ public void sourceFilesChanged(Set<Pair<VirtualFile, Module>> sources) {
if (isConfigSource(file)) {
// A microprofile config file properties file source has been updated, evict the cache of the properties
Module javaProject = pair.getSecond();
PsiMicroProfileProject mpProject = getMicroProfileProject(javaProject);
PsiMicroProfileProject mpProject = getMicroProfileProject(javaProject, false);
if (mpProject != null) {
mpProject.evictConfigSourcesCache(file);
}
Expand Down Expand Up @@ -90,11 +91,13 @@ private PsiMicroProfileProjectManager(Project project) {
connection.subscribe(ProjectTopics.MODULES, microprofileProjectListener);
}

public PsiMicroProfileProject getMicroProfileProject(Module project) {
@NotNull
public PsiMicroProfileProject getMicroProfileProject(@NotNull Module project) {
return getMicroProfileProject(project, true);
}

private PsiMicroProfileProject getMicroProfileProject(Module javaProject, boolean create) {
@Nullable
private PsiMicroProfileProject getMicroProfileProject(@NotNull Module javaProject, boolean create) {
PsiMicroProfileProject mpProject = javaProject.getUserData(KEY);
if (mpProject == null) {
if (!create) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,5 @@ public class QuarkusConstants {

public static final String QUARKUS_RUNTIME_CLASS_NAME = "io.quarkus.runtime.LaunchMode";
public static final String QUARKUS_BUILD_ITEM_CLASS_NAME = "io.quarkus.builder.item.BuildItem";
public static final String QUARKUS_RUN_CONTEXT_KEY = QuarkusConstants.class.getName() + ".quarkusContext";

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.project.PsiMicroProfileProject;
import com.redhat.devtools.lsp4ij.LSPIJUtils;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.core.ls.PsiUtilsLSImpl;
import com.redhat.devtools.intellij.quarkus.facet.QuarkusFacet;
Expand All @@ -37,6 +38,7 @@
import java.util.regex.Pattern;

public class QuarkusModuleUtil {

private static final Logger LOGGER = LoggerFactory.getLogger(QuarkusModuleUtil.class);

private static final Pattern QUARKUS_CORE_PATTERN = Pattern.compile("quarkus-core-(\\d[a-zA-Z\\d-.]+?).jar");
Expand Down Expand Up @@ -180,4 +182,36 @@ public static void sortRoot(List<VirtualFile> roots) {
public static void sortRoot(VirtualFile[] roots) {
Arrays.sort(roots, ROOT_COMPARATOR); // put root with smallest path first (eliminates generated sources roots)
}

public static String getApplicationUrl(@NotNull PsiMicroProfileProject mpProject) {
int port = getPort(mpProject);
String path = mpProject.getProperty("quarkus.http.root-path", "/");
return "http://localhost:" + port + normalize(path);
}

public static String getDevUIUrl(@NotNull PsiMicroProfileProject mpProject) {
int port = getPort(mpProject);
String path = mpProject.getProperty("quarkus.http.non-application-root-path", "q");
if (!path.startsWith("/")) {
String rootPath = mpProject.getProperty("quarkus.http.root-path", "/");
path = normalize(rootPath) + path;
}
return "http://localhost:" + port + normalize(path) + "dev";
}

private static String normalize(String path) {
StringBuilder builder = new StringBuilder(path);
if (builder.isEmpty() || builder.charAt(0) != '/') {
builder.insert(0, '/');
}
if (builder.charAt(builder.length() - 1) != '/') {
builder.append('/');
}
return builder.toString();
}

private static int getPort(@NotNull PsiMicroProfileProject mpProject) {
int port = mpProject.getPropertyAsInteger("quarkus.http.port", 8080);
return mpProject.getPropertyAsInteger("%dev.quarkus.http.port", port);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.runners.ExecutionEnvironmentBuilder;
import com.intellij.execution.runners.ExecutionUtil;
import com.intellij.execution.runners.ProgramRunner;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.Module;
Expand All @@ -33,7 +32,6 @@
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.redhat.devtools.intellij.quarkus.QuarkusConstants;
import com.redhat.devtools.intellij.quarkus.QuarkusModuleUtil;
import com.redhat.devtools.intellij.quarkus.TelemetryService;
import com.redhat.devtools.intellij.quarkus.buildtool.BuildToolDelegate;
Expand Down Expand Up @@ -134,8 +132,7 @@ public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEn
RunnerAndConfigurationSettings settings = toolDelegate.getConfigurationDelegate(getModule(), this);
if (settings != null) {
long groupId = ExecutionEnvironment.getNextUnusedExecutionId();
state = doRunConfiguration(settings, executor, DefaultExecutionTarget.INSTANCE, groupId, null,
desc -> desc.getComponent().putClientProperty(QuarkusConstants.QUARKUS_RUN_CONTEXT_KEY, new QuarkusRunContext(getModule())));
state = doRunConfiguration(settings, executor, DefaultExecutionTarget.INSTANCE, groupId, null);
}
} else {
telemetry.property("tool", "not found");
Expand Down Expand Up @@ -212,8 +209,7 @@ private static RunProfileState doRunConfiguration(@NotNull RunnerAndConfiguratio
@NotNull Executor executor,
@Nullable ExecutionTarget targetOrNullForDefault,
@Nullable Long executionId,
@Nullable DataContext dataContext,
ProgramRunner.Callback callback) throws ExecutionException {
@Nullable DataContext dataContext) throws ExecutionException {
ExecutionEnvironmentBuilder builder = createEnvironment(executor, configuration);
if (builder == null) {
return null;
Expand All @@ -229,7 +225,7 @@ private static RunProfileState doRunConfiguration(@NotNull RunnerAndConfiguratio
if (dataContext != null) {
builder.dataContext(dataContext);
}
return configuration.getConfiguration().getState(executor, builder.build(callback));
return configuration.getConfiguration().getState(executor, builder.build());
}

}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 66f8c8e

Please sign in to comment.