mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-06 12:20:56 +01:00
added Platform
This commit is contained in:
262
scm-core/src/main/java/sonia/scm/Platform.java
Normal file
262
scm-core/src/main/java/sonia/scm/Platform.java
Normal file
@@ -0,0 +1,262 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class Platform
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param osName
|
||||
* @param archModel
|
||||
* @param osArch
|
||||
*/
|
||||
public Platform(String osName, String archModel, String osArch)
|
||||
{
|
||||
this.name = osName;
|
||||
|
||||
if (Util.isNotEmpty(archModel))
|
||||
{
|
||||
arch = archModel;
|
||||
}
|
||||
else
|
||||
{
|
||||
arch = osArch;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean is32Bit()
|
||||
{
|
||||
return !x64;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean is64Bit()
|
||||
{
|
||||
return x64;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getArch()
|
||||
{
|
||||
return arch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public PlatformType getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isFreeBSD()
|
||||
{
|
||||
return PlatformType.FREEBSD == type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isLinux()
|
||||
{
|
||||
return PlatformType.LINUX == type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isMac()
|
||||
{
|
||||
return PlatformType.MAC == type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isOpenBSD()
|
||||
{
|
||||
return PlatformType.OPENBSD == type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isPosix()
|
||||
{
|
||||
return type.isPosix();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isSolaris()
|
||||
{
|
||||
return PlatformType.SOLARIS == type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isUnix()
|
||||
{
|
||||
return type.isUnix();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isWindows()
|
||||
{
|
||||
return PlatformType.WINDOWS == type;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private String arch;
|
||||
|
||||
/** Field description */
|
||||
private String name;
|
||||
|
||||
/** Field description */
|
||||
private PlatformType type;
|
||||
|
||||
/** Field description */
|
||||
private boolean x64;
|
||||
}
|
||||
90
scm-core/src/main/java/sonia/scm/PlatformType.java
Normal file
90
scm-core/src/main/java/sonia/scm/PlatformType.java
Normal file
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public enum PlatformType
|
||||
{
|
||||
UNSPECIFIED(false, false), MAC(true, true), LINUX(false, true),
|
||||
WINDOWS(false, false), SOLARIS(true, true), FREEBSD(true, true),
|
||||
OPENBSD(true, true);
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param unix
|
||||
* @param posix
|
||||
*/
|
||||
private PlatformType(boolean unix, boolean posix)
|
||||
{
|
||||
this.unix = unix;
|
||||
this.posix = posix;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isPosix()
|
||||
{
|
||||
return posix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isUnix()
|
||||
{
|
||||
return unix;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private boolean posix;
|
||||
|
||||
/** Field description */
|
||||
private boolean unix;
|
||||
}
|
||||
@@ -33,6 +33,10 @@
|
||||
|
||||
package sonia.scm.util;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.Platform;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -43,9 +47,18 @@ public class SystemUtil
|
||||
/** Field description */
|
||||
public static final String PROPERTY_ARCH = "sun.arch.data.model";
|
||||
|
||||
/** Field description */
|
||||
public static final String PROPERTY_OSARCH = "os.arch";
|
||||
|
||||
/** Field description */
|
||||
public static final String PROPERTY_OSNAME = "os.name";
|
||||
|
||||
/** Field description */
|
||||
private static Platform platform =
|
||||
new Platform(System.getProperty(PROPERTY_OSNAME),
|
||||
System.getProperty(PROPERTY_ARCH),
|
||||
System.getProperty(PROPERTY_OSARCH));
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -56,7 +69,7 @@ public class SystemUtil
|
||||
*/
|
||||
public static boolean is32bit()
|
||||
{
|
||||
return "32".equals(System.getProperty(PROPERTY_ARCH));
|
||||
return platform.is32Bit();
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
@@ -69,7 +82,7 @@ public class SystemUtil
|
||||
*/
|
||||
public static String getArch()
|
||||
{
|
||||
return System.getProperty(PROPERTY_ARCH, "32");
|
||||
return platform.getArch();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +93,18 @@ public class SystemUtil
|
||||
*/
|
||||
public static String getOS()
|
||||
{
|
||||
return System.getProperty(PROPERTY_OSNAME);
|
||||
return platform.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Platform getPlatform()
|
||||
{
|
||||
return platform;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,10 +115,7 @@ public class SystemUtil
|
||||
*/
|
||||
public static boolean isMac()
|
||||
{
|
||||
String os = System.getProperty(PROPERTY_OSNAME).toLowerCase();
|
||||
|
||||
// Mac
|
||||
return (os.indexOf("mac") >= 0);
|
||||
return platform.isMac();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,10 +126,7 @@ public class SystemUtil
|
||||
*/
|
||||
public static boolean isUnix()
|
||||
{
|
||||
String os = System.getProperty(PROPERTY_OSNAME).toLowerCase();
|
||||
|
||||
// linux or unix
|
||||
return ((os.indexOf("nix") >= 0) || (os.indexOf("nux") >= 0));
|
||||
return platform.isUnix();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,9 +137,6 @@ public class SystemUtil
|
||||
*/
|
||||
public static boolean isWindows()
|
||||
{
|
||||
String os = System.getProperty(PROPERTY_OSNAME).toLowerCase();
|
||||
|
||||
// windows
|
||||
return (os.indexOf("win") >= 0);
|
||||
return platform.isWindows();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user