List of usage examples for org.eclipse.jdt.core IJavaProject setOutputLocation
void setOutputLocation(IPath path, IProgressMonitor monitor) throws JavaModelException;
From source file:de.plugins.eclipse.depclipse.testcommons.TestingEnvironment.java
License:Open Source License
public IPath setOutputFolder(IPath projectPath, String outputFolder) { IPath outputPath = null;/*from www .ja v a2 s .c o m*/ try { checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ IJavaProject javaProject = JavaCore.create(getProject(projectPath)); outputPath = projectPath.append(outputFolder); javaProject.setOutputLocation(outputPath, null); } catch (JavaModelException e) { e.printStackTrace(); checkAssertion("JavaModelException", false); //$NON-NLS-1$ } return outputPath; }
From source file:egovframework.hdev.imp.ide.common.DeviceAPIIdeUtils.java
License:Apache License
/** * ?? ./*from ww w .j a v a 2 s . com*/ * @param project * @param outputPath * @throws CoreException */ public static void assignOutputLocationToJavaProject(IProject project, IPath outputPath) throws CoreException { IJavaProject javaProject = JavaCore.create(project); javaProject.setOutputLocation(outputPath, null); }
From source file:eldaEditor.wizards.DSCDiagramCreationPage_ChooseName.java
License:Open Source License
private void modifyProject(IFile newFile) { IProject project = newFile.getProject(); IProjectDescription description;/*from ww w. ja v a 2 s .co m*/ 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.ServiceSsNewProjectWizard.java
License:Apache License
@Override protected void finishPage(IProgressMonitor arg0) { IJavaProject project; try {//from w w w . ja v a 2s .c o m page2.performFinish(arg0); project = page2.getJavaProject(); IPackageFragmentRoot[] pfr = project.getPackageFragmentRoots(); if (pfr.length > 0) { // TODO: Try another way to get the main package fragment root, currently prf[0] IPackageFragment frag = pfr[0].createPackageFragment(page0.getPackageName(), true, arg0); IPackageFragment ce_frag = pfr[0].createPackageFragment(page0.getPackageName() + ".coreelements", true, arg0); System.out.println("Created packages: " + frag.getElementName() + ", " + ce_frag.getElementName()); IFolder out_folder = project.getProject().getFolder(ProjectMetadata.OUTPUT_FOLDER); out_folder.create(true, true, arg0); System.out.println("Folder created: " + out_folder.getFullPath().toOSString()); IFolder classes_folder = out_folder.getFolder(ProjectMetadata.CLASSES_FOLDER); classes_folder.create(true, true, arg0); System.out.println("Folder created: " + classes_folder.getFullPath().toOSString()); project.setOutputLocation(classes_folder.getFullPath(), arg0); System.out.println("OutpuLocation: " + project.getOutputLocation().toOSString()); IFolder folder = project.getProject().getFolder(ProjectMetadata.METADATA_FOLDER); folder.create(true, true, arg0); IFile meta = folder.getFile(ProjectMetadata.METADATA_FILENAME); ProjectMetadata pr_meta; pr_meta = new ProjectMetadata(page1.getProjectName()); pr_meta.setRuntimeLocation(page0.getRuntimeLocation()); pr_meta.setSourceDir(pfr[0].getElementName()); pr_meta.setMainPackageName(page0.getPackageName()); pr_meta.addDependency(page0.getRuntimeLocation() + ProjectMetadata.ITJAR_EXT, ProjectMetadata.JAR_DEP_TYPE); System.out.println(pr_meta.getString()); meta.create(new ByteArrayInputStream(pr_meta.getString().getBytes()), true, arg0); createClasspathEntries(project, arg0); IFile projectFile = project.getProject().getFile( frag.getPath().makeRelativeTo(project.getProject().getFullPath()).append("project.xml")); projectFile.create(initialProjectStream(), true, arg0); IFile resourcesFile = project.getProject().getFile( frag.getPath().makeRelativeTo(project.getProject().getFullPath()).append("resources.xml")); resourcesFile.create(initialResourcesStream(), true, arg0); } else { MessageDialog.openError(getShell(), "Error creating metadata file ", "There are not enough fragment roots for the project"); page2.performCancel(); } } catch (InterruptedException e) { MessageDialog.openError(getShell(), "Error creating project ", e.getMessage()); page2.performCancel(); // project.getProject().delete(true, arg0); e.printStackTrace(); } catch (CoreException e) { MessageDialog.openError(getShell(), "Error creating project elements ", e.getMessage()); page2.performCancel(); e.printStackTrace(); } catch (ParserConfigurationException e) { MessageDialog.openError(getShell(), "Error creating metadata file ", e.getMessage()); page2.performCancel(); e.printStackTrace(); } catch (TransformerException e) { MessageDialog.openError(getShell(), "Error creating metadata file ", e.getMessage()); page2.performCancel(); e.printStackTrace(); } }
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. * //w w w .j av a2 s. co 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:hornetq_project_gen.importWizards.hornetq.ImportWizard.java
License:Open Source License
public boolean performFinish() { MavenModelHelper helper = mainPage.getHelper(); if (helper == null) return false; IProgressMonitor progressMonitor = new GenericProgressMonitor(); IWorkspaceRoot rootWs = ResourcesPlugin.getWorkspace().getRoot(); try {// www .j av a2s .co m IProject project = rootWs.getProject(mainPage.getProjectName()); project.create(progressMonitor); project.open(progressMonitor); //add nature IProjectDescription description = project.getDescription(); description.setNatureIds(new String[] { JavaCore.NATURE_ID }); project.setDescription(description, progressMonitor); IJavaProject javaProject = JavaCore.create(project); //setup bin output folder if (javaProject.getOutputLocation() == null) { IFolder binFolder = project.getFolder("bin"); binFolder.create(false, true, null); javaProject.setOutputLocation(binFolder.getFullPath(), null); } //all source files Map<String, IClasspathEntry> sources = new HashMap<String, IClasspathEntry>(); helper.getProjectSources(project, sources); //all external jars helper.getDependencies(sources); //jre lib IClasspathEntry[] jreEntries = PreferenceConstants.getDefaultJRELibrary(); for (int i = 0; i < jreEntries.length; i++) { sources.put(jreEntries[i].getPath().toOSString(), jreEntries[i]); } //copy missing entries helper.findMissingEntries(project, sources); //copy resources helper.copyResources(project, sources); //set project classpath IClasspathEntry[] allEntries = sources.values().toArray(new IClasspathEntry[0]); javaProject.setRawClasspath(allEntries, progressMonitor); //add a builder final String BUILDER_ID = "hornetq_project_gen.hqbuilder"; IProjectDescription desc = project.getDescription(); ICommand[] commands = desc.getBuildSpec(); boolean found = false; for (int i = 0; i < commands.length; ++i) { if (commands[i].getBuilderName().equals(BUILDER_ID)) { found = true; break; } } if (!found) { //add builder to project ICommand command = desc.newCommand(); command.setBuilderName(BUILDER_ID); ICommand[] newCommands = new ICommand[commands.length + 1]; // Add it before other builders. System.arraycopy(commands, 0, newCommands, 1, commands.length); newCommands[0] = command; desc.setBuildSpec(newCommands); project.setDescription(desc, null); } } catch (CoreException e) { e.printStackTrace(); return false; } return true; }
From source file:hornetq_project_gen.importWizards.wildfly.WildFlyImportWizard.java
License:Open Source License
public boolean performFinish() { MavenModelHelper helper = mainPage.getHelper(); if (helper == null) return false; IProgressMonitor progressMonitor = new GenericProgressMonitor(); IWorkspaceRoot rootWs = ResourcesPlugin.getWorkspace().getRoot(); try {//from w w w. j av a 2s . c o m IProject project = rootWs.getProject(mainPage.getProjectName()); project.create(progressMonitor); project.open(progressMonitor); //add nature IProjectDescription description = project.getDescription(); description.setNatureIds(new String[] { JavaCore.NATURE_ID }); project.setDescription(description, progressMonitor); IJavaProject javaProject = JavaCore.create(project); //setup bin output folder if (javaProject.getOutputLocation() == null) { IFolder binFolder = project.getFolder("bin"); binFolder.create(false, true, null); javaProject.setOutputLocation(binFolder.getFullPath(), null); } //all source files Map<String, IClasspathEntry> sources = new HashMap<String, IClasspathEntry>(); helper.getProjectSources(project, sources); //all external jars helper.getDependencies(sources); //jre lib IClasspathEntry[] jreEntries = PreferenceConstants.getDefaultJRELibrary(); for (int i = 0; i < jreEntries.length; i++) { sources.put(jreEntries[i].getPath().toOSString(), jreEntries[i]); } //need jconsole for cli String jHome = System.getProperty("java.home"); File jreHome = new File(jHome); File libDir = new File(jreHome.getParentFile(), "lib"); File jConsoleJar = new File(libDir, "jconsole.jar"); String key = jConsoleJar.getAbsolutePath(); if (!sources.containsKey(key)) { IPath jarPath = Path.fromOSString(key); IClasspathEntry entry = JavaCore.newLibraryEntry(jarPath, null, null, false); sources.put(key, entry); } //copy missing entries helper.findMissingEntries(project, sources); //copy resources helper.copyResources(project, sources); //set project classpath IClasspathEntry[] allEntries = sources.values().toArray(new IClasspathEntry[0]); javaProject.setRawClasspath(allEntries, progressMonitor); //add a builder final String BUILDER_ID = "hornetq_project_gen.hqbuilder"; IProjectDescription desc = project.getDescription(); ICommand[] commands = desc.getBuildSpec(); boolean found = false; for (int i = 0; i < commands.length; ++i) { if (commands[i].getBuilderName().equals(BUILDER_ID)) { found = true; break; } } if (!found) { //add builder to project ICommand command = desc.newCommand(); command.setBuilderName(BUILDER_ID); ICommand[] newCommands = new ICommand[commands.length + 1]; // Add it before other builders. System.arraycopy(commands, 0, newCommands, 1, commands.length); newCommands[0] = command; desc.setBuildSpec(newCommands); project.setDescription(desc, null); } } catch (CoreException e) { e.printStackTrace(); return false; } return true; }
From source file:hydrograph.ui.project.structure.wizard.ProjectStructureCreator.java
License:Apache License
/** * Creates the custom project structure at the specified location and name * The Project will have below natures:<br> * <b>Java</b> and Custom nature as per <b>ETL</b> project * @param projectName Project name// www . j a v a2 s . com * @param location Where should the project be saved * @return */ public IProject createProject(String projectName, URI location) { if (StringUtils.isNotBlank(projectName) && projectName.contains(" ")) { MessageBox messageBox = new MessageBox(new Shell(), SWT.ICON_ERROR | SWT.OK); messageBox.setText("Error"); messageBox.setMessage("The Project Name has spaces"); if (messageBox.open() == SWT.OK) { return null; } } else if (StringUtils.isBlank(projectName)) { throw new InvalidProjectNameException(); } IProject project = null; try { project = createBaseProject(projectName, location); if (project != null) { addNature(project); addToProjectStructure(project, paths); IJavaProject javaProject = JavaCore.create(project); IFolder binFolder = project.getFolder(CustomMessages.ProjectSupport_BIN); javaProject.setOutputLocation(binFolder.getFullPath(), null); List<IClasspathEntry> entries = addJavaLibrariesInClassPath(); IFolder libFolder = project.getFolder(CustomMessages.ProjectSupport_LIB); //add libs to project class path String installLocation = Platform.getInstallLocation().getURL().getPath(); //copyExternalLibAndAddToClassPath(installLocation + CustomMessages.ProjectSupport_LIB, libFolder, entries); copyBuildFile(installLocation + CustomMessages.ProjectSupport_CONFIG_FOLDER + "/" + CustomMessages.ProjectSupport_GRADLE + "/" + BUILD, project); copyBuildFile(installLocation + CustomMessages.ProjectSupport_CONFIG_FOLDER + "/" + CustomMessages.ProjectSupport_GRADLE + "/" + PROPERTIES, project); copyBuildFile(installLocation + CustomMessages.ProjectSupport_CONFIG_FOLDER + "/" + MAVEN, project); updateMavenFile(POM_XML, project); javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null); //set source folder entry in classpath javaProject.setRawClasspath(setSourceFolderInClassPath(project, javaProject), null); } } catch (CoreException e) { logger.debug( "Failed to create Project with parameters as projectName : {} location : {}, exception : {}", new Object[] { projectName, location, e }); project = null; } return project; }
From source file:it.scoppelletti.sdk.ide.ui.NewProjectOperation.java
License:Apache License
/** * Imposta il class-path.//from w w w . ja va 2 s . co m * * @param project Progetto. * @param monitor Gestore dell’avanzamento. */ private void setClasspath(IJavaProject project, IProgressMonitor monitor) throws CoreException, JavaModelException { IPath path; IFolder outputFolder, sourceFolder; IClasspathEntry[] classpath = new IClasspathEntry[3]; ProjectDirectory projectDir; SubMonitor progress; progress = SubMonitor.convert(monitor, "Setting class-path...", 2); try { projectDir = new ProjectDirectory(project.getProject()); outputFolder = projectDir.getBuildClassesFolder(); project.setOutputLocation(outputFolder.getFullPath(), progress.newChild(1)); progress.worked(1); sourceFolder = projectDir.getSourceJavaFolder(); classpath[0] = JavaCore.newSourceEntry(sourceFolder.getFullPath()); path = JavaRuntime.newDefaultJREContainerPath(); classpath[1] = JavaCore.newContainerEntry(path); classpath[2] = JavaCore.newContainerEntry(DependenciesContainer.PATH); project.setRawClasspath(classpath, progress.newChild(1)); progress.worked(1); } finally { if (monitor != null) { monitor.done(); } } }
From source file:it.scoppelletti.sdk.ide.ui.NewWebProjectOperation.java
License:Apache License
/** * Crea il direttorio di output./*ww w. ja v a 2s . c om*/ * * @param project Progetto. * @param monitor Gestore dell’avanzamento. */ private void createOutputFolder(IJavaProject project, IProgressMonitor monitor) throws CoreException { IFolder outputFolder; ProjectDirectory projectDir; SubMonitor progress; progress = SubMonitor.convert(monitor, "Creating the output folder...", 2); try { projectDir = new ProjectDirectory(project.getProject()); outputFolder = projectDir.getBuildWebClassesFolder(); createFolder(outputFolder, progress.newChild(1)); progress.worked(1); // Imposto il direttorio del bytecode in modo che l'impostazione del // facet jst.web lo rilevi correttamente project.setOutputLocation(outputFolder.getFullPath(), progress.newChild(1)); progress.worked(1); } finally { if (monitor != null) { monitor.done(); } } }