protected List<IProject> importProjects(Collection<String> paths) throws Exception { final List<IPath> roots = new ArrayList<>(); for (String path : paths) { File file = copyFiles(path, true); roots.add(Path.fromOSString(file.getAbsolutePath())); } IWorkspaceRunnable runnable = new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { projectsManager.initializeProjects(roots, monitor); } }; JavaCore.run(runnable, null, monitor); waitForBackgroundJobs(); return WorkspaceHelper.getAllProjects(); }
public synchronized void appendText(final String text) { try { ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { // System.out.print(Thread.currentThread().getId() + " : " + message); outFile.appendContents(new ByteArrayInputStream(text.getBytes()), IResource.FORCE, monitor); } }, rule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor()); // if the console output is active, print to it } catch (CoreException e) { TLCActivator.logError("Error writing the TLC process output file for " + model.getName(), e); } }
public void saveEditors(final IRenameElementContext context) { new DisplayRunnable() { @Override protected void run() throws Exception { workspace.run(new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { IWorkbenchPage workbenchPage = getWorkbenchPage(context); if (prefs.isSaveAllBeforeRefactoring()) workbenchPage.saveAllEditors(false); else saveDeclaringEditor(context, workbenchPage); } }, new NullProgressMonitor()); } }.syncExec(); syncUtil.waitForBuild(null); }
@Override public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { IWorkspaceRunnable workspaceRunnable = new IWorkspaceRunnable() { @Override public void run(IProgressMonitor pm) throws CoreException { try { run2(pm); } catch (Exception e) { // Re-throw as OperationCanceledException, which will be // caught and re-thrown as InterruptedException below. throw new OperationCanceledException(e.getMessage()); } // CoreException and OperationCanceledException are propagated } }; ResourcesPlugin.getWorkspace().run(workspaceRunnable, resource, IResource.NONE, monitor); return monitor.isCanceled()? Status.CANCEL_STATUS : Status.OK_STATUS; }
/** * Removes an IJavaElement's resource. Retries if deletion failed (e.g. because the indexer still * locks the file). * * @param elem the element to delete * @throws CoreException if operation failed * @see #ASSERT_NO_MIXED_LINE_DELIMIERS */ public static void delete(final IJavaElement elem) throws CoreException { // if (ASSERT_NO_MIXED_LINE_DELIMIERS) // MixedLineDelimiterDetector.assertNoMixedLineDelimiters(elem); if (elem instanceof JavaProject) { ((JavaProject) elem).close(); JavaModelManager.getJavaModelManager().removePerProjectInfo((JavaProject) elem, true); } JavaModelManager.getJavaModelManager().resetTemporaryCache(); IWorkspaceRunnable runnable = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { // performDummySearch(); if (elem instanceof IJavaProject) { IJavaProject jproject = (IJavaProject) elem; jproject.setRawClasspath( new IClasspathEntry[0], jproject.getProject().getFullPath(), null); } delete(elem.getResource()); } }; ResourcesPlugin.getWorkspace().run(runnable, null); // emptyDisplayLoop(); }
/** * Removes all files in the project and sets the given classpath * * @param jproject The project to clear * @param entries The default class path to set * @throws Exception Clearing the project failed */ public static void clear(final IJavaProject jproject, final IClasspathEntry[] entries) throws Exception { // performDummySearch(); IWorkspaceRunnable runnable = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { jproject.setRawClasspath(entries, null); IResource[] resources = jproject.getProject().members(); for (int i = 0; i < resources.length; i++) { // if (!resources[i].getName().startsWith(".")) { delete(resources[i]); // } } } }; ResourcesPlugin.getWorkspace().run(runnable, null); // JavaProjectHelper.emptyDisplayLoop(); }
public void execute(IProgressMonitor m) throws CoreException { IProgressMonitor monitor; if (m == null) monitor = new NullProgressMonitor(); else monitor = m; if (type == ResetType.HARD) { IWorkspaceRunnable action = new IWorkspaceRunnable() { public void run(IProgressMonitor actMonitor) throws CoreException { reset(actMonitor); } }; // lock workspace to protect working tree changes ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, monitor); } else { reset(monitor); } }
static public synchronized void setRootConfigurationFolder(final File configFolder) throws CoreException { ConfigDispatcher.setConfigFolder(configFolder.getAbsolutePath()); IWorkspaceRunnable runnable = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { IProject defaultProject = ResourcesPlugin.getWorkspace().getRoot().getProject("config"); if(!defaultProject.exists()) { initialize(defaultProject); } if(configFolder!=null) { folder = defaultProject.getFolder("config"); if(folder.exists()) { folder.delete(true, null); } folder.createLink(configFolder.toURI(), IResource.ALLOW_MISSING_LOCAL, null); } } }; ResourcesPlugin.getWorkspace().run(runnable, null); }
/** * Constructs a line breakpoint on the given resource at the given line number * (line number is 1-based). * * @param resource file on which to set the breakpoint * @param lineNumber 1-based line number of the breakpoint * @throws CoreException if unable to create the breakpoint */ public ChromiumLineBreakpoint(final IResource resource, final int lineNumber, final String modelId) throws CoreException { IWorkspaceRunnable runnable = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { IMarker marker = resource.createMarker(ChromiumDebugPlugin.BP_MARKER); setMarker(marker); marker.setAttribute(IBreakpoint.ENABLED, Boolean.TRUE); marker.setAttribute(IMarker.LINE_NUMBER, lineNumber); marker.setAttribute(IBreakpoint.ID, modelId); marker.setAttribute(IMarker.MESSAGE, NLS.bind( Messages.JsLineBreakpoint_MessageMarkerFormat, resource.getName(), lineNumber)); } }; run(getMarkerRule(resource), runnable); }
/** * Save the given plan in the workspace. * @param plan the plan to save * @param monitor a progress monitor */ protected final void savePlanResourceSet(final EPlan plan, final IProgressMonitor monitor) { final Resource planResource = plan.eResource(); IFile file = EMFUtils.getFile(planResource); IProject project = file.getProject(); try { IWorkspace workspace = project.getWorkspace(); workspace.run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor m) { EMFUtils.save(planResource, "Saving the plan and associated files", monitor, getIgnorablePredicate()); } }, project, IWorkspace.AVOID_UPDATE, null); } catch (CoreException e) { LogUtil.error(e); } }
private static void writeProp(final ProjectPropertyEvent event) throws CoreException { if (event.resource.exists()) { ws().run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) { try { if (event.resource.exists()) writeProp(event.resource, event.key, event.value); } catch (Throwable t) { LogUtil.error(t); } } }, event.resource.getProject(), IWorkspace.AVOID_UPDATE, null); } projProps(event.resource).notifyListeners(event); }
protected void createFolderStructure() { final IFolder resourcesFolder = newProject.getFolder("Resources"); final IFolder conditionsFolder = newProject.getFolder("Conditions"); final boolean force = true; final boolean local = true; try { ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { resourcesFolder.create(force, local, monitor); conditionsFolder.create(force, local, monitor); } }, null); } catch (CoreException e) { e.printStackTrace(); } }
/** * Set the selection and focus to the list of elements * @param elements the object to be selected and displayed */ public void setSelection(final List<?> elements) { if (elements == null || elements.size() == 0) return; try { ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { fPackageViewer.refresh(); IStructuredSelection selection= new StructuredSelection(elements); fPackageViewer.setSelection(selection, true); fPackageViewer.getTree().setFocus(); if (elements.size() == 1 && elements.get(0) instanceof IJavaProject) fPackageViewer.expandToLevel(elements.get(0), 1); } }, ResourcesPlugin.getWorkspace().getRoot(), IWorkspace.AVOID_UPDATE, new NullProgressMonitor()); } catch (CoreException e) { JavaPlugin.log(e); } }
@Test public void testRemoveEngineUsingName() throws CoreException { final HybridMobileEngine[] engines = new HybridMobileEngine[2]; engines[0] = new HybridMobileEngine("android", "6.0.0", null); engines[1] = new HybridMobileEngine("ios", "4.4.0", null); manager.updateEngines(engines); JobUtils.waitForIdle(); // Run on a IWorkspaceRunnable because it needs to sync with the udpateEngines // call. IWorkspaceRunnable runnable = new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { manager.removeEngine(engines[0].getName(), monitor, true); Widget w = WidgetModel.getModel(testproject.hybridProject()).getWidgetForRead(); assertEquals(1, w.getEngines().size()); assertEquals(1, manager.getEngines().length); checkEnginesPersistedCorrectly(new HybridMobileEngine[] { engines[1] }); } }; IWorkspace ws = ResourcesPlugin.getWorkspace(); ISchedulingRule rule = ws.getRuleFactory().modifyRule(testproject.getProject()); ws.run(runnable, rule, 0, new NullProgressMonitor()); }
@Test public void testRemoveEngine() throws CoreException { final HybridMobileEngine[] engines = new HybridMobileEngine[2]; engines[0] = new HybridMobileEngine("android", "6.0.0", null); engines[1] = new HybridMobileEngine("ios", "4.4.0", null); manager.updateEngines(engines); JobUtils.waitForIdle(); // Run on a IWorkspaceRunnable because it needs to sync with the udpateEngines // call. IWorkspaceRunnable runnable = new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { manager.removeEngine(engines[0], monitor, true); Widget w = WidgetModel.getModel(testproject.hybridProject()).getWidgetForRead(); assertEquals(1, w.getEngines().size()); checkEnginesPersistedCorrectly(new HybridMobileEngine[] { engines[1] }); } }; IWorkspace ws = ResourcesPlugin.getWorkspace(); ISchedulingRule rule = ws.getRuleFactory().modifyRule(testproject.getProject()); ws.run(runnable, rule, 0, new NullProgressMonitor()); }
public void createMarker(final IResource resource, final Map<String, Object> attributes, final String markerType) { if (resource == null || !resource.exists()) { return; } try { IWorkspaceRunnable r = new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { // apply marker IMarker marker = resource.createMarker(markerType); marker.setAttributes(attributes); } }; ISchedulingRule sr = getRule(resource); resource.getWorkspace().run(r, sr, IWorkspace.AVOID_UPDATE, null); } catch (CoreException e) { String logMessage = Utils.generateCoreExceptionLog(e); logger.warn("Unable to apply marker to resource: " + logMessage); } }
@Override public boolean performFinish() { boolean superResult = super.performFinish(); final IProject project = getNewProject(); IWorkspaceRunnable setUpSensIDLProject = new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { addSensidlFileTo(project); addXtextNatureTo(project); } }; try { ResourcesPlugin.getWorkspace().run(setUpSensIDLProject, null); } catch (CoreException e) { new ErrorDialogHandler().execute(new Shell(), e); return false; } return superResult; }
/** * Removes all files in the project and sets the given classpath * * @param jproject * The project to clear * @param entries * The default class path to set * @throws Exception * Clearing the project failed */ public static void clear(final IJavaProject jproject, final IClasspathEntry[] entries) throws Exception { IWorkspaceRunnable runnable = new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { jproject.setRawClasspath(entries, null); IResource[] resources = jproject.getProject().members(); for (int i = 0; i < resources.length; i++) { if (!resources[i].getName().startsWith(".")) { delete(resources[i]); } } } }; ResourcesPlugin.getWorkspace().run(runnable, null); JavaProjectHelper.emptyDisplayLoop(); }
public void start(IProgressMonitor monitor) throws CoreException { ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor innerMonitor) throws CoreException { // Needed to make IJavaProject.getResolvedClasspath() work properly. JavaCore.initializeAfterLoad(innerMonitor); for (IProject p : ResourcesPlugin.getWorkspace().getRoot().getProjects()) { if (p.isOpen()) { try { projectChanged(p); } catch (CoreException e) { RoboVMPlugin.log(e); } } } ResourcesPlugin.getWorkspace().addResourceChangeListener(RoboVMProjectObserver.this); } }, null); }
/** * Store the breakpoint properties. * @see org.eclipse.jface.preference.IPreferencePage#performOk() */ @Override public boolean performOk() { IWorkspaceRunnable wr = new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { PyBreakpoint breakpoint = getBreakpoint(); boolean delOnCancel = breakpoint.getMarker().getAttribute(ATTR_DELETE_ON_CANCEL) != null; if (delOnCancel) { // if this breakpoint is being created, remove the "delete on cancel" attribute // and register with the breakpoint manager breakpoint.getMarker().setAttribute(ATTR_DELETE_ON_CANCEL, (String) null); breakpoint.setRegistered(true); } doStore(); } }; try { ResourcesPlugin.getWorkspace().run(wr, null, 0, null); } catch (CoreException e) { PydevDebugPlugin.errorDialog("An exception occurred while saving breakpoint properties.", e); //$NON-NLS-1$ PydevDebugPlugin.log(IStatus.ERROR, e.getLocalizedMessage(), e); } return super.performOk(); }
private Resource createBpmnDiagram(URI diagramUri) throws CoreException { final Bpmn2Resource resource = Bpmn2DiagramCreator.createBpmn2Resource(diagramUri); ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { try { resource.save(null); } catch (IOException e) { throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to save file", e)); } } }, new NullProgressMonitor()); return resource; }
Builder workspace() { final Runnable temp = this; return new Builder() { @Override public void run() { try { ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { temp.run(); } }, new NullProgressMonitor()); } catch (CoreException e) { throw new RuntimeException(e); } } }; }
@After public void tearDown() throws Exception { // Should undo all wizard actions ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { IProject project = EclipseUtils.getWorkspaceRoot().getProject(NEWPROJNAME); if(project.exists()) { project.delete(true, monitor); } } }, null); if(wizDialog != null) { wizDialog.close(); } }
public void doAddErrorMarkers(Iterable<ToolSourceMessage> buildErrors, Location rootPath, IProgressMonitor pm) throws CoreException { documents.clear(); ResourceUtils.getWorkspace().run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { for(ToolSourceMessage buildError : buildErrors) { if(pm.isCanceled()) { return; } addErrorMarkers(buildError, rootPath); } } }, ResourceUtils.getWorkspaceRoot(), IWorkspace.AVOID_UPDATE, pm); }
protected void updateProblemMarkers() throws CoreException { // Review if this can run outside lock IFile[] files = ResourceUtils.getWorkspaceRoot().findFilesForLocationURI(location.toUri()); if(files.length == 0) { return; } final IFile file = files[0]; ResourceUtils.getWorkspace().run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { try { doCreateProblemMarkers(file); } catch(OperationCancellation e) { return; } } }, file, IWorkspace.AVOID_UPDATE, null); }
public static void connectResourceListener(IResourceChangeListener listener, RunnableX<CoreException> initialUpdate, ISchedulingRule opRule, IOwner owner) { try { getWorkspace().run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.POST_CHANGE); initialUpdate.run(); } }, opRule, IWorkspace.AVOID_UPDATE, null); } catch (CoreException ce) { EclipseCore.logStatus(ce); // This really should not happen, but still try to recover by registering the listener. getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.POST_CHANGE); } owner.bind(() -> ResourcesPlugin.getWorkspace().removeResourceChangeListener(listener)); }
@Override public void resourceChanged(IResourceChangeEvent event) { if (event.getType() == IResourceChangeEvent.POST_CHANGE) { IJavaElement javaElement = JavaCore.create(event.getResource()); if (javaElement != null && javaElement instanceof IJavaProject) { IJavaProject javaProject = (IJavaProject)javaElement; Set<Model> models = Utils.getModel(javaProject); if (models.isEmpty()) { Set<IJavaProject> javaProjects = new HashSet<IJavaProject>(); javaProjects.add(javaProject); IWorkspaceRunnable jdt2uml = new ExportModels(javaProjects); try { ResourcesPlugin.getWorkspace().run(jdt2uml, new NullProgressMonitor()); } catch (CoreException e) { CoreActivator.logUnexpectedError(e); } } else { handleDeltaChanges(event.getDelta()); } } } }
/** * We have to set dynamic dependencies in the project meta data to ensure that the builder is correctly triggered * according to the declared dependencies in the N4JS manifest files. * * @param project * the project to update in respect of its dynamic references. */ public void updateProjectReferencesIfNecessary(final IProject project) { if (project instanceof ExternalProject) { return; // No need to adjust any dynamic references. } try { IProject[] eclipseRequired = project.getDescription().getDynamicReferences(); Set<IProject> currentRequires = Sets.newHashSet(eclipseRequired); final Set<IProject> newRequires = getProjectDependenciesAsSet(project); if (currentRequires.equals(newRequires)) { return; } IWorkspaceRunnable runnable = new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { IProjectDescription description = project.getDescription(); IProject[] array = newRequires.toArray(new IProject[newRequires.size()]); description.setDynamicReferences(array); project.setDescription(description, IResource.AVOID_NATURE_CONFIG, monitor); } }; internalWorkspace.getWorkspace().getWorkspace().run(runnable, null /* cannot use a scheduling rule here since this is triggered lazily by the linker */, IWorkspace.AVOID_UPDATE, null); } catch (CoreException e) { // ignore } }
/** * Constructor. * * @param identifier * the debug model identifier * @param instruction * the {@link EObject} representing the instruction * @param persistent * should be persisted * @throws CoreException * if marker can't be installed */ public DSLBreakpoint(String identifier, EObject instruction, boolean persistent) throws CoreException { super(); this.identifier = identifier; this.instructionUri = EcoreUtil.getURI(instruction); final URI resourceURI = ((EObject)instruction).eResource().getURI(); final String pathString = resourceURI.toPlatformString(true); final IFile resource = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(pathString)); if (resource != null) { IWorkspaceRunnable runnable = new CreateMarker(resource, instruction, persistent); run(getMarkerRule(resource), runnable); } }
@Override public boolean performFinish() { try { createdProject = _askProjectNamePage.getProjectHandle(); final String languageName = _askLanguageNamePage.getLanguageName(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProjectDescription description = workspace.newProjectDescription(createdProject.getName()); if (!_askProjectNamePage.getLocationPath().equals(workspace.getRoot().getLocation())) description.setLocation(_askProjectNamePage.getLocationPath()); //description.setLocationURI(_askProjectNamePage.getLocationURI()); IWorkspaceRunnable operation = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { createdProject.create(description, monitor); createdProject.open(monitor); initializeProject(createdProject, languageName); createdProject.refreshLocal(IResource.DEPTH_INFINITE, monitor); createdProject.touch(new NullProgressMonitor()); // [FT] One touch to force eclipse to serialize the project properties that will update accordingly the gemoc actions in the menu. //createdProject.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor()); } }; ResourcesPlugin.getWorkspace().run(operation, null); } catch (CoreException exception) { Activator.error(exception.getMessage(), exception); return false; } return true; }
public void flushPendingStatuses() { if (accessor.isFlushFeasible()) { try { ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) { accessor.flushPendingCacheWrites(); } }, null); } catch (CoreException e) { SVNProviderPlugin.log(SVNException.wrapException(e)); } } }
private IAction getGetContentsAction() { if(getContentsAction == null) { getContentsAction = getContextMenuAction(Policy.bind("HistoryView.getContentsAction"), new IWorkspaceRunnable() { //$NON-NLS-1$ public void run(IProgressMonitor monitor) throws CoreException { ISelection selection = getSelection(); if( !(selection instanceof IStructuredSelection)) return; IStructuredSelection ss = (IStructuredSelection) selection; ISVNRemoteFile remoteFile = (ISVNRemoteFile) getLogEntry(ss).getRemoteResource(); monitor.beginTask(null, 100); try { if(remoteFile != null) { if(confirmOverwrite()) { if (remoteFile instanceof RemoteResource) { if (resource != null) { ISVNLocalResource localResource = SVNWorkspaceRoot.getSVNResourceFor(resource); ((RemoteResource)remoteFile).setPegRevision(localResource.getRevision()); } else { ((RemoteResource)remoteFile).setPegRevision(SVNRevision.HEAD); } } InputStream in = ((IResourceVariant) remoteFile).getStorage(new SubProgressMonitor(monitor, 50)) .getContents(); IFile file = (IFile) resource; file.setContents(in, false, true, new SubProgressMonitor(monitor, 50)); } } } catch(TeamException e) { throw new CoreException(e.getStatus()); } finally { monitor.done(); } } }); PlatformUI.getWorkbench().getHelpSystem().setHelp(getContentsAction, IHelpContextIds.GET_FILE_CONTENTS_ACTION); } return getContentsAction; }
public void didClose(DidCloseTextDocumentParams params) { try { ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { handleClosed(params); } }, new NullProgressMonitor()); } catch (CoreException e) { JavaLanguageServerPlugin.logException("Handle document close ", e); } }
public void didOpen(DidOpenTextDocumentParams params) { try { ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { handleOpen(params); } }, new NullProgressMonitor()); } catch (CoreException e) { JavaLanguageServerPlugin.logException("Handle document open ", e); } }
public void didChange(DidChangeTextDocumentParams params) { try { ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { handleChanged(params); } }, new NullProgressMonitor()); } catch (CoreException e) { JavaLanguageServerPlugin.logException("Handle document change ", e); } }
public void didSave(DidSaveTextDocumentParams params) { try { ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { handleSaved(params); } }, new NullProgressMonitor()); } catch (CoreException e) { JavaLanguageServerPlugin.logException("Handle document save ", e); } }
void didChangeWatchedFiles(DidChangeWatchedFilesParams param){ List<FileEvent> changes = param.getChanges(); for (FileEvent fileEvent : changes) { CHANGE_TYPE changeType = toChangeType(fileEvent.getType()); if(changeType==CHANGE_TYPE.DELETED){ cleanUpDiagnostics(fileEvent.getUri()); } ICompilationUnit unit = JDTUtils.resolveCompilationUnit(fileEvent.getUri()); if (unit != null && changeType == CHANGE_TYPE.CREATED && !unit.exists()) { final ICompilationUnit[] units = new ICompilationUnit[1]; units[0] = unit; try { ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { units[0] = createCompilationUnit(units[0]); } }, new NullProgressMonitor()); } catch (CoreException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); } unit = units[0]; } if (unit != null && unit.isWorkingCopy()) { continue; } if(changeType == CHANGE_TYPE.DELETED || changeType == CHANGE_TYPE.CHANGED){ SharedASTProvider.getInstance().invalidate(unit); } pm.fileChanged(fileEvent.getUri(), changeType); } }
public static IProject setUpProject(final String projectName, String compliance, String sourceWorkspacePath) throws CoreException, IOException { // copy files in project from source workspace to target workspace String targetWorkspacePath = getWorkspaceRoot().getLocation().toFile().getCanonicalPath(); copyDirectory(new File(sourceWorkspacePath, projectName), new File(targetWorkspacePath, projectName)); // create project final IProject project = getWorkspaceRoot().getProject(projectName); IWorkspaceRunnable populate = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { project.create(null); try { project.open(null); } catch (ConcurrentModificationException e) { // wait and try again to work-around // ConcurrentModificationException (bug 280488) try { Thread.sleep(500); project.open(null); project.refreshLocal(IResource.DEPTH_INFINITE, null); } catch (InterruptedException e1) { Thread.currentThread().interrupt(); } } } }; getWorkspace().run(populate, null); return project; }
@Override public boolean deleteTestSuiteElement(final IPackageFragment packageOfDeletedClass, final ICompilationUnit deletedClass) throws CoreException { init(); if (packageOfDeletedClass == null) { return true; } JavaCore.run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { ICompilationUnit testSuite = getTestSuite(packageOfDeletedClass); String testElementList = createCommaSeparatedClassList(packageOfDeletedClass.getCompilationUnits(), null, deletedClass.getElementName().replace(".java", "")); IType testSuiteType = refreshTestSuiteElements(testSuite, TESTSUITE_PREFIX, testElementList); // if only the test-class and the test-suite is in the package, // then delete the complete package if (testSuiteType == null && packageOfDeletedClass.getCompilationUnits().length == 2) { // delete empty packages, if no class is inside JDTUtils.deletePackages(packageOfDeletedClass); } } }, null); return true; }