You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cd...@apache.org on 2014/05/11 20:14:59 UTC
[2/2] git commit: [flex-utilities] [refs/heads/mavenizer-refactoring]
- FLEX-34318 - [Mavenizer] Refactor the Mavenizer in preparation of future
mavenized releases of Flex - Split up the Mavenizer Logic into 3 parts:
AirConverter, FlashConverter and Flex
FLEX-34318 - [Mavenizer] Refactor the Mavenizer in preparation of future mavenized releases of Flex
- Split up the Mavenizer Logic into 3 parts: AirConverter, FlashConverter and FlexConverter
- Each converter is located in a dedicated Maven module while shared logic is located in a base-converter module.
- Code generation code has been dramatically cleaned up.
- The Flex modules no longer reference runtime artifacts
- The Flash converter generates an Apache dummy module for each Flashplayer version.
- Removed the Dependency-Version poms and included the dependencyManagement into the pom artifacts.
- Attached the resource-bundle dependencies to the swc artifacts directly instead of referencing both from a pom-artifact.
Project: http://git-wip-us.apache.org/repos/asf/flex-utilities/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-utilities/commit/5fc9d25c
Tree: http://git-wip-us.apache.org/repos/asf/flex-utilities/tree/5fc9d25c
Diff: http://git-wip-us.apache.org/repos/asf/flex-utilities/diff/5fc9d25c
Branch: refs/heads/mavenizer-refactoring
Commit: 5fc9d25cbf8b315c574710919f8f23493d1362ce
Parents: c11e18a
Author: Christofer Dutz <ch...@c-ware.de>
Authored: Sun May 11 20:10:37 2014 +0200
Committer: Christofer Dutz <ch...@c-ware.de>
Committed: Sun May 11 20:10:37 2014 +0200
----------------------------------------------------------------------
mavenizer/converters/air/pom.xml | 43 ++
.../utilities/converter/air/AirConverter.java | 210 +++++++
mavenizer/converters/base/pom.xml | 35 ++
.../flex/utilities/converter/BaseConverter.java | 486 +++++++++++++++
.../flex/utilities/converter/Converter.java | 14 +
.../exceptions/ConverterException.java | 16 +
.../converter/model/MavenArtifact.java | 152 +++++
mavenizer/converters/flash/pom.xml | 43 ++
.../converter/flash/FlashConverter.java | 262 ++++++++
mavenizer/converters/flex/pom.xml | 56 ++
.../utilities/converter/flex/FlexConverter.java | 617 +++++++++++++++++++
mavenizer/converters/pom.xml | 45 ++
mavenizer/deployers/aether/pom.xml | 35 ++
mavenizer/deployers/maven/pom.xml | 35 ++
mavenizer/deployers/pom.xml | 40 ++
mavenizer/pom.xml | 6 +
16 files changed, 2095 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/5fc9d25c/mavenizer/converters/air/pom.xml
----------------------------------------------------------------------
diff --git a/mavenizer/converters/air/pom.xml b/mavenizer/converters/air/pom.xml
new file mode 100644
index 0000000..c3021c5
--- /dev/null
+++ b/mavenizer/converters/air/pom.xml
@@ -0,0 +1,43 @@
+<?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>air-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/5fc9d25c/mavenizer/converters/air/src/main/java/org/apache/flex/utilities/converter/air/AirConverter.java
----------------------------------------------------------------------
diff --git a/mavenizer/converters/air/src/main/java/org/apache/flex/utilities/converter/air/AirConverter.java b/mavenizer/converters/air/src/main/java/org/apache/flex/utilities/converter/air/AirConverter.java
new file mode 100644
index 0000000..6212b8b
--- /dev/null
+++ b/mavenizer/converters/air/src/main/java/org/apache/flex/utilities/converter/air/AirConverter.java
@@ -0,0 +1,210 @@
+package org.apache.flex.utilities.converter.air;
+
+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 java.io.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Created by cdutz on 22.04.2014.
+ */
+public class AirConverter extends BaseConverter implements Converter {
+
+ protected String airSdkVersion;
+
+ /**
+ * @param rootSourceDirectory Path to the root of the original AIR SDK.
+ * @param rootTargetDirectory Path to the root of the directory where the Maven artifacts should be generated to.
+ * @throws ConverterException
+ */
+ public AirConverter(File rootSourceDirectory, File rootTargetDirectory) throws ConverterException {
+ super(rootSourceDirectory, rootTargetDirectory);
+
+ // Get the version of the current air sdk.
+ this.airSdkVersion = getAirVersion(rootSourceDirectory);
+ }
+
+ /**
+ * Entry point for generating the Maven artifacts for an AIR SDK.
+ *
+ * @throws ConverterException
+ */
+ @Override
+ protected void processDirectory() throws ConverterException {
+ if(!rootSourceDirectory.exists() || !rootSourceDirectory.isDirectory()) {
+ throw new ConverterException("Air SDK directory '" + rootSourceDirectory.getPath() + "' is invalid.");
+ }
+
+ generateCompilerArtifacts();
+ generateRuntimeArtifacts();
+ generateFrameworkArtifacts();
+ }
+
+ /**
+ * This method generates those artifacts that resemble the compiler part of the AIR SDK.
+ *
+ * @throws ConverterException
+ */
+ protected void generateCompilerArtifacts() throws ConverterException {
+ // Create the root artifact.
+ final MavenArtifact compiler = new MavenArtifact();
+ compiler.setGroupId("com.adobe.air");
+ compiler.setArtifactId("compiler");
+ compiler.setVersion(airSdkVersion);
+ compiler.setPackaging("pom");
+
+ // Create a list of all libs that should belong to the AIR SDK compiler.
+ final File directory = new File(rootSourceDirectory, "lib");
+ if(!directory.exists() || !directory.isDirectory()) {
+ throw new ConverterException("Compiler directory does not exist.");
+ }
+ final List<File> files = new ArrayList<File>();
+ files.addAll(Arrays.asList(directory.listFiles(new AirCompilerFilter())));
+
+ // Generate artifacts for every jar in the input directories.
+ for(final File sourceFile : files) {
+ final MavenArtifact artifact = resolveArtifact(sourceFile, "com.adobe.air.compiler", airSdkVersion);
+ compiler.addDependency(artifact);
+ }
+
+ // Write this artifact to file.
+ writeArtifact(compiler);
+ }
+
+ /**
+ * This method generates those artifacts that resemble the runtime part of the AIR SDK.
+ *
+ * @throws ConverterException
+ */
+ protected void generateRuntimeArtifacts() throws ConverterException {
+ // Create the root artifact.
+ final MavenArtifact runtime = new MavenArtifact();
+ runtime.setGroupId("com.adobe.air");
+ runtime.setArtifactId("runtime");
+ runtime.setVersion(airSdkVersion);
+ runtime.setPackaging("pom");
+
+ // Create a list of all libs that should belong to the AIR SDK runtime.
+ final File directory = new File(rootSourceDirectory, "bin");
+ if(!directory.exists() || !directory.isDirectory()) {
+ throw new ConverterException("Runtime directory does not exist.");
+ }
+ final List<File> files = new ArrayList<File>();
+ files.addAll(Arrays.asList(directory.listFiles(new AirRuntimeFilter())));
+
+ // Generate artifacts for every jar in the input directories.
+ for(final File sourceFile : files) {
+ final MavenArtifact artifact = resolveArtifact(sourceFile, "com.adobe.air.runtime", airSdkVersion);
+ runtime.addDependency(artifact);
+ }
+
+ // Write this artifact to file.
+ writeArtifact(runtime);
+ }
+
+ /**
+ * This method generates those artifacts that resemble the framework part of the AIR SDK.
+ *
+ * @throws ConverterException
+ */
+ protected void generateFrameworkArtifacts() throws ConverterException {
+ // Create the root artifact.
+ final MavenArtifact framework = new MavenArtifact();
+ framework.setGroupId("com.adobe.air");
+ framework.setArtifactId("framework");
+ framework.setVersion(airSdkVersion);
+ framework.setPackaging("pom");
+
+ // Create a list of all libs that should belong to the AIR SDK framework.
+ final File directory =
+ new File(rootSourceDirectory, "frameworks" + File.separator + "libs" + File.separator + "air");
+ if(!directory.exists() || !directory.isDirectory()) {
+ throw new ConverterException("Framework directory does not exist.");
+ }
+ final List<File> files = new ArrayList<File>();
+ files.addAll(Arrays.asList(directory.listFiles(new AirFrameworkFilter())));
+
+ // Generate artifacts for every jar in the input directories.
+ for(final File sourceFile : files) {
+ final MavenArtifact artifact = resolveArtifact(sourceFile, "com.adobe.air.framework", airSdkVersion);
+ framework.addDependency(artifact);
+ }
+
+ // Write this artifact to file.
+ writeArtifact(framework);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////
+ //
+ // Utility methods
+ //
+ ///////////////////////////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Get the version of an AIR SDK from the content of the SDK directory.
+ *
+ * @return version string for the current AIR SDK
+ */
+ protected String getAirVersion(File rootDirectory) throws ConverterException {
+ // All AIR SDKs contain a text file "AIR SDK Readme.txt" which contains a
+ // Version string in the first line. Newer SDKs contain an additional "airsdk.xml"
+ // which would be easier to parse, but as all SDKs contain the text-file, we'll
+ // stick to that for now.
+
+ final File sdkDescriptor = new File(rootDirectory, "AIR SDK Readme.txt");
+ if(!sdkDescriptor.exists() || !sdkDescriptor.isFile()) {
+ throw new ConverterException("Air SDK directory '" + rootDirectory.getPath() +
+ "' is missing a the version text-file 'AIR SDK Readme.txt'.");
+ }
+
+ DataInputStream in = null;
+ try {
+ final FileInputStream descriptorInputStream = new FileInputStream(sdkDescriptor);
+ in = new DataInputStream(descriptorInputStream);
+ 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) {
+ throw new ConverterException("Error getting AIR version.", e);
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException ioe) {
+ // Ignore.
+ }
+ }
+ }
+ }
+
+ public static class AirCompilerFilter implements FilenameFilter {
+ public boolean accept(File dir, String name) {
+ return name.equals("adt.jar");
+ }
+ }
+
+ public static class AirRuntimeFilter implements FilenameFilter {
+ public boolean accept(File dir, String name) {
+ return name.equalsIgnoreCase("adl.exe");
+ }
+ }
+
+ public static class AirFrameworkFilter implements FilenameFilter {
+ public boolean accept(File dir, String name) {
+ return name.equals("aircore.swc") || name.equals("airglobal.swc") ||
+ name.equals("applicationupdater.swc") || name.equals("applicationupdater_ui.swc") ||
+ name.equals("servicemonitor.swc");
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ AirConverter converter = new AirConverter(new File(args[0]), new File(args[1]));
+ converter.convert();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/5fc9d25c/mavenizer/converters/base/pom.xml
----------------------------------------------------------------------
diff --git a/mavenizer/converters/base/pom.xml b/mavenizer/converters/base/pom.xml
new file mode 100644
index 0000000..e058961
--- /dev/null
+++ b/mavenizer/converters/base/pom.xml
@@ -0,0 +1,35 @@
+<?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>base-converter</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+</project>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/5fc9d25c/mavenizer/converters/base/src/main/java/org/apache/flex/utilities/converter/BaseConverter.java
----------------------------------------------------------------------
diff --git a/mavenizer/converters/base/src/main/java/org/apache/flex/utilities/converter/BaseConverter.java b/mavenizer/converters/base/src/main/java/org/apache/flex/utilities/converter/BaseConverter.java
new file mode 100644
index 0000000..8a62f25
--- /dev/null
+++ b/mavenizer/converters/base/src/main/java/org/apache/flex/utilities/converter/BaseConverter.java
@@ -0,0 +1,486 @@
+/*
+ * 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.
+ */
+package org.apache.flex.utilities.converter;
+
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.WebResource;
+
+import org.apache.flex.utilities.converter.exceptions.ConverterException;
+import org.apache.flex.utilities.converter.model.MavenArtifact;
+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONException;
+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 javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.*;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import java.io.*;
+import java.math.BigInteger;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: cdutz
+ * Date: 11.05.12
+ * Time: 14:53
+ */
+public abstract class BaseConverter {
+
+ protected static final Map<String, MavenArtifact> checksums = new HashMap<String, MavenArtifact>();
+
+ 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"
+
+ protected File rootSourceDirectory;
+ protected File rootTargetDirectory;
+
+ protected BaseConverter(File rootSourceDirectory, File rootTargetDirectory) throws ConverterException {
+ if(rootSourceDirectory == null) {
+ throw new ConverterException("Air SDK directory is null.");
+ }
+ if(rootTargetDirectory == null) {
+ throw new ConverterException("Target directory is null.");
+ }
+
+ this.rootSourceDirectory = rootSourceDirectory;
+ this.rootTargetDirectory = rootTargetDirectory;
+ }
+
+ public void convert() throws ConverterException {
+ if(rootSourceDirectory.isFile()) {
+ processArchive();
+ } else {
+ processDirectory();
+ }
+ }
+
+ abstract protected void processDirectory() throws ConverterException;
+
+ protected void processArchive() throws ConverterException {
+
+ }
+
+ protected String calculateChecksum(File jarFile) throws ConverterException {
+ // Implement the calculation of checksums for a given jar.
+ final MessageDigest digest;
+ try {
+ 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);
+ }
+ }
+ } catch (NoSuchAlgorithmException e) {
+ throw new ConverterException("Error calculating checksum of file '" + jarFile.getPath() + "'", e);
+ } catch (FileNotFoundException e) {
+ throw new ConverterException("Error calculating checksum of file '" + jarFile.getPath() + "'", e);
+ }
+ }
+
+ protected MavenArtifact lookupMetadataForChecksum(String checksum) throws ConverterException {
+ 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();
+ try {
+ 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 MavenArtifact artifactMetadata = new MavenArtifact();
+ artifactMetadata.setGroupId((String) firstHit.get("g"));
+ artifactMetadata.setArtifactId((String) firstHit.get("a"));
+ artifactMetadata.setVersion((String) firstHit.get("v"));
+ artifactMetadata.setPackaging((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 MavenArtifact artifactMetadata = new MavenArtifact();
+ artifactMetadata.setGroupId((String) newestVersion.get("g"));
+ artifactMetadata.setArtifactId((String) newestVersion.get("a"));
+ artifactMetadata.setVersion((String) newestVersion.get("v"));
+ artifactMetadata.setPackaging((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;
+ } catch(IOException e) {
+ throw new ConverterException("Error processing Metadata for checksum: '" + checksum + "'", e);
+ } catch (JSONException e) {
+ throw new ConverterException("Error processing Metadata for checksum: '" + checksum + "'", e);
+ }
+ }
+
+ protected void copyFile(File source, File target) throws ConverterException {
+ try {
+ final File outputDirectory = target.getParentFile();
+ if(!outputDirectory.exists()) {
+ if(!outputDirectory.mkdirs()) {
+ throw new RuntimeException("Could not create directory: " + outputDirectory.getAbsolutePath());
+ }
+ }
+
+ final InputStream in = new FileInputStream(source);
+ final OutputStream out = new FileOutputStream(target);
+
+ final byte[] buf = new byte[1024];
+ int len;
+ while ((len = in.read(buf)) > 0){
+ out.write(buf, 0, len);
+ }
+
+ in.close();
+ out.close();
+ } catch(IOException e) {
+ throw new ConverterException("Error copying file from '" + source.getPath() +
+ "' to '" + target.getPath() + "'", e);
+ }
+ }
+
+ /*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.getGroupId());
+ dependency.appendChild(groupId);
+ final Element artifactId = doc.createElementNS(MAVEN_SCHEMA_URI, "artifactId");
+ artifactId.setTextContent(artifactMetadata.getArtifactId());
+ dependency.appendChild(artifactId);
+ final Element version = doc.createElementNS(MAVEN_SCHEMA_URI, "version");
+ version.setTextContent(artifactMetadata.getVersion());
+ dependency.appendChild(version);
+ if(!artifactMetadata.getPackaging().equals("jar")) {
+ final Element packaging = doc.createElementNS(MAVEN_SCHEMA_URI, "type");
+ packaging.setTextContent(artifactMetadata.getPackaging());
+ dependency.appendChild(packaging);
+ }
+ }*/
+
+ protected void writePomArtifact(MavenArtifact pomData) throws ConverterException {
+ final Document pomDoc = createPomDocument(pomData);
+ final File outputFile = pomData.getPomTargetFile(rootTargetDirectory);
+ writeDocument(pomDoc, outputFile);
+ }
+
+ protected void writeDocument(Document doc, File outputFile) throws ConverterException {
+ 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;
+ try {
+ transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
+ transformer.transform(source, result);
+ } catch (TransformerConfigurationException e) {
+ throw new ConverterException("Error writing xml document.", e);
+ } catch (TransformerException e) {
+ throw new ConverterException("Error writing xml document.", e);
+ }
+ }
+
+ protected Document createPomDocument(final MavenArtifact metadata) throws ConverterException {
+ final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ final DocumentBuilder builder;
+ try {
+ 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.getGroupId());
+ root.appendChild(groupId);
+ final Element artifactId = pom.createElementNS(MAVEN_SCHEMA_URI, "artifactId");
+ artifactId.setTextContent(metadata.getArtifactId());
+ root.appendChild(artifactId);
+ final Element version = pom.createElementNS(MAVEN_SCHEMA_URI, "version");
+ version.setTextContent(metadata.getVersion());
+ root.appendChild(version);
+ final Element packaging = pom.createElementNS(MAVEN_SCHEMA_URI, "packaging");
+ packaging.setTextContent(metadata.getPackaging());
+ root.appendChild(packaging);
+
+ // Output dependency data.
+ if((metadata.getDependencies() != null) && !metadata.getDependencies().isEmpty()) {
+ final Element dependencies = pom.createElementNS(MAVEN_SCHEMA_URI, "dependencies");
+ root.appendChild(dependencies);
+ final Element dependencyManagement = pom.createElementNS(MAVEN_SCHEMA_URI, "dependencyManagement");
+ final Element dependencyManagementDependencies = pom.createElementNS(MAVEN_SCHEMA_URI, "dependencies");
+ dependencyManagement.appendChild(dependencyManagementDependencies);
+ root.appendChild(dependencyManagement);
+
+ final Map<String, MavenArtifact> dependencyIndex = new HashMap<String, MavenArtifact>();
+ for(final MavenArtifact dependencyMetadata : metadata.getDependencies()) {
+ Element dependency = pom.createElementNS(MAVEN_SCHEMA_URI, "dependency");
+ dependencies.appendChild(dependency);
+
+ // Generate the normal dependency.
+ Element dependencyGroupId = pom.createElementNS(MAVEN_SCHEMA_URI, "groupId");
+ dependencyGroupId.setTextContent(dependencyMetadata.getGroupId());
+ dependency.appendChild(dependencyGroupId);
+ Element dependencyArtifactId = pom.createElementNS(MAVEN_SCHEMA_URI, "artifactId");
+ dependencyArtifactId.setTextContent(dependencyMetadata.getArtifactId());
+ dependency.appendChild(dependencyArtifactId);
+ Element dependencyPackaging = pom.createElementNS(MAVEN_SCHEMA_URI, "type");
+ dependencyPackaging.setTextContent(dependencyMetadata.getPackaging());
+ dependency.appendChild(dependencyPackaging);
+ if(dependencyMetadata.getClassifier() != null) {
+ final Element dependencyClassifier = pom.createElementNS(MAVEN_SCHEMA_URI, "classifier");
+ dependencyClassifier.setTextContent(dependencyMetadata.getClassifier());
+ dependency.appendChild(dependencyClassifier);
+ }
+
+ // Configure the dependency including version in the dependency management section of the pom.
+ dependency = pom.createElementNS(MAVEN_SCHEMA_URI, "dependency");
+ dependencyGroupId = pom.createElementNS(MAVEN_SCHEMA_URI, "groupId");
+ dependencyGroupId.setTextContent(dependencyMetadata.getGroupId());
+ dependency.appendChild(dependencyGroupId);
+ dependencyArtifactId = pom.createElementNS(MAVEN_SCHEMA_URI, "artifactId");
+ dependencyArtifactId.setTextContent(dependencyMetadata.getArtifactId());
+ dependency.appendChild(dependencyArtifactId);
+ Element dependencyVersion = pom.createElementNS(MAVEN_SCHEMA_URI, "version");
+ dependencyVersion.setTextContent(dependencyMetadata.getVersion());
+ dependency.appendChild(dependencyVersion);
+ dependencyPackaging = pom.createElementNS(MAVEN_SCHEMA_URI, "type");
+ dependencyPackaging.setTextContent(dependencyMetadata.getPackaging());
+ dependency.appendChild(dependencyPackaging);
+ dependencyManagementDependencies.appendChild(dependency);
+
+ dependencyIndex.put(dependencyMetadata.getArtifactId(), dependencyMetadata);
+ }
+
+ // Output the rb.swc dependencies.
+ if(metadata.getLibrariesWithResourceBundles() != null) {
+ for(final String artifactWithResourceBundle : metadata.getLibrariesWithResourceBundles()) {
+ final MavenArtifact 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.getGroupId());
+ dependency.appendChild(dependencyGroupId);
+ final Element dependencyArtifactId = pom.createElementNS(MAVEN_SCHEMA_URI, "artifactId");
+ dependencyArtifactId.setTextContent(dependencyMetadata.getArtifactId());
+ dependency.appendChild(dependencyArtifactId);
+ final Element dependencyVersion = pom.createElementNS(MAVEN_SCHEMA_URI, "version");
+ dependencyVersion.setTextContent(dependencyMetadata.getVersion());
+ dependency.appendChild(dependencyVersion);
+ final Element dependencyPackaging = pom.createElementNS(MAVEN_SCHEMA_URI, "type");
+ dependencyPackaging.setTextContent("rb.swc");
+ dependency.appendChild(dependencyPackaging);
+ }
+ }
+ }
+ }
+ return pom;
+ } catch (ParserConfigurationException e) {
+ throw new ConverterException("Error creating pom document.", e);
+ }
+ }
+
+ protected void writeDummy(final File targetFile) throws ConverterException {
+ try {
+ final ZipOutputStream out = new ZipOutputStream(new FileOutputStream(targetFile));
+ out.putNextEntry(new ZipEntry("dummy"));
+ out.closeEntry();
+ out.close();
+ } catch (IOException e) {
+ throw new ConverterException("Error generating dummy resouce bundle.");
+ }
+ }
+
+ protected static File findDirectory(File directory, String directoryToFind) {
+ File[] entries = directory.listFiles();
+ File founded = null;
+
+ // Go over entries
+ if(entries != null) {
+ 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;
+ }
+
+ protected MavenArtifact resolveArtifact(File sourceFile, String defaultGroupId, String defaultVersion)
+ throws ConverterException {
+ // 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(sourceFile);
+
+ // Try to get artifact metadata based upon the checksum by looking up the internal cache.
+ MavenArtifact artifact = checksums.get(checksum);
+
+ // Reusing artifact from other sdk version.
+ if(artifact != null) {
+ System.out.println("Reusing artifact (" + checksum + ") : " + artifact.getGroupId() + ":" +
+ artifact.getArtifactId() + ":" + artifact.getVersion());
+ return artifact;
+ }
+ // Id no artifact was found in the local cache, continue processing.
+ else {
+ // Do a lookup in maven central.
+ artifact = lookupMetadataForChecksum(checksum);
+
+ // The file was available on maven central, so use that version instead of the one coming with the sdk.
+ if(artifact != null) {
+ System.out.println("Using artifact from Maven Central (" + checksum + ") : " +
+ artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion());
+ }
+ // 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 artifactFileName = sourceFile.getName();
+ final String dependencyArtifactId = artifactFileName.substring(0, artifactFileName.lastIndexOf("."));
+ final String dependencyArtifactPackaging =
+ artifactFileName.substring(artifactFileName.lastIndexOf(".") + 1);
+
+ // Generate a new metadata object
+ artifact = new MavenArtifact();
+ artifact.setGroupId(defaultGroupId);
+ artifact.setArtifactId(dependencyArtifactId);
+ artifact.setVersion(defaultVersion);
+ artifact.setPackaging(dependencyArtifactPackaging);
+ artifact.addDefaultBinaryArtifact(sourceFile);
+
+ // Create the pom document that will reside next to the artifact lib.
+ writeArtifact(artifact);
+ }
+
+ // Remember the checksum for later re-usage.
+ checksums.put(checksum, artifact);
+
+ return artifact;
+ }
+ }
+
+ protected void writeArtifact(MavenArtifact artifact) throws ConverterException {
+ // Write the pom itself.
+ writePomArtifact(artifact);
+ final List<String> binaryClassifiers = artifact.getBinaryFilesClassifiers();
+ for(final String classifier : binaryClassifiers) {
+ final File binarySourceFile = artifact.getBinarySourceFile(classifier);
+ final File binaryTargetFile = artifact.getBinaryTargetFile(rootTargetDirectory, classifier);
+ copyFile(binarySourceFile, binaryTargetFile);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/5fc9d25c/mavenizer/converters/base/src/main/java/org/apache/flex/utilities/converter/Converter.java
----------------------------------------------------------------------
diff --git a/mavenizer/converters/base/src/main/java/org/apache/flex/utilities/converter/Converter.java b/mavenizer/converters/base/src/main/java/org/apache/flex/utilities/converter/Converter.java
new file mode 100644
index 0000000..0f94155
--- /dev/null
+++ b/mavenizer/converters/base/src/main/java/org/apache/flex/utilities/converter/Converter.java
@@ -0,0 +1,14 @@
+package org.apache.flex.utilities.converter;
+
+import org.apache.flex.utilities.converter.exceptions.ConverterException;
+
+import java.io.File;
+
+/**
+ * Created by cdutz on 18.04.2014.
+ */
+public interface Converter {
+
+ void convert() throws ConverterException;
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/5fc9d25c/mavenizer/converters/base/src/main/java/org/apache/flex/utilities/converter/exceptions/ConverterException.java
----------------------------------------------------------------------
diff --git a/mavenizer/converters/base/src/main/java/org/apache/flex/utilities/converter/exceptions/ConverterException.java b/mavenizer/converters/base/src/main/java/org/apache/flex/utilities/converter/exceptions/ConverterException.java
new file mode 100644
index 0000000..3a0b7c6
--- /dev/null
+++ b/mavenizer/converters/base/src/main/java/org/apache/flex/utilities/converter/exceptions/ConverterException.java
@@ -0,0 +1,16 @@
+package org.apache.flex.utilities.converter.exceptions;
+
+/**
+ * Created by cdutz on 07.05.2014.
+ */
+public class ConverterException extends Exception {
+
+ public ConverterException(String message) {
+ super(message);
+ }
+
+ public ConverterException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/5fc9d25c/mavenizer/converters/base/src/main/java/org/apache/flex/utilities/converter/model/MavenArtifact.java
----------------------------------------------------------------------
diff --git a/mavenizer/converters/base/src/main/java/org/apache/flex/utilities/converter/model/MavenArtifact.java b/mavenizer/converters/base/src/main/java/org/apache/flex/utilities/converter/model/MavenArtifact.java
new file mode 100644
index 0000000..0dca36c
--- /dev/null
+++ b/mavenizer/converters/base/src/main/java/org/apache/flex/utilities/converter/model/MavenArtifact.java
@@ -0,0 +1,152 @@
+/*
+ * 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.
+ */
+package org.apache.flex.utilities.converter.model;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: cdutz
+ * Date: 01.07.12
+ * Time: 12:31
+ */
+public class MavenArtifact {
+
+ public static final String DEFAULT_CLASSIFIER = "default";
+
+ protected String groupId;
+ protected String artifactId;
+ protected String version;
+ protected String packaging = "pom";
+ protected String classifier;
+ protected List<String> librariesWithResourceBundles;
+
+ protected List<MavenArtifact> dependencies;
+
+ protected Map<String, File> binaryArtifacts;
+
+ 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<MavenArtifact> getDependencies() {
+ return dependencies;
+ }
+
+ public void setDependencies(List<MavenArtifact> dependencies) {
+ this.dependencies = dependencies;
+ }
+
+ public void addDependency(MavenArtifact dependency) {
+ if(dependencies == null) {
+ dependencies = new ArrayList<MavenArtifact>();
+ }
+ dependencies.add(dependency);
+ }
+
+ public void addDefaultBinaryArtifact(File binaryArtifact) {
+ addBinaryArtifact(DEFAULT_CLASSIFIER, binaryArtifact);
+ }
+
+ public void addBinaryArtifact(String classifier, File binaryArtifact) {
+ if(binaryArtifacts == null) {
+ binaryArtifacts = new HashMap<String, File>();
+ }
+ binaryArtifacts.put(classifier, binaryArtifact);
+ }
+
+ public File getPomTargetFile(File targetRootDirectory) {
+ final String fileName = groupId.replace(".", File.separator) + File.separator + artifactId + File.separator +
+ version + File.separator + artifactId + "-" + version + ((classifier != null) ? "-" + classifier : "") +
+ ".pom";
+ return new File(targetRootDirectory, fileName);
+ }
+
+ public List<String> getBinaryFilesClassifiers() {
+ final List<String> classifiers = new ArrayList<String>();
+ if(binaryArtifacts != null) {
+ classifiers.addAll(binaryArtifacts.keySet());
+ }
+ return classifiers;
+ }
+
+ public File getBinarySourceFile(String classifier) {
+ if((binaryArtifacts != null) && (binaryArtifacts.containsKey(classifier))) {
+ return binaryArtifacts.get(classifier);
+ }
+ return null;
+ }
+
+ public File getBinaryTargetFile(File targetRootDirectory, String classifier) {
+ if((binaryArtifacts != null) && (binaryArtifacts.containsKey(classifier))) {
+ final String fileName = groupId.replace(".", File.separator) + File.separator + artifactId + File.separator +
+ version + File.separator + artifactId + "-" + version +
+ (DEFAULT_CLASSIFIER.equals(classifier) ? "" : "-" + classifier) + "." + packaging;
+ return new File(targetRootDirectory, fileName);
+ }
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/5fc9d25c/mavenizer/converters/flash/pom.xml
----------------------------------------------------------------------
diff --git a/mavenizer/converters/flash/pom.xml b/mavenizer/converters/flash/pom.xml
new file mode 100644
index 0000000..d231261
--- /dev/null
+++ b/mavenizer/converters/flash/pom.xml
@@ -0,0 +1,43 @@
+<?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>flash-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/5fc9d25c/mavenizer/converters/flash/src/main/java/org/apache/flex/utilities/converter/flash/FlashConverter.java
----------------------------------------------------------------------
diff --git a/mavenizer/converters/flash/src/main/java/org/apache/flex/utilities/converter/flash/FlashConverter.java b/mavenizer/converters/flash/src/main/java/org/apache/flex/utilities/converter/flash/FlashConverter.java
new file mode 100644
index 0000000..6ff5462
--- /dev/null
+++ b/mavenizer/converters/flash/src/main/java/org/apache/flex/utilities/converter/flash/FlashConverter.java
@@ -0,0 +1,262 @@
+package org.apache.flex.utilities.converter.flash;
+
+import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
+import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
+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 java.io.*;
+import java.text.NumberFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * Created by cdutz on 22.04.2014.
+ */
+public class FlashConverter extends BaseConverter implements Converter {
+
+ /**
+ * @param rootSourceDirectory Path to the root of the original Flash SDK.
+ * @param rootTargetDirectory Path to the root of the directory where the Maven artifacts should be generated to.
+ * @throws org.apache.flex.utilities.converter.exceptions.ConverterException
+ */
+ public FlashConverter(File rootSourceDirectory, File rootTargetDirectory) throws ConverterException {
+ super(rootSourceDirectory, rootTargetDirectory);
+ }
+
+ /**
+ * Entry point for generating the Maven artifacts for an Flash SDK.
+ *
+ * @throws ConverterException
+ */
+ @Override
+ protected void processDirectory() throws ConverterException {
+ if(!rootSourceDirectory.exists() || !rootSourceDirectory.isDirectory()) {
+ throw new ConverterException("Flash SDK directory '" + rootSourceDirectory.getPath() + "' is invalid.");
+ }
+
+ generateRuntimeArtifacts();
+ generateFrameworkArtifacts();
+ }
+
+ /**
+ * This method generates those artifacts that resemble the runtime part of the Flash SDK.
+ *
+ * @throws ConverterException
+ */
+ protected void generateRuntimeArtifacts() throws ConverterException {
+ // Create a list of all libs that should belong to the Flash SDK runtime.
+ final File directory = new File(rootSourceDirectory, "runtimes" + File.separator + "player");
+ if(!directory.exists() || !directory.isDirectory()) {
+ throw new ConverterException("Runtime directory does not exist.");
+ }
+ final List<File> playerVersions = new ArrayList<File>();
+ playerVersions.addAll(Arrays.asList(directory.listFiles(new FlashRuntimeFilter())));
+
+ // In really old SDKs the flash-player was installed in the players directory directly.
+ if(new File(directory, "win").exists()) {
+ playerVersions.add(directory);
+ }
+
+ // Generate artifacts for every jar in the input directories.
+ for(final File versionDir : playerVersions) {
+ // The flash-player 9 is installed directly in the player directory.
+ String playerVersionString;
+ if(versionDir == directory) {
+ playerVersionString = "9.0";
+ } else {
+ playerVersionString = 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 MavenArtifact playerArtifact = new MavenArtifact();
+ playerArtifact.setGroupId("com.adobe.flash");
+ playerArtifact.setArtifactId("runtime");
+ playerArtifact.setVersion(version);
+ playerArtifact.setPackaging("exe");
+
+ // 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) {
+ playerArtifact.addBinaryArtifact("win", flashPlayerBinary);
+ }
+ }
+
+ // 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) {
+ playerArtifact.addBinaryArtifact("mac", flashPlayerBinary);
+ }
+ }
+
+ // Deploy Linux binaries.
+ final File lnxDirectory = new File(versionDir, "lnx");
+ if(lnxDirectory.exists()) {
+ // Find out if a flash-player binary exists.
+ File flashPlayerBinary;
+ 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");
+ } else {
+ throw new ConverterException("Couldn't find player archive.");
+ }
+
+ // Decompress the archive.
+ // First unzip it.
+ final FileInputStream fin;
+ try {
+ 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) {
+ playerArtifact.addBinaryArtifact("linux", flashPlayerBinary);
+ }
+ } catch (FileNotFoundException e) {
+ throw new ConverterException("Error processing the linux player tar file", e);
+ } catch (IOException e) {
+ throw new ConverterException("Error processing the linux player tar file", e);
+ }
+ }
+
+ // Write this artifact to file.
+ writeArtifact(playerArtifact);
+ }
+ }
+
+ /**
+ * This method generates those artifacts that resemble the framework part of the Flash SDK.
+ *
+ * @throws ConverterException
+ */
+ protected void generateFrameworkArtifacts() throws ConverterException {
+ // Create a list of all libs that should belong to the Flash SDK runtime.
+ final File directory = new File(rootSourceDirectory, "frameworks.libs.player".replace(".", File.separator));
+ if (!directory.exists() || !directory.isDirectory()) {
+ throw new ConverterException("Runtime directory does not exist.");
+ }
+ final List<File> playerVersions = new ArrayList<File>();
+ final File[] versions = directory.listFiles();
+ if((versions != null) && (versions.length > 0)) {
+ playerVersions.addAll(Arrays.asList(versions));
+
+ // Generate artifacts for every jar in the input directories.
+ for (final File versionDir : playerVersions) {
+ final File playerglobalSwc = new File(versionDir, "playerglobal.swc");
+
+ // Convert any version into a two-segment version number.
+ final double playerVersion = Double.valueOf(versionDir.getName());
+ final NumberFormat doubleFormat = NumberFormat.getInstance(Locale.US);
+ doubleFormat.setMinimumFractionDigits(1);
+ doubleFormat.setMaximumFractionDigits(1);
+ final String version = doubleFormat.format(playerVersion);
+
+ // Create an artifact for the player-global.
+ final MavenArtifact playerglobal = new MavenArtifact();
+ playerglobal.setGroupId("com.adobe.flash.framework");
+ playerglobal.setArtifactId("playerglobal");
+ playerglobal.setVersion(version);
+ playerglobal.setPackaging("swc");
+ playerglobal.addDefaultBinaryArtifact(playerglobalSwc);
+ writeArtifact(playerglobal);
+
+ // Generate dummy pom-artifact which we are allowed to deploy.
+ final MavenArtifact playerglobalDummy = new MavenArtifact();
+ playerglobalDummy.setGroupId("org.apache.flex.runtime");
+ playerglobalDummy.setArtifactId("flashplayer");
+ playerglobalDummy.setVersion(version);
+ writeArtifact(playerglobalDummy);
+ }
+ }
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////
+ //
+ // Utility methods
+ //
+ ///////////////////////////////////////////////////////////////////////////////////////////////////
+
+ public static class FlashRuntimeFilter implements FileFilter {
+ public boolean accept(File pathname) {
+ return pathname.isDirectory() && !"win".equalsIgnoreCase(pathname.getName()) &&
+ !"lnx".equalsIgnoreCase(pathname.getName()) && !"mac".equalsIgnoreCase(pathname.getName());
+ }
+ }
+
+ public static class FlashFrameworkFilter implements FilenameFilter {
+ public boolean accept(File dir, String name) {
+ return name.equals("playerglobal.swc");
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ FlashConverter converter = new FlashConverter(new File(args[0]), new File(args[1]));
+ converter.convert();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/5fc9d25c/mavenizer/converters/flex/pom.xml
----------------------------------------------------------------------
diff --git a/mavenizer/converters/flex/pom.xml b/mavenizer/converters/flex/pom.xml
new file mode 100644
index 0000000..eca8505
--- /dev/null
+++ b/mavenizer/converters/flex/pom.xml
@@ -0,0 +1,56 @@
+<?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>flex-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>
+ <!--
+ Flex usually contains Air and Flash artifacts, so we need to reference them.
+ -->
+ <dependency>
+ <groupId>org.apache.flex.utilities.converter</groupId>
+ <artifactId>air-converter</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.flex.utilities.converter</groupId>
+ <artifactId>flash-converter</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+</project>