public static URL getLibraryJavadocLocation(IClasspathEntry entry) { if (entry == null) { throw new IllegalArgumentException("Entry must not be null"); // $NON-NLS-1$ } int kind = entry.getEntryKind(); if (kind != IClasspathEntry.CPE_LIBRARY && kind != IClasspathEntry.CPE_VARIABLE) { throw new IllegalArgumentException( "Entry must be of kind CPE_LIBRARY or CPE_VARIABLE"); //$NON-NLS-1$ } IClasspathAttribute[] extraAttributes = entry.getExtraAttributes(); for (int i = 0; i < extraAttributes.length; i++) { IClasspathAttribute attrib = extraAttributes[i]; if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) { return parseURL(attrib.getValue()); } } return null; }
/** * Initializes the ProjectProperties object. * * @param project * @throws JavaModelException * @throws CoreException */ public void refresh() throws JavaModelException, CoreException { classPath = new StringBuffer(); inPath = new StringBuffer(); sourceFiles = new ArrayList(); javaProject = JavaCore.create(project); String projectLocalPrefix = File.separator + project.getName(); /* * get paths */ this.projectLocation = project.getLocation().removeLastSegments(1).toOSString(); this.outputPath = javaProject.getOutputLocation().toOSString(); this.sourcePaths = new ArrayList<String>(); /* * get source files */ IClasspathEntry[] classPathEntries = javaProject.getResolvedClasspath(false); for (int i = 0; i < classPathEntries.length; i++) { if (classPathEntries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { // 1st segment of the path has to be removed because it is added // again by findMember ending in duplicated first segment in the path getAllSourceFiles( project.findMember(classPathEntries[i].getPath().removeFirstSegments(1)), this.sourceFiles); if (!this.sourcePaths.contains(classPathEntries[i].getPath().toOSString())) { this.sourcePaths.add(classPathEntries[i].getPath().toOSString()); } } else if (classPathEntries[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (this.classPath.length() > 0) { this.classPath.append(File.pathSeparator); } String cp = classPathEntries[i].getPath().toOSString(); if (cp.startsWith(projectLocalPrefix)) { cp = this.projectLocation + classPathEntries[i].getPath().toOSString(); } // add the lib to inPath if specified in the .classpath file // as an inpath resource for (IClasspathAttribute attr : classPathEntries[i].getExtraAttributes()) { if (attr.getName().equals("inpath") && attr.getValue().equals("true")) { if (this.inPath.length() > 0) { this.inPath.append(File.pathSeparator); } this.inPath.append(cp); break; } } this.classPath.append(cp); } } // IFile inpathFile = project.getFile("inpath.properties"); // if(inpathFile != null) { // Properties inpathProp = new Properties(); // try { // inpathProp.load(inpathFile.getContents()); // for(Object prop : inpathProp.keySet()) { // if(inPath.length() > 0) { // inPath.append(File.pathSeparator); // } // // inPath.append(this.projectLocation).append(projectLocalPrefix).append(File.separator).append(inpathProp.get(prop)); // } // } catch (IOException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // } }