Example usage for org.apache.commons.lang SystemUtils IS_OS_LINUX

List of usage examples for org.apache.commons.lang SystemUtils IS_OS_LINUX

Introduction

In this page you can find the example usage for org.apache.commons.lang SystemUtils IS_OS_LINUX.

Prototype

boolean IS_OS_LINUX

To view the source code for org.apache.commons.lang SystemUtils IS_OS_LINUX.

Click Source Link

Document

Is true if this is Linux.

The field will return false if OS_NAME is null.

Usage

From source file:results.report.java

/**
 * Return an HTML String with System information...
 * @return /*from w ww  .j  av a 2s.co m*/
 */
public String printSystemInfo() {
    StringBuilder st = new StringBuilder();
    st.append("<br>Compiler found: " + config.isCompilerFound() + "<br>");
    st.append("Developper mode: " + config.isDevelopperMode() + "<br>");
    st.append("Windows :" + SystemUtils.IS_OS_WINDOWS + "<br>");
    st.append("MacOSX :" + SystemUtils.IS_OS_MAC_OSX + "<br>");
    st.append("Linux :" + SystemUtils.IS_OS_LINUX + "<br>");
    st.append("Memory: " + PrintMemory() + "<br >");
    return st.toString();
}

From source file:sh.tak.appbundler.CreateApplicationBundleMojo.java

/**
 * Bundle project as a Mac OS X application bundle.
 *
 * @throws MojoExecutionException If an unexpected error occurs during
 * packaging of the bundle.//  ww  w .  ja va 2  s  .  com
 */
