List of usage examples for org.eclipse.jdt.core IJavaProject setRawClasspath
void setRawClasspath(IClasspathEntry[] entries, IProgressMonitor monitor) throws JavaModelException;
From source file:org.azzyzt.jee.tools.project.ProjectUtil.java
License:EUPL
public static void appendProjectToClassPath(IJavaProject jprj, IJavaProject jprjAdded) throws CoreException { try {/*w ww. j a v a2 s . c om*/ 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 }/*from w ww . j av a 2 s . 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 www. j a v a 2 s . co m*/ } else { newEntries.add(entry); } } if (changed) javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), null); }
From source file:org.bundlemaker.core.jdt.exporter.JdtProjectExporter.java
License:Open Source License
/** * {@inheritDoc}/*www . j a va2 s. c om*/ */ @Override public void doExport(IProgressMonitor progressMonitor) throws CoreException { // step 1: get a non-existing project name String projectName = Helper.getUniqueProjectName(getCurrentModule().getModuleIdentifier().getName()); // step 2: delete and create project IPath location = null; if (isUseClassifcationForExportDestination()) { Path destinationDirectoryPath = new Path( getCurrentContext().getDestinationDirectory().getAbsolutePath()); location = destinationDirectoryPath.append(getCurrentModule().getClassification()).append(projectName); } // (re-)create the project IProject project = Helper.deleteAndCreateProject(projectName, location); // step 3: add java and plug-nature IProjectDescription description = project.getDescription(); description.setNatureIds(new String[] { JavaCore.NATURE_ID }); project.setDescription(description, null); // 'clean' the java project IJavaProject javaProject = JavaCore.create(project); List<IClasspathEntry> classpathEntries = new LinkedList<IClasspathEntry>(); classpathEntries.add(JavaRuntime.getDefaultJREContainerEntry()); classpathEntries.add( JavaCore.newSourceEntry(new Path(project.getName()).makeAbsolute().append(SRC_DIRECTORY_NAME))); if (_referencedModules != null) { for (IModuleArtifact referencedModuleArtifact : _referencedModules) { IModule referencedModule = referencedModuleArtifact.getAssociatedModule(); classpathEntries.add(JavaCore.newProjectEntry( new Path(referencedModule.getModuleIdentifier().getName()).makeAbsolute())); } } javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), null); javaProject.save(null, true); // step 5: copy the source files IFolder srcFolder = project.getFolder(SRC_DIRECTORY_NAME); // copy the source for (IProjectContentResource resourceStandin : getCurrentModule().getResources(ResourceType.SOURCE)) { // File targetFile = new File(srcFolder.getRawLocation().toFile(), resourceStandin.getPath()); targetFile.getParentFile().mkdirs(); try { // FileUtils.copy(new ByteArrayInputStream(resourceStandin.getContent()), new FileOutputStream(targetFile), new byte[1024]); } catch (Exception e) { throw new CoreException(new Status(IStatus.ERROR, "org.bundlemaker.core.jdt", "Unable to copy file " + resourceStandin.getRoot() + "to " + targetFile + ": " + e, e)); } } // Refresh source-folder to make Eclipse aware of new copied files srcFolder.refreshLocal(1, progressMonitor); }
From source file:org.bundlemaker.core.jdt.internal.parser.JdtProjectHelper.java
License:Open Source License
/** * <p>/*from w ww . j av a 2 s.c o m*/ * </p> * * @param bundleMakerProject * @throws CoreException */ public static void setupAssociatedJavaProject(IProjectDescriptionAwareBundleMakerProject project) throws CoreException { try { // step 1: get the associated JDT project IJavaProject javaProject = getAssociatedJavaProject(project); // step 2: 'unset' the class path javaProject.setRawClasspath(null, null); // step 3: create the entries list List<IClasspathEntry> entries = new LinkedList<IClasspathEntry>(); // step 3.1: add the vm path IVMInstall vmInstall = VMInstallUtils.getIVMInstall(project.getProjectDescription().getJRE()); IPath path = JavaRuntime.newJREContainerPath(vmInstall); IClasspathEntry classpathEntry = JavaCore.newContainerEntry(path); entries.add(classpathEntry); // step 3.2: add the binary paths for (IProjectContentEntry projectContent : project.getProjectDescription().getContent()) { // TODO!! IPath sourceRoot = null; if (!projectContent.getSourceRootPaths().isEmpty()) { sourceRoot = projectContent.getSourceRootPaths().toArray(new VariablePath[0])[0] .getResolvedPath(); } // add binary paths for (VariablePath iClasspathEntry : projectContent.getBinaryRootPaths()) { classpathEntry = JavaCore.newLibraryEntry(iClasspathEntry.getResolvedPath(), sourceRoot, null); entries.add(classpathEntry); } } // set the classpath javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[0]), null); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.bundlemaker.core.osgi.exporter.pde.PdePluginProjectModuleExporter.java
License:Open Source License
/** * {@inheritDoc}/*from ww w . j a va 2s. co m*/ */ @Override public void doExport(IProgressMonitor progressMonitor) throws CoreException { // step 1: get a non-existing project name String projectName = Helper.getUniqueProjectName(getCurrentModule().getModuleIdentifier().getName()); // step 2: delete and create project IPath location = null; if (isUseClassifcationForExportDestination()) { Path destinationDirectoryPath = new Path( getCurrentContext().getDestinationDirectory().getAbsolutePath()); location = destinationDirectoryPath.append(getCurrentModule().getClassification()).append(projectName); } // (re-)create the project IProject project = Helper.deleteAndCreateProject(projectName, location); // step 3: add java and plug-nature IProjectDescription description = project.getDescription(); description.setNatureIds(new String[] { JavaCore.NATURE_ID, IBundleProjectDescription.PLUGIN_NATURE }); project.setDescription(description, null); // 'clean' the java project IJavaProject javaProject = JavaCore.create(project); javaProject.setRawClasspath(new IClasspathEntry[] { JavaRuntime.getDefaultJREContainerEntry() }, null); javaProject.save(null, true); // step 4: create and set the bundle project description IBundleProjectService bundleProjectService = Activator.getBundleProjectService(); IBundleProjectDescription bundleProjectDescription = bundleProjectService.getDescription(project); // for (String header : getManifestContents().getMainAttributes().keySet()) { bundleProjectDescription.setHeader(header, getManifestContents().getMainAttributes().get(header)); } // set source dir IBundleClasspathEntry bundleClasspathEntry = bundleProjectService .newBundleClasspathEntry(new Path(SRC_DIRECTORY_NAME), new Path(BIN_DIRECTORY_NAME), null); // bundleProjectDescription.setBundleClassath(new IBundleClasspathEntry[] { bundleClasspathEntry }); // bundleProjectDescription.apply(null); // step 5: copy the source files IFolder srcFolder = project.getFolder(SRC_DIRECTORY_NAME); // copy the source for (IProjectContentResource resourceStandin : getCurrentModule().getResources(ResourceType.SOURCE)) { if (!resourceStandin.getPath().startsWith("META-INF")) { // File targetFile = new File(srcFolder.getRawLocation().toFile(), resourceStandin.getPath()); targetFile.getParentFile().mkdirs(); try { // FileUtils.copy(new ByteArrayInputStream(resourceStandin.getContent()), new FileOutputStream(targetFile), new byte[1024]); } catch (Exception e) { throw new CoreException(new Status(IStatus.ERROR, Activator.BUNDLE_ID, "Unable to copy file " + resourceStandin.getRoot() + "to " + targetFile + ": " + e, e)); } } } // Refresh source-folder to make Eclipse aware of new copied files srcFolder.refreshLocal(1, progressMonitor); }
From source file:org.codehaus.groovy.eclipse.core.model.GroovyRuntime.java
License:Apache License
public static void removeLibraryFromClasspath(final IJavaProject javaProject, final IPath libraryPath) throws JavaModelException { final IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); for (int i = 0; i < oldEntries.length; i++) { final IClasspathEntry entry = oldEntries[i]; if (entry.getPath().equals(libraryPath)) { final IClasspathEntry[] newEntries = (IClasspathEntry[]) ArrayUtils.remove(oldEntries, i); javaProject.setRawClasspath(newEntries, null); return; }/*from ww w . java 2s . co m*/ } }
From source file:org.codehaus.groovy.eclipse.core.model.GroovyRuntime.java
License:Apache License
public static void removeClasspathContainer(IPath containerPath, IJavaProject javaProject) { try {// w ww .j a v a2 s . c o m if (!hasGroovyClasspathContainer(javaProject)) { return; } IClasspathEntry[] entries = javaProject.getRawClasspath(); int removeIndex = -1; for (int i = 0; i < entries.length; i++) { if (entries[i].getPath().equals(containerPath)) { removeIndex = i; break; } } IClasspathEntry[] newEntries = (IClasspathEntry[]) ArrayUtils.remove(entries, removeIndex); javaProject.setRawClasspath(newEntries, null); } catch (final CoreException ce) { GroovyCore.logException("Failed to add groovy classpath container:" + ce.getMessage(), ce); throw new RuntimeException(ce); } }
From source file:org.codehaus.groovy.eclipse.core.model.GroovyRuntime.java
License:Apache License
/** * Adds a classpath entry to the end of a project's the classpath * * @param project// ww w . jav a 2 s. c o m * The project to add the entry to. * @param newEntry * The entry to add. * @throws JavaModelException */ public static void addClassPathEntry(IJavaProject project, IClasspathEntry newEntry) throws JavaModelException { IClasspathEntry[] newEntries = (IClasspathEntry[]) ArrayUtils.add(project.getRawClasspath(), newEntry); project.setRawClasspath(newEntries, null); }
From source file:org.codehaus.groovy.eclipse.core.model.GroovyRuntime.java
License:Apache License
/** * Adds a classpath entry to the front of a project's the classpath * * @param project//w w w.j a v a 2s . co m * The project to add the entry to. * @param newEntry * The entry to add. * @throws JavaModelException */ public static void addClassPathEntryToFront(IJavaProject project, IClasspathEntry newEntry) throws JavaModelException { IClasspathEntry[] newEntries = (IClasspathEntry[]) ArrayUtils.add(project.getRawClasspath(), 0, newEntry); project.setRawClasspath(newEntries, null); }