2323import org .eclipse .jdt .core .dom .ASTParser ;
2424
2525import j2s .CorePlugin ;
26- import j2s .jmol .Java2ScriptLegacyCompiler ;
26+ import j2s .jmol .J2SLegacyCompiler ;
2727import j2s .swingjs .Java2ScriptSwingJSCompiler ;
2828
2929/**
@@ -84,10 +84,13 @@ public abstract class Java2ScriptCompiler {
8484
8585 abstract public boolean compileToJavaScript (IFile javaSource , String trailer );
8686
87- abstract protected String getDefaultJ2SFile ();
88-
8987 abstract public void finalizeProject ();
9088
89+ /*
90+ * To save a default file with comments specific to this transpiler.
91+ */
92+ abstract protected String getDefaultJ2SFileContents ();
93+
9194 /**
9295 * The name of the J2S options file, aka as the "Dot-j2s" file. Please do not
9396 * change this value.
@@ -99,7 +102,6 @@ public abstract class Java2ScriptCompiler {
99102 protected Properties props ;
100103
101104 protected String projectFolder ;
102- // protected String outputPath;
103105 protected String siteFolder ;
104106 protected String j2sPath ;
105107 protected String excludedPaths ;
@@ -114,6 +116,9 @@ public abstract class Java2ScriptCompiler {
114116
115117 protected IJavaProject project ;
116118
119+ protected int nResources ;
120+
121+
117122 /**
118123 * This will activate @j2sDebug blocks, at least in SwingJS
119124 */
@@ -158,7 +163,7 @@ public static Java2ScriptCompiler newCompiler(IJavaProject project, BuildContext
158163 File f = getJ2SConfigName (project , files [0 ]);
159164 return ( f == null ? null
160165 : J2S_CONFIG_JMOL .equals (j2stype = f .getName ()) ?
161- new Java2ScriptLegacyCompiler (f )
166+ new J2SLegacyCompiler (f )
162167 : J2S_CONFIG_SWINGJS .equals (j2stype ) ?
163168 new Java2ScriptSwingJSCompiler (f ) : null );
164169 }
@@ -271,10 +276,10 @@ protected boolean initializeProject(IJavaProject project, boolean isCleanBuild,
271276 return false ;
272277 }
273278 if (getFileContents (activeJ2SFile ).trim ().length () == 0 ) {
274- writeToFile (activeJ2SFile , getDefaultJ2SFile ());
279+ writeToFile (activeJ2SFile , getDefaultJ2SFileContents ());
275280 }
276281 int jslLevel = javaLanguageLevel ;
277- if (jslLevel == 8 ) {
282+ if (isSwingJS ) {
278283 // SwingJS allows 8 or 11
279284 try {
280285 String ver = getProperty (J2S_COMPILER_JAVA_VERSION , "" + jslLevel );
@@ -345,14 +350,17 @@ boolean excludeFile(IFile javaSource) {
345350 return excludeFile (javaSource .getFullPath ().toString ());
346351 }
347352
348- private boolean excludeFile (String filePath ) {
353+ public boolean excludeFile (String filePath ) {
349354 if (lstExcludedPaths != null ) {
355+ if (filePath == null )
356+ return true ;
350357 if (filePath .indexOf ('\\' ) >= 0 )
351358 filePath = filePath .replace ('\\' , '/' );
352- for (int i = lstExcludedPaths .size (); --i >= 0 ;)
359+ for (int i = lstExcludedPaths .size (); --i >= 0 ;) {
353360 if (filePath .indexOf (lstExcludedPaths .get (i )) >= 0 ) {
354361 return true ;
355362 }
363+ }
356364 }
357365 return false ;
358366 }
@@ -475,25 +483,24 @@ private int copyNonclassFiles(File dir, File target, int n) {
475483 return n ;
476484 }
477485
478- protected int checkCopiedResources (String packageName , String sourceLocation , String outputDir ) {
486+ protected void copyAllResources (String packageName , String sourceLocation ) {
479487 int pt = packageName .indexOf ("." );
480488 if (pt >= 0 )
481489 packageName = packageName .substring (0 , pt );
482490 if (copiedResourcePackages .contains (packageName ))
483- return 0 ;
491+ return ;
484492 copiedResourcePackages .add (packageName );
485493 pt = sourceLocation .lastIndexOf ("/" + packageName + "/" );
486494 if (pt <= 0 ) {
487495 // also don't allow "" root directory
488496 if (!"_" .equals (packageName ))
489497 System .out .println (
490498 "J2S ignoring bad sourceLocation for package \" " + packageName + "\" : " + sourceLocation );
491- return 0 ;
499+ return ;
492500 }
493- String sourceDir = sourceLocation .substring (0 , pt );
494- File src = new File (sourceDir , packageName );
495- File dest = new File (outputDir , packageName );
496- return copySiteResources (src , dest );
501+ File src = new File (sourceLocation .substring (0 , pt ), packageName );
502+ File dest = new File (j2sPath , packageName );
503+ nResources += copySiteResources (src , dest );
497504 }
498505
499506 protected String fixPackageName (String name ) {
0 commit comments