public void execute() throws MojoExecutionException {

    // 1. Create and set up directories
    getLog().info("Creating and setting up the bundle directories");
    buildDirectory.mkdirs();

    File bundleDir = new File(buildDirectory, bundleName + ".app");
    bundleDir.mkdirs();

    File contentsDir = new File(bundleDir, "Contents");
    contentsDir.mkdirs();

    File resourcesDir = new File(contentsDir, "Resources");
    resourcesDir.mkdirs();

    File javaDirectory = new File(contentsDir, "Java");
    javaDirectory.mkdirs();

    File macOSDirectory = new File(contentsDir, "MacOS");
    macOSDirectory.mkdirs();

    // 2. Copy in the native java application stub
    getLog().info("Copying the native Java Application Stub");
    File launcher = new File(macOSDirectory, javaLauncherName);
    launcher.setExecutable(true);

    FileOutputStream launcherStream = null;
    try {
        launcherStream = new FileOutputStream(launcher);
    } catch (FileNotFoundException ex) {
        throw new MojoExecutionException("Could not copy file to directory " + launcher, ex);
    }

    InputStream launcherResourceStream = this.getClass().getResourceAsStream(javaLauncherName);
    try {
        IOUtil.copy(launcherResourceStream, launcherStream);
    } catch (IOException ex) {
        throw new MojoExecutionException(
                "Could not copy file " + javaLauncherName + " to directory " + macOSDirectory, ex);
    }

    // 3.Copy icon file to the bundle if specified
    if (iconFile != null) {
        File f = searchFile(iconFile);

        if (f != null && f.exists() && f.isFile()) {
            getLog().info("Copying the Icon File");
            try {
                FileUtils.copyFileToDirectory(f, resourcesDir);
            } catch (IOException ex) {
                throw new MojoExecutionException("Error copying file " + iconFile + " to " + resourcesDir, ex);
            }
        }
    }

    // 4. Resolve and copy in all dependencies from the pom
    getLog().info("Copying dependencies");
    List<String> files = copyDependencies(javaDirectory);
    if (additionalBundledClasspathResources != null && !additionalBundledClasspathResources.isEmpty()) {
        files.addAll(copyAdditionalBundledClasspathResources(javaDirectory, "lib",
                additionalBundledClasspathResources));
    }

    // 5. Check if JRE should be embedded. Check JRE path. Copy JRE
    if (jrePath != null) {
        File f = new File(jrePath);
        if (f.exists() && f.isDirectory()) {
            // Check if the source folder is a jdk-home
            File pluginsDirectory = new File(contentsDir, "PlugIns/JRE/Contents/Home/jre");
            pluginsDirectory.mkdirs();

            File sourceFolder = new File(jrePath, "Contents/Home");
            if (new File(jrePath, "Contents/Home/jre").exists()) {
                sourceFolder = new File(jrePath, "Contents/Home/jre");
            }

            try {
                getLog().info("Copying the JRE Folder from : [" + sourceFolder + "] to PlugIn folder: ["
                        + pluginsDirectory + "]");
                FileUtils.copyDirectoryStructure(sourceFolder, pluginsDirectory);
                File binFolder = new File(pluginsDirectory, "bin");
                //Setting execute permissions on executables in JRE
                for (String filename : binFolder.list()) {
                    new File(binFolder, filename).setExecutable(true, false);
                }

                new File(pluginsDirectory, "lib/jspawnhelper").setExecutable(true, false);
                embeddJre = true;
            } catch (IOException ex) {
                throw new MojoExecutionException("Error copying folder " + f + " to " + pluginsDirectory, ex);
            }
        } else {
            getLog().warn("JRE not found check jrePath setting in pom.xml");
        }
    }

    // 6. Create and write the Info.plist file
    getLog().info("Writing the Info.plist file");
    File infoPlist = new File(bundleDir, "Contents" + File.separator + "Info.plist");
    this.writeInfoPlist(infoPlist, files);

    // 7. Copy specified additional resources into the top level directory
    getLog().info("Copying additional resources");
    if (additionalResources != null && !additionalResources.isEmpty()) {
        this.copyResources(buildDirectory, additionalResources);
    }

    // 7. Make the stub executable
    if (!SystemUtils.IS_OS_WINDOWS) {
        getLog().info("Making stub executable");
        Commandline chmod = new Commandline();
        try {
            chmod.setExecutable("chmod");
            chmod.createArgument().setValue("755");
            chmod.createArgument().setValue(launcher.getAbsolutePath());

            chmod.execute();
        } catch (CommandLineException e) {
            throw new MojoExecutionException("Error executing " + chmod + " ", e);
        }
    } else {
        getLog().warn("The stub was created without executable file permissions for UNIX systems");
    }

    // 8. Create the DMG file
    if (generateDiskImageFile) {
        if (SystemUtils.IS_OS_MAC_OSX) {
            getLog().info("Generating the Disk Image file");
            Commandline dmg = new Commandline();
            try {
                // user wants /Applications symlink in the resulting disk image
                if (includeApplicationsSymlink) {
                    createApplicationsSymlink();
                }
                dmg.setExecutable("hdiutil");
                dmg.createArgument().setValue("create");
                dmg.createArgument().setValue("-srcfolder");
                dmg.createArgument().setValue(buildDirectory.getAbsolutePath());
                dmg.createArgument().setValue(diskImageFile.getAbsolutePath());

                try {
                    dmg.execute().waitFor();
                } catch (InterruptedException ex) {
                    throw new MojoExecutionException(
                            "Thread was interrupted while creating DMG " + diskImageFile, ex);
                } finally {
                    if (includeApplicationsSymlink) {
                        removeApplicationsSymlink();
                    }
                }
            } catch (CommandLineException ex) {
                throw new MojoExecutionException("Error creating disk image " + diskImageFile, ex);
            }

            if (diskImageInternetEnable) {
                getLog().info("Enabling the Disk Image file for internet");
                try {
                    Commandline internetEnableCommand = new Commandline();

                    internetEnableCommand.setExecutable("hdiutil");
                    internetEnableCommand.createArgument().setValue("internet-enable");
                    internetEnableCommand.createArgument().setValue("-yes");
                    internetEnableCommand.createArgument().setValue(diskImageFile.getAbsolutePath());

                    internetEnableCommand.execute();
                } catch (CommandLineException ex) {
                    throw new MojoExecutionException("Error internet enabling disk image: " + diskImageFile,
                            ex);
                }
            }
            projectHelper.attachArtifact(project, "dmg", null, diskImageFile);
        }
        if (SystemUtils.IS_OS_LINUX) {
            getLog().info("Generating the Disk Image file");
            Commandline linux_dmg = new Commandline();
            try {
                linux_dmg.setExecutable("genisoimage");
                linux_dmg.createArgument().setValue("-V");
                linux_dmg.createArgument().setValue(bundleName);
                linux_dmg.createArgument().setValue("-D");
                linux_dmg.createArgument().setValue("-R");
                linux_dmg.createArgument().setValue("-apple");
                linux_dmg.createArgument().setValue("-no-pad");
                linux_dmg.createArgument().setValue("-o");
                linux_dmg.createArgument().setValue(diskImageFile.getAbsolutePath());
                linux_dmg.createArgument().setValue(buildDirectory.getAbsolutePath());

                try {
                    linux_dmg.execute().waitFor();
                } catch (InterruptedException ex) {
                    throw new MojoExecutionException(
                            "Thread was interrupted while creating DMG " + diskImageFile, ex);
                }
            } catch (CommandLineException ex) {
                throw new MojoExecutionException(
                        "Error creating disk image " + diskImageFile + " genisoimage probably missing", ex);
            }
            projectHelper.attachArtifact(project, "dmg", null, diskImageFile);

        } else {
            getLog().warn("Disk Image file cannot be generated in non Mac OS X and Linux environments");
        }
    }

    getLog().info("App Bundle generation finished");
}

From source file:util.PosixComplianceUtil.java

private boolean isMostlyPosixCompliant() {
    return SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_UNIX;
}

From source file:utils.GlobalParameters.java

public static File getShareDirectory() throws FileNotFoundException {

    if (configProperties == null) {
        configProperties = loadConfigFile();
    }//from   w ww.  j a  va 2s  .  c  om

    String hostIP = configProperties.getProperty("serverIP");
    String shareName = configProperties.getProperty("shareName");
    File shareDir = null;

    try {
        if (SystemUtils.IS_OS_WINDOWS) {

            shareDir = new File(File.separator + File.separator + hostIP + File.separator + shareName);
            log.info("Setting ShareDirectory on Windows OS to file: " + shareDir.getAbsolutePath());

        } else {
            if (SystemUtils.IS_OS_LINUX) {
                shareDir = new File(shareName);
                log.info("Setting mountet ShareDirectory on Linux OS to file: " + shareDir.getAbsolutePath());
            } else {
                log.error("No Share-Directory from Properties file with serverIP: " + hostIP
                        + " and shareName: " + shareName + " detected.");
                throw new FileNotFoundException("SystemUtils cannot determine OS");
            }
        }
    } catch (NullPointerException nullPointer) {
        throw new FileNotFoundException("Cannot instanciare shareDir-File Object from configProperties:"
                + "\nhostIP:\t" + hostIP + "\tshareName:\t" + shareName);
    }
    return shareDir;
}