Skip to content

Commit

Permalink
Fix cnescatlab#33 & Update cnescatlab#32 Add of an EP for Checks & La…
Browse files Browse the repository at this point in the history
…nguages & services

Service were added to access data. Analyzer was updated to use the new
extension points.
  • Loading branch information
Omar Waldmann committed Jul 4, 2017
1 parent 57d240b commit 1ce3f4a
Show file tree
Hide file tree
Showing 12 changed files with 373 additions and 129 deletions.
6 changes: 6 additions & 0 deletions fr.cnes.analysis.tools.analyzer/.project
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>net.sourceforge.metrics.nature</nature>
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
</natures>
</projectDescription>
4 changes: 2 additions & 2 deletions fr.cnes.analysis.tools.analyzer/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension-point id="fr.cnes.analysis.tools.languages" name="fr.cnes.analysis.tools.languages" schema="schema/fr.cnes.analysis.tools.languages.exsd"/>
<extension-point id="fr.cnes.analysis.tools.checks" name="fr.cnes.analysis.tools.checks" schema="schema/fr.cnes.analysis.tools.checks.exsd"/>
<extension-point id="languages" name="languages" schema="schema/languages.exsd"/>
<extension-point id="checks" name="checks" schema="schema/checks.exsd"/>
<extension
id="application"
point="org.eclipse.core.runtime.applications">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@
</annotation>
</attribute>
<attribute name="languageId" type="string" use="required">
<annotation>
<documentation>

</documentation>
<appinfo>
<meta.attribute kind="identifier" basedOn="fr.cnes.analysis.tools.analyzer.languages/language/@id"/>
</appinfo>
</annotation>
</attribute>
<attribute name="isMetric" type="boolean">
<annotation>
<documentation>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import fr.cnes.analysis.tools.analyzer.services.checkers.CheckerService;
import fr.cnes.analysis.tools.analyzer.services.languages.LanguageService;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -25,34 +24,21 @@
import org.eclipse.core.runtime.CoreException;

/**
* <h1>i-Code CNES analyzer service</h1>
* <h1>i-Code CNES Analyzer service</h1>
* <p>
* This class can be used by any third using {@link File} and {@link String} to
* run an analysis.
* This service must be used to run an analysis, using
* {@link #check(List, List, List)} method.
* </p>
* <p>
* <h2>Available methods</h2> The service method to call to run an analysis are
* {@link #check(List, List, List)} and
* {@link #computeMetrics(List, List, List)}. Once, it returns after a moment
* the results thanks to {@link CallableMetricAnalyzer} &
* {@link CallableChecker}.
* </p>
* <h2>Number of threads</h2>
* <p>
* To define the number of threads that should be running the analysis change
* the parameter {@link #THREAD_NB}. It's <strong>default value</strong> is set
* on <strong>one</strong>.
* </p>
* <h2>Handling exceptions</h2>
* <p>
* Both analyzer can throw the following type of exceptions :
* To reach required parameters, several services can be used :
* <ul>
* <li>{@link JFlexException} : When the syntax analysis is interrupted because
* JFLex couldn't handle the file. This can be thrown because of <i>file
* encryption, file format, unexpected file state</i> problem.</li>
* <li>{@link FileNotFoundException} : When one of the file couldn't be reached
* by the analyzer.</li>
* <li><code>languagesIds</code> - {@link LanguageService};</li>
* <li><code>excludedIds</code> - {@link CheckerService};</li>
* </ul>
*
* <p>
* For more informations on how to contribute to this, please refer to i-Code
* CNES User Manual.
* </p>
*
* @since 3.0
Expand Down Expand Up @@ -99,13 +85,9 @@ public List<CheckResult> check(List<File> pInputFiles, List<String> pLanguageIds
final String methodName = "check";
LOGGER.entering(this.getClass().getName(), methodName);

// Running both checker & language services.
CheckerService checkerService = new CheckerService();
LanguageService languageService = new LanguageService();

List<String> languageIds = pLanguageIds;
if (languageIds == null) {
languageIds = languageService.getLanguagesIds();
languageIds = LanguageService.getLanguagesIds();
}
List<String> excludedCheckIds = pExcludedCheckIds;
if (pExcludedCheckIds == null) {
Expand All @@ -126,10 +108,10 @@ public List<CheckResult> check(List<File> pInputFiles, List<String> pLanguageIds
* Each language must be run with it's own files (pending file
* extension).
*/
List<CheckerContainer> checkers;
final List<CheckerContainer> checkers;

