Repository: flex-falcon Updated Branches: refs/heads/develop f796ca222 -> 04bc65015
- Introduced a ITestAdapter interface that wraps build-system specific details - Moved the Ant-specific parts into a new AntTestAdapter - Added a new MavenTestAdapter for running unit-tests with Maven. - Changed the MXMLNodeBaseTests to use the AntTestAdapter per default, but to allow overriding this by setting a system-property and hereby switching to the MavenTestAdapter Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/04bc6501 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/04bc6501 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/04bc6501 Branch: refs/heads/develop Commit: 04bc65015703f7d3552c39008e9c2ca7eb7aeb9a Parents: f796ca2 Author: Christofer Dutz <[email protected]> Authored: Wed Feb 24 09:40:36 2016 +0100 Committer: Christofer Dutz <[email protected]> Committed: Wed Feb 24 09:40:36 2016 +0100 ---------------------------------------------------------------------- .../org/apache/flex/utils/AntTestAdapter.java | 46 ++++++++++++++ .../src/org/apache/flex/utils/ITestAdapter.java | 17 ++++++ .../org/apache/flex/utils/MavenTestAdapter.java | 63 ++++++++++++++++++++ .../internal/tree/mxml/MXMLNodeBaseTests.java | 29 ++++----- 4 files changed, 138 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/04bc6501/compiler.tests/src/org/apache/flex/utils/AntTestAdapter.java ---------------------------------------------------------------------- diff --git a/compiler.tests/src/org/apache/flex/utils/AntTestAdapter.java b/compiler.tests/src/org/apache/flex/utils/AntTestAdapter.java new file mode 100644 index 0000000..32c24d5 --- /dev/null +++ b/compiler.tests/src/org/apache/flex/utils/AntTestAdapter.java @@ -0,0 +1,46 @@ +package org.apache.flex.utils; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertNotNull; + +/** + * Created by christoferdutz on 23.02.16. + */ +public class AntTestAdapter implements ITestAdapter { + + private static EnvProperties env = EnvProperties.initiate(); + + @Override + public String getTempDir() { + return FilenameNormalization.normalize("temp"); // ensure this exists + } + + @Override + public List<File> getLibraries(boolean withFlex) { + // Do some checks if all needed environment variables are set. + if (withFlex) { + assertNotNull("Environment variable FLEX_HOME is not set", env.SDK); + } + assertNotNull("Environment variable PLAYERGLOBAL_HOME is not set", env.FPSDK); + + // Create a list of libs needed to compile. + List<File> libraries = new ArrayList<File>(); + libraries.add(new File(FilenameNormalization.normalize(env.FPSDK + "\\" + env.FPVER + "\\playerglobal.swc"))); + if (withFlex) + { + libraries.add(new File(FilenameNormalization.normalize(env.SDK + "\\frameworks\\libs\\framework.swc"))); + libraries.add(new File(FilenameNormalization.normalize(env.SDK + "\\frameworks\\libs\\rpc.swc"))); + libraries.add(new File(FilenameNormalization.normalize(env.SDK + "\\frameworks\\libs\\spark.swc"))); + } + return libraries; + } + + @Override + public String getManifestPath() { + return env.SDK + "\\frameworks\\mxml-2009-manifest.xml"; + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/04bc6501/compiler.tests/src/org/apache/flex/utils/ITestAdapter.java ---------------------------------------------------------------------- diff --git a/compiler.tests/src/org/apache/flex/utils/ITestAdapter.java b/compiler.tests/src/org/apache/flex/utils/ITestAdapter.java new file mode 100644 index 0000000..460ce16 --- /dev/null +++ b/compiler.tests/src/org/apache/flex/utils/ITestAdapter.java @@ -0,0 +1,17 @@ +package org.apache.flex.utils; + +import java.io.File; +import java.util.List; + +/** + * Created by christoferdutz on 23.02.16. + */ +public interface ITestAdapter { + + String getTempDir(); + + List<File> getLibraries(boolean withFlex); + + String getManifestPath(); + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/04bc6501/compiler.tests/src/org/apache/flex/utils/MavenTestAdapter.java ---------------------------------------------------------------------- diff --git a/compiler.tests/src/org/apache/flex/utils/MavenTestAdapter.java b/compiler.tests/src/org/apache/flex/utils/MavenTestAdapter.java new file mode 100644 index 0000000..403ee67 --- /dev/null +++ b/compiler.tests/src/org/apache/flex/utils/MavenTestAdapter.java @@ -0,0 +1,63 @@ +package org.apache.flex.utils; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by christoferdutz on 23.02.16. + */ +public class MavenTestAdapter implements ITestAdapter { + + @Override + public String getTempDir() { + File tempDir = new File("target/surefire-temp"); + if(!tempDir.exists()) { + if(!tempDir.mkdirs()) { + throw new RuntimeException("Could not create temp dir at: " + tempDir.getAbsolutePath()); + } + } + return tempDir.getPath(); + } + + @Override + public List<File> getLibraries(boolean withFlex) { + List<File> libs = new ArrayList<File>(); + libs.add(getDependency("com.adobe.flash.framework", "playerglobal", + System.getProperty("flashVersion"), "swc", null)); + if(withFlex) { + String flexVersion = System.getProperty("flexVersion"); + libs.add(getDependency("org.apache.flex.framework", "framework", flexVersion, "swc", null)); + libs.add(getDependency("org.apache.flex.framework", "rpc", flexVersion, "swc", null)); + libs.add(getDependency("org.apache.flex.framework", "spark", flexVersion, "swc", null)); + } + return libs; + } + + @Override + public String getManifestPath() { + File configsZip = getDependency("org.apache.flex.framework", "framework", + System.getProperty("flexVersion"), "zip", "configs"); + File frameworkDir = configsZip.getParentFile(); + File unpackedConfigsDir = new File(frameworkDir, "configs_zip"); + // If the directory doesn't exist, we have to create it by unpacking the zip archive. + // This is identical behaviour to Flexmojos, which does the same thing. + if(!unpackedConfigsDir.exists()) { + // TODO: Implement + } + return new File(unpackedConfigsDir, "mxml-2009-manifest.xml").getPath(); + } + + private File getDependency(String groupId, String artifactId, String version, String type, String classifier) { + String dependencyPath = System.getProperty("mavenLocalRepoDir") + "/" + groupId.replaceAll("\\.", "/") + "/" + + artifactId + "/" + version + "/" + artifactId + "-" + version + + ((classifier != null) ? "-" + classifier : "") + "." + type; + dependencyPath = FilenameNormalization.normalize(dependencyPath); + File dependency = new File(dependencyPath); + if(!dependency.exists()) { + throw new RuntimeException("Could not read SWC dependency at " + dependency.getAbsolutePath()); + } + return dependency; + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/04bc6501/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLNodeBaseTests.java ---------------------------------------------------------------------- diff --git a/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLNodeBaseTests.java b/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLNodeBaseTests.java index 048b44c..70eed1a 100644 --- a/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLNodeBaseTests.java +++ b/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLNodeBaseTests.java @@ -43,6 +43,9 @@ import org.apache.flex.compiler.units.requests.ISyntaxTreeRequestResult; import org.apache.flex.utils.EnvProperties; import org.apache.flex.utils.FilenameNormalization; import org.apache.flex.utils.StringUtils; +import org.apache.flex.utils.ITestAdapter; +import org.apache.flex.utils.AntTestAdapter; +import org.apache.flex.utils.MavenTestAdapter; import org.junit.Ignore; /** @@ -124,14 +127,14 @@ public class MXMLNodeBaseTests protected IMXMLFileNode getMXMLFileNode(String mxml, boolean withFlex) { - if (withFlex) - assertNotNull("Environment variable FLEX_HOME is not set", env.SDK); - assertNotNull("Environment variable PLAYERGLOBAL_HOME is not set", env.FPSDK); - project = new FlexProject(workspace); - FlexProjectConfigurator.configure(project); - - String tempDir = FilenameNormalization.normalize("temp"); // ensure this exists + FlexProjectConfigurator.configure(project); + + // Depending on the "buildType" system-property, create the corresponding test-adapter. + // Make the AntTestAdapter the default. + ITestAdapter testAdapter = System.getProperty("buildType", "Ant").equals("Maven") ? + new MavenTestAdapter() : new AntTestAdapter(); + String tempDir = testAdapter.getTempDir(); File tempMXMLFile = null; try @@ -152,21 +155,13 @@ public class MXMLNodeBaseTests sourcePath.add(new File(tempDir)); project.setSourcePath(sourcePath); - // Compile the code against playerglobal.swc. - List<File> libraries = new ArrayList<File>(); - libraries.add(new File(FilenameNormalization.normalize(env.FPSDK + "\\" + env.FPVER + "\\playerglobal.swc"))); - if (withFlex) - { - libraries.add(new File(FilenameNormalization.normalize(env.SDK + "\\frameworks\\libs\\framework.swc"))); - libraries.add(new File(FilenameNormalization.normalize(env.SDK + "\\frameworks\\libs\\rpc.swc"))); - libraries.add(new File(FilenameNormalization.normalize(env.SDK + "\\frameworks\\libs\\spark.swc"))); - } + List<File> libraries = testAdapter.getLibraries(withFlex); project.setLibraries(libraries); // Use the MXML 2009 manifest. List<IMXMLNamespaceMapping> namespaceMappings = new ArrayList<IMXMLNamespaceMapping>(); IMXMLNamespaceMapping mxml2009 = new MXMLNamespaceMapping( - "http://ns.adobe.com/mxml/2009", env.SDK + "\\frameworks\\mxml-2009-manifest.xml"); + "http://ns.adobe.com/mxml/2009", testAdapter.getManifestPath()); namespaceMappings.add(mxml2009); project.setNamespaceMappings(namespaceMappings);
