- Updated the migration script - Updated the closure compiler version to v20151015 - Updated guava version to 18.0 - Added some more build-tool goals needed to patch, copy, cut and otherwise update stuff in the externs modules - Extern modules -- Added poms -- Added config files for generation and compilation - Added a new flexjs-maven-plugin
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/dec07727 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/dec07727 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/dec07727 Branch: refs/heads/feature/maven-migration Commit: dec07727ac4e0b7869cafd7154cdacbb0bc2f2fa Parents: 5088977 Author: Christofer Dutz <[email protected]> Authored: Sat Mar 19 12:53:21 2016 +0100 Committer: Christofer Dutz <[email protected]> Committed: Sat Mar 19 12:53:21 2016 +0100 ---------------------------------------------------------------------- compiler-build-tools/pom.xml | 5 + .../compiler/tools/AnnotateClassesMojo.java | 135 --------------- .../tools/BaseProblemGeneratorMojo.java | 127 -------------- .../tools/ProblemEnumGeneratorMojo.java | 152 ---------------- .../ProblemResourceBundleGeneratorMojo.java | 101 ----------- .../tools/annotate/AnnotateClassesMojo.java | 135 +++++++++++++++ .../tools/patchfiles/CopyFileOperation.java | 31 ++++ .../compiler/tools/patchfiles/CutOperation.java | 54 ++++++ .../tools/patchfiles/DeleteFileOperation.java | 23 +++ .../compiler/tools/patchfiles/Operation.java | 13 ++ .../tools/patchfiles/PreProcessSourcesMojo.java | 86 +++++++++ .../tools/patchfiles/ReplaceOperation.java | 46 +++++ .../patchfiles/ReplaceRegexpOperation.java | 68 ++++++++ .../problems/BaseProblemGeneratorMojo.java | 127 ++++++++++++++ .../problems/ProblemEnumGeneratorMojo.java | 152 ++++++++++++++++ .../ProblemResourceBundleGeneratorMojo.java | 101 +++++++++++ .../tools/unpack/UnpackResourceMojo.java | 100 +++++++++++ compiler.jx/pom.xml | 2 +- compiler/pom.xml | 2 +- externs/GCL/pom.xml | 23 +++ externs/GCL/src/main/config/compile-config.xml | 103 +++++++++++ externs/cordova/pom.xml | 49 ++++++ .../cordova/src/main/config/compile-config.xml | 44 +++++ .../cordova/src/main/config/generate-config.xml | 39 +++++ externs/createjs/pom.xml | 167 ++++++++++++++++++ .../createjs/src/main/config/compile-config.xml | 102 +++++++++++ .../src/main/config/generate-config.xml | 130 ++++++++++++++ externs/google_maps/pom.xml | 88 ++++++++++ .../src/main/config/compile-config.xml | 97 +++++++++++ .../src/main/config/generate-config.xml | 39 +++++ externs/jasmine/pom.xml | 62 +++++++ .../jasmine/src/main/config/compile-config.xml | 97 +++++++++++ .../jasmine/src/main/config/generate-config.xml | 45 +++++ externs/jquery/pom.xml | 62 +++++++ .../jquery/src/main/config/compile-config.xml | 101 +++++++++++ .../jquery/src/main/config/generate-config.xml | 59 +++++++ externs/js/pom.xml | 131 ++++++++++++++ externs/js/src/main/config/compile-config.xml | 93 ++++++++++ externs/js/src/main/config/generate-config.xml | 173 +++++++++++++++++++ .../js/src/main/flex/__AS3__/vec/Vector$int.as | 81 +++++++++ .../src/main/flex/__AS3__/vec/Vector$object.as | 81 +++++++++ .../js/src/main/flex/__AS3__/vec/Vector$uint.as | 81 +++++++++ externs/node/pom.xml | 38 ++++ externs/node/src/main/config/compile-config.xml | 43 +++++ .../node/src/main/config/generate-config.xml | 38 ++++ externs/pom.xml | 29 ++++ flexjs-maven-plugin/pom.xml | 100 +++++++++++ .../apache/flex/maven/flexjs/CompileMojo.java | 59 +++++++ .../apache/flex/maven/flexjs/ExterncMojo.java | 52 ++++++ maven/falcon-jx-compiler.pom | 2 +- migrate-to-maven.sh | 40 +++++ pom.xml | 2 + 52 files changed, 3292 insertions(+), 518 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/compiler-build-tools/pom.xml ---------------------------------------------------------------------- diff --git a/compiler-build-tools/pom.xml b/compiler-build-tools/pom.xml index d773ee7..4f9e05f 100644 --- a/compiler-build-tools/pom.xml +++ b/compiler-build-tools/pom.xml @@ -46,6 +46,11 @@ <version>3.0.3</version> </dependency> <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-compress</artifactId> + <version>1.10</version> + </dependency> + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/AnnotateClassesMojo.java ---------------------------------------------------------------------- diff --git a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/AnnotateClassesMojo.java b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/AnnotateClassesMojo.java deleted file mode 100644 index cae1ad7..0000000 --- a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/AnnotateClassesMojo.java +++ /dev/null @@ -1,135 +0,0 @@ -package org.apache.flex.compiler.tools; - -/* - * Copyright 2001-2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.compiler.util.scan.InclusionScanException; -import org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner; -import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping; - -import java.io.*; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -/** - * Goal which adds annotations to generated classes. - */ -@Mojo(name="add-class-annotation",defaultPhase = LifecyclePhase.PROCESS_SOURCES) -public class AnnotateClassesMojo - extends AbstractMojo -{ - @Parameter - protected Set<String> includes = new HashSet<String>(); - - @Parameter - protected Set<String> excludes = new HashSet<String>(); - - @Parameter(defaultValue="${project.build.directory}/generated-sources") - private File directory; - - @Parameter(property="annotation", required=true) - private String annotation; - - public void execute() - throws MojoExecutionException - { - SuffixMapping mapping = new SuffixMapping("jbg", Collections.<String>emptySet()); - SimpleSourceInclusionScanner scan = new SimpleSourceInclusionScanner(includes, excludes); - scan.addSourceMapping(mapping); - - try { - Set<File> candidates = scan.getIncludedSources(directory, null); - for(File candidate : candidates) { - processFile(candidate); - } - } catch (InclusionScanException e) { - throw new MojoExecutionException("Error scanning filed to be processed.", e); - } - } - - private void processFile(File file) { - if(!file.exists()) { - System.out.println("Missing file: " + file.getPath()); - return; - } - System.out.println("Adding " + annotation + " to class: " + file.getPath()); - try - { - // Prepare to read the file. - FileInputStream fileInputStream = new FileInputStream(file); - InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream); - BufferedReader bufferedReader = new BufferedReader(inputStreamReader); - - File tmpOutputFile = new File(file.getParentFile(), file.getName() + ".tmp"); - FileOutputStream fileOutputStream = new FileOutputStream(tmpOutputFile); - PrintStream outputStream = new PrintStream(fileOutputStream); - try - { - // Read it line-by-line. - String line; - while ((line = bufferedReader.readLine()) != null) - { - // If the line starts with "public class", output the annotation on the previous line. - if (line.startsWith("public class") || line.startsWith("public interface")) { - outputStream.println(annotation); - } - outputStream.println(line); - } - } - finally - { - try { - bufferedReader.close(); - } catch(Exception e) { - // Ignore. - } - try { - outputStream.close(); - } catch(Exception e) { - // Ignore. - } - try { - fileOutputStream.close(); - } catch(Exception e) { - // Ignore. - } - } - - // Remove the original file. - if(!file.delete()) { - throw new MojoExecutionException("Error deleting original file at: " + file.getPath()); - } - - // Rename the temp file to the name of the original file. - if(!tmpOutputFile.renameTo(file)) { - throw new MojoExecutionException("Error renaming the temp file from: " + tmpOutputFile.getPath() + - " to: " + file.getPath()); - } - } - catch (Exception e) - { - e.printStackTrace(); - } - } - -} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/BaseProblemGeneratorMojo.java ---------------------------------------------------------------------- diff --git a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/BaseProblemGeneratorMojo.java b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/BaseProblemGeneratorMojo.java deleted file mode 100644 index 3845be9..0000000 --- a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/BaseProblemGeneratorMojo.java +++ /dev/null @@ -1,127 +0,0 @@ -package org.apache.flex.compiler.tools; - -import com.google.common.base.Predicate; -import com.google.common.collect.Collections2; -import com.google.common.collect.ImmutableSet; -import com.google.common.io.Files; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.nio.charset.Charset; -import java.util.Collection; -import java.util.Iterator; - -/** - * Created by christoferdutz on 20.02.16. - */ -public abstract class BaseProblemGeneratorMojo extends AbstractMojo -{ - - private ImmutableSet<String> nonProblemClassesToFilter = - new ImmutableSet.Builder<String>() - .add("DefaultSeverity.java") - .add("CompositeProblemFilter.java") - .add("FilteredIterator.java") - .add("CompilerProblemSeverity.java") - .build(); - - abstract protected File getInputDirectory(); - abstract protected File getOutputDirectory(); - abstract protected String getOutputFile(); - - public void execute() throws MojoExecutionException - { - File generatedFile = new File(getOutputDirectory(), getOutputFile()); - - if(!generatedFile.getParentFile().exists()) { - if(!generatedFile.getParentFile().mkdirs()) { - throw new MojoExecutionException("Could not create output directory: " + generatedFile.getParentFile()); - } - } - - try { - PrintWriter writer = new PrintWriter(new FileWriter(generatedFile, true)); - try { - printHeader(writer); - - Collection<File> problemClassSourceFiles = getProblemClassSourceFiles(getInputDirectory()); - Iterator<File> problemClassSourceFileIterator = problemClassSourceFiles.iterator(); - while (problemClassSourceFileIterator.hasNext()) { - File problemClassSourceFile = problemClassSourceFileIterator.next(); - printEntry(writer, problemClassSourceFile, !problemClassSourceFileIterator.hasNext()); - } - - printFooter(writer); - } finally { - writer.close(); - } - } catch (IOException e) { - throw new MojoExecutionException("Caught Exception while trying to create output file: " + generatedFile); - } - } - - - protected void printHeader(PrintWriter writer) { - // Optional. - } - - abstract protected void printEntry(PrintWriter writer, File source, boolean last); - - protected void printFooter(PrintWriter writer) { - // Optional. - } - - /** - * Recursively search a directory and its sub-directories for .class files. - * Use the file name to determine what equivalent class name should be - * available to the current classloader. - * - * @param dir - the directory to search - * @return list of source files found - */ - protected Collection<File> getProblemClassSourceFiles(File dir) - { - Collection<File> problemFiles = FileUtils.listFiles(dir, new String[] { "java" }, true); - return Collections2.filter(problemFiles, - new Predicate<File>() { - @Override - public boolean apply(File input) - { - return isProblemClass(input); - } - }); - } - - private boolean isProblemClass(File javaFile) - { - if (nonProblemClassesToFilter.contains(javaFile.getName())) - return false; - final String javaClassName = FilenameUtils.getBaseName(javaFile.getAbsolutePath()); - try - { - Collection<String> lines = Files.readLines(javaFile, Charset.forName("UTF8")); - for (String line : lines) - { - if (line.matches("^\\s*public\\s+final\\s+class\\s+" + javaClassName + "\\s+extends\\s+.*")) - return true; - if (line.matches("^\\s*final\\s+public\\s+class\\s+" + javaClassName + "\\s+extends\\s+.*")) - return true; - if (line.matches("^\\s*public\\s+class\\s+" + javaClassName + "\\s+extends\\s+.*")) - return true; - } - return false; - } - catch (IOException e) - { - return false; - } - - } - -} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/ProblemEnumGeneratorMojo.java ---------------------------------------------------------------------- diff --git a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/ProblemEnumGeneratorMojo.java b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/ProblemEnumGeneratorMojo.java deleted file mode 100644 index 54b621b..0000000 --- a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/ProblemEnumGeneratorMojo.java +++ /dev/null @@ -1,152 +0,0 @@ -package org.apache.flex.compiler.tools; - -/* - * Copyright 2001-2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.project.MavenProject; - -import java.io.File; -import java.io.PrintWriter; - -/** - * Goal which touches a timestamp file. - */ -@Mojo(name="generate-problems-enum",defaultPhase = LifecyclePhase.GENERATE_SOURCES) -public class ProblemEnumGeneratorMojo - extends BaseProblemGeneratorMojo -{ - @Parameter(defaultValue="${project.basedir}/src/main/java/org/apache/flex/compiler/problems", - property="inputDir", required=true) - private File inputDirectory; - - @Parameter(defaultValue="${project.build.directory}/generated-sources/build-tools", - property="outputDir", required=true) - private File outputDirectory; - - @Parameter(defaultValue="org/apache/flex/compiler/problems/ProblemID.java", - property="outputFile", required=true) - private String outputFile; - - @Parameter(defaultValue="${project}") - private MavenProject project; - - @Override - protected File getInputDirectory() { - return inputDirectory; - } - - @Override - protected File getOutputDirectory() { - return outputDirectory; - } - - @Override - protected String getOutputFile() { - return outputFile; - } - - @Override - public void execute() throws MojoExecutionException { - super.execute(); - - // Add the output directory to the source path. - project.addCompileSourceRoot(outputDirectory.getPath()); - } - - @Override - protected void printHeader(PrintWriter writer) { - writer.println("/*"); - writer.println(" * Licensed to the Apache Software Foundation (ASF) under one or more"); - writer.println(" * contributor license agreements. See the NOTICE file distributed with"); - writer.println(" * this work for additional information regarding copyright ownership."); - writer.println(" * The ASF licenses this file to You under the Apache License, Version 2.0"); - writer.println(" * (the \"License\"); you may not use this file except in compliance with"); - writer.println(" * the License. You may obtain a copy of the License at"); - writer.println(); - writer.println(" * http://www.apache.org/licenses/LICENSE-2.0"); - writer.println(); - writer.println(" * Unless required by applicable law or agreed to in writing, software"); - writer.println(" * distributed under the License is distributed on an \"AS IS\" BASIS,"); - writer.println(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied."); - writer.println(" * See the License for the specific language governing permissions and"); - writer.println(" * limitations under the License."); - writer.println(" */"); - writer.println(); - writer.println("package org.apache.flex.compiler.problems;"); - writer.println(); - writer.println("import java.util.EnumSet;"); - writer.println("import com.google.common.collect.ImmutableMap;"); - writer.println(); - writer.println("public enum ProblemID"); - writer.println("{"); - } - - @Override - protected void printEntry(PrintWriter writer, File source, boolean last) { - writer.println(" " + getProblemEnumEntry(source.getName()) + (last ? ";" : ",")); - } - - @Override - protected void printFooter(PrintWriter writer) { - writer.println(); - writer.println(" private ProblemID(Class<? extends CompilerProblem> problemClass)"); - writer.println(" {"); - writer.println(" this.problemClass = problemClass;"); - writer.println(" }"); - writer.println(); - writer.println(" private final Class<? extends CompilerProblem> problemClass;"); - writer.println(" public final Class<? extends CompilerProblem> getProblemClass()"); - writer.println(" {"); - writer.println(" return problemClass;"); - writer.println(" }"); - writer.println(); - writer.println(" public static final ProblemID getID(ICompilerProblem problem)"); - writer.println(" {"); - writer.println(" final CompilerProblem problemImpl = (CompilerProblem)problem;"); - writer.println(" return classToIDMap.get(problemImpl.getClass());"); - writer.println(" }"); - writer.println(); - writer.println(" public static final ProblemID getID(Class<?> problemClass)"); - writer.println(" {"); - writer.println(" return classToIDMap.get(problemClass);"); - writer.println(" }"); - writer.println(); - writer.println(" private static final ImmutableMap<Class<? extends CompilerProblem>, ProblemID> classToIDMap = createClassToIDMap();"); - writer.println(" private static ImmutableMap<Class<? extends CompilerProblem>, ProblemID> createClassToIDMap()"); - writer.println(" {"); - writer.println(" final ImmutableMap.Builder<Class<? extends CompilerProblem>, ProblemID> builder = new ImmutableMap.Builder<Class<? extends CompilerProblem>, ProblemID>();"); - writer.println(" for (ProblemID id : EnumSet.allOf(ProblemID.class))"); - writer.println(" builder.put(id.getProblemClass(), id);"); - writer.println(" return builder.build();"); - writer.println(" }"); - writer.println("}"); - } - - private static String getProblemEnumEntry(String problemClassName) { - String problemTypeName = problemClassName.substring(0, problemClassName.length() - "class".length()); - String enumConstantName = getEnumName(problemTypeName.replaceAll("Problem$", "")); - return enumConstantName + "(" + problemTypeName + ".class" + ")"; - } - - private static String getEnumName(String problemTypeName) { - return "PROBLEM_" + problemTypeName; - } - -} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/ProblemResourceBundleGeneratorMojo.java ---------------------------------------------------------------------- diff --git a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/ProblemResourceBundleGeneratorMojo.java b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/ProblemResourceBundleGeneratorMojo.java deleted file mode 100644 index dcbedce..0000000 --- a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/ProblemResourceBundleGeneratorMojo.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.apache.flex.compiler.tools; - -/* - * Copyright 2001-2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.project.MavenProject; - -import java.io.*; - -/** - * Goal which touches a timestamp file. - */ -@Mojo(name="generate-problems-resource-bundle",defaultPhase = LifecyclePhase.PROCESS_RESOURCES) -public class ProblemResourceBundleGeneratorMojo - extends BaseProblemGeneratorMojo -{ - @Parameter(defaultValue="${project.basedir}/src/main/java/org/apache/flex/compiler/problems", - property="inputDir", required=true) - private File inputDirectory; - - @Parameter(defaultValue="${project.build.directory}/classes/org/apache/flex/compiler", - property="outputDir", required=true) - private File outputDirectory; - - @Parameter(defaultValue="messages_en.properties", - property="outputFile", required=true) - private String outputFile; - - @Parameter(defaultValue="${project}") - private MavenProject project; - - @Override - protected File getInputDirectory() { - return inputDirectory; - } - - @Override - protected File getOutputDirectory() { - return outputDirectory; - } - - @Override - protected String getOutputFile() { - return outputFile; - } - - @Override - protected void printEntry(PrintWriter writer, File source, boolean last) { - writer.println(getProblemName(source) + "=" + getProblemDescription(source)); - } - - private String getProblemName(File sourceFile) { - String fileName = sourceFile.getName(); - return fileName.substring(0, fileName.length() - "class".length()); - } - - private String getProblemDescription(File sourceFile) { - try { - BufferedReader sourceFileReader = new BufferedReader(new FileReader(sourceFile)); - String line; - StringBuilder sb = null; - while((line = sourceFileReader.readLine()) != null) { - if(line.contains("DESCRIPTION")) { - sb = new StringBuilder(); - } - if(sb != null) { - sb.append(line); - if(line.trim().endsWith(";")) { - break; - } - } - } - if(sb != null) { - line = sb.toString(); - return line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\"")); - } - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - return ""; - } - -} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/annotate/AnnotateClassesMojo.java ---------------------------------------------------------------------- diff --git a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/annotate/AnnotateClassesMojo.java b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/annotate/AnnotateClassesMojo.java new file mode 100644 index 0000000..82712da --- /dev/null +++ b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/annotate/AnnotateClassesMojo.java @@ -0,0 +1,135 @@ +package org.apache.flex.compiler.tools.annotate; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.compiler.util.scan.InclusionScanException; +import org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner; +import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping; + +import java.io.*; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/** + * Goal which adds annotations to generated classes. + */ +@Mojo(name="add-class-annotation",defaultPhase = LifecyclePhase.PROCESS_SOURCES) +public class AnnotateClassesMojo + extends AbstractMojo +{ + @Parameter + protected Set<String> includes = new HashSet<String>(); + + @Parameter + protected Set<String> excludes = new HashSet<String>(); + + @Parameter(defaultValue="${project.build.directory}/generated-sources") + private File directory; + + @Parameter(property="annotation", required=true) + private String annotation; + + public void execute() + throws MojoExecutionException + { + SuffixMapping mapping = new SuffixMapping("jbg", Collections.<String>emptySet()); + SimpleSourceInclusionScanner scan = new SimpleSourceInclusionScanner(includes, excludes); + scan.addSourceMapping(mapping); + + try { + Set<File> candidates = scan.getIncludedSources(directory, null); + for(File candidate : candidates) { + processFile(candidate); + } + } catch (InclusionScanException e) { + throw new MojoExecutionException("Error scanning files to be processed.", e); + } + } + + private void processFile(File file) { + if(!file.exists()) { + System.out.println("Missing file: " + file.getPath()); + return; + } + System.out.println("Adding " + annotation + " to class: " + file.getPath()); + try + { + // Prepare to read the file. + FileInputStream fileInputStream = new FileInputStream(file); + InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream); + BufferedReader bufferedReader = new BufferedReader(inputStreamReader); + + File tmpOutputFile = new File(file.getParentFile(), file.getName() + ".tmp"); + FileOutputStream fileOutputStream = new FileOutputStream(tmpOutputFile); + PrintStream outputStream = new PrintStream(fileOutputStream); + try + { + // Read it line-by-line. + String line; + while ((line = bufferedReader.readLine()) != null) + { + // If the line starts with "public class", output the annotation on the previous line. + if (line.startsWith("public class") || line.startsWith("public interface")) { + outputStream.println(annotation); + } + outputStream.println(line); + } + } + finally + { + try { + bufferedReader.close(); + } catch(Exception e) { + // Ignore. + } + try { + outputStream.close(); + } catch(Exception e) { + // Ignore. + } + try { + fileOutputStream.close(); + } catch(Exception e) { + // Ignore. + } + } + + // Remove the original file. + if(!file.delete()) { + throw new MojoExecutionException("Error deleting original file at: " + file.getPath()); + } + + // Rename the temp file to the name of the original file. + if(!tmpOutputFile.renameTo(file)) { + throw new MojoExecutionException("Error renaming the temp file from: " + tmpOutputFile.getPath() + + " to: " + file.getPath()); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/CopyFileOperation.java ---------------------------------------------------------------------- diff --git a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/CopyFileOperation.java b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/CopyFileOperation.java new file mode 100644 index 0000000..188d946 --- /dev/null +++ b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/CopyFileOperation.java @@ -0,0 +1,31 @@ +package org.apache.flex.compiler.tools.patchfiles; + +import org.apache.commons.io.FileUtils; + +import java.io.File; +import java.io.IOException; + +/** + * Created by christoferdutz on 16.03.16. + */ +public class CopyFileOperation extends Operation { + + private File targetDirectory; + + public CopyFileOperation() { + } + + public File getTargetDirectory() { + return targetDirectory; + } + + public void setTargetDirectory(File targetDirectory) { + this.targetDirectory = targetDirectory; + } + + @Override + public void perform(File file) throws IOException { + FileUtils.copyFile(file, new File(targetDirectory, file.getName())); + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/CutOperation.java ---------------------------------------------------------------------- diff --git a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/CutOperation.java b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/CutOperation.java new file mode 100644 index 0000000..2834704 --- /dev/null +++ b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/CutOperation.java @@ -0,0 +1,54 @@ +package org.apache.flex.compiler.tools.patchfiles; + +import org.apache.commons.io.IOUtils; + +import java.io.*; + +/** + * Created by christoferdutz on 16.03.16. + */ +public class CutOperation extends Operation { + + private Integer startCuttingLine = -1; + private Integer stopCuttingLine = -1; + + public CutOperation() { + } + + public Integer getStartCuttingLine() { + return startCuttingLine; + } + + public void setStartCuttingLine(Integer startCuttingLine) { + this.startCuttingLine = startCuttingLine; + } + + public Integer getStopCuttingLine() { + return stopCuttingLine; + } + + public void setStopCuttingLine(Integer stopCuttingLine) { + this.stopCuttingLine = stopCuttingLine; + } + + @Override + public void perform(File file) throws IOException { + StringBuilder sb = new StringBuilder(); + BufferedReader reader = null; + try { + reader = new BufferedReader(new FileReader(file)); + String line; + for (int lineNumber = 1; (line = reader.readLine()) != null; lineNumber++) { + if((startCuttingLine > lineNumber) || (lineNumber > stopCuttingLine)) { + sb.append(line).append("\n"); + } + } + } finally { + if(reader != null) { + reader.close(); + } + } + IOUtils.write(sb.toString(), new FileOutputStream(file), "UTF-8"); + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/DeleteFileOperation.java ---------------------------------------------------------------------- diff --git a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/DeleteFileOperation.java b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/DeleteFileOperation.java new file mode 100644 index 0000000..ab225cb --- /dev/null +++ b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/DeleteFileOperation.java @@ -0,0 +1,23 @@ +package org.apache.flex.compiler.tools.patchfiles; + +import java.io.File; +import java.io.IOException; + +/** + * Created by christoferdutz on 16.03.16. + */ +public class DeleteFileOperation extends Operation { + + public DeleteFileOperation() { + } + + @Override + public void perform(File file) throws IOException { + if(file.exists()) { + if(!file.delete()) { + throw new IOException("Could not delete file " + file.getPath()); + } + } + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/Operation.java ---------------------------------------------------------------------- diff --git a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/Operation.java b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/Operation.java new file mode 100644 index 0000000..3c387d3 --- /dev/null +++ b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/Operation.java @@ -0,0 +1,13 @@ +package org.apache.flex.compiler.tools.patchfiles; + +import java.io.File; +import java.io.IOException; + +/** + * Created by christoferdutz on 16.03.16. + */ +public abstract class Operation { + + public abstract void perform(File file) throws IOException; + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/PreProcessSourcesMojo.java ---------------------------------------------------------------------- diff --git a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/PreProcessSourcesMojo.java b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/PreProcessSourcesMojo.java new file mode 100644 index 0000000..facd686 --- /dev/null +++ b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/PreProcessSourcesMojo.java @@ -0,0 +1,86 @@ +package org.apache.flex.compiler.tools.patchfiles; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.compiler.util.scan.InclusionScanException; +import org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner; +import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping; + +import java.io.File; +import java.io.IOException; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * Goal which pre-processes the JavaScript input files so they can be processed by EXTERNC. + */ +@Mojo(name="pre-process-sources",defaultPhase = LifecyclePhase.GENERATE_SOURCES) +public class PreProcessSourcesMojo + extends AbstractMojo +{ + + @Parameter + private Set<String> includes = new HashSet<String>(); + + @Parameter + private Set<String> excludes = new HashSet<String>(); + + @Parameter(defaultValue="${project.build.directory}/downloads") + private File downloadesSourceDirectory; + + @Parameter + private List<Operation> operations; + + @Parameter(defaultValue="${project}") + private MavenProject project; + + public void execute() + throws MojoExecutionException + { + SuffixMapping mapping = new SuffixMapping("js", Collections.<String>emptySet()); + SimpleSourceInclusionScanner scan = new SimpleSourceInclusionScanner(includes, excludes); + scan.addSourceMapping(mapping); + try { + Set<File> candidates = scan.getIncludedSources(downloadesSourceDirectory, null); + for(File candidate : candidates) { + if(operations != null) { + for (Operation operation : operations) { + try { + operation.perform(candidate); + } catch (IOException e) { + throw new MojoExecutionException("Error performing pre-processing operation " + + operation + " on file " + candidate.getPath(), e); + } + } + } + } + } catch (InclusionScanException e) { + throw new MojoExecutionException("Error scanning files to be processed.", e); + } + } + + + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/ReplaceOperation.java ---------------------------------------------------------------------- diff --git a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/ReplaceOperation.java b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/ReplaceOperation.java new file mode 100644 index 0000000..ef85301 --- /dev/null +++ b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/ReplaceOperation.java @@ -0,0 +1,46 @@ +package org.apache.flex.compiler.tools.patchfiles; + +import org.apache.commons.io.IOUtils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Created by christoferdutz on 16.03.16. + */ +public class ReplaceOperation extends Operation { + + private String token; + private String value; + + public ReplaceOperation() { + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + @Override + public void perform(File file) throws IOException { + String content = IOUtils.toString(new FileInputStream(file), "UTF-8"); + content = content.replaceAll(Pattern.quote(token), Matcher.quoteReplacement((value == null) ? "" : value)); + IOUtils.write(content, new FileOutputStream(file), "UTF-8"); + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/ReplaceRegexpOperation.java ---------------------------------------------------------------------- diff --git a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/ReplaceRegexpOperation.java b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/ReplaceRegexpOperation.java new file mode 100644 index 0000000..e76fc84 --- /dev/null +++ b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/patchfiles/ReplaceRegexpOperation.java @@ -0,0 +1,68 @@ +package org.apache.flex.compiler.tools.patchfiles; + +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.io.IOUtils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; + +/** + * Created by christoferdutz on 16.03.16. + */ +public class ReplaceRegexpOperation extends Operation { + + private String match; + private String replace; + private String flags; + + public ReplaceRegexpOperation() { + } + + public String getMatch() { + return match; + } + + public void setMatch(String match) { + this.match = match; + } + + public String getReplace() { + return replace; + } + + public void setReplace(String replace) { + this.replace = replace; + } + + public String getFlags() { + return flags; + } + + public void setFlags(String flags) { + this.flags = flags; + } + + @Override + public void perform(File file) throws IOException { + String content = IOUtils.toString(new FileInputStream(file), "UTF-8"); + // TODO: Add the "flags" support + String matchExpression = match; + if(matchExpression.contains("§{file.base}")) { + matchExpression = matchExpression.replaceAll("§\\{file.base\\}", FilenameUtils.getBaseName(file.getName())); + } + String replaceExpression = (replace == null) ? "" : replace; + if(replaceExpression.contains("§{file.base}")) { + replaceExpression = replaceExpression.replaceAll("§\\{file.base\\}", FilenameUtils.getBaseName(file.getName())); + } + if(replaceExpression.contains("_")) { + replaceExpression = replaceExpression.replaceAll("_", " "); + } + + //content = Pattern.compile(matchExpression, Pattern.DOTALL).matcher(content).replaceAll(replaceExpression); + content = content.replaceAll(matchExpression, replaceExpression); + IOUtils.write(content, new FileOutputStream(file), "UTF-8"); + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/problems/BaseProblemGeneratorMojo.java ---------------------------------------------------------------------- diff --git a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/problems/BaseProblemGeneratorMojo.java b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/problems/BaseProblemGeneratorMojo.java new file mode 100644 index 0000000..24f2560 --- /dev/null +++ b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/problems/BaseProblemGeneratorMojo.java @@ -0,0 +1,127 @@ +package org.apache.flex.compiler.tools.problems; + +import com.google.common.base.Predicate; +import com.google.common.collect.Collections2; +import com.google.common.collect.ImmutableSet; +import com.google.common.io.Files; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.FilenameUtils; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.charset.Charset; +import java.util.Collection; +import java.util.Iterator; + +/** + * Created by christoferdutz on 20.02.16. + */ +public abstract class BaseProblemGeneratorMojo extends AbstractMojo +{ + + private ImmutableSet<String> nonProblemClassesToFilter = + new ImmutableSet.Builder<String>() + .add("DefaultSeverity.java") + .add("CompositeProblemFilter.java") + .add("FilteredIterator.java") + .add("CompilerProblemSeverity.java") + .build(); + + abstract protected File getInputDirectory(); + abstract protected File getOutputDirectory(); + abstract protected String getOutputFile(); + + public void execute() throws MojoExecutionException + { + File generatedFile = new File(getOutputDirectory(), getOutputFile()); + + if(!generatedFile.getParentFile().exists()) { + if(!generatedFile.getParentFile().mkdirs()) { + throw new MojoExecutionException("Could not create output directory: " + generatedFile.getParentFile()); + } + } + + try { + PrintWriter writer = new PrintWriter(new FileWriter(generatedFile, true)); + try { + printHeader(writer); + + Collection<File> problemClassSourceFiles = getProblemClassSourceFiles(getInputDirectory()); + Iterator<File> problemClassSourceFileIterator = problemClassSourceFiles.iterator(); + while (problemClassSourceFileIterator.hasNext()) { + File problemClassSourceFile = problemClassSourceFileIterator.next(); + printEntry(writer, problemClassSourceFile, !problemClassSourceFileIterator.hasNext()); + } + + printFooter(writer); + } finally { + writer.close(); + } + } catch (IOException e) { + throw new MojoExecutionException("Caught Exception while trying to create output file: " + generatedFile); + } + } + + + protected void printHeader(PrintWriter writer) { + // Optional. + } + + abstract protected void printEntry(PrintWriter writer, File source, boolean last); + + protected void printFooter(PrintWriter writer) { + // Optional. + } + + /** + * Recursively search a directory and its sub-directories for .class files. + * Use the file name to determine what equivalent class name should be + * available to the current classloader. + * + * @param dir - the directory to search + * @return list of source files found + */ + protected Collection<File> getProblemClassSourceFiles(File dir) + { + Collection<File> problemFiles = FileUtils.listFiles(dir, new String[] { "java" }, true); + return Collections2.filter(problemFiles, + new Predicate<File>() { + @Override + public boolean apply(File input) + { + return isProblemClass(input); + } + }); + } + + private boolean isProblemClass(File javaFile) + { + if (nonProblemClassesToFilter.contains(javaFile.getName())) + return false; + final String javaClassName = FilenameUtils.getBaseName(javaFile.getAbsolutePath()); + try + { + Collection<String> lines = Files.readLines(javaFile, Charset.forName("UTF8")); + for (String line : lines) + { + if (line.matches("^\\s*public\\s+final\\s+class\\s+" + javaClassName + "\\s+extends\\s+.*")) + return true; + if (line.matches("^\\s*final\\s+public\\s+class\\s+" + javaClassName + "\\s+extends\\s+.*")) + return true; + if (line.matches("^\\s*public\\s+class\\s+" + javaClassName + "\\s+extends\\s+.*")) + return true; + } + return false; + } + catch (IOException e) + { + return false; + } + + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/problems/ProblemEnumGeneratorMojo.java ---------------------------------------------------------------------- diff --git a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/problems/ProblemEnumGeneratorMojo.java b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/problems/ProblemEnumGeneratorMojo.java new file mode 100644 index 0000000..d3acb6a --- /dev/null +++ b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/problems/ProblemEnumGeneratorMojo.java @@ -0,0 +1,152 @@ +package org.apache.flex.compiler.tools.problems; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; + +import java.io.File; +import java.io.PrintWriter; + +/** + * Goal which touches a timestamp file. + */ +@Mojo(name="generate-problems-enum",defaultPhase = LifecyclePhase.GENERATE_SOURCES) +public class ProblemEnumGeneratorMojo + extends BaseProblemGeneratorMojo +{ + @Parameter(defaultValue="${project.basedir}/src/main/java/org/apache/flex/compiler/problems", + property="inputDir", required=true) + private File inputDirectory; + + @Parameter(defaultValue="${project.build.directory}/generated-sources/build-tools", + property="outputDir", required=true) + private File outputDirectory; + + @Parameter(defaultValue="org/apache/flex/compiler/problems/ProblemID.java", + property="outputFile", required=true) + private String outputFile; + + @Parameter(defaultValue="${project}") + private MavenProject project; + + @Override + protected File getInputDirectory() { + return inputDirectory; + } + + @Override + protected File getOutputDirectory() { + return outputDirectory; + } + + @Override + protected String getOutputFile() { + return outputFile; + } + + @Override + public void execute() throws MojoExecutionException { + super.execute(); + + // Add the output directory to the source path. + project.addCompileSourceRoot(outputDirectory.getPath()); + } + + @Override + protected void printHeader(PrintWriter writer) { + writer.println("/*"); + writer.println(" * Licensed to the Apache Software Foundation (ASF) under one or more"); + writer.println(" * contributor license agreements. See the NOTICE file distributed with"); + writer.println(" * this work for additional information regarding copyright ownership."); + writer.println(" * The ASF licenses this file to You under the Apache License, Version 2.0"); + writer.println(" * (the \"License\"); you may not use this file except in compliance with"); + writer.println(" * the License. You may obtain a copy of the License at"); + writer.println(); + writer.println(" * http://www.apache.org/licenses/LICENSE-2.0"); + writer.println(); + writer.println(" * Unless required by applicable law or agreed to in writing, software"); + writer.println(" * distributed under the License is distributed on an \"AS IS\" BASIS,"); + writer.println(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied."); + writer.println(" * See the License for the specific language governing permissions and"); + writer.println(" * limitations under the License."); + writer.println(" */"); + writer.println(); + writer.println("package org.apache.flex.compiler.problems;"); + writer.println(); + writer.println("import java.util.EnumSet;"); + writer.println("import com.google.common.collect.ImmutableMap;"); + writer.println(); + writer.println("public enum ProblemID"); + writer.println("{"); + } + + @Override + protected void printEntry(PrintWriter writer, File source, boolean last) { + writer.println(" " + getProblemEnumEntry(source.getName()) + (last ? ";" : ",")); + } + + @Override + protected void printFooter(PrintWriter writer) { + writer.println(); + writer.println(" private ProblemID(Class<? extends CompilerProblem> problemClass)"); + writer.println(" {"); + writer.println(" this.problemClass = problemClass;"); + writer.println(" }"); + writer.println(); + writer.println(" private final Class<? extends CompilerProblem> problemClass;"); + writer.println(" public final Class<? extends CompilerProblem> getProblemClass()"); + writer.println(" {"); + writer.println(" return problemClass;"); + writer.println(" }"); + writer.println(); + writer.println(" public static final ProblemID getID(ICompilerProblem problem)"); + writer.println(" {"); + writer.println(" final CompilerProblem problemImpl = (CompilerProblem)problem;"); + writer.println(" return classToIDMap.get(problemImpl.getClass());"); + writer.println(" }"); + writer.println(); + writer.println(" public static final ProblemID getID(Class<?> problemClass)"); + writer.println(" {"); + writer.println(" return classToIDMap.get(problemClass);"); + writer.println(" }"); + writer.println(); + writer.println(" private static final ImmutableMap<Class<? extends CompilerProblem>, ProblemID> classToIDMap = createClassToIDMap();"); + writer.println(" private static ImmutableMap<Class<? extends CompilerProblem>, ProblemID> createClassToIDMap()"); + writer.println(" {"); + writer.println(" final ImmutableMap.Builder<Class<? extends CompilerProblem>, ProblemID> builder = new ImmutableMap.Builder<Class<? extends CompilerProblem>, ProblemID>();"); + writer.println(" for (ProblemID id : EnumSet.allOf(ProblemID.class))"); + writer.println(" builder.put(id.getProblemClass(), id);"); + writer.println(" return builder.build();"); + writer.println(" }"); + writer.println("}"); + } + + private static String getProblemEnumEntry(String problemClassName) { + String problemTypeName = problemClassName.substring(0, problemClassName.length() - "class".length()); + String enumConstantName = getEnumName(problemTypeName.replaceAll("Problem$", "")); + return enumConstantName + "(" + problemTypeName + ".class" + ")"; + } + + private static String getEnumName(String problemTypeName) { + return "PROBLEM_" + problemTypeName; + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/problems/ProblemResourceBundleGeneratorMojo.java ---------------------------------------------------------------------- diff --git a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/problems/ProblemResourceBundleGeneratorMojo.java b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/problems/ProblemResourceBundleGeneratorMojo.java new file mode 100644 index 0000000..be1b467 --- /dev/null +++ b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/problems/ProblemResourceBundleGeneratorMojo.java @@ -0,0 +1,101 @@ +package org.apache.flex.compiler.tools.problems; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; + +import java.io.*; + +/** + * Goal which touches a timestamp file. + */ +@Mojo(name="generate-problems-resource-bundle",defaultPhase = LifecyclePhase.PROCESS_RESOURCES) +public class ProblemResourceBundleGeneratorMojo + extends BaseProblemGeneratorMojo +{ + @Parameter(defaultValue="${project.basedir}/src/main/java/org/apache/flex/compiler/problems", + property="inputDir", required=true) + private File inputDirectory; + + @Parameter(defaultValue="${project.build.directory}/classes/org/apache/flex/compiler", + property="outputDir", required=true) + private File outputDirectory; + + @Parameter(defaultValue="messages_en.properties", + property="outputFile", required=true) + private String outputFile; + + @Parameter(defaultValue="${project}") + private MavenProject project; + + @Override + protected File getInputDirectory() { + return inputDirectory; + } + + @Override + protected File getOutputDirectory() { + return outputDirectory; + } + + @Override + protected String getOutputFile() { + return outputFile; + } + + @Override + protected void printEntry(PrintWriter writer, File source, boolean last) { + writer.println(getProblemName(source) + "=" + getProblemDescription(source)); + } + + private String getProblemName(File sourceFile) { + String fileName = sourceFile.getName(); + return fileName.substring(0, fileName.length() - "class".length()); + } + + private String getProblemDescription(File sourceFile) { + try { + BufferedReader sourceFileReader = new BufferedReader(new FileReader(sourceFile)); + String line; + StringBuilder sb = null; + while((line = sourceFileReader.readLine()) != null) { + if(line.contains("DESCRIPTION")) { + sb = new StringBuilder(); + } + if(sb != null) { + sb.append(line); + if(line.trim().endsWith(";")) { + break; + } + } + } + if(sb != null) { + line = sb.toString(); + return line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\"")); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return ""; + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/unpack/UnpackResourceMojo.java ---------------------------------------------------------------------- diff --git a/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/unpack/UnpackResourceMojo.java b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/unpack/UnpackResourceMojo.java new file mode 100644 index 0000000..aa5ac4f --- /dev/null +++ b/compiler-build-tools/src/main/java/org/apache/flex/compiler/tools/unpack/UnpackResourceMojo.java @@ -0,0 +1,100 @@ +package org.apache.flex.compiler.tools.unpack; + +import org.apache.commons.compress.archivers.ArchiveEntry; +import org.apache.commons.compress.archivers.ArchiveException; +import org.apache.commons.compress.archivers.ArchiveInputStream; +import org.apache.commons.compress.archivers.ArchiveStreamFactory; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; + +import java.io.*; + +/** + * Created by christoferdutz on 18.03.16. + */ +@Mojo(name="unpack-resources",defaultPhase = LifecyclePhase.GENERATE_SOURCES) +public class UnpackResourceMojo + extends AbstractMojo { + + private static final int KILOBYTE = 1024; + private static final int MEGABYTE = KILOBYTE * 1024; + private static final int BUFFER_MAX = MEGABYTE; + + @Parameter(required = true) + private String resource; + + @Parameter(defaultValue="${project.build.directory}/downloads") + private File targetDirectory; + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + InputStream is = getClass().getClassLoader().getResourceAsStream(resource); + if(is == null) { + throw new MojoExecutionException("Could not find resource " + resource); + } + + if(!targetDirectory.exists() && !targetDirectory.mkdirs()) { + throw new MojoExecutionException("Could not create output directory " + targetDirectory.getPath()); + } + + final byte[] data = new byte[BUFFER_MAX]; + ArchiveInputStream archiveInputStream = null; + ArchiveEntry entry; + try { + archiveInputStream = new ArchiveStreamFactory().createArchiveInputStream( + new BufferedInputStream(is)); + + while ((entry = archiveInputStream.getNextEntry()) != null) { + final File outputFile = new File(targetDirectory, entry.getName()); + + // Entry is a directory. + if (entry.isDirectory()) { + if (!outputFile.exists()) { + if(!outputFile.mkdirs()) { + throw new MojoExecutionException( + "Could not create output directory " + outputFile.getAbsolutePath()); + } + } + } + + // Entry is a file. + else { + final FileOutputStream fos = new FileOutputStream(outputFile); + BufferedOutputStream dest = null; + try { + dest = new BufferedOutputStream(fos, BUFFER_MAX); + + int count; + while ((count = archiveInputStream.read(data, 0, BUFFER_MAX)) != -1) { + dest.write(data, 0, count); + } + } finally { + if(dest != null) { + dest.flush(); + dest.close(); + } + } + } + } + } catch (FileNotFoundException e) { + throw new MojoExecutionException("Error unpacking resources", e); + } catch (IOException e) { + throw new MojoExecutionException("Error unpacking resources", e); + } catch (ArchiveException e) { + throw new MojoExecutionException("Error unpacking resources", e); + } finally { + if(archiveInputStream != null) { + try { + archiveInputStream.close(); + } catch(Exception e) { + // Ignore... + } + } + } + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/compiler.jx/pom.xml ---------------------------------------------------------------------- diff --git a/compiler.jx/pom.xml b/compiler.jx/pom.xml index 0b90a3c..e1f748e 100644 --- a/compiler.jx/pom.xml +++ b/compiler.jx/pom.xml @@ -94,7 +94,7 @@ <dependency> <groupId>com.google.javascript</groupId> <artifactId>closure-compiler</artifactId> - <version>v20150609</version> + <version>v20151015</version> </dependency> <dependency> <groupId>org.clojure</groupId> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/compiler/pom.xml ---------------------------------------------------------------------- diff --git a/compiler/pom.xml b/compiler/pom.xml index a2ee9b6..84b6cab 100644 --- a/compiler/pom.xml +++ b/compiler/pom.xml @@ -408,7 +408,7 @@ <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> - <version>17.0</version> + <version>18.0</version> </dependency> <dependency> <groupId>net.sourceforge.jburg</groupId> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/externs/GCL/pom.xml ---------------------------------------------------------------------- diff --git a/externs/GCL/pom.xml b/externs/GCL/pom.xml new file mode 100644 index 0000000..6fae9b2 --- /dev/null +++ b/externs/GCL/pom.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.flex.flexjs.compiler</groupId> + <artifactId>flex-compiler-externs</artifactId> + <version>0.6.0-SNAPSHOT</version> + </parent> + + <artifactId>flex-compiler-externs-gcl</artifactId> + <version>0.6.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <name>Apache Flex - FlexJS Compiler: Externs: GCL</name> + + <build> + <plugins> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/externs/GCL/src/main/config/compile-config.xml ---------------------------------------------------------------------- diff --git a/externs/GCL/src/main/config/compile-config.xml b/externs/GCL/src/main/config/compile-config.xml new file mode 100644 index 0000000..715ef39 --- /dev/null +++ b/externs/GCL/src/main/config/compile-config.xml @@ -0,0 +1,103 @@ +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<flex-config> + + <compiler> + + <accessible>true</accessible> + + <!-- + <external-library-path> + <path-element>${env.PLAYERGLOBAL_HOME}/${playerglobal.version}/playerglobal.swc</path-element> + <path-element>../../libs/framework.swc</path-element> + <path-element>../../libs/mx/mx.swc</path-element> + <path-element>../../libs/osmf.swc</path-element> + <path-element>../../libs/textLayout.swc</path-element> + </external-library-path> + + <keep-as3-metadata> + <name>SkinPart</name> + </keep-as3-metadata> + + <mxml> + <minimum-supported-version>4.0.0</minimum-supported-version> + </mxml> + + <locale/> + + <library-path/> + + <namespaces> + <namespace> + <uri>library://ns.adobe.com/flex/spark</uri> + <manifest>manifest.xml</manifest> + </namespace> + </namespaces> + --> + + <external-library-path> + <path-element>../js/out/bin/js.swc</path-element> + </external-library-path> + + <source-path> + <path-element>src</path-element> + <!--<path-element>out/as/classes</path-element> + <path-element>out/as/interfaces</path-element> + <path-element>out/as/constants</path-element> + <path-element>out/as/functions</path-element> + <path-element>out/as/interfaces</path-element> + <path-element>out/as/typedefs</path-element>--> + </source-path> + + <warn-no-constructor>false</warn-no-constructor> + </compiler> + + <include-sources> + <path-element>src</path-element> + <!--<path-element>out/as/classes</path-element> + <path-element>out/as/interfaces</path-element> + <path-element>out/as/constants</path-element> + <path-element>out/as/functions</path-element> + <path-element>out/as/interfaces</path-element> + <path-element>out/as/typedefs</path-element>--> + </include-sources> + + <!-- + <include-file> + <name>defaults.css</name> + <path>defaults.css</path> + </include-file> + <include-file> + <name>assets/ErrorIndicator.png</name> + <path>assets/ErrorIndicator.png</path> + </include-file> + <include-file> + <name>assets/RequiredIndicator.png</name> + <path>assets/RequiredIndicator.png</path> + </include-file> + + <include-namespaces> + <uri>library://ns.adobe.com/flex/spark</uri> + </include-namespaces> + + <resource-bundle-list>bundles.properties</resource-bundle-list> + + <target-player>${playerglobal.version}</target-player> + --> +</flex-config> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/externs/cordova/pom.xml ---------------------------------------------------------------------- diff --git a/externs/cordova/pom.xml b/externs/cordova/pom.xml new file mode 100644 index 0000000..9ccad91 --- /dev/null +++ b/externs/cordova/pom.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.flex.flexjs.compiler</groupId> + <artifactId>flex-compiler-externs</artifactId> + <version>0.6.0-SNAPSHOT</version> + </parent> + + <artifactId>flex-compiler-externs-cordova</artifactId> + <version>0.6.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <name>Apache Flex - FlexJS Compiler: Externs: Cordova</name> + + <properties> + <cordova.version>4.11</cordova.version> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.apache.flex.flexjs.compiler</groupId> + <artifactId>externc-maven-plugin</artifactId> + <version>0.6.0-SNAPSHOT</version> + <executions> + <execution> + <id>generate</id> + <goals> + <goal>generate</goal> + </goals> + </execution> + <execution> + <id>compile</id> + <goals> + <goal>compile</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <dependencies> + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/externs/cordova/src/main/config/compile-config.xml ---------------------------------------------------------------------- diff --git a/externs/cordova/src/main/config/compile-config.xml b/externs/cordova/src/main/config/compile-config.xml new file mode 100644 index 0000000..5499e36 --- /dev/null +++ b/externs/cordova/src/main/config/compile-config.xml @@ -0,0 +1,44 @@ +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<flex-config> + + <compiler> + <accessible>true</accessible> + + <external-library-path> + <!--path-element>../js/out/bin/js.swc</path-element--> + </external-library-path> + + <source-path> + <path-element>../../../target/generated-sources/externc/constants</path-element> + </source-path> + + <warn-no-constructor>false</warn-no-constructor> + </compiler> + + <include-sources> + <path-element>../../../target/generated-sources/externc/constants</path-element> + </include-sources> + + <include-file> + <name>externs/cordova_file_plugin-4-11.js</name> + <path>../javascript/cordova_file_plugin-4-11.js</path> + </include-file> + +</flex-config> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/dec07727/externs/cordova/src/main/config/generate-config.xml ---------------------------------------------------------------------- diff --git a/externs/cordova/src/main/config/generate-config.xml b/externs/cordova/src/main/config/generate-config.xml new file mode 100644 index 0000000..f10016a --- /dev/null +++ b/externs/cordova/src/main/config/generate-config.xml @@ -0,0 +1,39 @@ +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License</name></exclude> you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<flex-config> + + <compiler> + <accessible>true</accessible> + + <locale/> + + <source-path> + <path-element>src/main/javascript</path-element> + </source-path> + + <warn-no-constructor>false</warn-no-constructor> + </compiler> + + <external> + <path-element>../javascript/cordova_file_plugin-4-11.js</path-element> + </external> + + <as-root>../../../target/generated-sources/externc</as-root> + +</flex-config>
