List of usage examples for org.eclipse.jdt.core IJavaProject setRawClasspath
void setRawClasspath(IClasspathEntry[] entries, IProgressMonitor monitor) throws JavaModelException;
From source file:org.eclipse.recommenders.internal.coordinates.rcp.EclipseDependencyListenerTest.java
License:Open Source License
private static void appendJavaProjectToClasspath(IJavaProject javaProject, IJavaProject dependency) throws Exception { IClasspathEntry sourceEntry = JavaCore.newProjectEntry(dependency.getPath()); javaProject.setRawClasspath(concat(javaProject.getRawClasspath(), sourceEntry), new NullProgressMonitor()); }
From source file:org.eclipse.recommenders.internal.rcp.JavaModelEventsProviderTest.java
License:Open Source License
@Test public void test() throws CoreException { JavaProjectFixture f = new JavaProjectFixture(workspace, "model-events"); IJavaProject project = f.getJavaProject(); project.close();//from w w w .j a v a2 s .c om project.open(null); Pair<ICompilationUnit, List<Integer>> m = f.createFileAndParseWithMarkers("public class C {}"); ICompilationUnit cu = m.getFirst(); cu.getBuffer().append("// COMMENT"); cu.save(null, true); cu.delete(true, null); List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall(); LibraryLocation[] locations = JavaRuntime.getLibraryLocations(vmInstall); for (LibraryLocation element : locations) { entries.add(JavaCore.newLibraryEntry(element.getSystemLibraryPath(), null, null)); } // IFolder sourceFolder = project.getFolder("src"); // sourceFolder.create(false, true, null); // add libs to project class path project.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null); project.close(); }
From source file:org.eclipse.recommenders.tests.models.EclipseDependencyListenerTest.java
License:Open Source License
private IJavaProject createProject(final String projectName) throws Exception { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject project = workspaceRoot.getProject(projectName); project.create(null);// www . ja v a 2 s . com project.open(null); IProjectDescription description = project.getDescription(); description.setNatureIds(new String[] { JavaCore.NATURE_ID }); project.setDescription(description, null); IJavaProject javaProject = JavaCore.create(project); List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); entries.add(JavaRuntime.getDefaultJREContainerEntry()); javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null); IFolder sourceFolder = project.getFolder("src"); sourceFolder.create(false, true, null); IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(sourceFolder); IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1]; System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length); newEntries[oldEntries.length] = JavaCore.newSourceEntry(root.getPath()); javaProject.setRawClasspath(newEntries, null); javaProject.open(null); return javaProject; }
From source file:org.eclipse.titan.codegenerator.AstWalkerJava.java
License:Open Source License
public void run(IAction action) { /**///from w w w . j a v a 2s . c om IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); for (IProject p : projects) { if (p.getName().equals("org.eclipse.titan.codegenerator.output")) try { p.delete(true, true, null); } catch (Exception e) { e.printStackTrace(); } } IProject project = ResourcesPlugin.getWorkspace().getRoot() .getProject("org.eclipse.titan.codegenerator.output"); try { project.create(null); project.open(null); IProjectDescription description = project.getDescription(); description.setNatureIds(new String[] { JavaCore.NATURE_ID }); project.setDescription(description, null); IJavaProject javaProject = JavaCore.create(project); IFolder binFolder = project.getFolder("bin"); binFolder.create(false, true, null); javaProject.setOutputLocation(binFolder.getFullPath(), null); List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall(); LibraryLocation[] locations = JavaRuntime.getLibraryLocations(vmInstall); for (LibraryLocation element : locations) { entries.add(JavaCore.newLibraryEntry(element.getSystemLibraryPath(), null, null)); } javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null); IFolder sourceFolder = project.getFolder("src"); sourceFolder.create(false, true, null); IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(sourceFolder); IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1]; System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length); newEntries[oldEntries.length] = JavaCore.newSourceEntry(root.getPath()); javaProject.setRawClasspath(newEntries, null); javaProject.getPackageFragmentRoot(sourceFolder) .createPackageFragment("org.eclipse.titan.codegenerator.javagen", false, null); javaProject.getPackageFragmentRoot(sourceFolder) .createPackageFragment("org.eclipse.titan.codegenerator.TTCN3JavaAPI", false, null); } catch (Exception e) { e.printStackTrace(); } String destpath = new String(""); String wspath = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString().replaceAll("/", "\\\\"); destpath += wspath; destpath += "\\org.eclipse.titan.codegenerator.output\\src\\org\\eclipse\\titan\\codegenerator\\javagen\\"; props.setProperty("javafile.path", destpath); /**/ AstWalkerJava.files.clear(); AstWalkerJava.fileNames.clear(); AstWalkerJava.componentList.clear(); AstWalkerJava.testCaseList.clear(); AstWalkerJava.testCaseRunsOnList.clear(); AstWalkerJava.functionList.clear(); AstWalkerJava.functionRunsOnList.clear(); AstWalkerJava.initOutputFolder(); AstWalkerJava.getActiveProject(); /* * // init console logger IConsole myConsole = findConsole("myLogger"); * IWorkbenchPage page = window.getActivePage(); String id = * IConsoleConstants.ID_CONSOLE_VIEW; IConsoleView view; try { view = * (IConsoleView) page.showView(id); view.display(myConsole); } catch * (PartInitException e) { // TODO Auto-generated catch block * e.printStackTrace(); } */ // initialize common files myASTVisitor.currentFileName = "TTCN_functions"; myASTVisitor.visualizeNodeToJava(myASTVisitor.importListStrings); myASTVisitor.visualizeNodeToJava("class TTCN_functions{\r\n}\r\n"); Def_Template_Visit_Handler.isTemplate = false; final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(selectedProject); sourceParser.analyzeAll(); logToConsole("Version built on 2016.10.24"); logToConsole("Starting to generate files into: " + props.getProperty("javafile.path")); myASTVisitor visitor = new myASTVisitor(); for (Module module : sourceParser.getModules()) { // start AST processing walkChildren(visitor, module.getOutlineChildren()); } visitor.finish(); logToConsole("Files generated into: " + props.getProperty("javafile.path")); // write additional classes Additional_Class_Writer additional_class = new Additional_Class_Writer(); myASTVisitor.currentFileName = "HC"; myASTVisitor.visualizeNodeToJava(myASTVisitor.importListStrings); myASTVisitor.visualizeNodeToJava(additional_class.writeHCClass()); myASTVisitor.currentFileName = "HCType"; myASTVisitor.visualizeNodeToJava(myASTVisitor.importListStrings); myASTVisitor.visualizeNodeToJava(additional_class.writeHCTypeClass()); // clear lists logger.severe("analysis complete"); /**/ File fromdir = new File(wspath + "\\org.eclipse.titan.codegenerator\\src\\org\\eclipse\\titan\\codegenerator\\TTCN3JavaAPI\\"); String toapidir = wspath + "\\org.eclipse.titan.codegenerator.output\\src\\org\\eclipse\\titan\\codegenerator\\TTCN3JavaAPI\\"; File[] fromfiles = fromdir.listFiles(); for (File f : fromfiles) { try { Files.copy(Paths.get(f.getAbsolutePath()), Paths.get(toapidir + f.getName()), StandardCopyOption.REPLACE_EXISTING); } catch (Exception e) { e.printStackTrace(); } } String tppath = wspath + "\\" + selectedProject.getFullPath().toString().split("/")[1] + "\\src\\"; File tp_cfg_dir = new File(tppath); String togendir = wspath + "\\org.eclipse.titan.codegenerator.output\\src\\org\\eclipse\\titan\\codegenerator\\javagen\\"; File[] from_testports_cfg = tp_cfg_dir.listFiles(); for (File f : from_testports_cfg) { if (f.getName().endsWith(".java")) { try { Files.copy(Paths.get(f.getAbsolutePath()), Paths.get(togendir + f.getName()), StandardCopyOption.REPLACE_EXISTING); } catch (Exception e) { e.printStackTrace(); } } if (f.getName().endsWith(".cfg")) { try { Files.copy(Paths.get(f.getAbsolutePath()), Paths.get(toapidir + "cfg.cfg"), StandardCopyOption.REPLACE_EXISTING); } catch (Exception e) { e.printStackTrace(); } } } try { ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); } catch (Exception e) { e.printStackTrace(); } /**/ }
From source file:org.eclipse.umlgen.gen.java.services.WorkspaceServices.java
License:Open Source License
/** * Creates a project from scratch in the workspace. * * @param eObject/*from w ww .ja v a 2s .c om*/ * The model element */ public void createDefaultProject(EObject eObject) { if (!EMFPlugin.IS_ECLIPSE_RUNNING) { return; } IProgressMonitor monitor = new NullProgressMonitor(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); try { IWorkspaceRoot workspaceRoot = workspace.getRoot(); String projectName = UML2JavaConfigurationHolder.getDefaultProjectName(eObject); IProject project = workspaceRoot.getProject(projectName); if (project.exists() && project.isAccessible()) { if (!project.isOpen()) { project.open(monitor); } } else { project.create(new NullProgressMonitor()); project.open(new NullProgressMonitor()); IContainer intputContainer = project; String sourceFolderName = UML2JavaConfigurationHolder.getSourceFolderPath(eObject); StringTokenizer stringTokenizer = new StringTokenizer(sourceFolderName, "/"); while (stringTokenizer.hasMoreTokens()) { String token = stringTokenizer.nextToken(); IFolder src = intputContainer.getFolder(new Path(token)); if (!src.exists()) { src.create(true, true, monitor); } intputContainer = src; } IContainer outputContainer = project; String outputFolderName = UML2JavaConfigurationHolder.getOutputFolderPath(eObject); stringTokenizer = new StringTokenizer(outputFolderName, "/"); while (stringTokenizer.hasMoreTokens()) { String token = stringTokenizer.nextToken(); IFolder out = outputContainer.getFolder(new Path(token)); if (!out.exists()) { out.create(true, true, monitor); } outputContainer = out; } IProjectDescription description = project.getDescription(); String[] natures = new String[] {}; if (IUML2JavaConstants.Default.DEFAULT_COMPONENT_ARTIFACTS_TYPE_OSGI .equals(UML2JavaConfigurationHolder.getComponentBasedArchitecture(eObject)) || IUML2JavaConstants.Default.DEFAULT_COMPONENT_ARTIFACTS_TYPE_ECLIPSE .equals(UML2JavaConfigurationHolder.getComponentBasedArchitecture(eObject))) { natures = new String[] { JavaCore.NATURE_ID, IUML2JavaConstants.PDE_PLUGIN_NATURE_ID }; } else { natures = new String[] { JavaCore.NATURE_ID, }; } description.setNatureIds(natures); project.setDescription(description, monitor); IJavaProject javaProject = JavaCore.create(project); List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); IExecutionEnvironmentsManager executionEnvironmentsManager = JavaRuntime .getExecutionEnvironmentsManager(); IExecutionEnvironment[] executionEnvironments = executionEnvironmentsManager .getExecutionEnvironments(); String defaultJREExecutionEnvironment = UML2JavaConfigurationHolder .getJREExecutionEnvironment(eObject); for (IExecutionEnvironment iExecutionEnvironment : executionEnvironments) { if (defaultJREExecutionEnvironment.equals(iExecutionEnvironment.getId())) { entries.add( JavaCore.newContainerEntry(JavaRuntime.newJREContainerPath(iExecutionEnvironment))); break; } } javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null); IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1]; System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length); javaProject.setOutputLocation(outputContainer.getFullPath(), monitor); IPackageFragmentRoot packageRoot = javaProject .getPackageFragmentRoot(intputContainer.getFullPath().toString()); newEntries[oldEntries.length] = JavaCore.newSourceEntry(packageRoot.getPath(), new Path[] {}, new Path[] {}, outputContainer.getFullPath()); javaProject.setRawClasspath(newEntries, null); IFile buildPropertiesFile = project.getFile("build.properties"); if (!buildPropertiesFile.exists()) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append( "#################################################################################" + System.getProperty(LINE_SEPARATOR)); stringBuilder.append("## " + UML2JavaConfigurationHolder.getCopyrightAndLicense(eObject) + System.getProperty(LINE_SEPARATOR)); stringBuilder.append( "#################################################################################" + System.getProperty(LINE_SEPARATOR)); stringBuilder.append("source.. = " + UML2JavaConfigurationHolder.getSourceFolderPath(eObject) + System.getProperty(LINE_SEPARATOR)); stringBuilder.append("output.. = " + UML2JavaConfigurationHolder.getOutputFolderPath(eObject) + System.getProperty(LINE_SEPARATOR)); stringBuilder.append("" + System.getProperty(LINE_SEPARATOR)); buildPropertiesFile.create(new ByteArrayInputStream(stringBuilder.toString().getBytes()), true, monitor); } } } catch (CoreException coreException) { AcceleoEnginePlugin.log(coreException, true); } }
From source file:org.eclipse.virgo.ide.facet.core.BundleFacetUninstallDelegate.java
License:Open Source License
protected void removeFromClasspath(IJavaProject javaProject, IClasspathEntry entry, IProgressMonitor monitor) throws CoreException { Set<IClasspathEntry> entries = new LinkedHashSet<IClasspathEntry>(); for (IClasspathEntry existingEntry : javaProject.getRawClasspath()) { if (!existingEntry.equals(entry)) { entries.add(existingEntry);/* w w w .ja v a2s .c om*/ } } javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), monitor); }
From source file:org.eclipse.virgo.ide.facet.core.CreatePlanProjectOperation.java
License:Open Source License
public void run(IProgressMonitor monitor) throws CoreException { monitor.beginTask("", planName != null ? 4 : 3); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProjectDescription description = workspace.newProjectDescription(projectHandle.getName()); description.setLocationURI(location); // create the new project operation CreateProjectOperation op = new CreateProjectOperation(description, ""); try {/*from w w w. ja v a2 s . com*/ op.execute(new NullProgressMonitor(), WorkspaceUndoUtil.getUIInfoAdapter(shell)); } catch (ExecutionException e1) { CoreException cex = new CoreException( new Status(IStatus.ERROR, FacetCorePlugin.PLAN_FACET_ID, e1.getMessage())); cex.initCause(e1); throw cex; } monitor.worked(1); // make it a Java/Plan project description = projectHandle.getDescription(); String[] natures = description.getNatureIds(); String[] newNatures = new String[natures.length + 3]; System.arraycopy(natures, 0, newNatures, 0, natures.length); System.arraycopy(new String[] { WST_FACET_NATURE, FacetCorePlugin.PLAN_NATURE_ID, JavaCore.NATURE_ID }, 0, newNatures, natures.length, 3); description.setNatureIds(newNatures); projectHandle.setDescription(description, null); monitor.worked(1); // setup classpath IJavaProject javaProject = JavaCore.create(projectHandle); IFolder binFolder = projectHandle.getFolder("bin"); binFolder.create(false, true, null); javaProject.setOutputLocation(binFolder.getFullPath(), null); IFolder sourceFolder = projectHandle.getFolder("src"); sourceFolder.create(false, true, null); IClasspathEntry sourceEntry = JavaCore.newSourceEntry(sourceFolder.getFullPath()); List<IClasspathEntry> entries = Arrays.asList(sourceEntry, JavaRuntime.getDefaultJREContainerEntry()); javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null); IFacetedProject fProject = ProjectFacetsManager.create(projectHandle, true, null); fProject.installProjectFacet( ProjectFacetsManager.getProjectFacet(FacetCorePlugin.PLAN_FACET_ID).getDefaultVersion(), null, null); monitor.worked(1); if (planName != null) { String content = readResourceFromClassPath(TEMPLATE_PATH, UTF_8); content = MessageFormat.format(content, planName, scoped, atomic); IPath p = new Path(planName); if (!"plan".equals(p.getFileExtension())) { p = p.addFileExtension("plan"); } planFile = sourceFolder.getFile(p); try { planFile.create(new ByteArrayInputStream(content.getBytes(UTF_8)), true, null); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); // will never happen, all JVMs support UTF-8 } monitor.worked(1); } monitor.done(); }
From source file:org.eclipse.virgo.ide.jdt.internal.ui.actions.EnableServerClasspathContainerActionDelegate.java
License:Open Source License
private void addToClasspath(IJavaProject javaProject, IClasspathEntry entry, IProgressMonitor monitor) throws CoreException { IClasspathEntry[] current = javaProject.getRawClasspath(); IClasspathEntry[] updated = new IClasspathEntry[current.length + 1]; System.arraycopy(current, 0, updated, 0, current.length); updated[current.length] = entry;/*from w ww .j av a2s. c om*/ javaProject.setRawClasspath(updated, monitor); }
From source file:org.eclipse.virgo.ide.pde.core.internal.cmd.SetupProjectOperation.java
License:Open Source License
private IPath configureWABClasspath(IProject project) throws CoreException, JavaModelException { IJavaProject javaProject = (IJavaProject) project.getNature(JavaCore.NATURE_ID); javaProject.setOutputLocation(project.getFullPath().append(BIN), null); IClasspathEntry[] entries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; for (int i = 0; i < entries.length; i++) { IClasspathEntry iClasspathEntry = entries[i]; if (iClasspathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE && iClasspathEntry.getPath().lastSegment().equals(SRC)) { IClasspathEntry newEntry = JavaCore.newSourceEntry(iClasspathEntry.getPath(), iClasspathEntry.getInclusionPatterns(), iClasspathEntry.getExclusionPatterns(), project.getFullPath().append(BIN_WEB_INF_CLASSES)); newEntries[i] = newEntry;//from w w w . j av a2 s .c o m break; } else { newEntries[i] = entries[i]; } } IPath webContentPath = project.getFullPath().append(WEB_CONTENT_FOLDER); newEntries[entries.length] = JavaCore.newLibraryEntry(webContentPath, null, null); javaProject.setRawClasspath(newEntries, null); return webContentPath; }
From source file:org.eclipse.virgo.ide.ui.editors.BundleLibrarySection.java
License:Open Source License
private void updateJavaClasspathLibs(String[] oldPaths, String[] newPaths) { IProject project = ((IModel) getPage().getModel()).getUnderlyingResource().getProject(); IJavaProject jproject = JavaCore.create(project); try {// ww w.j a v a 2 s .c o m IClasspathEntry[] entries = jproject.getRawClasspath(); ArrayList toBeAdded = new ArrayList(); int index = -1; entryLoop: for (int i = 0; i < entries.length; i++) { if (entries[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (index == -1) { index = i; } // do not add the old paths (handling deletion/renaming) IPath path = entries[i].getPath().removeFirstSegments(1).removeTrailingSeparator(); for (int j = 0; j < oldPaths.length; j++) { if (oldPaths[j] != null && path.equals(new Path(oldPaths[j]).removeTrailingSeparator())) { continue entryLoop; } } } else if (entries[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (index == -1) { index = i; } } toBeAdded.add(entries[i]); } if (index == -1) { index = entries.length; } // add paths for (String element : newPaths) { if (element == null) { continue; } IClasspathEntry entry = JavaCore.newLibraryEntry(project.getFullPath().append(element), null, null, true); if (!toBeAdded.contains(entry)) { toBeAdded.add(index++, entry); } } if (toBeAdded.size() == entries.length) { return; } IClasspathEntry[] updated = (IClasspathEntry[]) toBeAdded .toArray(new IClasspathEntry[toBeAdded.size()]); jproject.setRawClasspath(updated, null); } catch (JavaModelException e) { } }