List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot isExternal
boolean isExternal();
From source file:org.eclipse.modisco.java.discoverer.internal.io.library.LibraryReader.java
License:Open Source License
/** * Returns the archive-relative path of the class file. If this class file * is in an archive (workspace or external), the path will be the path * inside the archive. If it is in a folder (workspace or external), the * path will be the full absolute path to this class file. * /*from w w w .j ava2 s.c om*/ * @param classFile * the class file * @return the archive-relative path */ public static String getPath(final IClassFile classFile) { IPackageFragmentRoot library = (IPackageFragmentRoot) classFile .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); String filePath = null; if (library.isArchive()) { // zip or jar IPackageFragment parent = (IPackageFragment) classFile.getParent(); String packagePath = parent.getElementName().replace('.', '/'); filePath = '/' + packagePath + '/' + classFile.getElementName(); } else { // folder if (library.isExternal()) { filePath = classFile.getPath().toOSString(); } else { IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(classFile.getPath()); filePath = file.getLocation().toOSString(); } } return filePath; }
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 ww . ja v a 2 s . c o 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.//www.j av a 2 s . co m */ 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.tests.AbstractJavaModelTests.java
License:Open Source License
/** * Returns the specified package fragment root in the given project, or * <code>null</code> if it does not exist. * If relative, the rootPath must be specified as a project relative path. * The empty path refers to the package fragment root that is the project * folder iteslf./*from ww w .ja v a 2 s . c o m*/ * If absolute, the rootPath refers to either an external jar, or a resource * internal to the workspace */ public IPackageFragmentRoot getPackageFragmentRoot(String projectName, String rootPath) throws JavaModelException { IJavaProject project = getJavaProject(projectName); if (project == null) { return null; } IPath path = new Path(rootPath); if (path.isAbsolute()) { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IResource resource = workspaceRoot.findMember(path); IPackageFragmentRoot root; if (resource == null) { // external jar root = project.getPackageFragmentRoot(rootPath); } else { // resource in the workspace root = project.getPackageFragmentRoot(resource); } return root; } else { IPackageFragmentRoot[] roots = project.getPackageFragmentRoots(); if (roots == null || roots.length == 0) { return null; } for (int i = 0; i < roots.length; i++) { IPackageFragmentRoot root = roots[i]; if (!root.isExternal() && root.getUnderlyingResource().getProjectRelativePath().equals(path)) { return root; } } } return null; }
From source file:org.eclipse.pde.internal.ui.views.plugins.ImportActionGroup.java
License:Open Source License
private static IPluginModelBase getModel(Object next) { IPluginModelBase model = null;// w w w . j a v a2 s. co m if (next instanceof IPluginModelBase) { model = (IPluginModelBase) next; } else if (next instanceof IPluginBase) { model = ((IPluginBase) next).getPluginModel(); } else if (next instanceof IPluginExtension) { model = ((IPluginExtension) next).getPluginModel(); } else if (next instanceof IPluginExtensionPoint) { model = ((IPluginExtensionPoint) next).getPluginModel(); } else if (next instanceof BundleDescription) { model = PDECore.getDefault().getModelManager().findModel((BundleDescription) next); } else if (next instanceof BundleSpecification) { // Required for contents of Target Platform State View BundleDescription desc = (BundleDescription) ((BundleSpecification) next).getSupplier(); if (desc != null) { model = PDECore.getDefault().getModelManager().findModel(desc); } } else if (next instanceof IPackageFragmentRoot) { // Required for context menu on PDE classpath container entries IPackageFragmentRoot root = (IPackageFragmentRoot) next; if (root.isExternal()) { String path = root.getPath().toOSString(); IPluginModelBase[] externalModels = PDECore.getDefault().getModelManager().getExternalModels(); for (int i = 0; i < externalModels.length; i++) { if (path.equals(externalModels[i].getInstallLocation())) { return externalModels[i]; } } } } return model; }
From source file:org.eclipse.recommenders.jdt.JavaElementsFinder.java
License:Open Source License
/** * Returns the compilation unit's absolute location on the local hard drive - if it exists. *//*from w w w. ja va2 s .co m*/ public static Optional<File> findLocation(@Nullable IPackageFragmentRoot root) { if (root == null) { return absent(); } File res = null; final IResource resource = root.getResource(); if (resource != null) { if (resource.getLocation() == null) { res = resource.getRawLocation().toFile().getAbsoluteFile(); } else { res = resource.getLocation().toFile().getAbsoluteFile(); } } if (root.isExternal()) { res = root.getPath().toFile().getAbsoluteFile(); } // if the file (for whatever reasons) does not exist return absent(). if (res != null && !res.exists()) { return absent(); } return fromNullable(res); }
From source file:org.eclipse.recommenders.rcp.utils.JdtUtils.java
License:Open Source License
public static Optional<File> getLocation(@Nullable final IPackageFragmentRoot packageRoot) { if (packageRoot == null) { return absent(); }// ww w. j ava 2s . c o m File res = null; final IResource resource = packageRoot.getResource(); if (resource != null) { if (resource.getLocation() == null) { res = resource.getRawLocation().toFile().getAbsoluteFile(); } else { res = resource.getLocation().toFile().getAbsoluteFile(); } } if (packageRoot.isExternal()) { res = packageRoot.getPath().toFile().getAbsoluteFile(); } // if the file (for whatever reasons) does not exist, skip it. if (res != null && !res.exists()) { res = null; } return Optional.fromNullable(res); }
From source file:org.eclipse.scout.sdk.saml.importer.operation.AbstractSamlElementImportOperation.java
License:Open Source License
protected void deleteClass(IScoutBundle bundle, String pckName, String className) throws CoreException { String fileName = className + ".java"; for (IPackageFragmentRoot r : bundle.getJavaProject().getPackageFragmentRoots()) { if (!r.isArchive() && !r.isReadOnly() && !r.isExternal()) { IFolder fld = (IFolder) r.getResource(); if (fld.exists()) { IFolder packageFolder = fld.getFolder(new Path(pckName.replace('.', '/'))); if (packageFolder.exists()) { IFile javaFile = packageFolder.getFile(fileName); if (javaFile.exists()) { javaFile.delete(true, false, getSamlContext().getMonitor()); break; }/*from w w w . j a v a2 s . c o m*/ } } } } }
From source file:org.eclipse.viatra.query.patternlanguage.emf.ui.util.JavaProjectExpectedPackageNameProvider.java
License:Open Source License
/** * Based on org.eclipse.xtend.ide.validator.XtendUIValidator.java *///from w w w .ja v a2 s .c o m @Override public String getExpectedPackageName(PatternModel model) { URI fileURI = model.eResource().getURI(); for (Pair<IStorage, IProject> storage : storage2UriMapper.getStorages(fileURI)) { if (storage.getFirst() instanceof IFile) { IPath fileWorkspacePath = storage.getFirst().getFullPath(); IJavaProject javaProject = JavaCore.create(storage.getSecond()); if (javaProject != null && javaProject.exists() && javaProject.isOpen()) { try { for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { if (!root.isArchive() && !root.isExternal()) { IResource resource = root.getResource(); if (resource != null) { IPath sourceFolderPath = resource.getFullPath(); if (sourceFolderPath.isPrefixOf(fileWorkspacePath)) { IPath classpathRelativePath = fileWorkspacePath .makeRelativeTo(sourceFolderPath); return classpathRelativePath.removeLastSegments(1).toString().replace("/", "."); } } } } } catch (JavaModelException e) { logger.error("Error resolving package declaration for Pattern Model", e); } } } } return null; }
From source file:org.eclipse.virgo.ide.export.BundleExportWizardPage.java
License:Open Source License
@Override protected ViewerFilter getTreeViewerFilter() { return new ViewerFilter() { @Override/*from www . j a v a 2 s. c o m*/ public boolean select(Viewer viewer, Object parentElement, Object element) { if (element instanceof IPackageFragmentRoot) { IPackageFragmentRoot root = (IPackageFragmentRoot) element; return !root.isArchive() && !root.isExternal(); } else if (element instanceof IProject) { IProject project = (IProject) element; try { IFacetedProject facetedProject = ProjectFacetsManager.create(project); if (facetedProject == null) { return false; } return facetedProject.hasProjectFacet(ProjectFacetsManager .getProjectFacet(FacetCorePlugin.BUNDLE_FACET_ID).getDefaultVersion()); } catch (CoreException e) { return false; } } return false; } }; }