use of net.jangaroo.exml.model.ExmlSourceFile 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()]);
}
use of net.jangaroo.exml.model.ExmlSourceFile in project jangaroo-tools by CoreMedia.
the class ExmlToMxml method exmlToMxml.
private File exmlToMxml(ExmlSourceFile exmlSourceFile) throws IOException, SAXException {
ExmlModel exmlModel = new ExmlToModelParser(configClassRegistry).parse(exmlSourceFile.getSourceFile());
File sourceFile = exmlSourceFile.getSourceFile();
File outputFile = CompilerUtils.fileFromQName(exmlSourceFile.getTargetClassName(), configClassRegistry.getConfig().getSourcePath().get(0), ".mxml");
FileUtils.forceMkdir(outputFile.getParentFile());
PrintStream writer = new PrintStream(new FileOutputStream(outputFile), true, net.jangaroo.exml.api.Exmlc.OUTPUT_CHARSET);
ExmlToConfigClassParser.parseFileWithHandler(sourceFile, new ExmlToMxmlHandler(exmlSourceFile, exmlModel, writer));
return outputFile;
}
use of net.jangaroo.exml.model.ExmlSourceFile in project jangaroo-tools by CoreMedia.
the class ExmlComponentClassGeneratorTest method testDoNotGenerateClassWhenActionScriptClassIsAlreadyThere.
@Test
public void testDoNotGenerateClassWhenActionScriptClassIsAlreadyThere() throws Exception {
setUp("exmlparser.config");
ExmlSourceFile exmlSourceFile = new ExmlSourceFile(getConfigClassRegistry(), getFile("/testPackage/TestAction.exml"));
File outputFile = exmlSourceFile.generateTargetClass();
Assert.assertNull("A target class must only be generated when there is no ActionScript source class of the same name as the EXML class.", outputFile);
}
Aggregations