/** {@inheritDoc} */ public Object execute(CommandLine commandLine) throws Exception { String name = commandLine.getValue(Options.PROJECT_OPTION); IProject project = ProjectUtils.getProject(name); String[] aliases = StringUtils.split(commandLine.getValue(Options.NATURE_OPTION), ','); IProjectDescription desc = project.getDescription(); String[] natureIds = desc.getNatureIds(); ArrayList<String> modified = new ArrayList<String>(); ArrayList<String> newNatures = new ArrayList<String>(); CollectionUtils.addAll(modified, natureIds); for (String alias : aliases) { String natureId = ProjectNatureFactory.getNatureForAlias(alias); if (natureId != null && !modified.contains(natureId)) { modified.add(natureId); newNatures.add(natureId); } } desc.setNatureIds((String[]) modified.toArray(new String[modified.size()])); project.setDescription(desc, new NullProgressMonitor()); for (String nature : newNatures) { ProjectManager manager = ProjectManagement.getProjectManager(nature); if (manager != null) { manager.create(project, commandLine); } } return Services.getMessage("project.nature.added"); }
private void addProjectNature(final IProject proj, final IProgressMonitor monitor) throws CoreException { monitor.subTask(Messages.getString("GridProjectCreationOperation.nature_task")); // $NON-NLS-1$ IProjectDescription desc = proj.getDescription(); String[] natureIDs = desc.getNatureIds(); String gridNatureID = GridProjectNature.getID(); boolean found = false; for (int i = 0; (i < natureIDs.length) && (!found); i++) { if (natureIDs[i].equals(gridNatureID)) { found = true; } } if (!found) { String[] newNatureIDs = new String[natureIDs.length + 1]; System.arraycopy(natureIDs, 0, newNatureIDs, 1, natureIDs.length); newNatureIDs[0] = gridNatureID; desc.setNatureIds(newNatureIDs); proj.setDescription(desc, new SubProgressMonitor(monitor, 100)); } if (monitor.isCanceled()) { throw new OperationCanceledException(); } }
/** * Sets or clears the Mule UMO Configuration nature to this project * * @param project The project to set. * @param setIt True if the nature should be added, false if it should be removed * @throws CoreException If something goes wrong */ public void setMuleNature(IProject project, boolean setIt) throws CoreException { /* * Four possible outcomes: A - transition to on B - already on C - transition to off D - already off */ if (project == null) return; IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); for (int i = 0; i < natures.length; ++i) { if (MuleNature.NATURE_ID.equals(natures[i])) { if (setIt) return; // outcome B - Already had the nature // Outcome C - Remove the nature String[] newNatures = new String[natures.length - 1]; System.arraycopy(natures, 0, newNatures, 0, i); System.arraycopy(natures, i + 1, newNatures, i, natures.length - i - 1); description.setNatureIds(newNatures); project.setDescription(description, null); return; // Outcome C - No longer has the nature } } if (!setIt) return; // Outcome D - didn't have it, just do nothing // Outcome A - add the nature String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 1, natures.length); newNatures[0] = MuleNature.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); }
public static void removeNatureFromProject(IProject project, String natureId) throws CoreException { IProjectDescription description = project.getDescription(); String[] prevNatures = description.getNatureIds(); int natureIndex = -1; for (int i = 0; i < prevNatures.length; i++) { if (prevNatures[i].equals(natureId)) { natureIndex = i; i = prevNatures.length; } } // Remove nature only if it exists... if (natureIndex != -1) { String[] newNatures = new String[prevNatures.length - 1]; System.arraycopy(prevNatures, 0, newNatures, 0, natureIndex); System.arraycopy( prevNatures, natureIndex + 1, newNatures, natureIndex, prevNatures.length - (natureIndex + 1)); description.setNatureIds(newNatures); project.setDescription(description, null); } TapestryCore.getDefault().getCoreListeners().fireCoreListenerEvent(); }
public static void addNature(IProject project) { if (!project.isOpen()) { return; } // Get the description IProjectDescription description; try { description = project.getDescription(); } catch (CoreException e) { JsonLog.logError("Error get project description: ", e); return; } List<String> newIds = new ArrayList<String>(); String[] natureIds = description.getNatureIds(); for (String natureId : natureIds) { if (natureId.equals(NATURE_ID)) { return; } } newIds.addAll(Arrays.asList(natureIds)); newIds.add(NATURE_ID); // Save description description.setNatureIds(newIds.toArray(new String[newIds.size()])); try { project.setDescription(description, null); } catch (CoreException e) { JsonLog.logError("Error set project description: ", e); } }
/** * Toggles sample nature on a project * * @param project to have sample nature added or removed */ private void toggleNature(IProject project) { try { IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); for (int i = 0; i < natures.length; ++i) { if (QSARNature.NATURE_ID.equals(natures[i])) { // Remove the nature String[] newNatures = new String[natures.length - 1]; System.arraycopy(natures, 0, newNatures, 0, i); System.arraycopy(natures, i + 1, newNatures, i, natures.length - i - 1); description.setNatureIds(newNatures); project.setDescription(description, null); return; } } // Add the nature String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = QSARNature.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); project.hasNature(QSARNature.NATURE_ID); } catch (CoreException e) { } }
/** * Add a Java Nature to a project when creating * * @param project * @throws CoreException */ private static void addJavaNature(final IProject project) throws CoreException { if (!project.hasNature(JavaCore.NATURE_ID)) { final IProjectDescription description = project.getDescription(); final String[] prevNatures = description.getNatureIds(); final String[] newNatures = new String[prevNatures.length + 1]; System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length); newNatures[prevNatures.length] = JavaCore.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); IFolder sourceFolder = project.getFolder("/src"); sourceFolder.create(true, true, null); IJavaProject javaProject = JavaCore.create(project); javaProject.setRawClasspath( new IClasspathEntry[] { JavaCore.newSourceEntry(sourceFolder.getFullPath()), JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER")) }, null); @SuppressWarnings("unchecked") Hashtable<String, String> javaOptions = JavaCore.getOptions(); javaOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); javaOptions.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); javaOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); javaProject.setOptions(javaOptions); } }
@Override public boolean performFinish() { boolean res = super.performFinish(); if (res == true) { final IProject project = getNewProject(); try { if (project != null) { IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = PopeNature.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); PopeCore.create(project); } } catch (CoreException e) { StatusManager.getManager().handle(e.getStatus()); } } return res; }
/** * adds the Camel nature to the project * * @param project * @param monitor * @throws CoreException */ private void addCamelNature(IProject project, IProgressMonitor monitor) throws CoreException { IProjectDescription projectDescription = project.getDescription(); String[] ids = projectDescription.getNatureIds(); String[] newIds = new String[ids.length + 1]; System.arraycopy(ids, 0, newIds, 0, ids.length); newIds[ids.length] = Activator.CAMEL_NATURE_ID; projectDescription.setNatureIds(newIds); project.setDescription(projectDescription, monitor); }
public static void enableNature(IProject project, boolean b) throws CoreException { IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = Constants.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); }
/** * @param project * @throws CoreException */ public void addJavaNature(IProject project) throws CoreException { IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = JavaCore.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, new NullProgressMonitor()); }
private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException { IProjectDescription description = proj.getDescription(); String[] prevNatures = description.getNatureIds(); String[] newNatures = new String[prevNatures.length + 1]; System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length); newNatures[prevNatures.length] = natureId; description.setNatureIds(newNatures); proj.setDescription(description, monitor); }
public static void addNature(IProject project, String nature) { try { IProjectDescription description = project.getDescription(); String[] prevNatures = description.getNatureIds(); String[] newNatures = new String[prevNatures.length + 1]; System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length); newNatures[prevNatures.length] = nature; description.setNatureIds(newNatures); project.setDescription(description, null); } catch (CoreException e) { e.printStackTrace(); } }
public void addNature(IProject project) { try { IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = XtextProjectHelper.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); } catch (CoreException e) { e.printStackTrace(); } }
/** Utility routine to remove a PythonNature from a project. */ public static synchronized void removeNature(IProject project, IProgressMonitor monitor) throws CoreException { if (monitor == null) { monitor = new NullProgressMonitor(); } PythonNature nature = PythonNature.getPythonNature(project); if (nature == null) { return; } try { // we have to set the nature store to stop listening changes to .pydevproject nature.pythonNatureStore.setProject(null); } catch (Exception e) { Log.log(e); } try { // we have to remove the project from the pythonpath nature too... nature.pythonPathNature.setProject(null, null); } catch (Exception e) { Log.log(e); } // notify listeners that the pythonpath nature is now empty for this project try { PythonNatureListenersManager.notifyPythonPathRebuilt(project, null); } catch (Exception e) { Log.log(e); } try { // actually remove the pydev configurations IResource member = project.findMember(".pydevproject"); if (member != null) { member.delete(true, null); } } catch (CoreException e) { Log.log(e); } // and finally... remove the nature IProjectDescription description = project.getDescription(); List<String> natures = new ArrayList<String>(Arrays.asList(description.getNatureIds())); natures.remove(PYTHON_NATURE_ID); description.setNatureIds(natures.toArray(new String[natures.size()])); project.setDescription(description, monitor); }
/** * @see * it.unitn.disi.unagi.application.services.IManageProjectsService#createNewProject(org.eclipse.core.runtime.IProgressMonitor, * java.lang.String) */ @Override public IProject createNewProject(IProgressMonitor progressMonitor, String name) throws CouldNotSaveUnagiProjectException { LogUtil.log.info("Creating a new project: {0}.", name); // $NON-NLS-1$ // Obtains a project descriptor with the desired name from the workspace. IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(name); // If the project already exists, throws a Unagi exception. if (project.exists()) { LogUtil.log.warn( "A project with the same name already exists in the workspace: {0}.", name); //$NON-NLS-1$ throw new CouldNotSaveUnagiProjectException(project); } try { // Creates and opens the project. project.create(progressMonitor); project.open(progressMonitor); // Sets the Unagi project nature. IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = UnagiProjectNature.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, progressMonitor); // Creates the project's subfolders. for (String subdir : PROJECT_SUBDIRS) { IFolder folder = project.getFolder(subdir); folder.create(true, true, progressMonitor); } } // If any other errors occurred, throw an exception. catch (CoreException e) { LogUtil.log.error( "Unagi caught an Eclipse exception while trying to create project: {0}.", e, name); // $NON-NLS-1$ throw new CouldNotSaveUnagiProjectException(project, e); } LogUtil.log.info("Successfully created and opened Unagi project: {0}.", name); // $NON-NLS-1$ return project; }
public static void addNaturesToProject( IProject proj, String[] natureIds, IProgressMonitor monitor) throws CoreException { IProjectDescription description = proj.getDescription(); String[] prevNatures = description.getNatureIds(); String[] newNatures = new String[prevNatures.length + natureIds.length]; System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length); for (int i = prevNatures.length; i < newNatures.length; i++) { newNatures[i] = natureIds[i - prevNatures.length]; } description.setNatureIds(newNatures); proj.setDescription(description, monitor); }
/* * (non-Javadoc) * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) */ @Override public Object[] getChildren(Object parentElement) { if (parentElement instanceof IProject) { IProject project = (IProject) parentElement; CamelVirtualFolder cvf = new CamelVirtualFolder(project); cvf.populateChildren(); boolean validNature = false; try { IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); for (int i = 0; i < natures.length; ++i) { if (Activator.CAMEL_NATURE_ID.equals(natures[i])) { validNature = true; } } } catch (Exception ex) { ex.printStackTrace(); } if (!validNature && cvf.getCamelFiles().size() > 0) { // add camel nature try { addCamelNature(project, null); } catch (CoreException ex) { System.err.println("Unable to set Camel Nature on the project..."); } finally { validNature = true; } } if (validNature) { CamelVirtualFolder[] resVal = new CamelVirtualFolder[1]; resVal[0] = cvf; return resVal; } return null; } else if (parentElement instanceof CamelVirtualFolder) { CamelVirtualFolder cvf = (CamelVirtualFolder) parentElement; if (cvf.getCamelFiles().size() < 1) { cvf.populateChildren(); } return cvf.getCamelFiles().toArray(new IFile[cvf.getCamelFiles().size()]); } return new Object[] {}; }
public static void addNatureToProject(IProject project, String natureId, boolean forceOrder) throws CoreException { IProjectDescription description = project.getDescription(); List<String> natures = new ArrayList<String>(Arrays.asList(description.getNatureIds())); if (!natures.contains(natureId)) { if (forceOrder) { // changes so that the project overlay icon shows up! natures.add(0, natureId); } else { natures.add(natureId); } description.setNatureIds((String[]) natures.toArray()); project.setDescription(description, null); } TapestryCore.getDefault().getCoreListeners().fireCoreListenerEvent(); }
private void addNature(IProject project, IProgressMonitor monitor) throws CoreException { monitor = Util.getNonNullMonitor(monitor); try { monitor.beginTask("", 1); IProjectDescription description = project.getDescription(); String[] prevNatures = description.getNatureIds(); String[] newNatures = new String[prevNatures.length + 1]; System.arraycopy(prevNatures, 0, newNatures, 1, prevNatures.length); newNatures[0] = Constants.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, IResource.FORCE, null); } finally { monitor.done(); } }
@Override public void configure() throws CoreException { IProjectDescription desc = getProject().getDescription(); ICommand[] commands = desc.getBuildSpec(); boolean found = false; for (ICommand command : commands) { if (RadlBuilder.BUILDER_ID.equals(command.getBuilderName())) { found = true; break; } } if (!found) { ICommand[] newCommands = new ICommand[commands.length + 1]; System.arraycopy(commands, 0, newCommands, 0, commands.length); ICommand command = desc.newCommand(); command.setBuilderName(RadlBuilder.BUILDER_ID); newCommands[newCommands.length - 1] = command; desc.setBuildSpec(newCommands); } desc.setNatureIds(ensureNature(desc.getNatureIds())); getProject().setDescription(desc, null); }
public static synchronized void setupProjectNatures(IProject project, IProgressMonitor monitor) throws CoreException { if ((project == null) || (!project.isOpen())) return; if (monitor == null) monitor = new NullProgressMonitor(); String natureId = "org.jil.ide.widgetNature"; if (!project.hasNature(natureId)) { IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 1, natures.length); newNatures[0] = natureId; description.setNatureIds(newNatures); project.setDescription(description, new SubProgressMonitor(monitor, 10)); } JavaScriptNature jsNature = new JavaScriptNature(project, monitor); jsNature.configure(); }
@Override public boolean performFinish() { boolean finish = super.performFinish(); try { IProject project = this.getNewProject(); IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); String[] newNatures = new String[natures.length + 1]; // add new natures System.arraycopy(natures, 0, newNatures, 1, natures.length); newNatures[0] = JavaCore.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); // retrieves the up-to-date description description = project.getDescription(); // filters out the Java builder ICommand[] commands = description.getBuildSpec(); List<ICommand> buildSpec = new ArrayList<ICommand>(commands.length); for (ICommand command : commands) { if (!JavaCore.BUILDER_ID.equals(command.getBuilderName())) { buildSpec.add(command); } } // updates the description and replaces the existing description description.setBuildSpec(buildSpec.toArray(new ICommand[0])); project.setDescription(description, null); } catch (CoreException e) { e.printStackTrace(); } return finish; }
public static void removeNature(IProject project, String nature) { try { IProjectDescription description = project.getDescription(); String[] prevNatures = description.getNatureIds(); int found = 0; for (int i = 0; i < prevNatures.length; i++) { if (prevNatures[i].equals(nature)) { found = i; break; } } if (found != -1) { String[] newNatures = new String[prevNatures.length - 1]; System.arraycopy(prevNatures, 0, newNatures, 0, found); System.arraycopy(prevNatures, found + 1, newNatures, found, newNatures.length - found); description.setNatureIds(newNatures); project.setDescription(description, null); } } catch (CoreException e) { e.printStackTrace(); } }
/** * Remove the PMD Nature from a project * * @param project a project to remove the PMD Nature * @param monitor a progress monitor * @return success true if the nature has been removed; false means the project already had not * the PMD Nature. * @throws CoreException if any error occurs. */ public static boolean removePMDNature(final IProject project) throws CoreException { final boolean success = false; if (project.hasNature(PMDNature.PMD_NATURE)) { final IProjectDescription description = project.getDescription(); final String[] natureIds = description.getNatureIds(); final String[] newNatureIds = new String[natureIds.length - 1]; for (int i = 0, j = 0; i < natureIds.length; i++) { if (!natureIds[i].equals(PMDNature.PMD_NATURE)) { newNatureIds[j++] = natureIds[i]; } } description.setNatureIds(newNatureIds); project.setDescription(description, null); project.deleteMarkers(PMDRuntimeConstants.PMD_MARKER, true, IResource.DEPTH_INFINITE); final IFile file = project.getFile(".pmd"); if (file.exists() && file.isAccessible()) { file.delete(true, false, null); } } return success; }
/** * Utility routine to add PythonNature to the project * * @param projectPythonpath: @see {@link IPythonPathNature#setProjectSourcePath(String)} */ public static synchronized IPythonNature addNature( IProject project, IProgressMonitor monitor, String version, String projectPythonpath, String externalProjectPythonpath, String projectInterpreter, Map<String, String> variableSubstitution) throws CoreException { if (project == null || !project.isOpen()) { return null; } if (monitor == null) { monitor = new NullProgressMonitor(); } if (projectInterpreter == null) { projectInterpreter = IPythonNature.DEFAULT_INTERPRETER; } IProjectDescription desc = project.getDescription(); // only add the nature if it still hasn't been added. if (project.hasNature(PYTHON_NATURE_ID) == false) { String[] natures = desc.getNatureIds(); String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = PYTHON_NATURE_ID; desc.setNatureIds(newNatures); project.setDescription(desc, monitor); } else { // Return if it already has the nature configured. IProjectNature n = getPythonNature(project); if (n instanceof IPythonNature) { return (IPythonNature) n; } } // add the builder. It is used for pylint, pychecker, code completion, etc. ICommand[] commands = desc.getBuildSpec(); // now, add the builder if it still hasn't been added. if (hasBuilder(commands) == false && PyDevBuilderPrefPage.usePydevBuilders()) { ICommand command = desc.newCommand(); command.setBuilderName(BUILDER_ID); ICommand[] newCommands = new ICommand[commands.length + 1]; System.arraycopy(commands, 0, newCommands, 1, commands.length); newCommands[0] = command; desc.setBuildSpec(newCommands); project.setDescription(desc, monitor); } IProjectNature n = getPythonNature(project); if (n instanceof PythonNature) { PythonNature nature = (PythonNature) n; // call initialize always - let it do the control. nature.init( version, projectPythonpath, externalProjectPythonpath, monitor, projectInterpreter, variableSubstitution); return nature; } return null; }
/** * The worker method. It will create a new project, then create the appropriate Soar heirarchy and * files. */ private void doFinish(String projectName, IProgressMonitor monitor) throws CoreException { monitor.beginTask("Creating " + projectName, 7); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject newProject = root.getProject(projectName); // creation of the project if (newProject.exists()) { throwCoreException("Project \"" + projectName + "\" already exists"); } else { newProject.create(monitor); newProject.open(monitor); try { IProjectDescription description = newProject.getDescription(); String[] natures = description.getNatureIds(); String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = SoarProjectNature.NATURE_ID; description.setNatureIds(newNatures); newProject.setDescription(description, IResource.FORCE, monitor); newProject.setPersistentProperty(DataMap.VERTEX_ID, "0"); } catch (CoreException e) { e.printStackTrace(); } // catch } // else monitor.worked(2); // Create the contents of the project's root directory IFolder folderAll = newProject.getFolder("all"); if (!folderAll.exists()) { folderAll.create(true, true, monitor); } // if FileMarker.markResource(folderAll, "file"); IFolder folderElaborations = newProject.getFolder("elaborations"); if (!folderElaborations.exists()) { folderElaborations.create(true, true, monitor); } // if FileMarker.markResource(folderElaborations, "file"); IFile file_firstload = newProject.getFile("_firstload.soar"); if (!file_firstload.exists()) { file_firstload.create( Utility.getFileTemplate(file_firstload, "_firstload.soar"), true, monitor); } // if FileMarker.markResource(file_firstload, "file"); IFile filedatamap = newProject.getFile("datamap.xdm"); if (!filedatamap.exists()) { filedatamap.create(Utility.getFileTemplate(filedatamap, "datamap.xdm"), true, monitor); } // if monitor.worked(3); // Create the contents of the elaborations folder IFile file_all = folderElaborations.getFile("_all.soar"); if (!file_all.exists()) { file_all.create(Utility.getFileTemplate(file_all, "_all.soar"), true, monitor); } // if FileMarker.markResource(file_all, "file"); IFile filetopstate = folderElaborations.getFile("top-state.soar"); if (!filetopstate.exists()) { filetopstate.create(Utility.getFileTemplate(filetopstate, "top-state.soar"), true, monitor); } // if FileMarker.markResource(filetopstate, "file"); SourcingFile.createSourcingFile(newProject, monitor); newProject.close(monitor); newProject.open(monitor); monitor.worked(2); monitor.done(); } // void doFinish(...)
/** * Adds the java nature to a given project * * @return the java project (nature) that has been set. */ protected IJavaProject configureAsJavaProject(IProject project, IProgressMonitor monitor) throws CoreException { IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = JavaCore.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, monitor); IFolder srcFolder = project.getFolder(new Path("src")); srcFolder.create(false, true, monitor); IJavaProject javaProject = JavaCore.create(project); javaProject.setRawClasspath( new IClasspathEntry[] {JavaCore.newSourceEntry(srcFolder.getFullPath())}, monitor); Set<IClasspathEntry> entries = new HashSet<IClasspathEntry>(); entries.addAll(Arrays.asList(javaProject.getRawClasspath())); entries.add(JavaRuntime.getDefaultJREContainerEntry()); javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), monitor); // create src/javamod1/javamod2 IFolder javaMod1Folder = srcFolder.getFolder("javamod1"); javaMod1Folder.create(true, true, monitor); IFolder javaMod2Folder = javaMod1Folder.getFolder("javamod2"); javaMod2Folder.create(true, true, monitor); // create src/JavaDefault.java IFile javaClassFile = srcFolder.getFile("JavaDefault.java"); String javaClassContents = "public class JavaDefault {\n" + // default package " private int testJavaDefault(String[] args) {\n" + " return 0;\n" + " }\n" + "}\n"; javaClassFile.create(new ByteArrayInputStream(javaClassContents.getBytes()), true, monitor); // create src/javamod1/JavaClass.java javaClassFile = javaMod1Folder.getFile("JavaClass.java"); javaClassContents = "package javamod1;\n" + "public class JavaClass {\n" + " \n" + " public static int JAVA_CLASS_CONSTANT = 1;\n" + " \n" + " public static void main(String[] args) {\n" + " new JavaClass().testJavaClass(new int[0]);\n" + " }\n" + " private int testJavaClass(int[] args) {\n" + " return 0;\n" + " }\n" + "}\n"; javaClassFile.create(new ByteArrayInputStream(javaClassContents.getBytes()), true, monitor); // create src/javamod1/javamod2/JavaClass2.java javaClassFile = javaMod2Folder.getFile("JavaClass2.java"); javaClassContents = "package javamod1.javamod2;\n" + "public class JavaClass2 {\n" + " \n" + " public static int JAVA_CLASS_CONSTANT_2 = 1;\n" + " \n" + " public JavaClass2(int i){};\n" + " \n" + " public static void main(String[] args) {\n" + " new JavaClass2(1).testJavaClass2(new int[0]);\n" + " }\n" + " private int testJavaClass2(int[] args) {\n" + " return 0;\n" + " }\n" + "}\n"; javaClassFile.create(new ByteArrayInputStream(javaClassContents.getBytes()), true, monitor); project.refreshLocal(IResource.DEPTH_INFINITE, monitor); return javaProject; }