List of usage examples for org.eclipse.jdt.core JavaCore newContainerEntry
public static IClasspathEntry newContainerEntry(IPath containerPath)
CPE_CONTAINER
for the given path. 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 2 s. 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.buildpath.JavaFXContainerWizardPage.java
License:Open Source License
public JavaFXContainerWizardPage() { super("JavaFXContainerPage"); //$NON-NLS-1$ setTitle("JavaFX Library"); setDescription("JavaFX Library Selection"); setImageDescriptor(JavaPluginImages.DESC_WIZBAN_ADD_LIBRARY); fContainerEntryResult = JavaCore.newContainerEntry(JavaFXCore.JAVAFX_CONTAINER_PATH); }
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) {// w ww . j ava 2 s. com 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 av a 2s . 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.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 w w. j a v a2s . 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.spardat.xma.gui.projectw.cp.ProjectClassPathHandler.java
License:Open Source License
public static IClasspathEntry[] createClassPath(ClassPathDetector detec, IJavaProject prj, String prjName) { List cp = new ArrayList(); try {/*from w w w .j a v a2s .co m*/ if (detec != null) { IClasspathEntry[] entries = detec.getClasspath(); if (entries != null) cp.addAll(Arrays.asList(entries)); } // IClasspathEntry[] defaultEntries = prj.getRawClasspath(); // if( defaultEntries != null) // cp.addAll(Arrays.asList(defaultEntries)); Path p = null; IClasspathEntry entry = null; //compute the basic classpath IClassPathProvider prov = new BasicClassPathProvider(); cp.addAll(Arrays.asList(prov.provideCP())); //compute the additive classpath from the extension prov = XMAProjectCreationWizzardPlugin.getDefault().getClassPathProvider(); cp.addAll(Arrays.asList(prov.provideCP())); p = new Path(JavaRuntime.JRE_CONTAINER); entry = JavaCore.newContainerEntry(p); cp.add(entry); p = new Path("/" + prjName + "/src"); entry = JavaCore.newSourceEntry(p); cp.add(entry); return (IClasspathEntry[]) cp.toArray(new IClasspathEntry[cp.size()]); } catch (Exception e) { IStatus status = new Status(IStatus.ERROR, XMAProjectCreationWizzardPlugin.PLUGINID, -1, "Error creating the classpath", e); XMAProjectCreationWizzardPlugin.getDefault().getLog().log(status); return 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. j a v a 2s . c o 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:ca.mcgill.sable.soot.launching.DavaHandler.java
License:Open Source License
private boolean createSpecialDavaProject(IPath jreLibPath) { IWorkbenchWindow window = SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow(); MessageDialog create = new MessageDialog(window.getShell(), Messages.getString("DavaHandler.Soot_Question"), null,//from w w w . ja v a 2 s . c o m Messages.getString( "DavaHandler.Would_you_like_to_create_a_new_Dava_Project_with_generated_Dava_src_files"), 0, new String[] { Messages.getString("DavaHandler.OK"), Messages.getString("DavaHandler.Cancel") }, 0); create.open(); if (create.getReturnCode() == Dialog.OK) { // create proj IProject proj = SootPlugin.getWorkspace().getRoot().getProject(getDavaProjName()); if (!proj.exists()) { try { proj.create(null); proj.open(null); IProjectDescription pd = proj.getDescription(); String[] natures = new String[] { Messages.getString("org.eclipse.jdt.core.javanature") }; pd.setNatureIds(natures); proj.setDescription(pd, null); setDavaProj(JavaCore.create(proj)); IFolder folder = proj.getFolder(Messages.getString("DavaHandler.src")); //$NON-NLS-1$ if (!folder.exists()) { folder.create(false, true, null); } setSrcFolder(folder); IFolder out = proj.getFolder(Messages.getString("DavaHandler.bin")); //$NON-NLS-1$ if (!folder.exists()) { folder.create(false, true, null); } getDavaProj().setOutputLocation(out.getFullPath(), null); IClasspathEntry[] entries = new IClasspathEntry[2]; entries[0] = JavaCore.newSourceEntry(folder.getFullPath()); if (jreLibPath != null) { entries[1] = JavaCore.newContainerEntry(jreLibPath); } getDavaProj().setRawClasspath(entries, null); return true; } catch (CoreException e) { e.printStackTrace(); return false; } } } return false; }
From source file:ccw.wizards.NewClojureProjectWizard.java
License:Open Source License
private void setupJavaProjectClassPath(IJavaProject javaProject) throws CoreException { IClasspathEntry[] entriesOld = javaProject.getRawClasspath(); IClasspathEntry[] entriesNew = new IClasspathEntry[entriesOld.length + 1]; System.arraycopy(entriesOld, 0, entriesNew, 0, entriesOld.length); // Ensure a proper "src" directory is used for sources (and not the project) for (int i = 0; i < entriesOld.length; i++) { if (entriesOld[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { IFolder src = javaProject.getProject().getFolder("src"); if (!src.exists()) src.create(true, true, null); entriesNew[i] = JavaCore.newSourceEntry(src.getFullPath()); }/*from ww w. j a va2 s. co m*/ } entriesNew[entriesOld.length] = JavaCore .newContainerEntry(Path.fromPortableString(JavaRuntime.JRE_CONTAINER)); javaProject.setRawClasspath(entriesNew, null); javaProject.save(null, true); }
From source file:ch.mlutz.plugins.t4e.handlers.ClasspathContainerHandler.java
License:Open Source License
private Object onAddClasspathContainer(ExecutionEvent event) throws ExecutionException { // boolean oldValue = HandlerUtil.toggleCommandState(event.getCommand()); String localRepositoryDir = MavenTools.getMavenLocalRepoPath(); log.info("LocalRepositoryDir: " + localRepositoryDir); /*//from w w w . jav a 2 s . c o m try { JavaCore.setClasspathContainer(containerSuggestion.getPath(), new IJavaProject[] {project}, new IClasspathContainer[] {new Maven2ClasspathContainer(containerPath, bundleUpdater.newEntries)}, null); } catch(JavaModelException ex) { Maven2Plugin.getDefault().getConsole().logError(ex.getMessage()); } */ // get workbench window IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); // set selection service ISelectionService service = window.getSelectionService(); // set structured selection IStructuredSelection structured = (IStructuredSelection) service.getSelection(); //check if it is an IFile Object el = structured.getFirstElement(); if (el instanceof IJavaProject) { IJavaProject javaProject = (IJavaProject) el; // Create new Classpath Container Entry IClasspathEntry containerEntry = JavaCore.newContainerEntry(CONTAINER_PATH); // Initialize Classpath Container ClasspathContainerInitializer containerInit = JavaCore .getClasspathContainerInitializer(Constants.CONTAINER_ID); try { containerInit.initialize(new Path(Constants.CONTAINER_ID), javaProject); // Set Classpath of Java Project List<IClasspathEntry> projectClassPath = new ArrayList<IClasspathEntry>( Arrays.asList(javaProject.getRawClasspath())); projectClassPath.add(containerEntry); javaProject.setRawClasspath(projectClassPath.toArray(new IClasspathEntry[projectClassPath.size()]), null); } catch (CoreException e) { log.error("Could not add Classpath container: ", e); } /* IClasspathEntry varEntry = JavaCore.newContainerEntry( new Path("JDKLIB/default"), // container 'JDKLIB' + hint 'default' false); //not exported try { JavaCore.setClasspathContainer( new Path("JDKLIB/default"), new IJavaProject[]{ (IJavaProject) el }, // value for 'myProject' new IClasspathContainer[] { new IClasspathContainer() { public IClasspathEntry[] getClasspathEntries() { return new IClasspathEntry[]{ JavaCore.newLibraryEntry(new Path("d:/rt.jar"), null, null, false) }; } public String getDescription() { return "Basic JDK library container"; } public int getKind() { return IClasspathContainer.K_SYSTEM; } public IPath getPath() { return new Path("JDKLIB/basic"); } } }, null); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } */ } return null; }