Skip to content

Commit

Permalink
Merge pull request #5721 from jlahoda/select-jtreg
Browse files Browse the repository at this point in the history
Adding a way to directly specify JTreg when no is known
  • Loading branch information
jlahoda authored Jun 10, 2023
2 parents 18542bf + 8a9df65 commit 0ea83cc
Showing 1 changed file with 58 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import java.net.InetAddress;
import java.net.ServerSocket;
Expand Down Expand Up @@ -66,6 +67,7 @@
import org.netbeans.spi.project.ui.CustomizerProvider2;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.NotifyDescriptor.InputLine;
import org.openide.cookies.LineCookie;
import org.openide.cookies.OpenCookie;
import org.openide.execution.ExecutionEngine;
Expand All @@ -83,6 +85,7 @@
import org.openide.util.NbBundle.Messages;
import org.openide.util.Pair;
import org.openide.util.RequestProcessor;
import org.openide.util.RequestProcessor.Task;
import org.openide.util.lookup.Lookups;
import org.openide.util.lookup.ServiceProvider;
import org.openide.windows.IOProvider;
Expand Down Expand Up @@ -123,7 +126,9 @@ public void invokeAction(String command, Lookup context) throws IllegalArgumentE
@Messages({"# {0} - simple file name",
"DN_Debugging=Debugging ({0})",
"# {0} - simple file name",
"DN_Running=Running ({0})"})
"DN_Running=Running ({0})",
"LBL_IncorrectVersionSelectJTReg=Location of JTReg:",
"TITLE_IncorrectVersionSelectJTReg=Version of JTReg appears to be incorrect, please select a correct version"})
public static ExecutorTask createAndRunTest(Lookup context, String command) {
final FileObject file = context.lookup(FileObject.class);
ensureProjectsRegistered(file);
Expand Down Expand Up @@ -304,12 +309,34 @@ public String[] getExtraMakeTargets() {
try {
stop.started();
Process jtregProcess = new ProcessBuilder(options).start();
BACKGROUND.post(new CopyReaderWriter(new InputStreamReader(jtregProcess.getInputStream()), io.getOut()));
BACKGROUND.post(new CopyReaderWriter(new InputStreamReader(jtregProcess.getErrorStream()), io.getErr()));
StringWriter errorOutput = new StringWriter();
Task outCopy = BACKGROUND.post(new CopyReaderWriter(new InputStreamReader(jtregProcess.getInputStream()), io.getOut()));
Task errCopy = BACKGROUND.post(new CopyReaderWriter(new InputStreamReader(jtregProcess.getErrorStream()), io.getErr(), errorOutput));
BACKGROUND.post(new CopyReaderWriter(io.getIn(), new OutputStreamWriter(jtregProcess.getOutputStream())));
jtregProcess.waitFor();
int processResult = jtregProcess.waitFor();
outCopy.waitFinished();
errCopy.waitFinished();
switch (processResult) {
case 5: //error
//check if it is a version error:
if (errorOutput.toString().contains("jtreg version")) {
Settings settings = prj.getLookup().lookup(Settings.class);
String jtregLocation = settings.getJTregLocation();
InputLine nd = new InputLine(Bundle.LBL_IncorrectVersionSelectJTReg(), Bundle.TITLE_IncorrectVersionSelectJTReg(), NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.ERROR_MESSAGE);
nd.setInputText(jtregLocation);
if (DialogDisplayer.getDefault().notify(nd) == NotifyDescriptor.OK_OPTION) {
settings.setJTregLocation(nd.getInputText());
BACKGROUND.post(() -> {
createAndRunTest(context, command);
});
}
}
break;
default:
printJTR(io, jtregWork, fullSourcePath, file);
break;
}
success = true;
printJTR(io, jtregWork, fullSourcePath, file);

for (File refresh : toRefresh) {
FileUtil.refreshFor(refresh);
Expand Down Expand Up @@ -624,10 +651,8 @@ public StackTraceLine(String expectedFileName, int lineNumber) {
}

@Messages({
"LBL_NoJTReg=No JTReg found, please specify JTReg location either when " +
"configuring JDK build, or in the Project Properties.\n" +
"Open Project Properties?\n",
"TITLE_NoJTReg=No JTReg found",
"LBL_SelectJTReg=JTreg Location:",
"TITLE_SelectJTReg=Please select JTReg location",
})
private static File findJTReg(FileObject file) {
File buildDir = BuildUtils.getBuildTargetDir(file);
Expand All @@ -647,18 +672,23 @@ private static File findJTReg(FileObject file) {
}
}
Project prj = FileOwnerQuery.getOwner(file);
String jtregLocation = prj.getLookup().lookup(Settings.class).getJTregLocation();
File jtregHome = jtregLocation != null ? new File(jtregLocation) : null;
File jtregJar = jtregHome != null ? new File(new File(jtregHome, "lib"), "jtreg.jar") : null;
if (jtregJar == null || !jtregJar.canRead()) {
NotifyDescriptor.Confirmation nd = new NotifyDescriptor.Confirmation(Bundle.LBL_NoJTReg(), Bundle.TITLE_NoJTReg(), NotifyDescriptor.OK_CANCEL_OPTION);
if (DialogDisplayer.getDefault().notify(nd) == NotifyDescriptor.OK_OPTION) {
CustomizerProvider2 p = prj.getLookup().lookup(CustomizerProvider2.class);
p.showCustomizer("test", null);
Settings settings = prj.getLookup().lookup(Settings.class);
while (true) {
String jtregLocation = settings.getJTregLocation();
File jtregHome = jtregLocation != null ? new File(jtregLocation) : null;
File jtregJar = jtregHome != null ? new File(new File(jtregHome, "lib"), "jtreg.jar") : null;
if (jtregJar == null || !jtregJar.canRead()) {
InputLine nd = new InputLine(Bundle.LBL_SelectJTReg(), Bundle.TITLE_SelectJTReg(), NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.ERROR_MESSAGE);
nd.setInputText(jtregLocation);
if (DialogDisplayer.getDefault().notify(nd) == NotifyDescriptor.OK_OPTION) {
settings.setJTregLocation(nd.getInputText());
continue;
} else {
return null;
}
}
return null;
return jtregJar;
}
return jtregJar;
}
private static final String JT_HOME_KEY = "JT_HOME:=";

Expand Down Expand Up @@ -886,10 +916,16 @@ public void run() {
private static final class CopyReaderWriter implements Runnable {
private final Reader in;
private final Writer out;
private final Writer secondaryOut;

public CopyReaderWriter(Reader in, Writer out) {
this(in, out, null);
}

public CopyReaderWriter(Reader in, Writer out, Writer secondaryOut) {
this.in = in;
this.out = out;
this.secondaryOut = secondaryOut;
}

@Override
Expand All @@ -900,6 +936,9 @@ public void run() {

while ((read = in.read(buf)) != (-1)) {
out.write(buf, 0, read);
if (secondaryOut != null) {
secondaryOut.write(buf, 0, read);
}
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
Expand Down

0 comments on commit 0ea83cc

Please sign in to comment.