try {
checkers = checkerService.getCheckers(languageIds, excludedCheckIds);
checkers = CheckerService.getCheckers(languageIds, excludedCheckIds);
for (CheckerContainer checker : checkers) {
for (File file : pInputFiles) {
if (checker.canVerifyFormat(this.getFileExtension(file.getAbsolutePath()))) {
Expand All @@ -140,13 +122,9 @@ public List<CheckResult> check(List<File> pInputFiles, List<String> pLanguageIds
}
}
} catch (NullContributionException | CoreException e) {
/*
* TODO : Define how to handles theses cases.
*
*/
// TODO : Define how to handles theses cases.
e.printStackTrace();
}

for (Future<List<CheckResult>> analysis : analyzers) {
try {
analysisResultCheckResult.addAll(analysis.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,75 @@
import java.util.List;
import org.eclipse.core.runtime.IConfigurationElement;

/**
* Container for checker defined in contribution of the
* {@link CheckerService#CHECKER_EP_ID} extension point to be used by
* {@link CheckerService} to access data.
*
* @since 3.0
*/
public class CheckerContainer {

/** Checker identifier */
private String id;
/** Checker name */
private String name;
/** Checker's language */
private LanguageContainer language;
/** Checker's analysis class */
private AbstractChecker checker;
/** Whether or not the checker is a metric */
private boolean isMetric;

public CheckerContainer(String pId, String pName, LanguageContainer pLanguage, AbstractChecker pChecker,
IConfigurationElement pCheckerContribution) {
/**
* @param pId
* Checker identifier.
* @param pName
* Checker name.
* @param pLanguage
* Checker's language.
* @param pChecker
* Checker analysis class.
* @param pCheckerContribution
* Checker's contribution.
*/
public CheckerContainer(String pId, String pName, LanguageContainer pLanguage,
AbstractChecker pChecker, IConfigurationElement pCheckerContribution) {
this.id = pId;
this.name = pName;
this.language = pLanguage;
this.checker = pChecker;
this.checker.setContribution(pCheckerContribution);
this.isMetric = false;
}

/**
* @param pId
* Checker identifier.
* @param pName
* Checker name.
* @param pLanguage
* Checker's language.
* @param pChecker
* Checker analysis class.
* @param pCheckerContribution
* Checker's contribution.
* @param pIsMetric
* whether or not the checker returns a value.
*/
public CheckerContainer(String pId, String pName, LanguageContainer pLanguage,
AbstractChecker pChecker, IConfigurationElement pCheckerContribution,
boolean pIsMetric) {
this.id = pId;
this.name = pName;
this.language = pLanguage;
this.checker = pChecker;
this.checker.setContribution(pCheckerContribution);
this.isMetric = pIsMetric;
}

public boolean canVerifyFormat(String format) {
return this.language.getFileExtension().contains(format);
public boolean canVerifyFormat(String pFormat) {
return this.language.getFileExtension().contains(pFormat);
}

public List<String> getVerifiableFormat() {
Expand All @@ -37,11 +88,11 @@ public final String getId() {
}

/**
* @param id
* @param pId
* the id to set
*/
protected final void setId(String id) {
this.id = id;
protected final void setId(String pId) {
this.id = pId;
}

/**
Expand All @@ -52,11 +103,11 @@ public final String getName() {
}

/**
* @param name
* @param pName
* the name to set
*/
protected final void setName(String name) {
this.name = name;
protected final void setName(String pName) {
this.name = pName;
}

/**
Expand All @@ -67,11 +118,11 @@ public final LanguageContainer getLanguage() {
}

/**
* @param language
* @param pLanguage
* the language to set
*/
protected final void setLanguage(LanguageContainer language) {
this.language = language;
protected final void setLanguage(LanguageContainer pLanguage) {
this.language = pLanguage;
}

/**
Expand All @@ -82,10 +133,25 @@ public final AbstractChecker getChecker() {
}

/**
* @param checker
* @param pChecker
* the checker to set
*/
protected final void setChecker(AbstractChecker checker) {
this.checker = checker;
protected final void setChecker(AbstractChecker pChecker) {
this.checker = pChecker;
}

/**
* @return the isMetric
*/
public final boolean isMetric() {
return isMetric;
}

/**
* @param pIsMetric
* the isMetric to set
*/
public final void setMetric(boolean pIsMetric) {
this.isMetric = pIsMetric;
}
}
Loading

0 comments on commit 1ce3f4a

Please sign in to comment.