我想要的是什么:我正在开发一个Eclipse编辑器插件。我希望能够构建一个由" New ... - >创建的项目。项目...... - >一般 - >项目&#34 ;.应该自动构建项目。
我有什么:我扩展了IncrementalProjectBuilder
类:
public class GenericProjectBuilder extends IncrementalProjectBuilder {
/**
* @see org.eclipse.core.resources.IncrementalProjectBuilder#build(int, java.util.Map, org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
protected IProject[] build(int arg0, Map<String, String> arg1, IProgressMonitor arg2) throws CoreException {
DIService.getInstance(ModelStateAssembler.class).scheduleFullRebuild();
return null;
}
}
我将此snippt添加到plugin.xml
:
<extension
id="GenericProjectBuilder"
name="GenericProjectBuilder"
point="org.eclipse.core.resources.builders">
<builder>
<run class="de.se_rwth.langeditor.global.GenericProjectBuilder"/>
</builder>
</extension>
如果我添加一个新项目,则会调用此方法以将项目与构建器关联:
public static IProject getProject(IStorage storage) {
if (storage instanceof IFile) {
final String BUILDER_ID = "de.se_rwth.langeditor.global.GenericProjectBuilder";
IProject project = ((IFile) storage).getProject();
IProjectDescription desc;
try {
desc = project.getDescription();
ICommand[] commands = desc.getBuildSpec();
boolean found = false;
for (int i = 0; i < commands.length; ++i) {
if (commands[i].getBuilderName().equals(BUILDER_ID)) {
found = true;
break;
}
}
if (!found) {
//add builder to project
ICommand command = desc.newCommand();
command.setBuilderName(BUILDER_ID);
ICommand[] newCommands = new ICommand[commands.length + 1];
// Add it before other builders.
System.arraycopy(commands, 0, newCommands, 1, commands.length);
newCommands[0] = command;
desc.setBuildSpec(newCommands);
project.setDescription(desc, null);
}
}
catch (CoreException e) {
e.printStackTrace();
}
return ((IFile) storage).getProject();
}
else if (storage instanceof IJarEntryResource) {
return ((IJarEntryResource) storage).getPackageFragmentRoot().getJavaProject().getProject();
}
else if (storage instanceof FileStorage) {
throw new IllegalArgumentException("Unknown IStorage implementation - Please use: Import -> General -> Filesystem, to import file in workspace");
}
else {
throw new IllegalArgumentException("Unknown IStorage implementation");
}
}
但永远不会调用build
方法。我错过了什么?