Sunday 17 October 2010

FlexUnit from both FlashBuilder and FlexMojos for library projects

FlashBuilder leaves its FlexUnitTestRunnerUI files in "src".
For packaging:swf FlexMojos projects, that's fine (*1), it builds them.
*1: OK, it may not be all that fine but it doesn't cause failure.
For packaging:swc FlexMojos projects, they fail with "Type was not found" etc errors! How to fix, after the break...
The full error they fail with is:
[INFO] --- flexmojos-maven-plugin:4.0-SNAPSHOT:compile-swc (default-compile-swc) @ deleteinbuild ---

[INFO] Flexmojos 4.0-SNAPSHOT
[INFO]   Apache License - Version 2.0 (NO WARRANTY) - See COPYRIGHT file
Writing configuration dump to C:\Users\MyUser\Dev\Experiments\MavenDeleteInBuild\target\deleteinbuild-1.0-SNAPSHOT-configs.xml
C:\Users\MyUser\Dev\Experiments\MavenDeleteInBuild\src\FlexUnitApplication.mxml(33):  Error: Type was not found or was not a compile-time constant: FlexUnitTestRunnerUI.

        <flexui:FlexUnitTestRunnerUI id="testRunner">

C:\Users\MyUser\Dev\Experiments\MavenDeleteInBuild\src\FlexUnitApplication.mxml(18):  Error: Accessof undefined property SomeClassTest in package a.b.c.

                                testsToRun.push(a.b.c.SomeClassTest);

C:\Users\MyUser\Dev\Experiments\MavenDeleteInBuild\src\FlexUnitCompilerApplication.mxml(13):  Error: Type was not found or was not a compile-time constant: SomeClassTest.

                        private var a_b_c_SomeClassTest_obj:a.b.c.SomeClassTest;

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
To solve this, they need eliding from checkin and deleting at FlexMojos build-time if they exist.
<plugin>
  <artifactId>maven-clean-plugin</artifactId>
  <version>2.4.1</version>
  <configuration>
    <excludeDefaultDirectories>true</excludeDefaultDirectories>
    <failOnError>false</failOnError>
    <filesets>
      <fileset>
        <directory>${project.build.sourceDirectory}</directory>
        <includes>
          <include>FlexUnitApplication.mxml</include>
          <include>FlexUnitApplication-app.xml</include>
          <include>FlexUnitCompilerApplication.mxml</include>
        </includes>
        <followSymlinks>true</followSymlinks>
      </fileset>
    </filesets>
  </configuration>
  <executions>
    <execution>
      <id>remove FB FlexUnit-generated files</id>
      <phase>initialize</phase>
      <goals><goal>clean</goal></goals>
    </execution>
  </executions>
</plugin>
Note this also works with adding extra source directories if:
  1. They don't need similar tidying
  2. they're added in a later phase (e.g. generate-sources)
HTH!

UPDATE: This may cause problems with clean since they will run this execution rather than the default. Can supply extra changes if people are interested.

No comments:

Post a Comment