Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 56b6736

Browse files
author
zhourenjian
committed
Update to version 20080907:
1. Fix bug that running Java2Script applications may leave "processes" in Debug stack view 2. Support exporting to *.jar in java 1.3 compatible mode.
1 parent e73e20e commit 56b6736

File tree

6 files changed

+135
-15
lines changed

6 files changed

+135
-15
lines changed

.settings/org.eclipse.jdt.core.prefs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#Wed Aug 29 20:57:36 CST 2007
2+
eclipse.preferences.version=1
3+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
4+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
5+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6+
org.eclipse.jdt.core.compiler.compliance=1.4
7+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
9+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
11+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
12+
org.eclipse.jdt.core.compiler.source=1.3

build.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ bin.includes = META-INF/,\
55
plugin.xml,\
66
schema/,\
77
icons/
8+
javacSource = 1.3
9+
javacTarget = 1.2

src/net/sf/j2s/ui/launching/J2SLaunchConfigurationDelegate.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package net.sf.j2s.ui.launching;
22

3+
import java.io.File;
4+
35
import org.eclipse.core.runtime.CoreException;
46
import org.eclipse.core.runtime.IProgressMonitor;
57
import org.eclipse.debug.core.ILaunch;
@@ -17,6 +19,13 @@ public void launch(ILaunchConfiguration configuration, String mode,
1719
if (configuration != null) {
1820
try {
1921
J2SLaunchingUtil.launchingJ2SApp(configuration, mode, "html");
22+
String mainType = J2SLaunchingUtil.getMainType(configuration);
23+
if (mainType != null) {
24+
File workingDir = J2SLaunchingUtil.getWorkingDirectory(configuration);
25+
if (workingDir != null) {
26+
launch.addProcess(new J2SProcess(launch, new File(workingDir, mainType + ".html").getAbsolutePath()));
27+
}
28+
}
2029
} catch (CoreException e) {
2130
e.printStackTrace();
2231
}

src/net/sf/j2s/ui/launching/J2SLaunchingUtil.java

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import java.util.Properties;
1616
import java.util.Set;
1717

18+
import net.sf.j2s.core.astvisitors.ASTTigerVisitor;
19+
import net.sf.j2s.core.astvisitors.ASTTypeVisitor;
1820
import net.sf.j2s.core.astvisitors.DependencyASTVisitor;
1921
import net.sf.j2s.core.hotspot.InnerHotspotServer;
2022
import net.sf.j2s.ui.Java2ScriptUIPlugin;
@@ -152,10 +154,11 @@ public static void launchingJ2SUnit(ILaunchConfiguration configuration, String m
152154
}
153155
}
154156
}
157+
String mainTypeName = new ASTTypeVisitor().assureQualifiedName(mainType);
155158
if (isTestSuite) {
156-
buf.append("\t\t\t\tjunit.textui.TestRunner.run (" + mainType + ".suite ());\r\n");
159+
buf.append("\t\t\t\tjunit.textui.TestRunner.run (" + mainTypeName + ".suite ());\r\n");
157160
} else {
158-
buf.append("\t\t\t\tjunit.textui.TestRunner.run (" + mainType + ");\r\n");
161+
buf.append("\t\t\t\tjunit.textui.TestRunner.run (" + mainTypeName + ");\r\n");
159162
}
160163
buf.append("\t\t\t});\r\n");
161164
buf.append("\t\t});\r\n");
@@ -183,10 +186,11 @@ public static void launchingJ2SUnit(ILaunchConfiguration configuration, String m
183186
}
184187
}
185188
}
189+
String mainTypeName = new ASTTypeVisitor().assureQualifiedName(mainType);
186190
if (isTestSuite) {
187-
buf.append("\t\tjunit.textui.TestRunner.run (" + mainType + ".suite ());\r\n");
191+
buf.append("\t\tjunit.textui.TestRunner.run (" + mainTypeName + ".suite ());\r\n");
188192
} else {
189-
buf.append("\t\tjunit.textui.TestRunner.run (" + mainType + ");\r\n");
193+
buf.append("\t\tjunit.textui.TestRunner.run (" + mainTypeName + ");\r\n");
190194
}
191195
buf.append("\t});\r\n");
192196
buf.append("});\r\n");
@@ -292,7 +296,8 @@ public static void launchingJ2SApp(ILaunchConfiguration configuration, String mo
292296
grelativePath, mainType, workingDir, configuration);
293297

