List of usage examples for org.eclipse.jdt.core IJavaProject getPath
IPath getPath();
From source file:org.eclipse.pde.internal.ui.wizards.plugin.NewLibraryPluginCreationOperation.java
License:Open Source License
/** * @return updated classpath or null if there were no changes *//* w ww . ja va 2 s .co m*/ private IClasspathEntry[] getUpdatedClasspath(IClasspathEntry[] cp, IJavaProject currentProject) { boolean exposed = false; int refIndex = -1; List<IClasspathEntry> result = new ArrayList<IClasspathEntry>(); Set<Manifest> manifests = new HashSet<Manifest>(); for (int i = 0; i < fData.getLibraryPaths().length; ++i) { try { manifests.add(new JarFile(fData.getLibraryPaths()[i]).getManifest()); } catch (IOException e) { PDEPlugin.log(e); } } IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); for (int i = 0; i < cp.length; ++i) { IClasspathEntry cpe = cp[i]; switch (cpe.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: String path = null; IPath location = root.getFile(cpe.getPath()).getLocation(); if (location != null) { path = location.toString(); } //try maybe path is absolute if (path == null) { path = cpe.getPath().toString(); } JarFile jarFile = null; try { jarFile = new JarFile(path); if (manifests.contains(jarFile.getManifest())) { if (refIndex < 0) { // allocate slot refIndex = result.size(); result.add(null); } exposed |= cpe.isExported(); } else { result.add(cpe); } } catch (IOException e) { PDEPlugin.log(e); } finally { if (jarFile != null) { try { jarFile.close(); } catch (IOException e) { PDEPlugin.log(e); } } } break; default: result.add(cpe); break; } } if (refIndex >= 0) { result.set(refIndex, JavaCore.newProjectEntry(currentProject.getPath(), exposed)); return result.toArray(new IClasspathEntry[result.size()]); } return null; }
From source file:org.eclipse.recommenders.internal.coordinates.rcp.EclipseDependencyListenerTest.java
License:Open Source License
private static void appendJavaProjectToClasspath(IJavaProject javaProject, IJavaProject dependency) throws Exception { IClasspathEntry sourceEntry = JavaCore.newProjectEntry(dependency.getPath()); javaProject.setRawClasspath(concat(javaProject.getRawClasspath(), sourceEntry), new NullProgressMonitor()); }
From source file:org.eclipse.recommenders.models.dependencies.rcp.EclipseDependencyListener.java
License:Open Source License
public static DependencyInfo createDependencyInfoForProject(final IJavaProject project) { File file = project.getPath().toFile(); DependencyInfo dependencyInfo = new DependencyInfo(file, DependencyType.PROJECT); return dependencyInfo; }
From source file:org.eclipse.virgo.ide.jdt.internal.core.classpath.ServerClasspathContainerInitializer.java
License:Open Source License
/** * {@inheritDoc}// w w w. ja v a 2 s . co m */ @Override public Object getComparisonID(IPath containerPath, IJavaProject project) { if (containerPath == null || project == null) { return null; } return containerPath.segment(0) + "/" + project.getPath().segment(0); //$NON-NLS-1$ }
From source file:org.eclipse.wb.internal.core.utils.jdt.core.ProjectUtils.java
License:Open Source License
/** * Requires <code>requiredProject</code> in <code>project</code>. *//* ww w.j a v a2s. co m*/ public static void requireProject(IJavaProject project, IJavaProject requiredProject) throws JavaModelException { IClasspathEntry[] rawClasspath = project.getRawClasspath(); rawClasspath = (IClasspathEntry[]) ArrayUtils.add(rawClasspath, JavaCore.newProjectEntry(requiredProject.getPath())); project.setRawClasspath(rawClasspath, null); }
From source file:org.eclipse.wb.internal.core.utils.jdt.ui.ProjectSelectionDialogField.java
License:Open Source License
/** * @return string presentation of {@link IJavaProject}.. *//*from w w w.j a va 2 s. co m*/ private static String getProjectString(IJavaProject project) { return project == null ? "" : project.getPath().makeRelative().toString(); }
From source file:org.eclipse.xtend.ide.tests.macros.JdtBasedProcessorProviderTest.java
License:Open Source License
private IJavaProject xtendProject(final String name, final IJavaProject... upstreamProjects) { try {/*from w ww . java2 s . c o m*/ final IJavaProject result = JavaProjectSetupUtil.createJavaProject(name); IResourcesSetupUtil.addNature(result.getProject(), XtextProjectHelper.NATURE_ID); this.xtendLibs.addLibsToClasspath(result, null); final Consumer<IJavaProject> _function = (IJavaProject it) -> { try { JavaProjectSetupUtil.addToClasspath(result, JavaCore.newProjectEntry(it.getPath(), true)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }; ((List<IJavaProject>) Conversions.doWrapArray(upstreamProjects)).forEach(_function); return result; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
From source file:org.eclipse.xtend.shared.ui.Activator.java
License:Open Source License
public static ExecutionContext getExecutionContext(final IJavaProject project) { final IXtendXpandProject xp = Activator.getExtXptModelManager().findProject(project.getPath()); final ExecutionContextImpl ctx = new XpandPluginExecutionContext(xp); final List<? extends MetamodelContributor> contr = MetamodelContributorRegistry .getActiveMetamodelContributors(project); for (MetamodelContributor contributor : contr) { final MetaModel[] metamodels = contributor.getMetamodels(project, ctx); for (int i = 0; i < metamodels.length; i++) { ctx.registerMetaModel(metamodels[i]); }/*from w ww . j a va2 s . co m*/ } return ctx; }
From source file:org.eclipse.xtend.shared.ui.core.metamodel.jdt.JdtMetaModel.java
License:Open Source License
public final static JdtMetaModel create(final String name, final IJavaProject project, final JdtTypeStrategy strategy) { JdtMetaModel mm = JdtMetaModel.metaModels.get(project.getPath()); if (mm == null || mm.changed) { if (mm != null) { JavaCore.removeElementChangedListener(mm); }/*from w w w.ja va 2s.c om*/ mm = new JdtMetaModel(name, project, strategy); JavaCore.addElementChangedListener(mm); JavaCore.addPreProcessingResourceChangedListener(mm, IResourceChangeEvent.PRE_BUILD); JdtMetaModel.metaModels.put(project.getPath(), mm); } return mm; }
From source file:org.eclipse.xtext.builder.impl.IntegrationTest.java
License:Open Source License
@Test public void testReexportedSource() throws Exception { IJavaProject foo = createJavaProject("foo"); IJavaProject bar = createJavaProject("bar"); IJavaProject baz = createJavaProject("baz"); addNature(foo.getProject(), XtextProjectHelper.NATURE_ID); addNature(bar.getProject(), XtextProjectHelper.NATURE_ID); addNature(baz.getProject(), XtextProjectHelper.NATURE_ID); IFile file = foo.getProject().getFile("foo.jar"); file.create(jarInputStream(new TextFile("foo/Foo" + F_EXT, "object Foo")), true, monitor()); IClasspathEntry newLibraryEntry = JavaCore.newLibraryEntry(file.getFullPath(), null, null, true); addToClasspath(foo, newLibraryEntry); addToClasspath(bar, JavaCore.newProjectEntry(foo.getPath(), true)); addToClasspath(baz, JavaCore.newProjectEntry(bar.getPath(), false)); IFile bazFile = createFile("baz/src/Baz" + F_EXT, "object Baz references Foo"); waitForBuild();/*from w ww . ja v a 2s . c o m*/ assertEquals(0, countMarkers(bazFile)); assertEquals(2, countResourcesInIndex()); Iterator<IReferenceDescription> references = getContainedReferences( URI.createPlatformResourceURI(bazFile.getFullPath().toString(), true)).iterator(); IReferenceDescription next = references.next(); assertFalse(references.hasNext()); assertEquals("platform:/resource/baz/src/Baz.buildertestlanguage#/", next.getSourceEObjectUri().toString()); assertEquals("archive:platform:/resource/foo/foo.jar!/foo/Foo.buildertestlanguage#/", next.getTargetEObjectUri().toString()); assertEquals(-1, next.getIndexInList()); assertEquals(BuilderTestLanguagePackage.Literals.ELEMENT__REFERENCES, next.getEReference()); }