Skip to content

Commit fcbef84

Browse files
committed
5.0.1 integrated Legacy and SwingJS transpilers
1 parent 78e249c commit fcbef84

33 files changed

+12123
-956
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
encoding/<project>=UTF-8
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
3-
Bundle-Name: Java2Script Core
4-
Bundle-SymbolicName: net.sf.j2s.core;singleton:=true
5-
Bundle-Version: 3.3.1
6-
Bundle-Activator: net.sf.j2s.core.CorePlugin
3+
Bundle-Name: Java2Script Core SwingJS and Legacy
4+
Bundle-SymbolicName: j2s.core;singleton:=true
5+
Bundle-Version: 5.0.1
6+
Bundle-Activator: j2s.CorePlugin
77
Bundle-Vendor: j2s.sourceforge.net
8+
Bundle-ActivationPolicy: lazy
89
Require-Bundle: org.eclipse.core.runtime,
910
org.eclipse.jdt.core,
1011
org.eclipse.core.resources
11-
Eclipse-AutoStart: true
12-
Export-Package: net.sf.j2s.core
12+
Export-Package: j2s,j2s.core
1313
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
14+
Automatic-Module-Name: Java2ScriptCore

sources/net.sf.j2s.core/src/net/sf/j2s/core/CorePlugin.java renamed to sources/net.sf.j2s.core/src/j2s/CorePlugin.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
package net.sf.j2s.core;
2-
3-
//import net.sf.j2s.core.hotspot.InnerHotspotServer;
1+
package j2s;
42

53
import org.eclipse.core.runtime.Plugin;
64
import org.osgi.framework.BundleContext;
75