294298
buf.append("\t\tClazzLoader.loadClass (\"" + mainType + "\", function () {\r\n");
295-
buf.append("\t\t\t" + mainType + ".main(" + ArgsUtil.wrapAsArgumentArray(args, true) + ");\r\n");
299+
String mainTypeName = new ASTTypeVisitor().assureQualifiedName(mainType);
300+
buf.append("\t\t\t" + mainTypeName + ".main(" + ArgsUtil.wrapAsArgumentArray(args, true) + ");\r\n");
296301
buf.append("\t\t});\r\n");
297302

298303
buf.append("\t}\r\n");
@@ -305,7 +310,8 @@ public static void launchingJ2SApp(ILaunchConfiguration configuration, String mo
305310
isJUnit, grelativePath, workingDir, configuration);
306311

307312
buf.append("ClazzLoader.loadClass (\"" + mainType + "\", function () {\r\n");
308-
buf.append("\t" + mainType + ".main(" + ArgsUtil.wrapAsArgumentArray(args, true) + ");\r\n");
313+
String mainTypeName = new ASTTypeVisitor().assureQualifiedName(mainType);
314+
buf.append("\t" + mainTypeName + ".main(" + ArgsUtil.wrapAsArgumentArray(args, true) + ");\r\n");
309315
buf.append("});\r\n");
310316
}
311317

