You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2016/09/30 15:08:48 UTC
[4/5] git commit: [flex-falcon] [refs/heads/develop] - teach COMPJSC
to insert its output into an existing SWC
teach COMPJSC to insert its output into an existing SWC
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/bdc4023f
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/bdc4023f
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/bdc4023f
Branch: refs/heads/develop
Commit: bdc4023f6edd1b9586d1b434bd814af488496427
Parents: 25358a8
Author: Alex Harui <ah...@apache.org>
Authored: Thu Sep 29 15:41:50 2016 -0700
Committer: Alex Harui <ah...@apache.org>
Committed: Thu Sep 29 20:56:44 2016 -0700
----------------------------------------------------------------------
.../apache/flex/compiler/clients/COMPJSC.java | 179 +++++++++++++++----
1 file changed, 145 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/bdc4023f/compiler-jx/src/main/java/org/apache/flex/compiler/clients/COMPJSC.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/COMPJSC.java b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/COMPJSC.java
index b3b9c64..697954f 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/clients/COMPJSC.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/clients/COMPJSC.java
@@ -24,12 +24,19 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Enumeration;
import java.util.List;
import java.util.Set;
+import java.util.zip.Deflater;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipOutputStream;
import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.IOUtils;
import org.apache.flex.compiler.codegen.as.IASWriter;
import org.apache.flex.compiler.driver.IBackend;
import org.apache.flex.compiler.driver.js.IJSApplication;
@@ -46,12 +53,16 @@ import org.apache.flex.compiler.internal.driver.mxml.vf2js.MXMLVF2JSSWCBackend;
import org.apache.flex.compiler.internal.projects.CompilerProject;
import org.apache.flex.compiler.internal.targets.FlexJSSWCTarget;
import org.apache.flex.compiler.internal.targets.JSTarget;
+import org.apache.flex.compiler.problems.FileNotFoundProblem;
import org.apache.flex.compiler.problems.ICompilerProblem;
import org.apache.flex.compiler.problems.InternalCompilerProblem;
+import org.apache.flex.compiler.problems.LibraryNotFoundProblem;
import org.apache.flex.compiler.problems.UnableToBuildSWFProblem;
import org.apache.flex.compiler.targets.ITarget.TargetType;
import org.apache.flex.compiler.targets.ITargetSettings;
import org.apache.flex.compiler.units.ICompilationUnit;
+import org.apache.flex.swc.ISWC;
+import org.apache.flex.swc.io.SWCReader;
/**
* @author Erik de Bruin
@@ -194,7 +205,67 @@ public class COMPJSC extends MXMLJSC
return false;
}
- File outputFolder = new File(getOutputFilePath());
+ boolean packingSWC = false;
+ String outputFolderName = getOutputFilePath();
+ File swcFile = new File(outputFolderName);
+ File jsOut = new File("js/out");
+ ZipFile zipFile = null;
+ ZipOutputStream zipOutputStream = null;
+ String catalog = null;
+ StringBuilder fileList = new StringBuilder();
+ if (outputFolderName.endsWith(".swc"))
+ {
+ packingSWC = true;
+ if (!swcFile.exists())
+ {
+ problems.add(new LibraryNotFoundProblem(outputFolderName));
+ return false;
+ }
+ zipFile = new ZipFile(swcFile, ZipFile.OPEN_READ);
+ final InputStream catalogInputStream = SWCReader.getInputStream(zipFile, SWCReader.CATALOG_XML);
+
+ catalog = IOUtils.toString(catalogInputStream);
+ catalogInputStream.close();
+ zipOutputStream = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outputFolderName + ".new")));
+ zipOutputStream.setLevel(Deflater.NO_COMPRESSION);
+ for (final Enumeration<? extends ZipEntry> entryEnum = zipFile.entries(); entryEnum.hasMoreElements();)
+ {
+ final ZipEntry entry = entryEnum.nextElement();
+ if (!entry.getName().contains("js/out") &&
+ !entry.getName().contains(SWCReader.CATALOG_XML))
+ {
+ InputStream input = zipFile.getInputStream(entry);
+ zipOutputStream.putNextEntry(entry);
+ IOUtils.copy(input, zipOutputStream);
+ zipOutputStream.closeEntry();
+ }
+ }
+ int filesIndex = catalog.indexOf("<files>");
+ if (filesIndex != -1)
+ {
+ int filesIndex2 = catalog.indexOf("</files>");
+ String files = catalog.substring(filesIndex, filesIndex2);
+ int fileIndex = files.indexOf("<file", 6);
+ int pathIndex = files.indexOf("path=");
+ while (pathIndex != -1)
+ {
+ int pathIndex2 = files.indexOf("\"", pathIndex + 6);
+ int fileIndex2 = files.indexOf("/>", fileIndex);
+ String path = files.substring(pathIndex + 6, pathIndex2);
+ if (!path.startsWith("js/out"))
+ {
+ fileList.append(files.substring(fileIndex - 8, fileIndex2 + 3));
+ }
+ pathIndex = files.indexOf("path=", pathIndex2);
+ fileIndex = files.indexOf("<file", fileIndex2);
+ }
+ catalog = catalog.substring(0, filesIndex) + catalog.substring(filesIndex2 + 8);
+ }
+ }
+
+ File outputFolder = null;
+ if (!packingSWC)
+ outputFolder = new File(outputFolderName);
Set<String> externs = config.getExterns();
Collection<ICompilationUnit> roots = ((FlexJSSWCTarget)target).getReachableCompilationUnits(errors);
@@ -209,36 +280,81 @@ public class COMPJSC extends MXMLJSC
String symbol = cu.getQualifiedNames().get(0);
if (externs.contains(symbol)) continue;
- final File outputClassFile = getOutputClassFile(
- cu.getQualifiedNames().get(0), outputFolder);
-
- System.out.println("Compiling file: " + outputClassFile);
-
- ICompilationUnit unit = cu;
-
- IASWriter writer;
- if (cuType == ICompilationUnit.UnitType.AS_UNIT)
- {
- writer = JSSharedData.backend.createWriter(project,
- (List<ICompilerProblem>) errors, unit,
- false);
- }
- else
- {
- writer = JSSharedData.backend.createMXMLWriter(
- project, (List<ICompilerProblem>) errors,
- unit, false);
- }
- problems.addAll(errors);
- BufferedOutputStream out = new BufferedOutputStream(
- new FileOutputStream(outputClassFile));
- writer.writeTo(out);
- out.flush();
- out.close();
- writer.close();
+ if (!packingSWC)
+ {
+ final File outputClassFile = getOutputClassFile(
+ cu.getQualifiedNames().get(0), outputFolder);
+
+ System.out.println("Compiling file: " + outputClassFile);
+
+ ICompilationUnit unit = cu;
+
+ IASWriter writer;
+ if (cuType == ICompilationUnit.UnitType.AS_UNIT)
+ {
+ writer = JSSharedData.backend.createWriter(project,
+ (List<ICompilerProblem>) errors, unit,
+ false);
+ }
+ else
+ {
+ writer = JSSharedData.backend.createMXMLWriter(
+ project, (List<ICompilerProblem>) errors,
+ unit, false);
+ }
+ problems.addAll(errors);
+ BufferedOutputStream out = new BufferedOutputStream(
+ new FileOutputStream(outputClassFile));
+ writer.writeTo(out);
+ out.flush();
+ out.close();
+ writer.close();
+ }
+ else
+ {
+ String outputClassFile = getOutputClassFile(
+ cu.getQualifiedNames().get(0), jsOut).getPath();
+ System.out.println("Compiling file: " + outputClassFile);
+
+ ICompilationUnit unit = cu;
+
+ IASWriter writer;
+ if (cuType == ICompilationUnit.UnitType.AS_UNIT)
+ {
+ writer = JSSharedData.backend.createWriter(project,
+ (List<ICompilerProblem>) errors, unit,
+ false);
+ }
+ else
+ {
+ writer = JSSharedData.backend.createMXMLWriter(
+ project, (List<ICompilerProblem>) errors,
+ unit, false);
+ }
+ problems.addAll(errors);
+ zipOutputStream.putNextEntry(new ZipEntry(outputClassFile));
+ writer.writeTo(zipOutputStream);
+ zipOutputStream.closeEntry();
+ writer.close();
+ fileList.append(" <file path=\"" + outputClassFile + "\" mod=\"" + System.currentTimeMillis() + "\"/>\n");
+ }
}
}
-
+ if (packingSWC)
+ {
+ zipFile.close();
+ int libraryIndex = catalog.indexOf("</libraries>");
+ catalog = catalog.substring(0, libraryIndex + 13) +
+ " <files>\n" + fileList.toString() + " </files>" +
+ catalog.substring(libraryIndex + 13);
+ zipOutputStream.putNextEntry(new ZipEntry(SWCReader.CATALOG_XML));
+ zipOutputStream.write(catalog.getBytes());
+ zipOutputStream.closeEntry();
+ zipOutputStream.close();
+ swcFile.delete();
+ File newSWCFile = new File(outputFolderName + ".new");
+ newSWCFile.renameTo(swcFile);
+ }
compilationSuccess = true;
}
}
@@ -325,11 +441,6 @@ public class COMPJSC extends MXMLJSC
else
{
String outputFolderName = config.getOutput();
- if (outputFolderName.endsWith(".swc"))
- {
- File outputFolder = new File(outputFolderName);
- outputFolderName = outputFolder.getParent();
- }
return outputFolderName;
}
}