Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Every exceptions thrown by checkers are sending more informative
messages

- Code was improved as defined in cnescatlab#77 with a logger & part of PMD &
checkstyle issues were solved

About the logger, a new class UILogger was made. It runs
org.eclipse.logger logger so all the logs are written directly to /*.log
file of ./metadata of workspace and /configuration of eclipse folder.
To precise the level of log a parameter must be indicated on the launch,
as defined in this page :
(https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fruntime-options.html
). So the following argument can be used to define level of the logger
-Declipse.log.level=<level> where level can be INFO, WARNING, or ERROR.

An important change was made on ConfigurationPagePreferences that was
using CheckerTableViewer and MetricsTableViewer in a composite
Container. These class are now extending Composite that contains a
search SWT.label, a SWT.Text (for the search input) and a TableViewer
with Checkers and parameters relatives to them. Old composite containing
these class was replaced by the new CheckerComposite and
MetricsComposite.
  • Loading branch information
Omar Waldmann committed Sep 4, 2017
1 parent 1aff959 commit 9af8af5
Show file tree
Hide file tree
Showing 56 changed files with 2,152 additions and 1,191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ 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);

Expand Down Expand Up @@ -117,15 +117,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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
Expand Down Expand Up @@ -48,6 +49,11 @@ public final class CheckerService {
/** Check's element isMetric attribute key */
public static final String CHECKER_EP_ELEMENT_CHECK_ATT_ISMETRIC = "isMetric";

/** The logger **/
private static final Logger LOGGER = Logger.getLogger(CheckerService.class.getName());
/** Class name **/
private static final String CLASS = CheckerService.class.getName();

/**
* Utils class default constructor removal.
*/
Expand All @@ -66,6 +72,8 @@ private CheckerService() {
*/
public static List<CheckerContainer> getCheckers()
throws NullContributionException, CoreException {
final String method = "getCheckers";
LOGGER.entering(CLASS, method);
final List<CheckerContainer> checkers = new ArrayList<>();
final IConfigurationElement[] checkerContributors = Platform.getExtensionRegistry()
.getConfigurationElementsFor(CHECKER_EP_ID);
Expand All @@ -89,8 +97,8 @@ public static List<CheckerContainer> getCheckers()
isMetric = false;
} else {
isMetric = Boolean
.valueOf(checkerElement
.getAttribute(CHECKER_EP_ELEMENT_CHECK_ATT_ISMETRIC))
.valueOf(checkerElement.getAttribute(
CHECKER_EP_ELEMENT_CHECK_ATT_ISMETRIC))
.booleanValue();
}

Expand All @@ -101,6 +109,7 @@ public static List<CheckerContainer> getCheckers()
// 1.7 Add the checkers to all checkers.
checkers.add(checker);
}
LOGGER.exiting(CLASS, method, checkers);
return checkers;
}

Expand All @@ -125,6 +134,8 @@ public static List<CheckerContainer> getCheckers()
*/
public static List<CheckerContainer> getCheckers(String languageId)
throws NullContributionException, CoreException {
final String method = "getCheckers";
LOGGER.entering(CLASS, method, languageId);
final List<CheckerContainer> checkers = new ArrayList<>();
final IConfigurationElement[] checkerContributors = Platform.getExtensionRegistry()
.getConfigurationElementsFor(CHECKER_EP_ID);
Expand All @@ -150,8 +161,8 @@ public static List<CheckerContainer> getCheckers(String languageId)
isMetric = false;
} else {
isMetric = Boolean
.valueOf(checkerElement
.getAttribute(CHECKER_EP_ELEMENT_CHECK_ATT_ISMETRIC))
.valueOf(checkerElement.getAttribute(
CHECKER_EP_ELEMENT_CHECK_ATT_ISMETRIC))
.booleanValue();
}

Expand All @@ -163,6 +174,7 @@ public static List<CheckerContainer> getCheckers(String languageId)
checkers.add(checker);
}
}
LOGGER.exiting(CLASS, method, checkers);
return checkers;
}

