Skip to content
Permalink
Browse files
- Fine tuned the generation of the AIR runtime artifacts
- Implemented the code to package a "misc" AIR package which conatains "all the rest" needed to produce a valid FDK containing AIR
  • Loading branch information
chrisdutz committed Jul 25, 2016
1 parent fe47eab commit e5c3d36e0734829111f6dd97402f24a454a70e00
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 36 deletions.
@@ -22,9 +22,7 @@
import org.apache.flex.utilities.converter.model.MavenArtifact;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;
import java.util.zip.ZipOutputStream;

/**
@@ -63,6 +61,7 @@ protected void processDirectory() throws ConverterException {
generateRuntimeArtifacts();
generateFrameworkArtifacts();
generateTemplatesArtifact();
generateMiscArtifact();
}

/**
@@ -154,7 +153,7 @@ private void generateRuntimeArtifacts() throws ConverterException {
adl.setArtifactId("adl");
adl.setVersion(airSdkVersion);
// We'll use pom packaging as we don't have a default artifact to download.
adl.setPackaging("exe");
adl.setPackaging("pom");
final File directory = new File(rootSourceDirectory, "bin");
if (!directory.exists() || !directory.isDirectory()) {
throw new ConverterException("Runtime directory does not exist.");
@@ -174,10 +173,12 @@ private void generateRuntimeArtifacts() throws ConverterException {
runtime.addDependency(adl);
writeArtifact(adl);

// Zip up the AIR runtime directory.
final MavenArtifact airRuntimeArtifact = generateAirRuntimeArtifact(rootSourceDirectory);
if (airRuntimeArtifact != null) {
runtime.addDependency(airRuntimeArtifact);
// Add up the AIR runtimes.
final List<MavenArtifact> airRuntimeArtifacts = generateAirRuntimeArtifacts(rootSourceDirectory);
if (airRuntimeArtifacts != null) {
for (MavenArtifact airRuntimeArtifact : airRuntimeArtifacts) {
runtime.addDependency(airRuntimeArtifact);
}
}

// Write this artifact to file.
@@ -247,6 +248,31 @@ public boolean accept(File pathname) {
writeArtifact(templates);
}

/**
* The misc artifact contains all the other stuff that the installer used to copy
* but that don't have an immediate effect on the maven build.
* @throws ConverterException something went wrong
*/
private void generateMiscArtifact() throws ConverterException {
// Create the root artifact.
final MavenArtifact misc = new MavenArtifact();
misc.setGroupId("com.adobe.air");
misc.setArtifactId("misc");
misc.setVersion(airSdkVersion);
misc.setPackaging("zip");

Collection<File> content = listAllFiles(rootSourceDirectory, new AirMiscFilter(rootSourceDirectory));
try {
final File zip = File.createTempFile("air-misc-" + airSdkVersion, "jar");
generateZip(rootSourceDirectory, content.toArray(new File[0]), zip);
misc.addDefaultBinaryArtifact(zip);
} catch (IOException e) {
throw new ConverterException("Error creating misc zip.", e);
}

writeArtifact(misc);
}

///////////////////////////////////////////////////////////////////////////////////////////////////
//
// Utility methods
@@ -270,35 +296,45 @@ private void generateCompilerPlatformArtifact(File inputDir, File outputFile) th
}
}

