Skip to content

Commit e82548c

Browse files
committed
transpiler try/catch for exceptions and fix for bad package name
1 parent 7a6098f commit e82548c

File tree

6 files changed

+30
-18
lines changed

6 files changed

+30
-18
lines changed
189 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20191104164911
1+
20191105121713
189 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20191104164911
1+
20191105121713

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public void buildFinished(IJavaProject project) {
137137
int ntotal = 0, nerror = 0;
138138
for (int j = 0; j < contexts.size(); j++) {
139139
BuildContext[] files = contexts.get(j);
140-
System.out.println("J2S building JavaScript for " + files.length + " file"+plural(files.length));
140+
System.out.println("J2S building JavaScript for " + files.length + " file" + plural(files.length));
141141

142142
for (int i = 0, n = files.length; i < n; i++) {
143143
// trying to keep the progess monitor running - didn't work
@@ -157,23 +157,29 @@ public void buildFinished(IJavaProject project) {
157157
System.out.println("J2S excluded " + filePath);
158158
} else {
159159
System.out.println("J2S transpiling (" + (i + 1) + "/" + n + ") " + filePath);
160-
if (j2sCompiler.compileToJavaScript(f)) {
161-
ntotal++;
162-
} else {
163-
nerror++;
164-
System.out.println("J2S Error processing " + filePath);
165-
if (breakOnError)
166-
break;
160+
try {
161+
if (j2sCompiler.compileToJavaScript(f)) {
162+
ntotal++;
163+
} else {
164+
nerror++;
165+
System.out.println("J2S Error processing " + filePath);
166+
if (breakOnError)
167+
break;
168+
}
169+
} catch (Exception e) {
170+
System.out.println("J2S Exception " + e);
171+
e.printStackTrace(System.out);
172+
e.printStackTrace(System.err);
167173
}
168174
}
169175
}
170176
}
171177
j2sCompiler.finalizeProject();
172178
contexts = null;
173-
System.out.println(
174-
"J2S buildFinished " + ntotal + " file"+plural(ntotal) + " transpiled for " + project.getProject().getLocation());
179+
System.out.println("J2S buildFinished " + ntotal + " file" + plural(ntotal) + " transpiled for "
180+
+ project.getProject().getLocation());
175181
System.out.println("J2S buildFinished nerror = " + nerror + " " + new Date());
176-
}
182+
}
177183
isCleanBuild = false;
178184
}
179185

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,17 @@ boolean compileToJavaScript(IFile javaSource) {
390390
if (pt >= 0)
391391
packageName = packageName.substring(0, pt);
392392
if (!copyResources.contains(packageName)) {
393-
copyResources.add(packageName);
394-
String sourceDir = sourceLocation.substring(0, sourceLocation.lastIndexOf("/" + packageName + "/"));
395-
File src = new File(sourceDir, packageName);
396-
File dest = new File(j2sPath, packageName);
397-
copySiteResources(src, dest);
393+
copyResources.add(packageName);
394+
pt = sourceLocation.lastIndexOf("/" + packageName + "/");
395+
if (pt <= 0) {
396+
// also don't allow "" root directory
397+
System.out.println("J2S ignoring bad sourceLocation for package \"" + packageName + "\": " + sourceLocation);
398+
} else {
399+
String sourceDir = sourceLocation.substring(0, pt);
400+
File src = new File(sourceDir, packageName);
401+
File dest = new File(j2sPath, packageName);
402+
copySiteResources(src, dest);
403+
}
398404
}
399405
}
400406
return true;

0 commit comments

Comments
 (0)