List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE
int CPE_SOURCE
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE.
Click Source Link
From source file:org.eclipse.m2e.wtp.jpa.internal.configurators.MavenResourceLocator.java
License:Open Source License
IPath lookupProjectSources(IProject project, IPath runtimePath) { IJavaProject javaProject = JavaCore.create(project); IPath resourcePath = null;//from w w w. j a va2s . c o m try { for (IClasspathEntry entry : javaProject.getRawClasspath()) { if (IClasspathEntry.CPE_SOURCE == entry.getEntryKind()) { resourcePath = getFilePath(entry.getPath(), runtimePath); if (resourcePath != null) { return resourcePath; } } } } catch (JavaModelException e) { LOG.error(NLS.bind("An error occured while looking up {0} sources", project), e); //$NON-NLS-1$ } return null; }
From source file:org.eclipse.m2e.wtp.WTPProjectsUtil.java
License:Open Source License
public static void removeTestFolderLinks(IProject project, MavenProject mavenProject, IProgressMonitor monitor, String folder) throws CoreException { IVirtualComponent component = ComponentCore.createComponent(project); if (component == null) { return;//from w w w .j a va2s. c om } IVirtualFolder jsrc = component.getRootFolder().getFolder(folder); for (IPath location : MavenProjectUtils.getSourceLocations(project, mavenProject.getTestCompileSourceRoots())) { if (location == null) continue; jsrc.removeLink(location, 0, monitor); } for (IPath location : MavenProjectUtils.getResourceLocations(project, mavenProject.getTestResources())) { if (location == null) continue; jsrc.removeLink(location, 0, monitor); } //MECLIPSEWTP-217 : exclude other test source folders, added by build-helper for instance if (project.hasNature(JavaCore.NATURE_ID)) { IJavaProject javaProject = JavaCore.create(project); if (javaProject == null) { return; } IPath testOutputDirPath = MavenProjectUtils.getProjectRelativePath(project, mavenProject.getBuild().getTestOutputDirectory()); if (testOutputDirPath == null) { return; } IPath testPath = project.getFullPath().append(testOutputDirPath); IClasspathEntry[] cpes = javaProject.getRawClasspath(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); for (IClasspathEntry cpe : cpes) { if (cpe != null && cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputLocation = cpe.getOutputLocation(); if (testPath.equals(outputLocation)) { IPath sourcePath = root.getFolder(cpe.getPath()).getProjectRelativePath(); if (sourcePath != null) { jsrc.removeLink(sourcePath, 0, monitor); } } } } } }
From source file:org.eclipse.ocl.examples.editor.ui.builder.CommonBuilder.java
License:Open Source License
/** * Return the classpath entry applicable to the file. * Returns null if none available./*from ww w .ja v a 2 s. c o m*/ */ protected IClasspathEntry getClasspathEntry(IFile file, IClasspathEntry[] resolvedClasspath) { IPath workspaceRelativeInputPath = file.getFullPath(); for (IClasspathEntry resolvedClasspathEntry : resolvedClasspath) { if (resolvedClasspathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath sourcePath = resolvedClasspathEntry.getPath(); if (sourcePath.isPrefixOf(workspaceRelativeInputPath)) return resolvedClasspathEntry; } } return null; }
From source file:org.eclipse.ocl.examples.editor.ui.builder.CommonBuilder.java
License:Open Source License
protected List<File> getSourceFolders(IPath projectRelativeInputPath) { List<File> srcFolders = new ArrayList<File>(); IPath inputPathParent = projectRelativeInputPath.removeLastSegments(1); IResource inputContainer = inputPathParent.segmentCount() > 0 ? getProject().getFile(inputPathParent) : getProject();// w w w.ja v a2 s . c o m if (inputContainer != null) srcFolders.add(inputContainer.getLocation().toFile()); IClasspathEntry[] resolvedClasspath = getClasspathEntries(getProject()); if (resolvedClasspath != null) { IWorkspaceRoot workspaceRoot = getProject().getWorkspace().getRoot(); for (IClasspathEntry resolvedClasspathEntry : resolvedClasspath) { if (resolvedClasspathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IFile sourceContainer = workspaceRoot.getFile(resolvedClasspathEntry.getPath()); if (sourceContainer != null) srcFolders.add(sourceContainer.getLocation().toFile()); } } } return srcFolders; }
From source file:org.eclipse.ocl.examples.editor.ui.builder.CommonBuilder.java
License:Open Source License
/** * @return true iff this resource identifies an output folder *//* w ww. j a v a 2s. c o m*/ @Override protected boolean isOutputFolder(IResource resource) { IClasspathEntry[] resolvedClasspath = getClasspathEntries(resource.getProject()); if (resolvedClasspath == null) return false; // FIXME ??? IPath workspaceRelativePath = resource.getFullPath(); for (IClasspathEntry resolvedClasspathEntry : resolvedClasspath) { if (resolvedClasspathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputPath = resolvedClasspathEntry.getOutputLocation(); if ((outputPath != null) && outputPath.isPrefixOf(workspaceRelativePath)) return true; } } return false; }
From source file:org.eclipse.osee.framework.ui.ws.AJavaProject.java
License:Open Source License
public static ArrayList<File> getJavaProjectProjectDependancies(IJavaProject javaProject) { ArrayList<File> urls = new ArrayList<File>(); try {//from w w w. j a va 2 s. c om IClasspathEntry[] paths = localGetResolvedClasspath(javaProject); for (int i = 0; i < paths.length; i++) { if (paths[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (paths[i].getPath().toFile().exists()) { // urls.add(paths[i].getPath().toFile()); } else { File file = null; file = new File(AWorkspace.getWorkspacePath().concat(paths[i].getPath().toOSString())); if (file.exists()) { urls.add(file); } } } else if (paths[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) { urls.add(new File(AWorkspace.getWorkspacePath().concat(paths[i].getPath().toFile().getPath() .concat(File.separator + "bin" + File.separator)))); } else if (paths[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { File projectlocation = javaProject.getProject().getLocation().toFile(); File projecttricky = javaProject.getProject().getFullPath().toFile(); IPath output = paths[i].getOutputLocation(); File fileLocation; if (output == null) { fileLocation = new File(paths[i].getPath().toFile().getPath().replace("src", "bin")); } else { fileLocation = paths[i].getOutputLocation().toFile(); } String realLocation = fileLocation.toString().replace(projecttricky.toString(), projectlocation.toString()); urls.add(new File(realLocation)); } } } catch (JavaModelException ex) { ex.printStackTrace(); } return urls; }
From source file:org.eclipse.pde.api.tools.internal.builder.ApiAnalysisBuilder.java
License:Open Source License
/** * Returns the complete listing of required projects from the classpath of * the backing project/*from www .j a v a 2 s . c om*/ * * @param includeBinaryPrerequisites * @return the list of projects required * @throws CoreException */ IProject[] getRequiredProjects(boolean includebinaries) throws CoreException { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); if (this.currentproject == null || workspaceRoot == null) { return new IProject[0]; } ArrayList<IProject> projects = new ArrayList<IProject>(); try { IJavaProject javaProject = JavaCore.create(this.currentproject); HashSet<IPath> blocations = new HashSet<IPath>(); blocations.add(javaProject.getOutputLocation()); this.output_locs.put(this.currentproject, blocations); HashSet<IPath> slocations = new HashSet<IPath>(); IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].isArchive()) { continue; } slocations.add(roots[i].getPath()); } this.src_locs.put(this.currentproject, slocations); IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); for (int i = 0, l = entries.length; i < l; i++) { IClasspathEntry entry = entries[i]; IPath path = entry.getPath(); IProject p = null; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: { p = workspaceRoot.getProject(path.lastSegment()); // missing // projects // are // considered // too if (isOptional(entry) && !p.hasNature(ApiPlugin.NATURE_ID)) {// except // if // entry // is // optional p = null; } break; } case IClasspathEntry.CPE_LIBRARY: { if (includebinaries && path.segmentCount() > 1) { // some binary resources on the class path can come // from projects that are not included in the // project references IResource resource = workspaceRoot.findMember(path.segment(0)); if (resource instanceof IProject) { p = (IProject) resource; } } break; } case IClasspathEntry.CPE_SOURCE: { IPath entrypath = entry.getOutputLocation(); if (entrypath != null) { blocations.add(entrypath); } break; } default: { break; } } if (p != null && !projects.contains(p)) { projects.add(p); // try to derive all of the output locations for each of the // projects javaProject = JavaCore.create(p); HashSet<IPath> bins = new HashSet<IPath>(); HashSet<IPath> srcs = new HashSet<IPath>(); if (javaProject.exists()) { bins.add(javaProject.getOutputLocation()); IClasspathEntry[] source = javaProject.getRawClasspath(); IPath entrypath = null; for (int j = 0; j < source.length; j++) { if (source[j].getEntryKind() == IClasspathEntry.CPE_SOURCE) { srcs.add(source[j].getPath()); entrypath = source[j].getOutputLocation(); if (entrypath != null) { bins.add(entrypath); } } } this.output_locs.put(p, bins); this.src_locs.put(p, srcs); } } } } catch (JavaModelException e) { return new IProject[0]; } IProject[] result = new IProject[projects.size()]; projects.toArray(result); return result; }
From source file:org.eclipse.pde.api.tools.internal.model.ProjectComponent.java
License:Open Source License
@Override protected synchronized List<IApiTypeContainer> createApiTypeContainers() throws CoreException { // first populate build.properties cache so we can create class file // containers // from bundle classpath entries fPathToOutputContainers = new HashMap<String, IApiTypeContainer>(4); fOutputLocationToContainer = new HashMap<IPath, IApiTypeContainer>(4); if (fProject.exists() && fProject.getProject().isOpen()) { IPluginModelBase model = PluginRegistry.findModel(fProject.getProject()); if (model != null) { IBuildModel buildModel = PluginRegistry.createBuildModel(model); if (buildModel != null) { IBuild build = buildModel.getBuild(); IBuildEntry entry = build.getEntry(ENTRY_CUSTOM); if (entry != null) { String[] tokens = entry.getTokens(); if (tokens.length == 1 && tokens[0].equals("true")) { //$NON-NLS-1$ // hack : add the current output location for each // classpath entries IClasspathEntry[] classpathEntries = fProject.getRawClasspath(); List<IApiTypeContainer> containers = new ArrayList<IApiTypeContainer>(); for (int i = 0; i < classpathEntries.length; i++) { IClasspathEntry classpathEntry = classpathEntries[i]; switch (classpathEntry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: String containerPath = classpathEntry.getPath().removeFirstSegments(1) .toString(); IApiTypeContainer container = getApiTypeContainer(containerPath, this); if (container != null && !containers.contains(container)) { containers.add(container); }/*from www .ja va 2s .c o m*/ break; case IClasspathEntry.CPE_VARIABLE: classpathEntry = JavaCore.getResolvedClasspathEntry(classpathEntry); //$FALL-THROUGH$ case IClasspathEntry.CPE_LIBRARY: IPath path = classpathEntry.getPath(); if (Util.isArchive(path.lastSegment())) { IResource resource = ResourcesPlugin.getWorkspace().getRoot() .findMember(path); if (resource != null) { // jar inside the workspace containers.add(new ArchiveApiTypeContainer(this, resource.getLocation().toOSString())); } else { // external jar containers.add(new ArchiveApiTypeContainer(this, path.toOSString())); } } break; default: break; } } if (!containers.isEmpty()) { IApiTypeContainer cfc = null; if (containers.size() == 1) { cfc = containers.get(0); } else { cfc = new CompositeApiTypeContainer(this, containers); } fPathToOutputContainers.put(".", cfc); //$NON-NLS-1$ } } } else { IBuildEntry[] entries = build.getBuildEntries(); int length = entries.length; for (int i = 0; i < length; i++) { IBuildEntry buildEntry = entries[i]; String name = buildEntry.getName(); if (name.startsWith(IBuildEntry.JAR_PREFIX)) { retrieveContainers(name, IBuildEntry.JAR_PREFIX, buildEntry); } else if (name.startsWith(EXTRA_PREFIX)) { retrieveContainers(name, EXTRA_PREFIX, buildEntry); } } } } } return super.createApiTypeContainers(); } return Collections.EMPTY_LIST; }
From source file:org.eclipse.pde.api.tools.internal.ProjectApiDescription.java
License:Open Source License
@Override protected ManifestNode createNode(ManifestNode parentNode, IElementDescriptor element) { switch (element.getElementType()) { case IElementDescriptor.PACKAGE: try {/*www .j a v a 2s . c o m*/ IPackageDescriptor pkg = (IPackageDescriptor) element; IPackageFragmentRoot[] roots = getJavaProject().getPackageFragmentRoots(); List<IPackageFragment> fragments = new ArrayList<IPackageFragment>(1); for (int i = 0; i < roots.length; i++) { IPackageFragmentRoot root = roots[i]; IClasspathEntry entry = root.getRawClasspathEntry(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: case IClasspathEntry.CPE_LIBRARY: IPackageFragment fragment = root.getPackageFragment(pkg.getName()); if (fragment.exists()) { fragments.add(fragment); } break; default: if (!root.isArchive() && root.getKind() == IPackageFragmentRoot.K_BINARY) { // class file folder fragment = root.getPackageFragment(pkg.getName()); if (fragment.exists()) { fragments.add(fragment); } } } } if (fragments.isEmpty()) { return null; } else { return newPackageNode(fragments.toArray(new IPackageFragment[fragments.size()]), parentNode, element, VisibilityModifiers.PRIVATE, RestrictionModifiers.NO_RESTRICTIONS); } } catch (CoreException e) { return null; } case IElementDescriptor.TYPE: IReferenceTypeDescriptor descriptor = (IReferenceTypeDescriptor) element; try { IType type = null; String name = descriptor.getName(); if (parentNode instanceof PackageNode) { IPackageFragment[] fragments = ((PackageNode) parentNode).fFragments; for (int i = 0; i < fragments.length; i++) { IPackageFragment fragment = fragments[i]; if (fragment.getKind() == IPackageFragmentRoot.K_SOURCE) { ICompilationUnit unit = fragment.getCompilationUnit(name + ".java"); //$NON-NLS-1$ try { IResource resource = unit.getUnderlyingResource(); if (resource != null) { type = unit.getType(name); } } catch (JavaModelException jme) { // exception if the resource does not exist if (!jme.getJavaModelStatus().isDoesNotExist()) { throw jme; } } } else { IClassFile file = fragment.getClassFile(name + ".class"); //$NON-NLS-1$ if (file.exists()) { type = file.getType(); } } } } else if (parentNode instanceof TypeNode) { type = ((TypeNode) parentNode).fType.getType(name); } if (type != null) { return newTypeNode(type, parentNode, element, VISIBILITY_INHERITED, RestrictionModifiers.NO_RESTRICTIONS); } } catch (CoreException e) { return null; } return null; default: break; } return super.createNode(parentNode, element); }
From source file:org.eclipse.pde.internal.core.builders.BuildErrorReporter.java
License:Open Source License
/** * Matches the javacSource, javacTarget, javacWarnings, javacErrors and jre.compilation.prile entries in build.properties with the * project specific Java Compiler properties and reports the errors found. * //from ww w . j a va 2 s . c o m * @param javacSourceEntry * @param javacTargetEntry * @param jreCompilationProfileEntry * @param javacWarningsEntries * @param javacErrorsEntries * @param libraryNames list of library names (javacWarnings/javacErrors require an entry for each source library) */ private void validateExecutionEnvironment(IBuildEntry javacSourceEntry, IBuildEntry javacTargetEntry, IBuildEntry jreCompilationProfileEntry, ArrayList<IBuildEntry> javacWarningsEntries, ArrayList<IBuildEntry> javacErrorsEntries, List<String> libraryNames) { // if there is no source to compile, don't worry about compiler settings IJavaProject project = JavaCore.create(fProject); if (project.exists()) { IClasspathEntry[] classpath = null; try { classpath = project.getRawClasspath(); } catch (JavaModelException e) { PDECore.log(e); return; } boolean source = false; for (int i = 0; i < classpath.length; i++) { IClasspathEntry cpe = classpath[i]; if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { source = true; } } if (!source) { return; } String projectComplianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, false); if (projectComplianceLevel != null) { IPluginModelBase model = PluginRegistry.findModel(fProject); String[] execEnvs = null; if (model != null) { BundleDescription bundleDesc = model.getBundleDescription(); if (bundleDesc != null) { execEnvs = bundleDesc.getExecutionEnvironments(); } } if (execEnvs == null || execEnvs.length == 0) { return; } //PDE Build uses top most entry to build the plug-in String execEnv = execEnvs[0]; String projectSourceCompatibility = project.getOption(JavaCore.COMPILER_SOURCE, true); String projectClassCompatibility = project.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true); if (projectComplianceLevel .equals(findMatchingEE(projectSourceCompatibility, projectClassCompatibility, false)) && execEnv.equals( findMatchingEE(projectSourceCompatibility, projectClassCompatibility, true))) { return; //The project compliance settings matches the BREE } Map<?, ?> defaultComplianceOptions = new HashMap<Object, Object>(); JavaCore.setComplianceOptions(projectComplianceLevel, defaultComplianceOptions); //project compliance does not match the BREE String projectJavaCompatibility = findMatchingEE(projectSourceCompatibility, projectClassCompatibility, true); String message = null; if (projectJavaCompatibility != null) { if (jreCompilationProfileEntry == null) { message = NLS.bind( PDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceMissingEntry, PROPERTY_JRE_COMPILATION_PROFILE, PDECoreMessages.BuildErrorReporter_CompilercomplianceLevel); prepareError(PROPERTY_JRE_COMPILATION_PROFILE, projectJavaCompatibility, message, PDEMarkerFactory.B_JAVA_ADDDITION, fJavaComplianceSeverity, PDEMarkerFactory.CAT_EE); } else { if (!projectJavaCompatibility.equalsIgnoreCase(jreCompilationProfileEntry.getTokens()[0])) { message = NLS.bind( PDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceDifferentToken, PROPERTY_JRE_COMPILATION_PROFILE, PDECoreMessages.BuildErrorReporter_CompilercomplianceLevel); prepareError(PROPERTY_JRE_COMPILATION_PROFILE, projectJavaCompatibility, message, PDEMarkerFactory.B_REPLACE, fJavaComplianceSeverity, PDEMarkerFactory.CAT_EE); } } } else { // Check source level setting if (projectSourceCompatibility.equals(defaultComplianceOptions.get(JavaCore.COMPILER_SOURCE))) { if (javacSourceEntry != null) { message = NLS.bind( PDECoreMessages.BuildErrorReporter_BuildEntryNotRequiredMatchesDefault, PROPERTY_JAVAC_SOURCE, PDECoreMessages.BuildErrorReporter_SourceCompatibility); prepareError(PROPERTY_JAVAC_SOURCE, null, message, PDEMarkerFactory.B_REMOVAL, fJavaComplianceSeverity, PDEMarkerFactory.CAT_EE); } } else { if (javacSourceEntry == null) { message = NLS.bind( PDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceMissingEntry, PROPERTY_JAVAC_SOURCE, PDECoreMessages.BuildErrorReporter_SourceCompatibility); prepareError(PROPERTY_JAVAC_SOURCE, projectSourceCompatibility, message, PDEMarkerFactory.B_JAVA_ADDDITION, fJavaComplianceSeverity, PDEMarkerFactory.CAT_EE); } else { if (!projectSourceCompatibility.equalsIgnoreCase(javacSourceEntry.getTokens()[0])) { message = NLS.bind( PDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceDifferentToken, PROPERTY_JAVAC_SOURCE, PDECoreMessages.BuildErrorReporter_SourceCompatibility); prepareError(PROPERTY_JAVAC_SOURCE, projectSourceCompatibility, message, PDEMarkerFactory.B_REPLACE, fJavaComplianceSeverity, PDEMarkerFactory.CAT_EE); } } } // Check target level setting if (projectClassCompatibility .equals(defaultComplianceOptions.get(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM))) { if (javacTargetEntry != null) { message = NLS.bind( PDECoreMessages.BuildErrorReporter_BuildEntryNotRequiredMatchesDefault, PROPERTY_JAVAC_TARGET, PDECoreMessages.BuildErrorReporter_GeneratedClassFilesCompatibility); prepareError(PROPERTY_JAVAC_TARGET, null, message, PDEMarkerFactory.B_REMOVAL, fJavaComplianceSeverity, PDEMarkerFactory.CAT_EE); } } else { if (javacTargetEntry == null) { message = NLS.bind( PDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceMissingEntry, PROPERTY_JAVAC_TARGET, PDECoreMessages.BuildErrorReporter_GeneratedClassFilesCompatibility); prepareError(PROPERTY_JAVAC_TARGET, projectClassCompatibility, message, PDEMarkerFactory.B_JAVA_ADDDITION, fJavaComplianceSeverity, PDEMarkerFactory.CAT_EE); } else { if (!projectClassCompatibility.equalsIgnoreCase(javacTargetEntry.getTokens()[0])) { message = NLS.bind( PDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceDifferentToken, PROPERTY_JAVAC_TARGET, PDECoreMessages.BuildErrorReporter_GeneratedClassFilesCompatibility); prepareError(PROPERTY_JAVAC_TARGET, projectClassCompatibility, message, PDEMarkerFactory.B_REPLACE, fJavaComplianceSeverity, PDEMarkerFactory.CAT_EE); } } } } boolean warnForJavacWarnings = message != null || javacSourceEntry != null || javacTargetEntry != null || jreCompilationProfileEntry != null; if (warnForJavacWarnings == false) { return; } checkJavaComplianceSettings(projectComplianceLevel, javacWarningsEntries, javacErrorsEntries, libraryNames); } } }