incubator-flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erikdebr...@apache.org
Subject svn commit: r1407406 [1/2] - in /incubator/flex/utilities/trunk/mavenizer: ./ src/ src/main/ src/main/java/ src/main/java/air/ src/main/java/common/ src/main/java/flex/ src/main/resources/ src/test/ src/test/java/
Date Fri, 09 Nov 2012 09:59:43 GMT
Author: erikdebruin
Date: Fri Nov  9 09:59:42 2012
New Revision: 1407406

URL: http://svn.apache.org/viewvc?rev=1407406&view=rev
Log:
Initial commit of the Apache Flex Mavenizer code donated by Christofer Dutz.

Added:
    incubator/flex/utilities/trunk/mavenizer/README.txt   (with props)
    incubator/flex/utilities/trunk/mavenizer/download-sources.txt   (with props)
    incubator/flex/utilities/trunk/mavenizer/pom.xml   (with props)
    incubator/flex/utilities/trunk/mavenizer/src/
    incubator/flex/utilities/trunk/mavenizer/src/main/
    incubator/flex/utilities/trunk/mavenizer/src/main/java/
    incubator/flex/utilities/trunk/mavenizer/src/main/java/SDKGenerator.java   (with props)
    incubator/flex/utilities/trunk/mavenizer/src/main/java/air/
    incubator/flex/utilities/trunk/mavenizer/src/main/java/air/AirFrameworkGenerator.java   (with props)
    incubator/flex/utilities/trunk/mavenizer/src/main/java/air/AirRuntimeGenerator.java   (with props)
    incubator/flex/utilities/trunk/mavenizer/src/main/java/common/
    incubator/flex/utilities/trunk/mavenizer/src/main/java/common/BaseGenerator.java   (with props)
    incubator/flex/utilities/trunk/mavenizer/src/main/java/common/MavenMetadata.java   (with props)
    incubator/flex/utilities/trunk/mavenizer/src/main/java/flex/
    incubator/flex/utilities/trunk/mavenizer/src/main/java/flex/FlexCompilerGenerator.java   (with props)
    incubator/flex/utilities/trunk/mavenizer/src/main/java/flex/FlexFrameworkGenerator.java   (with props)
    incubator/flex/utilities/trunk/mavenizer/src/main/java/flex/FlexRuntimeGenerator.java   (with props)
    incubator/flex/utilities/trunk/mavenizer/src/main/resources/
    incubator/flex/utilities/trunk/mavenizer/src/main/resources/dummy.rb.swc   (with props)
    incubator/flex/utilities/trunk/mavenizer/src/main/resources/manual-artifact-overrides.csv   (with props)
    incubator/flex/utilities/trunk/mavenizer/src/test/
    incubator/flex/utilities/trunk/mavenizer/src/test/java/

Added: incubator/flex/utilities/trunk/mavenizer/README.txt
URL: http://svn.apache.org/viewvc/incubator/flex/utilities/trunk/mavenizer/README.txt?rev=1407406&view=auto
==============================================================================
--- incubator/flex/utilities/trunk/mavenizer/README.txt (added)
+++ incubator/flex/utilities/trunk/mavenizer/README.txt Fri Nov  9 09:59:42 2012
@@ -0,0 +1,27 @@
+1. Download all the SDKs (Flex & AIR).
+2. Extract all of them into one directory.
+3. Modify the "flex-sdk-description.xml" of the Flex SDK 2.0.1.180927 so the version is "2.0.1"
+4. Create a target directory where all the artifacts will be generated.
+5. Execute the tool:
+    java SDKGenerator "source-directory" "target-directory"
+
+Flex SDK 2.0:
+- Version is strange "3.0 Moxie M2.180927". Has to be changed to 2.0.1.180927 in flex-sdk-description.xml
+
+Flex 3.0.0.477A:
+- Create text-file called "AIR SDK Readme.txt" in the Flex 3.0.0.477A SDK with following content:
+Adobe AIR 1.?.? SDK
+
+Flex 3.0.1.1732A:
+- Create text-file called "AIR SDK Readme.txt" in the Flex 3.0.1.1732A SDK with following content:
+Adobe AIR 1.?.? SDK
+
+Flex 3.2.0.3958A:
+- Create text-file called "AIR SDK Readme.txt" in the Flex 3.1.0.2710A SDK with following content:
+Adobe AIR 1.?.? SDK
+
+Flex 4.8.0.1359417:
+- Needs "player" directory in "framework" in order to execute compc (Copy from Flex 4.6.0).
+- "osmf" and "textlayout" are not included in 4.8.0 so they need to be copied from 4.6.0 (Rember to also copy the RSLs)
+- Needs to detect the AIR version the FDK is compatable with, this is currently determined by checking the version of
+    the airglobal.swc in the framework/libs/air/airglobal.swc. Simply copy this from the 4.6 FDK

Propchange: incubator/flex/utilities/trunk/mavenizer/README.txt
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/flex/utilities/trunk/mavenizer/download-sources.txt
URL: http://svn.apache.org/viewvc/incubator/flex/utilities/trunk/mavenizer/download-sources.txt?rev=1407406&view=auto
==============================================================================
--- incubator/flex/utilities/trunk/mavenizer/download-sources.txt (added)
+++ incubator/flex/utilities/trunk/mavenizer/download-sources.txt Fri Nov  9 09:59:42 2012
@@ -0,0 +1,4 @@
+Latest Air SDK: http://www.adobe.com/devnet/air/air-sdk-download.html
+Air SDK 3.2 (Win): http://airdownload.adobe.com/air/win/download/3.2/AdobeAIRSDK.zip
+Air SDK 3.2 (Mac): http://airdownload.adobe.com/air/mac/download/3.2/AdobeAIRSDK.tbz2
+Air SDKs & Runtimes: http://helpx.adobe.com/air/kb/archived-air-sdk-version.html
\ No newline at end of file

Propchange: incubator/flex/utilities/trunk/mavenizer/download-sources.txt
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/flex/utilities/trunk/mavenizer/pom.xml
URL: http://svn.apache.org/viewvc/incubator/flex/utilities/trunk/mavenizer/pom.xml?rev=1407406&view=auto
==============================================================================
--- incubator/flex/utilities/trunk/mavenizer/pom.xml (added)
+++ incubator/flex/utilities/trunk/mavenizer/pom.xml Fri Nov  9 09:59:42 2012
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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>
+
+    <groupId>net.flexmojos.oss</groupId>
+    <artifactId>flex-sdk-converter</artifactId>
+    <version>1.0</version>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.sun.jersey</groupId>
+            <artifactId>jersey-client</artifactId>
+            <version>1.12</version>
+        </dependency>
+        <dependency>
+            <groupId>org.codehaus.jettison</groupId>
+            <artifactId>jettison</artifactId>
+            <version>1.3.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-compress</artifactId>
+            <version>1.4</version>
+        </dependency>
+    </dependencies>
+
+</project>
\ No newline at end of file

