List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getPath
IPath getPath();
From source file:org.eclipse.jst.j2ee.refactor.listeners.J2EEElementChangedListener.java
License:Open Source License
private void getJavaSrcMappings(final IJavaElementDelta[] children, final boolean cpChanged, final IJavaProject jproject, final List pathsToAdd, final List pathsToRemove, final List changedPaths) throws CoreException { IVirtualComponent c = ComponentCore.createComponent(jproject.getProject()); if (c == null) return;/*from w w w . j av a 2 s . c o m*/ // get the default destination folder final IVirtualFolder defaultDestFolder = getDestinationFolder(c); for (int i = 0; i < children.length; i++) { final IJavaElementDelta delta = children[i]; final IJavaElement element = delta.getElement(); if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT) { final IPackageFragmentRoot root = (IPackageFragmentRoot) element; int cpeKind = IPackageFragmentRoot.K_SOURCE; boolean abortAdd = false; try { cpeKind = root.getKind(); } catch (JavaModelException jme) { // this is thrown if the folder corresponding to the CPE has been deleted // since it could represent another error, we need to abort adding. abortAdd = true; } // only update if we know it is a src folder if (cpeKind == IPackageFragmentRoot.K_SOURCE) { final int kind = delta.getKind(); if (!cpChanged) { // if the classpath is not changed, save modifications to the Java src path if (kind == IJavaElementDelta.CHANGED || kind == IJavaElementDelta.REMOVED) { changedPaths.add(root.getPath().removeFirstSegments(1)); } } else { // kind and flags for CP additions are somewhat sporadic; either: // -kind is ADDED and flags are 0 // or // -kind is CHANGED and flags are F_ADDED_TO_CLASSPATH final int flags = delta.getFlags(); if (kind == IJavaElementDelta.ADDED || (flags & IJavaElementDelta.F_ADDED_TO_CLASSPATH) == IJavaElementDelta.F_ADDED_TO_CLASSPATH) { if (!abortAdd) { final IPath pathToAdd = root.getPath().removeFirstSegments(1); pathsToAdd.add(new Object[] { pathToAdd, defaultDestFolder }); // if the added src path was moved from another location, remove any mapping for that // location if ((flags & IJavaElementDelta.F_MOVED_FROM) == IJavaElementDelta.F_MOVED_FROM) { final IJavaElement movedFromElement = delta.getMovedFromElement(); final IPath pathToRemove = movedFromElement.getPath().removeFirstSegments(1); pathsToRemove.add(new Object[] { pathToRemove, defaultDestFolder }); } } // getting a kind = REMOVED and flags = 0 for removal of the folder (w/o removing the CPE), probably // should not be generated } else if (kind == IJavaElementDelta.REMOVED || (flags & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) == IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) { IPath path = root.getPath().removeFirstSegments(1); pathsToRemove.add(new Object[] { path, defaultDestFolder }); } } } } } }
From source file:org.eclipse.jst.jsf.common.ui.internal.dialogfield.SourceFolderButtonDialogField.java
License:Open Source License
/** * Sets the current source folder (model and text field) to the given * package fragment root./* ww w .jav a 2 s.c om*/ * * @param root * The new root. * @param canBeModified * if <code>false</code> the source folder field can not be * changed by the user. If <code>true</code> the field is * editable */ public void setPackageFragmentRoot(IPackageFragmentRoot root, boolean canBeModified) { _fCurrRoot = root; String str = (root == null) ? "" : root.getPath().makeRelative().toString(); //$NON-NLS-1$ setText(str); setEnabled(canBeModified); }
From source file:org.eclipse.jst.server.jetty.core.internal.wst.ModuleTraverser.java
License:Open Source License
private static Map getComponentClasspathDependencies(final IJavaProject javaProject, final boolean isWebApp) throws CoreException { // get the raw entries final Map referencedRawEntries = getRawComponentClasspathDependencies(javaProject); final Map validRawEntries = new HashMap(); // filter out non-valid referenced raw entries final Iterator i = referencedRawEntries.keySet().iterator(); while (i.hasNext()) { final IClasspathEntry entry = (IClasspathEntry) i.next(); final IClasspathAttribute attrib = (IClasspathAttribute) referencedRawEntries.get(entry); if (isValid(entry, attrib, isWebApp, javaProject.getProject())) { validRawEntries.put(entry, attrib); }// www. j a v a 2 s .c o m } // if we have no valid raw entries, return empty map if (validRawEntries.isEmpty()) { return Collections.EMPTY_MAP; } // XXX Would like to replace the code below with use of a public JDT API that returns // the raw IClasspathEntry for a given resolved IClasspathEntry (see see https://bugs.eclipse.org/bugs/show_bug.cgi?id=183995) // The code must currently leverage IPackageFragmentRoot to determine this // mapping and, because IPackageFragmentRoots do not maintain IClasspathEntry data, a prior // call is needed to getResolvedClasspath() and the resolved IClasspathEntries have to be stored in a Map from IPath-to-IClasspathEntry to // support retrieval using the resolved IPackageFragmentRoot // retrieve the resolved classpath final IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); final Map pathToResolvedEntry = new HashMap(); // store in a map from path to entry for (int j = 0; j < entries.length; j++) { pathToResolvedEntry.put(entries[j].getPath(), entries[j]); } final Map referencedEntries = new LinkedHashMap(); // grab all IPackageFragmentRoots final IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); for (int j = 0; j < roots.length; j++) { final IPackageFragmentRoot root = roots[j]; final IClasspathEntry rawEntry = root.getRawClasspathEntry(); // is the raw entry valid? IClasspathAttribute attrib = (IClasspathAttribute) validRawEntries.get(rawEntry); if (attrib == null) { continue; } final IPath pkgFragPath = root.getPath(); final IClasspathEntry resolvedEntry = (IClasspathEntry) pathToResolvedEntry.get(pkgFragPath); final IClasspathAttribute resolvedAttrib = checkForComponentDependencyAttribute(resolvedEntry, DEPENDECYATTRIBUTETYPE_DEPENDENCY_OR_NONDEPENDENCY); // attribute for the resolved entry must either be unspecified or it must be the // dependency attribute for it to be included if (resolvedAttrib == null || resolvedAttrib.getName().equals(CLASSPATH_COMPONENT_DEPENDENCY)) { // filter out resolved entry if it doesn't pass the validation rules if (isValid(resolvedEntry, resolvedAttrib != null ? resolvedAttrib : attrib, isWebApp, javaProject.getProject())) { if (resolvedAttrib != null) { // if there is an attribute on the sub-entry, use that attrib = resolvedAttrib; } referencedEntries.put(resolvedEntry, attrib); } } } return referencedEntries; }
From source file:org.eclipse.libra.facet.OSGiBundleFacetInstallDelegate.java
License:Open Source License
private IPath[] getJavaSourceFolderPaths(IJavaProject javaProject) throws JavaModelException { List<IPath> paths = new ArrayList<IPath>(); IPackageFragmentRoot[] fragmentRoots = javaProject.getAllPackageFragmentRoots(); for (IPackageFragmentRoot fragmentRoot : fragmentRoots) { if (fragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE && fragmentRoot.getParent().equals(javaProject)) { paths.add(fragmentRoot.getPath()); }/* www. java2 s . c om*/ } return paths.toArray(new IPath[paths.size()]); }
From source file:org.eclipse.m2e.jdt.internal.JavaElementsAdapterFactory.java
License:Open Source License
public Object getAdapter(Object adaptableObject, Class adapterType) { if (adapterType == ArtifactKey.class) { if (adaptableObject instanceof IPackageFragmentRoot) { IPackageFragmentRoot fragment = (IPackageFragmentRoot) adaptableObject; IProject project = fragment.getJavaProject().getProject(); if (project.isAccessible() && fragment.isArchive()) { try { return getBuildPathManager().findArtifact(project, fragment.getPath()); } catch (CoreException ex) { log.error("Can't find artifact for " + fragment, ex); return null; }/*from w w w. j a va2 s .co m*/ } } else if (adaptableObject instanceof RequiredProjectWrapper) { IMavenProjectFacade projectFacade = getProjectFacade(adaptableObject); if (projectFacade != null) { return projectFacade.getArtifactKey(); } } else if (adaptableObject instanceof IJavaProject) { return ((IJavaProject) adaptableObject).getProject().getAdapter(ArtifactKey.class); } } else if (adapterType == IPath.class) { if (adaptableObject instanceof IJavaElement) { IResource resource = ((IJavaElement) adaptableObject).getResource(); if (resource != null) { return resource.getLocation(); } } } else if (adapterType == IMavenProjectFacade.class) { if (adaptableObject instanceof IJavaElement) { IProject project = ((IJavaElement) adaptableObject).getJavaProject().getProject(); IMavenProjectFacade projectFacade = getProjectFacade(project); if (projectFacade != null) { return projectFacade; } } else if (adaptableObject instanceof RequiredProjectWrapper) { ClassPathContainer container = ((RequiredProjectWrapper) adaptableObject) .getParentClassPathContainer(); IProject project = container.getJavaProject().getProject(); IMavenProjectFacade projectFacade = getProjectFacade(project); if (projectFacade != null) { return projectFacade; } } } return null; }
From source file:org.eclipse.modisco.java.discoverer.internal.io.library.LibraryReader.java
License:Open Source License
/** * Returns the absolute path of this library in the filesystem. * //from w w w.j ava2 s . co m * @param library * the library * @return the absolute path of this library */ public static String getPath(final IPackageFragmentRoot library) { String filePath = library.getPath().toOSString(); // non external resources are relative to the workspace if (!library.isExternal()) { IResource resource = null; if (library.isArchive()) { // zip or jar resource = ResourcesPlugin.getWorkspace().getRoot().getFile(library.getPath()); } else { // folder resource = ResourcesPlugin.getWorkspace().getRoot().getFolder(library.getPath()); } filePath = resource.getLocation().toOSString(); } return filePath; }
From source file:org.eclipse.modisco.java.discoverer.internal.io.library.ManifestReader.java
License:Open Source License
/** * Extract Manifest information./*from w w w.j a va 2 s. com*/ */ public static void completeArchiveWithManifest(final IPackageFragmentRoot physicalArchive, final Archive modelArchive, final JavaFactory factory) { try { File jarFile = null; if (physicalArchive.isExternal()) { jarFile = new File(physicalArchive.getPath().toOSString()); } else { jarFile = new File(physicalArchive.getResource().getRawLocation().toOSString()); } java.util.jar.JarFile jar = new java.util.jar.JarFile(jarFile); java.util.jar.Manifest manifest = jar.getManifest(); if (manifest != null) { Manifest modelManifest = factory.createManifest(); modelArchive.setManifest(modelManifest); java.util.jar.Attributes mainAttrs = manifest.getMainAttributes(); modelManifest.getMainAttributes().addAll(readAttributes(mainAttrs, factory)); for (Map.Entry<String, java.util.jar.Attributes> entry : manifest.getEntries().entrySet()) { ManifestEntry modelEntry = factory.createManifestEntry(); modelEntry.setName(entry.getKey()); modelEntry.getAttributes().addAll(readAttributes(entry.getValue(), factory)); modelManifest.getEntryAttributes().add(modelEntry); } } } catch (IOException e) { MoDiscoLogger.logError(e, JavaActivator.getDefault()); } }
From source file:org.eclipse.objectteams.otdt.debug.tests.OTProjectCreationDecorator.java
License:Open Source License
public void testProjectCreation() throws Exception { // delete any pre-existing project IProject pro = ResourcesPlugin.getWorkspace().getRoot().getProject("DebugTests"); if (pro.exists()) { pro.delete(true, true, null);/*ww w .j a v a 2 s . co m*/ } IWorkspaceDescription wsDescription = ResourcesPlugin.getWorkspace().getDescription(); wsDescription.setAutoBuilding(false); ResourcesPlugin.getWorkspace().setDescription(wsDescription); // create & configure project and import source fJavaProject = org.eclipse.objectteams.otdt.ui.tests.util.JavaProjectHelper .createOTJavaProject("DebugTests", "bin"); fJavaProject.setOption(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE); fJavaProject.setOption(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); fJavaProject.setOption(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.IGNORE); fJavaProject.setOption(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); IPackageFragmentRoot src = JavaProjectHelper.addSourceContainer(fJavaProject, "src"); //{ObjectTeams: rootfile-path is now org.eclipse.objectteams.otdt.debug.tests + "testprograms" File root = DebugTestsPlugin.getDefault().getPluginDirectoryPath(JavaProjectHelper.TEST_SRC_DIR); //ike} JavaProjectHelper.importFilesFromDirectory(root, src.getPath(), null); // import classfiles root = DebugTestsPlugin.getDefault().getPluginDirectoryPath(new Path("classfiles")); JavaProjectHelper.importFilesFromDirectory(root, src.getPath(), null); // add rt.jar IVMInstall vm = JavaRuntime.getDefaultVMInstall(); assertNotNull("No default JRE", vm); JavaProjectHelper.addContainerEntry(fJavaProject, new Path(JavaRuntime.JRE_CONTAINER)); //{ObjectTeams: add otre.jar: JavaProjectHelper.addContainerEntry(fJavaProject, new Path(OTREContainer.OTRE_CONTAINER_NAME)); // SH} pro = fJavaProject.getProject(); // all set up, can start auto-building now: wsDescription.setAutoBuilding(true); ResourcesPlugin.getWorkspace().setDescription(wsDescription); // create launch configuration folder IFolder folder = pro.getFolder("launchConfigurations"); if (folder.exists()) { folder.delete(true, null); } folder.create(true, true, null); // delete any existing launch configs ILaunchConfiguration[] configs = getLaunchManager().getLaunchConfigurations(); for (int i = 0; i < configs.length; i++) { configs[i].delete(); } // this one used by StratumTests: createLaunchConfiguration("Breakpoints"); //{ObjectTeams: own tests: createLaunchConfiguration("rofitests.RoFiTeam"); createLaunchConfiguration("copyinheritancetests.SubTeam"); createLaunchConfiguration("copyinheritancetests.SubTeam2"); createLaunchConfiguration("copyinheritancetests.SubTeam3"); // SH} }
From source file:org.eclipse.objectteams.otdt.internal.ui.wizards.listeners.NewTeamWizardPageListener.java
License:Open Source License
/** * Gets called when the package field has changed. The method * validates the package name and returns the status of the validation. * The validation also updates the package fragment model. * /*from w w w .j a v a 2s . com*/ * @return the status of the validation */ protected IStatus validatePackage() { StatusInfo status = new StatusInfo(); updatePackageStatusLabel(); getObservedPage().getPackageDialogField().enableButton(getObservedPage().getPackageFragmentRoot() != null); String packName = getObservedPage().getPackageName(); if (packName.trim().length() > 0) { IStatus val = NewTypeWizardPage.validatePackageName(packName, getObservedPage().getJavaProject()); if (val.getSeverity() == IStatus.ERROR) { status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidPackageName, val.getMessage())); return status; } else if (val.getSeverity() == IStatus.WARNING) { status.setWarning(Messages.format( NewWizardMessages.NewTypeWizardPage_warning_DiscouragedPackageName, val.getMessage())); // continue } } IPackageFragmentRoot root = getObservedPage().getPackageFragmentRoot(); if (root != null) { if (root.getJavaProject().exists() && packName.trim().length() > 0) { try { IPath rootPath = root.getPath(); IPath outputPath = root.getJavaProject().getOutputLocation(); if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) { // if the bin folder is inside of our root, dont allow to name a package // like the bin folder IPath packagePath = rootPath.append(packName.replace('.', '/')); if (outputPath.isPrefixOf(packagePath)) { status.setError(NewWizardMessages.NewTypeWizardPage_error_ClashOutputLocation); return status; } } } catch (JavaModelException ex) { OTDTUIPlugin.logException("", ex); //$NON-NLS-1$ // let pass } } getObservedPage().setPackageFragment(root.getPackageFragment(packName), true); } else { status.setError(""); //$NON-NLS-1$ } return status; }
From source file:org.eclipse.objectteams.otdt.tests.AbstractJavaModelTests.java
License:Open Source License
/** * Attaches a source zip to the given jar package fragment root. *///w ww . ja v a 2 s .c o m protected void attachSource(IPackageFragmentRoot root, String sourcePath, String sourceRoot) throws JavaModelException { IJavaProject javaProject = root.getJavaProject(); IClasspathEntry[] entries = (IClasspathEntry[]) javaProject.getRawClasspath().clone(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getPath().toOSString().toLowerCase().equals(root.getPath().toOSString().toLowerCase())) { entries[i] = JavaCore.newLibraryEntry(root.getPath(), sourcePath == null ? null : new Path(sourcePath), sourceRoot == null ? null : new Path(sourceRoot), false); break; } } javaProject.setRawClasspath(entries, null); }