List of usage examples for org.apache.commons.lang SystemUtils IS_OS_WINDOWS
boolean IS_OS_WINDOWS
To view the source code for org.apache.commons.lang SystemUtils IS_OS_WINDOWS.
Click Source Link
Is true
if this is Windows.
The field will return false
if OS_NAME
is null
.
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.//from w w w. j a va 2 s . c om */ 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:svnserver.tester.SvnTesterExternalListener.java
@Nullable private static String findExecutable(@NotNull String name) { final String path = System.getenv("PATH"); if (path != null) { final String suffix = SystemUtils.IS_OS_WINDOWS ? ".exe" : ""; for (String dir : path.split(File.pathSeparator)) { final File file = new File(dir, name + suffix); if (file.exists()) { return file.getAbsolutePath(); }// www. j av a 2 s . com } } return null; }
From source file:utils.CifsNetworkConfig.java
/** * Copy a file to the network-share directory, if the parentdirectorys not on * the windows share these directorys will be created If sending is * sucessfully, input source file will be deleted * /*from w w w .ja v a 2 s . co m*/ * @param deleteSourceFile * @param sourceFile * : File with the subfoder-directories to store on the network share * * @return the Complete windows network path where the sourcefile is copied */ public SmbFile copyFile(File sourceFile, boolean deleteSourceFile) throws IOException { String tempFolder = System.getProperty("java.io.tmpdir"); String relativeDestFilePath = sourceFile.getAbsolutePath(); relativeDestFilePath = relativeDestFilePath .substring(relativeDestFilePath.indexOf(tempFolder) + tempFolder.length()); if (SystemUtils.IS_OS_WINDOWS) { relativeDestFilePath = relativeDestFilePath.replace(File.separatorChar, '/'); } String destinationFilePath = NETWORK_FOLDER + relativeDestFilePath; networkCopy(sourceFile, destinationFilePath, deleteSourceFile); return currentSmbFile; }
From source file:utils.GlobalParameters.java
public static File getShareDirectory() throws FileNotFoundException { if (configProperties == null) { configProperties = loadConfigFile(); }/*from ww w .j a va 2s . c o m*/ 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; }
From source file:VASSAL.build.module.GlobalOptions.java
public void addTo(Buildable parent) { instance = this; final GameModule gm = GameModule.getGameModule(); final Prefs prefs = gm.getPrefs(); // should this moudule use a combined main window? final BooleanConfigurer combConf = new BooleanConfigurer(SINGLE_WINDOW, Resources.getString("GlobalOptions.use_combined"), //$NON-NLS-1$ Boolean.TRUE);//from w ww . j a v a 2 s. co m prefs.addOption(combConf); useSingleWindow = !Boolean.FALSE.equals(combConf.getValue()); // the initial heap size for this module final IntConfigurer initHeapConf = new IntConfigurer(INITIAL_HEAP, Resources.getString("GlobalOptions.initial_heap"), //$NON-NLS-1$ Integer.valueOf(256)); prefs.addOption(initHeapConf); // the maximum heap size for this module final IntConfigurer maxHeapConf = new IntConfigurer(MAXIMUM_HEAP, Resources.getString("GlobalOptions.maximum_heap"), //$NON-NLS-1$ Integer.valueOf(512)); prefs.addOption(maxHeapConf); // Bug 10295: Sometimes, for unknown reasons, the native drag handler // fails to draw images properly on Windows. This lets the user select // the drag handler to use. if (SystemUtils.IS_OS_WINDOWS) { final BooleanConfigurer bug10295Conf = new BooleanConfigurer(BUG_10295, Resources.getString("GlobalOptions.bug10295"), Boolean.FALSE); if (Boolean.TRUE.equals(bug10295Conf.getValue()) && !(PieceMover.AbstractDragHandler .getTheDragHandler() instanceof PieceMover.DragHandlerNoImage)) { PieceMover.AbstractDragHandler.setTheDragHandler(new PieceMover.DragHandlerNoImage()); } bug10295Conf.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { PieceMover.AbstractDragHandler.setTheDragHandler( (Boolean.TRUE.equals(e.getNewValue()) || !DragSource.isDragImageSupported()) ? new PieceMover.DragHandlerNoImage() : new PieceMover.DragHandler()); } }); prefs.addOption(bug10295Conf); } validator = new SingleChildInstance(gm, getClass()); }
From source file:VASSAL.Info.java
public static File getHomeDir() { // FIXME: creation of VASSAL's home should be moved someplace else, possibly // to the new Application class when it's merged with the trunk. if (homeDir == null) { if (SystemUtils.IS_OS_MAC_OSX) { homeDir = new File(System.getProperty("user.home"), "Library/Application Support/VASSAL"); } else if (SystemUtils.IS_OS_WINDOWS) { homeDir = new File(System.getenv("APPDATA") + "/VASSAL"); } else {//from w ww .j a va2s .c o m homeDir = new File(System.getProperty("user.home"), ".VASSAL"); } if (!homeDir.exists()) { // FIXME: What if this fails? This should be done from someplace that // can signal failure properly. homeDir.mkdirs(); } } return homeDir; }
From source file:VASSAL.launch.StartUp.java
protected void initUIProperties() { System.setProperty("swing.aatext", "true"); //$NON-NLS-1$ //$NON-NLS-2$ System.setProperty("swing.boldMetal", "false"); //$NON-NLS-1$ //$NON-NLS-2$ System.setProperty("awt.useSystemAAFontSettings", "on"); //$NON-NLS-1$ //$NON-NLS-2$ if (!SystemUtils.IS_OS_WINDOWS) { // use native LookAndFeel // NB: This must be after Mac-specific properties try {//ww w . j a va 2s.c om UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException e) { ErrorDialog.bug(e); } catch (IllegalAccessException e) { ErrorDialog.bug(e); } catch (InstantiationException e) { ErrorDialog.bug(e); } catch (UnsupportedLookAndFeelException e) { ErrorDialog.bug(e); } } // Ensure consistent behavior in NOT consuming "mousePressed" events // upon a JPopupMenu closing (added for Windows L&F, but others might // also be affected. UIManager.put("PopupMenu.consumeEventOnClose", Boolean.FALSE); }
From source file:VASSAL.preferences.Prefs.java
/** * Initialize visible Global Preferences that are shared between the * Module Manager and the Editor/Player. * *//*from w w w . ja va 2 s . com*/ public static void initSharedGlobalPrefs() { getGlobalPrefs(); // Option to disable D3D pipeline if (SystemUtils.IS_OS_WINDOWS) { final BooleanConfigurer d3dConf = new BooleanConfigurer(DISABLE_D3D, Resources.getString("Prefs.disable_d3d"), Boolean.FALSE); globalPrefs.addOption(d3dConf); } final BooleanConfigurer wizardConf = new BooleanConfigurer(WizardSupport.WELCOME_WIZARD_KEY, Resources.getString("WizardSupport.ShowWizard"), Boolean.TRUE); globalPrefs.addOption(wizardConf); }
From source file:VASSAL.tools.BrowserSupport.java
public static void openURL(String url) { //// www .ja va2 s . c om // This method is irritatingly complex, because: // * There is no java.awt.Desktop in Java 1.5. // * java.awt.Desktop seems not to work sometimes on Windows. // * BrowserLauncher failes sometimes on Linux, and isn't supported // anymore. // if (!SystemUtils.IS_JAVA_1_5) { if (Desktop.isDesktopSupported()) { final Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.BROWSE)) { try { desktop.browse(new URI(url)); return; } catch (IOException e) { // We ignore this on Windows, because Desktop seems flaky if (!SystemUtils.IS_OS_WINDOWS) { ReadErrorDialog.error(e, url); return; } } catch (IllegalArgumentException e) { ErrorDialog.bug(e); return; } catch (URISyntaxException e) { ErrorDialog.bug(e); return; } } } } if (browserLauncher != null) { browserLauncher.openURLinBrowser(url); } else { ErrorDialog.show("BrowserSupport.unable_to_launch", url); } }
From source file:VASSAL.tools.filechooser.FileChooser.java
/** * Creates a FileChooser appropriate for the user's OS. * * @param parent//from w w w. j ava 2s . c om * The Component over which the FileChooser should appear. * @param prefs * A FileConfigure that stores the preferred starting directory of the FileChooser in preferences */ public static FileChooser createFileChooser(Component parent, DirectoryConfigurer prefs, int mode) { FileChooser fc; if (SystemUtils.IS_OS_MAC_OSX) { // Mac has a good native file dialog fc = new NativeFileChooser(parent, prefs, mode); } else if (mode == FILES_ONLY && SystemUtils.IS_OS_WINDOWS) { // Window has a good native file dialog, but it doesn't support selecting directories fc = new NativeFileChooser(parent, prefs, mode); } else { // Linux's native dialog is inferior to Swing's fc = new SwingFileChooser(parent, prefs, mode); } return fc; }