List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE
int CPE_SOURCE
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE.
Click Source Link
From source file:com.redhat.ceylon.eclipse.code.preferences.ResourceContainerWorkbookPage.java
License:Open Source License
private void removeEntry() { List<Object> selElements = fFoldersList.getSelectedElements(); // for (int i= selElements.size() - 1; i >= 0 ; i--) { // Object elem= selElements.get(i); // if (elem instanceof CPListElementAttribute) { // CPListElementAttribute attrib= (CPListElementAttribute) elem; // String key= attrib.getKey(); // if (attrib.isBuiltIn()) { // Object value= null; // if (key.equals(CPListElement.EXCLUSION) || // key.equals(CPListElement.INCLUSION)) { // value= new Path[0]; // } // attrib.getParent().setAttribute(key, value); // } else { // removeCustomAttribute(attrib); // } // selElements.remove(i); // } // }//from ww w .j a v a2s. com if (selElements.isEmpty()) { fFoldersList.refresh(); fClassPathList.dialogFieldChanged(); // validate } else { for (Iterator<Object> iter = selElements.iterator(); iter.hasNext();) { CPListElement element = (CPListElement) iter.next(); if (element.getEntryKind() == IClasspathEntry.CPE_SOURCE) { List<CPListElement> list = ClasspathModifier.removeFilters(element.getPath(), fCurrJProject, fFoldersList.getElements()); for (Iterator<CPListElement> iterator = list.iterator(); iterator.hasNext();) { CPListElement modified = iterator.next(); fFoldersList.refresh(modified); fFoldersList.expandElement(modified, 3); } } } fFoldersList.removeElements(selElements); } }
From source file:com.redhat.ceylon.eclipse.code.preferences.ResourceContainerWorkbookPage.java
License:Open Source License
@Override public boolean isEntryKind(int kind) { return kind == IClasspathEntry.CPE_SOURCE; }
From source file:com.redhat.ceylon.eclipse.code.preferences.SourceContainerWorkbookPage.java
License:Open Source License
private void updateFoldersList() { if (fSWTControl == null || fSWTControl.isDisposed()) { return;/*from w w w. j av a 2 s . com*/ } ArrayList<CPListElement> folders = new ArrayList<CPListElement>(); // boolean useFolderOutputs= false; List<CPListElement> cpelements = fClassPathList.getElements(); for (int i = 0; i < cpelements.size(); i++) { CPListElement cpe = cpelements.get(i); if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { folders.add(cpe); // boolean hasOutputFolder= cpe.getAttribute(CPListElement.OUTPUT)!=null; // if (hasOutputFolder) { // useFolderOutputs= true; // } // } } fFoldersList.setElements(folders); // fUseFolderOutputs.setSelection(useFolderOutputs); // for (int i= 0; i < folders.size(); i++) { // CPListElement cpe= folders.get(i); // IPath[] ePatterns= (IPath[]) cpe.getAttribute(CPListElement.EXCLUSION); // IPath[] iPatterns= (IPath[])cpe.getAttribute(CPListElement.INCLUSION); // boolean hasOutputFolder= cpe.getAttribute(CPListElement.OUTPUT)!=null; // if (ePatterns.length > 0 || iPatterns.length > 0 || hasOutputFolder) { // fFoldersList.expandElement(cpe, 3); // } // } }
From source file:com.redhat.ceylon.eclipse.code.preferences.SourceContainerWorkbookPage.java
License:Open Source License
protected void sourcePageCustomButtonPressed(DialogField field, int index) { if (field == fFoldersList) { if (index == IDX_ADD) { IProject project = fCurrJProject.getProject(); if (project.isAccessible() && hasFolders(project)) { List<CPListElement> existingElements = fFoldersList.getElements(); CPListElement[] existing = existingElements.toArray(new CPListElement[existingElements.size()]); CreateMultipleResourceFoldersDialog dialog = new CreateMultipleResourceFoldersDialog( fCurrJProject, existing, fJavaOutputLocationField.getText(), "Source", DESC_WIZBAN_NEWSRCFOLDR, getShell()); if (dialog.open() == Window.OK) { refresh(dialog.getInsertedElements(), dialog.getRemovedElements(), dialog.getModifiedElements(), dialog.getOutputLocation()); }//from w w w. j av a 2 s. c o m } else { CPListElement newElement = new CPListElement(fCurrJProject, IClasspathEntry.CPE_SOURCE); AddResourceFolderWizard wizard = newSourceFolderWizard(newElement, fFoldersList.getElements(), fJavaOutputLocationField.getText(), true); OpenBuildPathWizardAction action = new OpenBuildPathWizardAction(wizard); action.run(); } } else if (index == IDX_ADD_LINK) { CPListElement newElement = new CPListElement(fCurrJProject, IClasspathEntry.CPE_SOURCE); AddResourceFolderWizard wizard = newLinkedSourceFolderWizard(newElement, fFoldersList.getElements(), fJavaOutputLocationField.getText(), true); OpenBuildPathWizardAction action = new OpenBuildPathWizardAction(wizard); action.run(); } else if (index == IDX_EDIT/*||index == IDX_TOGGLE*/) { editEntry(); } else if (index == IDX_REMOVE) { removeEntry(); } } }
From source file:com.redhat.ceylon.eclipse.code.wizard.AddResourceFolderWizardPage.java
License:Open Source License
private StatusInfo updateRootStatus() { IJavaProject javaProject = fNewElement.getJavaProject(); IProject project = javaProject.getProject(); StatusInfo pathNameStatus = validatePathName(fRootDialogField.getText(), fParent); if (!pathNameStatus.isOK()) return pathNameStatus; if (fLinkedMode) { IStatus linkNameStatus = validateLinkLocation(fRootDialogField.getText()); if (linkNameStatus.matches(IStatus.ERROR)) { StatusInfo result = new StatusInfo(); result.setError(linkNameStatus.getMessage()); return result; }// ww w.ja v a2s.co m } StatusInfo result = new StatusInfo(); result.setOK(); IPath projPath = project.getFullPath(); IPath path = fParent.getFullPath().append(fRootDialogField.getText()); restoreCPElements(); int projectEntryIndex = -1; boolean createFolderForExisting = false; IFolder folder = fParent.getFolder(new Path(fRootDialogField.getText())); for (int i = 0; i < fExistingEntries.size(); i++) { IClasspathEntry curr = fExistingEntries.get(i).getClasspathEntry(); if (curr.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (path.equals(curr.getPath()) && fExistingEntries.get(i) != fNewElement) { if (folder.exists()) { result.setError("The folder is already a source or resource folder."); return result; } else { createFolderForExisting = true; } } if (projPath.equals(curr.getPath())) { projectEntryIndex = i; } } } if (folder.exists() && !folder.getFullPath().equals(fOrginalPath)) return new StatusInfo(IStatus.ERROR, Messages.format(NewWizardMessages.NewFolderDialog_folderNameEmpty_alreadyExists, BasicElementLabels.getPathLabel(folder.getFullPath(), false))); boolean isProjectASourceFolder = projectEntryIndex != -1; fModifiedElements.clear(); updateFilters(fNewElement.getPath(), path); fNewElement.setPath(path); if (fLinkedMode) { fNewElement.setLinkTarget(fLinkFields.getLinkTarget()); } fRemovedElements.clear(); Set<CPListElement> modified = new HashSet<CPListElement>(); boolean isProjectSourceFolderReplaced = false; if (fAddExclusionPatterns.isSelected()) { if (fOrginalPath == null) { addExclusionPatterns(fNewElement, fExistingEntries, modified); fModifiedElements.addAll(modified); if (!createFolderForExisting) CPListElement.insert(fNewElement, fExistingEntries); } } else { if (isProjectASourceFolder) { if (fRemoveProjectFolder.isSelected()) { fOldProjectSourceFolder = fExistingEntries.get(projectEntryIndex); fRemovedElements.add(fOldProjectSourceFolder); fExistingEntries.set(projectEntryIndex, fNewElement); isProjectSourceFolderReplaced = true; } else { if (!createFolderForExisting) CPListElement.insert(fNewElement, fExistingEntries); } } else { if (!createFolderForExisting) CPListElement.insert(fNewElement, fExistingEntries); } } if ((!fAllowConflict && fCanCommitConflictingBuildpath) || createFolderForExisting) return new StatusInfo(); fNewOutputLocation = null; IJavaModelStatus status = JavaConventions.validateClasspath(javaProject, CPListElement.convertToClasspathEntries(fExistingEntries), fOutputLocation); if (!status.isOK()) { if (fOutputLocation.equals(projPath)) { //Try to change the output folder fNewOutputLocation = projPath.append( PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME)); IStatus status2 = JavaConventions.validateClasspath(javaProject, CPListElement.convertToClasspathEntries(fExistingEntries), fNewOutputLocation); if (status2.isOK()) { if (isProjectSourceFolderReplaced) { result.setInfo( Messages.format(NewWizardMessages.NewSourceFolderWizardPage_warning_ReplaceSFandOL, BasicElementLabels.getPathLabel(fNewOutputLocation, false))); } else { result.setInfo( Messages.format(NewWizardMessages.NewSourceFolderWizardPage_warning_ReplaceOL, BasicElementLabels.getPathLabel(fNewOutputLocation, false))); } return result; } } //Don't know what the problem is, report to user fNewOutputLocation = null; if (fCanCommitConflictingBuildpath) { result.setInfo(NewWizardMessages.AddSourceFolderWizardPage_conflictWarning + status.getMessage()); } else { result.setError(status.getMessage()); } return result; } if (!modified.isEmpty()) { //Added exclusion patterns to solve problem if (modified.size() == 1) { CPListElement elem = (CPListElement) modified.toArray()[0]; String changed = BasicElementLabels.getPathLabel(elem.getPath(), false); String excl = BasicElementLabels.getPathLabel(fNewElement.getPath(), false); result.setInfo(Messages.format(NewWizardMessages.AddSourceFolderWizardPage_addSinglePattern, new Object[] { excl, changed })); } else { result.setInfo( Messages.format(NewWizardMessages.NewSourceFolderWizardPage_warning_AddedExclusions_plural, String.valueOf(modified.size()))); } return result; } if (isProjectSourceFolderReplaced) { result.setInfo(NewWizardMessages.AddSourceFolderWizardPage_replaceSourceFolderInfo); return result; } return result; }
From source file:com.redhat.ceylon.eclipse.code.wizard.AddResourceFolderWizardPage.java
License:Open Source License
private void addExclusionPatterns(CPListElement newEntry, List<CPListElement> existing, Set<CPListElement> modifiedEntries) { IPath entryPath = newEntry.getPath(); for (int i = 0; i < existing.size(); i++) { CPListElement curr = existing.get(i); IPath currPath = curr.getPath(); if (curr != newEntry && curr.getEntryKind() == IClasspathEntry.CPE_SOURCE && currPath.isPrefixOf(entryPath)) { boolean added = curr.addToExclusions(entryPath); if (added) { modifiedEntries.add(curr); }/*from ww w .java 2s. c om*/ } } }
From source file:com.redhat.ceylon.eclipse.code.wizard.BuildPathsBlock.java
License:Open Source License
/** * Initializes the classpath for the given project. Multiple calls to init are allowed, * but all existing settings will be cleared and replace by the given or default paths. * @param jproject The java project to configure. Does not have to exist. * @param javaOutputLocation The output location to be set in the page. If <code>null</code> * is passed, jdt default settings are used, or - if the project is an existing Java project- the * output location of the existing project * @param classpathEntries The classpath entries to be set in the page. If <code>null</code> * is passed, jdt default settings are used, or - if the project is an existing Java project - the * classpath entries of the existing project *///from w w w. j av a 2s . co m public void init(IJavaProject jproject, IPath javaOutputLocation, IClasspathEntry[] classpathEntries) { fCurrJProject = jproject; boolean projectExists = false; List<CPListElement> newClassPath = null; IProject project = fCurrJProject.getProject(); projectExists = (project.exists() && project.getFile(".classpath").exists()); //$NON-NLS-1$ IClasspathEntry[] existingEntries = null; if (projectExists) { if (javaOutputLocation == null) { javaOutputLocation = fCurrJProject.readOutputLocation(); } existingEntries = fCurrJProject.readRawClasspath(); if (classpathEntries == null) { classpathEntries = existingEntries; //TODO: read existing ceylon output location from classpathEntries } } if (javaOutputLocation == null) { javaOutputLocation = getDefaultJavaOutputLocation(jproject); } if (classpathEntries != null) { newClassPath = getCPListElements(classpathEntries, existingEntries); } if (newClassPath == null) { newClassPath = getDefaultClassPath(jproject); } List<CPListElement> exportedEntries = new ArrayList<CPListElement>(); for (int i = 0; i < newClassPath.size(); i++) { CPListElement curr = newClassPath.get(i); if (curr.isExported() || curr.getEntryKind() == IClasspathEntry.CPE_SOURCE) { exportedEntries.add(curr); } } fJavaOutputLocationPath = javaOutputLocation.makeRelative(); // inits the dialog field fJavaBuildPathDialogField.setText(fJavaOutputLocationPath.toString()); fJavaBuildPathDialogField.enableButton(project.exists()); fClassPathList.setElements(newClassPath); fClassPathList.setCheckedElements(exportedEntries); fClassPathList.selectFirstElement(); if (fSourceContainerPage != null) { fSourceContainerPage.init(fCurrJProject); fProjectsPage.init(fCurrJProject); fLibrariesPage.init(fCurrJProject); } initializeTimeStamps(); updateUI(); }
From source file:com.redhat.ceylon.eclipse.code.wizard.BuildPathsBlock.java
License:Open Source License
private List<CPListElement> getDefaultClassPath(IJavaProject jproj) { List<CPListElement> list = new ArrayList<CPListElement>(); IResource srcFolder;/* w ww. ja v a 2 s . co m*/ IPreferenceStore store = PreferenceConstants.getPreferenceStore(); String sourceFolderName = store.getString(PreferenceConstants.SRCBIN_SRCNAME); if (store.getBoolean(PreferenceConstants.SRCBIN_FOLDERS_IN_NEWPROJ) && sourceFolderName.length() > 0) { srcFolder = jproj.getProject().getFolder(sourceFolderName); } else { srcFolder = jproj.getProject(); } list.add(new CPListElement(jproj, IClasspathEntry.CPE_SOURCE, srcFolder.getFullPath(), srcFolder)); IClasspathEntry[] jreEntries = PreferenceConstants.getDefaultJRELibrary(); list.addAll(getCPListElements(jreEntries, null)); return list; }
From source file:com.redhat.ceylon.eclipse.code.wizard.BuildPathsBlock.java
License:Open Source License
/** * Validates the build path./* www . j a va 2s . c o m*/ */ public void updateClassPathStatus() { fClassPathStatus.setOK(); List<CPListElement> elements = fClassPathList.getElements(); CPListElement entryMissing = null; CPListElement entryDeprecated = null; int nEntriesMissing = 0; IClasspathEntry[] entries = new IClasspathEntry[elements.size()]; for (int i = elements.size() - 1; i >= 0; i--) { CPListElement currElement = elements.get(i); boolean isChecked = fClassPathList.isChecked(currElement); if (currElement.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (!isChecked) { fClassPathList.setCheckedWithoutUpdate(currElement, true); } if (!fClassPathList.isGrayed(currElement)) { fClassPathList.setGrayedWithoutUpdate(currElement, true); } } else { currElement.setExported(isChecked); } entries[i] = currElement.getClasspathEntry(); if (currElement.isMissing()) { nEntriesMissing++; if (entryMissing == null) { entryMissing = currElement; } } if (entryDeprecated == null & currElement.isDeprecated()) { entryDeprecated = currElement; } } if (nEntriesMissing > 0) { if (nEntriesMissing == 1) { fClassPathStatus.setWarning(Messages.format(NewWizardMessages.BuildPathsBlock_warning_EntryMissing, BasicElementLabels.getPathLabel(entryMissing.getPath(), false))); } else { fClassPathStatus.setWarning(Messages.format( NewWizardMessages.BuildPathsBlock_warning_EntriesMissing, String.valueOf(nEntriesMissing))); } } else if (entryDeprecated != null) { fClassPathStatus.setInfo(entryDeprecated.getDeprecationMessage()); } /* if (fCurrJProject.hasClasspathCycle(entries)) { fClassPathStatus.setWarning(NewWizardMessages.getString("BuildPathsBlock.warning.CycleInClassPath")); //$NON-NLS-1$ } */ updateBuildPathStatus(); }
From source file:com.redhat.ceylon.eclipse.code.wizard.BuildPathsBlock.java
License:Open Source License
/** * Sets the configured build path and output location to the given Java project. * If the project already exists, only build paths are updated. * <p>// ww w. j a va 2 s .c o m * If the classpath contains an Execution Environment entry, the EE's compiler compliance options * are used as project-specific options (unless the classpath already contained the same Execution Environment) * * @param classPathEntries the new classpath entries (list of {@link CPListElement}) * @param javaOutputLocation the output location * @param javaProject the Java project * @param newProjectCompliance compliance to set for a new project, can be <code>null</code> * @param monitor a progress monitor, or <code>null</code> * @throws CoreException if flushing failed * @throws OperationCanceledException if flushing has been cancelled */ public static void flush(List<CPListElement> classPathEntries, IPath javaOutputLocation, IJavaProject javaProject, String newProjectCompliance, IProgressMonitor monitor) throws CoreException, OperationCanceledException { if (monitor == null) { monitor = new NullProgressMonitor(); } monitor.setTaskName(NewWizardMessages.BuildPathsBlock_operationdesc_java); monitor.beginTask("", classPathEntries.size() * 4 + 4); //$NON-NLS-1$ try { IProject project = javaProject.getProject(); IPath projPath = project.getFullPath(); IPath oldOutputLocation; try { oldOutputLocation = javaProject.getOutputLocation(); } catch (CoreException e) { oldOutputLocation = projPath.append( PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME)); } if (oldOutputLocation.equals(projPath) && !javaOutputLocation.equals(projPath)) { if (BuildPathsBlock.hasClassfiles(project)) { if (BuildPathsBlock.getRemoveOldBinariesQuery(JavaPlugin.getActiveWorkbenchShell()) .doQuery(false, projPath)) { BuildPathsBlock.removeOldClassfiles(project); } } } else if (!javaOutputLocation.equals(oldOutputLocation)) { IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(oldOutputLocation); if (folder.exists()) { if (folder.members().length == 0) { BuildPathsBlock.removeOldClassfiles(folder); } else { if (BuildPathsBlock.getRemoveOldBinariesQuery(JavaPlugin.getActiveWorkbenchShell()) .doQuery(folder.isDerived(), oldOutputLocation)) { BuildPathsBlock.removeOldClassfiles(folder); } } } } //TODO: more robust clean up the "old" ceylon output location! project.getFolder("modules").delete(true, monitor); monitor.worked(1); IWorkspaceRoot fWorkspaceRoot = JavaPlugin.getWorkspace().getRoot(); //create and set the output path first if (!fWorkspaceRoot.exists(javaOutputLocation)) { CoreUtility.createDerivedFolder(fWorkspaceRoot.getFolder(javaOutputLocation), true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } if (monitor.isCanceled()) { throw new OperationCanceledException(); } int nEntries = classPathEntries.size(); IClasspathEntry[] classpath = new IClasspathEntry[nEntries]; int i = 0; for (Iterator<CPListElement> iter = classPathEntries.iterator(); iter.hasNext();) { CPListElement entry = iter.next(); classpath[i] = entry.getClasspathEntry(); i++; IResource res = entry.getResource(); //1 tick if (res instanceof IFolder && entry.getLinkTarget() == null && !res.exists()) { CoreUtility.createFolder((IFolder) res, true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } //3 ticks if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath folderOutput = (IPath) entry.getAttribute(CPListElement.OUTPUT); if (folderOutput != null && folderOutput.segmentCount() > 1) { IFolder folder = fWorkspaceRoot.getFolder(folderOutput); CoreUtility.createDerivedFolder(folder, true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } IPath path = entry.getPath(); if (projPath.equals(path)) { monitor.worked(2); continue; } if (projPath.isPrefixOf(path)) { path = path.removeFirstSegments(projPath.segmentCount()); } IFolder folder = project.getFolder(path); IPath orginalPath = entry.getOrginalPath(); if (orginalPath == null) { if (!folder.exists()) { //New source folder needs to be created if (entry.getLinkTarget() == null) { CoreUtility.createFolder(folder, true, true, new SubProgressMonitor(monitor, 2)); } else { folder.createLink(entry.getLinkTarget(), IResource.ALLOW_MISSING_LOCAL, new SubProgressMonitor(monitor, 2)); } } } else { if (projPath.isPrefixOf(orginalPath)) { orginalPath = orginalPath.removeFirstSegments(projPath.segmentCount()); } IFolder orginalFolder = project.getFolder(orginalPath); if (entry.getLinkTarget() == null) { if (!folder.exists()) { //Source folder was edited, move to new location IPath parentPath = entry.getPath().removeLastSegments(1); if (projPath.isPrefixOf(parentPath)) { parentPath = parentPath.removeFirstSegments(projPath.segmentCount()); } if (parentPath.segmentCount() > 0) { IFolder parentFolder = project.getFolder(parentPath); if (!parentFolder.exists()) { CoreUtility.createFolder(parentFolder, true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } } else { monitor.worked(1); } orginalFolder.move(entry.getPath(), true, true, new SubProgressMonitor(monitor, 1)); } } else { if (!folder.exists() || !entry.getLinkTarget().equals(entry.getOrginalLinkTarget())) { orginalFolder.delete(true, new SubProgressMonitor(monitor, 1)); folder.createLink(entry.getLinkTarget(), IResource.ALLOW_MISSING_LOCAL, new SubProgressMonitor(monitor, 1)); } } } } else { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPath path = entry.getPath(); if (!path.equals(entry.getOrginalPath())) { String eeID = JavaRuntime.getExecutionEnvironmentId(path); if (eeID != null) { BuildPathSupport.setEEComplianceOptions(javaProject, eeID, newProjectCompliance); newProjectCompliance = null; // don't set it again below } } if (newProjectCompliance != null) { Map<String, String> options = javaProject.getOptions(false); JavaModelUtil.setComplianceOptions(options, newProjectCompliance); JavaModelUtil.setDefaultClassfileOptions(options, newProjectCompliance); // complete compliance options javaProject.setOptions(options); } } monitor.worked(3); } if (monitor.isCanceled()) { throw new OperationCanceledException(); } } javaProject.setRawClasspath(classpath, javaOutputLocation, new SubProgressMonitor(monitor, 2)); } finally { monitor.done(); } }