List of usage examples for org.eclipse.jdt.core IJavaProject setOutputLocation
void setOutputLocation(IPath path, IProgressMonitor monitor) throws JavaModelException;
From source file:it.wallgren.android.platform.project.AndroidPlatformProject.java
License:Apache License
private void addJavaNature(IProject project, IProgressMonitor monitor) throws CoreException { if (project == null) { throw new IllegalStateException("Project must be created before giving it a Java nature"); }// ww w . j a va2 s .c om final IFolder repoLink = createRepoLink(monitor, project, repoPath); IFile classpath = repoLink.getFile("development/ide/eclipse/.classpath"); IFile classpathDestination = project.getFile(".classpath"); if (classpathDestination.exists()) { classpathDestination.delete(true, monitor); } classpath.copy(classpathDestination.getFullPath(), true, monitor); final IProjectDescription description = project.getDescription(); final String[] natures = description.getNatureIds(); final String[] newNatures = Arrays.copyOf(natures, natures.length + 1); newNatures[natures.length] = JavaCore.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); final IJavaProject javaProject = JavaCore.create(project); @SuppressWarnings("rawtypes") final Map options = javaProject.getOptions(true); // Compliance level need to be 1.6 JavaCore.setComplianceOptions(JavaCore.VERSION_1_6, options); javaProject.setOptions(options); IClasspathEntry[] classPath = mangleClasspath(javaProject.getRawClasspath(), project, repoLink); javaProject.setRawClasspath(classPath, monitor); javaProject.setOutputLocation(javaProject.getPath().append("out"), monitor); }
From source file:it.wallgren.android.platform.project.PackagesProject.java
License:Apache License
private void addJavaNature(IClasspathEntry[] classPath, IProject project, IProgressMonitor monitor) throws CoreException { if (project == null) { throw new IllegalStateException("Project must be created before giving it a Java nature"); }/*from w w w.j a v a 2s . c o m*/ final IProjectDescription description = project.getDescription(); final String[] natures = description.getNatureIds(); final String[] newNatures = Arrays.copyOf(natures, natures.length + 1); newNatures[natures.length] = JavaCore.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); final IJavaProject javaProject = JavaCore.create(project); @SuppressWarnings("rawtypes") final Map options = javaProject.getOptions(true); // Compliance level need to be 1.6 JavaCore.setComplianceOptions(JavaCore.VERSION_1_6, options); javaProject.setOptions(options); javaProject.setRawClasspath(classPath, monitor); javaProject.setOutputLocation(javaProject.getPath().append("out"), monitor); }
From source file:metabup.annotations.wizards.NewAnnotationWizard.java
License:Open Source License
/** * The worker method. It will find the container, create the * file if missing or just replace its contents, and open * the editor on the newly created file. *///from ww w . j a v a2s.c o m private void doFinish(String projectName, String fileName, String annotationName, String description, IProgressMonitor monitor) throws CoreException { // create a sample file monitor.beginTask("Creating " + fileName, 2); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IResource resource = root.findMember(new Path(projectName)); if (!resource.exists() || !(resource instanceof IProject)) throwCoreException("Project \"" + projectName + "\" does not exist."); monitor.worked(1); IProject project = (IProject) resource; /* * Turn project into a Java project, if not yet */ IProjectDescription projectDescription = project.getDescription(); String javaNature[] = { JavaCore.NATURE_ID }; String projectNatures[] = projectDescription.getNatureIds(); boolean isJavaEnabled = false; for (int i = 0; i < projectNatures.length; i++) { if (projectNatures[i].equals(javaNature[0])) { isJavaEnabled = true; i = projectNatures.length; } } IJavaProject javaProject = JavaCore.create(project); if (!isJavaEnabled) { IProjectDescription pDescription = project.getDescription(); pDescription.setNatureIds(new String[] { JavaCore.NATURE_ID }); project.setDescription(pDescription, monitor); IFolder binFolder = project.getFolder("bin"); if (!binFolder.exists()) binFolder.create(false, true, monitor); javaProject.setOutputLocation(binFolder.getFullPath(), monitor); } monitor.worked(1); //Import Activator library Bundle plugin = Activator.getDefault().getBundle(); IPath relativePagePath = new Path(AnnotationsPluginPreferenceConstants.P_ANNOTATIONS_LIB_FILES); URL fileInPlugin = FileLocator.find(plugin, relativePagePath, null); if (fileInPlugin != null) { // the file exists URL fileUrl; try { fileUrl = FileLocator.toFileURL(fileInPlugin); File file = new File(fileUrl.getPath()); IClasspathEntry libEntry[] = { JavaCore.newLibraryEntry(new Path(file.getAbsolutePath()), null, // no source null, // no source false) }; // not exported monitor.worked(1); //set the build path IClasspathEntry[] buildPath = { JavaCore.newSourceEntry(project.getFullPath().append("src")), JavaRuntime.getDefaultJREContainerEntry(), libEntry[0] }; javaProject.setRawClasspath(buildPath, project.getFullPath().append("bin"), null); IFolder srcFolder = project.getFolder("src"); if (!srcFolder.exists()) srcFolder.create(true, true, monitor); project.refreshLocal(IResource.DEPTH_INFINITE, monitor); monitor.worked(1); //Add folder to Java element IPackageFragmentRoot folder = javaProject.getPackageFragmentRoot(srcFolder); //create package fragment IPackageFragment fragment = folder.createPackageFragment( AnnotationsPluginPreferenceConstants.P_ANNOTATIONS_PACKAGE, true, monitor); StringBuffer buffer = new StringBuffer(); ICompilationUnit cu = fragment.createCompilationUnit(fileName, AnnotationHandler.generateInstanceCode(buffer, annotationName, description).toString(), false, monitor); project.refreshLocal(IResource.DEPTH_INFINITE, monitor); monitor.worked(1); project.refreshLocal(IResource.DEPTH_INFINITE, monitor); } catch (IOException e) { // TODO Auto-generated catch block Activator.log(IStatus.ERROR, "Activator library couldn't be added to the java build path."); } } else { Activator.log(IStatus.ERROR, "Activator library couldn't be added to the java build path."); } /*final IFile file = container.getFile(new Path(fileName)); try { InputStream stream = openContentStream(); if (file.exists()) { file.setContents(stream, true, true, monitor); } else { file.create(stream, true, monitor); } stream.close(); } catch (IOException e) { }*/ /*monitor.setTaskName("Opening file for editing..."); getShell().getDisplay().asyncExec(new Runnable() { public void run() { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); try { IDE.openEditor(page, file, true); } catch (PartInitException e) { } } });*/ monitor.worked(1); }
From source file:net.roamstudio.roamflow.wizard.NewProjectWizard.java
License:Open Source License
private void createOutputLocation(IJavaProject javaProject) throws JavaModelException, CoreException { IFolder binFolder = javaProject.getProject().getFolder("bin"); //$NON-NLS-1$ createFolder(binFolder);//from ww w . j a va 2 s. c o m IPath outputLocation = binFolder.getFullPath(); javaProject.setOutputLocation(outputLocation, null); }
From source file:net.sf.rcer.jcoimport.ProjectGenerator.java
License:Open Source License
/** * Creates a plug-in project for the SAP JCo from the source file specified. * @param monitor/*from w w w . j av a2 s. c o m*/ * @param sourceFileName * @param pluginName * @throws CoreException * @throws IOException */ private void createJCoPluginProject(IProgressMonitor monitor, String sourceFileName, String pluginName) throws CoreException, IOException { monitor.subTask(MessageFormat.format(Messages.ProjectGenerator_CreatePluginTaskDescription, pluginName)); // read the source file 10 final Map<String, byte[]> files = readArchiveFile(sourceFileName); monitor.worked(10); // remove the project if it exists 5 IProject project = workspaceRoot.getProject(pluginName); if (project.exists()) { project.delete(true, true, new SubProgressMonitor(monitor, 5)); } else { monitor.worked(5); } // create and open the project 10 project.create(new SubProgressMonitor(monitor, 5)); project.open(new SubProgressMonitor(monitor, 5)); // update the project description 5 IProjectDescription description = project.getDescription(); description.setNatureIds(new String[] { JavaCore.NATURE_ID, PLUGIN_NATURE_ID }); project.setDescription(description, new SubProgressMonitor(monitor, 5)); // set the basic Java project properties 5 IJavaProject javaProject = JavaCore.create(project); IFolder binDir = project.getFolder("bin"); //$NON-NLS-1$ IPath binPath = binDir.getFullPath(); javaProject.setOutputLocation(binPath, new SubProgressMonitor(monitor, 5)); // create empty jni folder 5 project.getFolder("jni").create(true, true, new SubProgressMonitor(monitor, 5)); //$NON-NLS-1$ // copy sapjco3.jar 10 project.getFile("sapjco3.jar").create(new ByteArrayInputStream(files.get("sapjco3.jar")), //$NON-NLS-1$ //$NON-NLS-2$ true, new SubProgressMonitor(monitor, 10)); // create META-INF and MANIFEST.MF 10 // TODO use the version information from the MANIFEST.MF file in the archive IFolder metaInfFolder = project.getFolder("META-INF"); //$NON-NLS-1$ metaInfFolder.create(true, true, new SubProgressMonitor(monitor, 5)); StringBuilder manifest = new StringBuilder(); manifest.append("Manifest-Version: 1.0\n"); //$NON-NLS-1$ manifest.append("Bundle-ManifestVersion: 2\n"); //$NON-NLS-1$ manifest.append("Bundle-Name: SAP Java Connector v3\n"); //$NON-NLS-1$ manifest.append(MessageFormat.format("Bundle-SymbolicName: {0}\n", pluginName)); //$NON-NLS-1$ manifest.append("Bundle-Version: 7.11.0\n"); //$NON-NLS-1$ manifest.append("Bundle-ClassPath: bin/,\n"); //$NON-NLS-1$ manifest.append(" sapjco3.jar,\n"); //$NON-NLS-1$ manifest.append(" jni/\n"); //$NON-NLS-1$ manifest.append("Bundle-Vendor: SAP AG, Walldorf (packaged using RCER)\n"); //$NON-NLS-1$ manifest.append("Bundle-RequiredExecutionEnvironment: J2SE-1.5\n"); //$NON-NLS-1$ manifest.append("Export-Package: com.sap.conn.jco,\n"); //$NON-NLS-1$ manifest.append(" com.sap.conn.jco.ext,\n"); //$NON-NLS-1$ manifest.append(" com.sap.conn.jco.monitor,\n"); //$NON-NLS-1$ manifest.append(" com.sap.conn.jco.rt,\n"); //$NON-NLS-1$ manifest.append(" com.sap.conn.jco.server\n"); //$NON-NLS-1$ manifest.append("Bundle-ActivationPolicy: lazy\n"); //$NON-NLS-1$ writeTextFile(monitor, manifest, metaInfFolder.getFile("MANIFEST.MF")); //$NON-NLS-1$ // set classpath 5 final IPath jcoPath = new Path(MessageFormat.format("/{0}/sapjco3.jar", pluginName)); //$NON-NLS-1$ IClasspathEntry jcoEntry = JavaCore.newLibraryEntry(jcoPath, Path.EMPTY, Path.EMPTY, true); final IPath jniPath = new Path(MessageFormat.format("/{0}/jni", pluginName)); //$NON-NLS-1$ IClasspathEntry jniEntry = JavaCore.newLibraryEntry(jniPath, Path.EMPTY, Path.EMPTY, true); javaProject.setRawClasspath(new IClasspathEntry[] { jcoEntry, jniEntry }, new SubProgressMonitor(monitor, 5)); // create build.properties 5 StringBuilder buildProperties = new StringBuilder(); buildProperties.append("bin.includes = META-INF/,\\\n"); //$NON-NLS-1$ buildProperties.append(" sapjco3.jar,\\\n"); //$NON-NLS-1$ buildProperties.append(" jni/,\\\n"); //$NON-NLS-1$ buildProperties.append(" .\n"); //$NON-NLS-1$ writeTextFile(monitor, buildProperties, project.getFile("build.properties")); //$NON-NLS-1$ // collect the plug-in for export exportableBundles.add(modelManager.findModel(project)); }
From source file:net.sf.rcer.jcoimport.ProjectGenerator.java
License:Open Source License
/** * Creates a plug-in project for the SAP IDoc library from the source file specified. * @param monitor/*from w w w . jav a 2 s . c om*/ * @param sourceFileName * @param pluginName * @throws CoreException * @throws IOException */ private void createIDocPluginProject(IProgressMonitor monitor, String sourceFileName, String pluginName, String pluginNameJCo) throws CoreException, IOException { monitor.subTask(MessageFormat.format(Messages.ProjectGenerator_CreatePluginTaskDescription, pluginName)); // read the source file 10 final Map<String, byte[]> files = readArchiveFile(sourceFileName); monitor.worked(10); // remove the project if it exists 5 IProject project = workspaceRoot.getProject(pluginName); if (project.exists()) { project.delete(true, true, new SubProgressMonitor(monitor, 5)); } else { monitor.worked(5); } // create and open the project 10 project.create(new SubProgressMonitor(monitor, 5)); project.open(new SubProgressMonitor(monitor, 5)); // update the project description 5 IProjectDescription description = project.getDescription(); description.setNatureIds(new String[] { JavaCore.NATURE_ID, PLUGIN_NATURE_ID }); project.setDescription(description, new SubProgressMonitor(monitor, 5)); // set the basic Java project properties 5 IJavaProject javaProject = JavaCore.create(project); IFolder binDir = project.getFolder("bin"); //$NON-NLS-1$ IPath binPath = binDir.getFullPath(); javaProject.setOutputLocation(binPath, new SubProgressMonitor(monitor, 5)); // copy sapidoc3.jar 15 project.getFile("sapidoc3.jar").create(new ByteArrayInputStream(files.get("sapidoc3.jar")), //$NON-NLS-1$ //$NON-NLS-2$ true, new SubProgressMonitor(monitor, 15)); // create META-INF and MANIFEST.MF 10 // TODO use the version information from the MANIFEST.MF file in the archive IFolder metaInfFolder = project.getFolder("META-INF"); //$NON-NLS-1$ metaInfFolder.create(true, true, new SubProgressMonitor(monitor, 5)); StringBuilder manifest = new StringBuilder(); manifest.append("Manifest-Version: 1.0\n"); //$NON-NLS-1$ manifest.append("Bundle-ManifestVersion: 2\n"); //$NON-NLS-1$ manifest.append("Bundle-Name: SAP IDoc Library v3\n"); //$NON-NLS-1$ manifest.append(MessageFormat.format("Bundle-SymbolicName: {0}\n", pluginName)); //$NON-NLS-1$ manifest.append("Bundle-Version: 7.11.0\n"); //$NON-NLS-1$ manifest.append("Bundle-ClassPath: bin/,\n"); //$NON-NLS-1$ manifest.append(" sapidoc3.jar\n"); //$NON-NLS-1$ manifest.append("Bundle-Vendor: SAP AG, Walldorf (packaged using RCER)\n"); //$NON-NLS-1$ manifest.append("Bundle-RequiredExecutionEnvironment: J2SE-1.5\n"); //$NON-NLS-1$ manifest.append("Export-Package: com.sap.conn.idoc,\n"); //$NON-NLS-1$ manifest.append(" com.sap.conn.idoc.jco,\n"); //$NON-NLS-1$ manifest.append(" com.sap.conn.idoc.rt.cp,\n"); //$NON-NLS-1$ manifest.append(" com.sap.conn.idoc.rt.record,\n"); //$NON-NLS-1$ manifest.append(" com.sap.conn.idoc.rt.record.impl,\n"); //$NON-NLS-1$ manifest.append(" com.sap.conn.idoc.rt.trace,\n"); //$NON-NLS-1$ manifest.append(" com.sap.conn.idoc.rt.util,\n"); //$NON-NLS-1$ manifest.append(" com.sap.conn.idoc.rt.xml\n"); //$NON-NLS-1$ manifest.append("Bundle-ActivationPolicy: lazy\n"); //$NON-NLS-1$ manifest.append(MessageFormat.format("Require-Bundle: {0}\n", pluginNameJCo)); //$NON-NLS-1$ writeTextFile(monitor, manifest, metaInfFolder.getFile("MANIFEST.MF")); //$NON-NLS-1$ // set classpath 5 final IPath jcoPath = new Path(MessageFormat.format("/{0}/sapidoc3.jar", pluginName)); //$NON-NLS-1$ IClasspathEntry jcoEntry = JavaCore.newLibraryEntry(jcoPath, Path.EMPTY, Path.EMPTY, true); javaProject.setRawClasspath(new IClasspathEntry[] { jcoEntry }, new SubProgressMonitor(monitor, 5)); // create build.properties 5 StringBuilder buildProperties = new StringBuilder(); buildProperties.append("bin.includes = META-INF/,\\\n"); //$NON-NLS-1$ buildProperties.append(" sapidoc3.jar,\\\n"); //$NON-NLS-1$ buildProperties.append(" .\n"); //$NON-NLS-1$ writeTextFile(monitor, buildProperties, project.getFile("build.properties")); //$NON-NLS-1$ // collect the plug-in for export exportableBundles.add(modelManager.findModel(project)); }
From source file:org.apache.easyant4e.natures.EasyAntNature.java
License:Apache License
private void addSourceFolders(IJavaProject javaProject, String... path) throws JavaModelException { List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); entries.addAll(Arrays.asList(javaProject.getRawClasspath())); IResource outputLocation = javaProject.getProject().findMember("target"); if (outputLocation == null) { outputLocation = createSourceFolder(javaProject.getProject(), "target"); }//from w w w. j a va 2 s. co m javaProject.setOutputLocation(outputLocation.getFullPath(), null); for (String p : path) { IResource sourceFolder = javaProject.getProject().findMember(p); if (sourceFolder == null) { sourceFolder = createSourceFolder(javaProject.getProject(), p); } if (sourceFolder != null) { IPath[] exclusionPatterns = new IPath[] { outputLocation.getFullPath() }; IClasspathEntry srcEntry = JavaCore.newSourceEntry(sourceFolder.getFullPath(), exclusionPatterns, outputLocation.getFullPath()); entries.add(srcEntry); } } javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null); }
From source file:org.apache.easyant4e.tests.EclipseProjectBuilder.java
License:Apache License
private static void createOutputFolder(IJavaProject javaProject) throws CoreException { IFolder binFolder = createBinFolder(javaProject.getProject()); IPath outputLocation = binFolder.getFullPath(); javaProject.setOutputLocation(outputLocation, null); }
From source file:org.apache.openjpa.eclipse.EnhancerBuilderTest.java
License:Apache License
protected void setUp() throws Exception { IWorkspace workspace = null;//w w w . java 2s. co m try { workspace = ResourcesPlugin.getWorkspace(); } catch (IllegalStateException e) { fail("workspace is closed, you are most probably running this as a standalone JUnit Test instead of as an Eclipse PDE Plug-In Test?!"); } // create project project = workspace.getRoot().getProject(PROJECT_NAME); project.create(null); project.open(null); // create source and output folders IFolder srcFolder = project.getFolder("src"); srcFolder.create(true, true, null); IFolder binFolder = project.getFolder("bin"); binFolder.create(true, true, null); IProjectDescription desc = project.getDescription(); // Set the Java and OpenJPA natures on the project, // so that the builders is added and initialized desc.setNatureIds(new String[] { JavaCore.NATURE_ID, OpenJPANature.NATURE_ID }); project.setDescription(desc, null); // Declare Java source and output folders IJavaProject javaProject = JavaCore.create(project); javaProject.setOutputLocation(binFolder.getFullPath(), null); IClasspathEntry cpEntry = JavaCore.newSourceEntry(srcFolder.getFullPath()); javaProject.setRawClasspath(new IClasspathEntry[] { cpEntry }, null); // create a Java package and a class IPackageFragmentRoot pkgFragmentRoot = javaProject.getPackageFragmentRoot(srcFolder); IPackageFragment pkgFragment = pkgFragmentRoot.createPackageFragment(TESTCLASS_PACKAGE, true, null); // and copy the same classes already used in the PCEnhancerHelperTest copyTestClassToPackage(pkgFragment, "TestEntity.java"); // copyTestClassToPackage(pkgFragment, "NotToEnhance.java"); javaProject.save(null, true); }
From source file:org.apache.openjpa.eclipse.util.ClasspathHelperTest.java
License:Apache License
protected void setUp() throws Exception { IWorkspace workspace = null;// w w w.java 2 s.com try { workspace = ResourcesPlugin.getWorkspace(); } catch (IllegalStateException e) { fail("workspace is closed, you are most probably running this as a standalone JUnit Test instead of as an Eclipse PDE Plug-In Test?!"); } // create project project = workspace.getRoot().getProject(PROJECT_NAME); project.create(null); project.open(null); // create source and output folders IFolder srcFolder = project.getFolder("src"); srcFolder.create(true, true, null); IFolder binFolder = project.getFolder("bin"); binFolder.create(true, true, null); // Set the Java nature on the project, so that the builder is added and initialized IProjectDescription desc = workspace.newProjectDescription(PROJECT_NAME); desc.setNatureIds(new String[] { JavaCore.NATURE_ID }); project.setDescription(desc, null); // Declare Java source and output folders IJavaProject javaProject = JavaCore.create(project); javaProject.setOutputLocation(binFolder.getFullPath(), null); IClasspathEntry cpEntry = JavaCore.newSourceEntry(srcFolder.getFullPath()); javaProject.setRawClasspath(new IClasspathEntry[] { cpEntry }, null); // create a Java package and a class IPackageFragmentRoot pkgFragmentRoot = javaProject.getPackageFragmentRoot(srcFolder); IPackageFragment pkgFragment = pkgFragmentRoot.createPackageFragment(TESTCLASS_PACKAGE, true, null); InputStream is = Thread.currentThread().getContextClassLoader() .getResourceAsStream("/com/odcgroup/classpath/demo/tests/resources/testclasscontent.txt"); String contents = IOUtils.toString(is); pkgFragment.createCompilationUnit(TESTCLASS_NAME + ".java", contents, true, null); javaProject.save(null, true); }