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 5 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ atlassian-ide-plugin.xml
.classpath
.project
.settings/
.java-version
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 @@ -21,8 +21,8 @@

import com.cognifide.aemrules.metadata.Metadata;
import com.cognifide.aemrules.tag.Tags;
import com.cognifide.aemrules.utils.MultiMap;
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;
Expand Down Expand Up @@ -52,35 +52,36 @@ 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 MultiMap<String, String> TAG_ATTRIBUTE_MAPPING = MultiMap.builder(m -> {
m.add("form", "action");
m.add("blockquote", "cite");
m.add("del", "cite");
m.add("ins", "cite");
m.add("q", "cite");
m.add("object", "data");
m.add("button", "formaction");
m.add("input", "formaction");
m.add("a", "href");
m.add("area", "href");
m.add("link", "href");
m.add("base", "href");
m.add("html", "manifest");
m.add("video", "poster");
m.add("audio", "src");
m.add("embed", "src");
m.add("iframe", "src");
m.add("img", "src");
m.add("input", "src");
m.add("script", "src");
m.add("source", "src");
m.add("track", "src");
});

@Override
public void startElement(TagNode node) {
String nodeName = node.getNodeName();
if (TAG_ATTRIBUTE_MAPPING.containsKey(nodeName)) {
Collection<String> supportedAttributes = TAG_ATTRIBUTE_MAPPING.get(nodeName);
Collection<String> supportedAttributes = TAG_ATTRIBUTE_MAPPING.getAll(nodeName);
node.getAttributes().stream()
.filter(attribute -> supportedAttributes.contains(attribute.getName()))
.filter(a -> CONTEXT_URI_DEFINITION.matcher(a.getValue()).find())
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 endQNameMatcher = new EndQNameMatcher();
pun-ky marked this conversation as resolved.
Show resolved Hide resolved

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

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

public ElementTokenizer(String startToken, String endToken) {
super(startToken, endToken);
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import com.cognifide.aemrules.htl.checks.SlyElementsAreAutomaticallyUnwrappedCheck;
import com.cognifide.aemrules.htl.checks.UseMostRestrictiveHtlContextCheck;
import com.cognifide.aemrules.htl.checks.UseSlyTagsOverRedundantMarkupCheck;
import com.google.common.collect.ImmutableList;
import org.sonar.check.Rule;

import java.util.List;
Expand All @@ -50,7 +49,7 @@ public final class HtlCheckClasses {

public static final String REPOSITORY_NAME = "AEM Rules";

private static final List<Class<? extends HtlCheck>> CLASSES = ImmutableList.of(
private static final List<Class<? extends HtlCheck>> CLASSES = List.of(
ParsingErrorCheck.class,
HtlCommentsCheck.class,
AvoidExtraSlyTagsCheck.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
package com.cognifide.aemrules.htl.visitors;

import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -42,7 +42,7 @@ public class HtlScanner {

private static final ExpressionParser expressionParser = new ExpressionParser();

private final List<DefaultHtlVisitor> checkVisitors = Lists.newArrayList();
private final List<DefaultHtlVisitor> checkVisitors = new ArrayList<>();
private static void scanElementTag(DefaultHtlVisitor visitor, TagNode node) {
if (!node.isEndElement()) {
visitor.startElement(node);
Expand Down
Loading