List of usage examples for org.eclipse.jdt.core IClasspathEntry getEntryKind
int getEntryKind();
From source file:org.eclipse.ajdt.internal.ui.wizards.exports.AJJarPackageWizardPage.java
License:Open Source License
protected boolean validateSourceGroup() { if (!(fExportClassFilesCheckbox.getSelection() || fExportOutputFoldersCheckbox.getSelection() || fExportJavaFilesCheckbox.getSelection())) { setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_noExportTypeChecked); return false; }/*w w w . j a v a 2 s.co m*/ if (getSelectedResources().size() == 0) { if (getErrorMessage() != null) setErrorMessage(null); return false; } if (fExportClassFilesCheckbox.getSelection() || fExportOutputFoldersCheckbox.getSelection()) return true; // Source file only export - check if there are source files Iterator iter = getSelectedResourcesIterator(); while (iter.hasNext()) { Object element = iter.next(); if (element instanceof IClassFile) { IPackageFragmentRoot root = (IPackageFragmentRoot) ((IClassFile) element) .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (root == null) continue; IClasspathEntry cpEntry; try { cpEntry = root.getRawClasspathEntry(); } catch (JavaModelException e) { continue; } if (cpEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { return true; } } else { return true; } } if (getErrorMessage() != null) setErrorMessage(null); return false; }
From source file:org.eclipse.ajdt.internal.ui.wizards.PathBlock.java
License:Open Source License
protected void internalConfigureJavaProject(List pathElements, IProgressMonitor monitor) throws CoreException, InterruptedException { int nEntries = pathElements.size(); List /* IClasspathEntry */<IClasspathEntry> pathEntries = new ArrayList<IClasspathEntry>(); for (int i = 0; i < nEntries; i++) { // Bug 243356 // remove from the list if this is an entry contained in a container // because entries in containers are computed separately CPListElement element = ((CPListElement) pathElements.get(i)); if (!inClasspathContainer(element)) { pathEntries.add(element.getClasspathEntry()); }//from w w w .j av a2 s . c om } monitor.worked(2); Map<IPath, String> inpathRestrictions = new HashMap<IPath, String>(); Map<IPath, String> aspectpathRestrictions = new HashMap<IPath, String>(); StringBuffer pathBuffer = new StringBuffer(); StringBuffer contentKindBuffer = new StringBuffer(); StringBuffer entryKindBuffer = new StringBuffer(); for (Iterator<IClasspathEntry> pathIter = pathEntries.iterator(); pathIter.hasNext();) { IClasspathEntry pathEntry = pathIter.next(); pathBuffer.append(pathEntry.getPath()); pathBuffer.append(File.pathSeparator); contentKindBuffer.append(pathEntry.getContentKind()); contentKindBuffer.append(File.pathSeparator); entryKindBuffer.append(pathEntry.getEntryKind()); entryKindBuffer.append(File.pathSeparator); String inpathRestriction = AspectJCorePreferences.getRestriction(pathEntry, AspectJCorePreferences.INPATH_RESTRICTION_ATTRIBUTE_NAME); if (inpathRestriction != null && inpathRestriction.length() > 0) { inpathRestrictions.put(pathEntry.getPath(), inpathRestriction); } String aspectpathRestriction = AspectJCorePreferences.getRestriction(pathEntry, AspectJCorePreferences.ASPECTPATH_RESTRICTION_ATTRIBUTE_NAME); if (aspectpathRestriction != null && aspectpathRestriction.length() > 0) { aspectpathRestrictions.put(pathEntry.getPath(), aspectpathRestriction); } } pathBuffer = removeFinalPathSeparatorChar(pathBuffer); contentKindBuffer = removeFinalPathSeparatorChar(contentKindBuffer); entryKindBuffer = removeFinalPathSeparatorChar(entryKindBuffer); internalSetProjectPath(pathElements, pathBuffer, contentKindBuffer, entryKindBuffer); // update the classpath with the restrictions if (inpathRestrictions.size() > 0 || aspectpathRestrictions.size() > 0) { IClasspathEntry[] entries = getJavaProject().getRawClasspath(); boolean hasChanges = false; if (inpathRestrictions.size() > 0) { hasChanges |= updatePathRestrictions(entries, inpathRestrictions, false); } if (aspectpathRestrictions.size() > 0) { hasChanges |= updatePathRestrictions(entries, aspectpathRestrictions, true); } if (hasChanges) { getJavaProject().setRawClasspath(entries, new NullProgressMonitor()); } } }
From source file:org.eclipse.ajdt.internal.ui.wizards.PathBlock.java
License:Open Source License
protected List<CPListElement> getExistingEntries(IClasspathEntry[] pathEntries) { List<CPListElement> newPath = new ArrayList<CPListElement>(); for (int i = 0; i < pathEntries.length; i++) { IClasspathEntry curr = pathEntries[i]; if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { curr = AspectJCorePreferences.ensureHasAttribute(curr, getRestrictionPathAttrName(), ""); }/*from ww w .j av a 2 s . co m*/ newPath.add(CPListElement.createFromExisting(curr, fCurrJProject)); } return newPath; }
From source file:org.eclipse.ajdt.internal.utils.AJDTUtils.java
License:Open Source License
private static void includeAJfiles(IProject project, boolean prompt) { IJavaProject jp = JavaCore.create(project); try {//from w w w . j av a2s . c o m boolean changed = false; IClasspathEntry[] cpEntry = jp.getRawClasspath(); for (int i = 0; i < cpEntry.length; i++) { IClasspathEntry entry = cpEntry[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath[] exc = entry.getExclusionPatterns(); if (exc != null) { List<IPath> removeList = new ArrayList<IPath>(); for (int j = 0; j < exc.length; j++) { String ext = exc[j].getFileExtension(); if ((ext != null) && ext.equals("aj")) { //$NON-NLS-1$ removeList.add(exc[j]); } } if (removeList.size() > 0) { IPath[] exc2 = new IPath[exc.length - removeList.size()]; int ind = 0; for (int j = 0; j < exc.length; j++) { if (!removeList.contains(exc[j])) { exc2[ind++] = exc[j]; } } IClasspathEntry classpathEntry = JavaCore.newSourceEntry(entry.getPath(), exc2); cpEntry[i] = classpathEntry; changed = true; } } } } if (changed) { boolean restore = true; if (prompt) { IWorkbenchWindow window = AspectJUIPlugin.getDefault().getWorkbench() .getActiveWorkbenchWindow(); restore = MessageDialog.openQuestion(window.getShell(), UIMessages.ExcludedAJ_title, UIMessages.ExcludedAJ_message); } if (restore) { jp.setRawClasspath(cpEntry, null); } } } catch (JavaModelException e) { } }
From source file:org.eclipse.ajdt.internal.utils.AJDTUtils.java
License:Open Source License
private static void excludeAJfiles(IProject project) { IJavaProject jp = JavaCore.create(project); try {/*from www . j a v a2 s . c om*/ boolean changed = false; IClasspathEntry[] cpEntry = jp.getRawClasspath(); for (int i = 0; i < cpEntry.length; i++) { IClasspathEntry entry = cpEntry[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { List<IPath> excludeList = new ArrayList<IPath>(); IPackageFragmentRoot[] roots = jp.findPackageFragmentRoots(entry); for (int j = 0; j < roots.length; j++) { IJavaElement[] rootFragments; try { rootFragments = roots[j].getChildren(); for (int k = 0; k < rootFragments.length; k++) { if (rootFragments[k] instanceof IPackageFragment) { IPackageFragment pack = (IPackageFragment) rootFragments[k]; ICompilationUnit[] files = pack.getCompilationUnits(); for (int l = 0; l < files.length; l++) { IResource resource = files[l].getResource(); if (resource.getFileExtension().equals("aj")) { //$NON-NLS-1$ IPath resPath = resource.getFullPath(); int seg = resPath.matchingFirstSegments(roots[j].getPath()); excludeList.add(resPath.removeFirstSegments(seg)); } } } } } catch (JavaModelException e) { } } if (excludeList.size() > 0) { IPath[] exc = new IPath[excludeList.size()]; excludeList.toArray(exc); IClasspathEntry classpathEntry = JavaCore.newSourceEntry(entry.getPath(), exc); cpEntry[i] = classpathEntry; changed = true; } } } if (changed) { jp.setRawClasspath(cpEntry, null); } } catch (JavaModelException e) { } }
From source file:org.eclipse.ajdt.ui.tests.builder.ProjectDependenciesUtils.java
License:Open Source License
public static boolean projectHasProjectDependency(IProject project, IProject projectDependedOn) throws JavaModelException { IJavaProject javaProject = JavaCore.create(project); if (javaProject == null) return false; IClasspathEntry[] cpEntry = javaProject.getRawClasspath(); for (int j = 0; j < cpEntry.length; j++) { IClasspathEntry entry = cpEntry[j]; int entryKind = entry.getEntryKind(); IPath entryPath = entry.getPath(); if (entryKind == IClasspathEntry.CPE_PROJECT && entryPath.equals(projectDependedOn.getFullPath())) { return true; }/* w ww . java2s. c o m*/ } return false; }
From source file:org.eclipse.ajdt.ui.tests.builder.ProjectDependenciesUtils.java
License:Open Source License
public static boolean projectHasClassFolderDependency(IProject project, IProject projectDependedOn) throws JavaModelException { IJavaProject javaProject = JavaCore.create(project); IJavaProject depProject = JavaCore.create(projectDependedOn); if (javaProject == null || depProject == null) return false; // first get the output location for projectDependedOn IPath outputLocation = null;//from www.ja va2 s. c o m IClasspathEntry[] cp = depProject.getRawClasspath(); for (int j = 0; j < cp.length; j++) { IClasspathEntry entry = cp[j]; int contentKind = entry.getContentKind(); if (contentKind == ClasspathEntry.K_OUTPUT) { outputLocation = entry.getOutputLocation(); } if (entry.getEntryKind() == ClasspathEntry.K_OUTPUT) { outputLocation = entry.getOutputLocation(); } } if (outputLocation == null) { outputLocation = depProject.getOutputLocation(); } // now check the classpath entries of project for the output // location just calculated IClasspathEntry[] cpEntry = javaProject.getRawClasspath(); for (int j = 0; j < cpEntry.length; j++) { IClasspathEntry entry = cpEntry[j]; int entryKind = entry.getEntryKind(); IPath entryPath = entry.getPath(); if (entryKind == IClasspathEntry.CPE_LIBRARY && entryPath.equals(outputLocation)) { return true; } } return false; }
From source file:org.eclipse.ajdt.ui.tests.builder.ProjectDependenciesUtils.java
License:Open Source License
public static boolean projectHasNoSrc(IProject project) { IJavaProject javaProject = JavaCore.create(project); if (javaProject == null) { return false; }/*from ww w . j av a 2s. c o m*/ boolean foundSrc = false; try { IClasspathEntry[] cpEntry = javaProject.getRawClasspath(); for (int j = 0; j < cpEntry.length; j++) { IClasspathEntry entry = cpEntry[j]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { foundSrc = true; if (entry.getPath().equals(javaProject.getPath())) { return true; } } } if (!foundSrc) return true; } catch (JavaModelException e) { AspectJTestPlugin.log(e); } return false; }
From source file:org.eclipse.ajdt.ui.tests.builder.ProjectDependenciesUtils.java
License:Open Source License
public static boolean projectHasAnExportedClasspathEntry(IProject project) { IJavaProject javaProject = JavaCore.create(project); if (javaProject == null) { return false; }/*from w ww . j a va 2s . c o m*/ try { IClasspathEntry[] cpEntry = javaProject.getRawClasspath(); for (int j = 0; j < cpEntry.length; j++) { IClasspathEntry entry = cpEntry[j]; if (entry.isExported()) { // we don't want to export it in the new classpath. if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { return true; } } } } catch (JavaModelException e) { AspectJTestPlugin.log(e); } return false; }
From source file:org.eclipse.ajdt.ui.tests.builder.ProjectDependenciesUtils.java
License:Open Source License
public static boolean projectHasJarOnClasspath(IProject projectToHaveJar, IProject projectWhichExportedJar) throws JavaModelException { IJavaProject javaProject1 = JavaCore.create(projectToHaveJar); IJavaProject javaProject2 = JavaCore.create(projectWhichExportedJar); if (javaProject1 == null || javaProject2 == null) { return false; }//from w w w . j a v a 2s . c om IClasspathEntry[] cpEntry2 = javaProject2.getRawClasspath(); for (int j = 0; j < cpEntry2.length; j++) { IClasspathEntry entry = cpEntry2[j]; if (entry.isExported()) { // we don't want to export it in the new classpath. if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IClasspathEntry[] cpEntry1 = javaProject1.getRawClasspath(); for (int i = 0; i < cpEntry1.length; i++) { IClasspathEntry entry1 = cpEntry1[i]; if (entry1.getEntryKind() == entry.getEntryKind() && entry1.getPath().equals(entry.getPath())) { if (entry1.isExported()) { // don't want it to be exported return false; } return true; } } return false; } } } return false; }