Package org.eclipse.core.runtime

Examples of org.eclipse.core.runtime.SubMonitor


            throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Incorrect path (not a project): " + location, null));
        }
    }

    protected void createOrReplaceCnf(IProgressMonitor monitor) throws CoreException {
        SubMonitor progress = SubMonitor.convert(monitor);
        progress.setWorkRemaining(3);

        IProject cnfProject = ResourcesPlugin.getWorkspace().getRoot().getProject(Workspace.CNFDIR);
        URI location = operation.getLocation() != null ? operation.getLocation().toFile().toURI() : null;
        JavaCapabilityConfigurationPage.createProject(cnfProject, location, progress.newChild(1, SubMonitor.SUPPRESS_NONE));
        IJavaProject cnfJavaProject = JavaCore.create(cnfProject);

        configureJavaProject(cnfJavaProject, progress.newChild(1, SubMonitor.SUPPRESS_NONE));

        String bsn = templateConfig.getContributor().getName();
        Bundle bundle = BundleUtils.findBundle(Plugin.getDefault().getBundleContext(), bsn, null);
        String paths = templateConfig.getAttribute("paths");
        if (paths == null)
            throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Template is missing 'paths' property.", null));

        StringTokenizer tokenizer = new StringTokenizer(paths, ",");
        progress.setWorkRemaining(tokenizer.countTokens());

        while (tokenizer.hasMoreTokens()) {
            String path = tokenizer.nextToken().trim();
            if (!path.endsWith("/"))
                path = path + "/";

            copyBundleEntries(bundle, path, new Path(path), cnfProject, progress.newChild(1, SubMonitor.SUPPRESS_NONE));
        }

        try {
            Central.getWorkspace().refresh();
        } catch (Exception e) {
View Full Code Here


        if (entries != null)
            while (entries.hasMoreElements()) {
                subPaths.add(entries.nextElement());
            }
        int work = subPaths.size();
        SubMonitor progress = SubMonitor.convert(monitor, work);

        for (String subPath : subPaths) {
            if (subPath.endsWith("/")) {
                IPath destinationPath = new Path(subPath).makeRelativeTo(sourcePrefix);
                IFolder folder = destination.getFolder(destinationPath);
                if (!folder.exists())
                    folder.create(true, true, null);
                copyBundleEntries(sourceBundle, subPath, sourcePrefix, destination, progress.newChild(1, SubMonitor.SUPPRESS_NONE));
                progress.setWorkRemaining(--work);
            } else {
                copyBundleEntry(sourceBundle, subPath, sourcePrefix, destination, progress.newChild(1, SubMonitor.SUPPRESS_NONE));
                progress.setWorkRemaining(--work);
            }
        }
    }
View Full Code Here

            throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Failed to load data from template source bundle.", e));
        }
    }

    private static void configureJavaProject(IJavaProject javaProject, IProgressMonitor monitor) throws CoreException {
        SubMonitor progress = SubMonitor.convert(monitor, 5);
        IProject project = javaProject.getProject();
        BuildPathsBlock.addJavaNature(project, progress.newChild(1));

        // Create the source folder
        IFolder srcFolder = project.getFolder("src");
        if (!srcFolder.exists()) {
            srcFolder.create(true, true, progress.newChild(1));
        }
        progress.setWorkRemaining(3);

        // Create the output location
        IFolder outputFolder = project.getFolder("bin");
        if (!outputFolder.exists())
            outputFolder.create(true, true, progress.newChild(1));
        outputFolder.setDerived(true, null);
        progress.setWorkRemaining(2);

        // Set the output location
        javaProject.setOutputLocation(outputFolder.getFullPath(), progress.newChild(1));

        // Create classpath entries
        IClasspathEntry[] classpath = new IClasspathEntry[2];
        classpath[0] = JavaCore.newSourceEntry(srcFolder.getFullPath());
        classpath[1] = JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER"));

        javaProject.setRawClasspath(classpath, progress.newChild(1));
    }
