List of usage examples for org.eclipse.jdt.core IJavaProject setOutputLocation
void setOutputLocation(IPath path, IProgressMonitor monitor) throws JavaModelException;
From source file:org.eclipse.emf.cdo.dawn.codegen.util.ProjectCreationHelper.java
License:Open Source License
/** * @param project/*from ww w .j a v a2 s .c o m*/ * @param javaProject * @throws CoreException * @throws JavaModelException */ private void createOutputFolder(String path, IProject project, IJavaProject javaProject) throws CoreException, JavaModelException { try { IFolder binFolder = project.getFolder(new Path(path)); if (!binFolder.exists()) { binFolder.create(true, true, null); javaProject.setOutputLocation(binFolder.getFullPath(), null); } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.eclipse.emf.cheatsheets.actions.NewJavaProjectAction.java
License:Open Source License
/** * Create a new Java project// ww w . j av a 2 s. com * @param projectName Name of the project * @param monitor Monitoring the action * @return Java project */ @Override protected IProject createProject(String projectName, IProgressMonitor monitor) throws CoreException { monitor.beginTask( CheatSheetsPlugin.INSTANCE.getString("_UI_CreateJavaProject_message", new String[] { projectName }), 5); IProject project = super.createProject(projectName, BasicMonitor.subProgress(monitor, 1)); if (project != null) { IProjectDescription description = project.getDescription(); if (!description.hasNature(JavaCore.NATURE_ID)) { IJavaProject javaProject = JavaCore.create(project); if (javaProject != null) { String[] natures = description.getNatureIds(); String[] javaNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, javaNatures, 0, natures.length); javaNatures[natures.length] = JavaCore.NATURE_ID; description.setNatureIds(javaNatures); project.setDescription(description, BasicMonitor.subProgress(monitor, 1)); IFolder sourceFolder = project.getFolder(SOURCE_FOLDER); if (!sourceFolder.exists()) { sourceFolder.create(true, true, BasicMonitor.subProgress(monitor, 1)); } javaProject.setOutputLocation(project.getFolder(OUTPUT_FOLDER).getFullPath(), BasicMonitor.subProgress(monitor, 1)); IClasspathEntry[] entries = new IClasspathEntry[] { JavaCore.newSourceEntry(sourceFolder.getFullPath()), JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER")) }; javaProject.setRawClasspath(entries, BasicMonitor.subProgress(monitor, 1)); } } } monitor.done(); return project; }
From source file:org.eclipse.etrice.core.ui.newwizard.ProjectCreator.java
License:Open Source License
public static IProject createETriceProject(IPath javaSource, IPath javaSourceGen, URI projectLocationURI, IProject runtimeProject, List<String> naturesToAdd, List<String> buildersToAdd, Monitor monitor) { IProgressMonitor progressMonitor = BasicMonitor.toIProgressMonitor(monitor); String projectName = javaSource.segment(0); IProject project = null;/*from w ww . j av a 2s . c o m*/ try { List<IClasspathEntry> classpathEntries = new UniqueEList<IClasspathEntry>(); progressMonitor.beginTask("", 10); progressMonitor.subTask("Creating eTrice project " + projectName + " (" + (projectLocationURI != null ? projectLocationURI.toString() : projectName) + ")"); IWorkspace workspace = ResourcesPlugin.getWorkspace(); project = workspace.getRoot().getProject(projectName); // Clean up any old project information. // if (!project.exists()) { URI location = projectLocationURI; if (location == null) { location = URI .createFileURI(workspace.getRoot().getLocation().append(projectName).toOSString()); } location = location.appendSegment(".project"); File projectFile = new File(location.toString()); if (projectFile.exists()) { projectFile.renameTo(new File(location.toString() + ".old")); } } IJavaProject javaProject = JavaCore.create(project); IProjectDescription projectDescription = null; if (!project.exists()) { projectDescription = ResourcesPlugin.getWorkspace().newProjectDescription(projectName); if (projectLocationURI != null) { projectDescription.setLocationURI(new java.net.URI(projectLocationURI.toString())); } project.create(projectDescription, new SubProgressMonitor(progressMonitor, 1)); project.open(new SubProgressMonitor(progressMonitor, 1)); } else { projectDescription = project.getDescription(); project.open(new SubProgressMonitor(progressMonitor, 1)); if (project.hasNature(JavaCore.NATURE_ID)) { classpathEntries.addAll(Arrays.asList(javaProject.getRawClasspath())); } } boolean isInitiallyEmpty = classpathEntries.isEmpty(); { ArrayList<IProject> referencedProjects = new ArrayList<IProject>(); if (runtimeProject != null) referencedProjects.add(runtimeProject); if (!referencedProjects.isEmpty()) { projectDescription.setReferencedProjects( referencedProjects.toArray(new IProject[referencedProjects.size()])); for (IProject referencedProject : referencedProjects) { IClasspathEntry referencedProjectClasspathEntry = JavaCore .newProjectEntry(referencedProject.getFullPath()); classpathEntries.add(referencedProjectClasspathEntry); } } } { String[] natureIds = projectDescription.getNatureIds(); if (natureIds == null) { natureIds = new String[0]; } for (String nature : naturesToAdd) { natureIds = addNature(nature, natureIds, project); } projectDescription.setNatureIds(natureIds); ICommand[] builders = projectDescription.getBuildSpec(); if (builders == null) { builders = new ICommand[0]; } for (String builder : buildersToAdd) { builders = addBuilder(builder, builders, projectDescription); } projectDescription.setBuildSpec(builders); project.setDescription(projectDescription, new SubProgressMonitor(progressMonitor, 1)); createSrcFolder(progressMonitor, project, classpathEntries, javaSource); createSrcFolder(progressMonitor, project, classpathEntries, javaSourceGen); if (isInitiallyEmpty) { IClasspathEntry jreClasspathEntry = JavaCore.newVariableEntry( new Path(JavaRuntime.JRELIB_VARIABLE), new Path(JavaRuntime.JRESRC_VARIABLE), new Path(JavaRuntime.JRESRCROOT_VARIABLE)); for (Iterator<IClasspathEntry> i = classpathEntries.iterator(); i.hasNext();) { IClasspathEntry classpathEntry = i.next(); if (classpathEntry.getPath().isPrefixOf(jreClasspathEntry.getPath())) { i.remove(); } } String jreContainer = JavaRuntime.JRE_CONTAINER; jreContainer += "/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"; classpathEntries.add(JavaCore.newContainerEntry(new Path(jreContainer))); } javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), new SubProgressMonitor(progressMonitor, 1)); } if (isInitiallyEmpty) { javaProject.setOutputLocation(new Path("/" + javaSource.segment(0) + "/bin"), new SubProgressMonitor(progressMonitor, 1)); } javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), new SubProgressMonitor(progressMonitor, 1)); if (isInitiallyEmpty) { javaProject.setOutputLocation(new Path("/" + javaSource.segment(0) + "/bin"), new SubProgressMonitor(progressMonitor, 1)); } } catch (Exception e) { Logger.getLogger(ProjectCreator.class).error(e.getMessage(), e); } finally { progressMonitor.done(); } return project; }
From source file:org.eclipse.gmt.mod.infra.common.core.internal.utils.ProjectUtils.java
License:Open Source License
/** * @author Gregoire DUPE (Mia-Software) - classpath entries modification *//*from w ww . j a v a 2 s . co m*/ public static void configureAsJavaProject(final IProject project, final IProgressMonitor monitor) throws CoreException { addNature(project, monitor, JavaCore.NATURE_ID); IJavaProject javaProject = JavaCore.create(project); // Set output folder IPath path = project.getFullPath().append("bin"); //$NON-NLS-1$ javaProject.setOutputLocation(path, null); List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>(); // Set source folder IFolder sourceFolder = project.getFolder("src"); //$NON-NLS-1$ if (!sourceFolder.exists()) { sourceFolder.create(false, true, monitor); classpathEntries.add(JavaCore.newSourceEntry(javaProject.getPath().append(new Path("src")))); //$NON-NLS-1$ } Path jrePath = new Path( JavaRuntime.JRE_CONTAINER + "/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/" //$NON-NLS-1$ + JAVA_VERSION); boolean hasJrePath = false; IClasspathEntry[] existingClassPath = javaProject.getRawClasspath(); for (IClasspathEntry classpathEntry : existingClassPath) { if (jrePath.equals(classpathEntry.getPath())) { hasJrePath = true; } } if (!hasJrePath) { // add the jre api to the classpath classpathEntries.add(JavaCore.newContainerEntry(jrePath)); javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[0]), monitor); } }
From source file:org.eclipse.jst.j2ee.internal.project.WTPJETEmitter.java
License:Open Source License
/** * @param progressMonitor/* ww w . java2 s . c om*/ * @param project * @param javaProject * @throws CoreException * @throws JavaModelException * @throws BackingStoreException */ protected void initializeJavaProject(IProgressMonitor progressMonitor, final IProject project, IJavaProject javaProject) throws CoreException, JavaModelException, BackingStoreException { progressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_JETInitializingProject_message", //$NON-NLS-1$ new Object[] { project.getName() })); IClasspathEntry classpathEntry = JavaCore.newSourceEntry(new Path("/" + project.getName() + "/src")); //$NON-NLS-1$ //$NON-NLS-2$ //IClasspathEntry jreClasspathEntry = JavaCore.newVariableEntry(new Path(JavaRuntime.JRELIB_VARIABLE), new Path(JavaRuntime.JRESRC_VARIABLE), new Path(JavaRuntime.JRESRCROOT_VARIABLE)); IClasspathEntry jreClasspathEntry = JavaRuntime.getDefaultJREContainerEntry(); List classpath = new ArrayList(); classpath.add(classpathEntry); classpath.add(jreClasspathEntry); classpath.addAll(classpathEntries); IFolder sourceFolder = project.getFolder(new Path("src")); //$NON-NLS-1$ if (!sourceFolder.exists()) { sourceFolder.create(false, true, new SubProgressMonitor(progressMonitor, 1)); } IFolder runtimeFolder = project.getFolder(new Path("runtime")); //$NON-NLS-1$ if (!runtimeFolder.exists()) { runtimeFolder.create(false, true, new SubProgressMonitor(progressMonitor, 1)); } IClasspathEntry[] classpathEntryArray = (IClasspathEntry[]) classpath .toArray(new IClasspathEntry[classpath.size()]); javaProject.setRawClasspath(classpathEntryArray, new SubProgressMonitor(progressMonitor, 1)); javaProject.setOutputLocation(new Path("/" + project.getName() + "/runtime"), //$NON-NLS-1$//$NON-NLS-2$ new SubProgressMonitor(progressMonitor, 1)); // appended from previous implementation createClasspathEntries(project); IScopeContext context = new ProjectScope(project); IEclipsePreferences prefs = context.getNode(JavaCore.PLUGIN_ID); prefs.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.IGNORE); prefs.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.IGNORE); // set Java compiler compliance level to 1.5 prefs.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); prefs.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); prefs.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); prefs.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR); prefs.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR); // set Javadoc validation to the default ignore level prefs.put(JavaCore.COMPILER_PB_INVALID_JAVADOC, JavaCore.IGNORE); prefs.put(JavaCore.COMPILER_PB_INVALID_JAVADOC_TAGS, JavaCore.DISABLED); prefs.put(JavaCore.COMPILER_PB_INVALID_JAVADOC_TAGS__DEPRECATED_REF, JavaCore.DISABLED); prefs.put(JavaCore.COMPILER_PB_INVALID_JAVADOC_TAGS__NOT_VISIBLE_REF, JavaCore.DISABLED); prefs.put(JavaCore.COMPILER_PB_INVALID_JAVADOC_TAGS_VISIBILITY, JavaCore.PUBLIC); prefs.put(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAG_DESCRIPTION, JavaCore.COMPILER_PB_MISSING_JAVADOC_TAG_DESCRIPTION_RETURN_TAG); prefs.put(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS, JavaCore.IGNORE); prefs.put(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS_VISIBILITY, JavaCore.PUBLIC); prefs.put(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS_OVERRIDING, JavaCore.DISABLED); prefs.put(JavaCore.COMPILER_PB_MISSING_JAVADOC_COMMENTS, JavaCore.IGNORE); prefs.put(JavaCore.COMPILER_PB_MISSING_JAVADOC_COMMENTS_VISIBILITY, JavaCore.PUBLIC); prefs.put(JavaCore.COMPILER_PB_MISSING_JAVADOC_COMMENTS_OVERRIDING, JavaCore.DISABLED); // store changed properties permanently prefs.flush(); }
From source file:org.eclipse.jst.ws.internal.consumption.command.common.CreateJavaProjectCommand.java
License:Open Source License
public IStatus execute(IProgressMonitor monitor, IAdaptable adaptable) { IEnvironment env = getEnvironment(); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName_); if (project != null && !project.exists()) { try {/*from www. j av a2 s . co m*/ project.create(ResourcesPlugin.getWorkspace().newProjectDescription(project.getName()), monitor); project.open(monitor); IProjectDescription desc = project.getDescription(); desc.setNatureIds(new String[] { JavaCore.NATURE_ID }); ICommand cmd = desc.newCommand(); cmd.setBuilderName(JavaCore.BUILDER_ID); desc.setBuildSpec(new ICommand[] { cmd }); project.setDescription(desc, monitor); IJavaProject javaProject = JavaCore.create(project); Path projectRoot = new Path(Path.ROOT.append(new Path(project.getName())).toString()); javaProject.setRawClasspath(new IClasspathEntry[] { JavaCore.newSourceEntry(projectRoot), JavaCore.newContainerEntry(new Path(JavaRuntime.JRE_CONTAINER)) }, monitor); javaProject.setOutputLocation(projectRoot, monitor); } catch (CoreException ce) { IStatus status = StatusUtils .errorStatus(NLS.bind(ConsumptionMessages.MSG_ERROR_CANNOT_CREATE_JAVA_PROJECT, new String[] { projectName_ }), ce); env.getStatusHandler().reportError(status); return status; } } return Status.OK_STATUS; }
From source file:org.eclipse.m2e.maveneclipse.handler.additionalprojectfacets.JstWebFacetConfigProvider.java
License:Open Source License
/** * Sets the java output directory. This is required here to ensure that the correct * <tt>java-output-path</tt> is set by the {@link WebFacetInstallDelegate}. * @param context the context/*from w w w . ja v a2 s . c o m*/ * @throws JavaModelException */ private void setJavaOutputLocation(MavenEclipseContext context) throws JavaModelException { IProject project = context.getProject(); IJavaProject javaProject = JavaCore.create(project); if (javaProject != null) { String outputDirectory = context.getMavenProject().getBuild().getOutputDirectory(); IPath outputPath = MavenProjectUtils.getProjectRelativePath(project, outputDirectory); IFolder outputFolder = project.getFolder(outputPath); javaProject.setOutputLocation(outputFolder.getFullPath(), context.getMonitor()); } }
From source file:org.eclipse.m2m.internal.qvt.oml.ui.wizards.project.NewProjectCreationOperation.java
License:Open Source License
private void setupJava(IProject project, boolean pde, IProgressMonitor monitor) throws CoreException, JavaModelException { addNatureToProject(project, JavaCore.NATURE_ID, monitor); IContainer srcContainer = createJavaFolder(fData.getSourceFolderName(), monitor); IContainer binContainer = createJavaFolder(fData.getOutFolderName(), monitor); IJavaProject javaProject = JavaCore.create(project); javaProject.setOutputLocation(binContainer.getFullPath(), monitor); monitor.subTask(Messages.NewProjectCreationOperation_SetClassPathTask); IClasspathEntry[] entries = new IClasspathEntry[pde ? 3 : 1]; if (pde) {//w ww. j a v a 2 s .c o m String executionEnvironment = BUNDLE_EXEC_ENV; setComplianceOptions(javaProject, executionEnvironment, true); entries[0] = createJREEntry(executionEnvironment); entries[1] = createContainerEntry(); } entries[entries.length - 1] = JavaCore.newSourceEntry(srcContainer.getFullPath()); javaProject.setRawClasspath(entries, monitor); if (fData.isDoGenerateClass()) { generateTopLevelPluginClass(new SubProgressMonitor(monitor, 1)); } monitor.worked(1); }
From source file:org.eclipse.mylyn.context.sdk.java.WorkspaceSetupHelper.java
License:Open Source License
public static IJavaProject createPluginProject(IProject project) throws CoreException, JavaModelException { if (project == null) { return null; }/*from ww w. j a v a2 s.c om*/ IJavaProject javaProject = JavaCore.create(project); // create bin folder IFolder binFolder = project.getFolder("bin"); if (!binFolder.exists()) { binFolder.create(false, true, null); } // set java nature IProjectDescription description = project.getDescription(); description.setNatureIds(new String[] { PDE.PLUGIN_NATURE, JavaCore.NATURE_ID }); project.setDescription(description, null); // create output folder IPath outputLocation = binFolder.getFullPath(); javaProject.setOutputLocation(outputLocation, null); PluginProject pluginProject = new PluginProject(); pluginProject.setProject(project); pluginProject.configure(); return javaProject; }
From source file:org.eclipse.mylyn.context.tests.support.ContextTestUtil.java
License:Open Source License
private static IJavaProject createPluginProject(IProject project) throws CoreException, JavaModelException { if (project == null) { return null; }//from w w w .j a v a2s .co m IJavaProject javaProject = JavaCore.create(project); // create bin folder IFolder binFolder = project.getFolder("bin"); if (!binFolder.exists()) { binFolder.create(false, true, null); } // set java nature IProjectDescription description = project.getDescription(); description.setNatureIds(new String[] { PDE.PLUGIN_NATURE, JavaCore.NATURE_ID }); project.setDescription(description, null); // create output folder IPath outputLocation = binFolder.getFullPath(); javaProject.setOutputLocation(outputLocation, null); PluginProject pluginProject = new PluginProject(); pluginProject.setProject(project); pluginProject.configure(); return javaProject; }