Reputation: 3981
i made a new plugin in eclipse that adds a new project entry that can then be used to add a new project.
however when going to project properties i get this:
instead of this:
so, my question is, how to get my project to also include all the java things (like: java build path, etc...), as i want this project to be based on the default java project.
how i am making the project currently is (code):
@Override
public boolean performFinish()
{
if (project != null)
{
return true;
}
final IProject projectHandle = wizardPage.getProjectHandle();
URI projectURI = (!wizardPage.useDefaults()) ? wizardPage.getLocationURI() : null;
IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IProjectDescription desc = workspace.newProjectDescription(projectHandle.getName());
desc.setLocationURI(projectURI);
WorkspaceModifyOperation op = new WorkspaceModifyOperation()
{
protected void execute(IProgressMonitor monitor) throws CoreException
{
createProject(desc, projectHandle, monitor);
}
};
try
{
getContainer().run(true, true, op);
}
catch (InterruptedException e)
{
return false;
}
catch (InvocationTargetException e)
{
Throwable realException = e.getTargetException();
MessageDialog.openError(getShell(), "Error", realException.getMessage());
return false;
}
project = projectHandle;
if (project == null)
{
return false;
}
BasicNewProjectResourceWizard.updatePerspective(config);
BasicNewProjectResourceWizard.selectAndReveal(project, workbench.getActiveWorkbenchWindow());
return true;
}
edit ***
ok so the solution is to add a facet to the project. if i do this manualy after creating a new project via my plugin - from right click, project properties - it works. how to add this facet programmaticaly?
edit 2 ***
ok, so it is done via:
description.setNatureIds
but not quite.
here is how the project looks when i manually add the facet to it (and this is how i want it to look):
and this is how it actually looks when i add nature id "org.eclipse.jdt.core.javanature" programmaticaly (not how i want it)
so... how to fix that? do i need another nature?
here is the .project file content when i manually add the facet:
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>test</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
also the file .classpath gets added (when adding facet manually, but there is no such file when it gets added programmaticaly):
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
here is also my method createProject():
private void createProject(IProjectDescription description, IProject proj, IProgressMonitor monitor)
throws CoreException, OperationCanceledException
{
try
{
monitor.beginTask("", 2000);
proj.create(description, new SubProgressMonitor(monitor, 10));
if (monitor.isCanceled())
{
throw new OperationCanceledException();
}
proj.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 10));
IContainer container = (IContainer) proj;
[ *** ]
}
finally
{
monitor.done();
}
}
Upvotes: 4
Views: 6940
Reputation: 2907
Your created project is missing Java and WST natures and builders.
desc.setNatureIds(new String[] {org.eclipse.jdt.core.JavaCore.NATURE_ID, "org.eclipse.wst.common.project.facet.core.nature"});
org.eclipse.core.resources.ICommand[] commands = new ICommand[] { desc.newCommand(), desc.newCommand };
commands[0].setBuilderName(org.eclipse.jdt.core.JavaCore.BUILDER_ID);
commands[1].setBuilderName("org.eclipse.wst.common.project.facet.core.builder");
desc.setBuildSpec(commands);
createProject(...) {
...
proj.create(description, ...);
IFolder srcFolder = proj.getFolder(new Path("src"));
srcFolder.create(false, true, new NullProgressMonitor());
org.eclipse.jdt.core.IJavaProject javaProject = org.eclipse.jdt.core.JavaCore.create(proj);
org.eclipse.jdt.core.IClasspathEntry src = JavaCore.newSourceEntry(srcFolder.getFullPath());
IClasspathEntry jre = JavaCore.newContainerEntry(new Path(org.eclipse.jdt.launching.JavaRuntime.JRE_CONTAINER), new IAccessRule[0], new IClasspathAttribute[] { JavaCore.newClasspathAttribute("owner.project.facets", "java")}, false);
IClasspathEntry[] entries = new IClasspathEntry[] { src, jre };
javaProject.setRawClasspath(entries, proj.getFullPath().append("bin"), new NullProgressMonitor());
Cheers, Max
Upvotes: 5
Reputation: 3057
Without changing your plugin you could add the Java facet to the new project. Have a look at the "Project Facets" setting, convert the project to faceted form if necessary and select Java as the facet to use. This should enable the settings you're looking for.
Upvotes: 1