cordova publishing
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/240b1909 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/240b1909 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/240b1909 Branch: refs/heads/cordova Commit: 240b19099c9f32d024efbba5ff743c48784378ab Parents: 7b39280 Author: Alex Harui <[email protected]> Authored: Mon Jun 12 21:31:51 2017 -0700 Committer: Alex Harui <[email protected]> Committed: Mon Jun 12 21:31:51 2017 -0700 ---------------------------------------------------------------------- .../mxml/flexjs/MXMLFlexJSCordovaPublisher.java | 224 ++++++++++++++++++- .../mxml/flexjs/MXMLFlexJSPublisher.java | 2 +- .../compiler/internal/graph/GoogDepsWriter.java | 4 +- .../internal/graph/GoogDepsWriterCordova.java | 13 +- 4 files changed, 229 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/240b1909/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSCordovaPublisher.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSCordovaPublisher.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSCordovaPublisher.java index 6196c44..7b15059 100644 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSCordovaPublisher.java +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSCordovaPublisher.java @@ -20,13 +20,25 @@ package org.apache.flex.compiler.internal.codegen.mxml.flexjs; import org.apache.commons.io.FilenameUtils; +import org.apache.commons.io.IOUtils; import org.apache.flex.compiler.clients.problems.ProblemQuery; import org.apache.flex.compiler.config.Configuration; import org.apache.flex.compiler.internal.codegen.js.jsc.JSCPublisher; +import org.apache.flex.compiler.internal.driver.js.goog.JSGoogConfiguration; +import org.apache.flex.compiler.internal.graph.GoogDepsWriter; +import org.apache.flex.compiler.internal.graph.GoogDepsWriterCordova; import org.apache.flex.compiler.internal.projects.FlexJSProject; +import org.apache.flex.swc.ISWC; +import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.StringWriter; +import java.util.ArrayList; import java.util.List; public class MXMLFlexJSCordovaPublisher extends MXMLFlexJSPublisher @@ -35,29 +47,231 @@ public class MXMLFlexJSCordovaPublisher extends MXMLFlexJSPublisher { super(project, config); } + + private String cordova = "cordova"; + private String[] pathEnv = new String[3]; + + private boolean needNewProject; + + @Override + protected void setupOutputFolder() + { + if (!outputFolder.exists()) + needNewProject = true; + super.setupOutputFolder(); + } + + @Override + public File getOutputFolder() + { + File newOutputFolder = super.getOutputFolder(); + + String osName = System.getProperty("os.name"); + if (osName.contains("Windows")) + cordova = "cordova.cmd"; + else + { + File c = new File("/usr/local/bin/cordova"); + if (c.exists()) + { + cordova = "/usr/local/bin/cordova"; + String home = System.getenv("HOME"); + pathEnv[0] = "HOME=" + home; + File bash = new File(home + File.separator + ".bash_login"); + String path = System.getenv("PATH"); + String java = System.getenv("JAVA_HOME"); + if (path == null || !path.contains("node_modules") || java == null) + { + try + { + BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(bash), "UTF8")); + + String line = in.readLine(); + + while (line != null) + { + if (line.startsWith("export JAVA_HOME=") && java == null) + { + java = line.substring(17); + } + else if (line.startsWith("export PATH=")) + { + if (path == null) + path = ""; + String oldPath = path; + path = line.substring(12); + if (path.contains("$PATH")) + { + path = path.replace("$PATH", oldPath); + } + } + line = in.readLine(); + } + in.close(); + if (!path.contains("/usr/local/bin")) + { + path += ":/usr/local/bin"; + } + } + catch (Exception e) + { + // nothing to see, move along... + } + } + pathEnv[1] = "PATH=" + path; + pathEnv[2] = "JAVA_HOME=" + java; + } + } + + final String projectName = FilenameUtils.getBaseName(configuration.getTargetFile()); + + if (needNewProject) + { + String[] execParts = new String[5]; + execParts[0] = cordova; + execParts[1] = "create"; + execParts[2] = "app"; + execParts[3] = googConfiguration.getCordovaId(); + execParts[4] = projectName; + try { + Process p = Runtime.getRuntime().exec(execParts, pathEnv, newOutputFolder); + String line; + BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); + while ((line = input.readLine()) != null) { + System.out.println(line); + } + input.close(); + BufferedReader error = new BufferedReader(new InputStreamReader(p.getErrorStream())); + while ((line = error.readLine()) != null) { + System.out.println(line); + } + int ret = p.exitValue(); + System.out.println("cordova create returned " + ret); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + newOutputFolder = new File(newOutputFolder, "app"); + newOutputFolder = new File(newOutputFolder, "www"); + outputFolder = newOutputFolder; + return newOutputFolder; + } + @Override public boolean publish(ProblemQuery problems) throws IOException { - createCordovaProjectIfNeeded(); - //loadCordovaPlatformsIfNeeded(); - if (super.publish(problems)) { - //loadCordovaPlugins(); + cordovaPublish(); } return true; } - private void createCordovaProjectIfNeeded() + private void cordovaPublish() { // The "intermediate" is the "js-debug" output. final File intermediateDir = outputFolder; final String projectName = FilenameUtils.getBaseName(configuration.getTargetFile()); + File projectDir = intermediateDir.getParentFile(); // The "release" is the "js-release" directory. File releaseDir = new File(outputParentFolder, FLEXJS_RELEASE_DIR_NAME); + List<String> platforms = googConfiguration.getCordovaPlatforms(); + for (String platform : platforms) + { + File platformDir = new File(intermediateDir, "platforms" + File.separator + platform); + if (!platformDir.exists()) + { + String[] execParts = new String[4]; + execParts[0] = cordova; + execParts[1] = "platform"; + execParts[2] = "add"; + execParts[3] = platform; + try { + Process p = Runtime.getRuntime().exec(execParts, pathEnv, outputFolder.getParentFile()); + String line; + BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); + while ((line = input.readLine()) != null) { + System.out.println(line); + } + input.close(); + BufferedReader error = new BufferedReader(new InputStreamReader(p.getErrorStream())); + while ((line = error.readLine()) != null) { + System.out.println(line); + } + int ret = p.exitValue(); + System.out.println("cordova platform returned " + ret); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + } + + for (String plugin : plugins) + { + try { + String[] execParts = new String[4]; + execParts[0] = cordova; + execParts[1] = "plugin"; + execParts[2] = "add"; + execParts[3] = plugin; + Process p = Runtime.getRuntime().exec(execParts, pathEnv, outputFolder.getParentFile()); + String line; + BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); + while ((line = input.readLine()) != null) { + System.out.println(line); + } + input.close(); + BufferedReader error = new BufferedReader(new InputStreamReader(p.getErrorStream())); + while ((line = error.readLine()) != null) { + System.out.println(line); + } + int ret = p.exitValue(); + System.out.println("cordova plugin returned " + ret); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + try { + String[] execParts = new String[2]; + execParts[0] = cordova; + execParts[1] = "build"; + Process p = Runtime.getRuntime().exec(execParts, pathEnv, outputFolder.getParentFile()); + String line; + BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); + while ((line = input.readLine()) != null) { + System.out.println(line); + } + input.close(); + BufferedReader error = new BufferedReader(new InputStreamReader(p.getErrorStream())); + while ((line = error.readLine()) != null) { + System.out.println(line); + } + int ret = p.exitValue(); + System.out.println("cordova build returned " + ret); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } + + private ArrayList<String> plugins; + + protected GoogDepsWriter getGoogDepsWriter(File intermediateDir, + String projectName, + JSGoogConfiguration googConfiguration, + List<ISWC> swcs) + { + plugins = new ArrayList<String>(); + return new GoogDepsWriterCordova(intermediateDir, projectName, googConfiguration, swcs, plugins); + } + } http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/240b1909/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java index 9168d4b..1236967 100644 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java @@ -92,7 +92,7 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher private String outputPathParameter; private boolean useStrictPublishing; - private GoogDepsWriter getGoogDepsWriter(File intermediateDir, + protected GoogDepsWriter getGoogDepsWriter(File intermediateDir, String projectName, JSGoogConfiguration googConfiguration, List<ISWC> swcs) http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/240b1909/compiler-jx/src/main/java/org/apache/flex/compiler/internal/graph/GoogDepsWriter.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/graph/GoogDepsWriter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/graph/GoogDepsWriter.java index afc8d00..e6491cc 100644 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/graph/GoogDepsWriter.java +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/graph/GoogDepsWriter.java @@ -667,6 +667,8 @@ public class GoogDepsWriter { fi.deps = new ArrayList<String>(); fi.deps.add(s); } + else + otherScanning(line); } } } @@ -859,8 +861,6 @@ public class GoogDepsWriter { additionalHTML.add(s); continue; } - else - otherScanning(s); int c = s.indexOf(JSGoogEmitterTokens.GOOG_REQUIRE.getToken()); if (c > -1) { http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/240b1909/compiler-jx/src/main/java/org/apache/flex/compiler/internal/graph/GoogDepsWriterCordova.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/graph/GoogDepsWriterCordova.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/graph/GoogDepsWriterCordova.java index c053381..66536df 100644 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/graph/GoogDepsWriterCordova.java +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/graph/GoogDepsWriterCordova.java @@ -36,6 +36,7 @@ import java.util.Set; import org.apache.commons.io.FileUtils; import org.apache.flex.compiler.clients.problems.ProblemQuery; +import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitterTokens; import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitterTokens; import org.apache.flex.compiler.internal.driver.js.goog.JSGoogConfiguration; import org.apache.flex.compiler.problems.FileNotFoundProblem; @@ -46,22 +47,22 @@ import com.google.common.io.Files; public class GoogDepsWriterCordova extends GoogDepsWriter { - public GoogDepsWriterCordova(File outputFolder, String mainClassName, JSGoogConfiguration config, List<ISWC> swcs) + public GoogDepsWriterCordova(File outputFolder, String mainClassName, JSGoogConfiguration config, + List<ISWC> swcs, List<String> cordovaPlugins) { super(outputFolder, mainClassName, config, swcs); + this.cordovaPlugins = cordovaPlugins; } - private final String FLEXJS_CORDOVA_PLUGIN = "@flexjscordovaplugin"; - - public ArrayList<String> cordovaPlugins = new ArrayList<String>(); + private List<String> cordovaPlugins; @Override protected void otherScanning(String s) { - int c = s.indexOf(FLEXJS_CORDOVA_PLUGIN); + int c = s.indexOf(JSFlexJSEmitterTokens.CORDOVA_PLUGIN.getToken()); if (c > -1) { - cordovaPlugins.add(s.substring(c + FLEXJS_CORDOVA_PLUGIN.length()).trim()); + cordovaPlugins.add(s.substring(c + JSFlexJSEmitterTokens.CORDOVA_PLUGIN.getToken().length()).trim()); } } }
