public class Library extends Object implements Builder, Cloneable
Library class represents a SWC archive or a RSL. It implements the Builder interface
which allows for building the library incrementally. The following example defines a SWC archive or RSL:
Library lib = new Library();You can add components to the
Library object in the following ways:
1. String - Specify a fully-qualified name. 2. File - Specify a source file. 3. VirtualLocalFile - Specify an in-memory source object. 4. URI - Specify a namespace URI.
To add resource bundles to the Library, you can use the addResourceBundle() method,
as the following example shows:
lib.addResourceBundle("mx.controls"));
To add archive files to the Library, you can use the addArchiveFile() method, as the following
example shows:
lib.addArchiveFile("defaults.css", new File("path1/myStyle.css"));
Before you can compile with a Library object, you must configure it. The following
four methods are the most common methods you use to configure the Library object:
1. setLogger() - Use this to set a Logger so that the client can be notified of events that occurred during the compilation. 2. setConfiguration() - Optional. Use this to specify compiler options. 3. setOutput() - Optional. Use this to specify an output file name. 4. setDirectory() - Optional. Use this to specify an RSL output directory.You must implement the
flex2.tools.oem.Logger interface and use the implementation as the Logger
for the compilation. The following is an example Logger implementation:
lib.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 Library object, you
must get a Configuration object that is populated with default values. Then, you set
compiler options programmatically using methods of the Configuration class.
The setOutput() method lets you specify where the Library object writes
the output to. If you call the setOutput() method, the build(boolean) method
writes directly to the specified location; for example:
lib.setOutput(new File("MyLib.swc"));
lib.build(true);
If you do not call the setOutput() method, you can use the build(OutputStream, boolean)
method. This requires that you provide a buffered output stream; for example:
lib.build(new BufferedOutputStream(new FileOutputStream("MyLib.swc")), true);
The setDirectory() method lets you output RSLs to the specified directory; for example:
lib.setDirectory(new File("dir1"));
lib.build(true);
You can save the Library object compilation
data for reuse. You do this using the save(OutputStream) method. Subsequent compilations can use
the load(OutputStream) method to get the old data into the Library object; for example:
lib.save(new BufferedOutputStream(new FileOutputStream("MyLib.incr")));
When a cache file (for example, MyLib.incr) from a previous compilation is available before the
compilation, you can call the load(OutputStream) method before you call the build() method; for example:
lib.load(new BufferedInputStream(FileInputStream("MyLib.incr")));
lib.build(true);
The build(false) and build(OutputStream, false) methods always rebuild the library.
The first time you build the Library
object, the build(true)/build(OutputStream, true) methods do a complete build, which
is equivalent to the build(false)/build(OutputStream, false) methods, respectively. After you call the
clean() method, the Library object always does a full build.
The clean() method cleans up compilation data in the Library object the output
file, if the setOutput() method was called.
You can use the Library class to build a library from a combination of source
files in the file system and in-memory, dynamically-generated source objects. You
must use the addComponent(VirtualLocalFile), addResourceBundle(VirtualLocalFile), and
addArchiveFile(String, VirtualLocalFile) methods to use in-memory objects.
The Library class can be part of a Project.
Configuration,
flex2.tools.oem.Project| Modifier and Type | Field and Description |
|---|---|
protected PathResolver |
resolver |
| Constructor and Description |
|---|
Library()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addArchiveFile(String name,
File file)
Adds a file to this
Library object. |
void |
addArchiveFile(String name,
VirtualLocalFile file)
Adds an in-memory source object to this
Library object. |
void |
addComponent(File includeSource)
Adds a component to this
Library object. |
void |
addComponent(String includeClass)
Adds a class, function, variable, or namespace to this
Library object. |
void |
addComponent(URI includeNamespace)
Adds a list of components to this
Library object. |
void |
addComponent(VirtualLocalFile includeSource)
Adds a component to this
Library object. |
void |
addResourceBundle(String resourceBundle)
Adds a resource bundle to this
Library object. |
void |
addStyleSheet(String name,
File file)
Adds a CSS stylesheet to this
Library object. |
void |
addStyleSheet(String name,
VirtualLocalFile file)
Adds an in-memory CSS stylesheet object to this
Library object. |
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. |
Library |
clone() |
protected int |
compile(boolean incremental)
Compiles the
Library. |
void |
convertMessages(ProblemQuery pq) |
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.
|
HashMap<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.
|
File |
getDirectory()
Gets the RSL output directory.
|
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.
|
void |
refreshLastModified() |
void |
removeAllArchiveFiles()
Removes all the archive files from this
Library object. |
void |
removeAllComponents()
Removes all the components from this
Library object. |
void |
removeAllResourceBundles()
Removes all the resource bundles from this
Library object. |
void |
removeAllStyleSheets()
Removes all the CSS stylesheets from this
Library object. |
void |
removeArchiveFile(String name)
Removes the specified file from this
Library object. |
void |
removeComponent(File includeSource)
Removes the specified component from this
Library object. |
void |
removeComponent(String includeClass)
Removes the specified component from this
Library object. |
void |
removeComponent(URI includeNamespace)
Removes the specified list of components from this
Library object. |
void |
removeComponent(VirtualLocalFile includeSource)
Removes the specified component from this
Library object. |
void |
removeResourceBundle(String resourceBundle)
Removes the specified resource bundle name from this
Library object. |
void |
removeStyleSheet(String name)
Removes the specified CSS stylesheet from this
Library object. |
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 |
setDirectory(File directory)
Sets the RSL output directory.
|
void |
setLogger(Logger logger)
Sets the logger for this object.
|
void |
setOutput(File output)
Sets the output destination.
|
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 void addComponent(String includeClass)
Library object.
This is the equilvalent of the include-classes option of the compc compiler.includeClass - A fully-qualified name.public void addComponent(File includeSource)
Library object.
This is the equilvalent of the include-sources option of the compc compiler.includeSource - A source file.public void addComponent(VirtualLocalFile includeSource)
Library object.
This is equilvalent to the include-sources option of the compc compiler.includeSource - An in-memory source object.public void addComponent(URI includeNamespace)
Library object.
This is equilvalent to the include-namespaces option of the compc compiler.includeNamespace - A namespace URI.public void removeComponent(String includeClass)
Library object.
The name can be a class, a function, a variable, or a namespace.includeClass - A fully-qualified name.public void removeComponent(File includeSource)
Library object.includeSource - A source file.public void removeComponent(VirtualLocalFile includeSource)
Library object.includeSource - An in-memory source object.public void removeComponent(URI includeNamespace)
Library object. The input argument is a namespace URI.includeNamespace - A namespace URI.public void removeAllComponents()
Library object.public void addResourceBundle(String resourceBundle)
Library object.
This is equilvalent to the include-resource-bundles option of the compc compiler.resourceBundle - A resource bundle name.public void removeResourceBundle(String resourceBundle)
Library object.resourceBundle - A resource bundle name.public void removeAllResourceBundles()
Library object.public void addArchiveFile(String name, File file)
Library object. This is equilvalent to the include-file option of the compc compiler.name - The name in the archive.file - The file to be added.public void addArchiveFile(String name, VirtualLocalFile file)
Library object. This is equilvalent to the
include-file option of the compc compiler.name - The name in the archive.file - The in-memory source object to be added.public void removeArchiveFile(String name)
Library object.name - The name in the archive.public void removeAllArchiveFiles()
Library object.public void addStyleSheet(String name, File file)
Library object. This is equilvalent to the include-stylesheet option of the compc compiler.name - The name in the archive.file - The file to be added.public void addStyleSheet(String name, VirtualLocalFile file)
Library object. This is equilvalent to the
include-stylesheet option of the compc compiler.name - The name in the archive.file - The in-memory source object to be added.public void removeStyleSheet(String name)
Library object.name - The name in the archive.public void removeAllStyleSheets()
Library object.public void setConfiguration(Configuration configuration)
BuildergetDefaultConfiguration() method to get a Configuration object.setConfiguration in interface Builderconfiguration - An instance of an object that implements the Configuration interface.Configurationpublic Configuration getDefaultConfiguration()
Builderflex-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 BuilderConfiguration interface.Configurationpublic HashMap<String,PerformanceData[]> getCompilerBenchmarks()
BuildergetCompilerBenchmarks in interface Builderpublic Benchmark getBenchmark()
BuildergetBenchmark in interface Builderpublic Configuration getConfiguration()
BuildergetDefaultConfiguration() method,
this method returns null if the setConfiguration() method was not called.getConfiguration in interface BuilderConfiguration interface.Configurationpublic void setLogger(Logger logger)
Builderpublic Logger getLogger()
Buildernull if the setLogger()
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 BuildermimeType - MIME type.extensions - An array of file extensions.public void setOutput(File output)
build(boolean) method.
If you use the build(OutputStream, boolean) method, there is no need to use this method.output - An instance of the java.io.File class.public File getOutput()
null if you did not call the
setOutput() method.public void setDirectory(File directory)
directory - An RSL directory.public File getDirectory()
java.io.File, or null if you did not call the setDirectory() method.public void setProgressMeter(ProgressMeter meter)
BuildersetProgressMeter in interface Buildermeter - An object that implements the ProgressMeter interface.ProgressMeterpublic void setPathResolver(PathResolver resolver)
BuildersetPathResolver in interface Builderresolver - A path resolverPathResolverpublic long build(boolean incremental)
throws IOException
Builderincremental 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 Builderincremental - If true, build incrementally; if false, rebuild.IOException - Thrown when an I/O error occurs during compilation.Application,
Librarypublic long build(OutputStream out, boolean incremental) throws IOException
Builderincremental 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 Builderout - 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()
Builderpublic void clean()
BuildersetOutput() 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
Builderbuild() method.load in interface Builderin - The InputStream.IOException - Thrown when an I/O error occurs while loading the compilation data.public long save(OutputStream out) throws IOException
Builderbuild() method.
Do not use this to create a SWF or SWC file. Use the build() method instead.
save in interface Builderout - The OutputStream.IOException - Thrown when an I/O error occurs while saving the compilation data.public Report getReport()
Buildernull
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)
Library. This method does not link the Library.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 BuilderapplicationCache - A reference to the application cache.public LibraryCache getSwcCache()
public void setSwcCache(LibraryCache libraryCache)
setSwcCache in interface BuilderswcCache - A reference to an allocated swc cache.public void refreshLastModified()
public void convertMessages(ProblemQuery pq)
Copyright © 2016 The Apache Software Foundation. All rights reserved.