List of usage examples for org.eclipse.jdt.internal.core ClasspathEntry EXCLUDE_NONE
IPath[] EXCLUDE_NONE
To view the source code for org.eclipse.jdt.internal.core ClasspathEntry EXCLUDE_NONE.
Click Source Link
From source file:com.centurylink.mdw.plugin.project.assembly.ProjectConfigurator.java
License:Apache License
public void addJavaProjectSourceFolder(String sourceFolder, String outputFolder, IProgressMonitor monitor) throws CoreException, JavaModelException { if (!isJavaCapable()) return;/*from www . j a va 2s . com*/ IFolder folder = project.getSourceProject().getFolder(sourceFolder); if (!folder.exists()) folder.create(true, true, monitor); // projects with newly-added Java Nature contain root source entry, // which must be removed IClasspathEntry rootEntry = JavaCore.newSourceEntry(project.getSourceProject().getFullPath()); IPath outputPath = outputFolder == null ? null : project.getSourceProject().getFolder(outputFolder).getFullPath(); IClasspathEntry newEntry = JavaCore.newSourceEntry(folder.getFullPath(), ClasspathEntry.EXCLUDE_NONE, outputPath); boolean includesContainer = false; List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>(); IClasspathEntry toRemove = null; for (IClasspathEntry existingEntry : project.getSourceJavaProject().getRawClasspath()) { if (newEntry.equals(existingEntry)) return; // already on classpath else if (newEntry.getPath().equals(existingEntry.getPath()) && newEntry.getEntryKind() == existingEntry.getEntryKind()) toRemove = existingEntry; // to be replaced with new entry if (!rootEntry.equals(existingEntry)) classpathEntries.add(existingEntry); if (existingEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && String.valueOf(existingEntry.getPath()).indexOf("JRE_CONTAINER") >= 0) includesContainer = true; } if (toRemove != null) classpathEntries.remove(toRemove); classpathEntries.add(newEntry); if (!includesContainer) { IClasspathEntry jre = getJreContainerClasspathEntry(project.getJavaVersion()); if (jre == null) jre = JavaRuntime.getDefaultJREContainerEntry(); // fallback to // any // available classpathEntries.add(jre); } project.getSourceJavaProject().setRawClasspath(classpathEntries.toArray(new IClasspathEntry[0]), monitor); J2EEComponentClasspathUpdater.getInstance().queueUpdate(project.getSourceProject()); }
From source file:com.google.gdt.eclipse.appengine.rpc.wizards.helpers.RpcServiceLayerCreator.java
License:Open Source License
private void addAptSourceFolder(IProject project, IProgressMonitor monitor) throws JavaModelException { IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] entries = javaProject.getRawClasspath(); // add .apt_generated to classpath IClasspathAttribute[] attributes = new IClasspathAttribute[] { JavaCore.newClasspathAttribute("optional", "true") }; //$NON-NLS-N$ IFolder aptFolder = project.getFolder(APT_FOLDER); IClasspathEntry entry = JavaCore.newSourceEntry(aptFolder.getFullPath(), ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null, attributes); entries = CodegenUtils.addEntryToClasspath(entries, entry); javaProject.setRawClasspath(entries, new SubProgressMonitor(monitor, 10)); }
From source file:com.google.gdt.eclipse.mobile.android.wizards.helpers.AndroidProjectCreator.java
License:Open Source License
/** * Adds the given folder to the project's class path. * //ww w.j av a2 s.c o m * @param javaProject The Java Project to update. * @param sourceFolder Template Parameters. * @param monitor An existing monitor. * @throws CoreException */ private void setupSourceFolders(IJavaProject javaProject, String[] sourceFolders, IProgressMonitor monitor) throws CoreException { IProject project = javaProject.getProject(); // get the list of entries. IClasspathEntry[] entries = javaProject.getRawClasspath(); // remove the project as a source folder (This is the default) entries = removeSourceClasspath(entries, project); // add the source folders. for (String sourceFolder : sourceFolders) { IFolder srcFolder = project.getFolder(sourceFolder); // remove it first in case. entries = removeSourceClasspath(entries, srcFolder); entries = addEntryToClasspath(entries, JavaCore.newSourceEntry(srcFolder.getFullPath())); } IProject gaeProject = ResourcesPlugin.getWorkspace().getRoot() .getProject(projectName + AppEngineRPCPlugin.GAE_PROJECT_NAME_SUFFIX); IFolder sharedFolder = gaeProject.getFolder(ProjectCreationConstants.SHARED_FOLDER_NAME); if (sharedFolder.exists()) { IFolder androidLinkedFolder = androidProject.getFolder(ProjectCreationConstants.SHARED_FOLDER_NAME); /* The variable workspaceLoc is required only for Eclipse 3.5. * For Eclipses after 3.5, the project specific path variable WORKSPACE_LOC * can be used instead. */ String workspaceLoc = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString(); // use variables for shared folder path IPath sharedFolderPath = new Path(workspaceLoc + "/" + gaeProject.getName() + "/" //$NON-NLS-N$ + ProjectCreationConstants.SHARED_FOLDER_NAME); androidLinkedFolder.createLink(sharedFolderPath, IResource.ALLOW_MISSING_LOCAL, new SubProgressMonitor(monitor, 1)); entries = addEntryToClasspath(entries, JavaCore.newSourceEntry(androidLinkedFolder.getFullPath())); } // add .apt_generated to classpath IClasspathAttribute[] attributes = new IClasspathAttribute[] { JavaCore.newClasspathAttribute("optional", "true") }; //$NON-NLS-N$ IFolder aptFolder = project.getFolder(ProjectCreationConstants.APT_FOLDER); IClasspathEntry entry = JavaCore.newSourceEntry(aptFolder.getFullPath(), ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null, attributes); entries = addEntryToClasspath(entries, entry); javaProject.setRawClasspath(entries, new SubProgressMonitor(monitor, 10)); }
From source file:com.google.gwt.eclipse.core.compile.GWTCompileRunnerTest.java
License:Open Source License
/** * Create a source entry (including the dir structure) and add it to the raw * classpath.// w w w . j a va2 s. co m * * @param javaProject The Java project that receives the source entry * @param directoryName The source directory name * @param outputDirectoryName The optional output location of this source * directory. Pass null for the default output location. */ private static void addAndCreateSourceEntry(IJavaProject javaProject, String directoryName, String outputDirectoryName) throws CoreException { IFolder srcFolder = javaProject.getProject().getFolder(directoryName); ResourceUtils.createFolderStructure(javaProject.getProject(), srcFolder.getProjectRelativePath()); IPath workspaceRelOutPath = null; if (outputDirectoryName != null) { // Ensure output directory exists IFolder outFolder = javaProject.getProject().getFolder(outputDirectoryName); ResourceUtils.createFolderStructure(javaProject.getProject(), outFolder.getProjectRelativePath()); workspaceRelOutPath = outFolder.getFullPath(); } JavaProjectUtilities.addRawClassPathEntry(javaProject, JavaCore.newSourceEntry(srcFolder.getFullPath(), ClasspathEntry.EXCLUDE_NONE, workspaceRelOutPath)); }
From source file:fede.workspace.eclipse.java.JavaProjectManager.java
License:Apache License
/** * Adds the source folder associated with the item to the source entries in * the classpath of the java project.// w w w.ja va 2 s. com * * @param item * the item * @param monitor * the monitor * @param sourceFolder * the source folder * @param specificOutputFolder * the specific output folder * * @throws CoreException * the core exception */ public static void createJavaSourceFolder(Item item, IFolder sourceFolder, IFolder specificOutputFolder, IProgressMonitor monitor) throws CoreException { if (sourceFolder == null) { return; } IProject project = sourceFolder.getProject(); IJavaProject javaProject = JavaCore.create(project); if (javaProject == null) { return; } if (!sourceFolder.exists()) { sourceFolder.create(false, true, monitor); } IFolder defaultOutputFolder = project .getFolder(DEFAULT_OUTPUT_FOLDER_NAME.compute(ContextVariableImpl.DEFAULT, item)); if (!defaultOutputFolder.exists()) { defaultOutputFolder.create(false, true, monitor); } IPath specificOutputPath = null; if (specificOutputFolder != null) { specificOutputPath = specificOutputFolder.getFullPath(); if (!specificOutputFolder.exists()) { specificOutputFolder.create(false, true, monitor); } } List<IClasspathEntry> classpath = new ArrayList<IClasspathEntry>( Arrays.asList(javaProject.getRawClasspath())); IClasspathEntry sourceEntry = JavaCore.newSourceEntry(sourceFolder.getFullPath(), ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, specificOutputPath); if (!classpath.contains(sourceEntry)) { classpath.add(sourceEntry); javaProject.setRawClasspath(classpath.toArray(new IClasspathEntry[classpath.size()]), defaultOutputFolder.getFullPath(), monitor); } }
From source file:io.sarl.eclipse.natures.SARLProjectConfigurator.java
License:Apache License
/** Replies the default source entries for a SARL project. * * @param projectFolder the folder of the project. * @return the classpath entries./* w w w . jav a 2 s . c o m*/ */ public static List<IClasspathEntry> getDefaultSourceClassPathEntries(IPath projectFolder) { final IPath srcJava = projectFolder.append(Path.fromPortableString(SARLConfig.FOLDER_SOURCE_JAVA)); final IClasspathEntry srcJavaEntry = JavaCore.newSourceEntry(srcJava.makeAbsolute()); final IPath srcSarl = projectFolder.append(Path.fromPortableString(SARLConfig.FOLDER_SOURCE_SARL)); final IClasspathEntry srcSarlEntry = JavaCore.newSourceEntry(srcSarl.makeAbsolute()); final IPath srcGeneratedSources = projectFolder .append(Path.fromPortableString(SARLConfig.FOLDER_SOURCE_GENERATED)); final IClasspathAttribute attr = JavaCore .newClasspathAttribute(IClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS, Boolean.TRUE.toString()); final IClasspathEntry srcGeneratedSourcesEntry = JavaCore.newSourceEntry(srcGeneratedSources.makeAbsolute(), ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null /*output location*/, new IClasspathAttribute[] { attr }); final IPath srcResources = projectFolder.append(Path.fromPortableString(SARLConfig.FOLDER_RESOURCES)); final IClasspathEntry srcResourcesEntry = JavaCore.newSourceEntry(srcResources.makeAbsolute()); return Arrays.asList(srcSarlEntry, srcJavaEntry, srcResourcesEntry, srcGeneratedSourcesEntry); }
From source file:io.sarl.eclipse.natures.SARLProjectConfigurator.java
License:Apache License
private static List<CPListElement> buildClassPathEntries(IJavaProject project, IFolder[] sourcePaths, IFolder[] generationPaths) {/*from ww w. ja va 2s .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 ww w. jav a 2 s . 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.Utilities.java
License:Apache License
/** Create the classpath output location. * * @param bundle the bundle to point to. Never <code>null</code>. * @param precomputedBundlePath the path to the bundle that is already available. If <code>null</code>, * the path is computed from the bundle with {@link BundleUtil}. * @param javadocURLs the mappings from the bundle to the javadoc URL. It is used for linking the javadoc to the bundle if * the bundle platform does not know the Javadoc file. If <code>null</code>, no mapping is defined. * @return the classpath entry./*from w ww .ja va 2s .co m*/ */ public static IClasspathEntry newOutputClasspathEntry(Bundle bundle, IPath precomputedBundlePath, BundleURLMappings javadocURLs) { assert bundle != null; final IPath bundlePath; if (precomputedBundlePath == null) { bundlePath = BundleUtil.getBundlePath(bundle); } else { bundlePath = precomputedBundlePath; } final IPath sourceBundlePath = BundleUtil.getSourceBundlePath(bundle, bundlePath); final IPath javadocPath = BundleUtil.getJavadocBundlePath(bundle, bundlePath); final IClasspathAttribute[] extraAttributes; if (javadocPath == null) { if (javadocURLs != null) { final String url = javadocURLs.getURLForBundle(bundle); if (!Strings.isNullOrEmpty(url)) { final IClasspathAttribute attr = JavaCore .newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, url); extraAttributes = new IClasspathAttribute[] { attr }; } else { extraAttributes = ClasspathEntry.NO_EXTRA_ATTRIBUTES; } } else { extraAttributes = ClasspathEntry.NO_EXTRA_ATTRIBUTES; } } else { final IClasspathAttribute attr = JavaCore.newClasspathAttribute( IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, javadocPath.makeAbsolute().toOSString()); extraAttributes = new IClasspathAttribute[] { attr }; } return new ClasspathEntry(ClasspathEntry.K_OUTPUT, IClasspathEntry.CPE_LIBRARY, bundlePath, ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, sourceBundlePath, null, null, false, null, false, extraAttributes); }
From source file:org.codehaus.groovy.eclipse.core.model.GroovyRuntime.java
License:Apache License
/** * Adds a library/folder that already exists in the project to the * classpath. Only added if it is not already on the classpath. * * @param javaProject/* ww w . ja va2 s.co m*/ * The project to add add the classpath entry to. * @param libraryPath * The path to add to the classpath. * @param isExported TODO * @throws JavaModelException */ public static void addLibraryToClasspath(final IJavaProject javaProject, final IPath libraryPath, boolean isExported) throws JavaModelException { boolean alreadyExists = includesClasspathEntry(javaProject, libraryPath.lastSegment()); if (alreadyExists) { return; } addClassPathEntry(javaProject, new ClasspathEntry(IPackageFragmentRoot.K_BINARY, IClasspathEntry.CPE_CONTAINER, libraryPath, ClasspathEntry.INCLUDE_ALL, // inclusion patterns ClasspathEntry.EXCLUDE_NONE, // exclusion patterns null, null, null, // specific output folder true, // exported ClasspathEntry.NO_ACCESS_RULES, false, // no access rules to // combine ClasspathEntry.NO_EXTRA_ATTRIBUTES)); }