Java Code Examples for org.apache.commons.lang3.SystemUtils#IS_OS_LINUX

The following examples show how to use org.apache.commons.lang3.SystemUtils#IS_OS_LINUX . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DatabasePopulator.java    From pg-index-health with Apache License 2.0 6 votes vote down vote up
private void createCustomCollation(@Nonnull final Statement statement,
                                   @Nonnull final String customCollation) throws SQLException {
    final String query = "create collation \"%s\" from \"%s\";";
    final String systemLocale;
    if (SystemUtils.IS_OS_WINDOWS) {
        final String icuCollation = "en-US-x-icu";
        if (isCollationExist(statement, icuCollation)) {
            systemLocale = icuCollation; // for Pg 10+
        } else {
            systemLocale = "C"; // for Pg 9.6
        }
    } else {
        if (SystemUtils.IS_OS_LINUX) {
            systemLocale = "en_US.utf8";
        } else if (SystemUtils.IS_OS_MAC) {
            systemLocale = "en_US.UTF-8";
        } else {
            throw new RuntimeException("Unsupported operation system");
        }
    }
    statement.execute(String.format(query, customCollation, systemLocale));
}
 
Example 2
Source File: CheckGcpEnvironment.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
private static boolean isRunningOnGcp() {
  try {
    if (SystemUtils.IS_OS_LINUX) {
      // Checks GCE residency on Linux platform.
      return checkProductNameOnLinux(Files.newBufferedReader(Paths.get(DMI_PRODUCT_NAME), UTF_8));
    } else if (SystemUtils.IS_OS_WINDOWS) {
      // Checks GCE residency on Windows platform.
      Process p =
          new ProcessBuilder()
              .command(WINDOWS_COMMAND, "Get-WmiObject", "-Class", "Win32_BIOS")
              .start();
      return checkBiosDataOnWindows(
          new BufferedReader(new InputStreamReader(p.getInputStream(), UTF_8)));
    }
  } catch (IOException e) {
    logger.log(Level.WARNING, "Fail to read platform information: ", e);
    return false;
  }
  // Platforms other than Linux and Windows are not supported.
  return false;
}
 
Example 3
Source File: Browser.java    From DeskChan with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void browse(String value) throws Exception {
    String[] command;
    if (SystemUtils.IS_OS_WINDOWS) {
        command = new String[]{ "cmd", "/c", "start", "\"\"", wrap(value) };
    } else if (SystemUtils.IS_OS_MAC) {
        command = new String[]{"open", unwrap(value) };
    } else if (SystemUtils.IS_OS_LINUX) {
        command = new String[]{"xdg-open", unwrap(value) };
    } else {
        throw new Exception("System is not supported for links opening yet, platform: " + System.getProperty("os.name"));
    }
    Process p = Runtime.getRuntime().exec(command);
    p.waitFor();
    BufferedReader reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    String line = "";
    while ((line = reader.readLine())!= null) {
        System.out.println(line + "\n");
    }
}
 
Example 4
Source File: SysUtils.java    From mvn-golang with Apache License 2.0 6 votes vote down vote up
@Nullable
public static String findGoSdkOsType() {
  final String result;
  if (SystemUtils.IS_OS_WINDOWS) {
    result = "windows";
  } else if (SystemUtils.IS_OS_FREE_BSD) {
    result = "freebsd";
  } else if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX) {
    result = "darwin";
  } else if (SystemUtils.IS_OS_LINUX) {
    result = "linux";
  } else {
    result = null;
  }
  return result;
}
 
Example 5
Source File: HardwareUtils.java    From JavaSteam with MIT License 6 votes vote down vote up
public static byte[] getMachineID() {
    // the aug 25th 2015 CM update made well-formed machine MessageObjects required for logon
    // this was flipped off shortly after the update rolled out, likely due to linux steamclients running on distros without a way to build a machineid
    // so while a valid MO isn't currently (as of aug 25th) required, they could be in the future and we'll abide by The Valve Law now

    if (SERIAL_NUMBER != null) {
        return SERIAL_NUMBER.getBytes();
    }

    if (SystemUtils.IS_OS_WINDOWS) {
        SERIAL_NUMBER = getSerialNumberWin();
    }
    if (SystemUtils.IS_OS_MAC) {
        SERIAL_NUMBER = getSerialNumberMac();
    }
    if (SystemUtils.IS_OS_LINUX) {
        SERIAL_NUMBER = getSerialNumberUnix();
    }

    return SERIAL_NUMBER == null ? new byte[0] : SERIAL_NUMBER.getBytes();
}
 
