flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From que...@apache.org
Subject [28/50] [abbrv] git commit: [flex-utilities] [refs/heads/as3httpclient-work] - - Implemented a wrapper converter that creates wrapper artifacts used as templates for web-projects.
Date Sun, 31 May 2015 22:19:10 GMT
- Implemented a wrapper converter that creates wrapper artifacts used as templates for web-projects.


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

Branch: refs/heads/as3httpclient-work
Commit: 1a46b11276f24b2a13464461887bf63b4735006e
Parents: 05922ef
Author: Christofer Dutz <christofer.dutz@codecentric.de>
Authored: Thu Apr 23 17:15:44 2015 +0200
Committer: Christofer Dutz <christofer.dutz@codecentric.de>
Committed: Thu Apr 23 17:15:44 2015 +0200

----------------------------------------------------------------------
 .../converter/core/SdkConverterCLI.java         | 10 +++
 mavenizer/converters/flex/pom.xml               |  5 ++
 mavenizer/converters/pom.xml                    |  1 +
 mavenizer/converters/wrapper/pom.xml            | 41 +++++++++
 .../converter/wrapper/WrapperConverter.java     | 87 ++++++++++++++++++++
 mavenizer/maven-extension/pom.xml               |  5 ++
 .../converter/mavenextension/FlexEventSpy.java  | 23 ++++--
 .../converter/retrievers/types/SdkType.java     |  3 +-
 .../retrievers/download/DownloadRetriever.java  | 41 ++++++---
 9 files changed, 195 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/1a46b112/mavenizer/cli/src/main/java/org/apache/flex/utilities/converter/core/SdkConverterCLI.java
----------------------------------------------------------------------
diff --git a/mavenizer/cli/src/main/java/org/apache/flex/utilities/converter/core/SdkConverterCLI.java
b/mavenizer/cli/src/main/java/org/apache/flex/utilities/converter/core/SdkConverterCLI.java
index 56d5f1f..9f3d160 100644
--- a/mavenizer/cli/src/main/java/org/apache/flex/utilities/converter/core/SdkConverterCLI.java
+++ b/mavenizer/cli/src/main/java/org/apache/flex/utilities/converter/core/SdkConverterCLI.java
@@ -11,6 +11,7 @@ import org.apache.flex.utilities.converter.fontkit.FontkitConverter;
 import org.apache.flex.utilities.converter.retrievers.download.DownloadRetriever;
 import org.apache.flex.utilities.converter.retrievers.types.PlatformType;
 import org.apache.flex.utilities.converter.retrievers.types.SdkType;
+import org.apache.flex.utilities.converter.wrapper.WrapperConverter;
 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
 
 import java.io.File;
@@ -253,6 +254,10 @@ public class SdkConverterCLI {
                     File fdkDownloadDirectory = retriever.retrieve(SdkType.FLEX, flexVersion);
                     // Unpack the archive to the FDK directory.
                     mergeDirectories(fdkDownloadDirectory, fdkDir);
+
+                    // Add the swfobject files.
+                    File swfObjectDirectory = retriever.retrieve(SdkType.SWFOBJECT);
+                    mergeDirectories(swfObjectDirectory, fdkDir);
                 }
 
                 String flashVersions = cmd.getOptionValue(OPTION_FLASH_VERSIONS, "");
@@ -315,6 +320,11 @@ public class SdkConverterCLI {
                 FontkitConverter fontkitConverter = new FontkitConverter(fdkDir, mavenDir);
                 fontkitConverter.convert();
 
+                System.out.println("- Converting Wrappers from " + fdkDir.getAbsolutePath()
+
+                        " to " + mavenDir.getAbsolutePath());
+                WrapperConverter wrapperConverter = new WrapperConverter(fdkDir, mavenDir);
+                wrapperConverter.convert();
+
                 System.out.println("Finished conversion.");
             }
 

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/1a46b112/mavenizer/converters/flex/pom.xml
----------------------------------------------------------------------
diff --git a/mavenizer/converters/flex/pom.xml b/mavenizer/converters/flex/pom.xml
index 6df279f..480bc83 100644
--- a/mavenizer/converters/flex/pom.xml
+++ b/mavenizer/converters/flex/pom.xml
@@ -54,6 +54,11 @@
             <artifactId>fontkit-converter</artifactId>
             <version>1.0.0-SNAPSHOT</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.flex.utilities.converter</groupId>
