public class Application extends Object implements Builder
Application
class represents a Flex application. It implements the Builder
interface
which allows for building the application incrementally. There are many ways to define
a Flex application. The most common way is specify the location of the target source file
on disk:
Application app = new Application(new File("MyApp.mxml"));Before the
Application
object starts the compilation, it must be configured. The most common methods that the client
calls are setLogger()
, setConfiguration()
, and setOutput()
.
A logger must implement flex2.tools.oem.Logger
and use the implementation as the Logger
for the compilation. The following is an example Logger
implementation:
app.setLogger(new flex2.tools.oem.Logger() { public void log(Message message, int errorCode, String source) { System.out.println(message); } });To specify compiler options for the
Application
object, the client
must get a Configuration
object populated with default values. Then, the client can set
compiler options programmatically.
The setOutput()
method lets clients specify where the Application
object should write
the output to. If you call the setOutput()
method, the build(boolean)
method builds and
writes directly to the location specified by the setOutput()
method. For example:
app.setOutput(new File("MyApp.swf")); app.build(true);If you do not call the
setOutput()
method, the client can use the build(OutputStream, boolean)
method
which requires the client to provide a buffered output stream. For example:
app.build(new BufferedOutputStream(new FileOutputStream("MyApp.swf")), true);Before the
Application
object is thrown away, it is possible to save the compilation
data for reuse by using the save(OutputStream)
method. Subsequent compilations can use the
load(OutputStream)
method to get the old data into the Application
object.
app.save(new BufferedOutputStream(new FileOutputStream("MyApp.incr")));When a cache file (such as
MyApp.incr
) is available from a previous compilation, the client can
call the load(OutputStream)
method before calling the build(boolean)
method. For example:
app.load(new BufferedInputStream(FileInputStream("MyApp.incr"))); app.build();The
build(false)
and build(OutputStream, false)
methods always rebuild the application. If the Application
object is new, the first build(true)/build(OutputStream, true)
method call performs a full build, which
is equivalent to build(false)/build(OutputStream, false)
, respectively. After a call to the clean()
method,
the Application
object always performs a full build.
The clean()
method not only cleans up compilation data in the Application
object, but also the output
file if the setOutput()
method was called.
The Application
class also supports building applications from a combination of source
files from the file system and in-memory, dynamically-generated source objects. The client
must use the Application(String, VirtualLocalFile)
or Application(String, VirtualLocalFile[])
constructors.
The Application
class can be part of a Project
. For more information, see the Project
class's description.
Configuration
,
flex2.tools.oem.Project
Modifier and Type | Field and Description |
---|---|
protected PathResolver |
resolver |
Constructor and Description |
---|
Application()
Constructor.
|
Application(File file)
Constructor.
|
Application(File file,
LibraryCache libraryCache)
Constructor.
|
Application(VirtualLocalFile file)
Constructor.
|
Application(VirtualLocalFile[] files)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
long |
build(boolean incremental)
Builds the object.
|
long |
build(OutputStream out,
boolean incremental)
Builds the object.
|
void |
clean()
If you called the
setOutput() method, this method
deletes the Application or Library
file. |
protected int |
compile(boolean incremental)
Compiles the
Application object. |
ApplicationCache |
getApplicationCache()
Returns the cache of sources in the source list and source
path.
|
Benchmark |
getBenchmark()
Gets the overall performance data for the last build.
|
Map<String,PerformanceData[]> |
getCompilerBenchmarks()
Gets the performance data for each compiler phase for the last build.
|
Configuration |
getConfiguration()
Gets the compiler options for this object.
|
Configuration |
getDefaultConfiguration()
Gets the default compiler options.
|
Logger |
getLogger()
Gets the logger for this object.
|
File |
getOutput()
Gets the output destination.
|
Report |
getReport()
Reports information about the current compilation.
|
LibraryCache |
getSwcCache()
Get the cache of swcs in the library path.
|
long |
link(OutputStream output) |
void |
load(InputStream in)
Loads compilation data from a previous compilation.
|
long |
save(OutputStream out)
Saves the current compilation data.
|
void |
setApplicationCache(ApplicationCache applicationCache)
Sets the cache for sources in the source list and source path.
|
void |
setConfiguration(Configuration configuration)
Sets the compiler options for this object.
|
void |
setLogger(Logger logger)
Sets the logger for this object.
|
void |
setOutput(File output)
Sets the location of the compiler's output.
|
void |
setPathResolver(PathResolver resolver)
Sets the path resolver for this object.
|
void |
setProgressMeter(ProgressMeter meter)
Sets the progress meter for this object.
|
void |
setSupportedFileExtensions(String mimeType,
String[] extensions)
Sets the custom file extensions for this object.
|
void |
setSwcCache(LibraryCache libraryCache)
Set the cache for swcs in the library path.
|
void |
stop()
Stops the compilation.
|
protected PathResolver resolver
public Application(File file) throws FileNotFoundException
file
- The target source file.FileNotFoundException
- Thrown when the specified source file does not exist.public Application(File file, LibraryCache libraryCache) throws FileNotFoundException
file
- The target source file.libraryCache
- A reference to a LibraryCache object. After
building this Application object the cache may be saved
and used to compile another Application object that uses
a similar library path.FileNotFoundException
- Thrown when the specified source file does not exist.public Application(VirtualLocalFile file)
file
- An in-memory source object.public Application(VirtualLocalFile[] files)
files
- An array of in-memory source objects. The last element in the array is the target source object.public Application()
public void setConfiguration(Configuration configuration)
Builder
getDefaultConfiguration()
method to get a Configuration
object.setConfiguration
in interface Builder
configuration
- An instance of an object that implements the Configuration
interface.Configuration
public Configuration getDefaultConfiguration()
Builder
flex-config.xml
file. You can override the default values by using methods of the Configuration
interface.
This method returns the default compiler options in new Configuration
objects.
getDefaultConfiguration
in interface Builder
Configuration
interface.Configuration
public Map<String,PerformanceData[]> getCompilerBenchmarks()
Builder
getCompilerBenchmarks
in interface Builder
public Benchmark getBenchmark()
Builder
getBenchmark
in interface Builder
public Configuration getConfiguration()
Builder
getDefaultConfiguration()
method,
this method returns null
if the setConfiguration()
method was not called.getConfiguration
in interface Builder
Configuration
interface.Configuration
public void setLogger(Logger logger)
Builder
public Logger getLogger()
Builder
null
if the setLogger()
method was not called.public void setOutput(File output)
build(boolean)
method.
If you use the build(OutputStream, boolean)
method, in which an output stream
is provided, there is no need to use this method.output
- An instance of the java.io.File
class.public File getOutput()
null
if the setOutput()
method was not called.public void setSupportedFileExtensions(String mimeType, String[] extensions)
Builder
setSupportedFileExtensions(flex2.compiler.util.MimeMappings.MXML, new String[] {".foo"});This example instructs the compiler to treat files with the
*.foo
extension as MXML documents.
The supported MIME types are specified in the flex2.compiler.util.MimeMappings
class as constants.setSupportedFileExtensions
in interface Builder
mimeType
- MIME type.extensions
- An array of file extensions.public void setProgressMeter(ProgressMeter meter)
Builder
setProgressMeter
in interface Builder
meter
- An object that implements the ProgressMeter
interface.ProgressMeter
public void setPathResolver(PathResolver resolver)
Builder
setPathResolver
in interface Builder
resolver
- A path resolverPathResolver
public long build(boolean incremental) throws IOException
Builder
incremental
input argument is false
,
this method recompiles all parts of the object. If the incremental
input argument is true
,
this method compiles only the parts of the object that have changed since the last compilation.
You must call the setOutput()
method before calling this method. The result is saved to the location
specified by the getOutput()
method. If there is no output destination specified, this method
does nothing and returns 0
.
build
in interface Builder
incremental
- If true
, build incrementally; if false
, rebuild.IOException
- Thrown when an I/O error occurs during compilation.Application
,
Library
public long build(OutputStream out, boolean incremental) throws IOException
Builder
incremental
input argument is false
,
this method recompiles all parts of the object.
If the incremental
input argument is true
,
this method compiles only the parts of the object that have changed since the last compilation.
This method only outputs to the specified OutputStream
. For better performance, the OutputStream
should be buffered. This method does not output
to the destination specified by the setOutput()
method.
build
in interface Builder
out
- The OutputStream
.incremental
- If true
, build incrementally; if false
, rebuild.0
if the object fails to compile.IOException
- Thrown when an I/O error occurs during compilation.public void stop()
Builder
public void clean()
Builder
setOutput()
method, this method
deletes the Application
or Library
file. Calls to the build()
method trigger a full
recompilation.
The clean()
method does not remove compiler options or reset the output location.
public void load(InputStream in) throws IOException
Builder
build()
method.load
in interface Builder
in
- The InputStream
.IOException
- Thrown when an I/O error occurs while loading the compilation data.public long save(OutputStream out) throws IOException
Builder
build()
method.
Do not use this to create a SWF or SWC file. Use the build()
method instead.
save
in interface Builder
out
- The OutputStream
.IOException
- Thrown when an I/O error occurs while saving the compilation data.public Report getReport()
Builder
null
if you have not yet called the build(boolean)
, build(OutputStream, boolean)
, or
compile(boolean)
methods.
The Report
object includes the following information:
Application
or Library
.
You must call the getReport()
method to get a new report after each
call to the build()
method.
protected int compile(boolean incremental)
Application
object. This method does not link the Application
.incremental
- If true
, build incrementally; if false
, rebuild.Builder.OK
if this method call resulted in compilation of some/all parts of the application;
Builder.LINK
if this method call did not compile anything in the application but advise the caller to link again;
Builder.SKIP
if this method call did not compile anything in the application;
Builder.FAIL
if this method call encountered errors during compilation.public long link(OutputStream output)
public ApplicationCache getApplicationCache()
public void setApplicationCache(ApplicationCache applicationCache)
setApplicationCache
in interface Builder
applicationCache
- A reference to the application cache.public LibraryCache getSwcCache()
public void setSwcCache(LibraryCache libraryCache)
setSwcCache
in interface Builder
swcCache
- A reference to an allocated swc cache.Copyright © 2016 The Apache Software Foundation. All rights reserved.