*/
package org.sonar.scanner;
+import javax.annotation.concurrent.Immutable;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.measure.MetricFinder;
import org.sonar.api.measures.FileLinesContextFactory;
import org.sonar.scanner.scan.measure.MeasureCache;
+@Immutable
public class DefaultFileLinesContextFactory implements FileLinesContextFactory {
private final SensorContext sensorContext;
return false;
}
- private static void writeVersion(DefaultInputModule module, ScannerReport.Component.Builder builder) {
- ProjectDefinition def = module.definition();
- String version = getVersion(def);
+ private void writeVersion(DefaultInputModule module, ScannerReport.Component.Builder builder) {
+ String version = getVersion(module);
if (version != null) {
builder.setVersion(version);
}
throw new IllegalStateException("Unkown component: " + component.getClass());
}
- private static String getVersion(ProjectDefinition def) {
- String version = def.getOriginalVersion();
+ private String getVersion(DefaultInputModule module) {
+ String version = module.getOriginalVersion();
if (StringUtils.isNotBlank(version)) {
return version;
}
- return def.getParent() != null ? getVersion(def.getParent()) : null;
+ DefaultInputModule parent = moduleHierarchy.parent(module);
+
+ return parent != null ? getVersion(parent) : null;
}
private static void writeLinks(InputComponent c, ScannerReport.Component.Builder builder) {
import java.util.Map.Entry;
import java.util.Optional;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
import org.sonar.api.config.Configuration;
@Override
public void publish(ScannerReportWriter writer) {
DefaultInputModule rootProject = moduleHierarchy.root();
- ProjectDefinition rootDef = rootProject.definition();
ScannerReport.Metadata.Builder builder = ScannerReport.Metadata.newBuilder()
.setAnalysisDate(projectAnalysisInfo.analysisDate().getTime())
// Here we want key without branch
- .setProjectKey(rootDef.getKey())
+ .setProjectKey(rootProject.key())
.setCrossProjectDuplicationActivated(cpdSettings.isCrossProjectDuplicationEnabled())
.setRootComponentRef(rootProject.batchId());
builder.setMergeBranchName(branchTarget);
}
}
- Optional.ofNullable(rootDef.getBranch()).ifPresent(builder::setDeprecatedBranch);
+ Optional.ofNullable(rootProject.getBranch()).ifPresent(builder::setDeprecatedBranch);
for (QProfile qp : qProfiles.findAll()) {
builder.getMutableQprofilesPerLanguage().put(qp.getLanguage(), ScannerReport.Metadata.QProfile.newBuilder()
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.FileMetadata;
import org.sonar.api.batch.fs.internal.SensorStrategy;
import org.sonar.api.batch.rule.CheckFactory;
+import org.sonar.api.issue.NoSonarFilter;
import org.sonar.api.resources.Project;
import org.sonar.api.scan.filesystem.FileExclusions;
import org.sonar.core.platform.ComponentContainer;
import org.sonar.scanner.DefaultFileLinesContextFactory;
import org.sonar.scanner.bootstrap.ExtensionInstaller;
import org.sonar.scanner.bootstrap.ExtensionUtils;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
import org.sonar.scanner.bootstrap.ScannerExtensionDictionnary;
import org.sonar.scanner.deprecated.DeprecatedSensorContext;
import org.sonar.scanner.deprecated.perspectives.ScannerPerspectives;
import org.sonar.scanner.scan.filesystem.FileIndexer;
import org.sonar.scanner.scan.filesystem.InputFileBuilder;
import org.sonar.scanner.scan.filesystem.LanguageDetection;
-import org.sonar.scanner.scan.filesystem.MetadataGeneratorProvider;
+import org.sonar.scanner.scan.filesystem.MetadataGenerator;
import org.sonar.scanner.scan.filesystem.ModuleFileSystemInitializer;
import org.sonar.scanner.scan.filesystem.ModuleInputComponentStore;
-import org.sonar.scanner.scan.filesystem.StatusDetectionFactory;
import org.sonar.scanner.scan.report.IssuesReports;
import org.sonar.scanner.sensor.DefaultSensorStorage;
import org.sonar.scanner.sensor.SensorOptimizer;
public class ModuleScanContainer extends ComponentContainer {
private static final Logger LOG = LoggerFactory.getLogger(ModuleScanContainer.class);
private final DefaultInputModule module;
+ private final GlobalAnalysisMode analysisMode;
- public ModuleScanContainer(ProjectScanContainer parent, DefaultInputModule module) {
+ public ModuleScanContainer(ProjectScanContainer parent, DefaultInputModule module, GlobalAnalysisMode analysisMode) {
super(parent);
this.module = module;
+ this.analysisMode = analysisMode;
}
@Override
MutableModuleSettings.class,
new ModuleSettingsProvider());
- if (getComponentByType(AnalysisMode.class).isIssues()) {
- add(IssuesPhaseExecutor.class,
+ if (analysisMode.isIssues()) {
+ add(
+ IssuesPhaseExecutor.class,
IssuesReports.class);
} else {
- add(PublishPhaseExecutor.class);
+ add(
+ PublishPhaseExecutor.class);
}
add(
ModuleInputComponentStore.class,
FileExclusions.class,
ExclusionFilters.class,
- new MetadataGeneratorProvider(),
+ MetadataGenerator.class,
FileMetadata.class,
LanguageDetection.class,
FileIndexer.class,
// issues
IssuableFactory.class,
ModuleIssues.class,
- org.sonar.api.issue.NoSonarFilter.class,
+ NoSonarFilter.class,
// issue exclusions
IssueInclusionPatternInitializer.class,
import org.sonar.scanner.scan.branch.ProjectBranchesProvider;
import org.sonar.scanner.scan.filesystem.BatchIdGenerator;
import org.sonar.scanner.scan.filesystem.InputComponentStoreProvider;
-import org.sonar.scanner.scan.filesystem.StatusDetectionFactory;
+import org.sonar.scanner.scan.filesystem.StatusDetection;
import org.sonar.scanner.scan.measure.DefaultMetricFinder;
import org.sonar.scanner.scan.measure.DeprecatedMetricFinder;
import org.sonar.scanner.scan.measure.MeasureCache;
DefaultComponentTree.class,
BatchIdGenerator.class,
new ScmChangedFilesProvider(),
- StatusDetectionFactory.class,
+ StatusDetection.class,
// rules
new ActiveRulesProvider(),
}
LOG.debug("Start recursive analysis of project modules");
- scanRecursively(tree, tree.root());
+ scanRecursively(tree, tree.root(), analysisMode);
if (analysisMode.isMediumTest()) {
getComponentByType(ScanTaskObservers.class).notifyEndOfScanTask();
}
}
- private void scanRecursively(InputModuleHierarchy tree, DefaultInputModule module) {
+ private void scanRecursively(InputModuleHierarchy tree, DefaultInputModule module, GlobalAnalysisMode analysisMode) {
for (DefaultInputModule child : tree.children(module)) {
- scanRecursively(tree, child);
+ scanRecursively(tree, child, analysisMode);
}
- scan(module);
+ scan(module, analysisMode);
}
@VisibleForTesting
- void scan(DefaultInputModule module) {
- new ModuleScanContainer(this, module).execute();
+ void scan(DefaultInputModule module, GlobalAnalysisMode analysisMode) {
+ new ModuleScanContainer(this, module, analysisMode).execute();
}
static class BatchExtensionFilter implements ExtensionMatcher {
import org.sonar.api.batch.fs.internal.Metadata;
import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader;
-class MetadataGenerator {
+public class MetadataGenerator {
private static final Logger LOG = LoggerFactory.getLogger(MetadataGenerator.class);
@VisibleForTesting
static final Charset UTF_32BE = Charset.forName("UTF-32BE");
private final DefaultInputModule inputModule;
private final IssueExclusionsLoader exclusionsScanner;
- MetadataGenerator(DefaultInputModule inputModule, StatusDetection statusDetection, FileMetadata fileMetadata, IssueExclusionsLoader exclusionsScanner) {
+ public MetadataGenerator(DefaultInputModule inputModule, StatusDetection statusDetection, FileMetadata fileMetadata, IssueExclusionsLoader exclusionsScanner) {
this.inputModule = inputModule;
this.statusDetection = statusDetection;
this.fileMetadata = fileMetadata;
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 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.filesystem;
-
-import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.batch.ScannerSide;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.batch.fs.internal.FileMetadata;
-import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader;
-
-@ScannerSide
-public class MetadataGeneratorProvider extends ProviderAdapter {
- public MetadataGenerator provide(DefaultInputModule inputModule, StatusDetectionFactory statusDetectionFactory, FileMetadata fileMetadata,
- IssueExclusionsLoader exclusionsScanner) {
- return new MetadataGenerator(inputModule, statusDetectionFactory.create(), fileMetadata, exclusionsScanner);
- }
-}
private final List<Path> testDirsOrFiles;
private final Charset encoding;
- public ModuleFileSystemInitializer(DefaultInputModule inputModule, ProjectDefinition module) {
+ public ModuleFileSystemInitializer(DefaultInputModule inputModule) {
logDir("Base dir: ", inputModule.getBaseDir());
logDir("Working dir: ", inputModule.getWorkDir());
- sourceDirsOrFiles = initSources(module, inputModule.getBaseDir(), ProjectDefinition.SOURCES_PROPERTY, "Source paths: ");
- testDirsOrFiles = initSources(module, inputModule.getBaseDir(), ProjectDefinition.TESTS_PROPERTY, "Test paths: ");
- encoding = initEncoding(module);
+ sourceDirsOrFiles = initSources(inputModule, ProjectDefinition.SOURCES_PROPERTY, "Source paths: ");
+ testDirsOrFiles = initSources(inputModule, ProjectDefinition.TESTS_PROPERTY, "Test paths: ");
+ encoding = initEncoding(inputModule);
}
- private static List<Path> initSources(ProjectDefinition module, Path baseDir, String propertyKey, String logLabel) {
+ private static List<Path> initSources(DefaultInputModule module, String propertyKey, String logLabel) {
List<Path> result = new ArrayList<>();
PathResolver pathResolver = new PathResolver();
String srcPropValue = module.properties().get(propertyKey);
if (srcPropValue != null) {
for (String sourcePath : parseAsCsv(propertyKey, srcPropValue)) {
- File dirOrFile = pathResolver.relativeFile(module.getBaseDir(), sourcePath);
+ File dirOrFile = pathResolver.relativeFile(module.getBaseDir().toFile(), sourcePath);
if (dirOrFile.exists()) {
result.add(dirOrFile.toPath());
}
}
}
- logPaths(logLabel, baseDir, result);
+ logPaths(logLabel, module.getBaseDir(), result);
return result;
}
- private static Charset initEncoding(ProjectDefinition module) {
+ private static Charset initEncoding(DefaultInputModule module) {
String encodingStr = module.properties().get(CoreProperties.ENCODING_PROPERTY);
Charset result;
if (StringUtils.isNotEmpty(encodingStr)) {
import org.sonar.scanner.scm.ScmChangedFiles;
@Immutable
-class StatusDetection {
+public class StatusDetection {
private final ProjectRepositories projectRepositories;
private final ScmChangedFiles scmChangedFiles;
- StatusDetection(ProjectRepositories projectSettings, ScmChangedFiles scmChangedFiles) {
+ public StatusDetection(ProjectRepositories projectSettings, ScmChangedFiles scmChangedFiles) {
this.projectRepositories = projectSettings;
this.scmChangedFiles = scmChangedFiles;
}
if (StringUtils.isEmpty(previousHash)) {
return InputFile.Status.ADDED;
}
- if (!scmChangedFiles.confirmChanged(inputFile.path())) {
+ if (!scmChangedFiles.verifyChanged(inputFile.path())) {
return InputFile.Status.SAME;
}
return InputFile.Status.CHANGED;
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 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.filesystem;
-
-import org.sonar.api.batch.ScannerSide;
-import org.sonar.scanner.repository.ProjectRepositories;
-import org.sonar.scanner.scm.ScmChangedFiles;
-
-@ScannerSide
-public class StatusDetectionFactory {
-
- private final ProjectRepositories projectReferentials;
- private final ScmChangedFiles scmChangedFiles;
-
- public StatusDetectionFactory(ProjectRepositories projectReferentials, ScmChangedFiles scmChangedFiles) {
- this.projectReferentials = projectReferentials;
- this.scmChangedFiles = scmChangedFiles;
- }
-
- StatusDetection create() {
- return new StatusDetection(projectReferentials, scmChangedFiles);
- }
-}
moduleHierarchy = mock(InputModuleHierarchy.class);
when(moduleHierarchy.root()).thenReturn(root);
when(moduleHierarchy.children(root)).thenReturn(Collections.singleton(module1));
+ when(moduleHierarchy.parent(module1)).thenReturn(root);
tree.index(module1, root);
DefaultInputDir dir = new DefaultInputDir("module1", "src", 3);
moduleHierarchy = mock(InputModuleHierarchy.class);
when(moduleHierarchy.root()).thenReturn(root);
when(moduleHierarchy.children(root)).thenReturn(Collections.singleton(module1));
+ when(moduleHierarchy.parent(module1)).thenReturn(root);
tree.index(module1, root);
DefaultInputDir dir = new DefaultInputDir("module1", "src", 3);
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 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.filesystem;
-
-import java.io.IOException;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.mockito.Mockito;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.batch.fs.internal.FileMetadata;
-import org.sonar.scanner.issue.ignore.pattern.IssueExclusionPatternInitializer;
-import org.sonar.scanner.issue.ignore.pattern.PatternMatcher;
-import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-public class MetadataGeneratorProviderTest {
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- @Test
- public void create_builder() throws IOException {
- StatusDetectionFactory statusDetectionFactory = mock(StatusDetectionFactory.class, Mockito.RETURNS_MOCKS);
- IssueExclusionsLoader issueExclusionsLoader = new IssueExclusionsLoader(mock(IssueExclusionPatternInitializer.class), mock(PatternMatcher.class));
-
- MetadataGeneratorProvider factory = new MetadataGeneratorProvider();
- assertThat(factory.provide(new DefaultInputModule(ProjectDefinition.create().setKey("module").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder())),
- statusDetectionFactory, new FileMetadata(), issueExclusionsLoader)).isNotNull();
- }
-}
File workDir = temp.newFolder("work");
ProjectDefinition module = ProjectDefinition.create().setBaseDir(baseDir).setWorkDir(workDir);
- ModuleFileSystemInitializer initializer = new ModuleFileSystemInitializer(new DefaultInputModule(module), module);
+ ModuleFileSystemInitializer initializer = new ModuleFileSystemInitializer(new DefaultInputModule(module));
assertThat(logTester.logs(LoggerLevel.INFO)).contains("Base dir: " + baseDir.toPath().toAbsolutePath().toString());
assertThat(logTester.logs(LoggerLevel.INFO)).contains("Working dir: " + workDir.toPath().toAbsolutePath().toString());
.addSources("src/main/java", "src/main/unknown")
.addTests("src/test/java", "src/test/unknown");
- ModuleFileSystemInitializer initializer = new ModuleFileSystemInitializer(new DefaultInputModule(project), project);
+ ModuleFileSystemInitializer initializer = new ModuleFileSystemInitializer(new DefaultInputModule(project));
assertThat(initializer.sources()).hasSize(1);
assertThat(path(initializer.sources().get(0))).endsWith("src/main/java");
.addSources("\"my,File.cs\"")
.addTests("\"my,TestFile.cs\"");
- ModuleFileSystemInitializer initializer = new ModuleFileSystemInitializer(new DefaultInputModule(project), project);
+ ModuleFileSystemInitializer initializer = new ModuleFileSystemInitializer(new DefaultInputModule(project));
assertThat(initializer.sources()).hasSize(1);
assertThat(initializer.sources().get(0)).isEqualTo(sourceFile.toPath());
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 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.filesystem;
-
-import org.junit.Test;
-import org.sonar.scanner.repository.ProjectRepositories;
-import org.sonar.scanner.scm.ScmChangedFiles;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-public class StatusDetectionFactoryTest {
- @Test
- public void testCreate() throws Exception {
- StatusDetectionFactory factory = new StatusDetectionFactory(mock(ProjectRepositories.class), mock(ScmChangedFiles.class));
- StatusDetection detection = factory.create();
- assertThat(detection).isNotNull();
- }
-}