aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-protocol/src/main
diff options
context:
space:
mode:
authorMichal Duda <michalno1@gmail.com>2018-11-22 18:09:44 +0100
committersonartech <sonartech@sonarsource.com>2019-01-16 09:43:02 +0100
commitcf1c8d76184de334921362e9abd7dd64d56e5f16 (patch)
tree8daacd2319f8f93c5a0858638c040551b38ae386 /sonar-scanner-protocol/src/main
parente4c0b858c7e6807801c6481d995ca11682c58fad (diff)
downloadsonarqube-cf1c8d76184de334921362e9abd7dd64d56e5f16.tar.gz
sonarqube-cf1c8d76184de334921362e9abd7dd64d56e5f16.zip
SONAR-11507 WS /batch/project new file structure
Diffstat (limited to 'sonar-scanner-protocol/src/main')
-rw-r--r--sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/input/MultiModuleProjectRepository.java52
-rw-r--r--sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/input/ProjectRepositories.java30
-rw-r--r--sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/input/SingleProjectRepository.java45
3 files changed, 99 insertions, 28 deletions
diff --git a/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/input/MultiModuleProjectRepository.java b/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/input/MultiModuleProjectRepository.java
new file mode 100644
index 00000000000..7fbb9bb948f
--- /dev/null
+++ b/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/input/MultiModuleProjectRepository.java
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.scanner.protocol.input;
+
+import com.google.common.collect.Maps;
+import java.util.Map;
+import java.util.Optional;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+public class MultiModuleProjectRepository extends ProjectRepositories {
+ private Map<String, SingleProjectRepository> repositoryPerModule = Maps.newHashMap();
+
+ public ProjectRepositories addFileDataToModule(String moduleKey, @Nullable String path, FileData fileData) {
+ if (path == null || (fileData.hash() == null && fileData.revision() == null)) {
+ return this;
+ }
+
+ SingleProjectRepository repository = repositoryPerModule.computeIfAbsent(moduleKey, k -> new SingleProjectRepository());
+ repository.addFileData(path, fileData);
+ return this;
+ }
+
+ public Map<String, SingleProjectRepository> repositoriesByModule() {
+ return repositoryPerModule;
+ }
+
+ @CheckForNull
+ public FileData fileData(String moduleKeyWithBranch, @Nullable String path) {
+ Optional<SingleProjectRepository> moduleRepository = Optional.ofNullable(repositoryPerModule.get(moduleKeyWithBranch));
+ return moduleRepository
+ .map(singleProjectRepository -> singleProjectRepository.fileDataByPath(path))
+ .orElse(null);
+ }
+}
diff --git a/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/input/ProjectRepositories.java b/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/input/ProjectRepositories.java
index 9a557aa64cc..3737d98ab77 100644
--- a/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/input/ProjectRepositories.java
+++ b/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/input/ProjectRepositories.java
@@ -19,10 +19,7 @@
*/
package org.sonar.scanner.protocol.input;
-import java.util.Collections;
import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
@@ -30,34 +27,11 @@ import javax.annotation.Nullable;
* Container for all project data going from server to batch.
* This is not an API since server and batch always share the same version.
*/
-public class ProjectRepositories {
+public abstract class ProjectRepositories {
private long timestamp;
- private Map<String, Map<String, FileData>> fileDataByModuleAndPath = new HashMap<>();
- private Date lastAnalysisDate;
-
- public Map<String, Map<String, FileData>> fileDataByModuleAndPath() {
- return fileDataByModuleAndPath;
- }
-
- public Map<String, FileData> fileDataByPath(String moduleKey) {
- return fileDataByModuleAndPath.containsKey(moduleKey) ? fileDataByModuleAndPath.get(moduleKey) : Collections.<String, FileData>emptyMap();
- }
-
- public ProjectRepositories addFileData(String moduleKey, @Nullable String path, FileData fileData) {
- if (path == null || (fileData.hash() == null && fileData.revision() == null)) {
- return this;
- }
- Map<String, FileData> existingFileDataByPath = fileDataByModuleAndPath.computeIfAbsent(moduleKey, k -> new HashMap<>());
- existingFileDataByPath.put(path, fileData);
- return this;
- }
-
- @CheckForNull
- public FileData fileData(String projectKey, String path) {
- return fileDataByPath(projectKey).get(path);
- }
+ private Date lastAnalysisDate;
public long timestamp() {
return timestamp;
diff --git a/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/input/SingleProjectRepository.java b/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/input/SingleProjectRepository.java
new file mode 100644
index 00000000000..37af28c03c4
--- /dev/null
+++ b/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/input/SingleProjectRepository.java
@@ -0,0 +1,45 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.scanner.protocol.input;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+
+public class SingleProjectRepository extends ProjectRepositories {
+ private Map<String, FileData> fileDataByPath = new HashMap<>();
+
+ public ProjectRepositories addFileData(@Nullable String path, FileData fileData) {
+ if (path == null || (fileData.hash() == null && fileData.revision() == null)) {
+ return this;
+ }
+
+ fileDataByPath.put(path, fileData);
+ return this;
+ }
+
+ public Map<String, FileData> fileData() {
+ return fileDataByPath;
+ }
+
+ public FileData fileDataByPath(@Nullable String path) {
+ return fileDataByPath.get(path);
+ }
+}