Expand All @@ -172,6 +184,8 @@ public static List<CheckerContainer> getCheckers(String languageId)
* @return A list of every checker's ids referencing languageId.
*/
public static List<String> getCheckersIds(String languageId) {
final String method = "getCheckersIds";
LOGGER.entering(CLASS, method, languageId);
final List<String> checkers = new ArrayList<>();
final IConfigurationElement[] checkerContributors = Platform.getExtensionRegistry()
.getConfigurationElementsFor(CHECKER_EP_ID);
Expand All @@ -182,6 +196,7 @@ public static List<String> getCheckersIds(String languageId) {
.getAttribute(CheckerService.CHECKER_EP_ELEMENT_CHECK_ATT_ID));
}
}
LOGGER.exiting(CLASS, method, checkers);
return checkers;
}

Expand All @@ -206,6 +221,8 @@ public static List<String> getCheckersIds(String languageId) {
*/
public static List<CheckerContainer> getCheckers(List<String> checkersIds)
throws NullContributionException, CoreException {
final String method = "getCheckers";
LOGGER.entering(CLASS, method, checkersIds);
final List<CheckerContainer> checkers = new ArrayList<>();
final IConfigurationElement[] checkerContributors = Platform.getExtensionRegistry()
.getConfigurationElementsFor(CHECKER_EP_ID);
Expand All @@ -231,8 +248,8 @@ public static List<CheckerContainer> getCheckers(List<String> checkersIds)
isMetric = false;
} else {
isMetric = Boolean
.valueOf(checkerElement
.getAttribute(CHECKER_EP_ELEMENT_CHECK_ATT_ISMETRIC))
.valueOf(checkerElement.getAttribute(
CHECKER_EP_ELEMENT_CHECK_ATT_ISMETRIC))
.booleanValue();
}

Expand All @@ -244,6 +261,7 @@ public static List<CheckerContainer> getCheckers(List<String> checkersIds)
checkers.add(checker);
}
}
LOGGER.exiting(CLASS, method, checkers);
return checkers;
}

