You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ft...@apache.org on 2015/05/13 16:56:44 UTC

git commit: [flex-utilities] [refs/heads/develop] - Fix: https://issues.apache.org/jira/browse/FLEX-34839

Repository: flex-utilities
Updated Branches:
  refs/heads/develop 3be7ca735 -> 002b4defb


Fix: https://issues.apache.org/jira/browse/FLEX-34839


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

Branch: refs/heads/develop
Commit: 002b4defbbe9b2bc08b1c391b09d8346b758f73b
Parents: 3be7ca7
Author: Frédéric THOMAS <we...@gmail.com>
Authored: Wed May 13 15:55:22 2015 +0100
Committer: Frédéric THOMAS <we...@gmail.com>
Committed: Wed May 13 15:55:22 2015 +0100

----------------------------------------------------------------------
 .../converter/mavenextension/FlexEventSpy.java  |  3 +-
 mavenizer/retrievers/base/pom.xml               | 38 +++++++-
 .../retrievers/types/PlatformType.java          | 93 +++++++++++++++++++-
 .../retrievers/types/PlatformTypeTest.java      | 61 +++++++++++++
 4 files changed, 192 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/002b4def/mavenizer/maven-extension/src/main/java/org/apache/flex/utilities/converter/mavenextension/FlexEventSpy.java
----------------------------------------------------------------------
diff --git a/mavenizer/maven-extension/src/main/java/org/apache/flex/utilities/converter/mavenextension/FlexEventSpy.java b/mavenizer/maven-extension/src/main/java/org/apache/flex/utilities/converter/mavenextension/FlexEventSpy.java
index 27b0ae7..034636d 100644
--- a/mavenizer/maven-extension/src/main/java/org/apache/flex/utilities/converter/mavenextension/FlexEventSpy.java
+++ b/mavenizer/maven-extension/src/main/java/org/apache/flex/utilities/converter/mavenextension/FlexEventSpy.java
@@ -6,6 +6,7 @@ import org.apache.flex.utilities.converter.flash.FlashConverter;
 import org.apache.flex.utilities.converter.flex.FlexConverter;
 import org.apache.flex.utilities.converter.fontkit.FontkitConverter;
 import org.apache.flex.utilities.converter.retrievers.download.DownloadRetriever;
+import org.apache.flex.utilities.converter.retrievers.types.PlatformType;
 import org.apache.flex.utilities.converter.retrievers.types.SdkType;
 import org.apache.flex.utilities.converter.wrapper.WrapperConverter;
 import org.apache.maven.MavenExecutionException;