@@ -443,7 +449,15 @@ private static void generateFirefoxAddonPreJavaScript(StringBuffer buf,
443449
buf.append("\t/*forward : true,*/\r\n");
444450
buf.append("\tmode : \"dailybuild\",\r\n");
445451
buf.append("\tonload : function () {\r\n");
446-
452+
String j2xStr = J2SLaunchingUtil.generateClasspathJ2X(configuration, "j2slibPath", workingDir);
453+
if (j2xStr != null && j2xStr.length() != 0) {
454+
buf.append("\t\tvar o = window[\"j2s.lib\"];\r\n");
455+
buf.append("\t\tvar j2slibPath = o.base + (o.alias ? o.alias : o.version) + \"/\";\r\n");
456+
buf.append("\t\t");
457+
buf.append(j2xStr.replaceAll("\r\n", "\r\n\t\t").trim());
458+
buf.append("\r\n");
459+
}
460+
447461
buf.append("\t\tClazzLoader.setPrimaryFolder (\"");
448462
buf.append(grelativePath);
449463
buf.append("\");\r\n");
@@ -459,7 +473,9 @@ private static String generatePreJavaScript(StringBuffer buf, String args,
459473
String grelativePath, String gj2sLibPath, boolean isJUnit, String mode,
460474
String mainType, File workingDir, ILaunchConfiguration configuration)
461475
throws CoreException {
462-
buf.append("<a class=\"alaa\" href=\"javascript:if(a='");
476+
buf.append("<a class=\"alaa\" title=\"Launch ");
477+
buf.append(mainType);
478+
buf.append("\" href=\"javascript:if(a='");
463479
buf.append(mainType);
464480
buf.append('@');
465481
buf.append(grelativePath);
@@ -481,6 +497,7 @@ private static String generatePreJavaScript(StringBuffer buf, String args,
481497
buf.append(gj2sLibPath);
482498
buf.append("j2slib.z.js';(typeof x[t]=='undefined')?x.onload=f:x[t]=f;" +
483499
"d.getElementsByTagName('HEAD')[0].appendChild(x);void(0);}\">");
500+
buf.append("<span class=\"alaa-icon\"></span>");
484501
buf.append(mainType);
485502
buf.append("</a>\r\n\r\n");
486503

@@ -490,7 +507,7 @@ private static String generatePreJavaScript(StringBuffer buf, String args,
490507
buf.append("<script type=\"text/javascript\">\r\n");
491508

492509
J2SCyclicProjectUtils.emptyTracks();
493-
String j2xStr = J2SLaunchingUtil.generateClasspathJ2X(configuration, mainType, workingDir);
510+
String j2xStr = J2SLaunchingUtil.generateClasspathJ2X(configuration, null, workingDir);
494511

495512
if ("debug".equals(mode)) {
496513
buf.append("window[\"j2s.script.debugging\"] = true;\r\n");
@@ -549,13 +566,20 @@ private static void generateJ2SHeaderHTML(StringBuffer buf,
549566
"\twidth:1em;\r\n" +
550567
"\toverflow-x:visible;\r\n" +
551568
"\ttext-decoration:none;\r\n" +
552-
"\tborder-left:1em solid rgb(57,61,254);\r\n" +
553-
"\tpadding-left:4px;\r\n" +
569+
"\tpadding-left:32px;\r\n" +
554570
"\tmargin:2em;\r\n" +
555571
"\tcolor:navy;\r\n" +
556572
"\tcursor:pointer;\r\n" +
557573
"\tcursor:hand;\r\n");
558574
buf.append("}\r\n");
575+
buf.append("span.alaa-icon {\r\n");
576+
buf.append("\tdisplay:block;\r\n" +
577+
"\tposition:absolute;\r\n" +
578+
"\twidth:16px;\r\n" +
579+
"\theight:16px;\r\n" +
580+
"\tmargin:2px 8px 0 -24px;\r\n" +
581+
"\tbackground-color:rgb(57,61,254);\r\n");
582+
buf.append("}\r\n");
559583
buf.append("</style>\r\n");
560584
buf.append("</head>\r\n");
561585
buf.append("<body>\r\n");
@@ -667,7 +691,7 @@ static String generateClasspathHTML(
667691
* Append the *.js in classpath
668692
*/
669693
static String generateClasspathJ2X(
670-
ILaunchConfiguration configuration, String mainType, File workingDir)
694+
ILaunchConfiguration configuration, String varName, File workingDir)
671695
throws CoreException {
672696
boolean isUseGlobalURL = configuration.getAttribute(IJ2SLauchingConfiguration.USE_GLOBAL_ALAA_URL, false);
673697
StringBuffer buf = new StringBuffer();
@@ -783,7 +807,7 @@ public boolean accept(File pathname) {
783807
keyPkg.add(pkg);
784808
buf.append("ClazzLoader.packageClasspath (\"");
785809
buf.append(pkg);
786-
buf.append("\", \"");
810+
buf.append("\", ");
787811
String j2slibPath = FileUtil.toRelativePath(f.getParent(), workingDir.getAbsolutePath());
788812
String gj2sLibPath = j2slibPath;
789813
if (isUseGlobalURL) {
@@ -795,8 +819,13 @@ public boolean accept(File pathname) {
795819
gj2sLibPath += "/";
796820
}
797821
}
798-
buf.append(gj2sLibPath);
799-
buf.append("\"");
822+
if (varName == null) {
823+
buf.append("\"");
824+
buf.append(gj2sLibPath);
825+
buf.append("\"");
826+
} else {
827+
buf.append(varName);
828+
}
800829
File pkgFile = new File(f.getParentFile(), pkg.replace('.', '/') + "/package.js");
801830
if (pkgFile.exists()) {
802831
buf.append(", true");
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package net.sf.j2s.ui.launching;
2+
3+
import org.eclipse.debug.core.DebugException;
4+
import org.eclipse.debug.core.ILaunch;
5+
import org.eclipse.debug.core.model.IProcess;
6+
import org.eclipse.debug.core.model.IStreamsProxy;
7+
8+
public class J2SProcess implements IProcess {
9+
10+
private ILaunch launch;
11+
12+
private String label;
13+
14+
public J2SProcess(ILaunch launch, String label) {
15+
super();
16+
this.launch = launch;
17+
this.label = label;
18+
}
19+
20+
public String getAttribute(String key) {
21+
return null;
22+
}
23+
24+
public int getExitValue() throws DebugException {
25+
return 0;
26+
}
27+
28+
public String getLabel() {
29+
return label;
30+
}
31+
32+
public ILaunch getLaunch() {
33+
return launch;
34+
}
35+
36+
public IStreamsProxy getStreamsProxy() {
37+
return null;
38+
}
39+
40+
public void setAttribute(String key, String value) {
41+
}
42+
43+
public Object getAdapter(Class adapter) {
44+
return null;
45+
}
46+
47+
public boolean canTerminate() {
48+
return true;
49+
}
50+
51+
public boolean isTerminated() {
52+
// J2S process is terminated already as there is no way to monitor it
53+
return true;
54+
}
55+
56+
public void terminate() throws DebugException {
57+
}
58+
59+
}

src/net/sf/j2s/ui/launching/J2SUnitConfigurationDelegate.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package net.sf.j2s.ui.launching;
22

3+
import java.io.File;
4+
35
import org.eclipse.core.runtime.CoreException;
46
import org.eclipse.core.runtime.IProgressMonitor;
57
import org.eclipse.debug.core.ILaunch;
@@ -17,6 +19,13 @@ public void launch(ILaunchConfiguration configuration, String mode,
1719
if (configuration != null) {
1820
try {
1921
J2SLaunchingUtil.launchingJ2SUnit(configuration, mode, "junit.html");
22+
String mainType = J2SLaunchingUtil.getMainType(configuration);
23+
if (mainType != null) {
24+
File workingDir = J2SLaunchingUtil.getWorkingDirectory(configuration);
25+
if (workingDir != null) {
26+
launch.addProcess(new J2SProcess(launch, new File(workingDir, mainType + ".junit.html").getAbsolutePath()));
27+
}
28+
}
2029
} catch (CoreException e) {
2130
e.printStackTrace();
2231
}

0 commit comments

Comments
 (0)