Skip to content

Commit

Permalink
#23 - CheckResult creation. Replace Violation by CheckResult.
Browse files Browse the repository at this point in the history
  • Loading branch information
dupuisa committed May 23, 2017
1 parent 55ecc2f commit d335af3
Show file tree
Hide file tree
Showing 364 changed files with 4,281 additions and 4,875 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* This software is a free software, under the terms of the Eclipse Public License version 1.0.
* http://www.eclipse.org/legal/epl-v10.html
*
*/
*/
package fr.cnes.analysis.tools.analyzer;

import java.io.File;
Expand All @@ -17,98 +17,87 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;

import fr.cnes.analysis.tools.analyzer.datas.Violation;
import fr.cnes.analysis.tools.analyzer.datas.CheckResult;
import fr.cnes.analysis.tools.analyzer.exception.NullContributionException;

/**
* This class is used run analysis on a rule analyzer.
*/
public class RuleAnalysisJob extends AbstractAnalysisJob {
/** Array of descriptors used to store result of analysis. **/
private List<Violation> violations;
/** Array of descriptors used to store result of analysis. **/
private List<CheckResult> checkResults;

/**
* Constructor for this Job with extension id in parameter and files' path.
*
* @param pExtensionId
* the extension id of the analyzer on which this job applies
* @param pFiles
* list of path for files to analyze
*/
public RuleAnalysisJob(final String pExtensionId, final List<File> pFiles) {
super(pExtensionId, pFiles);
this.violations = new LinkedList<Violation>();
}
/**
* Constructor for this Job with extension id in parameter and files' path.
*
* @param pExtensionId
* the extension id of the analyzer on which this job applies
* @param pFiles
* list of path for files to analyze
*/
public RuleAnalysisJob(final String pExtensionId, final List<File> pFiles) {
super(pExtensionId, pFiles);
this.checkResults = new LinkedList<CheckResult>();
}

/**
* Getter for the violations.
*
* @return the violations
*/
public List<Violation> getViolations() {
return this.violations;
}
/**
* Getter for the violations. //TODO
*
* @return the violations
*/
public List<CheckResult> getCheckResults() {
return this.checkResults;
}

/**
* Setter for the violations.
*
* @param pViolations
* the violations to set
*/
public void setViolations(final List<Violation> pViolations) {
this.violations = pViolations;
}
/**
* Setter for the violations. TODO
*
* @param pCheckResults
* the violations to set
*/
public void setViolations(final List<CheckResult> pCheckResults) {
this.checkResults = pCheckResults;
}

/*
* (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.
* IProgressMonitor)
*/
@Override
public IStatus run(final IProgressMonitor monitor) {
LOGGER.finest("Begin run method");
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.
* IProgressMonitor)
*/
@Override
public IStatus run(final IProgressMonitor monitor) {
LOGGER.finest("Begin run method");

// Instantiate return variable
IStatus status = Status.OK_STATUS;
// Instantiate return variable
IStatus status = Status.OK_STATUS;

try {
final IConfigurationElement contribution =
AbstractAnalysisJob.getContribution(this.getExtensionId());
if (contribution == null) {
throw new CoreException(new Status(IStatus.ERROR,
"AnalysisJob", 0, "No contribution for analyzer id : "
+ this.getExtensionId(), null));
} else {
final RuleAnalyzer analyzer =
new RuleAnalyzer("Run "
+ contribution.getAttribute("name")
+ " computation...", this.getFiles(),
contribution.getAttribute("extensionId"));
try {
final IConfigurationElement contribution = AbstractAnalysisJob.getContribution(this.getExtensionId());
if (contribution == null) {
throw new CoreException(new Status(IStatus.ERROR, "AnalysisJob", 0,
"No contribution for analyzer id : " + this.getExtensionId(), null));
} else {
final RuleAnalyzer analyzer = new RuleAnalyzer(
"Run " + contribution.getAttribute("name") + " computation...", this.getFiles(),
contribution.getAttribute("extensionId"));

analyzer.setUser(true);
analyzer.setUser(true);

status = analyzer.run(monitor);
this.violations = analyzer.getViolations();
status = analyzer.run(monitor);
this.checkResults = analyzer.getCheckResults();

}
} catch (final CoreException exception) {
LOGGER.log(Level.FINER,
exception.getClass() + " : " + exception.getMessage(),
exception);
status =
new Status(Status.ERROR,
"fr.cnes.analysis.tools.fortran.analyzer",
Status.ERROR, exception.getMessage(), exception);
} catch (final NullContributionException exception) {
LOGGER.log(Level.FINER,
exception.getClass() + " : " + exception.getMessage(),
exception);
status =
new Status(Status.ERROR,
"fr.cnes.analysis.tools.fortran.analyzer",
Status.ERROR, exception.getMessage(), exception);
}
LOGGER.finest("End run method");
return status;
}
}
} catch (final CoreException exception) {
LOGGER.log(Level.FINER, exception.getClass() + " : " + exception.getMessage(), exception);
status = new Status(Status.ERROR, "fr.cnes.analysis.tools.fortran.analyzer", Status.ERROR,
exception.getMessage(), exception);
} catch (final NullContributionException exception) {
LOGGER.log(Level.FINER, exception.getClass() + " : " + exception.getMessage(), exception);
status = new Status(Status.ERROR, "fr.cnes.analysis.tools.fortran.analyzer", Status.ERROR,
exception.getMessage(), exception);
}
LOGGER.finest("End run method");
return status;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@
import org.eclipse.core.runtime.Status;

import fr.cnes.analysis.tools.analyzer.datas.AbstractRule;
import fr.cnes.analysis.tools.analyzer.datas.Violation;
import fr.cnes.analysis.tools.analyzer.datas.CheckResult;
import fr.cnes.analysis.tools.analyzer.exception.JFlexException;

/**
* This class is used to instantiate a new rule analyzer.
*/
public class RuleAnalyzer extends AbstractAnalyzer {
/** Logger. */
private static final Logger LOGGER = Logger.getLogger(RuleAnalyzer.class
.getName());
private static final Logger LOGGER = Logger.getLogger(RuleAnalyzer.class.getName());

/** List of values found during analysis. **/
private List<Violation> violations;
private List<CheckResult> checkResults;

/**
* Constructor that set the job with string name, extension id and a list of
Expand All @@ -44,57 +43,54 @@ public class RuleAnalyzer extends AbstractAnalyzer {
* @param pExtensionId
* the id of rule/metric contribution
*/
public RuleAnalyzer(final String name, final List<File> list,
final String pExtensionId) {
public RuleAnalyzer(final String name, final List<File> list, final String pExtensionId) {
super(name, list, pExtensionId);
this.violations = new LinkedList<Violation>();
this.checkResults = new LinkedList<CheckResult>();
}

/**
* Retrieve the violations of analysis.
* Retrieve the violations of analysis.TODO
*
* @return violations of the rule analysis
*/
public List<Violation> getViolations() {
return this.violations;
public List<CheckResult> getCheckResults() {
return this.checkResults;
}

/**
* Set the values with a list.
* Set the values with a list. TODO
*
* @param pViolations
* @param pCheckResults
* the list of violations to set
*/
public void setViolations(final List<Violation> pViolations) {
this.violations = pViolations;
public void setCheckResults(final List<CheckResult> pCheckResults) {
this.checkResults = pCheckResults;
}

/**
* Set the values with an array.
*
* @param pViolations
* @param pCheckResult
* the array of violations to set
*/
public void setDescriptors(final Violation[] pViolations) {
this.violations = new LinkedList<Violation>();
for (final Violation value : pViolations) {
this.violations.add(value);
public void setDescriptors(final CheckResult[] pCheckResult) {
this.checkResults = new LinkedList<CheckResult>();
for (final CheckResult value : pCheckResult) {
this.checkResults.add(value);
}
}

/*
* (non-Javadoc)
*
* @see
* fr.cnes.analysis.tools.analyzer.AbstractAnalyzer#runEvaluation(org.eclipse
* .core.runtime.IConfigurationElement, java.util.List,
* @see fr.cnes.analysis.tools.analyzer.AbstractAnalyzer#runEvaluation(org.
* eclipse .core.runtime.IConfigurationElement, java.util.List,
* org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
protected IStatus runEvaluation(final IConfigurationElement contribution,
final List<File> pFiles, final IProgressMonitor monitor)
throws CloneNotSupportedException, CoreException, IOException,
JFlexException {
protected IStatus runEvaluation(final IConfigurationElement contribution, final List<File> pFiles,
final IProgressMonitor monitor)
throws CloneNotSupportedException, CoreException, IOException, JFlexException {
LOGGER.finest("Begin runEvaluation method");

// Instantiate return variable
Expand All @@ -104,15 +100,13 @@ protected IStatus runEvaluation(final IConfigurationElement contribution,
for (final File file : pFiles) {

// Get the evaluation
final AbstractRule rule = (AbstractRule) contribution
.createExecutableExtension("class");
final AbstractRule rule = (AbstractRule) contribution.createExecutableExtension("class");
rule.setContribution(contribution);

// Run the evaluation
LOGGER.finest("File : " + file.getName());
monitor.subTask("Analyzing " + contribution.getAttribute("id")
+ " on file " + file.getName());
this.violations.addAll(this.runRuleOnFile(rule, file));
monitor.subTask("Analyzing " + contribution.getAttribute("id") + " on file " + file.getName());
this.checkResults.addAll(this.runRuleOnFile(rule, file));
monitor.worked(1);

// Stop analysis if cancel button selected
Expand All @@ -139,8 +133,8 @@ protected IStatus runEvaluation(final IConfigurationElement contribution,
* @throws JFlexException
* JFlex analysis error
*/
private List<Violation> runRuleOnFile(final AbstractRule rule,
final File file) throws IOException, JFlexException {
private List<CheckResult> runRuleOnFile(final AbstractRule rule, final File file)
throws IOException, JFlexException {
LOGGER.finest("Begin runRuleOnFile method");

// Initializing file reader in the metric
Expand All @@ -150,8 +144,7 @@ private List<Violation> runRuleOnFile(final AbstractRule rule,
try {
return rule.run();
} catch (JFlexException e) {
String msg = e.getCause().getMessage() + " : file " + file
+ " : rule " + rule.getClass();
String msg = e.getCause().getMessage() + " : file " + file + " : rule " + rule.getClass();
throw new JFlexException(new Exception(msg));
}
}
Expand All @@ -163,6 +156,6 @@ private List<Violation> runRuleOnFile(final AbstractRule rule,
*/
@Override
protected void canceling() {
this.violations.clear();
this.checkResults.clear();
}
}
Loading

0 comments on commit d335af3

Please sign in to comment.