Example 6
Source File: ElasticsearchArtifact.java    From elasticsearch-maven-plugin with Apache License 2.0 6 votes vote down vote up
private String getArtifactType(String version)
{
    if (VersionUtil.isEqualOrGreater_7_0_0(version))
    {
        if (SystemUtils.IS_OS_WINDOWS)
        {
            return "zip";
        }
        else if (SystemUtils.IS_OS_MAC)
        {
            return "tar.gz";
        }
        else if (SystemUtils.IS_OS_LINUX)
        {
            return "tar.gz";
        }
        else {
            throw new IllegalStateException("Unknown OS, cannot determine the Elasticsearch classifier.");
        }
    }
    else // Only a single artifact type below 7.0.0
    {
        return "zip";
    }
}
 
Example 7
Source File: SimpleLoadManagerImplTest.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Test
public void testBrokerHostUsage() {
    BrokerHostUsage brokerUsage;
    if (SystemUtils.IS_OS_LINUX) {
        brokerUsage = new LinuxBrokerHostUsageImpl(pulsar1);
    } else {
        brokerUsage = new GenericBrokerHostUsageImpl(pulsar1);
    }
    brokerUsage.getBrokerHostUsage();
    // Ok
}
 
Example 8
Source File: JDA.java    From java-disassembler with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Main startup
 *
 * @param args files you want to open or CLI
 */
public static void main(String[] args) {
    GuiUtils.setAntialiasingSettings();
    if (SystemUtils.IS_OS_LINUX) {
        GuiUtils.setWmClassName("JDA");
    }
    GuiUtils.setLookAndFeel();
    try {
        System.out.println("JDA v" + version);
        getJDADirectory();

        registerModules();
        loadPlugins();

        Settings.loadGUI();
        if (!recentsFile.exists() && !recentsFile.createNewFile())
            throw new RuntimeException("Could not create recent files file");
        recentFiles.addAll(FileUtils.readLines(recentsFile, "UTF-8"));

        viewer = new MainViewerGUI();
        JDA.onGUILoad();
        Boot.boot();
        JDA.boot(args);
    } catch (Exception e) {
        new ExceptionUI(e, "initializing");
    }
}
 
Example 9
Source File: NativeBundle.java    From spoofax with Apache License 2.0 5 votes vote down vote up
/**
 * @return URI to the native directory. Can point to a directory on the local file system, or to a directory in a
 *         JAR file.
 */
public static URI getNativeDirectory() {
    if(SystemUtils.IS_OS_WINDOWS) {
        return getResource("native/cygwin/");
    } else if(SystemUtils.IS_OS_MAC_OSX) {
        return getResource("native/macosx/");
    } else if(SystemUtils.IS_OS_LINUX) {
        return getResource("native/linux/");
    } else {
        throw new UnsupportedOperationException("Unsupported platform " + SystemUtils.OS_NAME);
    }
}
 
Example 10
Source File: WebDriverHandlerImpl.java    From IridiumApplicationTesting with MIT License 5 votes vote down vote up
@Override
public void configureWebDriver(@NotNull final List<File> tempFiles) {
	checkNotNull(tempFiles);

	final boolean useSuppliedWebDrivers =
		SYSTEM_PROPERTY_UTILS.getPropertyAsBoolean(
			Constants.USE_SUPPLIED_WEBDRIVERS, true);

	final boolean is64BitOS = OS_DETECTION.is64BitOS();

	if (SystemUtils.IS_OS_WINDOWS) {
		configureWindows(tempFiles, is64BitOS, useSuppliedWebDrivers);
	} else if (SystemUtils.IS_OS_MAC) {
		configureMac(tempFiles, is64BitOS, useSuppliedWebDrivers);
	} else if (SystemUtils.IS_OS_LINUX) {
		configureLinux(tempFiles, is64BitOS, useSuppliedWebDrivers);
	}

	/*
		Log some details about the diver locations
	 */
	Stream.of(Constants.CHROME_WEB_DRIVER_LOCATION_SYSTEM_PROPERTY,
		Constants.OPERA_WEB_DRIVER_LOCATION_SYSTEM_PROPERTY,
		Constants.IE_WEB_DRIVER_LOCATION_SYSTEM_PROPERTY,
		Constants.PHANTOM_JS_BINARY_PATH_SYSTEM_PROPERTY,
		GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY,
		Constants.EDGE_WEB_DRIVER_LOCATION_SYSTEM_PROPERTY)
		.forEach(x -> LOGGER.info(
			"WEBAPPTESTER-INFO-0004: System property {}: {}",
			x,
			System.getProperty(x)));
}
 