Expand All @@ -266,6 +284,10 @@ public static List<CheckerContainer> getCheckers(List<String> checkersIds)
*/
public static List<CheckerContainer> getCheckers(List<String> languagesIds,
List<String> excludedIds) throws NullContributionException, CoreException {
final String method = "getCheckers";
LOGGER.entering(CLASS, method, new Object[] {
languagesIds, excludedIds
});
final List<CheckerContainer> checkers = new ArrayList<>();
final IConfigurationElement[] checkerContributors = Platform.getExtensionRegistry()
.getConfigurationElementsFor(CHECKER_EP_ID);
Expand All @@ -292,8 +314,8 @@ public static List<CheckerContainer> getCheckers(List<String> languagesIds,
isMetric = false;
} else {
isMetric = Boolean
.valueOf(checkerElement
.getAttribute(CHECKER_EP_ELEMENT_CHECK_ATT_ISMETRIC))
.valueOf(checkerElement.getAttribute(
CHECKER_EP_ELEMENT_CHECK_ATT_ISMETRIC))
.booleanValue();
}
final CheckerContainer checker = new CheckerContainer(checkerId, checkerName,
Expand All @@ -303,7 +325,7 @@ public static List<CheckerContainer> getCheckers(List<String> languagesIds,
checkers.add(checker);
}
}

LOGGER.exiting(CLASS, method, checkers);
return checkers;

}
Expand All @@ -315,6 +337,8 @@ public static List<CheckerContainer> getCheckers(List<String> languagesIds,
* parameter is contributing to {@link #CHECKER_EP_ID}.
*/
public static boolean isCheckerIdContributor(String checkerId) {
final String method = "isCheckerIdContributor";
LOGGER.entering(CLASS, method, checkerId);
boolean isCheckerIdContributor = false;
final IConfigurationElement[] checkerContributors = Platform.getExtensionRegistry()
.getConfigurationElementsFor(CHECKER_EP_ID);
Expand All @@ -323,6 +347,7 @@ public static boolean isCheckerIdContributor(String checkerId) {
isCheckerIdContributor = true;
}
}
LOGGER.exiting(CLASS, method);
return isCheckerIdContributor;
}

Expand All @@ -342,11 +367,23 @@ public static boolean isCheckerIdContributor(String checkerId) {
*/
public static CheckerContainer getChecker(String checkerId)
throws NullContributionException, CoreException {
final String method = "getChecker";
LOGGER.entering(CLASS, checkerId);
final IConfigurationElement[] checkerContributors = Platform.getExtensionRegistry()
.getConfigurationElementsFor(CHECKER_EP_ID);
for (IConfigurationElement checkerContributor : checkerContributors) {
for (IConfigurationElement checkerElement : checkerContributor
.getChildren(CheckerService.CHECKER_EP_ELEMENT_CHECK)) {
boolean found = false;
int checkerContributorsCounter = 0;
IConfigurationElement checkerContributor;
int checkerElementCounter = 0;
IConfigurationElement checkerElement;
CheckerContainer cherckerFound = null;
while (checkerContributors.length > checkerContributorsCounter && !found) {
checkerContributor = checkerContributors[checkerContributorsCounter];
while (checkerContributor.getChildren(
CheckerService.CHECKER_EP_ELEMENT_CHECK).length > checkerElementCounter
&& !found) {
checkerElement = checkerContributor.getChildren(
CheckerService.CHECKER_EP_ELEMENT_CHECK)[checkerElementCounter];
if (checkerElement.getAttribute(CHECKER_EP_ELEMENT_CHECK_ATT_ID)
.equals(checkerId)) {
// 1.1. Get the checker name
Expand All @@ -367,20 +404,29 @@ public static CheckerContainer getChecker(String checkerId)
isMetric = false;
} else {
isMetric = Boolean
.valueOf(checkerElement
.getAttribute(CHECKER_EP_ELEMENT_CHECK_ATT_ISMETRIC))
.valueOf(checkerElement.getAttribute(
CHECKER_EP_ELEMENT_CHECK_ATT_ISMETRIC))
.booleanValue();
}
// 1.6 Create the Checker

return new CheckerContainer(checkerId, checkerName, language, checkerClass,
checkerElement, isMetric);
cherckerFound = new CheckerContainer(checkerId, checkerName, language,
checkerClass, checkerElement, isMetric);
found = true;

}
checkerElementCounter++;
}
checkerContributorsCounter++;
}
if (found) {
LOGGER.exiting(CLASS, method, cherckerFound);
return cherckerFound;
}
throw new NullContributionException(
final NullContributionException exception = new NullContributionException(
"Impossible to find " + checkerId + " checker id in contributors.");
LOGGER.throwing(CLASS, method, exception);
throw exception;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
Expand Down Expand Up @@ -42,6 +43,11 @@ public final class LanguageService {
/** Language extension point's file extension element's attribute name */
public static final String LANGUAGE_EP_EL_FILEEXTENSION_ATT_NAME = "name";

/** The logger **/
private static final Logger LOGGER = Logger.getLogger(LanguageService.class.getName());
/** Class name **/
private static final String CLASS = LanguageService.class.getName();

/**
* Utils class default constructor removal.
*/
Expand All @@ -53,6 +59,8 @@ private LanguageService() {
* @return languages contributing to {@link #LANGUAGE_EP_ID}.
*/
public static List<LanguageContainer> getLanguages() {
final String method = "getLanguages";
LOGGER.entering(CLASS, method);
final List<LanguageContainer> languages = new ArrayList<>();
final IConfigurationElement[] languagesContributors = Platform.getExtensionRegistry()
.getConfigurationElementsFor(LanguageService.LANGUAGE_EP_ID);
Expand All @@ -73,7 +81,7 @@ public static List<LanguageContainer> getLanguages() {
language.getAttribute(LanguageService.LANGUAGE_EP_EL_LANGUAGE_ATT_NAME),
fileExtensions));
}

LOGGER.exiting(CLASS, method, languages);
return languages;

}
Expand All @@ -85,6 +93,8 @@ public static List<LanguageContainer> getLanguages() {
* {@link #LANGUAGE_EP_ID}
*/
public static boolean isLanguageIdContributor(String languageId) {
final String method = "isLanguageIdContributor";
LOGGER.entering(CLASS, method, languageId);
boolean isLanguageIdContributor = false;
final IConfigurationElement[] languagesContributors = Platform.getExtensionRegistry()
.getConfigurationElementsFor(LanguageService.LANGUAGE_EP_ID);
Expand All @@ -94,6 +104,7 @@ public static boolean isLanguageIdContributor(String languageId) {
isLanguageIdContributor = true;
}
}
LOGGER.exiting(CLASS, method);
return isLanguageIdContributor;
}

Expand All @@ -108,6 +119,8 @@ public static boolean isLanguageIdContributor(String languageId) {
*/
public static LanguageContainer getLanguage(String languageId)
throws NullContributionException {
final String method = "getLanguage";
LOGGER.entering(CLASS, method, languageId);
final IConfigurationElement[] languagesContributors = Platform.getExtensionRegistry()
.getConfigurationElementsFor(LanguageService.LANGUAGE_EP_ID);
for (IConfigurationElement language : languagesContributors) {
Expand All @@ -124,6 +137,7 @@ public static LanguageContainer getLanguage(String languageId)
fileExtensions.add(fileExtension);
}
}
LOGGER.exiting(CLASS, method);
return new LanguageContainer(
language.getAttribute(
LanguageService.LANGUAGE_EP_EL_LANGUAGE_ATT_ID),
Expand All @@ -132,9 +146,10 @@ public static LanguageContainer getLanguage(String languageId)
fileExtensions);
}
}
throw new NullContributionException(
final NullContributionException exception = new NullContributionException(
"Impossible to find " + languageId + " in analyzer contributors.");

LOGGER.throwing(CLASS, method, exception);
throw exception;
}

/**
Expand All @@ -144,6 +159,8 @@ public static LanguageContainer getLanguage(String languageId)
* from <code>languagesIds</code> contribution.
*/
public static List<LanguageContainer> getLanguages(List<String> languagesIds) {
final String method = "getLanguages";
LOGGER.entering(CLASS, method, languagesIds);
final List<LanguageContainer> languages = new ArrayList<>();
final IConfigurationElement[] languagesContributors = Platform.getExtensionRegistry()
.getConfigurationElementsFor(LanguageService.LANGUAGE_EP_ID);
Expand All @@ -165,7 +182,7 @@ public static List<LanguageContainer> getLanguages(List<String> languagesIds) {
LanguageService.LANGUAGE_EP_EL_LANGUAGE_ATT_NAME, fileExtensions));
}
}

LOGGER.exiting(CLASS, method, languages);
return languages;
}

Expand All @@ -174,12 +191,15 @@ public static List<LanguageContainer> getLanguages(List<String> languagesIds) {
* {@link #LANGUAGE_EP_ID}.
*/
public static List<String> getLanguagesIds() {
final String method = "getLanguagesIds";
LOGGER.entering(CLASS, method);
final List<String> languagesIds = new ArrayList<>();
final IConfigurationElement[] languagesContributors = Platform.getExtensionRegistry()
.getConfigurationElementsFor(LanguageService.LANGUAGE_EP_ID);
for (IConfigurationElement language : languagesContributors) {
languagesIds.add(language.getAttribute(LanguageService.LANGUAGE_EP_EL_LANGUAGE_ATT_ID));
}
LOGGER.exiting(CLASS, method, languagesIds);
return languagesIds;
}

Expand Down
Loading

0 comments on commit 9af8af5

Please sign in to comment.