Search in sources :

Example 1 with MxmlLibraryManifestGenerator

use of net.jangaroo.exml.generator.MxmlLibraryManifestGenerator in project jangaroo-tools by CoreMedia.

the class ExmlToMxml method convert.

public File[] convert() {
    InputStream migrationMapStream = resourceClassLoader.getResourceAsStream("ext-as-3.4-migration-map.properties");
    if (migrationMapStream == null) {
        throw new ExmlcException("Could not find migration map 'ext-as-3.4-migration-map.properties' in classpath.");
    }
    try {
        this.migrationMap.load(migrationMapStream);
    } catch (IOException e) {
        throw new ExmlcException("Unable to load migration map", e);
    }
    new CatalogComponentsParser(mxmlComponentRegistry).parse(resourceClassLoader.getResourceAsStream("catalog.xml"));
    try {
        new MxmlLibraryManifestGenerator(configClassRegistry).createManifestFile();
    } catch (IOException e) {
        throw new ExmlcException("Unable to create manifest.xml file: " + e.getMessage(), e);
    }
    Map<String, ExmlSourceFile> exmlSourceFilesByConfigClassName = configClassRegistry.getExmlSourceFilesByConfigClassName();
    List<File> mxmlFiles = new ArrayList<File>();
    Collection<ExmlSourceFile> exmlSourceFiles;
    List<File> sourceFiles = configClassRegistry.getConfig().getSourceFiles();
    if (sourceFiles.isEmpty()) {
        exmlSourceFiles = exmlSourceFilesByConfigClassName.values();
    } else {
        exmlSourceFiles = new ArrayList<ExmlSourceFile>();
        for (File exmlFile : sourceFiles) {
            exmlSourceFiles.add(configClassRegistry.getExmlSourceFile(exmlFile));
        }
    }
    for (ExmlSourceFile exmlSourceFile : exmlSourceFiles) {
        System.out.printf("Converting EXML file %s...%n", exmlSourceFile.getSourceFile());
        if (exmlSourceFile.hasSourceTargetClass()) {
            System.out.printf("  Target class %s is implemented in ActionScript: no need to generate MXML target class.", exmlSourceFile.getTargetClassName());
        } else {
            try {
                File mxmlFile = exmlToMxml(exmlSourceFile);
                mxmlFiles.add(mxmlFile);
                System.out.printf("  Generated MXML target class %s into file %s.%n", exmlSourceFile.getTargetClassName(), mxmlFile.getPath());
            } catch (Exception e) {
                throw new ExmlcException("Unable to convert to MXML: " + e.getMessage(), exmlSourceFile.getSourceFile(), e);
            }
        }
    }
    if (!configClassRegistry.getConfig().isKeepExmlFiles()) {
        // clean up EXML files:
        for (ExmlSourceFile exmlSourceFile : exmlSourceFiles) {
            if (!exmlSourceFile.getSourceFile().delete()) {
                System.err.println("Failed to delete EXML source file " + exmlSourceFile.getSourceFile().getPath());
            }
        }
    }
    return mxmlFiles.toArray(new File[mxmlFiles.size()]);
}
Also used : InputStream(java.io.InputStream) ExmlcException(net.jangaroo.exml.api.ExmlcException) CatalogComponentsParser(net.jangaroo.jooc.mxml.CatalogComponentsParser) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExmlcException(net.jangaroo.exml.api.ExmlcException) IOException(java.io.IOException) MxmlLibraryManifestGenerator(net.jangaroo.exml.generator.MxmlLibraryManifestGenerator) ExmlSourceFile(net.jangaroo.exml.model.ExmlSourceFile) ExmlSourceFile(net.jangaroo.exml.model.ExmlSourceFile) File(java.io.File)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 ExmlcException (net.jangaroo.exml.api.ExmlcException)1 MxmlLibraryManifestGenerator (net.jangaroo.exml.generator.MxmlLibraryManifestGenerator)1 ExmlSourceFile (net.jangaroo.exml.model.ExmlSourceFile)1 CatalogComponentsParser (net.jangaroo.jooc.mxml.CatalogComponentsParser)1 SAXException (org.xml.sax.SAXException)1