Example 11
Source File: FbxConv.java    From Mundus with Apache License 2.0 5 votes vote down vote up
public FbxConv(String fbxBinary) {
    this.fbxBinary = fbxBinary;
    if (SystemUtils.IS_OS_MAC) {
        os = Os.MAC;
    } else if (SystemUtils.IS_OS_WINDOWS) {
        os = Os.WINDOWS;
    } else if (SystemUtils.IS_OS_LINUX) {
        os = Os.LINUX;
    } else {
        throw new OsNotSupported();
    }

    pb = new ProcessBuilder(fbxBinary);
}
 
Example 12
Source File: NativeImageBuildStep.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private RuntimeException imageGenerationFailed(int exitValue, List<String> command) {
    if (exitValue == OOM_ERROR_VALUE) {
        if (command.contains("docker") && !SystemUtils.IS_OS_LINUX) {
            return new RuntimeException("Image generation failed. Exit code was " + exitValue
                    + " which indicates an out of memory error. The most likely cause is Docker not being given enough memory. Also consider increasing the Xmx value for native image generation by setting the \""
                    + QUARKUS_XMX_PROPERTY + "\" property");
        } else {
            return new RuntimeException("Image generation failed. Exit code was " + exitValue
                    + " which indicates an out of memory error. Consider increasing the Xmx value for native image generation by setting the \""
                    + QUARKUS_XMX_PROPERTY + "\" property");
        }
    } else {
        return new RuntimeException("Image generation failed. Exit code: " + exitValue);
    }
}
 
Example 13
Source File: JobConstants.java    From genie with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the appropriate flag to append to kill command based on the OS.
 *
 * @return The flag to use for kill command.
 */
public static String getKillFlag() {
    if (SystemUtils.IS_OS_LINUX) {
        return KILL_PROCESS_GROUP_FLAG;
    } else {
        return KILL_PARENT_PID_FLAG;
    }
}
 
Example 14
Source File: SteamSearch.java    From ModTheSpire with MIT License 5 votes vote down vote up
private static Path getSteamPath()
{
    Path steamPath = null;

    if (SystemUtils.IS_OS_WINDOWS) {
        steamPath = Paths.get(System.getenv("ProgramFiles") + " (x86)", "Steam", "steamapps");
        if (!steamPath.toFile().exists()) {
            steamPath = Paths.get(System.getenv("ProgramFiles"), "Steam", "steamapps");
            if (!steamPath.toFile().exists()) {
                steamPath = null;
            }
        }
        return steamPath;
    } else if (SystemUtils.IS_OS_MAC) {
        steamPath = Paths.get(SystemUtils.USER_HOME, "Library/Application Support/Steam/steamapps");
        if (!steamPath.toFile().exists()) {
            steamPath = null;
        }
    } else if (SystemUtils.IS_OS_LINUX) {
        Path[] possiblePaths = {
            Paths.get(SystemUtils.USER_HOME, ".steam/steam/SteamApps"),
            Paths.get(SystemUtils.USER_HOME, ".steam/steam/steamapps"),
            Paths.get(SystemUtils.USER_HOME, ".local/share/steam/SteamApps"),
            Paths.get(SystemUtils.USER_HOME, ".local/share/steam/steamapps")
        };

        for (Path p : possiblePaths) {
            if (p.toFile().exists()) {
                steamPath = p;
                break;
            }
        }
    }

    return steamPath;
}
 
Example 15
Source File: InferenceVerticle.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
public static int getPid() throws UnsatisfiedLinkError {
    if (SystemUtils.IS_OS_WINDOWS) {
        return windows.GetCurrentProcessId();
    } else if (SystemUtils.IS_OS_MAC) {
        return macosx.getpid();
    } else if (SystemUtils.IS_OS_LINUX){
        return linux.getpid();
    } else {
        return -1;
    }
}
 
Example 16
Source File: GremlinServer.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a Gremlin Server instance from {@link Settings} and {@link ExecutorService}.
 * This constructor is useful when Gremlin Server is being used in an embedded style
 * and there is a need to share thread pools with the hosting application.
 */
