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;
}
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;
}
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();
}
}
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();
}
}
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;
}
Aggregations