List of usage examples for org.eclipse.jdt.core IClasspathEntry getPath
IPath getPath();
From source file:de.ovgu.featureide.migration.impl.DefaultSPLMigrator.java
License:Open Source License
/** * @param project/*from w w w .java 2 s .co m*/ * @param destinationPath * @param classpathToMigrate */ private void migrateSourceFiles(IProject project, IPath destinationPath, IClasspathEntry[] classpathToMigrate) { IPath relativeDestinationPath = ((IPath) destinationPath.clone()).makeRelativeTo(newProject.getFullPath()); System.out.println( "migrate source destination: " + destinationPath + " relative: " + relativeDestinationPath); IFolder destination = newProject.getFolder(relativeDestinationPath); for (IClasspathEntry entry : classpathToMigrate) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { try { IPath relativeSourcePath = entry.getPath().makeRelativeTo(project.getFullPath()); IFolder source = project.getFolder(relativeSourcePath); SPLMigrationUtils.recursiveCopyFiles(source, destination); newProject.refreshLocal(IProject.DEPTH_INFINITE, null); } catch (CoreException e) { CorePlugin.getDefault().logError(e); e.printStackTrace(); } } } }
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/*from w w w. j av a 2 s. 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:de.ovgu.featureide.ui.wizards.ConversionPage.java
License:Open Source License
/** * Set the build path to the java projects build path */// w w w . jav a 2s.co m private void setBuildPath() { try { if (p.hasNature(JAVA_NATURE)) { JavaProject javaProject = new JavaProject(p, null); for (IClasspathEntry entry : javaProject.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { String path = entry.getPath().toOSString(); if (path.contains("\\")) path = path.substring(path.indexOf('\\') + 1); if (path.contains("\\")) path = path.substring(path.indexOf('\\') + 1); buildPath.setText(path); buildPath.setEnabled(false); buildLabel.setToolTipText(MESSAGE); return; } } } } catch (CoreException e) { UIPlugin.getDefault().logError(e); } }
From source file:de.ovgu.featureide.ui.wizards.FeatureCProjectPage.java
License:Open Source License
/** * Set the build path to the java projects build path *//* w w w . j a v a 2 s .c o m*/ private void setBuildPath() { try { if (project.hasNature(JAVA_NATURE)) { JavaProject javaProject = new JavaProject(project, null); for (IClasspathEntry entry : javaProject.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { String path = entry.getPath().toOSString(); String fileSeparator = System.getProperty("file.separator"); if (path.contains(fileSeparator)) path = path.substring(path.indexOf(fileSeparator) + 1); if (path.contains(fileSeparator)) path = path.substring(path.indexOf(fileSeparator) + 1); buildPath.setText(path); buildPath.setEnabled(false); buildLabel.setToolTipText(MESSAGE); return; } } } } catch (CoreException e) { UIPlugin.getDefault().logError(e); } }
From source file:de.se_rwth.langeditor.modelpath.ModelPathContainerPage.java
License:Open Source License
private Table createTable(Composite parent) { Table table = new Table(parent, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION); table.setHeaderVisible(true);/*from ww w .j a v a 2 s .c o m*/ GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); table.setLayoutData(data); TableColumn column = new TableColumn(table, SWT.NONE); column.setText("Modelpath entries"); for (IClasspathEntry classpathEntry : modelPathEntries) { createTableItem(table, classpathEntry.getPath().toOSString()); } column.pack(); return table; }
From source file:de.se_rwth.langeditor.util.ResourceLocator.java
License:Open Source License
public static ImmutableList<Path> assembleModelPath(IProject project) { ImmutableList.Builder<Path> builder = ImmutableList.builder(); for (IClasspathEntry classpathEntry : getModelPathEntries(JavaCore.create(project))) { builder.add(classpathEntry.getPath().toFile().toPath()); }/*from ww w. ja v a2 s. c o m*/ return builder.build(); }
From source file:de.se_rwth.langeditor.util.ResourceLocator.java
License:Open Source License
private static Map<IPackageFragmentRoot, IProject> getPackageFragmentRootsOnModelPath() { Map<IPackageFragmentRoot, IProject> packageFragmentRoots = new HashMap<>(); for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) { IJavaProject javaProject = JavaCore.create(project); try {// www. j av a 2 s. c o m for (IClasspathEntry entry : getModelPathEntries(javaProject)) { Optional.ofNullable(javaProject.findPackageFragmentRoot(entry.getPath())).ifPresent( packageFragmentRoot -> packageFragmentRoots.put(packageFragmentRoot, project)); } } catch (JavaModelException e) { continue; } } return packageFragmentRoots; }
From source file:de.tobject.findbugs.builder.FindBugsWorker.java
License:Open Source License
/** * @return map of all source folders to output folders, for current java * project, where both are represented by absolute IPath objects * * @throws CoreException// w w w. j ava2s. c o m */ private Map<IPath, IPath> createOutputLocations() throws CoreException { Map<IPath, IPath> srcToOutputMap = new HashMap<IPath, IPath>(); // get the default location => relative to wsp IPath defaultOutputLocation = ResourceUtils.relativeToAbsolute(javaProject.getOutputLocation()); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); // path to the project without project name itself IClasspathEntry entries[] = javaProject.getResolvedClasspath(true); for (int i = 0; i < entries.length; i++) { IClasspathEntry classpathEntry = entries[i]; if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputLocation = ResourceUtils.getOutputLocation(classpathEntry, defaultOutputLocation); if (outputLocation == null) { continue; } IResource cpeResource = root.findMember(classpathEntry.getPath()); // patch from 2891041: do not analyze derived "source" folders // because they probably contain auto-generated classes if (cpeResource != null && cpeResource.isDerived()) { continue; } // TODO not clear if it is absolute in workspace or in global FS IPath srcLocation = ResourceUtils.relativeToAbsolute(classpathEntry.getPath()); if (srcLocation != null) { srcToOutputMap.put(srcLocation, outputLocation); } } } return srcToOutputMap; }
From source file:de.tobject.findbugs.builder.PDEClassPathGenerator.java
License:Open Source License
@SuppressWarnings("restriction") private static Set<String> createJavaClasspath(IJavaProject javaProject, Set<IProject> projectOnCp) { LinkedHashSet<String> classPath = new LinkedHashSet<String>(); try {//from w w w . j av a 2s. c o m // doesn't return jre libraries String[] defaultClassPath = JavaRuntime.computeDefaultRuntimeClassPath(javaProject); for (String classpathEntry : defaultClassPath) { IPath path = new Path(classpathEntry); if (isValidPath(path)) { classPath.add(path.toOSString()); } } // add CPE_CONTAINER classpathes IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); for (IClasspathEntry entry : rawClasspath) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(entry.getPath(), javaProject); if (classpathContainer != null) { if (classpathContainer instanceof JREContainer) { IClasspathEntry[] classpathEntries = classpathContainer.getClasspathEntries(); for (IClasspathEntry iClasspathEntry : classpathEntries) { IPath path = iClasspathEntry.getPath(); // smallest possible fix for #1228 Eclipse plugin always uses host VM to resolve JDK classes if (isValidPath(path) && "rt.jar".equals(path.lastSegment())) { classPath.add(path.toOSString()); break; } } } else { IClasspathEntry[] classpathEntries = classpathContainer.getClasspathEntries(); for (IClasspathEntry classpathEntry : classpathEntries) { IPath path = classpathEntry.getPath(); // shortcut for real files if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && isValidPath(path)) { classPath.add(path.toOSString()); } else { resolveInWorkspace(classpathEntry, classPath, projectOnCp); } } } } } } } catch (CoreException e) { FindbugsPlugin.getDefault().logException(e, "Could not compute aux. classpath for project " + javaProject); } return classPath; }
From source file:de.tobject.findbugs.builder.PDEClassPathGenerator.java
License:Open Source License
private static void resolveInWorkspace(IClasspathEntry classpathEntry, Set<String> classPath, Set<IProject> projectOnCp) { int entryKind = classpathEntry.getEntryKind(); switch (entryKind) { case IClasspathEntry.CPE_PROJECT: Set<String> cp = resolveProjectClassPath(classpathEntry.getPath(), projectOnCp); classPath.addAll(cp);/*from w ww . j a v a 2s.c om*/ break; case IClasspathEntry.CPE_VARIABLE: classpathEntry = JavaCore.getResolvedClasspathEntry(classpathEntry); if (classpathEntry == null) { return; } //$FALL-THROUGH$ case IClasspathEntry.CPE_LIBRARY: String lib = resolveLibrary(classpathEntry.getPath()); if (lib != null) { classPath.add(lib); } break; case IClasspathEntry.CPE_SOURCE: // ??? break; default: break; } }