Why isn't my standard RSL being loaded? - actionscript

I've created a modular application where a parent SWF loads a number of other SWFs on demand. For optimization, I've created a standard RSL.
I've compiled common code into a swc, and recompiled the application swfs to reference this swc, using the following in my build.xml ANT task (for each swf in my application):
<static-link-runtime-shared-libraries>false</static-link-runtime-shared-libraries>
<runtime-shared-library-path path-element="${lib.loc}/RSL.swc">
<url rsl-url="RSL.swf"/>
</runtime-shared-library-path>
I've extracted RSL.swf from RSL.swc and put this on my webserver in the same directory as the application swfs and container html file.
Now when I load my application, I get the message:
VerifyError: Error #1014: Class mx.core:BitmapAsset could not be found.
I can see this class included in the classes in RSL.swc / RSL.swf.
I've used fiddler to observe what is happening and I can see my Application swf file is loaded, but no attempt is made to get the RSL.swf.
Having set up the Application.swf file to use RSLs, I would have expected it to attempt loading RSL.swf before initialising, however this doesn't happen. Can anyone suggest why?

From http://livedocs.adobe.com/flex/3/html/help.html?content=rsl_02.html:
"You cannot use RSLs in ActionScript-only projects if the base class is Sprite or MovieClip. RSLs require that the application's base class, such as Application or SimpleApplication, understand RSL loading."
As my base class was Sprite, I had this error.
In my case, it was better to compile all the required classes into my Application swf file, using the following steps:
use compc to create a SWC with the files I want to include in my Application swf file
use mxmlc with include-libraries pointing to the SWC file to include. Generate a linked file report (xml) using link-report
compile each additional child swf with load-externs pointing to the linked file report (xml) - this excludes the files linked to the Application.swf from being compiled into each of the child swfs
To achieve step 1:
<!-- We define the global classes which will be compiled into the parent Application
swf, but excluded from the tool swfs. As pure actionscript projects with base
class of Sprite can't usually use RSLs, we are forcing these classes to be loaded
into the parent application, and excluded from the child applications, allowing an
"Rsl-like" optimisation -->
<fileset id="rsl.inclusions" dir="${main.src.loc}">
<include name="${main.src.loc}/path1/**/*.as"/>
<include name="${main.src.loc}/path2/**/*.as"/>
...
</fileset>
<pathconvert property="rsl.classes" pathsep=" " refid="rsl.inclusions">
<chainedmapper>
<globmapper from="${main.src.loc}\*" to="*"/>
<mapper type="package" from="*.as" to="*"/>
</chainedmapper>
</pathconvert>
<!-- Compile SWC -->
<compc output="${lib.loc}/MySwc.swc"
include-classes="${rsl.classes}">
<static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
<source-path path-element="${main.src.loc}"/>
</compc>
To achieve step 2:
<mxmlc file="${main.src.loc}/pathToApp/Application.as"
output="${bin.loc}/Application.swf"
debug="${debug}"
use-network="true"
link-report="WorkbenchLinkReport.xml"
fork="true">
<compiler.source-path path-element="${main.src.loc}" />
<static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
<include-libraries dir="${lib.loc}" append="true">
<include name="MySwc.swc" />
</include-libraries>
</mxmlc>
To achieve step 3:
<mxmlc file="${main.src.loc}/pathToChildSwf1/Child1.as"
output="${bin.loc}/Child1.swf"
debug="${debug}"
load-externs="WorkbenchLinkReport.xml"
fork="true">
<compiler.source-path path-element="${main.src.loc}" />
<static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
<compiler.headless-server>true</compiler.headless-server>
</mxmlc>
Another handy tip: using fork="true" prevents the Java VM running out of memory where many swfs are being compiled.
Hope this is helpful!

Related

In ant, how does one create and use a 'library' of targets?

