Java Code Examples for org.eclipse.jdt.core.IClasspathEntry#getOutputLocation()
The following examples show how to use
org.eclipse.jdt.core.IClasspathEntry#getOutputLocation() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestabilityLauncher.java From testability-explorer with Apache License 2.0 | 6 votes |
public String[] getClassPaths(IJavaProject javaProject, String projectLocation) throws JavaModelException { IClasspathEntry[] classPathEntries = javaProject.getRawClasspath(); String[] classPaths = new String[classPathEntries.length + 1]; for (int i = 0; i < classPathEntries.length; i++) { IClasspathEntry classPathEntry = classPathEntries[i]; String classPathString = null; IPath outputPath = classPathEntry.getOutputLocation(); if (outputPath != null) { classPathString = projectLocation + outputPath.toOSString(); } else { IPath classPath = classPathEntry.getPath(); classPathString = classPath.toOSString(); if (!classPathString.startsWith(System.getProperty("file.separator"))) { classPathString = System.getProperty("file.separator") + classPathString; } classPathString = projectLocation + classPathString; } classPathString = classPathString.replace("\\", "/"); classPaths[i] = classPathString; } String defaultOutputPath = javaProject.getOutputLocation().toOSString(); defaultOutputPath = defaultOutputPath.replace("\\", "/"); classPaths[classPathEntries.length] = projectLocation + defaultOutputPath; return classPaths; }
Example 2
Source File: SuperDevModeSrcArgumentProcessor.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Get the class path entries that are the source. * * @param javaProject the java project. * @param entry classpath entry value. * @return the path. */ private String getPathIfDir(IJavaProject javaProject, IClasspathEntry entry) { IPath p = entry.getPath(); String projectName = javaProject.getProject().getName(); String path = null; // src directories don't have an output // cpe source are src,test directories if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && (entry.getOutputLocation() == null || (entry.getOutputLocation() != null && !entry .getOutputLocation().lastSegment().toString().equals("test-classes")))) { String dir = p.toString(); // if the base segment has the project name, // lets remove that so its relative to project if (dir.contains(projectName)) { IPath relative = p.removeFirstSegments(1); path = relative.toString(); } } return path; }
Example 3
Source File: FatJarPackageWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static boolean isRootAt(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) { JavaPlugin.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; }
Example 4
Source File: FixedFatJarExportPage.java From sarl with Apache License 2.0 | 6 votes |
private static boolean isRootAt(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) { JavaPlugin.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; }
Example 5
Source File: CrySLBuilder.java From CogniCrypt with Eclipse Public License 2.0 | 5 votes |
@Override protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor) throws CoreException { try { CrySLParser csmr = new CrySLParser(getProject()); final IProject curProject = getProject(); List<IPath> resourcesPaths = new ArrayList<IPath>(); List<IPath> outputPaths = new ArrayList<IPath>(); IJavaProject projectAsJavaProject = JavaCore.create(curProject); for (final IClasspathEntry entry : projectAsJavaProject.getResolvedClasspath(true)) { if (entry.getContentKind() == IPackageFragmentRoot.K_SOURCE) { IPath res = entry.getPath(); if (!projectAsJavaProject.getPath().equals(res)) { resourcesPaths.add(res); IPath outputLocation = entry.getOutputLocation(); outputPaths.add(outputLocation != null ? outputLocation : projectAsJavaProject.getOutputLocation()); } } } for (int i = 0; i < resourcesPaths.size(); i++) { CrySLParserUtils.storeRulesToFile(csmr.readRulesWithin(resourcesPaths.get(i).toOSString()), ResourcesPlugin.getWorkspace().getRoot().findMember(outputPaths.get(i)).getLocation().toOSString()); } } catch (IOException e) { Activator.getDefault().logError(e, "Build of CrySL rules failed."); } return null; }
Example 6
Source File: CrySLBuilder.java From CogniCrypt with Eclipse Public License 2.0 | 5 votes |
protected void clean(IProgressMonitor monitor) throws CoreException { IProject project = getProject(); for (final IClasspathEntry entry : JavaCore.create(project).getResolvedClasspath(true)) { if (entry.getContentKind() == IPackageFragmentRoot.K_SOURCE && !(entry.getPath().toPortableString().lastIndexOf(Constants.innerFileSeparator) < 1)) { IPath outputLocation = entry.getOutputLocation(); if (outputLocation != null) { Arrays.asList(new File(project.getLocation().toOSString() + Constants.outerFileSeparator + outputLocation.removeFirstSegments(1).toOSString()).listFiles()) .parallelStream().filter(e -> e.exists()).forEach(e -> e.delete()); } } } }
Example 7
Source File: CreateAppEngineWtpProject.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
private void fixTestSourceDirectorySettings(IProject newProject, IProgressMonitor monitor) throws CoreException { // 1. Fix the output folder of "src/test/java". IPath testSourcePath = newProject.getFolder("src/test/java").getFullPath(); IJavaProject javaProject = JavaCore.create(newProject); IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && entry.getPath().equals(testSourcePath) && entry.getOutputLocation() == null) { // Default output location? IPath oldOutputPath = javaProject.getOutputLocation(); IPath newOutputPath = oldOutputPath.removeLastSegments(1).append("test-classes"); entries[i] = JavaCore.newSourceEntry(testSourcePath, ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, newOutputPath); javaProject.setRawClasspath(entries, monitor); break; } } // 2. Remove "src/test/java" from the Web Deployment Assembly sources. deployAssemblyEntryRemoveJob = new DeployAssemblyEntryRemoveJob(newProject, new Path("src/test/java")); deployAssemblyEntryRemoveJob.setSystem(true); deployAssemblyEntryRemoveJob.schedule(); }
Example 8
Source File: JdtHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public boolean isFromOutputPath(IResource resource) { IProject project = resource.getProject(); IJavaProject javaProject = JavaCore.create(project); if (javaProject != null && javaProject.exists()) { try { IPath defaultOutputLocation = javaProject.getOutputLocation(); IPath resourcePath = resource.getFullPath(); if (defaultOutputLocation != null && !defaultOutputLocation.isEmpty() && defaultOutputLocation.isPrefixOf(resourcePath)) { return true; } IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); for(IClasspathEntry classpathEntry: classpathEntries) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath specializedOutputLocation = classpathEntry.getOutputLocation(); if (specializedOutputLocation != null) { if (!specializedOutputLocation.equals(classpathEntry.getPath()) && specializedOutputLocation.isPrefixOf(resourcePath)) { return true; } } } } } catch(CoreException e) { if (log.isDebugEnabled()) log.debug("Error in isJavaTargetFolder():" + e.getMessage(), e); } } return false; }
Example 9
Source File: ResourceUtils.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
public static IPath getOutputLocation(IClasspathEntry classpathEntry, IPath defaultOutputLocation) { IPath outputLocation = classpathEntry.getOutputLocation(); if (outputLocation != null) { // this location is workspace relative and starts with project dir outputLocation = relativeToAbsolute(outputLocation); } else { outputLocation = defaultOutputLocation; } return outputLocation; }
Example 10
Source File: JarFileExportOperation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private IContainer[] getOutputContainers(IJavaProject javaProject) throws CoreException { Set<IPath> outputPaths= new HashSet<IPath>(); boolean includeDefaultOutputPath= false; IPackageFragmentRoot[] roots= javaProject.getPackageFragmentRoots(); for (int i= 0; i < roots.length; i++) { if (roots[i] != null) { IClasspathEntry cpEntry= roots[i].getRawClasspathEntry(); if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath location= cpEntry.getOutputLocation(); if (location != null) outputPaths.add(location); else includeDefaultOutputPath= true; } } } if (includeDefaultOutputPath) { // Use default output location outputPaths.add(javaProject.getOutputLocation()); } // Convert paths to containers Set<IContainer> outputContainers= new HashSet<IContainer>(outputPaths.size()); Iterator<IPath> iter= outputPaths.iterator(); while (iter.hasNext()) { IPath path= iter.next(); if (javaProject.getProject().getFullPath().equals(path)) outputContainers.add(javaProject.getProject()); else { IFolder outputFolder= createFolderHandle(path); if (outputFolder == null || !outputFolder.isAccessible()) { String msg= JarPackagerMessages.JarFileExportOperation_outputContainerNotAccessible; addToStatus(new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, msg, null))); } else outputContainers.add(outputFolder); } } return outputContainers.toArray(new IContainer[outputContainers.size()]); }
Example 11
Source File: JdtBasedProcessorProvider.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
protected void collectClasspathURLs(final IJavaProject projectToUse, final LinkedHashSet<URL> result, final boolean includeOutputFolder, final Set<IJavaProject> visited) throws JavaModelException { try { if (((!projectToUse.getProject().isAccessible()) || (!visited.add(projectToUse)))) { return; } if (includeOutputFolder) { IPath path = projectToUse.getOutputLocation().addTrailingSeparator(); String _string = URI.createPlatformResourceURI(path.toString(), true).toString(); URL url = new URL(_string); result.add(url); } final IClasspathEntry[] resolvedClasspath = projectToUse.getResolvedClasspath(true); for (final IClasspathEntry entry : resolvedClasspath) { { URL url_1 = null; int _entryKind = entry.getEntryKind(); switch (_entryKind) { case IClasspathEntry.CPE_SOURCE: if (includeOutputFolder) { final IPath path_1 = entry.getOutputLocation(); if ((path_1 != null)) { String _string_1 = URI.createPlatformResourceURI(path_1.addTrailingSeparator().toString(), true).toString(); URL _uRL = new URL(_string_1); url_1 = _uRL; } } break; case IClasspathEntry.CPE_PROJECT: IPath path_2 = entry.getPath(); final IResource project = this.getWorkspaceRoot(projectToUse).findMember(path_2); final IJavaProject referencedProject = JavaCore.create(project.getProject()); this.collectClasspathURLs(referencedProject, result, true, visited); break; case IClasspathEntry.CPE_LIBRARY: IPath path_3 = entry.getPath(); final IResource library = this.getWorkspaceRoot(projectToUse).findMember(path_3); URL _xifexpression = null; if ((library != null)) { URL _xblockexpression = null; { final java.net.URI locationUri = library.getLocationURI(); URL _xifexpression_1 = null; String _scheme = null; if (locationUri!=null) { _scheme=locationUri.getScheme(); } boolean _equals = Objects.equal(EFS.SCHEME_FILE, _scheme); if (_equals) { java.net.URI _rawLocationURI = library.getRawLocationURI(); URL _uRL_1 = null; if (_rawLocationURI!=null) { _uRL_1=_rawLocationURI.toURL(); } _xifexpression_1 = _uRL_1; } else { _xifexpression_1 = null; } _xblockexpression = _xifexpression_1; } _xifexpression = _xblockexpression; } else { _xifexpression = path_3.toFile().toURI().toURL(); } url_1 = _xifexpression; break; default: { IPath path_4 = entry.getPath(); url_1 = path_4.toFile().toURI().toURL(); } break; } if ((url_1 != null)) { result.add(url_1); } } } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 12
Source File: ClasspathChange.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private int classpathContains(IClasspathEntry[] list, IClasspathEntry entry) { IPath[] exclusionPatterns = entry.getExclusionPatterns(); IPath[] inclusionPatterns = entry.getInclusionPatterns(); int listLen = list == null ? 0 : list.length; nextEntry: for (int i = 0; i < listLen; i++) { IClasspathEntry other = list[i]; if (other.getContentKind() == entry.getContentKind() && other.getEntryKind() == entry.getEntryKind() && other.isExported() == entry.isExported() && other.getPath().equals(entry.getPath())) { // check custom outputs IPath entryOutput = entry.getOutputLocation(); IPath otherOutput = other.getOutputLocation(); if (entryOutput == null) { if (otherOutput != null) continue; } else { if (!entryOutput.equals(otherOutput)) continue; } // check inclusion patterns IPath[] otherIncludes = other.getInclusionPatterns(); if (inclusionPatterns != otherIncludes) { if (inclusionPatterns == null) continue; int includeLength = inclusionPatterns.length; if (otherIncludes == null || otherIncludes.length != includeLength) continue; for (int j = 0; j < includeLength; j++) { // compare toStrings instead of IPaths // since IPath.equals is specified to ignore trailing separators if (!inclusionPatterns[j].toString().equals(otherIncludes[j].toString())) continue nextEntry; } } // check exclusion patterns IPath[] otherExcludes = other.getExclusionPatterns(); if (exclusionPatterns != otherExcludes) { if (exclusionPatterns == null) continue; int excludeLength = exclusionPatterns.length; if (otherExcludes == null || otherExcludes.length != excludeLength) continue; for (int j = 0; j < excludeLength; j++) { // compare toStrings instead of IPaths // since IPath.equals is specified to ignore trailing separators if (!exclusionPatterns[j].toString().equals(otherExcludes[j].toString())) continue nextEntry; } } return i; } } return -1; }