public GremlinServer(final Settings settings, final ExecutorService gremlinExecutorService) {
    settings.optionalMetrics().ifPresent(GremlinServer::configureMetrics);
    this.settings = settings;
    provideDefaultForGremlinPoolSize(settings);
    this.isEpollEnabled = settings.useEpollEventLoop && SystemUtils.IS_OS_LINUX;
    if (settings.useEpollEventLoop && !SystemUtils.IS_OS_LINUX){
        logger.warn("cannot use epoll in non-linux env, falling back to NIO");
    }

    Runtime.getRuntime().addShutdownHook(new Thread(() -> this.stop().join(), SERVER_THREAD_PREFIX + "shutdown"));

    final ThreadFactory threadFactoryBoss = ThreadFactoryUtil.create("boss-%d");
    // if linux os use epoll else fallback to nio based eventloop
    // epoll helps in reducing GC and has better  performance
    // http://netty.io/wiki/native-transports.html
    if (isEpollEnabled){
        bossGroup = new EpollEventLoopGroup(settings.threadPoolBoss, threadFactoryBoss);
    } else {
        bossGroup = new NioEventLoopGroup(settings.threadPoolBoss, threadFactoryBoss);
    }

    final ThreadFactory threadFactoryWorker = ThreadFactoryUtil.create("worker-%d");
    if (isEpollEnabled) {
        workerGroup = new EpollEventLoopGroup(settings.threadPoolWorker, threadFactoryWorker);
    } else {
        workerGroup = new NioEventLoopGroup(settings.threadPoolWorker, threadFactoryWorker);
    }

    // use the ExecutorService returned from ServerGremlinExecutor as it might be initialized there
    serverGremlinExecutor = new ServerGremlinExecutor(settings, gremlinExecutorService, workerGroup);
    this.gremlinExecutorService = serverGremlinExecutor.getGremlinExecutorService();

    // initialize the OpLoader with configurations being passed to each OpProcessor implementation loaded
    OpLoader.init(settings);
}
 
Example 17
Source File: Utils.java    From JavaSteam with MIT License 4 votes vote down vote up
public static EOSType getOSType() {
    if (SystemUtils.IS_OS_WINDOWS_7) {
        return EOSType.Windows7;
    }
    if (SystemUtils.IS_OS_WINDOWS_8) {
        return EOSType.Windows8;
    }
    if (SystemUtils.IS_OS_WINDOWS_10) {
        return EOSType.Windows10;
    }
    if (SystemUtils.IS_OS_WINDOWS_95) {
        return EOSType.Win95;
    }
    if (SystemUtils.IS_OS_WINDOWS_98) {
        return EOSType.Win98;
    }
    if (SystemUtils.IS_OS_WINDOWS_2000) {
        return EOSType.Win2000;
    }
    if (SystemUtils.IS_OS_WINDOWS_2003) {
        return EOSType.Win2003;
    }
    if (SystemUtils.IS_OS_WINDOWS_2008) {
        return EOSType.Win2008;
    }
    if (SystemUtils.IS_OS_WINDOWS_2012) {
        return EOSType.Win2012;
    }
    if (SystemUtils.IS_OS_WINDOWS_ME) {
        return EOSType.WinME;
    }
    if (SystemUtils.IS_OS_WINDOWS_NT) {
        return EOSType.WinNT;
    }
    if (SystemUtils.IS_OS_WINDOWS_VISTA) {
        return EOSType.WinVista;
    }
    if (SystemUtils.IS_OS_WINDOWS_XP) {
        return EOSType.WinXP;
    }
    if (SystemUtils.IS_OS_WINDOWS) {
        return EOSType.WinUnknown;
    }
    if (SystemUtils.IS_OS_MAC_OSX_TIGER) {
        return EOSType.MacOS104;
    }
    if (SystemUtils.IS_OS_MAC_OSX_LEOPARD) {
        return EOSType.MacOS105;
    }
    if (SystemUtils.IS_OS_MAC_OSX_SNOW_LEOPARD) {
        return EOSType.MacOS106;
    }
    if (SystemUtils.IS_OS_MAC_OSX_LION) {
        return EOSType.MacOS107;
    }
    if (SystemUtils.IS_OS_MAC_OSX_MOUNTAIN_LION) {
        return EOSType.MacOS108;
    }
    if (SystemUtils.IS_OS_MAC_OSX_MAVERICKS) {
        return EOSType.MacOS109;
    }
    if (SystemUtils.IS_OS_MAC_OSX_YOSEMITE) {
        return EOSType.MacOS1010;
    }
    if (SystemUtils.IS_OS_MAC_OSX_EL_CAPITAN) {
        return EOSType.MacOS1011;
    }
    if (checkOS("Mac OS X", "10.12")) {
        return EOSType.MacOS1012;
    }
    if (checkOS("Mac OS X", "10.13")) {
        return EOSType.Macos1013;
    }
    if (checkOS("Mac OS X", "10.14")) {
        return EOSType.Macos1014;
    }
    if (SystemUtils.IS_OS_MAC) {
        return EOSType.MacOSUnknown;
    }
    if (JAVA_RUNTIME != null && JAVA_RUNTIME.startsWith("Android")) {
        return EOSType.AndroidUnknown;
    }
    if (SystemUtils.IS_OS_LINUX) {
        return EOSType.LinuxUnknown;
    }
    return EOSType.Unknown;
}
 