To eliminate redundancy in my ant build.xml files, I decided out-factor the repeated targets into mytargets.xml file, publish it to to the artifact repository, and then import it in the following way:
<import>
<url url="http://mycompany.com/artifacts/mycompany.com/mytargets/1.2.3/mytargets-1.2.3.xml"/>
</import>
There are two things I don't like about this approach:
mytargets-1.2.3.xml never appears anywhere on the disk where I can easily look at it.
I absolutely need access to http://mycompany.com/artifacts in order to do anything in the project---it completely undermines offline work.
So, I tried creating a setup target to fetch a local copy of mytargets.xml and adjusted my <import> to use this local copy.
<import file="${basedir}/antlib/mytargets/mytargets.xml"/>
However, as you have probably guessed, I cannot even execute my setup my target after adjusting my <import> in this way because the file does not yet exist:
Buildfile: /home/me/myproject/build.xml
BUILD FAILED
/home/me/myproject/build.xml:265: Cannot find /home/me/myproject/antlib/mytargets/mytargets.xml imported from /home/me/myproject/build.xml
Adding optional="true" to the <import> only defers the problem to the first target that depends upon mytargets.xml.
I looked at https://ant.apache.org/manual/Types/antlib.html, but this approach does not appears to permit you to define a <target>.
So, how does someone share bits of ant XML across multiple projects? Am I already doing it the 'one true way'? Or, is there a better way?
If you're mainly just trying to avoid download the remote copy when you have a local copy already available, you can try something like this:
<condition property="mytargets.xml.available">
<available file="${basedir}/antlib/mytargets/mytargets.xml" />
</condition>
<target name="setup" unless="mytargets.xml.available">
<get
src="http://mycompany.com/artifacts/mycompany.com/mytargets/1.2.3/mytargets-1.2.3.xml"
dest="${basedir}/antlib/mytargets"
/>
</target>
<target name="main" depends="setup">
<import file="${basedir}/antlib/mytargets/mytargets.xml" />
...
</target>
So, it seems to me that <target> is inherently local and not intended for reuse. On the other hand, <macrodef> appears intended for reuse.
Here is the 'library', mymacros.xml:
<?xml version="1.0"?>
<antlib>
<macrodef name="mymacro">
...
</macrodef>
</antlib>
Here is the client, myproject/build.xml:
<?xml version="1.0"?>
<project name="myproject">
<target name="mytarget">
<mymacro/>
</target>
<taskdef file="mymacros.xml"/>
</project>
Unlike <import> and <include>, <taskdef> will not cause the build to fail immediately if mymacros.xml is missing, which gives you the opportunity to download it.

yguard not updating properties file in the jar

I have jar file having some properties files in it like log4j.properties and config.properties. Following is my ant script for yguard. Everything else is working but the properties file updation.
<target name="yguard">
<taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" classpath="lib/yguard.jar" />
<yguard>
<inoutpairs resources="none">
<fileset dir="${basedir}">
<include name="MyApp.jar" />
</fileset>
<mapper type="glob" from="MyApp.jar" to="MyAppObs.jar" />
</inoutpairs>
<externalclasses>
<pathelement location="lib/log4j-1.2.17.jar" />
</externalclasses>
<rename conservemanifest="true" mainclass="com.amit.Application" >
<adjust replaceContent="true" >
<include name="**/*.properties" />
</adjust>
</rename>
</yguard>
</target>
config.properties file
com.amit.Application.param1 = something
I found some question in stackoverflow but they didn't help. One place it was mentioned that the file (like jsp, xml, properties) should be in the jar file which I already have. But my yguard obfuscated file just get the files copied as it is.
I tried many combinations with rename & adjust tags but nothing worked for me.
Following post I already visited
Is it possible to manage logs through Obfuscation with yGuard?
How to include obfuscated jar file into a war file
Apparently you want yGuard to obfuscate the name of the field param1, because com.amit.Application is obviously your entry point and yGuard excludes the given main class automatically. So basically you want the outcome to be something like
com.amit.Application.AÖÜF = something
This isn't possible, because yGuard can only adjust class names in property files, as state here: yGuard Manual

JaCoCo report looks correct but can not view source

