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

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

Introduction

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

Prototype

boolean IS_OS_WINDOWS

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

Click Source Link

Document

Is true if this is Windows.

The field will return false if OS_NAME is null.

Usage

From source file:org.openoffice.maven.ConfigurationManagerTest.java

/**
 * Test method for {@link ConfigurationManager#runCommand(String)}.
 */// w w w .j  a  v  a 2s.  c  o  m
@Test
public synchronized void testRunCommand() throws CommandLineException {
    String command = SystemUtils.IS_OS_WINDOWS ? "dir" : "date";
    log.info("running " + command + "...");
    int ret = ConfigurationManager.runCommand(command);
    assertEquals(0, ret);
}

From source file:org.openoffice.maven.Environment.java

private static File guessOfficeHome() {
    File home = getenvAsFile(OFFICE_HOME);
    if (home != null) {
        return home;
    }//  w  w  w. j a  va  2 s. co m
    home = guessOfficeHomeFromPATH();
    if (home != null) {
        return home;
    }
    if (SystemUtils.IS_OS_LINUX) {
        home = tryDirs("/opt/openoffice.org3", "/usr/lib/openoffice");
    } else if (SystemUtils.IS_OS_MAC) {
        home = tryDirs("/Applications/OpenOffice.org.app", "/opt/ooo/OpenOffice.org.app");
    } else if (SystemUtils.IS_OS_WINDOWS) {
        home = tryDirs("C:/programs/OpenOffice.org3", "C:/Programme/OpenOffice.org3",
                "C:/programs/OpenOffice.org 3", "C:/Programme/OpenOffice.org 3",
                "C:/Program Files (x86)/OpenOffice.org 3");
    } else {
        home = tryDirs("/opt/openoffice.org3");
    }
    if (home == null) {
        getLog().debug("office home not found - must be set via configuration '<ooo>...</ooo>'");
    }
    return home;
}

From source file:org.openoffice.maven.Environment.java

private static File guessOoSdkHome() {
    File home = getenvAsFile(OO_SDK_HOME);
    if (home != null) {
        return home;
    }//from   w ww  . ja v  a  2 s.  c o m
    if (SystemUtils.IS_OS_LINUX) {
        home = tryDirs("/opt/openoffice.org/basis3.2/sdk", "/usr/lib/openoffice/basis3.2/sdk");
    } else if (SystemUtils.IS_OS_MAC) {
        home = tryDirs("/Applications/OpenOffice.org3.2_SDK", "/opt/ooo/OpenOffice.org3.2_SDK");
    } else if (SystemUtils.IS_OS_WINDOWS) {
        home = tryDirs(officeHome + "/Basis/sdk", "C:/Programme/OOsdk", "C:/sdk/OpenOffice.org_3.2_SDK/sdk",
                "C:/OO_SDK/sdk");
    } else {
        home = FileFinder.tryDirs(new File(officeHome, "Basis/sdk"),
                new File("/opt/openoffice.org/basis3.2/sdk"));
    }
    if (home == null) {
        getLog().debug("SDK home not found - must be set via configuration '<sdk>...</sdk>'");
    }
    return home;
}

From source file:org.openoffice.maven.Environment.java

private static String getBaseDirName() {
    if (SystemUtils.IS_OS_MAC) {
        return "Contents/basis-link";
    } else if (SystemUtils.IS_OS_WINDOWS) {
        return "Basis";
    } else {//w w  w  .j  a  v  a 2  s.c  om
        return "basis-link";
    }
}

From source file:org.openoffice.maven.Environment.java

/**
 * Returns the home directory of URE installation directory
 * (OO_SDK_URE_HOME).//from   w  w  w. ja v  a2  s. c om
 * 
 * @return URE home directory
 */
public static synchronized File getOoSdkUreHome() {
    if (ooSdkUreHome == null) {
        if (SystemUtils.IS_OS_WINDOWS) {
            ooSdkUreHome = FileFinder.tryDirs(new File(getOfficeHome(), "URE"), getOoSdkHome());
        } else {
            ooSdkUreHome = new File(getOfficeBaseHome(), "ure-link");
        }
    }
    return ooSdkUreHome;
}

