List of usage examples for org.eclipse.jdt.core IJavaProject setOutputLocation
void setOutputLocation(IPath path, IProgressMonitor monitor) throws JavaModelException;
From source file:org.jetbrains.kotlin.wizards.ProjectCreationOp.java
License:Apache License
private static IJavaProject buildJavaProject(@NotNull IProject project) throws CoreException, FileNotFoundException { IJavaProject result = JavaCore.create(project); IFolder binFolder = project.getFolder(BIN_FOLDER); if (!binFolder.exists()) { binFolder.create(false, true, null); }//www. j av a2s. c o m result.setOutputLocation(binFolder.getFullPath(), null); IFolder srcFolder = project.getFolder(SRC_FOLDER); if (!srcFolder.exists()) { srcFolder.create(false, true, null); } result.setRawClasspath( new IClasspathEntry[] { JavaCore.newContainerEntry(new Path(JavaRuntime.JRE_CONTAINER)), JavaCore.newSourceEntry(result.getPackageFragmentRoot(srcFolder).getPath()) }, null); ProjectUtils.addKotlinRuntime(project); return result; }
From source file:org.kie.eclipse.utils.FileUtils.java
License:Apache License
public static void createOutputLocation(IJavaProject project, String folderName, IProgressMonitor monitor) throws JavaModelException, CoreException { IFolder folder = createFolder(project, folderName, monitor); IPath path = folder.getFullPath();// w ww . java2 s. co m JavaModelManager.getJavaModelManager().getPerProjectInfo(project.getProject(), true); project.setRawClasspath(new IClasspathEntry[0], monitor); project.setOutputLocation(path, monitor); }
From source file:org.kie.eclipse.wizard.project.AbstractKieProjectWizard.java
License:Apache License
protected void createOutputLocation(IJavaProject project, String folderName, IProgressMonitor monitor) throws JavaModelException, CoreException { IFolder folder = FileUtils.createFolder(project, folderName, monitor); IPath path = folder.getFullPath();/*www. j a v a2s .c o m*/ project.setOutputLocation(path, null); }
From source file:org.lunifera.ide.core.ui.project.BundleProjectFactory.java
License:Open Source License
@SuppressWarnings("restriction") @Override/* www. jav a2 s . c om*/ protected void enhanceProject(IProject project, SubMonitor monitor, Shell shell) throws CoreException { super.enhanceProject(project, monitor, shell); SubMonitor subMonitor = SubMonitor.convert(monitor, 10); try { subMonitor.subTask("Configures the bundle " + projectName); IJavaProject javaProject = JavaCore.create(project); List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>(); for (final IProject referencedProject : project.getReferencingProjects()) { final IClasspathEntry referencedProjectClasspathEntry = JavaCore .newProjectEntry(referencedProject.getFullPath()); classpathEntries.add(referencedProjectClasspathEntry); } for (final String folderName : folders) { final IFolder sourceFolder = project.getFolder(folderName); final IClasspathEntry srcClasspathEntry = JavaCore.newSourceEntry(sourceFolder.getFullPath()); classpathEntries.add(srcClasspathEntry); } IClasspathEntry defaultJREContainerEntry = getDefaultJREContainerEntry(); classpathEntries.add(defaultJREContainerEntry); addMoreClasspathEntriesTo(classpathEntries); javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), subMonitor.newChild(1)); javaProject.setOutputLocation(new Path("/" + project.getName() + "/target/classes"), //$NON-NLS-1$//$NON-NLS-2$ subMonitor.newChild(1)); String executionEnvironmentId = JavaRuntime .getExecutionEnvironmentId(defaultJREContainerEntry.getPath()); if (executionEnvironmentId != null) { BuildPathSupport.setEEComplianceOptions(javaProject, executionEnvironmentId, null); } } catch (JavaModelException e) { LOGGER.error(e.getMessage(), e); } // create bundle createManifest(project, subMonitor.newChild(1)); createBuildProperties(project, subMonitor.newChild(1)); }
From source file:org.megatome.frame2.wizards.Frame2ProjectWizard.java
License:Open Source License
private IJavaProject configureFolders(final IProject newProject, final IProgressMonitor monitor) throws CoreException { final IFolder infFolder = newProject.getFolder(WEBINF); setJavaNatureOnProject(newProject, monitor); setFrame2NatureOnProject(newProject, monitor); final IJavaProject jProject = JavaCore.create(newProject); jProject.setOutputLocation(infFolder.getFolder(CLASSES_DIR).getFullPath(), monitor); final IFolder binDir = newProject.getFolder(Frame2Plugin.getString("Frame2ProjectWizard.bin")); //$NON-NLS-1$ if (binDir.exists()) { binDir.delete(true, monitor);/* w ww.ja v a 2 s . com*/ } final IClasspathEntry[] entries = new IClasspathEntry[2]; entries[0] = JavaRuntime.getDefaultJREContainerEntry(); entries[1] = JavaCore.newSourceEntry(infFolder.getFolder(SRC_DIR).getFullPath()); jProject.setRawClasspath(entries, monitor); return jProject; }
From source file:org.mobicents.eclipslee.servicecreation.wizards.project.ProjectWizard.java
License:Apache License
private void configureClasspath(final IProject project, IProgressMonitor monitor) throws CoreException { // Let's try with mobicents:eclipse first... MavenExecutionResult mavenResult = null; try {/* w ww .ja v a2 s . c om*/ mavenResult = MavenProjectUtils.runMavenTask(project.getFile("pom.xml"), new String[] { "mobicents:eclipse" }, monitor); } catch (Exception e) { // ignore } if (mavenResult == null || mavenResult.hasExceptions()) { // Fallback to manually created since mobicents:eclipse failed IJavaProject javaProject = JavaCore.create(project); IPath path = project.getFullPath().append("/target/classes"); javaProject.setOutputLocation(path, null); int n = 0; boolean hasRA = projectModules.getModules().contains("ra"); IClasspathEntry[] entries = new IClasspathEntry[projectModules.getModuleCount() * 2 + 1 + (projectUseExtensions ? 1 : 0) + (hasRA ? 1 : 0)]; for (String module : projectModules.getModules()) { if (!module.equals("du")) { path = project.getFullPath().append(module + "/src/main/java"); entries[n++] = JavaCore.newSourceEntry(path); } path = project.getFullPath().append(module + "/src/main/resources"); entries[n++] = JavaCore.newSourceEntry(path); } entries[n++] = JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER")); // Path to slee.jar entries[n++] = JavaCore.newVariableEntry(new Path(SLEE_JAR.toOSString()), null /* No available source */, null /* hell knows */); // If we are using SLEE 1.1 Extensions if (projectUseExtensions) { entries[n++] = JavaCore.newVariableEntry(new Path(SLEE_EXT_1_1_JAR.toOSString()), null /* No available source */, null /* hell knows */); } // If we have an RA, we are using Mobicents FT RA API if (hasRA) { entries[n++] = JavaCore.newVariableEntry(new Path(MOBICENTS_FT_RA_JAR.toOSString()), null /* No available source */, null /* hell knows */); } javaProject.setRawClasspath(entries, null); } }
From source file:org.obeonetwork.dsl.uml2.design.internal.services.NewPluginProject.java
License:Open Source License
/** * Create a new plug-in project.// w w w .ja v a2 s . co m * * @param pluginProjectName * plug-in name * @param srcFolders * source folder * @param referencedProjects * referenced projects * @param requiredBundles * required bundles * @param exportedPackages * exported packages * @param progressMonitor * progress monitor * @param theShell * shell * @return a new project. */ public IProject createPluginProject(final String pluginProjectName, final List<String> srcFolders, final List<IProject> referencedProjects, final Set<String> requiredBundles, final List<String> exportedPackages, final IProgressMonitor progressMonitor, final Shell theShell) { IProject project = null; try { progressMonitor.beginTask("", 10); //$NON-NLS-1$ progressMonitor.subTask("Creating project " + pluginProjectName); //$NON-NLS-1$ final IWorkspace workspace = ResourcesPlugin.getWorkspace(); project = workspace.getRoot().getProject(pluginProjectName); // Clean up any old project information. if (project.exists()) { project.delete(true, true, new SubProgressMonitor(progressMonitor, 1)); } final IJavaProject javaProject = JavaCore.create(project); final IProjectDescription projectDescription = ResourcesPlugin.getWorkspace() .newProjectDescription(pluginProjectName); projectDescription.setLocation(null); project.create(projectDescription, new SubProgressMonitor(progressMonitor, 1)); final List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>(); if (referencedProjects.size() != 0) { projectDescription .setReferencedProjects(referencedProjects.toArray(new IProject[referencedProjects.size()])); for (final IProject referencedProject : referencedProjects) { final IClasspathEntry referencedProjectClasspathEntry = JavaCore .newProjectEntry(referencedProject.getFullPath()); classpathEntries.add(referencedProjectClasspathEntry); } } projectDescription .setNatureIds(new String[] { JavaCore.NATURE_ID, IBundleProjectDescription.PLUGIN_NATURE }); final ICommand java = projectDescription.newCommand(); java.setBuilderName(JavaCore.BUILDER_ID); final ICommand manifest = projectDescription.newCommand(); manifest.setBuilderName(PDE_MANIFEST_BUILDER); final ICommand schema = projectDescription.newCommand(); schema.setBuilderName(PDE_SCHEMA_BUILDER); projectDescription.setBuildSpec(new ICommand[] { java, manifest, schema }); project.open(new SubProgressMonitor(progressMonitor, 1)); project.setDescription(projectDescription, new SubProgressMonitor(progressMonitor, 1)); Collections.reverse(srcFolders); for (final String src : srcFolders) { final IFolder srcContainer = project.getFolder(src); if (!srcContainer.exists()) { srcContainer.create(false, true, new SubProgressMonitor(progressMonitor, 1)); } final IClasspathEntry srcClasspathEntry = JavaCore.newSourceEntry(srcContainer.getFullPath()); classpathEntries.add(0, srcClasspathEntry); } classpathEntries.add(JavaCore.newContainerEntry(new Path( "org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"))); //$NON-NLS-1$ classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins"))); //$NON-NLS-1$ javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), new SubProgressMonitor(progressMonitor, 1)); javaProject.setOutputLocation(new Path("/" + pluginProjectName + "/bin"), new SubProgressMonitor( //$NON-NLS-1$ //$NON-NLS-2$ progressMonitor, 1)); createManifest(pluginProjectName, requiredBundles, exportedPackages, progressMonitor, project); createBuildProps(progressMonitor, project, srcFolders); } catch (final Exception exception) { LogServices.INSTANCE.error("createPluginProject(" + pluginProjectName.getClass() + "," //$NON-NLS-1$ //$NON-NLS-2$ + srcFolders.getClass() + "," //$NON-NLS-1$ + referencedProjects.getClass() + "," //$NON-NLS-1$ + requiredBundles.getClass() + "," //$NON-NLS-1$ + exportedPackages.getClass() + "," //$NON-NLS-1$ + progressMonitor.getClass() + "," //$NON-NLS-1$ + theShell.getClass() + ") not handled", exception); //$NON-NLS-1$ exception.printStackTrace(); } finally { progressMonitor.done(); } return project; }
From source file:org.obeonetwork.dsl.uml2.profile.design.exportprofile.NewPluginProject.java
License:Open Source License
/** * Create a new plug-in project.//from w ww. j a v a 2 s . c o m * * @param pluginProjectName * plug-in name * @param srcFolders * source folder * @param referencedProjects * referenced projects * @param requiredBundles * required bundles * @param exportedPackages * exported packages * @param progressMonitor * progress monitor * @param theShell * shell * @return a new project. */ public IProject createPluginProject(final String pluginProjectName, final List<String> srcFolders, final List<IProject> referencedProjects, final Set<String> requiredBundles, final List<String> exportedPackages, final IProgressMonitor progressMonitor, final Shell theShell) { IProject project = null; try { progressMonitor.beginTask("", 10); progressMonitor.subTask("Creating project " + pluginProjectName); final IWorkspace workspace = ResourcesPlugin.getWorkspace(); project = workspace.getRoot().getProject(pluginProjectName); // Clean up any old project information. if (project.exists()) { project.delete(true, true, new SubProgressMonitor(progressMonitor, 1)); } final IJavaProject javaProject = JavaCore.create(project); final IProjectDescription projectDescription = ResourcesPlugin.getWorkspace() .newProjectDescription(pluginProjectName); projectDescription.setLocation(null); project.create(projectDescription, new SubProgressMonitor(progressMonitor, 1)); final List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>(); if (referencedProjects.size() != 0) { projectDescription .setReferencedProjects(referencedProjects.toArray(new IProject[referencedProjects.size()])); for (final IProject referencedProject : referencedProjects) { final IClasspathEntry referencedProjectClasspathEntry = JavaCore .newProjectEntry(referencedProject.getFullPath()); classpathEntries.add(referencedProjectClasspathEntry); } } projectDescription .setNatureIds(new String[] { JavaCore.NATURE_ID, IBundleProjectDescription.PLUGIN_NATURE }); final ICommand java = projectDescription.newCommand(); java.setBuilderName(JavaCore.BUILDER_ID); final ICommand manifest = projectDescription.newCommand(); manifest.setBuilderName(PDE_MANIFEST_BUILDER); final ICommand schema = projectDescription.newCommand(); schema.setBuilderName(PDE_SCHEMA_BUILDER); projectDescription.setBuildSpec(new ICommand[] { java, manifest, schema }); project.open(new SubProgressMonitor(progressMonitor, 1)); project.setDescription(projectDescription, new SubProgressMonitor(progressMonitor, 1)); Collections.reverse(srcFolders); for (final String src : srcFolders) { final IFolder srcContainer = project.getFolder(src); if (!srcContainer.exists()) { srcContainer.create(false, true, new SubProgressMonitor(progressMonitor, 1)); } final IClasspathEntry srcClasspathEntry = JavaCore.newSourceEntry(srcContainer.getFullPath()); classpathEntries.add(0, srcClasspathEntry); } classpathEntries.add(JavaCore.newContainerEntry(new Path( "org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"))); classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins"))); javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), new SubProgressMonitor(progressMonitor, 1)); javaProject.setOutputLocation(new Path("/" + pluginProjectName + "/bin"), new SubProgressMonitor(progressMonitor, 1)); createManifest(pluginProjectName, requiredBundles, exportedPackages, progressMonitor, project); createBuildProps(progressMonitor, project, srcFolders); } catch (final Exception exception) { new LogServices().error("createPluginProject(" + pluginProjectName.getClass() + "," + srcFolders.getClass() + "," + referencedProjects.getClass() + "," + requiredBundles.getClass() + "," + exportedPackages.getClass() + "," + progressMonitor.getClass() + "," + theShell.getClass() + ") not handled", exception); exception.printStackTrace(); } finally { progressMonitor.done(); } return project; }
From source file:org.objectstyle.wolips.target.TargetBuilder.java
License:Open Source License
protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException { State buildState;/* ww w .j a v a 2 s . c o m*/ String buldStateKey; IProject[] result = null; IProject project = getProject(); List targets = targets(); if (targets == null) return null; IJavaProject javaProject = JavaCore.create(project); IPath projectOutputLocation = javaProject.getOutputLocation(); IClasspathEntry[] projectClasspath = javaProject.getRawClasspath(); _problemMarkers = new HashMap(); TargetBuilderPlugin plugin = TargetBuilderPlugin.getDefault(); try { for (int i = 0; i < targets.size(); i++) { BuildTarget target = (BuildTarget) targets.get(i); buldStateKey = project.getName() + "/" + target.name(); javaProject.setOutputLocation(target.outputLocation(), monitor); javaProject.setRawClasspath(target.classPathEntries(), monitor); buildState = plugin.buildStateForKey(buldStateKey); JavaModelManager.getJavaModelManager().setLastBuiltState(project, buildState); result = super.build(kind, args, monitor); buildState = (State) JavaModelManager.getJavaModelManager().getLastBuiltState(project, monitor); plugin.setBuildStateForKey(buildState, buldStateKey); registerProblemMarkers(JavaBuilder.getProblemsFor(getProject())); // cancelBuildOnErrors(javaProject); } } finally { javaProject.setOutputLocation(projectOutputLocation, monitor); javaProject.setRawClasspath(projectClasspath, monitor); updateProblemMarkers(); cancelBuildOnErrors(); } return result; }
From source file:org.occiware.clouddesigner.occi.gen.connector.ui.wizards.NewConnectorWizard.java
License:Open Source License
private void createConnectorJavaProject(String connectorProjectName, String extensionScheme, IProgressMonitor monitor) throws CoreException { // Get the file containing the OCCI extension. String extensionFile = OCCIRegistry.getInstance().getFileURI(extensionScheme); // This connector project will require the bundle containing the OCCI extension. // Warning extensionFile must be a platform URI (plugin or resource). String tmp = extensionFile.substring("platform:/".length()); tmp = tmp.substring(tmp.indexOf('/') + 1); String requireBundle = tmp.substring(0, tmp.indexOf('/')); // FIXME we suppose that the project name is equals to the bundle name. IProject requireProject = ResourcesPlugin.getWorkspace().getRoot().getProject(requireBundle); // See https://sdqweb.ipd.kit.edu/wiki/JDT_Tutorial:_Creating_Eclipse_Java_Projects_Programmatically // Create an Eclipse project. IProject connectorProject = ResourcesPlugin.getWorkspace().getRoot().getProject(connectorProjectName); connectorProject.create(null);//from w ww . j a v a2 s .c om connectorProject.open(null); // Because we need a java project, we have to set the Java nature to the created project: IProjectDescription description = connectorProject.getDescription(); description.setNatureIds(new String[] { JavaCore.NATURE_ID }); connectorProject.setDescription(description, null); // Now we can create our Java project IJavaProject javaProject = JavaCore.create(connectorProject); // However, it's not enough if we want to add Java source code to the project. We have to set the Java build path: // (1) We first specify the output location of the compiler (the bin folder): IFolder binFolder = connectorProject.getFolder("bin"); binFolder.create(false, true, null); javaProject.setOutputLocation(binFolder.getFullPath(), null); // (2) Define the class path entries. IClasspathEntry[] entries = new IClasspathEntry[(requireProject.exists()) ? 3 : 2]; // Add JRE System Library. entries[0] = JavaRuntime.getDefaultJREContainerEntry(); // (3) We have not yet the source folder created: IFolder sourceFolder = connectorProject.getFolder("src"); sourceFolder.create(false, true, null); // (4) Now the created source folder should be added to the class entries of the project, otherwise compilation will fail: IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(sourceFolder); entries[1] = JavaCore.newSourceEntry(root.getPath()); // Add the extension project. if (requireProject.exists()) { entries[2] = JavaCore.newSourceEntry(requireProject.getFullPath()); } // (5) Set the Java build path. javaProject.setRawClasspath(entries, null); // Convert this project to a plugin project. try { new ConvertProjectToPluginOperation(new IProject[] { connectorProject }, false).run(monitor); } catch (InvocationTargetException | InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // Generate META-INF/MANIFEST.MF IFile manifest = PDEProject.getManifest(connectorProject); String manifestContent = "Manifest-Version: 1.0\n" + "Bundle-ManifestVersion: 2\n" + "Bundle-Name: " + connectorProjectName + "\n" + "Bundle-SymbolicName: " + connectorProjectName + ";singleton:=true\n" + "Bundle-Version: 0.1.0.qualifier\n" + "Bundle-ClassPath: .\n" + "Bundle-Vendor: OCCIware\n" + // "Bundle-Localization: plugin\n" + // FIXME generate plugin.properties "Bundle-RequiredExecutionEnvironment: JavaSE-1.7\n" + "Bundle-ActivationPolicy: lazy\n" + "Require-Bundle: org.slf4j.api,\n" + " org.occiware.clouddesigner.occi,\n" + " " + requireBundle + "\n" + "Export-Package: " + connectorProjectName + "\n"; manifest.setContents(new ByteArrayInputStream(manifestContent.getBytes()), true, false, monitor); // Generate build.properties IFile build = PDEProject.getBuildProperties(connectorProject); String buildContent = "# Copyright (c) 2016 Inria\n" + "#\n" + "# All rights reserved. This program and the accompanying materials\n" + "# are made available under the terms of the Eclipse Public License v1.0\n" + "# which accompanies this distribution, and is available at\n" + "# http://www.eclipse.org/legal/epl-v10.html\n" + "#\n" + "# Contributors:\n" + "# - Philippe Merle <philippe.merle@inria.fr>\n" + "#\n" + "\n" + "source.. = src/\n" + "output.. = bin/\n" + "bin.includes = META-INF/, plugin.xml, .\n"; build.setContents(new ByteArrayInputStream(buildContent.getBytes()), true, false, monitor); // Generate plugin.xml IFile pluginXML = PDEProject.getPluginXml(connectorProject); String pluginContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<?eclipse version=\"3.0\"?>\n" + "<!--\n" + " Copyright (c) 2016 Inria\n" + "\n" + " All rights reserved. This program and the accompanying materials\n" + " are made available under the terms of the Eclipse Public License v1.0\n" + " which accompanies this distribution, and is available at\n" + " http://www.eclipse.org/legal/epl-v10.html\n" + "\n" + " Contributors:\n" + " - Philippe Merle <philippe.merle@inria.fr>\n" + "-->\n" + "<plugin>\n" + "\n" + " <!-- Register the factory of this connector. -->\n" + " <extension point=\"org.eclipse.emf.ecore.factory_override\">\n" + " <factory\n" + " uri=\"" + Occi2Ecore.convertOcciScheme2EcoreNamespace(extensionScheme) + "\"\n" + " class=\"" + connectorProjectName + ".ConnectorFactory\"/>\n" + " </extension>\n" + "\n" + "</plugin>\n"; pluginXML.create(new ByteArrayInputStream(pluginContent.getBytes()), true, monitor); // Generate Java code for the connector. try { URI modelURI = URI.createURI(extensionFile, true); // Generate Java code for the connector. IContainer target = connectorProject.getFolder("src"); // Compute the arguments of the generator. ArrayList<String> arguments = new ArrayList<String>(); // The full name of the package to generate. arguments.add(connectorProjectName); // The full name of the package to extend. arguments.add(requireBundle); // Call the generator. GenerateAll generator = new GenerateAll(modelURI, target, arguments); generator.doGenerate(monitor); } catch (IOException e) { IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); Activator.getDefault().getLog().log(status); } finally { connectorProject.refreshLocal(IResource.DEPTH_INFINITE, monitor); } }