Skip to content
Merged
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 @@ -686,6 +686,9 @@
<property name="severity" value="ignore"/>
</module>
<module name="OuterTypeFilename"/>
<module name="TodoComment">
<property name="format" value="(TODO)|(FIXME)" />
</module>
<module name="UncommentedMain">
<property name="excludedClasses" value="\.(Main|JavadocPropertiesGenerator)$"/>
</module>
Expand Down
3 changes: 3 additions & 0 deletions config/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@
<suppress id="regexpHeader" files="[/\\]net.sf.eclipsecs.ui[/\\]src[/\\]net[/\\]sf[/\\]eclipsecs[/\\]ui[/\\]util[/\\]table[/\\]ITableComparableProvider.java" />
<suppress id="regexpHeader" files="[/\\]net.sf.eclipsecs.ui[/\\]src[/\\]net[/\\]sf[/\\]eclipsecs[/\\]ui[/\\]util[/\\]table[/\\]ITableSettingsProvider.java" />

<!-- code is copied from ant -->
<suppress checks="TodoComment" files="PropertyUtil.java"/>

<!-- temporal suppression due to leak -->
<suppress checks="JavadocVariable"
files="XmlProfileWriter.java"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//============================================================================
//
// Copyright (C) 2003-2023 the original author or authors.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
//============================================================================

package net.sf.eclipsecs.core.config;

import java.util.Map;

import org.dom4j.Element;

/**
* Utility for serializing check configurations to XML.
*/
public final class CheckConfigurationXmlWriter {

private CheckConfigurationXmlWriter() {
}

/**
* Writes a check configuration as an XML child element under the given parent.
*
* @param parentElement
* the parent XML element
* @param checkConfig
* the check configuration to write
* @param location
* the resolved location string
* @param elementName
* the XML element name to use
*/
public static void writeCheckConfiguration(Element parentElement, ICheckConfiguration checkConfig,
String location, String elementName) {
Element configEl = parentElement.addElement(elementName);
configEl.addAttribute(XMLTags.NAME_TAG, checkConfig.getName());
configEl.addAttribute(XMLTags.LOCATION_TAG, location);
configEl.addAttribute(XMLTags.TYPE_TAG, checkConfig.getType().getInternalName());
if (checkConfig.getDescription() != null) {
configEl.addAttribute(XMLTags.DESCRIPTION_TAG, checkConfig.getDescription());
}
for (ResolvableProperty prop : checkConfig.getResolvableProperties()) {
Element propEl = configEl.addElement(XMLTags.PROPERTY_TAG);
propEl.addAttribute(XMLTags.NAME_TAG, prop.getPropertyName());
propEl.addAttribute(XMLTags.VALUE_TAG, prop.getValue());
}
for (Map.Entry<String, String> entry : checkConfig.getAdditionalData().entrySet()) {
Element addEl = configEl.addElement(XMLTags.ADDITIONAL_DATA_TAG);
addEl.addAttribute(XMLTags.NAME_TAG, entry.getKey());
addEl.addAttribute(XMLTags.VALUE_TAG, entry.getValue());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.dom4j.Document;
Expand Down Expand Up @@ -329,28 +328,8 @@ private static Document createCheckConfigurationsDocument(
continue;
}

Element configEl = root.addElement(XMLTags.CHECK_CONFIG_TAG);
configEl.addAttribute(XMLTags.NAME_TAG, config.getName());
configEl.addAttribute(XMLTags.LOCATION_TAG, config.getLocation());
configEl.addAttribute(XMLTags.TYPE_TAG, config.getType().getInternalName());
if (config.getDescription() != null) {
configEl.addAttribute(XMLTags.DESCRIPTION_TAG, config.getDescription());
}

// Write resolvable properties
for (ResolvableProperty prop : config.getResolvableProperties()) {

Element propEl = configEl.addElement(XMLTags.PROPERTY_TAG);
propEl.addAttribute(XMLTags.NAME_TAG, prop.getPropertyName());
propEl.addAttribute(XMLTags.VALUE_TAG, prop.getValue());
}

for (Map.Entry<String, String> entry : config.getAdditionalData().entrySet()) {

Element addEl = configEl.addElement(XMLTags.ADDITIONAL_DATA_TAG);
addEl.addAttribute(XMLTags.NAME_TAG, entry.getKey());
addEl.addAttribute(XMLTags.VALUE_TAG, entry.getValue());
}
CheckConfigurationXmlWriter.writeCheckConfiguration(root, config, config.getLocation(),
XMLTags.CHECK_CONFIG_TAG);
}
return doc;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@

package net.sf.eclipsecs.core.jobs;

import java.io.FileNotFoundException;
import java.util.Map;
import java.util.stream.Collectors;

import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
Expand All @@ -32,53 +33,57 @@

import net.sf.eclipsecs.core.CheckstylePlugin;
import net.sf.eclipsecs.core.Messages;
import net.sf.eclipsecs.core.transformer.FormatterConfigParser;
import net.sf.eclipsecs.core.transformer.FormatterConfiguration;
import net.sf.eclipsecs.core.transformer.FormatterTransformer;
import net.sf.eclipsecs.core.util.CheckstylePluginException;

import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;

/**
* Job who starts transforming the formatter-rules to checkstyle-settings.
*
*
*/
public class TransformFormatterRulesJob extends WorkspaceJob {

/** Selected project in workspace. */
private final IProject mProject;

/**
* Job for transforming formatter-rules to checkstyle-settings.
*
* @param project
* The current selected project in the workspace.
*/
public TransformFormatterRulesJob() {
public TransformFormatterRulesJob(final IProject project) {
super(Messages.TransformFormatterRulesJob_name);

this.mProject = project;
}

@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
SubMonitor subMonitor = SubMonitor.convert(monitor);
subMonitor.setWorkRemaining(IProgressMonitor.UNKNOWN);

// TODO this way of loading formatter profiles is very dubious, to say
// the least, refer to FormatterConfigWriter for a better API
final String workspace = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString();

final String configLocation = workspace
+ "/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs"; //$NON-NLS-1$

FormatterConfigParser parser;

try {
parser = new FormatterConfigParser(configLocation);
} catch (final FileNotFoundException ex) {
IJavaProject javaProject = JavaCore.create(mProject);
if (javaProject == null) {
return Status.CANCEL_STATUS;
}
final FormatterConfiguration rules = parser.parseRules();

if (rules == null) {
final String projectPath = mProject.getLocation().toString();

Map<String, String> formatterSettings = javaProject.getOptions(true).entrySet().stream()
.filter(entry -> entry.getKey().startsWith("org.eclipse.jdt.core.formatter."))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

if (formatterSettings.isEmpty()) {
return Status.CANCEL_STATUS;
}

try {
FormatterTransformer transformer = new FormatterTransformer();
transformer.transformRules(workspace + "/test-checkstyle.xml", rules.getFormatterSettings()); //$NON-NLS-1$
transformer.transformRules(projectPath + "/test-checkstyle.xml", formatterSettings);
} catch (CheckstylePluginException ex) {
Status status = new Status(IStatus.ERROR, CheckstylePlugin.PLUGIN_ID, IStatus.ERROR,
ex.getMessage(), ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.dom4j.Document;
Expand All @@ -44,9 +43,9 @@
import net.sf.eclipsecs.core.Messages;
import net.sf.eclipsecs.core.config.CheckConfigurationFactory;
import net.sf.eclipsecs.core.config.CheckConfigurationWorkingCopy;
import net.sf.eclipsecs.core.config.CheckConfigurationXmlWriter;
import net.sf.eclipsecs.core.config.ICheckConfiguration;
import net.sf.eclipsecs.core.config.ICheckConfigurationWorkingSet;
import net.sf.eclipsecs.core.config.ResolvableProperty;
import net.sf.eclipsecs.core.config.configtypes.BuiltInConfigurationType;
import net.sf.eclipsecs.core.config.configtypes.ProjectConfigurationType;
import net.sf.eclipsecs.core.projectconfig.filters.IFilter;
Expand Down Expand Up @@ -414,9 +413,6 @@ private Document writeProjectConfig(ProjectConfigurationWorkingCopy config)
*/
private void writeLocalConfiguration(ICheckConfiguration checkConfig, Element docRoot) {

// TODO refactor to avoid code duplication with
// GlobalCheckConfigurationWorkingSet

// don't store built-in configurations to persistence or local
// configurations
if (checkConfig.getType() instanceof BuiltInConfigurationType || checkConfig.isGlobal()) {
Expand All @@ -438,29 +434,8 @@ private void writeLocalConfiguration(ICheckConfiguration checkConfig, Element do
}
}

Element configEl = docRoot.addElement(XMLTags.CHECK_CONFIG_TAG);
configEl.addAttribute(XMLTags.NAME_TAG, checkConfig.getName());
configEl.addAttribute(XMLTags.LOCATION_TAG, location);
configEl.addAttribute(XMLTags.TYPE_TAG, checkConfig.getType().getInternalName());
if (checkConfig.getDescription() != null) {
configEl.addAttribute(XMLTags.DESCRIPTION_TAG, checkConfig.getDescription());
}

// Write resolvable properties
for (ResolvableProperty prop : checkConfig.getResolvableProperties()) {

Element propEl = configEl.addElement(XMLTags.PROPERTY_TAG);
propEl.addAttribute(XMLTags.NAME_TAG, prop.getPropertyName());
propEl.addAttribute(XMLTags.VALUE_TAG, prop.getValue());
}

// Write additional data
for (Map.Entry<String, String> entry : checkConfig.getAdditionalData().entrySet()) {

Element addEl = configEl.addElement(XMLTags.ADDITIONAL_DATA_TAG);
addEl.addAttribute(XMLTags.NAME_TAG, entry.getKey());
addEl.addAttribute(XMLTags.VALUE_TAG, entry.getValue());
}
CheckConfigurationXmlWriter.writeCheckConfiguration(docRoot, checkConfig, location,
XMLTags.CHECK_CONFIG_TAG);
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,29 @@
import net.sf.eclipsecs.core.transformer.FormatterConfiguration;

/**
* Wrapperclass for converting the checkstyle-rule FinalParameters to appropriate
* Wrapper class for converting the checkstyle-rule FinalParameters to appropriate
* eclipse-formatter-rules.
*
*/
public class FinalParametersTransformer extends AbstractCTransformationClass {
@Override
public FormatterConfiguration transformRule() {
// TODO tokens
String tokens = getAttribute("tokens");
if (tokens == null) {
tokens = "METHOD_DEF, CTOR_DEF";
}

for (String token : tokens.split("\\s*,\\s*")) {
switch (token) {
case "METHOD_DEF", "CTOR_DEF" -> useCleanupSetting("make_parameters_final", "true");
case "LITERAL_CATCH", "FOR_EACH_CLAUSE", "PATTERN_VARIABLE_DEF" ->
useCleanupSetting("make_local_variable_final", "true");
default -> {
// nothing to transform
}
}
}
useCleanupSetting("make_variable_declarations_final", "true");
useCleanupSetting("make_parameters_final", "true");
return getFormatterSetting();
}
}
Loading
Loading