Flex and Ant: How do I include other folders via ant script? - apache-flex

I currently have a Flex project that was done in Eclipse, using the following compiler settings:
Flex Build Path: (Source Path) includes source folders from other areas, i.e common_components, which aren't projects on their own but just folders with various code I need to share. This works fine but I want to migrate to using ant.
I have read in places on how to include libraries, via compiler.include-libraries, but as this isn't a library but rather just bunch of folders with .as and MXML files, how do i accomplish this?

You want to look into adding source paths so that the compile can look at more than one place for your classes. You can do that by adding new compiler options.
The compiler option you're looking for is source-path path-element [...].

Related

How do I use compc to build a swc that dynamically links in Flex components?

In Flash Builder 4.6, when managing a Flex project, under the Build Path options for a Flex Library Project, I can select between "external" and "Merged into code" Framework linkage, with "external" being the default.
How can I use external linkage when calling compc directly?
It seems like compc by default puts the Flex components in the library-path section instead of in the external-library-path section (looking at the generated -dump-config file).
It seems like the option available in Flash Builder ought to be accessible through some option on compc or through some combination of arguments. I've looked through the compc options documentation and unfortunately have come up empty. Any help would be appreciated.
First have a look at the flex-config.xml file. You'll find it in [flex_sdk_path]/frameworks/flex-config.xml. Now find the nodes called runtime-shared-library-path. Here you'll find a list of all the libraries that will be merged when you compile with compc (the nodes are called runtime-shared-library-path because RSL is the default linkage when you use mxmlc). These are the files that you need to link externally.
You have two options to do this:
Create your own config file in which you translate all those runtime-shared-library-path nodes to external-library-path nodes. Load this file instead of the default by adding -load-config=my-config.xml to the compiler command.
Keep the default config file but override the linkage with command options. Simply add each swc to the external-library-path: -external-library-path+=libs/framework.swc and so forth.
When you compile an application with mxmlc though, the default linkage is RSL. You may want to override this too and make it 'merged'. In this case you'll first have to reset the RSL path: -runtime-shared-library-path= (that's right, nothing after the =). Then add each swc to the -library-path: -library-path+=libs/framework.swc
Alternatively (warning! shameless self-promotion on the way), you could use a build tool called GradleFx. If you create a build file with just this line:
type = 'swc'
it will compile your library with the framework linked externally. You can override this default if the need be:
type = 'swc'
frameworkLinkage = 'merged'

git + Flash Builder workflow: how do I set it up so git works smoothly?

I'm using git to track a project I'm developing in Flash Builder, and I'm wondering the best way to go about having it track it, especially regarding Flash Builder generated files, Compiler generated files, and source files that aren't necessarily flex files.
I had it set up to ignore all of the flash builder .project & debugging directories via .gitignore:
.actionScriptProperties
.flexProperties
.metadata
.project
.settings
bin-debug
and also treating any swf/swc files as binaries via .gitattributes
*.swf -crlf -diff -merge
*.swc -crlf -diff -merge
One issue with this setup is checking out this project and using
it in Flash Builder from scratch:
Flash Builder doesn't like it when
you have a project folder without
the .project files. Only way to
import the source into Flash Builder is to:
Create a new Flex Application
Smother the template files it
created (specifially APP_NAME.mxml)
with a git clone.
Where do I put libraries? From a git perspective, I'd like to have them in the lib folder of the repo so when someone clones the repo, everything just works, but from a local file system perspective I'd like to store all my libraries in a single location and use Flash Builder to reference them, as I may update the library or download a later version. Maybe I should put the libraries in their own repo and load them as a git module? This way I don't need to manually remember to update my Y library files in all X projects that are using them, edit: they will simply update when I update each projects' submodules.
And what about external swfs/flex modules? I've was sticking external swf files in the bin-debug folder for now so the SWFLoader class can find them, but because I'm .gitignoring the bin-debug folder, they don't come with the repo when it's cloned.
One final issue is where to keep the files for the server. Do I have them in a separate repo? I'm using php VOs' with AMFPHP so it's good to be able to edit the php files alongside my actionscript files in Flash Builder... but they don't belong in the project src folder.
The current solution I'm using is:
Creating a 'server' folder in the project root
Pointing an apache virtualhost at it
Setting the run/debug settings to http://APP_NAME.localhost
Then using the server folder as a replacement for bin-debug when the files get exported
The problem with this is I've got a big mess of compiler generated files, and non-AS source files in my server folder. It just doesn't seem like an elegant solution.
How do you set up git to work with flash builder smoothly? Could all this be resolved with multiple git repos/Flash Builder projects, or an ANT script or something?
Thanks.
I've found a good solution which avoids all of the horror of having untracked files and keeping a massive .ignore list:
CLEAN your projects before you git commit.
Simple as that.
Whether it be by Flash Builder or by ant, you should have the ability to clean anyway, so if you simply clean before you commit, the problem of generated files is solved. Duh.
In fact you could probably set it up as a git hook or something.
Typically for eclipse projects with any SCM, I initially check in everything including .projects, etc., but maybe except bin-debug in your case. Then just make sure that anybody who checks out the project never checks back in those .xxx files. For instance, when I use perforce, I first check out the .xxx files to a changelist that I never check in. Then check out the rest to a separate changelist.
Another tip is to use user defined library variables when working with build paths, etc.

How do you enforce dependencies among java folders in Netbeans?

I am new to Netbeans. I am wondering if someone can help me with project setup in netbeans. I am moving half million lines of Java code from a different IDE to Netbeans. I was able to get the code build and run in Netbeans easily. I have a project with many folders with dependencies among those folders. They have to be built in specific order. This is to enforce layering so that a module in lower layer cannot call into higher layers. I couldn't get that configured in Netbeans. Below is how my project looks like
project/
libA/
libB/
libC/
libD/
libE/
appA/
...
I have one project that builds all the libs and appA. The project build xml is stored under project/ folder. But the libs have dependencies among them. libB should be built after libA. libC after libA. libE depends on libD and libB etc.
I tried to change the order of source folders for libs in project properties. That didn't seem to make any difference. Even if I move libA after libB, it was building everything fine. I expected it to fail because libA didn't build yet.
Iam lost. Just wondering what the trick is to enforce this kind of dependencies. I created my project using "Java project using existing sources" wizard.
I appreciate your help
Thanks
Video guy.
Even though it would be a pain, you could just write your own ant build script and then just have Netbeans use that.
Basically:
write the custom ant build file
install the Ant plugin
create an Ant build file
right click the build file
run the selected target.
This would enable you to enforce whatever you need to do, but, if Netbeans is figuring out the correct order then why not just use it.
Does something break when you just compile and run in Netbeans?
Well! Lets say a team member added piece of code in lower level package that calls into higher layer code. It should fail because it breaks the layering. Because Netbeans seem to compile all the files in one javac invocation, the build compiles just fine. I want Netbeans to break the build in this case.
Writing my own ant script is another way of enforcing it. The whole point in using an IDE is to save yourself from writing your own make files (or ant scripts). This is something any IDE was able to accomplish 10 years back out of the box. I am wondering if I am missing something here.
Thanks
Video Guy

Post Build Actions in Flex Builder

