mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 17:26:22 +01:00
improve os plugin condition
This commit is contained in:
@@ -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 --------------------------------------------------------------
|
||||
|
||||
@@ -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 ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 ---------------------------------------------------------------
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user