aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar/scanner/scan')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultComponentTree.java54
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleIndexer.java5
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java1
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java32
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStore.java79
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputFileBuilder.java4
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStore.java17
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/JSONReport.java63
8 files changed, 33 insertions, 222 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultComponentTree.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultComponentTree.java
deleted file mode 100644
index 7da8990ded6..00000000000
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultComponentTree.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 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.scan;
-
-import com.google.common.base.Preconditions;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Set;
-import javax.annotation.CheckForNull;
-import org.sonar.api.batch.fs.InputComponent;
-import org.sonar.api.batch.fs.internal.InputComponentTree;
-
-public class DefaultComponentTree implements InputComponentTree {
- private Map<InputComponent, InputComponent> parents = new HashMap<>();
- private Map<InputComponent, Set<InputComponent>> children = new HashMap<>();
-
- public void index(InputComponent component, InputComponent parent) {
- Preconditions.checkNotNull(component);
- Preconditions.checkNotNull(parent);
- parents.put(component, parent);
- children.computeIfAbsent(parent, k -> new LinkedHashSet<>()).add(component);
- }
-
- @Override
- public Collection<InputComponent> getChildren(InputComponent component) {
- return children.getOrDefault(component, Collections.emptySet());
- }
-
- @CheckForNull
- @Override
- public InputComponent getParent(InputComponent component) {
- return parents.get(component);
- }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleIndexer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleIndexer.java
index 60baccdfa5a..4b85e732f66 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleIndexer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleIndexer.java
@@ -30,12 +30,10 @@ import org.sonar.scanner.scan.filesystem.InputComponentStore;
* project definitions provided by the {@link ImmutableProjectReactor}.
*/
public class ModuleIndexer implements Startable {
- private final DefaultComponentTree componentTree;
private final InputModuleHierarchy moduleHierarchy;
private final InputComponentStore componentStore;
- public ModuleIndexer(DefaultComponentTree componentTree, InputComponentStore componentStore, InputModuleHierarchy moduleHierarchy) {
- this.componentTree = componentTree;
+ public ModuleIndexer(InputComponentStore componentStore, InputModuleHierarchy moduleHierarchy) {
this.componentStore = componentStore;
this.moduleHierarchy = moduleHierarchy;
}
@@ -49,7 +47,6 @@ public class ModuleIndexer implements Startable {
private void indexChildren(DefaultInputModule parent) {
for (DefaultInputModule module : moduleHierarchy.children(parent)) {
- componentTree.index(module, parent);
componentStore.put(module);
indexChildren(module);
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java
index eb33fe12f42..7e595179de1 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java
@@ -160,7 +160,6 @@ public class ProjectScanContainer extends ComponentContainer {
PathResolver.class,
new InputProjectProvider(),
new InputModuleHierarchyProvider(),
- DefaultComponentTree.class,
ScannerComponentIdGenerator.class,
new ScmChangedFilesProvider(),
StatusDetection.class,
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java
index 5294797c67c..20a1d803688 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java
@@ -44,12 +44,9 @@ import org.sonar.api.batch.ScannerSide;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputFile.Type;
import org.sonar.api.batch.fs.InputFileFilter;
-import org.sonar.api.batch.fs.internal.DefaultInputDir;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.api.utils.MessageException;
-import org.sonar.scanner.scan.DefaultComponentTree;
import org.sonar.scanner.util.ProgressReport;
/**
@@ -62,7 +59,6 @@ public class FileIndexer {
private final InputFileFilter[] filters;
private final ExclusionFilters exclusionFilters;
private final InputFileBuilder inputFileBuilder;
- private final DefaultComponentTree componentTree;
private final DefaultInputModule module;
private final ScannerComponentIdGenerator scannerComponentIdGenerator;
private final InputComponentStore componentStore;
@@ -74,13 +70,12 @@ public class FileIndexer {
private ProgressReport progressReport;
public FileIndexer(ScannerComponentIdGenerator scannerComponentIdGenerator, InputComponentStore componentStore, DefaultInputModule module, ExclusionFilters exclusionFilters,
- DefaultComponentTree componentTree, InputFileBuilder inputFileBuilder, DefaultModuleFileSystem defaultModuleFileSystem,
+ InputFileBuilder inputFileBuilder, DefaultModuleFileSystem defaultModuleFileSystem,
LanguageDetection languageDetection,
InputFileFilter[] filters) {
this.scannerComponentIdGenerator = scannerComponentIdGenerator;
this.componentStore = componentStore;
this.module = module;
- this.componentTree = componentTree;
this.inputFileBuilder = inputFileBuilder;
this.defaultModuleFileSystem = defaultModuleFileSystem;
this.langDetection = languageDetection;
@@ -90,9 +85,9 @@ public class FileIndexer {
}
public FileIndexer(ScannerComponentIdGenerator scannerComponentIdGenerator, InputComponentStore componentStore, DefaultInputModule module, ExclusionFilters exclusionFilters,
- DefaultComponentTree componentTree, InputFileBuilder inputFileBuilder, DefaultModuleFileSystem defaultModuleFileSystem,
+ InputFileBuilder inputFileBuilder, DefaultModuleFileSystem defaultModuleFileSystem,
LanguageDetection languageDetection) {
- this(scannerComponentIdGenerator, componentStore, module, exclusionFilters, componentTree, inputFileBuilder, defaultModuleFileSystem, languageDetection,
+ this(scannerComponentIdGenerator, componentStore, module, exclusionFilters, inputFileBuilder, defaultModuleFileSystem, languageDetection,
new InputFileFilter[0]);
}
@@ -192,34 +187,15 @@ public class FileIndexer {
progress.increaseExcludedByPatternsCount();
return null;
}
- String parentRelativePath = getParentRelativePath(realAbsoluteFile);
synchronized (this) {
progress.markAsIndexed(inputFile);
- indexFileAndParentDir(inputFile, parentRelativePath);
+ defaultModuleFileSystem.add(inputFile);
}
LOG.debug("'{}' indexed {}with language '{}'", relativePath, type == Type.TEST ? "as test " : "", inputFile.language());
inputFileBuilder.checkMetadata(inputFile);
return null;
}
- private String getParentRelativePath(Path filePath) {
- Path parentDir = filePath.getParent();
- return PathResolver.relativize(module.getBaseDir(), parentDir)
- .orElseThrow(() -> new IllegalStateException("Failed to compute relative path of file: " + parentDir));
- }
-
- private void indexFileAndParentDir(InputFile inputFile, String parentRelativePath) {
- DefaultInputDir inputDir = (DefaultInputDir) componentStore.getDir(module.key(), parentRelativePath);
- if (inputDir == null) {
- inputDir = new DefaultInputDir(module.key(), parentRelativePath, scannerComponentIdGenerator.getAsInt());
- inputDir.setModuleBaseDir(module.getBaseDir());
- componentTree.index(inputDir, module);
- defaultModuleFileSystem.add(inputDir);
- }
- componentTree.index(inputFile, inputDir);
- defaultModuleFileSystem.add(inputFile);
- }
-
private boolean accept(InputFile indexedFile) {
// InputFileFilter extensions. Might trigger generation of metadata
for (InputFileFilter filter : filters) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStore.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStore.java
index 15eb4f6b0a0..8d1071b172c 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStore.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStore.java
@@ -24,7 +24,6 @@ import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.SetMultimap;
import com.google.common.collect.Table;
import com.google.common.collect.TreeBasedTable;
-import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -34,13 +33,10 @@ import java.util.TreeSet;
import java.util.stream.Stream;
import javax.annotation.CheckForNull;
import org.sonar.api.batch.fs.InputComponent;
-import org.sonar.api.batch.fs.InputDir;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
-import org.sonar.api.batch.fs.internal.DefaultInputDir;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.FileExtensionPredicate;
-import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.api.scanner.fs.InputProject;
import org.sonar.scanner.scan.branch.BranchConfiguration;
@@ -53,9 +49,7 @@ public class InputComponentStore {
private final SortedSet<String> globalLanguagesCache = new TreeSet<>();
private final Map<String, SortedSet<String>> languagesCache = new HashMap<>();
private final Map<String, InputFile> globalInputFileCache = new HashMap<>();
- private final Table<String, String, InputFile> inputFileCache = TreeBasedTable.create();
- private final Map<String, InputDir> globalInputDirCache = new HashMap<>();
- private final Table<String, String, InputDir> inputDirCache = TreeBasedTable.create();
+ private final Table<String, String, InputFile> inputFileByModuleCache = TreeBasedTable.create();
// indexed by key with branch
private final Map<String, AbstractProjectOrModule> inputModuleCache = new HashMap<>();
private final Map<String, InputComponent> inputComponents = new HashMap<>();
@@ -74,7 +68,7 @@ public class InputComponentStore {
}
private Stream<DefaultInputFile> allFilesToPublishStream() {
- return inputFileCache.values().stream()
+ return inputFileByModuleCache.values().stream()
.map(f -> (DefaultInputFile) f)
.filter(DefaultInputFile::isPublished);
}
@@ -90,11 +84,7 @@ public class InputComponentStore {
}
public Iterable<InputFile> allFiles() {
- return inputFileCache.values();
- }
-
- public Iterable<InputDir> allDirs() {
- return inputDirCache.values();
+ return globalInputFileCache.values();
}
public InputComponent getByKey(String key) {
@@ -102,35 +92,13 @@ public class InputComponentStore {
}
public Iterable<InputFile> filesByModule(String moduleKey) {
- return inputFileCache.row(moduleKey).values();
- }
-
- public Iterable<InputDir> dirsByModule(String moduleKey) {
- return inputDirCache.row(moduleKey).values();
- }
-
- public InputComponentStore removeModule(String moduleKey) {
- inputFileCache.row(moduleKey).clear();
- inputDirCache.row(moduleKey).clear();
- return this;
- }
-
- public InputComponentStore remove(InputFile inputFile) {
- DefaultInputFile file = (DefaultInputFile) inputFile;
- inputFileCache.remove(file.moduleKey(), file.getModuleRelativePath());
- return this;
- }
-
- public InputComponentStore remove(InputDir inputDir) {
- DefaultInputDir dir = (DefaultInputDir) inputDir;
- inputDirCache.remove(dir.moduleKey(), inputDir.relativePath());
- return this;
+ return inputFileByModuleCache.row(moduleKey).values();
}
- public InputComponentStore put(InputFile inputFile) {
+ public InputComponentStore put(String moduleKey, InputFile inputFile) {
DefaultInputFile file = (DefaultInputFile) inputFile;
- addToLanguageCache(file);
- inputFileCache.put(file.moduleKey(), file.getModuleRelativePath(), inputFile);
+ addToLanguageCache(moduleKey, file);
+ inputFileByModuleCache.put(moduleKey, file.getModuleRelativePath(), inputFile);
globalInputFileCache.put(file.getProjectRelativePath(), inputFile);
inputComponents.put(inputFile.key(), inputFile);
filesByNameCache.put(inputFile.filename(), inputFile);
@@ -138,34 +106,17 @@ public class InputComponentStore {
return this;
}
- private void addToLanguageCache(DefaultInputFile inputFile) {
+ private void addToLanguageCache(String moduleKey, DefaultInputFile inputFile) {
String language = inputFile.language();
if (language != null) {
globalLanguagesCache.add(language);
- languagesCache.computeIfAbsent(inputFile.moduleKey(), k -> new TreeSet<>()).add(language);
+ languagesCache.computeIfAbsent(moduleKey, k -> new TreeSet<>()).add(language);
}
}
- public InputComponentStore put(InputDir inputDir) {
- DefaultInputDir dir = (DefaultInputDir) inputDir;
- inputDirCache.put(dir.moduleKey(), inputDir.relativePath(), inputDir);
- // FIXME an InputDir can be already indexed by another module
- globalInputDirCache.put(getProjectRelativePath(dir), inputDir);
- inputComponents.put(inputDir.key(), inputDir);
- return this;
- }
-
- private String getProjectRelativePath(DefaultInputDir dir) {
- return PathResolver.relativize(getProjectBaseDir(), dir.path()).orElseThrow(() -> new IllegalStateException("Dir " + dir.path() + " should be relative to project baseDir"));
- }
-
- private Path getProjectBaseDir() {
- return ((AbstractProjectOrModule) project).getBaseDir();
- }
-
@CheckForNull
public InputFile getFile(String moduleKey, String relativePath) {
- return inputFileCache.get(moduleKey, relativePath);
+ return inputFileByModuleCache.get(moduleKey, relativePath);
}
@CheckForNull
@@ -174,16 +125,6 @@ public class InputComponentStore {
}
@CheckForNull
- public InputDir getDir(String moduleKey, String relativePath) {
- return inputDirCache.get(moduleKey, relativePath);
- }
-
- @CheckForNull
- public InputDir getDir(String relativePath) {
- return globalInputDirCache.get(relativePath);
- }
-
- @CheckForNull
public AbstractProjectOrModule getModule(String moduleKeyWithBranch) {
return inputModuleCache.get(moduleKeyWithBranch);
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputFileBuilder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputFileBuilder.java
index 4de7d1bf07e..438a0edd44b 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputFileBuilder.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputFileBuilder.java
@@ -30,6 +30,7 @@ import org.sonar.api.batch.fs.internal.SensorStrategy;
import org.sonar.scanner.scan.ScanProperties;
public class InputFileBuilder {
+ private final DefaultInputProject project;
private final DefaultInputModule module;
private final ScannerComponentIdGenerator idGenerator;
private final MetadataGenerator metadataGenerator;
@@ -42,6 +43,7 @@ public class InputFileBuilder {
SensorStrategy sensorStrategy) {
this.sensorStrategy = sensorStrategy;
this.projectBaseDir = project.getBaseDir();
+ this.project = project;
this.module = module;
this.metadataGenerator = metadataGenerator;
this.idGenerator = idGenerator;
@@ -49,7 +51,7 @@ public class InputFileBuilder {
}
DefaultInputFile create(InputFile.Type type, Path absolutePath, @Nullable String language) {
- DefaultIndexedFile indexedFile = new DefaultIndexedFile(absolutePath, module.key(),
+ DefaultIndexedFile indexedFile = new DefaultIndexedFile(absolutePath, project.key(),
projectBaseDir.relativize(absolutePath).toString(),
module.getBaseDir().relativize(absolutePath).toString(),
type, language, idGenerator.getAsInt(), sensorStrategy);
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStore.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStore.java
index 8d694756fb9..6bb17759043 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStore.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStore.java
@@ -21,7 +21,6 @@ package org.sonar.scanner.scan.filesystem;
import java.util.SortedSet;
import org.sonar.api.batch.ScannerSide;
-import org.sonar.api.batch.fs.InputDir;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputModule;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
@@ -59,15 +58,6 @@ public class ModuleInputComponentStore extends DefaultFileSystem.Cache {
}
@Override
- public InputDir inputDir(String relativePath) {
- if (strategy.isGlobal()) {
- return inputComponentStore.getDir(relativePath);
- } else {
- return inputComponentStore.getDir(moduleKey, relativePath);
- }
- }
-
- @Override
public SortedSet<String> languages() {
if (strategy.isGlobal()) {
return inputComponentStore.getLanguages();
@@ -78,12 +68,7 @@ public class ModuleInputComponentStore extends DefaultFileSystem.Cache {
@Override
protected void doAdd(InputFile inputFile) {
- inputComponentStore.put(inputFile);
- }
-
- @Override
- protected void doAdd(InputDir inputDir) {
- inputComponentStore.put(inputDir);
+ inputComponentStore.put(moduleKey, inputFile);
}
@Override
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/JSONReport.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/JSONReport.java
index b302742bf7b..d965bb3e908 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/JSONReport.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/JSONReport.java
@@ -38,13 +38,8 @@ import org.sonar.api.Property;
import org.sonar.api.PropertyType;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputComponent;
-import org.sonar.api.batch.fs.InputDir;
-import org.sonar.api.batch.fs.InputPath;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.batch.fs.internal.InputComponentTree;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
import org.sonar.api.batch.rule.Rule;
import org.sonar.api.batch.rule.Rules;
import org.sonar.api.config.Configuration;
@@ -72,21 +67,17 @@ public class JSONReport implements Reporter {
private final Rules rules;
private final IssueCache issueCache;
private final InputComponentStore componentStore;
- private final DefaultInputModule rootModule;
- private final InputModuleHierarchy moduleHierarchy;
- private final InputComponentTree inputComponentTree;
+ private final DefaultInputProject project;
- public JSONReport(InputModuleHierarchy moduleHierarchy, Configuration settings, FileSystem fileSystem, Server server, Rules rules, IssueCache issueCache,
- DefaultInputModule rootModule, InputComponentStore componentStore, InputComponentTree inputComponentTree) {
- this.moduleHierarchy = moduleHierarchy;
+ public JSONReport(Configuration settings, FileSystem fileSystem, Server server, Rules rules, IssueCache issueCache,
+ DefaultInputProject project, InputComponentStore componentStore) {
this.settings = settings;
this.fileSystem = fileSystem;
this.server = server;
this.rules = rules;
this.issueCache = issueCache;
- this.rootModule = rootModule;
+ this.project = project;
this.componentStore = componentStore;
- this.inputComponentTree = inputComponentTree;
}
@Override
@@ -126,14 +117,14 @@ public class JSONReport implements Reporter {
for (TrackedIssue issue : getIssues()) {
if (issue.resolution() == null) {
InputComponent component = componentStore.getByKey(issue.componentKey());
- String componentKey = getModule(component).definition().getKeyWithBranch();
- if (component instanceof InputPath) {
- componentKey = ComponentKeys.createEffectiveKey(componentKey, (InputPath) component);
+ String componentKeyWithBranch = project.getKeyWithBranch();
+ if (component.isFile()) {
+ componentKeyWithBranch = ComponentKeys.createEffectiveKey(componentKeyWithBranch, (DefaultInputFile) component);
}
json
.beginObject()
.prop("key", issue.key())
- .prop("component", componentKey)
+ .prop("component", componentKeyWithBranch)
.prop("line", issue.startLine())
.prop("startLine", issue.startLine())
.prop("startOffset", issue.startLineOffset())
@@ -158,54 +149,28 @@ public class JSONReport implements Reporter {
json.endArray();
}
- private AbstractProjectOrModule getModule(InputComponent component) {
- if (component.isFile()) {
- return (AbstractProjectOrModule) inputComponentTree.getParent(inputComponentTree.getParent(component));
- }
- if (component instanceof InputDir) {
- return (AbstractProjectOrModule) inputComponentTree.getParent(component);
- }
- return (AbstractProjectOrModule) component;
- }
-
private void writeJsonComponents(JsonWriter json) {
json.name("components").beginArray();
// Dump modules
- writeJsonModuleComponents(json, rootModule);
+ writeJsonProject(json);
for (DefaultInputFile inputFile : componentStore.allFilesToPublish()) {
- String moduleKey = getModule(inputFile).definition().getKeyWithBranch();
- String key = ComponentKeys.createEffectiveKey(moduleKey, inputFile);
+ String projectKey = project.getKeyWithBranch();
+ String key = ComponentKeys.createEffectiveKey(projectKey, inputFile);
json
.beginObject()
.prop("key", key)
.prop("path", inputFile.relativePath())
- .prop("moduleKey", moduleKey)
.prop("status", inputFile.status().name())
.endObject();
}
- for (InputDir inputDir : componentStore.allDirs()) {
- String moduleKey = getModule(inputDir).definition().getKeyWithBranch();
- String key = ComponentKeys.createEffectiveKey(moduleKey, inputDir);
- json
- .beginObject()
- .prop("key", key)
- .prop("path", inputDir.relativePath())
- .prop("moduleKey", moduleKey)
- .endObject();
-
- }
json.endArray();
}
- private void writeJsonModuleComponents(JsonWriter json, DefaultInputModule moduleOrProject) {
+ private void writeJsonProject(JsonWriter json) {
json
.beginObject()
- .prop("key", moduleOrProject.definition().getKeyWithBranch())
- .prop("path", moduleHierarchy.relativePath(moduleOrProject))
+ .prop("key", project.definition().getKeyWithBranch())
.endObject();
- for (DefaultInputModule subModule : moduleHierarchy.children(moduleOrProject)) {
- writeJsonModuleComponents(json, subModule);
- }
}
private void writeJsonRules(JsonWriter json, Set<RuleKey> ruleKeys) {