List of usage examples for org.eclipse.jdt.core IClasspathEntry getOutputLocation
IPath getOutputLocation();
.class
files generated for this source entry (entry kind #CPE_SOURCE ). From source file:org.jboss.tools.arquillian.core.internal.classpath.ArquillianClassLoader.java
License:Open Source License
private static void addSource(IJavaProject jProject, Set<URL> urls, IClasspathEntry entry) throws JavaModelException, MalformedURLException { IPath path = entry.getOutputLocation(); if (path == null) { path = jProject.getOutputLocation(); }//from w w w .j av a2 s. c o m addPath(urls, path); IPath sourcePath = entry.getPath(); if (sourcePath != null) { addPath(urls, sourcePath); } }
From source file:org.jboss.tools.arquillian.core.internal.compiler.ArquillianNameEnvironment.java
License:Open Source License
private void computeClasspathLocations(IWorkspaceRoot root, JavaProject javaProject, SimpleLookupTable binaryLocationsPerProject) throws CoreException { /* Update cycle marker */ IMarker cycleMarker = javaProject.getCycleMarker(); if (cycleMarker != null) { int severity = JavaCore.ERROR.equals(javaProject.getOption(JavaCore.CORE_CIRCULAR_CLASSPATH, true)) ? IMarker.SEVERITY_ERROR : IMarker.SEVERITY_WARNING; if (severity != cycleMarker.getAttribute(IMarker.SEVERITY, severity)) cycleMarker.setAttribute(IMarker.SEVERITY, severity); }//from w w w . j a v a 2 s. c o m IClasspathEntry[] classpathEntries = javaProject.getExpandedClasspath(); ArrayList sLocations = new ArrayList(classpathEntries.length); ArrayList bLocations = new ArrayList(classpathEntries.length); nextEntry: for (int i = 0, l = classpathEntries.length; i < l; i++) { ClasspathEntry entry = (ClasspathEntry) classpathEntries[i]; IPath path = entry.getPath(); Object target = JavaModel.getTarget(path, true); if (target == null) continue nextEntry; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: if (!(target instanceof IContainer)) continue nextEntry; IPath outputPath = entry.getOutputLocation() != null ? entry.getOutputLocation() : javaProject.getOutputLocation(); IContainer outputFolder; if (outputPath.segmentCount() == 1) { outputFolder = javaProject.getProject(); } else { outputFolder = root.getFolder(outputPath); if (!outputFolder.exists()) createOutputFolder(outputFolder); } sLocations.add(ClasspathLocation.forSourceFolder((IContainer) target, outputFolder, entry.fullInclusionPatternChars(), entry.fullExclusionPatternChars())); continue nextEntry; case IClasspathEntry.CPE_PROJECT: if (!(target instanceof IProject)) continue nextEntry; IProject prereqProject = (IProject) target; if (!JavaProject.hasJavaNature(prereqProject)) continue nextEntry; // if project doesn't have java nature or is not accessible JavaProject prereqJavaProject = (JavaProject) JavaCore.create(prereqProject); IClasspathEntry[] prereqClasspathEntries = prereqJavaProject.getRawClasspath(); ArrayList seen = new ArrayList(); nextPrereqEntry: for (int j = 0, m = prereqClasspathEntries.length; j < m; j++) { IClasspathEntry prereqEntry = prereqClasspathEntries[j]; if (prereqEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { Object prereqTarget = JavaModel.getTarget(prereqEntry.getPath(), true); if (!(prereqTarget instanceof IContainer)) continue nextPrereqEntry; IPath prereqOutputPath = prereqEntry.getOutputLocation() != null ? prereqEntry.getOutputLocation() : prereqJavaProject.getOutputLocation(); IContainer binaryFolder = prereqOutputPath.segmentCount() == 1 ? (IContainer) prereqProject : (IContainer) root.getFolder(prereqOutputPath); if (binaryFolder.exists() && !seen.contains(binaryFolder)) { seen.add(binaryFolder); ClasspathLocation bLocation = ClasspathLocation.forBinaryFolder(binaryFolder, true, entry.getAccessRuleSet()); bLocations.add(bLocation); if (binaryLocationsPerProject != null) { // normal builder mode ClasspathLocation[] existingLocations = (ClasspathLocation[]) binaryLocationsPerProject .get(prereqProject); if (existingLocations == null) { existingLocations = new ClasspathLocation[] { bLocation }; } else { int size = existingLocations.length; System.arraycopy(existingLocations, 0, existingLocations = new ClasspathLocation[size + 1], 0, size); existingLocations[size] = bLocation; } binaryLocationsPerProject.put(prereqProject, existingLocations); } } } } continue nextEntry; case IClasspathEntry.CPE_LIBRARY: if (target instanceof IResource) { IResource resource = (IResource) target; ClasspathLocation bLocation = null; if (resource instanceof IFile) { AccessRuleSet accessRuleSet = (JavaCore.IGNORE .equals(javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true)) && JavaCore.IGNORE.equals( javaProject.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true))) ? null : entry.getAccessRuleSet(); bLocation = ClasspathLocation.forLibrary((IFile) resource, accessRuleSet); } else if (resource instanceof IContainer) { AccessRuleSet accessRuleSet = (JavaCore.IGNORE .equals(javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true)) && JavaCore.IGNORE.equals( javaProject.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true))) ? null : entry.getAccessRuleSet(); bLocation = ClasspathLocation.forBinaryFolder((IContainer) target, false, accessRuleSet); // is library folder not output folder } bLocations.add(bLocation); if (binaryLocationsPerProject != null) { // normal builder mode IProject p = resource.getProject(); // can be the project being built ClasspathLocation[] existingLocations = (ClasspathLocation[]) binaryLocationsPerProject .get(p); if (existingLocations == null) { existingLocations = new ClasspathLocation[] { bLocation }; } else { int size = existingLocations.length; System.arraycopy(existingLocations, 0, existingLocations = new ClasspathLocation[size + 1], 0, size); existingLocations[size] = bLocation; } binaryLocationsPerProject.put(p, existingLocations); } } else if (target instanceof File) { AccessRuleSet accessRuleSet = (JavaCore.IGNORE .equals(javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true)) && JavaCore.IGNORE.equals( javaProject.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true))) ? null : entry.getAccessRuleSet(); bLocations.add(ClasspathLocation.forLibrary(path.toString(), accessRuleSet)); } continue nextEntry; } } // now split the classpath locations... place the output folders ahead of the other .class file folders & jars ArrayList outputFolders = new ArrayList(1); this.sourceLocations = new ClasspathMultiDirectory[sLocations.size()]; if (!sLocations.isEmpty()) { sLocations.toArray(this.sourceLocations); // collect the output folders, skipping duplicates next: for (int i = 0, l = this.sourceLocations.length; i < l; i++) { ClasspathMultiDirectory md = this.sourceLocations[i]; IPath outputPath = md.binaryFolder.getFullPath(); for (int j = 0; j < i; j++) { // compare against previously walked source folders if (outputPath.equals(this.sourceLocations[j].binaryFolder.getFullPath())) { md.hasIndependentOutputFolder = this.sourceLocations[j].hasIndependentOutputFolder; continue next; } } outputFolders.add(md); // also tag each source folder whose output folder is an independent folder & is not also a source folder for (int j = 0, m = this.sourceLocations.length; j < m; j++) if (outputPath.equals(this.sourceLocations[j].sourceFolder.getFullPath())) continue next; md.hasIndependentOutputFolder = true; } } // combine the output folders with the binary folders & jars... place the output folders before other .class file folders & jars // this.binaryLocations = new ClasspathLocation[outputFolders.size() + bLocations.size()]; // int index = 0; // for (int i = 0, l = outputFolders.size(); i < l; i++) // this.binaryLocations[index++] = (ClasspathLocation) outputFolders.get(i); // for (int i = 0, l = bLocations.size(); i < l; i++) // this.binaryLocations[index++] = (ClasspathLocation) bLocations.get(i); this.binaryLocations = new ClasspathLocation[bLocations.size()]; int index = 0; // for (int i = 0, l = outputFolders.size(); i < l; i++) // this.binaryLocations[index++] = (ClasspathLocation) outputFolders.get(i); for (int i = 0, l = bLocations.size(); i < l; i++) this.binaryLocations[index++] = (ClasspathLocation) bLocations.get(i); this.baseBinaryLocations = new ClasspathLocation[binaryLocations.length]; System.arraycopy(binaryLocations, 0, baseBinaryLocations, 0, binaryLocations.length); this.baseSourceLocations = new ClasspathMultiDirectory[sourceLocations.length]; System.arraycopy(sourceLocations, 0, baseSourceLocations, 0, sourceLocations.length); }
From source file:org.jboss.tools.common.jdt.core.internal.buildpath.MavenLibraryMaterializationPostProcessor.java
License:Open Source License
private void removeExclusionPatterns(IJavaProject javaProject, IProgressMonitor monitor) throws JavaModelException { IClasspathEntry[] entries = javaProject.getRawClasspath(); ArrayList<IClasspathEntry> newEntriesList = new ArrayList<IClasspathEntry>(entries.length); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath[] newExclusionPatterns = getExclusionPatterns(entry.getExclusionPatterns()); IClasspathEntry newEntry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(), newExclusionPatterns, entry.getOutputLocation(), entry.getExtraAttributes()); newEntriesList.add(newEntry); } else {/* w w w. ja v a 2 s. c om*/ newEntriesList.add(entry); } } IClasspathEntry[] newEntries = new IClasspathEntry[newEntriesList.size()]; newEntriesList.toArray(newEntries); javaProject.setRawClasspath(newEntries, monitor); }
From source file:org.jboss.tools.m2e.extras.AptBuildParticipant.java
License:Open Source License
private void processClasspathElement(IClasspathEntry ice, IProject containingProject, Xpp3Dom newClasspathElementsDom) throws JavaModelException { IPath path;/* www. ja va2 s. com*/ switch (ice.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: { path = ice.getOutputLocation(); if (path == null) { path = JavaCore.create(containingProject).getOutputLocation(); } break; } case IClasspathEntry.CPE_PROJECT: { IProject referenceProject = containingProject.getWorkspace().getRoot() .getProject(ice.getPath().toPortableString()); for (IClasspathEntry resolvedIce : JavaCore.create(referenceProject).getRawClasspath()) { // we're only concerned with exported libraries and the project // output if (resolvedIce.isExported() || resolvedIce.getEntryKind() == IClasspathEntry.CPE_SOURCE) { try { processClasspathElement(resolvedIce, referenceProject, newClasspathElementsDom); } catch (JavaModelException e) { } } } return; } case IClasspathEntry.CPE_CONTAINER: { // we're only concerned with the PDE container if (!PDE_CLASSPATH_CONTAINER.equals(ice.getPath())) { return; } IClasspathContainer icc = JavaCore.getClasspathContainer(ice.getPath(), JavaCore.create(containingProject)); if (icc == null) { return; } for (IClasspathEntry resolvedIce : icc.getClasspathEntries()) { try { processClasspathElement(resolvedIce, containingProject, newClasspathElementsDom); } catch (JavaModelException e) { } } return; } case IClasspathEntry.CPE_LIBRARY: path = ice.getPath(); break; case IClasspathEntry.CPE_VARIABLE: ice = JavaCore.getResolvedClasspathEntry(ice); if (ice == null) { return; } path = ice.getPath(); break; default: return; } // make sure we have an absolute file system path Xpp3Dom child = new Xpp3Dom("#"); IResource resource = containingProject.getWorkspace().getRoot().findMember(path); if (resource == null) { child.setValue(ice.getPath().toPortableString()); } else { child.setValue(resource.getLocation().toPortableString()); } newClasspathElementsDom.addChild(child); }
From source file:org.jbpm.eclipse.util.ProjectClassLoader.java
License:Apache License
public static List<URL> getProjectClassPathURLs(IJavaProject project, List<String> alreadyLoadedProjects) { List<URL> pathElements = new ArrayList<URL>(); try {/*www.j a v a 2 s .c om*/ IClasspathEntry[] paths = project.getResolvedClasspath(true); Set<IPath> outputPaths = new HashSet<IPath>(); if (paths != null) { for (int i = 0; i < paths.length; i++) { IClasspathEntry path = paths[i]; if (path.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { URL url = getRawLocationURL(path.getPath()); pathElements.add(url); } else if (path.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath output = path.getOutputLocation(); if (path.getOutputLocation() != null) { outputPaths.add(output); } } } } IPath location = getProjectLocation(project.getProject()); IPath outputPath = location.append(project.getOutputLocation().removeFirstSegments(1)); pathElements.add(0, outputPath.toFile().toURI().toURL()); for (IPath path : outputPaths) { outputPath = location.append(path.removeFirstSegments(1)); pathElements.add(0, outputPath.toFile().toURI().toURL()); } // also add classpath of required projects for (String projectName : project.getRequiredProjectNames()) { if (!alreadyLoadedProjects.contains(projectName)) { alreadyLoadedProjects.add(projectName); IProject reqProject = project.getProject().getWorkspace().getRoot().getProject(projectName); if (reqProject != null) { IJavaProject reqJavaProject = JavaCore.create(reqProject); pathElements.addAll(getProjectClassPathURLs(reqJavaProject, alreadyLoadedProjects)); } } } } catch (JavaModelException e) { JBPMEclipsePlugin.log(e); } catch (MalformedURLException e) { JBPMEclipsePlugin.log(e); } catch (Throwable t) { JBPMEclipsePlugin.log(t); } return pathElements; }
From source file:org.libreoffice.ide.eclipse.java.JavaProjectHandler.java
License:LGPL
/** * {@inheritDoc}//from ww w . j av a2 s .c o m */ @Override public IFolder[] getBinFolders(IUnoidlProject pUnoidlProject) { ArrayList<IFolder> folders = new ArrayList<IFolder>(); IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot(); IProject prj = workspace.getProject(pUnoidlProject.getName()); IJavaProject javaPrj = JavaCore.create(prj); try { folders.add(workspace.getFolder(javaPrj.getOutputLocation())); IClasspathEntry[] entries = javaPrj.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && entry.getOutputLocation() != null) { folders.add(workspace.getFolder(entry.getOutputLocation())); } } } catch (JavaModelException e) { } return folders.toArray(new IFolder[folders.size()]); }
From source file:org.limy.eclipse.qalab.common.LimyQalabUtils.java
License:Open Source License
/** * v?WFNgS?o?pX results ?B/*from w w w. ja v a 2 s . c om*/ * @param project * @param results i[? */ public static void appendProjectBinPaths(IJavaProject project, Collection<IPath> results) { results.add(project.readOutputLocation()); // v?WFNg\?[XfBNg?[v for (IClasspathEntry entry : project.readRawClasspath()) { IPath location = entry.getOutputLocation(); if (location != null) { // \?[XfBNgL?ofBNgw?? results.add(location); } } }
From source file:org.mule.munit.plugin.MunitLaunchConfigurationDelegate.java
License:Open Source License
public synchronized void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { if (monitor == null) { monitor = new NullProgressMonitor(); }/* w w w . j a v a 2 s.com*/ monitor.beginTask(MessageFormat.format("{0}...", new String[] { configuration.getName() }), 5); //$NON-NLS-1$ // check for cancellation if (monitor.isCanceled()) { return; } try { try { preLaunchCheck(configuration, launch, new SubProgressMonitor(monitor, 2)); } catch (CoreException e) { if (e.getStatus().getSeverity() == IStatus.CANCEL) { monitor.setCanceled(true); return; } throw e; } // check for cancellation if (monitor.isCanceled()) { return; } IProject project = getJavaProject(configuration).getProject(); project.build(IncrementalProjectBuilder.FULL_BUILD, monitor); Map<String, IFolder> sourceFolders = new HashMap<String, IFolder>(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IJavaProject javaProject = getJavaProject(configuration); IPath munitOutputFolder = null; IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath path = entry.getPath(); IFolder sourceFolder = root.getFolder(path); if (sourceFolder.getLocation().toString().contains("test/munit")) { munitOutputFolder = entry.getOutputLocation(); } } } MunitEclipseUpdater.launch(); String mainTypeName = verifyMainTypeName(configuration); IVMRunner runner = getVMRunner(configuration, mode); File workingDir = verifyWorkingDirectory(configuration); String workingDirName = null; if (workingDir != null) { workingDirName = workingDir.getAbsolutePath(); } String[] envp = getEnvironment(configuration); ArrayList vmArguments = new ArrayList(); ArrayList programArguments = new ArrayList(); programArguments.add("-resource"); programArguments.add(configuration.getAttribute("resource", "")); programArguments.add("-path"); programArguments.add(configuration.getAttribute("Mpath", "")); programArguments.add("-port"); programArguments.add(String.valueOf(MunitEclipseUpdater.getInstance().getPort())); // VM-specific attributes Map vmAttributesMap = getVMSpecificAttributesMap(configuration); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath path = entry.getPath(); IFolder sourceFolder = root.getFolder(path); if (!sourceFolder.getLocation().toString().contains("test/munit")) { try { IFolder folder = root.getFolder(entry.getOutputLocation()); for (IResource resource : folder.members()) { try { resource.copy(munitOutputFolder, IFolder.SHALLOW, monitor); } catch (Throwable e) { } } } catch (Throwable y) { } } } } String[] classpath = getClasspath(configuration); // ClasspathgetC List<String> classPathAsList = new ArrayList<String>(Arrays.asList(classpath)); try { URL[] urlClasspath = new ClasspathProvider().getClassPath(getJavaProject(configuration)); for (URL url : urlClasspath) { classPathAsList.add(url.getFile()); } } catch (MalformedURLException e) { e.printStackTrace(); } // Create VM config VMRunnerConfiguration runConfig = new VMRunnerConfiguration( "org.mule.munit.runner.remote.MunitRemoteRunner", classPathAsList.toArray(new String[] {})); runConfig.setVMArguments((String[]) vmArguments.toArray(new String[vmArguments.size()])); runConfig.setProgramArguments((String[]) programArguments.toArray(new String[programArguments.size()])); runConfig.setEnvironment(envp); runConfig.setWorkingDirectory(workingDirName); runConfig.setVMSpecificAttributesMap(vmAttributesMap); // Bootpath runConfig.setBootClassPath(getBootpath(configuration)); // check for cancellation if (monitor.isCanceled()) { return; } // done the verification phase monitor.worked(1); setDefaultSourceLocator(launch, configuration); monitor.worked(1); runner.run(runConfig, launch, monitor); if (monitor.isCanceled()) { return; } } finally { fTestElements = null; monitor.done(); } }
From source file:org.mybatis.generator.eclipse.ui.actions.RunGeneratorThread.java
License:Apache License
private void setClassLoader() { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IJavaProject javaProject = getJavaProject(); try {/*from w ww.j a v a2 s .co m*/ if (javaProject != null) { List<URL> entries = new ArrayList<URL>(); IPath path = javaProject.getOutputLocation(); IResource iResource = root.findMember(path); path = iResource.getLocation(); path = path.addTrailingSeparator(); entries.add(path.toFile().toURI().toURL()); IClasspathEntry[] cpEntries = javaProject.getRawClasspath(); for (IClasspathEntry cpEntry : cpEntries) { switch (cpEntry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: path = cpEntry.getOutputLocation(); if (path != null) { iResource = root.findMember(path); path = iResource.getLocation(); path = path.addTrailingSeparator(); entries.add(path.toFile().toURI().toURL()); } break; case IClasspathEntry.CPE_LIBRARY: iResource = root.findMember(cpEntry.getPath()); if (iResource == null) { // resource is not in workspace, must be an external JAR path = cpEntry.getPath(); } else { path = iResource.getLocation(); } entries.add(path.toFile().toURI().toURL()); break; } } ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); URL[] entryArray = new URL[entries.size()]; entries.toArray(entryArray); ClassLoader newCl = new URLClassLoader(entryArray, oldCl); Thread.currentThread().setContextClassLoader(newCl); oldClassLoader = oldCl; } } catch (Exception e) { // ignore - something too complex is wrong ; } }
From source file:org.nuxeo.ide.sdk.java.ClasspathEditor.java
License:Open Source License
/** * Extends classpath target project with src folder * * @param name//from w w w. j ava 2 s. c o m * @throws JavaModelException */ public void extendClasspath(String name) throws JavaModelException { IProject project = java.getProject(); IFolder folder = project.getFolder("src/main/" + name); IPackageFragmentRoot root = java.getPackageFragmentRoot(folder); if (root.exists()) { IClasspathEntry entry = root.getRawClasspathEntry(); if (entry.getOutputLocation() != null) { return; } entries.remove(entry); } // extend project class path IFolder binFolder = project.getFolder("bin/" + name); IClasspathEntry newEntry = JavaCore.newSourceEntry(folder.getFullPath(), new IPath[0], new IPath[0], binFolder.getFullPath()); entries.add(newEntry); dirty = true; }