List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getRawClasspathEntry
IClasspathEntry getRawClasspathEntry() throws JavaModelException;
From source file:org.eclipse.pde.internal.core.util.PackageFragmentRootPropertyTester.java
License:Open Source License
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { if (property.equals(PROP_IN_PLUGIN_CONTAINER)) { if (receiver instanceof IPackageFragmentRoot) { IPackageFragmentRoot element = (IPackageFragmentRoot) receiver; try { IClasspathEntry entry = element.getRawClasspathEntry(); if (entry.getPath().equals(PDECore.REQUIRED_PLUGINS_CONTAINER_PATH)) { return true; }//from w w w.j a v a2s . com } catch (JavaModelException e) { return false; } } } return false; }
From source file:org.eclipse.pde.internal.ui.editor.build.RuntimeInfoSection.java
License:Open Source License
private void refreshOutputKeys() { if (!isJavaProject()) return;//from ww w . j a v a2 s . c o m IBuildEntry buildEntry = getLibrarySelection(); if (buildEntry == null) return; Set<String> outputFolders = new HashSet<String>(); 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) { PDEPlugin.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) { PDEPlugin.logException(e); } } setOutputEntryTokens(outputFolders, outputEntry); } }
From source file:org.eclipse.pde.internal.ui.wizards.tools.ConvertJarsAction.java
License:Open Source License
/** * @see IActionDelegate#run(IAction)// w w w . j a v a 2 s .c o m */ public void run(IAction action) { Map<Manifest, Object> filesMap = new HashMap<Manifest, Object>(); Set<IProject> projectSelection = new HashSet<IProject>(); Iterator<?> i = selection.toList().iterator(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); while (i.hasNext()) { IPackageFragmentRoot pfr = (IPackageFragmentRoot) i.next(); JarFile file = null; try { projectSelection.add(pfr.getJavaProject().getProject()); IClasspathEntry rawClasspathEntry = pfr.getRawClasspathEntry(); IPath path = rawClasspathEntry.getPath(); IFile iFile = root.getFile(path); if (iFile.exists()) { file = new JarFile(iFile.getLocation().toString()); if (!filesMap.containsKey(file.getManifest())) { filesMap.put(file.getManifest(), iFile); } } else { String pathStr = path.toString(); file = new JarFile(pathStr); if (!filesMap.containsKey(file.getManifest())) { filesMap.put(file.getManifest(), new File(file.getName())); } } } catch (Exception e) { PDEPlugin.logException(e); } finally { if (file != null) { try { file.close(); } catch (IOException e) { PDEPlugin.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:org.eclipse.pde.internal.ui.wizards.tools.ConvertJarsAction.java
License:Open Source License
/** * @see IActionDelegate#selectionChanged(IAction, ISelection) *//* w w w. ja v a2 s. co m*/ 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 (PDE.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:org.eclipse.virgo.ide.bundlor.internal.core.BundlorProjectBuilder.java
License:Open Source License
private void doGetAffectedResources(IResource resource, int kind, int deltaKind) throws CoreException { IJavaProject project = JavaCore.create(getProject()); if (project == null) { return;//from w w w. j a v a2s . com } IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); // Get the source folders Set<IClasspathEntry> classpathEntries = ServerModuleDelegate .getSourceClasspathEntries(resource.getProject(), false); Set<IClasspathEntry> testClasspathEntries = ServerModuleDelegate .getSourceClasspathEntries(resource.getProject(), true); // Java source files if (!this.scanByteCode && resource.getName().endsWith("java")) { //$NON-NLS-1$ IJavaElement element = JavaCore.create(resource); if (element != null && element.getJavaProject().isOnClasspath(element)) { IPackageFragmentRoot root = (IPackageFragmentRoot) element .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); try { IClasspathEntry classpathEntry = root.getRawClasspathEntry(); for (IClasspathEntry entry : classpathEntries) { if (classpathEntry.equals(entry)) { if (deltaKind == IResourceDelta.REMOVED) { this.deletedSourceResources.add(resource); } else { this.sourceResources.add(resource); } break; } } for (IClasspathEntry entry : testClasspathEntries) { if (classpathEntry.equals(entry)) { if (deltaKind == IResourceDelta.REMOVED) { this.deletedTestResources.add(resource); } else { this.testResources.add(resource); } break; } } } catch (JavaModelException e) { // This can happen in case of .java resources not on the // classpath of the project } } } // Java byte code else if (this.scanByteCode && resource.getName().endsWith(CLASS_FILE_EXTENSION)) { IPath classFilePath = resource.getFullPath(); // Check default output folders IPath defaultOutputLocation = project.getOutputLocation(); if (defaultOutputLocation.isPrefixOf(classFilePath)) { // Ok we know that the file is a class in the default output // location; let's get the class name String className = classFilePath.removeFirstSegments(defaultOutputLocation.segmentCount()) .toString(); className = className.substring(0, className.length() - CLASS_FILE_EXTENSION.length()); int ix = className.indexOf('$'); if (ix > 0) { className = className.substring(0, ix); } className = className + ".java"; if (deltaKind == IResourceDelta.REMOVED) { this.deletedSourceResources.add(resource); this.deletedTestResources.add(resource); } else { for (IClasspathEntry entry : classpathEntries) { IPath sourceLocation = entry.getPath(); IResource sourceFolder = wsRoot.findMember(sourceLocation); if (sourceFolder instanceof IFolder) { if (((IFolder) sourceFolder).findMember(className) != null) { this.sourceResources.add(resource); break; } } } for (IClasspathEntry entry : testClasspathEntries) { IPath sourceLocation = entry.getPath(); IResource sourceFolder = wsRoot.findMember(sourceLocation); if (sourceFolder instanceof IFolder) { if (((IFolder) sourceFolder).findMember(className) != null) { this.testResources.add(resource); break; } } } } } // Check output folders of source folders for (IClasspathEntry entry : classpathEntries) { IPath outputLocation = entry.getOutputLocation(); if (outputLocation != null && outputLocation.isPrefixOf(classFilePath)) { if (deltaKind == IResourceDelta.REMOVED) { this.deletedSourceResources.add(resource); } else { this.sourceResources.add(resource); } break; } } // Check output folders for test source folders for (IClasspathEntry entry : testClasspathEntries) { IPath outputLocation = entry.getOutputLocation(); if (outputLocation != null && outputLocation.isPrefixOf(classFilePath)) { if (deltaKind == IResourceDelta.REMOVED) { this.deletedTestResources.add(resource); } else { this.testResources.add(resource); } break; } } } // Some template or actual manifest file (whether or not it actually // affects packaged build) has changed. Note that this is different // behavior than // pre-Virgo server. Still, it seems reasonably conservative as worst // case we'll be re-building the project when we really don't need to, // and best case we'll catch an edge case that we would have otherwise // missed. else if (resource.getName().equals("template.mf") || resource.getName().equals("MANIFEST.MF")) { this.forceFullBuild = true; } // Hibernate mapping files else if (resource.getName().endsWith(".hbm")) { addResourceIfInSourceFolder(resource, classpathEntries, testClasspathEntries); } // JPA persistence descriptor else if (resource.getName().equals("persistence.xml") && resource.getParent() != null && resource.getParent().getName().equals("META-INF")) { addResourceIfInSourceFolder(resource, classpathEntries, testClasspathEntries); } else if (isWebXML(resource)) { this.sourceResources.add(resource); } // Spring configuration file else if (resource.getName().endsWith(".xml")) { addResourceIfInSourceFolder(resource, classpathEntries, testClasspathEntries); } }
From source file:org.eclipse.virgo.ide.export.BundleExportUtils.java
License:Open Source License
/** * Find manifest file given a java project * * @param project/* www . j ava2s . com*/ * @return */ public static IResource getOutputManifestFile(IJavaProject project) { try { Set<IPath> outputPaths = new HashSet<IPath>(); outputPaths.add(project.getOutputLocation()); IPackageFragmentRoot[] roots = project.getPackageFragmentRoots(); for (IPackageFragmentRoot root : roots) { if (root != null) { IClasspathEntry cpEntry = root.getRawClasspathEntry(); if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath location = cpEntry.getOutputLocation(); if (location != null) { outputPaths.add(location); } } } } for (IPath outputPath : outputPaths) { IResource manifest = getManifestFile(outputPath, project.getProject()); if (manifest != null) { return manifest; } } } catch (JavaModelException e) { // No error handling existed before. Are these expected?! throw new RuntimeException(e); } catch (MalformedURLException e) { // No error handling existed before. Are these expected?! throw new RuntimeException(e); } return null; }
From source file:org.eclipse.virgo.ide.export.BundleExportUtils.java
License:Open Source License
/** * Create export operation given project to be exported and location of the JAR. * * @param project//from www . jav a 2 s .c om * @param jarLocation * @param shell * @param warningMessages * @return */ public static IJarExportRunnable createExportOperation(IJavaProject project, IPath jarLocation, Shell shell, List<IStatus> warnings) { JarPackageData jarPackage = new JarPackageData(); jarPackage.setJarLocation(jarLocation); jarPackage.setExportClassFiles(true); jarPackage.setExportJavaFiles(false); jarPackage.setOverwrite(true); jarPackage.setExportErrors(true); jarPackage.setExportWarnings(true); jarPackage.setBuildIfNeeded(true); Set<Object> outputFiles = new LinkedHashSet<Object>(); try { Set<IClasspathEntry> entries = ServerModuleDelegate.getSourceClasspathEntries(project.getProject(), false); for (IPackageFragmentRoot root : project.getPackageFragmentRoots()) { if (entries.contains(root.getRawClasspathEntry())) { outputFiles.add(root); } } } catch (JavaModelException e) { // TODO add error handling throw new RuntimeException(e); } jarPackage.setElements(outputFiles.toArray()); setManifestFile(project, jarPackage, shell, warnings); return jarPackage.createJarExportRunnable(shell); }
From source file:org.eclipse.virgo.ide.jdt.internal.ui.decoration.JdtClasspathContainerElementDecorator.java
License:Open Source License
/** * Decorates the given <code>element</code>. *//*from w w w .j av a2 s . c o m*/ public void decorate(Object element, IDecoration decoration) { // package fragments are the first elements below the JAR file if (element instanceof IPackageFragment) { IPackageFragment packageFragment = (IPackageFragment) element; if (shouldDecorateImportedPackageFragment(packageFragment)) { // make light gray and lock icon decoration decoration.setForegroundColor(ColorMap.GRAY_LIGHT); decoration.addOverlay(JdtUiImages.DESC_OVR_LOCKED, IDecoration.TOP_LEFT); } else if (shouldDecorateExportedPackageFragment(packageFragment)) { decoration.addOverlay(JdtUiImages.DESC_OVR_EXPORTED, IDecoration.TOP_RIGHT); } } // jar package fragments roots; decorate those that come from a test dependency else if (element instanceof IPackageFragmentRoot) { IPackageFragmentRoot root = (IPackageFragmentRoot) element; try { if (ServerClasspathContainer.CLASSPATH_CONTAINER_PATH.equals(root.getRawClasspathEntry().getPath()) && root.getJavaProject().getProject().isAccessible() && root.getJavaProject().isOpen()) { ServerClasspathContainer cpContainer = (ServerClasspathContainer) JavaCore .getClasspathContainer(ServerClasspathContainer.CLASSPATH_CONTAINER_PATH, root.getJavaProject()); if (cpContainer != null) { for (IClasspathEntry entry : cpContainer.getClasspathEntries()) { if (entry.getPath().equals(root.getPath()) && entry.getExtraAttributes() != null) { for (IClasspathAttribute attribute : entry.getExtraAttributes()) { if (attribute.getName() .equals(ServerClasspathContainer.TEST_CLASSPATH_ATTRIBUTE_VALUE)) { decoration.setForegroundColor(ColorMap.GRAY_LIGHT); decoration.addOverlay(JdtUiImages.DESC_OVR_LOCKED, IDecoration.TOP_LEFT); } } break; } } } } } catch (JavaModelException e) { } } // class files represent a single type file in a JAR else if (element instanceof IClassFile) { IClassFile classFile = (IClassFile) element; if (classFile.getParent() instanceof IPackageFragment) { if (shouldDecorateImportedPackageFragment((IPackageFragment) classFile.getParent())) { // make light gray decoration.setForegroundColor(ColorMap.GRAY_LIGHT); } } } // decorate the class path container and add the originating target runtime else if (element instanceof ClassPathContainer) { ClassPathContainer container = (ClassPathContainer) element; if (container.getClasspathEntry().getPath().equals(ServerClasspathContainer.CLASSPATH_CONTAINER_PATH)) { try { if (container.getJavaProject().getProject().isAccessible() && container.getJavaProject().isOpen()) { ServerClasspathContainer cpContainer = (ServerClasspathContainer) JavaCore .getClasspathContainer(ServerClasspathContainer.CLASSPATH_CONTAINER_PATH, container.getJavaProject()); decoration.addSuffix(cpContainer.getDescriptionSuffix()); } } catch (JavaModelException e) { } } } }
From source file:org.eclipse.virgo.ide.jdt.internal.ui.decoration.JdtClasspathContainerElementDecorator.java
License:Open Source License
/** * Checks if a given {@link IPackageFragment} is in the list of resolved imports for the current * {@link IJavaProject}.//ww w . j a v a 2s . co m * * @return true if the {@link IPackageFragment} is not accessible from the java project */ private boolean shouldDecorateImportedPackageFragment(IPackageFragment packageFragment) { IPackageFragmentRoot root = (IPackageFragmentRoot) packageFragment.getParent(); IJavaProject javaProject = packageFragment.getJavaProject(); if (!(javaProject.getProject().isAccessible() && javaProject.isOpen())) { return false; } // Only decorate in bundle projects if (!FacetUtils.isBundleProject(javaProject.getProject())) { return false; } try { IClasspathEntry entry = root.getRawClasspathEntry(); if (entry.getPath().equals(ServerClasspathContainer.CLASSPATH_CONTAINER_PATH)) { if (!BundleManifestCorePlugin.getBundleManifestManager() .getResolvedPackageImports(root.getJavaProject()) .contains(packageFragment.getElementName())) { return true; } } } catch (JavaModelException e) { } return false; }
From source file:org.eclipse.xtext.builder.impl.javasupport.JdtToBeBuiltComputer.java
License:Open Source License
/** * Handle all fragment roots that are on the classpath and not a source folder. */// w w w . j av a 2 s. c om private boolean shouldHandle(IPackageFragmentRoot root) { try { boolean result = !JavaRuntime.newDefaultJREContainerPath() .isPrefixOf(root.getRawClasspathEntry().getPath()); result &= (root.isArchive() || root.isExternal()); return result; } catch (JavaModelException ex) { if (!ex.isDoesNotExist()) log.error(ex.getMessage(), ex); return false; } }