Skip to content

Commit

Permalink
Update cnescatlab#77 Cleaning code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Omar Waldmann committed Aug 4, 2017
1 parent 22f3b30 commit e021363
Show file tree
Hide file tree
Showing 101 changed files with 3,604 additions and 2,528 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,49 @@
* 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 org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

/**
* Initialize bundle context
*/
public class Activator implements BundleActivator {

private static BundleContext context;
/**
* Bundle context
*/
private static BundleContext context;

static BundleContext getContext() {
return context;
}
/**
* @return bundle context
*/
static BundleContext getContext() {
return context;
}

/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
@Override
/*
* (non-Javadoc)
*
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.
* BundleContext)
*/
@Override
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
}
Activator.context = bundleContext;
}

/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
@Override
/*
* (non-Javadoc)
*
* @see
* org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
@Override
public void stop(BundleContext bundleContext) throws Exception {
Activator.context = null;
}
Activator.context = null;
}

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

import fr.cnes.analysis.tools.analyzer.datas.CheckResult;
import fr.cnes.analysis.tools.analyzer.exception.JFlexException;
import fr.cnes.analysis.tools.analyzer.exception.NullContributionException;
import fr.cnes.analysis.tools.analyzer.services.checkers.CheckerContainer;
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.IOException;
import java.util.ArrayList;
Expand All @@ -21,8 +15,16 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.logging.Logger;

import org.eclipse.core.runtime.CoreException;

import fr.cnes.analysis.tools.analyzer.datas.CheckResult;
import fr.cnes.analysis.tools.analyzer.exception.JFlexException;
import fr.cnes.analysis.tools.analyzer.exception.NullContributionException;
import fr.cnes.analysis.tools.analyzer.services.checkers.CheckerContainer;
import fr.cnes.analysis.tools.analyzer.services.checkers.CheckerService;
import fr.cnes.analysis.tools.analyzer.services.languages.LanguageService;

/**
* <h1>i-Code CNES Analyzer service</h1>
* <p>
Expand All @@ -45,13 +47,12 @@
*
*/
public class Analyzer {
/** Analyzer plugin ID */
public static final String ANALYZER_PLUGIN_ID = "fr.cnes.analysis.tools.analyzer";

/** Logger */
private static final Logger LOGGER = Logger.getLogger(Analyzer.class.getName());

/** Analyzer plugin ID */
public static final String ANALYZER_PLUGIN_ID = "fr.cnes.analysis.tools.analyzer";

/** Number of thread to run the analysis */
private static int THREAD_NB = 1;

Expand Down Expand Up @@ -81,7 +82,7 @@ public class Analyzer {
* when the syntax analysis failed.
*/
public List<CheckResult> check(List<File> pInputFiles, List<String> pLanguageIds,
List<String> pExcludedCheckIds) throws IOException, JFlexException {
List<String> pExcludedCheckIds) throws IOException, JFlexException {
final String methodName = "check";
LOGGER.entering(this.getClass().getName(), methodName);

Expand All @@ -98,8 +99,6 @@ public List<CheckResult> check(List<File> pInputFiles, List<String> pLanguageIds
* 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.newFixedThreadPool(THREAD_NB);
final List<Future<List<CheckResult>>> analyzers = new ArrayList<Future<List<CheckResult>>>();
Expand All @@ -116,13 +115,12 @@ public List<CheckResult> check(List<File> pInputFiles, List<String> pLanguageIds
for (File file : pInputFiles) {
if (checker.canVerifyFormat(this.getFileExtension(file.getAbsolutePath()))) {
final CallableChecker callableAnalysis = new CallableChecker(
checker.getChecker(), file);
checker.getChecker(), file);
analyzers.add(service.submit(callableAnalysis));
}
}
}
} catch (NullContributionException | CoreException e) {
// TODO : Define how to handles theses cases.
e.printStackTrace();
}
for (Future<List<CheckResult>> analysis : analyzers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
*/
package fr.cnes.analysis.tools.analyzer.datas;

import fr.cnes.analysis.tools.analyzer.exception.JFlexException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import org.eclipse.core.runtime.IConfigurationElement;

import fr.cnes.analysis.tools.analyzer.exception.JFlexException;

/**
* This class must be extended by any Rule analyzer or Metric computer
* contributing to i-Code CNES Analyzer.
Expand All @@ -32,11 +34,13 @@
* </p>
*/
public abstract class AbstractChecker {
/** Analysed file. */
/** Analyzed file. */
private File inputFile;

/** List of {@link CheckResult} found during analysis. **/
private List<CheckResult> checkResults = new ArrayList<>();
/** The configuration element linked to this evaluation. **/
private IConfigurationElement contribution;

/**
* Run analysis for considering file and rule.
Expand All @@ -63,11 +67,11 @@ public abstract class AbstractChecker {
* exception thrown when cloning error appears
*/
protected void setError(final String pLocation, final String pMessage, final int pLine)
throws JFlexException {
CheckResult checkResult = new CheckResult(this.getContribution().getAttribute("name"),
this.getContribution().getAttribute("id"),
this.getContribution().getAttribute("languageId"));
checkResult.setLine(pLine);
throws JFlexException {
final CheckResult checkResult = new CheckResult(this.getContribution().getAttribute("name"),
this.getContribution().getAttribute("id"),
this.getContribution().getAttribute("languageId"));
checkResult.setLine(Integer.valueOf(pLine));
checkResult.setLocation(pLocation);
checkResult.setMessage(pMessage);
checkResult.setFile(inputFile);
Expand All @@ -89,13 +93,13 @@ protected void setError(final String pLocation, final String pMessage, final int
* exception thrown when cloning error appears
*/
protected void computeMetric(final String pLocation, final float pValue, final int pLine)
throws JFlexException {
CheckResult checkResult = new CheckResult(this.getContribution().getAttribute("name"),
this.getContribution().getAttribute("id"),
this.getContribution().getAttribute("languageId"));
checkResult.setLine(pLine);
throws JFlexException {
final CheckResult checkResult = new CheckResult(this.getContribution().getAttribute("name"),
this.getContribution().getAttribute("id"),
this.getContribution().getAttribute("languageId"));
checkResult.setLine(Integer.valueOf(pLine));
checkResult.setLocation(pLocation);
checkResult.setValue(pValue);
checkResult.setValue(Float.valueOf(pValue));
checkResult.setFile(this.inputFile);
this.checkResults.add(checkResult);

Expand All @@ -104,23 +108,20 @@ protected void computeMetric(final String pLocation, final float pValue, final i
/**
* Set the input file to be analyzed.
*
* @param inputFile
* @param pInputFile
* file's path
* @throws FileNotFoundException
* exception thrown when a file is not found
*/
public void setInputFile(final File pInputFile) throws FileNotFoundException {
this.checkResults = new LinkedList<CheckResult>();
CheckResult checkResult = new CheckResult(this.getContribution().getAttribute("name"),
this.getContribution().getAttribute("id"),
this.getContribution().getAttribute("languageId"));
final CheckResult checkResult = new CheckResult(this.getContribution().getAttribute("name"),
this.getContribution().getAttribute("id"),
this.getContribution().getAttribute("languageId"));
checkResult.setFile(pInputFile);
this.inputFile = pInputFile;
}

/** The configuration element linked to this evaluation. **/
private IConfigurationElement contribution;

/**
* Getter for the contribution.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
/*
* i-Code CNES is a static code analyser.
* 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.services.checkers;

import fr.cnes.analysis.tools.analyzer.datas.AbstractChecker;
import fr.cnes.analysis.tools.analyzer.services.languages.LanguageContainer;
import java.util.List;

import org.eclipse.core.runtime.IConfigurationElement;

import fr.cnes.analysis.tools.analyzer.datas.AbstractChecker;
import fr.cnes.analysis.tools.analyzer.services.languages.LanguageContainer;

/**
* Container for checker defined in contribution of the
* {@link CheckerService#CHECKER_EP_ID} extension point to be used by
Expand Down Expand Up @@ -38,7 +46,7 @@ public class CheckerContainer {
* Checker's contribution.
*/
public CheckerContainer(String pId, String pName, LanguageContainer pLanguage,
AbstractChecker pChecker, IConfigurationElement pCheckerContribution) {
AbstractChecker pChecker, IConfigurationElement pCheckerContribution) {
this.id = pId;
this.name = pName;
this.language = pLanguage;
Expand All @@ -62,8 +70,8 @@ public CheckerContainer(String pId, String pName, LanguageContainer pLanguage,
* whether or not the checker returns a value.
*/
public CheckerContainer(String pId, String pName, LanguageContainer pLanguage,
AbstractChecker pChecker, IConfigurationElement pCheckerContribution,
boolean pIsMetric) {
AbstractChecker pChecker, IConfigurationElement pCheckerContribution,
boolean pIsMetric) {
this.id = pId;
this.name = pName;
this.language = pLanguage;
Expand All @@ -72,10 +80,18 @@ public CheckerContainer(String pId, String pName, LanguageContainer pLanguage,
this.isMetric = pIsMetric;
}

/**
* @param pFormat
* to test
* @return whether or not the format is handled by this checker.
*/
public boolean canVerifyFormat(String pFormat) {
return this.language.getFileExtension().contains(pFormat);
}

/**
* @return format that can be handled by this checker's language.
*/
public List<String> getVerifiableFormat() {
return this.language.getFileExtension();
}
Expand Down
Loading

0 comments on commit e021363

Please sign in to comment.