List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_CONTAINER
int CPE_CONTAINER
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_CONTAINER.
Click Source Link
From source file:com.mountainminds.eclemma.core.ScopeUtils.java
License:Open Source License
/** * Remove all JRE runtime entries from the given set * /* w w w . jav a2 s . com*/ * @param scope * set to filter * @return filtered set without JRE runtime entries */ public static Set<IPackageFragmentRoot> filterJREEntries(Collection<IPackageFragmentRoot> scope) throws JavaModelException { final Set<IPackageFragmentRoot> filtered = new HashSet<IPackageFragmentRoot>(); for (final IPackageFragmentRoot root : scope) { final IClasspathEntry entry = root.getRawClasspathEntry(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: filtered.add(root); break; case IClasspathEntry.CPE_CONTAINER: IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), root.getJavaProject()); if (container != null && container.getKind() == IClasspathContainer.K_APPLICATION) { filtered.add(root); } break; } } return filtered; }
From source file:com.redhat.ceylon.eclipse.code.explorer.PackageExplorerContentProvider.java
License:Open Source License
@Override protected Object[] getPackageFragmentRoots(IJavaProject project) throws JavaModelException { if (!project.getProject().isOpen()) return NO_CHILDREN; List<Object> result = new ArrayList<Object>(); IPackageFragmentRoot[] roots = project.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { IPackageFragmentRoot root = roots[i]; IClasspathEntry classpathEntry = root.getRawClasspathEntry(); int entryKind = classpathEntry.getEntryKind(); if (entryKind == IClasspathEntry.CPE_CONTAINER) { // all ClassPathContainers are added later } else if (fShowLibrariesNode && (entryKind == IClasspathEntry.CPE_LIBRARY || entryKind == IClasspathEntry.CPE_VARIABLE)) { IResource resource = root.getResource(); if (resource != null && project.getResource().equals(resource.getParent())) { // show resource as child of project, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=141906 result.add(resource);/*from w ww . j a va 2 s .com*/ } else { // skip: will add the referenced library node later } } else { if (isProjectPackageFragmentRoot(root)) { // filter out package fragments that correspond to projects and // replace them with the package fragments directly Object[] fragments = getPackageFragmentRootContent(root); for (int j = 0; j < fragments.length; j++) { result.add(fragments[j]); } } else { result.add(root); } } } if (fShowLibrariesNode) { result.add(new LibraryContainer(project)); } // separate loop to make sure all containers are on the classpath (even empty ones) IClasspathEntry[] rawClasspath = project.getRawClasspath(); for (int i = 0; i < rawClasspath.length; i++) { IClasspathEntry classpathEntry = rawClasspath[i]; if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { result.add(new ClassPathContainer(project, classpathEntry)); } } Object[] resources = project.getNonJavaResources(); for (int i = 0; i < resources.length; i++) { result.add(resources[i]); } return result.toArray(); }
From source file:com.redhat.ceylon.eclipse.code.explorer.PackageExplorerContentProvider.java
License:Open Source License
@Override protected Object internalGetParent(Object element) { if (!fIsFlatLayout && element instanceof IPackageFragment) { return getHierarchicalPackageParent((IPackageFragment) element); } else if (element instanceof IPackageFragmentRoot) { // since we insert logical package containers we have to fix // up the parent for package fragment roots so that they refer // to the container and containers refer to the project IPackageFragmentRoot root = (IPackageFragmentRoot) element; try {//w ww . j a v a 2s. c o m IClasspathEntry entry = root.getRawClasspathEntry(); int entryKind = entry.getEntryKind(); if (entryKind == IClasspathEntry.CPE_CONTAINER) { return new ClassPathContainer(root.getJavaProject(), entry); } else if (fShowLibrariesNode && (entryKind == IClasspathEntry.CPE_LIBRARY || entryKind == IClasspathEntry.CPE_VARIABLE)) { return new LibraryContainer(root.getJavaProject()); } } catch (JavaModelException e) { // fall through } } else if (element instanceof PackageFragmentRootContainer) { return ((PackageFragmentRootContainer) element).getJavaProject(); } return super.internalGetParent(element); }
From source file:com.redhat.ceylon.eclipse.code.preferences.CeylonBuildPathsBlock.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>/*from w w w. ja va2s . c om*/ * 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, List<CPListElement> resourcePathEntries, 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 (CeylonBuildPathsBlock.hasClassfiles(project)) { if (CeylonBuildPathsBlock.getRemoveOldBinariesQuery(JavaPlugin.getActiveWorkbenchShell()) .doQuery(false, projPath)) { CeylonBuildPathsBlock.removeOldClassfiles(project); } } } else if (!javaOutputLocation.equals(oldOutputLocation)) { IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(oldOutputLocation); if (folder.exists()) { if (folder.members().length == 0) { CeylonBuildPathsBlock.removeOldClassfiles(folder); } else { if (CeylonBuildPathsBlock.getRemoveOldBinariesQuery(JavaPlugin.getActiveWorkbenchShell()) .doQuery(folder.isDerived(), oldOutputLocation)) { CeylonBuildPathsBlock.removeOldClassfiles(folder); } } } } getCeylonModulesOutputFolder(project).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(); } for (Iterator<CPListElement> iter = resourcePathEntries.iterator(); iter.hasNext();) { CPListElement entry = iter.next(); 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)); } } } } 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) { setOptionsFromJavaProject(javaProject, newProjectCompliance); } } monitor.worked(3); } if (monitor.isCanceled()) { throw new OperationCanceledException(); } } javaProject.setRawClasspath(classpath, javaOutputLocation, new SubProgressMonitor(monitor, 2)); CeylonProjectConfig config = CeylonProjectConfig.get(project); List<String> srcDirs = new ArrayList<String>(); for (CPListElement cpe : classPathEntries) { if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { srcDirs.add(configFilePath(project, cpe)); } } config.setProjectSourceDirectories(srcDirs); List<String> rsrcDirs = new ArrayList<String>(); for (CPListElement cpe : resourcePathEntries) { rsrcDirs.add(configFilePath(project, cpe)); } config.setProjectResourceDirectories(rsrcDirs); config.save(); } finally { monitor.done(); } }
From source file:com.redhat.ceylon.eclipse.code.preferences.CeylonBuildPathsBlock.java
License:Open Source License
private int getPageIndex(int entryKind) { switch (entryKind) { case IClasspathEntry.CPE_CONTAINER: case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: return 2; case IClasspathEntry.CPE_PROJECT: return 1; case IClasspathEntry.CPE_SOURCE: return 0; }/*ww w . ja v a2s .c o m*/ return 0; }
From source file:com.redhat.ceylon.eclipse.code.preferences.CeylonBuildPathsBlock.java
License:Open Source License
private CPListElement findElement(IClasspathEntry entry) { CPListElement prefixMatch = null;/* www .j a v a 2s . c o m*/ int entryKind = entry.getEntryKind(); for (int i = 0, len = fClassPathList.getSize(); i < len; i++) { CPListElement curr = fClassPathList.getElement(i); if (curr.getEntryKind() == entryKind) { IPath entryPath = entry.getPath(); IPath currPath = curr.getPath(); if (currPath.equals(entryPath)) { return curr; } // in case there's no full match, look for a similar container (same ID segment): if (prefixMatch == null && entryKind == IClasspathEntry.CPE_CONTAINER) { int n = entryPath.segmentCount(); if (n > 0) { IPath genericContainerPath = n == 1 ? entryPath : entryPath.removeLastSegments(n - 1); if (n > 1 && genericContainerPath.isPrefixOf(currPath)) { prefixMatch = curr; } } } } } return prefixMatch; }
From source file:com.redhat.ceylon.eclipse.code.preferences.ResourceListLabelProvider.java
License:Open Source License
public String getCPListElementAttributeText(CPListElementAttribute attrib) { String notAvailable = NewWizardMessages.CPListLabelProvider_none; String key = attrib.getKey(); if (key.equals(CPListElement.SOURCEATTACHMENT)) { String arg;/*from ww w . java 2 s .co m*/ IPath path = (IPath) attrib.getValue(); if (path != null && !path.isEmpty()) { if (attrib.getParent().getEntryKind() == IClasspathEntry.CPE_VARIABLE) { arg = getVariableString(path); } else { arg = getPathString(path, path.getDevice() != null); } } else { arg = notAvailable; } return Messages.format(NewWizardMessages.CPListLabelProvider_source_attachment_label, new String[] { arg }); } else if (key.equals(CPListElement.OUTPUT)) { String arg = null; IPath path = (IPath) attrib.getValue(); if (path != null) { arg = BasicElementLabels.getPathLabel(path, false); } else { arg = NewWizardMessages.CPListLabelProvider_default_output_folder_label; } return Messages.format(NewWizardMessages.CPListLabelProvider_output_folder_label, new String[] { arg }); } else if (key.equals(CPListElement.EXCLUSION)) { String arg = null; IPath[] patterns = (IPath[]) attrib.getValue(); if (patterns != null && patterns.length > 0) { int patternsCount = 0; StringBuffer buf = new StringBuffer(); for (int i = 0; i < patterns.length; i++) { if (patterns[i].segmentCount() > 0) { String pattern = BasicElementLabels.getPathLabel(patterns[i], false); if (patternsCount > 0) { buf.append(NewWizardMessages.CPListLabelProvider_exclusion_filter_separator); } buf.append(pattern); patternsCount++; } } if (patternsCount > 0) { arg = buf.toString(); } else { arg = notAvailable; } } else { arg = notAvailable; } return Messages.format(NewWizardMessages.CPListLabelProvider_exclusion_filter_label, new String[] { arg }); } else if (key.equals(CPListElement.INCLUSION)) { String arg = null; IPath[] patterns = (IPath[]) attrib.getValue(); if (patterns != null && patterns.length > 0) { int patternsCount = 0; StringBuffer buf = new StringBuffer(); for (int i = 0; i < patterns.length; i++) { if (patterns[i].segmentCount() > 0) { String pattern = BasicElementLabels.getPathLabel(patterns[i], false); if (patternsCount > 0) { buf.append(NewWizardMessages.CPListLabelProvider_inclusion_filter_separator); } buf.append(pattern); patternsCount++; } } if (patternsCount > 0) { arg = buf.toString(); } else { arg = notAvailable; } } else { arg = NewWizardMessages.CPListLabelProvider_all; } return Messages.format(NewWizardMessages.CPListLabelProvider_inclusion_filter_label, new String[] { arg }); } else if (key.equals(CPListElement.ACCESSRULES)) { IAccessRule[] rules = (IAccessRule[]) attrib.getValue(); int nRules = rules != null ? rules.length : 0; int parentKind = attrib.getParent().getEntryKind(); if (parentKind == IClasspathEntry.CPE_PROJECT) { Boolean combined = (Boolean) attrib.getParent().getAttribute(CPListElement.COMBINE_ACCESSRULES); if (nRules > 0) { if (combined.booleanValue()) { if (nRules == 1) { return NewWizardMessages.CPListLabelProvider_project_access_rules_combined_singular; } else { return Messages.format( NewWizardMessages.CPListLabelProvider_project_access_rules_combined_plural, String.valueOf(nRules)); } } else { if (nRules == 1) { return NewWizardMessages.CPListLabelProvider_project_access_rules_not_combined_singular; } else { return Messages.format( NewWizardMessages.CPListLabelProvider_project_access_rules_not_combined_plural, String.valueOf(nRules)); } } } else { return NewWizardMessages.CPListLabelProvider_project_access_rules_no_rules; } } else if (parentKind == IClasspathEntry.CPE_CONTAINER) { if (nRules > 1) { return Messages.format(NewWizardMessages.CPListLabelProvider_container_access_rules_plural, String.valueOf(nRules)); } else if (nRules == 1) { return NewWizardMessages.CPListLabelProvider_container_access_rules_singular; } else { return NewWizardMessages.CPListLabelProvider_container_no_access_rules; } } else { if (nRules > 1) { return Messages.format(NewWizardMessages.CPListLabelProvider_access_rules_enabled_plural, String.valueOf(nRules)); } else if (nRules == 1) { return NewWizardMessages.CPListLabelProvider_access_rules_enabled_singular; } else { return NewWizardMessages.CPListLabelProvider_access_rules_disabled; } } } else if (key.equals(CPListElement.IGNORE_OPTIONAL_PROBLEMS)) { String arg; if ("true".equals(attrib.getValue())) { //$NON-NLS-1$ arg = NewWizardMessages.CPListLabelProvider_ignore_optional_problems_yes; } else { arg = NewWizardMessages.CPListLabelProvider_ignore_optional_problems_no; } return Messages.format(NewWizardMessages.CPListLabelProvider_ignore_optional_problems_label, arg); } else { ClasspathAttributeConfiguration config = fAttributeDescriptors.get(key); if (config != null) { ClasspathAttributeAccess access = attrib.getClasspathAttributeAccess(); String nameLabel = config.getNameLabel(access); String valueLabel = config.getValueLabel(access); // should be LTR marked return Messages.format(NewWizardMessages.CPListLabelProvider_attribute_label, new String[] { nameLabel, valueLabel }); } String arg = (String) attrib.getValue(); if (arg == null) { arg = notAvailable; } return Messages.format(NewWizardMessages.CPListLabelProvider_attribute_label, new String[] { key, arg }); } }
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>/*from www . j ava2 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(); } }
From source file:com.redhat.ceylon.eclipse.core.classpath.CeylonClasspathUtil.java
License:Apache License
/** * Search the Ceylon classpath containers within the specified Java project * // w w w.j a v a 2 s . c o m * @param javaProject * the project to search into * @return the Ivy classpath container if found */ public static List<CeylonClasspathContainer> getCeylonClasspathContainers(IJavaProject javaProject) { List<CeylonClasspathContainer> containers = new ArrayList<CeylonClasspathContainer>(); if (FakeProjectManager.isFake(javaProject) || !javaProject.exists()) { return containers; } try { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPath path = entry.getPath(); if (isCeylonClasspathContainer(path)) { IClasspathContainer cp = JavaCore.getClasspathContainer(path, javaProject); if (cp instanceof CeylonClasspathContainer) { containers.add((CeylonClasspathContainer) cp); } } } } } catch (JavaModelException e) { // unless there are issues with the JDT, this should never happen e.printStackTrace(); } return containers; }
From source file:com.redhat.ceylon.eclipse.core.classpath.CeylonClasspathUtil.java
License:Apache License
/** * Search the Ivy classpath entry within the specified Java project with the specific path * /*from www .j a v a 2 s . co m*/ * @param containerPath * the path of the container * @param javaProject * the project to search into * @return the Ivy classpath container if found, otherwise return <code>null</code> */ public static IClasspathEntry getCeylonClasspathEntry(IPath containerPath, IJavaProject javaProject) { if (FakeProjectManager.isFake(javaProject) || !javaProject.exists()) { return null; } try { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (containerPath.equals(entry.getPath())) { return entry; } } } } catch (JavaModelException e) { // unless there are issues with the JDT, this should never happen e.printStackTrace(); } return null; }