Skip to content

Commit

Permalink
Merge pull request #27 from WaldoFR/V3-dev
Browse files Browse the repository at this point in the history
Update #16 & Fix #19
  • Loading branch information
dupuisa authored Jun 12, 2017
2 parents 98d41c7 + ebe1bbd commit eecdb33
Show file tree
Hide file tree
Showing 429 changed files with 36,357 additions and 43,820 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ bin/

# Ignore code generation directories
*/src-gen/fr/

#Ignore checkstyle configuration
*.checkstyle
1 change: 0 additions & 1 deletion fr.cnes.analysis.tools.analyzer/.gitignore

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
*/
package fr.cnes.analysis.tools.analyzer;

import fr.cnes.analysis.tools.analyzer.datas.AbstractMetric;
import fr.cnes.analysis.tools.analyzer.datas.AbstractRule;
import fr.cnes.analysis.tools.analyzer.datas.AbstractChecker;
import fr.cnes.analysis.tools.analyzer.datas.CheckResult;
import fr.cnes.analysis.tools.analyzer.datas.FileValue;
import fr.cnes.analysis.tools.analyzer.exception.JFlexException;
import java.io.File;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -37,7 +35,7 @@
* {@link #check(List, List, List)} and
* {@link #computeMetrics(List, List, List)}. Once, it returns after a moment
* the results thanks to {@link CallableMetricAnalyzer} &
* {@link CallableRuleAnalyzer}.
* {@link CallableChecker}.
* </p>
* <h2>Number of threads</h2>
* <p>
Expand Down Expand Up @@ -151,8 +149,17 @@ public List<CheckResult> check(List<File> pInputFiles, List<String> pLanguageIds
final List<String> allowedExtension = new ArrayList<>();
for (IConfigurationElement fileExtension : analyzerContribution
.getChildren(ANALYZER_EP_ELEMENT_FILE_EXTENSION)) {
allowedExtension.add(fileExtension
.getAttribute(ANALYZER_EP_ELEMENT_FILE_EXTENSION_ATTRIBUTE_NAME));
// we remove the dot in case the contributor added it.
if (fileExtension
.getAttribute(ANALYZER_EP_ELEMENT_FILE_EXTENSION_ATTRIBUTE_NAME)
.contains(".")) {
allowedExtension.add(fileExtension
.getAttribute(ANALYZER_EP_ELEMENT_FILE_EXTENSION_ATTRIBUTE_NAME)
.replace(".", ""));
} else {
allowedExtension.add(fileExtension
.getAttribute(ANALYZER_EP_ELEMENT_FILE_EXTENSION_ATTRIBUTE_NAME));
}
}
// 1.2. Restricting analysis only on file that the plugin can
// handle.
Expand All @@ -176,19 +183,19 @@ public List<CheckResult> check(List<File> pInputFiles, List<String> pLanguageIds
.contains(contribution.getAttribute(ANALYZER_EP_CONTRIBUTOR_CHECK_ID))
&& !excludedCheckIds.contains((contribution
.getAttribute(ANALYZER_EP_CONTRIBUTOR_CHECK_ID)))) {
AbstractRule rule;
AbstractChecker rule;
/*
* We are currently to load as much Rule as there is
* files because the lex files are designed to be run
* only on one file.
*/
for (File analyzedFile : restrictedFiles) {
try {
rule = (AbstractRule) contribution
rule = (AbstractChecker) contribution
.createExecutableExtension("class");
rule.setContribution(contribution);
final CallableRuleAnalyzer callableAnalysis = new CallableRuleAnalyzer(
rule, analyzedFile);
final CallableChecker callableAnalysis = new CallableChecker(rule,
analyzedFile);
analyzers.add(service.submit(callableAnalysis));
} catch (CoreException e) {

Expand All @@ -214,6 +221,8 @@ public List<CheckResult> check(List<File> pInputFiles, List<String> pLanguageIds
throw ((IOException) executionException.getCause());
} else if (executionException.getCause() instanceof JFlexException) {
throw ((JFlexException) executionException.getCause());
} else {
executionException.printStackTrace();
}
}
}
Expand All @@ -238,122 +247,4 @@ private String getFileExtension(String pFileName) {
return extension;
}

/**
* <h1>{@link #computeMetrics(List, List, List)}</h1>
* <p>
* This method compute every metric of the different contributions set in
* parameter except the ones excluded. File in parameters are being analyzed
* by each contribution able to handle it or none if it isn't.
* </p>
* <p>
* <strong>Important :</strong> Default configurations to run analysis are
* available when setting parameters.
*
* @param pInputFiles
* to analyze
* @param pLanguageIds
* to include in the analysis. <strong>Set null</strong> to run
* an analysis including all contributions.
* @param pExcludedCheckIds
* rules identifier to exclude from the analysis. <strong>Set
* null</strong> run analysis with every rules.
* @return list of {@link CheckResult} found by the analysis.
* @throws IOException
* when a file couldn't be reached for analysis.
* @throws JFlexException
* when the syntax analysis failed.
*/
public List<FileValue> computeMetrics(List<File> pInputFiles, List<String> pLanguageIds,
List<String> pExcludedCheckIds) throws IOException, JFlexException {
final String methodName = "computeMetrics";
List<String> languageIds = pLanguageIds;
if (languageIds == null) {
languageIds = new ArrayList<String>();
}
List<String> excludedCheckIds = pExcludedCheckIds;
if (pExcludedCheckIds == null) {
excludedCheckIds = new ArrayList<String>();
}
final List<FileValue> analysisResultFileValues = new ArrayList<>();
/*
* The number of threads could be defined by the number of files or the
* number of rule or both of them. This is pending how we decide to run
* the analysis.
*
* TODO : Chose one solution for the number of threads
*/
final ExecutorService service = Executors.newSingleThreadExecutor();
final List<Future<List<FileValue>>> analyzers = new ArrayList<Future<List<FileValue>>>();

for (IConfigurationElement analyzerContribution : Platform.getExtensionRegistry()
.getConfigurationElementsFor(Analyzer.ANALYZER_EP_ID)) {
if (languageIds.contains(
analyzerContribution.getAttribute(ANALYZER_EP_ATTRIBUTE_EXTENSION_ID))) {
final ArrayList<String> allowedExtension = new ArrayList<>();
for (IConfigurationElement fileExtension : analyzerContribution
.getChildren(ANALYZER_EP_ELEMENT_FILE_EXTENSION)) {
allowedExtension.add(fileExtension
.getAttribute(ANALYZER_EP_ELEMENT_FILE_EXTENSION_ATTRIBUTE_NAME));
}
// 1.2. Restricting analysis only on file that the plugin can
// handle.
final ArrayList<File> restrictedFiles = new ArrayList<>();
for (File file : pInputFiles) {
if (allowedExtension.contains(this.getFileExtension(file.getAbsolutePath()))
&& !restrictedFiles.contains(file)) {
restrictedFiles.add(file);
}
}
for (IConfigurationElement contribution : Platform.getExtensionRegistry()
.getConfigurationElementsFor(analyzerContribution
.getAttribute(ANALYZER_EP_ATTRIBUTE_EXTENSION_ID))) {
if (PlatformUI.getPreferenceStore()
.contains(contribution.getAttribute(ANALYZER_EP_CONTRIBUTOR_CHECK_ID))
&& !excludedCheckIds.contains(
contribution.getAttribute(ANALYZER_EP_CONTRIBUTOR_CHECK_ID))) {
AbstractMetric metric;
for (File analysisFile : restrictedFiles) {
try {
metric = (AbstractMetric) contribution
.createExecutableExtension("class");
metric.setContribution(contribution);
final CallableMetricAnalyzer callableAnalysis = new CallableMetricAnalyzer(
metric, analysisFile);
analyzers.add(service.submit(callableAnalysis));
} catch (CoreException e) {

// TODO : Define how to warn here of the
// execution
// failure without throwing new
// exception
e.printStackTrace();
}
}
}
}
}
}

for (Future<List<FileValue>> analysis : analyzers) {
try {
analysisResultFileValues.addAll(analysis.get());
} catch (InterruptedException interruptedException) {
LOGGER.throwing(this.getClass().getName(), methodName, interruptedException);
} catch (ExecutionException executionException) {
if (executionException.getCause() instanceof IOException) {
final IOException causeException = ((IOException) executionException
.getCause());
LOGGER.throwing(this.getClass().getName(), methodName, causeException);
throw causeException;
} else if (executionException.getCause() instanceof JFlexException) {
final JFlexException causeException = ((JFlexException) executionException
.getCause());
LOGGER.throwing(this.getClass().getName(), methodName, causeException);
throw causeException;
}
}
}
return analysisResultFileValues;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
package fr.cnes.analysis.tools.analyzer;

import fr.cnes.analysis.tools.analyzer.datas.AbstractRule;
import fr.cnes.analysis.tools.analyzer.datas.AbstractChecker;
import fr.cnes.analysis.tools.analyzer.datas.CheckResult;
import fr.cnes.analysis.tools.analyzer.exception.JFlexException;
import java.io.File;
Expand All @@ -21,22 +21,22 @@
*
* @since 3.0
*/
public class CallableRuleAnalyzer implements Callable<List<CheckResult>> {
public class CallableChecker implements Callable<List<CheckResult>> {

/** The rule to apply */
private AbstractRule rule;
private AbstractChecker rule;
/** The metric to analyze */
private File file;

/**
* Constructor for {@link CallableRuleAnalyzer}.
* Constructor for {@link CallableChecker}.
*
* @param pRule
* to apply
* @param pInputFile
* to analyze
*/
public CallableRuleAnalyzer(AbstractRule pRule, File pInputFile) {
public CallableChecker(AbstractChecker pRule, File pInputFile) {
this.rule = pRule;
this.file = pInputFile;
}
Expand Down

This file was deleted.

Loading

0 comments on commit eecdb33

Please sign in to comment.