Repository: flex-falcon Updated Branches: refs/heads/develop d61a68857 -> 82a07043b
- Extended the CompileJSMojo to be able to operate if the Swf compilation had been skipped (The Mojo now generates a dummy swc with an empty catalog.xml to satisfy the JS compiler) Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/82a07043 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/82a07043 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/82a07043 Branch: refs/heads/develop Commit: 82a07043b3d2809e77f23eb063b558b3058728b6 Parents: d61a688 Author: Christofer Dutz <[email protected]> Authored: Wed Feb 22 14:53:00 2017 +0100 Committer: Christofer Dutz <[email protected]> Committed: Wed Feb 22 14:53:00 2017 +0100 ---------------------------------------------------------------------- .../apache/flex/maven/flexjs/CompileJSMojo.java | 55 +++++++++++++++++--- 1 file changed, 49 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/82a07043/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileJSMojo.java ---------------------------------------------------------------------- diff --git a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileJSMojo.java b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileJSMojo.java index 03a0f63..2347f4a 100644 --- a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileJSMojo.java +++ b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileJSMojo.java @@ -21,9 +21,11 @@ import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; -import java.io.File; +import java.io.*; import java.util.LinkedList; import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; /** * goal which compiles a project into a flexjs swc library. @@ -69,14 +71,19 @@ public class CompileJSMojo @Override public void execute() throws MojoExecutionException { - File outputDirectory = getOutput(); - if(!outputDirectory.exists()) { - if(!outputDirectory.mkdirs()) { - throw new MojoExecutionException("Could not create output directory " + outputDirectory.getPath()); - } + // FlexJS requires an existing SWC. If we skipped + // the AS compilation, this doesn't exist yet so + // we simply generate an empty swc and use that. + if(!getOutput().exists()) { + createEmptySwc(getOutput()); } super.execute(); + + if(getOutput().exists()) { + // Attach the file created by the compiler as artifact file to maven. + project.getArtifact().setFile(getOutput()); + } } @Override @@ -117,4 +124,40 @@ public class CompileJSMojo return "typedefs".equalsIgnoreCase(library.getClassifier()); } + private void createEmptySwc(File outputFile) throws MojoExecutionException { + if(!outputFile.getParentFile().exists()) { + if(!outputFile.getParentFile().mkdirs()) { + throw new MojoExecutionException("Could not create directory " + outputFile.getParent()); + } + } + + // Create a dummy swc (A zip file which contains a minimal catalog.xml) */ + try { + OutputStream stream = new FileOutputStream(outputFile); + stream = new BufferedOutputStream(stream); + ZipOutputStream zipStream = new ZipOutputStream(stream); + ZipEntry entry = new ZipEntry("catalog.xml"); + zipStream.putNextEntry(entry); + byte[] dummyCatalog = ( + "<?xml version=\"1.0\" ?>\n" + + "<swc xmlns=\"http://www.adobe.com/flash/swccatalog/9\">\n" + + " <versions>\n" + + " <swc version=\"1.2\"/>\n" + + " <compiler name=\"Apache Flex - FlexJS: Compiler: Compiler\" version=\"0.8\" build=\"0-SNAPSHOT\"/>\n" + + " </versions>\n" + + " <features>\n" + + " </features>\n" + + " <libraries>\n" + + " </libraries>\n" + + "</swc>").getBytes(); + zipStream.write(dummyCatalog); + zipStream.closeEntry(); + zipStream.close(); + } catch (FileNotFoundException e) { + throw new MojoExecutionException("Could not create empty zip file at " + outputFile.getPath()); + } catch (IOException e) { + throw new MojoExecutionException("Could not create empty zip file at " + outputFile.getPath()); + } + } + }
