|
| 1 | +<project name="JSmol" default="toJs" basedir="."> |
| 2 | + |
| 3 | + <!-- |
| 4 | + |
| 5 | + An important issue with SwingJS is that it requires several hundred Java |
| 6 | + classes to be loaded. While in development mode this may be no problem, |
| 7 | + it is not desirable for distribution. |
| 8 | + |
| 9 | + To solve this problem, SwingJS is designed to read one or more "core" |
| 10 | + files when loading. (And, in the future, when accessing specific packages |
| 11 | + or classes, but that work has not been completed, as of 2019.05.) |
| 12 | + |
| 13 | + The core file is simply a Google Closure Compiler minified concatenation |
| 14 | + of all or most of the files needed for your application. This compiler is |
| 15 | + in the tools folder you need to have copied to your project from the |
| 16 | + sources/net.sf.j2s.java.core/dist directory of the java2script GitHub project. |
| 17 | + |
| 18 | + This ANT task, build-core.xml, creates a core file in site/swingjs/j2s/core/ |
| 19 | + with the name core_xxx.js and its minified version, core_xxx.z.js, where you |
| 20 | + can indicate what "_xxx" is, below. (The _ is not significant, but I recommend it.) |
| 21 | + |
| 22 | + This core file can be used to replace coreswingjs.z.js in the default |
| 23 | + loading sequence. SwingJS will look for the value of the Info.core |
| 24 | + key passed to the system from the HTML page. Possible values: |
| 25 | + |
| 26 | + core: "none" // do not use any core files - useful for debugging and core construction |
| 27 | + core: null // (or just no "core" entry) - use coreswingjs.z.js |
| 28 | + core: "_xxx" // use my created core_xxx.z.js file |
| 29 | + |
| 30 | + Creating a customized core_xxx file |
| 31 | + - - - - - - - - - - - - - - - - - - |
| 32 | + |
| 33 | + 1) Prepare _j2sclasslist.txt, a list of site/swingjs/j2s files for inclusion. |
| 34 | + |
| 35 | + You can do this by: |
| 36 | + |
| 37 | + a) Just creating it by hand. |
| 38 | + b) Fully exercizing your application via the site/*.html file |
| 39 | + that is produced by the j2s transpiler and based on template.html |
| 40 | + in your project directory, then clicking the get _j2sclasslist.txt link. |
| 41 | + c) appending to the _j2sclasslist.txt that was used to create coreswingjs.z.js |
| 42 | + (provided in the distribution). |
| 43 | + d) Some combination of the above, or any other process of your design. |
| 44 | + |
| 45 | + _j2sclasslist.txt can have duplicate entries. build-core.xml will ignore the duplicates. |
| 46 | + |
| 47 | + If you need to, you can provide every file needed by your application |
| 48 | + in _j2sclasslist.txt. However, that is not really necesssary if you are willing to |
| 49 | + put the full swingjs/j2s directory on your site, allowing occasional additional |
| 50 | + classes to be loaded on demand. It's totally up to you. |
| 51 | + |
| 52 | + 2. Edit build-core.xml, providing a meaningful core.name parameter, such as "_project". |
| 53 | + |
| 54 | + 3. Run build-core.xml. This will create the swingjs/j2s/core/ file. |
| 55 | + |
| 56 | + 4. In your HTML5 file, indicate |
| 57 | + |
| 58 | + Info = { |
| 59 | + ... |
| 60 | + core: "_project", |
| 61 | + ... |
| 62 | + } |
| 63 | + |
| 64 | + If you change the project template.html file to this and then do a |
| 65 | + Project...Clean Build, all the test html files in site/ will be updated. |
| 66 | + |
| 67 | + That's it! |
| 68 | + |
| 69 | + If you want to not use the core at any time during testing, add |
| 70 | + |
| 71 | + ?j2snocore |
| 72 | + |
| 73 | + to the URL. |
| 74 | + |
| 75 | + If you want to see all the files being loaded, just to see if anything unexpected |
| 76 | + is being loaded, use |
| 77 | + |
| 78 | + ?j2sverbose |
| 79 | + |
| 80 | + Any combination of these is fine, either in the query or the # reference: |
| 81 | + |
| 82 | + ?j2snocore j2sverbose |
| 83 | + |
| 84 | + or |
| 85 | + |
| 86 | + #j2snocore,j2sverbose |
| 87 | + |
| 88 | + for example. |
| 89 | +
|
| 90 | + Bob Hanson hansonr@stolaf.edu 2015.05.11 |
| 91 | + |
| 92 | + --> |
| 93 | + |
| 94 | + <property name="core.name" value="_project" /> |
| 95 | + |
| 96 | + |
| 97 | + <property name="j2s.class.list.file" value="_j2sclasslist.txt" /> |
| 98 | + <property name="site.path" value="site/swingjs" /> |
| 99 | + |
| 100 | + <target name="toJs" id="toJs"> |
| 101 | + |
| 102 | + <!-- create a NON svn local directory only containing JS files |
| 103 | + |
| 104 | + <echo>Deleting the site directory.</echo> |
| 105 | + <delete quiet="true" dir="site" /> |
| 106 | + --> |
| 107 | + |
| 108 | + <!-- make core files --> |
| 109 | + |
| 110 | + <echo>creating and compressing core files - warnings are OK; "does not exist" is trouble</echo> |
| 111 | + <echo>reading core class list from file coreclasses</echo> |
| 112 | + <loadresource property="coreclasses"> |
| 113 | + <file file="${j2s.class.list.file}"/> |
| 114 | + </loadresource> |
| 115 | + <resourcecount property="line.count" count="0" when="eq"> |
| 116 | + <tokens> |
| 117 | + <concat> |
| 118 | + <filterchain> |
| 119 | + <tokenfilter> |
| 120 | + <stringtokenizer delims="${line.separator}" /> |
| 121 | + </tokenfilter> |
| 122 | + </filterchain> |
| 123 | + <propertyresource name="coreclasses" /> |
| 124 | + </concat> |
| 125 | + </tokens> |
| 126 | + </resourcecount> |
| 127 | + <echo message="${j2s.class.list.file} has ${line.count} unique lines" /> |
| 128 | + |
| 129 | + <!-- not including core/coreswingjs.js --> |
| 130 | + |
| 131 | + <antcall target="call-core"> |
| 132 | + <param name="call-core.name" value="${core.name}" /> |
| 133 | + <param name="call-core.list" value=" |
| 134 | + ${coreclasses} |
| 135 | + " /> |
| 136 | + </antcall> |
| 137 | + |
| 138 | + |
| 139 | + </target> |
| 140 | + |
| 141 | + |
| 142 | + <target name="call-core" id="call-core"> |
| 143 | + <echo>......Creating core${call-core.name}.js</echo> |
| 144 | + <concat destfile="${site.path}/js/core/tmp.js"> |
| 145 | + <filelist dir="${site.path}/j2s" files="${call-core.list}" /> |
| 146 | + </concat> |
| 147 | + |
| 148 | + <replace dir="${site.path}/js/core" includes="tmp.js" token="Clazz." value="Clazz_"/> |
| 149 | + <replace dir="${site.path}/js/core" includes="tmp.js" token="Clazz__" value="Clazz._"/> |
| 150 | + <echo>......Generating ${site.path}/j2s/core/core${call-core.name}.js</echo> |
| 151 | + <concat destfile="${site.path}/j2s/core/core${call-core.name}.js"><filelist dir="${site.path}/js" files=" |
| 152 | + core/coretop2.js |
| 153 | + core/tmp.js |
| 154 | + core/corebottom2.js |
| 155 | + " /> |
| 156 | + </concat> |
| 157 | + <echo>......Generating ${site.path}/j2s/core/core${call-core.name}.z.js</echo> |
| 158 | + <java jar="jars/closure_compiler.jar" fork="true" dir="${site.path}/j2s/core" failonerror="false"> |
| 159 | + <arg line="--js core${call-core.name}.js --js_output_file core${call-core.name}.z.js" /> |
| 160 | + </java> |
| 161 | + <delete quiet="true" file="${site.path}/js/core/tmp.js" /> |
| 162 | + <length file="${site.path}/j2s/core/core${call-core.name}.z.js" property="core.length"/> |
| 163 | + <echo>... ${site.path}/j2s/core/core${call-core.name}.z.js created [${core.length} bytes]</echo> |
| 164 | + </target> |
| 165 | + |
| 166 | + |
| 167 | + |
| 168 | +</project> |
0 commit comments