forked from phoedos/pmd
Continuing the refactoring experiment
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@3048 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -35,6 +35,9 @@
|
||||
*/
|
||||
package net.sourceforge.pmd.eclipse.cmd;
|
||||
|
||||
import net.sourceforge.pmd.eclipse.model.ModelFactory;
|
||||
import net.sourceforge.pmd.eclipse.model.ProjectPropertiesModel;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IncrementalProjectBuilder;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
@ -48,6 +51,9 @@ import org.eclipse.core.runtime.Status;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.2 2004/11/28 20:31:37 phherlin
|
||||
* Continuing the refactoring experiment
|
||||
*
|
||||
* Revision 1.1 2004/11/21 21:39:45 phherlin
|
||||
* Applying Command and CommandProcessor patterns
|
||||
*
|
||||
@ -73,6 +79,9 @@ public class BuildProjectCommand extends JobCommand {
|
||||
protected IStatus execute() throws CommandException {
|
||||
try {
|
||||
this.project.build(IncrementalProjectBuilder.FULL_BUILD, this.getMonitor());
|
||||
|
||||
ProjectPropertiesModel model = ModelFactory.getFactory().getProperiesModelForProject(this.project);
|
||||
model.setNeedRebuild(false);
|
||||
} catch (CoreException e) {
|
||||
throw new CommandException(e);
|
||||
}
|
||||
|
@ -1,143 +0,0 @@
|
||||
/*
|
||||
* Created on 20 nov. 2004
|
||||
*
|
||||
* Copyright (c) 2004, PMD for Eclipse Development Team
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The end-user documentation included with the redistribution, if
|
||||
* any, must include the following acknowledgement:
|
||||
* "This product includes software developed in part by support from
|
||||
* the Defense Advanced Research Project Agency (DARPA)"
|
||||
* * Neither the name of "PMD for Eclipse Development Team" nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.sourceforge.pmd.eclipse.cmd;
|
||||
|
||||
import net.sourceforge.pmd.RuleSet;
|
||||
import net.sourceforge.pmd.eclipse.PMDPlugin;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.ui.IWorkingSet;
|
||||
|
||||
/**
|
||||
* This command retrieves the PMD specific properties of a particular
|
||||
* workbench project. This is a composite basic command.
|
||||
*
|
||||
* @author Philippe Herlin
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.1 2004/11/21 21:39:45 phherlin
|
||||
* Applying Command and CommandProcessor patterns
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class QueryProjectPropertiesCmd extends DefaultCommand {
|
||||
private IProject project;
|
||||
private boolean pmdEnabled;
|
||||
private IWorkingSet projectWorkingSet;
|
||||
private RuleSet projectRuleSet;
|
||||
private boolean ruleSetStoredInProject;
|
||||
|
||||
/**
|
||||
* Default constructor. Initializes command attributes
|
||||
*
|
||||
*/
|
||||
public QueryProjectPropertiesCmd() {
|
||||
setReadOnly(true);
|
||||
setOutputData(true);
|
||||
setName("QueryProjectProperties");
|
||||
setDescription("Query the PMD specific properties of a particular workbench project.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.eclipse.cmd.Command#performExecute()
|
||||
*/
|
||||
protected void execute() throws CommandException {
|
||||
if (this.project == null) throw new MandatoryInputParameterMissingException("project");
|
||||
|
||||
QueryPmdEnabledPropertyCmd queryPmdEnabledCmd = new QueryPmdEnabledPropertyCmd();
|
||||
queryPmdEnabledCmd.setProject(this.project);
|
||||
queryPmdEnabledCmd.performExecute();
|
||||
this.pmdEnabled = queryPmdEnabledCmd.isPmdEnabled();
|
||||
|
||||
QueryProjectWorkingSetCmd queryProjectWorkingSetCmd = new QueryProjectWorkingSetCmd();
|
||||
queryProjectWorkingSetCmd.setProject(this.project);
|
||||
queryProjectWorkingSetCmd.performExecute();
|
||||
this.projectWorkingSet = queryProjectWorkingSetCmd.getProjectWorkingSet();
|
||||
|
||||
QueryProjectRuleSetCmd queryProjectRuleSetCmd = new QueryProjectRuleSetCmd();
|
||||
queryProjectRuleSetCmd.setProject(this.project);
|
||||
queryProjectRuleSetCmd.setFromProperties(true);
|
||||
queryProjectRuleSetCmd.performExecute();
|
||||
this.projectRuleSet = queryProjectRuleSetCmd.getProjectRuleSet();
|
||||
if (this.projectRuleSet == null) {
|
||||
this.projectRuleSet = PMDPlugin.getDefault().getRuleSet();
|
||||
}
|
||||
|
||||
QueryRuleSetStoredInProjectPropertyCmd queryRuleSetStoredInProjectCmd = new QueryRuleSetStoredInProjectPropertyCmd();
|
||||
queryRuleSetStoredInProjectCmd.setProject(this.project);
|
||||
queryRuleSetStoredInProjectCmd.performExecute();
|
||||
this.ruleSetStoredInProject = queryRuleSetStoredInProjectCmd.isRuleSetStoredInProject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Mandatory input parameter.
|
||||
* Specify the project to query.
|
||||
* @param project
|
||||
*/
|
||||
public void setProject(IProject project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether PMD is activated for that project
|
||||
*/
|
||||
public boolean isPMDEnabled() {
|
||||
return this.pmdEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the project working set
|
||||
*/
|
||||
public IWorkingSet getProjectWorkingSet() {
|
||||
return this.projectWorkingSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the project rule set
|
||||
*/
|
||||
public RuleSet getProjectRuleSet() {
|
||||
return this.projectRuleSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether the project rule set is stored inside the project
|
||||
* instead of the plugin properties store
|
||||
*/
|
||||
public boolean isRuleSetStoredInProject() {
|
||||
return this.ruleSetStoredInProject;
|
||||
}
|
||||
}
|
@ -51,6 +51,9 @@ import org.eclipse.core.runtime.CoreException;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.2 2004/11/28 20:31:37 phherlin
|
||||
* Continuing the refactoring experiment
|
||||
*
|
||||
* Revision 1.1 2004/11/21 21:39:45 phherlin
|
||||
* Applying Command and CommandProcessor patterns
|
||||
*
|
||||
@ -104,7 +107,7 @@ public class UpdatePmdEnabledPropertyCmd extends DefaultCommand {
|
||||
* @return Returns the needRebuild.
|
||||
*/
|
||||
public boolean isNeedRebuild() {
|
||||
return needRebuild;
|
||||
return this.needRebuild;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,6 +36,9 @@
|
||||
package net.sourceforge.pmd.eclipse.cmd;
|
||||
|
||||
import net.sourceforge.pmd.RuleSet;
|
||||
import net.sourceforge.pmd.eclipse.model.ModelException;
|
||||
import net.sourceforge.pmd.eclipse.model.ModelFactory;
|
||||
import net.sourceforge.pmd.eclipse.model.ProjectPropertiesModel;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
@ -49,6 +52,9 @@ import org.eclipse.ui.IWorkingSet;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.2 2004/11/28 20:31:37 phherlin
|
||||
* Continuing the refactoring experiment
|
||||
*
|
||||
* Revision 1.1 2004/11/21 21:39:45 phherlin
|
||||
* Applying Command and CommandProcessor patterns
|
||||
*
|
||||
@ -61,7 +67,7 @@ public class UpdateProjectPropertiesCmd extends JobCommand {
|
||||
private RuleSet projectRuleSet;
|
||||
private boolean ruleSetStoredInProject;
|
||||
private boolean needRebuild;
|
||||
private boolean ruleSetFileNotFound;
|
||||
private boolean ruleSetFileExists;
|
||||
|
||||
/**
|
||||
* Default constructor. Initializes command attributes
|
||||
@ -83,51 +89,30 @@ public class UpdateProjectPropertiesCmd extends JobCommand {
|
||||
if (this.projectRuleSet == null) throw new MandatoryInputParameterMissingException("projectRuleSet");
|
||||
|
||||
this.getMonitor().beginTask("Updating project properties", 4);
|
||||
UpdatePmdEnabledPropertyCmd pmdEnabledCmd = new UpdatePmdEnabledPropertyCmd();
|
||||
if (!this.getMonitor().isCanceled()) {
|
||||
this.getMonitor().subTask("Updating PMD enabling state");
|
||||
pmdEnabledCmd.setProject(this.project);
|
||||
pmdEnabledCmd.setPmdEnabled(this.pmdEnabled);
|
||||
pmdEnabledCmd.execute();
|
||||
this.getMonitor().worked(1);
|
||||
}
|
||||
|
||||
UpdateProjectRuleSetCmd projectRuleSetCmd = new UpdateProjectRuleSetCmd();
|
||||
if (!this.getMonitor().isCanceled()) {
|
||||
this.getMonitor().subTask("Updating project rule set");
|
||||
projectRuleSetCmd.setProject(this.project);
|
||||
projectRuleSetCmd.setProjectRuleSet(this.projectRuleSet);
|
||||
projectRuleSetCmd.execute();
|
||||
this.getMonitor().worked(1);
|
||||
}
|
||||
|
||||
UpdateProjectWorkingSetCmd projectWorkingSetCmd = new UpdateProjectWorkingSetCmd();
|
||||
if (!this.getMonitor().isCanceled()) {
|
||||
this.getMonitor().subTask("Updating project working set");
|
||||
projectWorkingSetCmd.setProject(this.project);
|
||||
projectWorkingSetCmd.setProjectWorkingSet(this.projectWorkingSet);
|
||||
projectWorkingSetCmd.execute();
|
||||
this.getMonitor().worked(1);
|
||||
}
|
||||
|
||||
UpdateRuleSetStoredInProjectPropertyCmd ruleSetStoredInProjectCmd = new UpdateRuleSetStoredInProjectPropertyCmd();
|
||||
if (!this.getMonitor().isCanceled()) {
|
||||
this.getMonitor().subTask("Updating rule set location state");
|
||||
ruleSetStoredInProjectCmd.setProject(this.project);
|
||||
ruleSetStoredInProjectCmd.setRuleSetStoredInProject(this.ruleSetStoredInProject);
|
||||
ruleSetStoredInProjectCmd.execute();
|
||||
this.ruleSetFileNotFound = ruleSetStoredInProjectCmd.isRuleSetFileNotFound();
|
||||
this.getMonitor().worked(1);
|
||||
}
|
||||
|
||||
if (!this.getMonitor().isCanceled()) {
|
||||
this.needRebuild = ruleSetStoredInProjectCmd.isNeedRebuild();
|
||||
if (this.pmdEnabled) {
|
||||
if (!this.ruleSetStoredInProject) {
|
||||
this.needRebuild |= projectRuleSetCmd.isNeedRebuild();
|
||||
}
|
||||
this.needRebuild |= pmdEnabledCmd.isNeedRebuild();
|
||||
this.needRebuild |= projectWorkingSetCmd.isNeedRebuild();
|
||||
try {
|
||||
ProjectPropertiesModel projectPropertyModel = ModelFactory.getFactory().getProperiesModelForProject(this.project);
|
||||
|
||||
this.getMonitor().subTask("Updating PMD enabling state");
|
||||
projectPropertyModel.setPmdEnabled(this.pmdEnabled);
|
||||
this.getMonitor().worked(1);
|
||||
|
||||
this.getMonitor().subTask("Updating project rule set");
|
||||
projectPropertyModel.setProjectRuleSet(this.projectRuleSet);
|
||||
this.getMonitor().worked(1);
|
||||
|
||||
this.getMonitor().subTask("Updating project working set");
|
||||
projectPropertyModel.setProjectWorkingSet(this.projectWorkingSet);
|
||||
this.getMonitor().worked(1);
|
||||
|
||||
this.getMonitor().subTask("Updating rule set location state");
|
||||
projectPropertyModel.setRuleSetStoredInProject(this.ruleSetStoredInProject);
|
||||
this.getMonitor().worked(1);
|
||||
|
||||
this.needRebuild = projectPropertyModel.isNeedRebuild();
|
||||
this.ruleSetFileExists = !projectPropertyModel.isRuleSetFileExist();
|
||||
} catch (ModelException e) {
|
||||
throw new CommandException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,13 +159,13 @@ public class UpdateProjectPropertiesCmd extends JobCommand {
|
||||
* @return Returns the needRebuild.
|
||||
*/
|
||||
public boolean isNeedRebuild() {
|
||||
return needRebuild;
|
||||
return this.needRebuild;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the ruleSetFileNotFound.
|
||||
* @return Returns the ruleSetFileExists.
|
||||
*/
|
||||
public boolean isRuleSetFileNotFound() {
|
||||
return ruleSetFileNotFound;
|
||||
public boolean isRuleSetFileExists() {
|
||||
return this.ruleSetFileExists;
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,9 @@ import org.eclipse.core.runtime.CoreException;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.2 2004/11/28 20:31:37 phherlin
|
||||
* Continuing the refactoring experiment
|
||||
*
|
||||
* Revision 1.1 2004/11/21 21:39:45 phherlin
|
||||
* Applying Command and CommandProcessor patterns
|
||||
*
|
||||
@ -55,7 +58,7 @@ import org.eclipse.core.runtime.CoreException;
|
||||
public class UpdateRuleSetStoredInProjectPropertyCmd extends DefaultCommand {
|
||||
private IProject project;
|
||||
private boolean ruleSetStoredInProject;
|
||||
private boolean ruleSetFileNotFound;
|
||||
private boolean ruleSetFileExists;
|
||||
private boolean needRebuild;
|
||||
|
||||
/**
|
||||
@ -90,7 +93,7 @@ public class UpdateRuleSetStoredInProjectPropertyCmd extends DefaultCommand {
|
||||
}
|
||||
|
||||
IFile ruleSetFile = this.project.getFile(".ruleset");
|
||||
this.ruleSetFileNotFound = !ruleSetFile.exists();
|
||||
this.ruleSetFileExists = ruleSetFile.exists();
|
||||
|
||||
} catch (CoreException e) {
|
||||
throw new CommandException(getMessage(MSGKEY_ERROR_CORE_EXCEPTION), e);
|
||||
@ -101,10 +104,10 @@ public class UpdateRuleSetStoredInProjectPropertyCmd extends DefaultCommand {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the ruleSetFileNotFound.
|
||||
* @return Returns the ruleSetFileExists.
|
||||
*/
|
||||
public boolean isRuleSetFileNotFound() {
|
||||
return ruleSetFileNotFound;
|
||||
public boolean isRuleSetFileExists() {
|
||||
return ruleSetFileExists;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Created on 24 nov. 2004
|
||||
*
|
||||
* Copyright (c) 2004, PMD for Eclipse Development Team
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The end-user documentation included with the redistribution, if
|
||||
* any, must include the following acknowledgement:
|
||||
* "This product includes software developed in part by support from
|
||||
* the Defense Advanced Research Project Agency (DARPA)"
|
||||
* * Neither the name of "PMD for Eclipse Development Team" nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.sourceforge.pmd.eclipse.model;
|
||||
|
||||
/**
|
||||
* This is the default exception thrown by public model method
|
||||
*
|
||||
* @author Philippe Herlin
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.1 2004/11/28 20:31:38 phherlin
|
||||
* Continuing the refactoring experiment
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ModelException extends Exception {
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public ModelException() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message a message for the exception
|
||||
*/
|
||||
public ModelException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message a message for the exception
|
||||
* @param cause a root cause
|
||||
*/
|
||||
public ModelException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cause a root cause
|
||||
*/
|
||||
public ModelException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Created on 24 nov. 2004
|
||||
*
|
||||
* Copyright (c) 2004, PMD for Eclipse Development Team
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The end-user documentation included with the redistribution, if
|
||||
* any, must include the following acknowledgement:
|
||||
* "This product includes software developed in part by support from
|
||||
* the Defense Advanced Research Project Agency (DARPA)"
|
||||
* * Neither the name of "PMD for Eclipse Development Team" nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.sourceforge.pmd.eclipse.model;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
||||
/**
|
||||
* This class holds methods factory for plugin models
|
||||
*
|
||||
* @author Philippe Herlin
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.1 2004/11/28 20:31:38 phherlin
|
||||
* Continuing the refactoring experiment
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ModelFactory {
|
||||
private static final ModelFactory modelFactory = new ModelFactory();
|
||||
private Map projectPropertiesModels = new HashMap();
|
||||
|
||||
/**
|
||||
* Default private constructor. The ModelFactory is a singleton
|
||||
*/
|
||||
public ModelFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the default implementation
|
||||
*/
|
||||
public static ModelFactory getFactory() {
|
||||
return modelFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method factory for ProjectPropertiesModels
|
||||
* @param project the project for which properties are requested
|
||||
* @return The PMD related properties for that project
|
||||
*/
|
||||
public synchronized ProjectPropertiesModel getProperiesModelForProject(IProject project) {
|
||||
ProjectPropertiesModel model = (ProjectPropertiesModel) this.projectPropertiesModels.get(project.getName());
|
||||
if (model == null) {
|
||||
model = new ProjectPropertiesModelImpl(project);
|
||||
this.projectPropertiesModels.put(project.getName(), model);
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Created on 24 nov. 2004
|
||||
*
|
||||
* Copyright (c) 2004, PMD for Eclipse Development Team
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The end-user documentation included with the redistribution, if
|
||||
* any, must include the following acknowledgement:
|
||||
* "This product includes software developed in part by support from
|
||||
* the Defense Advanced Research Project Agency (DARPA)"
|
||||
* * Neither the name of "PMD for Eclipse Development Team" nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.sourceforge.pmd.eclipse.model;
|
||||
|
||||
import net.sourceforge.pmd.RuleSet;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.ui.IWorkingSet;
|
||||
|
||||
/**
|
||||
* This interface specifies what is the model for the PMD related project
|
||||
* properties
|
||||
*
|
||||
* @author Philippe Herlin
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.1 2004/11/28 20:31:38 phherlin
|
||||
* Continuing the refactoring experiment
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface ProjectPropertiesModel {
|
||||
/**
|
||||
* @return the related project
|
||||
*/
|
||||
IProject getProject();
|
||||
|
||||
/**
|
||||
* @return Returns whether PMD is enabled for that project.
|
||||
*/
|
||||
boolean isPmdEnabled() throws ModelException;
|
||||
|
||||
/**
|
||||
* @param pmdEnabled Enable or disable PMD for that project.
|
||||
*/
|
||||
void setPmdEnabled(boolean pmdEnabled) throws ModelException;
|
||||
|
||||
/**
|
||||
* @return Returns the project Rule Set.
|
||||
*/
|
||||
RuleSet getProjectRuleSet() throws ModelException;
|
||||
|
||||
/**
|
||||
* @param projectRuleSet The project Rule Set to set.
|
||||
*/
|
||||
void setProjectRuleSet(RuleSet projectRuleSet) throws ModelException;
|
||||
|
||||
/**
|
||||
* @return Returns the whether the project rule set is stored as a file
|
||||
* inside the project.
|
||||
*/
|
||||
boolean isRuleSetStoredInProject() throws ModelException;
|
||||
|
||||
/**
|
||||
* @param ruleSetStoredInProject Specify whether the rule set is stored in
|
||||
* the project.
|
||||
*/
|
||||
void setRuleSetStoredInProject(boolean ruleSetStoredInProject) throws ModelException;
|
||||
|
||||
/**
|
||||
* @return Returns the project Working Set.
|
||||
*/
|
||||
IWorkingSet getProjectWorkingSet() throws ModelException;
|
||||
|
||||
/**
|
||||
* @param projectWorkingSet The project Working Set to set.
|
||||
*/
|
||||
void setProjectWorkingSet(IWorkingSet projectWorkingSet) throws ModelException;
|
||||
|
||||
/**
|
||||
* @return whether the project needs to be rebuilt.
|
||||
*/
|
||||
boolean isNeedRebuild();
|
||||
|
||||
/**
|
||||
* Let force the rebuild state of a project.
|
||||
*/
|
||||
void setNeedRebuild(boolean needRebuild);
|
||||
|
||||
/**
|
||||
* @return in case the rule set is stored inside the project, whether
|
||||
* the ruleset file exists.
|
||||
*/
|
||||
boolean isRuleSetFileExist();
|
||||
}
|
@ -0,0 +1,271 @@
|
||||
/*
|
||||
* Created on 24 nov. 2004
|
||||
*
|
||||
* Copyright (c) 2004, PMD for Eclipse Development Team
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The end-user documentation included with the redistribution, if
|
||||
* any, must include the following acknowledgement:
|
||||
* "This product includes software developed in part by support from
|
||||
* the Defense Advanced Research Project Agency (DARPA)"
|
||||
* * Neither the name of "PMD for Eclipse Development Team" nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.sourceforge.pmd.eclipse.model;
|
||||
|
||||
import net.sourceforge.pmd.RuleSet;
|
||||
import net.sourceforge.pmd.eclipse.cmd.CommandException;
|
||||
import net.sourceforge.pmd.eclipse.cmd.QueryPmdEnabledPropertyCmd;
|
||||
import net.sourceforge.pmd.eclipse.cmd.QueryProjectRuleSetCmd;
|
||||
import net.sourceforge.pmd.eclipse.cmd.QueryProjectWorkingSetCmd;
|
||||
import net.sourceforge.pmd.eclipse.cmd.QueryRuleSetStoredInProjectPropertyCmd;
|
||||
import net.sourceforge.pmd.eclipse.cmd.UpdatePmdEnabledPropertyCmd;
|
||||
import net.sourceforge.pmd.eclipse.cmd.UpdateProjectRuleSetCmd;
|
||||
import net.sourceforge.pmd.eclipse.cmd.UpdateProjectWorkingSetCmd;
|
||||
import net.sourceforge.pmd.eclipse.cmd.UpdateRuleSetStoredInProjectPropertyCmd;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.ui.IWorkingSet;
|
||||
|
||||
/**
|
||||
* Default implementation of a ProjectPropertiesModel
|
||||
*
|
||||
* @author Philippe Herlin
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.1 2004/11/28 20:31:38 phherlin
|
||||
* Continuing the refactoring experiment
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ProjectPropertiesModelImpl implements ProjectPropertiesModel {
|
||||
private static final Log log = LogFactory.getLog("net.sourceforge.pmd.eclipse.model.ProjectPropertiesModelImpl");
|
||||
private IProject project;
|
||||
private boolean needRebuild;
|
||||
private boolean ruleSetFileExist;
|
||||
|
||||
private boolean pmdEnabled;
|
||||
private boolean pmdEnabledInit;
|
||||
private boolean ruleSetStoredInProject;
|
||||
private boolean ruleSetStoredInProjectInit;
|
||||
private RuleSet projectRuleSet;
|
||||
private boolean projectRuleSetInit;
|
||||
private IWorkingSet projectWorkingSet;
|
||||
private boolean projectWorkingSetInit;
|
||||
|
||||
/**
|
||||
* The default constructor takes a project as an argument
|
||||
*/
|
||||
public ProjectPropertiesModelImpl(IProject project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.eclipse.model.ProjectPropertiesModel#getProject()
|
||||
*/
|
||||
public IProject getProject() {
|
||||
return this.project;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.eclipse.model.ProjectPropertiesModel#isPmdEnabled()
|
||||
*/
|
||||
public boolean isPmdEnabled() throws ModelException {
|
||||
if (!this.pmdEnabledInit) {
|
||||
try {
|
||||
QueryPmdEnabledPropertyCmd cmd = new QueryPmdEnabledPropertyCmd();
|
||||
cmd.setProject(this.project);
|
||||
cmd.performExecute();
|
||||
this.pmdEnabled = cmd.isPmdEnabled();
|
||||
this.pmdEnabledInit = true;
|
||||
} catch (CommandException e) {
|
||||
throw new ModelException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
return this.pmdEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.eclipse.model.ProjectPropertiesModel#setPmdEnabled(boolean)
|
||||
*/
|
||||
public void setPmdEnabled(boolean pmdEnabled) throws ModelException {
|
||||
log.info("Enable PMD for project " + this.project.getName() + " : " + pmdEnabled);
|
||||
try {
|
||||
UpdatePmdEnabledPropertyCmd cmd = new UpdatePmdEnabledPropertyCmd();
|
||||
cmd.setPmdEnabled(pmdEnabled);
|
||||
cmd.setProject(this.project);
|
||||
cmd.performExecute();
|
||||
this.pmdEnabled = pmdEnabled;
|
||||
this.pmdEnabledInit = true;
|
||||
this.needRebuild |= cmd.isNeedRebuild();
|
||||
log.debug(" Project need rebuild : " + this.needRebuild);
|
||||
} catch (CommandException e) {
|
||||
throw new ModelException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.eclipse.model.ProjectPropertiesModel#getProjectRuleSet()
|
||||
*/
|
||||
public RuleSet getProjectRuleSet() throws ModelException {
|
||||
if (!this.projectRuleSetInit) {
|
||||
try {
|
||||
QueryProjectRuleSetCmd cmd = new QueryProjectRuleSetCmd();
|
||||
cmd.setProject(this.project);
|
||||
cmd.performExecute();
|
||||
this.projectRuleSet = cmd.getProjectRuleSet();
|
||||
this.projectRuleSetInit = true;
|
||||
} catch (CommandException e) {
|
||||
throw new ModelException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
return this.projectRuleSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.eclipse.model.ProjectPropertiesModel#setProjectRuleSet(net.sourceforge.pmd.RuleSet)
|
||||
*/
|
||||
public void setProjectRuleSet(RuleSet projectRuleSet) throws ModelException {
|
||||
log.info("Set rule set for project " + this.project.getName());
|
||||
try {
|
||||
UpdateProjectRuleSetCmd cmd = new UpdateProjectRuleSetCmd();
|
||||
cmd.setProject(this.project);
|
||||
cmd.setProjectRuleSet(projectRuleSet);
|
||||
cmd.performExecute();
|
||||
this.projectRuleSet = projectRuleSet;
|
||||
this.projectRuleSetInit = true;
|
||||
this.needRebuild |= cmd.isNeedRebuild();
|
||||
log.debug(" Project need rebuild : " + this.needRebuild);
|
||||
} catch (CommandException e) {
|
||||
throw new ModelException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.eclipse.model.ProjectPropertiesModel#isRuleSetStoredInProject()
|
||||
*/
|
||||
public boolean isRuleSetStoredInProject() throws ModelException {
|
||||
if (!this.ruleSetStoredInProjectInit) {
|
||||
try {
|
||||
QueryRuleSetStoredInProjectPropertyCmd cmd = new QueryRuleSetStoredInProjectPropertyCmd();
|
||||
cmd.setProject(this.project);
|
||||
cmd.performExecute();
|
||||
this.ruleSetStoredInProject = cmd.isRuleSetStoredInProject();
|
||||
this.ruleSetStoredInProjectInit = true;
|
||||
} catch (CommandException e) {
|
||||
throw new ModelException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
return this.ruleSetStoredInProject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.eclipse.model.ProjectPropertiesModel#setRuleSetStoredInProject(boolean)
|
||||
*/
|
||||
public void setRuleSetStoredInProject(boolean ruleSetStoredInProject) throws ModelException {
|
||||
log.info("Set rule set stored in project for project " + this.project.getName() + " : " + ruleSetStoredInProject);
|
||||
try {
|
||||
UpdateRuleSetStoredInProjectPropertyCmd cmd = new UpdateRuleSetStoredInProjectPropertyCmd();
|
||||
cmd.setProject(this.project);
|
||||
cmd.setRuleSetStoredInProject(ruleSetStoredInProject);
|
||||
cmd.performExecute();
|
||||
this.ruleSetStoredInProject = ruleSetStoredInProject;
|
||||
this.ruleSetStoredInProjectInit = true;
|
||||
this.needRebuild |= cmd.isNeedRebuild();
|
||||
this.ruleSetFileExist = cmd.isRuleSetFileExists();
|
||||
log.debug(" Project need rebuild : " + this.needRebuild);
|
||||
} catch (CommandException e) {
|
||||
throw new ModelException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.eclipse.model.ProjectPropertiesModel#getProjectWorkingSet()
|
||||
*/
|
||||
public IWorkingSet getProjectWorkingSet() throws ModelException {
|
||||
if (!this.projectWorkingSetInit) {
|
||||
try {
|
||||
QueryProjectWorkingSetCmd cmd = new QueryProjectWorkingSetCmd();
|
||||
cmd.setProject(this.project);
|
||||
cmd.performExecute();
|
||||
this.projectWorkingSet = cmd.getProjectWorkingSet();
|
||||
this.projectWorkingSetInit = true;
|
||||
} catch (CommandException e) {
|
||||
throw new ModelException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
return this.projectWorkingSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.eclipse.model.ProjectPropertiesModel#setProjectWorkingSet(org.eclipse.ui.IWorkingSet)
|
||||
*/
|
||||
public void setProjectWorkingSet(IWorkingSet projectWorkingSet) throws ModelException {
|
||||
log.info("Set working set for project " + this.project.getName() + " : " + (projectWorkingSet == null ? "none" : projectWorkingSet.getName()));
|
||||
try {
|
||||
UpdateProjectWorkingSetCmd cmd = new UpdateProjectWorkingSetCmd();
|
||||
cmd.setProject(this.project);
|
||||
cmd.setProjectWorkingSet(projectWorkingSet);
|
||||
cmd.performExecute();
|
||||
this.projectWorkingSet = projectWorkingSet;
|
||||
this.projectWorkingSetInit = true;
|
||||
this.needRebuild |= cmd.isNeedRebuild();
|
||||
log.debug(" Project need rebuild : " + this.needRebuild);
|
||||
} catch (CommandException e) {
|
||||
throw new ModelException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.eclipse.model.ProjectPropertiesModel#isNeedRebuild()
|
||||
*/
|
||||
public boolean isNeedRebuild() {
|
||||
log.debug("Query if project " + this.project.getName() + " need rebuild : " + (this.pmdEnabled && this.needRebuild));
|
||||
log.debug(" PMD Enabled = " + this.pmdEnabled);
|
||||
log.debug(" Project need rebuild = " + this.needRebuild);
|
||||
return this.pmdEnabled && this.needRebuild;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.eclipse.model.ProjectPropertiesModel#setNeedRebuild()
|
||||
*/
|
||||
public void setNeedRebuild(boolean needRebuild) {
|
||||
this.needRebuild = needRebuild;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.sourceforge.pmd.eclipse.model.ProjectPropertiesModel#isRuleSetFileExist()
|
||||
*/
|
||||
public boolean isRuleSetFileExist() {
|
||||
return this.ruleSetFileExist;
|
||||
}
|
||||
}
|
@ -75,6 +75,9 @@ import org.eclipse.ui.dialogs.PropertyPage;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.15 2004/11/28 20:31:38 phherlin
|
||||
* Continuing the refactoring experiment
|
||||
*
|
||||
* Revision 1.14 2004/11/21 21:38:43 phherlin
|
||||
* Continue applying MVC.
|
||||
*
|
||||
@ -132,7 +135,7 @@ import org.eclipse.ui.dialogs.PropertyPage;
|
||||
public class PMDPropertyPage extends PropertyPage implements PMDConstants {
|
||||
private static final Log log = LogFactory.getLog("net.sourceforge.pmd.eclipse.properties.PMDPropertyPage");
|
||||
private PMDPropertyPageController controller;
|
||||
private PMDPropertyPageModel model;
|
||||
private PMDPropertyPageBean model;
|
||||
private IProject project;
|
||||
private Button enablePMDButton;
|
||||
protected TableViewer availableRulesTableViewer;
|
||||
@ -156,7 +159,7 @@ public class PMDPropertyPage extends PropertyPage implements PMDConstants {
|
||||
log.info("PMD properties editing requested");
|
||||
this.project = (IProject) this.getElement().getAdapter(IProject.class);
|
||||
this.controller.setProject(this.project);
|
||||
this.model = controller.getPropertyPageModel();
|
||||
this.model = controller.getPropertyPageBean();
|
||||
|
||||
Composite composite = null;
|
||||
noDefaultAndApplyButton();
|
||||
|
@ -47,12 +47,15 @@ import org.eclipse.ui.IWorkingSet;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.1 2004/11/28 20:31:38 phherlin
|
||||
* Continuing the refactoring experiment
|
||||
*
|
||||
* Revision 1.1 2004/11/21 21:38:42 phherlin
|
||||
* Continue applying MVC.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class PMDPropertyPageModel {
|
||||
public class PMDPropertyPageBean {
|
||||
private boolean pmdEnabled;
|
||||
private IWorkingSet projectWorkingSet;
|
||||
private RuleSet projectRuleSet;
|
@ -47,8 +47,10 @@ import net.sourceforge.pmd.eclipse.RuleSetWriter;
|
||||
import net.sourceforge.pmd.eclipse.WriterAbstractFactory;
|
||||
import net.sourceforge.pmd.eclipse.cmd.BuildProjectCommand;
|
||||
import net.sourceforge.pmd.eclipse.cmd.CommandException;
|
||||
import net.sourceforge.pmd.eclipse.cmd.QueryProjectPropertiesCmd;
|
||||
import net.sourceforge.pmd.eclipse.cmd.UpdateProjectPropertiesCmd;
|
||||
import net.sourceforge.pmd.eclipse.model.ModelException;
|
||||
import net.sourceforge.pmd.eclipse.model.ModelFactory;
|
||||
import net.sourceforge.pmd.eclipse.model.ProjectPropertiesModel;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@ -56,7 +58,6 @@ import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.ui.IWorkbench;
|
||||
@ -72,6 +73,9 @@ import org.eclipse.ui.dialogs.IWorkingSetSelectionDialog;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.3 2004/11/28 20:31:39 phherlin
|
||||
* Continuing the refactoring experiment
|
||||
*
|
||||
* Revision 1.2 2004/11/21 21:38:43 phherlin
|
||||
* Continue applying MVC.
|
||||
* Revision 1.1 2004/11/18 23:54:27
|
||||
@ -84,7 +88,8 @@ public class PMDPropertyPageController implements PMDConstants {
|
||||
private static final Log log = LogFactory.getLog("net.sourceforge.pmd.eclipse.properties.PMDPropertyPageController");
|
||||
private IProject project;
|
||||
private PMDPropertyPage propertyPage;
|
||||
private PMDPropertyPageModel propertyPageModel;
|
||||
private PMDPropertyPageBean propertyPageBean;
|
||||
private ProjectPropertiesModel projectPropertiesModel;
|
||||
|
||||
/**
|
||||
* Contructor
|
||||
@ -99,7 +104,7 @@ public class PMDPropertyPageController implements PMDConstants {
|
||||
/**
|
||||
* @return Returns the project.
|
||||
*/
|
||||
public IAdaptable getProject() {
|
||||
public IProject getProject() {
|
||||
return this.project;
|
||||
}
|
||||
|
||||
@ -116,28 +121,26 @@ public class PMDPropertyPageController implements PMDConstants {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the propertyPageModel.
|
||||
* @return Returns the propertyPageBean.
|
||||
*/
|
||||
public PMDPropertyPageModel getPropertyPageModel() {
|
||||
public PMDPropertyPageBean getPropertyPageBean() {
|
||||
// assert ((this.project != null) && (this.project.isAccessible()))
|
||||
|
||||
if (propertyPageModel == null) {
|
||||
if (this.propertyPageBean == null) {
|
||||
try {
|
||||
QueryProjectPropertiesCmd cmd = new QueryProjectPropertiesCmd();
|
||||
cmd.setProject(this.project);
|
||||
cmd.performExecute();
|
||||
this.projectPropertiesModel = ModelFactory.getFactory().getProperiesModelForProject(this.project);
|
||||
|
||||
propertyPageModel = new PMDPropertyPageModel();
|
||||
propertyPageModel.setPmdEnabled(cmd.isPMDEnabled());
|
||||
propertyPageModel.setProjectWorkingSet(cmd.getProjectWorkingSet());
|
||||
propertyPageModel.setProjectRuleSet(cmd.getProjectRuleSet());
|
||||
propertyPageModel.setRuleSetStoredInProject(cmd.isRuleSetStoredInProject());
|
||||
} catch (CommandException e) {
|
||||
this.propertyPageBean = new PMDPropertyPageBean();
|
||||
this.propertyPageBean.setPmdEnabled(this.projectPropertiesModel.isPmdEnabled());
|
||||
this.propertyPageBean.setProjectWorkingSet(this.projectPropertiesModel.getProjectWorkingSet());
|
||||
this.propertyPageBean.setProjectRuleSet(this.projectPropertiesModel.getProjectRuleSet());
|
||||
this.propertyPageBean.setRuleSetStoredInProject(this.projectPropertiesModel.isRuleSetStoredInProject());
|
||||
} catch (ModelException e) {
|
||||
PMDPlugin.getDefault().showError(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
return propertyPageModel;
|
||||
return this.propertyPageBean;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -158,17 +161,17 @@ public class PMDPropertyPageController implements PMDConstants {
|
||||
try {
|
||||
// first check whether the project ruleset file exists if user has
|
||||
// choosen this option
|
||||
if ((this.propertyPageModel.isPmdEnabled()) && (this.propertyPageModel.isRuleSetStoredInProject())) {
|
||||
if ((this.propertyPageBean.isPmdEnabled()) && (this.propertyPageBean.isRuleSetStoredInProject())) {
|
||||
this.checkProjectRuleSetFile();
|
||||
}
|
||||
|
||||
// Then updates the project properties
|
||||
UpdateProjectPropertiesCmd cmd = new UpdateProjectPropertiesCmd();
|
||||
cmd.setProject(this.project);
|
||||
cmd.setPmdEnabled(this.propertyPageModel.isPmdEnabled());
|
||||
cmd.setProjectWorkingSet(this.propertyPageModel.getProjectWorkingSet());
|
||||
cmd.setProjectRuleSet(this.propertyPageModel.getProjectRuleSet());
|
||||
cmd.setRuleSetStoredInProject(this.propertyPageModel.isRuleSetStoredInProject());
|
||||
cmd.setPmdEnabled(this.propertyPageBean.isPmdEnabled());
|
||||
cmd.setProjectWorkingSet(this.propertyPageBean.getProjectWorkingSet());
|
||||
cmd.setProjectRuleSet(this.propertyPageBean.getProjectRuleSet());
|
||||
cmd.setRuleSetStoredInProject(this.propertyPageBean.isRuleSetStoredInProject());
|
||||
cmd.performExecute();
|
||||
|
||||
// If rebuild is needed, then rebuild the project
|
||||
@ -240,7 +243,7 @@ public class PMDPropertyPageController implements PMDConstants {
|
||||
if (!ruleSetFile.exists()) {
|
||||
if (MessageDialog.openQuestion(this.propertyPage.getShell(), this.getMessage(MSGKEY_QUESTION_TITLE),
|
||||
this.getMessage(MSGKEY_QUESTION_CREATE_RULESET_FILE))) {
|
||||
RuleSet ruleSet = this.propertyPageModel.getProjectRuleSet();
|
||||
RuleSet ruleSet = this.propertyPageBean.getProjectRuleSet();
|
||||
ruleSet.setName("Project rulset");
|
||||
ruleSet.setDescription("Generated by PMD Plugin for Eclipse");
|
||||
try {
|
||||
|
Reference in New Issue
Block a user