forked from phoedos/pmd
first version
adding nature and incremental builder git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1546 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -0,0 +1,114 @@
|
||||
package net.sourceforge.pmd.eclipse.builder;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.sourceforge.pmd.eclipse.PMDConstants;
|
||||
import net.sourceforge.pmd.eclipse.PMDDeltaVisitor;
|
||||
import net.sourceforge.pmd.eclipse.PMDPlugin;
|
||||
import net.sourceforge.pmd.eclipse.PMDVisitor;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResourceDelta;
|
||||
import org.eclipse.core.resources.IResourceVisitor;
|
||||
import org.eclipse.core.resources.IncrementalProjectBuilder;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
/**
|
||||
* Implements an incremental builder for PMD. Use PMDVisitor and PMDDeltaVisitor
|
||||
* to process each file of the project.
|
||||
*
|
||||
* @author Philippe Herlin
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.1 2003/03/17 23:35:59 phherlin
|
||||
* first version
|
||||
* adding nature and incremental builder
|
||||
*
|
||||
*/
|
||||
public class PMDBuilder extends IncrementalProjectBuilder {
|
||||
public static final String PMD_BUILDER = "net.sourceforge.pmd.eclipse.pmdBuilder";
|
||||
|
||||
/**
|
||||
* @see org.eclipse.core.internal.events.InternalBuilder#build(int, Map, IProgressMonitor)
|
||||
*/
|
||||
protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
|
||||
IProject[] result = null;
|
||||
|
||||
if (kind == AUTO_BUILD) {
|
||||
result = buildAuto(args, monitor);
|
||||
} else if (kind == FULL_BUILD) {
|
||||
result = buildFull(args, monitor);
|
||||
} else if (kind == INCREMENTAL_BUILD) {
|
||||
result = buildIncremental(args, monitor);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatic build
|
||||
* @param args build parameters
|
||||
* @param monitor progress indicator
|
||||
* @return IProject[] related projects list
|
||||
* @throws CoreException
|
||||
*/
|
||||
private IProject[] buildAuto(Map args, IProgressMonitor monitor) throws CoreException {
|
||||
return buildIncremental(args, monitor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Full build
|
||||
* @param args build parameters
|
||||
* @param monitor progress indicator
|
||||
* @return IProject[] related projects list
|
||||
* @throws CoreException
|
||||
*/
|
||||
private IProject[] buildFull(Map args, IProgressMonitor monitor) throws CoreException {
|
||||
IProject currentProject = getProject();
|
||||
if (currentProject != null) {
|
||||
processProjectFiles(currentProject, monitor);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Incremental build
|
||||
* @param args build parameters
|
||||
* @param monitor progress indicator
|
||||
* @return IProject[] related projects list
|
||||
* @throws CoreException
|
||||
*/
|
||||
private IProject[] buildIncremental(Map args, IProgressMonitor monitor) throws CoreException {
|
||||
IProject result[] = null;
|
||||
|
||||
IProject currentProject = getProject();
|
||||
if (currentProject != null) {
|
||||
IResourceDelta resourceDelta = getDelta(currentProject);
|
||||
if (resourceDelta != null) {
|
||||
monitor.beginTask(PMDPlugin.getDefault().getMessage(PMDConstants.MSGKEY_PMD_PROCESSING), IProgressMonitor.UNKNOWN);
|
||||
PMDDeltaVisitor visitor = new PMDDeltaVisitor(monitor);
|
||||
resourceDelta.accept(visitor);
|
||||
monitor.done();
|
||||
} else {
|
||||
result = buildFull(args, monitor);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process all files in the project
|
||||
* @param project the project
|
||||
* @param monitor a progress indicator
|
||||
*/
|
||||
private void processProjectFiles(IProject project, IProgressMonitor monitor) throws CoreException {
|
||||
monitor.beginTask(PMDPlugin.getDefault().getMessage(PMDConstants.MSGKEY_PMD_PROCESSING), IProgressMonitor.UNKNOWN);
|
||||
IResourceVisitor visitor = new PMDVisitor(monitor);
|
||||
project.accept(visitor);
|
||||
monitor.done();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
package net.sourceforge.pmd.eclipse.builder;
|
||||
|
||||
import org.eclipse.core.resources.ICommand;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.resources.IProjectNature;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* A project nature for PMD. Add a PMDBuilder to a project
|
||||
*
|
||||
* @author Philippe Herlin
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.1 2003/03/17 23:35:59 phherlin
|
||||
* first version
|
||||
* adding nature and incremental builder
|
||||
*
|
||||
*/
|
||||
public class PMDNature implements IProjectNature {
|
||||
public static final String PMD_NATURE = "net.sourceforge.pmd.eclipse.pmdNature";
|
||||
private IProject project;
|
||||
|
||||
/**
|
||||
* @see org.eclipse.core.resources.IProjectNature#configure()
|
||||
*/
|
||||
public void configure() throws CoreException {
|
||||
IProjectDescription description = project.getDescription();
|
||||
ICommand[] commands = description.getBuildSpec();
|
||||
if (!pmdBuilderFound(commands)) {
|
||||
ICommand pmdBuilderCommand = description.newCommand();
|
||||
pmdBuilderCommand.setBuilderName(PMDBuilder.PMD_BUILDER);
|
||||
ICommand[] newCommands = new ICommand[commands.length + 1];
|
||||
System.arraycopy(commands, 0, newCommands, 0, commands.length);
|
||||
newCommands[commands.length] = pmdBuilderCommand;
|
||||
description.setBuildSpec(newCommands);
|
||||
project.setDescription(description, null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.core.resources.IProjectNature#deconfigure()
|
||||
*/
|
||||
public void deconfigure() throws CoreException {
|
||||
IProjectDescription description = project.getDescription();
|
||||
ICommand[] commands = description.getBuildSpec();
|
||||
if (pmdBuilderFound(commands)) {
|
||||
ICommand[] newCommands = new ICommand[commands.length - 1];
|
||||
for (int i = 0, j = 0; i < commands.length; i++) {
|
||||
if (!commands[i].getBuilderName().equals(PMDBuilder.PMD_BUILDER)) {
|
||||
newCommands[j++] = commands[i];
|
||||
}
|
||||
}
|
||||
description.setBuildSpec(newCommands);
|
||||
project.setDescription(description, null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.core.resources.IProjectNature#getProject()
|
||||
*/
|
||||
public IProject getProject() {
|
||||
return project;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.core.resources.IProjectNature#setProject(IProject)
|
||||
*/
|
||||
public void setProject(IProject project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if PMD builder is allready in command list
|
||||
* @param commands a command list
|
||||
*/
|
||||
private boolean pmdBuilderFound(ICommand[] commands) {
|
||||
boolean flFound = false;
|
||||
for (int i = 0; i < commands.length; i++) {
|
||||
if (commands[i].getBuilderName().equals(PMDBuilder.PMD_BUILDER)) {
|
||||
flFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return flFound;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user