Skip to content

Commit 7622dc6

Browse files
committed
Bug: J2S compiler not activated on Linux/macOS (Wrong ".J2S" file name)
Cause ===== In Java2ScriptCompiler the literals ".J2S" and ".j2s" are used as names for the J2S compiler options file (the "dot-j2s" file). The literals only differ in the case of the letters. On Windows both literals ".J2S" and ".j2s" denote the same file. However on other operating systems (like Linux and macOS) the two literals (can) identify two different files. This is because these operating system have (or can have) case-sensitive file systems. As a consequence adding a file ".j2s" (with lower case letters) to a project will not activate the J2S compiler on Linux and macOS because the compiler's "isActive" method checks for the file ".J2S" (with upper case letters) and does not find such a file. Solution ======== Always use one unique name for the J2S compiler options file (".j2s"), accessible through constant `Java2ScriptCompiler.J2S_OPTIONS_FILE_NAME`. Also ==== - fix "unused import" warnings in Java2ScriptCompiler.java
1 parent 4c08840 commit 7622dc6

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

sources/net.sf.j2s.core/src/net/sf/j2s/core/compiler/Java2ScriptCompiler.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,15 @@
1818
import java.util.Map;
1919
import java.util.Properties;
2020

21-
import org.eclipse.core.resources.IContainer;
2221
import org.eclipse.core.resources.IFile;
2322
import org.eclipse.core.resources.IProject;
2423
import org.eclipse.jdt.core.JavaCore;
2524
import org.eclipse.jdt.core.dom.AST;
2625
import org.eclipse.jdt.core.dom.ASTParser;
2726
import org.eclipse.jdt.core.dom.CompilationUnit;
28-
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
29-
import org.eclipse.jdt.internal.core.builder.SourceFile;
3027

3128
import net.sf.j2s.core.CorePlugin;
3229
import net.sf.j2s.core.astvisitors.Java2ScriptVisitor;
33-
//import net.sf.j2s.core.builder.SourceFile;
34-
//import net.sf.j2s.core.builder.SourceFileProxy;
35-
//import net.sf.j2s.core.hotspot.InnerHotspotServer;
3630

3731
/**
3832
* The main (and currently only operational) Java2Script compiler.
@@ -42,7 +36,11 @@
4236
*/
4337
@SuppressWarnings("restriction")
4438
public class Java2ScriptCompiler {
45-
39+
/**
40+
* The name of the J2S options file, aka as the "Dot-j2s" file.
41+
*/
42+
public static final String J2S_OPTIONS_FILE_NAME = ".j2s";
43+
4644
// BH: added "true".equals(getProperty(props,
4745
// "j2s.compiler.allow.compression")) to ensure compression only occurs when
4846
// desired
@@ -83,8 +81,8 @@ public class Java2ScriptCompiler {
8381

8482
public static boolean isActive(IProject project) {
8583
try {
86-
return new File(project.getProject().getLocation().toOSString(), ".J2S").exists();
87-
} catch (Exception e) {
84+
return new File(project.getProject().getLocation().toOSString(), J2S_OPTIONS_FILE_NAME).exists();
85+
} catch (@SuppressWarnings("unused") Exception e) {
8886
return false;
8987
}
9088
}
@@ -141,7 +139,7 @@ public boolean initializeProject(IProject project, boolean isCompilationParticip
141139
projectFolder = project.getLocation().toOSString();
142140
props = new Properties();
143141
try {
144-
File j2sFile = new File(projectFolder, ".j2s");
142+
File j2sFile = new File(projectFolder, J2S_OPTIONS_FILE_NAME);
145143
props.load(new FileInputStream(j2sFile));
146144
String status = getProperty("j2s.compiler.status");
147145
if (!"enable".equals(status) && !"enabled".equals(status)) {

0 commit comments

Comments
 (0)