Example 18
Source File: SimpleLoadManagerImpl.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(final PulsarService pulsar) {
    if (SystemUtils.IS_OS_LINUX) {
        brokerHostUsage = new LinuxBrokerHostUsageImpl(pulsar);
    } else {
        brokerHostUsage = new GenericBrokerHostUsageImpl(pulsar);
    }
    this.policies = new SimpleResourceAllocationPolicies(pulsar);
    lastLoadReport = new LoadReport(pulsar.getSafeWebServiceAddress(), pulsar.getWebServiceAddressTls(),
            pulsar.getSafeBrokerServiceUrl(), pulsar.getBrokerServiceUrlTls());
    lastLoadReport.setProtocols(pulsar.getProtocolDataToAdvertise());
    lastLoadReport.setPersistentTopicsEnabled(pulsar.getConfiguration().isEnablePersistentTopics());
    lastLoadReport.setNonPersistentTopicsEnabled(pulsar.getConfiguration().isEnableNonPersistentTopics());

    loadReportCacheZk = new ZooKeeperDataCache<LoadReport>(pulsar.getLocalZkCache()) {
        @Override
        public LoadReport deserialize(String key, byte[] content) throws Exception {
            return ObjectMapperFactory.getThreadLocal().readValue(content, LoadReport.class);
        }
    };
    loadReportCacheZk.registerListener(this);
    this.dynamicConfigurationCache = new ZooKeeperDataCache<Map<String, String>>(pulsar.getLocalZkCache()) {
        @Override
        public Map<String, String> deserialize(String key, byte[] content) throws Exception {
            return ObjectMapperFactory.getThreadLocal().readValue(content, HashMap.class);
        }
    };
    int entryExpiryTime = (int) pulsar.getConfiguration().getLoadBalancerSheddingGracePeriodMinutes();
    unloadedHotNamespaceCache = CacheBuilder.newBuilder().expireAfterWrite(entryExpiryTime, TimeUnit.MINUTES)
            .build(new CacheLoader<String, Long>() {
                @Override
                public Long load(String key) throws Exception {
                    return System.currentTimeMillis();
                }
            });

    availableActiveBrokers = new ZooKeeperChildrenCache(pulsar.getLocalZkCache(), LOADBALANCE_BROKERS_ROOT);
    availableActiveBrokers.registerListener(new ZooKeeperCacheListener<Set<String>>() {
        @Override
        public void onUpdate(String path, Set<String> data, Stat stat) {
            if (log.isDebugEnabled()) {
                log.debug("Update Received for path {}", path);
            }
            scheduler.submit(SimpleLoadManagerImpl.this::updateRanking);
        }
    });
    this.pulsar = pulsar;
}
 
Example 19
Source File: CondisOS.java    From skUtilities with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean check(Event e) {
  Boolean chk = false;
  switch (ty) {
    case (0):
      chk = SystemUtils.IS_OS_WINDOWS;
      break;
    case (1):
      chk = SystemUtils.IS_OS_MAC;
      break;
    case (2):
      chk = SystemUtils.IS_OS_LINUX;
      break;
    case (3):
      chk = SystemUtils.IS_OS_UNIX;
      break;
    case (4):
      chk = SystemUtils.IS_OS_SOLARIS;
      break;
    case (5):
      chk = SystemUtils.IS_OS_SUN_OS;
      break;
    case (6):
      chk = SystemUtils.IS_OS_HP_UX;
      break;
    case (7):
      chk = SystemUtils.IS_OS_AIX;
      break;
    case (8):
      chk = SystemUtils.IS_OS_IRIX;
      break;
    case (9):
      chk = SystemUtils.IS_OS_FREE_BSD;
      break;
    case (10):
      chk = SystemUtils.IS_OS_OPEN_BSD;
      break;
    case (11):
      chk = SystemUtils.IS_OS_NET_BSD;
      break;
  }
  return (isNegated() ? !chk : chk);
}
 
Example 20
Source File: NativeUtils.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @return true if we're running on a Linux operating system, otherwise false
 */
public static boolean runningOnLinux() {
    return SystemUtils.IS_OS_LINUX;
}