Skip to content

Commit 89ecc53

Browse files
committed
SCANJLIB-205 Remove code related to tasks
1 parent 0c256a4 commit 89ecc53

8 files changed

Lines changed: 13 additions & 103 deletions

File tree

lib/src/main/java/org/sonarsource/scanner/lib/Dirs.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
*/
2020
package org.sonarsource.scanner.lib;
2121

22-
import java.io.File;
2322
import java.nio.file.Files;
2423
import java.nio.file.Path;
2524
import java.nio.file.Paths;
@@ -36,15 +35,6 @@ class Dirs {
3635
}
3736

3837
void init(Map<String, String> p) {
39-
boolean onProject = Utils.taskRequiresProject(p);
40-
if (onProject) {
41-
initProjectDirs(p);
42-
} else {
43-
initTaskDirs(p);
44-
}
45-
}
46-
47-
private void initProjectDirs(Map<String, String> p) {
4838
String pathString = Optional.ofNullable(p.get(ScanProperties.PROJECT_BASEDIR)).orElse("");
4939
Path absoluteProjectPath = Paths.get(pathString).toAbsolutePath().normalize();
5040
if (!Files.isDirectory(absoluteProjectPath)) {
@@ -65,13 +55,4 @@ private void initProjectDirs(Map<String, String> p) {
6555
p.put(ScannerProperties.WORK_DIR, workDirPath.normalize().toString());
6656
logger.debug("Work directory: " + workDirPath.normalize().toString());
6757
}
68-
69-
/**
70-
* Non-scan task
71-
*/
72-
private static void initTaskDirs(Map<String, String> p) {
73-
String path = Optional.ofNullable(p.get(ScannerProperties.WORK_DIR)).orElse(".");
74-
File workDir = new File(path);
75-
p.put(ScannerProperties.WORK_DIR, workDir.getAbsolutePath());
76-
}
7758
}

lib/src/main/java/org/sonarsource/scanner/lib/EmbeddedScanner.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ public String serverVersion() {
114114
return launcher.getVersion();
115115
}
116116

117-
public void execute(Map<String, String> taskProps) {
117+
public void execute(Map<String, String> analysisProps) {
118118
checkLauncherExists();
119119
try (IsolatedLauncherFactory launcherFactoryToBeClosed = launcherFactory) {
120120
Map<String, String> allProps = new HashMap<>();
121121
allProps.putAll(globalProperties);
122-
allProps.putAll(taskProps);
122+
allProps.putAll(analysisProps);
123123
initAnalysisProperties(allProps);
124124
doExecute(allProps);
125125
} catch (IOException e) {
@@ -145,18 +145,15 @@ private void initAnalysisProperties(Map<String, String> p) {
145145
}
146146

147147
void initSourceEncoding(Map<String, String> p) {
148-
boolean onProject = Utils.taskRequiresProject(p);
149-
if (onProject) {
150-
String sourceEncoding = Optional.ofNullable(p.get(ScanProperties.PROJECT_SOURCE_ENCODING)).orElse("");
151-
boolean platformDependent = false;
152-
if ("".equals(sourceEncoding)) {
153-
sourceEncoding = Charset.defaultCharset().name();
154-
platformDependent = true;
155-
p.put(ScanProperties.PROJECT_SOURCE_ENCODING, sourceEncoding);
156-
}
157-
logger.info("Default locale: \"" + Locale.getDefault() + "\", source code encoding: \"" + sourceEncoding + "\""
158-
+ (platformDependent ? " (analysis is platform dependent)" : ""));
148+
String sourceEncoding = Optional.ofNullable(p.get(ScanProperties.PROJECT_SOURCE_ENCODING)).orElse("");
149+
boolean platformDependent = false;
150+
if ("".equals(sourceEncoding)) {
151+
sourceEncoding = Charset.defaultCharset().name();
152+
platformDependent = true;
153+
p.put(ScanProperties.PROJECT_SOURCE_ENCODING, sourceEncoding);
159154
}
155+
logger.info("Default locale: \"" + Locale.getDefault() + "\", source code encoding: \"" + sourceEncoding + "\""
156+
+ (platformDependent ? " (analysis is platform dependent)" : ""));
160157
}
161158

162159
private void setGlobalDefaultValue(String key, String value) {

lib/src/main/java/org/sonarsource/scanner/lib/ScanProperties.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@
2727
*/
2828
public interface ScanProperties {
2929

30-
/**
31-
* Default task
32-
*
33-
* @see ScannerProperties#TASK
34-
*/
35-
String SCAN_TASK = "scan";
36-
3730
/**
3831
* Required project key
3932
*/

lib/src/main/java/org/sonarsource/scanner/lib/ScannerProperties.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ public interface ScannerProperties {
3131
*/
3232
String HOST_URL = "sonar.host.url";
3333

34-
/**
35-
* Task to execute, "scan" by default
36-
*/
37-
String TASK = "sonar.task";
38-
3934
/**
4035
* Working directory containing generated reports and temporary data.
4136
*/

lib/src/main/java/org/sonarsource/scanner/lib/Utils.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ static String join(String[] array, String delimiter) {
8484
return sb.toString();
8585
}
8686

87-
static boolean taskRequiresProject(Map<String, String> props) {
88-
Object task = props.get(ScannerProperties.TASK);
89-
return task == null || ScanProperties.SCAN_TASK.equals(task);
90-
}
91-
9287
static void writeProperties(File outputFile, Properties p) {
9388
try (OutputStream output = new FileOutputStream(outputFile)) {
9489
p.store(output, "Generated by sonar-runner");

lib/src/test/java/org/sonarsource/scanner/lib/DirsTest.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,8 @@ public class DirsTest {
3737
@Rule
3838
public TemporaryFolder temp = new TemporaryFolder();
3939

40-
@Test
41-
public void should_init_default_task_work_dir() throws Exception {
42-
p.put("sonar.task", "views");
43-
new Dirs(mock(Logger.class)).init(p);
44-
45-
File workDir = new File(p.get(ScannerProperties.WORK_DIR));
46-
assertThat(workDir).isNotNull().isDirectory();
47-
assertThat(workDir.getCanonicalPath()).isEqualTo(new File(".").getCanonicalPath());
48-
}
49-
50-
@Test
51-
public void should_use_parameterized_task_work_dir() throws Exception {
52-
p.put("sonar.task", "views");
53-
p.put(ScannerProperties.WORK_DIR, "generated/reports");
54-
new Dirs(mock(Logger.class)).init(p);
55-
56-
File workDir = new File(p.get(ScannerProperties.WORK_DIR));
57-
assertThat(workDir).isNotNull();
58-
// separators from windows to unix
59-
assertThat(workDir.getCanonicalPath().replace("\\", "/")).contains("generated/reports");
60-
}
61-
6240
@Test
6341
public void should_init_default_project_dirs() throws Exception {
64-
p.put("sonar.task", "scan");
6542
new Dirs(mock(Logger.class)).init(p);
6643

6744
File projectDir = new File(p.get(ScanProperties.PROJECT_BASEDIR));
@@ -78,7 +55,6 @@ public void should_init_default_project_dirs() throws Exception {
7855
@Test
7956
public void should_set_relative_path_to_project_work_dir() throws Exception {
8057
File initialProjectDir = temp.getRoot();
81-
p.put("sonar.task", "scan");
8258
p.put(ScannerProperties.WORK_DIR, "relative/path");
8359
p.put(ScanProperties.PROJECT_BASEDIR, initialProjectDir.getAbsolutePath());
8460
new Dirs(mock(Logger.class)).init(p);

lib/src/test/java/org/sonarsource/scanner/lib/EmbeddedScannerTest.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ public void should_launch_in_simulation_mode() throws IOException {
225225
@Test
226226
public void should_set_default_platform_encoding() throws Exception {
227227
Map<String, String> p = new HashMap<>();
228-
p.put("sonar.task", "scan");
229228
scanner.initSourceEncoding(p);
230229
assertThat(p.get("sonar.sourceEncoding")).isEqualTo(Charset.defaultCharset().name());
231230
verify(logger).info("Default locale: \"" + Locale.getDefault() + "\", source code encoding: \"" + Charset.defaultCharset().name() + "\" (analysis is platform dependent)");
@@ -234,7 +233,6 @@ public void should_set_default_platform_encoding() throws Exception {
234233
@Test
235234
public void should_set_default_platform_encoding_when_empty() throws Exception {
236235
Map<String, String> p = new HashMap<>();
237-
p.put("sonar.task", "scan");
238236
p.put("sonar.sourceEncoding", "");
239237
scanner.initSourceEncoding(p);
240238
assertThat(p.get("sonar.sourceEncoding")).isEqualTo(Charset.defaultCharset().name());
@@ -253,18 +251,9 @@ public void cannot_start_twice() {
253251
@Test
254252
public void should_use_parameterized_encoding() throws Exception {
255253
Map<String, String> p = new HashMap<>();
256-
p.put("sonar.task", "scan");
257254
p.put("sonar.sourceEncoding", "THE_ISO_1234");
258255
scanner.initSourceEncoding(p);
259256
assertThat(p.get("sonar.sourceEncoding")).isEqualTo("THE_ISO_1234");
260257
}
261258

262-
@Test
263-
public void should_not_init_encoding_if_not_project_task() throws Exception {
264-
Map<String, String> p = new HashMap<>();
265-
p.put("sonar.task", "views");
266-
scanner.initSourceEncoding(p);
267-
assertThat(p.get("sonar.sourceEncoding")).isNull();
268-
}
269-
270259
}

lib/src/test/java/org/sonarsource/scanner/lib/UtilsTest.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,9 @@ public class UtilsTest {
4444

4545
@Test
4646
public void should_join_strings() {
47-
assertThat(Utils.join(new String[] {}, ",")).isEqualTo("");
48-
assertThat(Utils.join(new String[] {"foo"}, ",")).isEqualTo("foo");
49-
assertThat(Utils.join(new String[] {"foo", "bar"}, ",")).isEqualTo("foo,bar");
50-
}
51-
52-
@Test
53-
public void task_should_require_project() {
54-
Map<String, String> props = new HashMap<>();
55-
assertThat(Utils.taskRequiresProject(props)).isTrue();
56-
57-
props.put("sonar.task", "scan");
58-
assertThat(Utils.taskRequiresProject(props)).isTrue();
47+
assertThat(Utils.join(new String[]{}, ",")).isEqualTo("");
48+
assertThat(Utils.join(new String[]{"foo"}, ",")).isEqualTo("foo");
49+
assertThat(Utils.join(new String[]{"foo", "bar"}, ",")).isEqualTo("foo,bar");
5950
}
6051

6152
@Test
@@ -67,13 +58,6 @@ public void write_properties() throws IOException {
6758
assertThat(Files.readAllLines(f.toPath(), StandardCharsets.UTF_8)).contains("key=value");
6859
}
6960

70-
@Test
71-
public void task_should_not_require_project() {
72-
Map<String, String> props = new HashMap<>();
73-
props.put("sonar.task", "views");
74-
assertThat(Utils.taskRequiresProject(props)).isFalse();
75-
}
76-
7761
@Test
7862
public void delete_non_empty_directory() throws IOException {
7963
/*-

0 commit comments

Comments
 (0)