private MavenArtifact generateAirRuntimeArtifact(File rootDirectory) throws ConverterException {
final MavenArtifact airRuntimeArtifact = new MavenArtifact();
airRuntimeArtifact.setGroupId("com.adobe.air.runtime");
airRuntimeArtifact.setArtifactId("air-runtime");
airRuntimeArtifact.setVersion(airSdkVersion);
airRuntimeArtifact.setPackaging("zip");

final File runtimeRoot = new File(rootDirectory, "runtimes.air".replace(".", File.separator));
final File[] platforms = runtimeRoot.listFiles();
if (platforms != null) {
for (final File platform : platforms) {
if (!platform.isDirectory()) {
continue;
}
final String platformName = platform.getName();
try {
final File zip = File.createTempFile("AirRuntime-" + platformName + "-" + airSdkVersion, "zip");
generateZip(platform.listFiles(), zip);
airRuntimeArtifact.addBinaryArtifact(platformName, zip);
} catch (IOException e) {
throw new ConverterException("Error creating runtime zip.", e);
private List<MavenArtifact> generateAirRuntimeArtifacts(File rootDirectory) throws ConverterException {
List<MavenArtifact> airRuntimeArtifacts = new LinkedList<MavenArtifact>();

final File runtimeRoot = new File(rootDirectory, "runtimes");
final File[] runtimes = runtimeRoot.listFiles();
if(runtimes != null) {
for(File runtime : runtimes) {
final MavenArtifact airRuntimeArtifact = new MavenArtifact();
airRuntimeArtifact.setGroupId("com.adobe.air.runtime");
airRuntimeArtifact.setArtifactId(runtime.getName());
airRuntimeArtifact.setVersion(airSdkVersion);
// We'll use pom packaging as we don't have a default artifact to download.
airRuntimeArtifact.setPackaging("pom");

final File[] platforms = runtime.listFiles();
if (platforms != null) {
for (final File platform : platforms) {
if (!platform.isDirectory()) {
continue;
}
final String platformName = platform.getName();
try {
final File zip = File.createTempFile("AirRuntime-" + platformName + "-" + airSdkVersion, "zip");
generateZip(platform.listFiles(), zip);
airRuntimeArtifact.addBinaryArtifact(platformName, zip);
} catch (IOException e) {
throw new ConverterException("Error creating runtime zip.", e);
}
}
} else {
return null;
}

writeArtifact(airRuntimeArtifact);
airRuntimeArtifacts.add(airRuntimeArtifact);
}
} else {
return null;
}

writeArtifact(airRuntimeArtifact);
return airRuntimeArtifact;
return airRuntimeArtifacts;
}

/**
@@ -362,6 +398,41 @@ public boolean accept(File dir, String name) {
}
}

private static class AirMiscFilter implements FileFilter {

private File rootSourceDirectory;

AirMiscFilter(File rootSourceDirectory) {
this.rootSourceDirectory = rootSourceDirectory;
}

public boolean accept(File pathname) {
// frameworks/libs/air/ (All non swf & swc)
// frameworks/projects/air/
// include/
// install/android/
// samples/

String relativePath = pathname.getAbsolutePath().substring(
rootSourceDirectory.getAbsolutePath().length());

boolean result = "/AIR SDK license.pdf".equals(relativePath) ||
"/AIR SDK Readme.txt".equals(relativePath) ||
"/airsdk.xml".equals(relativePath) ||
relativePath.startsWith("/frameworks/projects/air/") ||
relativePath.startsWith("/include/") ||
relativePath.startsWith("/install/") ||
relativePath.startsWith("/samples/");

if(relativePath.startsWith("/frameworks/libs/air/")) {
result = !(pathname.getName().endsWith(".swc") || pathname.getName().endsWith(".swf"));
}

System.out.println(relativePath + " = " + result);
return result;
}
}

public static void main(String[] args) throws Exception {
AirConverter converter = new AirConverter(new File(args[0]), new File(args[1]));
converter.convert();
@@ -41,9 +41,7 @@
import java.nio.channels.ReadableByteChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

@@ -372,6 +370,13 @@ protected void generateZip(File[] sourceFiles, File targetFile) throws Converter
return;
}
final File rootDir = sourceFiles[0].getParentFile();
generateZip(rootDir, sourceFiles, targetFile);
}

protected void generateZip(File rootDir, File[] sourceFiles, File targetFile) throws ConverterException {
if((sourceFiles == null) || (sourceFiles.length == 0)) {
return;
}
final File zipInputFiles[] = new File[sourceFiles.length];
System.arraycopy(sourceFiles, 0, zipInputFiles, 0, sourceFiles.length);

@@ -459,4 +464,21 @@ protected String getFlexVersion(File rootDirectory) throws ConverterException {
}
}

protected Collection<File> listAllFiles(File source, FileFilter filter) {
if(filter.accept(source)) {
return Collections.singleton(source);
}
else if(source.isDirectory()) {
File[] dirContent = source.listFiles();
if(dirContent != null) {
Collection<File> filteredContent = new LinkedList<File>();
for(File child : dirContent) {
filteredContent.addAll(listAllFiles(child, filter));
}
return filteredContent;
}
}
return Collections.emptyList();
}

}

0 comments on commit e5c3d36

Please sign in to comment.