This is an automated email from the ASF dual-hosted git repository. jlahoda pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-netbeans.git
The following commit(s) were added to refs/heads/master by this push: new 6b33d35 Fixing problems with watches evaluation on (not only) the upcoming JDK 11, fixing EvaluatorTest to pass on both JDK 8 with nb-javac and on recent JDK 11. 6b33d35 is described below commit 6b33d358012d670bfa229c21f8fd0dd18887a317 Author: Jan Lahoda <jlah...@netbeans.org> AuthorDate: Sat May 12 10:21:35 2018 +0200 Fixing problems with watches evaluation on (not only) the upcoming JDK 11, fixing EvaluatorTest to pass on both JDK 8 with nb-javac and on recent JDK 11. --- .../debugger/jpda/projects/IntroduceClass.java | 1 + debugger.jpda/nbproject/project.properties | 1 + debugger.jpda/nbproject/project.xml | 5 +++ .../debugger/jpda/expr/EvaluatorVisitor.java | 2 +- .../netbeans/api/debugger/jpda/EvaluatorTest.java | 18 ++++++++++ .../netbeans/api/debugger/jpda/JPDASupport.java | 39 ++++++++++++---------- .../api/debugger/jpda/testapps/EvaluatorApp.java | 6 +++- nbjunit/apichanges.xml | 14 ++++++++ nbjunit/manifest.mf | 2 +- nbjunit/src/org/netbeans/junit/NbModuleSuite.java | 13 ++++++++ 10 files changed, 80 insertions(+), 21 deletions(-) diff --git a/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/IntroduceClass.java b/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/IntroduceClass.java index c76fbd7..612d06a 100644 --- a/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/IntroduceClass.java +++ b/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/IntroduceClass.java @@ -124,6 +124,7 @@ class IntroduceClass { lsBegin -= codeOffset; this.snippetCode = new StringBuilder(this.snippetCode) .insert((int) lsBegin, "return ") + .append(';') .toString(); } if (returnType == null) { diff --git a/debugger.jpda/nbproject/project.properties b/debugger.jpda/nbproject/project.properties index 46316d0..ab2561a 100644 --- a/debugger.jpda/nbproject/project.properties +++ b/debugger.jpda/nbproject/project.properties @@ -25,5 +25,6 @@ requires.nb.javac=true spec.version.base=1.110.0 test-unit-sys-prop.test.dir.src=${basedir}/test/unit/src/ test-unit-sys-prop.netbeans.user=${basedir}/work/nb_user_dir +test.unit.cp.extra=../java.source.nbjavac/build/test-nb-javac/cluster/modules/org-netbeans-modules-java-source-nbjavac-test.jar diff --git a/debugger.jpda/nbproject/project.xml b/debugger.jpda/nbproject/project.xml index 814e374..14cbb11 100644 --- a/debugger.jpda/nbproject/project.xml +++ b/debugger.jpda/nbproject/project.xml @@ -184,6 +184,11 @@ <recursive/> </test-dependency> <test-dependency> + <code-name-base>org.netbeans.modules.java.source.nbjavac</code-name-base> + <compile-dependency/> + <test/> + </test-dependency> + <test-dependency> <code-name-base>org.netbeans.modules.nbjunit</code-name-base> <recursive/> <compile-dependency/> diff --git a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/expr/EvaluatorVisitor.java b/debugger.jpda/src/org/netbeans/modules/debugger/jpda/expr/EvaluatorVisitor.java index 04edbe7..614b7c7 100644 --- a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/expr/EvaluatorVisitor.java +++ b/debugger.jpda/src/org/netbeans/modules/debugger/jpda/expr/EvaluatorVisitor.java @@ -1992,7 +1992,7 @@ public class EvaluatorVisitor extends ErrorAwareTreePathScanner<Mirror, Evaluati identifierPath = getCurrentPath(); } elm = evaluationContext.getTrees().getElement(identifierPath); - if (elm instanceof TypeElement && ((TypeElement) elm).asType() instanceof ErrorType) { + if (elm instanceof TypeElement && ((TypeElement) elm).asType().getKind() == TypeKind.ERROR) { currentPath = null; // Elements not resolved correctly } } diff --git a/debugger.jpda/test/unit/src/org/netbeans/api/debugger/jpda/EvaluatorTest.java b/debugger.jpda/test/unit/src/org/netbeans/api/debugger/jpda/EvaluatorTest.java index 30e22ec..43e3481 100644 --- a/debugger.jpda/test/unit/src/org/netbeans/api/debugger/jpda/EvaluatorTest.java +++ b/debugger.jpda/test/unit/src/org/netbeans/api/debugger/jpda/EvaluatorTest.java @@ -23,6 +23,7 @@ import com.sun.jdi.ArrayReference; import com.sun.jdi.StringReference; import com.sun.jdi.Value; import java.io.BufferedReader; +import java.io.File; import java.io.InputStreamReader; import java.net.URL; import java.util.ArrayList; @@ -30,8 +31,16 @@ import java.util.List; import junit.framework.AssertionFailedError; import junit.framework.Test; import org.netbeans.api.debugger.DebuggerManager; +import org.netbeans.api.java.classpath.ClassPath; +import org.netbeans.api.java.source.ClasspathInfo; +import org.netbeans.api.java.source.JavaSource; +import org.netbeans.api.project.FileOwnerQuery; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ui.OpenProjects; import org.netbeans.junit.NbTestCase; import org.netbeans.modules.debugger.jpda.expr.JDIVariable; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; /** * Tests evaluation of various expressions. @@ -58,6 +67,15 @@ public class EvaluatorTest extends NbTestCase { protected void setUp () throws Exception { super.setUp (); + //PreferredCCParser is using SourceUtils.isScanInProgress() to modify behavior; ensure indexing is not running. + FileObject prjRoot = FileUtil.toFileObject(new File(System.getProperty("test.dir.src"))); + assertNotNull(prjRoot); + Project prj = FileOwnerQuery.getOwner(prjRoot); + assertNotNull(prj); + Project annotationsPrj = FileOwnerQuery.getOwner(prj.getProjectDirectory().getParent().getFileObject("api.annotations.common")); + assertNotNull(annotationsPrj); + OpenProjects.getDefault().open(new Project[] {annotationsPrj}, false); + JavaSource.create(ClasspathInfo.create(ClassPath.EMPTY, ClassPath.EMPTY, ClassPath.EMPTY)).runWhenScanFinished(p -> {}, true).get(); System.setProperty("debugger.evaluator2", "true"); JPDASupport.removeAllBreakpoints (); Utils.BreakPositions bp = Utils.getBreakPositions(System.getProperty ("test.dir.src")+ diff --git a/debugger.jpda/test/unit/src/org/netbeans/api/debugger/jpda/JPDASupport.java b/debugger.jpda/test/unit/src/org/netbeans/api/debugger/jpda/JPDASupport.java index 23e70f5..b13a30a 100644 --- a/debugger.jpda/test/unit/src/org/netbeans/api/debugger/jpda/JPDASupport.java +++ b/debugger.jpda/test/unit/src/org/netbeans/api/debugger/jpda/JPDASupport.java @@ -46,6 +46,8 @@ import org.netbeans.junit.NbModuleSuite; import org.netbeans.junit.NbModuleSuite.Configuration; import org.netbeans.spi.java.classpath.support.ClassPathSupport; import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.Exceptions; /** * Contains support functionality for unit tests. @@ -82,7 +84,25 @@ public class JPDASupport implements DebuggerManagerListener { public static Test createTestSuite(Class<? extends TestCase> clazz) { Configuration suiteConfiguration = NbModuleSuite.createConfiguration(clazz); - suiteConfiguration = suiteConfiguration.gui(false); + suiteConfiguration = suiteConfiguration.clusters(".*").enableModules(".*java.source.*").gui(false); + if (!(ClassLoader.getSystemClassLoader() instanceof URLClassLoader)) { + //when running on JDK 9+, to make the com.sun.jdi package dependency work, we need to make getPackage("com.sun.jdi") work + //for system CL's parent (which otherwise happily loads the VirtualMachineManager class, + //but won't return the package from getPackage due to JDK "specialty": + suiteConfiguration = suiteConfiguration.parentClassLoader(new ClassLoader(ClassLoader.getSystemClassLoader().getParent()) { + @Override + protected Package getPackage(String pack) { + if ("com.sun.jdi".equals(pack)) { + try { + return loadClass("com.sun.jdi.VirtualMachineManager").getPackage(); + } catch (ClassNotFoundException ex) { + throw new IllegalStateException(ex); + } + } + return super.getPackage(pack); + } + }); + } //suiteConfiguration = suiteConfiguration.reuseUserDir(false); return NbModuleSuite.create(suiteConfiguration); } @@ -134,22 +154,6 @@ public class JPDASupport implements DebuggerManagerListener { // return new JPDASupport (jpdaDebugger); // } - private static void deleteUserDir() { - String userDir = System.getProperty("netbeans.user"); - if (userDir != null) { - delete(new File(userDir)); - } - } - - private static void delete(File f) { - if (f.isDirectory()) { - for (File cf : f.listFiles()) { - delete(cf); - } - } - f.delete(); - } - public static JPDASupport attach (String mainClass) throws IOException, DebuggerStartException { return attach(mainClass, null); @@ -241,7 +245,6 @@ public class JPDASupport implements DebuggerManagerListener { debuggerEngine.getActionsManager (). doAction (ActionsManager.ACTION_KILL); waitState (JPDADebugger.STATE_DISCONNECTED); - deleteUserDir(); } public void waitState (int state) { diff --git a/debugger.jpda/test/unit/src/org/netbeans/api/debugger/jpda/testapps/EvaluatorApp.java b/debugger.jpda/test/unit/src/org/netbeans/api/debugger/jpda/testapps/EvaluatorApp.java index d520076..b1d8995 100644 --- a/debugger.jpda/test/unit/src/org/netbeans/api/debugger/jpda/testapps/EvaluatorApp.java +++ b/debugger.jpda/test/unit/src/org/netbeans/api/debugger/jpda/testapps/EvaluatorApp.java @@ -846,7 +846,7 @@ public class EvaluatorApp extends BaseClass { } public static int testMember7() { - // return pointObject.x; + // return-TODO pointObject.x; return ((java.awt.Point) pointObject).x; } @@ -1120,6 +1120,10 @@ public class EvaluatorApp extends BaseClass { return super.basedField; } + public long testLambdas() { + return Arrays.stream(new String[] {"a", "b"}).map(str -> str.length()).distinct().count(); + } + // Private access // Test public class first diff --git a/nbjunit/apichanges.xml b/nbjunit/apichanges.xml index fb563af..ab04d99 100644 --- a/nbjunit/apichanges.xml +++ b/nbjunit/apichanges.xml @@ -34,6 +34,20 @@ <!-- ACTUAL CHANGES BEGIN HERE: --> <changes> + <change id="NbModuleSuite.Configuration.parentClassLoader"> + <api name="nbjunit"/> + <summary>NbModuleSuite.Configuration.parentClassLoader()</summary> + <version major="1" minor="91"/> + <date day="17" month="6" year="2018"/> + <author login="jlahoda"/> + <compatibility addition="yes"/> + <description> + <p> + Adding a way to set parent classloader on which the NB platform should start. + </p> + </description> + <class package="org.netbeans.junit" name="NbModuleSuite"/> + </change> <change id="branding.token"> <api name="nbjunit"/> <summary>System property branding.token</summary> diff --git a/nbjunit/manifest.mf b/nbjunit/manifest.mf index 953464f..00b5bba 100644 --- a/nbjunit/manifest.mf +++ b/nbjunit/manifest.mf @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.nbjunit/1 OpenIDE-Module-Localizing-Bundle: org/netbeans/junit/Bundle.properties -OpenIDE-Module-Specification-Version: 1.90 +OpenIDE-Module-Specification-Version: 1.91 diff --git a/nbjunit/src/org/netbeans/junit/NbModuleSuite.java b/nbjunit/src/org/netbeans/junit/NbModuleSuite.java index 311171d..696ed77 100644 --- a/nbjunit/src/org/netbeans/junit/NbModuleSuite.java +++ b/nbjunit/src/org/netbeans/junit/NbModuleSuite.java @@ -508,6 +508,19 @@ public class NbModuleSuite { } /** + * Sets the parent ClassLoader on which the NB platform should start. + * @param parentCL the parent ClassLoader + * @return clone of this configuration with the parent ClassLoader set + * @since 1.91 + */ + public Configuration parentClassLoader(ClassLoader parentCL) { + return new Configuration( + clusterRegExp, moduleRegExp, startupArgs, parentCL, tests, + latestTestCaseClass, reuseUserDir, gui, enableClasspathModules + ,honorAutoEager, failOnMessage, failOnException, hideExtraModules); + } + + /** * Creates a test suite from this configuration. * Same as {@link #create(org.netbeans.junit.NbModuleSuite.Configuration)} but more fluid. * @return a suite ready for returning from a {@code public static Test suite()} method -- To stop receiving notification emails like this one, please contact jlah...@apache.org. --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists