List of usage examples for org.eclipse.jdt.core JavaCore run
public static void run(IWorkspaceRunnable action, IProgressMonitor monitor) throws CoreException
From source file:com.javadude.antxr.eclipse.core.AntxrNature.java
License:Open Source License
public void configure() throws CoreException { if (AntxrNature.DEBUG) { System.out.println("configuring ANTXR nature"); }//w w w .j a va2s. c o m IProject project = getProject(); IProjectDescription projectDescription = project.getDescription(); List<ICommand> commands = new ArrayList<ICommand>(Arrays.asList(projectDescription.getBuildSpec())); ICommand antxrBuilderCommand = projectDescription.newCommand(); antxrBuilderCommand.setBuilderName(AntxrBuilder.BUILDER_ID); ICommand warningCleanerBuilderCommand = projectDescription.newCommand(); warningCleanerBuilderCommand.setBuilderName(WarningCleanerBuilder.BUILDER_ID); ICommand smapBuilderCommand = projectDescription.newCommand(); smapBuilderCommand.setBuilderName(SMapInstallerBuilder.BUILDER_ID); if (!commands.contains(antxrBuilderCommand)) { commands.add(0, antxrBuilderCommand); // add at start } if (!commands.contains(warningCleanerBuilderCommand)) { commands.add(warningCleanerBuilderCommand); // add at end } if (!commands.contains(smapBuilderCommand)) { commands.add(smapBuilderCommand); // add at end } // Commit the spec change into the project projectDescription.setBuildSpec(commands.toArray(new ICommand[commands.size()])); getProject().setDescription(projectDescription, null); // // add the antxr.jar file to a lib dir // IFolder folder = getProject().getFolder("lib"); // if (!folder.exists()) { // folder.create(true, true, null); // } // IPath rawLocation = folder.getRawLocation(); // URL antxrJarUrl = AntxrCorePlugin.getDefault().getBundle().getEntry("lib/antxr.jar"); // // BufferedOutputStream bout = null; // BufferedInputStream bin = null; // int b; // try { // try { // bout = new BufferedOutputStream(new FileOutputStream(new File(rawLocation.toFile(), "antxr.jar"))); // bin = new BufferedInputStream(antxrJarUrl.openStream()); // while ((b = bin.read()) != -1) { // bout.write(b); // } // } finally { // if (bout != null) { // bout.close(); // } // if (bin != null) { // bin.close(); // } // } // } catch (IOException e) { // e.printStackTrace(); // } // // folder.refreshLocal(IResource.DEPTH_ONE, null); // // // add the jar to the classpath if not present // String jarPath = "/" + getProject().getName() + "/lib/antxr.jar"; IFolder antxr3GeneratedFolder = getProject().getFolder("antxr-generated"); if (!antxr3GeneratedFolder.exists()) { antxr3GeneratedFolder.create(true, true, null); } String generatedSourcePath = "/" + getProject().getName() + "/antxr-generated"; final IJavaProject javaProject = JavaCore.create(getProject()); IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); boolean generatedSourceDirFound = false; for (IClasspathEntry classpathEntry : rawClasspath) { // if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { // if (classpathEntry.getPath().toString().equals(jarPath)) { // found = true; // } // } if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (classpathEntry.getPath().toString().equals(generatedSourcePath)) { generatedSourceDirFound = true; } } } int toAdd = 0; if (!generatedSourceDirFound) { toAdd++; } if (!generatedSourceDirFound) { final IClasspathEntry newEntries[] = new IClasspathEntry[rawClasspath.length + toAdd]; System.arraycopy(rawClasspath, 0, newEntries, 0, rawClasspath.length); // newEntries[rawClasspath.length] = JavaCore.newLibraryEntry(new Path(jarPath), Path.EMPTY, Path.ROOT); if (!generatedSourceDirFound) { newEntries[newEntries.length - 1] = JavaCore.newSourceEntry(new Path(generatedSourcePath)); } JavaCore.run(new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { javaProject.setRawClasspath(newEntries, null); } }, null); } }
From source file:com.javadude.antxr.eclipse.core.AntxrNature.java
License:Open Source License
public void deconfigure() throws CoreException { if (AntxrNature.DEBUG) { System.out.println("deconfiguring ANTXR nature"); }// w w w . j a v a 2 s . c o m IProject project = getProject(); IProjectDescription desc = project.getDescription(); List<ICommand> commands = new ArrayList<ICommand>(Arrays.asList(desc.getBuildSpec())); for (Iterator i = commands.iterator(); i.hasNext();) { ICommand command = (ICommand) i.next(); if (command.getBuilderName().equals(AntxrBuilder.BUILDER_ID) || command.getBuilderName().equals(SMapInstallerBuilder.BUILDER_ID) || command.getBuilderName().equals(WarningCleanerBuilder.BUILDER_ID)) { i.remove(); } } // Commit the spec change into the project desc.setBuildSpec(commands.toArray(new ICommand[commands.size()])); project.setDescription(desc, null); // remove the jar from the classpath if present // delete the jar from the lib dir // if the lib dir is empty, delete it // String jarPath = "/" + getProject().getName() + "/lib/antxr.jar"; String generatedSourcePath = "/" + getProject().getName() + "/antxr-generated"; final IJavaProject javaProject = JavaCore.create(getProject()); IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); final List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(); for (IClasspathEntry entry : rawClasspath) { // if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { // if (entry.getPath().toString().equals(jarPath)) { // found = i; // break; // } if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (entry.getPath().toString().equals(generatedSourcePath)) { continue; // skip the antxr-generated source folder } } newEntries.add(entry); } JavaCore.run(new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { IClasspathEntry entries[] = newEntries.toArray(new IClasspathEntry[newEntries.size()]); javaProject.setRawClasspath(entries, null); IFolder folder = getProject().getFolder("antxr-generated"); if (folder.exists() && !hasNonAntxrGeneratedFile(folder)) { folder.delete(true, null); } else { AntxrCorePlugin.getUtil().warning(4211, "Did not delete antxr-generated source directory; it contains non-generated source. You should move that source to another source dir; it really doesn't belong there..."); } } }, null); }
From source file:org.eclipse.buildship.core.workspace.internal.SynchronizeCompositeBuildOperation.java
License:Open Source License
@Override public void run(IProgressMonitor monitor) throws CoreException { JavaCore.run(new IWorkspaceRunnable() { @Override// ww w. j a v a 2 s .co m public void run(IProgressMonitor monitor) throws CoreException { synchronizeGradleBuilds(monitor); } }, monitor); }
From source file:org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildOperation.java
License:Open Source License
private void synchronizeJavaProject(final OmniEclipseProject project, final IProject workspaceProject, final PersistentModelBuilder persistentModel, SubMonitor progress) throws CoreException { JavaCore.run(new IWorkspaceRunnable() { @Override//from w w w. j a va 2s.c om public void run(IProgressMonitor monitor) throws CoreException { SubMonitor progress = SubMonitor.convert(monitor); synchronizeJavaProjectInTransaction(project, workspaceProject, persistentModel, progress); } }, progress.newChild(1)); }
From source file:org.eclipse.objectteams.otdt.ui.tests.refactoring.extractmethod.AbstractSelectionTestCase.java
License:Open Source License
protected void performTest(final ICompilationUnit unit, final Refactoring refactoring, int mode, final String out, boolean doUndo) throws Exception { IProgressMonitor pm = new NullProgressMonitor(); switch (mode) { case VALID_SELECTION: assertTrue(checkPreconditions(refactoring, pm).isOK()); break;/*from ww w . j a va 2 s .c om*/ case INVALID_SELECTION: assertTrue(!checkPreconditions(refactoring, pm).isOK()); break; case COMPARE_WITH_OUTPUT: IUndoManager undoManager = RefactoringCore.getUndoManager(); undoManager.flush(); String original = unit.getSource(); PerformRefactoringOperation op = new PerformRefactoringOperation(refactoring, getCheckingStyle()); JavaCore.run(op, new NullProgressMonitor()); assertTrue("Precondition check failed", !op.getConditionStatus().hasFatalError()); assertTrue("Validation check failed", !op.getValidationStatus().hasFatalError()); assertNotNull("No Undo", op.getUndoChange()); compareSource(unit.getSource(), out); Change undo = op.getUndoChange(); assertNotNull("Undo doesn't exist", undo); assertTrue("Undo manager is empty", undoManager.anythingToUndo()); if (doUndo) { undoManager.performUndo(null, new NullProgressMonitor()); assertTrue("Undo manager still has undo", !undoManager.anythingToUndo()); assertTrue("Undo manager is empty", undoManager.anythingToRedo()); compareSource(original, unit.getSource()); } break; } }
From source file:repast.simphony.eclipse.util.WorkspaceRunnableAdapter.java
License:Open Source License
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try {/*from w ww . j ava2 s. co m*/ JavaCore.run(workspaceRunnable, monitor); } catch (OperationCanceledException e) { throw new InterruptedException(e.getMessage()); } catch (CoreException e) { throw new InvocationTargetException(e); } }