diff options
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar')
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectInfo.java (renamed from sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectAnalysisInfo.java) | 32 | ||||
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultFilterableIssue.java | 10 | ||||
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueFilters.java | 14 | ||||
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/IssueTransition.java | 12 | ||||
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java | 5 | ||||
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java | 21 | ||||
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/InputProjectProvider.java | 2 | ||||
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorValidator.java | 5 | ||||
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java | 4 |
9 files changed, 56 insertions, 49 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectAnalysisInfo.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectInfo.java index 3cd2928bb72..71c0e77b692 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectAnalysisInfo.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectInfo.java @@ -22,24 +22,28 @@ package org.sonar.scanner; import java.time.Clock; import java.util.Date; import java.util.Optional; +import javax.annotation.CheckForNull; import org.picocontainer.Startable; import org.sonar.api.CoreProperties; import org.sonar.api.config.Configuration; import org.sonar.api.utils.DateUtils; +import org.sonar.api.utils.MessageException; + +import static java.lang.String.format; /** * @since 6.3 - * + * * Immutable after {@link #start()} */ -public class ProjectAnalysisInfo implements Startable { +public class ProjectInfo implements Startable { private final Clock clock; private Configuration settings; private Date analysisDate; - private String analysisVersion; + private String projectVersion; - public ProjectAnalysisInfo(Configuration settings, Clock clock) { + public ProjectInfo(Configuration settings, Clock clock) { this.settings = settings; this.clock = clock; } @@ -48,8 +52,9 @@ public class ProjectAnalysisInfo implements Startable { return analysisDate; } - public String analysisVersion() { - return analysisVersion; + @CheckForNull + public String projectVersion() { + return projectVersion; } private Date loadAnalysisDate() { @@ -71,14 +76,23 @@ public class ProjectAnalysisInfo implements Startable { } } - private String loadAnalysisVersion() { - return settings.get(CoreProperties.PROJECT_VERSION_PROPERTY).orElse(null); + @CheckForNull + private String loadProjectVersion() { + return settings.get(CoreProperties.PROJECT_VERSION_PROPERTY) + .filter(version -> { + if (version.length() > 100) { + throw MessageException.of(format("\"%s\" is not a valid project version. " + + "The maximum length for version numbers is 100 characters.", version)); + } + return true; + }) + .orElse(null); } @Override public void start() { this.analysisDate = loadAnalysisDate(); - this.analysisVersion = loadAnalysisVersion(); + this.projectVersion = loadProjectVersion(); } @Override diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultFilterableIssue.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultFilterableIssue.java index bb92a02f31c..d6c925c6f50 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultFilterableIssue.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultFilterableIssue.java @@ -30,19 +30,19 @@ import org.sonar.api.batch.fs.internal.DefaultTextPointer; import org.sonar.api.batch.fs.internal.DefaultTextRange; import org.sonar.api.rule.RuleKey; import org.sonar.api.scan.issue.filter.FilterableIssue; -import org.sonar.scanner.ProjectAnalysisInfo; +import org.sonar.scanner.ProjectInfo; import org.sonar.scanner.protocol.output.ScannerReport.Issue; @ThreadSafe public class DefaultFilterableIssue implements FilterableIssue { private final Issue rawIssue; private final InputComponent component; - private final ProjectAnalysisInfo projectAnalysisInfo; + private final ProjectInfo projectInfo; private DefaultInputProject project; - public DefaultFilterableIssue(DefaultInputProject project, ProjectAnalysisInfo projectAnalysisInfo, Issue rawIssue, InputComponent component) { + public DefaultFilterableIssue(DefaultInputProject project, ProjectInfo projectInfo, Issue rawIssue, InputComponent component) { this.project = project; - this.projectAnalysisInfo = projectAnalysisInfo; + this.projectInfo = projectInfo; this.rawIssue = rawIssue; this.component = component; } @@ -91,7 +91,7 @@ public class DefaultFilterableIssue implements FilterableIssue { @Override public Date creationDate() { - return projectAnalysisInfo.analysisDate(); + return projectInfo.analysisDate(); } @Override diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueFilters.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueFilters.java index b4ade123839..2a3e6374dc0 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueFilters.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueFilters.java @@ -24,7 +24,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputProject; import org.sonar.api.scan.issue.filter.FilterableIssue; import org.sonar.api.scan.issue.filter.IssueFilter; import org.sonar.api.scan.issue.filter.IssueFilterChain; -import org.sonar.scanner.ProjectAnalysisInfo; +import org.sonar.scanner.ProjectInfo; import org.sonar.scanner.protocol.output.ScannerReport; /** @@ -34,20 +34,20 @@ import org.sonar.scanner.protocol.output.ScannerReport; public class IssueFilters { private final IssueFilterChain filterChain; private final DefaultInputProject project; - private final ProjectAnalysisInfo projectAnalysisInfo; + private final ProjectInfo projectInfo; - public IssueFilters(DefaultInputProject project, ProjectAnalysisInfo projectAnalysisInfo, IssueFilter[] exclusionFilters) { + public IssueFilters(DefaultInputProject project, ProjectInfo projectInfo, IssueFilter[] exclusionFilters) { this.project = project; this.filterChain = new DefaultIssueFilterChain(exclusionFilters); - this.projectAnalysisInfo = projectAnalysisInfo; + this.projectInfo = projectInfo; } - public IssueFilters(DefaultInputProject project, ProjectAnalysisInfo projectAnalysisInfo) { - this(project, projectAnalysisInfo, new IssueFilter[0]); + public IssueFilters(DefaultInputProject project, ProjectInfo projectInfo) { + this(project, projectInfo, new IssueFilter[0]); } public boolean accept(InputComponent component, ScannerReport.Issue rawIssue) { - FilterableIssue fIssue = new DefaultFilterableIssue(project, projectAnalysisInfo, rawIssue, component); + FilterableIssue fIssue = new DefaultFilterableIssue(project, projectInfo, rawIssue, component); return filterChain.accept(fIssue); } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/IssueTransition.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/IssueTransition.java index 737a4f6614a..fb90c7f5a0e 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/IssueTransition.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/IssueTransition.java @@ -28,7 +28,7 @@ import javax.annotation.Nullable; import org.sonar.api.batch.fs.InputComponent; import org.sonar.api.batch.fs.internal.DefaultInputComponent; import org.sonar.core.util.CloseableIterator; -import org.sonar.scanner.ProjectAnalysisInfo; +import org.sonar.scanner.ProjectInfo; import org.sonar.scanner.issue.IssueCache; import org.sonar.scanner.issue.IssueTransformer; import org.sonar.scanner.protocol.output.ScannerReport; @@ -45,17 +45,17 @@ public class IssueTransition { @Nullable private final LocalIssueTracking localIssueTracking; - public IssueTransition(InputComponentStore inputComponentCache, ProjectAnalysisInfo projectAnalysisInfo, IssueCache issueCache, ReportPublisher reportPublisher, - @Nullable LocalIssueTracking localIssueTracking) { + public IssueTransition(InputComponentStore inputComponentCache, ProjectInfo projectInfo, IssueCache issueCache, ReportPublisher reportPublisher, + @Nullable LocalIssueTracking localIssueTracking) { this.inputComponentStore = inputComponentCache; this.issueCache = issueCache; this.reportPublisher = reportPublisher; this.localIssueTracking = localIssueTracking; - this.analysisDate = projectAnalysisInfo.analysisDate(); + this.analysisDate = projectInfo.analysisDate(); } - public IssueTransition(InputComponentStore inputComponentCache, ProjectAnalysisInfo projectAnalysisInfo, IssueCache issueCache, ReportPublisher reportPublisher) { - this(inputComponentCache, projectAnalysisInfo, issueCache, reportPublisher, null); + public IssueTransition(InputComponentStore inputComponentCache, ProjectInfo projectInfo, IssueCache issueCache, ReportPublisher reportPublisher) { + this(inputComponentCache, projectInfo, issueCache, reportPublisher, null); } public void execute() { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java index a9d042489b9..dfd8163cb52 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java @@ -96,11 +96,6 @@ public class ComponentsPublisher implements ReportPublisherStep { projectBuilder.setDescription(description); } - String version = project.getOriginalVersion(); - if (version != null) { - projectBuilder.setVersion(version); - } - writeLinks(project, projectBuilder); return projectBuilder; } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java index fbbecab9fa1..2c83efeeb90 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java @@ -23,7 +23,6 @@ import java.io.File; import java.nio.file.Path; import java.util.LinkedList; import java.util.Map.Entry; -import java.util.Optional; import java.util.regex.Pattern; import javax.annotation.Nullable; import org.sonar.api.batch.fs.internal.AbstractProjectOrModule; @@ -32,7 +31,7 @@ import org.sonar.api.batch.fs.internal.InputModuleHierarchy; import org.sonar.api.batch.scm.ScmProvider; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; -import org.sonar.scanner.ProjectAnalysisInfo; +import org.sonar.scanner.ProjectInfo; import org.sonar.scanner.bootstrap.ScannerPlugin; import org.sonar.scanner.bootstrap.ScannerPluginRepository; import org.sonar.scanner.cpd.CpdSettings; @@ -45,13 +44,16 @@ import org.sonar.scanner.scan.ScanProperties; import org.sonar.scanner.scan.branch.BranchConfiguration; import org.sonar.scanner.scm.ScmConfiguration; +import static java.util.Optional.ofNullable; +import static org.apache.commons.lang.StringUtils.trimToNull; + public class MetadataPublisher implements ReportPublisherStep { private static final Logger LOG = Loggers.get(MetadataPublisher.class); private final ScanProperties properties; private final QualityProfiles qProfiles; - private final ProjectAnalysisInfo projectAnalysisInfo; + private final ProjectInfo projectInfo; private final InputModuleHierarchy moduleHierarchy; private final CpdSettings cpdSettings; private final ScannerPluginRepository pluginRepository; @@ -60,10 +62,10 @@ public class MetadataPublisher implements ReportPublisherStep { @Nullable private final ScmConfiguration scmConfiguration; - public MetadataPublisher(ProjectAnalysisInfo projectAnalysisInfo, InputModuleHierarchy moduleHierarchy, ScanProperties properties, + public MetadataPublisher(ProjectInfo projectInfo, InputModuleHierarchy moduleHierarchy, ScanProperties properties, QualityProfiles qProfiles, CpdSettings cpdSettings, ScannerPluginRepository pluginRepository, BranchConfiguration branchConfiguration, @Nullable ScmConfiguration scmConfiguration) { - this.projectAnalysisInfo = projectAnalysisInfo; + this.projectInfo = projectInfo; this.moduleHierarchy = moduleHierarchy; this.properties = properties; this.qProfiles = qProfiles; @@ -73,20 +75,21 @@ public class MetadataPublisher implements ReportPublisherStep { this.scmConfiguration = scmConfiguration; } - public MetadataPublisher(ProjectAnalysisInfo projectAnalysisInfo, InputModuleHierarchy moduleHierarchy, ScanProperties properties, + public MetadataPublisher(ProjectInfo projectInfo, InputModuleHierarchy moduleHierarchy, ScanProperties properties, QualityProfiles qProfiles, CpdSettings cpdSettings, ScannerPluginRepository pluginRepository, BranchConfiguration branchConfiguration) { - this(projectAnalysisInfo, moduleHierarchy, properties, qProfiles, cpdSettings, pluginRepository, branchConfiguration, null); + this(projectInfo, moduleHierarchy, properties, qProfiles, cpdSettings, pluginRepository, branchConfiguration, null); } @Override public void publish(ScannerReportWriter writer) { AbstractProjectOrModule rootProject = moduleHierarchy.root(); ScannerReport.Metadata.Builder builder = ScannerReport.Metadata.newBuilder() - .setAnalysisDate(projectAnalysisInfo.analysisDate().getTime()) + .setAnalysisDate(projectInfo.analysisDate().getTime()) // Here we want key without branch .setProjectKey(rootProject.key()) .setCrossProjectDuplicationActivated(cpdSettings.isCrossProjectDuplicationEnabled()) .setRootComponentRef(rootProject.scannerId()); + ofNullable(trimToNull(projectInfo.projectVersion())).ifPresent(builder::setProjectVersion); properties.organizationKey().ifPresent(builder::setOrganizationKey); @@ -94,7 +97,7 @@ public class MetadataPublisher implements ReportPublisherStep { addBranchInformation(builder); } - Optional.ofNullable(rootProject.getBranch()).ifPresent(builder::setDeprecatedBranch); + ofNullable(rootProject.getBranch()).ifPresent(builder::setDeprecatedBranch); if (scmConfiguration != null) { addScmInformation(builder); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/InputProjectProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/InputProjectProvider.java index cfb03e5a4b4..08303ac0a0b 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/InputProjectProvider.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/InputProjectProvider.java @@ -35,7 +35,7 @@ public class InputProjectProvider extends ProviderAdapter { private DefaultInputProject project = null; public DefaultInputProject provide(ProjectBuildersExecutor projectBuildersExecutor, ProjectReactorValidator validator, - ProjectReactor projectReactor, ScannerComponentIdGenerator scannerComponentIdGenerator) { + ProjectReactor projectReactor, ScannerComponentIdGenerator scannerComponentIdGenerator) { if (project == null) { // 1 Apply project builders projectBuildersExecutor.execute(projectReactor); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorValidator.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorValidator.java index 5eba211bbca..fb67d7dc0fa 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorValidator.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorValidator.java @@ -120,11 +120,6 @@ public class ProjectReactorValidator { validationMessages.add(format("\"%s\" is not a valid project or module key. " + "Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.", moduleDef.getKey())); } - String originalVersion = moduleDef.getOriginalVersion(); - if (originalVersion != null && originalVersion.length() > 100) { - validationMessages.add(format("\"%s\" is not a valid version name for module \"%s\". " + - "The maximum length for version numbers is 100 characters.", originalVersion, moduleDef.getKey())); - } } private static void validateBranch(List<String> validationMessages, @Nullable String branch) { 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 049d49cdc04..09900d136c1 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 @@ -37,7 +37,7 @@ import org.sonar.core.extension.CoreExtensionsInstaller; import org.sonar.core.metric.ScannerMetrics; import org.sonar.core.platform.ComponentContainer; import org.sonar.scanner.DefaultFileLinesContextFactory; -import org.sonar.scanner.ProjectAnalysisInfo; +import org.sonar.scanner.ProjectInfo; import org.sonar.scanner.analysis.AnalysisTempFolderProvider; import org.sonar.scanner.analysis.DefaultAnalysisMode; import org.sonar.scanner.bootstrap.ExtensionInstaller; @@ -167,7 +167,7 @@ public class ProjectScanContainer extends ComponentContainer { ResourceTypes.class, ProjectReactorValidator.class, MetricProvider.class, - ProjectAnalysisInfo.class, + ProjectInfo.class, Storages.class, new RulesProvider(), new BranchConfigurationProvider(), |