View Full Code Here

      return;
    }
    if (monitor.isCanceled()) {
      throw new OperationCanceledException();
    }
    SubMonitor subMonitor = SubMonitor.convert(monitor, deltas.size() * 2 + 2);
    IProject project = context.getBuiltProject();
    CompilerPreferences compilerPreferences = compilerPreferences(storeAccess, project);
    if (!compilerPreferences.shouldCompileProtoFiles()) {
      return;
    }
    PathsPreferences pathsPreferences = new PathsPreferences(storeAccess, project);
    ProtocCommandBuilder commandBuilder = new ProtocCommandBuilder(compilerPreferences, pathsPreferences);
    for (Delta delta : deltas) {
      if (subMonitor.isCanceled()) {
        throw new OperationCanceledException();
      }
      IFile protoFile = protoFile(delta.getUri(), project);
      subMonitor.worked(1);
      if (protoFile != null) {
        subMonitor.subTask("Compiling " + protoFile.getName() + " with protoc");
        generateSingleProto(commandBuilder.buildCommand(protoFile), protoFile);
      }
      subMonitor.worked(1);
    }
    if (compilerPreferences.refreshResources()) {
      List<IFolder> outputDirectories = commandBuilder.outputDirectories();
      boolean refreshProject = compilerPreferences.refreshProject();
      refresh(project, outputDirectories, refreshProject, subMonitor.newChild(outputDirectories.size() + 1));
    }
  }
View Full Code Here

        // Create or remove file
        FileActivity.Type type = activity.getType();
        if (type == FileActivity.Type.Created) {
            // TODO The progress should be reported to the user.
            SubMonitor monitor = SubMonitor.convert(new NullProgressMonitor());
            try {
                FileUtils.writeFile(
                    new ByteArrayInputStream(activity.getContents()), file,
                    monitor);
            } catch (Exception e) {
                log.error("Could not write file: " + file);
            }
        } else if (type == FileActivity.Type.Removed) {
            if (file.exists())
                FileUtils.delete(file);
        } else if (type == FileActivity.Type.Moved) {

            IPath newFilePath = activity.getPath().getFile().getFullPath();

            IResource oldResource = activity.getOldPath().getFile();

            if (oldResource == null) {
                log.error(".exec Old File is not availible while moving "
                    + activity.getOldPath());
            } else {
                FileUtils.mkdirs(activity.getPath().getFile());
                FileUtils.move(newFilePath, oldResource);
            }

            // while moving content of the file changed
            if (activity.getContents() != null) {

                SubMonitor monitor = SubMonitor
                    .convert(new NullProgressMonitor());
                try {
                    FileUtils.writeFile(
                        new ByteArrayInputStream(activity.getContents()), file,
                        monitor);
View Full Code Here

        checkCancellation();

        ZipInputStream zipStream = new ZipInputStream(archiveStream);
        ZipEntry zipEntry;
        // unpacking the big archive
        SubMonitor zipStreamLoopMonitor = submonitor.newChild(30);
        while ((zipEntry = zipStream.getNextEntry()) != null) {
            // Every zipEntry is (again) a ZipArchive, which contains all
            // missing files for one project.
            SubMonitor lMonitor = zipStreamLoopMonitor
                .newChild(100 / numberOfLoops);
            /*
             * For every entry (which is a zipArchive for a single project) we
             * have to find out which project it is meant for. So we need the
             * projectID.
             *
             * The archive name contains the projectID.
             *
             * archiveName = projectID + this.projectIDDelimiter + randomNumber
             * + '.zip'
             */
            String projectID = zipEntry.getName().substring(0,
                zipEntry.getName().indexOf(this.projectIDDelimiter));
            IProject project = localProjects.get(projectID);
            IPath path = Path.fromPortableString(zipEntry.getName());
            // store the archive temporary
            IFile file = project.getFile(path);
            // Archive needs to be stored temporarily to be accessed
            FileUtils.writeFile(new FilterInputStream(zipStream) {
                @Override
                public void close() throws IOException {
                    // prevent the ZipInputStream from being closed
                }
            }, file, lMonitor.newChild(10));

            InputStream inputStream = file.getContents();
            log.debug(file.getProjectRelativePath().toString());
            // write all files in archive to project
            writeArchive(inputStream, project, lMonitor.newChild(80));
            zipStream.closeEntry();
            file.delete(true, false, lMonitor.newChild(10));
        }
        submonitor.done();
    }
View Full Code Here

        /*
         * this for loop sets up all the projects needed for the session and
         * computes the missing files.
         */
        for (Entry<String, String> entry : projectNames.entrySet()) {
            SubMonitor lMonitor = subMonitor.newChild(100 / numberOfLoops);
            String projectID = entry.getKey();
            String projectName = entry.getValue();
            checkCancellation();
            ProjectExchangeInfo projectInfo = null;
            for (ProjectExchangeInfo pInfo : this.projectInfos) {
                if (pInfo.getProjectID().equals(projectID))
                    projectInfo = pInfo;
            }
            if (projectInfo == null) {
                log.error("tried to add a project that wasn't shared");
                // this should never happen
                continue;
            }

            VCSAdapter vcs = null;
            if (preferenceUtils.useVersionControl() && useVersionControl) {
                vcs = VCSAdapter.getAdapter(projectInfo.getFileList()
                    .getVcsProviderID());
            }

            IProject iProject = eclipseHelper.getWorkspace().getRoot()
                .getProject(projectName);
            if (iProject.exists()) {
                /*
                 * Saving unsaved files is supposed to be done in
                 * JoinSessionWizard#performFinish().
                 */
                if (EditorAPI.existUnsavedFiles(iProject)) {
                    log.error("Unsaved files detected.");
                }
            } else {
                iProject = null;
            }
            IProject localProject = assignLocalProject(iProject, projectName,
                projectID, vcs, lMonitor.newChild(30), projectInfo);
            localProjects.put(projectID, localProject);

            checkCancellation();
            if (vcs != null && !isPartialRemoteProject(projectID)) {
                log.debug("initVcState");
                initVcState(localProject, vcs, lMonitor.newChild(40),
                    projectInfo.getFileList());
            }
            checkCancellation();

            log.debug("compute required Files for project " + projectName
                + " with ID: " + projectID);
            FileList requiredFiles = computeRequiredFiles(localProject,
                projectInfo.getFileList(), projectID, skipSyncs.get(projectID)
                    .booleanValue(), vcs, lMonitor.newChild(30));
            requiredFiles.setProjectID(projectID);
            checkCancellation();
            missingFiles.add(requiredFiles);
            lMonitor.done();
        }
        return missingFiles;
    }
View Full Code Here

        dialog.run(true, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor)
                throws InvocationTargetException {
                try {
                    SubMonitor subMonitor = SubMonitor.convert(monitor,
                        "Copy local resources... ", 300);

                    subMonitor.subTask("Clearing History...");
                    project.clearHistory(subMonitor.newChild(100));

                    subMonitor.subTask("Refreshing Project");
                    project.refreshLocal(IResource.DEPTH_INFINITE,
                        subMonitor.newChild(100));

                    if (baseProject == null) {
                        subMonitor.subTask("Creating Project...");
                        project.create(subMonitor.newChild(50));

                        subMonitor.subTask("Opening Project...");
                        project.open(subMonitor.newChild(50));
                    } else {
                        subMonitor.subTask("Copying Project...");
                        baseProject.copy(project.getFullPath(), true,
                            subMonitor.newChild(100));
                    }
                } catch (Exception e) {
                    throw new RuntimeException(e.getCause());
                }
            }
View Full Code Here

                null, vcs != null, monitor.newChild(1));
        } catch (CoreException e) {
            e.printStackTrace();
            return FileListFactory.createEmptyFileList();
        }
        SubMonitor childMonitor = monitor.newChild(5,
            SubMonitor.SUPPRESS_ALL_LABELS);
        filesToSynchronize = computeDiff(localFileList, remoteFileList,
            currentLocalProject, projectID, childMonitor);

        List<IPath> missingFiles = filesToSynchronize.getAddedPaths();
