You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by jo...@apache.org on 2017/03/21 23:11:17 UTC
[40/50] git commit: [flex-falcon] [refs/heads/master] - - Added a
PackageJSMojo to make the usage of the maven-war-plugin and the
build-helper-plugin obsolete.
- Added a PackageJSMojo to make the usage of the maven-war-plugin and the build-helper-plugin obsolete.
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/aee4ae31
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/aee4ae31
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/aee4ae31
Branch: refs/heads/master
Commit: aee4ae31ab2d5c2fd31d068e2d0aa624d60901e2
Parents: 4426fbf
Author: Christofer Dutz <ch...@codecentric.de>
Authored: Sat Mar 11 21:56:42 2017 +0100
Committer: Christofer Dutz <ch...@codecentric.de>
Committed: Sat Mar 11 21:56:42 2017 +0100
----------------------------------------------------------------------
.../flex/maven/flexjs/CompileAppMojo.java | 16 +--
.../apache/flex/maven/flexjs/PackageJSMojo.java | 116 +++++++++++++++++++
.../resources/META-INF/plexus/components.xml | 6 +-
3 files changed, 123 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/aee4ae31/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
index 258f6cc..5f4b11b 100644
--- 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
@@ -17,11 +17,9 @@ package org.apache.flex.maven.flexjs;
import org.apache.flex.tools.FlexTool;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
-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.MavenProjectHelper;
import org.apache.velocity.VelocityContext;
import java.io.File;
@@ -41,8 +39,8 @@ public class CompileAppMojo
@Parameter(defaultValue = "${project.artifactId}-${project.version}.swf")
private String flashOutputFileName;
- @Parameter(defaultValue = "${project.artifactId}-${project.version}.war")
- private String javascriptOutputFileName;
+ @Parameter(defaultValue = "javascript")
+ private String javascriptOutputDirectoryName;
@Parameter(defaultValue = "namespaces")
protected String namespaceDirectory;
@@ -60,9 +58,6 @@ public class CompileAppMojo
@Parameter(defaultValue = "false")
protected boolean removeCirculars;
- @Component
- protected MavenProjectHelper mavenProjectHelper;
-
@Override
protected String getToolGroupName() {
if(outputJavaScript) {
@@ -95,7 +90,7 @@ public class CompileAppMojo
@Override
protected File getOutput() throws MojoExecutionException {
if(outputJavaScript) {
- return new File(outputDirectory, "javascript");
+ return new File(outputDirectory, javascriptOutputDirectoryName);
}
return new File(outputDirectory, flashOutputFileName);
}
@@ -192,10 +187,7 @@ public class CompileAppMojo
@Override
protected boolean isForceSwcExternalLibraryPath() {
// The forceSwcExternalLibraryPath should only apply to Flash compilations.
- if(outputJavaScript) {
- return false;
- }
- return super.isForceSwcExternalLibraryPath();
+ return !outputJavaScript && super.isForceSwcExternalLibraryPath();
}
/*private void zipDirectory(File source, File target) {
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/aee4ae31/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/PackageJSMojo.java
----------------------------------------------------------------------
diff --git a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/PackageJSMojo.java b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/PackageJSMojo.java
new file mode 100644
index 0000000..8a9c2d4
--- /dev/null
+++ b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/PackageJSMojo.java
@@ -0,0 +1,116 @@
+/*
+ * 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 org.apache.commons.io.IOUtils;
+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.MavenProjectHelper;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+/**
+ * Created by christoferdutz on 11.03.17.
+ */
+@Mojo(name="package-js",defaultPhase = LifecyclePhase.PACKAGE)
+public class PackageJSMojo extends AbstractMojo {
+
+ @Parameter(defaultValue="${project.build.directory}")
+ protected File outputDirectory;
+
+ @Parameter(defaultValue = "javascript")
+ private String javascriptOutputDirectoryName;
+
+ @Parameter(defaultValue = "${project.artifactId}-${project.version}.war")
+ private String warOutputFileName;
+
+ @Parameter
+ protected boolean debug = false;
+
+ @Component
+ protected MavenProject project;
+
+ @Component
+ private MavenProjectHelper projectHelper;
+
+ /**
+ * This mojo should only be executed if a JS output was generated
+ *
+ * @throws MojoExecutionException
+ * @throws MojoFailureException
+ */
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ File warSourceDirectory = new File(outputDirectory, javascriptOutputDirectoryName);
+ warSourceDirectory = new File(new File(warSourceDirectory, "bin"), debug ? "js-debug" : "js-release");
+
+ // If the directory exists, pack everything into one zip file.
+ if(warSourceDirectory.exists()) {
+ File warTargetFile = new File(outputDirectory, warOutputFileName);
+
+ // If the output file already exists, delete it first.
+ if(warTargetFile.exists()) {
+ if(!warTargetFile.delete()) {
+ throw new MojoExecutionException(
+ "Could not delete existing war file at " + warSourceDirectory.getPath());
+ }
+ }
+
+ // Create a new zip file with the output of the JS compiler.
+ try {
+ ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(warTargetFile));
+ addDirectoryToZip(warSourceDirectory, warSourceDirectory, zipOutputStream);
+ IOUtils.closeQuietly(zipOutputStream);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Error creating war archive", e);
+ }
+
+ // Attach the war file to the maven project.
+ if(warTargetFile.exists()) {
+ projectHelper.attachArtifact( project, "war", null, warTargetFile);
+ }
+ }
+ }
+
+ private void addDirectoryToZip(File zipRootDirectory, File currentDirectory, ZipOutputStream zipOutputStream)
+ throws IOException {
+ File[] directoryContent = currentDirectory.listFiles();
+ if(directoryContent != null) {
+ for (File file : directoryContent) {
+ if(file.isDirectory()) {
+ addDirectoryToZip(zipRootDirectory, file, zipOutputStream);
+ } else {
+ String relativePath = zipRootDirectory.toURI().relativize(currentDirectory.toURI()).getPath();
+ ZipEntry zipEntry = new ZipEntry(relativePath + "/" + file.getName());
+ zipOutputStream.putNextEntry(zipEntry);
+ FileInputStream in = new FileInputStream(file);
+ IOUtils.copy(in, zipOutputStream);
+ IOUtils.closeQuietly(in);
+ }
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/aee4ae31/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 78dbe96..441a165 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
@@ -116,9 +116,9 @@
<!--test>
org.apache.maven.plugins:maven-surefire-plugin:test
</test-->
- <!--package>
- org.apache.flex.flexjs.compiler:flexjs-maven-plugin:package
- </package-->
+ <package>
+ org.apache.flex.flexjs.compiler:flexjs-maven-plugin:package-js
+ </package>
<install>
org.apache.maven.plugins:maven-install-plugin:install
</install>