From source file:org.openoffice.maven.Environment.java

/**
 * Returns the library directory of OpenOffice SDK (OO_SDK_URE_LIB_DIR).
 * This can be uses as path for DYLD_LIBRARY_PATH (Mac OS X).
 * /*from w  ww  .  ja v  a 2  s  .co m*/
 * @return directory with dynamic libraries
 */
public static synchronized File getOoSdkUreLibDir() {
    if (SystemUtils.IS_OS_WINDOWS) {
        return new File(getOoSdkUreHome(), "bin");
    } else {
        return new File(getOoSdkUreHome(), "lib");
    }
}

From source file:org.openoffice.maven.EnvironmentTest.java

/**
 * Test method for//  ww  w . j  a va 2  s . com
 * {@link org.openoffice.maven.Environment#getOfficeBaseHome()}.
 */
@Test
public void testGetOfficeBaseHome() {
    if (!SystemUtils.IS_OS_WINDOWS) {
        File dir = Environment.getOfficeBaseHome();
        assertTrue(dir + " is no directory", dir.isDirectory());
    }
}

From source file:org.ostara.cmd.BaseCmdLineCmd.java

protected void executeCommand(ICmdResult result, List<String> cmd, String cmdExecDir, boolean wait) {
    Process p = null;//from  w ww  . java2  s . co  m
    ProcessCall processCall = null;
    ProcessCallOutput output = null;

    List<String> cmdLine = new ArrayList<String>();

    // For windows system
    if (SystemUtils.IS_OS_WINDOWS) {
        cmdLine.add("cmd.exe");
        cmdLine.add("/C");
    }

    cmdLine.addAll(cmd);

    int retry = 0;
    Exception error = null;
    while (retry < 3) {
        try {

            ProcessBuilder processBuilder = new ProcessBuilder();
            processBuilder.redirectErrorStream(true);
            processBuilder.directory(new File(cmdExecDir));

            logger.info("Executing process: " + cmdLine);

            p = processBuilder.command(cmdLine).start();
            if (wait) {
                processCall = new ProcessCall(p);
                output = processCall.call();
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            error = e;
            retry++;
            continue;
        }
        break;
    }

    if (output == null) {
        result.setException(error);
    } else if (output.exitValue != 0) {
        result.setException(new RuntimeException(
                "Failed to execute command(%" + getClass().getName() + "%), rtn value:" + output.exitValue));
    } else {
        result.setMessage(output.output);
    }
}

From source file:org.overture.ide.plugins.codegen.commands.Vdm2JavaCommand.java

public Object execute(ExecutionEvent event) throws ExecutionException {
    // Validate project
    ISelection selection = HandlerUtil.getCurrentSelection(event);

    if (!(selection instanceof IStructuredSelection)) {
        return null;
    }// www  .j  ava  2  s.  c  o m

    IStructuredSelection structuredSelection = (IStructuredSelection) selection;

    Object firstElement = structuredSelection.getFirstElement();

    if (!(firstElement instanceof IProject)) {
        return null;
    }

    final IProject project = (IProject) firstElement;
    final IVdmProject vdmProject = (IVdmProject) project.getAdapter(IVdmProject.class);

    try {
        Settings.release = vdmProject.getLanguageVersion();
        Settings.dialect = vdmProject.getDialect();
    } catch (CoreException e) {
        Activator.log("Problems setting VDM language version and dialect", e);
        e.printStackTrace();
    }

    CodeGenConsole.GetInstance().activate();

    deleteMarkers(project);

    final IVdmModel model = vdmProject.getModel();

    if (!PluginVdm2JavaUtil.isSupportedVdmDialect(vdmProject)) {
        CodeGenConsole.GetInstance().println("Project : " + project.getName()
                + " is not supported by the Java code generator. Currently, VDM++ is the only supported dialect.");
        return null;
    }

    if (model == null) {
        CodeGenConsole.GetInstance().println("Could not get model for project: " + project.getName());
        return null;
    }

    if (!model.isParseCorrect()) {
        CodeGenConsole.GetInstance().println("Could not parse model: " + project.getName());
        return null;
    }

    if (!model.isTypeChecked()) {
        VdmTypeCheckerUi.typeCheck(HandlerUtil.getActiveShell(event), vdmProject);
    }

    if (!model.isTypeCorrect()) {
        CodeGenConsole.GetInstance().println("Could not type check model: " + project.getName());
        return null;
    }

    Job codeGenerate = new Job("Code generate") {
        @Override
        protected IStatus run(IProgressMonitor monitor) {
            // Begin code generation
            final JavaCodeGen vdm2java = new JavaCodeGen();

            Preferences preferences = InstanceScope.INSTANCE.getNode(ICodeGenConstants.PLUGIN_ID);

            boolean generateCharSeqsAsStrings = preferences.getBoolean(
                    ICodeGenConstants.GENERATE_CHAR_SEQUENCES_AS_STRINGS,
                    ICodeGenConstants.GENERATE_CHAR_SEQUENCES_AS_STRING_DEFAULT);
            boolean generateConcMechanisms = preferences.getBoolean(
                    ICodeGenConstants.GENERATE_CONCURRENCY_MECHANISMS,
                    ICodeGenConstants.GENERATE_CONCURRENCY_MECHANISMS_DEFAULT);

            IRSettings irSettings = new IRSettings();
            irSettings.setCharSeqAsString(generateCharSeqsAsStrings);
            irSettings.setGenerateConc(generateConcMechanisms);

            boolean disableCloning = preferences.getBoolean(ICodeGenConstants.DISABLE_CLONING,
                    ICodeGenConstants.DISABLE_CLONING_DEFAULT);

            JavaSettings javaSettings = new JavaSettings();
            javaSettings.setDisableCloning(disableCloning);
            List<String> classesToSkip = PluginVdm2JavaUtil.getClassesToSkip();
            javaSettings.setClassesToSkip(classesToSkip);

            vdm2java.setSettings(irSettings);
            vdm2java.setJavaSettings(javaSettings);

            try {
                CodeGenConsole.GetInstance().clearConsole();
                CodeGenConsole.GetInstance().println("Starting VDM++ to Java code generation...\n");

                File outputFolder = PluginVdm2JavaUtil.getOutputFolder(vdmProject);

                // Clean folder with generated Java code
                GeneralUtils.deleteFolderContents(outputFolder);

                // Generate user specified classes
                List<IVdmSourceUnit> sources = model.getSourceUnits();
                List<SClassDefinition> mergedParseLists = PluginVdm2JavaUtil.mergeParseLists(sources);
                GeneratedData generatedData = vdm2java.generateJavaFromVdm(mergedParseLists);

                outputUserSpecifiedSkippedClasses(classesToSkip);
                outputSkippedClasses(generatedData.getSkippedClasses());

                File javaOutputFolder = new File(outputFolder,
                        PluginVdm2JavaUtil.CODEGEN_RUNTIME_SRC_FOLDER_NAME);

                try {
                    vdm2java.generateJavaSourceFiles(javaOutputFolder, generatedData.getClasses());
                } catch (Exception e) {
                    CodeGenConsole.GetInstance()
                            .printErrorln("Problems saving the code generated Java source files to disk.");
                    CodeGenConsole.GetInstance().printErrorln("Try to run Overture with write permissions.\n");

                    if (SystemUtils.IS_OS_WINDOWS) {
                        CodeGenConsole.GetInstance().println("Operating System: Windows.");
                        CodeGenConsole.GetInstance().println(
                                "If you installed Overture in a location such as \"C:\\Program Files\\Overture\"");
                        CodeGenConsole.GetInstance().println(
                                "you may need to give Overture permissions to write to the file system. You can try");
                        CodeGenConsole.GetInstance()
                                .println("run Overture as administrator and see if this solves the problem.");
                    }

                    return Status.CANCEL_STATUS;
                }

                File libFolder = new File(outputFolder, PluginVdm2JavaUtil.CODEGEN_RUNTIME_LIB_FOLDER_NAME);
                try {
                    PluginVdm2JavaUtil.copyCodeGenFile(PluginVdm2JavaUtil.CODEGEN_RUNTIME_BIN_FILE_NAME,
                            libFolder);
                    outputRuntimeBinaries(libFolder);
                } catch (Exception e) {
                    CodeGenConsole.GetInstance()
                            .printErrorln("Problems copying the Java code generator runtime library to "
                                    + outputFolder.getAbsolutePath());
                    CodeGenConsole.GetInstance().printErrorln("Reason: " + e.getMessage());
                }

                try {
                    PluginVdm2JavaUtil.copyCodeGenFile(PluginVdm2JavaUtil.CODEGEN_RUNTIME_SOURCES_FILE_NAME,
                            libFolder);
                    outputRuntimeSources(libFolder);
                } catch (Exception e) {
                    CodeGenConsole.GetInstance()
                            .printErrorln("Problems copying the Java code generator runtime library sources to "
                                    + outputFolder.getAbsolutePath());
                    CodeGenConsole.GetInstance().printErrorln("Reason: " + e.getMessage());
                }

                try {
                    PluginVdm2JavaUtil.copyCodeGenFile(
                            PluginVdm2JavaUtil.ECLIPSE_RES_FILES_FOLDER_NAME + "/"
                                    + PluginVdm2JavaUtil.ECLIPSE_PROJECT_TEMPLATE_FILE_NAME,
                            PluginVdm2JavaUtil.ECLIPSE_PROJECT_FILE_NAME, outputFolder);
                    PluginVdm2JavaUtil.copyCodeGenFile(
                            PluginVdm2JavaUtil.ECLIPSE_RES_FILES_FOLDER_NAME + "/"
                                    + PluginVdm2JavaUtil.ECLIPSE_CLASSPATH_TEMPLATE_FILE_NAME,
                            PluginVdm2JavaUtil.ECLIPSE_CLASSPATH_FILE_NAME, outputFolder);

                    GeneralCodeGenUtils.replaceInFile(
                            new File(outputFolder, PluginVdm2JavaUtil.ECLIPSE_PROJECT_FILE_NAME), "%s",
                            project.getName());

                    CodeGenConsole.GetInstance()
                            .println("Generated Eclipse project with Java generated code.\n");

                } catch (Exception e) {
                    e.printStackTrace();
                    CodeGenConsole.GetInstance().printErrorln(
                            "Problems generating the eclipse project with the generated Java code");
                    CodeGenConsole.GetInstance().printErrorln("Reason: " + e.getMessage());
                }

                outputUserspecifiedModules(javaOutputFolder, generatedData.getClasses());

                // Quotes generation
                outputQuotes(vdmProject, new File(javaOutputFolder, PluginVdm2JavaUtil.QUOTES_FOLDER), vdm2java,
                        generatedData.getQuoteValues());

                // Renaming of variables shadowing other variables
                outputRenamings(generatedData.getAllRenamings());

                InvalidNamesResult invalidNames = generatedData.getInvalidNamesResult();

                if (invalidNames != null && !invalidNames.isEmpty()) {
                    handleInvalidNames(invalidNames);
                }

                int noOfClasses = generatedData.getClasses().size();

                String msg = String.format("...finished Java code generation (generated %s %s).", noOfClasses,
                        noOfClasses == 1 ? "class" : "classes");

                CodeGenConsole.GetInstance().println(msg);

                project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());

            } catch (UnsupportedModelingException ex) {
                handleUnsupportedModeling(ex);
            } catch (AnalysisExceptionCG ex) {
                CodeGenConsole.GetInstance().println("Could not code generate VDM model: " + ex.getMessage());
            } catch (Exception ex) {
                handleUnexpectedException(ex);
            }

            return Status.OK_STATUS;
        }
    };

    codeGenerate.schedule();

    return null;
}

From source file:org.pentaho.di.core.ConstTest.java

@Test
public void testQuoteCharByOS() {
    assertEquals(SystemUtils.IS_OS_WINDOWS ? "\"" : "'", Const.getQuoteCharByOS());
}