Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No guava dependencies #197

Merged
merged 7 commits into from
Jun 29, 2020
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ atlassian-ide-plugin.xml
.classpath
.project
.settings/
.java-version
.DS_Store
20 changes: 13 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
<name>Jędrzej Pluciński</name>
<email>[email protected]</email>
</developer>
<developer>
<id>krystian.panek</id>
<name>Krystian Panek</name>
<email>[email protected]</email>
</developer>
</developers>

<scm>
Expand Down Expand Up @@ -131,6 +136,12 @@
<type>sonar-plugin</type>
<version>${sonar.java.plugin}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.sonarsource.sslr-squid-bridge</groupId>
Expand Down Expand Up @@ -159,11 +170,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.2-jre</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down Expand Up @@ -293,8 +299,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>11</source>
Copy link
Author

@pun-ky pun-ky May 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as of we are mentioning that most recent version of our plugin requires Java 11, to be able to write code in Java 11 I decided to update it also

<target>11</target>
</configuration>
</plugin>
<plugin>
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/cognifide/aemrules/AemRulesSonarPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@
import com.cognifide.aemrules.htl.Constants;
import com.cognifide.aemrules.htl.HtlProfile;
import com.cognifide.aemrules.htl.HtlSensor;
import com.google.common.collect.ImmutableList;
import org.sonar.api.Plugin;
import org.sonar.api.config.PropertyDefinition;
import org.sonar.api.resources.Qualifiers;

import java.util.List;

