List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getRawClasspathEntry
IClasspathEntry getRawClasspathEntry() throws JavaModelException;
From source file:com.redhat.ceylon.eclipse.core.model.loader.JDTModelLoader.java
License:Open Source License
@Override public synchronized boolean loadPackage(String packageName, boolean loadDeclarations) { packageName = Util.quoteJavaKeywords(packageName); if (loadDeclarations && !loadedPackages.add(packageName)) { return true; }//from ww w. ja v a 2 s .co m Module module = lookupModuleInternal(packageName); if (module instanceof JDTModule) { JDTModule jdtModule = (JDTModule) module; List<IPackageFragmentRoot> roots = jdtModule.getPackageFragmentRoots(); IPackageFragment packageFragment = null; for (IPackageFragmentRoot root : roots) { // skip packages that are not present if (!root.exists()) continue; try { IClasspathEntry entry = root.getRawClasspathEntry(); //TODO: is the following really necessary? //Note that getContentKind() returns an undefined //value for a classpath container or variable if (entry.getEntryKind() != IClasspathEntry.CPE_CONTAINER && entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE && entry.getContentKind() == IPackageFragmentRoot.K_SOURCE && !CeylonBuilder.isCeylonSourceEntry(entry)) { continue; } packageFragment = root.getPackageFragment(packageName); if (packageFragment.exists()) { if (!loadDeclarations) { // we found the package return true; } else { try { for (IClassFile classFile : packageFragment.getClassFiles()) { // skip removed class files if (!classFile.exists()) continue; IType type = classFile.getType(); if (type.exists() && !type.isMember() && !sourceDeclarations.containsKey( getQualifiedName(type.getPackageFragment().getElementName(), type.getTypeQualifiedName()))) { convertToDeclaration(type.getFullyQualifiedName(), DeclarationType.VALUE); } } for (org.eclipse.jdt.core.ICompilationUnit compilationUnit : packageFragment .getCompilationUnits()) { // skip removed CUs if (!compilationUnit.exists()) continue; for (IType type : compilationUnit.getTypes()) { if (type.exists() && !type.isMember() && !sourceDeclarations.containsKey( getQualifiedName(type.getPackageFragment().getElementName(), type.getTypeQualifiedName()))) { convertToDeclaration(type.getFullyQualifiedName(), DeclarationType.VALUE); } } } } catch (JavaModelException e) { e.printStackTrace(); } } } } catch (JavaModelException e) { e.printStackTrace(); } } } return false; }
From source file:com.siteview.mde.internal.core.ClasspathComputer.java
License:Open Source License
private static void addSourceFolder(IBuildEntry buildEntry, IProject project, HashSet paths, ArrayList result) throws CoreException { String[] folders = buildEntry.getTokens(); for (int j = 0; j < folders.length; j++) { String folder = folders[j]; IPath path = project.getFullPath().append(folder); if (paths.add(path)) { if (project.findMember(folder) == null) { CoreUtility.createFolder(project.getFolder(folder)); } else { IPackageFragmentRoot root = JavaCore.create(project).getPackageFragmentRoot(path.toString()); if (root.exists() && root.getKind() == IPackageFragmentRoot.K_BINARY) { result.add(root.getRawClasspathEntry()); continue; }//from w w w. j a va 2s .com } result.add(JavaCore.newSourceEntry(path)); } } }
From source file:com.siteview.mde.internal.core.ClasspathComputer.java
License:Open Source License
private static void addLibraryEntry(IProject project, IMonitorLibrary library, IPath sourceAttachment, IClasspathAttribute[] attrs, ArrayList result) throws JavaModelException { String name = ClasspathUtilCore.expandLibraryName(library.getName()); IResource jarFile = project.findMember(name); if (jarFile == null) return;//from w w w. j a v a 2s . c o m IPackageFragmentRoot root = JavaCore.create(project).getPackageFragmentRoot(jarFile); if (root.exists() && root.getKind() == IPackageFragmentRoot.K_BINARY) { IClasspathEntry oldEntry = root.getRawClasspathEntry(); // If we have the same binary root but new or different source, we should recreate the entry if ((sourceAttachment == null && oldEntry.getSourceAttachmentPath() != null) || (sourceAttachment != null && sourceAttachment.equals(oldEntry.getSourceAttachmentPath()))) { if (!result.contains(oldEntry)) { result.add(oldEntry); return; } } } IClasspathEntry entry = createClasspathEntry(project, jarFile, name, sourceAttachment, attrs, library.isExported()); if (!result.contains(entry)) result.add(entry); }
From source file:com.siteview.mde.internal.core.JavaElementChangeListener.java
License:Open Source License
private boolean ignoreDelta(IJavaElementDelta delta) { try {/*from w w w . j av a 2 s . com*/ IJavaElement element = delta.getElement(); if (element instanceof IPackageFragmentRoot) { IPackageFragmentRoot root = (IPackageFragmentRoot) element; IClasspathEntry entry = root.getRawClasspathEntry(); if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) return true; } } catch (JavaModelException e) { } return false; }
From source file:com.siteview.mde.internal.core.util.PDEJavaHelper.java
License:Open Source License
public static boolean isJRELibrary(IPackageFragmentRoot root) { try {// ww w . java 2 s .c o m IPath path = root.getRawClasspathEntry().getPath(); if (path.equals(new Path(JavaRuntime.JRE_CONTAINER)) || path.equals(new Path(JavaRuntime.JRELIB_VARIABLE))) { return true; } } catch (JavaModelException e) { } return false; }
From source file:com.siteview.mde.internal.ui.editor.build.RuntimeInfoSection.java
License:Open Source License
private void refreshOutputKeys() { if (!isJavaProject()) return;// ww w . j a v a 2s . com IBuildEntry buildEntry = getLibrarySelection(); if (buildEntry == null) return; Set outputFolders = new HashSet(); String[] jarFolders = buildEntry.getTokens(); IPackageFragmentRoot[] sourceFolders = computeSourceFolders(); for (int j = 0; j < jarFolders.length; j++) { IPackageFragmentRoot sourceFolder = getSourceFolder(jarFolders[j], sourceFolders); if (sourceFolder != null) { try { IClasspathEntry entry = sourceFolder.getRawClasspathEntry(); IPath outputPath = entry.getOutputLocation(); if (outputPath == null) { outputFolders.add("bin"); //$NON-NLS-1$ } else { outputPath = outputPath.removeFirstSegments(1); outputFolders.add(outputPath.toString()); } } catch (JavaModelException e) { MDEPlugin.logException(e); } } } if (outputFolders.size() != 0) { String libName = buildEntry.getName().substring(7); IBuildModel buildModel = getBuildModel(); IBuild build = buildModel.getBuild(); String outputName = PROPERTY_OUTPUT_PREFIX + libName; IBuildEntry outputEntry = build.getEntry(outputName); if (outputEntry == null) { outputEntry = buildModel.getFactory().createEntry(outputName); try { build.add(outputEntry); } catch (CoreException e) { MDEPlugin.logException(e); } } setOutputEntryTokens(outputFolders, outputEntry); } }
From source file:com.siteview.mde.internal.ui.wizards.tools.ConvertJarsAction.java
License:Open Source License
/** * @see IActionDelegate#run(IAction)//from w w w .ja v a 2s. c o m */ public void run(IAction action) { Map filesMap = new HashMap(); Set projectSelection = new HashSet(); Iterator i = selection.toList().iterator(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); while (i.hasNext()) { IPackageFragmentRoot pfr = (IPackageFragmentRoot) i.next(); try { projectSelection.add(pfr.getJavaProject().getProject()); IClasspathEntry rawClasspathEntry = pfr.getRawClasspathEntry(); IPath path = rawClasspathEntry.getPath(); IFile iFile = root.getFile(path); if (iFile.exists()) { JarFile jFile = new JarFile(iFile.getLocation().toString()); if (!filesMap.containsKey(jFile.getManifest())) { filesMap.put(jFile.getManifest(), iFile); } } else { String pathStr = path.toString(); JarFile file = new JarFile(pathStr); if (!filesMap.containsKey(file.getManifest())) { filesMap.put(file.getManifest(), new File(file.getName())); } } } catch (Exception e) { MDEPlugin.logException(e); } } NewLibraryPluginProjectWizard wizard = new NewLibraryPluginProjectWizard(filesMap.values(), projectSelection); wizard.init(workbench, selection); WizardDialog dialog = new WizardDialog(Display.getDefault().getActiveShell(), wizard); dialog.open(); }
From source file:com.siteview.mde.internal.ui.wizards.tools.ConvertJarsAction.java
License:Open Source License
/** * @see IActionDelegate#selectionChanged(IAction, ISelection) */// ww w. j a v a 2s. com public void selectionChanged(IAction action, ISelection s) { boolean enabled = true; if (s instanceof IStructuredSelection) { selection = (IStructuredSelection) s; if (selection.size() == 0) return; Iterator i = selection.iterator(); while (i.hasNext()) { Object obj = i.next(); if (obj instanceof IPackageFragmentRoot) { try { IPackageFragmentRoot packageFragment = (IPackageFragmentRoot) obj; if (packageFragment.getKind() == IPackageFragmentRoot.K_BINARY) { if (MDE.hasPluginNature(packageFragment.getJavaProject().getProject())) { if (packageFragment.getRawClasspathEntry() .getEntryKind() == IClasspathEntry.CPE_LIBRARY) continue; } } } catch (JavaModelException e) { } } enabled = false; break; } } else { enabled = false; this.selection = null; } action.setEnabled(enabled); }
From source file:de.loskutov.bco.ui.JdtUtils.java
License:Open Source License
/** * @param project/*from ww w. j a va2s. c o m*/ * @param pack * @return true if 'pack' argument is package root * @throws JavaModelException */ private static boolean isPackageRoot(IJavaProject project, IResource pack) throws JavaModelException { boolean isRoot = false; if (project == null || pack == null || !(pack instanceof IContainer)) { return isRoot; } IPackageFragmentRoot root = project.getPackageFragmentRoot(pack); IClasspathEntry clPathEntry = null; if (root != null) { clPathEntry = root.getRawClasspathEntry(); } isRoot = clPathEntry != null; return isRoot; }
From source file:de.loskutov.eclipse.jdepend.views.TreeObject.java
License:Open Source License
public static boolean isPackageRoot(IJavaProject project, IResource pack) throws JavaModelException { boolean isRoot = false; if (project == null || pack == null) { return isRoot; }//from w w w . j a v a2s. c o m IPackageFragmentRoot root = project.getPackageFragmentRoot(pack); IClasspathEntry clPathEntry = null; if (root != null) { clPathEntry = root.getRawClasspathEntry(); } isRoot = clPathEntry != null; return isRoot; }