List of usage examples for org.eclipse.jdt.core IJavaProject setRawClasspath
void setRawClasspath(IClasspathEntry[] entries, IProgressMonitor monitor) throws JavaModelException;
From source file:eldaEditor.wizards.DSCDiagramCreationPage_ChooseName.java
License:Open Source License
private void modifyProject(IFile newFile) { IProject project = newFile.getProject(); IProjectDescription description;// ww w. ja v a 2 s . com try { description = project.getDescription(); String[] currentNatures = description.getNatureIds(); String[] newNatures = new String[currentNatures.length + 1]; System.arraycopy(currentNatures, 0, newNatures, 0, currentNatures.length); newNatures[newNatures.length - 1] = JavaCore.NATURE_ID; description.setNatureIds(newNatures); try { project.setDescription(description, new NullProgressMonitor()); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } IJavaProject javaProj = JavaCore.create(project); IFolder binDir = project.getFolder("bin"); IPath binPath = binDir.getFullPath(); javaProj.setOutputLocation(binPath, null); IClasspathEntry cpeFramework = JavaCore.newVariableEntry(CodeGenerator.frameworkPath, null, null); IClasspathEntry cpeJade = JavaCore.newVariableEntry(CodeGeneratorForJADE.jadePath, null, null); IClasspathEntry cpeJava = JavaRuntime.getDefaultJREContainerEntry(); //recupero le classpath entry originali IClasspathEntry[] dscEntries = null; try { dscEntries = javaProj.getRawClasspath(); } catch (JavaModelException e4) { // TODO Auto-generated catch block e4.printStackTrace(); } boolean frameworkEntryExists = false; boolean jadeEntryExists = false; boolean javaEntryExists = false; for (int i = 0; i < dscEntries.length; i++) { //vedo se ELDAFramework gi stato aggiunto al progetto originario if (dscEntries[i].equals(JavaCore.newVariableEntry(CodeGenerator.frameworkPath, null, null))) frameworkEntryExists = true; //vedo se JADE gi stato aggiunto al progetto originario if (dscEntries[i].equals(JavaCore.newVariableEntry(CodeGeneratorForJADE.jadePath, null, null))) jadeEntryExists = true; //vedo se Java gi stato aggiunto al progetto originario if (dscEntries[i].equals(JavaRuntime.getDefaultJREContainerEntry())) javaEntryExists = true; } IClasspathEntry[] newEntries = null; if (frameworkEntryExists && javaEntryExists && jadeEntryExists) { newEntries = new IClasspathEntry[dscEntries.length]; for (int i = 0; i < dscEntries.length; i++) newEntries[i] = dscEntries[i]; } else { ArrayList<IClasspathEntry> list = new ArrayList<IClasspathEntry>(); if (!frameworkEntryExists) { list.add(cpeFramework); } if (!javaEntryExists) { list.add(cpeJava); } if (!jadeEntryExists) { list.add(cpeJade); } newEntries = new IClasspathEntry[dscEntries.length + list.size()]; for (int i = 0; i < dscEntries.length; i++) { newEntries[i] = dscEntries[i]; } for (int i = 0; i < list.size(); i++) { newEntries[dscEntries.length + i] = list.get(i); } } javaProj.setRawClasspath(newEntries, new NullProgressMonitor()); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:es.bsc.servicess.ide.wizards.coretypes.ServiceSpecificTreatment.java
License:Apache License
public void generateServiceCode(IProgressMonitor arg0) throws CoreException { // TODO generateServiceCode // Check if already exists IJavaProject project = secondPage.getJavaProject(); IFolder generated = project.getProject().getFolder("generated"); if (!generated.exists()) { generated.create(true, true, arg0); IClasspathEntry cpe = JavaCore.newSourceEntry(generated.getFullPath()); IClasspathEntry[] e = project.getRawClasspath(); IClasspathEntry[] e2 = new IClasspathEntry[e.length + 1]; for (int i = 0; i < e.length; i++) { e2[i] = e[i];/*from w w w . j a va2 s.com*/ } e2[e.length] = cpe; project.setRawClasspath(e2, arg0); } try { ClassGenerator cg = new ClassGenerator(System.out, generated, project); // schClasses = cg.addReferenceClasses(schClasses, schModels); // cg.generateClassesCode(schClasses, schModels, arg0); cg.generateClassesCode(schModels, arg0); cg.generateDummy((ServiceCoreElement) element, secondPage.getClassName().substring(0, secondPage.getClassName().length() - 3), arg0); generated.refreshLocal(IFolder.DEPTH_INFINITE, arg0); } catch (IOException e) { e.printStackTrace(); } }
From source file:es.bsc.servicess.ide.wizards.ServiceSsNewProjectWizard.java
License:Apache License
/**Create class path entries for the new created project. * @param project Project created/*from ww w . j av a 2 s . c om*/ * @param monitor Eclipse progress monitor * @throws CoreException */ protected void createClasspathEntries(IJavaProject project, IProgressMonitor monitor) throws CoreException { IClasspathEntry[] entries = project.getRawClasspath(); IClasspathEntry[] new_entries = new IClasspathEntry[entries.length + 1]; for (int i = 0; i < entries.length; i++) { new_entries[i] = entries[i]; } new_entries[entries.length] = JavaCore.newContainerEntry(new Path(ProjectMetadata.DEPENDENCY_ENTRYPATH)); project.setRawClasspath(new_entries, monitor); JavaCore.setClasspathContainer(new Path(ProjectMetadata.DEPENDENCY_ENTRYPATH), new IJavaProject[] { project }, // value for 'myProject' new IClasspathContainer[] { new DependenciesClasspathContainer(project) }, monitor); project.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor); }
From source file:eu.artist.migration.modernization.uml2java.repackaged.gen.java.services.WorkspaceServices.java
License:Open Source License
/** * Creates a project from scratch in the workspace. * /* ww w . j a v a 2s. c o m*/ * @param eObject * 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:fede.workspace.eclipse.composition.java.JavaProjectComposer.java
License:Apache License
@Override protected void postCompose(IBuildingContext context, List<IExportedContent> listExportedContent, IExporterTarget target) {/* www . j a va 2 s.co m*/ try { /* * Verify this item is actually hosted in a Java Project */ if (!JavaProjectManager.isJavaProject(MelusineProjectManager.getProject(getItem()))) { return; } /* * Add a classpath container that will resolve dependencies to the * components in the repository associated with this item */ IJavaProject javaProject = JavaProjectManager.getJavaProject(getItem()); List<IClasspathEntry> classpath = new ArrayList<IClasspathEntry>( Arrays.asList(javaProject.getRawClasspath())); IProgressMonitor monitor = ((CompositeBuildingContext) context).getMonitor(); boolean entriesCreated = initializeClasspath(classpath, monitor); if (entriesCreated) { javaProject.setRawClasspath(classpath.toArray(new IClasspathEntry[classpath.size()]), monitor); } /* * Recalculates the component classpath container entry to add the * local copy of the packaged components as exported library entries * of the classpath of the project. * * The net effect is that all classes in the packaged components are * perceived as belonging to this project. */ IClasspathContainer container = new ItemComponentsClasspathEntryClasses(javaProject, getItem(), true); JavaCore.setClasspathContainer(ItemComponentsClasspathEntryClasses.CLASSPATH_ENTRY_PATH, new IJavaProject[] { javaProject }, new IClasspathContainer[] { container }, null); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:fede.workspace.eclipse.java.JavaProjectManager.java
License:Apache License
/** * Replace project classpath./*from w w w. jav a 2 s .c o m*/ * * @param ce * the ce * @param project * the project * @param progressMonitor * the progress monitor * * @return the i classpath entry * * @throws JavaModelException * the java model exception */ static public IClasspathEntry replaceProjectClasspath(IClasspathEntry ce, IJavaProject project, IProgressMonitor progressMonitor) throws JavaModelException { if (project == null) { return null; } IClasspathEntry[] classpath = project.getRawClasspath(); boolean find = false; IPath rootPath = ce.getPath(); int cpLength = classpath.length; int newCPIndex = -1; IClasspathEntry findentry = null; for (int j = 0; j < cpLength; j++) { IClasspathEntry entry = classpath[j]; if (rootPath.equals(entry.getPath())) { if (!find) { find = true; newCPIndex = j; classpath[newCPIndex++] = ce; findentry = entry; } } else if (find) { classpath[newCPIndex++] = entry; } } if (find) { if (newCPIndex == cpLength) { project.setRawClasspath(classpath, progressMonitor); } else { IClasspathEntry[] newClasspath = new IClasspathEntry[newCPIndex]; System.arraycopy(classpath, 0, newClasspath, 0, newCPIndex); project.setRawClasspath(newClasspath, progressMonitor); } } else { IClasspathEntry[] newClasspath = new IClasspathEntry[cpLength + 1]; System.arraycopy(classpath, 0, newClasspath, 0, cpLength); newClasspath[cpLength] = ce; project.setRawClasspath(newClasspath, progressMonitor); } return findentry; }
From source file:fede.workspace.eclipse.java.JavaProjectManager.java
License:Apache License
/** * Removes the project classpath./*from www .java 2s . c o m*/ * * @param rootPath * the root path * @param project * the project * @param progressMonitor * the progress monitor * * @return the i classpath entry * * @throws JavaModelException * the java model exception */ static public IClasspathEntry removeProjectClasspath(IPath rootPath, IJavaProject project, IProgressMonitor progressMonitor) throws JavaModelException { if (project == null) { return null; } IClasspathEntry[] classpath = project.getRawClasspath(); boolean find = false; int cpLength = classpath.length; int newCPIndex = -1; IClasspathEntry findentry = null; for (int j = 0; j < cpLength; j++) { IClasspathEntry entry = classpath[j]; if (rootPath.equals(entry.getPath())) { if (!find) { find = true; newCPIndex = j; findentry = entry; } } else if (find) { classpath[newCPIndex++] = entry; } } if (find) { IClasspathEntry[] newClasspath = new IClasspathEntry[newCPIndex]; System.arraycopy(classpath, 0, newClasspath, 0, newCPIndex); project.setRawClasspath(newClasspath, progressMonitor); } return findentry; }
From source file:fede.workspace.eclipse.java.JavaProjectManager.java
License:Apache License
/** * Delete java source folder.//from w w w .ja va 2 s .c o m * * @param item * the item * @param sourceFolder * the source folder * @param monitor * the monitor * * @throws CoreException * the core exception */ public static void deleteJavaSourceFolder(Item item, IFolder sourceFolder, IProgressMonitor monitor) throws CoreException { IJavaProject javaProject = getJavaProject(item); if (javaProject == null) { return; } if (sourceFolder == null) { return; } List<IClasspathEntry> classpath = new ArrayList<IClasspathEntry>( Arrays.asList(javaProject.getRawClasspath())); classpath.remove(JavaCore.newSourceEntry(sourceFolder.getFullPath())); javaProject.setRawClasspath(classpath.toArray(new IClasspathEntry[classpath.size()]), monitor); }
From source file:fede.workspace.eclipse.java.JavaProjectManager.java
License:Apache License
/** * Adds the project classpath./* w w w.j av a2 s . c o m*/ * * @param project * the project * @param ce * the ce * @param progressMonitor * the progress monitor * @param overwrite * true si force le classpath * * @throws JavaModelException * the java model exception */ static public void addProjectClasspath(IJavaProject project, IClasspathEntry ce, IProgressMonitor progressMonitor, boolean overwrite) throws JavaModelException { if (project == null) { return; } IClasspathEntry[] classpath = project.getRawClasspath(); int cpLength = classpath.length; for (int i = 0; i < classpath.length; i++) { IClasspathEntry entry = classpath[i]; if (entry.getPath().equals(ce.getPath())) { if (overwrite) { classpath[i] = ce; project.setRawClasspath(classpath, progressMonitor); } return; } } IClasspathEntry[] newClasspath = new IClasspathEntry[cpLength + 1]; ; System.arraycopy(classpath, 0, newClasspath, 0, cpLength); newClasspath[cpLength] = ce; project.setRawClasspath(newClasspath, progressMonitor); }
From source file:fr.imag.adele.cadse.test.tutos.tuto2.Tuto2Part3_tc_execution.java
License:Apache License
@Test public void test_build_path() throws Exception { packageExplorerView.show();/*from ww w. j a va2s.c o m*/ packageExplorerView.selectNode("ServletAPI", "sources"); packageExplorerView.selectNode("ServletAPI"); packageExplorerView.capture("image076"); /* Gets the IJavaProject */ GTCadseTree cadseTree = workspaceView.findTree(); Item servlet_item = cadseTree.getItem(new GTTreePath("ServletAPI")); IJavaProject jp = servlet_item.getMainMappingContent(IJavaProject.class); /* Creates a new entry */ IClasspathEntry libEntry = JavaCore.newLibraryEntry( new Path(System.getProperty("test.resourcesPath") + File.separator + "servlet-api.jar"), null, null); /* Add entry to classpath */ IClasspathEntry[] classpath = jp.getRawClasspath(); int cpLength = classpath.length; IClasspathEntry[] newClasspath = new IClasspathEntry[cpLength + 1]; System.arraycopy(classpath, 0, newClasspath, 0, cpLength); newClasspath[cpLength] = libEntry; jp.setRawClasspath(newClasspath, null); GTTreePath api = new GTTreePath("ServletAPI", "Referenced Libraries", "servlet-api.jar" + " - " + System.getProperty("test.resourcesPath")); packageExplorerView.selectNode(api); packageExplorerView.capture("image080"); packageExplorerView.contextMenu(api, "Build Path", "Configure Build Path...").click(); shell = new GTCadseShell("Properties for ServletAPI"); bot.tabItem("Order and Export").activate(); bot.table().getTableItem("servlet-api.jar" + " - " + System.getProperty("test.resourcesPath")).select(); bot.table().getTableItem("servlet-api.jar" + " - " + System.getProperty("test.resourcesPath")).check(); shell.capture("image082"); shell.close(); checkCompilationErrors(workspaceView, new GTTreePath("HelloApp", "test.HelloServlet")); bot.sleep(2000); // Waits until errors disappear. packageExplorerView.show(); packageExplorerView.capture("image084"); }