You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2018/09/30 07:28:53 UTC

[GitHub] geertjanw closed pull request #925: For OpenJDK projects, automatically detect JTReg from OpenJDK configu…

geertjanw closed pull request #925: For OpenJDK projects, automatically detect JTReg from OpenJDK configu…
URL: https://github.com/apache/incubator-netbeans/pull/925
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/java/java.openjdk.project/nbproject/project.xml b/java/java.openjdk.project/nbproject/project.xml
index fc83334b2c..f109bc9502 100644
--- a/java/java.openjdk.project/nbproject/project.xml
+++ b/java/java.openjdk.project/nbproject/project.xml
@@ -216,6 +216,14 @@
                         <specification-version>7.70</specification-version>
                     </run-dependency>
                 </dependency>
+                <dependency>
+                    <code-name-base>org.openide.dialogs</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <specification-version>7.45</specification-version>
+                    </run-dependency>
+                </dependency>
                 <dependency>
                     <code-name-base>org.openide.execution</code-name-base>
                     <build-prerequisite/>
diff --git a/java/java.openjdk.project/src/org/netbeans/modules/java/openjdk/jtreg/ActionProviderImpl.java b/java/java.openjdk.project/src/org/netbeans/modules/java/openjdk/jtreg/ActionProviderImpl.java
index 413eadd593..a288455046 100644
--- a/java/java.openjdk.project/src/org/netbeans/modules/java/openjdk/jtreg/ActionProviderImpl.java
+++ b/java/java.openjdk.project/src/org/netbeans/modules/java/openjdk/jtreg/ActionProviderImpl.java
@@ -30,12 +30,14 @@
 import java.net.InetAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Set;
 import java.util.WeakHashMap;
 import java.util.concurrent.CountDownLatch;
@@ -57,6 +59,8 @@
 import org.netbeans.spi.project.ActionProgress;
 import org.netbeans.spi.project.ActionProvider;
 import org.netbeans.spi.project.ui.CustomizerProvider2;
+import org.openide.DialogDisplayer;
+import org.openide.NotifyDescriptor;
 import org.openide.cookies.LineCookie;
 import org.openide.cookies.OpenCookie;
 import org.openide.execution.ExecutionEngine;
@@ -131,13 +135,8 @@ public static ExecutorTask createAndRunTest(Lookup context, String command) {
         final File jtregReport = new File(jtregOutput, "report");
         final ActionProgress progress = ActionProgress.start(context);
         ProfileSupport profiler = COMMAND_PROFILE_TEST_SINGLE.equals(command) ? Lookup.getDefault().lookup(ProfileSupport.Factory.class).create() : null;
-        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()) {
-            CustomizerProvider2 p = prj.getLookup().lookup(CustomizerProvider2.class);
-            p.showCustomizer("test", null);
+        File jtregJar = findJTReg(file);
+        if (jtregJar == null) {
             return null;
         }
         return ExecutionEngine.getDefault().execute(ioName, new Runnable() {
@@ -596,6 +595,52 @@ 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",
+    })
+    private static File findJTReg(FileObject file) {
+        File buildDir = BuildUtils.getBuildTargetDir(file);
+        File spec = new File(buildDir, "spec.gmk");
+        if (spec.canRead()) {
+            try {
+                String jtHome = Files.lines(spec.toPath())
+                                     .filter(l -> l.startsWith(JT_HOME_KEY))
+                                     .findAny()
+                                     .orElse(JT_HOME_KEY)
+                                     .substring(JT_HOME_KEY.length());
+                File jtregJar = findJTRegJar(jtHome);
+                if (jtregJar != null) {
+                    return jtregJar;
+                }
+            } catch (IOException ex) {
+                LOG.log(Level.FINE, null, ex);
+            }
+        }
+        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);
+            }
+            return null;
+        }
+        return jtregJar;
+    }
+        private static final String JT_HOME_KEY = "JT_HOME:=";
+
+    private static File findJTRegJar(String installDir) {
+        File jtregHome = installDir != null ? new File(installDir) : null;
+        File jtregJar = jtregHome != null ? new File(new File(jtregHome, "lib"), "jtreg.jar") : null;
+        return jtregJar == null || !jtregJar.canRead() ? null : jtregJar;
+    }
+
     @Override
     public boolean isActionEnabled(String command, Lookup context) throws IllegalArgumentException {
         FileObject file = context.lookup(FileObject.class);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists