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.sapphire.java.jdt.JdtUtil.java
License:Open Source License
/** * Finds the Java source folders of the specified project. If the project is not * a Java project, an empty list is returned. * /*from w w w . j a v a2 s.c o m*/ * @param project the project for which source folders are requested * @return the source folders of the specified project * @throws IllegalArgumentException if project is null */ public static List<IContainer> findSourceFolders(final IJavaProject project) { if (project == null) { throw new IllegalArgumentException(); } final ListFactory<IContainer> sourceFolders = ListFactory.start(); final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); try { for (IClasspathEntry cpe : project.getRawClasspath()) { if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { final IResource sourceFolderResource = root.findMember(cpe.getPath()); if (sourceFolderResource instanceof IContainer) { sourceFolders.add((IContainer) sourceFolderResource); } } } } catch (JavaModelException e) { // Ignore the exception and return an empty list. return ListFactory.empty(); } return sourceFolders.result(); }
From source file:org.eclipse.sirius.editor.utils.WorkspaceClassLoading.java
License:Open Source License
private void computeURLs(IProject project, List<URL> uRLs) { final IJavaProject javaProject = JavaCore.create(project); try {//from w w w . j a va 2s . c o m for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { final IPath output = entry.getOutputLocation(); if (output != null) { IFile reference = ResourcesPlugin.getWorkspace().getRoot().getFile(output); if (reference.exists()) { URL url; try { url = reference.getLocation().toFile().toURI().toURL(); uRLs.add(url); } catch (MalformedURLException e) { /* * We don't know how to handle this class path * entry. */ } } } } } /* * Add the default output location to the classpath anyway since * source folders are not required to have their own */ final IPath output = javaProject.getOutputLocation(); if (output != null) { IFolder reference = ResourcesPlugin.getWorkspace().getRoot().getFolder(output); if (reference.exists() && reference.getLocation() != null) { URL url; File file = reference.getLocation().toFile(); try { if (file != null && file.exists()) { url = file.toURI().toURL(); uRLs.add(url); } } catch (MalformedURLException e) { /* * the given path does not map to a file which can * actually be mapped to an url, ignore it. */ } } } } catch (JavaModelException e) { } }
From source file:org.eclipse.swt.tools.builders.Check64CompilationParticipant.java
License:Open Source License
void build(IJavaProject project, String root) throws CoreException { PrintWriter writer = null;/*from w ww .j a va 2 s .c o m*/ try { StringBuffer sourcePath = new StringBuffer(), cp = new StringBuffer(); IClasspathEntry[] entries = project.getResolvedClasspath(true); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; String path = entry.getPath().toPortableString(); if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (path.startsWith(pluginDir)) { if (sourcePath.length() > 0) sourcePath.append(File.pathSeparatorChar); String dir = root + path.substring(pluginDir.length()); sourcePath.append(dir); } } else { if (cp.length() > 0) cp.append(File.pathSeparator); cp.append(path); } } String bin = root + "/bin"; if (cp.length() > 0) cp.append(File.pathSeparator); cp.append(bin); ArrayList<String> args = new ArrayList<String>(); args.addAll(Arrays.asList(new String[] { "-nowarn", "-1.5", // "-verbose", "-d", bin, "-cp", cp.toString(), "-log", root + "/log.xml", "-sourcepath", sourcePath.toString(), })); args.addAll(sources); writer = new PrintWriter(new BufferedOutputStream(new FileOutputStream(root + "/out.txt"))); BatchCompiler.compile(args.toArray(new String[args.size()]), writer, writer, null); writer.close(); writer = null; project.getProject().findMember(new Path(buildDir)).refreshLocal(IResource.DEPTH_INFINITE, null); } catch (Exception e) { throw new CoreException( new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Problem building 64-bit code", e)); } finally { if (writer != null) writer.close(); } }
From source file:org.eclipse.swt.tools.builders.Check64CompilationParticipant.java
License:Open Source License
boolean is64bit(IJavaProject project) { try {//from w ww . j ava 2 s . com IClasspathEntry[] entries = project.getResolvedClasspath(true); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { String path = entry.getPath().toPortableString(); if (path.equals(pluginDir + "Eclipse SWT PI/win32") || path.equals(pluginDir + "Eclipse SWT PI/cocoa") || path.equals(pluginDir + "Eclipse SWT PI/gtk")) { return true; } } } } catch (JavaModelException e) { } return false; }
From source file:org.eclipse.virgo.ide.export.BundleExportUtils.java
License:Open Source License
/** * Find manifest file given a java project * * @param project/* ww w.j a va2s .com*/ * @return */ public static IResource getOutputManifestFile(IJavaProject project) { try { Set<IPath> outputPaths = new HashSet<IPath>(); outputPaths.add(project.getOutputLocation()); IPackageFragmentRoot[] roots = project.getPackageFragmentRoots(); for (IPackageFragmentRoot root : roots) { if (root != null) { IClasspathEntry cpEntry = root.getRawClasspathEntry(); if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath location = cpEntry.getOutputLocation(); if (location != null) { outputPaths.add(location); } } } } for (IPath outputPath : outputPaths) { IResource manifest = getManifestFile(outputPath, project.getProject()); if (manifest != null) { return manifest; } } } catch (JavaModelException e) { // No error handling existed before. Are these expected?! throw new RuntimeException(e); } catch (MalformedURLException e) { // No error handling existed before. Are these expected?! throw new RuntimeException(e); } return null; }
From source file:org.eclipse.virgo.ide.facet.core.FacetUtils.java
License:Open Source License
/** * Gets all the plan files found in the given project. * * @param project/*from w ww . ja v a 2s .c o m*/ * @return */ public static Collection<IFile> getPlansInPlanProject(IProject project) { if (!isPlanProject(project)) { return Collections.emptyList(); } final List<IFile> planFiles = new ArrayList<IFile>(); // Collect output locations if java project final Set<IPath> outputLocations = new HashSet<IPath>(); try { if (FacetUtils.hasNature(project, JavaCore.NATURE_ID)) { IJavaProject je = JavaCore.create(project); try { outputLocations.add(je.getOutputLocation()); for (IClasspathEntry entry : je.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (entry.getOutputLocation() != null) { outputLocations.add(entry.getOutputLocation()); } } } } catch (JavaModelException e) { // safe to ignore } } project.accept(new IResourceVisitor() { public boolean visit(IResource resource) throws CoreException { if (resource.isTeamPrivateMember() || resource.isDerived()) { return false; } if (resource instanceof IFile && "plan".equals(resource.getFileExtension())) { planFiles.add((IFile) resource); } else if (resource instanceof IContainer) { IPath path = ((IContainer) resource).getFullPath(); for (IPath outputLocation : outputLocations) { if (outputLocation.isPrefixOf(path)) { return false; } } return true; } return true; } }); } catch (CoreException e) { // TODO CD log exception } return planFiles; }
From source file:org.eclipse.virgo.ide.jdt.internal.ui.properties.TestSourceFolderPreferencePage.java
License:Open Source License
public boolean performOk() { if (!modified) { return true; }// www . j a v a2 s .co m try { List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); for (IClasspathEntry entry : JavaCore.create(project).getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { Set<IClasspathAttribute> attrs = new HashSet<IClasspathAttribute>(); for (IClasspathAttribute attr : entry.getExtraAttributes()) { if (!attr.getName().equals(ServerModuleDelegate.TEST_CLASSPATH_ENTRY_ATTRIBUTE)) { attrs.add(attr); } } attrs.add(getClasspathAttribute(entry)); entries.add(JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(), entry.getExclusionPatterns(), entry.getOutputLocation(), (IClasspathAttribute[]) attrs.toArray(new IClasspathAttribute[attrs.size()]))); } else { entries.add(entry); } } JavaCore.create(project).setRawClasspath( (IClasspathEntry[]) entries.toArray(new IClasspathEntry[entries.size()]), new NullProgressMonitor()); } catch (JavaModelException e) { } return true; }
From source file:org.eclipse.virgo.ide.module.core.ServerModuleDelegate.java
License:Open Source License
public static Set<IClasspathEntry> getSourceClasspathEntries(IProject project, boolean onlyTestFolders) { IJavaProject javaProject = JavaCore.create(project); if (javaProject == null) { return Collections.emptySet(); }/*from w w w . ja v a 2 s . c om*/ Set<IClasspathEntry> entries = new LinkedHashSet<IClasspathEntry>(); try { for (IClasspathEntry entry : javaProject.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (onlyTestFolders && !isSourceFolder(entry.getExtraAttributes()) || !onlyTestFolders && isSourceFolder(entry.getExtraAttributes())) { entries.add(entry); } } } } catch (JavaModelException e) { } return entries; }
From source file:org.eclipse.virgo.ide.module.core.ServerModuleFactoryDelegate.java
License:Open Source License
/** * {@inheritDoc}//w w w . ja v a 2 s . com */ @Override protected IModule[] createModules(final IProject project) { final Set<IModule> modules = new HashSet<IModule>(); if (FacetUtils.isBundleProject(project)) { // Add module for bundle deployment modules.add(createModule(project.getName(), project.getName(), FacetCorePlugin.BUNDLE_FACET_ID, "1.0", project)); // Add module for par deployment for (IProject parProject : FacetUtils.getParProjects(project)) { modules.add(createModule(parProject.getName() + "$" + project.getName(), project.getName(), FacetCorePlugin.BUNDLE_FACET_ID, "1.0", project)); } } else if (FacetUtils.isParProject(project)) { modules.add(createModule(project.getName(), project.getName(), FacetCorePlugin.PAR_FACET_ID, "1.0", project)); } // Every project can also be a plan project if (FacetUtils.isPlanProject(project)) { // Collect output locations if java project final Set<IPath> outputLocations = new HashSet<IPath>(); if (JdtUtils.isJavaProject(project)) { IJavaProject je = JdtUtils.getJavaProject(project); try { outputLocations.add(je.getOutputLocation()); for (IClasspathEntry entry : je.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (entry.getOutputLocation() != null) { outputLocations.add(entry.getOutputLocation()); } } } } catch (JavaModelException e) { } } try { project.accept(new IResourceVisitor() { public boolean visit(IResource resource) throws CoreException { if (resource instanceof IFile && resource.getName().endsWith(".plan")) { modules.add(createModule(resource.getFullPath().toString(), resource.getProject().getName() + "/" + resource.getProjectRelativePath().toString(), FacetCorePlugin.PLAN_FACET_ID, "2.0", project)); } else if (resource instanceof IContainer) { IPath path = ((IContainer) resource).getFullPath(); for (IPath outputLocation : outputLocations) { if (outputLocation.isPrefixOf(path)) { return false; } } return true; } return true; } }); } catch (CoreException e) { // TODO CD log exception } } return (IModule[]) modules.toArray(new IModule[modules.size()]); }
From source file:org.eclipse.virgo.ide.pde.core.internal.cmd.SetupProjectOperation.java
License:Open Source License
private IPath configureWABClasspath(IProject project) throws CoreException, JavaModelException { IJavaProject javaProject = (IJavaProject) project.getNature(JavaCore.NATURE_ID); javaProject.setOutputLocation(project.getFullPath().append(BIN), null); IClasspathEntry[] entries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; for (int i = 0; i < entries.length; i++) { IClasspathEntry iClasspathEntry = entries[i]; if (iClasspathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE && iClasspathEntry.getPath().lastSegment().equals(SRC)) { IClasspathEntry newEntry = JavaCore.newSourceEntry(iClasspathEntry.getPath(), iClasspathEntry.getInclusionPatterns(), iClasspathEntry.getExclusionPatterns(), project.getFullPath().append(BIN_WEB_INF_CLASSES)); newEntries[i] = newEntry;//w w w .ja v a 2 s . c o m break; } else { newEntries[i] = entries[i]; } } IPath webContentPath = project.getFullPath().append(WEB_CONTENT_FOLDER); newEntries[entries.length] = JavaCore.newLibraryEntry(webContentPath, null, null); javaProject.setRawClasspath(newEntries, null); return webContentPath; }