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:in.cypal.studio.gwt.samples.wizards.SamplesWizard.java
License:Apache License
public IClasspathEntry ensureSourceFolder(IJavaProject javaProject) throws JavaModelException { IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); IClasspathEntry sampleSrc = null;//from w w w. j a va2s . c om for (int i = 0; i < classpathEntries.length; i++) { if (classpathEntries[i].getEntryKind() != IClasspathEntry.CPE_SOURCE) continue;// we are interested only in source folders String folderName = classpathEntries[i].getPath().lastSegment(); if (folderName.equals(SAMPLE_SRC)) { sampleSrc = classpathEntries[i]; break; } } if (sampleSrc == null) { addSourceFolder(javaProject, classpathEntries); } return sampleSrc; }
From source file:in.software.analytics.parichayana.core.internal.builder.ParichayanaBuilder.java
License:Open Source License
private List<ICompilationUnit> getCompilationUnits() throws JavaModelException { List<ICompilationUnit> compilationUnits = new ArrayList<ICompilationUnit>(); IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(entry); for (IPackageFragmentRoot root : roots) { if (root.isArchive()) { continue; }//from ww w .j av a 2 s.com IJavaElement[] children = root.getChildren(); for (IJavaElement child : children) { if (child instanceof IPackageFragment) { IPackageFragment packageFragment = (IPackageFragment) child; ICompilationUnit[] cus = packageFragment.getCompilationUnits(); for (ICompilationUnit cu : cus) { cleanupMarkers(cu.getUnderlyingResource()); compilationUnits.add(cu); } } } } } } return compilationUnits; }
From source file:info.evanchik.eclipse.felix.FelixLaunchConfiguration.java
License:Open Source License
/** * Gets the path to the specified bundle in the following manner:<br> * <br>/*from w ww. j av a 2 s . c o m*/ * <ol> * <li>If the bundle is found in the Plug-in Registry and is not a workspace * resource, return the path to the bundle</li> * <li>If the bundle is in the Plug-in Registry but is a workspace resource, * return the path to the path to the output location that contains the * package specified ({@code project/output folder})</li> * <li>If the bundle is not found in the Plug-in Registry then look for it * in the OSGi platform</li> * </ol> * * @param bundleName * the symbolic name of the bundle * @param packageName * the name of the package used to locate the output folder * @return a fully qualified path to the requested bundle or null if it does * not exist * @throws CoreException */ private static String getBundlePath(String bundleName, String packageName) throws CoreException { final IPluginModelBase model = PluginRegistry.findModel(bundleName); if (model != null) { final IResource resource = model.getUnderlyingResource(); if (!isWorkspaceModel(model)) { return model.getInstallLocation(); } final IProject project = resource.getProject(); if (project.hasNature(JavaCore.NATURE_ID)) { final IJavaProject jProject = JavaCore.create(project); final IClasspathEntry[] entries = jProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { final int kind = entries[i].getEntryKind(); if (kind == IClasspathEntry.CPE_SOURCE || kind == IClasspathEntry.CPE_LIBRARY) { final IPackageFragmentRoot[] roots = jProject.findPackageFragmentRoots(entries[i]); for (int j = 0; j < roots.length; j++) { if (roots[j].getPackageFragment(packageName).exists()) { // if source folder, find the output folder if (kind == IClasspathEntry.CPE_SOURCE) { IPath path = entries[i].getOutputLocation(); if (path == null) { path = jProject.getOutputLocation(); } path = path.removeFirstSegments(1); return project.getLocation().append(path).toOSString(); } // else if is a library jar, then get the // location of the jar itself final IResource jar = roots[j].getResource(); if (jar != null) { return jar.getLocation().toOSString(); } } } } } } } final Bundle bundle = Platform.getBundle(bundleName); if (bundle != null) { try { URL url = FileLocator.resolve(bundle.getEntry("/")); //$NON-NLS-1$ url = FileLocator.toFileURL(url); String path = url.getFile(); if (path.startsWith("file:")) { //$NON-NLS-1$ path = path.substring(5); } path = new File(path).getAbsolutePath(); if (path.endsWith("!")) { //$NON-NLS-1$ path = path.substring(0, path.length() - 1); } return path; } catch (IOException e) { } } return null; }
From source file:io.sarl.eclipse.natures.SARLProjectConfigurator.java
License:Apache License
private static List<CPListElement> buildClassPathEntries(IJavaProject project, IFolder[] sourcePaths, IFolder[] generationPaths) {//from w ww. j a v a2 s.c o m final List<CPListElement> list = new ArrayList<>(); for (final IFolder sourcePath : sourcePaths) { if (sourcePath != null) { list.add(new CPListElement(project, IClasspathEntry.CPE_SOURCE, sourcePath.getFullPath().makeAbsolute(), sourcePath)); } } for (final IFolder sourcePath : generationPaths) { if (sourcePath != null) { final IClasspathAttribute attr = JavaCore.newClasspathAttribute( IClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS, Boolean.TRUE.toString()); final IClasspathEntry entry = JavaCore.newSourceEntry(sourcePath.getFullPath().makeAbsolute(), ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null /*output location*/, new IClasspathAttribute[] { attr }); list.add(CPListElement.create(entry, false, project)); } } for (final IClasspathEntry current : PreferenceConstants.getDefaultJRELibrary()) { if (current != null) { list.add(CPListElement.create(current, true, project)); break; } } list.add(CPListElement.create(JavaCore.newContainerEntry(SARLClasspathContainerInitializer.CONTAINER_ID), true, project)); return list; }
From source file:io.sarl.eclipse.util.JavaClasspathParser.java
License:Apache License
/** * Decodes one XML element with the XML stream. * * @param element//from w ww.jav a 2s . c o m * - the considered element * @param projectName * - the name of project containing the .classpath file * @param projectRootAbsoluteFullPath * - he path to project containing the .classpath file * @param unknownElements * - map of unknown elements * @return the set of CLasspath ENtries extracted from the considered element */ @SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity" }) public static IClasspathEntry elementDecode(Element element, String projectName, IPath projectRootAbsoluteFullPath, Map<IPath, UnknownXmlElements> unknownElements) { final IPath projectPath = projectRootAbsoluteFullPath; final NamedNodeMap attributes = element.getAttributes(); final NodeList children = element.getChildNodes(); final boolean[] foundChildren = new boolean[children.getLength()]; final String kindAttr = removeAttribute(ClasspathEntry.TAG_KIND, attributes); final String pathAttr = removeAttribute(ClasspathEntry.TAG_PATH, attributes); // ensure path is absolute IPath path = new Path(pathAttr); final int kind = kindFromString(kindAttr); if (kind != IClasspathEntry.CPE_VARIABLE && kind != IClasspathEntry.CPE_CONTAINER && !path.isAbsolute()) { if (!(path.segmentCount() > 0 && path.segment(0).equals(ClasspathEntry.DOT_DOT))) { path = projectPath.append(path); } } // source attachment info (optional) IPath sourceAttachmentPath = element.hasAttribute(ClasspathEntry.TAG_SOURCEPATH) ? new Path(removeAttribute(ClasspathEntry.TAG_SOURCEPATH, attributes)) : null; if (kind != IClasspathEntry.CPE_VARIABLE && sourceAttachmentPath != null && !sourceAttachmentPath.isAbsolute()) { sourceAttachmentPath = projectPath.append(sourceAttachmentPath); } final IPath sourceAttachmentRootPath = element.hasAttribute(ClasspathEntry.TAG_ROOTPATH) ? new Path(removeAttribute(ClasspathEntry.TAG_ROOTPATH, attributes)) : null; // exported flag (optional) final boolean isExported = removeAttribute(ClasspathEntry.TAG_EXPORTED, attributes).equals("true"); //$NON-NLS-1$ // inclusion patterns (optional) IPath[] inclusionPatterns = decodePatterns(attributes, ClasspathEntry.TAG_INCLUDING); if (inclusionPatterns == null) { inclusionPatterns = ClasspathEntry.INCLUDE_ALL; } // exclusion patterns (optional) IPath[] exclusionPatterns = decodePatterns(attributes, ClasspathEntry.TAG_EXCLUDING); if (exclusionPatterns == null) { exclusionPatterns = ClasspathEntry.EXCLUDE_NONE; } // access rules (optional) NodeList attributeList = getChildAttributes(ClasspathEntry.TAG_ACCESS_RULES, children, foundChildren); IAccessRule[] accessRules = decodeAccessRules(attributeList); // backward compatibility if (accessRules == null) { accessRules = getAccessRules(inclusionPatterns, exclusionPatterns); } // combine access rules (optional) final boolean combineAccessRestrictions = !removeAttribute(ClasspathEntry.TAG_COMBINE_ACCESS_RULES, attributes).equals("false"); //$NON-NLS-1$ // extra attributes (optional) attributeList = getChildAttributes(ClasspathEntry.TAG_ATTRIBUTES, children, foundChildren); final IClasspathAttribute[] extraAttributes = decodeExtraAttributes(attributeList); // custom output location final IPath outputLocation = element.hasAttribute(ClasspathEntry.TAG_OUTPUT) ? projectPath.append(removeAttribute(ClasspathEntry.TAG_OUTPUT, attributes)) : null; String[] unknownAttributes = null; ArrayList<String> unknownChildren = null; if (unknownElements != null) { // unknown attributes final int unknownAttributeLength = attributes.getLength(); if (unknownAttributeLength != 0) { unknownAttributes = new String[unknownAttributeLength * 2]; for (int i = 0; i < unknownAttributeLength; i++) { final Node attribute = attributes.item(i); unknownAttributes[i * 2] = attribute.getNodeName(); unknownAttributes[i * 2 + 1] = attribute.getNodeValue(); } } // unknown children for (int i = 0, length = foundChildren.length; i < length; i++) { if (!foundChildren[i]) { final Node node = children.item(i); if (node.getNodeType() != Node.ELEMENT_NODE) { continue; } if (unknownChildren == null) { unknownChildren = new ArrayList<>(); } final StringBuffer buffer = new StringBuffer(); decodeUnknownNode(node, buffer); unknownChildren.add(buffer.toString()); } } } // recreate the CP entry IClasspathEntry entry = null; switch (kind) { case IClasspathEntry.CPE_PROJECT: /* * IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_PROJECT, path, ClasspathEntry.INCLUDE_ALL, // inclusion patterns * ClasspathEntry.EXCLUDE_NONE, // exclusion patterns null, // source attachment null, // source attachment root null, // specific output * folder */ entry = new ClasspathEntry(IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_PROJECT, path, ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null, null, null, isExported, accessRules, combineAccessRestrictions, extraAttributes); break; case IClasspathEntry.CPE_LIBRARY: entry = JavaCore.newLibraryEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, accessRules, extraAttributes, isExported); break; case IClasspathEntry.CPE_SOURCE: // must be an entry in this project or specify another project final String projSegment = path.segment(0); if (projSegment != null && projSegment.equals(projectName)) { // this project entry = JavaCore.newSourceEntry(path, inclusionPatterns, exclusionPatterns, outputLocation, extraAttributes); } else { if (path.segmentCount() == 1) { // another project entry = JavaCore.newProjectEntry(path, accessRules, combineAccessRestrictions, extraAttributes, isExported); } else { // an invalid source folder entry = JavaCore.newSourceEntry(path, inclusionPatterns, exclusionPatterns, outputLocation, extraAttributes); } } break; case IClasspathEntry.CPE_VARIABLE: entry = JavaCore.newVariableEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, accessRules, extraAttributes, isExported); break; case IClasspathEntry.CPE_CONTAINER: entry = JavaCore.newContainerEntry(path, accessRules, extraAttributes, isExported); break; case ClasspathEntry.K_OUTPUT: if (!path.isAbsolute()) { return null; } /* * ClasspathEntry.EXCLUDE_NONE, null, // source attachment null, // source attachment root null, // custom output location false, null, // * no access rules false, // no accessible files to combine */ entry = new ClasspathEntry(ClasspathEntry.K_OUTPUT, IClasspathEntry.CPE_LIBRARY, path, ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null, null, null, false, null, false, ClasspathEntry.NO_EXTRA_ATTRIBUTES); break; default: throw new AssertionFailedException(Messages.bind(Messages.classpath_unknownKind, kindAttr)); } if (unknownAttributes != null || unknownChildren != null) { final UnknownXmlElements unknownXmlElements = new UnknownXmlElements(); unknownXmlElements.attributes = unknownAttributes; unknownXmlElements.children = unknownChildren; if (unknownElements != null) { unknownElements.put(path, unknownXmlElements); } } return entry; }
From source file:io.sarl.eclipse.util.JavaClasspathParser.java
License:Apache License
/** * Returns the kind of a <code>PackageFragmentRoot</code> from its <code>String</code> form. * * @param kindStr// w ww .j a v a 2 s .c om * - string to test * @return the integer identifier of the type of the specified string: CPE_PROJECT, CPE_VARIABLE, CPE_CONTAINER, etc. */ @SuppressWarnings("checkstyle:equalsavoidnull") private static int kindFromString(String kindStr) { if (kindStr.equalsIgnoreCase("prj")) { //$NON-NLS-1$ return IClasspathEntry.CPE_PROJECT; } if (kindStr.equalsIgnoreCase("var")) { //$NON-NLS-1$ return IClasspathEntry.CPE_VARIABLE; } if (kindStr.equalsIgnoreCase("con")) { //$NON-NLS-1$ return IClasspathEntry.CPE_CONTAINER; } if (kindStr.equalsIgnoreCase("src")) { //$NON-NLS-1$ return IClasspathEntry.CPE_SOURCE; } if (kindStr.equalsIgnoreCase("lib")) { //$NON-NLS-1$ return IClasspathEntry.CPE_LIBRARY; } if (kindStr.equalsIgnoreCase("output")) { //$NON-NLS-1$ return ClasspathEntry.K_OUTPUT; } return -1; }
From source file:io.sarl.eclipse.wizards.newproject.NewSarlProjectWizard.java
License:Apache License
private static boolean hasSourcePath(IJavaProject javaProject, IPath path) { if (path != null) { final IPath pathInProject = javaProject.getProject().getFullPath().append(path); try {/*from w ww . j ava 2 s . c o m*/ for (final IClasspathEntry entry : javaProject.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && pathInProject.equals(entry.getPath())) { return true; } } } catch (Throwable exception) { // } } return false; }
From source file:io.sarl.eclipse.wizards.newproject.NewSarlProjectWizard.java
License:Apache License
private static String buildInvalidOutputPathMessageFragment(IJavaProject javaProject) { final StringBuilder sourceFolders = new StringBuilder(); try {// w w w . ja va2 s.c o m for (final IClasspathEntry entry : javaProject.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { sourceFolders.append("\t"); //$NON-NLS-1$ sourceFolders.append(entry.getPath().toOSString()); sourceFolders.append("\n"); //$NON-NLS-1$ } } } catch (Throwable exception) { // } return sourceFolders.toString(); }
From source file:it.wallgren.android.platform.project.AndroidPlatformProject.java
License:Apache License
private IClasspathEntry[] mangleClasspath(IClasspathEntry[] rawClasspath, IProject project, IFolder repoLink) { LinkedList<IClasspathEntry> entries = new LinkedList<IClasspathEntry>(); // Filter out anything that is not framworks, packages, libcore or R IFile frameworks = project.getFile("frameworks"); IFile packages = project.getFile("packages"); IFile libcore = project.getFile("libcore"); for (IClasspathEntry entry : rawClasspath) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { // is frameworks source folder or R source folder if (frameworks.getFullPath().isPrefixOf(entry.getPath()) || libcore.getFullPath().isPrefixOf(entry.getPath()) || packages.getFullPath().isPrefixOf(entry.getPath()) || entry.getPath().lastSegment().equals("R")) { IPath path = entry.getPath().removeFirstSegments(1); IFolder entryFolder = repoLink.getFolder(path); if (!isBroken(entryFolder)) { entries.add(JavaCore.newSourceEntry(entryFolder.getFullPath())); }//from w w w . j a v a 2 s.com } } } // Add the special platform libs container entries.add(getAndroidDependenceis(repoPath)); return entries.toArray(new IClasspathEntry[0]); }
From source file:me.gladwell.eclipse.m2e.android.configuration.classpath.ModifySourceFolderOutputClasspathConfigurer.java
License:Open Source License
public void configure(Project project) { for (IClasspathEntry entry : project.getClasspath().getEntries()) { if (entry.getOutputLocation() != null && entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && !entry.getOutputLocation() .equals(project.getJavaProject().getPath().append(ANDROID_CLASSES_FOLDER))) { project.getClasspath().removeEntry(entry.getPath()); project.getClasspath().addSourceEntry(entry.getPath(), project.getJavaProject().getPath().append(ANDROID_CLASSES_FOLDER), true); }//from w w w. ja va 2s .c o m } }