org.eclipse.jdt.internal.ui.util.CoreUtility Java Examples
The following examples show how to use
org.eclipse.jdt.internal.ui.util.CoreUtility.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavaProjectHelper.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
/** * Adds a source container to a IJavaProject. * * @param jproject * The parent project * @param containerName * The name of the new source container * @param inclusionFilters * Inclusion filters to set * @param exclusionFilters * Exclusion filters to set * @return The handle to the new source container * @throws CoreException * Creation failed */ public static IPackageFragmentRoot addSourceContainer(IJavaProject jproject, String containerName, IPath[] inclusionFilters, IPath[] exclusionFilters) throws CoreException { IProject project = jproject.getProject(); IContainer container = null; if (containerName == null || containerName.length() == 0) { container = project; } else { IFolder folder = project.getFolder(containerName); if (!folder.exists()) { CoreUtility.createFolder(folder, false, true, null); } container = folder; } IPackageFragmentRoot root = jproject.getPackageFragmentRoot(container); IClasspathEntry cpe = JavaCore.newSourceEntry(root.getPath(), inclusionFilters, exclusionFilters, null); addToClasspath(jproject, cpe); return root; }
Example #2
Source File: JavaProjectHelper.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
/** * Creates and adds a class folder to the class path. * * @param jproject * The parent project * @param containerName * @param sourceAttachPath * The source attachment path * @param sourceAttachRoot * The source attachment root path * @return The handle of the created root * @throws CoreException */ public static IPackageFragmentRoot addClassFolder(IJavaProject jproject, String containerName, IPath sourceAttachPath, IPath sourceAttachRoot) throws CoreException { IProject project = jproject.getProject(); IContainer container = null; if (containerName == null || containerName.length() == 0) { container = project; } else { IFolder folder = project.getFolder(containerName); if (!folder.exists()) { CoreUtility.createFolder(folder, false, true, null); } container = folder; } IClasspathEntry cpe = JavaCore.newLibraryEntry(container.getFullPath(), sourceAttachPath, sourceAttachRoot); addToClasspath(jproject, cpe); return jproject.getPackageFragmentRoot(container); }
Example #3
Source File: BuildSettingWizardPage.java From sarl with Apache License 2.0 | 6 votes |
/** * Called from the wizard on finish. * * @param monitor the progress monitor * @throws CoreException thrown when the project creation or configuration failed * @throws InterruptedException thrown when the user canceled the project creation */ public void performFinish(IProgressMonitor monitor) throws CoreException, InterruptedException { final SubMonitor subMonitor = SubMonitor.convert(monitor, 4); try { monitor.beginTask(NewWizardMessages.NewJavaProjectWizardPageTwo_operation_create, 3); if (this.currProject == null) { updateProject(subMonitor.newChild(1)); } final String newProjectCompliance = this.keepContent ? null : this.firstPage.getCompilerCompliance(); configureJavaProject(newProjectCompliance, subMonitor.newChild(1)); } catch (Throwable e) { if (this.currProject != null) { removeProvisonalProject(); } throw e; } finally { subMonitor.done(); this.currProject = null; if (this.isAutobuild != null) { CoreUtility.setAutoBuilding(this.isAutobuild.booleanValue()); this.isAutobuild = null; } } }
Example #4
Source File: NewJavaProjectWizardPageTwo.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Called from the wizard on finish. * * @param monitor the progress monitor * @throws CoreException thrown when the project creation or configuration failed * @throws InterruptedException thrown when the user cancelled the project creation */ public void performFinish(IProgressMonitor monitor) throws CoreException, InterruptedException { try { monitor.beginTask(NewWizardMessages.NewJavaProjectWizardPageTwo_operation_create, 3); if (fCurrProject == null) { updateProject(new SubProgressMonitor(monitor, 1)); } String newProjectCompliance= fKeepContent ? null : fFirstPage.getCompilerCompliance(); configureJavaProject(newProjectCompliance, new SubProgressMonitor(monitor, 2)); } finally { monitor.done(); fCurrProject= null; if (fIsAutobuild != null) { CoreUtility.setAutoBuilding(fIsAutobuild.booleanValue()); fIsAutobuild= null; } } }
Example #5
Source File: ContributedJavadocWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private JavadocExportWizardPage getPage() { if (fPage == null) { try { Object elem= CoreUtility.createExtension(fConfigElement, ATT_PAGE_CLASS); if (elem instanceof JavadocExportWizardPage) { fPage= (JavadocExportWizardPage) elem; fPage.setContainer(this); statusUpdated(); return fPage; } } catch (CoreException e) { JavaPlugin.log(e); } fPage= new ErrorJavadocExportWizardPage(); } return fPage; }
Example #6
Source File: BuildSettingWizardPage.java From sarl with Apache License 2.0 | 5 votes |
private void doRemoveProject(IProgressMonitor monitor) throws InvocationTargetException { // Test if the project is inside the workspace final boolean noProgressMonitor = this.currProjectLocation == null; final SubMonitor subMonitor = SubMonitor.convert(noProgressMonitor ? null : monitor, 3); subMonitor.beginTask(NewWizardMessages.NewJavaProjectWizardPageTwo_operation_remove, 3); try { try { final URI projLoc = this.currProject.getLocationURI(); final boolean removeContent = !this.keepContent && this.currProject.isSynchronized(IResource.DEPTH_INFINITE); if (!removeContent) { restoreExistingFolders(projLoc); } this.currProject.delete(removeContent, false, subMonitor.newChild(2)); restoreExistingFiles(projLoc, subMonitor.newChild(1)); } finally { // fIsAutobuild must be set CoreUtility.setAutoBuilding(this.isAutobuild.booleanValue()); this.isAutobuild = null; } } catch (CoreException e) { throw new InvocationTargetException(e); } finally { subMonitor.done(); this.currProject = null; this.keepContent = false; } }
Example #7
Source File: JavaProjectHelper.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
/** * Creates a IJavaProject. * * @param projectName * The name of the project * @param binFolderName * Name of the output folder * @return Returns the Java project handle * @throws CoreException * Project creation failed */ public static IJavaProject createJavaProject(String projectName, String binFolderName) throws CoreException { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(projectName); if (!project.exists()) { project.create(null); } else { project.refreshLocal(IResource.DEPTH_INFINITE, null); } if (!project.isOpen()) { project.open(null); } IPath outputLocation; if (binFolderName != null && binFolderName.length() > 0) { IFolder binFolder = project.getFolder(binFolderName); if (!binFolder.exists()) { CoreUtility.createFolder(binFolder, false, true, null); } outputLocation = binFolder.getFullPath(); } else { outputLocation = project.getFullPath(); } if (!project.hasNature(JavaCore.NATURE_ID)) { addNatureToProject(project, JavaCore.NATURE_ID, null); } IJavaProject jproject = JavaCore.create(project); jproject.setOutputLocation(outputLocation, null); jproject.setRawClasspath(new IClasspathEntry[0], null); return jproject; }
Example #8
Source File: SARLProjectConfigurator.java From sarl with Apache License 2.0 | 5 votes |
private static IFolder ensureOutputFolder(IProject project, String folderPath, boolean isIFolderRequired, boolean createFolder, IProgressMonitor monitor) throws CoreException { final IFolder folder = project.getFolder(Path.fromPortableString(folderPath)); if (!folder.exists()) { if (createFolder) { CoreUtility.createFolder(folder, true, true, monitor); } else if (!isIFolderRequired) { monitor.done(); return null; } } setDerived(folder); monitor.done(); return folder; }
Example #9
Source File: SARLProjectConfigurator.java From sarl with Apache License 2.0 | 5 votes |
private static IFolder ensureSourceFolder(IProject project, String folderPath, boolean isIFolderRequired, boolean createFolder, IProgressMonitor monitor) throws CoreException { final IFolder folder = project.getFolder(Path.fromPortableString(folderPath)); if (!folder.exists()) { if (createFolder) { CoreUtility.createFolder(folder, true, true, monitor); } else if (!isIFolderRequired) { monitor.done(); return null; } } monitor.done(); return folder; }
Example #10
Source File: SARLProjectConfigurator.java From sarl with Apache License 2.0 | 5 votes |
private static IFolder ensureGeneratedSourceFolder(IProject project, String folderPath, boolean isIFolderRequired, boolean createFolder, IProgressMonitor monitor) throws CoreException { final IFolder folder = project.getFolder(Path.fromPortableString(folderPath)); if (!folder.exists()) { if (createFolder) { CoreUtility.createFolder(folder, true, true, monitor); } else if (!isIFolderRequired) { monitor.done(); return null; } } setDerived(folder); monitor.done(); return folder; }
Example #11
Source File: ClasspathAttributeConfigurationDescriptors.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public ClasspathAttributeConfiguration getInstance() throws CoreException { if (fInstance == null) { Object elem= CoreUtility.createExtension(fConfigElement, ATT_CLASS); if (elem instanceof ClasspathAttributeConfiguration) { fInstance= (ClasspathAttributeConfiguration) elem; } else { throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, 0, "Invalid extension (page not of type IClasspathContainerPage): " + getKey(), null)); //$NON-NLS-1$ } } return fInstance; }
Example #12
Source File: LoggedCreateTargetQueries.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void createPackageFragmentRoot(IPackageFragmentRoot root) throws CoreException { final IJavaProject project= root.getJavaProject(); if (!project.exists()) createJavaProject(project.getProject()); final IFolder folder= project.getProject().getFolder(root.getElementName()); if (!folder.exists()) CoreUtility.createFolder(folder, true, true, new NullProgressMonitor()); final List<IClasspathEntry> list= Arrays.asList(project.getRawClasspath()); list.add(JavaCore.newSourceEntry(folder.getFullPath())); project.setRawClasspath(list.toArray(new IClasspathEntry[list.size()]), new NullProgressMonitor()); }
Example #13
Source File: WebAppUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Sets the project's default output directory to the WAR output directory's * WEB-INF/classes folder. If the WAR output directory does not have a WEB-INF * directory, this method returns without doing anything. * * @throws CoreException if there's a problem setting the output directory */ public static void setOutputLocationToWebInfClasses(IJavaProject javaProject, IProgressMonitor monitor) throws CoreException { IProject project = javaProject.getProject(); IFolder webInfOut = getWebInfOut(project); if (!webInfOut.exists()) { // If the project has no output <WAR>/WEB-INF directory, don't touch the // output location return; } IPath oldOutputPath = javaProject.getOutputLocation(); IPath outputPath = webInfOut.getFullPath().append("classes"); if (!outputPath.equals(oldOutputPath)) { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); // Remove old output location and contents IFolder oldOutputFolder = workspaceRoot.getFolder(oldOutputPath); if (oldOutputFolder.exists()) { try { removeOldClassfiles(oldOutputFolder); } catch (Exception e) { CorePluginLog.logError(e); } } // Create the new output location if necessary IFolder outputFolder = workspaceRoot.getFolder(outputPath); if (!outputFolder.exists()) { // TODO: Could move recreate this in a utilities class CoreUtility.createDerivedFolder(outputFolder, true, true, null); } javaProject.setOutputLocation(outputPath, monitor); } }
Example #14
Source File: NewTypeDropDownAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override protected INewWizard createWizard() throws CoreException { return (INewWizard) CoreUtility.createExtension(fConfigurationElement, ATT_CLASS); }
Example #15
Source File: OptionsConfigurationBlock.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
protected boolean processChanges(IWorkbenchPreferenceContainer container) { IScopeContext currContext= fLookupOrder[0]; List<Key> changedOptions= new ArrayList<Key>(); boolean needsBuild= getChanges(currContext, changedOptions); if (changedOptions.isEmpty()) { return true; } if (needsBuild) { int count= getRebuildCount(); if (count > fRebuildCount) { needsBuild= false; // build already requested fRebuildCount= count; } } boolean doBuild= false; if (needsBuild) { String[] strings= getFullBuildDialogStrings(fProject == null); if (strings != null) { if (ResourcesPlugin.getWorkspace().getRoot().getProjects().length == 0) { doBuild= true; // don't bother the user } else { MessageDialog dialog= new MessageDialog(getShell(), strings[0], null, strings[1], MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 2); int res= dialog.open(); if (res == 0) { doBuild= true; } else if (res != 1) { return false; // cancel pressed } } } } if (container != null) { // no need to apply the changes to the original store: will be done by the page container if (doBuild) { // post build incrementRebuildCount(); container.registerUpdateJob(CoreUtility.getBuildJob(fProject)); } } else { // apply changes right away try { fManager.applyChanges(); } catch (BackingStoreException e) { JavaPlugin.log(e); return false; } if (doBuild) { CoreUtility.getBuildJob(fProject).schedule(); } } return true; }
Example #16
Source File: ReorgCorrectionsSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void run(IProgressMonitor monitor) throws CoreException { boolean needsBuild= updateJRE(monitor); if (needsBuild) { fUpdateJob= CoreUtility.getBuildJob(fChangeOnWorkspace ? null : fProject.getProject()); } }
Example #17
Source File: BinaryRefactoringHistoryWizard.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * {@inheritDoc} */ @Override protected RefactoringStatus aboutToPerformHistory(final IProgressMonitor monitor) { final RefactoringStatus status= new RefactoringStatus(); try { fJavaProject= null; fSourceFolder= null; fProcessedFragments.clear(); monitor.beginTask(JarImportMessages.JarImportWizard_prepare_import, 520); status.merge(super.aboutToPerformHistory(new SubProgressMonitor(monitor, 10, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL))); if (!status.hasFatalError()) { final IPackageFragmentRoot root= getPackageFragmentRoot(); if (root != null) { status.merge(checkPackageFragmentRoots(root, new SubProgressMonitor(monitor, 90, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL))); if (!status.hasFatalError()) { status.merge(checkSourceAttachmentRefactorings(new SubProgressMonitor(monitor, 20, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL))); if (!status.hasFatalError()) { final IJavaProject project= root.getJavaProject(); if (project != null) { final IFolder folder= project.getProject().getFolder(SOURCE_FOLDER + String.valueOf(System.currentTimeMillis())); try { fAutoBuild= CoreUtility.setAutoBuilding(false); final RefactoringHistory history= getRefactoringHistory(); if (history != null && !history.isEmpty()) configureClasspath(project, root, folder, new SubProgressMonitor(monitor, 300, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); } catch (CoreException exception) { status.merge(RefactoringStatus.createFatalErrorStatus(exception.getLocalizedMessage())); try { project.setRawClasspath(project.readRawClasspath(), false, new SubProgressMonitor(monitor, 100, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); } catch (CoreException throwable) { JavaPlugin.log(throwable); } } finally { if (!status.hasFatalError()) { fJavaProject= project; fSourceFolder= folder; } } } } } } } } finally { monitor.done(); } return status; }