Skip to content

Commit

Permalink
Merge pull request cnescatlab#90 from WaldoFR/V3-dev
Browse files Browse the repository at this point in the history
Logger, Exception & minor fixes
  • Loading branch information
dupuisa authored Sep 11, 2017
2 parents 1aff959 + 954d366 commit 6f2878b
Show file tree
Hide file tree
Showing 283 changed files with 5,296 additions and 2,788 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ jdk:
- oraclejdk8
install: true
script :
- mvn install
- mvn install -DskipTests
- mvn verify
sudo: false
1 change: 1 addition & 0 deletions fr.cnes.analysis.tools.analyzer/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: fr.cnes.analysis.tools.analyzer;uses:="org.osgi.framework,org.eclipse.core.runtime.jobs,org.eclipse.core.runtime",
fr.cnes.analysis.tools.analyzer.datas;uses:="org.eclipse.core.runtime",
fr.cnes.analysis.tools.analyzer.exception,
fr.cnes.analysis.tools.analyzer.logger,
fr.cnes.analysis.tools.analyzer.services.checkers,
fr.cnes.analysis.tools.analyzer.services.languages
Bundle-Vendor: CNES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
*/
public class Activator implements BundleActivator {

/** Plug-in ID */
public static final String PLUGIN_ID = "fr.cnes.analysis.tools.analyzer";

/**
* Bundle context
*/
Expand All @@ -22,7 +25,7 @@ public class Activator implements BundleActivator {
/**
* @return bundle context
*/
static BundleContext getContext() {
public static BundleContext getContext() {
return context;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
import java.util.concurrent.ExecutorService;
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.logger.ICodeLogger;
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;
Expand Down Expand Up @@ -50,9 +50,6 @@ 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());

/** Number of thread to run the analysis */
private static final int THREAD_NB = Runtime.getRuntime().availableProcessors();

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

List<String> languageIds = pLanguageIds;
if (languageIds == null) {
Expand Down Expand Up @@ -117,15 +114,15 @@ public List<CheckResult> check(List<File> pInputFiles, List<String> pLanguageIds

final long maxMemory = Runtime.getRuntime().maxMemory();
checkers = CheckerService.getCheckers(languageIds, excludedCheckIds);
for (CheckerContainer checker : checkers) {
for (File file : pInputFiles) {
for (final CheckerContainer checker : checkers) {
for (final File file : pInputFiles) {
if (checker.canVerifyFormat(this.getFileExtension(file.getAbsolutePath()))) {
final CallableChecker callableAnalysis = new CallableChecker(
checker.getChecker(), file);
if ((MAX_MEMORY_THRESHOLD * maxMemory < (Runtime.getRuntime().totalMemory()
- Runtime.getRuntime().freeMemory()))
&& !analyzers.isEmpty()) {
for (Future<List<CheckResult>> analysis : analyzers) {
for (final Future<List<CheckResult>> analysis : analyzers) {
analysisResultCheckResult.addAll(analysis.get());
}
analyzers.clear();
Expand All @@ -140,9 +137,11 @@ public List<CheckResult> check(List<File> pInputFiles, List<String> pLanguageIds
}
} catch (NullContributionException | InterruptedException | CoreException e) {

LOGGER.throwing(this.getClass().getName(), methodName, e);
ICodeLogger.error(this.getClass().getName(), methodName, e);
} catch (ExecutionException exception) {
ICodeLogger.error(this.getClass().getName(), methodName, exception);
if (exception.getCause() instanceof JFlexException) {
ICodeLogger.throwing(this.getClass().getName(), methodName, exception.getCause());
throw (JFlexException) exception.getCause();
}
}
Expand All @@ -155,7 +154,7 @@ public List<CheckResult> check(List<File> pInputFiles, List<String> pLanguageIds
* to retrieve the extension
* @return The extension name of the file
*/
private String getFileExtension(String pFileName) {
private String getFileExtension(final String pFileName) {
String extension = null;

final int i = pFileName.lastIndexOf('.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
*/
package fr.cnes.analysis.tools.analyzer;

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;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;

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 fr.cnes.analysis.tools.analyzer.logger.ICodeLogger;

/**
* This class is responsible of applying a rule on a file and to return it's
* results as a Thread by implementing {@link Callable} interface.
Expand All @@ -23,6 +25,9 @@
*/
public class CallableChecker implements Callable<List<CheckResult>> {

/** Class name */
private static final String CLASS = CallableChecker.class.getName();

/** The rule to apply */
private AbstractChecker rule;
/** The metric to analyze */
Expand All @@ -36,9 +41,14 @@ public class CallableChecker implements Callable<List<CheckResult>> {
* @param pInputFile
* to analyze
*/
public CallableChecker(AbstractChecker pRule, File pInputFile) {
public CallableChecker(final AbstractChecker pRule, final File pInputFile) {
final String method = "CallableChecker";
ICodeLogger.entering(CLASS, method, new Object[] {
pRule, pInputFile
});
this.rule = pRule;
this.file = pInputFile;
ICodeLogger.exiting(CLASS, method);
}

/*
Expand All @@ -48,9 +58,12 @@ public CallableChecker(AbstractChecker pRule, File pInputFile) {
*/
@Override
public List<CheckResult> call() throws IOException, JFlexException {
final String method = "call";
ICodeLogger.entering(CLASS, method);
final List<CheckResult> results = new ArrayList<>();
rule.setInputFile(file);
results.addAll(rule.run());
ICodeLogger.exiting(CLASS, method, results);
return results;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.eclipse.core.runtime.IConfigurationElement;

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

/**
* This class must be extended by any Rule analyzer or Metric computer
Expand All @@ -34,6 +35,9 @@
* </p>
*/
public abstract class AbstractChecker {

/** Class name */
private static final String CLASS = AbstractChecker.class.getName();
/** Analyzed file. */
private File inputFile;

Expand Down Expand Up @@ -68,6 +72,10 @@ public abstract class AbstractChecker {
*/
protected void setError(final String pLocation, final String pMessage, final int pLine)
throws JFlexException {
final String method = "setError";
ICodeLogger.entering(CLASS, method, new Object[] {
pLocation, pMessage, Integer.valueOf(pLine)
});
final CheckResult checkResult = new CheckResult(this.getContribution().getAttribute("name"),
this.getContribution().getAttribute("id"),
this.getContribution().getAttribute("languageId"));
Expand All @@ -76,6 +84,7 @@ protected void setError(final String pLocation, final String pMessage, final int
checkResult.setMessage(pMessage);
checkResult.setFile(inputFile);
this.checkResults.add(checkResult);
ICodeLogger.exiting(CLASS, method);

}

Expand All @@ -94,6 +103,10 @@ protected void setError(final String pLocation, final String pMessage, final int
*/
protected void computeMetric(final String pLocation, final float pValue, final int pLine)
throws JFlexException {
final String method = "computeMetric";
ICodeLogger.entering(CLASS, method, new Object[] {
pLocation, Float.valueOf(pValue), Integer.valueOf(pLine)
});
final CheckResult checkResult = new CheckResult(this.getContribution().getAttribute("name"),
this.getContribution().getAttribute("id"),
this.getContribution().getAttribute("languageId"));
Expand All @@ -102,6 +115,7 @@ protected void computeMetric(final String pLocation, final float pValue, final i
checkResult.setValue(Float.valueOf(pValue));
checkResult.setFile(this.inputFile);
this.checkResults.add(checkResult);
ICodeLogger.exiting(CLASS, method);

}

Expand All @@ -114,12 +128,15 @@ protected void computeMetric(final String pLocation, final float pValue, final i
* exception thrown when a file is not found
*/
public void setInputFile(final File pInputFile) throws FileNotFoundException {
final String method = "setInputFile";
ICodeLogger.entering(CLASS, method, pInputFile);
this.checkResults = new LinkedList<CheckResult>();
final CheckResult checkResult = new CheckResult(this.getContribution().getAttribute("name"),
this.getContribution().getAttribute("id"),
this.getContribution().getAttribute("languageId"));
checkResult.setFile(pInputFile);
this.inputFile = pInputFile;
ICodeLogger.exiting(CLASS, method);
}

/**
Expand All @@ -128,6 +145,9 @@ public void setInputFile(final File pInputFile) throws FileNotFoundException {
* @return the contribution
*/
public IConfigurationElement getContribution() {
final String method = "getContribution";
ICodeLogger.entering(CLASS, method);
ICodeLogger.exiting(CLASS, method, this.contribution);
return this.contribution;
}

Expand All @@ -138,7 +158,10 @@ public IConfigurationElement getContribution() {
* the new contribution
*/
public void setContribution(final IConfigurationElement pContribution) {
final String method = "setContribution";
ICodeLogger.entering(CLASS, method, pContribution);
this.contribution = pContribution;
ICodeLogger.exiting(CLASS, method);
}

/**
Expand All @@ -147,6 +170,9 @@ public void setContribution(final IConfigurationElement pContribution) {
* @return the {@link CheckResult}s
*/
public List<CheckResult> getCheckResults() {
final String method = "getCheckResults";
ICodeLogger.entering(CLASS, method);
ICodeLogger.exiting(CLASS, method, this.checkResults);
return this.checkResults;
}

Expand All @@ -157,7 +183,10 @@ public List<CheckResult> getCheckResults() {
* the {@link CheckResult}s to set
*/
public void setCheckResults(final List<CheckResult> pCheckResults) {
final String method = "setCheckResults";
ICodeLogger.entering(CLASS, method, pCheckResults);
this.checkResults = pCheckResults;
ICodeLogger.exiting(CLASS, method);
}

/**
Expand All @@ -166,20 +195,10 @@ public void setCheckResults(final List<CheckResult> pCheckResults) {
* @return the analyzed file.
*/
public File getInputFile() {
final String method = "getInputFile";
ICodeLogger.entering(CLASS, method);
ICodeLogger.exiting(CLASS, method, inputFile);
return inputFile;
}

/**
* @param str
* to set to ASCII decimal
* @return
* @return ASCII decimal of <code>str</code>
*/
public static final String toASCII(final String str) {
String code = "";
for (char character : str.toCharArray()) {
code += (int) character;
}
return code;
}
}
Loading

0 comments on commit 6f2878b

Please sign in to comment.