You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cd...@apache.org on 2016/05/18 14:45:13 UTC
git commit: [flex-falcon] [refs/heads/develop] - - Implemented a goal
that dumps namespace manifests to the filesystem - Implemented an application
compiler goal - Added a "swf" lifecycle mapping - Fine-tuned the config
templates
Repository: flex-falcon
Updated Branches:
refs/heads/develop 78a150e71 -> 87ceb80b4
- Implemented a goal that dumps namespace manifests to the filesystem
- Implemented an application compiler goal
- Added a "swf" lifecycle mapping
- Fine-tuned the config templates
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/87ceb80b
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/87ceb80b
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/87ceb80b
Branch: refs/heads/develop
Commit: 87ceb80b47a227a4982d6b48532f694643523be2
Parents: 78a150e
Author: Christofer Dutz <ch...@codecentric.de>
Authored: Wed May 18 16:44:48 2016 +0200
Committer: Christofer Dutz <ch...@codecentric.de>
Committed: Wed May 18 16:45:07 2016 +0200
----------------------------------------------------------------------
README_MAVEN.txt | 4 +-
.../org/apache/flex/maven/flexjs/BaseMojo.java | 55 ++---
.../apache/flex/maven/flexjs/CompileASMojo.java | 2 +-
.../flex/maven/flexjs/CompileAppMojo.java | 152 +++++++++++++
.../flex/maven/flexjs/CompileExternMojo.java | 2 +-
.../apache/flex/maven/flexjs/CompileJSMojo.java | 2 +-
.../maven/flexjs/GenerateManifestsMojo.java | 211 +++++++++++++++++++
.../maven/flexjs/utils/DependencyHelper.java | 41 ++++
.../resources/META-INF/plexus/components.xml | 53 +++++
.../resources/config/compile-app-config.xml | 98 +++++++++
.../main/resources/config/compile-as-config.xml | 8 +-
.../resources/config/compile-extern-config.xml | 16 +-
.../main/resources/config/compile-js-config.xml | 16 +-
13 files changed, 614 insertions(+), 46 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/87ceb80b/README_MAVEN.txt
----------------------------------------------------------------------
diff --git a/README_MAVEN.txt b/README_MAVEN.txt
index eb33859..8443655 100644
--- a/README_MAVEN.txt
+++ b/README_MAVEN.txt
@@ -10,7 +10,7 @@ In order to build falcon with Maven you need to perform the following steps:
NOTE FOR WINDOWS USERS: tun the script using gitbash
3. Build the parts needed by the build
- mvn install -P minimal
+ mvn install -P utils
4. Build the project itself (without tests)
mvn install -DskipTests
@@ -33,7 +33,7 @@ to build with this settings.xml by adding the "-s" parameter to the call to mave
Look here for examples:
-mvn -s settings-template.xml clean install -P minimal
+mvn -s settings-template.xml clean install -P utils
mvn -s settings-template.xml clean install -DskipTests
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/87ceb80b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/BaseMojo.java
----------------------------------------------------------------------
diff --git a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/BaseMojo.java b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/BaseMojo.java
index 62321bf..7fa183c 100644
--- a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/BaseMojo.java
+++ b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/BaseMojo.java
@@ -1,9 +1,9 @@
package org.apache.flex.maven.flexjs;
+import org.apache.flex.maven.flexjs.utils.DependencyHelper;
import org.apache.flex.tools.FlexTool;
import org.apache.flex.tools.FlexToolGroup;
import org.apache.flex.tools.FlexToolRegistry;
-import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -67,14 +67,15 @@ public abstract class BaseMojo
protected VelocityContext getVelocityContext() throws MojoExecutionException {
VelocityContext context = new VelocityContext();
- List<Artifact> allLibraries = getAllLibraries();
+ List<Artifact> allLibraries = DependencyHelper.getAllLibraries(
+ project, repositorySystemSession, projectDependenciesResolver);
List<Artifact> libraries = getLibraries(allLibraries);
List<Artifact> externalLibraries = getExternalLibraries(allLibraries);
List<String> sourcePaths = getSourcePaths();
context.put("libraries", libraries);
context.put("externalLibraries", externalLibraries);
context.put("sourcePaths", sourcePaths);
- context.put("namespaces", namespaces);
+ context.put("namespaces", getNamespaces());
context.put("includeClasses", includeClasses);
context.put("targetPlayer", targetPlayer);
context.put("includeSources", includeSources);
@@ -88,18 +89,32 @@ public abstract class BaseMojo
protected abstract String getFlexTool();
+ protected Namespace[] getNamespaces() {
+ return namespaces;
+ }
+
@SuppressWarnings("unchecked")
protected List<String> getSourcePaths() {
List<String> sourcePaths = new LinkedList<String>();
- for(String sourcerPath : (List<String>) project.getCompileSourceRoots()) {
- if(new File(sourcerPath).exists()) {
- sourcePaths.add(sourcerPath);
+ for(String sourcePath : (List<String>) project.getCompileSourceRoots()) {
+ if(new File(sourcePath).exists()) {
+ sourcePaths.add(sourcePath);
}
}
return sourcePaths;
}
- protected List<String> getCompilerArgs(File configFile) {
+ protected String getSourcePath(String resourceOnPath) {
+ for(String path : getSourcePaths()) {
+ File tmpFile = new File(path, resourceOnPath);
+ if(tmpFile.exists()) {
+ return tmpFile.getPath();
+ }
+ }
+ return null;
+ }
+
+ protected List<String> getCompilerArgs(File configFile) throws MojoExecutionException {
List<String> args = new LinkedList<String>();
args.add("-load-config=" + configFile.getPath());
return args;
@@ -121,6 +136,12 @@ public abstract class BaseMojo
velocityEngine.init();
Template template = velocityEngine.getTemplate("config/" + getConfigFileName());
VelocityContext context = getVelocityContext();
+
+ if(!configFile.getParentFile().exists()) {
+ if(!configFile.getParentFile().mkdirs()) {
+ throw new MojoExecutionException("Could not create output directory: " + configFile.getParent());
+ }
+ }
FileWriter writer = null;
try {
writer = new FileWriter(configFile);
@@ -171,26 +192,6 @@ public abstract class BaseMojo
return externalLibraries;
}
- private List<Artifact> getAllLibraries() throws MojoExecutionException {
- DefaultDependencyResolutionRequest dependencyResolutionRequest =
- new DefaultDependencyResolutionRequest(project, repositorySystemSession);
- DependencyResolutionResult dependencyResolutionResult;
-
- try {
- dependencyResolutionResult = projectDependenciesResolver.resolve(dependencyResolutionRequest);
- } catch (DependencyResolutionException ex) {
- throw new MojoExecutionException(ex.getMessage(), ex);
- }
-
- List<Artifact> artifacts = new LinkedList<Artifact>();
- if (dependencyResolutionResult.getDependencyGraph() != null
- && !dependencyResolutionResult.getDependencyGraph().getChildren().isEmpty()) {
- RepositoryUtils.toArtifacts(artifacts, dependencyResolutionResult.getDependencyGraph().getChildren(),
- Collections.singletonList(project.getArtifact().getId()), null);
- }
- return artifacts;
- }
-
protected boolean includeLibrary(Artifact library) {
return true;
}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/87ceb80b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileASMojo.java
----------------------------------------------------------------------
diff --git a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileASMojo.java b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileASMojo.java
index 26635e8..e1d242e 100644
--- a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileASMojo.java
+++ b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileASMojo.java
@@ -66,7 +66,7 @@ public class CompileASMojo
}
@Override
- protected List<String> getCompilerArgs(File configFile) {
+ protected List<String> getCompilerArgs(File configFile) throws MojoExecutionException {
List<String> args = super.getCompilerArgs(configFile);
args.add("-define=COMPILE::AS3,true");
args.add("-define=COMPILE::JS,false");
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/87ceb80b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileAppMojo.java
----------------------------------------------------------------------
diff --git a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileAppMojo.java b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileAppMojo.java
new file mode 100644
index 0000000..3bffef1
--- /dev/null
+++ b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileAppMojo.java
@@ -0,0 +1,152 @@
+/*
+ * 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.
+ */
+
+package org.apache.flex.maven.flexjs;
+
+import edu.emory.mathcs.backport.java.util.Arrays;
+import org.apache.flex.tools.FlexTool;
+import org.apache.maven.artifact.Artifact;
+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.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * goal which compiles a project into a flexjs sef application.
+ */
+@Mojo(name="compile-app",defaultPhase = LifecyclePhase.PROCESS_SOURCES)
+public class CompileAppMojo
+ extends BaseMojo
+{
+
+ @Parameter
+ private String mainClass;
+
+ @Parameter(defaultValue = "${project.artifactId}-${project.version}.swf")
+ private String outputFileName;
+
+ @Parameter(defaultValue = "namespaces")
+ protected String namespaceDirectory;
+
+ @Override
+ protected String getToolGroupName() {
+ return "Falcon";
+ }
+
+ @Override
+ protected String getFlexTool() {
+ return FlexTool.FLEX_TOOL_MXMLC;
+ }
+
+ @Override
+ protected String getConfigFileName() {
+ return "compile-app-config.xml";
+ }
+
+ @Override
+ protected File getOutput() {
+ return new File(outputDirectory, outputFileName);
+ }
+
+ @Override
+ protected List<String> getCompilerArgs(File configFile) throws MojoExecutionException {
+ if(mainClass == null) {
+ throw new MojoExecutionException("The mainClass has to be declared for SWF type modules.");
+ }
+ String mainClassPath = getSourcePath(mainClass);
+ if(mainClassPath == null) {
+ throw new MojoExecutionException("Could not find main class");
+ }
+ List<String> args = super.getCompilerArgs(configFile);
+ args.add("-define=COMPILE::AS3,true");
+ args.add("-define=COMPILE::JS,false");
+ args.add(mainClassPath);
+ return args;
+ }
+
+ @Override
+ public void execute() throws MojoExecutionException {
+ super.execute();
+
+ if(getOutput().exists()) {
+ // Attach the file created by the compiler as artifact file to maven.
+ project.getArtifact().setFile(getOutput());
+ }
+ }
+
+ /**
+ * @return list of the explicitly defined as well as the automatically detected namespaces.
+ */
+ @Override
+ @SuppressWarnings("unchecked")
+ protected Namespace[] getNamespaces() {
+ File namespaceDir = new File(outputDirectory, namespaceDirectory);
+ if(namespaceDir.exists()) {
+ File[] namespaceFiles = namespaceDir.listFiles();
+ if(namespaceFiles != null) {
+ List<Namespace> autoNamespaces = new ArrayList<Namespace>(namespaceFiles.length);
+ // Read the namespace-uri attribute of each file and add them to the namespaces.
+ for(File namespaceFile : namespaceFiles) {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ try {
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document namespaceDoc = builder.parse(namespaceFile);
+ String namespaceUri = namespaceDoc.getDocumentElement().getAttribute("namespace-uri");
+ Namespace namespace = new Namespace();
+ namespace.setUri(namespaceUri);
+ namespace.setManifest(namespaceFile.getPath());
+ autoNamespaces.add(namespace);
+ } catch (SAXException e) {
+ e.printStackTrace();
+ } catch (ParserConfigurationException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ if(!autoNamespaces.isEmpty()) {
+ List<Namespace> namespaces;
+ Namespace[] manualNamespaces = super.getNamespaces();
+ if(manualNamespaces != null) {
+ namespaces = new ArrayList<Namespace>(Arrays.asList(manualNamespaces));
+ namespaces.addAll(autoNamespaces);
+ } else {
+ namespaces = autoNamespaces;
+ }
+ return namespaces.toArray(new Namespace[0]);
+ }
+ }
+ }
+ return super.getNamespaces();
+ }
+
+ @Override
+ protected boolean includeLibrary(Artifact library) {
+ return !"extern".equalsIgnoreCase(library.getClassifier());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/87ceb80b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileExternMojo.java
----------------------------------------------------------------------
diff --git a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileExternMojo.java b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileExternMojo.java
index b91cb2a..0126593 100644
--- a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileExternMojo.java
+++ b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileExternMojo.java
@@ -70,7 +70,7 @@ public class CompileExternMojo
}
@Override
- protected List<String> getCompilerArgs(File configFile) {
+ protected List<String> getCompilerArgs(File configFile) throws MojoExecutionException {
List<String> args = super.getCompilerArgs(configFile);
args.add("-define=COMPILE::AS3,false");
args.add("-define=COMPILE::JS,true");
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/87ceb80b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileJSMojo.java
----------------------------------------------------------------------
diff --git a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileJSMojo.java b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileJSMojo.java
index 1b181e6..371ff05 100644
--- a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileJSMojo.java
+++ b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileJSMojo.java
@@ -79,7 +79,7 @@ public class CompileJSMojo
}
@Override
- protected List<String> getCompilerArgs(File configFile) {
+ protected List<String> getCompilerArgs(File configFile) throws MojoExecutionException {
List<String> args = super.getCompilerArgs(configFile);
args.add("-js-output-type=FLEXJS");
args.add("-compiler.strict-xml=true");
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/87ceb80b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/GenerateManifestsMojo.java
----------------------------------------------------------------------
diff --git a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/GenerateManifestsMojo.java b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/GenerateManifestsMojo.java
new file mode 100644
index 0000000..940d35a
--- /dev/null
+++ b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/GenerateManifestsMojo.java
@@ -0,0 +1,211 @@
+package org.apache.flex.maven.flexjs;
+
+import org.apache.flex.maven.flexjs.utils.DependencyHelper;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Component;
+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.apache.maven.project.ProjectDependenciesResolver;
+import org.eclipse.aether.RepositorySystemSession;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.*;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.xpath.*;
+import java.io.*;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+/**
+ * Created by christoferdutz on 18.05.16.
+ */
+@Mojo(name="generate-manifests",defaultPhase = LifecyclePhase.GENERATE_RESOURCES)
+public class GenerateManifestsMojo
+ extends AbstractMojo
+{
+
+ @Parameter(defaultValue = "namespaces")
+ protected String namespaceDirectory;
+
+ @Parameter(defaultValue = "${project}", readonly = true)
+ protected MavenProject project;
+
+ @Parameter(defaultValue="${project.build.directory}")
+ protected File outputDirectory;
+
+ @Parameter(readonly = true, defaultValue = "${repositorySystemSession}")
+ private RepositorySystemSession repositorySystemSession;
+
+ @Component
+ private ProjectDependenciesResolver projectDependenciesResolver;
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ List<Artifact> allLibraries = DependencyHelper.getAllLibraries(
+ project, repositorySystemSession, projectDependenciesResolver);
+ Map<String, Map<String, String>> namespaces = new HashMap<String, Map<String, String>>();
+ for(Artifact library : allLibraries) {
+ File libraryFile = library.getFile();
+ // Check if the file exists and is a SWC.
+ if(libraryFile.exists() && libraryFile.getName().endsWith(".swc")) {
+ // Get the component data from the current library.
+ Map<String, Map<String, String>> curLibNamespaces = getNamespacesFromLibrary(libraryFile);
+
+ // Merge that data with the current index.
+ for(Map.Entry<String, Map<String, String>> namespace : curLibNamespaces.entrySet()) {
+ String namespaceUri = namespace.getKey();
+ if(!namespaces.containsKey(namespaceUri)) {
+ namespaces.put(namespaceUri, new HashMap<String, String>());
+ }
+ for(Map.Entry<String, String> component : namespace.getValue().entrySet()) {
+ namespaces.get(namespaceUri).put(component.getKey(), component.getValue());
+ }
+ }
+ }
+ }
+
+ // Serialize the namespace information into separate files.
+ for(Map.Entry<String, Map<String, String>> namespace : namespaces.entrySet()) {
+ createNamespace(namespace.getKey(), namespace.getValue());
+ }
+ }
+
+ private Map<String, Map<String, String>> getNamespacesFromLibrary(File library) {
+ Map<String, Map<String, String>> namespaces = new HashMap<String, Map<String, String>>();
+ try {
+ // Open the file as a zip
+ byte[] catalogBytes = null;
+ FileInputStream fin = new FileInputStream(library);
+ BufferedInputStream bin = new BufferedInputStream(fin);
+ ZipInputStream zin = new ZipInputStream(bin);
+ ZipEntry ze;
+ while ((ze = zin.getNextEntry()) != null) {
+ if (ze.getName().equals("catalog.xml")) {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] buffer = new byte[8192];
+ int len;
+ while ((len = zin.read(buffer)) != -1) {
+ out.write(buffer, 0, len);
+ }
+ out.close();
+ catalogBytes = out.toByteArray();
+ break;
+ }
+ }
+
+ // Read the catalog.xml file inside.
+ if(catalogBytes != null) {
+ try {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document catalog = builder.parse(new ByteArrayInputStream(catalogBytes));
+ XPath xpath = XPathFactory.newInstance().newXPath();
+ xpath.setNamespaceContext(new NamespaceContext() {
+ public String getNamespaceURI(String prefix) {
+ return prefix.equals("cat") ? "http://www.adobe.com/flash/swccatalog/9" : null;
+ }
+ public Iterator getPrefixes(String val) {
+ return null;
+ }
+ public String getPrefix(String uri) {
+ return null;
+ }
+ });
+ XPathExpression expr = xpath.compile("/cat:swc/cat:components/cat:component");
+ Object result = expr.evaluate(catalog, XPathConstants.NODESET);
+ NodeList nodes = (NodeList) result;
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Element componentElement = (Element) nodes.item(i);
+ String className = componentElement.getAttribute("className");
+ String name = componentElement.getAttribute("name");
+ String uri = componentElement.getAttribute("uri");
+ if(!namespaces.containsKey(uri)) {
+ namespaces.put(uri, new HashMap<String, String>());
+ }
+ namespaces.get(uri).put(name, className);
+ }
+ } catch (ParserConfigurationException e) {
+ e.printStackTrace();
+ } catch (SAXException e) {
+ e.printStackTrace();
+ } catch (XPathExpressionException e) {
+ e.printStackTrace();
+ }
+ }
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return namespaces;
+ }
+
+ private void createNamespace(String namespaceUri, Map<String, String> components) throws MojoExecutionException {
+ File namespaceDir = new File(outputDirectory, namespaceDirectory);
+ if(!namespaceDir.exists()) {
+ if(!namespaceDir.mkdirs()) {
+ throw new MojoExecutionException(
+ "Could not create namespace output directory at " + namespaceDir.getPath());
+ }
+ }
+
+ String namespaceFilename = namespaceUri.replaceAll(":", "-").replaceAll("/", "-") + ".xml";
+ File namespaceOutputFile = new File(namespaceDir, namespaceFilename);
+ try {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ Document namespaceDoc = factory.newDocumentBuilder().newDocument();
+ Element componentPackageElement = namespaceDoc.createElement("componentPackage");
+ // TODO: Check if the compiler doesn't trip over this ...
+ componentPackageElement.setAttribute("namespace-uri", namespaceUri);
+ namespaceDoc.appendChild(componentPackageElement);
+ for (Map.Entry<String, String> component : components.entrySet()) {
+ Element componentElement = namespaceDoc.createElement("component");
+ componentElement.setAttribute("id", component.getKey());
+ componentElement.setAttribute("class", component.getValue().replace(":", "."));
+ componentPackageElement.appendChild(componentElement);
+ }
+
+
+ try {
+ Source source = new DOMSource(namespaceDoc);
+ Result result = new StreamResult(namespaceOutputFile);
+
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer transformer = tf.newTransformer();
+ transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
+ transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
+ transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ transformer.transform(source, result);
+ } catch (TransformerConfigurationException e) {
+ e.printStackTrace();
+ } catch (TransformerException e) {
+ e.printStackTrace();
+ }
+
+ } catch (ParserConfigurationException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/87ceb80b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/utils/DependencyHelper.java
----------------------------------------------------------------------
diff --git a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/utils/DependencyHelper.java b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/utils/DependencyHelper.java
new file mode 100644
index 0000000..7605283
--- /dev/null
+++ b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/utils/DependencyHelper.java
@@ -0,0 +1,41 @@
+package org.apache.flex.maven.flexjs.utils;
+
+import org.apache.maven.RepositoryUtils;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.*;
+import org.eclipse.aether.RepositorySystemSession;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Created by christoferdutz on 18.05.16.
+ *
+ * TODO: Change this to a real component ... statics suck.
+ */
+public class DependencyHelper {
+
+ public static List<Artifact> getAllLibraries(MavenProject project, RepositorySystemSession repositorySystemSession,
+ ProjectDependenciesResolver projectDependenciesResolver) throws MojoExecutionException {
+ DefaultDependencyResolutionRequest dependencyResolutionRequest =
+ new DefaultDependencyResolutionRequest(project, repositorySystemSession);
+ DependencyResolutionResult dependencyResolutionResult;
+
+ try {
+ dependencyResolutionResult = projectDependenciesResolver.resolve(dependencyResolutionRequest);
+ } catch (DependencyResolutionException ex) {
+ throw new MojoExecutionException(ex.getMessage(), ex);
+ }
+
+ List<Artifact> artifacts = new LinkedList<Artifact>();
+ if (dependencyResolutionResult.getDependencyGraph() != null
+ && !dependencyResolutionResult.getDependencyGraph().getChildren().isEmpty()) {
+ RepositoryUtils.toArtifacts(artifacts, dependencyResolutionResult.getDependencyGraph().getChildren(),
+ Collections.singletonList(project.getArtifact().getId()), null);
+ }
+ return artifacts;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/87ceb80b/flexjs-maven-plugin/src/main/resources/META-INF/plexus/components.xml
----------------------------------------------------------------------
diff --git a/flexjs-maven-plugin/src/main/resources/META-INF/plexus/components.xml b/flexjs-maven-plugin/src/main/resources/META-INF/plexus/components.xml
index 28f01bb..384e3b3 100644
--- a/flexjs-maven-plugin/src/main/resources/META-INF/plexus/components.xml
+++ b/flexjs-maven-plugin/src/main/resources/META-INF/plexus/components.xml
@@ -65,6 +65,59 @@
</configuration>
</component>
<component>
+ <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
+ <role-hint>swf</role-hint>
+ <implementation>
+ org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping
+ </implementation>
+ <configuration>
+ <lifecycles>
+ <lifecycle>
+ <id>default</id>
+ <phases>
+ <generate-resources>
+ org.apache.flex.flexjs.compiler:flexjs-maven-plugin:generate-manifests
+ </generate-resources>
+ <process-resources>
+ org.apache.maven.plugins:maven-resources-plugin:resources
+ </process-resources>
+ <!-- Compile the ActionScript to Flash (SWF) -->
+ <compile>
+ org.apache.flex.flexjs.compiler:flexjs-maven-plugin:compile-app
+ </compile>
+ <process-test-resources>
+ org.apache.maven.plugins:maven-resources-plugin:testResources
+ </process-test-resources>
+ <!--generate-test-sources>
+
+ </generate-test-sources-->
+ <!--generate-test-resources>
+
+ </generate-test-resources-->
+ <!--test-compile>
+ org.apache.flex.flexjs.compiler:flexjs-maven-plugin:testCompile
+ </test-compile-->
+ <process-test-classes>
+ org.apache.flex.flexjs.compiler:flexjs-maven-plugin:trust
+ </process-test-classes>
+ <!--test>
+ org.apache.maven.plugins:maven-surefire-plugin:test
+ </test-->
+ <!--package>
+ org.apache.flex.flexjs.compiler:flexjs-maven-plugin:package
+ </package-->
+ <install>
+ org.apache.maven.plugins:maven-install-plugin:install
+ </install>
+ <deploy>
+ org.apache.maven.plugins:maven-deploy-plugin:deploy
+ </deploy>
+ </phases>
+ </lifecycle>
+ </lifecycles>
+ </configuration>
+ </component>
+ <component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>swc</role-hint>
<implementation>
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/87ceb80b/flexjs-maven-plugin/src/main/resources/config/compile-app-config.xml
----------------------------------------------------------------------
diff --git a/flexjs-maven-plugin/src/main/resources/config/compile-app-config.xml b/flexjs-maven-plugin/src/main/resources/config/compile-app-config.xml
new file mode 100644
index 0000000..5729616
--- /dev/null
+++ b/flexjs-maven-plugin/src/main/resources/config/compile-app-config.xml
@@ -0,0 +1,98 @@
+<!--
+
+ 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>
+
+ <library-path>
+#foreach($artifact in $libraries) <path-element>$artifact.file</path-element>
+#end
+ </library-path>
+
+ <external-library-path>
+#foreach($artifact in $externalLibraries) <path-element>$artifact.file</path-element>
+#end
+ </external-library-path>
+
+ <source-path>
+#foreach($sourcePath in $sourcePaths) <path-element>$sourcePath</path-element>
+#end
+ </source-path>
+
+ <namespaces>
+#foreach($namespace in $namespaces) <namespace>
+ <uri>$namespace.uri</uri>
+ <manifest>$namespace.manifest</manifest>
+ </namespace>
+#end
+ </namespaces>
+
+ <keep-as3-metadata>
+ <name>Bindable</name>
+ <name>Managed</name>
+ <name>ChangeEvent</name>
+ <name>NonCommittingChangeEvent</name>
+ <name>Transient</name>
+ </keep-as3-metadata>
+
+ <mxml>
+ <children-as-data>true</children-as-data>
+ </mxml>
+
+ <binding-value-change-event>org.apache.flex.events.ValueChangeEvent</binding-value-change-event>
+ <binding-value-change-event-kind>org.apache.flex.events.ValueChangeEvent</binding-value-change-event-kind>
+ <binding-value-change-event-type>valueChange</binding-value-change-event-type>
+
+ <locale>
+ </locale>
+
+ <warn-no-constructor>false</warn-no-constructor>
+ <show-deprecation-warnings>false</show-deprecation-warnings>
+
+ <define append="true">
+ <name>COMPILE::JS</name>
+ <value>false</value>
+ </define>
+ <define append="true">
+ <name>COMPILE::AS3</name>
+ <value>true</value>
+ </define>
+ </compiler>
+
+#if($includeSources)
+ <include-sources>
+#foreach($sourcePath in $sourcePaths) <path-element>$sourcePath</path-element>
+#end
+ </include-sources>
+#end
+
+#if($includeClasses)
+ <include-classes>
+#foreach($includeClass in $includeClasses) <class>$includeClass</class>
+#end
+ </include-classes>
+#end
+
+ <target-player>${targetPlayer}</target-player>
+
+ <output>${output}</output>
+
+</flex-config>
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/87ceb80b/flexjs-maven-plugin/src/main/resources/config/compile-as-config.xml
----------------------------------------------------------------------
diff --git a/flexjs-maven-plugin/src/main/resources/config/compile-as-config.xml b/flexjs-maven-plugin/src/main/resources/config/compile-as-config.xml
index 2526018..7b8bcdd 100644
--- a/flexjs-maven-plugin/src/main/resources/config/compile-as-config.xml
+++ b/flexjs-maven-plugin/src/main/resources/config/compile-as-config.xml
@@ -77,22 +77,26 @@
</define>
</compiler>
- <include-sources>
#if($includeSources)
+ <include-sources>
#foreach($sourcePath in $sourcePaths) <path-element>$sourcePath</path-element>
#end
-#end
</include-sources>
+#end
+#if($includeClasses)
<include-classes>
#foreach($includeClass in $includeClasses) <class>$includeClass</class>
#end
</include-classes>
+#end
+#if($namespaces)
<include-namespaces>
#foreach($namespace in $namespaces) <uri>$namespace.uri</uri>
#end
</include-namespaces>
+#end
<target-player>${targetPlayer}</target-player>
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/87ceb80b/flexjs-maven-plugin/src/main/resources/config/compile-extern-config.xml
----------------------------------------------------------------------
diff --git a/flexjs-maven-plugin/src/main/resources/config/compile-extern-config.xml b/flexjs-maven-plugin/src/main/resources/config/compile-extern-config.xml
index 1b399a8..690fad6 100644
--- a/flexjs-maven-plugin/src/main/resources/config/compile-extern-config.xml
+++ b/flexjs-maven-plugin/src/main/resources/config/compile-extern-config.xml
@@ -75,22 +75,26 @@
</define>
</compiler>
- <include-sources>
#if($includeSources)
+ <include-sources>
#foreach($sourcePath in $sourcePaths) <path-element>$sourcePath</path-element>
#end
-#end
</include-sources>
-
- <include-namespaces>
-#foreach($namespace in $namespaces) <uri>$namespace.uri</uri>
#end
- </include-namespaces>
+#if($includeClasses)
<include-classes>
#foreach($includeClass in $includeClasses) <class>$includeClass</class>
#end
</include-classes>
+#end
+
+#if($namespaces)
+ <include-namespaces>
+#foreach($namespace in $namespaces) <uri>$namespace.uri</uri>
+#end
+ </include-namespaces>
+#end
<output>${output}</output>
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/87ceb80b/flexjs-maven-plugin/src/main/resources/config/compile-js-config.xml
----------------------------------------------------------------------
diff --git a/flexjs-maven-plugin/src/main/resources/config/compile-js-config.xml b/flexjs-maven-plugin/src/main/resources/config/compile-js-config.xml
index e1ece41..08a95e6 100644
--- a/flexjs-maven-plugin/src/main/resources/config/compile-js-config.xml
+++ b/flexjs-maven-plugin/src/main/resources/config/compile-js-config.xml
@@ -75,22 +75,26 @@
</define>
</compiler>
- <include-sources>
#if($includeSources)
+ <include-sources>
#foreach($sourcePath in $sourcePaths) <path-element>$sourcePath</path-element>
#end
-#end
</include-sources>
-
- <include-namespaces>
-#foreach($namespace in $namespaces) <uri>$namespace.uri</uri>
#end
- </include-namespaces>
+#if($includeClasses)
<include-classes>
#foreach($includeClass in $includeClasses) <class>$includeClass</class>
#end
</include-classes>
+#end
+
+#if($namespaces)
+ <include-namespaces>
+#foreach($namespace in $namespaces) <uri>$namespace.uri</uri>
+#end
+ </include-namespaces>
+#end
<js-output-type>FLEXJS</js-output-type>