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:net.sf.j2s.core.builder.NameEnvironment.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); }// w ww . ja va 2s .co 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(), entry.ignoreOptionalProblems())); 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); }
From source file:net.sf.jasperreports.eclipse.classpath.JavaProjectClassLoader.java
License:Open Source License
private void resolveClasspathEntries(Set<URL> urls, IWorkspaceRoot root, IClasspathEntry[] entries) throws JavaModelException { for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath path = entry.getPath(); if (path.segmentCount() >= 2) { IFolder sourceFolder = root.getFolder(path); try { urls.add(new URL("file:///" + sourceFolder.getRawLocation().toOSString() + "/")); } catch (MalformedURLException e) { }//from w ww . j a v a 2 s .c o m } } else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath sourcePath = entry.getPath(); covertPathToUrl(javaProject.getProject(), urls, sourcePath); IPath sourceOutputPath = entry.getOutputLocation(); covertPathToUrl(javaProject.getProject(), urls, sourceOutputPath); } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (entry.getPath().equals(JRClasspathContainer.ID)) continue; IClasspathContainer cont = JavaCore.getClasspathContainer(entry.getPath(), javaProject); resolveClasspathEntries(urls, root, cont.getClasspathEntries()); } } }
From source file:net.sf.refactorit.eclipse.vfs.EclipseSourcePath.java
License:Open Source License
private IClasspathEntry[] getSourcePathEntries() throws JavaModelException { IJavaProject jProject = getJavaProject(); List result = new ArrayList(); IClasspathEntry[] pathEntries = jProject.getResolvedClasspath(true); for (int i = 0; i < pathEntries.length; i++) { IClasspathEntry entry = pathEntries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE /*|| entry.getEntryKind() == IClasspathEntry.CPE_PROJECT*/) { result.add(entry);/* w w w. j a va2s .c o m*/ if (debug) { log.debug("exclusion patterns = " + Arrays.asList(entry.getExclusionPatterns())); } } } return (IClasspathEntry[]) result.toArray(new IClasspathEntry[result.size()]); }
From source file:net.sourceforge.floggy.eclipse.builder.MTJBuilder.java
License:Open Source License
/** * This is where the classpool is actually set. The typical case only requires adding the required jar files * to the classpool (classPool and classPoolList), however if the project is dependent on other projects then * not only do we need the jar files from these dependencies but we also need the output folders. * @TODO EXPERIMENTAL - Dependencies support should be considered experimental at this time because it isn't fully tested ! *//*from w ww . j a va2s. com*/ private void configureClassPool(ClassPool classPool, List classPoolList, IClasspathEntry[] entries, IProject project, boolean isRootProject) throws NotFoundException, JavaModelException { IClasspathEntry classpathEntry; String pathName; for (int i = 0; i < entries.length; i++) { classpathEntry = JavaCore.getResolvedClasspathEntry(entries[i]); IPath classIPath = classpathEntry.getPath(); if ((isRootProject || classpathEntry.isExported()) && classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { pathName = getAccessablePathName(classIPath, project); } else if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { classIPath = classpathEntry.getOutputLocation(); if (classIPath == null) { classIPath = JavaCore.create(project).getOutputLocation(); } pathName = getAccessablePathName(classIPath, project); } else { // Currently we only add : All source folders, All libs in the root project & Exported libs in other projects continue; } if (pathName.contains("floggy-persistence-framework-impl.jar")) { continue; } if (pathName != null && !classPoolList.contains(pathName)) { LOG.debug(pathName + " added to classPool"); classPoolList.add(pathName); classPool.appendClassPath(pathName); } else { LOG.debug(pathName + " alreaded added to classPool"); } } }
From source file:nl.mwensveen.m2e.extras.cxf.tests.CXFGenerationTest.java
License:Open Source License
public void test_p001_simple() throws Exception { ResolverConfiguration configuration = new ResolverConfiguration(); IProject project1 = importProject("projects/cxf/pom.xml", configuration); waitForJobsToComplete();//from ww w . ja v a2s . c o m project1.build(IncrementalProjectBuilder.FULL_BUILD, monitor); project1.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); waitForJobsToComplete(); assertNoErrors(project1); IJavaProject javaProject1 = JavaCore.create(project1); IClasspathEntry[] cp1 = javaProject1.getRawClasspath(); boolean found = false; for (IClasspathEntry iClasspathEntry : cp1) { if (iClasspathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (iClasspathEntry.getPath().equals(new Path("/cxf-test-project/target/generated-sources/cxf"))) { found = true; } } } assertTrue(found); assertTrue(project1.getFile("target/generated-sources/cxf/com/example/xsd/ComplexType.java") .isSynchronized(IResource.DEPTH_ZERO)); assertTrue( project1.getFile("target/generated-sources/cxf/com/example/xsd/ComplexType.java").isAccessible()); }
From source file:nz.ac.auckland.ptjava.newclasswizard.WizardNewPTJavaFileCreationPage.java
License:Open Source License
/** * Creates the initial contents to be placed inside the newly created PTJava class file. * Current version will generate package declaration and basic class declaration if * those options are checked on the wizard page. *//*from w ww. j a v a 2 s . co m*/ @Override protected InputStream getInitialContents() { // String buffer for appending to file StringBuffer sb = new StringBuffer(); if (fCodeCreationGroup.getGeneratePackage()) { IPath containerFullPath = getContainerFullPath(); // the original string to the container path String pathString = containerFullPath.toString(); //System.out.println(pathString); int slashIndex = pathString.indexOf('/', 1); String truncatedPath = null; if (slashIndex > 0) truncatedPath = pathString.substring(0, slashIndex); else truncatedPath = pathString; // find the project src folder path IProject project = JavaPlugin.getWorkspace().getRoot().getProject(truncatedPath); IJavaProject javaProject = JavaCore.create(project); if (javaProject != null) { try { String srcPath = null; IClasspathEntry[] cp = javaProject.getRawClasspath(); for (IClasspathEntry i : cp) { //System.out.println("i:"+i); if (i.getEntryKind() == IClasspathEntry.CPE_SOURCE) { // src entry found! srcPath = i.getPath().toString(); //System.out.println("srcPath: " + srcPath); break; } } if (srcPath != null) { if (pathString.equals(srcPath)) { // do nothing } else { String s = null; // omit src path if part of path string if (pathString.startsWith(srcPath)) s = pathString.substring(srcPath.length() + 1); // the +1 is to remove the first "/" after the src path else s = pathString; // currently looks like "some/path/to/file", we want "some.path.to.file" s = s.replace('/', '.'); // append it // should be something like "package some.path;" sb.append("package "); sb.append(s); sb.append(";"); sb.append("\n\n"); //System.out.println("s: " + s); } } } catch (JavaModelException e) { e.printStackTrace(); } } } if (fCodeCreationGroup.getGenerateClass()) { sb.append("public class "); String filename = getFileName(); if (filename.contains(".")) filename = filename.substring(0, filename.indexOf('.')); sb.append(filename); sb.append(" {\n\t\n}"); } if (sb.length() == 0) return null; return new ByteArrayInputStream(sb.toString().getBytes()); }
From source file:org.antlr.eclipse.core.builder.AntlrBuilder.java
License:Open Source License
/** * Compile a grammar/*from w w w . ja v a 2 s.com*/ * @param aFile The grammar file to compile * @param aMonitor A progress monitor */ public void compileFile(IFile aFile, IProgressMonitor aMonitor) { String grammarFileName = aFile.getProjectRelativePath().toString(); try { // delete the old generated files for this grammar aFile.getProject().accept(new CleaningVisitor(aMonitor, grammarFileName)); // if it's in a java project, only build it if it's in a source dir if (aFile.getProject().hasNature(JavaCore.NATURE_ID)) { IProject project = aFile.getProject(); IJavaProject javaProject = JavaCore.create(project); IPath path = aFile.getFullPath(); boolean ok = false; IClasspathEntry[] resolvedClasspath = javaProject.getResolvedClasspath(true); for (int i = 0; i < resolvedClasspath.length; i++) { IClasspathEntry entry = resolvedClasspath[i]; if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) continue; IPath entryPath = entry.getPath(); if (entryPath.isPrefixOf(path)) { ok = true; break; } } if (!ok) { return; } } } catch (CoreException e1) { e1.printStackTrace(); } fFile = aFile; aMonitor.beginTask( AntlrCorePlugin.getFormattedMessage("AntlrBuilder.compiling", aFile.getFullPath().toString()), 4); // Remove all markers from this file try { aFile.deleteMarkers(null, true, IResource.DEPTH_INFINITE); } catch (CoreException e) { AntlrCorePlugin.log(e); } // Prepare arguments for ANTLR compiler // read the settings for this grammar HashMap<String, HashMap<String, String>> map = SettingsPersister.readSettings(aFile.getProject()); ArrayList<String> args = createArguments(map, aFile); if (DEBUG) { System.out.println("Compiling ANTLR grammar '" + aFile.getName() + "': arguments=" + args); } // Monitor system out and err fOriginalOut = System.out; fOriginalErr = System.err; System.setOut(new PrintStream(new MonitoredOutputStream(this))); System.setErr(new PrintStream(new MonitoredOutputStream(this))); try { // Compile ANTLR grammar file AntlrTool tool = new AntlrTool(); if (!tool.preprocess(args.toArray(new String[args.size()]))) { try { aMonitor.worked(1); if (!tool.parse()) { aMonitor.worked(1); if (!tool.generate()) { aMonitor.worked(1); refreshFolder(map, tool, args, aFile, grammarFileName, ResourcesPlugin.getWorkspace().getRoot().findMember(fOutput), aMonitor, tool.getSourceMaps()); } else { // If errors during generate then delete all // generated files deleteFiles(tool, aFile.getParent(), aMonitor); } aMonitor.worked(1); } } catch (CoreException e) { AntlrCorePlugin.log(e); } } } catch (Throwable e) { if (!(e instanceof SecurityException)) { AntlrCorePlugin.log(e); } } finally { System.setOut(fOriginalOut); System.setErr(fOriginalErr); aMonitor.done(); } }
From source file:org.antlr.eclipse.smapinstaller.SMapInstallerBuilder.java
License:Open Source License
/** * Installs the modified smap into a generated classfile * @param resource//ww w. ja v a 2 s. c om * @throws JavaModelException */ protected void installSmap(final IResource resource) throws JavaModelException { // We only work on smap files -- skip everything else if (!(resource instanceof IFile)) return; IFile smapIFile = (IFile) resource; if (!"smap".equalsIgnoreCase(smapIFile.getFileExtension())) return; IJavaProject javaProject = JavaCore.create(smapIFile.getProject()); // get the name of the corresponding java source file IPath smapPath = smapIFile.getFullPath(); IClasspathEntry[] classpathEntries = javaProject.getResolvedClasspath(true); for (int i = 0, l = classpathEntries.length; i < l; i++) { IClasspathEntry entry = classpathEntries[i]; if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) continue; if (!entry.getPath().isPrefixOf(smapPath)) continue; // found the right source container IPath outputLocation = entry.getOutputLocation(); if (outputLocation == null) outputLocation = javaProject.getOutputLocation(); // strip the source dir and .smap suffix String sourceDir = entry.getPath().toString(); String smapName = smapPath.toString(); String javaSourceName = smapName.substring(0, smapName.length() - 5) + ".java"; String className = smapName.substring(sourceDir.length(), smapName.length() - 5) + ".class"; IPath path = outputLocation.append(className); IPath workspaceLoc = ResourcesPlugin.getWorkspace().getRoot().getLocation(); IPath classFileLocation = workspaceLoc.append(path); IResource classResource = ResourcesPlugin.getWorkspace().getRoot().findMember(javaSourceName); File classFile = classFileLocation.toFile(); File smapFile = smapIFile.getLocation().toFile(); try { String installSmap = classResource.getPersistentProperty(AntlrBuilder.INSTALL_SMAP); if ("true".equals(installSmap)) SDEInstaller.install(classFile, smapFile); } catch (CoreException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:org.apache.easyant4e.tests.ImportProjectTest.java
License:Apache License
private void assertSourceFolders(IProject project) throws Exception { assertTrue(project.hasNature(JavaCore.NATURE_ID)); IJavaProject javaProject = (IJavaProject) project.getNature(JavaCore.NATURE_ID); assertNotNull(javaProject);/*from w w w. j a v a 2 s.c o m*/ List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); entries.addAll(Arrays.asList(javaProject.getRawClasspath())); assertTrue(entries.size() > 0); HashSet<String> sourceFolders = new HashSet<String>(); for (IClasspathEntry entry : entries) { if (IClasspathEntry.CPE_SOURCE == entry.getEntryKind()) { String path = entry.getPath().toOSString(); assertNotNull(path); sourceFolders.add(path); } } assertTrue(sourceFolders.contains("/simplejavaproject/src/main/java")); assertTrue(sourceFolders.contains("/simplejavaproject/src/test/java")); assertTrue(sourceFolders.contains("/simplejavaproject/src/main/resources")); assertTrue(sourceFolders.contains("/simplejavaproject/src/test/resources")); }
From source file:org.apache.felix.sigil.eclipse.internal.builders.SigilIncrementalProjectBuilder.java
License:Apache License
private void convert(IClasspathEntry cp, ISigilProjectModel sigil, List<File> files) throws CoreException { switch (cp.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: { convertProject(cp, files);//from ww w . j a va 2s . c o m break; } case IClasspathEntry.CPE_SOURCE: { convertSource(sigil, cp, files); break; } case IClasspathEntry.CPE_LIBRARY: { convertLibrary(sigil, cp, files); break; } case IClasspathEntry.CPE_VARIABLE: convertVariable(cp, files); break; } }