View Full Code Here

        try {
            dialog.run(true, true, new IRunnableWithProgress() {
                public void run(final IProgressMonitor monitor) {

                    final SubMonitor progress = SubMonitor.convert(monitor);

                    try {

                        progress.beginTask(Messages.SarosUI_permission_change,
                            IProgressMonitor.UNKNOWN);

                        sessionManager.getSarosSession()
                            .initiatePermissionChange(user, newPermission,
                                progress);

                    } catch (CancellationException e) {
                        log.warn("Permission change failed because buddy canceled the permission change"); //$NON-NLS-1$
                        Utils.runSafeSWTSync(log, new Runnable() {
                            public void run() {
                                MessageDialog.openInformation(EditorAPI
                                    .getAWorkbenchWindow().getShell(),
                                    Messages.SarosUI_permission_canceled,
                                    Messages.SarosUI_permission_canceled_text);
                            }
                        });
                    } catch (InterruptedException e) {
                        log.error("Code not designed to be interruptable", e); //$NON-NLS-1$
                    } finally {
                        progress.done();
                    }
                }
            });
        } catch (InvocationTargetException e) {
            log.error("Internal Error: ", e); //$NON-NLS-1$
View Full Code Here

TOP

Related Classes of org.eclipse.core.runtime.SubMonitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.