List of usage examples for org.eclipse.jdt.core IClasspathContainer getPath
IPath getPath();
From source file:cn.ieclipse.adt.ext.helpers.ProjectHelper.java
License:Apache License
public static boolean isContainerInClasspath(IJavaProject javaProject, IClasspathContainer container) throws JavaModelException { IClasspathEntry[] entries = javaProject.getRawClasspath(); // IClasspathEntry[] temps = container.getClasspathEntries(); boolean result = false; for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath().equals(container.getPath())) { result = true;/*from w w w. j a v a 2s . co m*/ break; } } return result; }
From source file:com.google.gwt.eclipse.core.runtime.GWTRuntimeContainerInitializerTest.java
License:Open Source License
public void testInitialize() throws Exception { // Start with gwt-user.jar and gwt-dev-PLAT.jar on the classpath for this // test// w ww . jav a 2 s. co m removeGWTRuntimeFromTestProject(); // Add the default GWT runtime to the test project (this implicitly calls // the GWTRuntimeContainerInitializer.intialize(...) method. IJavaProject project = getTestProject(); GWTUpdateProjectSdkCommand command = new GWTUpdateProjectSdkCommand(project, null, GWTPreferences.getDefaultRuntime(), UpdateType.DEFAULT_CONTAINER, null); command.execute(); JobsUtilities.waitForIdle(); // Verify the bound classpath container IClasspathContainer container = JavaCore.getClasspathContainer(defaultRuntimePath, project); assertEquals(IClasspathContainer.K_APPLICATION, container.getKind()); assertEquals(defaultRuntimePath, container.getPath()); }
From source file:com.liferay.ide.adt.core.ADTUtil.java
License:Open Source License
public static void addLibsToAndroidProject(final IProject project, List<File[]> filesList, IProgressMonitor monitor) throws CoreException { final IFolder libsFolder = project.getFolder("libs"); CoreUtil.makeFolders(libsFolder);//ww w . ja va 2s . c o m final IFolder srcFolder = libsFolder.getFolder("src"); CoreUtil.makeFolders(srcFolder); for (File[] files : filesList) { monitor.worked(1); monitor.subTask("Added file " + files[0].getName()); FileUtil.copyFileToIFolder(files[0], libsFolder, monitor); FileUtil.copyFileToIFolder(files[1], srcFolder, monitor); final String propsFilename = files[0].getName() + ".properties"; final String content = "src=src/" + files[1].getName(); final IFile propsFile = libsFolder.getFile(propsFilename); if (propsFile.exists()) { propsFile.setContents(new ByteArrayInputStream(content.getBytes()), true, true, monitor); } else { propsFile.create(new ByteArrayInputStream(content.getBytes()), true, monitor); } } project.refreshLocal(IResource.DEPTH_INFINITE, monitor); try { final IJavaProject javaProject = JavaCore.create(project); final IPath path = new Path("com.android.ide.eclipse.adt.LIBRARIES"); final IClasspathContainer container = JavaCore.getClasspathContainer(path, javaProject); final ClasspathContainerInitializer initializer = JavaCore .getClasspathContainerInitializer("org.eclipse.jst.j2ee.internal.web.container"); //$NON-NLS-1$ initializer.requestClasspathContainerUpdate(container.getPath(), javaProject, container); } catch (Exception e) { // ignore errors since this is best effort } }
From source file:com.tasktop.dropwizard.launcher.DropwizardRuntimeClasspathProvider.java
License:Open Source License
protected void addProjectEntries(Set<IRuntimeClasspathEntry> resolved, IPath path, int scope, String classifier, ILaunchConfiguration launchConfiguration, final IProgressMonitor monitor) throws CoreException { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(path.segment(0)); IMavenProjectFacade projectFacade = projectManager.create(project, monitor); if (projectFacade == null) { return;//from w w w . j av a2 s . c o m } ResolverConfiguration configuration = projectFacade.getResolverConfiguration(); if (configuration == null) { return; } IJavaProject javaProject = JavaCore.create(project); boolean projectResolved = false; for (IClasspathEntry entry : javaProject.getRawClasspath()) { IRuntimeClasspathEntry rce = null; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: if (!projectResolved) { IMavenClassifierManager mavenClassifierManager = MavenJdtPlugin.getDefault() .getMavenClassifierManager(); IClassifierClasspathProvider classifierClasspathProvider = mavenClassifierManager .getClassifierClasspathProvider(projectFacade, classifier); if (IClasspathManager.CLASSPATH_TEST == scope) { classifierClasspathProvider.setTestClasspath(resolved, projectFacade, monitor); } else { classifierClasspathProvider.setRuntimeClasspath(resolved, projectFacade, monitor); } projectResolved = true; } break; case IClasspathEntry.CPE_CONTAINER: IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); if (container != null && !MavenClasspathHelpers.isMaven2ClasspathContainer(entry.getPath())) { switch (container.getKind()) { case IClasspathContainer.K_APPLICATION: rce = JavaRuntime.newRuntimeContainerClasspathEntry(container.getPath(), IRuntimeClasspathEntry.USER_CLASSES, javaProject); break; default: break; } } break; case IClasspathEntry.CPE_LIBRARY: rce = JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath()); break; case IClasspathEntry.CPE_VARIABLE: if (!JavaRuntime.JRELIB_VARIABLE.equals(entry.getPath().segment(0))) { rce = JavaRuntime.newVariableRuntimeClasspathEntry(entry.getPath()); } break; case IClasspathEntry.CPE_PROJECT: IProject res = root.getProject(entry.getPath().segment(0)); if (res != null) { IJavaProject otherProject = JavaCore.create(res); if (otherProject != null) { rce = JavaRuntime.newDefaultProjectClasspathEntry(otherProject); } } break; default: break; } if (rce != null) { addStandardClasspathEntries(resolved, rce, launchConfiguration); } } }
From source file:com.threecrickets.creel.eclipse.internal.EclipseUtil.java
License:LGPL
/** * Sets a classpath container in a project. If the classpath container is * already there, will recreate it. (Assumes that the path is only used * once.)//from www . j a v a 2 s . c o m * * @param project * The project * @param container * The classpath container * @throws JavaModelException * In case of an Eclipse JDT error */ public static void setClasspathContainer(IJavaProject project, IClasspathContainer container) throws JavaModelException { IPath path = container.getPath(); IClasspathEntry[] entries = project.getRawClasspath(); int found = -1; for (int i = 0, length = entries.length; i < length; i++) { IClasspathEntry entry = entries[i]; if ((entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) && (entry.getPath().equals(path))) { found = i; break; } } if (found == -1) { IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; System.arraycopy(entries, 0, newEntries, 0, entries.length); newEntries[entries.length] = JavaCore.newContainerEntry(container.getPath()); project.setRawClasspath(newEntries, null); } else { entries[found] = JavaCore.newContainerEntry(path); project.setRawClasspath(entries, null); } JavaCore.setClasspathContainer(Classpath.PATH, new IJavaProject[] { project }, new IClasspathContainer[] { container }, null); }
From source file:es.optsicom.res.client.util.ProjectDependenciesResolver.java
License:Eclipse Public License
private void calculateDependencies(IClasspathEntry[] cpe, IProject project) throws DependenciesResolverException { try {//from w ww . j a v a 2s.com IWorkspace workspace = project.getWorkspace(); IPath workspacePath = workspace.getRoot().getLocation(); String nombreWorkspace = workspacePath.toString(); IJavaProject jp = JavaCore.create(project); if (!dependencies.contains(project.getLocation().toString())) { // Aadimos la carpeta bin classpathFiles.add(workspacePath.append(jp.getOutputLocation()).toFile()); classpath.add(jp.getOutputLocation().toString()); } for (IClasspathEntry cpEntry : cpe) { String path = cpEntry.getPath().toString(); String dependency = nombreWorkspace.concat(path); if (!dependencies.contains(dependency)) { RESClientPlugin.log("Adding dependency: " + dependency); dependencies.add(dependency); if (cpEntry.getOutputLocation() != null) { RESClientPlugin.log("Binarios: " + cpEntry.getOutputLocation().toString()); classpath.add(cpEntry.getOutputLocation().makeRelativeTo(workspacePath).toString()); classpathFiles.add(cpEntry.getOutputLocation().toFile()); } int tipo = cpEntry.getEntryKind(); //Si la dependencia es de una libreria( if (tipo == IClasspathEntry.CPE_LIBRARY) { String dep = cpEntry.getPath().makeRelativeTo(workspacePath).toString(); //mgarcia: Optsicom res Evolution if (new File(workspacePath.toFile(), cpEntry.getPath().toOSString()).exists()) { classpathFiles.add(new File(workspacePath.toFile(), cpEntry.getPath().toOSString())); //Aadimos las dependencias a las properties RESClientPlugin.log("Adding library: " + dep); classpath.add(cpEntry.getPath().toString()); } else { throw new DependenciesResolverException(); } } else if (tipo == IClasspathEntry.CPE_PROJECT) { // File[] files = new File(dependency).listFiles(); // for (File f : files){ // lista.add(f); // String dep = f.getPath(); // RESClientPlugin.log("Adding dependency: " + dep); // dependencies.add(dep); // } IProject p = workspace.getRoot().getProject(cpEntry.getPath().lastSegment()); IJavaProject projectDependency = JavaCore.create(p); IClasspathEntry[] cp = projectDependency.getRawClasspath(); classpathFiles.add(workspacePath.append(projectDependency.getOutputLocation()).toFile()); classpath.add(projectDependency.getOutputLocation().toString()); RESClientPlugin.log("Populating files from: " + p.getName()); calculateDependencies(cp, p); } else if (tipo == IClasspathEntry.CPE_SOURCE) { File f = new File(dependency); classpathFiles.add(f); RESClientPlugin.log("Adding source: " + dependency); } else if (tipo == IClasspathEntry.CPE_VARIABLE) { IClasspathEntry[] clpe = new IClasspathEntry[1]; clpe[0] = JavaCore.getResolvedClasspathEntry(cpEntry); if (clpe[0] != null) { RESClientPlugin.log("Populating files from: " + clpe[0].getPath().toOSString()); calculateDependencies(clpe, project); } } else if (tipo == IClasspathEntry.CPE_CONTAINER) { if (cpEntry.getPath().toOSString().contains("JRE_CONTAINER") || cpEntry.getPath().toOSString().contains("requiredPlugins")) { continue; } IClasspathContainer cc = JavaCore.getClasspathContainer(cpEntry.getPath(), jp); IClasspathEntry[] entradas = cc.getClasspathEntries(); RESClientPlugin.log("Populating files from: " + cc.getPath().toOSString()); calculateDependencies(entradas, project); } } } } catch (JavaModelException e) { RESClientPlugin.log(e); } for (String path : classpath) { RESClientPlugin.log("Classpath: " + path); } for (File file : classpathFiles) { RESClientPlugin.log("Classpath file: " + file.getAbsolutePath()); } }
From source file:it.scoppelletti.sdk.ide.projects.DependenciesContainer.java
License:Apache License
/** * Imposta per un progetto il class-path corrispondente alle dipendenze del * progetto stesso./*ww w .ja v a 2 s .c om*/ * * @param project Progetto. * @param monitor Gestore dell’avanzamento. * @since 1.1.0 */ public static void setClasspath(IJavaProject project, IProgressMonitor monitor) throws CoreException { String msg; DependenciesContainer.Builder builder; IClasspathContainer container; SubMonitor progress; if (project == null) { throw new NullPointerException("Argument project is null."); } msg = String.format("Calculating class-path \"%1$s\" for project \"%2$s\"...", DependenciesContainer.NAME, project.getElementName()); progress = SubMonitor.convert(monitor, msg, 2); try { builder = new DependenciesContainer.Builder(project); container = new DependenciesContainer(builder.run(progress.newChild(1))); progress.worked(1); JavaCore.setClasspathContainer(container.getPath(), new IJavaProject[] { project }, new IClasspathContainer[] { container }, progress.newChild(1)); progress.worked(1); } finally { if (monitor != null) { monitor.done(); } } }
From source file:it.wallgren.android.platform.AndroidClasspathContainerInitializer.java
License:Apache License
/** * Persist relevant parts of the container for future sessions * * @param containerPath//from w w w .java2s .co m * @param container * @throws CoreException */ private void persistClasspathContainer(IJavaProject project, IClasspathContainer container) throws CoreException { final IClasspathEntry[] entries = container.getClasspathEntries(); for (int i = 0; i < entries.length; i++) { final IClasspathEntry entry = entries[i]; final QualifiedName qname = new QualifiedName(container.getPath().toString(), "IClasspathEntry." + i); final String encodedClasspathEntry = project.encodeClasspathEntry(entry); ResourcesPlugin.getWorkspace().getRoot().setPersistentProperty(qname, encodedClasspathEntry); } }
From source file:me.gladwell.eclipse.m2e.android.project.EclipseClasspath.java
License:Open Source License
public void addContainer(IClasspathContainer container) { try {//from ww w . j a v a 2 s. c o m setClasspathContainer(container.getPath(), new IJavaProject[] { project }, new IClasspathContainer[] { container }, new NullProgressMonitor()); classpath.addEntry(newContainerEntry(container.getPath(), false)); } catch (JavaModelException e) { throw new ProjectConfigurationException(e); } }
From source file:me.gladwell.eclipse.m2e.android.project.MavenEclipseClasspath.java
License:Open Source License
public void addContainer(IClasspathContainer container) { try {/* ww w . j a v a 2 s. c om*/ setClasspathContainer(container.getPath(), new IJavaProject[] { project.getJavaProject() }, new IClasspathContainer[] { container }, new NullProgressMonitor()); classpath.addEntry(newContainerEntry(container.getPath(), false)); } catch (JavaModelException e) { throw new ProjectConfigurationException(e); } }