List of usage examples for org.eclipse.jdt.core IJavaProject getRawClasspath
IClasspathEntry[] getRawClasspath() throws JavaModelException;
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];// ww w .j ava2 s . c o m } 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/*ww w. ja v a 2s .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:es.optsicom.res.client.launcher.local.LocalVersionedJavaShortcut.java
License:Eclipse Public License
private List<File> getFicheros(IClasspathEntry[] cpe, IType type, List<File> lista, String nombreProyecto) { try {/*from w w w . ja va2 s. c om*/ for (int i = 0; i < cpe.length; i++) { IWorkspace ws = type.getResource().getWorkspace(); String localizacionProyecto = nombreWorkspace; String path = cpe[i].getPath().makeAbsolute().toOSString(); String dependencia = localizacionProyecto.concat(path); if (!dependencias.contains(dependencia)) { dependencias.add(dependencia); if (cpe[i].getOutputLocation() != null) RESClientPlugin.log("Binarios: " + cpe[i].getOutputLocation().toOSString()); int tipo = cpe[i].getEntryKind(); //Si la dependencia es de una libreria( if (tipo == 1) { String ruta = localizacionProyecto + cpe[i].getPath().toOSString(); File f = new File(ruta); String dep = f.getAbsolutePath(); //Aadimos las dependencias a las properties librerias.add(dep); } //Si la dependencia es un proyecto if (tipo == 2) { File[] f = new File(dependencia).listFiles(); for (int j = 0; j < f.length; j++) { lista.add(f[j]); String dep = f[j].getAbsolutePath(); dependencias.add(dep); } IProject p = ws.getRoot().getProject(nombreProyecto); IJavaProject jp = JavaCore.create(p); IClasspathEntry[] cp = jp.getRawClasspath(); String nombre = cpe[i].getPath().lastSegment(); lista.addAll(getFicheros(cp, type, lista, nombre)); } if (tipo == 3) { File f = new File(dependencia); lista.add(f); String dep = f.getAbsolutePath(); dependencias.add(dep); } //Si la dependencia es de una variable if (tipo == 4) { IClasspathEntry[] clpe = new IClasspathEntry[1]; clpe[0] = JavaCore.getResolvedClasspathEntry(cpe[i]); if (clpe[0] != null) getFicheros(clpe, type, lista, nombreProyecto); } //Si la dependencia es de un contenedor if (tipo == 5) { IProject project = type.getResource().getProject(); IJavaProject jp = JavaCore.create(project); if (cpe[i].getPath().toOSString().contains("JRE_CONTAINER") || cpe[i].getPath().toOSString().contains("requiredPlugins")) { continue; } IClasspathContainer cc = JavaCore.getClasspathContainer(cpe[i].getPath(), jp); IClasspathEntry[] entradas = cc.getClasspathEntries(); getFicheros(entradas, type, lista, nombreProyecto); } } } return lista; } catch (JavaModelException e) { RESClientPlugin.log(e); return null; } }
From source file:es.optsicom.res.client.launcher.local.LocalVersionedJavaShortcut.java
License:Eclipse Public License
private String creacionFicheros(IType type) { List<File> listaZip = new ArrayList<File>(); //Creacion del fichero comprimido IProject project = type.getResource().getProject(); IJavaProject jp = JavaCore.create(project); nombreProyecto = jp.getElementName(); //Obtencion del directorio de trabajo IWorkspace ws = type.getResource().getWorkspace(); nombreWorkspace = ws.getRoot().getLocation().toOSString(); String nombreZip = ""; try {/*from w ww .j a va2 s. co m*/ String dirBinarios = nombreWorkspace + jp.getOutputLocation().toOSString(); File binarios = new File(dirBinarios); IClasspathEntry[] cpe = jp.getRawClasspath(); listaZip = getFicheros(cpe, type, listaZip, nombreProyecto); vaciarDependencias(); listaZip.add(binarios); File[] filesZip = listaZip.toArray(new File[listaZip.size()]); ZipCreator zc = new ZipCreator(); File zipFileFolder = new File(nombreWorkspace, nombreProyecto); File zipFile = new File(zipFileFolder, nombreProyecto + RESClientPlugin.getTimeStamp() + ".zip"); nombreZip = zipFile.getAbsolutePath(); zc.zip(filesZip, nombreZip); } catch (JavaModelException e) { RESClientPlugin.log(e); MessageDialog.openError(getShell(), "Error while retrieving project classpath files", e.getMessage()); } catch (ZipCreatorException e) { RESClientPlugin.log(e); MessageDialog.openError(getShell(), "Error while creating zip file", e.getMessage()); } return nombreZip; }
From source file:es.optsicom.res.client.util.ProjectDependenciesResolver.java
License:Eclipse Public License
private void calculateDependencies(IClasspathEntry[] cpe, IProject project) throws DependenciesResolverException { try {/*from w ww.jav a 2s.c o m*/ IWorkspace workspace = project.getWorkspace(); IPath workspacePath = workspace.getRoot().getLocation(); String nombreWorkspace = workspacePath.toString(); IJavaProject jp = JavaCore.create(project); if (!dependencies.contains(project.getLocation().toString())) { // Aadimos la carpeta bin classpathFiles.add(workspacePath.append(jp.getOutputLocation()).toFile()); classpath.add(jp.getOutputLocation().toString()); } for (IClasspathEntry cpEntry : cpe) { String path = cpEntry.getPath().toString(); String dependency = nombreWorkspace.concat(path); if (!dependencies.contains(dependency)) { RESClientPlugin.log("Adding dependency: " + dependency); dependencies.add(dependency); if (cpEntry.getOutputLocation() != null) { RESClientPlugin.log("Binarios: " + cpEntry.getOutputLocation().toString()); classpath.add(cpEntry.getOutputLocation().makeRelativeTo(workspacePath).toString()); classpathFiles.add(cpEntry.getOutputLocation().toFile()); } int tipo = cpEntry.getEntryKind(); //Si la dependencia es de una libreria( if (tipo == IClasspathEntry.CPE_LIBRARY) { String dep = cpEntry.getPath().makeRelativeTo(workspacePath).toString(); //mgarcia: Optsicom res Evolution if (new File(workspacePath.toFile(), cpEntry.getPath().toOSString()).exists()) { classpathFiles.add(new File(workspacePath.toFile(), cpEntry.getPath().toOSString())); //Aadimos las dependencias a las properties RESClientPlugin.log("Adding library: " + dep); classpath.add(cpEntry.getPath().toString()); } else { throw new DependenciesResolverException(); } } else if (tipo == IClasspathEntry.CPE_PROJECT) { // File[] files = new File(dependency).listFiles(); // for (File f : files){ // lista.add(f); // String dep = f.getPath(); // RESClientPlugin.log("Adding dependency: " + dep); // dependencies.add(dep); // } IProject p = workspace.getRoot().getProject(cpEntry.getPath().lastSegment()); IJavaProject projectDependency = JavaCore.create(p); IClasspathEntry[] cp = projectDependency.getRawClasspath(); classpathFiles.add(workspacePath.append(projectDependency.getOutputLocation()).toFile()); classpath.add(projectDependency.getOutputLocation().toString()); RESClientPlugin.log("Populating files from: " + p.getName()); calculateDependencies(cp, p); } else if (tipo == IClasspathEntry.CPE_SOURCE) { File f = new File(dependency); classpathFiles.add(f); RESClientPlugin.log("Adding source: " + dependency); } else if (tipo == IClasspathEntry.CPE_VARIABLE) { IClasspathEntry[] clpe = new IClasspathEntry[1]; clpe[0] = JavaCore.getResolvedClasspathEntry(cpEntry); if (clpe[0] != null) { RESClientPlugin.log("Populating files from: " + clpe[0].getPath().toOSString()); calculateDependencies(clpe, project); } } else if (tipo == IClasspathEntry.CPE_CONTAINER) { if (cpEntry.getPath().toOSString().contains("JRE_CONTAINER") || cpEntry.getPath().toOSString().contains("requiredPlugins")) { continue; } IClasspathContainer cc = JavaCore.getClasspathContainer(cpEntry.getPath(), jp); IClasspathEntry[] entradas = cc.getClasspathEntries(); RESClientPlugin.log("Populating files from: " + cc.getPath().toOSString()); calculateDependencies(entradas, project); } } } } catch (JavaModelException e) { RESClientPlugin.log(e); } for (String path : classpath) { RESClientPlugin.log("Classpath: " + path); } for (File file : classpathFiles) { RESClientPlugin.log("Classpath file: " + file.getAbsolutePath()); } }
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. * //from w ww . ja va2s . 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.copy.exporter.JavaClassRefExporter.java
License:Apache License
protected Map<IPath, FolderExportedContent> findLocations(FolderExportedContent folderContent, String exporterType) throws JavaModelException, CoreException { IJavaProject javaProject = JavaProjectManager.getJavaProject(getItem()); Map<IPath, FolderExportedContent> outputLocations = new HashMap<IPath, FolderExportedContent>(); IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); if (exporterType.equals(JAVA_REF_EXPORTER_TYPE)) { for (IClasspathEntry entry : rawClasspath) { if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) continue; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputPath = entry.getOutputLocation(); if (outputPath == null) outputPath = javaProject.getOutputLocation(); outputLocations.put(getRelativePath(outputPath), folderContent); } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath outputPath = entry.getPath(); if (outputPath != null) outputLocations.put(getRelativePath(outputPath), folderContent); }/*w w w . ja v a 2s . com*/ } } else { for (IClasspathEntry entry : rawClasspath) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputPath = entry.getPath(); if (outputPath != null) outputLocations.put(getRelativePath(outputPath), folderContent); } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath outputPath = entry.getSourceAttachmentPath(); if (outputPath != null) outputLocations.put(getRelativePath(outputPath), folderContent); } } } return outputLocations; }
From source file:fede.workspace.eclipse.composition.java.JavaProjectComposer.java
License:Apache License
@Override protected void postCompose(IBuildingContext context, List<IExportedContent> listExportedContent, IExporterTarget target) {//ww w. ja va 2 s . c om 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
/** * Adds the source folder associated with the item to the source entries in * the classpath of the java project./*from w ww . ja v a 2s. c o m*/ * * @param item * the item * @param monitor * the monitor * @param sourceFolder * the source folder * @param specificOutputFolder * the specific output folder * * @throws CoreException * the core exception */ public static void createJavaSourceFolder(Item item, IFolder sourceFolder, IFolder specificOutputFolder, IProgressMonitor monitor) throws CoreException { if (sourceFolder == null) { return; } IProject project = sourceFolder.getProject(); IJavaProject javaProject = JavaCore.create(project); if (javaProject == null) { return; } if (!sourceFolder.exists()) { sourceFolder.create(false, true, monitor); } IFolder defaultOutputFolder = project .getFolder(DEFAULT_OUTPUT_FOLDER_NAME.compute(ContextVariableImpl.DEFAULT, item)); if (!defaultOutputFolder.exists()) { defaultOutputFolder.create(false, true, monitor); } IPath specificOutputPath = null; if (specificOutputFolder != null) { specificOutputPath = specificOutputFolder.getFullPath(); if (!specificOutputFolder.exists()) { specificOutputFolder.create(false, true, monitor); } } List<IClasspathEntry> classpath = new ArrayList<IClasspathEntry>( Arrays.asList(javaProject.getRawClasspath())); IClasspathEntry sourceEntry = JavaCore.newSourceEntry(sourceFolder.getFullPath(), ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, specificOutputPath); if (!classpath.contains(sourceEntry)) { classpath.add(sourceEntry); javaProject.setRawClasspath(classpath.toArray(new IClasspathEntry[classpath.size()]), defaultOutputFolder.getFullPath(), monitor); } }
From source file:fede.workspace.eclipse.java.JavaProjectManager.java
License:Apache License
/** * Use default classes.//from w w w. j ava2s.c o m * * @param project * the project * * @return true, if successful * * @throws JavaModelException * the java model exception */ static boolean useDefaultClasses(IJavaProject project) throws JavaModelException { IClasspathEntry[] classpath = project.getRawClasspath(); int cpLength = classpath.length; for (int j = 0; j < cpLength; j++) { IClasspathEntry entry = classpath[j]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && entry.getOutputLocation() == null) { return true; } } return false; }