private boolean skeletonmaker()

in netbeansintegration/tags/4.0.5.alpha/src/org/openoffice/extensions/util/ProjectCreator.java [509:709]


    private boolean skeletonmaker(FileObject[] idlFileObjects, String[] dumpTypes) throws IOException {
        boolean executeWorked = true; // return variable; set to false in case of error
        String projDir = ((File)wiz.getProperty("projdir")).getCanonicalPath(); // NOI18N
        String platform = PlatformInfo.getPlatformBinDir();
        String sdkPath = (String)wiz.getProperty("SdkPath"); // NOI18N
        String sdkBinPath = sdkPath.concat(File.separator).concat("bin"); // NOI18N
        String ureBinPath = OpenOfficeLocation.getOpenOfficeLocation().getUreBinPath();
        // np exception? should not happen this far in the code
        if (OpenOfficeLocation.getOpenOfficeLocation().isThreeLayerOffice()) {
            sdkBinPath = sdkPath.concat(File.separator).concat("bin"); // NOI18N
            ureBinPath = OpenOfficeLocation.getOpenOfficeLocation().getUreBinPath();
        }               
        
        // adapt path for Ubuntu script execution of sdk tools
//        String soProgramPath = ((String)wiz.getProperty("OfficePath")).concat(File.separator).concat(PlatformInfo.getOfficeProgramDir()); // NOI18N
//        String soUrl = (soProgramPath.startsWith("/") ? "file://" : "file:///").concat(soProgramPath.replace('\\', '/')); // NOI18N
        String soPath = "";
        String[] typesRdbPath = null;
        OpenOfficeLocation loc = OpenOfficeLocation.getOpenOfficeLocation();
        if (loc != null) {
            soPath = loc.getPathVariable();
            if (!PlatformInfo.isWindows()) {
                soPath = soPath.concat(File.pathSeparator).concat("/usr/bin"); // NOI18N
            }
            typesRdbPath = loc.getUnoTypesPath();
        }
        else {
            typesRdbPath = new String[0];
        }

        
        // tempdir is needed for idlc
        Map<String,String> p = new HashMap<String,String>(5);
        p.put(ScriptExecutor.PATH, soPath);
        p.put(ScriptExecutor.LD_LIBRARY_PATH, soPath);
        p.put(ScriptExecutor.DYLD_LIBRARY_PATH, soPath);
        p.put(ScriptExecutor.TEMP, System.getProperty("java.io.tmpdir"));
        p.put(ScriptExecutor.TMP, System.getProperty("java.io.tmpdir"));
        ScriptExecutor.setEnv(p); // NOI18N
        
        // don't do all this if no own idls are defined.
        String rdbPath = null;
        if (idlFileObjects.length != 0) {
            // idlc
            String srcIdlPath = projDir.concat(File.separator).concat("src"); // NOI18N
            String sdkIdlIncludes =  sdkPath.concat(File.separator).concat("idl").concat(";").concat(srcIdlPath); // NOI18N

            String urdOutPath = projDir.concat(File.separator).concat("build").concat(File.separator)
            .concat("idl").concat(File.separator).concat("urd"); // NOI18N

            String[] command = new String[3 + idlFileObjects.length];
            command[0] = sdkBinPath.concat(File.separator).concat("idlc"); // NOI18N
            command[1] = "-I".concat(sdkIdlIncludes); // NOI18N
            command[2] = "-O".concat(urdOutPath); // NOI18N
            for (int i=0; i<idlFileObjects.length; i++) {
                command[3+i] = FileUtil.toFile(idlFileObjects[i]).getCanonicalPath();
            }

            ScriptExecutor.executeScript(command, (File)wiz.getProperty("projdir")); // NOI18N
            LogWriter.getLogWriter().log(LogWriter.LEVEL_INFO, ScriptExecutor.getOutput());
            LogWriter.getLogWriter().log(LogWriter.LEVEL_CRITICAL, ScriptExecutor.getErrors());

            // regmerge
            File f = new File(projDir.concat(File.separator).concat("build").concat(File.separator)
            .concat("idl").concat(File.separator).concat("rdb")); // NOI18N
            f.mkdirs();
            rdbPath = projDir.concat(File.separator).concat("build").concat(File.separator)
            .concat("idl").concat(File.separator).concat("rdb").concat(File.separator).concat("types.rdb"); // NOI18N

            command = new String[3 + idlFileObjects.length];
            command[0] = ureBinPath.concat(File.separator).concat("regmerge"); // NOI18N
            command[1] = rdbPath;
            command[2] = "/UCR"; // NOI18N
            for (int i=0; i<idlFileObjects.length; i++) {
                command[3+i] = urdOutPath.concat(File.separator)
                .concat(FileUtil.toFile(idlFileObjects[i]).getName().replaceAll("\\.idl", ".urd")); // NOI18N
            }

            ScriptExecutor.executeScript(command);
            if (ScriptExecutor.hasErrors()) {  // message box with errors...
                String message = NbBundle.getMessage(ProjectCreator.class, "ERROR_CommandExecute").concat(
                    "\n").concat(ScriptExecutor.getErrors()); // NOI18N
                JOptionPane.showMessageDialog(null, message,
                    NbBundle.getMessage(ProjectCreator.class, "LOG_Level_critical"), JOptionPane.ERROR_MESSAGE); // NOI18N
                executeWorked = false;
            }
            LogWriter.getLogWriter().log(LogWriter.LEVEL_INFO, ScriptExecutor.getOutput());
            LogWriter.getLogWriter().log(LogWriter.LEVEL_CRITICAL, ScriptExecutor.getErrors());
            
            // new part for initially creating a IDL_types.rdb
            // javamaker
            f = new File(projDir.concat(File.separator).concat("build").concat(File.separator)
            .concat("classes")); // NOI18N
            String classesOutPath = f.getCanonicalPath();
            f.mkdirs();
            command = new String[5 + typesRdbPath.length];
            command[0] = sdkBinPath.concat(File.separator).concat("javamaker"); // NOI18N
            command[1] = "-BUCR"; // NOI18N
            command[2] = "-O";
            command[3] = classesOutPath;
            command[4] = rdbPath;
            for (int i = 0; i < typesRdbPath.length; i++) {
                command[5 + i] = "-X".concat(typesRdbPath[i]);
            }
            
            ScriptExecutor.executeScript(command);
            if (ScriptExecutor.hasErrors()) {  // message box with errors...
                String message = NbBundle.getMessage(ProjectCreator.class, "ERROR_CommandExecute").concat(
                    "\n").concat(ScriptExecutor.getErrors()); // NOI18N
                JOptionPane.showMessageDialog(null, message,
                    NbBundle.getMessage(ProjectCreator.class, "LOG_Level_critical"), JOptionPane.ERROR_MESSAGE); // NOI18N
                executeWorked = false;
            }
            LogWriter.getLogWriter().log(LogWriter.LEVEL_INFO, ScriptExecutor.getOutput());
            LogWriter.getLogWriter().log(LogWriter.LEVEL_CRITICAL, ScriptExecutor.getErrors());

            // make a jar
            PrintStream outStream = new PrintStream(LogWriter.getLogWriter().getLogStream(LogWriter.LEVEL_INFO));
            PrintStream errStream = new PrintStream(LogWriter.getLogWriter().getLogStream(LogWriter.LEVEL_CRITICAL));
            Main jartool = new Main(outStream, errStream, "jar");
            
            f = new File(projDir.concat(File.separator).concat("dist"));
            f.mkdirs();
            command = new String[2  + 3 * idlFileObjects.length];
            final String IDL_JAR_NAME = (String)ProjectTypeHelper.getObjectFromUnoProperties(
                m_RootFile, "idl_types.jar"); // NOI18N
            String jarFile = f.getCanonicalPath().concat(File.separator).concat(IDL_JAR_NAME);
            f = new File(jarFile);
            if (f.exists()) {
                command[0] = "uf";
            }
            else {
                command[0] = "cf";
            }
            command[1] = jarFile;
            for (int i = 0; i < idlFileObjects.length; i++) {
                // remove first part of path to build correct directory structure in jar file
                String fileName = FileUtil.toFile(idlFileObjects[i]).getCanonicalPath().replace(srcIdlPath, ""); 
                command[2 + i * 3] = "-C";
                command[3 + i * 3] = classesOutPath; // build/classes
                command[4 + i * 3] = fileName.substring(1).replace(".idl", ".class"); // remove preceding "/"
                LogWriter.getLogWriter().log(LogWriter.LEVEL_INFO, "File: " + command[4 + i * 3]);
            }

            jartool.run(command);
        }

        // skeletonmaker
        String outFileWithPackage = ((String)wiz.getProperty("packageName")).concat(".").concat((String)wiz.getProperty("mainClassName")); // NOI18N

        Vector<String> commandVector = new Vector<String>();
        commandVector.add(sdkBinPath.concat(File.separator).concat("uno-skeletonmaker")); // NOI18N
        
        if (typesRdbPath.length > 0) {
            String typesURLList = prepareTypesURLList(typesRdbPath);
            commandVector.add("-env:UNO_TYPES=".concat(typesURLList)); // NOI18N
        }
        
        commandVector.add(this.m_ProjectType==ADDIN_TYPE?"calc-add-in":"component"); // NOI18N

        commandVector.add("--java5"); // NOI18N
        if (idlFileObjects.length!=0)
            commandVector.add("-l".concat(PathExchanger.pathToOfficeFileUrl(rdbPath))); // NOI18N

        // this is different for components
        if (this.m_ProjectType==ADDIN_TYPE) {
            commandVector.add("-t".concat(outFileWithPackage)); // NOI18N
        }
        else {
            // add all the types.
            for (int i=0; i<dumpTypes.length; i++) {
                commandVector.add("-t".concat(dumpTypes[i])); // NOI18N
            }
        }
        commandVector.add("-o".concat(projDir)
        .concat(File.separator).concat("src")); // NOI18N
        if (this.m_ProjectType==ADDIN_TYPE) {
            commandVector.add("-n".concat(outFileWithPackage).concat("Impl")); // NOI18N
        }
        else {
            commandVector.add("-n".concat(outFileWithPackage)); // NOI18N
        }
                   
        String[] command = commandVector.toArray(new String[commandVector.size()]);
        StringBuffer c = new StringBuffer();
        for (int i=0; i<command.length; i++) {
            c.append(command[i]).append(" "); // NOI18N
        }
        LogWriter.getLogWriter().log(LogWriter.LEVEL_INFO, c.toString());
        ScriptExecutor.executeScript(command);
        if (ScriptExecutor.hasErrors()) {  // message box with errors...
            String message = NbBundle.getMessage(ProjectCreator.class, "ERROR_CommandExecute").concat(
                "\n").concat(ScriptExecutor.getErrors()); // NOI18N
            JOptionPane.showMessageDialog(null, message, 
                NbBundle.getMessage(ProjectCreator.class, "LOG_Level_critical"), JOptionPane.ERROR_MESSAGE); // NOI18N
            executeWorked = false;
        }
        LogWriter.getLogWriter().log(LogWriter.LEVEL_INFO, ScriptExecutor.getOutput());
        LogWriter.getLogWriter().log(LogWriter.LEVEL_CRITICAL, ScriptExecutor.getErrors());
        return executeWorked;
    }