*每次从svn或clean项目时,都会在刷新工作区后执行项目构件,而在项目很多时,就浪费很多时间.
想到的解决的方法之一,是去除项目的构建器.
*构建器是定义在".project"中,如下是java项目的构建器定义
builder定义<?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>cb</name> <comment></comment> <projects> </projects> <buildSpec> <buildCommand> <name>org.eclipse.jdt.core.javabuilder</name> <arguments> </arguments> </buildCommand> </buildSpec> <natures> <nature>cn.agree.ab.ide.abideProject</nature> <nature>org.eclipse.jdt.core.javanature</nature> </natures> </projectDescription>
*添加和删除构建器
AddOrRemove Builder/** * Copyright(C) 2011 Agree Tech, All rights reserved. * * Created on 2011-4-14 by dzh */ package cn.com.agree.ide.navigator.action; import org.eclipse.core.resources.ICommand; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IViewActionDelegate; import org.eclipse.ui.IViewPart; import org.eclipse.ui.PlatformUI; public class ToggleBuilderAction implements IViewActionDelegate { private static final String NAME_JAVABUILDER ="org.eclipse.jdt.core.javabuilder"; //$NON-NLS-1$ private boolean isExist; private IProject project; @Override public void init(IViewPart view) { } @Override public void run(IAction action) { Shell shell =PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); boolean code =MessageDialog.openConfirm(shell, Messages.getString("ToggleBuilderAction.JavaBuilder_Configuration"), action.getText()); //$NON-NLS-1$ if(!code) return; try { if(isExist){ deconfigure(); }else{ configure(); } } catch (CoreException e) { e.printStackTrace(); } } public void configure() throws CoreException { IProjectDescription desc = project.getDescription(); ICommand[] commands = desc.getBuildSpec(); for (int i = 0; i < commands.length; ++i) { if (commands[i].getBuilderName().equals(NAME_JAVABUILDER)) { return; } } ICommand[] newCommands = new ICommand[commands.length + 1]; System.arraycopy(commands, 0, newCommands, 0, commands.length); ICommand command = desc.newCommand(); command.setBuilderName(NAME_JAVABUILDER); newCommands[newCommands.length - 1] = command; desc.setBuildSpec(newCommands); project.setDescription(desc, null); } public void deconfigure() throws CoreException { IProjectDescription description = project.getDescription(); ICommand[] commands = description.getBuildSpec(); for (int i = 0; i < commands.length; ++i) { if (commands[i].getBuilderName().equals(NAME_JAVABUILDER)) { ICommand[] newCommands = new ICommand[commands.length - 1]; System.arraycopy(commands, 0, newCommands, 0, i); System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1); description.setBuildSpec(newCommands); project.setDescription(description, null); return; } } } @Override public void selectionChanged(IAction action, ISelection selection) { action.setEnabled(false); if(!selection.isEmpty()){ if(selection instanceof IStructuredSelection){ Object obj =((IStructuredSelection)selection).getFirstElement(); if(obj instanceof IProject){ action.setEnabled(true); changeAction((IProject) obj,action); } } } } /** * * @param project */ private void changeAction(IProject project,IAction action){ this.project =project; try { IProjectDescription desc =project.getDescription(); ICommand[] commands =desc.getBuildSpec(); for(ICommand cmd:commands){ if(cmd.getBuilderName().equals(NAME_JAVABUILDER)){ isExist =true; action.setText(Messages.getString("ToggleBuilderAction.remove_javabuilder")); //$NON-NLS-1$ return; } } action.setText(Messages.getString("ToggleBuilderAction.add_javabuilder")); //$NON-NLS-1$ isExist =false; } catch (CoreException e) { e.printStackTrace(); } } }