aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-css-plugin/src/main/java
diff options
context:
space:
mode:
authorElena Vilchik2018-06-14 17:40:32 +0200
committerGitHub2018-06-14 17:40:32 +0200
commit6383829aa3b6b25975da1fe7c618e3f611d8c6e1 (patch)
tree25752e58f8ef71a3a3db849a987dc24a1f54e0f1 /sonar-css-plugin/src/main/java
parentb3887099d35a9d8909c00f43ca194cc02ba0b16a (diff)
downloadsonar-css-6383829aa3b6b25975da1fe7c618e3f611d8c6e1.tar.bz2
Integrate stylelint inside plugin (#42)
Diffstat (limited to 'sonar-css-plugin/src/main/java')
-rw-r--r--sonar-css-plugin/src/main/java/org/sonar/css/plugin/BundleHandler.java28
-rw-r--r--sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssPlugin.java5
-rw-r--r--sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRuleSensor.java115
-rw-r--r--sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRules.java70
-rw-r--r--sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRulesDefinition.java46
-rw-r--r--sonar-css-plugin/src/main/java/org/sonar/css/plugin/LinterCommandProvider.java28
-rw-r--r--sonar-css-plugin/src/main/java/org/sonar/css/plugin/SonarWayProfile.java8
-rw-r--r--sonar-css-plugin/src/main/java/org/sonar/css/plugin/StylelintExecution.java38
-rw-r--r--sonar-css-plugin/src/main/java/org/sonar/css/plugin/Zip.java52
-rw-r--r--sonar-css-plugin/src/main/java/org/sonar/css/plugin/bundle/CssBundleHandler.java55
-rw-r--r--sonar-css-plugin/src/main/java/org/sonar/css/plugin/bundle/package-info.java21
-rw-r--r--sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/ColorNoInvalidHex.java31
-rw-r--r--sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/CssRule.java26
-rw-r--r--sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/package-info.java21
14 files changed, 542 insertions, 2 deletions
diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/BundleHandler.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/BundleHandler.java
new file mode 100644
index 0000000..79a7d5b
--- /dev/null
+++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/BundleHandler.java
@@ -0,0 +1,28 @@
+/*
+ * SonarCSS
+ * Copyright (C) 2018-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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 3 of the License, or (at your option) any later version.
+ *
+ * This program 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 program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.css.plugin;
+
+import java.io.File;
+
+public interface BundleHandler {
+
+ void deployBundle(File deployDestination);
+
+}
diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssPlugin.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssPlugin.java
index 65e6453..2835edb 100644
--- a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssPlugin.java
+++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssPlugin.java
@@ -22,6 +22,7 @@ package org.sonar.css.plugin;
import org.sonar.api.Plugin;
import org.sonar.api.config.PropertyDefinition;
import org.sonar.api.resources.Qualifiers;
+import org.sonar.css.plugin.bundle.CssBundleHandler;
public class CssPlugin implements Plugin {
@@ -37,6 +38,10 @@ public class CssPlugin implements Plugin {
MetricSensor.class,
CssLanguage.class,
SonarWayProfile.class,
+ CssRulesDefinition.class,
+ CssBundleHandler.class,
+ CssRuleSensor.class,
+ StylelintExecution.class,
PropertyDefinition.builder(FILE_SUFFIXES_KEY)
.defaultValue(FILE_SUFFIXES_DEFVALUE)
diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRuleSensor.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRuleSensor.java
new file mode 100644
index 0000000..8b6558b
--- /dev/null
+++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRuleSensor.java
@@ -0,0 +1,115 @@
+/*
+ * SonarCSS
+ * Copyright (C) 2018-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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 3 of the License, or (at your option) any later version.
+ *
+ * This program 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 program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.css.plugin;
+
+import com.google.gson.Gson;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import org.sonar.api.batch.fs.FileSystem;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.rule.CheckFactory;
+import org.sonar.api.batch.sensor.Sensor;
+import org.sonar.api.batch.sensor.SensorContext;
+import org.sonar.api.batch.sensor.SensorDescriptor;
+import org.sonar.api.batch.sensor.issue.NewIssue;
+import org.sonar.api.batch.sensor.issue.NewIssueLocation;
+
+public class CssRuleSensor implements Sensor {
+
+ private final BundleHandler bundleHandler;
+ private final CssRules cssRules;
+ private final LinterCommandProvider linterCommandProvider;
+
+ public CssRuleSensor(BundleHandler bundleHandler, CheckFactory checkFactory, LinterCommandProvider linterCommandProvider) {
+ this.bundleHandler = bundleHandler;
+ this.linterCommandProvider = linterCommandProvider;
+ this.cssRules = new CssRules(checkFactory);
+ }
+
+ @Override
+ public void describe(SensorDescriptor descriptor) {
+ descriptor
+ .onlyOnLanguage(CssLanguage.KEY)
+ .name("SonarCSS Rules")
+ .onlyOnFileType(InputFile.Type.MAIN);
+ }
+
+ @Override
+ public void execute(SensorContext context) {
+ File deployDestination = context.fileSystem().workDir();
+ bundleHandler.deployBundle(deployDestination);
+
+ File projectBaseDir = context.fileSystem().baseDir();
+
+ String[] commandParts = linterCommandProvider.commandParts(deployDestination, projectBaseDir);
+ ProcessBuilder processBuilder = new ProcessBuilder(commandParts);
+
+ try {
+ Process process = processBuilder.start();
+
+ try (InputStreamReader inputStreamReader = new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8)) {
+ IssuesPerFile[] issues = new Gson().fromJson(inputStreamReader, IssuesPerFile[].class);
+ saveIssues(context, cssRules, issues);
+ }
+
+ } catch (IOException e) {
+ String command = String.join(" ", commandParts);
+ throw new IllegalStateException(String.format("Failed to run external process '%s'. Re-run analysis with debug option for more information.", command), e);
+ }
+ }
+
+ private static void saveIssues(SensorContext context, CssRules cssRules, IssuesPerFile[] issues) {
+ FileSystem fileSystem = context.fileSystem();
+
+ for (IssuesPerFile issuesPerFile : issues) {
+ InputFile inputFile = fileSystem.inputFile(fileSystem.predicates().hasAbsolutePath(issuesPerFile.source));
+
+ if (inputFile != null) {
+ for (Issue issue : issuesPerFile.warnings) {
+ NewIssue sonarIssue = context.newIssue();
+
+ NewIssueLocation location = sonarIssue.newLocation()
+ .on(inputFile)
+ .at(inputFile.selectLine(issue.line))
+ .message(issue.text);
+
+ sonarIssue
+ .at(location)
+ .forRule(cssRules.getSonarKey(issue.rule))
+ .save();
+ }
+ }
+ }
+ }
+
+ static class IssuesPerFile {
+ String source;
+ Issue[] warnings;
+ }
+
+ static class Issue {
+ int line;
+ String rule;
+ String text;
+ }
+
+}
diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRules.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRules.java
new file mode 100644
index 0000000..4ece37e
--- /dev/null
+++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRules.java
@@ -0,0 +1,70 @@
+/*
+ * SonarCSS
+ * Copyright (C) 2018-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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 3 of the License, or (at your option) any later version.
+ *
+ * This program 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 program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.css.plugin;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.sonar.api.batch.rule.CheckFactory;
+import org.sonar.api.batch.rule.Checks;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.css.plugin.rules.CssRule;
+import org.sonar.css.plugin.rules.ColorNoInvalidHex;
+
+public class CssRules {
+
+ private final Map<String, RuleKey> stylelintKeyToRuleKey;
+ private final StylelintConfig config = new StylelintConfig();
+
+ public CssRules(CheckFactory checkFactory) {
+ Checks<CssRule> checks = checkFactory.<CssRule>create(CssRulesDefinition.REPOSITORY_KEY).addAnnotatedChecks((Iterable) getRuleClasses());
+ Collection<CssRule> enabledRules = checks.all();
+ stylelintKeyToRuleKey = new HashMap<>();
+ for (CssRule rule : enabledRules) {
+ stylelintKeyToRuleKey.put(rule.stylelintKey(), checks.ruleKey(rule));
+ config.rules.put(rule.stylelintKey(), true);
+ }
+ }
+
+ public static List<Class> getRuleClasses() {
+ return Collections.unmodifiableList(Arrays.asList(
+ ColorNoInvalidHex.class
+ ));
+ }
+
+ public RuleKey getSonarKey(String stylelintKey) {
+ RuleKey ruleKey = stylelintKeyToRuleKey.get(stylelintKey);
+ if (ruleKey == null) {
+ throw new IllegalStateException("Unknown stylelint rule or rule not enabled " + stylelintKey);
+ }
+ return ruleKey;
+ }
+
+ public StylelintConfig getConfig() {
+ return config;
+ }
+
+ public static class StylelintConfig {
+ Map<String, Boolean> rules = new HashMap<>();
+ }
+}
diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRulesDefinition.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRulesDefinition.java
new file mode 100644
index 0000000..196252f
--- /dev/null
+++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRulesDefinition.java
@@ -0,0 +1,46 @@
+/*
+ * SonarCSS
+ * Copyright (C) 2018-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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 3 of the License, or (at your option) any later version.
+ *
+ * This program 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 program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.css.plugin;
+
+import java.util.Collections;
+import org.sonar.api.server.rule.RulesDefinition;
+import org.sonar.css.plugin.rules.ColorNoInvalidHex;
+import org.sonarsource.analyzer.commons.RuleMetadataLoader;
+
+import static org.sonar.css.plugin.SonarWayProfile.PROFILE_PATH;
+
+public class CssRulesDefinition implements RulesDefinition {
+
+ public static final String REPOSITORY_KEY = "css";
+ public static final String RULE_REPOSITORY_NAME = "SonarAnalyzer";
+
+ public static final String RESOURCE_FOLDER = "org/sonar/l10n/css/rules/css";
+
+ @Override
+ public void define(Context context) {
+ NewRepository repository = context
+ .createRepository(REPOSITORY_KEY, CssLanguage.KEY)
+ .setName(RULE_REPOSITORY_NAME);
+
+ RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(RESOURCE_FOLDER, PROFILE_PATH);
+ ruleMetadataLoader.addRulesByAnnotatedClass(repository, Collections.singletonList(ColorNoInvalidHex.class));
+ repository.done();
+ }
+}
diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/LinterCommandProvider.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/LinterCommandProvider.java
new file mode 100644
index 0000000..6f06c84
--- /dev/null
+++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/LinterCommandProvider.java
@@ -0,0 +1,28 @@
+/*
+ * SonarCSS
+ * Copyright (C) 2018-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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 3 of the License, or (at your option) any later version.
+ *
+ * This program 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 program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.css.plugin;
+
+import java.io.File;
+
+public interface LinterCommandProvider {
+
+ String[] commandParts(File deployDestination, File projectBaseDir);
+
+}
diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/SonarWayProfile.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/SonarWayProfile.java
index a54de22..01f6d83 100644
--- a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/SonarWayProfile.java
+++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/SonarWayProfile.java
@@ -20,16 +20,20 @@
package org.sonar.css.plugin;
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition;
+import org.sonarsource.analyzer.commons.BuiltInQualityProfileJsonLoader;
+
+import static org.sonar.css.plugin.CssRulesDefinition.REPOSITORY_KEY;
+import static org.sonar.css.plugin.CssRulesDefinition.RESOURCE_FOLDER;
public class SonarWayProfile implements BuiltInQualityProfilesDefinition {
public static final String PROFILE_NAME = "Sonar way";
-// private static final String PROFILE_PATH = "org/sonar/l10n/css/rules/css/Sonar_way_profile.json";
+ public static final String PROFILE_PATH = RESOURCE_FOLDER + "/Sonar_way_profile.json";
@Override
public void define(Context context) {
-
NewBuiltInQualityProfile profile = context.createBuiltInQualityProfile(PROFILE_NAME, CssLanguage.KEY);
+ BuiltInQualityProfileJsonLoader.load(profile, REPOSITORY_KEY, PROFILE_PATH);
profile.done();
}
}
diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/StylelintExecution.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/StylelintExecution.java
new file mode 100644
index 0000000..c88a0ac
--- /dev/null
+++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/StylelintExecution.java
@@ -0,0 +1,38 @@
+/*
+ * SonarCSS
+ * Copyright (C) 2018-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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 3 of the License, or (at your option) any later version.
+ *
+ * This program 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 program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.css.plugin;
+
+import java.io.File;
+import org.sonar.api.batch.ScannerSide;
+
+@ScannerSide
+public class StylelintExecution implements LinterCommandProvider {
+
+ @Override
+ public String[] commandParts(File deployDestination, File projectBaseDir) {
+ return new String[]{
+ "node",
+ new File(deployDestination, "css-bundle/node_modules/stylelint/bin/stylelint").getAbsolutePath(),
+ projectBaseDir.getAbsolutePath(),
+ "--config", new File(deployDestination, "css-bundle/stylelintconfig.json").getAbsolutePath(),
+ "-f", "json"
+ };
+ }
+}
diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/Zip.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/Zip.java
new file mode 100644
index 0000000..62df45e
--- /dev/null
+++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/Zip.java
@@ -0,0 +1,52 @@
+/*
+ * SonarCSS
+ * Copyright (C) 2018-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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 3 of the License, or (at your option) any later version.
+ *
+ * This program 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 program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.css.plugin;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import org.apache.commons.io.FileUtils;
+
+public class Zip {
+
+ private Zip() {
+ // utility class
+ }
+
+ public static void extract(InputStream bundle, File destination) throws IOException {
+ ZipInputStream zip = new ZipInputStream(bundle);
+ ZipEntry entry = zip.getNextEntry();
+ if (entry == null) {
+ throw new IllegalStateException("At least one entry expected.");
+ }
+ while (entry != null) {
+ File entryDestination = new File(destination, entry.getName());
+ if (entry.isDirectory()) {
+ entryDestination.mkdirs();
+ } else {
+ FileUtils.copyToFile(zip, entryDestination);
+ }
+ zip.closeEntry();
+ entry = zip.getNextEntry();
+ }
+ }
+}
diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/bundle/CssBundleHandler.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/bundle/CssBundleHandler.java
new file mode 100644
index 0000000..acf9245
--- /dev/null
+++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/bundle/CssBundleHandler.java
@@ -0,0 +1,55 @@
+/*
+ * SonarCSS
+ * Copyright (C) 2018-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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 3 of the License, or (at your option) any later version.
+ *
+ * This program 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 program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.css.plugin.bundle;
+
+import java.io.File;
+import java.io.InputStream;
+import org.sonar.api.batch.ScannerSide;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.css.plugin.BundleHandler;
+import org.sonar.css.plugin.Zip;
+
+@ScannerSide
+public class CssBundleHandler implements BundleHandler {
+
+ private static final String BUNDLE_LOCATION = "/css-bundle.zip";
+ private static final Logger LOG = Loggers.get(CssBundleHandler.class);
+ String bundleLocation = BUNDLE_LOCATION;
+
+ /**
+ * Extracting "css-bundle.zip" (containing stylelint)
+ * to deployDestination (".sonar" directory of the analyzed project).
+ */
+ @Override
+ public void deployBundle(File deployDestination) {
+ InputStream bundle = getClass().getResourceAsStream(bundleLocation);
+ if (bundle == null) {
+ throw new IllegalStateException("CSS bundle not found at " + bundleLocation);
+ }
+ try {
+ LOG.debug("Deploying bundle to {}", deployDestination.getAbsolutePath());
+ Zip.extract(bundle, deployDestination);
+ } catch (Exception e) {
+ throw new IllegalStateException("Failed to deploy CSS bundle (with classpath '" + bundleLocation + "')", e);
+ }
+ }
+
+}
diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/bundle/package-info.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/bundle/package-info.java
new file mode 100644
index 0000000..003d535
--- /dev/null
+++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/bundle/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * SonarCSS
+ * Copyright (C) 2018-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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 3 of the License, or (at your option) any later version.
+ *
+ * This program 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 program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+@javax.annotation.ParametersAreNonnullByDefault
+package org.sonar.css.plugin.bundle;
diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/ColorNoInvalidHex.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/ColorNoInvalidHex.java
new file mode 100644
index 0000000..b976abb
--- /dev/null
+++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/ColorNoInvalidHex.java
@@ -0,0 +1,31 @@
+/*
+ * SonarCSS
+ * Copyright (C) 2018-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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 3 of the License, or (at your option) any later version.
+ *
+ * This program 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 program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.css.plugin.rules;
+
+import org.sonar.check.Rule;
+
+@Rule(key = "S4647")
+public class ColorNoInvalidHex implements CssRule {
+
+ @Override
+ public String stylelintKey() {
+ return "color-no-invalid-hex";
+ }
+}
diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/CssRule.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/CssRule.java
new file mode 100644
index 0000000..237228b
--- /dev/null
+++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/CssRule.java
@@ -0,0 +1,26 @@
+/*
+ * SonarCSS
+ * Copyright (C) 2018-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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 3 of the License, or (at your option) any later version.
+ *
+ * This program 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 program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.css.plugin.rules;
+
+public interface CssRule {
+
+ String stylelintKey();
+
+}
diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/package-info.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/package-info.java
new file mode 100644
index 0000000..2c279a3
--- /dev/null
+++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * SonarCSS
+ * Copyright (C) 2018-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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 3 of the License, or (at your option) any later version.
+ *
+ * This program 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 program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+@javax.annotation.ParametersAreNonnullByDefault
+package org.sonar.css.plugin.rules;