I am new to JaCoCo and trying to figure out why the html report that I am generating is not linked with my source.
The coverage numbers look correct and I can browse down to each class and then each method but I can not see the source. I have tried many different things inside the sourcefiles tag but nothing is working. Has anyone else had this issue? Here is a snippet of my ant script:
...
<test name="test.fw.UITestSuite" todir="${logdir}"/>
</junit>
</jacoco:coverage>
<fail if="TestFailed" status="1" message="UI junit test failure detected"/>
<echo message="${src}"/>
<jacoco:report>
<executiondata>
<file file="jacoco.exec"/>
</executiondata>
<structure name="UI">
<classfiles>
<fileset dir="${build}/fw"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="fw" includes="**./*.java"/>
</sourcefiles>
</structure>
<html destdir="report"/>
</jacoco:report>
</target>
...
Your fileset definition seems odd.
The include must be (the first . is misplaced):
includes="**/*.java
Try simply pointing it to the root of your src dir (there is no need for the includes)
<fileset dir="fw" />
But fw has to be the root of your sources, i.e. it contains the package folders like:
src
-org
-module
-MyClass1.java
-MyClass2.java
I’ve seen this break when using Scala-style package directory names, e.g.,
src/main/java/com.example.foo.bar/Foo.java
for fewer levels of nesting, faster autocompletion, &c., compared to the standard
src/main/java/com/example/foo/bar/Foo.java
Most tools support the first version just fine, but usually if you try it out and everything works fine, by the time you notice something like the jacoco reports not showing the source anymore, you’ve long forgotten the directory name change …

iajc and aspectpath

I'm a bit confused with the aspectpath option of the iajc compiler.
My project use AspectJ to weave metric code into an existing swing application.
All the application source are packaged this way:
com.xxx.yyy.myapp.*
We have put our aspect in a package inside the same project:
com.xxx.yyy.aop.*
The project is built with javac first and the outpout goes into ${classes.dir}.
Then we invoke iacj this way:
<iajc inpath="${classes.dir}"
destDir="${classes.dir}"
fork="true"
maxmem="${aspectj.maxmem}"
verbose="true"
showWeaveInfo="true"
debug="true"
source="1.6"
target="1.6">
<classpath refid="ajclasspath"/>
</iajc>
and
<path id="ajclasspath">
<path refid="classpath"/>
<pathelement location="${scm.home}/ant_libs/aspectjrt.jar"/>
</path>
With that said, do i need to specify an aspectpath in the iajc?
Regards
According to documentation similar to classpath, aspectpath contains read-only, binary aspect libraries that are woven into sources but not included in the output. In your case you include your aspects in output and they are in ${classes.dir} with normal classes.
So you don't have to specify aspectpath when you don't want to separate your aspects.

How to strip one folder during Ant copy

I have a file which has filepaths like "LibraryX/A/Stuff/FileY.txt", which I'm using as includesfile in Ant build. However, I'm in need of removing the "LibraryX/A/" part of the path DURING the copy process: The file gets copied from "LibraryX/A/Stuff/FileY.txt" and lands into "Stuff/FileY.txt". I've looked into few regexpmappers but haven't had any success with them at all. :/
The purpose for this is that the target folder can have custom files in "Stuff/MoreStuff" overwritten, and I want to use the overwrite="false" to keep the disk access into minimum and keeping the custom files intact.
Ant:
<copy todir="C:/targetdir/" overwrite="false">
<fileset dir="C:/sourcedir/">
<includesfile name="C:/targetdir/includes.file" />
</fileset>
</copy>
Includes.file:
LibraryX/A/Stuff/FileA.txt
LibraryX/A/Stuff/FileB.txt
LibraryX/A/Stuff/FileC.txt
LibraryX/A/Stuff/FileY.txt
Sourcedir:
sourcedir/LibraryX/A/Stuff/FileA.txt
sourcedir/LibraryX/A/Stuff/FileB.txt
sourcedir/LibraryX/A/Stuff/FileC.txt
sourcedir/LibraryX/A/Stuff/FileY.txt
Target dir:
targetdir/Stuff/FileY.txt
Now, all the files in Stuff -folder at sourcedir, should end into the Stuff -folder in targetdir. But how?
Bonus: If I move the files from "targetdir/LibraryX/A/Stuff", they will overwrite everything in the "targetdir/Stuff" folder, even with the overwrite="false". Presumably because they are newer files than the ones in the Stuff folder currently.
Note: I could, of course, move the custom files away from the target directory, copy the stuff over and then move the custom files back, overwriting the new ones. But this accesses the disk quite a lot, slowing down the process.
Starting with Ant v1.8.2 you can use the cutdirsmapper to strip some number of leading directories from file paths. See the very bottom of the mapper type docs.
<copy todir="C:/targetdir/" overwrite="false">
<fileset dir="C:/sourcedir/">
<includesfile name="C:/targetdir/includes.file" />
</fileset>
<cutdirsmapper dirs="2"/>
</copy>
Bonus: You could use the touch ant task to make all the files in targetdir newer than all the source files and therefore prevent them from being overwritten.

Resources