@Override public void launch( final ILaunchConfiguration config, final String mode, final ILaunch launch, final IProgressMonitor monitor) throws CoreException { final int WORK_LAUNCH = 10; final int WORK_POST_LAUNCH = 100; SubMonitor subMonitor = SubMonitor.convert(monitor, WORK_LAUNCH + WORK_POST_LAUNCH); // Validate all XML before doing anything else final SoftPkg spd = SpdLauncherUtil.getSpd(config); IStatus status = SpdLauncherUtil.validateAllXML(spd); if (!status.isOK()) { throw new CoreException(status); } final ILaunchConfigurationWorkingCopy copy = config.getWorkingCopy(); insertProgramArguments(spd, launch, copy); try { super.launch(copy, mode, launch, subMonitor.newChild(WORK_LAUNCH)); SpdLauncherUtil.postLaunch(spd, copy, mode, launch, subMonitor.newChild(WORK_POST_LAUNCH)); } finally { if (monitor != null) { monitor.done(); } } }
/** * Creates a new project resource with the selected name. * * <p>In normal usage, this method is invoked after the user has pressed Finish on the wizard; the * enablement of the Finish button implies that all controls on the pages currently contain valid * values. * * <p>Note that this wizard caches the new project once it has been successfully created; * subsequent invocations of this method will answer the same project resource without attempting * to create it again. * * @param monitor TODO * @return the created project resource, or <code>null</code> if the project was not created */ protected IProject createNewProject(IProgressMonitor monitor) throws InvocationTargetException { SubMonitor sub = SubMonitor.convert(monitor, 100); // Project description creation IProjectDescription description = ResourceUtil.getProjectDescription(destPath, getProjectNatures(), getProjectBuilders()); description.setName(newProject.getName()); description.setLocationURI(location); // Update the referenced project in case it was initialized. if (refProjects != null && refProjects.length > 0) { description.setReferencedProjects(refProjects); } sub.worked(10); if (!applySourcedProjectFilesAfterProjectCreated() && isCloneFromGit()) { cloneFromGit(newProject, description, sub.newChild(90)); } else { doBasicCreateProject(newProject, description, sub.newChild(75)); if (!applySourcedProjectFilesAfterProjectCreated() && selectedTemplate != null && !isCloneFromGit()) { selectedTemplate.apply(newProject, true); } } return newProject; }
/** * Produces a graph depicting the old and new and the delta between them. Output is in SVG format. * * @param catalogName The name to generate as title in the graph. May be <code>null</code> * @param oldCatalogSream * @param newCatalogStream * @param svgStream * @param monitor * @param root - the root for files listed as source files in the catalog */ public void produceSVGDeltaGraph( String catalogName, InputStream oldCatalogStream, IPath oldRoot, InputStream newCatalogStream, IPath newRoot, OutputStream svgStream, IProgressMonitor monitor) throws IOException { final SubMonitor ticker = SubMonitor.convert(monitor, 2000); CatalogDeltaGraphProducer graphProducer = new CatalogDeltaGraphProducer(hrefProducer, prefix); Catalog oldCatalog = CatalogJsonSerializer.load(oldCatalogStream); Catalog newCatalog = CatalogJsonSerializer.load(newCatalogStream); ICancel cancel = new ProgressMonitorCancelIndicator(ticker.newChild(IProgressMonitor.UNKNOWN), 1000); ByteArrayOutputStream2 out = new ByteArrayOutputStream2(); graphProducer.produceGraph(cancel, catalogName, oldCatalog, oldRoot, newCatalog, newRoot, out); graphProducer .getSVGProducer() .produceSVG( out.toInputStream(false), svgStream, false, // ticker.newChild(IProgressMonitor.UNKNOWN)); }
/** * Performs a git clone to a temporary location and then copies the files over top the already * generated project. This is because git cannot clone into an existing directory. * * @param monitor * @throws Exception */ protected void cloneAfter(IProgressMonitor monitor) throws Exception { SubMonitor sub = SubMonitor.convert(monitor, Messages.AbstractNewProjectWizard_CloningFromGitMsg, 100); // clone to tmp dir then copy files over top the project! File tmpFile = File.createTempFile("delete_me", "tmp"); // $NON-NLS-1$ //$NON-NLS-2$ File dest = new File(tmpFile.getParent(), "git_clone_tmp"); // $NON-NLS-1$ GitExecutable.instance() .clone( selectedTemplate.getLocation(), Path.fromOSString(dest.getAbsolutePath()), true, sub.newChild(85)); IFileStore tmpClone = EFS.getStore(dest.toURI()); // Wipe the .git folder before copying? Wipe the .project file before copying? IFileStore dotGit = tmpClone.getChild(".git"); // $NON-NLS-1$ dotGit.delete(EFS.NONE, sub.newChild(2)); IFileStore dotProject = tmpClone.getChild(IProjectDescription.DESCRIPTION_FILE_NAME); if (dotProject.fetchInfo().exists()) { dotProject.delete(EFS.NONE, sub.newChild(1)); } // OK, copy the cloned template's contents over IFileStore projectStore = EFS.getStore(newProject.getLocationURI()); tmpClone.copy(projectStore, EFS.OVERWRITE, sub.newChild(9)); // Now get rid of the temp clone! tmpClone.delete(EFS.NONE, sub.newChild(3)); sub.done(); }
private void buildFile( BuildContext context, List<IBuildParticipant> participants, IProgressMonitor monitor) throws CoreException { if (CollectionsUtil.isEmpty(participants)) { return; } SubMonitor sub = SubMonitor.convert(monitor, 2 * participants.size()); for (IBuildParticipant participant : participants) { long startTime = System.nanoTime(); participant.buildFile(context, sub.newChild(1)); if (traceParticipantsEnabled) { double endTime = ((double) System.nanoTime() - startTime) / 1000000; IdeLog.logTrace( BuildPathCorePlugin.getDefault(), MessageFormat.format( "Executed build participant ''{0}'' on ''{1}'' in {2} ms.", participant.getName(), context.getURI(), endTime), IDebugScopes.BUILDER_PARTICIPANTS); // $NON-NLS-1$ } // stop building if it has been canceled if (sub.isCanceled()) { break; } } updateMarkers(context, sub.newChild(participants.size())); sub.done(); }
/** * Install selected features in to developer studio. Note: call {@link * #setSelectedFeaturesToInstall(List) setSelectedFeaturesToInstall} first. * * @param monitor */ public void installSelectedFeatures(IProgressMonitor monitor) { SubMonitor progress = SubMonitor.convert(monitor, Messages.UpdateManager_32, 2); URI[] repos = new URI[] {getDevStudioReleaseSite()}; session = new ProvisioningSession(p2Agent); installOperation = new InstallOperation(session, selectedFeatures); installOperation.getProvisioningContext().setArtifactRepositories(repos); installOperation.getProvisioningContext().setMetadataRepositories(repos); IStatus status = installOperation.resolveModal(progress.newChild(1)); if (status.getSeverity() == IStatus.CANCEL || progress.isCanceled()) { throw new OperationCanceledException(); } else if (status.getSeverity() == IStatus.ERROR) { String message = status.getChildren()[0].getMessage(); log.error(Messages.UpdateManager_33 + message); } else { ProvisioningJob provisioningJob = installOperation.getProvisioningJob(progress.newChild(1)); if (provisioningJob != null) { provisioningJob.addJobChangeListener( new JobChangeAdapter() { @Override public void done(IJobChangeEvent arg0) { Display.getDefault() .syncExec( new Runnable() { @Override public void run() { boolean restart = MessageDialog.openQuestion( Display.getDefault().getActiveShell(), Messages.UpdateManager_34, Messages.UpdateManager_35 + Messages.UpdateManager_36); if (restart) { PlatformUI.getWorkbench().restart(); } } }); } }); provisioningJob.schedule(); Display.getDefault() .syncExec( new Runnable() { @Override public void run() { try { PlatformUI.getWorkbench() .getActiveWorkbenchWindow() .getActivePage() .showView(IProgressConstants.PROGRESS_VIEW_ID); } catch (PartInitException e) { log.error(e); } } }); } else { log.error(Messages.UpdateManager_37); } } }
/** * Standard impl of restart justc alls stop and then start. Subclasses should override if there's * a quicker implementation. */ public IStatus restart(String mode, IProgressMonitor monitor) { SubMonitor sub = SubMonitor.convert(monitor, 100); IStatus status = stop(true, sub.newChild(30)); if (!status.isOK()) { return status; } return start(mode, sub.newChild(70)); }
private Map<String, EnhancedFeature> loadWSO2FeaturesInRepo( IArtifactRepository artifactRepository, IQueryResult<IInstallableUnit> allAvailableIUs, IProgressMonitor monitor) throws ProvisionException, URISyntaxException, IOException { if (monitor == null) { monitor = new NullProgressMonitor(); } SubMonitor progress = SubMonitor.convert(monitor, Messages.UpdateManager_15, 10); String tmpRoot = System.getProperty(JAVA_IO_TMPDIR) + File.separator + DEVS_UPDATER_TMP; Collection<IInstallableUnit> wso2FeatureJars = filterInstallableUnits( WSO2_FEATURE_PREFIX, FEATURE_JAR_IU_ID_SFX, allAvailableIUs, progress.newChild(1)); Map<String, EnhancedFeature> loadedFeatureMap = new HashMap<>(); for (IInstallableUnit iu : wso2FeatureJars) { SubMonitor downloadProgress = SubMonitor.convert(progress, Messages.UpdateManager_16, wso2FeatureJars.size() * 2); Collection<IArtifactKey> artifacts = iu.getArtifacts(); // ideally there should be only one artifact in a feature.jar iu for (IArtifactKey iArtifactKey : artifacts) { IArtifactDescriptor[] artifactDescriptors = artifactRepository.getArtifactDescriptors(iArtifactKey); File featureCacheRoot = new File(tmpRoot, iu.getId() + File.separator + iu.getVersion().toString()); File cachedFeatureDir = new File(featureCacheRoot, FEATURE_JAR_EXTRCT_FOLDER); if (cachedFeatureDir.exists() && cachedFeatureDir.isDirectory()) { downloadProgress.worked(2); } else { featureCacheRoot.mkdirs(); File jarFile = new File(featureCacheRoot, iu.getId()); try { if (jarFile.exists()) { // something is wrong with the file // if it is there without the cache dir. jarFile.delete(); } FileOutputStream fop = new FileOutputStream(jarFile); // jar iu only contains a single artifact. hence [0] artifactRepository.getArtifact( artifactDescriptors[0], fop, downloadProgress.newChild(1)); cachedFeatureDir.mkdirs(); extractJar(jarFile, cachedFeatureDir); downloadProgress.worked(1); } catch (IOException e) { throw new IOException(Messages.UpdateManager_17, e); } } EnhancedFeature feature = readEnhancedMetadata(iu, cachedFeatureDir); loadedFeatureMap.put(feature.getId(), feature); } } return loadedFeatureMap; }
@SuppressWarnings("rawtypes") @Override protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException { traceParticipantsEnabled = IdeLog.isTraceEnabled(BuildPathCorePlugin.getDefault(), IDebugScopes.BUILDER_PARTICIPANTS); boolean logTraceEnabled = traceLoggingEnabled(); IProject project = getProjectHandle(); String projectName = project.getName(); long startTime = System.nanoTime(); SubMonitor sub = SubMonitor.convert(monitor, 100); // Keep these build participant instances and use them in the build process, rather than // grabbing new ones // in sub-methods. We do pre- and post- setups on them, so we need to retain instances. IBuildParticipantManager manager = getBuildParticipantManager(); if (manager == null) { return new IProject[0]; } List<IBuildParticipant> participants = manager.getAllBuildParticipants(); participants = filterToEnabled(participants, project); buildStarting(participants, kind, sub.newChild(10)); if (kind == IncrementalProjectBuilder.FULL_BUILD) { if (logTraceEnabled) { logTrace(MessageFormat.format(Messages.UnifiedBuilder_PerformingFullBuld, projectName)); } fullBuild(participants, sub.newChild(80)); } else { IResourceDelta delta = getResourceDelta(); if (delta == null) { if (logTraceEnabled) { logTrace( MessageFormat.format( Messages.UnifiedBuilder_PerformingFullBuildNullDelta, projectName)); } fullBuild(participants, sub.newChild(80)); } else { if (logTraceEnabled) { logTrace( MessageFormat.format( Messages.UnifiedBuilder_PerformingIncrementalBuild, projectName)); } incrementalBuild(participants, delta, sub.newChild(80)); } } buildEnding(participants, sub.newChild(10)); if (logTraceEnabled) { double endTime = ((double) System.nanoTime() - startTime) / 1000000; logTrace(MessageFormat.format(Messages.UnifiedBuilder_FinishedBuild, projectName, endTime)); } return null; }
@Override public RefactoringStatus checkInitialConditions(final IProgressMonitor monitor) throws CoreException { final SubMonitor progress = SubMonitor.convert(monitor, 6); try { if (fSelectionRegion != null) { fSourceUnit.connect(progress.newChild(1)); try { final AbstractDocument document = fSourceUnit.getDocument(monitor); final IRModelInfo modelInfo = (IRModelInfo) fSourceUnit.getModelInfo( RModel.TYPE_ID, IRModelManager.MODEL_FILE, progress.newChild(1)); if (modelInfo != null) { final IRegion region = fAdapter.trimToAstRegion(document, fSelectionRegion); ISourceStructElement element = LTKUtil.getCoveringSourceElement(modelInfo.getSourceElement(), region); while (element != null) { if (element instanceof IRMethod) { fFunction = (IRMethod) element; break; } element = element.getSourceParent(); } } if (fFunction != null) { final ISourceStructElement source = (ISourceStructElement) fFunction; fOperationRegion = fAdapter.expandSelectionRegion(document, source.getSourceRange(), fSelectionRegion); } } finally { fSourceUnit.disconnect(progress.newChild(1)); } } if (fFunction == null) { return RefactoringStatus.createFatalErrorStatus( Messages.FunctionToS4Method_error_InvalidSelection_message); } final RefactoringStatus result = new RefactoringStatus(); fAdapter.checkInitialForModification(result, fElementSet); progress.worked(1); if (result.hasFatalError()) { return result; } checkFunction(result); progress.worked(2); return result; } finally { progress.done(); } }
private Collection<IInstallableUnit> getInstalledWSO2Features(IProgressMonitor monitor) throws OperationCanceledException { SubMonitor progress = SubMonitor.convert(monitor, Messages.UpdateManager_23, 2); OperationFactory operationFactory = new OperationFactory(); IQueryResult<IInstallableUnit> queryResult = operationFactory.listInstalledElements(true, progress.newChild(1)); return filterInstallableUnits( WSO2_FEATURE_PREFIX, FEATURE_GROUP_IU_ID_SFX, queryResult, progress.newChild(1)); }
public void findAllReferences( IQueryData queryData, ILocalResourceAccess localResourceAccess, final IAcceptor<IReferenceDescription> acceptor, IProgressMonitor monitor) { final SubMonitor subMonitor = SubMonitor.convert(monitor, 2); if (!queryData.getTargetURIs().isEmpty()) { findLocalReferences(queryData, localResourceAccess, acceptor, subMonitor.newChild(1)); findIndexedReferences(queryData, acceptor, subMonitor.newChild(1)); } }
/** * @param monitor the progress monitor to use for reporting progress to the user. It is the * caller's responsibility to call done() on the given monitor. Accepts null, indicating that * no progress should be reported and that the operation cannot be cancelled. */ protected void fullBuild(final IProgressMonitor monitor, boolean isRecoveryBuild) throws CoreException { SubMonitor progress = SubMonitor.convert(monitor, 10); IProject project = getProject(); ToBeBuilt toBeBuilt = isRecoveryBuild ? toBeBuiltComputer.updateProjectNewResourcesOnly(project, progress.newChild(2)) : toBeBuiltComputer.updateProject(project, progress.newChild(2)); doBuild(toBeBuilt, progress.newChild(8), isRecoveryBuild ? BuildType.RECOVERY : BuildType.FULL); }
@Override public RefactoringStatus checkInitialConditions(final IProgressMonitor monitor) throws CoreException { final SubMonitor progress = SubMonitor.convert(monitor, 6); RAstNode rootNode = null; try { if (fSelectionRegion != null) { fSourceUnit.connect(progress.newChild(1)); try { final AbstractDocument document = fSourceUnit.getDocument(monitor); final RHeuristicTokenScanner scanner = fAdapter.getScanner(fSourceUnit); final IRModelInfo modelInfo = (IRModelInfo) fSourceUnit.getModelInfo( RModel.TYPE_ID, IRModelManager.MODEL_FILE, progress.newChild(1)); if (modelInfo != null) { final IRegion region = fAdapter.trimToAstRegion(document, fSelectionRegion, scanner); final AstInfo ast = modelInfo.getAst(); if (ast != null) { rootNode = (RAstNode) AstSelection.search( ast.root, region.getOffset(), region.getOffset() + region.getLength(), AstSelection.MODE_COVERING_SAME_LAST) .getCovering(); } } } finally { fSourceUnit.disconnect(progress.newChild(1)); } } if (rootNode == null) { return RefactoringStatus.createFatalErrorStatus( Messages.ExtractTemp_error_InvalidSelection_message); } final RefactoringStatus result = new RefactoringStatus(); fAdapter.checkInitialToModify(result, fElementSet); progress.worked(1); if (result.hasFatalError()) { return result; } searchVariables(rootNode, result); progress.worked(2); return result; } finally { progress.done(); } }
/** * Creates a new REDHAWK component project without any files. Should be invoked in the context of * a {@link org.eclipse.ui.actions.WorkspaceModifyOperation WorkspaceModifyOperation}. * * @param projectName The project name * @param projectLocation the location on disk to create the project * @param monitor the progress monitor to use for reporting progress to the user. It is the * caller's responsibility to call done() on the given monitor. Accepts null, indicating that * no progress should be reported and that the operation cannot be canceled. * @return The newly created project * @throws CoreException A problem occurs while creating the project */ public static IProject createEmptyProject( final String projectName, final URI projectLocation, final IProgressMonitor monitor) throws CoreException { final SubMonitor progress = SubMonitor.convert(monitor, "Creating empty project", 2); final String[] additionalNatureIDs = new String[] {ScaComponentProjectNature.ID, "org.python.pydev.pythonNature"}; final IProject project = ProjectCreator.createEmptyProject( projectName, projectLocation, additionalNatureIDs, progress.newChild(1)); ProjectCreator.resetProject(project, progress.newChild(1)); return project; }
@Override public void build(final IBuildContext context, IProgressMonitor monitor) throws CoreException { if (!isEnabled(context)) { return; } final List<IResourceDescription.Delta> deltas = getRelevantDeltas(context); if (deltas.isEmpty()) { return; } StoppedTask task = Stopwatches.forTask( "org.eclipse.xtext.builder.BuilderParticipant.build(IBuildContext, IProgressMonitor)"); try { task.start(); // monitor handling if (monitor.isCanceled()) throw new OperationCanceledException(); SubMonitor subMonitor = SubMonitor.convert(monitor, context.getBuildType() == BuildType.RECOVERY ? 5 : 3); EclipseResourceFileSystemAccess2 access = fileSystemAccessProvider.get(); IProject builtProject = context.getBuiltProject(); access.setProject(builtProject); Map<String, OutputConfiguration> outputConfigurations = getOutputConfigurations(context); refreshOutputFolders(context, outputConfigurations, subMonitor.newChild(1)); if (subMonitor.isCanceled()) { throw new OperationCanceledException(); } access.setOutputConfigurations(outputConfigurations); if (context.getBuildType() == BuildType.CLEAN || context.getBuildType() == BuildType.RECOVERY) { SubMonitor cleanMonitor = SubMonitor.convert(subMonitor.newChild(2), outputConfigurations.size()); for (OutputConfiguration config : outputConfigurations.values()) { cleanOutput(context, config, access, cleanMonitor.newChild(1)); } if (context.getBuildType() == BuildType.CLEAN) return; } Map<OutputConfiguration, Iterable<IMarker>> generatorMarkers = getGeneratorMarkers(builtProject, outputConfigurations.values()); if (subMonitor.isCanceled()) { throw new OperationCanceledException(); } doBuild( deltas, outputConfigurations, generatorMarkers, context, access, subMonitor.newChild(2)); } finally { task.stop(); } }
/** * @param monitor the progress monitor to use for reporting progress to the user. It is the * <em>implementors</em> responsibility to call done() on the given monitor. Accepts null, * indicating that no progress should be reported and that the operation cannot be cancelled. */ @Override protected void clean(IProgressMonitor monitor) throws CoreException { SubMonitor progress = SubMonitor.convert(monitor, 10); try { ToBeBuilt toBeBuilt = toBeBuiltComputer.removeProject(getProject(), progress.newChild(2)); if (monitor.isCanceled()) { throw new OperationCanceledException(); } doClean(toBeBuilt, progress.newChild(8)); } finally { if (monitor != null) monitor.done(); } }
@Override protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { SubMonitor subMonitor = SubMonitor.convert(monitor, getCreateModelProjectMessage(), 2); try { final IProject project = createProject(subMonitor.newChild(1)); if (project == null) return; enhanceProject(project, subMonitor.newChild(1)); IFile modelFile = getModelFile(project); setResult(modelFile); } finally { subMonitor.done(); } }
private void create_project( final String project_path, final String lang, final String codegenId, final String templateId, String project_type, final IProgressMonitor progressMonitor) throws CoreException { final SubMonitor monitor = SubMonitor.convert(progressMonitor, 2); final IPath projectPath = new Path(project_path); if (projectPath.toFile().exists()) { throw new CoreException( new Status( IStatus.ERROR, CodegeneratorApplication.PLUGIN_ID, "Provided project path must not yet exist", null)); } if (lang == null) { throw new CoreException( new Status( IStatus.ERROR, CodegeneratorApplication.PLUGIN_ID, "You must provide a programming language when creating a new component project", null)); } // Clean-up project_type if ((project_type == null) || ("resource".equals(project_type))) { create_component_project(projectPath, lang, codegenId, templateId, monitor.newChild(1)); } else if ("device".equals(project_type)) { project_type = "device"; create_device_project( projectPath, "Device", lang, codegenId, templateId, monitor.newChild(1)); } else if ("loadabledevice".equals(project_type)) { project_type = "device"; create_device_project( projectPath, "Loadable", lang, codegenId, templateId, monitor.newChild(1)); } else if ("executabledevice".equals(project_type)) { project_type = "device"; create_device_project( projectPath, "Executable", lang, codegenId, templateId, monitor.newChild(1)); } else { throw new CoreException( new Status( IStatus.ERROR, CodegeneratorApplication.PLUGIN_ID, "Unsupported project type", null)); } }
@Override protected IStatus run(IProgressMonitor monitor) { final XtextEditor editor = initialEditor; final boolean isMarkOccurrences = initialIsMarkOccurrences; final ITextSelection selection = initialSelection; final SubMonitor progress = SubMonitor.convert(monitor, 2); if (!progress.isCanceled()) { final Map<Annotation, Position> annotations = (isMarkOccurrences) ? occurrenceComputer.createAnnotationMap(editor, selection, progress.newChild(1)) : Collections.<Annotation, Position>emptyMap(); if (!progress.isCanceled()) { Display.getDefault() .asyncExec( new Runnable() { public void run() { if (!progress.isCanceled()) { final IAnnotationModel annotationModel = getAnnotationModel(editor); if (annotationModel instanceof IAnnotationModelExtension) ((IAnnotationModelExtension) annotationModel) .replaceAnnotations( getExistingOccurrenceAnnotations(annotationModel), annotations); else if (annotationModel != null) throw new IllegalStateException( "AnnotationModel does not implement IAnnotationModelExtension"); //$NON-NLS-1$ } } }); } } return progress.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS; }
private void compileFiles(BuildContext[] contexts, IProgressMonitor monitor) throws CoreException { SubMonitor sub = SubMonitor.convert(monitor, "Analyzing Files...", fParticipants.length + contexts.length); if (fParticipants != null) { for (int i = 0; i < fParticipants.length; i++) { if (monitor.isCanceled()) throw new OperationCanceledException(); try { long start = System.currentTimeMillis(); fParticipants[i].buildStarting(contexts, true, sub.newChild(1)); if (RubyBuilder.DEBUG) System.out.println( fParticipants[i].getClass().getSimpleName() + " took " + (System.currentTimeMillis() - start) + "ms"); } catch (Exception e) { RubyCore.log(e); } } } for (int i = 0; i < contexts.length; i++) { CategorizedProblem[] problems = contexts[i].getProblems(); if (problems == null || problems.length == 0) { sub.worked(1); continue; } for (int j = 0; j < problems.length; j++) { markerManager.addProblem(contexts[i].getFile(), problems[j]); } sub.worked(1); } sub.done(); }
private void buildFiles( List<IBuildParticipant> participants, Collection<IFile> files, IProgressMonitor monitor) throws CoreException { if (CollectionsUtil.isEmpty(participants) || CollectionsUtil.isEmpty(files)) { return; } SubMonitor sub = SubMonitor.convert(monitor, 100); // Filter files = filterFiles(files, sub.newChild(10)); // Then build doBuildFiles(participants, files, sub.newChild(90)); sub.done(); }
private void doBuildFiles( List<IBuildParticipant> participants, Collection<IFile> files, IProgressMonitor monitor) throws CoreException { if (CollectionsUtil.isEmpty(files)) { return; } SubMonitor sub = SubMonitor.convert(monitor, 15 * files.size()); for (IFile file : files) { BuildContext context = new BuildContext(file); sub.worked(1); IBuildParticipantManager manager = getBuildParticipantManager(); if (manager == null) { return; } List<IBuildParticipant> filteredParticipants = manager.filterParticipants(participants, context.getContentType()); sub.worked(2); buildFile(context, filteredParticipants, sub.newChild(12)); // stop building if canceled if (sub.isCanceled()) { break; } } sub.done(); }
@Override public List<Object> computeContext( IInteractionContext context, IAdaptable input, IProgressMonitor monitor) { if (delegates == null || delegates.isEmpty()) { return Collections.emptyList(); } List<Object> objects = new ArrayList<Object>(); SubMonitor progress = SubMonitor.convert(monitor); int workPerDelegate = 1000; progress.beginTask( Messages.CompoundContextComputationStrategy_Computing_Context_Task_Label, delegates.size() * workPerDelegate); try { for (ContextComputationStrategy delegate : delegates) { if (progress.isCanceled()) { break; } objects.addAll(delegate.computeContext(context, input, progress.newChild(workPerDelegate))); } } finally { progress.done(); } return objects; }
@Override protected void clean(IProgressMonitor monitor) throws CoreException { super.clean(monitor); IProject project = getProjectHandle(); IBuildParticipantManager manager = getBuildParticipantManager(); if (manager == null) { return; } List<IBuildParticipant> participants = manager.getAllBuildParticipants(); participants = filterToEnabled(participants, project); SubMonitor sub = SubMonitor.convert(monitor, participants.size() + 2); sub.worked(1); removeProblemsAndTasksFor(project); sub.worked(1); // FIXME Should we visit all files and call "deleteFile" sort of like what we do with fullBuild? for (IBuildParticipant participant : participants) { if (sub.isCanceled()) { return; } participant.clean(project, sub.newChild(1)); } sub.done(); }
/** This method is extremely expensive. */ @OnEclipseVersionUpgrade("Replace monitor.newChild(1) by monitor.split(1)") private boolean isMethodUsedInItsPackage(IMethodBinding methodBinding, MethodDeclaration node) { final IPackageBinding methodPackage = methodBinding.getDeclaringClass().getPackage(); final AtomicBoolean methodIsUsedInPackage = new AtomicBoolean(false); final SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) { methodIsUsedInPackage.set(true); } }; final SubMonitor subMonitor = SubMonitor.convert(ctx.getProgressMonitor(), 1); final SubMonitor childMonitor = subMonitor.newChild(1); try { final SearchEngine searchEngine = new SearchEngine(); searchEngine.search( createPattern(methodBinding.getJavaElement(), REFERENCES, R_EXACT_MATCH), new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, SearchEngine.createJavaSearchScope(new IJavaElement[] {methodPackage.getJavaElement()}), requestor, childMonitor); return methodIsUsedInPackage.get(); } catch (CoreException e) { throw new UnhandledException(node, e); } finally { childMonitor.done(); } }
@Override public IStatus execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException { final SubMonitor progress = SubMonitor.convert( monitor, Messages.getString("org.kalypso.model.flood.ui.map.operations.ImportTinOperation.0"), 100); //$NON-NLS-1$ /* Add sources as new tin references */ progress.subTask( Messages.getString( "org.kalypso.model.flood.ui.map.operations.ImportTinOperation.1")); //$NON-NLS-1$ m_tinRefs = new ITinReference[m_sources.length]; final Feature[] changedFeatures = new Feature[m_sources.length]; for (int i = 0; i < m_sources.length; i++) { final IGmlSource source = m_sources[i]; final ITinReference tinRef = m_tins.addNew(-1, ITinReference.QNAME, ITinReference.class); tinRef.setName(source.getName()); tinRef.setDescription(source.getDescription()); tinRef.setSourceLocation(source.getLocation()); tinRef.setSourceFeaturePath(source.getPath()); tinRef.setSourceType(typeForSource(source)); m_tinRefs[i] = tinRef; changedFeatures[i] = tinRef; } ProgressUtilities.worked(progress, 20); /* post command for events stuff... */ final Feature parentFeature = m_tins.getParentFeature(); final GMLWorkspace workspace = parentFeature.getWorkspace(); final ModellEvent modelEvent = new FeatureStructureChangeModellEvent( workspace, parentFeature, changedFeatures, FeatureStructureChangeModellEvent.STRUCTURE_CHANGE_ADD); workspace.fireModellEvent(modelEvent); /* Save data model */ // progress.subTask( "speichere Datenmodell" ); // m_provider.saveModel( IFloodModel.class, progress.newChild( 20 ) ); /* update tins */ progress.subTask( Messages.getString( "org.kalypso.model.flood.ui.map.operations.ImportTinOperation.2")); //$NON-NLS-1$ final UpdateTinsOperation updateOp = new UpdateTinsOperation(m_tinRefs, m_provider); updateOp.execute(progress.newChild(60)); /* Jump to imported tins */ final GM_Envelope envelope = FeatureHelper.getEnvelope(changedFeatures); final GM_Envelope scaledBox = envelope == null ? null : GeometryUtilities.scaleEnvelope(envelope, 1.05); if (m_mapPanel != null && scaledBox != null) m_mapPanel.setBoundingBox(scaledBox); return Status.OK_STATUS; }
/** * Run a refresh synchronously. FIXME Should this even be visible to callers? We should pick up * file events via watcher to refresh whenever we really need to. This should become default * visibility. * * @param monitor * @return */ public IStatus refresh(IProgressMonitor monitor) { SubMonitor sub = SubMonitor.convert(monitor, 100); try { return refresh(true, null, sub.newChild(100)); } finally { sub.done(); } }
private List<String> createChanges(final TextFileChange change, final SubMonitor progress) throws BadLocationException { final List<String> names = new ArrayList<String>(); int remaining = fVariablesList.size() + 3; progress.setWorkRemaining(remaining); remaining -= 3; fSourceUnit.connect(progress.newChild(2)); try { for (final Map<String, Variable> frameList : fVariablesList.values()) { progress.setWorkRemaining(remaining--); createMainChanges(frameList, change, names); } return names; } finally { fSourceUnit.disconnect(progress.newChild(1)); } }
/** * Scans the specified source {@linkplain CompilationUnit} for contributed API javadoc tags. Tags * on methods will have unresolved signatures. * * @param source the source file to scan for tags * @param description the API description to annotate with any new tag rules found * @param container optional class file container containing the class file for the given source * that can be used to resolve method signatures if required (for tags on methods). If not * provided (<code>null</code>), method signatures will be unresolved. * @param options a map of Java compiler options to use when creating the AST to scan or <code> * null</code> if default options should be used * @param monitor * @throws CoreException */ public void scan( CompilationUnit source, IApiDescription description, IApiTypeContainer container, Map options, IProgressMonitor monitor) throws CoreException { SubMonitor localmonitor = SubMonitor.convert(monitor, 2); ASTParser parser = ASTParser.newParser(AST.JLS3); InputStream inputStream = null; try { inputStream = source.getInputStream(); parser.setSource( Util.getInputStreamAsCharArray( inputStream, -1, System.getProperty("file.encoding"))); // $NON-NLS-1$ } catch (FileNotFoundException e) { throw new CoreException( new Status( IStatus.ERROR, ApiPlugin.PLUGIN_ID, MessageFormat.format( "Compilation unit source not found: {0}", new String[] {source.getName()}), e)); //$NON-NLS-1$ } catch (IOException e) { if (DEBUG) { System.err.println(source.getName()); } throw new CoreException( new Status( IStatus.ERROR, ApiPlugin.PLUGIN_ID, MessageFormat.format( "Error reading compilation unit: {0}", new String[] {source.getName()}), e)); //$NON-NLS-1$ } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { ApiPlugin.log(e); } } } Util.updateMonitor(localmonitor); Map loptions = options; if (loptions == null) { loptions = JavaCore.getOptions(); } loptions.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); parser.setCompilerOptions(loptions); org.eclipse.jdt.core.dom.CompilationUnit cunit = (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(localmonitor.newChild(1)); Visitor visitor = new Visitor(description, container); cunit.accept(visitor); if (visitor.getException() != null) { throw visitor.getException(); } }