+            <artifactId>wrapper-converter</artifactId>
+            <version>1.0.0-SNAPSHOT</version>
+        </dependency>
     </dependencies>
 
 </project>

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/1a46b112/mavenizer/converters/pom.xml
----------------------------------------------------------------------
diff --git a/mavenizer/converters/pom.xml b/mavenizer/converters/pom.xml
index d2dbad4..69a859b 100644
--- a/mavenizer/converters/pom.xml
+++ b/mavenizer/converters/pom.xml
@@ -39,6 +39,7 @@
         <module>flash</module>
         <module>flex</module>
         <module>fontkit</module>
+        <module>wrapper</module>
     </modules>
 
 </project>

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/1a46b112/mavenizer/converters/wrapper/pom.xml
----------------------------------------------------------------------
diff --git a/mavenizer/converters/wrapper/pom.xml b/mavenizer/converters/wrapper/pom.xml
new file mode 100644
index 0000000..86f8a43
--- /dev/null
+++ b/mavenizer/converters/wrapper/pom.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+  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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.flex.utilities.converter</groupId>
+        <artifactId>converters</artifactId>
+        <version>1.0.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>wrapper-converter</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.flex.utilities.converter</groupId>
+            <artifactId>base-converter</artifactId>
+            <version>1.0.0-SNAPSHOT</version>
+        </dependency>
+    </dependencies>
+
+</project>

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/1a46b112/mavenizer/converters/wrapper/src/main/java/org/apache/flex/utilities/converter/wrapper/WrapperConverter.java
----------------------------------------------------------------------
diff --git a/mavenizer/converters/wrapper/src/main/java/org/apache/flex/utilities/converter/wrapper/WrapperConverter.java
b/mavenizer/converters/wrapper/src/main/java/org/apache/flex/utilities/converter/wrapper/WrapperConverter.java
new file mode 100644
index 0000000..6a2b691
--- /dev/null
+++ b/mavenizer/converters/wrapper/src/main/java/org/apache/flex/utilities/converter/wrapper/WrapperConverter.java
@@ -0,0 +1,87 @@
+package org.apache.flex.utilities.converter.wrapper;
+
+import org.apache.flex.utilities.converter.BaseConverter;
+import org.apache.flex.utilities.converter.Converter;
+import org.apache.flex.utilities.converter.exceptions.ConverterException;
+import org.apache.flex.utilities.converter.model.MavenArtifact;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+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;
+
+/**
+ * Created by christoferdutz on 06.04.15.
+ */
+public class WrapperConverter extends BaseConverter implements Converter {
+
+    public WrapperConverter(File rootSourceDirectory, File rootTargetDirectory) throws ConverterException
{
+        super(rootSourceDirectory, rootTargetDirectory);
+    }
+
+    @Override
+    protected void processDirectory() throws ConverterException {
+        File wrapperRootDir = new File(rootSourceDirectory, "templates/swfobject");
+        if(!wrapperRootDir.exists() || !wrapperRootDir.isDirectory()) {
+            System.out.println("Skipping Wrapper generation.");
+            return;
+        }
+
+        try {
+            final File wrapperJar = File.createTempFile("SWFObjectWrapper-2.2", ".jar");
+            generateZip(wrapperRootDir.listFiles(), wrapperJar);
+
+            final MavenArtifact swfobjectWrapper = new MavenArtifact();
+            swfobjectWrapper.setGroupId("org.apache.flex.wrapper");
+            swfobjectWrapper.setArtifactId("swfobject");
+            swfobjectWrapper.setVersion(getFlexVersion(rootSourceDirectory));
+            swfobjectWrapper.setPackaging("jar");
+            swfobjectWrapper.addDefaultBinaryArtifact(wrapperJar);
+
+            writeArtifact(swfobjectWrapper);
+        } catch (IOException e) {
+            throw new ConverterException("Error creating wrapper jar.", e);
+        }
+    }
+
+    /**
+     * Get the version of an Flex SDK from the content of the SDK directory.
+     *
+     * @return version string for the current Flex SDK
+     */
+    protected String getFlexVersion(File rootDirectory) throws ConverterException {
+        final File sdkDescriptor = new File(rootDirectory, "flex-sdk-description.xml");
+
+        // If the descriptor is not present, return null as this FDK directory doesn't
+        // seem to contain a Flex SDK.
+        if(!sdkDescriptor.exists()) {
+            return null;
+        }
+
+        final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        try {
+            // Parse the document
+            final DocumentBuilder db = dbf.newDocumentBuilder();
+            final Document dom = db.parse(sdkDescriptor);
+
+            // Get name, version and build nodes
+            final Element root = dom.getDocumentElement();
+            final String version = root.getElementsByTagName("version").item(0).getTextContent();
+            final String build = root.getElementsByTagName("build").item(0).getTextContent();
+
+            // In general the version consists of the content of the version element with
an appended build-number.
+            return (build.equals("0")) ? version + "-SNAPSHOT" : version;
+        } catch (ParserConfigurationException pce) {
+            throw new RuntimeException(pce);
+        } catch (SAXException se) {
+            throw new RuntimeException(se);
+        } catch (IOException ioe) {
+            throw new RuntimeException(ioe);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/1a46b112/mavenizer/maven-extension/pom.xml
----------------------------------------------------------------------
diff --git a/mavenizer/maven-extension/pom.xml b/mavenizer/maven-extension/pom.xml
index 384fba9..4a96355 100644
--- a/mavenizer/maven-extension/pom.xml
+++ b/mavenizer/maven-extension/pom.xml
@@ -95,6 +95,11 @@
             <artifactId>fontkit-converter</artifactId>
             <version>1.0.0-SNAPSHOT</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.flex.utilities.converter</groupId>
+            <artifactId>wrapper-converter</artifactId>
+            <version>1.0.0-SNAPSHOT</version>
+        </dependency>
 
         <dependency>
             <groupId>javax.inject</groupId>

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/1a46b112/mavenizer/maven-extension/src/main/java/org/apache/flex/utilities/converter/mavenextension/FlexEventSpy.java
----------------------------------------------------------------------
diff --git a/mavenizer/maven-extension/src/main/java/org/apache/flex/utilities/converter/mavenextension/FlexEventSpy.java
b/mavenizer/maven-extension/src/main/java/org/apache/flex/utilities/converter/mavenextension/FlexEventSpy.java
index f6d5c4f..e946db0 100644
--- a/mavenizer/maven-extension/src/main/java/org/apache/flex/utilities/converter/mavenextension/FlexEventSpy.java
+++ b/mavenizer/maven-extension/src/main/java/org/apache/flex/utilities/converter/mavenextension/FlexEventSpy.java
@@ -7,6 +7,7 @@ import org.apache.flex.utilities.converter.flex.FlexConverter;
 import org.apache.flex.utilities.converter.fontkit.FontkitConverter;
 import org.apache.flex.utilities.converter.retrievers.download.DownloadRetriever;
 import org.apache.flex.utilities.converter.retrievers.types.SdkType;
+import org.apache.flex.utilities.converter.wrapper.WrapperConverter;
 import org.apache.maven.MavenExecutionException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
 import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
@@ -110,7 +111,7 @@ public class FlexEventSpy extends AbstractEventSpy {
             }
             ArtifactResolutionResult res = repositorySystem.resolve(req);
             return res.isSuccess();
-        } catch (Exception e) {
+        } catch (Throwable e) {
             return false;
         }
     }
@@ -123,17 +124,25 @@ public class FlexEventSpy extends AbstractEventSpy {
             DownloadRetriever downloadRetriever = new DownloadRetriever();
             File sdkRoot = downloadRetriever.retrieve(SdkType.FLEX, version);
 
+            // In order to create a fully functional wrapper we need to download
+            // SWFObject and merge that with the fdk first.
+            File swfObjectRoot = downloadRetriever.retrieve(SdkType.SWFOBJECT);
+            FileUtils.copyDirectory(swfObjectRoot, sdkRoot);
+
             // In order to compile some of the themes, we need to download a
             // playerglobal version.
             logger.info("In order to convert the Apache Flex SDK, a Flash SDK has to be downloaded.");
             File flashSdkRoot = downloadRetriever.retrieve(SdkType.FLASH, "10.2");
             FileUtils.copyDirectory(flashSdkRoot, sdkRoot);
 
+            // Convert the FDK itself.
             FlexConverter converter = new FlexConverter(sdkRoot, localRepoBaseDir);
             converter.convert();
-        } catch (Exception ce) {
-            logger.error("Error", ce);
-            ce.printStackTrace();
+
+            // Convert the wrapper.
+            WrapperConverter wrapperConverter = new WrapperConverter(sdkRoot, localRepoBaseDir);
+            wrapperConverter.convert();
+        } catch (Throwable ce) {
             throw new MavenExecutionException(
                     "Caught exception while downloading and converting artifact.", ce);
         }
@@ -149,7 +158,7 @@ public class FlexEventSpy extends AbstractEventSpy {
             File sdkRoot = downloadRetriever.retrieve(SdkType.FLASH, version);
             FlashConverter converter = new FlashConverter(sdkRoot, localRepoBaseDir);
             converter.convert();
-        } catch (Exception ce) {
+        } catch (Throwable ce) {
             throw new MavenExecutionException(
                     "Caught exception while downloading and converting artifact.", ce);
         }
@@ -165,7 +174,7 @@ public class FlexEventSpy extends AbstractEventSpy {
             File sdkRoot = downloadRetriever.retrieve(SdkType.AIR, version);
             AirConverter converter = new AirConverter(sdkRoot, localRepoBaseDir);
             converter.convert();
-        } catch (Exception ce) {
+        } catch (Throwable ce) {
             throw new MavenExecutionException(
                     "Caught exception while downloading and converting artifact.", ce);
         }
@@ -181,7 +190,7 @@ public class FlexEventSpy extends AbstractEventSpy {
             File sdkRoot = downloadRetriever.retrieve(SdkType.FONTKIT);
             FontkitConverter converter = new FontkitConverter(sdkRoot, localRepoBaseDir);
             converter.convert();
-        } catch (Exception ce) {
+        } catch (Throwable ce) {
             throw new MavenExecutionException(
                     "Caught exception while downloading and converting artifact.", ce);
         }

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/1a46b112/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/types/SdkType.java
----------------------------------------------------------------------
diff --git a/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/types/SdkType.java
b/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/types/SdkType.java
index 5ea0ba8..f8b3024 100644
--- a/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/types/SdkType.java
+++ b/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/types/SdkType.java
@@ -24,6 +24,7 @@ public enum SdkType {
     FLEX,
     FLASH,
     AIR,
-    FONTKIT
+    FONTKIT,
+    SWFOBJECT
 
 }

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/1a46b112/mavenizer/retrievers/download/src/main/java/org/apache/flex/utilities/converter/retrievers/download/DownloadRetriever.java
----------------------------------------------------------------------
diff --git a/mavenizer/retrievers/download/src/main/java/org/apache/flex/utilities/converter/retrievers/download/DownloadRetriever.java
b/mavenizer/retrievers/download/src/main/java/org/apache/flex/utilities/converter/retrievers/download/DownloadRetriever.java
index 81c4f75..45c9570 100644
--- a/mavenizer/retrievers/download/src/main/java/org/apache/flex/utilities/converter/retrievers/download/DownloadRetriever.java
+++ b/mavenizer/retrievers/download/src/main/java/org/apache/flex/utilities/converter/retrievers/download/DownloadRetriever.java
@@ -125,20 +125,36 @@ public class DownloadRetriever extends BaseRetriever {
                     final File targetDirectory = new File(targetFile.getParent(),
                             targetFile.getName().substring(0, targetFile.getName().lastIndexOf(".")
- 1));
                     final File libDestFile = new File(targetDirectory, "frameworks/libs/player/"
+ version + "/playerglobal.swc");
-                    if(!libDestFile.getParentFile().exists()) {
+                    if (!libDestFile.getParentFile().exists()) {
                         libDestFile.getParentFile().mkdirs();
                     }
                     FileUtils.moveFile(targetFile, libDestFile);
                     return targetDirectory;
                 } else {
                     System.out.println("Extracting archive to temp directory.");
-                    final File targetDirectory = new File(targetFile.getParent(),
+                    File targetDirectory = new File(targetFile.getParent(),
                             targetFile.getName().substring(0, targetFile.getName().lastIndexOf(".")
- 1));
-                    unpack(targetFile, targetDirectory);
+                    if(type.equals(SdkType.SWFOBJECT)) {
+                        unpack(targetFile, new File(targetDirectory, "templates"));
+                    } else {
+                        unpack(targetFile, targetDirectory);
+                    }
                     System.out.println();
                     System.out.println("Finished extracting.");
                     System.out.println("===========================================================");
 
+                    // In case of the swfobject, delete some stuff we don't want in there.
+                    if(type.equals(SdkType.SWFOBJECT)) {
+                        File delFile = new File(targetDirectory, "templates/swfobject/index_dynamic.html");
+                        FileUtils.deleteQuietly(delFile);
+                        delFile = new File(targetDirectory, "templates/swfobject/index.html");
+                        FileUtils.deleteQuietly(delFile);
+                        delFile = new File(targetDirectory, "templates/swfobject/test.swf");
+                        FileUtils.deleteQuietly(delFile);
+                        delFile = new File(targetDirectory, "templates/swfobject/src");
+                        FileUtils.deleteDirectory(delFile);
+                    }
+
                     return targetDirectory;
                 }
             }
@@ -250,7 +266,7 @@ public class DownloadRetriever extends BaseRetriever {
             }
 
             final StringBuilder stringBuilder = new StringBuilder();
-            if (sdkType == SdkType.FLEX) {
+            if ((sdkType == SdkType.FLEX) || (sdkType == SdkType.SWFOBJECT)) {
                 final String path = artifactElement.getAttribute("path");
                 final String file = artifactElement.getAttribute("file");
                 if (!path.startsWith("http://")) {
@@ -260,7 +276,10 @@ public class DownloadRetriever extends BaseRetriever {
                 if(!path.endsWith("/")) {
                     stringBuilder.append("/");
                 }
-                stringBuilder.append(file).append(".zip");
+                stringBuilder.append(file);
+                if(sdkType == SdkType.FLEX) {
+                    stringBuilder.append(".zip");
+                }
             } else {
                 final NodeList pathElements = artifactElement.getElementsByTagName("path");
                 final NodeList fileElements = artifactElement.getElementsByTagName("file");
@@ -318,7 +337,10 @@ public class DownloadRetriever extends BaseRetriever {
                 break;
             case FONTKIT:
                 stringBuilder.append("//fontswf");
-
+                break;
+            case SWFOBJECT:
+                stringBuilder.append("//swfobject");
+                break;
         }
         return stringBuilder.toString();
     }
@@ -413,11 +435,4 @@ public class DownloadRetriever extends BaseRetriever {
         }
         return result;
     }
-
-    public static void main(String[] args) throws Exception {
-        DownloadRetriever downloadRetriever = new DownloadRetriever();
-        //downloadRetriever.getAvailableVersions(SdkType.FLEX);
-        //downloadRetriever.getAvailableVersions(SdkType.FLASH);
-        downloadRetriever.getAvailableVersions(SdkType.AIR);
-    }
 }


Mime
View raw message