private Map indexProjects()

in remoting/server/indexer/impl/src/org/netbeans/modules/jackpot30/backend/impl/OptionProcessorImpl.java [357:428]


    private Map<String, String> indexProjects(Set<FileObject> sourceRoots, Map<FileObject, String> extraJars, Env env) throws IOException, InterruptedException {
        if (sourceRoots.isEmpty()) {
            env.getErrorStream().println("Error: There is nothing to index!");
            return Collections.emptyMap();
        } else {
            //XXX: to start up the project systems and RepositoryUpdater:
            ((Runnable) OpenProjects.getDefault().openProjects()).run();
            org.netbeans.api.project.ui.OpenProjects.getDefault().getOpenProjects();
            ClassPath source = ClassPathSupport.createClassPath(sourceRoots.toArray(new FileObject[0]));

            LOG.log(Level.FINE, "Registering as source path: {0}", source.toString());
            GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, new ClassPath[] {source});
            SourceUtils.waitScanFinished();
            Map<String, String> classpath = new HashMap<String, String>();

            if (STORE_CLASSPATH) {
                long extraJarCounter = 0;

                for (FileObject sourceRoot : sourceRoots) {
                    StringBuilder cp = new StringBuilder();
                    ClassPath sourceCP = ClassPath.getClassPath(sourceRoot, ClassPath.SOURCE);

                    if (sourceCP != null) {
                        for (ClassPath.Entry e : sourceCP.entries()) {
                            cp.append(CacheFolder.getDataFolder(e.getURL()).getNameExt());
                            cp.append(":");
                        }
                    }

                    ClassPath compileCP = ClassPath.getClassPath(sourceRoot, ClassPath.COMPILE);

                    if (compileCP != null) {
                        for (ClassPath.Entry e : compileCP.entries()) {
                            Result2 sourceMapping = SourceForBinaryQuery.findSourceRoots2(e.getURL());

                            if (sourceMapping.preferSources() && /*XXX:*/ sourceMapping.getRoots().length > 0) {
                                for (FileObject sr : sourceMapping.getRoots()) {
                                    cp.append(CacheFolder.getDataFolder(sr.toURL()).getNameExt());
                                    cp.append(":");
                                }
                            } else {
                                FileObject root = e.getRoot();
                                FileObject jar = root != null ? FileUtil.getArchiveFile(root) : null;

                                if (jar != null) root = jar;

                                if (root != null && root.isData()) { //XXX: class folders
                                    String rootId = extraJars.get(root);

                                    if (rootId == null) {
                                        extraJars.put(root, rootId = "ej" + extraJarCounter++ + ".jar");
                                    }

                                    cp.append(rootId);
                                    cp.append(":");
                                }
                            }
                        }
                    }

                    if (cp.length() > 0)
                        cp.deleteCharAt(cp.length() - 1);

                    classpath.put(CacheFolder.getDataFolder(sourceRoot.toURL()).getNameExt(), cp.toString());
                }
            }

            GlobalPathRegistry.getDefault().unregister(ClassPath.SOURCE, new ClassPath[] {source});

            return classpath;
        }
    }