How do I add post-build actions in Flex Builder? For example, I'd like my build to work as normal, and execute from the bin folder; but I'd also like a copy of the final SWF to be copied to another folder automatically (I'm sick of doing it myself).
Thanks!
I know this post has been answered, but I found something simpler. I'm sure the Ant solutions are the way to go, but I didn't feel like messing with ant for my small project. All I really want is to have my html files and swf files in different directories. I guess that's a lot to ask.
I'm building on windows, so I created a simple batch file that performs my post-build steps (namely some move commands). I then created a new builder in flex using windows cmd.exe. I just told it to call the batch file using the /C option. It works perfectly and was very simple to set up. I tried adding screen shots, but I guess I'm too new to the site.
You can extend or replace the builder used by Flex Builder 3 with extenal programs - ant is a good choice.
If you run "Flex Builder 3 standalone" (which is a minimalist Eclipse version + the Flex builder plugin) as opposed to the Flex builder plugin in a standard Eclipse, you first need to install ant support. I didn't find ant separately packaged, so I just selected the Java build environment from Help / Software Updates.
Now you can go to your project properties (Right-Click on your Project, Properties) and chose Builders. You'll notice there is a Flex Builder per default, which you cannot remove nor change. However, you can deselect it and you can add other builders.
So in your case: "add" a new builder, ant builder, select a build.xml (can be named differently), preferably from within your project folder, and set the correct targets. This will continue to use the internal IDE builder while running your ant task just before or afterwards. The ordering on the screen will be the build order, which you can change using the arrow buttons.
I used this to copy required libraries into my /lib folder, compile the Flex sources using the IDE build (which has Eclipse-integration with error messages, which a pure ant-based commandline build would miss), and copy the result to a common deploy directory, renaming the wrapper html file in this process.
For details of how to write an ant file, please refer to the ant documentation.
I would also recommend using ant.
I posted a big article on how to get it set up for flexbuilder here http://dispatchevent.org/mims/ant-for-flex-part-1/ I think there is even an example in my build script of copying files from one place to another after compiling.
Good luck!
You'll have to create a custom build script. For whatever reason, the included, default 'builder' is not editable through the interface, so you'll have to replicate a lot of its functionality. Luckily, (or maybe not) Flex Builder uses Apache Ant for its build scripts, so this may or may not be a familiar way to do this for you.
To create a custom build script:
In the Flex Navigator view, select a project and then right-click (Control-click on Macintosh) to display the context menu and select Properties.
Select the Builders properties page. If you're using other Eclipse plug-ins, there may be more than one builder listed. Flex Builder provides a builder named Flex, which you cannot modify.
Select New.
In the Choose Configuration Type dialog box, select the appropriate configuration type. Flex Builder supports the program type. Select it and click OK to continue. From the new builder properties page you define the builder properties and reference the Ant script (an XML file).
Click OK to apply it to the project.
Flex builder is based on Eclipse 3.1, so documentation for Ant integration for that release is relevant here.
Note: Ant support must be enabled in Flex Builder first. I usually use Flex Builder as a plugin, rather than the standalone version, and the standalone version doesn't come with it out of the box. Here's a tutorial on how to do this.
Steve,
If you want use Ant in Flex Builder, you may see:http://www.peterelst.com/blog/2006/09/03/flex-builder-2-ant-support/
but I am not sure this is work in flex builder 3 or not.
Steve,
Here is a bit more detail on the post build script. It will be a simple bat file. For instance add the below line to a simple text file postbuild.bat (name doesn't matter).
copy bin/*.* 'someother location'
This would copy everything in the bin folder to another folder, just change the 'someother location'.
The least elegant solution but it will work on linux.
Create cron task to be executed every minute.
Use cp command with "-u" option.
From "man cp".
-u, --update
copy only when the SOURCE file is newer than the destination
file or when the destination file is missing
In crontab -e add
* * * * * cp -u /path/to/bin-debug/*.swf /path/to/destination/
For more elegant solution - Ant the way to go.

Which files should go into source control in a Flex Builder project?

I noticed that Eclipse (Flex Builder) generates hundreds of metadata files. Should I check them into my source control? They seem necessary, because if I delete them Flex Builder just opens up an empty workbench...
Some of these files plainly do not belong in source control (like .history files and some cache files). If I delete them my project opens up again without a hitch. But the list is long and there seem to be no clear separation between folders that contain files that belong in source control and those that do not.
I can't just shove them all into svn, even if I were to ignore the inefficiency, because Eclipse generates new ones constantly, with different names, which in turn also seem to be crucial for the project to load.
Can someone please enlighten me?
Don't check in the hundreds of metadata files. If you want to be able to check out the project in a way that it can just be imported, then check in:
.actionScriptProperties
.project
.flexProperties
And "html-template" and "libs". As Christian says, any resources you depend on. I usually keep those as separate Flex Library projects though.
I generally put all of my source code under src, and I check in src and all of its descendents. If my project relies on any external dependencies (e.g., the Cairngorm SWC, as3corelib, etc.), Flash/graphical assets, stylesheets, or resource files, I check those in, too. But I don't check in any generated (bin-*), intermediate or IDE-specific stuff, because having that stuff in source control doesn't seem to provide much practical benefit, and in my experience has only caused me headaches; in general, I check in the most minimal set of whatever I'd need -- given a clean FlexBuilder installation (or none at all -- for example, if I were compiling instead with mxmlc or compc) and an empty project -- to build the project successfully.
Most of the eclipse project files, like .project, .properties, everything in .settings, can go into your source control. As long as the files don't have user-dependent settings like file paths or local urls, you should be fine.
One method we use is creating local property files that don't get used in SCM, but are included in the ones that do. I.E an ant build file including a local.properties file which has local metadata.
What if the .actionScriptProperties, .project, or .flexProperties have user-dependent stuff in them? Typically this will be url or path information. What's the best practice way of externalizing this? I tried creating path variables, but this only works obviously for paths. Not for things like hostname, etc.

Resources