public class AemRulesSonarPlugin implements Plugin {

private static ImmutableList<PropertyDefinition> pluginProperties() {
return ImmutableList.of(
private static List<PropertyDefinition> pluginProperties() {
pun-ky marked this conversation as resolved.
Show resolved Hide resolved
return List.of(
PropertyDefinition.builder(Constants.FILE_EXTENSIONS_PROP_KEY)
.name("File suffixes")
.description("List of file suffixes that will be scanned.")
Expand Down
30 changes: 13 additions & 17 deletions src/main/java/com/cognifide/aemrules/extensions/RulesLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
package com.cognifide.aemrules.extensions;

import com.cognifide.aemrules.metadata.Metadata;
import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Resources;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.annotation.CheckForNull;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -52,20 +51,17 @@ public class RulesLoader {

private static final String RULE_DESCRIPTION_EXTENSION = "md";

private static final Function<Class<?>, RuleParamType> TYPE_FOR_CLASS = Functions.forMap(
ImmutableMap.<Class<?>, RuleParamType>builder()
.put(Integer.class, RuleParamType.INTEGER)
.put(int.class, RuleParamType.INTEGER)
.put(Float.class, RuleParamType.FLOAT)
.put(float.class, RuleParamType.FLOAT)
.put(Boolean.class, RuleParamType.BOOLEAN)
.put(boolean.class, RuleParamType.BOOLEAN)
.build(),
RuleParamType.STRING
private static final Map<Class<?>, RuleParamType> TYPE_FOR_CLASS = Map.of(
Integer.class, RuleParamType.INTEGER,
int.class, RuleParamType.INTEGER,
Float.class, RuleParamType.FLOAT,
float.class, RuleParamType.FLOAT,
Boolean.class, RuleParamType.BOOLEAN,
boolean.class, RuleParamType.BOOLEAN
);

private static RuleParamType guessType(Class<?> type) {
return TYPE_FOR_CLASS.apply(type);
return TYPE_FOR_CLASS.getOrDefault(type, RuleParamType.STRING);
}

public <T> void load(RulesDefinition.NewExtendedRepository repo, List<Class<? extends T>> annotatedClasses) {
Expand Down Expand Up @@ -123,8 +119,8 @@ private String loadResource(String resourceFolder, String ruleKey, String fileEx
String result = null;
try {
String path = String.format("/%s/%s.%s", resourceFolder, ruleKey, fileExtension);
URL url = Resources.getResource(RulesLoader.class, path);
result = Resources.toString(url, StandardCharsets.UTF_8);
URL url = getClass().getResource(path);
result = IOUtils.toString(url, StandardCharsets.UTF_8);
} catch (IOException | IllegalArgumentException e) {
LOG.error("Cannot read resource file.", e);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/cognifide/aemrules/htl/HtlChecks.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
package com.cognifide.aemrules.htl;

import com.cognifide.aemrules.htl.api.HtlCheck;
import com.google.common.collect.Sets;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -34,7 +34,7 @@ public class HtlChecks {

private final CheckFactory checkFactory;

private Set<Checks<HtlCheck>> checksByRepository = Sets.newHashSet();
private final Set<Checks<HtlCheck>> checksByRepository = new HashSet<>();

private HtlChecks(CheckFactory checkFactory) {
this.checkFactory = checkFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@

import com.cognifide.aemrules.htl.api.ParsingErrorRule;
import com.cognifide.aemrules.htl.rules.HtlCheckClasses;
import com.google.common.base.Throwables;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.concurrent.CancellationException;

import com.cognifide.aemrules.utils.Throwables;
import org.apache.sling.scripting.sightly.compiler.SightlyCompilerException;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.rule.CheckFactory;
Expand All @@ -41,7 +42,7 @@ public abstract class HtlFilesAnalyzer {

private static final Logger LOGGER = Loggers.get(HtlFilesAnalyzer.class);
protected final HtlChecks checks;
private RuleKey parsingErrorRuleKey;
private final RuleKey parsingErrorRuleKey;

public HtlFilesAnalyzer(CheckFactory checkFactory) {
this.checks = HtlChecks.createHtlCheck(checkFactory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
import com.cognifide.aemrules.metadata.Metadata;
import com.cognifide.aemrules.tag.Tags;
import com.cognifide.aemrules.version.AemVersion;
import com.google.common.collect.ImmutableList;
import org.apache.commons.lang3.StringUtils;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.html.node.Attribute;
import org.sonar.plugins.html.node.TagNode;

import java.util.List;
import java.util.Optional;

@Rule(
Expand All @@ -51,7 +51,7 @@ public class AvoidExtraSlyTagsCheck extends AbstractHtlCheck {

private static final String SLY_TAG = "sly";

private static final ImmutableList SLY_ATTRIBUTES = ImmutableList.of("data-sly-use",
private static final List<String> SLY_ATTRIBUTES = List.of("data-sly-use",
"data-sly-test",
"data-sly-call");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
import com.cognifide.aemrules.metadata.Metadata;
import com.cognifide.aemrules.tag.Tags;
import com.cognifide.aemrules.version.AemVersion;
import com.google.common.collect.ImmutableMultimap;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.html.node.TagNode;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

@Rule(
Expand All @@ -52,29 +53,29 @@ public class DefaultDisplayContextCheck extends AbstractHtlCheck {

private static final String VIOLATION_MESSAGE = "Explicitly using default display context, please remove display context from expression";

private static final ImmutableMultimap<String, String> TAG_ATTRIBUTE_MAPPING = ImmutableMultimap.<String, String>builder()
.put("form", "action")
.put("blockquote", "cite")
.put("del", "cite")
.put("ins", "cite")
.put("q", "cite")
.put("object", "data")
.put("button", "formaction")
.put("input", "formaction")
.put("a", "href")
.put("area", "href")
.put("link", "href")
.put("base", "href")
.put("html", "manifest")
.put("video", "poster")
.put("audio", "src")
.put("embed", "src")
.put("iframe", "src")
.put("img", "src")
.put("input", "src")
.put("script", "src")
.put("source", "src")
.put("track", "src").build();
private static final Map<String, List<String>> TAG_ATTRIBUTE_MAPPING = Map.ofEntries(
Map.entry("a", List.of("href")),
Map.entry("area", List.of("href")),
Map.entry("audio", List.of("src")),
Map.entry("base", List.of("href")),
Map.entry("blockquote", List.of("cite")),
Map.entry("button", List.of("formaction")),
Map.entry("del", List.of("cite")),
Map.entry("embed", List.of("src")),
Map.entry("form", List.of("action")),
Map.entry("html", List.of("manifest")),
Map.entry("img", List.of("src")),
Map.entry("ins", List.of("cite")),
Map.entry("input", List.of("formaction", "src")),
Map.entry("iframe", List.of("src")),
Map.entry("link", List.of("href")),
Map.entry("q", List.of("cite")),
Map.entry("object", List.of("data")),
Map.entry("video", List.of("poster")),
Map.entry("script", List.of("src")),
Map.entry("source", List.of("src")),
Map.entry("track", List.of("src"))
);

@Override
public void startElement(TagNode node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

import com.cognifide.aemrules.metadata.Metadata;
import com.cognifide.aemrules.tag.Tags;
import com.cognifide.aemrules.utils.Comparables;
import com.cognifide.aemrules.version.AemVersion;
import com.google.common.collect.Ordering;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -53,7 +53,7 @@ public class HtlAttributesShouldBeAtTheEndCheck extends AbstractHtlCheck {
static final String RULE_MESSAGE = "Always place HTL attributes at the end";

private static boolean isOrdered(Iterable<Integer> list) {
return Ordering.natural().isOrdered(list);
return Comparables.isOrdered(list);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.cognifide.aemrules.metadata.Metadata;
import com.cognifide.aemrules.tag.Tags;
import com.cognifide.aemrules.version.AemVersion;
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -52,9 +51,8 @@ public class HtlCommentsCheck extends AbstractHtlCheck {

static final String RULE_MESSAGE = "Always use HTL style of comments";

private static final List<String> SSI_ELEMENTS = Lists
.newArrayList("comment", "config", "echo", "exec", "fsize", "flastmod", "include", "printenv",
"set");
private static final List<String> SSI_ELEMENTS = List.of("comment", "config", "echo", "exec", "fsize", "flastmod",
"include", "printenv", "set");

private static final Pattern CONDITIONAL_COMMENT_PATTERN = Pattern
.compile("<!--\\[.*]-->");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.cognifide.aemrules.metadata.Metadata;
import com.cognifide.aemrules.tag.Tags;
import com.cognifide.aemrules.version.AemVersion;
import com.google.common.collect.ImmutableList;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.scripting.sightly.compiler.expression.Expression;
import org.sonar.check.Priority;
Expand Down Expand Up @@ -55,10 +54,12 @@ public class UseSlyTagsOverRedundantMarkupCheck extends AbstractHtlCheck {

private static final String SLY_TAG = "sly";

private static final ImmutableList SLY_ATTRIBUTES = ImmutableList.of("data-sly-use",
private static final List<String> SLY_ATTRIBUTES = List.of(
"data-sly-use",
"data-sly-include",
"data-sly-resource",
"data-sly-call");
"data-sly-call"
);

@Override
public void startHtlElement(List<Expression> expressions, TagNode node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package com.cognifide.aemrules.htl.lex;

import com.google.common.collect.ImmutableSet;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.List;
Expand All @@ -33,11 +32,11 @@

class ElementTokenizer extends AbstractTokenizer<List<Node>> {

private static EndQNameMatcher endQNameMatcher = new EndQNameMatcher();
private static final EndQNameMatcher END_Q_NAME_MATCHER = new EndQNameMatcher();

private static EndTokenMatcher endTokenMatcher = new EndTokenMatcher();
private static final EndTokenMatcher END_TOKEN_MATCHER = new EndTokenMatcher();

private static EndUnquotedAttributeMatcher endUnquotedAttributeMatcher = new EndUnquotedAttributeMatcher();
private static final EndUnquotedAttributeMatcher END_UNQUOTED_ATTRIBUTE_MATCHER = new EndUnquotedAttributeMatcher();

public ElementTokenizer(String startToken, String endToken) {
super(startToken, endToken);
Expand Down Expand Up @@ -81,7 +80,7 @@ private static void handleBeforeAttributeValue(CodeReader codeReader, TagNode el
codeReader.pop();
attribute.setQuoteChar((char) ch);
} else {
codeReader.popTo(endUnquotedAttributeMatcher, sbValue);
codeReader.popTo(END_UNQUOTED_ATTRIBUTE_MATCHER, sbValue);
attribute.setValue(sbValue.toString().trim());
}
}
Expand All @@ -90,15 +89,15 @@ private static void handleBeforeAttributeValue(CodeReader codeReader, TagNode el
private static void handleBeforeAttributeName(CodeReader codeReader, TagNode element) {
Attribute attribute;
StringBuilder sbQName = new StringBuilder();
codeReader.popTo(endQNameMatcher, sbQName);
codeReader.popTo(END_Q_NAME_MATCHER, sbQName);
attribute = new Attribute(sbQName.toString().trim());
attribute.setLine(codeReader.getLinePosition() + element.getStartLinePosition() - 1);
element.getAttributes().add(attribute);
}

private static void handleBeforeNodeName(CodeReader codeReader, TagNode element) {
StringBuilder sbNodeName = new StringBuilder();
codeReader.popTo(endTokenMatcher, sbNodeName);
codeReader.popTo(END_TOKEN_MATCHER, sbNodeName);
element.setNodeName(sbNodeName.toString());
}

Expand Down Expand Up @@ -196,7 +195,7 @@ public boolean match(int character) {

private static final class EndUnquotedAttributeMatcher implements EndMatcher {

private static final Set<Character> FORBIDDEN = ImmutableSet.of(
private static final Set<Character> FORBIDDEN = Set.of(
'"',
'\'',
'=',
Expand Down
Loading