List of usage examples for org.eclipse.jdt.core IClasspathEntry getContentKind
int getContentKind();
From source file:de.ovgu.featureide.ahead.actions.FeatureHouseToAHEADConversion.java
License:Open Source License
/** * Set the source path of given <code>ClasspathEntry</code> to the current build path * @param e The entry to set/*from ww w .j a va2 s. c om*/ * @return The entry with the new source path */ public IClasspathEntry setSourceEntry(IClasspathEntry e) { return new ClasspathEntry(e.getContentKind(), e.getEntryKind(), featureProject.getBuildFolder().getFullPath(), e.getInclusionPatterns(), e.getExclusionPatterns(), e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes()); }
From source file:de.ovgu.featureide.aspectj.AspectJComposer.java
License:Open Source License
/** * Set the unselected aspect files to be excluded * @param e The ClasspathEntry to set/*from www . ja v a2 s.c o m*/ * @return The set entry */ private IClasspathEntry setSourceEntry(IClasspathEntry e) { IPath[] excludedAspects = new IPath[unSelectedFeatures.size()]; int i = 0; for (String f : unSelectedFeatures) { excludedAspects[i++] = new Path(f.replaceAll("_", "/") + ".aj"); } return new ClasspathEntry(e.getContentKind(), e.getEntryKind(), e.getPath(), e.getInclusionPatterns(), excludedAspects, e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes()); }
From source file:de.ovgu.featureide.core.builder.ComposerExtensionClass.java
License:Open Source License
/** * Set the source path of the given <code>ClasspathEntry</code> * @param buildPath The new build path//from ww w .j a v a2 s .c o m * @param e The entry to set * @return The entry with the new source path */ public IClasspathEntry setSourceEntry(String buildPath, IClasspathEntry e) { return new ClasspathEntry(e.getContentKind(), e.getEntryKind(), new Path(buildPath), e.getInclusionPatterns(), e.getExclusionPatterns(), e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes()); }
From source file:de.ovgu.featureide.core.mpl.job.MPLRenameExternalJob.java
License:Open Source License
private static IPath setJavaBuildPath(JavaProject javaProject, IPath path, int index) { try {/*w w w . ja v a 2s . c o m*/ final IClasspathEntry[] classpathEntrys = javaProject.getRawClasspath(); if (index >= 0) { final IClasspathEntry e = classpathEntrys[index]; if (!e.getPath().equals(path)) { final IPath formerSourcePath = e.getPath(); classpathEntrys[index] = new ClasspathEntry(e.getContentKind(), e.getEntryKind(), path, e.getInclusionPatterns(), e.getExclusionPatterns(), e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes()); javaProject.setRawClasspath(classpathEntrys, null); return formerSourcePath; } } else { final IClasspathEntry[] newEntrys = new IClasspathEntry[classpathEntrys.length + 1]; System.arraycopy(classpathEntrys, 0, newEntrys, 0, classpathEntrys.length); newEntrys[newEntrys.length - 1] = new ClasspathEntry(IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_SOURCE, path, new IPath[0], new IPath[0], null, null, null, false, null, false, new IClasspathAttribute[0]); javaProject.setRawClasspath(newEntrys, null); } } catch (JavaModelException e) { MPLPlugin.getDefault().logError(e); } return null; }
From source file:de.ovgu.featureide.core.mpl.job.MPLRenameExternalJob.java
License:Open Source License
private static void resetJavaBuildPath(JavaProject javaProject, IPath formerSourcePath, int formerSourcePathIndex) { try {/*from ww w . j av a2s . c o m*/ final IClasspathEntry[] classpathEntrys = javaProject.getRawClasspath(); if (formerSourcePath != null) { final IClasspathEntry e = classpathEntrys[formerSourcePathIndex]; classpathEntrys[formerSourcePathIndex] = new ClasspathEntry(e.getContentKind(), e.getEntryKind(), formerSourcePath, e.getInclusionPatterns(), e.getExclusionPatterns(), e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes()); javaProject.setRawClasspath(classpathEntrys, null); } else if (formerSourcePathIndex == -1) { final IClasspathEntry[] newEntrys = new IClasspathEntry[classpathEntrys.length - 1]; System.arraycopy(classpathEntrys, 0, newEntrys, 0, newEntrys.length); javaProject.setRawClasspath(newEntrys, null); } } catch (JavaModelException e) { MPLPlugin.getDefault().logError(e); } }
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 2 s. co m*/ 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. c om */ // 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:io.sarl.eclipse.util.JavaClasspathParser.java
License:Apache License
/** * Reads and decode an XML classpath string. Returns a two-dimensional array, where the number of elements in the row is fixed to 2. The first * element is an array of raw classpath entries and the second element is an array of referenced entries that may have been stored by the client * earlier. See {@link IJavaProject#getReferencedClasspathEntries()} for more details. * * @param projectName/*w w w . j a v a 2 s . com*/ * - the name of project containing the .classpath file * @param projectRootAbsoluteFullPath * - the path to project containing the .classpath file * @param xmlClasspath * - path to the XML * @param unknownElements * - map of unknow elements * @return the set of CLasspath ENtries extracted from the .classpath * @throws IOException * - exception during parsing of .classpath * @throws ClasspathEntry.AssertionFailedException * - exception during parsing of .classpath */ @SuppressWarnings("checkstyle:npathcomplexity") public static IClasspathEntry[][] decodeClasspath(String projectName, IPath projectRootAbsoluteFullPath, String xmlClasspath, Map<IPath, UnknownXmlElements> unknownElements) throws IOException, ClasspathEntry.AssertionFailedException { final List<IClasspathEntry> paths = new ArrayList<>(); IClasspathEntry defaultOutput = null; final Element cpElement; try (StringReader reader = new StringReader(xmlClasspath);) { final DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); cpElement = parser.parse(new InputSource(reader)).getDocumentElement(); } catch (SAXException e) { throw new IOException(Messages.file_badFormat); } catch (ParserConfigurationException e) { throw new IOException(Messages.file_badFormat); } if (!cpElement.getNodeName().equalsIgnoreCase("classpath")) { //$NON-NLS-1$ throw new IOException(Messages.file_badFormat); } NodeList list = cpElement.getElementsByTagName(ClasspathEntry.TAG_CLASSPATHENTRY); int length = list.getLength(); for (int i = 0; i < length; ++i) { final Node node = list.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { final IClasspathEntry entry = elementDecode((Element) node, projectName, projectRootAbsoluteFullPath, unknownElements); if (entry != null) { if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) { // separate output defaultOutput = entry; } else { paths.add(entry); } } } } final int pathSize = paths.size(); final IClasspathEntry[][] entries = new IClasspathEntry[2][]; entries[0] = new IClasspathEntry[pathSize + (defaultOutput == null ? 0 : 1)]; paths.toArray(entries[0]); if (defaultOutput != null) { // ensure output is last item entries[0][pathSize] = defaultOutput; } paths.clear(); list = cpElement.getElementsByTagName(ClasspathEntry.TAG_REFERENCED_ENTRY); length = list.getLength(); for (int i = 0; i < length; ++i) { final Node node = list.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { final IClasspathEntry entry = elementDecode((Element) node, projectName, projectRootAbsoluteFullPath, unknownElements); if (entry != null) { paths.add(entry); } } } entries[1] = new IClasspathEntry[paths.size()]; paths.toArray(entries[1]); return entries; }
From source file:net.sf.jasperreports.eclipse.classpath.OutputFolderClassLoader.java
License:Open Source License
private byte[] loadClassData(String className, IJavaProject javaProject) throws Exception { IPath defaultLocationPath = javaProject.getOutputLocation(); IWorkspaceRoot wsRoot = javaProject.getProject().getWorkspace().getRoot(); IFolder folder = wsRoot.getFolder(defaultLocationPath); String prjDefaultLocation = folder.getLocation().toOSString(); byte[] classBytes = loadClassFile(prjDefaultLocation + "/" + className.replaceAll("\\.", "/") + ".class"); if (classBytes == null) { // Iterate over the (possible) output locations of the sourcefolder classpath entries IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); for (IClasspathEntry e : classpathEntries) { if (e.getContentKind() == IPackageFragmentRoot.K_SOURCE) { IPath entryOutputLocation = e.getOutputLocation(); if (entryOutputLocation != null) { IFolder entryOutputFolder = wsRoot.getFolder(entryOutputLocation); classBytes = loadClassFile( entryOutputFolder + "/" + className.replaceAll("\\.", "/") + ".class"); if (classBytes != null) break; }/* www . j a v a 2 s . c om*/ } } } return classBytes; }
From source file:no.javatime.inplace.bundleproject.ProjectProperties.java
License:Open Source License
/** * Finds all source class path entries and return the relative path of source folders * //from w w w . ja v a2 s .c o m * @param project with source folders * @return source folders or an empty collection * @throws JavaModelException when accessing the project resource or the class path element does not exist * @throws InPlaceException if the project could not be accessed */ public static Collection<IPath> getJavaProjectSourceFolders(IProject project) throws JavaModelException, InPlaceException { ArrayList<IPath> paths = new ArrayList<IPath>(); IJavaProject javaProject = getJavaProject(project); IClasspathEntry[] classpathEntries = javaProject.getResolvedClasspath(true); for (int i = 0; i < classpathEntries.length; i++) { IClasspathEntry entry = classpathEntries[i]; if (entry.getContentKind() == IPackageFragmentRoot.K_SOURCE) { IPath path = entry.getPath(); String segment = path.segment(path.segmentCount() - 1); if (null != segment) { paths.add(new Path(segment)); } } } return paths; }