Logo Search packages:      
Sourcecode: ooeclipseintegration version File versions  Download package

static Process org::openoffice::ide::eclipse::core::OOEclipsePlugin::runToolWithEnv ( IUnoidlProject  project,
String  shellCommand,
String[]  env,
IProgressMonitor  monitor 
) [inline, static]

Create a process for the given shell command. This process will be created with the project parameters such as it's SDK and location path

Parameters:
project the UNO-IDL project on which to run the tool
shellCommand the shell command to execute the tool
env tool environement variable
monitor a process monitor to watch the tool launching
Returns:
the process executing the tool

Definition at line 316 of file OOEclipsePlugin.java.

References org::openoffice::ide::eclipse::core::preferences::IOOo::getLibsPath().

Referenced by runTool().

                                                                              {
            
            Process process = null;
            
            try {
                  ISdk sdk = project.getSdk();
                  IOOo ooo = project.getOOo();
                  
                  if (null != sdk && null != ooo){
                        
                        // Get local references to the SDK used members
                        String sdkHome = sdk.getHome();
                        
                        String pathSeparator = System.getProperty("path.separator"); //$NON-NLS-1$
                        
                        String binPath = null;
                        String[] vars = env;
                        String[] command = new String[3];;
                        
                        // Fetch the OS family
                        String osName = System.getProperty("os.name").toLowerCase(); //$NON-NLS-1$
                        
                        
                        // Create the exec parameters depending on the OS
                        if (osName.startsWith("windows")){ //$NON-NLS-1$
                              String sdkWinHome = new Path(sdkHome).toOSString();
                              
                              binPath = sdkWinHome + "\\windows\\bin\\";  //$NON-NLS-1$
                              
                              // Definining path variables
                              Path oooLibsPath = new Path(ooo.getLibsPath());
                              vars = addEnv(env, "PATH", binPath + pathSeparator +  //$NON-NLS-1$
                                          oooLibsPath.toOSString(), pathSeparator);
                              
                              // Defining the command
                              
                              if (osName.startsWith("windows 9")){ //$NON-NLS-1$
                                    command[0] = "command.com"; //$NON-NLS-1$
                              } else {
                                    command[0] = "cmd.exe"; //$NON-NLS-1$
                              }
                              
                              command[1] = "/C"; //$NON-NLS-1$
                              command[2] = shellCommand;
                              
                              
                        } else if (osName.equals("linux") || osName.equals("solaris") ||  //$NON-NLS-1$ //$NON-NLS-2$
                                    osName.equals("sun os")) { //$NON-NLS-1$
                              
                              // An UN*X platform
                              
                              // Determine the platform
                              String platform = null;
                              
                              if (osName.equals("linux")){ //$NON-NLS-1$
                                    platform = "/linux"; //$NON-NLS-1$
                              } else {
                                    String osArch = System.getProperty("os.arch"); //$NON-NLS-1$
                                    if (osArch.equals("sparc")) { //$NON-NLS-1$
                                          platform = "/solsparc"; //$NON-NLS-1$
                                          
                                    } else if (osArch.equals("x86")) { //$NON-NLS-1$
                                          platform = "/solintel"; //$NON-NLS-1$
                                    }
                              }
                              
                              if (null != platform){
                                    
                                    // The platform is one supported by a SDK
                                    binPath = sdkHome + platform + "/bin"; //$NON-NLS-1$

                                    String[] tmpVars = addEnv(env, "PATH",  //$NON-NLS-1$
                                                sdkHome + platform + "/bin", pathSeparator); //$NON-NLS-1$
                                    vars = addEnv(tmpVars, "LD_LIBRARY_PATH", //$NON-NLS-1$
                                                ooo.getLibsPath(), pathSeparator);
                                    
                                    // Set the command
                                    command[0] = "sh"; //$NON-NLS-1$
                                    command[1] = "-c"; //$NON-NLS-1$
                                    command[2] = shellCommand;
                              }
                              
                        } else {
                              // Unmanaged OS
                              PluginLogger.error(
                                          Messages.getString("OOEclipsePlugin.InvalidSdkError"), null); //$NON-NLS-1$
                        }
                        
                        // Run only if the OS and ARCH are valid for the SDK
                        if (null != vars && null != command){
                              
                              File projectFile = project.getProjectPath().toFile();
                              process = Runtime.getRuntime().exec(command, vars, projectFile);
                        }
                        
                  }
                  
            } catch (IOException e) {
                  // Error while launching the process 
                  
                  MessageDialog dialog = new MessageDialog(
                              OOEclipsePlugin.getDefault().getWorkbench().
                                    getActiveWorkbenchWindow().getShell(),
                              Messages.getString("OOEclipsePlugin.PluginError"), //$NON-NLS-1$
                              null,
                              Messages.getString("OOEclipsePlugin.ProcessError"), //$NON-NLS-1$
                              MessageDialog.ERROR,
                              new String[]{Messages.getString("OOEclipsePlugin.Ok")}, 0); //$NON-NLS-1$
                  dialog.setBlockOnOpen(true);
                  dialog.create();
                  dialog.open();
                  
            } catch (SecurityException e) {
                  // SubProcess creation unauthorized
                  
                  MessageDialog dialog = new MessageDialog(
                              OOEclipsePlugin.getDefault().getWorkbench().
                                          getActiveWorkbenchWindow().getShell(),
                              Messages.getString("OOEclipsePlugin.PluginError"), //$NON-NLS-1$
                              null,
                              Messages.getString("OOEclipsePlugin.ProcessError"), //$NON-NLS-1$
                              MessageDialog.ERROR,
                              new String[]{Messages.getString("OOEclipsePlugin.Ok")},     0); //$NON-NLS-1$
                  dialog.setBlockOnOpen(true);
                  dialog.create();
                  dialog.open();
            }
            
            return process;
      }


Generated by  Doxygen 1.6.0   Back to index