You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by jt...@apache.org on 2021/07/02 08:25:19 UTC
[netbeans] branch master updated: Prefer .class execution over
.java if the class already exists
This is an automated email from the ASF dual-hosted git repository.
jtulach pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 8d822bf Prefer .class execution over .java if the class already exists
new bd41d87 Merge pull request #3036 from JaroslavTulach/jtulach/SingleExecPreferClass
8d822bf is described below
commit 8d822bfce59b269ca6ea2b7c8848e2aff358ee0d
Author: Jaroslav Tulach <ja...@oracle.com>
AuthorDate: Fri Jul 2 07:38:18 2021 +0200
Prefer .class execution over .java if the class already exists
---
.../java/api/common/singlesourcefile/LaunchProcess.java | 2 +-
.../api/common/singlesourcefile/SingleSourceFileUtil.java | 4 ++++
.../common/singlesourcefile/SingleSourceFileUtilTest.java | 12 +++++++++++-
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/LaunchProcess.java b/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/LaunchProcess.java
index 6902319..0421828 100644
--- a/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/LaunchProcess.java
+++ b/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/LaunchProcess.java
@@ -53,7 +53,7 @@ final class LaunchProcess implements Callable<Process> {
private Process setupProcess(String port) throws InterruptedException {
try {
- boolean compile = SingleSourceFileUtil.findJavaVersion() < 11;
+ boolean compile = SingleSourceFileUtil.findJavaVersion() < 11 || SingleSourceFileUtil.hasClassSibling(fileObject);
if (compile) {
Process p = SingleSourceFileUtil.compileJavaSource(fileObject);
diff --git a/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/SingleSourceFileUtil.java b/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/SingleSourceFileUtil.java
index 3a76836..2914ee0 100644
--- a/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/SingleSourceFileUtil.java
+++ b/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/SingleSourceFileUtil.java
@@ -101,4 +101,8 @@ final class SingleSourceFileUtil {
return null;
}
+ static boolean hasClassSibling(FileObject fo) {
+ return fo.getParent().getFileObject(fo.getName(), "class") != null;
+ }
+
}
diff --git a/java/java.api.common/test/unit/src/org/netbeans/modules/java/api/common/singlesourcefile/SingleSourceFileUtilTest.java b/java/java.api.common/test/unit/src/org/netbeans/modules/java/api/common/singlesourcefile/SingleSourceFileUtilTest.java
index a380a05..016eab8 100644
--- a/java/java.api.common/test/unit/src/org/netbeans/modules/java/api/common/singlesourcefile/SingleSourceFileUtilTest.java
+++ b/java/java.api.common/test/unit/src/org/netbeans/modules/java/api/common/singlesourcefile/SingleSourceFileUtilTest.java
@@ -40,5 +40,15 @@ public class SingleSourceFileUtilTest {
assertEquals("Java FileObject found in the lookup", java, result);
}
-
+ @Test
+ public void testCanFindSiblingClass() throws IOException {
+ final FileObject folder = FileUtil.createMemoryFileSystem().getRoot().createFolder("dir");
+ FileObject java = folder.createData("Ahoj.java");
+ assertFalse("No sibling found", SingleSourceFileUtil.hasClassSibling(java));
+
+ FileObject clazz = folder.createData("Ahoj.class");
+ assertNotNull("class created", clazz);
+
+ assertTrue("Sibling found", SingleSourceFileUtil.hasClassSibling(java));
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists