Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/checkstyle-checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@
SuppressWarnings, FunctionalInterface, NoSuchMethodException,
InvocationTargetException, IllegalAccessException"/>
</module>
<module name="CyclomaticComplexity">
<property name="switchBlockAsSingleDecisionPoint" value="true"/>
</module>
<module name="NPathComplexity"/>

<!-- Misc -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,67 +228,16 @@ public final <T extends IResource> void handleBuildSelection(final Collection<T>
boolean backgroundFullBuild = CheckstylePluginPrefs
.getBoolean(CheckstylePluginPrefs.PREF_BACKGROUND_FULL_BUILD);

List<FileSet> enabledFileSets = configuration.getFileSets().stream()
.filter(FileSet::isEnabled)
.toList();

List<IFile> files = resources.stream()
.filter(resource -> resource instanceof IFile)
.map(resource -> (IFile) resource)
.toList();

//
// Build a set of auditors from the file sets of this project
// configuration.
// File sets that share the same check configuration merge into
// one Auditor.
//
Map<ICheckConfiguration, Auditor> audits = new HashMap<>();
Map<ICheckConfiguration, Auditor> audits = resolveAudits(resources, configuration, project);

try {
for (FileSet fileSet : enabledFileSets) {
ICheckConfiguration checkConfig = fileSet.getCheckConfig();
if (checkConfig == null) {
throw new CheckstylePluginException(
NLS.bind(Messages.errorNoCheckConfig, project.getName()));
}

Auditor audit = audits.computeIfAbsent(checkConfig, Auditor::new);

// check which files belong to the file set
List<IFile> filesInFileset = files.stream()
.filter(fileSet::includesFile)
.toList();

for (IFile file : filesInFileset) {
boolean hasCompileErrors = IMarker.SEVERITY_ERROR == file.findMaxProblemSeverity(
IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_ZERO);

// remove markers on this file
file.deleteMarkers(CheckstyleMarker.MARKER_ID, false, IResource.DEPTH_ZERO);

// avoid checkstyle parser errors being shown
if (hasCompileErrors) {
continue;
}

audit.addFile(file);

// remove markers from package to prevent
// packagehtml messages from accumulatin
file.getParent().deleteMarkers(CheckstyleMarker.MARKER_ID, false,
IResource.DEPTH_ZERO);
}
}

// run all auditors
for (Auditor audit : audits.values()) {
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}

if (backgroundFullBuild && kind == FULL_BUILD) {

AuditorJob job = new AuditorJob(project, audit);
job.schedule();
} else {
Expand All @@ -302,6 +251,60 @@ public final <T extends IResource> void handleBuildSelection(final Collection<T>
}
}

/**
* Build a set of auditors from the file sets of this project
* configuration.
* File sets that share the same check configuration merge into
* one Auditor.
*/
private <T extends IResource> Map<ICheckConfiguration, Auditor> resolveAudits(
Collection<T> resources, IProjectConfiguration configuration,
IProject project) throws CoreException {
List<FileSet> enabledFileSets = configuration.getFileSets().stream()
.filter(FileSet::isEnabled)
.toList();

List<IFile> files = resources.stream()
.filter(resource -> resource instanceof IFile)
.map(resource -> (IFile) resource)
.toList();
Map<ICheckConfiguration, Auditor> audits = new HashMap<>();
for (FileSet fileSet : enabledFileSets) {
ICheckConfiguration checkConfig = fileSet.getCheckConfig();
if (checkConfig == null) {
throw new CoreException(new Status(IStatus.ERROR, CheckstylePlugin.PLUGIN_ID,
NLS.bind(Messages.errorNoCheckConfig, project.getName())));
}

Auditor audit = audits.computeIfAbsent(checkConfig, Auditor::new);

// check which files belong to the file set
List<IFile> filesInFileset = files.stream()
.filter(fileSet::includesFile)
.toList();

for (IFile file : filesInFileset) {
boolean hasCompileErrors = IMarker.SEVERITY_ERROR == file.findMaxProblemSeverity(
IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_ZERO);

// remove markers on this file
file.deleteMarkers(CheckstyleMarker.MARKER_ID, false, IResource.DEPTH_ZERO);

// avoid checkstyle parser errors being shown
if (hasCompileErrors) {
continue;
}

audit.addFile(file);

// remove markers from package to prevent
// packagehtml messages from accumulatin
file.getParent().deleteMarkers(CheckstyleMarker.MARKER_ID, false, IResource.DEPTH_ZERO);
}
}
return audits;
}

/**
* Get the files for the build by analyzing the resource delta.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;

import org.eclipse.core.runtime.IPath;
import org.eclipse.equinox.security.storage.EncodingUtils;
import org.eclipse.equinox.security.storage.ISecurePreferences;
Expand Down Expand Up @@ -100,7 +99,6 @@ public CheckstyleConfigurationFile getCheckstyleConfiguration(
byte[] configurationFileData = null;

try {

System.setProperty(KEY_MAX_REDIRECTS, "3");

final URLConnection connection = data.getResolvedConfigFileURL().openConnection();
Expand Down Expand Up @@ -128,15 +126,8 @@ public CheckstyleConfigurationFile getCheckstyleConfiguration(

data.setCheckConfigFileBytes(configurationFileData);

// get the properties bundle
Optional<byte[]> additionalPropertiesBytes = Optional.empty();
if (originalFileSuccess) {
additionalPropertiesBytes = getAdditionPropertiesBundleBytes(
data.getResolvedConfigFileURL());
} else if (useCacheFile) {
additionalPropertiesBytes = getBytesFromCacheBundleFile(checkConfiguration);
}

Optional<byte[]> additionalPropertiesBytes = getPropertiesBundle(originalFileSuccess,
useCacheFile, data, checkConfiguration);
additionalPropertiesBytes.ifPresent(data::setAdditionalPropertyBundleBytes);

// get the property resolver
Expand Down Expand Up @@ -172,6 +163,17 @@ public CheckstyleConfigurationFile getCheckstyleConfiguration(
return data;
}

private Optional<byte[]> getPropertiesBundle(boolean originalFileSuccess, boolean useCacheFile,
CheckstyleConfigurationFile data, ICheckConfiguration checkConfiguration) {
if (originalFileSuccess) {
return getAdditionPropertiesBundleBytes(data.getResolvedConfigFileURL());
}
if (useCacheFile) {
return getBytesFromCacheBundleFile(checkConfiguration);
}
return Optional.empty();
}

@Override
protected URL resolveLocation(ICheckConfiguration checkConfiguration) throws IOException {
return new URL(checkConfiguration.getLocation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,9 @@ private static List<ConfigPropertyMetadata> processProperties(Element moduleElem
}

// get explicit enumeration option values
for (Element optionEl : enumEl
.elements(XMLTags.PROPERTY_VALUE_OPTIONS_TAG)) {
property.getPropertyEnumeration().add(optionEl.attributeValue(XMLTags.VALUE_TAG));
}
enumEl.elements(XMLTags.PROPERTY_VALUE_OPTIONS_TAG).stream()
.map(optionEl -> optionEl.attributeValue(XMLTags.VALUE_TAG))
.forEach(property.getPropertyEnumeration()::add);
}
}
return properties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

package net.sf.eclipsecs.core.transformer.ctransformerclasses;

import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;

import net.sf.eclipsecs.core.transformer.AbstractCTransformationClass;
Expand All @@ -40,36 +42,31 @@ public FormatterConfiguration transformRule() {
}
final StringTokenizer token = new StringTokenizer(tokens, ", ");

String option = getAttribute("option");
if (option == null || "eol".equals(option)) {
option = "end_of_line";
} else if ("nl".equals(option) || "nlow".equals(option)) {
option = "next_line";
}
String option = switch (getAttribute("option")) {
case null -> "end_of_line";
case "eol" -> "end_of_line";
case "nl", "nlow" -> "next_line";
case String s -> s;
};

while (token.hasMoreTokens()) {
String tok = token.nextToken();
if ("CLASS_DEF".equals(tok)) {
userFormatterSetting("brace_position_for_anonymous_type_declaration", option);
userFormatterSetting("brace_position_for_enum_constant", option);
userFormatterSetting("brace_position_for_enum_declaration", option);
userFormatterSetting("brace_position_for_type_declaration", option);
userFormatterSetting("brace_position_for_annotation_type_declaration", option);
} else if ("INTERFACE_DEF".equals(tok)) {
userFormatterSetting("brace_position_for_annotation_type_declaration", option);
userFormatterSetting("brace_position_for_type_declaration", option);
} else if ("CTOR_DEF".equals(tok)) {
userFormatterSetting("brace_position_for_constructor_declaration", option);
} else if ("METHOD_DEF".equals(tok)) {
userFormatterSetting("brace_position_for_method_declaration", option);
} else if ("LITERAL_DO".equals(tok) || "LITERAL_ELSE".equals(tok) || "LITERAL_FOR".equals(tok)
|| "LITERAL_IF".equals(tok) || "LITERAL_WHILE".equals(tok)
|| "LITERAL_CATCH".equals(tok) || "LITERAL_FINALLY".equals(tok)
|| "LITERAL_TRY".equals(tok)) {
userFormatterSetting("brace_position_for_block", option);
} else if ("LITERAL_SWITCH".equals(tok)) {
userFormatterSetting("brace_position_for_switch", option);
}
List<String> settings = switch (token.nextToken()) {
case "CLASS_DEF" -> List.of("brace_position_for_anonymous_type_declaration",
"brace_position_for_enum_constant",
"brace_position_for_enum_declaration",
"brace_position_for_type_declaration",
"brace_position_for_annotation_type_declaration");
case "INTERFACE_DEF" -> List.of(
"brace_position_for_annotation_type_declaration",
"brace_position_for_type_declaration");
case "CTOR_DEF" -> List.of("brace_position_for_constructor_declaration");
case "METHOD_DEF" -> List.of("brace_position_for_method_declaration");
case "LITERAL_DO", "LITERAL_ELSE", "LITERAL_FOR", "LITERAL_IF", "LITERAL_WHILE", "LITERAL_CATCH",
"LITERAL_FINALLY", "LITERAL_TRY" -> List.of("brace_position_for_block");
case "LITERAL_SWITCH" -> List.of("brace_position_for_switch");
default -> Collections.emptyList();
};
settings.forEach(setting -> userFormatterSetting(setting, option));
}
return getFormatterSetting();
}
Expand Down
Loading
Loading