Java Code Examples for org.eclipse.jdt.core.JavaCore#newLibraryEntry()
The following examples show how to use
org.eclipse.jdt.core.JavaCore#newLibraryEntry() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DerbyClasspathContainer.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public DerbyClasspathContainer() { List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); Bundle bundle = Platform.getBundle(CommonNames.CORE_PATH); Enumeration en = bundle.findEntries("/", "*.jar", true); String rootPath = null; try { rootPath = FileLocator.resolve(FileLocator.find(bundle, new Path("/"), null)).getPath(); } catch(IOException e) { Logger.log(e.getMessage(), IStatus.ERROR); } while(en.hasMoreElements()) { IClasspathEntry cpe = JavaCore.newLibraryEntry(new Path(rootPath+'/'+((URL)en.nextElement()).getFile()), null, null); entries.add(cpe); } IClasspathEntry[] cpes = new IClasspathEntry[entries.size()]; _entries = (IClasspathEntry[])entries.toArray(cpes); }
Example 2
Source File: Bug486584Test.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testNoFullBuildWhenClasspathNotReallyChanged_1() throws CoreException, IOException, InterruptedException { IJavaProject project = setupProject(); IFile libaryFile = copyAndGetXtendExampleJar(project); IPath rawLocation = libaryFile.getRawLocation(); IClasspathEntry libraryEntry = JavaCore.newLibraryEntry(rawLocation, null, null); addToClasspath(project, libraryEntry); build(); assertFalse(getEvents().isEmpty()); getEvents().clear(); project.setRawClasspath(project.getRawClasspath(), null); project.getProject().getFile("src/dummy.txt").create(new StringInputStream(""), false, null); project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); build(); assertEquals(0, getEvents().size()); }
Example 3
Source File: DerbyClasspathContainer.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public DerbyClasspathContainer() { List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); Bundle bundle = Platform.getBundle(CommonNames.CORE_PATH); Enumeration en = bundle.findEntries("/", "*.jar", true); String rootPath = null; try { rootPath = FileLocator.resolve(FileLocator.find(bundle, new Path("/"), null)).getPath(); } catch(IOException e) { Logger.log(e.getMessage(), IStatus.ERROR); } while(en.hasMoreElements()) { IClasspathEntry cpe = JavaCore.newLibraryEntry(new Path(rootPath+'/'+((URL)en.nextElement()).getFile()), null, null); entries.add(cpe); } IClasspathEntry[] cpes = new IClasspathEntry[entries.size()]; _entries = (IClasspathEntry[])entries.toArray(cpes); }
Example 4
Source File: LibraryClasspathContainerResolverService.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
private IClasspathEntry resolveLibraryFileAttachSourceSync(LibraryFile libraryFile) throws CoreException { Artifact artifact = repositoryService.resolveArtifact(libraryFile, new NullProgressMonitor()); IPath libraryPath = new Path(artifact.getFile().getAbsolutePath()); // Not all artifacts have sources; need to work if no source artifact is available // e.g. appengine-api-sdk doesn't IPath sourceAttachmentPath = repositoryService.resolveSourceArtifact( libraryFile, artifact.getVersion(), new NullProgressMonitor()); IClasspathEntry newLibraryEntry = JavaCore.newLibraryEntry( libraryPath, sourceAttachmentPath, null /* sourceAttachmentRootPath */, getAccessRules(libraryFile.getFilters()), getClasspathAttributes(libraryFile, artifact), true /* isExported */); return newLibraryEntry; }
Example 5
Source File: SarlClassPathDetector.java From sarl with Apache License 2.0 | 6 votes |
/** Detect the libraries. * * @param cpEntries the classpath entries to be updated with libraries. * @param outputLocation the detected output location. */ protected void detectLibraries(List<IClasspathEntry> cpEntries, IPath outputLocation) { final List<IClasspathEntry> res = new ArrayList<>(); final Set<IPath> sourceFolderSet = this.sourceFolders.keySet(); for (final IPath path : this.jarFiles) { if (Utilities.isNested(path, sourceFolderSet.iterator())) { continue; } if (outputLocation != null && outputLocation.isPrefixOf(path)) { continue; } final IClasspathEntry entry = JavaCore.newLibraryEntry(path, null, null); res.add(entry); } Collections.sort(res, getCPEntryComparator()); cpEntries.addAll(res); }
Example 6
Source File: SimpleProjectsIntegrationTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testJarOnTwoProjectsRemovedFromOne() 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(JavaProjectSetupUtil.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(bar, JavaCore.newLibraryEntry(file.getFullPath(), null, null,true)); addToClasspath(baz, JavaCore.newProjectEntry(bar.getPath(), false)); addSourceFolder(baz, "src"); IFile bazFile = createFile("baz/src/Baz"+F_EXT, "object Baz references Foo"); build(); assertEquals(0,countMarkers(bazFile)); assertEquals(2, countResourcesInIndex()); deleteClasspathEntry(foo, newLibraryEntry.getPath()); build(); assertEquals(0,countMarkers(bazFile)); assertEquals(2, countResourcesInIndex()); }
Example 7
Source File: JarImportWizard.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * {@inheritDoc} */ @Override protected boolean deconfigureClasspath(final IClasspathEntry[] entries, final IProgressMonitor monitor) throws CoreException { final boolean rename= fImportData.isRenameJarFile(); if (rename && !fCancelled) { final IPackageFragmentRoot root= getPackageFragmentRoot(); if (root != null) { final IClasspathEntry entry= root.getRawClasspathEntry(); for (int index= 0; index < entries.length; index++) { if (entries[index].equals(entry)) { final IPath path= getTargetPath(entries[index]); if (path != null) entries[index]= JavaCore.newLibraryEntry(path, entries[index].getSourceAttachmentPath(), entries[index].getSourceAttachmentRootPath(), entries[index].getAccessRules(), entries[index].getExtraAttributes(), entries[index].isExported()); } } } } if (!fCancelled) replaceJarFile(new SubProgressMonitor(monitor, 100, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); return rename; }
Example 8
Source File: FixProjectsUtils.java From hybris-commerce-eclipse-plugin with Apache License 2.0 | 6 votes |
public static void addToClassPath(IResource res, int type, IJavaProject javaProject, IProgressMonitor monitor) throws JavaModelException { Set<IClasspathEntry> entries = new HashSet<IClasspathEntry>(Arrays.asList(javaProject.getRawClasspath())); IClasspathEntry entry = null; switch (type) { case IClasspathEntry.CPE_SOURCE: entry = JavaCore.newSourceEntry(res.getFullPath()); break; case IClasspathEntry.CPE_LIBRARY: entry = JavaCore.newLibraryEntry(res.getFullPath(), null, null, true); break; case IClasspathEntry.CPE_PROJECT: entry = JavaCore.newProjectEntry(res.getFullPath(), true); break; } entries.add(entry); setClasspath(entries.toArray(new IClasspathEntry[entries.size()]), javaProject, monitor); }
Example 9
Source File: JavaProjectSetupUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public static IClasspathEntry addPlatformJarToClasspath(final Plugin srcPlugin, final String jarFileName, final IJavaProject destProject) throws JavaModelException, IOException { final IPath jarFilePath = PluginUtil.findPathInPlugin(srcPlugin, jarFileName); final IClasspathEntry newLibraryEntry = JavaCore.newLibraryEntry(jarFilePath, null, null); addToClasspath(destProject, newLibraryEntry); return newLibraryEntry; }
Example 10
Source File: GWTMavenRuntime.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
private IClasspathEntry findJavaXValidationClasspathEntry() throws JavaModelException { IType type = javaProject.findType("javax.validation.Constraint"); if (type == null) { return null; } IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) type .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_BINARY) { return JavaCore.newLibraryEntry(packageFragmentRoot.getPath(), null, null); } return null; }
Example 11
Source File: JavaProjectSetupUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public static IClasspathEntry addPlatformJarToClasspath(final Plugin srcPlugin, final String jarFileName, final IJavaProject destProject) throws JavaModelException, IOException { final IPath jarFilePath = PluginUtil.findPathInPlugin(srcPlugin, jarFileName); final IClasspathEntry newLibraryEntry = JavaCore.newLibraryEntry(jarFilePath, null, null); addToClasspath(destProject, newLibraryEntry); return newLibraryEntry; }
Example 12
Source File: Bug486584Test.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testNoFullBuildIfAttachmentChangeOnly() throws CoreException, InterruptedException { IJavaProject project = setupProject(); assertFalse(getEvents().isEmpty()); getEvents().clear(); IFile libaryFile = copyAndGetXtendExampleJar(project); IClasspathEntry libraryEntry = JavaCore.newLibraryEntry(libaryFile.getFullPath(), null, null); addToClasspath(project, libraryEntry); build(); assertEquals(1, getEvents().size()); Event singleEvent = getEvents().get(0); ImmutableList<Delta> deltas = singleEvent.getDeltas(); assertEquals(1, deltas.size()); getEvents().clear(); IClasspathEntry[] classpath = project.getRawClasspath(); for (int i = 0; i < classpath.length; ++i) { IPath entryPath = classpath[i].getPath(); if (libraryEntry.getPath().equals(entryPath)) { IClasspathEntry[] newClasspath = new IClasspathEntry[classpath.length]; System.arraycopy(classpath, 0, newClasspath, 0, classpath.length); classpath[i] = JavaCore.newLibraryEntry(libaryFile.getFullPath(), libaryFile.getFullPath(), null); project.setRawClasspath(classpath, null); } } build(); assertEquals(0, getEvents().size()); }
Example 13
Source File: XbaseEditorOpenClassFileTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
public IPackageFragmentRoot addJarToClassPath(final IJavaProject jp, final String fileName, final String fileNameOfSource) { try { IProject _project = jp.getProject(); Path _path = new Path(fileName); final IFile jarFile = _project.getFile(_path); jarFile.create(this.getClass().getResourceAsStream(fileName), true, null); IFile _xifexpression = null; if ((fileNameOfSource != null)) { IFile _xblockexpression = null; { IProject _project_1 = jp.getProject(); Path _path_1 = new Path(fileNameOfSource); final IFile source = _project_1.getFile(_path_1); source.create(this.getClass().getResourceAsStream(fileNameOfSource), true, null); _xblockexpression = source; } _xifexpression = _xblockexpression; } final IFile sourceFile = _xifexpression; IPath _fullPath = jarFile.getFullPath(); IPath _fullPath_1 = null; if (sourceFile!=null) { _fullPath_1=sourceFile.getFullPath(); } final IClasspathEntry cp = JavaCore.newLibraryEntry(_fullPath, _fullPath_1, null); JavaProjectSetupUtil.addToClasspath(jp, cp); return JavaCore.createJarPackageFragmentRootFrom(jarFile); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 14
Source File: SimpleProjectsIntegrationTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@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(JavaProjectSetupUtil.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)); addSourceFolder(baz, "src"); IFile bazFile = createFile("baz/src/Baz"+F_EXT, "object Baz references Foo"); build(); 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()); }
Example 15
Source File: ConfigureBuildPathAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public void run() { IProject project= null; Object firstElement= getSelectedElements().get(0); HashMap<Object, IClasspathEntry> data= new HashMap<Object, IClasspathEntry>(); if (firstElement instanceof IJavaElement) { IJavaElement element= (IJavaElement) firstElement; IPackageFragmentRoot root= (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (root != null) { try { data.put(BuildPathsPropertyPage.DATA_REVEAL_ENTRY, root.getRawClasspathEntry()); } catch (JavaModelException e) { // ignore } } project= element.getJavaProject().getProject(); } else if (firstElement instanceof PackageFragmentRootContainer) { PackageFragmentRootContainer container= (PackageFragmentRootContainer) firstElement; project= container.getJavaProject().getProject(); IClasspathEntry entry= container instanceof ClassPathContainer ? ((ClassPathContainer) container).getClasspathEntry() : JavaCore.newLibraryEntry(new Path("/x/y"), null, null); //$NON-NLS-1$ data.put(BuildPathsPropertyPage.DATA_REVEAL_ENTRY, entry); } else { project= ((IResource) ((IAdaptable) firstElement).getAdapter(IResource.class)).getProject(); } PreferencesUtil.createPropertyDialogOn(getShell(), project, BuildPathsPropertyPage.PROP_ID, null, data).open(); }
Example 16
Source File: LibraryClasspathContainerInitializerTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@Test public void testInitialize_ifSourcePathIsValidContainerIsNotResolvedAgain() throws CoreException, IOException { File artifactFile = temporaryFolder.newFile(); File sourceArtifactFile = temporaryFolder.newFile(); IClasspathEntry entry = JavaCore.newLibraryEntry(new Path(artifactFile.getAbsolutePath()), new Path(sourceArtifactFile.getAbsolutePath()), null); IClasspathEntry[] entries = new IClasspathEntry[]{ entry }; LibraryClasspathContainer container = mock(LibraryClasspathContainer.class); when(container.getClasspathEntries()).thenReturn(entries); when(serializer.loadContainer(any(IJavaProject.class), any(IPath.class))).thenReturn(container); LibraryClasspathContainerInitializer containerInitializer = new LibraryClasspathContainerInitializer(TEST_CONTAINER_PATH, serializer, resolverService); containerInitializer.initialize(new Path(TEST_LIBRARY_PATH), testProject.getJavaProject()); testProject.getJavaProject().getRawClasspath(); IClasspathEntry[] resolvedClasspath = testProject.getJavaProject().getResolvedClasspath(false); for (IClasspathEntry resolvedEntry : resolvedClasspath) { if (resolvedEntry.getPath().toOSString().equals(artifactFile.getAbsolutePath())) { assertThat(resolvedEntry.getSourceAttachmentPath().toOSString(), is(sourceArtifactFile.getAbsolutePath())); verifyResolveServiceResolveContainerNotCalled(); return; } } fail("classpath entry not found"); }
Example 17
Source File: GWTMavenRuntime.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Find the classpath for get-dev.jar which is used to run super dev mode. * * @return IClasspathEntry for the path to gwt-dev.jar * @throws JavaModelException */ private IClasspathEntry findGwtCodeServerClasspathEntry() throws JavaModelException { IType type = javaProject.findType(GwtLaunchConfigurationProcessorUtilities.GWT_CODE_SERVER); if (type == null) { return null; } IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) type .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_BINARY) { return JavaCore.newLibraryEntry(packageFragmentRoot.getPath(), null, null); } return null; }
Example 18
Source File: BazelClasspathContainer.java From eclipse with Apache License 2.0 | 5 votes |
private IClasspathEntry[] jarsToClasspathEntries(Set<Jars> jars) { IClasspathEntry[] entries = new IClasspathEntry[jars.size()]; int i = 0; File execRoot = instance.getExecRoot(); for (Jars j : jars) { entries[i] = JavaCore.newLibraryEntry(getJarIPath(execRoot, j.getJar()), getJarIPath(execRoot, j.getSrcJar()), null); i++; } return entries; }
Example 19
Source File: IDECPListElement.java From birt with Eclipse Public License 1.0 | 4 votes |
private IClasspathEntry newClasspathEntry( ) { IClasspathAttribute[] extraAttributes = new IClasspathAttribute[0]; switch ( fEntryKind ) { case IClasspathEntry.CPE_SOURCE : return JavaCore.newSourceEntry( fPath, null, null, null, extraAttributes ); case IClasspathEntry.CPE_LIBRARY : { return JavaCore.newLibraryEntry( fPath, null, null, null, extraAttributes, isExported( ) ); } case IClasspathEntry.CPE_PROJECT : { return JavaCore.newProjectEntry( fPath, null, false, extraAttributes, isExported( ) ); } case IClasspathEntry.CPE_CONTAINER : { return JavaCore.newContainerEntry( fPath, null, extraAttributes, isExported( ) ); } case IClasspathEntry.CPE_VARIABLE : { return JavaCore.newVariableEntry( fPath, null, null, null, extraAttributes, isExported( ) ); } default : return null; } }
Example 20
Source File: JavaProjectSetupUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
public static IClasspathEntry addJarToClasspath(IJavaProject javaProject, IFile jarFile) throws JavaModelException { IClasspathEntry newLibraryEntry = JavaCore.newLibraryEntry(jarFile.getFullPath(), null, null); addToClasspath(javaProject, newLibraryEntry); return newLibraryEntry; }