86
/**
97
* The main plugin class to be used in the desktop.
10-
*
118
*/
129
public class CorePlugin extends Plugin {
1310

@@ -20,16 +17,17 @@ public class CorePlugin extends Plugin {
2017
* the actual "x.y.z" version is specified in plugin.xml.
2118
*
2219
* Note that Eclipse must be started with the -clean flag if it is to register
23-
* the bundle version properly. So we use VERSION here instead, and
24-
* also we recommend the plugin added to Eclipse be given just the name
25-
* "net.sf.j2s.core.jar" not "net.sf.j2s.core.3.2.5"
20+
* the bundle version properly. So we use VERSION here instead
21+
*
22+
* This version should be also placed in MANIFEST.MF for the bundle version
2623
*
2724
*/
28-
public static String VERSION = "3.3.1-v7";
25+
public static String VERSION = "5.0.1-v1";
2926

3027
// if you change the x.x.x number, be sure to also indicate that in
3128
// j2sApplet.js and also (Bob only) update.bat, update-clean.bat
3229

30+
// BH 2023.11.09 -- 5.0.1-v1 merges Jmol legacy (.j2sjmol) with Java8//11 (.j2s)
3331
// BH 2023.03.29 -- 3.3.1-v7 fixes outer static method call from within lambda expression.
3432
// BH 2023.02.09 -- 3.3.1.v6 fixes j2s.excluded.paths needing /src/xxxx
3533
// BH 2022.06.27 -- 3.3.1-v5 fixes missing method annotations
@@ -151,22 +149,17 @@ public CorePlugin() {
151149
* This method is called upon plug-in activation
152150
*/
153151
public void start(BundleContext context) throws Exception {
152+
System.out.println(VERSION + " started");
154153
super.start(context);
155-
System.out.println("net.sf.j2s.core." + context.getBundle().getVersion() + "/" + VERSION + " started");
156-
// if (!InnerHotspotServer.isServerStarted()) {
157-
// InnerHotspotServer.getSingletonServer().startServer();
158-
// }
159154
}
160155

161156
/**
162157
* This method is called when the plug-in is stopped
163158
*/
164159
public void stop(BundleContext context) throws Exception {
160+
System.out.println("J2S 4.2 stopped");
165161
super.stop(context);
166162
plugin = null;
167-
// if (InnerHotspotServer.isServerStarted()) {
168-
// InnerHotspotServer.getSingletonServer().stopServer();
169-
// }
170163
}
171164

172165
/**

sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptCompilationParticipant.java renamed to sources/net.sf.j2s.core/src/j2s/core/Java2ScriptCompilationParticipant.java

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
package net.sf.j2s.core;
1+
package j2s.core;
22

3+
import j2s.CorePlugin;
34
import java.util.ArrayList;
45
import java.util.Date;
56

@@ -48,13 +49,15 @@ public boolean isActive(IJavaProject project) {
4849
// happens when comparing to team...show history item
4950
return false;
5051
}
51-
boolean isj2s = Java2ScriptCompiler.isActive(project);
52+
String j2sFileName = Java2ScriptCompiler.getJ2SConfigName(project);
53+
boolean isj2s = (j2sFileName != null);
5254
String loc = " " + project.getProject().getLocation() + " ";
5355
// notify only if changed
54-
if (isActiveNotified.indexOf(isj2s + loc) < 0) {
55-
System.out.println("J2S isActive " + isj2s + loc);
56-
isActiveNotified = isActiveNotified.replace((!isj2s) + loc, "");
57-
isActiveNotified += isj2s + loc;
56+
String key = j2sFileName + "," + isj2s + "," + loc + ";";
57+
if (isActiveNotified.indexOf(key) < 0) {
58+
System.out.println("J2S isActive " + (isj2s ? j2sFileName : "false") + loc);
59+
isActiveNotified = isActiveNotified.replace(j2sFileName + (!isj2s) + loc, "");
60+
isActiveNotified += key;
5861
}
5962
return isj2s;
6063
}
@@ -76,7 +79,7 @@ public boolean isActive(IJavaProject project) {
7679
*/
7780
@Override
7881
public int aboutToBuild(IJavaProject project) {
79-
System.out.println("J2S aboutToBuild " + project.getProject().getName() + " " + project.getProject().getLocation());
82+
//System.out.println("J2S aboutToBuild " + project.getProject().getName() + " " + project.getProject().getLocation());
8083
if (contexts == null)
8184
contexts = new ArrayList<>();
8285
return READY_FOR_BUILD;
@@ -92,7 +95,7 @@ public int aboutToBuild(IJavaProject project) {
9295
*/
9396
@Override
9497
public void cleanStarting(IJavaProject project) {
95-
System.out.println("J2S cleanStarting " + project.getProject().getLocation());
98+
//System.out.println("J2S cleanStarting " + project.getProject().getLocation());
9699
isCleanBuild = true;
97100
}
98101

@@ -128,9 +131,9 @@ public void buildStarting(BuildContext[] files, boolean isBatch) {
128131
@Override
129132
public void buildFinished(IJavaProject project) {
130133
if (contexts != null && contexts.size() > 0) {
131-
Java2ScriptCompiler j2sCompiler = new Java2ScriptCompiler();
134+
Java2ScriptCompiler j2sCompiler = Java2ScriptCompiler.newCompiler(project);
132135
j2sCompiler.startBuild(isCleanBuild);
133-
if (!j2sCompiler.initializeProject(project, true)) {
136+
if (!j2sCompiler.initializeProject(project)) {
134137
System.out.println("J2S .j2s disabled");
135138
return;
136139
}
@@ -141,27 +144,18 @@ public void buildFinished(IJavaProject project) {
141144
for (int j = 0; j < contexts.size(); j++) {
142145
BuildContext[] files = contexts.get(j);
143146
System.out.println("J2S building JavaScript for " + files.length + " file" + plural(files.length));
144-
147+
String trailer = CorePlugin.VERSION + " " + new Date();
145148
for (int i = 0, n = files.length; i < n; i++) {
146-
// trying to keep the progess monitor running - didn't work
147-
// try {
148-
// Thread.currentThread().sleep(1);
149-
// } catch (InterruptedException e) {
150-
// // ignore
151-
// }
152-
// System.out.println("J2S file"
153-
// + " name=" + files[i].getFile().getName()
154-
// + " fullpath=" + files[i].getFile().getFullPath()
155-
// + " location=" + files[i].getFile().getLocation());
156-
//
157149
IFile f = files[i].getFile();
158150
String filePath = f.getLocation().toString();
159151
if (j2sCompiler.excludeFile(f)) {
152+
if (j2sCompiler.isDebugging)
160153
System.out.println("J2S excluded " + filePath);
161154
} else {
155+
if (j2sCompiler.isDebugging)
162156
System.out.println("J2S transpiling (" + (i + 1) + "/" + n + ") " + filePath);
163157
try {
164-
if (j2sCompiler.compileToJavaScript(f)) {
158+
if (j2sCompiler.compileToJavaScript(f, trailer)) {
165159
ntotal++;
166160
} else {
167161
nerror++;
@@ -186,7 +180,7 @@ public void buildFinished(IJavaProject project) {
186180
isCleanBuild = false;
187181
}
188182

189-
static String plural(int n) {
183+
public static String plural(int n) {
190184
return (n == 1 ? "" : "s");
191185
}
192186

0 commit comments

Comments
 (0)