flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [38/50] git commit: [flex-falcon] [refs/heads/master] - Implemented the MavenTestAdapter to automatically unpack the framework config zip (Needed the commons-compress library for that)
Date Wed, 06 Apr 2016 15:02:47 GMT
Implemented the MavenTestAdapter to automatically unpack the framework config zip (Needed the
commons-compress library for that)


Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/da24e603
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/da24e603
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/da24e603

Branch: refs/heads/master
Commit: da24e6038b731d4ec725724e8a8b892137e049a0
Parents: b4fd161
Author: Christofer Dutz <christofer.dutz@codecentric.de>
Authored: Sat Mar 19 17:07:42 2016 +0100
Committer: Christofer Dutz <christofer.dutz@codecentric.de>
Committed: Sat Mar 19 17:07:42 2016 +0100

----------------------------------------------------------------------
 compiler.tests/downloads.xml                    | 35 ++++++++-
 .../org/apache/flex/utils/MavenTestAdapter.java | 74 +++++++++++++++++++-
 2 files changed, 103 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/da24e603/compiler.tests/downloads.xml
----------------------------------------------------------------------
diff --git a/compiler.tests/downloads.xml b/compiler.tests/downloads.xml
index 2638cb9..ebd4324 100644
--- a/compiler.tests/downloads.xml
+++ b/compiler.tests/downloads.xml
@@ -33,7 +33,8 @@
 	       For Apache, the JARS must be removed from the repository.
 	       
 	       Licenses:
-            JUnit (4.10) - CPL 1.0        
+            JUnit (4.10) - CPL 1.0
+            Commons Compress - Apache 2.0
 	-->
 		     
     <!-- 
@@ -41,7 +42,7 @@
         they are each downloaded only if they don't already exist. 
     -->
     
-	<target name="main" depends="prepare, junit-jar"
+	<target name="main" depends="prepare, junit-jar, commons-compress-jar"
 		    description="Downloads all the required thirdparty JARs"/>
 
     <target name="prepare" >
@@ -57,6 +58,7 @@
         <delete includeEmptyDirs="true" failonerror="false">
             <fileset dir="${download.dir}">
                 <include name="junit*/**"/>
+                <include name="commons-compress*/**"/>
             </fileset>
         </delete>
     </target>
@@ -115,5 +117,32 @@
             <param name="destJarFile" value="${lib.dir}/junit-4.10.jar"/>
         </antcall>
     </target>
-    
+
+    <!--
+        commons-compress
+    -->
+
+    <target name="commons-compress-jar-check" description="Checks if commons-compress
JAR exists.">
+        <condition property="commons-compress.jar.exists">
+            <and>
+                <available file="${lib.dir}/commons-compress-1.10.jar"/>
+            </and>
+        </condition>
+    </target>
+
+    <target name="commons-compress-jar" depends="commons-compress-jar-check" unless="commons-compress.jar.exists"
+            description="Copies the commons-compress JAR to the lib directory.">
+        <echo message="Obtaining lib/commons-compress-1.10.jar"/>
+        <antcall target="commons-compress-download-jar"/>
+    </target>
+
+    <target name="commons-compress-download-jar" depends="commons-compress-jar-check"
unless="commons-compress.jar.exists"
+            description="Downloads the commons-compress jar.">
+        <antcall target="download-jar">
+            <param name="srcUrl" value="https://repo1.maven.org/maven2/org/apache/commons/commons-compress/1.10"/>
+            <param name="srcJarFile" value="commons-compress-1.10.jar"/>
+            <param name="destJarFile" value="${lib.dir}/commons-compress-1.10.jar"/>
+        </antcall>
+    </target>
+
 </project>

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/da24e603/compiler.tests/src/org/apache/flex/utils/MavenTestAdapter.java
----------------------------------------------------------------------
diff --git a/compiler.tests/src/org/apache/flex/utils/MavenTestAdapter.java b/compiler.tests/src/org/apache/flex/utils/MavenTestAdapter.java
index 485d14b..ae45eda 100644
--- a/compiler.tests/src/org/apache/flex/utils/MavenTestAdapter.java
+++ b/compiler.tests/src/org/apache/flex/utils/MavenTestAdapter.java
@@ -19,9 +19,13 @@
 
 package org.apache.flex.utils;
 
+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.commons.io.FilenameUtils;
 
-import java.io.File;
+import java.io.*;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -30,6 +34,10 @@ import java.util.List;
  */
 public class MavenTestAdapter implements ITestAdapter {
 
+    private static final int KILOBYTE = 1024;
+    private static final int MEGABYTE = KILOBYTE * 1024;
+    private static final int BUFFER_MAX = MEGABYTE;
+
     @Override
     public String getTempDir() {
         File tempDir = new File("target/surefire-temp");
@@ -79,7 +87,7 @@ public class MavenTestAdapter implements ITestAdapter {
         // If the directory doesn't exist, we have to create it by unpacking the zip archive.
         // This is identical behaviour to Flexmojos, which does the same thing.
         if(!unpackedConfigsDir.exists()) {
-            // TODO: Implement
+            unpackFrameworkConfigs(configsZip, unpackedConfigsDir);
         }
         return new File(unpackedConfigsDir, type + "-manifest.xml").getPath();
     }
@@ -105,7 +113,7 @@ public class MavenTestAdapter implements ITestAdapter {
         // If the directory doesn't exist, we have to create it by unpacking the zip archive.
         // This is identical behaviour to Flexmojos, which does the same thing.
         if(!unpackedConfigsDir.exists()) {
-            // TODO: Implement
+            unpackFrameworkConfigs(configsZip, unpackedConfigsDir);
         }
         return new File(unpackedConfigsDir, type + "-manifest.xml").getPath();
     }
@@ -133,4 +141,64 @@ public class MavenTestAdapter implements ITestAdapter {
         return dependency;
     }
 
+    private void unpackFrameworkConfigs(File configZip, File outputDirectory) {
+        final byte[] data = new byte[BUFFER_MAX];
+        ArchiveInputStream archiveInputStream = null;
+        ArchiveEntry entry;
+        try {
+            archiveInputStream = new ArchiveStreamFactory().createArchiveInputStream(
+                    new BufferedInputStream(new FileInputStream(configZip)));
+            if(!outputDirectory.exists() && !outputDirectory.mkdirs()) {
+                throw new RuntimeException("Could not create output directory for config
zip at " +
+                        outputDirectory.getPath());
+            }
+            while ((entry = archiveInputStream.getNextEntry()) != null) {
+                final File outputFile = new File(outputDirectory, entry.getName());
+
+                // Entry is a directory.
+                if (entry.isDirectory()) {
+                    if (!outputFile.exists()) {
+                        if(!outputFile.mkdirs()) {
+                            throw new RuntimeException(
+                                    "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 RuntimeException("Error unpacking resources", e);
+        } catch (IOException e) {
+            throw new RuntimeException("Error unpacking resources", e);
+        } catch (ArchiveException e) {
+            throw new RuntimeException("Error unpacking resources", e);
+        } finally {
+            if(archiveInputStream != null) {
+                try {
+                    archiveInputStream.close();
+                } catch(Exception e) {
+                    // Ignore...
+                }
+            }
+        }
+    }
+
 }


Mime
View raw message