List of usage examples for org.eclipse.jdt.core IJavaProject getOutputLocation
IPath getOutputLocation() throws JavaModelException;
From source file:org.hammurapi.eclipse.plugin.HammurapiBuilder.java
License:Open Source License
/** * @author Daniel Berg jdt-dev@eclipse.org. * @param javaProject/* ww w . ja v a2s . com*/ * @return */ private List getClasspathURLs(IJavaProject javaProject, boolean exportedOnly) throws JavaModelException, MalformedURLException, CoreException { HashSet urls = new HashSet(); IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); boolean defaultOutputAdded = false; for (int i = 0; i < entries.length; i++) { // Source entries are apparently always assumed to be exported - but don't // report themselves as such. if (!exportedOnly || entries[i].isExported() || entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { switch (entries[i].getEntryKind()) { case IClasspathEntry.CPE_SOURCE: { IPath outputLocation = null; if (isEclipse_2_1_Safe()) { outputLocation = entries[i].getOutputLocation(); } if (outputLocation == null) { // // If the output location is null then the project's // default output location is being used. // if (!defaultOutputAdded) { defaultOutputAdded = true; outputLocation = javaProject.getOutputLocation(); } } if (outputLocation != null) { // When the output location is the project itself, the project // can't resolve the file - therefore just get the project's // location. if (outputLocation.segmentCount() == 1) { outputLocation = javaProject.getProject().getLocation(); } else { // Output locations are always workspace relative. Do this mess // to get a fully qualified location. outputLocation = javaProject.getProject().getParent().getFile(outputLocation) .getLocation(); } urls.add(outputLocation.addTrailingSeparator().toFile().toURL()); } break; } case IClasspathEntry.CPE_LIBRARY: { // Jars always come with a nice fully specified path. urls.add(new URL("file:/" + entries[i].getPath().toOSString())); break; } case IClasspathEntry.CPE_PROJECT: { IJavaProject dependentProject = (IJavaProject) (ResourcesPlugin.getWorkspace().getRoot() .getProject(entries[i].getPath().segment(0))).getAdapter(IJavaElement.class); urls.addAll(getClasspathURLs(dependentProject, true)); break; } default: { String msg = "Encountered unexpected classpath entry : " + entries[i].getEntryKind(); HammurapiPlugin.report2LogError(msg, null); Status status = new Status(IStatus.ERROR, "HammurapiPlugin", IStatus.ERROR, msg, null); throw new CoreException(status); } } } } return new ArrayList(urls); }
From source file:org.hibernate.eclipse.console.utils.ClassLoaderHelper.java
License:Open Source License
static public List<URL> getProjectClassPathURLs(IJavaProject project) { List<URL> pathElements = new ArrayList<URL>(); try {/*from w w w . j a v a 2s . c om*/ IClasspathEntry paths[] = project.getResolvedClasspath(true); if (paths != null) { for (int i = 0; i < paths.length; i++) { IClasspathEntry path = paths[i]; if (path.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath simplePath = path.getPath(); URL url = getRawLocationURL(simplePath); pathElements.add(url); } } } IPath location = getProjectLocation(project.getProject()); IPath outputPath = location.append(project.getOutputLocation().removeFirstSegments(1)); pathElements.add(outputPath.toFile().toURI().toURL()); } catch (JavaModelException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } return pathElements; }
From source file:org.hibernate.eclipse.console.utils.OpenMappingUtils.java
License:Open Source License
/** * Trying to find hibernate console config ejb3 mapping file, * which is corresponding to provided element. * /* w w w . j av a 2 s . co m*/ * @param consoleConfig * @param element * @return */ @SuppressWarnings("unchecked") public static IFile searchInEjb3MappingFiles(ConsoleConfiguration consoleConfig, Object element) { IFile file = null; if (consoleConfig == null) { return file; } final ConsoleConfiguration cc2 = consoleConfig; List<String> documentPaths = (List<String>) consoleConfig.execute(new ExecutionContext.Command() { public Object execute() { String persistenceUnitName = cc2.getPreferences().getPersistenceUnitName(); EntityResolver entityResolver = cc2.getConfiguration().getEntityResolver(); IService service = cc2.getHibernateExtension().getHibernateService(); return service.getJPAMappingFilePaths(persistenceUnitName, entityResolver); } }); if (documentPaths == null) { return file; } IJavaProject[] projs = ProjectUtils.findJavaProjects(consoleConfig); ArrayList<IPath> pathsSrc = new ArrayList<IPath>(); ArrayList<IPath> pathsOut = new ArrayList<IPath>(); ArrayList<IPath> pathsFull = new ArrayList<IPath>(); for (int i = 0; i < projs.length; i++) { IJavaProject proj = projs[i]; IPath projPathFull = proj.getResource().getLocation(); IPath projPath = proj.getPath(); IPath projPathOut = null; try { projPathOut = proj.getOutputLocation(); projPathOut = projPathOut.makeRelativeTo(projPath); } catch (JavaModelException e) { // just ignore } IPackageFragmentRoot[] pfrs = new IPackageFragmentRoot[0]; try { pfrs = proj.getAllPackageFragmentRoots(); } catch (JavaModelException e) { // just ignore } for (int j = 0; j < pfrs.length; j++) { // TODO: think about possibility to open resources from jar files if (pfrs[j].isArchive() || pfrs[j].isExternal()) { continue; } final IPath pathSrc = pfrs[j].getPath(); final IPath pathOut = projPathOut; final IPath pathFull = projPathFull; pathsSrc.add(pathSrc); pathsOut.add(pathOut); pathsFull.add(pathFull); } } int scanSize = Math.min(pathsSrc.size(), pathsOut.size()); scanSize = Math.min(pathsFull.size(), scanSize); for (int i = 0; i < scanSize && file == null; i++) { final IPath pathSrc = pathsSrc.get(i); final IPath pathOut = pathsOut.get(i); final IPath pathFull = pathsFull.get(i); Iterator<String> it = documentPaths.iterator(); while (it.hasNext() && file == null) { String docPath = it.next(); IPath path2DocFull = Path.fromOSString(docPath); IPath resPath = path2DocFull.makeRelativeTo(pathFull); if (pathOut != null) { resPath = resPath.makeRelativeTo(pathOut); } resPath = pathSrc.append(resPath); file = ResourcesPlugin.getWorkspace().getRoot().getFile(resPath); if (file == null || !file.exists()) { file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(resPath); } if (file != null && file.exists()) { if (elementInFile(consoleConfig, file, element)) { break; } } file = null; } } return file; }
From source file:org.hyperic.hypclipse.internal.ClasspathComputer.java
License:Open Source License
public static IClasspathEntry[] getClasspath(IProject project, IPluginModelBase model, boolean clear, boolean overrideCompliance) throws CoreException { IJavaProject javaProject = JavaCore.create(project); ArrayList<IClasspathEntry> result = new ArrayList<IClasspathEntry>(); IBuild build = getBuild(project);//from w ww. j av a2 s .co m // // add JRE and set compliance options // String ee = getExecutionEnvironment(model.getBundleDescription()); // result.add(createEntryUsingPreviousEntry(javaProject, ee, PDECore.JRE_CONTAINER_PATH)); // setComplianceOptions(JavaCore.create(project), ExecutionEnvironmentAnalyzer.getCompliance(ee), overrideCompliance); // // // add pde container // result.add(createEntryUsingPreviousEntry(javaProject, ee, PDECore.REQUIRED_PLUGINS_CONTAINER_PATH)); // // // add own libraries/source // addSourceAndLibraries(project, model, build, clear, result); // IClasspathEntry[] entries = result.toArray(new IClasspathEntry[0]); IJavaModelStatus validation = JavaConventions.validateClasspath(javaProject, entries, javaProject.getOutputLocation()); if (!validation.isOK()) { HQDEPlugin.logErrorMessage(validation.getMessage()); throw new CoreException(validation); } return result.toArray(new IClasspathEntry[0]); }
From source file:org.infinitest.eclipse.workspace.JavaProjectTestSupport.java
License:Open Source License
public static void outputLocationExpectation(IJavaProject project, String baseDir) throws JavaModelException { when(project.getOutputLocation()).thenReturn(new Path(baseDir + "/target/classes/")); }
From source file:org.jboss.ide.eclipse.archives.jdt.integration.model.WorkspaceJARArchiveType.java
License:Open Source License
public IArchive createDefaultConfiguration(String projectName, IProgressMonitor monitor) { //IPackageType t = this; IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); Assert.isNotNull(project);//from w w w . ja v a 2s.co m IJavaProject javaProject = JavaCore.create(project); Assert.isNotNull(javaProject); if (monitor == null) monitor = new NullProgressMonitor(); monitor.beginTask(ArchivesCore.bind(ArchivesCoreMessages.CreatingDefaultJarConfig, project.getName()), 2); IPath outputPath; try { outputPath = javaProject.getOutputLocation(); } catch (JavaModelException e) { ArchivesCore.getInstance().getLogger().log(IStatus.WARNING, e.getMessage(), e); return null; } outputPath = outputPath.removeFirstSegments(1); IContainer outputContainer = project.getFolder(outputPath); IArchive jar = new ArchiveImpl(); jar.setDestinationPath(project.getLocation()); jar.setInWorkspace(true); jar.setExploded(false); jar.setName(project.getName() + ".jar"); //$NON-NLS-1$ jar.setArchiveType(this); IArchiveStandardFileSet classes = new ArchiveFileSetImpl(); classes.setIncludesPattern("**/*"); //$NON-NLS-1$ classes.setRawSourcePath(outputContainer.getFullPath().toString()); classes.setInWorkspace(true); try { jar.addChild(classes); } catch (ArchivesModelException ame) { } monitor.worked(1); monitor.done(); return jar; }
From source file:org.jboss.ide.eclipse.freemarker.linetracker.ConsoleLineTracker.java
License:Open Source License
public void populateMatchingFiles(IContainer container, List<IResource> files, String[] fileNameSeq) throws CoreException { IResource[] resources = container.members(); for (int i = 0; i < resources.length; i++) { IResource resource = resources[i]; if (resource instanceof IContainer) { populateMatchingFiles((IContainer) resource, files, fileNameSeq); } else if (resource instanceof IFile) { if (isCorrectFile((IFile) resource, fileNameSeq)) { boolean doAdd = true; try { IJavaProject javaProject = JavaCore.create(resource.getProject()); if (javaProject.getOutputLocation().isPrefixOf(((IFile) resource).getFullPath())) doAdd = false;//www . j av a2s . c o m } catch (JavaModelException e) { Plugin.log(e); } if (doAdd) files.add(resource); } } } }
From source file:org.jboss.mapper.eclipse.internal.util.JavaUtil.java
License:Open Source License
/** * Creates a ClassLoader using the project's build path. * * @param javaProject the Java project./* w w w .jav a 2 s . c o m*/ * @param parentClassLoader the parent class loader, may be null. * * @return a new ClassLoader based on the project's build path. * * @throws Exception if something goes wrong. */ public static ClassLoader getProjectClassLoader(IJavaProject javaProject, ClassLoader parentClassLoader) throws Exception { IProject project = javaProject.getProject(); IWorkspaceRoot root = project.getWorkspace().getRoot(); List<URL> urls = new ArrayList<>(); urls.add( new File(project.getLocation() + "/" + javaProject.getOutputLocation().removeFirstSegments(1) + "/") //$NON-NLS-2$ //$NON-NLS-2$ .toURI().toURL()); for (IClasspathEntry classpathEntry : javaProject.getResolvedClasspath(true)) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IPath projectPath = classpathEntry.getPath(); IProject otherProject = root.getProject(projectPath.segment(0)); IJavaProject otherJavaProject = JavaCore.create(otherProject); urls.add(new File(otherProject.getLocation() + "/" //$NON-NLS-1$ + otherJavaProject.getOutputLocation().removeFirstSegments(1) + "/").toURI().toURL()); //$NON-NLS-1$ } else if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { urls.add(new File(classpathEntry.getPath().toOSString()).toURI().toURL()); } } if (parentClassLoader == null) { return new URLClassLoader(urls.toArray(new URL[urls.size()])); } return new URLClassLoader(urls.toArray(new URL[urls.size()]), parentClassLoader); }
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(); }// w w w . j a v a 2 s . com addPath(urls, path); IPath sourcePath = entry.getPath(); if (sourcePath != null) { addPath(urls, sourcePath); } }
From source file:org.jboss.tools.arquillian.core.internal.compiler.ArquillianCompilationParticipant.java
License:Open Source License
protected boolean isExcludedFromProject(IPath childPath, IJavaProject project) throws JavaModelException { // answer whether the folder should be ignored when walking the project as a source folder if (childPath.segmentCount() > 2) return false; // is a subfolder of a package for (int j = 0, k = this.sourceLocations.length; j < k; j++) { if (childPath.equals(this.sourceLocations[j].binaryFolder.getFullPath())) return true; if (childPath.equals(this.sourceLocations[j].sourceFolder.getFullPath())) return true; }/*from ww w . ja v a 2s .com*/ // skip default output folder which may not be used by any source folder return childPath.equals(project.getOutputLocation()); }