List of usage examples for org.eclipse.jdt.core IClasspathEntry getExtraAttributes
IClasspathAttribute[] getExtraAttributes();
From source file:de.ovgu.featureide.featurehouse.FeatureHouseComposer.java
License:Open Source License
/** * Sets the Java build path to the folder at the build folder, named like the current configuration. * @param buildPath The name of the current configuration *///from w w w .j a v a 2s . c om private void setJavaBuildPath(String buildPath) { try { JavaProject javaProject = new JavaProject(featureProject.getProject(), null); IClasspathEntry[] classpathEntrys = javaProject.getRawClasspath(); int i = 0; for (IClasspathEntry e : classpathEntrys) { if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath path = featureProject.getBuildFolder().getFolder(buildPath).getFullPath(); /** return if nothing has to be changed **/ if (e.getPath().equals(path)) { return; } /** change the actual source entry to the new build path **/ ClasspathEntry changedEntry = new ClasspathEntry(e.getContentKind(), e.getEntryKind(), path, e.getInclusionPatterns(), e.getExclusionPatterns(), e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes()); classpathEntrys[i] = changedEntry; javaProject.setRawClasspath(classpathEntrys, null); return; } i++; } /** case: there is no source entry at the class path * add the source entry to the classpath **/ IFolder folder = featureProject.getBuildFolder().getFolder(buildPath); ClasspathEntry sourceEntry = new ClasspathEntry(IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_SOURCE, folder.getFullPath(), new IPath[0], new IPath[0], null, null, null, false, null, false, new IClasspathAttribute[0]); IClasspathEntry[] newEntrys = new IClasspathEntry[classpathEntrys.length + 1]; System.arraycopy(classpathEntrys, 0, newEntrys, 0, classpathEntrys.length); newEntrys[newEntrys.length - 1] = sourceEntry; javaProject.setRawClasspath(newEntrys, null); } catch (JavaModelException e) { FeatureHouseCorePlugin.getDefault().logError(e); } }
From source file:de.ovgu.featureide.ui.actions.generator.Generator.java
License:Open Source License
/** * Sets the classpath entries for the newly created project * @param p The new project/* w w w.j a v a 2s. co m*/ */ // TODO remove redundant calculations for each configuration // TODO copy settings private void setClassPath(IProject p) { JavaProject baseProject = new JavaProject(builder.featureProject.getProject(), null); JavaProject newProject = new JavaProject(p, null); try { IClasspathEntry[] entries = baseProject.getRawClasspath().clone(); for (int i = 0; i < entries.length; i++) { // set source entry to "src" IClasspathEntry e = entries[i]; if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { entries[i] = new ClasspathEntry(e.getContentKind(), e.getEntryKind(), new Path("src"), e.getInclusionPatterns(), e.getExclusionPatterns(), e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes()); } else if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { // set the library entries and copy the libraries // which are direct at the old projects folder IPath path = e.getPath().removeFirstSegments(1); IProject project = builder.featureProject.getProject(); IFile file = project.getFile(path); if (!file.exists()) { path = e.getPath(); file = project.getFile(path); if (!file.exists()) { continue; } } createLibFolder(p.getFile(path).getParent()); file.copy(p.getFile(e.getPath().removeFirstSegments(1)).getFullPath(), true, null); entries[i] = new ClasspathEntry(e.getContentKind(), e.getEntryKind(), e.getPath().removeFirstSegments(1), e.getInclusionPatterns(), e.getExclusionPatterns(), e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes()); } } newProject.setRawClasspath(entries, null); } catch (JavaModelException e) { UIPlugin.getDefault().logError(e); } catch (CoreException e) { UIPlugin.getDefault().logError(e); } }
From source file:edu.brown.cs.bubbles.bedrock.BedrockProject.java
License:Open Source License
private void addPath(IvyXmlWriter xw, IJavaProject jp, IClasspathEntry ent, boolean nest) { IPath p = ent.getPath();//www . j a v a 2 s .co m IPath op = ent.getOutputLocation(); IPath sp = ent.getSourceAttachmentPath(); IProject ip = jp.getProject(); String jdp = null; boolean opt = false; IClasspathAttribute[] atts = ent.getExtraAttributes(); for (IClasspathAttribute att : atts) { if (att.getName().equals(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME)) jdp = att.getValue(); else if (att.getName().equals(IClasspathAttribute.OPTIONAL)) { String v = att.getValue(); if (v.equals("true")) opt = true; } } if (p == null && op == null) return; File f1 = null; if (p != null) { f1 = BedrockUtil.getFileForPath(p, ip); if (!f1.exists()) { BedrockPlugin.logD("Path file " + p + " not found as " + f1); // f1 = null; } } File f2 = null; if (op != null) { f2 = BedrockUtil.getFileForPath(op, ip); if (!f2.exists()) { BedrockPlugin.logD("Path file " + op + " not found"); f2 = null; } } File f3 = null; if (sp != null) { f3 = BedrockUtil.getFileForPath(sp, ip); if (!f3.exists()) { BedrockPlugin.logD("Path file " + sp + " not found"); f3 = null; } } if (f1 == null && f2 == null) return; // references to nested projects are handled in addClassPaths if (ent.getEntryKind() == IClasspathEntry.CPE_PROJECT) return; xw.begin("PATH"); xw.field("ID", ent.hashCode()); if (nest) xw.field("NESTED", "TRUE"); switch (ent.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: xw.field("TYPE", "SOURCE"); f3 = f1; f1 = null; break; case IClasspathEntry.CPE_PROJECT: xw.field("TYPE", "BINARY"); break; case IClasspathEntry.CPE_LIBRARY: xw.field("TYPE", "LIBRARY"); break; } if (ent.isExported()) xw.field("EXPORTED", true); if (opt) xw.field("OPTIONAL", true); if (f1 != null) xw.textElement("BINARY", f1.getAbsolutePath()); if (f2 != null) xw.textElement("OUTPUT", f2.getAbsolutePath()); if (f3 != null) xw.textElement("SOURCE", f3.getAbsolutePath()); if (jdp != null) xw.textElement("JAVADOC", jdp); IAccessRule[] rls = ent.getAccessRules(); for (IAccessRule ar : rls) { xw.begin("ACCESS"); xw.field("KIND", ar.getKind()); xw.field("PATTERN", ar.getPattern().toString()); xw.field("IGNOREIFBETTER", ar.ignoreIfBetter()); xw.end("ACCESS"); } xw.end("PATH"); }
From source file:me.gladwell.eclipse.m2e.android.configuration.JavadocsEntryAttacher.java
License:Open Source License
public boolean isAttached(IClasspathEntry entry) { ClasspathAttributes attributes = new ClasspathAttributes(entry.getExtraAttributes()); return attributes.hasAttribute(JAVADOC_LOCATION_ATTRIBUTE_NAME); }
From source file:me.gladwell.eclipse.m2e.android.configuration.JavadocsEntryAttacher.java
License:Open Source License
public IClasspathEntry attach(IClasspathEntry entry, Artifact docs) { try {//from ww w . ja va2 s.c om ClasspathAttributes attributes = new ClasspathAttributes(entry.getExtraAttributes()); attributes.set(newClasspathAttribute(JAVADOC_LOCATION_ATTRIBUTE_NAME, getJavaDocUrl(docs.getFile()))); IClasspathEntry entryWithDocs = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(), null, entry.getAccessRules(), attributes.toArray(), entry.isExported()); return entryWithDocs; } catch (Exception e) { throw new ProjectConfigurationException(e); } }
From source file:me.gladwell.eclipse.m2e.android.configuration.SourcesEntryAttacher.java
License:Open Source License
public IClasspathEntry attach(IClasspathEntry entry, Artifact sources) { return JavaCore.newLibraryEntry(entry.getPath(), Path.fromOSString(sources.getFile().getAbsolutePath()), null, entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported()); }
From source file:me.gladwell.eclipse.m2e.android.test.DownloadSourcesAndJavadocTest.java
License:Open Source License
private Matcher<IClasspathEntry> hasExtraAttribute(final String expected) { return new BaseMatcher<IClasspathEntry>() { @Override/*from www . j ava2 s.c o m*/ public boolean matches(Object target) { IClasspathEntry entry = (IClasspathEntry) target; for (IClasspathAttribute attribute : entry.getExtraAttributes()) { if (attribute.getName().equals(expected)) return true; } return false; } @Override public void describeTo(Description d) { d.appendText("entry with expected attribute '"); d.appendText(expected); d.appendText("'"); } }; }
From source file:monolipse.core.internal.BooNature.java
License:Open Source License
private Map<IClasspathEntry, IClasspathEntry> addExclusionPatternsTo(IClasspathEntry[] classpath) { Map<IClasspathEntry, IClasspathEntry> modified = new HashMap<IClasspathEntry, IClasspathEntry>(); for (int i = 0; i < classpath.length; i++) { IClasspathEntry entry = classpath[i]; if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) continue; IPath[] exclusionPatterns = entry.getExclusionPatterns(); IPath[] newExclusionPatterns = addExclusionPatternsTo(exclusionPatterns); if (exclusionPatterns == newExclusionPatterns) continue; IClasspathEntry newSourceEntry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(), newExclusionPatterns, entry.getOutputLocation(), entry.getExtraAttributes()); modified.put(entry, newSourceEntry); }// w w w . j ava 2 s . co m return modified; }
From source file:net.rim.ejde.internal.util.ImportUtils.java
License:Open Source License
/** * Applies the Java Path exclusion patterns to a given project and returns the list of filtered IClasspathEntry * * @param eclipseProject/* w w w. j ava 2s .c o m*/ * @param legacyProject * @param originalClasspathEntries * @return */ static public List<IClasspathEntry> applyExclusionPatterns(IProject eclipseProject, Project legacyProject, List<IClasspathEntry> originalClasspathEntries) { if (null == eclipseProject) { throw new IllegalArgumentException("Can't process undefined Eclipse project!"); } if (null == legacyProject) { throw new IllegalArgumentException("Can't process undefined legacy project!"); } if (null == originalClasspathEntries) { throw new IllegalArgumentException("Can't process undefined Eclipse classpath entries!"); } // TODO: call this when importing projects, rather than from the // Compilation Participant List<WorkspaceFile> excludedWorkspaceFiles = getFilesToBeExcluded(legacyProject); if (excludedWorkspaceFiles.isEmpty() && originalClasspathEntries.isEmpty()) { return originalClasspathEntries; } List<IClasspathEntry> excludedClasspathEntries = new ArrayList<IClasspathEntry>(); HashMap<IPath, IClasspathEntry> filterMap = new HashMap<IPath, IClasspathEntry>(); String projectNamePattern = IPath.SEPARATOR + eclipseProject.getName() + IPath.SEPARATOR; List<IPath> exclusionPatterns; IPath classpathEntryPath, exclusionPatternPath; boolean forProject; String lastSegment; IFolder folder; IPath srcLocation; IClasspathEntry newEntry; IPath[] excludedPaths; File file; String workspaceFilePath; String packageId; for (IClasspathEntry entry : originalClasspathEntries) { exclusionPatterns = new ArrayList<IPath>(); classpathEntryPath = entry.getPath(); if (IClasspathEntry.CPE_SOURCE == entry.getEntryKind()) { lastSegment = classpathEntryPath.lastSegment(); if (lastSegment.equalsIgnoreCase( ImportUtils.getImportPref(ResourceBuilder.LOCALE_INTERFACES_FOLDER_NAME))) { continue; } folder = eclipseProject.getFolder(lastSegment); if (folder.isDerived() || !folder.exists()) { continue; } forProject = classpathEntryPath.toString().startsWith(projectNamePattern); if (forProject) { srcLocation = folder.getLocation(); if (srcLocation == null || srcLocation.isEmpty()) { return originalClasspathEntries; } for (WorkspaceFile workspaceFile : excludedWorkspaceFiles) { workspaceFilePath = workspaceFile.toString(); file = workspaceFile.getFile(); if (null != file && file.exists() && file.isFile()) { // Fix for IDT 149988 - Check type of source folder and file type to prevent duplication for exclusion // patterns if (lastSegment.equalsIgnoreCase( ImportUtils.getImportPref(LegacyImportHelper.PROJECT_SRC_FOLDER_NAME_KEY))) { if (!workspaceFile.getIsJava()) { continue; } } else { if (workspaceFile.getIsJava()) { continue; } } if (workspaceFile.getIsJava() || workspaceFile.getIsResourceHeader() || workspaceFile.getIsResource()) { packageId = IConstants.EMPTY_STRING; try { packageId = PackageUtils.getFilePackageString(file, legacyProject); } catch (CoreException e) { _log.error(e.getMessage()); packageId = IConstants.EMPTY_STRING; } workspaceFilePath = File.separator + packageId + File.separator + workspaceFilePath; } exclusionPatternPath = getExclusionPattern(workspaceFile, lastSegment, eclipseProject, legacyProject); if (!exclusionPatternPath.isEmpty()) { exclusionPatterns.add(exclusionPatternPath); } } } } if (exclusionPatterns.isEmpty()) { excludedPaths = new IPath[] {}; } else { excludedPaths = exclusionPatterns.toArray(new IPath[exclusionPatterns.size()]); } newEntry = JavaCore.newSourceEntry(classpathEntryPath, entry.getInclusionPatterns(), excludedPaths, entry.getOutputLocation(), entry.getExtraAttributes()); filterMap.put(classpathEntryPath, newEntry); } else {// IClasspathEntry of type other than CPE_SOURCE filterMap.put(classpathEntryPath, entry); } } IPath elementPath; for (IClasspathEntry element : originalClasspathEntries) { elementPath = element.getPath(); newEntry = filterMap.get(elementPath); if (null != newEntry) { excludedClasspathEntries.add(newEntry); } } return excludedClasspathEntries; }
From source file:net.sourceforge.eclipsejetty.launch.JettyLaunchClasspathMatcher.java
License:Apache License
/** * Matches all entries, that contain the specified attribute. * /*from w ww. j a va2 s.co m*/ * @param name the name, regular expression * @param value the value, regular expression * @return all matching entries */ public static JettyLaunchClasspathMatcher withExtraAttribute(String name, String value) { final RegularMatcher nameMatcher = new RegularMatcher(name); final RegularMatcher valueMatcher = new RegularMatcher(value); return new JettyLaunchClasspathMatcher() { @Override public Collection<IRuntimeClasspathEntry> match(Collection<IRuntimeClasspathEntry> entries) { Iterator<IRuntimeClasspathEntry> iterator = entries.iterator(); entry: while (iterator.hasNext()) { IRuntimeClasspathEntry entry = iterator.next(); IClasspathEntry classpathEntry = entry.getClasspathEntry(); if (classpathEntry == null) { iterator.remove(); continue; } IClasspathAttribute[] extraAttributes = classpathEntry.getExtraAttributes(); for (IClasspathAttribute extraAttribute : extraAttributes) { if ((nameMatcher.matches(extraAttribute.getName())) && (valueMatcher.matches(extraAttribute.getValue()))) { continue entry; } } iterator.remove(); } return entries; } @Override public String toString() { return "mavenTestScope"; } }; }