Search in sources :

Example 91 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.

the class ProcessorBasedRefactoring method checkInitialConditions.

/**
	 * {@inheritDoc}
	 */
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
    if (pm == null)
        pm = new NullProgressMonitor();
    RefactoringStatus result = new RefactoringStatus();
    //$NON-NLS-1$
    pm.beginTask("", 10);
    pm.setTaskName(RefactoringCoreMessages.ProcessorBasedRefactoring_initial_conditions);
    result.merge(getProcessor().checkInitialConditions(new SubProgressMonitor(pm, 8)));
    if (result.hasFatalError()) {
        pm.done();
        return result;
    }
    pm.done();
    return result;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 92 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.

the class ProcessorBasedRefactoring method createChange.

/**
	 * {@inheritDoc}
	 */
public Change createChange(IProgressMonitor pm) throws CoreException {
    if (pm == null)
        pm = new NullProgressMonitor();
    //$NON-NLS-1$
    pm.beginTask("", fParticipants.size() + 3);
    pm.setTaskName(RefactoringCoreMessages.ProcessorBasedRefactoring_create_change);
    Change processorChange = getProcessor().createChange(new SubProgressMonitor(pm, 1));
    if (pm.isCanceled())
        throw new OperationCanceledException();
    fTextChangeMap = new HashMap();
    addToTextChangeMap(processorChange);
    List /*<Change>*/
    changes = new ArrayList();
    List /*<Change>*/
    preChanges = new ArrayList();
    Map /*<Change, RefactoringParticipant>*/
    participantMap = new HashMap();
    for (Iterator iter = fParticipants.iterator(); iter.hasNext(); ) {
        final RefactoringParticipant participant = (RefactoringParticipant) iter.next();
        try {
            //$NON-NLS-1$
            final PerformanceStats stats = PerformanceStats.getStats(PERF_CREATE_CHANGES, getName() + ", " + participant.getName());
            stats.startRun();
            Change preChange = participant.createPreChange(new SubProgressMonitor(pm, 1));
            Change change = participant.createChange(new SubProgressMonitor(pm, 1));
            stats.endRun();
            if (preChange != null) {
                if (fPreChangeParticipants == null)
                    fPreChangeParticipants = new ArrayList();
                fPreChangeParticipants.add(participant);
                preChanges.add(preChange);
                participantMap.put(preChange, participant);
                addToTextChangeMap(preChange);
            }
            if (change != null) {
                changes.add(change);
                participantMap.put(change, participant);
                addToTextChangeMap(change);
            }
        } catch (CoreException e) {
            disableParticipant(participant, e);
            throw e;
        } catch (OperationCanceledException e) {
            throw e;
        } catch (RuntimeException e) {
            disableParticipant(participant, e);
            throw e;
        }
        if (pm.isCanceled())
            throw new OperationCanceledException();
    }
    fTextChangeMap = null;
    Change postChange = getProcessor().postCreateChange((Change[]) changes.toArray(new Change[changes.size()]), new SubProgressMonitor(pm, 1));
    ProcessorChange result = new ProcessorChange(getName());
    result.addAll((Change[]) preChanges.toArray(new Change[preChanges.size()]));
    result.add(processorChange);
    result.addAll((Change[]) changes.toArray(new Change[changes.size()]));
    result.setParticipantMap(participantMap);
    result.setPreChangeParticipants(fPreChangeParticipants);
    if (postChange != null)
        result.add(postChange);
    return result;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) HashMap(java.util.HashMap) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) TextChange(org.eclipse.ltk.core.refactoring.TextChange) Change(org.eclipse.ltk.core.refactoring.Change) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) PerformanceStats(org.eclipse.core.runtime.PerformanceStats) CoreException(org.eclipse.core.runtime.CoreException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 93 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.

the class RefactoringHistoryService method moveHistory.

/**
	 * Moves the project history from the old project to the new one.
	 *
	 * @param oldProject
	 *            the old project, which does not exist anymore
	 * @param newProject
	 *            the new project, which already exists
	 * @param monitor
	 *            the progress monitor to use
	 */
private void moveHistory(final IProject oldProject, final IProject newProject, final IProgressMonitor monitor) {
    try {
        monitor.beginTask(RefactoringCoreMessages.RefactoringHistoryService_updating_history, 60);
        final IFileStore historyStore = EFS.getLocalFileSystem().getStore(RefactoringCorePlugin.getDefault().getStateLocation()).getChild(NAME_HISTORY_FOLDER);
        final String oldName = oldProject.getName();
        final String newName = newProject.getName();
        final IFileStore oldStore = historyStore.getChild(oldName);
        if (oldStore.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 10, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)).exists()) {
            final IFileStore newStore = historyStore.getChild(newName);
            if (newStore.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 10, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)).exists())
                newStore.delete(EFS.NONE, new SubProgressMonitor(monitor, 20, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
            oldStore.move(newStore, EFS.OVERWRITE, new SubProgressMonitor(monitor, 20, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
        }
    } catch (CoreException exception) {
        RefactoringCorePlugin.log(exception);
    } finally {
        monitor.done();
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IFileStore(org.eclipse.core.filesystem.IFileStore) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 94 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.

the class RefactoringHistoryService method deleteRefactoringHistory.

/**
	 * Deletes the refactoring history of a project. Refactorings associated
	 * with the workspace are not deleted.
	 * <p>
	 * If a refactoring history is deleted, all files stored in the hidden
	 * refactoring history folder of the project folder are removed. If no
	 * shared refactoring history is enabled, the refactoring history
	 * information is removed from the internal workspace refactoring history.
	 * </p>
	 *
	 * @param project
	 *            the project to delete its history
	 * @param monitor
	 *            the progress monitor to use, or <code>null</code>
	 * @throws CoreException
	 *             if an error occurs while deleting the refactoring history.
	 *             Reasons include:
	 *             <ul>
	 *             <li>An I/O error occurs while deleting the refactoring
	 *             history.</li>
	 *             </ul>
	 */
public void deleteRefactoringHistory(final IProject project, IProgressMonitor monitor) throws CoreException {
    Assert.isNotNull(project);
    if (monitor == null)
        monitor = new NullProgressMonitor();
    try {
        monitor.beginTask(RefactoringCoreMessages.RefactoringHistoryService_deleting_refactorings, 100);
        final String name = project.getName();
        final IFileStore stateStore = EFS.getLocalFileSystem().getStore(RefactoringCorePlugin.getDefault().getStateLocation());
        if (name.equals(NAME_WORKSPACE_PROJECT)) {
            final IFileStore metaStore = stateStore.getChild(NAME_HISTORY_FOLDER).getChild(name);
            metaStore.delete(EFS.NONE, new SubProgressMonitor(monitor, 100));
        } else {
            final URI uri = project.getLocationURI();
            if (uri != null && project.isAccessible()) {
                try {
                    final IFileStore metaStore = stateStore.getChild(NAME_HISTORY_FOLDER).getChild(name);
                    metaStore.delete(EFS.NONE, new SubProgressMonitor(monitor, 20));
                    final IFileStore projectStore = EFS.getStore(uri).getChild(NAME_HISTORY_FOLDER);
                    projectStore.delete(EFS.NONE, new SubProgressMonitor(monitor, 20));
                } finally {
                    project.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 60));
                }
            }
        }
    } finally {
        monitor.done();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFileStore(org.eclipse.core.filesystem.IFileStore) URI(java.net.URI) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 95 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project tdi-studio-se by Talend.

the class BuildJobManager method buildJobs.

public boolean buildJobs(String destinationPath, List<? extends IRepositoryNode> nodes, List<String> topNames, String version, String context, Map<ExportChoice, Object> exportChoiceMap, JobExportType jobExportType, IProgressMonitor monitor) throws Exception {
    IProgressMonitor pMonitor = new NullProgressMonitor();
    if (monitor != null) {
        pMonitor = monitor;
    }
    final List<ProcessItem> processes = getProcesses(nodes);
    if (processes.size() == 1) {
        ProcessItem item = processes.get(0);
        buildJob(destinationPath, item, version, context, exportChoiceMap, jobExportType, pMonitor);
    } else {
        int scale = 1000;
        int steps = 3;
        pMonitor.beginTask(Messages.getString("JobScriptsExportWizardPage.newExportJobScript", jobExportType), //$NON-NLS-1$
        steps * scale * nodes.size());
        String topName = null;
        if (topNames != null && !topNames.isEmpty()) {
            topName = topNames.get(0);
        } else {
            topName = ProjectManager.getInstance().getCurrentProject().getLabel();
        }
        File desFile = new File(destinationPath);
        //$NON-NLS-1$ //$NON-NLS-2$
        File createTempFile = File.createTempFile("building_job", "");
        createTempFile.delete();
        File tempFolder = new File(desFile.getParent() + File.separator + createTempFile.getName());
        if (tempFolder.exists()) {
            tempFolder.delete();
        }
        File tempProFolder = new File(tempFolder, topName);
        tempProFolder.mkdirs();
        for (int i = 0; i < processes.size(); i++) {
            ProcessItem processItem = processes.get(i);
            //$NON-NLS-1$
            pMonitor.setTaskName(Messages.getString("BuildJobManager.building", processItem.getProperty().getLabel()));
            IBuildJobHandler buildJobHandler = BuildJobFactory.createBuildJobHandler(processItem, context, processItem.getProperty().getVersion(), exportChoiceMap, jobExportType);
            buildJobHandler.generateItemFiles(true, new SubProgressMonitor(pMonitor, scale));
            buildJobHandler.generateJobFiles(new SubProgressMonitor(pMonitor, scale));
            buildJobHandler.build(new SubProgressMonitor(pMonitor, scale));
            IFile jobTargetFile = buildJobHandler.getJobTargetFile();
            if (jobTargetFile != null && jobTargetFile.exists()) {
                // unzip to temp folder
                FilesUtils.unzip(jobTargetFile.getLocation().toPortableString(), tempProFolder.getAbsolutePath());
                String zipPath = jobTargetFile.getLocation().toPortableString();
                if (needClasspathJar(exportChoiceMap)) {
                    JavaJobExportReArchieveCreator creator = new JavaJobExportReArchieveCreator(zipPath, processItem.getProperty().getLabel());
                    creator.setTempFolder(tempFolder.getAbsolutePath());
                    creator.buildNewJar();
                }
            }
            pMonitor.worked(scale);
        }
        FilesUtils.zip(tempFolder.getAbsolutePath(), destinationPath);
        FilesUtils.deleteFile(tempFolder, true);
        pMonitor.done();
    }
    return true;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) ProcessItem(org.talend.core.model.properties.ProcessItem) IBuildJobHandler(org.talend.core.runtime.process.IBuildJobHandler) JavaJobExportReArchieveCreator(org.talend.repository.ui.wizards.exportjob.JavaJobExportReArchieveCreator) ZipToFile(org.talend.repository.ui.utils.ZipToFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Aggregations

SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)217 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)54 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)53 CoreException (org.eclipse.core.runtime.CoreException)40 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)39 ArrayList (java.util.ArrayList)36 IFile (org.eclipse.core.resources.IFile)33 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)31 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)30 IOException (java.io.IOException)23 IType (org.eclipse.jdt.core.IType)19 HashSet (java.util.HashSet)17 IPath (org.eclipse.core.runtime.IPath)17 IResource (org.eclipse.core.resources.IResource)16 IProject (org.eclipse.core.resources.IProject)15 File (java.io.File)14 List (java.util.List)13 IMethod (org.eclipse.jdt.core.IMethod)13 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 HashMap (java.util.HashMap)12