of(
40 | BOMCheck.class,
41 | FileNameCheck.class,
42 | KeyRegularExpressionCheck.class,
43 | MissingNewLineAtEndOfFileCheck.class,
44 | ParsingErrorCheck.class,
45 | PuppetDeprecatedKeysCheck.class,
46 | PuppetDuplicatedDependenciesCheck.class,
47 | PuppetEnforceAuthorValueCheck.class,
48 | PuppetEnforceLicenseValueCheck.class,
49 | PuppetLicenseCheck.class,
50 | PuppetRequiredKeysCheck.class,
51 | PuppetVersionCheck.class,
52 | TabCharacterCheck.class);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/json-checks/src/main/java/org/sonar/json/checks/CheckUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.checks;
21 |
22 | import org.sonar.check.Rule;
23 | import org.sonar.plugins.json.api.JSONCheck;
24 |
25 | public class CheckUtils {
26 |
27 | public static final String LINK_TO_JAVA_REGEX_PATTERN_DOC = "http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html";
28 |
29 | private CheckUtils() {
30 | }
31 |
32 | public static String paramsErrorMessage(Class extends JSONCheck> clazz, String message) {
33 | return "Check json:" + clazz.getAnnotation(Rule.class).key()
34 | + " (" + clazz.getAnnotation(Rule.class).name() + "): "
35 | + message;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/json-checks/src/main/java/org/sonar/json/checks/GenerateRuleDescriptionsBatch.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.checks;
21 |
22 | import java.io.File;
23 |
24 | public class GenerateRuleDescriptionsBatch {
25 |
26 | private static final String TEMPLATE_DIRECTORY = "json-checks/src/main/resources/org/sonar/l10n/json/rules/json/template/";
27 | private static final String TARGET_DIRECTORY = "json-checks/target/classes/org/sonar/l10n/json/rules/json/";
28 |
29 | private GenerateRuleDescriptionsBatch() {
30 | }
31 |
32 | public static void main(String... args) throws Exception {
33 | RuleDescriptionsGenerator ruleDescriptionsGenerator = new RuleDescriptionsGenerator();
34 | File[] files = new File(TEMPLATE_DIRECTORY).listFiles();
35 | for (File file : files) {
36 | ruleDescriptionsGenerator.generateHtmlRuleDescription(file.getPath(), TARGET_DIRECTORY + file.getName());
37 | }
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/json-checks/src/main/java/org/sonar/json/checks/Tags.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.checks;
21 |
22 | public class Tags {
23 |
24 | public static final String CONVENTION = "convention";
25 | public static final String BUG = "bug";
26 | public static final String OBSOLETE = "obsolete";
27 | public static final String PITFALL = "pitfall";
28 | public static final String PUPPET = "puppet";
29 |
30 | private Tags() {
31 | // This class only defines constants
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/json-checks/src/main/java/org/sonar/json/checks/generic/ParsingErrorCheck.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.checks.generic;
21 |
22 | import org.sonar.check.Priority;
23 | import org.sonar.check.Rule;
24 | import org.sonar.json.checks.Tags;
25 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitorCheck;
26 | import org.sonar.squidbridge.annotations.ActivatedByDefault;
27 | import org.sonar.squidbridge.annotations.SqaleConstantRemediation;
28 |
29 | @Rule(
30 | key = "S2260",
31 | name = "JSON parser failure",
32 | priority = Priority.CRITICAL,
33 | tags = {Tags.BUG})
34 | @ActivatedByDefault
35 | @SqaleConstantRemediation("5min")
36 | public class ParsingErrorCheck extends DoubleDispatchVisitorCheck {
37 | }
38 |
--------------------------------------------------------------------------------
/json-checks/src/main/java/org/sonar/json/checks/generic/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | @ParametersAreNonnullByDefault
21 | package org.sonar.json.checks.generic;
22 |
23 | import javax.annotation.ParametersAreNonnullByDefault;
24 |
25 |
--------------------------------------------------------------------------------
/json-checks/src/main/java/org/sonar/json/checks/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | @ParametersAreNonnullByDefault
21 | package org.sonar.json.checks;
22 |
23 | import javax.annotation.ParametersAreNonnullByDefault;
24 |
25 |
--------------------------------------------------------------------------------
/json-checks/src/main/java/org/sonar/json/checks/puppet/AbstractPuppetCheck.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.checks.puppet;
21 |
22 | import org.sonar.check.Priority;
23 | import org.sonar.check.Rule;
24 | import org.sonar.json.checks.Tags;
25 | import org.sonar.plugins.json.api.tree.JsonTree;
26 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitorCheck;
27 | import org.sonar.squidbridge.annotations.SqaleConstantRemediation;
28 |
29 | @Rule(
30 | key = "puppet-deprecated-keys",
31 | name = "Deprecated keys should be removed from Puppet \"metadata.json\" files",
32 | priority = Priority.MAJOR,
33 | tags = {Tags.OBSOLETE, Tags.PUPPET})
34 | @SqaleConstantRemediation("5min")
35 | public abstract class AbstractPuppetCheck extends DoubleDispatchVisitorCheck {
36 |
37 | @Override
38 | public void visitJson(JsonTree tree) {
39 | if ("metadata.json".equals(getContext().getFile().getName())) {
40 | super.visitJson(tree);
41 | }
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/json-checks/src/main/java/org/sonar/json/checks/puppet/PuppetDeprecatedKeysCheck.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.checks.puppet;
21 |
22 | import org.sonar.check.Priority;
23 | import org.sonar.check.Rule;
24 | import org.sonar.json.checks.Tags;
25 | import org.sonar.plugins.json.api.tree.KeyTree;
26 | import org.sonar.squidbridge.annotations.SqaleConstantRemediation;
27 |
28 | @Rule(
29 | key = "puppet-deprecated-keys",
30 | name = "Deprecated keys should be removed from Puppet \"metadata.json\" files",
31 | priority = Priority.MAJOR,
32 | tags = {Tags.OBSOLETE, Tags.PUPPET})
33 | @SqaleConstantRemediation("5min")
34 | public class PuppetDeprecatedKeysCheck extends AbstractPuppetCheck {
35 |
36 | @Override
37 | public void visitKey(KeyTree tree) {
38 | if ("types".equals(tree.actualText())) {
39 | addPreciseIssue(tree, "Remove this deprecated \"types\" key.");
40 | } else if ("checksums".equals(tree.actualText())) {
41 | addPreciseIssue(tree, "Remove this deprecated \"checksums\" key.");
42 | } else if ("description".equals(tree.actualText())) {
43 | addPreciseIssue(tree, "Replace this deprecated \"description\" key by the \"summary\" key.");
44 | }
45 | super.visitKey(tree);
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/json-checks/src/main/java/org/sonar/json/checks/puppet/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | @ParametersAreNonnullByDefault
21 | package org.sonar.json.checks.puppet;
22 |
23 | import javax.annotation.ParametersAreNonnullByDefault;
24 |
25 |
--------------------------------------------------------------------------------
/json-checks/src/main/resources/org/sonar/l10n/json/rules/json/S1578.html:
--------------------------------------------------------------------------------
1 |
2 | Shared coding conventions allow teams to collaborate effectively. This rule checks that all file names match a
3 | provided regular expression.
4 |
5 | As JSON files are used in a large variety of ways and by many frameworks, it might sometimes be tricky to enforce a
6 | strict file naming convention. However, the default regular expression has been designed to match as closely as
7 | possible the following guidelines:
8 |
9 |
24 |
--------------------------------------------------------------------------------
/json-checks/src/main/resources/org/sonar/l10n/json/rules/json/S2260.html:
--------------------------------------------------------------------------------
1 |
2 | When the parser fails, it is possible to record the failure as an issue on the file. This way, not only is it
3 | possible to track the number of files that do not parse but also to easily find out why they do not parse.
4 |
5 |
--------------------------------------------------------------------------------
/json-checks/src/main/resources/org/sonar/l10n/json/rules/json/bom-utf8-files.html:
--------------------------------------------------------------------------------
1 |
2 | As stated in the Unicode specifications, use of a Byte Order Mark (BOM) is neither required nor recommended for
3 | UTF-8 files.
4 |
5 |
6 | See
7 |
11 |
12 |
--------------------------------------------------------------------------------
/json-checks/src/main/resources/org/sonar/l10n/json/rules/json/empty-line-end-of-file.html:
--------------------------------------------------------------------------------
1 | Some tools such as Git work better when files end with an empty line.
2 | This rule simply generates an issue if it is missing.
3 | For example, a Git diff looks like:
4 |
5 | {
6 | "key": "value"
7 | }
8 | \ No newline at end of file
9 |
10 | if the empty line is missing at the end of the file.
11 |
12 |
--------------------------------------------------------------------------------
/json-checks/src/main/resources/org/sonar/l10n/json/rules/json/key-regular-expression.html:
--------------------------------------------------------------------------------
1 | This rule template can be used to create rules which will be triggered when a key matches a given regular
2 | expression.
3 |
4 |
5 | For example, one can create a rule with the regular expression .*error.*
to match all key containing
6 | "error". Note that, in order to match "error" regardless of the case, the (?i)
modifier can be
7 | prepended to the expression, as in (?i).*error.*
.
8 |
9 |
--------------------------------------------------------------------------------
/json-checks/src/main/resources/org/sonar/l10n/json/rules/json/puppet-deprecated-keys.html:
--------------------------------------------------------------------------------
1 |
2 | The following keys are deprecated in Puppet metadata.json
files:
3 |
4 |
5 | types
: Should be removed
6 | checksums
: Should be removed
7 | description
: Should be replaced by the summary
key
8 |
9 |
10 | See
11 |
--------------------------------------------------------------------------------
/json-checks/src/main/resources/org/sonar/l10n/json/rules/json/puppet-duplicated-dependencies.html:
--------------------------------------------------------------------------------
1 |
2 | This rule checks for duplicated dependency entries in Puppet metadata.json
files. Those duplicated
3 | dependencies should be merged.
4 |
5 |
6 | Noncompliant Code Example
7 |
8 | {
9 | ...
10 | "dependencies": [
11 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
12 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" },
13 | { "name": "puppetlabs/apt", "version_requirement": ">=1.1.0 <2.0.0" },
14 | { "name": "puppetlabs/stdlib", "version_requirement": ">=4.2.0" } # Noncompliant: Duplicated dependency
15 | ]
16 | ...
17 | }
18 |
19 |
20 | Compliant Solution
21 |
22 | {
23 | ...
24 | "dependencies": [
25 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
26 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" },
27 | { "name": "puppetlabs/apt", "version_requirement": ">=1.1.0 <2.0.0" }
28 | ]
29 | ...
30 | }
31 |
32 |
33 | See
34 |
--------------------------------------------------------------------------------
/json-checks/src/main/resources/org/sonar/l10n/json/rules/json/puppet-enforce-author-value.html:
--------------------------------------------------------------------------------
1 |
2 | This rule allows you to enforce a specific value for the author
field in Puppet
3 | metadata.json
files.
4 |
5 |
6 | Note that the rule is not triggered when no author
key is defined. To enforce the definition of an
7 | author
key, activate rule puppet-required-keys.
8 |
9 |
10 |
--------------------------------------------------------------------------------
/json-checks/src/main/resources/org/sonar/l10n/json/rules/json/puppet-enforce-license-value.html:
--------------------------------------------------------------------------------
1 |
2 | This rule allows you to enforce a specific value for the license
field in Puppet
3 | metadata.json
files.
4 |
5 |
6 | Note that the rule is not triggered when no license
key is defined. To enforce the definition of a
7 | license
key, activate rule puppet-required-keys.
8 |
9 |
10 |
--------------------------------------------------------------------------------
/json-checks/src/main/resources/org/sonar/l10n/json/rules/json/puppet-required-keys.html:
--------------------------------------------------------------------------------
1 |
2 | Every Puppet metadata.json
file should define the following keys:
3 |
4 |
5 | name
6 | version
7 | author
8 | license
9 | summary
10 | source
11 | dependencies
12 |
13 |
14 | Noncompliant Code Example
15 | Missing author
and license
keys:
16 |
17 | {
18 | "name": "examplecorp-mymodule",
19 | "version": "0.0.1",
20 | "summary": "A module for a thing",
21 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
22 | "dependencies": [
23 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
24 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
25 | ]
26 | }
27 |
28 |
29 | Compliant Solution
30 |
31 | {
32 | "name": "examplecorp-mymodule",
33 | "version": "0.0.1",
34 | "author": "Pat",
35 | "license": "Apache-2.0",
36 | "summary": "A module for a thing",
37 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
38 | "dependencies": [
39 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
40 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
41 | ]
42 | }
43 |
44 |
45 | See
46 |
--------------------------------------------------------------------------------
/json-checks/src/main/resources/org/sonar/l10n/json/rules/json/puppet-version.html:
--------------------------------------------------------------------------------
1 |
2 | Version management should comply with semantic version.
3 |
4 |
5 | Given a version number MAJOR.MINOR.PATCH, increment the:
6 |
7 |
8 | - MAJOR version when you make incompatible API changes
9 | - MINOR version when you add functionality in a backwards-compatible manner
10 | - PATCH version when you make backwards-compatible bug fixes
11 |
12 |
13 | This rule check the version format that should be made of 3 digits separated by dots: ^\d+\.\d+\.\d+$
14 |
15 |
16 | Noncompliant Version
17 |
18 | {
19 | "version": "1.0",
20 | "version": "1.0.0.2"
21 | }
22 |
23 |
24 | Compliant Version
25 |
26 | {
27 | "version": "1.0.0",
28 | "version": "1.0.2"
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/json-checks/src/main/resources/org/sonar/l10n/json/rules/json/tab-character.html:
--------------------------------------------------------------------------------
1 |
2 | Developers should not need to configure the tab width of their text editors in order to be able to read source code.
3 | So the use of tabulation character must be banned.
4 |
--------------------------------------------------------------------------------
/json-checks/src/main/resources/org/sonar/l10n/json/rules/json/template/puppet-license.html:
--------------------------------------------------------------------------------
1 |
2 | License should be either proprietary
or one listed on the SPDX
3 | page.
4 |
5 |
6 | Nocompliant Code Example
7 |
8 | {
9 | ...
10 | "license": blabla
11 | ...
12 | }
13 |
14 |
15 | Compliant Solution
16 |
17 | {
18 | ...
19 | "license": "proprietary"
20 | ...
21 | }
22 |
23 | {
24 | ...
25 | "license": "LGPL-3.0"
26 | ...
27 | }
28 |
29 |
30 | See
31 |
35 |
36 | List of Licenses
37 | [[allLicenses]]
--------------------------------------------------------------------------------
/json-checks/src/test/java/org/sonar/json/checks/CheckTestUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.checks;
21 |
22 | import java.io.File;
23 |
24 | public class CheckTestUtils {
25 |
26 | private CheckTestUtils() {
27 | }
28 |
29 | public static File getTestFile(String relativePath) {
30 | return new File("src/test/resources/checks/" + relativePath);
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/json-checks/src/test/java/org/sonar/json/checks/generic/BOMCheckTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.checks.generic;
21 |
22 | import com.google.common.base.Charsets;
23 | import org.junit.Test;
24 | import org.sonar.json.checks.CheckTestUtils;
25 | import org.sonar.json.checks.verifier.JSONCheckVerifier;
26 |
27 | public class BOMCheckTest {
28 |
29 | @Test
30 | public void should_find_a_BOM_in_UTF8_file_and_raise_an_issue() {
31 | JSONCheckVerifier.verify(new BOMCheck(), CheckTestUtils.getTestFile("utf8WithBOM.json"))
32 | .next().withMessage("Remove the BOM.")
33 | .noMore();
34 | }
35 |
36 | @Test
37 | public void should_find_a_BOM_in_UTF16_files_but_not_raise_any_issue() {
38 | JSONCheckVerifier.verify(new BOMCheck(), CheckTestUtils.getTestFile("utf16BE.json"), Charsets.UTF_16BE)
39 | .noMore();
40 |
41 | JSONCheckVerifier.verify(new BOMCheck(), CheckTestUtils.getTestFile("utf16LE.json"), Charsets.UTF_16LE)
42 | .noMore();
43 | }
44 |
45 | @Test
46 | public void should_not_find_a_BOM_in_UTF8_file_and_not_raise_any_issue() {
47 | JSONCheckVerifier.verify(new BOMCheck(), CheckTestUtils.getTestFile("sample.json"), Charsets.UTF_8)
48 | .noMore();
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/json-checks/src/test/java/org/sonar/json/checks/generic/MissingNewLineAtEndOfFileCheckTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.checks.generic;
21 |
22 | import org.junit.Test;
23 | import org.sonar.json.checks.CheckTestUtils;
24 | import org.sonar.json.checks.verifier.JSONCheckVerifier;
25 |
26 | public class MissingNewLineAtEndOfFileCheckTest {
27 |
28 | @Test
29 | public void should_have_an_empty_new_line_at_the_end_of_the_file_and_not_raise_any_issue() {
30 | JSONCheckVerifier.verify(new MissingNewLineAtEndOfFileCheck(), CheckTestUtils.getTestFile("newLineEndOfFile.json"))
31 | .noMore();
32 | }
33 |
34 | @Test
35 | public void should_not_have_an_empty_new_line_at_the_end_of_the_file_and_raise_an_issue() {
36 | JSONCheckVerifier.verify(new MissingNewLineAtEndOfFileCheck(), CheckTestUtils.getTestFile("noNewLineEndOfFile.json"))
37 | .next().withMessage("Add an empty new line at the end of this file.")
38 | .noMore();
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/json-checks/src/test/java/org/sonar/json/checks/generic/TabCharacterCheckTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.checks.generic;
21 |
22 | import org.junit.Test;
23 | import org.sonar.json.checks.CheckTestUtils;
24 | import org.sonar.json.checks.verifier.JSONCheckVerifier;
25 |
26 | public class TabCharacterCheckTest {
27 |
28 | @Test
29 | public void should_find_tab_characters_and_raise_an_issue() {
30 | JSONCheckVerifier.verify(new TabCharacterCheck(), CheckTestUtils.getTestFile("tabCharacter.json"))
31 | .next().withMessage("Replace all tab characters in this file by sequences of whitespaces.")
32 | .noMore();
33 | }
34 |
35 | @Test
36 | public void should_not_find_tab_characters_and_not_raise_an_issue() {
37 | JSONCheckVerifier.verify(new TabCharacterCheck(), CheckTestUtils.getTestFile("sample.json"))
38 | .noMore();
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/json-checks/src/test/java/org/sonar/json/checks/puppet/PuppetDeprecatedKeysCheckTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.checks.puppet;
21 |
22 | import org.junit.Test;
23 | import org.sonar.json.checks.CheckTestUtils;
24 | import org.sonar.json.checks.verifier.JSONCheckVerifier;
25 |
26 | public class PuppetDeprecatedKeysCheckTest {
27 |
28 | @Test
29 | public void should_find_some_deprecated_keys_and_raise_some_issues() {
30 | JSONCheckVerifier.verify(new PuppetDeprecatedKeysCheck(), CheckTestUtils.getTestFile("puppet/deprecated-keys/metadata.json"))
31 | .next().startAtLine(4).startAtColumn(3).endAtLine(4).endAtColumn(16).withMessage("Replace this deprecated \"description\" key by the \"summary\" key.")
32 | .next().startAtLine(5).startAtColumn(3).endAtLine(5).endAtColumn(10).withMessage("Remove this deprecated \"types\" key.")
33 | .next().startAtLine(6).startAtColumn(3).endAtLine(6).endAtColumn(14).withMessage("Remove this deprecated \"checksums\" key.")
34 | .noMore();
35 | }
36 |
37 | @Test
38 | public void should_not_raise_any_issues_because_it_is_not_a_metadata_json_file() {
39 | JSONCheckVerifier.verify(new PuppetDeprecatedKeysCheck(), CheckTestUtils.getTestFile("puppet/deprecated-keys/notmetadata.json"))
40 | .noMore();
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/file-name.ko.json:
--------------------------------------------------------------------------------
1 | {
2 | "def": {},
3 | "abc" : [123, 234],
4 | "abc" : 123,
5 |
6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]}
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/keyRegularExpression.json:
--------------------------------------------------------------------------------
1 | {
2 | "mykey": {},
3 | "abc" : [123, 234],
4 | "blabla_mykey_blabla" : 123,
5 |
6 | "zzz": { "ddd": "jjj", "mykey": "\"jjj", "ee": [244, 333]}
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/newLineEndOfFile.json:
--------------------------------------------------------------------------------
1 | {
2 | "def": {},
3 | "abc" : [123, 234],
4 | "abc" : 123,
5 |
6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]}
7 | }
8 |
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/noNewLineEndOfFile.json:
--------------------------------------------------------------------------------
1 | {
2 | "def": {},
3 | "abc" : [123, 234],
4 | "abc" : 123,
5 |
6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]}
7 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/parsingError.json:
--------------------------------------------------------------------------------
1 | blabla...
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/author/custom/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "author": "Pat",
5 | "license": "Apache-2.0",
6 | "summary": "A module for a thing",
7 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
10 | "tags": ["things", "stuff"],
11 | "operatingsystem_support": [
12 | {
13 | "operatingsystem":"RedHat",
14 | "operatingsystemrelease":[ "5.0", "6.0" ]
15 | },
16 | {
17 | "operatingsystem": "Ubuntu",
18 | "operatingsystemrelease": [ "12.04", "10.04" ]
19 | }
20 | ],
21 | "dependencies": [
22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
24 | ]
25 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/author/default-issue/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "author": "Pat",
5 | "author": [
6 | "abc",
7 | "def"
8 | ],
9 | "license": "Apache-2.0",
10 | "summary": "A module for a thing",
11 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
12 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
13 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
14 | "tags": ["things", "stuff"],
15 | "operatingsystem_support": [
16 | {
17 | "operatingsystem":"RedHat",
18 | "operatingsystemrelease":[ "5.0", "6.0" ]
19 | },
20 | {
21 | "operatingsystem": "Ubuntu",
22 | "operatingsystemrelease": [ "12.04", "10.04" ]
23 | }
24 | ],
25 | "dependencies": [
26 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
27 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
28 | ]
29 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/author/default/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "author": "John Doe",
5 | "license": "Apache-2.0",
6 | "summary": "A module for a thing",
7 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
10 | "tags": ["things", "stuff"],
11 | "operatingsystem_support": [
12 | {
13 | "operatingsystem":"RedHat",
14 | "operatingsystemrelease":[ "5.0", "6.0" ]
15 | },
16 | {
17 | "operatingsystem": "Ubuntu",
18 | "operatingsystemrelease": [ "12.04", "10.04" ]
19 | }
20 | ],
21 | "dependencies": [
22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
24 | ]
25 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/author/not-metadata-json-file/notmetadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "author": "John Doe",
5 | "license": "Apache-2.0",
6 | "summary": "A module for a thing",
7 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
10 | "tags": ["things", "stuff"],
11 | "operatingsystem_support": [
12 | {
13 | "operatingsystem":"RedHat",
14 | "operatingsystemrelease":[ "5.0", "6.0" ]
15 | },
16 | {
17 | "operatingsystem": "Ubuntu",
18 | "operatingsystemrelease": [ "12.04", "10.04" ]
19 | }
20 | ],
21 | "dependencies": [
22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
24 | ]
25 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/dependencies/duplicated-dependencies/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "author": "Pat",
5 | "license": "Apache-2.0",
6 | "summary": "A module for a thing",
7 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
10 | "tags": ["things", "stuff"],
11 | "operatingsystem_support": [
12 | {
13 | "operatingsystem":"RedHat",
14 | "operatingsystemrelease":[ "5.0", "6.0" ]
15 | },
16 | {
17 | "operatingsystem": "Ubuntu",
18 | "operatingsystemrelease": [ "12.04", "10.04" ]
19 | }
20 | ],
21 | "dependencies": [
22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" },
24 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
25 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" },
26 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
27 | ]
28 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/dependencies/invalid-dependencies/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "author": "Pat",
5 | "license": "Apache-2.0",
6 | "summary": "A module for a thing",
7 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
10 | "tags": ["things", "stuff"],
11 | "operatingsystem_support": [
12 | {
13 | "operatingsystem":"RedHat",
14 | "operatingsystemrelease":[ "5.0", "6.0" ]
15 | },
16 | {
17 | "operatingsystem": "Ubuntu",
18 | "operatingsystemrelease": [ "12.04", "10.04" ]
19 | }
20 | ],
21 | "dependencies": "abc"
22 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/dependencies/no-dependencies/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "author": "Pat",
5 | "license": "Apache-2.0",
6 | "summary": "A module for a thing",
7 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
10 | "tags": ["things", "stuff"],
11 | "operatingsystem_support": [
12 | {
13 | "operatingsystem":"RedHat",
14 | "operatingsystemrelease":[ "5.0", "6.0" ]
15 | },
16 | {
17 | "operatingsystem": "Ubuntu",
18 | "operatingsystemrelease": [ "12.04", "10.04" ]
19 | }
20 | ]
21 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/dependencies/not-metadata-json-file/notmetadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "author": "Pat",
5 | "license": "Apache-2.0",
6 | "summary": "A module for a thing",
7 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
10 | "tags": ["things", "stuff"],
11 | "operatingsystem_support": [
12 | {
13 | "operatingsystem":"RedHat",
14 | "operatingsystemrelease":[ "5.0", "6.0" ]
15 | },
16 | {
17 | "operatingsystem": "Ubuntu",
18 | "operatingsystemrelease": [ "12.04", "10.04" ]
19 | }
20 | ],
21 | "dependencies": "abc"
22 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/dependencies/valid-dependencies/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "author": "Pat",
5 | "license": "Apache-2.0",
6 | "summary": "A module for a thing",
7 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
10 | "tags": ["things", "stuff"],
11 | "operatingsystem_support": [
12 | {
13 | "operatingsystem":"RedHat",
14 | "operatingsystemrelease":[ "5.0", "6.0" ]
15 | },
16 | {
17 | "operatingsystem": "Ubuntu",
18 | "operatingsystemrelease": [ "12.04", "10.04" ]
19 | }
20 | ],
21 | "dependencies": [
22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
24 | ]
25 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/deprecated-keys/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "description": "A module for a thing",
5 | "types": "blabla",
6 | "checksums": "blabla",
7 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
10 | "tags": ["things", "stuff"],
11 | "operatingsystem_support": [
12 | {
13 | "operatingsystem":"RedHat",
14 | "operatingsystemrelease":[ "5.0", "6.0" ]
15 | },
16 | {
17 | "operatingsystem": "Ubuntu",
18 | "operatingsystemrelease": [ "12.04", "10.04" ]
19 | }
20 | ],
21 | "dependencies": [
22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
24 | ]
25 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/deprecated-keys/notmetadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "description": "A module for a thing",
5 | "types": "blabla",
6 | "checksums": "blabla",
7 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
10 | "tags": ["things", "stuff"],
11 | "operatingsystem_support": [
12 | {
13 | "operatingsystem":"RedHat",
14 | "operatingsystemrelease":[ "5.0", "6.0" ]
15 | },
16 | {
17 | "operatingsystem": "Ubuntu",
18 | "operatingsystemrelease": [ "12.04", "10.04" ]
19 | }
20 | ],
21 | "dependencies": [
22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
24 | ]
25 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/license/invalid/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "author": "Pat",
5 | "license": "blabla",
6 | "summary": "A module for a thing",
7 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
10 | "tags": ["things", "stuff"],
11 | "operatingsystem_support": [
12 | {
13 | "operatingsystem":"RedHat",
14 | "operatingsystemrelease":[ "5.0", "6.0" ]
15 | },
16 | {
17 | "operatingsystem": "Ubuntu",
18 | "operatingsystemrelease": [ "12.04", "10.04" ]
19 | }
20 | ],
21 | "dependencies": [
22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
24 | ]
25 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/license/match-required-value-custom/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "author": "Pat",
5 | "license": "blabla",
6 | "summary": "A module for a thing",
7 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
10 | "tags": ["things", "stuff"],
11 | "operatingsystem_support": [
12 | {
13 | "operatingsystem":"RedHat",
14 | "operatingsystemrelease":[ "5.0", "6.0" ]
15 | },
16 | {
17 | "operatingsystem": "Ubuntu",
18 | "operatingsystemrelease": [ "12.04", "10.04" ]
19 | }
20 | ],
21 | "dependencies": [
22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
24 | ]
25 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/license/match-required-value/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "author": "Pat",
5 | "license": "blabla",
6 | "license": [ "blabla" ],
7 | "summary": "A module for a thing",
8 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
9 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
10 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
11 | "tags": ["things", "stuff"],
12 | "operatingsystem_support": [
13 | {
14 | "operatingsystem":"RedHat",
15 | "operatingsystemrelease":[ "5.0", "6.0" ]
16 | },
17 | {
18 | "operatingsystem": "Ubuntu",
19 | "operatingsystemrelease": [ "12.04", "10.04" ]
20 | }
21 | ],
22 | "dependencies": [
23 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
24 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
25 | ]
26 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/license/no-license/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "author": "Pat",
5 | "summary": "A module for a thing",
6 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
7 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
8 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
9 | "tags": ["things", "stuff"],
10 | "operatingsystem_support": [
11 | {
12 | "operatingsystem":"RedHat",
13 | "operatingsystemrelease":[ "5.0", "6.0" ]
14 | },
15 | {
16 | "operatingsystem": "Ubuntu",
17 | "operatingsystemrelease": [ "12.04", "10.04" ]
18 | }
19 | ],
20 | "dependencies": [
21 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
22 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
23 | ]
24 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/license/not-metadata-json-file/notmetadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "author": "Pat",
5 | "license": "blabla",
6 | "summary": "A module for a thing",
7 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
10 | "tags": ["things", "stuff"],
11 | "operatingsystem_support": [
12 | {
13 | "operatingsystem":"RedHat",
14 | "operatingsystemrelease":[ "5.0", "6.0" ]
15 | },
16 | {
17 | "operatingsystem": "Ubuntu",
18 | "operatingsystemrelease": [ "12.04", "10.04" ]
19 | }
20 | ],
21 | "dependencies": [
22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
24 | ]
25 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/license/two-licenses/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "author": "Pat",
5 | "license": "Apache-2.0",
6 | "license": "Apache-2.0",
7 | "summary": "A module for a thing",
8 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
9 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
10 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
11 | "tags": ["things", "stuff"],
12 | "operatingsystem_support": [
13 | {
14 | "operatingsystem":"RedHat",
15 | "operatingsystemrelease":[ "5.0", "6.0" ]
16 | },
17 | {
18 | "operatingsystem": "Ubuntu",
19 | "operatingsystemrelease": [ "12.04", "10.04" ]
20 | }
21 | ],
22 | "dependencies": [
23 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
24 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
25 | ]
26 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/license/valid-proprietary/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "author": "Pat",
5 | "license": "proprietary",
6 | "summary": "A module for a thing",
7 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
10 | "tags": ["things", "stuff"],
11 | "operatingsystem_support": [
12 | {
13 | "operatingsystem":"RedHat",
14 | "operatingsystemrelease":[ "5.0", "6.0" ]
15 | },
16 | {
17 | "operatingsystem": "Ubuntu",
18 | "operatingsystemrelease": [ "12.04", "10.04" ]
19 | }
20 | ],
21 | "dependencies": [
22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
24 | ]
25 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/license/valid-spdx/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "author": "Pat",
5 | "license": "LGPL-3.0",
6 | "summary": "A module for a thing",
7 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
10 | "tags": ["things", "stuff"],
11 | "operatingsystem_support": [
12 | {
13 | "operatingsystem":"RedHat",
14 | "operatingsystemrelease":[ "5.0", "6.0" ]
15 | },
16 | {
17 | "operatingsystem": "Ubuntu",
18 | "operatingsystemrelease": [ "12.04", "10.04" ]
19 | }
20 | ],
21 | "dependencies": [
22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
24 | ]
25 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/required-keys/empty-file/metadata.json:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/racodond/sonar-json-plugin/84d464b3827a7698dd6ff70e91bf0960db3a14f1/json-checks/src/test/resources/checks/puppet/required-keys/empty-file/metadata.json
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/required-keys/missing-keys/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "summary": "A module for a thing",
5 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
6 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
7 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
8 | "tags": ["things", "stuff"],
9 | "operatingsystem_support": [
10 | {
11 | "operatingsystem":"RedHat",
12 | "operatingsystemrelease":[ "5.0", "6.0" ]
13 | },
14 | {
15 | "operatingsystem": "Ubuntu",
16 | "operatingsystemrelease": [ "12.04", "10.04" ]
17 | }
18 | ],
19 | "dependencies": [
20 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
21 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
22 | ]
23 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/required-keys/no-missing-keys/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "author": "Pat",
5 | "license": "Apache-2.0",
6 | "summary": "A module for a thing",
7 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
8 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
9 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
10 | "tags": ["things", "stuff"],
11 | "operatingsystem_support": [
12 | {
13 | "operatingsystem":"RedHat",
14 | "operatingsystemrelease":[ "5.0", "6.0" ]
15 | },
16 | {
17 | "operatingsystem": "Ubuntu",
18 | "operatingsystemrelease": [ "12.04", "10.04" ]
19 | }
20 | ],
21 | "dependencies": [
22 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
23 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
24 | ]
25 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/required-keys/not-metadata-json-file/notmetadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "summary": "A module for a thing",
5 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
6 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
7 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
8 | "tags": ["things", "stuff"],
9 | "operatingsystem_support": [
10 | {
11 | "operatingsystem":"RedHat",
12 | "operatingsystemrelease":[ "5.0", "6.0" ]
13 | },
14 | {
15 | "operatingsystem": "Ubuntu",
16 | "operatingsystemrelease": [ "12.04", "10.04" ]
17 | }
18 | ],
19 | "dependencies": [
20 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
21 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
22 | ]
23 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/version/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "version": "0.1",
5 | "version": "1.0.1-beta",
6 | "version": "abc",
7 | "version": [ "0.1" ],
8 | "author": "Pat",
9 | "license": "Apache-2.0",
10 | "summary": "A module for a thing",
11 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
12 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
13 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
14 | "tags": ["things", "stuff"],
15 | "operatingsystem_support": [
16 | {
17 | "operatingsystem":"RedHat",
18 | "operatingsystemrelease":[ "5.0", "6.0" ]
19 | },
20 | {
21 | "operatingsystem": "Ubuntu",
22 | "operatingsystemrelease": [ "12.04", "10.04" ]
23 | }
24 | ],
25 | "dependencies": [
26 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
27 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
28 | ]
29 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/puppet/version/notmetadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "examplecorp-mymodule",
3 | "version": "0.0.1",
4 | "version": "0.1",
5 | "version": "1.0.1-beta",
6 | "version": "abc",
7 | "author": "Pat",
8 | "license": "Apache-2.0",
9 | "summary": "A module for a thing",
10 | "source": "https://github.com/examplecorp/examplecorp-mymodule",
11 | "project_page": "https://forge.puppetlabs.com/examplecorp/mymodule",
12 | "issues_url": "https://github.com/examplecorp/examplecorp-mymodule/issues",
13 | "tags": ["things", "stuff"],
14 | "operatingsystem_support": [
15 | {
16 | "operatingsystem":"RedHat",
17 | "operatingsystemrelease":[ "5.0", "6.0" ]
18 | },
19 | {
20 | "operatingsystem": "Ubuntu",
21 | "operatingsystemrelease": [ "12.04", "10.04" ]
22 | }
23 | ],
24 | "dependencies": [
25 | { "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" },
26 | { "name": "puppetlabs/firewall", "version_requirement": ">= 0.0.4" }
27 | ]
28 | }
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/sample.json:
--------------------------------------------------------------------------------
1 | {
2 | "def": {},
3 | "abc" : [123, 234],
4 | "foo" : 123,
5 |
6 | "zzz": { "ddd": "jjj", "abc": "\"wtf", "ee": [244, 333]}
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/tab-character.json~:
--------------------------------------------------------------------------------
1 | {
2 | "def": {},
3 | "abc" : [123, 234],
4 | "abc" : 123,
5 |
6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]}
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/tabCharacter.json:
--------------------------------------------------------------------------------
1 | {
2 | "def": {},
3 | "abc" : [true, null],
4 | "abc" : false,
5 |
6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]}
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/utf16BE.json:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/racodond/sonar-json-plugin/84d464b3827a7698dd6ff70e91bf0960db3a14f1/json-checks/src/test/resources/checks/utf16BE.json
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/utf16LE.json:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/racodond/sonar-json-plugin/84d464b3827a7698dd6ff70e91bf0960db3a14f1/json-checks/src/test/resources/checks/utf16LE.json
--------------------------------------------------------------------------------
/json-checks/src/test/resources/checks/utf8WithBOM.json:
--------------------------------------------------------------------------------
1 | {
2 | "def": {},
3 | "abc" : [123, 234],
4 | "abc" : 123,
5 |
6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]}
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/json-frontend/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 |
6 | org.codehaus.sonar-plugins.json
7 | json
8 | 2.4-SNAPSHOT
9 |
10 |
11 | json-frontend
12 | SonarQube JSON Analyzer :: Frontend
13 |
14 |
15 |
16 | org.sonarsource.sonarqube
17 | sonar-plugin-api
18 | provided
19 |
20 |
21 | commons-lang
22 | commons-lang
23 |
24 |
25 | org.sonarsource.sslr
26 | sslr-core
27 |
28 |
29 | org.sonarsource.sslr-squid-bridge
30 | sslr-squid-bridge
31 |
32 |
33 | com.google.guava
34 | guava
35 |
36 |
37 | junit
38 | junit
39 | test
40 |
41 |
42 | org.sonarsource.sslr
43 | sslr-testing-harness
44 | test
45 |
46 |
47 | org.mockito
48 | mockito-all
49 | test
50 |
51 |
52 |
53 |
54 |
55 |
56 | org.jacoco
57 | jacoco-maven-plugin
58 |
59 | ${sonar.jacoco.reportPath}
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/json/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | @ParametersAreNonnullByDefault
21 | package org.sonar.json;
22 |
23 | import javax.annotation.ParametersAreNonnullByDefault;
24 |
25 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/json/parser/JSONParserBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.parser;
21 |
22 | import com.google.common.annotations.VisibleForTesting;
23 | import com.sonar.sslr.api.typed.ActionParser;
24 |
25 | import java.nio.charset.Charset;
26 |
27 | import org.sonar.plugins.json.api.tree.Tree;
28 | import org.sonar.sslr.grammar.GrammarRuleKey;
29 |
30 | public class JSONParserBuilder {
31 |
32 | private JSONParserBuilder() {
33 | }
34 |
35 | public static ActionParser createParser(Charset charset) {
36 | return createParser(charset, JSONLexicalGrammar.JSON);
37 | }
38 |
39 | @VisibleForTesting
40 | public static ActionParser createTestParser(Charset charset, GrammarRuleKey rootRule) {
41 | return createParser(charset, rootRule);
42 | }
43 |
44 | private static ActionParser createParser(Charset charset, GrammarRuleKey rootRule) {
45 | return new ActionParser<>(
46 | charset,
47 | JSONLexicalGrammar.createGrammar(),
48 | JSONGrammar.class,
49 | new TreeFactory(),
50 | new JSONNodeBuilder(),
51 | rootRule);
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/json/parser/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | @ParametersAreNonnullByDefault
21 | package org.sonar.json.parser;
22 |
23 | import javax.annotation.ParametersAreNonnullByDefault;
24 |
25 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/json/tree/impl/FalseTreeImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.tree.impl;
21 |
22 | import org.sonar.plugins.json.api.tree.SyntaxToken;
23 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitor;
24 |
25 | public class FalseTreeImpl extends LiteralTreeImpl {
26 |
27 | public FalseTreeImpl(SyntaxToken value) {
28 | super(value);
29 | }
30 |
31 | @Override
32 | public Kind getKind() {
33 | return Kind.FALSE;
34 | }
35 |
36 | @Override
37 | public void accept(DoubleDispatchVisitor visitor) {
38 | visitor.visitFalse(this);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/json/tree/impl/KeyTreeImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.tree.impl;
21 |
22 | import com.google.common.collect.Iterators;
23 |
24 | import java.util.Iterator;
25 |
26 | import org.sonar.plugins.json.api.tree.KeyTree;
27 | import org.sonar.plugins.json.api.tree.SyntaxToken;
28 | import org.sonar.plugins.json.api.tree.Tree;
29 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitor;
30 |
31 | public class KeyTreeImpl extends JSONTree implements KeyTree {
32 |
33 | private final SyntaxToken key;
34 |
35 | public KeyTreeImpl(SyntaxToken key) {
36 | this.key = key;
37 | }
38 |
39 | @Override
40 | public Tree.Kind getKind() {
41 | return Tree.Kind.KEY;
42 | }
43 |
44 | @Override
45 | public Iterator childrenIterator() {
46 | return Iterators.singletonIterator(key);
47 | }
48 |
49 | @Override
50 | public String actualText() {
51 | return key.text().substring(1, key.text().length() - 1);
52 | }
53 |
54 | @Override
55 | public SyntaxToken value() {
56 | return key;
57 | }
58 |
59 | @Override
60 | public void accept(DoubleDispatchVisitor visitor) {
61 | visitor.visitKey(this);
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/json/tree/impl/LiteralTreeImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.tree.impl;
21 |
22 | import com.google.common.collect.Iterators;
23 |
24 | import java.util.Iterator;
25 |
26 | import org.sonar.plugins.json.api.tree.LiteralTree;
27 | import org.sonar.plugins.json.api.tree.SyntaxToken;
28 | import org.sonar.plugins.json.api.tree.Tree;
29 |
30 | public abstract class LiteralTreeImpl extends JSONTree implements LiteralTree {
31 |
32 | private final SyntaxToken value;
33 | private final String text;
34 |
35 | public LiteralTreeImpl(SyntaxToken value) {
36 | this.value = value;
37 | text = value.text();
38 | }
39 |
40 | @Override
41 | public Iterator childrenIterator() {
42 | return Iterators.singletonIterator(value);
43 | }
44 |
45 | @Override
46 | public SyntaxToken value() {
47 | return value;
48 | }
49 |
50 | @Override
51 | public String text() {
52 | return text;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/json/tree/impl/NullTreeImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.tree.impl;
21 |
22 | import org.sonar.plugins.json.api.tree.SyntaxToken;
23 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitor;
24 |
25 | public class NullTreeImpl extends LiteralTreeImpl {
26 |
27 | public NullTreeImpl(SyntaxToken value) {
28 | super(value);
29 | }
30 |
31 | @Override
32 | public Kind getKind() {
33 | return Kind.NULL;
34 | }
35 |
36 | @Override
37 | public void accept(DoubleDispatchVisitor visitor) {
38 | visitor.visitNull(this);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/json/tree/impl/NumberTreeImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.tree.impl;
21 |
22 | import org.sonar.plugins.json.api.tree.SyntaxToken;
23 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitor;
24 |
25 | public class NumberTreeImpl extends LiteralTreeImpl {
26 |
27 | public NumberTreeImpl(SyntaxToken value) {
28 | super(value);
29 | }
30 |
31 | @Override
32 | public Kind getKind() {
33 | return Kind.NUMBER;
34 | }
35 |
36 | @Override
37 | public void accept(DoubleDispatchVisitor visitor) {
38 | visitor.visitNumber(this);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/json/tree/impl/PairTreeImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.tree.impl;
21 |
22 | import com.google.common.collect.Iterators;
23 |
24 | import java.util.Iterator;
25 |
26 | import org.sonar.plugins.json.api.tree.*;
27 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitor;
28 |
29 | public class PairTreeImpl extends JSONTree implements PairTree {
30 |
31 | private final KeyTree key;
32 | private final SyntaxToken colon;
33 | private final ValueTree value;
34 |
35 | public PairTreeImpl(KeyTree key, SyntaxToken colon, ValueTree value) {
36 | this.key = key;
37 | this.colon = colon;
38 | this.value = value;
39 | }
40 |
41 | @Override
42 | public Kind getKind() {
43 | return Kind.PAIR;
44 | }
45 |
46 | @Override
47 | public Iterator childrenIterator() {
48 | return Iterators.forArray(key, colon, value);
49 | }
50 |
51 | @Override
52 | public KeyTree key() {
53 | return key;
54 | }
55 |
56 | @Override
57 | public SyntaxToken colon() {
58 | return colon;
59 | }
60 |
61 | @Override
62 | public ValueTree value() {
63 | return value;
64 | }
65 |
66 | @Override
67 | public void accept(DoubleDispatchVisitor visitor) {
68 | visitor.visitPair(this);
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/json/tree/impl/StringTreeImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.tree.impl;
21 |
22 | import org.sonar.plugins.json.api.tree.StringTree;
23 | import org.sonar.plugins.json.api.tree.SyntaxToken;
24 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitor;
25 |
26 | public class StringTreeImpl extends LiteralTreeImpl implements StringTree {
27 |
28 | public StringTreeImpl(SyntaxToken value) {
29 | super(value);
30 | }
31 |
32 | @Override
33 | public Kind getKind() {
34 | return Kind.STRING;
35 | }
36 |
37 | @Override
38 | public void accept(DoubleDispatchVisitor visitor) {
39 | visitor.visitString(this);
40 | }
41 |
42 | @Override
43 | public String actualText() {
44 | return text().substring(1, text().length() - 1);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/json/tree/impl/TrueTreeImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.tree.impl;
21 |
22 | import org.sonar.plugins.json.api.tree.SyntaxToken;
23 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitor;
24 |
25 | public class TrueTreeImpl extends LiteralTreeImpl {
26 |
27 | public TrueTreeImpl(SyntaxToken value) {
28 | super(value);
29 | }
30 |
31 | @Override
32 | public Kind getKind() {
33 | return Kind.TRUE;
34 | }
35 |
36 | @Override
37 | public void accept(DoubleDispatchVisitor visitor) {
38 | visitor.visitTrue(this);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/json/tree/impl/ValueTreeImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.tree.impl;
21 |
22 | import com.google.common.collect.Iterators;
23 |
24 | import java.util.Iterator;
25 |
26 | import org.sonar.plugins.json.api.tree.Tree;
27 | import org.sonar.plugins.json.api.tree.ValueTree;
28 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitor;
29 |
30 | public class ValueTreeImpl extends JSONTree implements ValueTree {
31 |
32 | private final Tree value;
33 |
34 | public ValueTreeImpl(Tree value) {
35 | this.value = value;
36 | }
37 |
38 | @Override
39 | public Kind getKind() {
40 | return Kind.VALUE;
41 | }
42 |
43 | @Override
44 | public Iterator childrenIterator() {
45 | return Iterators.singletonIterator(value);
46 | }
47 |
48 | @Override
49 | public void accept(DoubleDispatchVisitor visitor) {
50 | visitor.visitValue(this);
51 | }
52 |
53 | @Override
54 | public Tree value() {
55 | return value;
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/json/tree/impl/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | @ParametersAreNonnullByDefault
21 | package org.sonar.json.tree.impl;
22 |
23 | import javax.annotation.ParametersAreNonnullByDefault;
24 |
25 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/json/visitors/CharsetAwareVisitor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.visitors;
21 |
22 | import java.nio.charset.Charset;
23 |
24 | @FunctionalInterface
25 | public interface CharsetAwareVisitor {
26 |
27 | void setCharset(Charset charset);
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/json/visitors/JSONVisitorContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.visitors;
21 |
22 | import java.io.File;
23 |
24 | import org.sonar.plugins.json.api.tree.JsonTree;
25 | import org.sonar.plugins.json.api.visitors.TreeVisitorContext;
26 |
27 | public class JSONVisitorContext implements TreeVisitorContext {
28 |
29 | private final JsonTree tree;
30 | private final File file;
31 |
32 | public JSONVisitorContext(JsonTree tree, File file) {
33 | this.tree = tree;
34 | this.file = file;
35 | }
36 |
37 | @Override
38 | public JsonTree getTopTree() {
39 | return tree;
40 | }
41 |
42 | @Override
43 | public File getFile() {
44 | return file;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/json/visitors/metrics/LinesOfCodeVisitor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.visitors.metrics;
21 |
22 | import com.google.common.collect.ImmutableList;
23 | import com.google.common.collect.Sets;
24 |
25 | import java.util.List;
26 | import java.util.Set;
27 |
28 | import org.sonar.json.tree.impl.InternalSyntaxToken;
29 | import org.sonar.plugins.json.api.tree.Tree;
30 | import org.sonar.plugins.json.api.visitors.SubscriptionVisitor;
31 |
32 | public class LinesOfCodeVisitor extends SubscriptionVisitor {
33 |
34 | private Set linesOfCode = Sets.newHashSet();
35 |
36 | public LinesOfCodeVisitor(Tree tree) {
37 | linesOfCode.clear();
38 | scanTree(tree);
39 | }
40 |
41 | @Override
42 | public List nodesToVisit() {
43 | return ImmutableList.of(Tree.Kind.TOKEN);
44 | }
45 |
46 | @Override
47 | public void visitNode(Tree tree) {
48 | InternalSyntaxToken token = (InternalSyntaxToken) tree;
49 | if (!token.isEOF() && !token.isBOM()) {
50 | linesOfCode.add(token.line());
51 | }
52 | }
53 |
54 | public int getNumberOfLinesOfCode() {
55 | return linesOfCode.size();
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/json/visitors/metrics/StatementsVisitor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.visitors.metrics;
21 |
22 | import com.google.common.collect.ImmutableList;
23 |
24 | import java.util.List;
25 |
26 | import org.sonar.plugins.json.api.tree.Tree;
27 | import org.sonar.plugins.json.api.visitors.SubscriptionVisitor;
28 |
29 | public class StatementsVisitor extends SubscriptionVisitor {
30 |
31 | private int statements;
32 |
33 | public StatementsVisitor(Tree tree) {
34 | statements = 0;
35 | scanTree(tree);
36 | }
37 |
38 | @Override
39 | public List nodesToVisit() {
40 | return ImmutableList.of(Tree.Kind.PAIR);
41 | }
42 |
43 | @Override
44 | public void visitNode(Tree tree) {
45 | statements++;
46 | }
47 |
48 | public int getNumberOfStatements() {
49 | return statements;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/json/visitors/metrics/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | @ParametersAreNonnullByDefault
21 | package org.sonar.json.visitors.metrics;
22 |
23 | import javax.annotation.ParametersAreNonnullByDefault;
24 |
25 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/json/visitors/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | @ParametersAreNonnullByDefault
21 | package org.sonar.json.visitors;
22 |
23 | import javax.annotation.ParametersAreNonnullByDefault;
24 |
25 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/plugins/json/api/JSONCheck.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.plugins.json.api;
21 |
22 | import java.util.List;
23 |
24 | import org.sonar.plugins.json.api.tree.Tree;
25 | import org.sonar.plugins.json.api.visitors.TreeVisitorContext;
26 | import org.sonar.plugins.json.api.visitors.issue.FileIssue;
27 | import org.sonar.plugins.json.api.visitors.issue.Issue;
28 | import org.sonar.plugins.json.api.visitors.issue.LineIssue;
29 | import org.sonar.plugins.json.api.visitors.issue.PreciseIssue;
30 |
31 | public interface JSONCheck {
32 |
33 | PreciseIssue addPreciseIssue(Tree tree, String message);
34 |
35 | FileIssue addFileIssue(String message);
36 |
37 | LineIssue addLineIssue(int line, String message);
38 |
39 | List scanFile(TreeVisitorContext context);
40 |
41 | void validateParameters();
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/plugins/json/api/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | @ParametersAreNonnullByDefault
21 | package org.sonar.plugins.json.api;
22 |
23 | import javax.annotation.ParametersAreNonnullByDefault;
24 |
25 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/plugins/json/api/tree/ArrayTree.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.plugins.json.api.tree;
21 |
22 | import java.util.List;
23 |
24 | public interface ArrayTree extends Tree {
25 |
26 | SyntaxToken leftBracket();
27 |
28 | List elements();
29 |
30 | SyntaxToken rightBracket();
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/plugins/json/api/tree/JsonTree.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.plugins.json.api.tree;
21 |
22 | public interface JsonTree extends Tree {
23 |
24 | boolean hasByteOrderMark();
25 |
26 | ValueTree value();
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/plugins/json/api/tree/KeyTree.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.plugins.json.api.tree;
21 |
22 | public interface KeyTree extends Tree {
23 |
24 | SyntaxToken value();
25 |
26 | String actualText();
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/plugins/json/api/tree/LiteralTree.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.plugins.json.api.tree;
21 |
22 | public interface LiteralTree extends Tree {
23 |
24 | SyntaxToken value();
25 |
26 | String text();
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/plugins/json/api/tree/ObjectTree.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.plugins.json.api.tree;
21 |
22 | import java.util.List;
23 |
24 | public interface ObjectTree extends Tree {
25 |
26 | SyntaxToken leftBrace();
27 |
28 | List pairs();
29 |
30 | SyntaxToken rightBrace();
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/plugins/json/api/tree/PairTree.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.plugins.json.api.tree;
21 |
22 | public interface PairTree extends Tree {
23 |
24 | KeyTree key();
25 |
26 | SyntaxToken colon();
27 |
28 | ValueTree value();
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/plugins/json/api/tree/StringTree.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.plugins.json.api.tree;
21 |
22 | public interface StringTree extends LiteralTree {
23 |
24 | /**
25 | * @return String without double quotes
26 | */
27 | String actualText();
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/plugins/json/api/tree/SyntaxSpacing.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.plugins.json.api.tree;
21 |
22 | public interface SyntaxSpacing extends Tree {
23 |
24 | String text();
25 |
26 | int line();
27 |
28 | int column();
29 |
30 | int endLine();
31 |
32 | int endColumn();
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/plugins/json/api/tree/SyntaxToken.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.plugins.json.api.tree;
21 |
22 | public interface SyntaxToken extends Tree {
23 |
24 | String text();
25 |
26 | int line();
27 |
28 | int column();
29 |
30 | int endLine();
31 |
32 | int endColumn();
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/plugins/json/api/tree/Tree.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.plugins.json.api.tree;
21 |
22 | import org.sonar.plugins.json.api.visitors.DoubleDispatchVisitor;
23 | import org.sonar.sslr.grammar.GrammarRuleKey;
24 |
25 | public interface Tree {
26 |
27 | boolean is(Kind... kind);
28 |
29 | void accept(DoubleDispatchVisitor visitor);
30 |
31 | enum Kind implements GrammarRuleKey {
32 |
33 | JSON(JsonTree.class),
34 | ARRAY(ArrayTree.class),
35 | OBJECT(ObjectTree.class),
36 | PAIR(PairTree.class),
37 | VALUE(ValueTree.class),
38 | KEY(KeyTree.class),
39 | STRING(StringTree.class),
40 | NUMBER(LiteralTree.class),
41 | FALSE(LiteralTree.class),
42 | TRUE(LiteralTree.class),
43 | NULL(LiteralTree.class),
44 | TOKEN(SyntaxToken.class),
45 | SPACING(SyntaxSpacing.class);
46 |
47 | final Class extends Tree> associatedInterface;
48 |
49 | Kind(Class extends Tree> associatedInterface) {
50 | this.associatedInterface = associatedInterface;
51 | }
52 |
53 | public Class extends Tree> getAssociatedInterface() {
54 | return associatedInterface;
55 | }
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/plugins/json/api/tree/ValueTree.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.plugins.json.api.tree;
21 |
22 | public interface ValueTree extends Tree {
23 |
24 | Tree value();
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/plugins/json/api/tree/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | @ParametersAreNonnullByDefault
21 | package org.sonar.plugins.json.api.tree;
22 |
23 | import javax.annotation.ParametersAreNonnullByDefault;
24 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/plugins/json/api/visitors/TreeVisitor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.plugins.json.api.visitors;
21 |
22 | public interface TreeVisitor {
23 |
24 | TreeVisitorContext getContext();
25 |
26 | void scanTree(TreeVisitorContext context);
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/plugins/json/api/visitors/TreeVisitorContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.plugins.json.api.visitors;
21 |
22 | import java.io.File;
23 |
24 | import org.sonar.plugins.json.api.tree.JsonTree;
25 |
26 | public interface TreeVisitorContext {
27 |
28 | /**
29 | * @return the top tree node of the current file AST representation.
30 | */
31 | JsonTree getTopTree();
32 |
33 | /**
34 | * @return the current file
35 | */
36 | File getFile();
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/plugins/json/api/visitors/issue/Issue.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.plugins.json.api.visitors.issue;
21 |
22 | import javax.annotation.Nullable;
23 |
24 | import org.sonar.plugins.json.api.JSONCheck;
25 |
26 | public interface Issue {
27 |
28 | JSONCheck check();
29 |
30 | @Nullable
31 | Double cost();
32 |
33 | Issue cost(double cost);
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/plugins/json/api/visitors/issue/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | @ParametersAreNonnullByDefault
21 | package org.sonar.plugins.json.api.visitors.issue;
22 |
23 | import javax.annotation.ParametersAreNonnullByDefault;
24 |
25 |
--------------------------------------------------------------------------------
/json-frontend/src/main/java/org/sonar/plugins/json/api/visitors/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | @ParametersAreNonnullByDefault
21 | package org.sonar.plugins.json.api.visitors;
22 |
23 | import javax.annotation.ParametersAreNonnullByDefault;
24 |
25 |
--------------------------------------------------------------------------------
/json-frontend/src/test/java/org/sonar/json/parser/BOMTreeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.parser;
21 |
22 | import org.junit.Test;
23 |
24 | public class BOMTreeTest extends CommonSyntaxTokenTreeTest {
25 |
26 | public BOMTreeTest() {
27 | super(JSONLexicalGrammar.BOM);
28 | }
29 |
30 | @Test
31 | public void bom() {
32 | checkParsed("\ufeff");
33 | }
34 |
35 | @Test
36 | public void notBom() {
37 | checkNotParsed("\"\\ufeff\"");
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/json-frontend/src/test/java/org/sonar/json/parser/ColonTreeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.parser;
21 |
22 | import org.junit.Test;
23 |
24 | public class ColonTreeTest extends CommonSyntaxTokenTreeTest {
25 |
26 | public ColonTreeTest() {
27 | super(JSONLexicalGrammar.COLON, ":");
28 | }
29 |
30 | @Test
31 | public void colon() {
32 | checkParsed(":");
33 | checkParsed(" :");
34 | checkParsed(" :");
35 | }
36 |
37 | @Test
38 | public void notColon() {
39 | checkNotParsed("=");
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/json-frontend/src/test/java/org/sonar/json/parser/CommaTreeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.parser;
21 |
22 | import org.junit.Test;
23 |
24 | public class CommaTreeTest extends CommonSyntaxTokenTreeTest {
25 |
26 | public CommaTreeTest() {
27 | super(JSONLexicalGrammar.COMMA, ",");
28 | }
29 |
30 | @Test
31 | public void comma() {
32 | checkParsed(",");
33 | checkParsed(" ,");
34 | checkParsed(" ,");
35 | }
36 |
37 | @Test
38 | public void notComma() {
39 | checkNotParsed(":");
40 | checkNotParsed(";");
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/json-frontend/src/test/java/org/sonar/json/parser/CommonJsonTreeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.parser;
21 |
22 | import com.google.common.base.Charsets;
23 | import com.google.common.io.Files;
24 | import com.sonar.sslr.api.typed.ActionParser;
25 | import org.sonar.plugins.json.api.tree.Tree;
26 |
27 | import java.io.File;
28 |
29 | import static org.junit.Assert.fail;
30 |
31 | public abstract class CommonJsonTreeTest {
32 |
33 | private final ActionParser parser;
34 |
35 | public CommonJsonTreeTest(JSONLexicalGrammar ruleKey) {
36 | parser = JSONParserBuilder.createTestParser(Charsets.UTF_8, ruleKey);
37 | }
38 |
39 | public ActionParser parser() {
40 | return parser;
41 | }
42 |
43 | public void checkNotParsed(String toParse) {
44 | try {
45 | parser.parse(toParse);
46 | } catch (Exception e) {
47 | return;
48 | }
49 | fail("Did not throw a RecognitionException as expected.");
50 | }
51 |
52 | public void checkNotParsed(File file) {
53 | try {
54 | parser.parse(Files.toString(file, Charsets.UTF_8));
55 | } catch (Exception e) {
56 | return;
57 | }
58 | fail("Did not throw a RecognitionException as expected.");
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/json-frontend/src/test/java/org/sonar/json/parser/CommonSyntaxTokenTreeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.parser;
21 |
22 | import org.sonar.plugins.json.api.tree.SyntaxToken;
23 |
24 | import static org.fest.assertions.Assertions.assertThat;
25 |
26 | public abstract class CommonSyntaxTokenTreeTest extends CommonJsonTreeTest {
27 |
28 | private String expectedText;
29 |
30 | public CommonSyntaxTokenTreeTest(JSONLexicalGrammar ruleKey) {
31 | super(ruleKey);
32 | this.expectedText = null;
33 | }
34 |
35 | public CommonSyntaxTokenTreeTest(JSONLexicalGrammar ruleKey, String expectedText) {
36 | super(ruleKey);
37 | this.expectedText = expectedText;
38 | }
39 |
40 | public void checkParsed(String toParse, String expected) {
41 | SyntaxToken token = (SyntaxToken) parser().parse(toParse);
42 | assertThat(token.text()).isEqualTo(expected);
43 | }
44 |
45 | public void checkParsed(String toParse) {
46 | checkParsed(
47 | toParse,
48 | expectedText != null ? expectedText : toParse);
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/json-frontend/src/test/java/org/sonar/json/parser/FalseTreeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.parser;
21 |
22 | import org.junit.Test;
23 |
24 | public class FalseTreeTest extends CommonSyntaxTokenTreeTest {
25 |
26 | public FalseTreeTest() {
27 | super(JSONLexicalGrammar.FALSE, "false");
28 | }
29 |
30 | @Test
31 | public void isFalse() {
32 | checkParsed("false");
33 | checkParsed(" false");
34 | checkParsed(" false");
35 | }
36 |
37 | @Test
38 | public void notFalse() {
39 | checkNotParsed("FALSE");
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/json-frontend/src/test/java/org/sonar/json/parser/LeftBraceTreeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.parser;
21 |
22 | import org.junit.Test;
23 |
24 | public class LeftBraceTreeTest extends CommonSyntaxTokenTreeTest {
25 |
26 | public LeftBraceTreeTest() {
27 | super(JSONLexicalGrammar.LEFT_BRACE, "{");
28 | }
29 |
30 | @Test
31 | public void leftBrace() {
32 | checkParsed("{");
33 | checkParsed(" {");
34 | checkParsed(" {");
35 | }
36 |
37 | @Test
38 | public void notLeftBrace() {
39 | checkNotParsed("[");
40 | checkNotParsed("}");
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/json-frontend/src/test/java/org/sonar/json/parser/LeftBracketTreeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.parser;
21 |
22 | import org.junit.Test;
23 |
24 | public class LeftBracketTreeTest extends CommonSyntaxTokenTreeTest {
25 |
26 | public LeftBracketTreeTest() {
27 | super(JSONLexicalGrammar.LEFT_BRACKET, "[");
28 | }
29 |
30 | @Test
31 | public void leftBracket() {
32 | checkParsed("[");
33 | checkParsed(" [");
34 | checkParsed(" [");
35 | }
36 |
37 | @Test
38 | public void notLeftBracket() {
39 | checkNotParsed("]");
40 | checkNotParsed("{");
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/json-frontend/src/test/java/org/sonar/json/parser/NullTreeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.parser;
21 |
22 | import org.junit.Test;
23 |
24 | public class NullTreeTest extends CommonSyntaxTokenTreeTest {
25 |
26 | public NullTreeTest() {
27 | super(JSONLexicalGrammar.NULL, "null");
28 | }
29 |
30 | @Test
31 | public void isNull() {
32 | checkParsed("null");
33 | checkParsed(" null", "null");
34 | checkParsed(" null", "null");
35 | }
36 |
37 | @Test
38 | public void notNull() {
39 | checkNotParsed("NULL");
40 | checkNotParsed("\"NULL\"");
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/json-frontend/src/test/java/org/sonar/json/parser/RightBraceTreeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.parser;
21 |
22 | import com.google.common.base.Charsets;
23 | import org.junit.Test;
24 | import org.sonar.plugins.json.api.tree.SyntaxToken;
25 |
26 | public class RightBraceTreeTest extends CommonSyntaxTokenTreeTest {
27 |
28 | public RightBraceTreeTest() {
29 | super(JSONLexicalGrammar.RIGHT_BRACE, "}");
30 | }
31 |
32 | @Test
33 | public void rightBrace() {
34 | checkParsed("}");
35 | checkParsed(" }");
36 | checkParsed(" }");
37 | }
38 |
39 | @Test
40 | public void notRightBrace() {
41 | checkNotParsed("{");
42 | checkNotParsed("]");
43 | }
44 |
45 | private SyntaxToken parse(String toParse) {
46 | return (SyntaxToken) JSONParserBuilder
47 | .createTestParser(Charsets.UTF_8, JSONLexicalGrammar.RIGHT_BRACE)
48 | .parse(toParse);
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/json-frontend/src/test/java/org/sonar/json/parser/RightBracketTreeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.parser;
21 |
22 | import org.junit.Test;
23 |
24 | public class RightBracketTreeTest extends CommonSyntaxTokenTreeTest {
25 |
26 | public RightBracketTreeTest() {
27 | super(JSONLexicalGrammar.RIGHT_BRACKET, "]");
28 | }
29 |
30 | @Test
31 | public void rightBracket() {
32 | checkParsed("]");
33 | checkParsed(" ]");
34 | checkParsed(" ]");
35 | }
36 |
37 | @Test
38 | public void notRightBracket() {
39 | checkNotParsed("[");
40 | checkNotParsed("}");
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/json-frontend/src/test/java/org/sonar/json/parser/TrueTreeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.parser;
21 |
22 | import org.junit.Test;
23 |
24 | public class TrueTreeTest extends CommonSyntaxTokenTreeTest {
25 |
26 | public TrueTreeTest() {
27 | super(JSONLexicalGrammar.TRUE, "true");
28 | }
29 |
30 | @Test
31 | public void isTrue() {
32 | checkParsed("true");
33 | checkParsed(" true", "true");
34 | checkParsed(" true", "true");
35 | }
36 |
37 | @Test
38 | public void notTrue() {
39 | checkNotParsed("TRUE");
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/json-frontend/src/test/java/org/sonar/json/visitors/metrics/MetricsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.json.visitors.metrics;
21 |
22 | import com.google.common.base.Charsets;
23 | import com.sonar.sslr.api.typed.ActionParser;
24 | import org.junit.Test;
25 | import org.sonar.json.parser.JSONParserBuilder;
26 | import org.sonar.plugins.json.api.tree.Tree;
27 |
28 | import java.io.File;
29 |
30 | import static org.fest.assertions.Assertions.assertThat;
31 |
32 | public class MetricsTest {
33 |
34 | private static final ActionParser PARSER = JSONParserBuilder.createParser(Charsets.UTF_8);
35 |
36 | @Test
37 | public void metrics() {
38 | String path = "src/test/resources/metrics.json";
39 | Tree tree = PARSER.parse(new File(path));
40 | assertMetrics(tree);
41 | }
42 |
43 | @Test
44 | public void metrics_UTF8_file_with_BOM() {
45 | String path = "src/test/resources/metricsUtf8WithBom.json";
46 | Tree tree = PARSER.parse(new File(path));
47 | assertMetrics(tree);
48 | }
49 |
50 | private void assertMetrics(Tree tree) {
51 | assertThat(new LinesOfCodeVisitor(tree).getNumberOfLinesOfCode()).isEqualTo(6);
52 | assertThat(new StatementsVisitor(tree).getNumberOfStatements()).isEqualTo(7);
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/json-frontend/src/test/resources/file1.json:
--------------------------------------------------------------------------------
1 | {
2 | "def": {},
3 | "abc" : [123, 234],
4 | "abc" : 123,
5 |
6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]}
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/json-frontend/src/test/resources/metrics.json:
--------------------------------------------------------------------------------
1 | {
2 | "def": {},
3 | "abc" : [123, 234],
4 | "abc" : 123,
5 |
6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]}
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/json-frontend/src/test/resources/metricsUtf8WithBom.json:
--------------------------------------------------------------------------------
1 | {
2 | "def": {},
3 | "abc" : [123, 234],
4 | "abc" : 123,
5 |
6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]}
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/sonar-json-plugin/src/main/java/org/sonar/plugins/json/JSONLanguage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.plugins.json;
21 |
22 | import org.sonar.api.resources.AbstractLanguage;
23 |
24 | public class JSONLanguage extends AbstractLanguage {
25 |
26 | public static final String KEY = "json";
27 |
28 | public JSONLanguage() {
29 | super(KEY, "JSON");
30 | }
31 |
32 | @Override
33 | public String[] getFileSuffixes() {
34 | return new String[] {"json"};
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/sonar-json-plugin/src/main/java/org/sonar/plugins/json/JSONPlugin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.plugins.json;
21 |
22 | import org.sonar.api.Plugin;
23 |
24 | public class JSONPlugin implements Plugin {
25 |
26 | @Override
27 | public void define(Context context) {
28 | context.addExtensions(
29 | JSONLanguage.class,
30 | JSONSquidSensor.class,
31 | JSONProfile.class,
32 | JSONRulesDefinition.class);
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/sonar-json-plugin/src/main/java/org/sonar/plugins/json/JSONProfile.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.plugins.json;
21 |
22 | import org.sonar.api.profiles.ProfileDefinition;
23 | import org.sonar.api.profiles.RulesProfile;
24 | import org.sonar.api.rules.RuleFinder;
25 | import org.sonar.api.utils.ValidationMessages;
26 | import org.sonar.json.checks.CheckList;
27 | import org.sonar.squidbridge.annotations.AnnotationBasedProfileBuilder;
28 |
29 | public class JSONProfile extends ProfileDefinition {
30 |
31 | private final RuleFinder ruleFinder;
32 |
33 | public static final String SONARQUBE_WAY_PROFILE_NAME = "SonarQube Way";
34 |
35 | public JSONProfile(RuleFinder ruleFinder) {
36 | this.ruleFinder = ruleFinder;
37 | }
38 |
39 | @Override
40 | public RulesProfile createProfile(ValidationMessages messages) {
41 | AnnotationBasedProfileBuilder annotationBasedProfileBuilder = new AnnotationBasedProfileBuilder(ruleFinder);
42 | return annotationBasedProfileBuilder.build(
43 | CheckList.REPOSITORY_KEY,
44 | SONARQUBE_WAY_PROFILE_NAME,
45 | JSONLanguage.KEY,
46 | CheckList.getChecks(),
47 | messages);
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/sonar-json-plugin/src/main/java/org/sonar/plugins/json/JSONRulesDefinition.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.plugins.json;
21 |
22 | import org.sonar.api.server.rule.RulesDefinition;
23 | import org.sonar.json.checks.CheckList;
24 | import org.sonar.squidbridge.annotations.AnnotationBasedRulesDefinition;
25 |
26 | public class JSONRulesDefinition implements RulesDefinition {
27 |
28 | @Override
29 | public void define(Context context) {
30 | NewRepository repository = context
31 | .createRepository(JSONLanguage.KEY, JSONLanguage.KEY)
32 | .setName(CheckList.REPOSITORY_NAME);
33 |
34 | new AnnotationBasedRulesDefinition(repository, JSONLanguage.KEY).addRuleClasses(false, CheckList.getChecks());
35 | repository.done();
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/sonar-json-plugin/src/main/java/org/sonar/plugins/json/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | @ParametersAreNonnullByDefault
21 | package org.sonar.plugins.json;
22 |
23 | import javax.annotation.ParametersAreNonnullByDefault;
24 |
25 |
--------------------------------------------------------------------------------
/sonar-json-plugin/src/test/java/org/sonar/plugins/json/JSONLanguageTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.plugins.json;
21 |
22 | import org.junit.Test;
23 |
24 | import static org.fest.assertions.Assertions.assertThat;
25 |
26 | public class JSONLanguageTest {
27 |
28 | @Test
29 | public void language_key_and_name() {
30 | JSONLanguage json = new JSONLanguage();
31 | assertThat(json.getKey()).isEqualTo("json");
32 | assertThat(json.getName()).isEqualTo("JSON");
33 | }
34 |
35 | @Test
36 | public void default_file_suffix() {
37 | JSONLanguage json = new JSONLanguage();
38 | assertThat(json.getFileSuffixes()).containsOnly("json");
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/sonar-json-plugin/src/test/java/org/sonar/plugins/json/JSONPluginTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.plugins.json;
21 |
22 | import org.junit.Test;
23 | import org.sonar.api.Plugin;
24 | import org.sonar.api.utils.Version;
25 |
26 | import static org.fest.assertions.Assertions.assertThat;
27 |
28 | public class JSONPluginTest {
29 |
30 | @Test
31 | public void should_get_the_right_version() {
32 | Plugin.Context context = new Plugin.Context(Version.create(5, 6));
33 | new JSONPlugin().define(context);
34 | assertThat(context.getSonarQubeVersion().major()).isEqualTo(5);
35 | assertThat(context.getSonarQubeVersion().minor()).isEqualTo(6);
36 | }
37 |
38 | @Test
39 | public void should_get_the_right_number_of_extensions() {
40 | Plugin.Context context = new Plugin.Context(Version.create(5, 6));
41 | new JSONPlugin().define(context);
42 | assertThat(context.getExtensions()).hasSize(4);
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/sonar-json-plugin/src/test/java/org/sonar/plugins/json/JSONRulesDefinitionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarQube JSON Analyzer
3 | * Copyright (C) 2015-2017 David RACODON
4 | * david.racodon@gmail.com
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program; if not, write to the Free Software Foundation,
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 | */
20 | package org.sonar.plugins.json;
21 |
22 | import org.junit.Test;
23 | import org.sonar.api.server.rule.RulesDefinition;
24 | import org.sonar.check.Rule;
25 | import org.sonar.json.checks.CheckList;
26 | import org.sonar.json.checks.generic.FileNameCheck;
27 |
28 | import static org.fest.assertions.Assertions.assertThat;
29 |
30 | public class JSONRulesDefinitionTest {
31 |
32 | @Test
33 | public void test() {
34 | JSONRulesDefinition rulesDefinition = new JSONRulesDefinition();
35 | RulesDefinition.Context context = new RulesDefinition.Context();
36 | rulesDefinition.define(context);
37 | RulesDefinition.Repository repository = context.repository("json");
38 |
39 | assertThat(repository.name()).isEqualTo("SonarQube");
40 | assertThat(repository.language()).isEqualTo("json");
41 | assertThat(repository.rules()).hasSize(CheckList.getChecks().size());
42 |
43 | RulesDefinition.Rule fileNameRule = repository.rule(FileNameCheck.class.getAnnotation(Rule.class).key());
44 | assertThat(fileNameRule).isNotNull();
45 | assertThat(fileNameRule.name()).isEqualTo(FileNameCheck.class.getAnnotation(Rule.class).name());
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/sonar-json-plugin/src/test/resources/parsingError.json:
--------------------------------------------------------------------------------
1 | blabla...
--------------------------------------------------------------------------------
/sonar-json-plugin/src/test/resources/sample.json:
--------------------------------------------------------------------------------
1 | {
2 | "def": {},
3 | "abc" : [123, 234],
4 | "abc" : 123,
5 |
6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]}
7 | }
--------------------------------------------------------------------------------
/sonar-json-plugin/src/test/resources/sampleUTF8WithBOM.json:
--------------------------------------------------------------------------------
1 | {
2 | "def": {},
3 | "abc" : [123, 234],
4 | "abc" : 123,
5 |
6 | "zzz": { "ddd": "jjj", "aaa": "\"jjj", "ee": [244, 333]}
7 | }
--------------------------------------------------------------------------------
/travis.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -euo pipefail
4 |
5 | mvn -B clean install -Pits -Dsonar.runtimeVersion=$SQ_VERSION
6 |
7 | if [ "$SQ_VERSION" == "LTS" ]; then
8 |
9 | mvnCommand='mvn -B sonar:sonar'
10 | commonArgs="-Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN -Dsonar.organization=racodond-github"
11 | githubArgs="-Dsonar.analysis.mode=preview -Dsonar.github.pullRequest=$TRAVIS_PULL_REQUEST -Dsonar.github.repository=$TRAVIS_REPO_SLUG -Dsonar.github.oauth=$GITHUB_TOKEN"
12 | branchArgs=''
13 |
14 | if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
15 | if [ "$TRAVIS_BRANCH" != "master" ]; then
16 | branchArgs="-Dsonar.branch.name=$TRAVIS_BRANCH -Dsonar.branch.target=master"
17 | fi
18 | eval $mvnCommand $commonArgs $branchArgs
19 | else
20 | eval $mvnCommand $commonArgs $githubArgs
21 | fi
22 |
23 | fi
24 |
--------------------------------------------------------------------------------