-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduced better error handling for sdk platform as well as allowed …
…for usage of platform as well as api level as parameter with internal automatic translation
- Loading branch information
Showing
5 changed files
with
155 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/main/java/com/jayway/maven/plugins/android/PlatformApiLevel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.jayway.maven.plugins.android; | ||
|
||
/** | ||
* | ||
* | ||
* @author Manfred Moser <manfred@simpligility.com> | ||
*/ | ||
public enum PlatformApiLevel { | ||
ONE_ONE("1.1", "2"), | ||
ONE_FIVE("1.5", "3"), | ||
ONE_SIX("1.6", "4"), | ||
TWO_ZERO("2.0", "5"), | ||
TWO_ZERO_ONE("2.01", "6"), | ||
TWO_ONE("2.1", "7"); | ||
|
||
private String platform; | ||
private String apilevel; | ||
|
||
private PlatformApiLevel(String platform, String apilevel) { | ||
this.platform = platform; | ||
this.apilevel = apilevel; | ||
} | ||
|
||
public String getPlatform() { | ||
return platform; | ||
} | ||
|
||
public void setPlatform(String platform) { | ||
this.platform = platform; | ||
} | ||
|
||
public String getApilevel() { | ||
return apilevel; | ||
} | ||
|
||
public void setApilevel(String apilevel) { | ||
this.apilevel = apilevel; | ||
} | ||
|
||
public static String findPlatform(String apilevel) { | ||
PlatformApiLevel[] allPlatformApiLevels = PlatformApiLevel.values(); | ||
for (PlatformApiLevel platformApiLevel : allPlatformApiLevels) { | ||
if (platformApiLevel.getApilevel().equals(apilevel)) return platformApiLevel.getPlatform(); | ||
} | ||
return null; | ||
} | ||
|
||
public static String findApiLevel(String platform) { | ||
PlatformApiLevel[] allPlatformApiLevels = PlatformApiLevel.values(); | ||
for (PlatformApiLevel platformApiLevel : allPlatformApiLevels) { | ||
if (platformApiLevel.getPlatform().equals(platform)) return platformApiLevel.getApilevel(); | ||
} | ||
return null; | ||
} | ||
|
||
public static boolean isValidPlatform(String platform) { | ||
boolean valid = false; | ||
PlatformApiLevel[] allPlatformApiLevels = PlatformApiLevel.values(); | ||
for (PlatformApiLevel current : allPlatformApiLevels) { | ||
if (current.getPlatform().equals(platform)) valid = true; | ||
} | ||
return valid; | ||
} | ||
|
||
public static boolean isValidApiLevel(String apiLevel) { | ||
boolean valid = false; | ||
PlatformApiLevel[] allPlatformApiLevels = PlatformApiLevel.values(); | ||
for (PlatformApiLevel current : allPlatformApiLevels) { | ||
if (current.getApilevel().equals(apiLevel)) valid = true; | ||
} | ||
return valid; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/test/java/com/jayway/maven/plugins/android/PlatformApiLevelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.jayway.maven.plugins.android; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* | ||
* | ||
* @author Manfred Moser <manfred@simpligility.com> | ||
*/ | ||
public class PlatformApiLevelTest { | ||
|
||
@Test | ||
public void checkTotalNumber() { | ||
Assert.assertEquals(6, PlatformApiLevel.values().length); | ||
} | ||
|
||
@Test | ||
public void checkApiLevelLookup() { | ||
Assert.assertEquals("1.1", PlatformApiLevel.findPlatform("2")); | ||
Assert.assertEquals("1.5", PlatformApiLevel.findPlatform("3")); | ||
Assert.assertEquals("1.6", PlatformApiLevel.findPlatform("4")); | ||
Assert.assertEquals("2.0", PlatformApiLevel.findPlatform("5")); | ||
Assert.assertEquals("2.01", PlatformApiLevel.findPlatform("6")); | ||
Assert.assertEquals("2.1", PlatformApiLevel.findPlatform("7")); | ||
} | ||
|
||
@Test | ||
public void checkPlatformLookup() { | ||
Assert.assertEquals("2", PlatformApiLevel.findApiLevel("1.1")); | ||
Assert.assertEquals("3", PlatformApiLevel.findApiLevel("1.5")); | ||
Assert.assertEquals("4", PlatformApiLevel.findApiLevel("1.6")); | ||
Assert.assertEquals("5", PlatformApiLevel.findApiLevel("2.0")); | ||
Assert.assertEquals("6", PlatformApiLevel.findApiLevel("2.01")); | ||
Assert.assertEquals("7", PlatformApiLevel.findApiLevel("2.1")); | ||
} | ||
|
||
@Test | ||
public void checkValidPlatform() { | ||
Assert.assertTrue(PlatformApiLevel.isValidApiLevel("2")); | ||
Assert.assertTrue(PlatformApiLevel.isValidApiLevel("3")); | ||
Assert.assertTrue(PlatformApiLevel.isValidApiLevel("4")); | ||
Assert.assertTrue(PlatformApiLevel.isValidApiLevel("5")); | ||
Assert.assertTrue(PlatformApiLevel.isValidApiLevel("6")); | ||
Assert.assertTrue(PlatformApiLevel.isValidApiLevel("7")); | ||
|
||
Assert.assertFalse(PlatformApiLevel.isValidApiLevel("something")); | ||
Assert.assertFalse(PlatformApiLevel.isValidApiLevel("1.0")); | ||
} | ||
|
||
@Test | ||
public void checkValidApiLevel() { | ||
|
||
Assert.assertTrue(PlatformApiLevel.isValidPlatform("1.1")); | ||
Assert.assertTrue(PlatformApiLevel.isValidPlatform("1.5")); | ||
Assert.assertTrue(PlatformApiLevel.isValidPlatform("1.6")); | ||
Assert.assertTrue(PlatformApiLevel.isValidPlatform("2.0")); | ||
Assert.assertTrue(PlatformApiLevel.isValidPlatform("2.01")); | ||
Assert.assertTrue(PlatformApiLevel.isValidPlatform("2.1")); | ||
|
||
Assert.assertFalse(PlatformApiLevel.isValidPlatform("something")); | ||
Assert.assertFalse(PlatformApiLevel.isValidPlatform("1.0")); | ||
} | ||
} |