tagsToOpen,
113 | StringBuilder decoratedText) {
114 | for (String tagToOpen : tagsToOpen) {
115 | injectOpeningHtmlForRule(tagToOpen, decoratedText);
116 | charactersReader.registerOpenTag(tagToOpen);
117 | }
118 | }
119 |
120 | private static void closeCurrentSyntaxTags(CharactersReader charactersReader, StringBuilder decoratedText) {
121 | for (int i = 0; i < charactersReader.getOpenTags().size(); i++) {
122 | injectClosingHtml(decoratedText);
123 | }
124 | }
125 |
126 | private static void injectOpeningHtmlForRule(String textType, StringBuilder decoratedText) {
127 | decoratedText.append("");
128 | }
129 |
130 | private static void injectClosingHtml(StringBuilder decoratedText) {
131 | decoratedText.append("");
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/src/main/java/org/sonarlint/cli/report/source/OpeningHtmlTag.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.report.source;
21 |
22 | class OpeningHtmlTag {
23 |
24 | private final int startOffset;
25 | private final String cssClass;
26 |
27 | OpeningHtmlTag(int startOffset, String cssClass) {
28 | this.startOffset = startOffset;
29 | this.cssClass = cssClass;
30 | }
31 |
32 | int getStartOffset() {
33 | return startOffset;
34 | }
35 |
36 | String getCssClass() {
37 | return cssClass;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/org/sonarlint/cli/report/source/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.report.source;
22 |
23 | import javax.annotation.ParametersAreNonnullByDefault;
24 |
--------------------------------------------------------------------------------
/src/main/java/org/sonarlint/cli/util/Logger.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.util;
21 |
22 | import java.io.PrintStream;
23 |
24 | public class Logger {
25 | private static volatile Logger instance;
26 | private boolean debugEnabled = false;
27 | private boolean displayStackTrace = false;
28 | private PrintStream stdOut;
29 | private PrintStream stdErr;
30 |
31 | private Logger() {
32 | this.stdErr = System.err;
33 | this.stdOut = System.out;
34 | }
35 |
36 | public Logger(PrintStream stdOut, PrintStream stdErr) {
37 | this.stdErr = stdErr;
38 | this.stdOut = stdOut;
39 | }
40 |
41 | public static Logger get() {
42 | if (instance == null) {
43 | instance = new Logger();
44 | }
45 | return instance;
46 | }
47 |
48 | public static void set(PrintStream stdOut, PrintStream stdErr) {
49 | get().stdOut = stdOut;
50 | get().stdErr = stdErr;
51 | }
52 |
53 | public void setDebugEnabled(boolean debugEnabled) {
54 | this.debugEnabled = debugEnabled;
55 | }
56 |
57 | public void setDisplayStackTrace(boolean displayStackTrace) {
58 | this.displayStackTrace = displayStackTrace;
59 | }
60 |
61 | public boolean isDebugEnabled() {
62 | return debugEnabled;
63 | }
64 |
65 | public void debug(String message) {
66 | if (isDebugEnabled()) {
67 | stdOut.println("DEBUG: " + message);
68 | }
69 | }
70 |
71 | public void debug(String message, Throwable t) {
72 | if (isDebugEnabled()) {
73 | stdErr.println("DEBUG: " + message);
74 | if (displayStackTrace) {
75 | t.printStackTrace(stdErr);
76 | }
77 | }
78 | }
79 |
80 | public void info(String message) {
81 | stdOut.println("INFO: " + message);
82 | }
83 |
84 | public void warn(String message) {
85 | stdOut.println("WARN: " + message);
86 | }
87 |
88 | public void error(String message) {
89 | stdErr.println("ERROR: " + message);
90 | }
91 |
92 | public void error(String message, Throwable t) {
93 | stdErr.println("ERROR: " + message);
94 | if (displayStackTrace) {
95 | t.printStackTrace(stdErr);
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/main/java/org/sonarlint/cli/util/MutableInt.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.util;
21 |
22 | public class MutableInt {
23 | private int value;
24 |
25 | public MutableInt() {
26 | this(0);
27 | }
28 |
29 | public MutableInt(int value) {
30 | this.value = value;
31 | }
32 |
33 | public void set(int value) {
34 | this.value = value;
35 | }
36 |
37 | public int get() {
38 | return value;
39 | }
40 |
41 | public void inc() {
42 | value++;
43 | }
44 |
45 | @Override
46 | public int hashCode() {
47 | return value;
48 | }
49 |
50 | @Override
51 | public boolean equals(Object obj) {
52 | if (this == obj) {
53 | return true;
54 | }
55 | if (obj == null || getClass() != obj.getClass()) {
56 | return false;
57 | }
58 | MutableInt other = (MutableInt) obj;
59 | return value == other.value;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/org/sonarlint/cli/util/System2.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.util;
21 |
22 | import javax.annotation.CheckForNull;
23 |
24 | import java.util.Map;
25 | import java.util.Properties;
26 |
27 | /**
28 | * Proxy over {@link java.lang.System}. It aims to improve testability of classes
29 | * that interact with low-level system methods, for example :
30 | *
31 | *
32 | * public class MyClass {
33 | * private final System2 system;
34 | *
35 | * public MyClass(System2 s) {
36 | * this.system = s;
37 | * }
38 | *
39 | * public long xxx() {
40 | * return system.now();
41 | * }
42 | * }
43 | *
44 | * {@literal @}Test
45 | * public void should_return_xxx() {
46 | * // using Mockito
47 | * System2 system = mock(System2.class);
48 | * long now = 123456789L;
49 | * doReturn(now).when(system).now();
50 | * assertThat(new MyClass(system).xxx()).isEqualTo(now);
51 | * }
52 | *
53 | *
54 | * Note that the name System2 was chosen to not conflict with {@link java.lang.System}.
55 | *
56 | */
57 | public class System2 {
58 |
59 | public static final System2 INSTANCE = new System2();
60 |
61 | /**
62 | * Shortcut for {@link System#currentTimeMillis()}
63 | */
64 | public long now() {
65 | return System.currentTimeMillis();
66 | }
67 |
68 | /**
69 | * Shortcut for {@link System#getProperties()}
70 | */
71 | public Properties properties() {
72 | return System.getProperties();
73 | }
74 |
75 | /**
76 | * Shortcut for {@link System#getProperty(String)}
77 | */
78 | @CheckForNull
79 | public String property(String key) {
80 | return System.getProperty(key);
81 | }
82 |
83 | /**
84 | * Shortcut for {@link System#getProperty(String)}
85 | */
86 | @CheckForNull
87 | public String getProperty(String key) {
88 | return System.getProperty(key);
89 | }
90 |
91 | /**
92 | * Shortcut for {@link System#getenv(String)}
93 | */
94 | @CheckForNull
95 | public String getenv(String key) {
96 | return System.getenv(key);
97 | }
98 |
99 | public void exit(int code) {
100 | System.exit(code);
101 | }
102 |
103 | /**
104 | * Shortcut for {@link System#getenv()}
105 | */
106 | public Map envVariables() {
107 | return System.getenv();
108 | }
109 |
110 | /**
111 | * Shortcut for {@link System#getenv(String)}
112 | */
113 | @CheckForNull
114 | public String envVariable(String key) {
115 | return System.getenv(key);
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/src/main/java/org/sonarlint/cli/util/SystemInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.util;
21 |
22 | public class SystemInfo {
23 | private static System2 system = new System2();
24 |
25 | private SystemInfo() {
26 | }
27 |
28 | public static void setSystem(System2 system) {
29 | SystemInfo.system = system;
30 | }
31 |
32 | public static void print(Logger logger) {
33 | logger.info(java());
34 | logger.info(os());
35 | String runnerOpts = system.getenv("SONARLINT_OPTS");
36 | if (runnerOpts != null) {
37 | logger.info("SONARLINT_OPTS=" + runnerOpts);
38 | }
39 | }
40 |
41 | public static String getVersion() {
42 | String version = "unknown";
43 |
44 | Package p = SystemInfo.class.getPackage();
45 | if (p != null) {
46 | String implVersion = p.getImplementationVersion();
47 | if (implVersion != null) {
48 | version = implVersion;
49 | }
50 | }
51 |
52 | return version;
53 | }
54 |
55 | public static String java() {
56 | StringBuilder sb = new StringBuilder();
57 | sb
58 | .append("Java ")
59 | .append(system.getProperty("java.version"))
60 | .append(" ")
61 | .append(system.getProperty("java.vendor"));
62 | String bits = system.getProperty("sun.arch.data.model");
63 | if ("32".equals(bits) || "64".equals(bits)) {
64 | sb.append(" (").append(bits).append("-bit)");
65 | }
66 | return sb.toString();
67 | }
68 |
69 | public static String os() {
70 | StringBuilder sb = new StringBuilder();
71 | sb
72 | .append(system.getProperty("os.name"))
73 | .append(" ")
74 | .append(system.getProperty("os.version"))
75 | .append(" ")
76 | .append(system.getProperty("os.arch"));
77 | return sb.toString();
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/org/sonarlint/cli/util/Util.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.util;
21 |
22 | import java.util.HashMap;
23 | import java.util.Map;
24 | import java.util.Properties;
25 | import java.util.function.Supplier;
26 |
27 | public class Util {
28 | private Util() {
29 | // static only
30 | }
31 |
32 | public static U getOrCreate(Map map, T key, Supplier f) {
33 | U value = map.get(key);
34 | if (value != null) {
35 | return value;
36 | }
37 | value = f.get();
38 | map.put(key, value);
39 | return value;
40 | }
41 |
42 | public static Map toMap(Properties properties) {
43 | return new HashMap<>((Map) properties);
44 | }
45 |
46 | public static String escapeFileName(String fileName) {
47 | return fileName.replaceAll("[^a-zA-Z0-9.-]", "_");
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/org/sonarlint/cli/util/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.util;
22 |
23 | import javax.annotation.ParametersAreNonnullByDefault;
24 |
--------------------------------------------------------------------------------
/src/main/resources/org/sonarlint/cli/report/sonarlintreport_files/DIR.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SonarSource/sonarlint-cli/be030e98d118c41b39762b3becb04d309653030f/src/main/resources/org/sonarlint/cli/report/sonarlintreport_files/DIR.png
--------------------------------------------------------------------------------
/src/main/resources/org/sonarlint/cli/report/sonarlintreport_files/FIL.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SonarSource/sonarlint-cli/be030e98d118c41b39762b3becb04d309653030f/src/main/resources/org/sonarlint/cli/report/sonarlintreport_files/FIL.png
--------------------------------------------------------------------------------
/src/main/resources/org/sonarlint/cli/report/sonarlintreport_files/PRJ.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SonarSource/sonarlint-cli/be030e98d118c41b39762b3becb04d309653030f/src/main/resources/org/sonarlint/cli/report/sonarlintreport_files/PRJ.png
--------------------------------------------------------------------------------
/src/main/resources/org/sonarlint/cli/report/sonarlintreport_files/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SonarSource/sonarlint-cli/be030e98d118c41b39762b3becb04d309653030f/src/main/resources/org/sonarlint/cli/report/sonarlintreport_files/favicon.ico
--------------------------------------------------------------------------------
/src/main/resources/org/sonarlint/cli/report/sonarlintreport_files/rule.css:
--------------------------------------------------------------------------------
1 | body {
2 | font-family: Helvetica Neue, Segoe UI, Helvetica, Arial, sans-serif;
3 | font-size: 13px;
4 | line-height: 1.23076923;
5 | }
6 |
7 | h1 {
8 | color: #444;
9 | font-size: 14px;
10 | font-weight: 500;
11 | }
12 |
13 | h2 {
14 | line-height: 24px;
15 | color: #444;
16 | }
17 |
18 | a {
19 | border-bottom: 1px solid #cae3f2;
20 | color: #236a97;
21 | cursor: pointer;
22 | outline: none;
23 | text-decoration: none;
24 | transition: all .2s ease;
25 | }
26 |
27 | .rule-desc {
28 | line-height: 1.5;
29 | }
30 |
31 | .rule-desc {
32 | line-height: 1.5;
33 | }
34 |
35 | .rule-desc h2 {
36 | font-size: 16px;
37 | font-weight: 400;
38 | }
39 |
40 | .rule-desc code {
41 | padding: .2em .45em;
42 | margin: 0;
43 | background-color: rgba(0, 0, 0, .04);
44 | border-radius: 3px;
45 | white-space: nowrap;
46 | }
47 |
48 | .rule-desc pre {
49 | padding: 10px;
50 | border-top: 1px solid #e6e6e6;
51 | border-bottom: 1px solid #e6e6e6;
52 | line-height: 18px;
53 | overflow: auto;
54 | }
55 |
56 | .rule-desc code, .rule-desc pre {
57 | font-family: Consolas, Liberation Mono, Menlo, Courier, monospace;
58 | font-size: 12px;
59 | }
60 |
61 | .rule-desc ul {
62 | padding-left: 40px;
63 | list-style: disc;
64 | }
--------------------------------------------------------------------------------
/src/main/resources/org/sonarlint/cli/report/sonarlintreport_files/sep12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SonarSource/sonarlint-cli/be030e98d118c41b39762b3becb04d309653030f/src/main/resources/org/sonarlint/cli/report/sonarlintreport_files/sep12.png
--------------------------------------------------------------------------------
/src/main/resources/org/sonarlint/cli/report/sonarlintreport_files/sonar.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SonarSource/sonarlint-cli/be030e98d118c41b39762b3becb04d309653030f/src/main/resources/org/sonarlint/cli/report/sonarlintreport_files/sonar.eot
--------------------------------------------------------------------------------
/src/main/resources/org/sonarlint/cli/report/sonarlintreport_files/sonar.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SonarSource/sonarlint-cli/be030e98d118c41b39762b3becb04d309653030f/src/main/resources/org/sonarlint/cli/report/sonarlintreport_files/sonar.ttf
--------------------------------------------------------------------------------
/src/main/resources/org/sonarlint/cli/report/sonarlintreport_files/sonar.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SonarSource/sonarlint-cli/be030e98d118c41b39762b3becb04d309653030f/src/main/resources/org/sonarlint/cli/report/sonarlintreport_files/sonar.woff
--------------------------------------------------------------------------------
/src/main/resources/org/sonarlint/cli/report/sonarlintreport_files/sonarlint.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SonarSource/sonarlint-cli/be030e98d118c41b39762b3becb04d309653030f/src/main/resources/org/sonarlint/cli/report/sonarlintreport_files/sonarlint.png
--------------------------------------------------------------------------------
/src/test/java/org/sonarlint/cli/OptionsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli;
21 |
22 | import java.text.ParseException;
23 | import org.junit.Rule;
24 | import org.junit.Test;
25 | import org.junit.rules.ExpectedException;
26 |
27 | import static org.assertj.core.api.Assertions.assertThat;
28 |
29 | public class OptionsTest {
30 | @Rule
31 | public ExpectedException exception = ExpectedException.none();
32 |
33 | @Test
34 | public void testHelp() throws ParseException {
35 | Options opt = Options.parse(args("-h"));
36 | assertThat(opt.isHelp()).isTrue();
37 |
38 | opt = Options.parse(args("--help"));
39 | assertThat(opt.isHelp()).isTrue();
40 | }
41 |
42 | @Test
43 | public void testReport() throws ParseException {
44 | Options opt = Options.parse(args("--html-report", "myreport"));
45 |
46 | assertThat(opt.htmlReport()).isEqualTo("myreport");
47 | }
48 |
49 | @Test
50 | public void testGlobs() throws ParseException {
51 | Options opt = Options.parse(args("--src", "source", "--tests", "tests", "--exclude", "exclude"));
52 |
53 | assertThat(opt.src()).isEqualTo("source");
54 | assertThat(opt.tests()).isEqualTo("tests");
55 | assertThat(opt.exclusions()).isEqualTo("exclude");
56 | }
57 |
58 | @Test
59 | public void testStack() throws ParseException {
60 | Options opt = Options.parse(args("-e"));
61 | assertThat(opt.showStack()).isTrue();
62 |
63 | opt = Options.parse(args("--errors"));
64 | assertThat(opt.showStack()).isTrue();
65 | }
66 |
67 | @Test
68 | public void testCharset() throws ParseException {
69 | Options opt = Options.parse(args("--charset", "UTF-8"));
70 | assertThat(opt.charset()).isEqualTo("UTF-8");
71 | }
72 |
73 | @Test
74 | public void testUpdate() throws ParseException {
75 | Options opt = Options.parse(args("-u"));
76 | assertThat(opt.isUpdate()).isTrue();
77 |
78 | opt = Options.parse(args("--update"));
79 | assertThat(opt.isUpdate()).isTrue();
80 | }
81 |
82 | @Test
83 | public void testInteractive() throws ParseException {
84 | Options opt = Options.parse(args("-i"));
85 | assertThat(opt.isInteractive()).isTrue();
86 |
87 | opt = Options.parse(args("--interactive"));
88 | assertThat(opt.isInteractive()).isTrue();
89 | }
90 |
91 | @Test
92 | public void testVersion() throws ParseException {
93 | Options opt = Options.parse(args("-v"));
94 | assertThat(opt.isVersion()).isTrue();
95 |
96 | opt = Options.parse(args("--version"));
97 | assertThat(opt.isVersion()).isTrue();
98 | }
99 |
100 | @Test
101 | public void testVerbose() throws ParseException {
102 | Options opt = Options.parse(args("-X"));
103 | assertThat(opt.isVerbose()).isTrue();
104 | }
105 |
106 | @Test
107 | public void testTask() throws ParseException {
108 | Options opt = Options.parse(args("mytask"));
109 | assertThat(opt.task()).isEqualTo("mytask");
110 | }
111 |
112 | @Test
113 | public void testInvalidArg() throws ParseException {
114 | exception.expect(ParseException.class);
115 | exception.expectMessage("Unrecognized option:");
116 | Options.parse(args("-a"));
117 | }
118 |
119 | @Test
120 | public void testArgMissing() throws ParseException {
121 | exception.expect(ParseException.class);
122 | exception.expectMessage("Missing argument for option -D");
123 | Options.parse(args("-D"));
124 | }
125 |
126 | @Test
127 | public void testProperties() throws ParseException {
128 | Options opt = Options.parse(args("-Dkey=value", "--define", "key2=value2"));
129 |
130 | assertThat(opt.properties()).containsEntry("key", "value");
131 | assertThat(opt.properties()).containsEntry("key2", "value2");
132 | }
133 |
134 | @Test
135 | public void testCombinedOptions() throws ParseException {
136 | Options opt = Options.parse(args("-X", "-e", "--help"));
137 |
138 | assertThat(opt.isVerbose()).isTrue();
139 | assertThat(opt.showStack()).isTrue();
140 | assertThat(opt.isHelp()).isTrue();
141 | }
142 |
143 | private static String[] args(String... str) {
144 | return str;
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/src/test/java/org/sonarlint/cli/StatsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli;
21 |
22 | import org.mockito.Mockito;
23 | import org.sonarlint.cli.util.Logger;
24 |
25 | import java.io.PrintStream;
26 | import java.io.UnsupportedEncodingException;
27 |
28 | import static org.mockito.Mockito.verify;
29 | import static org.mockito.Mockito.mock;
30 |
31 | import org.junit.Before;
32 | import org.junit.Test;
33 |
34 | import static org.assertj.core.api.Assertions.assertThat;
35 |
36 | public class StatsTest {
37 | private PrintStream stdOut = mock(PrintStream.class);
38 | private PrintStream stdErr;
39 |
40 | @Before
41 | public void setUp() {
42 | Logger.set(stdOut, stdErr);
43 | }
44 |
45 | @Test
46 | public void shouldPrintStats() throws UnsupportedEncodingException {
47 | new Stats().start().stop();
48 |
49 | verify(stdOut).println(Mockito.contains("Total time: "));
50 | verify(stdOut).println(Mockito.contains("Final Memory: "));
51 | }
52 |
53 | @Test
54 | public void shouldFormatTime() {
55 | assertThat(Stats.formatTime(1 * 60 * 60 * 1000 + 2 * 60 * 1000 + 3 * 1000 + 400)).isEqualTo("1:02:03.400s");
56 | assertThat(Stats.formatTime(2 * 60 * 1000 + 3 * 1000 + 400)).isEqualTo("2:03.400s");
57 | assertThat(Stats.formatTime(3 * 1000 + 400)).isEqualTo("3.400s");
58 | assertThat(Stats.formatTime(400)).isEqualTo("0.400s");
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/test/java/org/sonarlint/cli/TestUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli;
21 |
22 | import org.sonarlint.cli.report.RichIssue;
23 | import org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile;
24 |
25 | import static org.mockito.Mockito.mock;
26 | import static org.mockito.Mockito.when;
27 |
28 | public class TestUtils {
29 | public static RichIssue createTestIssue(String filePath, String ruleKey, String severity, int line) {
30 | ClientInputFile inputFile = mock(ClientInputFile.class);
31 | when(inputFile.getPath()).thenReturn(filePath);
32 |
33 | RichIssue issue = mock(RichIssue.class);
34 | when(issue.getStartLine()).thenReturn(line);
35 | when(issue.getInputFile()).thenReturn(inputFile);
36 | when(issue.getRuleKey()).thenReturn(ruleKey);
37 | when(issue.getSeverity()).thenReturn(severity);
38 | return issue;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/test/java/org/sonarlint/cli/analysis/IssueCollectorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.analysis;
21 |
22 | import static org.mockito.Mockito.mock;
23 | import static org.assertj.core.api.Assertions.*;
24 |
25 | import org.junit.Test;
26 | import org.sonarsource.sonarlint.core.client.api.common.analysis.Issue;
27 |
28 | public class IssueCollectorTest {
29 | @Test
30 | public void testCollector() {
31 | IssueCollector collector = new IssueCollector();
32 | Issue i1 = mock(Issue.class);
33 | Issue i2 = mock(Issue.class);
34 | collector.handle(i1);
35 | collector.handle(i2);
36 |
37 | assertThat(collector.get()).containsExactly(i1, i2);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/test/java/org/sonarlint/cli/analysis/StandaloneSonarLintTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.analysis;
21 |
22 | import org.junit.Before;
23 | import org.junit.Rule;
24 | import org.junit.Test;
25 | import org.junit.rules.ExpectedException;
26 | import org.junit.rules.TemporaryFolder;
27 | import org.sonarlint.cli.InputFileFinder;
28 | import org.sonarlint.cli.report.ReportFactory;
29 | import org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl;
30 | import org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile;
31 | import org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration;
32 | import org.sonarsource.sonarlint.core.client.api.standalone.StandaloneSonarLintEngine;
33 |
34 | import java.io.IOException;
35 | import java.nio.charset.StandardCharsets;
36 | import java.nio.file.Path;
37 | import java.util.Collections;
38 | import java.util.HashMap;
39 |
40 | import static org.assertj.core.api.Assertions.assertThat;
41 | import static org.mockito.Matchers.any;
42 | import static org.mockito.Mockito.mock;
43 | import static org.mockito.Mockito.verify;
44 | import static org.mockito.Mockito.when;
45 |
46 | public class StandaloneSonarLintTest {
47 | private StandaloneSonarLint sonarLint;
48 | private StandaloneSonarLintEngine engine;
49 |
50 | @Rule
51 | public TemporaryFolder temp = new TemporaryFolder();
52 |
53 | @Rule
54 | public ExpectedException exception = ExpectedException.none();
55 |
56 | @Before
57 | public void setUp() throws IOException {
58 | engine = new StandaloneSonarLintEngineImpl(StandaloneGlobalConfiguration.builder().build());
59 | sonarLint = new StandaloneSonarLint(engine);
60 | }
61 |
62 | @Test
63 | public void startStop() {
64 | engine = mock(StandaloneSonarLintEngine.class);
65 | sonarLint = new StandaloneSonarLint(engine);
66 | sonarLint.stop();
67 | verify(engine).stop();
68 | }
69 |
70 | @Test
71 | public void run() throws IOException {
72 | InputFileFinder fileFinder = mock(InputFileFinder.class);
73 | Path inputFile = temp.newFile().toPath();
74 | when(fileFinder.collect(any(Path.class))).thenReturn(Collections.singletonList(createInputFile(inputFile, false)));
75 | Path projectHome = temp.newFolder().toPath();
76 | sonarLint.runAnalysis(new HashMap<>(), new ReportFactory(StandardCharsets.UTF_8), fileFinder, projectHome);
77 |
78 | verify(fileFinder).collect(projectHome);
79 |
80 | Path htmlReport = projectHome.resolve(".sonarlint").resolve("sonarlint-report.html");
81 | assertThat(htmlReport).exists();
82 | }
83 |
84 | @Test
85 | public void runWithoutFiles() throws IOException {
86 | InputFileFinder fileFinder = mock(InputFileFinder.class);
87 | when(fileFinder.collect(any(Path.class))).thenReturn(Collections.emptyList());
88 | Path projectHome = temp.newFolder().toPath();
89 | sonarLint.runAnalysis(new HashMap<>(), new ReportFactory(StandardCharsets.UTF_8), fileFinder, projectHome);
90 |
91 | Path htmlReport = projectHome.resolve(".sonarlint").resolve("sonarlint-report.html");
92 | assertThat(htmlReport).doesNotExist();
93 | }
94 |
95 | private static ClientInputFile createInputFile(final Path filePath, final boolean test) {
96 | return new InputFileFinder.DefaultClientInputFile(filePath, test, StandardCharsets.UTF_8);
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/test/java/org/sonarlint/cli/config/ConfigurationReaderTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.config;
21 |
22 | import java.io.IOException;
23 | import java.nio.charset.StandardCharsets;
24 | import java.nio.file.Files;
25 | import java.nio.file.Path;
26 | import org.junit.Rule;
27 | import org.junit.Test;
28 | import org.junit.rules.ExpectedException;
29 | import org.junit.rules.TemporaryFolder;
30 |
31 | import static org.assertj.core.api.Assertions.assertThat;
32 |
33 | public class ConfigurationReaderTest {
34 | @Rule
35 | public TemporaryFolder temp = new TemporaryFolder();
36 |
37 | @Rule
38 | public ExpectedException exception = ExpectedException.none();
39 |
40 | @Test
41 | public void readProjectConfig() throws IOException {
42 | String json = "{serverId=\"localhost\",projectKey=project1}";
43 |
44 | Path file = temp.newFile().toPath();
45 | Files.write(file, json.getBytes(StandardCharsets.UTF_8));
46 | ProjectConfiguration projectConfig = new ConfigurationReader().readProject(file);
47 |
48 | assertThat(projectConfig.serverId()).isEqualTo("localhost");
49 | assertThat(projectConfig.projectKey()).isEqualTo("project1");
50 | }
51 |
52 | @Test
53 | public void readEmptyFileProject() throws IOException {
54 | String json = "";
55 |
56 | Path file = temp.newFile().toPath();
57 | Files.write(file, json.getBytes(StandardCharsets.UTF_8));
58 | exception.expect(IllegalStateException.class);
59 | exception.expectMessage("Failed to parse JSON file");
60 | new ConfigurationReader().readProject(file);
61 | }
62 |
63 | @Test
64 | public void readEmptyFileGlobal() throws IOException {
65 | String json = "";
66 |
67 | Path file = temp.newFile().toPath();
68 | Files.write(file, json.getBytes(StandardCharsets.UTF_8));
69 | exception.expect(IllegalStateException.class);
70 | exception.expectMessage("Failed to parse JSON file");
71 | new ConfigurationReader().readGlobal(file);
72 | }
73 |
74 | @Test
75 | public void readInvalidJsonGlobal() throws IOException {
76 | String json = "{"
77 | + "servers = ["
78 | + " { ] {]}";
79 |
80 | Path file = temp.newFile().toPath();
81 | Files.write(file, json.getBytes(StandardCharsets.UTF_8));
82 | exception.expect(IllegalStateException.class);
83 | exception.expectMessage("Failed to parse JSON file");
84 | new ConfigurationReader().readGlobal(file);
85 | }
86 |
87 | @Test
88 | public void readInvalidJsonProject() throws IOException {
89 | String json = "{"
90 | + "servers = ["
91 | + " { ] {]}";
92 |
93 | Path file = temp.newFile().toPath();
94 | Files.write(file, json.getBytes(StandardCharsets.UTF_8));
95 | exception.expect(IllegalStateException.class);
96 | exception.expectMessage("Failed to parse JSON file");
97 | new ConfigurationReader().readProject(file);
98 | }
99 |
100 | @Test
101 | public void readGlobalConfig() throws IOException {
102 | String json = "{"
103 | + "servers = [{"
104 | + " url = \"http://localhost:9000\","
105 | + " token = mytoken"
106 | + "}"
107 | + "]}";
108 |
109 | Path file = temp.newFile().toPath();
110 | Files.write(file, json.getBytes(StandardCharsets.UTF_8));
111 | GlobalConfiguration config = new ConfigurationReader().readGlobal(file);
112 |
113 | assertThat(config.servers()).hasSize(1);
114 | assertThat(config.servers().get(0).url()).isEqualTo("http://localhost:9000");
115 | assertThat(config.servers().get(0).token()).isEqualTo("mytoken");
116 | }
117 |
118 | @Test
119 | public void failWithRepeatedServers() throws IOException {
120 | String json = "{"
121 | + "servers = ["
122 | + " {url = \"http://localhost:9000\",token = mytoken},"
123 | + " {url = \"http://localhost:9000\",token = mytoken}"
124 | + "]}";
125 |
126 | Path file = temp.newFile().toPath();
127 | Files.write(file, json.getBytes(StandardCharsets.UTF_8));
128 |
129 | exception.expect(IllegalStateException.class);
130 | exception.expectMessage("Invalid SonarQube servers configuration: Each server configured must have a unique URL");
131 | new ConfigurationReader().readGlobal(file);
132 | }
133 |
134 | @Test
135 | public void failServerWithoutUrl() throws IOException {
136 | String json = "{"
137 | + "servers = ["
138 | + " {token = mytoken}"
139 | + "]}";
140 |
141 | Path file = temp.newFile().toPath();
142 | Files.write(file, json.getBytes(StandardCharsets.UTF_8));
143 |
144 | exception.expect(IllegalStateException.class);
145 | exception.expectMessage("Invalid SonarQube servers configuration: server URL must be defined");
146 | new ConfigurationReader().readGlobal(file);
147 | }
148 |
149 | @Test
150 | public void failProjectWithoutBindingKey() throws IOException {
151 | String json = "{serverUrl=\"http://localhost:9000\"}";
152 |
153 | Path file = temp.newFile().toPath();
154 | Files.write(file, json.getBytes(StandardCharsets.UTF_8));
155 |
156 | exception.expect(IllegalStateException.class);
157 | exception.expectMessage("Project binding must have a project key defined");
158 | new ConfigurationReader().readProject(file);
159 | }
160 | }
161 |
--------------------------------------------------------------------------------
/src/test/java/org/sonarlint/cli/report/CategoryReportTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.report;
21 |
22 | import org.junit.Before;
23 | import org.junit.Test;
24 |
25 | import static org.assertj.core.api.Assertions.assertThat;
26 | import static org.mockito.Mockito.mock;
27 | import static org.mockito.Mockito.when;
28 |
29 | public class CategoryReportTest {
30 | private CategoryReport report;
31 | private IssueCategory cat;
32 |
33 | @Before
34 | public void setUp() {
35 | cat = mock(IssueCategory.class);
36 | when(cat.getRuleKey()).thenReturn("rule1");
37 | when(cat.getSeverity()).thenReturn(Severity.MINOR);
38 | report = new CategoryReport(cat);
39 | }
40 |
41 | @Test
42 | public void testGetters() {
43 | assertThat(report.getRuleKey()).isEqualTo("rule1");
44 | assertThat(report.getSeverity()).isEqualTo(Severity.MINOR);
45 | assertThat(report.getCategory()).isEqualTo(cat);
46 |
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/test/java/org/sonarlint/cli/report/ConsoleReportTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.report;
21 |
22 | import java.io.ByteArrayOutputStream;
23 | import java.io.IOException;
24 | import java.io.PrintStream;
25 | import java.nio.charset.StandardCharsets;
26 | import java.util.Date;
27 | import java.util.LinkedList;
28 | import java.util.List;
29 | import java.util.stream.Collectors;
30 | import org.junit.Before;
31 | import org.junit.Rule;
32 | import org.junit.Test;
33 | import org.junit.rules.ExpectedException;
34 | import org.sonarlint.cli.util.Logger;
35 | import org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults;
36 | import org.sonarsource.sonarlint.core.client.api.common.analysis.Issue;
37 | import org.sonarsource.sonarlint.core.tracking.IssueTrackable;
38 | import org.sonarsource.sonarlint.core.tracking.Trackable;
39 |
40 | import static org.assertj.core.api.Assertions.assertThat;
41 | import static org.mockito.Mockito.mock;
42 | import static org.mockito.Mockito.when;
43 | import static org.sonarlint.cli.TestUtils.createTestIssue;
44 |
45 | public class ConsoleReportTest {
46 | private final static String PROJECT_NAME = "project";
47 | private final static Date DATE = new Date(System.currentTimeMillis());
48 | @Rule
49 | public ExpectedException exception = ExpectedException.none();
50 | private ConsoleReport report;
51 | private AnalysisResults result;
52 | private ByteArrayOutputStream out;
53 | private ByteArrayOutputStream err;
54 | private PrintStream stdOut;
55 | private PrintStream stdErr;
56 |
57 | @Before
58 | public void setUp() {
59 | setStreams();
60 | report = new ConsoleReport();
61 | result = mock(AnalysisResults.class);
62 | when(result.fileCount()).thenReturn(1);
63 | }
64 |
65 | @Test
66 | public void testLog() throws IOException {
67 | List issues = new LinkedList<>();
68 | issues.add(createTestIssue("comp1", "rule", "MAJOR", 10));
69 | issues.add(createTestIssue("comp1", "rule", "MINOR", 10));
70 | issues.add(createTestIssue("comp1", "rule", "CRITICAL", 10));
71 | issues.add(createTestIssue("comp1", "rule", "INFO", 10));
72 | issues.add(createTestIssue("comp1", "rule", "BLOCKER", 10));
73 |
74 | List trackables = toTrackables(issues);
75 |
76 | report.execute(PROJECT_NAME, DATE, toTrackables(issues), result, k -> null);
77 |
78 | stdOut.flush();
79 | assertThat(getLog(out)).contains("SonarLint Report");
80 | assertThat(getLog(out)).contains("5 issues");
81 | assertThat(getLog(out)).contains("1 major");
82 | assertThat(getLog(out)).contains("1 minor");
83 | assertThat(getLog(out)).contains("1 info");
84 | assertThat(getLog(out)).contains("1 critical");
85 | assertThat(getLog(out)).contains("1 blocker");
86 |
87 | assertThat(getLog(out)).doesNotContain("new");
88 | }
89 |
90 | private List toTrackables(List issues) {
91 | return issues.stream().map(IssueTrackable::new).collect(Collectors.toList());
92 | }
93 |
94 | @Test
95 | public void testInvalidSeverity() throws IOException {
96 | List issues = new LinkedList<>();
97 | issues.add(createTestIssue("comp1", "rule", "INVALID", 10));
98 |
99 | exception.expect(IllegalStateException.class);
100 | exception.expectMessage("Unknown severity");
101 | report.execute(PROJECT_NAME, DATE, toTrackables(issues), result, k -> null);
102 | }
103 |
104 | @Test
105 | public void testReportWithoutIssues() throws IOException {
106 | List issues = new LinkedList<>();
107 | report.execute(PROJECT_NAME, DATE, toTrackables(issues), result, k -> null);
108 | stdOut.flush();
109 | assertThat(getLog(out)).contains("SonarLint Report");
110 | assertThat(getLog(out)).contains("No issues to display");
111 | assertThat(getLog(out)).contains("1 file analyzed");
112 | }
113 |
114 | @Test
115 | public void testReportMultipleFiles() throws IOException {
116 | when(result.fileCount()).thenReturn(2);
117 | List issues = new LinkedList<>();
118 | report.execute(PROJECT_NAME, DATE, toTrackables(issues), result, k -> null);
119 | stdOut.flush();
120 | assertThat(getLog(out)).contains("SonarLint Report");
121 | assertThat(getLog(out)).contains("No issues to display");
122 | assertThat(getLog(out)).contains("2 files analyzed");
123 | }
124 |
125 | @Test
126 | public void testReportNoFilesAnalyzed() throws IOException {
127 | List issues = new LinkedList<>();
128 | when(result.fileCount()).thenReturn(0);
129 | report.execute(PROJECT_NAME, DATE, toTrackables(issues), result, k -> null);
130 | stdOut.flush();
131 | assertThat(getLog(out)).contains("SonarLint Report");
132 | assertThat(getLog(out)).contains("No files analyzed");
133 |
134 | assertThat(getLog(out)).doesNotContain("issues");
135 | }
136 |
137 | private String getLog(ByteArrayOutputStream byteStream) throws IOException {
138 | return new String(byteStream.toByteArray(), StandardCharsets.UTF_8);
139 | }
140 |
141 | private void setStreams() {
142 | out = new ByteArrayOutputStream();
143 | err = new ByteArrayOutputStream();
144 | stdOut = new PrintStream(out);
145 | stdErr = new PrintStream(err);
146 | Logger.set(stdOut, stdErr);
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/src/test/java/org/sonarlint/cli/report/HtmlReportTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.report;
21 |
22 | import java.nio.charset.StandardCharsets;
23 | import java.nio.file.Path;
24 | import java.util.Arrays;
25 | import java.util.Date;
26 | import java.util.LinkedList;
27 | import org.junit.Before;
28 | import org.junit.Rule;
29 | import org.junit.Test;
30 | import org.junit.rules.TemporaryFolder;
31 | import org.sonarsource.sonarlint.core.client.api.common.RuleDetails;
32 | import org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults;
33 | import org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile;
34 | import org.sonarsource.sonarlint.core.client.api.common.analysis.Issue;
35 | import org.sonarsource.sonarlint.core.tracking.IssueTrackable;
36 | import org.sonarsource.sonarlint.core.tracking.Trackable;
37 |
38 | import static org.assertj.core.api.Assertions.assertThat;
39 | import static org.mockito.Mockito.mock;
40 | import static org.mockito.Mockito.when;
41 |
42 | public class HtmlReportTest {
43 | private HtmlReport html;
44 | private AnalysisResults result;
45 |
46 | @Rule
47 | public TemporaryFolder temp = new TemporaryFolder();
48 | private Path reportFile;
49 |
50 | @Before
51 | public void setUp() {
52 | result = mock(AnalysisResults.class);
53 | when(result.fileCount()).thenReturn(1);
54 | reportFile = temp.getRoot().toPath().resolve("report.html");
55 | html = new HtmlReport(temp.getRoot().toPath(), reportFile, StandardCharsets.UTF_8);
56 | }
57 |
58 | @Test
59 | public void testHtml() {
60 | html.execute("project", new Date(), new LinkedList<>(), result, k -> null);
61 | }
62 |
63 | @Test
64 | public void testCopyRuleDesc() {
65 | html.execute("project", new Date(), Arrays.asList(createTestIssue("foo", "squid:1234", "bla", "MAJOR", 1)), result,
66 | k -> "squid:1234".equals(k) ? mockRuleDetails() : null);
67 |
68 | assertThat(reportFile.getParent().resolve("sonarlintreport_rules/rule.css").toFile()).exists();
69 | assertThat(reportFile.getParent().resolve("sonarlintreport_rules/squid_1234.html").toFile()).usingCharset(StandardCharsets.UTF_8).hasContent(
70 | "Foo (squid:1234)
foo bar
");
71 | }
72 |
73 | @Test
74 | public void testExtendedDesc() {
75 | RuleDetails mockRuleDetailsWithExtendedDesc = mockRuleDetails();
76 | when(mockRuleDetailsWithExtendedDesc.getExtendedDescription()).thenReturn("bar baz");
77 |
78 | html.execute("project", new Date(), Arrays.asList(createTestIssue("foo", "squid:1234", "bla", "MAJOR", 1)), result,
79 | k -> "squid:1234".equals(k) ? mockRuleDetailsWithExtendedDesc : null);
80 |
81 | assertThat(reportFile.getParent().resolve("sonarlintreport_rules/rule.css").toFile()).exists();
82 | assertThat(reportFile.getParent().resolve("sonarlintreport_rules/squid_1234.html").toFile()).usingCharset(StandardCharsets.UTF_8).hasContent(
83 | "Foo (squid:1234)
");
84 | }
85 |
86 | private RuleDetails mockRuleDetails() {
87 | RuleDetails ruleDetails = mock(RuleDetails.class);
88 | when(ruleDetails.getName()).thenReturn("Foo");
89 | when(ruleDetails.getHtmlDescription()).thenReturn("foo bar");
90 | when(ruleDetails.getExtendedDescription()).thenReturn("");
91 | return ruleDetails;
92 | }
93 |
94 | private static Trackable createTestIssue(String filePath, String ruleKey, String name, String severity, int line) {
95 | ClientInputFile inputFile = mock(ClientInputFile.class);
96 | when(inputFile.getPath()).thenReturn(filePath);
97 |
98 | Issue issue = mock(Issue.class);
99 | when(issue.getStartLine()).thenReturn(line);
100 | when(issue.getStartLineOffset()).thenReturn(null);
101 | when(issue.getEndLine()).thenReturn(line);
102 | when(issue.getEndLineOffset()).thenReturn(null);
103 | when(issue.getRuleName()).thenReturn(name);
104 | when(issue.getInputFile()).thenReturn(inputFile);
105 | when(issue.getRuleKey()).thenReturn(ruleKey);
106 | when(issue.getSeverity()).thenReturn(severity);
107 | return new IssueTrackable(issue);
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/src/test/java/org/sonarlint/cli/report/IssueCategoryTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.report;
21 |
22 | import org.junit.Before;
23 | import org.junit.Test;
24 |
25 | import static org.assertj.core.api.Assertions.assertThat;
26 |
27 | public class IssueCategoryTest {
28 | private final static String RULE_KEY = "key";
29 | private final static String RULE_NAME = "key name";
30 | private final static Severity SEVERITY = Severity.MAJOR;
31 | private IssueCategory category;
32 |
33 | @Before
34 | public void setUp() {
35 | category = new IssueCategory(RULE_KEY, SEVERITY, RULE_NAME);
36 | }
37 |
38 | @Test
39 | public void getters() {
40 | assertThat(category.getRuleKey()).isEqualTo(RULE_KEY);
41 | assertThat(category.getSeverity()).isEqualTo(SEVERITY);
42 | assertThat(category.getName()).isEqualTo(RULE_NAME);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/test/java/org/sonarlint/cli/report/IssueVariationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.report;
21 |
22 | import org.junit.Before;
23 | import org.junit.Test;
24 |
25 | import static org.assertj.core.api.Assertions.assertThat;
26 |
27 | public class IssueVariationTest {
28 | private IssueVariation variation;
29 |
30 | @Before
31 | public void setUp() {
32 | variation = new IssueVariation();
33 | }
34 |
35 | @Test
36 | public void defaultZero() {
37 | assertThat(variation.getCountInCurrentAnalysis()).isZero();
38 | assertThat(variation.getNewIssuesCount()).isZero();
39 | assertThat(variation.getResolvedIssuesCount()).isZero();
40 | }
41 |
42 | @Test
43 | public void incCurrent() {
44 | variation.incrementCountInCurrentAnalysis();
45 |
46 | assertThat(variation.getCountInCurrentAnalysis()).isEqualTo(1);
47 | assertThat(variation.getNewIssuesCount()).isZero();
48 | assertThat(variation.getResolvedIssuesCount()).isZero();
49 | }
50 |
51 | @Test
52 | public void incNew() {
53 | variation.incrementNewIssuesCount();
54 |
55 | assertThat(variation.getCountInCurrentAnalysis()).isZero();
56 | assertThat(variation.getNewIssuesCount()).isEqualTo(1);
57 | assertThat(variation.getResolvedIssuesCount()).isZero();
58 | }
59 |
60 | @Test
61 | public void incResolved() {
62 | variation.incrementResolvedIssuesCount();
63 |
64 | assertThat(variation.getCountInCurrentAnalysis()).isZero();
65 | assertThat(variation.getNewIssuesCount()).isZero();
66 | assertThat(variation.getResolvedIssuesCount()).isEqualTo(1);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/test/java/org/sonarlint/cli/report/IssuesReportTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.report;
21 |
22 | import java.io.IOException;
23 | import java.nio.charset.StandardCharsets;
24 | import java.nio.file.Path;
25 | import java.nio.file.Paths;
26 | import java.util.Date;
27 | import javax.annotation.Nullable;
28 | import org.apache.commons.io.FileUtils;
29 | import org.junit.Before;
30 | import org.junit.Rule;
31 | import org.junit.Test;
32 | import org.junit.rules.TemporaryFolder;
33 | import org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile;
34 | import org.sonarsource.sonarlint.core.client.api.common.analysis.Issue;
35 | import org.sonarsource.sonarlint.core.tracking.IssueTrackable;
36 | import org.sonarsource.sonarlint.core.tracking.Trackable;
37 |
38 | import static org.assertj.core.api.Assertions.assertThat;
39 | import static org.mockito.Mockito.mock;
40 | import static org.mockito.Mockito.when;
41 |
42 | public class IssuesReportTest {
43 |
44 | @Rule
45 | public TemporaryFolder temp = new TemporaryFolder();
46 |
47 | private IssuesReport report;
48 |
49 | @Before
50 | public void setUp() {
51 | report = new IssuesReport(Paths.get(""), StandardCharsets.UTF_8);
52 | }
53 |
54 | @Test
55 | public void test_round_trip() {
56 | Date d = new Date();
57 | String title = "title";
58 |
59 | report.setDate(d);
60 | report.setTitle(title);
61 |
62 | assertThat(report.getDate()).isEqualTo(d);
63 | assertThat(report.getTitle()).isEqualTo(title);
64 | assertThat(report.noIssues()).isTrue();
65 | assertThat(report.noFiles()).isTrue();
66 |
67 | report.setFilesAnalyzed(1);
68 | assertThat(report.getFilesAnalyzed()).isEqualTo(1);
69 | assertThat(report.noFiles()).isFalse();
70 | }
71 |
72 | @Test
73 | public void should_find_added_issue() {
74 | String filePath = "comp";
75 | String ruleKey = "rule1";
76 | report.addIssue(createTestIssue(filePath, ruleKey, "name1", "MAJOR", 10));
77 | report.addIssue(createTestIssue(filePath, "rule2", "name2", "MAJOR", 11));
78 | assertThat(report.getSummary()).isNotNull();
79 | assertThat(report.getSummary().getTotal()).isEqualTo(new IssueVariation(2, 0, 0));
80 |
81 | assertThat(report.getResourceReportsByResource()).containsOnlyKeys(Paths.get(filePath));
82 | assertThat(report.getRuleName(ruleKey)).isEqualTo("name1");
83 |
84 | assertThat(report.noIssues()).isFalse();
85 | assertThat(report.getResourceReports()).isNotEmpty();
86 | assertThat(report.getResourcesWithReport()).isNotEmpty();
87 | }
88 |
89 | @Test
90 | public void should_decorate_full_line_when_no_precise_location() throws Exception {
91 | Path file = temp.newFile().toPath();
92 | FileUtils.write(file.toFile(), "if (a && b)\nif (a < b)\nif (a > b)", StandardCharsets.UTF_8);
93 | report.addIssue(createTestIssue(file.toString(), "rule1", "name1", "MAJOR", 1));
94 | report.addIssue(createTestIssue(file.toString(), "rule2", "name2", "MAJOR", 2));
95 | assertThat(report.getEscapedSource(file)).containsExactly("if (a && b)", "if (a < b)",
96 | "if (a > b)");
97 | }
98 |
99 | @Test
100 | public void should_decorate_precise_location() throws Exception {
101 | Path file = temp.newFile().toPath();
102 | FileUtils.write(file.toFile(), " foo bar ", StandardCharsets.UTF_8);
103 | Trackable issue1 = createTestIssue(file.toString(), "rule1", "name1", "MAJOR", 1);
104 | when(issue1.getIssue().getStartLineOffset()).thenReturn(1);
105 | when(issue1.getIssue().getEndLineOffset()).thenReturn(8);
106 | Trackable issue2 = createTestIssue(file.toString(), "rule2", "name2", "MAJOR", 1);
107 | when(issue2.getIssue().getStartLineOffset()).thenReturn(5);
108 | when(issue2.getIssue().getEndLineOffset()).thenReturn(8);
109 | report.addIssue(issue1);
110 | report.addIssue(issue2);
111 | assertThat(report.getEscapedSource(file)).containsExactly(" foo bar ");
112 | }
113 |
114 | @Test
115 | public void should_be_able_to_create_issue_without_file() {
116 | Trackable issueWithoutFile = createTestIssue(null, "rule1", "name1", "MAJOR", 1);
117 | report.addIssue(issueWithoutFile);
118 | assertThat(report.getSummary().getTotal().getCountInCurrentAnalysis()).isEqualTo(1);
119 | }
120 |
121 | @Test
122 | public void should_return_empty_escaped_source_for_null_path() {
123 | assertThat(report.getEscapedSource(null)).isEmpty();
124 | }
125 |
126 | @Test
127 | public void should_return_empty_escaped_source_for_nonexistent_file() {
128 | assertThat(report.getEscapedSource(Paths.get("nonexistent"))).isEmpty();
129 | }
130 |
131 | @Test(expected = IllegalStateException.class)
132 | public void getEscapedSource_should_throw_on_unreadable_file() throws IOException {
133 | report.getEscapedSource(temp.newFolder().toPath());
134 | }
135 |
136 | @Test(expected = IllegalStateException.class)
137 | public void getEscapedSource_should_throw_if_file_has_no_associated_report() throws IOException {
138 | Path file = temp.newFile().toPath();
139 | FileUtils.write(file.toFile(), "blah\nblah\n", StandardCharsets.UTF_8);
140 | report.getEscapedSource(file);
141 | }
142 |
143 | private static Trackable createTestIssue(@Nullable String filePath, String ruleKey, String name, String severity, int line) {
144 | Issue issue = mock(Issue.class);
145 |
146 | if (filePath != null) {
147 | ClientInputFile inputFile = mock(ClientInputFile.class);
148 | when(inputFile.getPath()).thenReturn(filePath);
149 | when(issue.getInputFile()).thenReturn(inputFile);
150 | }
151 |
152 | when(issue.getStartLine()).thenReturn(line);
153 | when(issue.getStartLineOffset()).thenReturn(null);
154 | when(issue.getEndLine()).thenReturn(line);
155 | when(issue.getEndLineOffset()).thenReturn(null);
156 | when(issue.getRuleName()).thenReturn(name);
157 | when(issue.getRuleKey()).thenReturn(ruleKey);
158 | when(issue.getSeverity()).thenReturn(severity);
159 | return new IssueTrackable(issue);
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/src/test/java/org/sonarlint/cli/report/ReportFactoryTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.report;
21 |
22 | import org.junit.Before;
23 | import org.junit.Rule;
24 | import org.junit.Test;
25 | import org.junit.rules.TemporaryFolder;
26 |
27 | import java.nio.charset.Charset;
28 | import java.nio.file.Path;
29 | import java.nio.file.Paths;
30 | import java.util.List;
31 |
32 | import static org.assertj.core.api.Assertions.assertThat;
33 |
34 | public class ReportFactoryTest {
35 | private ReportFactory factory;
36 |
37 | @Rule
38 | public TemporaryFolder temp = new TemporaryFolder();
39 |
40 | @Before
41 | public void setUp() {
42 | factory = new ReportFactory(Charset.defaultCharset());
43 | }
44 |
45 | @Test
46 | public void test() {
47 | List reporters = factory.createReporters(Paths.get("test"));
48 | assertThat(reporters).hasSize(2);
49 | }
50 |
51 | @Test
52 | public void defaultReportFile() {
53 | Path report = factory.getReportFile(temp.getRoot().toPath());
54 | assertThat(report).isEqualTo(temp.getRoot().toPath().resolve(".sonarlint").resolve("sonarlint-report.html"));
55 | }
56 |
57 | @Test
58 | public void customReportFile() {
59 | factory.setHtmlPath(Paths.get("myreport", "myfile.html").toString());
60 | Path report = factory.getReportFile(temp.getRoot().toPath());
61 | assertThat(report).isEqualTo(temp.getRoot().toPath().resolve("myreport").resolve("myfile.html"));
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/test/java/org/sonarlint/cli/report/ReportSummaryTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.report;
21 |
22 | import java.util.LinkedList;
23 | import java.util.List;
24 | import org.junit.Before;
25 | import org.junit.Test;
26 |
27 | import static org.assertj.core.api.Assertions.assertThat;
28 | import static org.assertj.core.api.Assertions.entry;
29 | import static org.sonarlint.cli.TestUtils.createTestIssue;
30 |
31 | public class ReportSummaryTest {
32 | private ReportSummary summary;
33 |
34 | @Before
35 | public void setUp() {
36 | summary = new ReportSummary();
37 | }
38 |
39 | @Test
40 | public void test() {
41 | for (RichIssue i : createTestIssues()) {
42 | summary.addIssue(i);
43 | }
44 |
45 | assertThat(summary.getTotalByRuleKey()).contains(
46 | entry("rule1", variation(2, 0, 0)),
47 | entry("rule2", variation(2, 0, 0)));
48 |
49 | assertThat(summary.getTotalBySeverity()).contains(
50 | entry("MAJOR", variation(2, 0, 0)),
51 | entry("MINOR", variation(1, 0, 0)),
52 | entry("BLOCKER", variation(1, 0, 0)));
53 |
54 | assertThat(summary.getCategoryReports()).hasSize(3);
55 | assertVar(summary.getTotal(), 4, 0, 0);
56 | }
57 |
58 | private static IssueVariation variation(int current, int newCount, int resolved) {
59 | return new IssueVariation(current, newCount, resolved);
60 | }
61 |
62 | private static void assertVar(IssueVariation iv, int current, int newCount, int resolved) {
63 | assertThat(iv.getCountInCurrentAnalysis()).isEqualTo(current);
64 | assertThat(iv.getNewIssuesCount()).isEqualTo(newCount);
65 | assertThat(iv.getResolvedIssuesCount()).isEqualTo(resolved);
66 | }
67 |
68 | private static List createTestIssues() {
69 | List issueList = new LinkedList<>();
70 |
71 | issueList.add(createTestIssue("comp1", "rule1", "MAJOR", 10));
72 | issueList.add(createTestIssue("comp1", "rule2", "MINOR", 11));
73 | issueList.add(createTestIssue("comp4", "rule1", "MAJOR", 12));
74 | issueList.add(createTestIssue("comp2", "rule2", "BLOCKER", 13));
75 |
76 | return issueList;
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/test/java/org/sonarlint/cli/report/ResourceReportTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.report;
21 |
22 | import java.io.File;
23 | import java.nio.file.Path;
24 | import java.nio.file.Paths;
25 | import java.util.Collections;
26 | import java.util.LinkedList;
27 | import java.util.List;
28 | import org.junit.Before;
29 | import org.junit.Test;
30 |
31 | import static org.assertj.core.api.Assertions.assertThat;
32 | import static org.assertj.core.api.Assertions.entry;
33 | import static org.sonarlint.cli.TestUtils.createTestIssue;
34 |
35 | public class ResourceReportTest {
36 | private final static Path RESOURCE = Paths.get("resource");
37 | private ResourceReport resourceReport;
38 |
39 | @Before
40 | public void setUp() {
41 | resourceReport = new ResourceReport(Paths.get(""), RESOURCE);
42 | }
43 |
44 | @Test
45 | public void testIssuesLines() {
46 | RichIssue i1 = createTestIssue("file1", "rule1", "MAJOR", 10);
47 | RichIssue i2 = createTestIssue("file1", "rule1", "MAJOR", 11);
48 | resourceReport.addIssue(i1);
49 | resourceReport.addIssue(i2);
50 |
51 | assertThat(resourceReport.getIssues()).containsOnly(i1, i2);
52 | assertThat(resourceReport.getIssuesAtLine(10)).containsExactly(i1);
53 | assertThat(resourceReport.getIssuesAtLine(20)).isEmpty();
54 | assertThat(resourceReport.getIssuesPerLine()).containsOnly(
55 | entry(i1.getStartLine(), Collections.singletonList(i1)),
56 | entry(i2.getStartLine(), Collections.singletonList(i2)));
57 | assertThat(resourceReport.getName()).isEqualTo("resource");
58 | assertThat(resourceReport.getPath()).isEqualTo(RESOURCE);
59 | }
60 |
61 | @Test
62 | public void testType() {
63 | assertThat(resourceReport.getType()).isEqualTo("FIL");
64 |
65 | resourceReport = new ResourceReport(Paths.get(""), Paths.get(""));
66 | assertThat(resourceReport.getType()).isEqualTo("PRJ");
67 | }
68 |
69 | @Test
70 | public void testName() {
71 | resourceReport = new ResourceReport(Paths.get("/tmp/test"), Paths.get("/tmp/test/src/file1"));
72 | assertThat(resourceReport.getName()).isEqualTo("src" + File.separator + "file1");
73 | }
74 |
75 | @Test
76 | public void testCategoryReport() {
77 | RichIssue i1 = createTestIssue("file1", "rule1", "MAJOR", 10);
78 | RichIssue i2 = createTestIssue("file1", "rule1", "MINOR", 11);
79 | RichIssue i3 = createTestIssue("file1", "rule2", "MINOR", 11);
80 | RichIssue i4 = createTestIssue("file1", "rule2", "MINOR", 12);
81 | resourceReport.addIssue(i1);
82 | resourceReport.addIssue(i2);
83 | resourceReport.addIssue(i3);
84 | resourceReport.addIssue(i4);
85 |
86 | List l = new LinkedList<>();
87 | l.add(Severity.MINOR);
88 | l.add(Severity.MAJOR);
89 | Collections.sort(l);
90 |
91 | List categoryReports = resourceReport.getCategoryReports();
92 | assertThat(categoryReports).hasSize(3);
93 |
94 | // sort first by severity, then by rule key
95 | assertThat(categoryReports).extracting("ruleKey").containsExactly("rule1", "rule1", "rule2");
96 | assertThat(categoryReports).extracting("severity").containsExactly(Severity.MAJOR, Severity.MINOR, Severity.MINOR);
97 |
98 | // grouping
99 | assertThat(categoryReports.get(0).getTotal().getCountInCurrentAnalysis()).isEqualTo(1);
100 | assertThat(categoryReports.get(1).getTotal().getCountInCurrentAnalysis()).isEqualTo(1);
101 | assertThat(categoryReports.get(2).getTotal().getCountInCurrentAnalysis()).isEqualTo(2);
102 |
103 | assertThat(resourceReport.getTotal().getCountInCurrentAnalysis()).isEqualTo(4);
104 | }
105 |
106 | @Test
107 | public void lineIssues() {
108 | RichIssue i1 = createTestIssue("file1", "rule1", "MAJOR", 10);
109 | RichIssue i2 = createTestIssue("file1", "rule1", "MINOR", 11);
110 | resourceReport.addIssue(i1);
111 | resourceReport.addIssue(i2);
112 |
113 | assertThat(resourceReport.isDisplayableLine(0)).isFalse();
114 | assertThat(resourceReport.isDisplayableLine(-3)).isFalse();
115 | assertThat(resourceReport.isDisplayableLine(null)).isFalse();
116 |
117 | assertThat(resourceReport.isDisplayableLine(7)).isFalse();
118 | assertThat(resourceReport.isDisplayableLine(8)).isTrue();
119 | assertThat(resourceReport.isDisplayableLine(9)).isTrue();
120 | assertThat(resourceReport.isDisplayableLine(10)).isTrue();
121 | assertThat(resourceReport.isDisplayableLine(11)).isTrue();
122 | assertThat(resourceReport.isDisplayableLine(12)).isTrue();
123 | assertThat(resourceReport.isDisplayableLine(13)).isTrue();
124 | assertThat(resourceReport.isDisplayableLine(14)).isFalse();
125 |
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/src/test/java/org/sonarlint/cli/util/LoggerTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.util;
21 |
22 | import org.junit.Before;
23 | import org.junit.Test;
24 | import org.mockito.Mock;
25 | import org.mockito.MockitoAnnotations;
26 | import org.sonarlint.cli.util.Logger;
27 |
28 | import java.io.PrintStream;
29 |
30 | import static org.mockito.Mockito.verifyNoMoreInteractions;
31 | import static org.mockito.Mockito.verifyZeroInteractions;
32 | import static org.mockito.Mockito.mock;
33 | import static org.mockito.Mockito.verify;
34 |
35 | public class LoggerTest {
36 | @Mock
37 | private PrintStream stdOut;
38 |
39 | @Mock
40 | private PrintStream stdErr;
41 |
42 | private Logger logger;
43 |
44 | @Before
45 | public void setUp() {
46 | MockitoAnnotations.initMocks(this);
47 | logger = new Logger(stdOut, stdErr);
48 | }
49 |
50 | @Test
51 | public void testInfo() {
52 | logger.info("info");
53 | verify(stdOut).println("INFO: info");
54 | verifyNoMoreInteractions(stdOut, stdErr);
55 | }
56 |
57 | @Test
58 | public void testError() {
59 | Exception e = new NullPointerException("exception");
60 | logger.setDisplayStackTrace(false);
61 | logger.error("error1");
62 | verify(stdErr).println("ERROR: error1");
63 |
64 | logger.error("error2", e);
65 | verify(stdErr).println("ERROR: error2");
66 |
67 | verifyNoMoreInteractions(stdOut, stdErr);
68 |
69 | logger.setDisplayStackTrace(true);
70 | logger.error("error3", e);
71 | verify(stdErr).println("ERROR: error3");
72 | // other interactions to print the exception..
73 | }
74 |
75 | @Test
76 | public void testDebugThrowableWithStack() {
77 | Throwable t = mock(Throwable.class);
78 | logger.setDebugEnabled(true);
79 |
80 | logger.setDebugEnabled(true);
81 | logger.setDisplayStackTrace(true);
82 | logger.debug("debug", t);
83 | verify(stdErr).println("DEBUG: debug");
84 | verify(t).printStackTrace(stdErr);
85 |
86 | logger.setDebugEnabled(false);
87 | logger.debug("debug");
88 | verifyNoMoreInteractions(stdOut, stdErr);
89 | }
90 |
91 | @Test
92 | public void testDebugThrowableWithoutStack() {
93 | Throwable t = mock(Throwable.class);
94 | logger.setDebugEnabled(true);
95 | logger.setDisplayStackTrace(false);
96 |
97 | logger.debug("debug", t);
98 | verify(stdErr).println("DEBUG: debug");
99 | verifyZeroInteractions(t);
100 | }
101 |
102 | @Test
103 | public void testDebug() {
104 | logger.setDebugEnabled(true);
105 |
106 | logger.debug("debug");
107 | verify(stdOut).println("DEBUG: debug");
108 |
109 | logger.setDebugEnabled(false);
110 | logger.debug("debug");
111 | verifyNoMoreInteractions(stdOut, stdErr);
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/src/test/java/org/sonarlint/cli/util/MutableIntTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.util;
21 |
22 | import org.junit.Before;
23 | import org.junit.Test;
24 | import org.sonarlint.cli.util.MutableInt;
25 |
26 | import static org.assertj.core.api.Assertions.assertThat;
27 |
28 | public class MutableIntTest {
29 | private MutableInt integer;
30 |
31 | @Before
32 | public void setUp() {
33 | integer = new MutableInt();
34 | }
35 |
36 | @Test
37 | public void inc() {
38 | assertThat(integer.get()).isEqualTo(0);
39 |
40 | integer.inc();
41 | assertThat(integer.get()).isEqualTo(1);
42 |
43 | integer.inc();
44 | assertThat(integer.get()).isEqualTo(2);
45 | }
46 |
47 | @Test
48 | public void set() {
49 | integer.set(10);
50 | assertThat(integer.get()).isEqualTo(10);
51 | }
52 |
53 | @Test
54 | public void equals() {
55 | MutableInt integer1 = new MutableInt(2);
56 | MutableInt integer2 = new MutableInt(2);
57 | MutableInt integer3 = new MutableInt(3);
58 |
59 | assertThat(integer1).isEqualTo(integer2);
60 | assertThat(integer1).isEqualTo(integer1);
61 | assertThat(integer1).isNotEqualTo(integer3);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/test/java/org/sonarlint/cli/util/System2Test.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.util;
21 |
22 | import org.assertj.core.data.Percentage;
23 | import org.junit.Test;
24 |
25 | import java.util.Map.Entry;
26 |
27 | import static org.assertj.core.api.Assertions.assertThat;
28 |
29 | public class System2Test {
30 | @Test
31 | public void testProxy() {
32 | System.setProperty("test1", "prop1");
33 |
34 | assertThat(System2.INSTANCE.envVariables()).isEqualTo(System.getenv());
35 | assertThat(System2.INSTANCE.property("test1")).isEqualTo("prop1");
36 | assertThat(System2.INSTANCE.getProperty("test1")).isEqualTo("prop1");
37 | assertThat(System2.INSTANCE.properties()).isEqualTo(System.getProperties());
38 |
39 | Entry envVar = System.getenv().entrySet().iterator().next();
40 |
41 | assertThat(System2.INSTANCE.envVariable(envVar.getKey())).isEqualTo(envVar.getValue());
42 | assertThat(System2.INSTANCE.getenv(envVar.getKey())).isEqualTo(envVar.getValue());
43 |
44 | assertThat(System2.INSTANCE.now()).isCloseTo(System.currentTimeMillis(), Percentage.withPercentage(0.01));
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/test/java/org/sonarlint/cli/util/SystemInfoTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.util;
21 |
22 | import org.junit.Before;
23 | import org.junit.Test;
24 |
25 | import static org.assertj.core.api.Assertions.assertThat;
26 | import static org.mockito.Mockito.mock;
27 | import static org.mockito.Mockito.verify;
28 | import static org.mockito.Mockito.verifyNoMoreInteractions;
29 | import static org.mockito.Mockito.when;
30 |
31 | public class SystemInfoTest {
32 | System2 mockSystem;
33 | Logger logger;
34 |
35 | @Before
36 | public void setUp() {
37 | mockSystem = mock(System2.class);
38 | logger = mock(Logger.class);
39 | SystemInfo.setSystem(mockSystem);
40 | }
41 |
42 | @Test
43 | public void test_java() {
44 | mockJava();
45 | assertThat(SystemInfo.java()).isEqualTo("Java 1.9 oracle (64-bit)");
46 |
47 | when(mockSystem.getProperty("sun.arch.data.model")).thenReturn("32");
48 | assertThat(SystemInfo.java()).isEqualTo("Java 1.9 oracle (32-bit)");
49 |
50 | when(mockSystem.getProperty("sun.arch.data.model")).thenReturn(null);
51 | assertThat(SystemInfo.java()).isEqualTo("Java 1.9 oracle");
52 | }
53 |
54 | @Test
55 | public void test_os() {
56 | mockOs();
57 |
58 | assertThat(SystemInfo.os()).isEqualTo("linux 2.5 x64");
59 | }
60 |
61 | private void mockJava() {
62 | when(mockSystem.getProperty("java.version")).thenReturn("1.9");
63 | when(mockSystem.getProperty("java.vendor")).thenReturn("oracle");
64 | when(mockSystem.getProperty("sun.arch.data.model")).thenReturn("64");
65 | }
66 |
67 | private void mockOs() {
68 | when(mockSystem.getProperty("os.version")).thenReturn("2.5");
69 | when(mockSystem.getProperty("os.arch")).thenReturn("x64");
70 | when(mockSystem.getProperty("os.name")).thenReturn("linux");
71 | }
72 |
73 | @Test
74 | public void should_print() {
75 | mockOs();
76 | mockJava();
77 | when(mockSystem.getenv("SONARLINT_OPTS")).thenReturn("arg");
78 |
79 | SystemInfo.print(logger);
80 |
81 | verify(mockSystem).getProperty("java.version");
82 | verify(mockSystem).getProperty("os.version");
83 | verify(mockSystem).getenv("SONARLINT_OPTS");
84 |
85 | verify(logger).info("Java 1.9 oracle (64-bit)");
86 | verify(logger).info("linux 2.5 x64");
87 | verify(logger).info("SONARLINT_OPTS=arg");
88 | verifyNoMoreInteractions(logger);
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/test/java/org/sonarlint/cli/util/UtilTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SonarLint CLI
3 | * Copyright (C) 2016-2017 SonarSource SA
4 | * mailto:info AT sonarsource DOT 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.sonarlint.cli.util;
21 |
22 | import static org.assertj.core.api.Assertions.assertThat;
23 |
24 | import org.junit.Test;
25 |
26 | public class UtilTest {
27 | @Test
28 | public void testEscapeFileName() {
29 | assertThat(Util.escapeFileName("myfile.html")).isEqualTo("myfile.html");
30 | assertThat(Util.escapeFileName("myfile.h.html")).isEqualTo("myfile.h.html");
31 | assertThat(Util.escapeFileName("invalid:name.html")).isEqualTo("invalid_name.html");
32 | assertThat(Util.escapeFileName("name-ok.html")).isEqualTo("name-ok.html");
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/test/resources/org/sonarlint/cli/config/sonarlint_global.json:
--------------------------------------------------------------------------------
1 | {
2 | servers: [
3 | {
4 | "id": "local",
5 | "url": "http://localhost:9000",
6 | "login": "admin",
7 | "password": "admin"
8 | }
9 | ]
10 | }
--------------------------------------------------------------------------------
/src/test/resources/org/sonarlint/cli/config/sonarlint_project.json:
--------------------------------------------------------------------------------
1 | {
2 | "serverId": "local",
3 | "projectKey": "myProject"
4 | }
--------------------------------------------------------------------------------
/third-party-licenses.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | mvn org.codehaus.mojo:license-maven-plugin:aggregate-add-third-party -Dlicense.includedScopes=compile -pl sonar-application -am
3 |
4 | cat target/generated-sources/license/THIRD-PARTY.txt
5 |
--------------------------------------------------------------------------------
/travis.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -euo pipefail
4 |
5 | function installTravisTools {
6 | mkdir -p ~/.local
7 | curl -sSL https://github.com/SonarSource/travis-utils/tarball/v33 | tar zx --strip-components 1 -C ~/.local
8 | source ~/.local/bin/install
9 | }
10 |
11 | installTravisTools
12 |
13 | regular_mvn_build_deploy_analyze
14 |
--------------------------------------------------------------------------------