As Maven was designed by the principal: "Convention over Configuration" it makes sense to stick to the defaults configuration. In order to stick to it, you have to know about it. 

So here comes the default directory layout of a Flex project being built by Flexmojos:

pom.xml
src/main/flex
src/main/resources
src/main/locales/en_US
src/main/locales/de_DE
src/main/locales/...
src/test/flex
src/test/resources
 
target/classes
target/generated
target/generated-sources
target/surefire-reports
target/test-classes
target/test-classes/generated
target/test-classes/TestRunner.mxml
target/test-classes/TestRunner.swf
target/test-classes/TestRunner-configs.xml
target/test-classes/TestRunner-link-report.xml
target/test-classes/TestRunner-size-report.xml
target/{artifactId}-{version}.swc (or swf)
target/{artifactId}-{version}-configs.xml
target/{artifactId}-{version}-link-report.xml
target/{artifactId}-{version}-size-report.xml
target/fonts.ser

So in general there are two main directories: "src" which contains the sources and "target" which contains all the output the maven build creates during the build.

Source directories

Even if I should be fair and state that the default source directory in Maven is "src/main/java" and "src/test/java" and therefore you have to explicitly set them to "src/main/flex" and "src/test/flex" to have maven use these instead of the "java" versions. I strongly recommend to to that though.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>


	...
 
	<build>
	    <sourceDirectory>src/main/flex</sourceDirectory>
		<testSourceDirectory>src/test/flex</testSourceDirectory>
		...
	</build>
 
	...
 
</project>

The "src/main/resources" and "src/test/resources" contain static content, that is simply copied to the result (eventually making use of filtering which can replace variables in the content). In Flex applications I place xml-content, images, fonts and other static resources to that directory. Same as with Java projects, the content in the sourceDirectory doesn't get copied to the output but it get's fed into the compiler and the output that produces gets written to the output. That's a good rule of thumb to remember whenever you need to decide where to place something:

  • Flex code (.as or .mxml) gets processed by the compiler so it belongs into the source directory
  • CSS stylesheets get processed by the compiler, so they belong there too
  • Images don't get compiled, so they belong into the resources
  • static xml, text, whatsoever files don't get compiled so they belong into the resources
  • ...

With Flex it's not that 100% clear what get's compiled ... embedded resources for example usually get compiled into the output, same with fonts. I usually stick to the question "is it code or css?".

Besides the source and resources directories you could see several directories inside the "locales" directory. This is a speciality of Flexmojos and Flex. It allows to provide I18N resources for several locales. In the above example there is one directory for default english "en_US" and one for german "de_DE" resources. 

I think you could probably provide language resources for test code, but I have to admit that I have never even thought about trying that (wink) feel free to experiment here. 

Output directories

As several parts of the Maven build produce different output the content of the "target" directory is a little more confusing as the input, but in general you only need:

target/{artifactId}-{version}.swc (or swf)

Which is the output of the maven build. The rest is just meta-information, reports and intermediate code.

Let's dig through the other parts:

First thing to notice is that wherever the Flex compiler produces an SWC or SWF it creates 3 additional xml files:

  • {name}-configs.xml
  • {name}-link-report.xml
  • {name}-size-report.xml

The "{name}-configs.xml" actually represents the configuration file that the Flex compiler reads in order to know what it has to do. It contains all the configuration information that is needed to perform the compilation

link- and size-report.xml are output by the compiler during compilation. the link-report.xml contains information about which class in the compiled code is located where (byte position in the binar output) and which other classes it references. This is used by the linker when creating an SWF for example, to know which classes it has to include in the output he creates and it can be used for optimizing the size of some libraries (For example if you have a loader application that already links in a lot of base classes, you can tell the flex compiler to omit these from modules that will be loaded by that loader dramatically reducing the size of the modules output).

The size report simply contains a list of classes and resources that are compiled into the output and how big they are.

In general you can probably completely ignore these three file types. You will probably never really need them. But if you should be having problems compiling or at runtime or want to start optimizing the size or performance of your artifacts, it doesn't hurt to have a look here.

The "classes" directory simply contains the resources of the "src/main/resources" directory, eventually processed by Maven filters. The stuff in here is the version available to be statically accessed from your flex code (Images, static text or binary resources, ...

The "generated" directory contains the code the compiler generates. As in general only ActionScript code can be compiled to SWC or SWF, the Flex compiler generates ActionScript code from any CSS or MXML file it processes. Same as with the xml files produced by the build you will actually never have to look in here, except if you are having problems. Then this directory is a valuable source of information to find out what's going wrong.

The "generated-sources" directory contains code generated by parts of the Maven build. In my projects for example I have a lot of code generated from Java model classes by Flexmojos granite generator. The code this generator creates is located in "target/generated-sources/flexmojos". I am also a freak regularly using Antlr to produce parsers based on grammar files, this code is generated to "target/generated-sources/antlr3".

In the end the source directories that are passed to the compiler are:

  • src/main/flex
  • target/generated
  • target/generated-sources/flexmojos
  • target/generated-sources/antlr3

The test-classes have a similar structure inside the "target/test-classes" directory.

Unit-tests in Maven are usually executed by Surefire and output of that is usually located in "target/surefire-reports" and tools such as CI servers know where to get unit test-results. When executing Flex based unit-tests with Flexmojos, Flexmojos generates a test-runner in "target/test-classes/TestRunner.mxml". The output the unit-test execution is written to the "surefire-reports" directory in the same format as Surefire would making it easy for CI server to pick up the results.

The last part I haven't explained is the "target/fonts.ser" file. This is simply an intermediate file the Flex compiler creates ("File containing system font data produced by flex2.tools.FontSnapshot"). You can generally ignore this (wink)

  • No labels