List of usage examples for org.eclipse.jdt.core IJavaProject setRawClasspath
void setRawClasspath(IClasspathEntry[] entries, IProgressMonitor monitor) throws JavaModelException;
From source file:ariba.ideplugin.eclipse.wizards.CreateProject.java
License:Apache License
public void updateClasspath(IJavaProject proj, File root, String projectName, IProgressMonitor monitor) { try {/*from w w w .j a v a 2s . c o m*/ File buildFile = new File(root, "build.xml"); List<String> paths = _connector.getRequiredLibs(buildFile); IClasspathEntry jreEntry = JavaCore .newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER")); IClasspathEntry srcEntry = JavaCore.newSourceEntry(new Path("/" + projectName)); ArrayList<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); entries.add(srcEntry); entries.add(jreEntry); String awhome = new File(_connector.getAWHome()).getCanonicalPath(); String fileSeperator = System.getProperty("file.separator"); int len = awhome.endsWith(fileSeperator) ? awhome.length() - 1 : awhome.length(); for (int i = 0; i < paths.size(); i++) { String path = new File(paths.get(i)).getCanonicalPath(); if (path.startsWith(awhome)) { path = Activator.ClasspathAWHome + path.substring(len); } if (fileSeperator.equals("\\") && path.indexOf('\\') > -1) { path = path.replace('\\', '/'); } if (path.endsWith(".jar") || path.endsWith(".zip")) { Path src = null; if (paths.get(i).indexOf("ariba.appcore") > -1) { src = new Path(Activator.ClasspathAWHome + "/lib/ariba.appcore-src.jar"); } else if (paths.get(i).indexOf("ariba.") > -1) { src = new Path(Activator.ClasspathAWHome + "/lib/ariba.aw-all-src.jar"); } if (path.startsWith(Activator.ClasspathAWHome)) { entries.add(JavaCore.newVariableEntry(new Path(path), src, null)); } else { entries.add(JavaCore.newLibraryEntry(new Path(path), src, null)); } } } IClasspathEntry[] centries = new IClasspathEntry[entries.size()]; proj.setRawClasspath(entries.toArray(centries), monitor); } catch (JavaModelException e) { throw new WrapperRuntimeException(e); } catch (IOException e) { throw new WrapperRuntimeException(e); } }
From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.wizard.JavaFXLibraryProjectWizard.java
License:Open Source License
@Override public boolean performFinish() { boolean res = super.performFinish(); if (res) {//from w w w . j a va2 s. c om final IJavaElement newElement = getCreatedElement(); try { IJavaProject p = (IJavaProject) newElement; IClasspathEntry[] current = p.getRawClasspath(); IClasspathEntry[] currentFX = new IClasspathEntry[current.length + 1]; System.arraycopy(current, 0, currentFX, 0, current.length); currentFX[current.length] = JavaCore.newContainerEntry(JavaFXCore.JAVAFX_CONTAINER_PATH); p.setRawClasspath(currentFX, new NullProgressMonitor()); } catch (JavaModelException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } IWorkingSet[] workingSets = fFirstPage.getWorkingSets(); if (workingSets.length > 0) { PlatformUI.getWorkbench().getWorkingSetManager().addToWorkingSets(newElement, workingSets); } BasicNewProjectResourceWizard.updatePerspective(fConfigElement); selectAndReveal(fSecondPage.getJavaProject().getProject()); Display.getDefault().asyncExec(new Runnable() { public void run() { IWorkbenchPart activePart = getActivePart(); if (activePart instanceof IPackagesViewPart) { PackageExplorerPart view = PackageExplorerPart.openInActivePerspective(); view.tryToReveal(newElement); } } }); } return res; }
From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.wizard.JavaFXProjectWizard.java
License:Open Source License
@Override public boolean performFinish() { boolean res = super.performFinish(); if (res) {/*from w w w .j a va 2 s . c o m*/ final IJavaElement newElement = getCreatedElement(); IWorkingSet[] workingSets = fFirstPage.getWorkingSets(); if (workingSets.length > 0) { PlatformUI.getWorkbench().getWorkingSetManager().addToWorkingSets(newElement, workingSets); } try { IJavaProject p = (IJavaProject) newElement; IClasspathEntry[] current = p.getRawClasspath(); IClasspathEntry[] currentFX = new IClasspathEntry[current.length + 1]; System.arraycopy(current, 0, currentFX, 0, current.length); currentFX[current.length] = JavaCore.newContainerEntry(JavaFXCore.JAVAFX_CONTAINER_PATH); p.setRawClasspath(currentFX, new NullProgressMonitor()); } catch (JavaModelException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } IFile buildFile = fSecondPage.getJavaProject().getProject().getFile(new Path("build.fxbuild")); try { StringBuilder b = new StringBuilder(); // TODO write as xmi file b.append("jfx.build.stagingdir = ${workspace}/" + fFirstPage.getProjectName() + "/build"); b.append(System.getProperty("line.separator")); b.append("jfx.build.apptitle = " + fFirstPage.getProjectName()); ByteArrayInputStream stream = new ByteArrayInputStream(b.toString().getBytes()); buildFile.create(stream, true, new NullProgressMonitor()); stream.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } BasicNewProjectResourceWizard.updatePerspective(fConfigElement); selectAndReveal(fSecondPage.getJavaProject().getProject()); Display.getDefault().asyncExec(new Runnable() { public void run() { IWorkbenchPart activePart = getActivePart(); if (activePart instanceof IPackagesViewPart) { PackageExplorerPart view = PackageExplorerPart.openInActivePerspective(); view.tryToReveal(newElement); } } }); } return res; }
From source file:at.bestsolution.efxclipse.tooling.rrobot.impl.JDTProjectHandler.java
License:Open Source License
protected IStatus customizeProject(IProgressMonitor monitor, IProject project, P model) { try {/*from w w w .j a v a2 s.c o m*/ addNatureToProject(project, JavaCore.NATURE_ID, monitor); IJavaProject javaProject = JavaCore.create(project); javaProject.setOutputLocation(project.getFullPath().append("bin"), monitor); //FIXME has to come from model IClasspathEntry[] tmpEntries = createClasspathEntries(model); IClasspathEntry[] entries = new IClasspathEntry[tmpEntries.length + model.getSourceFragments().size()]; int i = 0; for (SourceFragment f : model.getSourceFragments()) { StringBuilder b = new StringBuilder(); Folder folder = f.getFolder(); while (folder != null) { if (b.length() > 0) { b.insert(0, "/"); } b.insert(0, folder.getName()); if (folder.eContainer() instanceof Folder) { folder = (Folder) folder.eContainer(); } else { break; } } entries[i] = JavaCore.newSourceEntry(project.getProject().getFullPath().append(b.toString())); } System.arraycopy(tmpEntries, 0, entries, model.getSourceFragments().size(), tmpEntries.length); javaProject.setRawClasspath(entries, monitor); } catch (CoreException e) { return new Status(IStatus.ERROR, PLUGIN_ID, "Unable to add nature", e); } return super.customizeProject(monitor, project, model); }
From source file:at.bestsolution.fxide.jdt.maven.MavenModuleTypeService.java
License:Open Source License
@Override public Status createModule(IProject project, IResource resource) { IProjectDescription description = project.getWorkspace().newProjectDescription(project.getName()); description.setNatureIds(new String[] { JavaCore.NATURE_ID, "org.eclipse.m2e.core.maven2Nature" }); ICommand[] commands = new ICommand[2]; {//from w w w. j a va 2s. c o m ICommand cmd = description.newCommand(); cmd.setBuilderName(JavaCore.BUILDER_ID); commands[0] = cmd; } { ICommand cmd = description.newCommand(); cmd.setBuilderName("org.eclipse.m2e.core.maven2Builder"); commands[1] = cmd; } if (resource != null) { // If we get a parent path we create a nested project try { if (resource.getProject().getNature("org.eclipse.m2e.core.maven2Nature") != null) { IFolder folder = resource.getProject().getFolder(project.getName()); if (folder.exists()) { return Status.status(State.ERROR, -1, "Folder already exists", null); } folder.create(true, true, null); description.setLocation(folder.getLocation()); } } catch (CoreException e1) { // TODO Auto-generated catch block e1.printStackTrace(); return Status.status(State.ERROR, -1, "Could not create parent relation", e1); } } description.setBuildSpec(commands); try { project.create(description, null); project.open(null); project.getFolder(new Path("target")).create(true, true, null); project.getFolder(new Path("target").append("classes")).create(true, true, null); project.getFolder(new Path("target")).setDerived(true, null); project.getFolder(new Path("target").append("classes")).setDerived(true, null); project.getFolder(new Path("src")).create(true, true, null); project.getFolder(new Path("src").append("main")).create(true, true, null); project.getFolder(new Path("src").append("main").append("java")).create(true, true, null); project.getFolder(new Path("src").append("main").append("resources")).create(true, true, null); project.getFolder(new Path("src").append("test")).create(true, true, null); project.getFolder(new Path("src").append("test").append("java")).create(true, true, null); project.getFolder(new Path("src").append("test").append("resources")).create(true, true, null); { IFile file = project.getFile(new Path("pom.xml")); try (InputStream templateStream = getClass().getResourceAsStream("template-pom.xml")) { String pomContent = IOUtils.readToString(templateStream, Charset.forName("UTF-8")); Map<String, String> map = new HashMap<>(); map.put("groupId", project.getName()); map.put("artifactId", project.getName()); map.put("version", "1.0.0"); file.create(new ByteArrayInputStream(StrSubstitutor.replace(pomContent, map).getBytes()), true, null); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } IJavaProject jProject = JavaCore.create(project); jProject.setOutputLocation(project.getFolder(new Path("target").append("classes")).getFullPath(), null); List<IClasspathEntry> entries = new ArrayList<>(); { IClasspathAttribute[] attributes = new IClasspathAttribute[2]; attributes[0] = JavaCore.newClasspathAttribute("optional", "true"); attributes[1] = JavaCore.newClasspathAttribute("maven.pomderived", "true"); IPath path = new Path("src").append("main").append("java"); IPath output = new Path("target").append("classes"); IClasspathEntry sourceEntry = JavaCore.newSourceEntry( project.getProject().getFullPath().append(path), null, null, project.getProject().getFullPath().append(output), attributes); entries.add(sourceEntry); } { IClasspathAttribute[] attributes = new IClasspathAttribute[1]; attributes[0] = JavaCore.newClasspathAttribute("maven.pomderived", "true"); IPath path = new Path("src").append("main").append("resources"); IPath output = new Path("target").append("classes"); IPath[] exclusions = new IPath[] { new Path("**") }; entries.add(JavaCore.newSourceEntry(project.getProject().getFullPath().append(path), null, exclusions, project.getProject().getFullPath().append(output), attributes)); } { IClasspathAttribute[] attributes = new IClasspathAttribute[2]; attributes[0] = JavaCore.newClasspathAttribute("optional", "true"); attributes[1] = JavaCore.newClasspathAttribute("maven.pomderived", "true"); IPath path = new Path("src").append("test").append("java"); IPath output = new Path("target").append("test-classes"); IClasspathEntry sourceEntry = JavaCore.newSourceEntry( project.getProject().getFullPath().append(path), null, null, project.getProject().getFullPath().append(output), attributes); entries.add(sourceEntry); } { IClasspathAttribute[] attributes = new IClasspathAttribute[1]; attributes[0] = JavaCore.newClasspathAttribute("maven.pomderived", "true"); IPath path = new Path("src").append("test").append("resources"); IPath output = new Path("target").append("test-classes"); IPath[] exclusions = new IPath[] { new Path("**") }; entries.add(JavaCore.newSourceEntry(project.getProject().getFullPath().append(path), null, exclusions, project.getProject().getFullPath().append(output), attributes)); } { IClasspathAttribute[] attributes = new IClasspathAttribute[1]; attributes[0] = JavaCore.newClasspathAttribute("maven.pomderived", "true"); IPath path = JavaRuntime.newDefaultJREContainerPath(); entries.add(JavaCore.newContainerEntry(path, null, attributes, false)); } { IClasspathAttribute[] attributes = new IClasspathAttribute[1]; attributes[0] = JavaCore.newClasspathAttribute("maven.pomderived", "true"); IPath path = new Path("org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"); entries.add(JavaCore.newContainerEntry(path, null, attributes, false)); } jProject.setRawClasspath(entries.toArray(new IClasspathEntry[0]), null); project.getWorkspace().save(true, null); return Status.ok(); } catch (CoreException ex) { //TODO ex.printStackTrace(); return Status.status(State.ERROR, -1, "Failed to create project", ex); } }
From source file:at.bestsolution.fxide.jdt.services.JDTModuleTypeService.java
License:Open Source License
@Override public Status createModule(IProject project, IResource resource) { IProjectDescription description = project.getWorkspace().newProjectDescription(project.getName()); description.setNatureIds(new String[] { JavaCore.NATURE_ID }); ICommand cmd = description.newCommand(); cmd.setBuilderName(JavaCore.BUILDER_ID); description.setBuildSpec(new ICommand[] { cmd }); try {/* w ww .j a v a2 s. com*/ project.create(description, null); project.open(null); project.getFolder(new Path("target")).create(true, true, null); project.getFolder(new Path("target").append("classes")).create(true, true, null); project.getFolder(new Path("target")).setDerived(true, null); project.getFolder(new Path("target").append("classes")).setDerived(true, null); project.getFolder(new Path("src")).create(true, true, null); project.getFolder(new Path("src").append("main")).create(true, true, null); project.getFolder(new Path("src").append("main").append("java")).create(true, true, null); project.getFolder(new Path("src").append("main").append("resources")).create(true, true, null); project.getFolder(new Path("src").append("test")).create(true, true, null); project.getFolder(new Path("src").append("test").append("java")).create(true, true, null); project.getFolder(new Path("src").append("test").append("resources")).create(true, true, null); // IExecutionEnvironmentsManager executionEnvironmentsManager = JavaRuntime.getExecutionEnvironmentsManager(); // IExecutionEnvironment[] executionEnvironments = executionEnvironmentsManager.getExecutionEnvironments(); // System.err.println(JavaRuntime.getDefaultVMInstall().getInstallLocation()); IJavaProject jProject = JavaCore.create(project); jProject.setOutputLocation(project.getFolder(new Path("target").append("classes")).getFullPath(), null); List<IClasspathEntry> entries = new ArrayList<>(); entries.add(JavaCore.newSourceEntry( project.getProject().getFullPath().append("src").append("main").append("java"))); entries.add(JavaCore.newSourceEntry( project.getProject().getFullPath().append("src").append("main").append("resources"))); entries.add(JavaCore.newSourceEntry( project.getProject().getFullPath().append("src").append("test").append("java"))); entries.add(JavaCore.newSourceEntry( project.getProject().getFullPath().append("src").append("test").append("resources"))); entries.add(JavaCore.newContainerEntry(JavaRuntime.newDefaultJREContainerPath())); jProject.setRawClasspath(entries.toArray(new IClasspathEntry[0]), null); project.getWorkspace().save(true, null); return Status.ok(); } catch (CoreException ex) { return Status.status(State.ERROR, -1, "Failed to create project", ex); } }
From source file:at.component.newcomponentwizard.generator.NewProjectCreationOperation.java
License:Open Source License
private void setClasspath(IProject project, IFieldData data) throws JavaModelException, CoreException { IJavaProject javaProject = JavaCore.create(project); // Set output folder if (data.getOutputFolderName() != null) { IPath path = project.getFullPath().append(data.getOutputFolderName()); javaProject.setOutputLocation(path, null); }/*www .jav a 2s .co m*/ IClasspathEntry[] entries = getClassPathEntries(javaProject, data); javaProject.setRawClasspath(entries, null); }
From source file: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 && BndContainerInitializer.PATH_ID.equals(entry.getPath())) return; // already installed }//from w w w .ja va2 s .co m IClasspathEntry[] newEntries = new IClasspathEntry[classpath.length + 1]; System.arraycopy(classpath, 0, newEntries, 0, classpath.length); newEntries[classpath.length] = JavaCore.newContainerEntry(BndContainerInitializer.PATH_ID); javaProject.setRawClasspath(newEntries, null); }
From source file: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 && BndContainerInitializer.PATH_ID.equals(entry.getPath())) { changed = true;//from w ww . j a v a 2s. c o m } else { newEntries.add(entry); } } if (changed) javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[newEntries.size()]), null); }
From source file:ca.mcgill.sable.soot.examples.NewSootExampleWizard.java
License:Open Source License
@Override public boolean performFinish() { boolean performFinish = super.performFinish(); if (performFinish) { IJavaProject newProject = (IJavaProject) getCreatedElement(); try {//w w w. j a v a 2 s .com IClasspathEntry[] originalCP = newProject.getRawClasspath(); IClasspathEntry ajrtLIB = JavaCore.newVariableEntry( new Path(SootClasspathVariableInitializer.VARIABLE_NAME_CLASSES), new Path(SootClasspathVariableInitializer.VARIABLE_NAME_SOURCE), null); // Update the raw classpath with the new entry int originalCPLength = originalCP.length; IClasspathEntry[] newCP = new IClasspathEntry[originalCPLength + 1]; System.arraycopy(originalCP, 0, newCP, 0, originalCPLength); newCP[originalCPLength] = ajrtLIB; newProject.setRawClasspath(newCP, new NullProgressMonitor()); } catch (JavaModelException e) { } String templateFilePath = fromFile; InputStream is = null; FileOutputStream fos = null; try { is = SootPlugin.getDefault().getBundle().getResource(templateFilePath).openStream(); if (is == null) { new RuntimeException("Resource " + templateFilePath + " not found!").printStackTrace(); } else { IClasspathEntry[] resolvedClasspath = newProject.getResolvedClasspath(true); IClasspathEntry firstSourceEntry = null; for (IClasspathEntry classpathEntry : resolvedClasspath) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { firstSourceEntry = classpathEntry; break; } } if (firstSourceEntry != null) { IPath path = SootPlugin.getWorkspace().getRoot().getFile(firstSourceEntry.getPath()) .getLocation(); String srcPath = path.toString(); String newfileName = toFile; final IPath newFilePath = firstSourceEntry.getPath().append(newfileName); fos = new FileOutputStream(srcPath + File.separator + newfileName); int temp = is.read(); while (temp > -1) { fos.write(temp); temp = is.read(); } fos.close(); //refresh project newProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); final IWorkbenchPage activePage = JavaPlugin.getActivePage(); if (activePage != null) { final Display display = getShell().getDisplay(); if (display != null) { display.asyncExec(new Runnable() { public void run() { try { IResource newResource = SootPlugin.getWorkspace().getRoot() .findMember(newFilePath); IDE.openEditor(activePage, (IFile) newResource, true); } catch (PartInitException e) { JavaPlugin.log(e); } } }); } } } } } catch (Exception e) { e.printStackTrace(); } finally { try { if (is != null) is.close(); if (fos != null) fos.close(); } catch (IOException e) { } } } return performFinish; }