improve os plugin condition

This commit is contained in:
Sebastian Sdorra
2011-03-13 13:12:44 +01:00
parent 90c550ac9c
commit bf15e96204
4 changed files with 68 additions and 39 deletions

View File

@@ -68,35 +68,7 @@ public class Platform
arch = arch.toLowerCase();
x64 = "64".equals(arch) || "x86_64".equals(arch) || "ppc64".equals(arch)
|| "sparcv9".equals(arch) || "amd64".equals(arch);
if (osName.startsWith("Linux"))
{
type = PlatformType.LINUX;
}
else if (osName.startsWith("Mac") || osName.startsWith("Darwin"))
{
type = PlatformType.MAC;
}
else if (osName.startsWith("Windows"))
{
type = PlatformType.WINDOWS;
}
else if (osName.startsWith("Solaris") || osName.startsWith("SunOS"))
{
type = PlatformType.SOLARIS;
}
else if (osName.startsWith("FreeBSD"))
{
type = PlatformType.FREEBSD;
}
else if (osName.startsWith("OpenBSD"))
{
type = PlatformType.OPENBSD;
}
else
{
type = PlatformType.UNSPECIFIED;
}
type = PlatformType.createPlatformType(osName);
}
//~--- methods --------------------------------------------------------------

View File

@@ -56,6 +56,50 @@ public enum PlatformType
this.posix = posix;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param osName
*
* @return
*/
public static PlatformType createPlatformType(String osName)
{
osName = osName.toLowerCase();
PlatformType type = PlatformType.UNSPECIFIED;
if (osName.startsWith("linux"))
{
type = PlatformType.LINUX;
}
else if (osName.startsWith("mac") || osName.startsWith("darwin"))
{
type = PlatformType.MAC;
}
else if (osName.startsWith("windows"))
{
type = PlatformType.WINDOWS;
}
else if (osName.startsWith("solaris") || osName.startsWith("sunos"))
{
type = PlatformType.SOLARIS;
}
else if (osName.startsWith("freebsd"))
{
type = PlatformType.FREEBSD;
}
else if (osName.startsWith("openbsd"))
{
type = PlatformType.OPENBSD;
}
return type;
}
//~--- get methods ----------------------------------------------------------
/**

View File

@@ -35,6 +35,7 @@ package sonia.scm.plugin;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.PlatformType;
import sonia.scm.SCMContext;
import sonia.scm.util.SystemUtil;
import sonia.scm.util.Util;
@@ -149,11 +150,12 @@ public class PluginCondition
if (supported && Util.isNotEmpty(this.os) && Util.isNotEmpty(os))
{
supported = false;
os = os.toLowerCase();
PlatformType platformType = PlatformType.createPlatformType(os);
for (String osType : this.os)
{
supported = isOs(osType, os);
supported = isOs(osType, platformType);
if (supported)
{
@@ -212,18 +214,23 @@ public class PluginCondition
*
*
* @param osType
* @param os
* @param type
*
* @return
*/
private boolean isOs(String osType, String os)
private boolean isOs(String osType, PlatformType type)
{
osType = osType.toLowerCase();
return (osType.startsWith("mac") && (os.indexOf("mac") >= 0))
|| (osType.startsWith("win") && (os.indexOf("win") >= 0))
|| ((osType.startsWith("unix") && (os.indexOf("nix") >= 0))
|| (os.indexOf("nux") >= 0));
return
( osType.indexOf("win") >= 0 && PlatformType.WINDOWS == type ) ||
( osType.indexOf("unix") >= 0 && type.isUnix() ) ||
( osType.indexOf("posix") >= 0 && type.isPosix() ) ||
( osType.indexOf("mac") >= 0 && PlatformType.MAC == type) ||
( osType.indexOf("linux") >= 0 && PlatformType.LINUX == type ) ||
( osType.indexOf("solaris") >= 0 && PlatformType.SOLARIS == type ) ||
( osType.indexOf("openbsd") >= 0 && PlatformType.OPENBSD == type ) ||
( osType.indexOf("freebsd") >= 0 && PlatformType.FREEBSD == type );
}
//~--- fields ---------------------------------------------------------------

View File

@@ -70,8 +70,14 @@ public class PluginConditionTest
@Test
public void testIsOsSupported()
{
assertTrue(new PluginCondition(null, Arrays.asList("unix"),
assertTrue(new PluginCondition(null, Arrays.asList("linux"),
null).isSupported(null, "linux", null));
assertTrue(new PluginCondition(null, Arrays.asList("unix"),
null).isSupported(null, "Mac OS X", null));
assertTrue(new PluginCondition(null, Arrays.asList("unix"),
null).isSupported(null, "Solaris", null));
assertTrue(new PluginCondition(null, Arrays.asList("posix"),
null).isSupported(null, "Linux", null));
assertTrue(new PluginCondition(null, Arrays.asList("win"),
null).isSupported(null, "Windows 2000",
null));