List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getPath
IPath getPath();
From source file:org.org.eclipse.dws.core.internal.jobs.UpdateJavadocAndSourcesJob.java
License:Open Source License
/** * Update javadoc./*from w w w .ja v a2 s. co m*/ * * @param project * the project * @param packageFragmentRoot * the package fragment root * @param file * the file * @param monitor * the monitor * * @throws CoreException * the core exception */ @SuppressWarnings("restriction") private void updateJavadoc(IJavaProject project, IPackageFragmentRoot packageFragmentRoot, File file, IProgressMonitor monitor) throws CoreException { try { logger.info("updating javadoc location of " + packageFragmentRoot.getElementName() + " with " + file); IClasspathEntry rawClasspathEntry = packageFragmentRoot.getRawClasspathEntry(); IPath containerPath = null; if (rawClasspathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { containerPath = rawClasspathEntry.getPath(); rawClasspathEntry = handleContainerEntry(containerPath, project, packageFragmentRoot.getPath()); } CPListElement cpElem = CPListElement.createFromExisting(rawClasspathEntry, project); String loc = "jar:file:/" + file.getAbsolutePath() + "!/"; cpElem.setAttribute(CPListElement.JAVADOC, loc); IClasspathEntry newEntry = cpElem.getClasspathEntry(); String[] changedAttributes = { CPListElement.JAVADOC }; BuildPathSupport.modifyClasspathEntry(null, newEntry, changedAttributes, project, containerPath, true, monitor); } catch (JavaModelException e) { throw new MavenRepositoryInteractionException( "Impossible to set javadoc location:" + file.getAbsolutePath(), e); } catch (CoreException e) { throw new MavenRepositoryInteractionException( "Impossible to set javadoc location:" + file.getAbsolutePath(), e); } }
From source file:org.org.eclipse.dws.ui.internal.wizards.pages.DependenciesFromClasspathPage.java
License:Open Source License
/** * Gets the possible dependency wrappers. * /* www.j a va 2 s .co m*/ * @param javaProject * the java project * * @return the possible dependency wrappers * * @throws JavaModelException * the java model exception */ private Set<PossibleDependencyWrapper> getPossibleDependencyWrappers(IJavaProject javaProject) throws JavaModelException { Set<IPackageFragmentRoot> packageFragmentRoots = new TreeSet<IPackageFragmentRoot>( new Comparator<IPackageFragmentRoot>() { public int compare(IPackageFragmentRoot o1, IPackageFragmentRoot o2) { return o1.getElementName().compareTo(o2.getElementName()); } }); for (IPackageFragmentRoot packageFragmentRoot : javaProject.getPackageFragmentRoots()) { if (isPossibleDependency(packageFragmentRoot)) { packageFragmentRoots.add(packageFragmentRoot); } } Set<PossibleDependencyWrapper> possibleDependencyWrappers = new TreeSet<PossibleDependencyWrapper>( new Comparator<PossibleDependencyWrapper>() { public int compare(PossibleDependencyWrapper o1, PossibleDependencyWrapper o2) { int result = o1.getLibraryId().compareTo(o2.getLibraryId()); if (o1.getExactMatch() != o2.getExactMatch()) { result = -(o1.getExactMatch().compareTo(o2.getExactMatch())); } return result; } }); for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) { String libraryPath = packageFragmentRoot.getPath().toOSString(); final String libraryId = packageFragmentRoot.getElementName(); Set<ArtifactVersion> possibleDependencies = findPossibleDependencies(libraryId); if (possibleDependencies.size() > 0) { Set<ArtifactVersionWrapper> artifactVersionWrappers = new TreeSet<ArtifactVersionWrapper>( new ArtifactVersionWrappersComparator(libraryId)); wrapArtifactVersions(possibleDependencies, artifactVersionWrappers, libraryId); boolean hasExactMatch = lookForExactMatch(artifactVersionWrappers); possibleDependencyWrappers.add(new PossibleDependencyWrapper(libraryPath, libraryId, Collections.unmodifiableSet(artifactVersionWrappers), hasExactMatch)); } } possibleDependencyWrappers = Collections.unmodifiableSet(possibleDependencyWrappers); return possibleDependencyWrappers; }
From source file:org.org.eclipse.dws.ui.internal.wizards.pages.LookupJavadocAndSourcesForLibrariesInClasspathPage.java
License:Open Source License
/** * Gets the libraries with missing javadoc or sources wrappers. * //w w w . j a v a 2s . com * @param javaProject * the java project * * @return the libraries with missing javadoc or sources wrappers * * @throws JavaModelException * the java model exception */ private Set<LibraryWithMissingJavadocOrSourcesWrapper> getLibrariesWithMissingJavadocOrSourcesWrappers( IJavaProject javaProject) throws JavaModelException { Set<IPackageFragmentRoot> packageFragmentRoots = new TreeSet<IPackageFragmentRoot>( new Comparator<IPackageFragmentRoot>() { public int compare(IPackageFragmentRoot o1, IPackageFragmentRoot o2) { return o1.getElementName().compareTo(o2.getElementName()); } }); for (IPackageFragmentRoot packageFragmentRoot : javaProject.getPackageFragmentRoots()) { if (isLibraryWithMissingJavadocOrSource(packageFragmentRoot)) { packageFragmentRoots.add(packageFragmentRoot); } } Set<LibraryWithMissingJavadocOrSourcesWrapper> librariesWithMissingJavadocOrSources = new TreeSet<LibraryWithMissingJavadocOrSourcesWrapper>( new Comparator<LibraryWithMissingJavadocOrSourcesWrapper>() { public int compare(LibraryWithMissingJavadocOrSourcesWrapper o1, LibraryWithMissingJavadocOrSourcesWrapper o2) { return o1.getLibraryId().compareTo(o2.getLibraryId()); } }); for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) { String libraryPath = packageFragmentRoot.getPath().toOSString(); final String libraryId = packageFragmentRoot.getElementName(); Set<ArtifactVersion> possibleDependencies = findPossibleDependencies(libraryId); if (possibleDependencies.size() > 0) { Set<ArtifactVersionWrapper> artifactVersionWrappers = new TreeSet<ArtifactVersionWrapper>( new ArtifactVersionWrappersComparator(libraryId)); wrapArtifactVersions(possibleDependencies, artifactVersionWrappers, libraryId); boolean hasExactMatch = lookForExactMatch(artifactVersionWrappers); if (hasExactMatch) { librariesWithMissingJavadocOrSources.add(new LibraryWithMissingJavadocOrSourcesWrapper( libraryPath, libraryId, artifactVersionWrappers, missesJavadoc(packageFragmentRoot), missesSources(packageFragmentRoot), packageFragmentRoot)); } } } librariesWithMissingJavadocOrSources = Collections.unmodifiableSet(librariesWithMissingJavadocOrSources); return librariesWithMissingJavadocOrSources; }
From source file:org.parallelj.designer.typeselector.processor.annotation.AnnotationProcessor.java
License:Open Source License
/** * Retrieves IType in JavaProject, for the TypeNameDescriptor * /*from www .jav a2 s .c o m*/ * @param javaProject * @param typeNameDescriptor * @return Type */ private IType getTypeFromPath(String path) { String[] pathChunks = path.split("\\|"); IJavaElement myJavaElement = null; if (pathChunks.length == 2) { String pathToJar = pathChunks[0]; String pathToClass = pathChunks[1]; IPackageFragmentRoot myJarPackageFragmentRoot = null; try { for (int i = 0; i < javaProject.getAllPackageFragmentRoots().length && myJarPackageFragmentRoot == null; i++) { IPackageFragmentRoot packageFragmentRoot = javaProject.getAllPackageFragmentRoots()[i]; String path1 = pathToJar.replace("\\", "/"); String path2 = packageFragmentRoot.getPath().toString().replace("\\", "/"); if (path1.equals(path2)) myJarPackageFragmentRoot = packageFragmentRoot; } } catch (JavaModelException e) { AnnotationActivator.getDefault() .logError("An Exception has been thrown while loading IResources in IContainer", e); } if (myJarPackageFragmentRoot == null) return null; pathToClass = pathToClass.replace("/", "."); try { for (int i = 0; i < myJarPackageFragmentRoot.getChildren().length && myJavaElement == null; i++) { IJavaElement javaElement = myJarPackageFragmentRoot.getChildren()[i]; if (javaElement instanceof IPackageFragment) { IPackageFragment packageFragment = (IPackageFragment) javaElement; for (int j = 0; j < packageFragment.getClassFiles().length && myJavaElement == null; j++) { IClassFile classFile = packageFragment.getClassFiles()[j]; String fileName = packageFragment.getElementName() + "." + classFile.getElementName(); if (pathToClass.equals(fileName)) myJavaElement = classFile; } for (int j = 0; j < packageFragment.getCompilationUnits().length && myJavaElement == null; j++) { ICompilationUnit compilationUnit = packageFragment.getCompilationUnits()[j]; String fileName = packageFragment.getElementName() + "." + compilationUnit.getElementName(); if (pathToClass.equals(fileName)) myJavaElement = compilationUnit; } } else if (javaElement instanceof IClassFile) { IClassFile classFile = (IClassFile) javaElement; String fileName = classFile.getElementName(); if (pathToClass.equals(fileName)) myJavaElement = classFile; } else if (javaElement instanceof ICompilationUnit) { ICompilationUnit compilationUnit = (ICompilationUnit) javaElement; String fileName = compilationUnit.getElementName(); if (pathToClass.equals(fileName)) myJavaElement = compilationUnit; } } } catch (JavaModelException e) { AnnotationActivator.getDefault() .logError("An Exception has been thrown while loading IResources in IContainer", e); } } else if (pathChunks.length == 1) { IFile file2 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(pathChunks[0])); if (file2 != null && file2.exists()) myJavaElement = JavaCore.create(file2); } if (myJavaElement instanceof ICompilationUnit) { ICompilationUnit compilationUnit = (ICompilationUnit) myJavaElement; return compilationUnit.getType(myJavaElement.getElementName().replace(".java", "")); } else if (myJavaElement instanceof IClassFile) { IClassFile classFile = (IClassFile) myJavaElement; return classFile.getType(); } return null; }
From source file:org.projectusus.core.internal.TestProjectCreator.java
License:Open Source License
private void addSourceFolder(IJavaProject javaProject) throws CoreException { IFolder sourceFolder = javaProject.getProject().getFolder(SOURCE_FOLDER); sourceFolder.create(false, true, null); IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(sourceFolder); IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1]; System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length); newEntries[oldEntries.length] = JavaCore.newSourceEntry(root.getPath()); javaProject.setRawClasspath(newEntries, null); }
From source file:org.seasar.dbflute.emecha.eclipse.plugin.dfassist.action.AbstractOpenActionBase.java
License:Apache License
/** * ????/*from w w w. j av a 2 s .com*/ * @param file ??? * @return ?? */ protected String getBasePackageName(IFile file, IJavaProject javap) { String filePath = file.getParent().getFullPath().toString(); String rootPath = null; try { for (IPackageFragmentRoot root : javap.getPackageFragmentRoots()) { if (filePath.startsWith(root.getPath().toString())) { rootPath = root.getPath().toString(); break; } } } catch (JavaModelException e) { DfAssistPlugin.log(e); } if (rootPath == null) return null; String dir = filePath.substring(rootPath.length() + 1); int index = dir.indexOf("/exbhv"); if (index > 0) { return dir.substring(0, index).replace('/', '.'); } return null; }
From source file:org.sf.feeling.decompiler.editor.DecompilerSourceMapper.java
License:Open Source License
protected String getArchivePath(IPackageFragmentRoot root) { String archivePath = null;//from www .ja v a2 s.c om IResource resource; try { if ((resource = root.getUnderlyingResource()) != null) // jar in workspace archivePath = resource.getLocation().toOSString(); else // external jar archivePath = root.getPath().toOSString(); } catch (JavaModelException e) { throw new RuntimeException("Unexpected Java model exception: " //$NON-NLS-1$ + e.toString()); } return archivePath; }
From source file:org.sf.feeling.decompiler.util.SortMemberUtil.java
License:Open Source License
public static IPackageFragmentRoot getDecompilerSourceFolder() { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(".decompiler"); //$NON-NLS-1$ if (project == null) return null; if (!project.exists()) { try {/* w ww . j a v a 2 s . c o m*/ project.create(null); project.open(null); IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = JavaCore.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); } catch (CoreException e1) { JavaDecompilerPlugin.logError(e1, ""); //$NON-NLS-1$ return null; } if (!project.isOpen()) return null; } else if (!project.isOpen()) { try { project.open(null); } catch (CoreException e) { JavaDecompilerPlugin.logError(e, ""); //$NON-NLS-1$ return null; } } if (decompilerSourceFolder != null) return decompilerSourceFolder; IJavaProject javaProject = JavaCore.create(project); try { List entries = new ArrayList(); IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall(); LibraryLocation[] locations = JavaRuntime.getLibraryLocations(vmInstall); for (int i = 0; i < locations.length; i++) { LibraryLocation element = locations[i]; entries.add(JavaCore.newLibraryEntry(element.getSystemLibraryPath(), null, null)); } // add libs to project class path javaProject.setRawClasspath((IClasspathEntry[]) entries.toArray(new IClasspathEntry[entries.size()]), null); IFolder sourceFolder = project.getFolder("src"); //$NON-NLS-1$ sourceFolder.create(false, true, null); IPackageFragmentRoot codeGenFolder = javaProject.getPackageFragmentRoot(sourceFolder); IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1]; System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length); newEntries[oldEntries.length] = JavaCore.newSourceEntry(codeGenFolder.getPath()); javaProject.setRawClasspath(newEntries, null); javaProject.open(null); decompilerSourceFolder = javaProject.getPackageFragmentRoot(sourceFolder); return decompilerSourceFolder; } catch (CoreException e) { JavaDecompilerPlugin.logError(e, ""); //$NON-NLS-1$ } return null; }
From source file:org.springframework.ide.eclipse.beans.core.internal.model.BeansJavaConfig.java
License:Open Source License
public BeansJavaConfig(IBeansProject project, IType configClass, String configClassName, Type type) { super(project, BeansConfigFactory.JAVA_CONFIG_TYPE + configClassName, type); this.configClass = configClass; this.configClassName = configClassName; modificationTimestamp = IResource.NULL_STAMP; if (this.configClass != null) { IResource resource = this.configClass.getResource(); if (resource != null && resource instanceof IFile) { file = (IFile) resource;/*from w ww . j a v a 2 s. c o m*/ } else { IClassFile classFile = configClass.getClassFile(); PackageFragment pkg = (PackageFragment) configClass.getPackageFragment(); IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent(); if (root.isArchive()) { IPath zipPath = root.getPath(); String classFileName = classFile.getElementName(); String path = Util.concatWith(pkg.names, classFileName, '/'); file = new ExternalFile(zipPath.toFile(), path, project.getProject()); } } } if (file == null || !file.exists()) { modificationTimestamp = IResource.NULL_STAMP; String msg = "Beans Java config class '" + configClassName + "' not accessible"; problems = new CopyOnWriteArraySet<ValidationProblem>(); problems.add(new ValidationProblem(IMarker.SEVERITY_ERROR, msg, file, -1)); } else { modificationTimestamp = file.getModificationStamp(); try { file.setSessionProperty(IBeansConfig.CONFIG_FILE_TAG, IBeansConfig.CONFIG_FILE_TAG_VALUE); } catch (CoreException e) { BeansCorePlugin.log(new Status(IStatus.WARNING, BeansCorePlugin.PLUGIN_ID, String.format("Error occured while tagging config file '%s'", file.getFullPath()), e)); } } }
From source file:org.springframework.ide.eclipse.boot.dash.cloudfoundry.JavaPackageFragmentRootHandler.java
License:Open Source License
/** * * Determines if the given package fragment root corresponds to the class * path entry path./*from w w w .ja v a 2s. c o m*/ * <p/> * Note that different package fragment roots may point to the same class * path entry. * <p/> * Example: * <p/> * A Java project may have the following package fragment roots: * <p/> * - src/main/java * <p/> * - src/main/resources * <p/> * Both may be using the same output folder: * <p/> * target/classes. * <p/> * In this case, the output folder will have a class path entry - * target/classes - and it will be the same for both roots, and this method * will return true for both roots if passed the entry for target/classes * * @param root * to check if it corresponds to the given class path entry path * @param entry * @return true if root is at the given entry */ private static boolean isRootAtEntry(IPackageFragmentRoot root, IPath entry) { try { IClasspathEntry cpe = root.getRawClasspathEntry(); if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputLocation = cpe.getOutputLocation(); if (outputLocation == null) { outputLocation = root.getJavaProject().getOutputLocation(); } IPath location = ResourcesPlugin.getWorkspace().getRoot().findMember(outputLocation).getLocation(); if (entry.equals(location)) { return true; } } } catch (JavaModelException e) { BootDashActivator.log(e); } IResource resource = root.getResource(); if (resource != null && entry.equals(resource.getLocation())) { return true; } IPath path = root.getPath(); if (path != null && entry.equals(path)) { return true; } return false; }