Propchange: incubator/flex/utilities/trunk/mavenizer/pom.xml
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/flex/utilities/trunk/mavenizer/src/main/java/SDKGenerator.java
URL: http://svn.apache.org/viewvc/incubator/flex/utilities/trunk/mavenizer/src/main/java/SDKGenerator.java?rev=1407406&view=auto
==============================================================================
--- incubator/flex/utilities/trunk/mavenizer/src/main/java/SDKGenerator.java (added)
+++ incubator/flex/utilities/trunk/mavenizer/src/main/java/SDKGenerator.java Fri Nov  9 09:59:42 2012
@@ -0,0 +1,219 @@
+import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.parsers.*;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+import air.AirFrameworkGenerator;
+import air.AirRuntimeGenerator;
+import flex.FlexCompilerGenerator;
+import flex.FlexFrameworkGenerator;
+import flex.FlexRuntimeGenerator;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: cdutz
+ * Date: 11.05.12
+ * Time: 12:03
+ */
+public class SDKGenerator {
+
+    protected List<String> generatedAirVersions = new ArrayList<String>();
+
+    /**
+     * All this little helper does is list up all directories in the given base directory and
+     * trigger the actual import on that. If a flex sdk comes with an air runtime, the structure
+     * is identical to that of an ordinary air sdk. Therefore the import works if a flex sdk or
+     * an air sdk directory is passed to this method.
+     *
+     * @param sdkSourceDirectory source directory containing the air content
+     * @param sdkTargetDirectory directory where to copy the content
+     * @throws Exception
+     */
+    public void generateAllAir(File sdkSourceDirectory, File sdkTargetDirectory) throws Exception {
+        final File sdkDirectories[] = sdkSourceDirectory.listFiles(new FileFilter() {
+            public boolean accept(File pathname) {
+                return pathname.isDirectory();
+            }
+        });
+        if (sdkDirectories != null) {
+            System.out.println("---------------------------------------------");
+            for (final File sdkDirectory : sdkDirectories) {
+                String sdkVersion = getAirSdkVersion(sdkDirectory);
+
+                // As we are eventually generating the air sdks first, a flex sdk processed
+                // later could contain the same version of air, in this case we skip that.
+                if((sdkVersion != null) && !generatedAirVersions.contains(sdkVersion)) {
+                    System.out.println("-- Generating Air SDK version: " + sdkVersion);
+                    System.out.println("---------------------------------------------");
+
+                    generateAir(sdkDirectory, sdkTargetDirectory, sdkVersion);
+
+                    System.out.println("---------------------------------------------");
+
+                    generatedAirVersions.add(sdkVersion);
+                }
+            }
+        }
+    }
+
+    public void generateAir(final File sdkSourceDirectory, final File sdkTargetDirectory, final String sdkVersion) throws Exception {
+        // Generate the artifacts, needed by the flex application.
+        new AirFrameworkGenerator().process(sdkSourceDirectory, false, sdkTargetDirectory, sdkVersion);
+
+        // Deploy the FlashPlayer and AIR runtime binaries.
+        new AirRuntimeGenerator().process(sdkSourceDirectory, false, sdkTargetDirectory, sdkVersion);
+    }
+
+    public void generateAllFlex(File sdkSourceDirectory, File sdkTargetDirectory) throws Exception {
+        final File sdkDirectories[] = sdkSourceDirectory.listFiles(new FileFilter() {
+            public boolean accept(File pathname) {
+                return pathname.isDirectory();
+            }
+        });
+        if (sdkDirectories != null) {
+            System.out.println("---------------------------------------------");
+            for (final File sdkDirectory : sdkDirectories) {
+                String sdkVersion = getFlexSdkVersion(sdkDirectory);
+
+                // Apache FDKs (ok ... the only one available) have the version prefix "Apache-"
+                // So this is what we use in order to determine what type of FDK it is.
+                final boolean isApache = sdkVersion.startsWith("Apache-");
+                if (isApache) {
+                    sdkVersion = sdkVersion.substring("Apache-".length());
+                }
+
+                System.out.println("-- Generating Flex SDK version: " + sdkVersion);
+                System.out.println("---------------------------------------------");
+
+                // TODO: Comment this line in to deploy the apache flex under org.apache.flex
+                //generateFlex(sdkDirectory, isApache, sdkTargetDirectory, sdkVersion);
+                generateFlex(sdkDirectory, false, sdkTargetDirectory, sdkVersion);
+
+                System.out.println("---------------------------------------------");
+            }
+        }
+    }
+
+    public void generateFlex(final File sdkSourceDirectory, final boolean isApache, final File sdkTargetDirectory, final String sdkVersion) throws Exception {
+        // Generate the artifacts, needed by the flex compiler.
+        new FlexCompilerGenerator().process(sdkSourceDirectory, isApache, sdkTargetDirectory, sdkVersion);
+
+        // Generate the artifacts, needed by the flex application.
+        new FlexFrameworkGenerator().process(sdkSourceDirectory, isApache, sdkTargetDirectory, sdkVersion);
+
+        // Deploy the FlashPlayer and AIR runtime binaries.
+        new FlexRuntimeGenerator().process(sdkSourceDirectory, isApache, sdkTargetDirectory, sdkVersion);
+    }
+
+    public static void main(String[] args) throws Exception {
+
+        if (args.length != 2) {
+            System.out.println("Usage: SDKGenerator {source-directory} {target-directory}");
+            System.exit(0);
+        }
+
+        final String sdkSourceDirectoryName = args[0];
+        final String sdkTargetDirectoryName = args[1];
+
+        final File sdkSourceDirectory = new File(sdkSourceDirectoryName);
+        final File sdkTargetDirectory = new File(sdkTargetDirectoryName);
+
+        // When generating the fdks the generator tries to figure out the flashplayer-version and air-version
+        // by comparing the hash of the playerglobal.swc and airglobal.swc with some hashes. This list of
+        // hashes has to be created first. Therefore the Generator generates air artifacts by processing air
+        // sdk directories and then by extracting the needed artifacts from the flex fdks.
+        final SDKGenerator generator = new SDKGenerator();
+        generator.generateAllAir(new File(sdkSourceDirectory, "air"), sdkTargetDirectory);
+        generator.generateAllAir(new File(sdkSourceDirectory, "flex"), sdkTargetDirectory);
+
+        // After the air artifacts are generated and
+        generator.generateAllFlex(new File(sdkSourceDirectory, "flex"), sdkTargetDirectory);
+    }
+
+    /**
+     * The only place I found where to extract the version of an Air SDK was the "AIR SDK Readme.txt" file.
+     * In order to get the version we need to cut out the version-part from the title-row of that text file.
+     * This file is present in the root of a pure air sdk or in the root of a flex sdk, therefore the same
+     * algorithm works if sdkSourceDirectory points to a flex sdk or an air sdk.
+     *
+     * @param sdkSourceDirectory directory in which to look for the sdk descriptor file of an air sdk
+     * @return version of the sdk in th given directory
+     */
+    public static String getAirSdkVersion(final File sdkSourceDirectory) {
+        final File sdkDescriptor = new File(sdkSourceDirectory, "AIR SDK Readme.txt");
+
+        if (sdkDescriptor.exists()) {
+            DataInputStream in = null;
+            try {
+                final FileInputStream fstream = new FileInputStream(sdkDescriptor);
+                in = new DataInputStream(fstream);
+                final BufferedReader br = new BufferedReader(new InputStreamReader(in));
+                final String strLine = br.readLine();
+                return strLine.substring("Adobe AIR ".length(), strLine.indexOf(" ", "Adobe AIR ".length()));
+            } catch (Exception e) {
+                e.printStackTrace();
+            } finally {
+                if (in != null) {
+                    try {
+                        in.close();
+                    } catch (IOException ioe) {
+                        // Ignore.
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
+     * The Flex SDK version is contained in the flex-sdk-description.xml file.
+     *
+     * @param sdkSourceDirectory directory where to look for the fdk descriptor file
+     * @return version string of the fdk
+     */
+    public static String getFlexSdkVersion(final File sdkSourceDirectory) {
+        final File sdkDescriptor = new File(sdkSourceDirectory, "flex-sdk-description.xml");
+
+        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 name = root.getElementsByTagName("name").item(0).getTextContent();
+            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.
+            String sdkVersion = version + "." + build;
+
+            // Deal with the patched re-releases of all older SDKs:
+            // The patched versions have A or B appended to their name and not a modified version or build number.
+            // In order to differentiate the patched versions from the un-patched ones, we appnd A or B to the
+            // version string.
+            if (name.endsWith("A")) {
+                sdkVersion += "A";
+            } else if (name.endsWith("B")) {
+                sdkVersion += "B";
+            }
+
+            // If the name contains "Apache", we prefix the version with "Apache-". This is cut off
+            // again later on.
+            if (name.contains("Apache")) {
+                sdkVersion = "Apache-" + sdkVersion;
+            }
+
+            return sdkVersion;
+        } catch (ParserConfigurationException pce) {
+            throw new RuntimeException(pce);
+        } catch (SAXException se) {
+            throw new RuntimeException(se);
+        } catch (IOException ioe) {
+            throw new RuntimeException(ioe);
+        }
+    }
+}

Propchange: incubator/flex/utilities/trunk/mavenizer/src/main/java/SDKGenerator.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/flex/utilities/trunk/mavenizer/src/main/java/air/AirFrameworkGenerator.java
URL: http://svn.apache.org/viewvc/incubator/flex/utilities/trunk/mavenizer/src/main/java/air/AirFrameworkGenerator.java?rev=1407406&view=auto
==============================================================================
--- incubator/flex/utilities/trunk/mavenizer/src/main/java/air/AirFrameworkGenerator.java (added)
+++ incubator/flex/utilities/trunk/mavenizer/src/main/java/air/AirFrameworkGenerator.java Fri Nov  9 09:59:42 2012
@@ -0,0 +1,147 @@
+package air;
+
+import common.BaseGenerator;
+import common.MavenMetadata;
+import org.w3c.dom.Document;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: cdutz
+ * Date: 11.05.12
+ * Time: 14:55
+ */
+public class AirFrameworkGenerator extends BaseGenerator {
+
+    protected Map<String, String> libraryVersions = new HashMap<String, String>();
+    protected Map<String, String> libraryLocations = new HashMap<String, String>();
+
+    public void process(File sdkSourceDirectory, final boolean isApache, File sdkTargetDirectory, String sdkVersion)
+            throws Exception
+    {
+        final File frameworksDirectory = new File(sdkSourceDirectory, "frameworks");
+        final File targetBaseDirectory = new File(sdkTargetDirectory, "com/adobe/air/framework");
+
+        // Generate the artifacts based upon the structure of the libraries in the lib-directory.
+        final File swcsDirectory = new File(frameworksDirectory, "libs/air");
+        generateArtifactsForDirectory(
+                swcsDirectory, targetBaseDirectory, sdkVersion, "com.adobe.air.framework");
+    }
+
+    protected void generateArtifactsForDirectory(
+            final File sourceDirectory, final File targetDirectory, final String sdkVersion, final String groupId)
+            throws Exception
+    {
+        final MavenMetadata groupMetadata = new MavenMetadata();
+        groupMetadata.setGroupId(groupId);
+        groupMetadata.setArtifactId(groupId.substring(groupId.lastIndexOf(".") + 1, groupId.length()));
+        groupMetadata.setVersion(sdkVersion);
+        groupMetadata.setPackaging("pom");
+        groupMetadata.setLibrariesWithResourceBundles(new ArrayList<String>());
+        groupMetadata.setDependencies(new ArrayList<MavenMetadata>());
+
+        // Don't deploy the player, as this has to be dealt with differently.
+        final File[] directoryContent = sourceDirectory.listFiles(new FileFilter() {
+            public boolean accept(File pathname) {
+                return pathname.getName().endsWith(".swc");
+            }
+        });
+
+        if(directoryContent != null) {
+            for(File file : directoryContent) {
+                final MavenMetadata metadata = new MavenMetadata();
+                metadata.setGroupId(groupId);
+                String libraryName = file.getName().substring(0, file.getName().lastIndexOf("."));
+
+                String libraryVersion = libraryVersions.get(libraryName);
+                if(libraryVersion == null) {
+                    libraryVersion = sdkVersion;
+                }
+                final File targetSwcDirectory = new File(targetDirectory, libraryName + "/" + libraryVersion);
+                if(!targetSwcDirectory.exists()) {
+                    if(!targetSwcDirectory.mkdirs()) {
+                        throw new RuntimeException(
+                                "Could not create directory: " + targetSwcDirectory.getAbsolutePath());
+                    }
+                }
+                final File targetSwcFile =
+                        new File(targetSwcDirectory, libraryName + "-" + libraryVersion + ".swc");
+                copyFile(file, targetSwcFile);
+
+                metadata.setArtifactId(libraryName);
+                metadata.setVersion(libraryVersion);
+                metadata.setPackaging("swc");
+
+                generateSwcPom(targetSwcFile, metadata);
+
+                groupMetadata.getDependencies().add(metadata);
+
+                // Save the checksum and metadata of the playerglobal, so we can
+                // find out which air sdk is used when deploying the flex sdks later
+                // on.
+                if("airglobal".equals(libraryName)) {
+                    final String checksum = calculateChecksum(file);
+                    checksums.put(checksum, metadata);
+                }
+
+                libraryLocations.put(libraryName, targetSwcDirectory.getAbsolutePath());
+                libraryVersions.put(libraryName, libraryVersion);
+            }
+        }
+
+        final MavenMetadata commonFrameworkMetaData = new MavenMetadata();
+        commonFrameworkMetaData.setGroupId(groupMetadata.getGroupId());
+        commonFrameworkMetaData.setArtifactId("common-framework");
+        commonFrameworkMetaData.setVersion(groupMetadata.getVersion());
+        commonFrameworkMetaData.setPackaging("pom");
+        commonFrameworkMetaData.setDependencies(new ArrayList<MavenMetadata>());
+        commonFrameworkMetaData.setLibrariesWithResourceBundles(new ArrayList<String>());
+
+        for(final MavenMetadata dependency : groupMetadata.getDependencies()) {
+            commonFrameworkMetaData.getDependencies().add(dependency);
+            if(groupMetadata.getLibrariesWithResourceBundles().contains(dependency.getArtifactId())) {
+                commonFrameworkMetaData.getLibrariesWithResourceBundles().add(dependency.getArtifactId());
+            }
+        }
+        final File commonFrameworkPom = new File(targetDirectory,
+                "common-framework/" + groupMetadata.getVersion() + "/common-framework-" +
+                        groupMetadata.getVersion() + ".pom");
+        generateSwcPom(commonFrameworkPom, commonFrameworkMetaData);
+
+        // Generate a dummy entry for the "flex-framework" pom,
+        // which will be generated later in the process.
+        final MavenMetadata flexFrameworkMetadata = new MavenMetadata();
+        flexFrameworkMetadata.setGroupId(groupMetadata.getGroupId());
+        flexFrameworkMetadata.setArtifactId("flex-framework");
+        flexFrameworkMetadata.setVersion(groupMetadata.getVersion());
+        flexFrameworkMetadata.setPackaging("pom");
+        groupMetadata.getDependencies().add(flexFrameworkMetadata);
+
+        // Generate the master pom for the current library (Pom that defines
+        // all versions of the current sdk libraries.
+        final File groupPomFile = new File(targetDirectory,
+                groupMetadata.getVersion() + "/" + groupMetadata.getArtifactId() + "-" +
+                        groupMetadata.getVersion() + ".pom");
+        generateDependencyManagementPom(groupPomFile, groupMetadata);
+    }
+
+    protected void generateSwcPom(final File targetSwc, final MavenMetadata metadata) throws Exception {
+        final String swcPath = targetSwc.getAbsolutePath();
+        final String pomPath = swcPath.substring(0, swcPath.lastIndexOf(".")) + ".pom";
+
+        final Document pom = createPomDocument(metadata);
+
+        writeDocument(pom, new File(pomPath));
+    }
+
+    protected void generateDependencyManagementPom(final File targetSwc, final MavenMetadata metadata) throws Exception {
+        final String swcPath = targetSwc.getAbsolutePath();
+        final String pomPath = swcPath.substring(0, swcPath.lastIndexOf(".")) + ".pom";
+
+        final Document pom = createPomDocumentDependencyManagement(metadata);
+
+        writeDocument(pom, new File(pomPath));
+    }
+}

Propchange: incubator/flex/utilities/trunk/mavenizer/src/main/java/air/AirFrameworkGenerator.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/flex/utilities/trunk/mavenizer/src/main/java/air/AirRuntimeGenerator.java
URL: http://svn.apache.org/viewvc/incubator/flex/utilities/trunk/mavenizer/src/main/java/air/AirRuntimeGenerator.java?rev=1407406&view=auto
==============================================================================
--- incubator/flex/utilities/trunk/mavenizer/src/main/java/air/AirRuntimeGenerator.java (added)
+++ incubator/flex/utilities/trunk/mavenizer/src/main/java/air/AirRuntimeGenerator.java Fri Nov  9 09:59:42 2012
@@ -0,0 +1,188 @@
+package air;
+
+import common.BaseGenerator;
+import common.MavenMetadata;
+import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
+import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
+
+import java.io.*;
+import java.text.NumberFormat;
+import java.util.Locale;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: cdutz
+ * Date: 14.05.12
+ * Time: 22:42
+ */
+public class AirRuntimeGenerator extends BaseGenerator {
+
+    @Override
+    public void process(File sdkSourceDirectory, boolean isApache, File sdkTargetDirectory, String sdkVersion)
+            throws Exception
+    {
+        processFlashRuntime(sdkSourceDirectory, sdkTargetDirectory);
+    }
+
+    protected void processFlashRuntime(File sdkSourceDirectory, File sdkTargetDirectory)
+            throws Exception
+    {
+        final File runtimeDirectory = new File(sdkSourceDirectory, "runtimes");
+        final File flashPlayerDirectory = new File(runtimeDirectory, "player");
+
+        File[] versions = flashPlayerDirectory.listFiles(new FileFilter() {
+            public boolean accept(File pathname) {
+                return pathname.isDirectory() && !"win".equalsIgnoreCase(pathname.getName()) &&
+                        !"lnx".equalsIgnoreCase(pathname.getName()) && !"mac".equalsIgnoreCase(pathname.getName());
+            }
+        });
+        // The flash-player 9 is installed directly in the player directory.
+        if(new File(flashPlayerDirectory, "win").exists()) {
+            final File[] extendedVersions = new File[versions.length + 1];
+            System.arraycopy(versions, 0, extendedVersions, 0, versions.length);
+            extendedVersions[versions.length] = flashPlayerDirectory;
+            versions = extendedVersions;
+        }
+
+        if(versions != null) {
+            for(final File versionDir : versions) {
+                // If the versionDir is called "player", then this is the home of the flash-player version 9.
+                final String playerVersionString = "player".equalsIgnoreCase(versionDir.getName()) ? "9.0" : versionDir.getName();
+                final double playerVersion = Double.valueOf(playerVersionString);
+                final NumberFormat doubleFormat = NumberFormat.getInstance(Locale.US);
+                doubleFormat.setMinimumFractionDigits(1);
+                doubleFormat.setMaximumFractionDigits(1);
+                final String version = doubleFormat.format(playerVersion);
+
+                final File targetDir = new File(sdkTargetDirectory, "com/adobe/flash/runtime/" + version);
+
+                // Deploy Windows binaries.
+                final File windowsDirectory = new File(versionDir, "win");
+                if(windowsDirectory.exists()) {
+                    // Find out if a flash-player binary exists.
+                    File flashPlayerBinary = null;
+                    if(new File(windowsDirectory, "FlashPlayerDebugger.exe").exists()) {
+                        flashPlayerBinary = new File(windowsDirectory, "FlashPlayerDebugger.exe");
+                    } else if(new File(windowsDirectory, "FlashPlayer.exe").exists()) {
+                        flashPlayerBinary = new File(windowsDirectory, "FlashPlayer.exe");
+                    }
+
+                    // If a binary exists, copy it to the target and create a pom for it.
+                    if (flashPlayerBinary != null) {
+                        if(!targetDir.exists()) {
+                            if(!targetDir.mkdirs()) {
+                                throw new RuntimeException("Could not create directory: " + targetDir.getAbsolutePath());
+                            }
+                        }
+                        final File targetFile = new File(targetDir, "/runtime-" + version + "-win.exe");
+                        copyFile(flashPlayerBinary, targetFile);
+                    }
+                }
+
+                // Deploy Mac binaries.
+                final File macDirectory = new File(versionDir, "mac");
+                if(macDirectory.exists()) {
+                    // Find out if a flash-player binary exists.
+                    File flashPlayerBinary = null;
+                    if(new File(macDirectory, "Flash Player.app.zip").exists()) {
+                        flashPlayerBinary = new File(macDirectory, "Flash Player.app.zip");
+                    } else if(new File(macDirectory, "Flash Player Debugger.app.zip").exists()) {
+                        flashPlayerBinary = new File(macDirectory, "Flash Player Debugger.app.zip");
+                    }
+
+                    // If a binary exists, copy it to the target and create a pom for it.
+                    if (flashPlayerBinary != null) {
+                        if(!targetDir.exists()) {
+                            if(!targetDir.mkdirs()) {
+                                throw new RuntimeException("Could not create directory: " + targetDir.getAbsolutePath());
+                            }
+                        }
+                        final File targetFile = new File(targetDir, "/runtime-" + version + "-mac.zip");
+                        copyFile(flashPlayerBinary, targetFile);
+                    }
+                }
+
+                // Deploy Linux binaries.
+                final File lnxDirectory = new File(versionDir, "lnx");
+                if(lnxDirectory.exists()) {
+                    // Find out if a flash-player binary exists.
+                    File flashPlayerBinary = null;
+                    if(new File(lnxDirectory, "flashplayer.tar.gz").exists()) {
+                        flashPlayerBinary = new File(lnxDirectory, "flashplayer.tar.gz");
+                    } else if(new File(lnxDirectory, "flashplayerdebugger.tar.gz").exists()) {
+                        flashPlayerBinary = new File(lnxDirectory, "flashplayerdebugger.tar.gz");
+                    }
+
+                    // Decompress the archive.
+                    // First unzip it.
+                    final FileInputStream fin = new FileInputStream(flashPlayerBinary);
+                    final BufferedInputStream in = new BufferedInputStream(fin);
+                    final File tempTarFile = File.createTempFile("flex-sdk-linux-flashplayer-binary-" + version, ".tar");
+                    final FileOutputStream out = new FileOutputStream(tempTarFile);
+                    final GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in);
+                    final byte[] buffer = new byte[1024];
+                    int n;
+                    while (-1 != (n = gzIn.read(buffer))) {
+                        out.write(buffer, 0, n);
+                    }
+                    out.close();
+                    gzIn.close();
+
+                    // Then untar it.
+                    File uncompressedBinary = null;
+                    final FileInputStream tarFileInputStream = new FileInputStream(tempTarFile);
+                    final TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(tarFileInputStream);
+                    ArchiveEntry entry;
+                    while((entry = tarArchiveInputStream.getNextEntry()) != null) {
+                        if("flashplayer".equals(entry.getName())) {
+                            uncompressedBinary = File.createTempFile("flex-sdk-linux-flashplayer-binary-" + version, ".uexe");
+                            final FileOutputStream uncompressedBinaryOutputStream = new FileOutputStream(uncompressedBinary);
+                            while(-1 != (n = tarArchiveInputStream.read(buffer))) {
+                                uncompressedBinaryOutputStream.write(buffer, 0, n);
+                            }
+                            uncompressedBinaryOutputStream.close();
+                        } else if("flashplayerdebugger".equals(entry.getName())) {
+                            uncompressedBinary = File.createTempFile("flex-sdk-linux-flashplayer-binary-" + version, ".uexe");
+                            final FileOutputStream uncompressedBinaryOutputStream = new FileOutputStream(uncompressedBinary);
+                            while(-1 != (n = tarArchiveInputStream.read(buffer))) {
+                                uncompressedBinaryOutputStream.write(buffer, 0, n);
+                            }
+                            uncompressedBinaryOutputStream.close();
+                        }
+                    }
+                    tarFileInputStream.close();
+
+                    // If a binary exists, copy it to the target and create a pom for it.
+                    if (uncompressedBinary != null) {
+                        if(!targetDir.exists()) {
+                            if(!targetDir.mkdirs()) {
+                                throw new RuntimeException("Could not create directory: " + targetDir.getAbsolutePath());
+                            }
+                        }
+                        final File targetFile = new File(targetDir, "/runtime-" + version + "-linux.uexe");
+                        copyFile(uncompressedBinary, targetFile);
+
+                        // Clean up in the temp directory.
+                        if(!uncompressedBinary.delete()) {
+                            System.out.println("Could not delete: " + uncompressedBinary.getAbsolutePath());
+                        }
+                    }
+
+                    // Clean up in the temp directory.
+                    if(!tempTarFile.delete()) {
+                        System.out.println("Could not delete: " + tempTarFile.getAbsolutePath());
+                    }
+                }
+
+                final MavenMetadata playerArtifact = new MavenMetadata();
+                playerArtifact.setGroupId("com.adobe.flash");
+                playerArtifact.setArtifactId("runtime");
+                playerArtifact.setVersion(version);
+                playerArtifact.setPackaging("exe");
+
+                writeDocument(createPomDocument(playerArtifact), new File(targetDir, "runtime-" + version + ".pom"));
+            }
+        }
+    }
+}

Propchange: incubator/flex/utilities/trunk/mavenizer/src/main/java/air/AirRuntimeGenerator.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/flex/utilities/trunk/mavenizer/src/main/java/common/BaseGenerator.java
URL: http://svn.apache.org/viewvc/incubator/flex/utilities/trunk/mavenizer/src/main/java/common/BaseGenerator.java?rev=1407406&view=auto
==============================================================================
--- incubator/flex/utilities/trunk/mavenizer/src/main/java/common/BaseGenerator.java (added)
+++ incubator/flex/utilities/trunk/mavenizer/src/main/java/common/BaseGenerator.java Fri Nov  9 09:59:42 2012
@@ -0,0 +1,373 @@
+package common;
+
+import java.io.*;
+import java.math.BigInteger;
+import java.security.MessageDigest;
+import java.util.*;
+import javax.xml.parsers.*;
+import javax.xml.transform.*;
+import javax.xml.transform.dom.*;
+import javax.xml.transform.stream.*;
+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONObject;
+import org.codehaus.jettison.json.JSONTokener;
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.WebResource;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: cdutz
+ * Date: 11.05.12
+ * Time: 14:53
+ */
+public abstract class BaseGenerator {
+
+    protected static final Map<String, MavenMetadata> checksums = new HashMap<String, MavenMetadata>();
+
+    protected static final String MAVEN_SCHEMA_URI = "http://maven.apache.org/POM/4.0.0";
+    protected static final String MAVEN_CENTRAL_SHA_1_QUERY_URL = "http://search.maven.org/solrsearch/select?rows=20&wt=json&q=1:";
+    // Artifactory: "http://server:port/artifactory/api/search/checksum?repos=libs-release-local&md5=04040c7c184620af0a0a8a3682a75eb7
+    // Nexus: "http://repository.sonatype.org/service/local/data_index?a=04040c7c184620af0a0a8a3682a75eb7"
+
+    abstract public void process(File sdkSourceDirectory, boolean isApache, File sdkTargetDirectory, String sdkVersion)
+            throws Exception;
+
+    protected String calculateChecksum(File jarFile) throws Exception {
+        // Implement the calculation of checksums for a given jar.
+        final MessageDigest digest = MessageDigest.getInstance("SHA-1");
+
+        final InputStream is = new FileInputStream(jarFile);
+        final byte[] buffer = new byte[8192];
+        int read;
+        try {
+        	while( (read = is.read(buffer)) > 0) {
+                digest.update(buffer, 0, read);
+        	}
+            final byte[] md5sum = digest.digest();
+            final BigInteger bigInt = new BigInteger(1, md5sum);
+            return bigInt.toString(16);
+        }
+        catch(IOException e) {
+        	throw new RuntimeException("Unable to process file for MD5", e);
+        }
+        finally {
+        	try {
+        		is.close();
+        	}
+        	catch(IOException e) {
+                //noinspection ThrowFromFinallyBlock
+                throw new RuntimeException("Unable to close input stream for MD5 calculation", e);
+        	}
+        }
+    }
+
+    protected MavenMetadata lookupMetadataForChecksum(String checksum) throws Exception {
+        final String queryUrl = MAVEN_CENTRAL_SHA_1_QUERY_URL + checksum;
+
+        final Client client = Client.create();
+        final WebResource webResource = client.resource(queryUrl);
+        final ClientResponse response = webResource.accept("application/json").get(ClientResponse.class);
+
+      	if (response.getStatus() != 200) {
+   		   throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
+      	}
+
+        final String output = response.getEntity(String.class);
+
+        final BufferedReader reader = new BufferedReader(new StringReader(output));
+        final StringBuilder builder = new StringBuilder();
+        for (String line; (line = reader.readLine()) != null; ) {
+            builder.append(line).append("\n");
+        }
+        final JSONTokener tokener = new JSONTokener(builder.toString());
+        final JSONObject rootObject = new JSONObject(tokener);
+
+        final JSONObject responseObject = (JSONObject) rootObject.get("response");
+        final int numFound = (Integer) responseObject.get("numFound");
+        if(numFound == 0) {
+            return null;
+        }
+        else if(numFound == 1) {
+            final JSONArray docs = (JSONArray) responseObject.get("docs");
+            final JSONObject firstHit = (JSONObject) docs.get(0);
+
+            final MavenMetadata artifactMetadata = new MavenMetadata();
+            artifactMetadata.groupId = (String) firstHit.get("g");
+            artifactMetadata.artifactId = (String) firstHit.get("a");
+            artifactMetadata.version = (String) firstHit.get("v");
+            artifactMetadata.packaging = (String) firstHit.get("p");
+
+            return artifactMetadata;
+        } else {
+            long newestTimestamp = 0;
+            JSONObject newestVersion = null;
+
+            JSONArray options = (JSONArray) responseObject.get("docs");
+            // if the "groupId" is "batik" then use the newer version.
+            for(int i = 0; i < numFound; i++) {
+                final JSONObject option = (JSONObject) options.get(0);
+                if("batik".equals(option.get("g")) && "batik-dom".equals(option.get("a")) && "jar".equals(option.get("p"))) {
+                    final long timestamp = (Long) option.get("timestamp");
+                    if(timestamp > newestTimestamp) {
+                        newestTimestamp = timestamp;
+                        newestVersion = option;
+                    }
+                }
+            }
+
+            if(newestVersion != null) {
+                final MavenMetadata artifactMetadata = new MavenMetadata();
+                artifactMetadata.groupId = (String) newestVersion.get("g");
+                artifactMetadata.artifactId = (String) newestVersion.get("a");
+                artifactMetadata.version = (String) newestVersion.get("v");
+                artifactMetadata.packaging = (String) newestVersion.get("p");
+
+                return artifactMetadata;
+            } else {
+                System.out.println("For jar-file with checksum: " + checksum +
+                        " more than one result was returned by query: " + queryUrl);
+            }
+        }
+        return null;
+    }
+
+    protected void copyFile(File source, File target) throws Exception {
+        InputStream in = new FileInputStream(source);
+        OutputStream out = new FileOutputStream(target);
+
+        byte[] buf = new byte[1024];
+        int len;
+        while ((len = in.read(buf)) > 0){
+            out.write(buf, 0, len);
+        }
+
+        in.close();
+        out.close();
+    }
+
+    protected void appendArtifact(MavenMetadata artifactMetadata, Element dependencies) {
+        final Document doc = dependencies.getOwnerDocument();
+        final Element dependency = doc.createElementNS(MAVEN_SCHEMA_URI, "dependency");
+        dependencies.appendChild(dependency);
+
+        final Element groupId = doc.createElementNS(MAVEN_SCHEMA_URI, "groupId");
+        groupId.setTextContent(artifactMetadata.groupId);
+        dependency.appendChild(groupId);
+        final Element artifactId = doc.createElementNS(MAVEN_SCHEMA_URI, "artifactId");
+        artifactId.setTextContent(artifactMetadata.artifactId);
+        dependency.appendChild(artifactId);
+        final Element version = doc.createElementNS(MAVEN_SCHEMA_URI, "version");
+        version.setTextContent(artifactMetadata.version);
+        dependency.appendChild(version);
+        if(!artifactMetadata.getPackaging().equals("jar")) {
+            final Element packaging = doc.createElementNS(MAVEN_SCHEMA_URI, "type");
+            packaging.setTextContent(artifactMetadata.packaging);
+            dependency.appendChild(packaging);
+        }
+    }
+
+    protected void writeDocument(Document doc, File outputFile) throws Exception {
+        final Source source = new DOMSource(doc);
+        final File outputDirectory = outputFile.getParentFile();
+        if(!outputDirectory.exists()) {
+            if(!outputDirectory.mkdirs()) {
+                throw new RuntimeException("Could not create directory: " + outputDirectory.getAbsolutePath());
+            }
+        }
+
+        final Result result = new StreamResult(outputFile);
+        final Transformer transformer = TransformerFactory.newInstance().newTransformer();
+        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
+        transformer.transform(source, result);
+    }
+
+    protected Document createPomDocument(final MavenMetadata metadata) throws Exception {
+        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        factory.setNamespaceAware(true);
+        final DocumentBuilder builder = factory.newDocumentBuilder();
+        DOMImplementation domImpl = builder.getDOMImplementation();
+        final Document pom = domImpl.createDocument(MAVEN_SCHEMA_URI, "project", null);
+
+        final Element root = pom.getDocumentElement();
+        final Element modelVersion = pom.createElementNS(MAVEN_SCHEMA_URI, "modelVersion");
+        modelVersion.setTextContent("4.0.0");
+        root.appendChild(modelVersion);
+        final Element groupId = pom.createElementNS(MAVEN_SCHEMA_URI, "groupId");
+        groupId.setTextContent(metadata.groupId);
+        root.appendChild(groupId);
+        final Element artifactId = pom.createElementNS(MAVEN_SCHEMA_URI, "artifactId");
+        artifactId.setTextContent(metadata.artifactId);
+        root.appendChild(artifactId);
+        final Element version = pom.createElementNS(MAVEN_SCHEMA_URI, "version");
+        version.setTextContent(metadata.version);
+        root.appendChild(version);
+        final Element packaging = pom.createElementNS(MAVEN_SCHEMA_URI, "packaging");
+        packaging.setTextContent(metadata.packaging);
+        root.appendChild(packaging);
+
+        // Output dependency data.
+        if((metadata.dependencies != null) && !metadata.dependencies.isEmpty()) {
+            final Element dependencies = pom.createElementNS(MAVEN_SCHEMA_URI, "dependencies");
+            root.appendChild(dependencies);
+
+            final Map<String, MavenMetadata> dependencyIndex = new HashMap<String, MavenMetadata>();
+            for(final MavenMetadata dependencyMetadata : metadata.dependencies) {
+                final Element dependency = pom.createElementNS(MAVEN_SCHEMA_URI, "dependency");
+                dependencies.appendChild(dependency);
+
+                final Element dependencyGroupId = pom.createElementNS(MAVEN_SCHEMA_URI, "groupId");
+                dependencyGroupId.setTextContent(dependencyMetadata.groupId);
+                dependency.appendChild(dependencyGroupId);
+                final Element dependencyArtifactId = pom.createElementNS(MAVEN_SCHEMA_URI, "artifactId");
+                dependencyArtifactId.setTextContent(dependencyMetadata.artifactId);
+                dependency.appendChild(dependencyArtifactId);
+                final Element dependencyVersion = pom.createElementNS(MAVEN_SCHEMA_URI, "version");
+                dependencyVersion.setTextContent(dependencyMetadata.version);
+                dependency.appendChild(dependencyVersion);
+                final Element dependencyPackaging = pom.createElementNS(MAVEN_SCHEMA_URI, "type");
+                dependencyPackaging.setTextContent(dependencyMetadata.packaging);
+                dependency.appendChild(dependencyPackaging);
+                if(dependencyMetadata.classifier != null) {
+                    final Element dependencyClassifier = pom.createElementNS(MAVEN_SCHEMA_URI, "classifier");
+                    dependencyClassifier.setTextContent(dependencyMetadata.classifier);
+                    dependency.appendChild(dependencyClassifier);
+                }
+
+                dependencyIndex.put(dependencyMetadata.artifactId, dependencyMetadata);
+            }
+
+            // Output the rb.swc dependencies.
+            if(metadata.librariesWithResourceBundles != null) {
+                for(final String artifactWithResourceBundle : metadata.librariesWithResourceBundles) {
+                    final MavenMetadata dependencyMetadata = dependencyIndex.get(artifactWithResourceBundle);
+                    if(dependencyMetadata != null) {
+                        final Element dependency = pom.createElementNS(MAVEN_SCHEMA_URI, "dependency");
+                        dependencies.appendChild(dependency);
+
+                        final Element dependencyGroupId = pom.createElementNS(MAVEN_SCHEMA_URI, "groupId");
+                        dependencyGroupId.setTextContent(dependencyMetadata.groupId);
+                        dependency.appendChild(dependencyGroupId);
+                        final Element dependencyArtifactId = pom.createElementNS(MAVEN_SCHEMA_URI, "artifactId");
+                        dependencyArtifactId.setTextContent(dependencyMetadata.artifactId);
+                        dependency.appendChild(dependencyArtifactId);
+                        final Element dependencyVersion = pom.createElementNS(MAVEN_SCHEMA_URI, "version");
+                        dependencyVersion.setTextContent(dependencyMetadata.version);
+                        dependency.appendChild(dependencyVersion);
+                        final Element dependencyPackaging = pom.createElementNS(MAVEN_SCHEMA_URI, "type");
+                        dependencyPackaging.setTextContent("rb.swc");
+                        dependency.appendChild(dependencyPackaging);
+                    }
+                }
+            }
+        }
+
+        return pom;
+    }
+
+    protected Document createPomDocumentDependencyManagement(final MavenMetadata metadata) throws Exception {
+        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        factory.setNamespaceAware(true);
+        final DocumentBuilder builder = factory.newDocumentBuilder();
+        DOMImplementation domImpl = builder.getDOMImplementation();
+        final Document pom = domImpl.createDocument(MAVEN_SCHEMA_URI, "project", null);
+
+        final Element root = pom.getDocumentElement();
+        final Element modelVersion = pom.createElementNS(MAVEN_SCHEMA_URI, "modelVersion");
+        modelVersion.setTextContent("4.0.0");
+        root.appendChild(modelVersion);
+        final Element groupId = pom.createElementNS(MAVEN_SCHEMA_URI, "groupId");
+        groupId.setTextContent(metadata.groupId);
+        root.appendChild(groupId);
+        final Element artifactId = pom.createElementNS(MAVEN_SCHEMA_URI, "artifactId");
+        artifactId.setTextContent(metadata.artifactId);
+        root.appendChild(artifactId);
+        final Element version = pom.createElementNS(MAVEN_SCHEMA_URI, "version");
+        version.setTextContent(metadata.version);
+        root.appendChild(version);
+        final Element packaging = pom.createElementNS(MAVEN_SCHEMA_URI, "packaging");
+        packaging.setTextContent(metadata.packaging);
+        root.appendChild(packaging);
+
+        // Output dependency data.
+        if((metadata.dependencies != null) && !metadata.dependencies.isEmpty()) {
+            final Element dependencyManagement = pom.createElementNS(MAVEN_SCHEMA_URI, "dependencyManagement");
+            root.appendChild(dependencyManagement);
+            final Element dependencies = pom.createElementNS(MAVEN_SCHEMA_URI, "dependencies");
+            dependencyManagement.appendChild(dependencies);
+
+            final Map<String, MavenMetadata> dependencyIndex = new HashMap<String, MavenMetadata>();
+            for(final MavenMetadata dependencyMetadata : metadata.dependencies) {
+                final Element dependency = pom.createElementNS(MAVEN_SCHEMA_URI, "dependency");
+                dependencies.appendChild(dependency);
+
+                final Element dependencyGroupId = pom.createElementNS(MAVEN_SCHEMA_URI, "groupId");
+                dependencyGroupId.setTextContent(dependencyMetadata.groupId);
+                dependency.appendChild(dependencyGroupId);
+                final Element dependencyArtifactId = pom.createElementNS(MAVEN_SCHEMA_URI, "artifactId");
+                dependencyArtifactId.setTextContent(dependencyMetadata.artifactId);
+                dependency.appendChild(dependencyArtifactId);
+                final Element dependencyVersion = pom.createElementNS(MAVEN_SCHEMA_URI, "version");
+                dependencyVersion.setTextContent(dependencyMetadata.version);
+                dependency.appendChild(dependencyVersion);
+                final Element dependencyPackaging = pom.createElementNS(MAVEN_SCHEMA_URI, "type");
+                dependencyPackaging.setTextContent(dependencyMetadata.packaging);
+                dependency.appendChild(dependencyPackaging);
+                if(dependencyMetadata.classifier != null) {
+                    final Element dependencyClassifier = pom.createElementNS(MAVEN_SCHEMA_URI, "classifier");
+                    dependencyClassifier.setTextContent(dependencyMetadata.classifier);
+                    dependency.appendChild(dependencyClassifier);
+                }
+
+                dependencyIndex.put(dependencyMetadata.artifactId, dependencyMetadata);
+            }
+
+            // Output the rb.swc dependencies.
+            for(final String artifactWithResourceBundle : metadata.librariesWithResourceBundles) {
+                final MavenMetadata dependencyMetadata = dependencyIndex.get(artifactWithResourceBundle);
+                if(dependencyMetadata != null) {
+                    final Element dependency = pom.createElementNS(MAVEN_SCHEMA_URI, "dependency");
+                    dependencies.appendChild(dependency);
+
+                    final Element dependencyGroupId = pom.createElementNS(MAVEN_SCHEMA_URI, "groupId");
+                    dependencyGroupId.setTextContent(dependencyMetadata.groupId);
+                    dependency.appendChild(dependencyGroupId);
+                    final Element dependencyArtifactId = pom.createElementNS(MAVEN_SCHEMA_URI, "artifactId");
+                    dependencyArtifactId.setTextContent(dependencyMetadata.artifactId);
+                    dependency.appendChild(dependencyArtifactId);
+                    final Element dependencyVersion = pom.createElementNS(MAVEN_SCHEMA_URI, "version");
+                    dependencyVersion.setTextContent(dependencyMetadata.version);
+                    dependency.appendChild(dependencyVersion);
+                    final Element dependencyPackaging = pom.createElementNS(MAVEN_SCHEMA_URI, "type");
+                    dependencyPackaging.setTextContent("rb.swc");
+                    dependency.appendChild(dependencyPackaging);
+                }
+            }
+        }
+
+        return pom;
+    }
+
+    protected static File findDirectory(File directory, String directoryToFind) {
+        File[] entries = directory.listFiles();
+        File founded = null;
+
+        // Go over entries
+        for (File entry : entries) {
+            if (entry.isDirectory() && directoryToFind.equalsIgnoreCase(entry.getName())) {
+                founded = entry;
+                break;
+            }
+            if (entry.isDirectory()) {
+                founded = findDirectory(entry, directoryToFind);
+                if (founded != null)
+                    break;
+            }
+        }
+        return founded;
+    }
+}

Propchange: incubator/flex/utilities/trunk/mavenizer/src/main/java/common/BaseGenerator.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/flex/utilities/trunk/mavenizer/src/main/java/common/MavenMetadata.java
URL: http://svn.apache.org/viewvc/incubator/flex/utilities/trunk/mavenizer/src/main/java/common/MavenMetadata.java?rev=1407406&view=auto
==============================================================================
--- incubator/flex/utilities/trunk/mavenizer/src/main/java/common/MavenMetadata.java (added)
+++ incubator/flex/utilities/trunk/mavenizer/src/main/java/common/MavenMetadata.java Fri Nov  9 09:59:42 2012
@@ -0,0 +1,75 @@
+package common;
+
+import java.util.List;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: cdutz
+ * Date: 01.07.12
+ * Time: 12:31
+ */
+public class MavenMetadata {
+    protected String groupId;
+    protected String artifactId;
+    protected String version;
+    protected String packaging;
+    protected String classifier;
+    protected List<String> librariesWithResourceBundles;
+    protected List<MavenMetadata> dependencies;
+
+    public String getGroupId() {
+        return groupId;
+    }
+
+    public void setGroupId(String groupId) {
+        this.groupId = groupId;
+    }
+
+    public String getArtifactId() {
+        return artifactId;
+    }
+
+    public void setArtifactId(String artifactId) {
+        this.artifactId = artifactId;
+    }
+
+    public String getVersion() {
+        return version;
+    }
+
+    public void setVersion(String version) {
+        this.version = version;
+    }
+
+    public String getPackaging() {
+        return packaging;
+    }
+
+    public void setPackaging(String packaging) {
+        this.packaging = packaging;
+    }
+
+    public String getClassifier() {
+        return classifier;
+    }
+
+    public void setClassifier(String classifier) {
+        this.classifier = classifier;
+    }
+
+    public List<String> getLibrariesWithResourceBundles() {
+        return librariesWithResourceBundles;
+    }
+
+    public void setLibrariesWithResourceBundles(List<String> librariesWithResourceBundles) {
+        this.librariesWithResourceBundles = librariesWithResourceBundles;
+    }
+
+    public List<MavenMetadata> getDependencies() {
+        return dependencies;
+    }
+
+    public void setDependencies(List<MavenMetadata> dependencies) {
+        this.dependencies = dependencies;
+    }
+}

Propchange: incubator/flex/utilities/trunk/mavenizer/src/main/java/common/MavenMetadata.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/flex/utilities/trunk/mavenizer/src/main/java/flex/FlexCompilerGenerator.java
URL: http://svn.apache.org/viewvc/incubator/flex/utilities/trunk/mavenizer/src/main/java/flex/FlexCompilerGenerator.java?rev=1407406&view=auto
==============================================================================
--- incubator/flex/utilities/trunk/mavenizer/src/main/java/flex/FlexCompilerGenerator.java (added)
+++ incubator/flex/utilities/trunk/mavenizer/src/main/java/flex/FlexCompilerGenerator.java Fri Nov  9 09:59:42 2012
@@ -0,0 +1,222 @@
+package flex;
+
+import java.io.*;
+import java.util.*;
+import java.util.zip.*;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import common.BaseGenerator;
+import common.MavenMetadata;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: cdutz
+ * Date: 11.05.12
+ * Time: 14:53
+ */
+public class FlexCompilerGenerator extends BaseGenerator {
+
+    public void process(final File sdkSourceDirectory, final boolean isApache, final File sdkTargetDirectory, final String sdkVersion)
+            throws Exception {
+
+        final File sdkCompilerLibsDirectory = new File(sdkSourceDirectory, "lib");
+        final List<File> jars = new ArrayList<File>();
+        jars.addAll(Arrays.asList(sdkCompilerLibsDirectory.listFiles(new FilenameFilter() {
+            public boolean accept(File dir, String name) {
+                return name.endsWith(".jar");
+            }
+        })));
+
+        // The Apache SDKs have an additional "external" directory
+        // containing external libs. These have to be added too.
+        final File externalLibsDirectory = new File(sdkCompilerLibsDirectory, "external");
+        if(externalLibsDirectory.exists() && externalLibsDirectory.isDirectory()) {
+            final File[] externalJars = externalLibsDirectory.listFiles(new FilenameFilter() {
+                public boolean accept(File dir, String name) {
+                    return name.endsWith(".jar");
+                }
+            });
+            jars.addAll(Arrays.asList(externalJars));
+        }
+
+        // The Apache SDKs have an additional "optional" directory
+        // containing external libs. These have to be added too.
+        final File optionalLibsDirectory = new File(externalLibsDirectory, "optional");
+        if (optionalLibsDirectory.exists() && optionalLibsDirectory.isDirectory()) {
+            final File[] optionalJars = optionalLibsDirectory.listFiles(new FilenameFilter() {
+                public boolean accept(File dir, String name) {
+                    return name.endsWith(".jar");
+                }
+            });
+            jars.addAll(Arrays.asList(optionalJars));
+        }
+
+        // A pom artifact will be generated that has all libs as a dependency.
+        final MavenMetadata metadata = new MavenMetadata();
+        metadata.setGroupId((isApache) ? "org.apache.flex" : "com.adobe.flex");
+        metadata.setArtifactId("compiler");
+        metadata.setVersion(sdkVersion);
+        metadata.setPackaging("pom");
+
+        // Create an empty pom document.
+        final Document pom = createPomDocument(metadata);
+
+        // Get the root element, as we will be adding the dependencies to that.
+        final Element root = pom.getDocumentElement();
+        // Add a "dependencies" element.
+        final Element dependencies = pom.createElementNS(BaseGenerator.MAVEN_SCHEMA_URI, "dependencies");
+        root.appendChild(dependencies);
+
+        // Generate artifacts for every jar in the input directories.
+        for(final File sourceJarFile : jars) {
+            // Calculate a checksum for the current file. We will use this checksum to query maven central
+            // in order to find out if this lib has already been published. If it has, there is no need to
+            // publish it again under a new name. In case a matching artifact is found the generated FDK
+            // will use the already deployed version. Additionally the checksum will be saved and if a
+            // fdk generated after this one uses the same version of a lib, the version of the older fdk is
+            // used also reducing the amount of jars that have to be re-deployed.
+            final String checksum = calculateChecksum(sourceJarFile);
+
+            // Try to get artifact metadata based upon the checksum by looking up the internal cache.
+            MavenMetadata artifactMetadata = BaseGenerator.checksums.get(checksum);
+            // Reusing artifact from other sdk version.
+            if(artifactMetadata != null) {
+                System.out.println("Reusing artifact (" + checksum + ") : " + artifactMetadata.getGroupId() + ":" +
+                        artifactMetadata.getArtifactId() + ":" + artifactMetadata.getVersion());
+                appendArtifact(artifactMetadata, dependencies);
+            }
+            // Id no artifact was found in the local cache, continue processing.
+            else {
+                // Do a lookup in maven central.
+                artifactMetadata = lookupMetadataForChecksum(checksum);
+
+                // The file was available on maven central, so use that version instead of the one coming with the sdk.
+                if(artifactMetadata != null) {
+                    appendArtifact(artifactMetadata, dependencies);
+                }
+                // The file was not available on maven central, so we have to add it manually.
+                else {
+                    // The artifact name is the name of the jar.
+                    final String dependencyArtifactId =
+                            sourceJarFile.getName().substring(0, sourceJarFile.getName().lastIndexOf("."));
+
+                    // Generate a new metadata object
+                    artifactMetadata = new MavenMetadata();
+                    artifactMetadata.setGroupId((isApache) ? "org.apache.flex.compiler" : "com.adobe.flex.compiler");
+                    artifactMetadata.setArtifactId(dependencyArtifactId);
+                    artifactMetadata.setVersion(sdkVersion);
+                    artifactMetadata.setPackaging("jar");
+
+                    // Create the name of the directory that will contain the artifact.
+                    final File targetJarDirectory = new File(sdkTargetDirectory,
+                            ((isApache) ? "org\\apache\\flex\\compiler\\" : "com\\adobe\\flex\\compiler\\") +
+                            artifactMetadata.getArtifactId() + "\\" + artifactMetadata.getVersion());
+                    // Create the directory.
+                    if(targetJarDirectory.mkdirs()) {
+                        // Create the filename of the artifact.
+                        final File targetJarFile = new File(targetJarDirectory, artifactMetadata.getArtifactId() + "-" +
+                                artifactMetadata.getVersion() + "." + artifactMetadata.getPackaging());
+
+                        // Copy the file to it's destination.
+                        copyFile(sourceJarFile, targetJarFile);
+
+                        // Add the dependency to the compiler-poms dependency section.
+                        appendArtifact(artifactMetadata, dependencies);
+                    } else {
+                        throw new RuntimeException("Could not create directory: " + targetJarDirectory.getAbsolutePath());
+                    }
+
+                    // Create the pom document that will reside next to the artifact lib.
+                    final Document artifactPom = createPomDocument(artifactMetadata);
+                    final File artifactPomFile =
+                            new File(targetJarDirectory, dependencyArtifactId + "-" + sdkVersion + ".pom");
+                    writeDocument(artifactPom, artifactPomFile);
+
+                    // The asdoc library needs us to zip up an additional directory and
+                    // deploy that as "asdoc-{version}-template.zip"
+                    if("asdoc".equals(dependencyArtifactId)) {
+                        final File asdocTemplatesDirectory = new File(sdkSourceDirectory, "asdoc/templates");
+                        if(asdocTemplatesDirectory.exists()) {
+                            createAsdocTemplatesZip(asdocTemplatesDirectory, targetJarDirectory, sdkVersion);
+                        }
+                    }
+                }
+
+                // Remember the checksum for later re-usage.
+                BaseGenerator.checksums.put(checksum, artifactMetadata);
+            }
+        }
+
+        // Add a reference to the versions pom of the framework. This is needed so the compiler can check which
+        // versions of the framework libs belong to the current compiler version. This is especially needed to
+        // perform the check if the correct version of framework.swc is included in the dependencies. This step
+        // was needed due to the re-deployment of patched FDKs in 2011/2012 in which the framework.swc no longer
+        // has the same version as the compiler.
+        final MavenMetadata frameworkVersions = new MavenMetadata();
+        frameworkVersions.setGroupId((isApache) ? "org.apache.flex" : "com.adobe.flex");
+        frameworkVersions.setArtifactId("framework");
+        frameworkVersions.setVersion(sdkVersion);
+        frameworkVersions.setPackaging("pom");
+        appendArtifact(frameworkVersions, dependencies);
+
+        // Write the compiler-pom document to file.
+        final File pomFile = new File(sdkTargetDirectory,
+                ((isApache) ? "org\\apache\\flex\\compiler\\" : "com\\adobe\\flex\\compiler\\") + sdkVersion + "\\compiler-" + sdkVersion + ".pom");
+        writeDocument(pom, pomFile);
+    }
+
+    /**
+     * Zips up the stuff in the asdoc templates directory.
+     *
+     * @param asdocTemplatesDirectory asdoc templates directory
+     * @param asdocDestinationDir directory containing the asdoc lib
+     * @param asdocVersion version of the asdoc lib
+     * @throws Exception
+     */
+    private void createAsdocTemplatesZip(File asdocTemplatesDirectory, File asdocDestinationDir, String asdocVersion) throws Exception {
+        // ZIP up every file (not directory) in the framework directory and the entire themes directory.
+        final File sourceFiles[] = asdocTemplatesDirectory.listFiles(new FileFilter() {
+            public boolean accept(File pathname) {
+                return pathname.isFile();
+            }
+        });
+        final File zipInputFiles[] = new File[sourceFiles.length + 1];
+        System.arraycopy(sourceFiles, 0, zipInputFiles, 0, sourceFiles.length);
+        final File imagesDirectory = new File(asdocTemplatesDirectory, "images");
+        zipInputFiles[sourceFiles.length] = imagesDirectory;
+
+        // Add all the content to a zip-file.
+        final File targetFile = new File(asdocDestinationDir,
+                "asdoc-" + asdocVersion + "-template.zip");
+        final ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(targetFile));
+        for(final File file : zipInputFiles) {
+            addFileToZip(zipOutputStream, file, asdocTemplatesDirectory);
+        }
+        zipOutputStream.close();
+    }
+
+    private void addFileToZip(ZipOutputStream zipOutputStream, File inputFile, File rootDirectory) throws Exception {
+        // If this is a directory, add all it's children.
+        if(inputFile.isDirectory()) {
+            final File directoryContent[] = inputFile.listFiles();
+            if(directoryContent != null) {
+                for(final File file : directoryContent) {
+                    addFileToZip(zipOutputStream, file, rootDirectory);
+                }
+            }
+        }
+        // If this is a file, add it to the zips output.
+        else {
+            byte[] buf = new byte[1024];
+            final FileInputStream in = new FileInputStream(inputFile);
+            final String zipPath = inputFile.getAbsolutePath().substring(rootDirectory.getAbsolutePath().length() + 1);
+            zipOutputStream.putNextEntry(new ZipEntry(zipPath));
+            int len;
+            while ((len = in.read(buf)) > 0) {
+                zipOutputStream.write(buf, 0, len);
+            }
+            zipOutputStream.closeEntry();
+            in.close();
+        }
+    }
+}

Propchange: incubator/flex/utilities/trunk/mavenizer/src/main/java/flex/FlexCompilerGenerator.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message