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

Make sure the test roots are associated with the correct project(s) before attempting to run tests. #5722

Merged
merged 2 commits into from
Jun 10, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@
import javax.swing.SwingUtilities;

import org.netbeans.api.java.classpath.ClassPath;
import org.netbeans.api.java.project.JavaProjectConstants;
import org.netbeans.api.project.FileOwnerQuery;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectManager;
import org.netbeans.api.project.ProjectUtils;
import org.netbeans.modules.java.openjdk.common.BuildUtils;
import org.netbeans.modules.java.openjdk.common.BuildUtils.ExtraMakeTargets;
import org.netbeans.modules.java.openjdk.common.ShortcutUtils;
Expand Down Expand Up @@ -123,6 +126,7 @@ public void invokeAction(String command, Lookup context) throws IllegalArgumentE
"DN_Running=Running ({0})"})
public static ExecutorTask createAndRunTest(Lookup context, String command) {
final FileObject file = context.lookup(FileObject.class);
ensureProjectsRegistered(file);
String ioName = COMMAND_DEBUG_TEST_SINGLE.equals(command) ? Bundle.DN_Debugging(file.getName()) : Bundle.DN_Running(file.getName());
StopAction newStop = new StopAction();
ReRunAction newReRun = new ReRunAction(COMMAND_TEST_SINGLE);
Expand Down Expand Up @@ -671,13 +675,48 @@ public boolean isActionEnabled(String command, Lookup context) throws IllegalArg
if (file == null)
return false;

return findJDKRoot(file) != null;
}

private static FileObject findJDKRoot(FileObject file) {
while (!file.isRoot()) {
if (Utilities.isJDKRepository(file))
return true;
return file;
file = file.getParent();
}

return false;
return null;
}

private static void ensureProjectsRegistered(FileObject file) {
if (FileOwnerQuery.getOwner(file) != null) {
return ;
}

FileObject jdkRoot = findJDKRoot(file);

if (jdkRoot == null) {
return ;
}

for (String wellKnownProject : new String[] {"java.base", "java.compiler",
"java.xml", "jdk.scripting.nashorn"}) {
for (String open : new String[] {"open/", ""}) {
FileObject prjRoot = jdkRoot.getFileObject(open + "src/" + wellKnownProject);

if (prjRoot == null) {
continue;
}

Project thisPrj = FileOwnerQuery.getOwner(prjRoot);

if (thisPrj != null) {
//ensure external roots are registered:
ProjectUtils.getSources(thisPrj)
.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
}
}
}
}

private static TestType inferTestType(Project prj) {
Expand Down