List of usage examples for org.eclipse.jdt.core IJavaProject getRawClasspath
IClasspathEntry[] getRawClasspath() throws JavaModelException;
From source file:org.apache.ivyde.internal.eclipse.ui.NewIvyDEContainerWizard.java
License:Apache License
public boolean performFinish() { containerPage.finish();//from w w w. j a va 2 s. c om IClasspathEntry newEntry = containerPage.getSelection(); IPath path = newEntry.getPath(); IJavaProject project = containerPage.getProject(); try { IvyClasspathContainerImpl ivycp = new IvyClasspathContainerImpl(project, path, new IClasspathEntry[0], new IClasspathAttribute[0]); JavaCore.setClasspathContainer(path, new IJavaProject[] { project }, new IClasspathContainer[] { ivycp }, null); IClasspathEntry[] entries = project.getRawClasspath(); List newEntries = new ArrayList(Arrays.asList(entries)); newEntries.add(newEntry); entries = (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]); project.setRawClasspath(entries, project.getOutputLocation(), null); ivycp.launchResolve(false, null); } catch (JavaModelException e) { IvyPlugin.log(e); return false; } return true; }
From source file:org.apache.openjpa.eclipse.ToggleNatureAction.java
License:Apache License
/** * Add the captive runtime libraries of the bundle to the classpath of the given project. *///from www .ja v a 2s .c o m private void addClasspath(IProject project, IClasspathEntry[] libs) throws CoreException { if (libs.length == 0) return; IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] projectClasspaths = javaProject.getRawClasspath(); IClasspathEntry[] newClasspaths = new IClasspathEntry[projectClasspaths.length + libs.length]; System.arraycopy(libs, 0, newClasspaths, 0, libs.length); System.arraycopy(projectClasspaths, 0, newClasspaths, libs.length, projectClasspaths.length); javaProject.setRawClasspath(newClasspaths, null); project.setPersistentProperty(PluginProperty.USING_CAPTIVE_LIBS, "" + true); }
From source file:org.apache.openjpa.eclipse.ToggleNatureAction.java
License:Apache License
private void removeClasspath(IProject project) throws CoreException { if ("false".equalsIgnoreCase(project.getPersistentProperty(PluginProperty.USING_CAPTIVE_LIBS))) { return;//www.ja v a2 s . c om } IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] projectClasspaths = javaProject.getRawClasspath(); PluginLibrary cpc = new PluginLibrary(); IClasspathEntry[] cpsOpenJPA = cpc.getLibraryClasspaths(project, null, false); List<IClasspathEntry> cpsModified = new ArrayList<IClasspathEntry>(); cpsModified.addAll(Arrays.asList(projectClasspaths)); cpsModified.removeAll(Arrays.asList(cpsOpenJPA)); javaProject.setRawClasspath(cpsModified.toArray(new IClasspathEntry[cpsModified.size()]), null); project.setPersistentProperty(PluginProperty.USING_CAPTIVE_LIBS, "" + false); }
From source file:org.asup.dk.source.jdt.JDTProjectUtil.java
License:Open Source License
public static IJavaProject convertToJavaPluginProject(IProject project) throws CoreException { IJavaProject javaProject = JavaCore.create(project); IProjectDescription projectDescription = project.getDescription(); List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>(); classpathEntries.addAll(Arrays.asList(javaProject.getRawClasspath())); ICommand[] builders = projectDescription.getBuildSpec(); if (builders == null) { builders = new ICommand[0]; }//from w w w.j ava 2 s . c o m boolean hasManifestBuilder = false; boolean hasSchemaBuilder = false; for (int i = 0; i < builders.length; ++i) { if (PDE_MANIFEST_BUILDER.equals(builders[i].getBuilderName())) { hasManifestBuilder = true; } if (PDE_SCHEMA_BUILDER.equals(builders[i].getBuilderName())) { hasSchemaBuilder = true; } } if (!hasManifestBuilder) { ICommand[] oldBuilders = builders; builders = new ICommand[oldBuilders.length + 1]; System.arraycopy(oldBuilders, 0, builders, 0, oldBuilders.length); builders[oldBuilders.length] = projectDescription.newCommand(); builders[oldBuilders.length].setBuilderName(PDE_MANIFEST_BUILDER); } if (!hasSchemaBuilder) { ICommand[] oldBuilders = builders; builders = new ICommand[oldBuilders.length + 1]; System.arraycopy(oldBuilders, 0, builders, 0, oldBuilders.length); builders[oldBuilders.length] = projectDescription.newCommand(); builders[oldBuilders.length].setBuilderName(PDE_SCHEMA_BUILDER); } projectDescription.setBuildSpec(builders); project.setDescription(projectDescription, null); // classpath List<IClasspathEntry> classpath = new ArrayList<IClasspathEntry>(); // jre IClasspathEntry jreClasspathEntry = JavaCore.newContainerEntry(new Path(JRE_CONTAINER_ID)); classpath.add(jreClasspathEntry); // pde IClasspathEntry pdeClasspathEntry = JavaCore.newContainerEntry(new Path(PDE_CONTAINER_ID)); classpath.add(pdeClasspathEntry); // source folder IClasspathEntry classpathEntry = JavaCore.newSourceEntry(javaProject.getPath().append(JAVA_SRC_DIRECTORY)); classpath.add(classpathEntry); IClasspathEntry[] classpathEntryArray = classpath.toArray(new IClasspathEntry[classpath.size()]); javaProject.setRawClasspath(classpathEntryArray, null); // compilation output javaProject.setOutputLocation(javaProject.getPath().append(JAVA_CLASSES_DIRECTORY), null); return javaProject; }
From source file:org.autorefactor.refactoring.rules.JavaCoreHelper.java
License:Open Source License
private static void addToClasspath(IJavaProject javaProject, List<IClasspathEntry> classpathEntries) throws Exception { if (!classpathEntries.isEmpty()) { IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries;/*www . j a v a 2s . co m*/ if (oldEntries.length != 0) { // remove duplicate entries Set<IClasspathEntry> set = new HashSet<IClasspathEntry>(Arrays.asList(oldEntries)); set.addAll(classpathEntries); newEntries = set.toArray(new IClasspathEntry[set.size()]); } else { newEntries = classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]); } javaProject.setRawClasspath(newEntries, null); } }
From source file:org.azzyzt.jee.tools.project.ProjectUtil.java
License:EUPL
public static void appendProjectToClassPath(IJavaProject jprj, IJavaProject jprjAdded) throws CoreException { try {//from w w w. ja v a 2s .com IClasspathEntry[] entries = jprj.getRawClasspath(); IClasspathEntry newEntry = JavaCore.newProjectEntry(jprjAdded.getPath(), true); for (IClasspathEntry entry : entries) { if (newEntry.equals(entry)) { return; } } IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; System.arraycopy(entries, 0, newEntries, 0, entries.length); newEntries[newEntries.length - 1] = newEntry; jprj.setRawClasspath(newEntries, null); } catch (JavaModelException e) { throw Util.createCoreException("Can't add " + jprjAdded.getProject().getName() + " to class path of " + jprj.getProject().getName(), e); } }
From source file:org.bndtools.builder.BndProjectNature.java
License:Open Source License
private void installBndClasspath() throws CoreException { IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] classpath = javaProject.getRawClasspath(); for (IClasspathEntry entry : classpath) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && BndtoolsConstants.BND_CLASSPATH_ID.equals(entry.getPath())) return; // already installed }/*w w w.j a v a 2s . co m*/ IClasspathEntry[] newEntries = new IClasspathEntry[classpath.length + 1]; System.arraycopy(classpath, 0, newEntries, 0, classpath.length); newEntries[classpath.length] = JavaCore.newContainerEntry(BndtoolsConstants.BND_CLASSPATH_ID); javaProject.setRawClasspath(newEntries, null); }
From source file:org.bndtools.builder.BndProjectNature.java
License:Open Source License
private void removeBndClasspath() throws CoreException { IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] classpath = javaProject.getRawClasspath(); List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(classpath.length); boolean changed = false; for (IClasspathEntry entry : classpath) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && BndtoolsConstants.BND_CLASSPATH_ID.equals(entry.getPath())) { changed = true;//from w ww. j a v a 2 s .c o m } else { newEntries.add(entry); } } if (changed) javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), null); }
From source file:org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelRepositoryStore.java
License:Open Source License
protected IRegion regionWithBDM(final IJavaProject javaProject) throws JavaModelException { final IRegion newRegion = JavaCore.newRegion(); final IClasspathEntry repositoryDependenciesClasspathEntry = find(asIterable(javaProject.getRawClasspath()), repositoryDependenciesEntry(), null); final IPackageFragmentRoot[] fragmentRoots = javaProject .findPackageFragmentRoots(repositoryDependenciesClasspathEntry); final IPackageFragmentRoot packageFragmentRoot = find(asIterable(fragmentRoots), withElementName(BDM_CLIENT_POJO_JAR_NAME), null); if (packageFragmentRoot != null) { newRegion.add(packageFragmentRoot); }/*from www. ja v a2 s . c o m*/ return newRegion; }
From source file:org.checkthread.plugin.eclipse.CheckThreadRunner.java
License:Open Source License
private static void loadDirFromProject(HashMap<IProject, Boolean> projectSearchMap, boolean isrecursed, IProject project, ArrayList<IPath> srcDirList, ArrayList<URI> targetFileList, ArrayList<URI> classPathList) { // if we already searched this project if (projectSearchMap.get(project) != null) { return;//from w ww . ja va 2s . com // we haven't searched this project yet } else { // add to cache projectSearchMap.put(project, true); } // recursive traverse referenced projects // stopping condition: project already searched try { IProject[] projectList = project.getReferencedProjects(); for (IProject p : projectList) { loadDirFromProject(projectSearchMap, true, p, srcDirList, targetFileList, classPathList); } } catch (Exception e) { e.printStackTrace(); } IJavaProject javaProject = JavaCore.create(project); IPath defaultOutputLocationRelative = null; try { defaultOutputLocationRelative = javaProject.getOutputLocation(); } catch (Exception e) { e.printStackTrace(); return; } sLogger.info("DEFAULT OUTPUT LOCATION RELATIVE: " + defaultOutputLocationRelative); IPath projectLocationAbsolute = project.getLocation(); sLogger.info("PROJECT LOCATION: " + projectLocationAbsolute); // Make path absolute IPath defaultOutputLocationAbsolute = projectLocationAbsolute .append(defaultOutputLocationRelative.removeFirstSegments(1)); sLogger.info("DEFAULT OUTPUT LOCATION ABSOLUTE: " + defaultOutputLocationAbsolute); // Work around, stomp over target java files. Instead, just give the // root directory sLogger.info("WORKAROUND: IGNORE CHANGED CLASS FILES< RECHECK EVERYTHING"); if (!isrecursed) { URI uri = defaultOutputLocationAbsolute.toFile().toURI(); if (uri != null) { targetFileList.add(uri); } } // Add to input URI cURI = defaultOutputLocationAbsolute.toFile().toURI(); if (cURI != null) { classPathList.add(cURI); } // Loop through classpath entries and get src directory list IClasspathEntry[] rawClassPathList = null; try { rawClassPathList = javaProject.getRawClasspath(); } catch (JavaModelException e) { e.printStackTrace(); } if (rawClassPathList != null) { for (IClasspathEntry classPathEntry : rawClassPathList) { switch (classPathEntry.getEntryKind()) { // Source Directory case IClasspathEntry.CPE_SOURCE: { if (!isrecursed) { IPath p = classPathEntry.getPath().removeFirstSegments(1); if (p != null) { srcDirList.add(p); sLogger.info("CPE_SOURCE: " + p); } } break; } // external libraries used case IClasspathEntry.CPE_LIBRARY: { File file = classPathEntry.getPath().toFile(); IPath p; // The entry may be a relative path to the project root // or it could be an absolute path to a library. if (file.isFile() || file.isDirectory()) { p = classPathEntry.getPath(); } else { p = projectLocationAbsolute.append(classPathEntry.getPath().removeFirstSegments(1)); } URI uri = p.toFile().toURI(); if (uri != null) { classPathList.add(uri); } sLogger.info("CPE_LIBRARY: " + uri); break; } // ignore case IClasspathEntry.CPE_CONTAINER: sLogger.info("CPE_CONTAINER: " + classPathEntry); break; //ignore case IClasspathEntry.CPE_PROJECT: sLogger.info("CPE_PROJECT: " + classPathEntry); break; } } } }