diff options
| author | Elena Vilchik | 2018-06-12 13:34:33 +0200 |
|---|---|---|
| committer | GitHub | 2018-06-12 13:34:33 +0200 |
| commit | fb56fdc0dc18d277ccfae2cdb948e9da367377ea (patch) | |
| tree | abf9f112d0249d97bac25123f30bdb6188164401 /sonar-css-plugin/src | |
| parent | 6cebcca87c5d276627fe22b9c53ddeb4844894b6 (diff) | |
| download | sonar-css-fb56fdc0dc18d277ccfae2cdb948e9da367377ea.tar.bz2 | |
Create CSS language and set up trivial ITs (#39)
Diffstat (limited to 'sonar-css-plugin/src')
5 files changed, 159 insertions, 0 deletions
diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssLanguage.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssLanguage.java new file mode 100644 index 0000000..be5e431 --- /dev/null +++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssLanguage.java @@ -0,0 +1,41 @@ +/* + * 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 org.sonar.api.config.Configuration; +import org.sonar.api.resources.AbstractLanguage; + +public class CssLanguage extends AbstractLanguage { + + public static final String KEY = "css"; + + private Configuration configuration; + + public CssLanguage(Configuration configuration) { + super(KEY, "CSS"); + this.configuration = configuration; + } + + @Override + public String[] getFileSuffixes() { + return configuration.getStringArray(CssPlugin.FILE_SUFFIXES_KEY); + } + +} 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 8d2a12b..07b4feb 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 @@ -20,12 +20,32 @@ package org.sonar.css.plugin; import org.sonar.api.Plugin; +import org.sonar.api.config.PropertyDefinition; +import org.sonar.api.resources.Qualifiers; public class CssPlugin implements Plugin { + static final String FILE_SUFFIXES_KEY = "sonar.css.file.suffixes"; + public static final String FILE_SUFFIXES_DEFVALUE = ".css,.less,.scss"; + + private static final String CSS_CATEGORY = "CSS"; + private static final String GENERAL_SUBCATEGORY = "General"; @Override public void define(Context context) { + context.addExtensions( + CssLanguage.class, + SonarWayProfile.class, + PropertyDefinition.builder(FILE_SUFFIXES_KEY) + .defaultValue(FILE_SUFFIXES_DEFVALUE) + .name("File Suffixes") + .description("List of suffixes for files to analyze.") + .subCategory(GENERAL_SUBCATEGORY) + .category(CSS_CATEGORY) + .onQualifiers(Qualifiers.PROJECT) + .multiValues(true) + .build() + ); } } 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 new file mode 100644 index 0000000..a54de22 --- /dev/null +++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/SonarWayProfile.java @@ -0,0 +1,35 @@ +/* + * 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 org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; + +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"; + + @Override + public void define(Context context) { + + NewBuiltInQualityProfile profile = context.createBuiltInQualityProfile(PROFILE_NAME, CssLanguage.KEY); + profile.done(); + } +} diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/package-info.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/package-info.java new file mode 100644 index 0000000..a7efac0 --- /dev/null +++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/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; diff --git a/sonar-css-plugin/src/test/java/org/sonar/css/plugin/CssPluginTest.java b/sonar-css-plugin/src/test/java/org/sonar/css/plugin/CssPluginTest.java new file mode 100644 index 0000000..3da86ca --- /dev/null +++ b/sonar-css-plugin/src/test/java/org/sonar/css/plugin/CssPluginTest.java @@ -0,0 +1,42 @@ +/* + * 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 org.junit.Test; +import org.sonar.api.Plugin; +import org.sonar.api.SonarQubeSide; +import org.sonar.api.SonarRuntime; +import org.sonar.api.internal.SonarRuntimeImpl; +import org.sonar.api.utils.Version; + +import static org.assertj.core.api.Assertions.assertThat; + + +public class CssPluginTest { + + @Test + public void count_extensions() throws Exception { + SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(6, 7), SonarQubeSide.SCANNER); + Plugin.Context context = new Plugin.Context(runtime); + Plugin underTest = new CssPlugin(); + underTest.define(context); + assertThat(context.getExtensions()).hasSize(3); + } +} |