@@ -175,7 +176,7 @@ public class FlexEventSpy extends AbstractEventSpy {
         try {
             File localRepoBaseDir = new File(mavenSession.getLocalRepository().getBasedir());
             DownloadRetriever downloadRetriever = new DownloadRetriever();
-            File sdkRoot = downloadRetriever.retrieve(SdkType.AIR, version);
+            File sdkRoot = downloadRetriever.retrieve(SdkType.AIR, version, PlatformType.getCurrent());
             AirConverter converter = new AirConverter(sdkRoot, localRepoBaseDir);
             converter.convert();
         } catch (Throwable ce) {

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/002b4def/mavenizer/retrievers/base/pom.xml
----------------------------------------------------------------------
diff --git a/mavenizer/retrievers/base/pom.xml b/mavenizer/retrievers/base/pom.xml
index 507ee13..d13b4cb 100644
--- a/mavenizer/retrievers/base/pom.xml
+++ b/mavenizer/retrievers/base/pom.xml
@@ -30,6 +30,11 @@
     <version>1.0.0-SNAPSHOT</version>
     <packaging>jar</packaging>
 
+    <properties>
+        <powermock.version>1.6.2</powermock.version>
+        <junit.version>4.8.2</junit.version>
+    </properties>
+
     <dependencies>
         <dependency>
             <groupId>commons-io</groupId>
@@ -46,6 +51,37 @@
             <artifactId>commons-lang</artifactId>
             <version>2.6</version>
         </dependency>
-    </dependencies>
 
+        <!--TEST-->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>${junit.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.powermock</groupId>
+            <artifactId>powermock-module-junit4-rule-agent</artifactId>
+            <version>${powermock.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.powermock</groupId>
+            <artifactId>powermock-module-junit4</artifactId>
+            <version>${powermock.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.powermock</groupId>
+            <artifactId>powermock-api-easymock</artifactId>
+            <version>${powermock.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymock</artifactId>
+            <version>3.3.1</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/002b4def/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/types/PlatformType.java
----------------------------------------------------------------------
diff --git a/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/types/PlatformType.java b/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/types/PlatformType.java
index b5cf83f..2dceba0 100644
--- a/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/types/PlatformType.java
+++ b/mavenizer/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/types/PlatformType.java
@@ -23,6 +23,97 @@ public enum PlatformType {
 
     WINDOWS,
     LINUX,
-    MAC
+    MAC;
 
+    public static PlatformType getCurrent()
+    {
+        PlatformType platformType = null;
+
+        if (isWindows())
+        {
+            platformType = PlatformType.WINDOWS;
+        }
+        else if (isMac())
+        {
+            platformType = PlatformType.MAC;
+        }
+        else if (isUnixBased())
+        {
+            platformType = PlatformType.LINUX;
+        }
+
+        return platformType;
+    }
+
+    static final String NET_BSD = "netbsd";
+
+    static final String FREE_BSD = "freebsd";
+
+    static final String WINDOWS_OS = "windows";
+
+    static final String MAC_OS = "mac os x";
+
+    static final String MAC_OS_DARWIN = "darwin";
+
+    static final String LINUX_OS = "linux";
+
+    static final String SOLARIS_OS = "sunos";
+
+    private static String osString()
+    {
+        return System.getProperty( "os.name" ).toLowerCase();
+    }
+
+    /**
+     * Return a boolean to show if we are running on Windows.
+     *
+     * @return true if we are running on Windows.
+     */
+    private static boolean isWindows()
+    {
+        return osString().startsWith( WINDOWS_OS );
+    }
+
+    /**
+     * Return a boolean to show if we are running on Linux.
+     *
+     * @return true if we are running on Linux.
+     */
+    private static boolean isLinux()
+    {
+        return osString().startsWith( LINUX_OS ) ||
+                // I know, but people said that workds...
+                osString().startsWith( NET_BSD ) ||
+                osString().startsWith( FREE_BSD );
+    }
+
+    /**
+     * Return a boolean to show if we are running on Solaris.
+     *
+     * @return true if we are running on Solaris.
+     */
+    private static boolean isSolaris()
+    {
+        return osString().startsWith( SOLARIS_OS );
+    }
+
+    /**
+     * Return a boolean to show if we are running on a unix-based OS.
+     *
+     * @return true if we are running on a unix-based OS.
+     */
+    private static boolean isUnixBased()
+    {
+        return isLinux() || isSolaris();
+    }
+
+    /**
+     * Return a boolean to show if we are running on Mac OS X.
+     *
+     * @return true if we are running on Mac OS X.
+     */
+    private static boolean isMac()
+    {
+        return osString().startsWith( MAC_OS ) || osString().startsWith( MAC_OS_DARWIN );
+    }
 }

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/002b4def/mavenizer/retrievers/base/src/test/java/org/apache/flex/utilities/converter/retrievers/types/PlatformTypeTest.java
----------------------------------------------------------------------
diff --git a/mavenizer/retrievers/base/src/test/java/org/apache/flex/utilities/converter/retrievers/types/PlatformTypeTest.java b/mavenizer/retrievers/base/src/test/java/org/apache/flex/utilities/converter/retrievers/types/PlatformTypeTest.java
new file mode 100644
index 0000000..d8571bc
--- /dev/null
+++ b/mavenizer/retrievers/base/src/test/java/org/apache/flex/utilities/converter/retrievers/types/PlatformTypeTest.java
@@ -0,0 +1,61 @@
+package org.apache.flex.utilities.converter.retrievers.types;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.rule.PowerMockRule;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.assertEquals;
+import static org.powermock.api.easymock.PowerMock.*;
+
+/**
+ * @author: Frederic Thomas
+ * Date: 12/05/2015
+ * Time: 01:34
+ */
+@PrepareForTest( { PlatformType.class })
+@RunWith(Parameterized.class)
+public class PlatformTypeTest {
+
+	private String osName;
+	private PlatformType platformType;
+
+	@Rule
+	public PowerMockRule powerMockRule = new PowerMockRule();
+
+	@Parameterized.Parameters
+	public static Collection<Object[]> data() {
+
+		return Arrays.asList(new Object[][]{
+				{PlatformType.WINDOWS_OS, PlatformType.WINDOWS},
+				{PlatformType.MAC_OS, PlatformType.MAC},
+				{PlatformType.MAC_OS_DARWIN, PlatformType.MAC},
+				{PlatformType.FREE_BSD, PlatformType.LINUX},
+				{PlatformType.LINUX_OS, PlatformType.LINUX},
+				{PlatformType.NET_BSD, PlatformType.LINUX},
+				{PlatformType.SOLARIS_OS, PlatformType.LINUX}
+		});
+	}
+
+	public PlatformTypeTest(String osName, PlatformType platformType) {
+		this.osName = osName;
+		this.platformType = platformType;
+	}
+
+	@Test
+	public void it_returns_the_current_platform_type() throws Exception {
+		mockStatic(System.class);
+
+		expect(System.getProperty("os.name")).andReturn(osName).anyTimes();
+		replayAll();
+
+		assertEquals(platformType, PlatformType.getCurrent());
+		verifyAll();
+	}
+}