22
33import java .io .BufferedReader ;
44import java .io .File ;
5+ import java .io .FileFilter ;
56import java .io .FileInputStream ;
67import java .io .FileNotFoundException ;
78import java .io .FileOutputStream ;
89import java .io .IOException ;
910import java .io .InputStreamReader ;
11+ import java .nio .file .Files ;
12+ import java .nio .file .StandardCopyOption ;
1013import java .util .ArrayList ;
14+ import java .util .HashSet ;
1115import java .util .Iterator ;
1216import java .util .List ;
1317import java .util .Properties ;
1418
1519import org .eclipse .core .resources .IContainer ;
1620import org .eclipse .core .resources .IProject ;
17- import org .eclipse .jdt .core .IMethod ;
18- import org .eclipse .jdt .core .IType ;
1921import org .eclipse .jdt .core .JavaCore ;
20- import org .eclipse .jdt .core .JavaModelException ;
2122import org .eclipse .jdt .core .dom .AST ;
2223import org .eclipse .jdt .core .dom .ASTParser ;
2324import org .eclipse .jdt .core .dom .CompilationUnit ;
@@ -40,14 +41,17 @@ public class Java2ScriptCompiler implements IExtendedCompiler {
4041
4142 // BH: added "true".equals(getProperty(props, "j2s.compiler.allow.compression")) to ensure compression only occurs when desired
4243 static final int JSL_LEVEL = AST .JLS8 ; // BH can we go to JSL 8?
43- private static boolean showJ2SSettings = true ; // BH adding this
44+
45+ private static boolean showJ2SSettings = true ;
46+ private static HashSet <String > copyResources = new HashSet <String >();
47+
4448 private static Properties props ;
4549 private static String htmlTemplate = null ;
4650
4751 public void process (ICompilationUnit sourceUnit , IContainer binaryFolder ) {
4852 final IProject project = binaryFolder .getProject ();
4953
50-
54+
5155 bhTest (project );
5256
5357 /*
@@ -98,12 +102,22 @@ public void process(ICompilationUnit sourceUnit, IContainer binaryFolder) {
98102
99103 if (htmlTemplate == null ) {
100104 String htmlTemplateFile = getProperty ("template.html" );
105+ //System.err.println("htmltemplate " + htmlTemplateFile);
101106 if (htmlTemplateFile == null )
102107 htmlTemplateFile = "template.html" ;
103- file = new File (siteFolder , htmlTemplateFile );
104- if (!file .exists ())
105- writeToFile (file , getDefaultHTMLTemplate ());
108+ //System.err.println("htmltemplate " + htmlTemplateFile);
109+ file = new File (prjFolder , htmlTemplateFile );
110+ //System.err.println("htmltemplate " + htmlTemplateFile);
111+ if (!file .exists ()) {
112+ String html = getDefaultHTMLTemplate ();
113+ System .err .println ("creating new htmltemplate\n " + html );
114+ writeToFile (file , html );
115+ }
106116 htmlTemplate = getFileContents (file );
117+ //System.err.println("htmltemplate:\n" + htmlTemplate);
118+
119+ if (showJ2SSettings )
120+ System .err .println ("using HTML template " + file );
107121 }
108122
109123 CompilationUnit root ;
@@ -241,8 +255,23 @@ public void process(ICompilationUnit sourceUnit, IContainer binaryFolder) {
241255 }
242256 }
243257 }
258+ String packageName = visitor .getPackageName ();
259+ if (packageName != null ) {
260+ int pt = packageName .indexOf ("." );
261+ if (pt >= 0 )
262+ packageName = packageName .substring (0 , pt );
263+ if (!copyResources .contains (packageName )) {
264+ copyResources .add (packageName );
265+ File src = new File (prjFolder + "/src" , packageName );
266+ File dest = new File (j2sPath , packageName );
267+ copySiteResources (src , dest );
268+ }
269+ }
244270 }
245271
272+ /**
273+ * @param project
274+ */
246275 private void bhTest (IProject project ) {
247276// IJavaProject jp = JavaCore.create(project);
248277// try {
@@ -266,20 +295,6 @@ private void bhTest(IProject project) {
266295//
267296 }
268297
269- private void showClass (IType t2c ) throws JavaModelException {
270- IMethod [] im = t2c .getMethods ();
271- if (im != null )
272- for (int i = 0 ; i < im .length ; i ++) {
273- IMethod m = im [i ];
274- System .err .print (m .getElementName () + " " + m .getSignature () + " " );
275- String [] mt = m .getParameterTypes ();
276- if (mt != null )
277- for (int j = 0 ; j < mt .length ; j ++)
278- System .err .print ("para " + mt [j ]);
279- System .err .println ("\n \n " );
280- }
281- }
282-
283298 /**
284299 * untested
285300 *
@@ -748,5 +763,47 @@ private static void addHTML(ArrayList<String> appList, String siteFolder, String
748763 }
749764 }
750765
766+ private static FileFilter filter = new FileFilter () {
767+
768+ @ Override
769+ public boolean accept (File pathname ) {
770+ return pathname .isDirectory () || !pathname .getName ().endsWith (".java" );
771+ }
772+
773+ };
774+
775+ private static void copySiteResources (File from , File dest ) {
776+ copyNonclassFiles (from , dest );
777+ }
778+
779+ private static void copyNonclassFiles (File dir , File target ) {
780+ if (dir .equals (target ))
781+ return ;
782+ File [] files = dir .listFiles (filter );
783+ File f = null ;
784+ if (files != null )
785+ try {
786+ if (!target .exists ())
787+ Files .createDirectories (target .toPath ());
788+ for (int i = 0 ; i < files .length ; i ++) {
789+ f = files [i ];
790+ if (f == null ) {
791+ //
792+ } else if (f .isDirectory ()) {
793+ copyNonclassFiles (f , new File (target , f .getName ()));
794+ } else {
795+ Files .copy (f .toPath (), new File (target , f .getName ()).toPath (),
796+ StandardCopyOption .REPLACE_EXISTING );
797+ System .err .println ("copied " + f + " to " + target );
798+ }
799+ }
800+ } catch (IOException e1 ) {
801+ // TODO Auto-generated catch block
802+ System .err .println ("error copying " + f + " to " + target );
803+ e1 .printStackTrace ();
804+ }
805+ }
806+
751807
752808}
809+
0 commit comments