import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.api.batch.sensor.SensorContext;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.duplications.cpd.FileCodeLoaderWithoutCache;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
import org.slf4j.LoggerFactory;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.process.NetworkUtils;
import org.sonar.process.ProcessProperties;
import java.util.Optional;
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.SettingsReader;
@ComputeEngineSide
-public class ProjectSettings extends Settings {
+public class ProjectSettings extends Settings implements SettingsReader {
private final Map<String, String> projectProps = new HashMap<>();
private final Settings globalSettings;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.process.DefaultProcessCommands;
import org.sonar.process.ProcessEntryPoint;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.process.DefaultProcessCommands;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.System2;
import org.sonar.core.util.UuidFactory;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.security.Authenticator;
import org.sonar.api.security.ExternalGroupsProvider;
import org.sonar.api.security.ExternalUsersProvider;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.internal.AlwaysIncreasingSystem2;
import org.sonar.core.util.stream.MoreCollectors;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.authentication.UserIdentity;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.internal.AlwaysIncreasingSystem2;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.authentication.BaseIdentityProvider;
import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import javax.servlet.http.HttpServletResponse;
import org.junit.Before;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.server.authentication.BasicAuthenticator;
import org.sonar.server.authentication.JwtHttpHandler;
import org.sonar.server.authentication.event.AuthenticationException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
import org.assertj.core.api.AbstractListAssert;
import org.junit.Before;
import org.junit.Rule;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.server.ws.WebService.Param;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.WebService;
import org.junit.Test;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.log.Logger;
import org.sonar.core.config.PurgeConstants;
import org.sonar.db.DbSession;
import org.junit.rules.ExpectedException;
import org.sonar.api.ce.measure.Component;
import org.sonar.api.ce.measure.MeasureComputer;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.Duration;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.ce.settings.ProjectSettingsFactory;
import org.sonar.db.DbClient;
import java.util.Collections;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.duplications.block.Block;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.CoreProperties;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.user.UserDto;
import java.util.Collections;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.server.es.EsTester;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.rule.RuleKey;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.server.computation.task.projectanalysis.component.Component;
import org.junit.rules.ExpectedException;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.utils.MessageException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.purge.IdUuidPair;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.server.computation.task.projectanalysis.component.Component;
import org.sonar.server.computation.task.projectanalysis.component.ReportComponent;
import org.sonar.server.computation.task.projectanalysis.component.SettingsRepository;
import org.junit.rules.Timeout;
import org.sonar.api.SonarQubeSide;
import org.sonar.api.SonarRuntime;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.internal.SonarRuntimeImpl;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.Version;
import org.junit.Test;
import org.sonar.api.ce.posttask.CeTask;
import org.sonar.api.ce.posttask.PostProjectAnalysisTaskTester;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.server.computation.task.projectanalysis.component.SettingsRepository;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.process.ProcessProperties;
import org.elasticsearch.node.NodeBuilder;
import org.elasticsearch.search.SearchHit;
import org.junit.rules.ExternalResource;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.core.platform.ComponentContainer;
import static com.google.common.base.Preconditions.checkState;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mockito;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.process.ProcessProperties;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.utils.System2;
import org.sonar.core.issue.DefaultIssue;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.issue.Issue;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.rule.RuleKey;
package org.sonar.server.issue.index;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.server.es.IndexDefinition;
import org.sonar.server.es.NewIndex;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.issue.Issue;
import org.sonar.api.resources.Scopes;
import org.sonar.api.rule.RuleKey;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.EmailSettings;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.notifications.Notification;
import org.sonar.db.DbTester;
import org.sonar.plugins.emailnotifications.api.EmailMessage;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.utils.internal.TestSystem2;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.rules.RuleType;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.System2;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.utils.System2;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService.Action;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.WebService.Action;
import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.utils.System2;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.measures.Metric;
import org.sonar.api.measures.Metric.ValueType;
import org.sonar.api.utils.System2;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.measures.Metric;
import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.measures.Metric.ValueType;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.DateUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.measures.Metric.ValueType;
import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.resources.Qualifiers;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.resources.Qualifiers;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDbTester;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.notifications.Notification;
import org.sonar.api.notifications.NotificationChannel;
import org.sonar.db.DbClient;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.internal.TestSystem2;
import org.sonar.api.web.UserRole;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.System2;
import org.sonar.core.util.UuidFactory;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.server.ws.WebService.Param;
import org.sonar.db.DbClient;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentTesting;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.junit.Test;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import org.sonar.api.CoreProperties;
import org.sonar.api.SonarRuntime;
import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.Version;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.process.ProcessProperties;
import org.junit.rules.ExpectedException;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.core.config.CorePropertyDefinitions;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.database.DatabaseProperties;
import org.sonar.api.utils.System2;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.process.NetworkUtils;
import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.server.es.EsClient;
import org.sonar.server.es.EsTester;
import org.sonar.server.issue.index.IssueIndexDefinition;
import org.sonar.api.config.PropertyDefinition;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import static org.apache.commons.lang.StringUtils.repeat;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.platform.Server;
import org.sonar.api.security.SecurityRealm;
import org.sonar.api.utils.log.LoggerLevel;
import org.junit.rules.ExpectedException;
import org.mockito.InOrder;
import org.mockito.Mockito;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.server.app.ProcessCommandWrapper;
import java.nio.charset.StandardCharsets;
import org.junit.Before;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.SonarException;
import org.sonar.api.utils.UriReader;
import org.sonar.core.config.WebConstants;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.component.ComponentDto;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.PropertyType;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Languages;
import org.sonar.api.rule.RuleKey;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.profiles.ProfileImporter;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.rules.RulePriority;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.resources.Languages;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Languages;
import org.sonar.api.rule.RuleKey;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.process.ProcessProperties;
import org.sonar.server.es.EsTester;
import org.sonar.server.es.IndexDefinition;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.utils.System2;
import com.google.common.collect.ImmutableSet;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.api.rules.RuleType;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.resources.Languages;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.junit.Before;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.resources.Languages;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.resources.Languages;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.resources.Languages;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.junit.Test;
import org.mockito.Mockito;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.ce.settings.ProjectSettingsFactory;
import org.sonar.db.DbClient;
import org.sonar.db.property.PropertyDto;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.config.Encryption;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.WebService;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.tester.UserSessionRule;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.config.Encryption;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.WebService;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.config.Encryption;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.WebService;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.tester.UserSessionRule;
import java.util.List;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.server.es.EsTester;
import org.sonar.server.es.SearchOptions;
import org.elasticsearch.search.SearchHit;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.protobuf.DbFileSources;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.platform.Server;
import org.sonar.api.resources.ResourceType;
import org.sonar.api.resources.ResourceTypeTree;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.web.page.Page;
import org.sonar.api.web.page.PageDefinition;
import org.sonar.core.config.WebConstants;
import org.junit.Test;
import org.sonar.api.CoreProperties;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.security.LoginPasswordAuthenticator;
import org.sonar.api.security.SecurityRealm;
import org.sonar.api.utils.SonarException;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.platform.NewUserHandler;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.internal.TestSystem2;
package org.sonar.server.user.index;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.server.es.IndexDefinition;
import org.sonar.server.es.NewIndex;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.server.es.EsTester;
import org.sonar.server.es.SearchOptions;
import java.util.List;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.user.UserDto;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.server.es.EsTester;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.internal.AlwaysIncreasingSystem2;
import org.sonar.core.config.CorePropertyDefinitions;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.internal.AlwaysIncreasingSystem2;
import org.sonar.db.DbClient;
import java.util.function.Consumer;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.junit.Test;
import org.sonar.api.SonarQubeSide;
import org.sonar.api.SonarRuntime;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.internal.SonarRuntimeImpl;
import org.sonar.api.utils.Version;
package org.sonar.server.view.index;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.server.es.IndexDefinition;
import org.sonar.server.es.NewIndex;
import java.util.List;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.server.es.EsTester;
import static com.google.common.collect.Lists.newArrayList;
import java.util.Map;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.api.platform.Server;
import org.sonar.api.utils.HttpDownloader;
import org.sonar.api.utils.SonarException;
import org.sonar.api.utils.log.Loggers;
import static org.apache.commons.io.FileUtils.copyInputStreamToFile;
-import static org.apache.commons.lang.StringUtils.isNotEmpty;
import static org.sonar.core.util.FileUtils.deleteQuietly;
/**
private final Integer readTimeout;
private final Integer connectTimeout;
- public DefaultHttpDownloader(Server server, Settings settings) {
- this(server, settings, null);
+ public DefaultHttpDownloader(Server server, Configuration config) {
+ this(server, config, null);
}
- public DefaultHttpDownloader(Server server, Settings settings, @Nullable Integer readTimeout) {
- this(server, settings, null, readTimeout);
+ public DefaultHttpDownloader(Server server, Configuration config, @Nullable Integer readTimeout) {
+ this(server, config, null, readTimeout);
}
- public DefaultHttpDownloader(Server server, Settings settings, @Nullable Integer connectTimeout, @Nullable Integer readTimeout) {
+ public DefaultHttpDownloader(Server server, Configuration config, @Nullable Integer connectTimeout, @Nullable Integer readTimeout) {
this.readTimeout = readTimeout;
this.connectTimeout = connectTimeout;
- downloader = new BaseHttpDownloader(new AuthenticatorFacade(), settings, server.getVersion());
+ downloader = new BaseHttpDownloader(new AuthenticatorFacade(), config, server.getVersion());
}
- public DefaultHttpDownloader(Settings settings) {
- this(settings, null);
+ public DefaultHttpDownloader(Configuration config) {
+ this(config, null);
}
- public DefaultHttpDownloader(Settings settings, @Nullable Integer readTimeout) {
- this(settings, null, readTimeout);
+ public DefaultHttpDownloader(Configuration config, @Nullable Integer readTimeout) {
+ this(config, null, readTimeout);
}
- public DefaultHttpDownloader(Settings settings, @Nullable Integer connectTimeout, @Nullable Integer readTimeout) {
+ public DefaultHttpDownloader(Configuration config, @Nullable Integer connectTimeout, @Nullable Integer readTimeout) {
this.readTimeout = readTimeout;
this.connectTimeout = connectTimeout;
- downloader = new BaseHttpDownloader(new AuthenticatorFacade(), settings, null);
+ downloader = new BaseHttpDownloader(new AuthenticatorFacade(), config, null);
}
@Override
private String userAgent;
- BaseHttpDownloader(AuthenticatorFacade system, Settings settings, @Nullable String userAgent) {
- initProxy(system, settings);
- initUserAgent(userAgent, settings);
+ BaseHttpDownloader(AuthenticatorFacade system, Configuration config, @Nullable String userAgent) {
+ initProxy(system, config);
+ initUserAgent(userAgent, config);
}
- private void initProxy(AuthenticatorFacade system, Settings settings) {
+ private void initProxy(AuthenticatorFacade system, Configuration config) {
// register credentials
- String login = settings.getString(HTTP_PROXY_USER);
- if (isNotEmpty(login)) {
- system.setDefaultAuthenticator(new ProxyAuthenticator(login, settings.getString(HTTP_PROXY_PASSWORD)));
+ Optional<String> login = config.get(HTTP_PROXY_USER);
+ if (login.isPresent()) {
+ system.setDefaultAuthenticator(new ProxyAuthenticator(login.get(), config.get(HTTP_PROXY_PASSWORD).orElse(null)));
}
}
- private void initUserAgent(@Nullable String sonarVersion, Settings settings) {
- String serverId = settings.getString(CoreProperties.SERVER_ID);
- userAgent = sonarVersion == null ? "SonarQube" : String.format("SonarQube %s # %s", sonarVersion, Optional.ofNullable(serverId).orElse(""));
+ private void initUserAgent(@Nullable String sonarVersion, Configuration settings) {
+ Optional<String> serverId = settings.get(CoreProperties.SERVER_ID);
+ userAgent = sonarVersion == null ? "SonarQube" : String.format("SonarQube %s # %s", sonarVersion, serverId.orElse(""));
System.setProperty("http.agent", userAgent);
}
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.i18n.I18n;
import static org.mockito.Matchers.anyString;
import org.simpleframework.http.core.Container;
import org.simpleframework.transport.connect.SocketConnection;
import org.sonar.api.CoreProperties;
-import org.sonar.api.config.MapSettings;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.platform.Server;
import org.sonar.api.utils.SonarException;
@Override
public boolean matches(Object ex) {
return
- // Java 8
- ex instanceof NoRouteToHostException || ex instanceof SocketException
- // Java 7 or before
- || ex instanceof SocketTimeoutException;
+ // Java 8
+ ex instanceof NoRouteToHostException || ex instanceof SocketException
+ // Java 7 or before
+ || ex instanceof SocketTimeoutException;
}
@Override
public void describeTo(Description arg0) {
}
}));
- DefaultHttpDownloader downloader = new DefaultHttpDownloader(new MapSettings(), 10, 50000);
+ DefaultHttpDownloader downloader = new DefaultHttpDownloader(new MapSettings().asConfig(), 10, 50000);
downloader.openStream(new URI(url));
}
@Test
public void downloadBytes() throws URISyntaxException {
- byte[] bytes = new DefaultHttpDownloader(new MapSettings()).readBytes(new URI(baseUrl));
+ byte[] bytes = new DefaultHttpDownloader(new MapSettings().asConfig()).readBytes(new URI(baseUrl));
assertThat(bytes.length).isGreaterThan(10);
}
@Test
public void readString() throws URISyntaxException {
- String text = new DefaultHttpDownloader(new MapSettings()).readString(new URI(baseUrl), StandardCharsets.UTF_8);
+ String text = new DefaultHttpDownloader(new MapSettings().asConfig()).readString(new URI(baseUrl), StandardCharsets.UTF_8);
assertThat(text.length()).isGreaterThan(10);
}
@Test
public void readGzipString() throws URISyntaxException {
- String text = new DefaultHttpDownloader(new MapSettings()).readString(new URI(baseUrl + "/gzip/"), StandardCharsets.UTF_8);
+ String text = new DefaultHttpDownloader(new MapSettings().asConfig()).readString(new URI(baseUrl + "/gzip/"), StandardCharsets.UTF_8);
assertThat(text).isEqualTo("GZIP response");
}
@Test
public void readStringWithDefaultTimeout() throws URISyntaxException {
- String text = new DefaultHttpDownloader(new MapSettings()).readString(new URI(baseUrl + "/timeout/"), StandardCharsets.UTF_8);
+ String text = new DefaultHttpDownloader(new MapSettings().asConfig()).readString(new URI(baseUrl + "/timeout/"), StandardCharsets.UTF_8);
assertThat(text.length()).isGreaterThan(10);
}
public void describeTo(Description arg0) {
}
});
- new DefaultHttpDownloader(new MapSettings(), 50).readString(new URI(baseUrl + "/timeout/"), StandardCharsets.UTF_8);
+ new DefaultHttpDownloader(new MapSettings().asConfig(), 50).readString(new URI(baseUrl + "/timeout/"), StandardCharsets.UTF_8);
}
@Test
File toDir = temporaryFolder.newFolder();
File toFile = new File(toDir, "downloadToFile.txt");
- new DefaultHttpDownloader(new MapSettings()).download(new URI(baseUrl), toFile);
+ new DefaultHttpDownloader(new MapSettings().asConfig()).download(new URI(baseUrl), toFile);
assertThat(toFile).exists();
assertThat(toFile.length()).isGreaterThan(10l);
}
try {
int port = new InetSocketAddress("localhost", 0).getPort();
- new DefaultHttpDownloader(new MapSettings()).download(new URI("http://localhost:" + port), toFile);
+ new DefaultHttpDownloader(new MapSettings().asConfig()).download(new URI("http://localhost:" + port), toFile);
} catch (SonarException e) {
assertThat(toFile).doesNotExist();
}
MapSettings settings = new MapSettings();
settings.setProperty(CoreProperties.SERVER_ID, "blablabla");
- InputStream stream = new DefaultHttpDownloader(server, settings).openStream(new URI(baseUrl));
+ InputStream stream = new DefaultHttpDownloader(server, settings.asConfig()).openStream(new URI(baseUrl));
Properties props = new Properties();
props.load(stream);
stream.close();
Server server = mock(Server.class);
when(server.getVersion()).thenReturn("2.2");
- InputStream stream = new DefaultHttpDownloader(server, new MapSettings()).openStream(new URI(baseUrl));
+ InputStream stream = new DefaultHttpDownloader(server, new MapSettings().asConfig()).openStream(new URI(baseUrl));
Properties props = new Properties();
props.load(stream);
stream.close();
@Test
public void userAgent_is_static_value_when_server_is_not_provided() throws URISyntaxException, IOException {
- InputStream stream = new DefaultHttpDownloader(new MapSettings()).openStream(new URI(baseUrl));
+ InputStream stream = new DefaultHttpDownloader(new MapSettings().asConfig()).openStream(new URI(baseUrl));
Properties props = new Properties();
props.load(stream);
stream.close();
@Test
public void followRedirect() throws URISyntaxException {
- String content = new DefaultHttpDownloader(new MapSettings()).readString(new URI(baseUrl + "/redirect/"), StandardCharsets.UTF_8);
+ String content = new DefaultHttpDownloader(new MapSettings().asConfig()).readString(new URI(baseUrl + "/redirect/"), StandardCharsets.UTF_8);
assertThat(content).contains("agent");
}
@Test
public void supported_schemes() {
- assertThat(new DefaultHttpDownloader(new MapSettings()).getSupportedSchemes()).contains("http");
+ assertThat(new DefaultHttpDownloader(new MapSettings().asConfig()).getSupportedSchemes()).contains("http");
}
@Test
public void uri_description() throws URISyntaxException {
- String description = new DefaultHttpDownloader(new MapSettings()).description(new URI("http://sonarsource.org"));
+ String description = new DefaultHttpDownloader(new MapSettings().asConfig()).description(new URI("http://sonarsource.org"));
assertThat(description).matches("http://sonarsource.org \\(.*\\)");
}
@Test
public void configure_http_proxy_credentials() {
DefaultHttpDownloader.AuthenticatorFacade system = mock(DefaultHttpDownloader.AuthenticatorFacade.class);
- Settings settings = new MapSettings();
+ MapSettings settings = new MapSettings();
settings.setProperty("https.proxyHost", "1.2.3.4");
settings.setProperty("http.proxyUser", "the_login");
settings.setProperty("http.proxyPassword", "the_passwd");
- new DefaultHttpDownloader.BaseHttpDownloader(system, settings, null);
+ new DefaultHttpDownloader.BaseHttpDownloader(system, settings.asConfig(), null);
verify(system).setDefaultAuthenticator(argThat(new TypeSafeMatcher<Authenticator>() {
@Override
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import org.sonar.api.config.Configuration;
/**
* Plugin properties. This annotation is only used on classes implementing org.sonar.api.Plugin.
* Note that {@link org.sonar.api.config.PropertyDefinition} is an alternative, programmatic and recommended approach
* to declare properties.
* <br>
- * Effective property values are accessible at runtime through the component {@link org.sonar.api.config.Settings}
+ * Effective property values are accessible at runtime through the component {@link Configuration}
*
* @since 1.10
*/
}
return null;
}
-
+
@CheckForNull
public String getOriginalVersion() {
return properties.get(CoreProperties.PROJECT_VERSION_PROPERTY);
}
return version;
}
-
+
@CheckForNull
public String getOriginalName() {
return properties.get(CoreProperties.PROJECT_NAME_PROPERTY);
return this;
}
+ @CheckForNull
public ProjectDefinition getParent() {
return parent;
}
/**
* @since 4.3
+ * @deprecated since 6.5 debt model will soon be unavailable on batch side
*/
public class DebtRemediationFunction {
import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.postjob.issue.PostJobIssue;
+import org.sonar.api.config.Configuration;
import org.sonar.api.config.Settings;
/**
public interface PostJobContext {
/**
- * Get settings of the current project.
+ * @deprecated since 6.5 use {@link PostJobContext#config()}
*/
Settings settings();
+ /**
+ * Get configuration of the current project.
+ * @since 6.5
+ */
+ Configuration config();
+
AnalysisMode analysisMode();
// ----------- Only available in preview mode --------------
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputModule;
+import org.sonar.api.batch.postjob.PostJobContext;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.sensor.coverage.NewCoverage;
import org.sonar.api.batch.sensor.cpd.NewCpdTokens;
import org.sonar.api.batch.sensor.measure.NewMeasure;
import org.sonar.api.batch.sensor.symbol.NewSymbolTable;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.api.utils.Version;
/**
public interface SensorContext {
/**
- * Get settings of the current module.
+ * @deprecated since 6.5 use {@link PostJobContext#config()}
*/
Settings settings();
+ /**
+ * Get settings of the current module, or of the project for a global Sensor.
+ * @since 6.5
+ */
+ Configuration config();
+
/**
* Get filesystem of the current module.
*/
import org.sonar.api.batch.sensor.cpd.NewCpdTokens;
import org.sonar.api.batch.sensor.internal.DefaultStorable;
import org.sonar.api.batch.sensor.internal.SensorStorage;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.duplications.internal.pmd.TokensLine;
import static com.google.common.base.Preconditions.checkState;
public class DefaultCpdTokens extends DefaultStorable implements NewCpdTokens {
- private final Settings settings;
+ private final Configuration config;
private final ArrayList<TokensLine> result = new ArrayList<>();
private InputFile inputFile;
private int startLine = Integer.MIN_VALUE;
private TextRange lastRange;
private boolean excluded;
- public DefaultCpdTokens(Settings settings, SensorStorage storage) {
+ public DefaultCpdTokens(Configuration config, SensorStorage storage) {
super(storage);
- this.settings = settings;
+ this.config = config;
}
@Override
public DefaultCpdTokens onFile(InputFile inputFile) {
this.inputFile = requireNonNull(inputFile, "file can't be null");
- String[] cpdExclusions = settings.getStringArray(CoreProperties.CPD_EXCLUSIONS);
+ String[] cpdExclusions = config.getStringArray(CoreProperties.CPD_EXCLUSIONS);
for (PathPattern cpdExclusion : PathPattern.create(cpdExclusions)) {
if (cpdExclusion.match(inputFile)) {
this.excluded = true;
import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
import org.sonar.api.batch.sensor.symbol.NewSymbolTable;
import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.Configuration;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.ConfigurationBridge;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.internal.ApiVersion;
import org.sonar.api.internal.SonarRuntimeImpl;
import org.sonar.api.measures.Metric;
return settings;
}
+ @Override
+ public Configuration config() {
+ return new ConfigurationBridge(settings);
+ }
+
public SensorContextTester setSettings(Settings settings) {
this.settings = settings;
return this;
@Override
public NewCpdTokens newCpdTokens() {
- return new DefaultCpdTokens(settings, sensorStorage);
+ return new DefaultCpdTokens(config(), sensorStorage);
}
@Override
--- /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.api.config;
+
+import java.util.Optional;
+import org.sonar.api.batch.ScannerSide;
+import org.sonar.api.ce.ComputeEngineSide;
+import org.sonar.api.config.internal.MapSettings;
+import org.sonar.api.server.ServerSide;
+import org.sonarsource.api.sonarlint.SonarLintSide;
+
+/**
+ * Component to get effective configuration. Values of properties depend on the runtime environment:
+ * <ul>
+ * <li>immutable project or module configuration in scanner.</li>
+ * <li>global configuration in web server. It does not allow to get the settings overridden on projects.</li>
+ * <li>project configuration in Compute Engine.</li>
+ * </ul>
+ *
+ * <h3>Usage</h3>
+ * <pre>
+ * public class MyExtension {
+ *
+ * private final Configuration config;
+ *
+ * public MyExtension(Configuration config) {
+ * this.config = config;
+ * }
+ * public void doSomething() {
+ * String fooValue = config.get("sonar.foo").orElse(null);
+ * // ..
+ * }
+ * }
+ * </pre>
+ *
+ * <h3>Scanner example</h3>
+ * Scanner sensor can get the reference on Configuration directly through SensorContext,
+ * without injecting the component into constructor.
+ *
+ * <pre>
+ * public class MySensor implements Sensor {
+ * {@literal @}Override
+ * public void execute(SensorContext context) {
+ * String fooValue = context.config().get("sonar.foo").orElse(null);
+ * // ..
+ * }
+ * }
+ * </pre>
+ *
+ * <p>
+ * For testing, and only for testing, the in-memory implementation {@link MapSettings} can be used.
+ * <pre>
+ * {@literal @}Test
+ * public void my_test() {
+ * MapSettings settings = new MapSettings();
+ * settings.setProperty("foo", "bar");
+ * MyExtension underTest = new MyExtension(settings.asConfig());
+ * // ...
+ * }
+ * </pre>
+ *
+ * @see MapSettings
+ * @see PropertyDefinition
+ * @since 6.5
+ */
+@ScannerSide
+@ServerSide
+@ComputeEngineSide
+@SonarLintSide
+public interface Configuration {
+
+ /**
+ * The effective value of the specified property. Can return {@code Optional#empty()} if the property is not set and has no defined default value.
+ * <p>
+ * If the property is encrypted with a secret key, then the returned value is decrypted.
+ * </p>
+ *
+ * @throws IllegalStateException if value is encrypted but fails to be decrypted.
+ */
+ Optional<String> get(String key);
+
+ /**
+ * @return {@code true} if the property has a non-default value, else {@code false}.
+ */
+ boolean hasKey(String key);
+
+ /**
+ * Used to read multi-valued properties.
+ * <p>
+ * See {@link PropertyDefinition.Builder#multiValues(boolean)}
+ * Multi-valued properties coming from scanner are parsed as CSV lines (ie comma separator and optional double quotes to escape values).
+ * Non quoted values are trimmed.
+ * <br>
+ * Examples :
+ * <ul>
+ * <li>"one,two,three " -> ["one", "two", "three"]</li>
+ * <li>" one, two, three " -> ["one", "two", "three"]</li>
+ * <li>"one, , three" -> ["one", "", "three"]</li>
+ * <li>"one,\"two,three\",\" four \"" -> ["one", "two,three", " four "]</li>
+ * </ul>
+ */
+ String[] getStringArray(String key);
+
+ /**
+ * Effective value as boolean. It is {@code empty} if {@link #get(String)} is empty or if it
+ * does not return {@code "true"}, even if it's not a boolean representation.
+ * @return {@code true} if the effective value is {@code "true"}, {@code false} for any other non empty value.
+ * If the property does not have value nor default value, then {@code empty} is returned.
+ */
+ default Optional<Boolean> getBoolean(String key) {
+ return get(key).map(Boolean::parseBoolean);
+ }
+
+ /**
+ * Effective value as {@code int}.
+ * @return the value as {@code int}. If the property does not have value nor default value, then {@code empty} is returned.
+ * @throws NumberFormatException if value is not empty and is not a parsable integer
+ */
+ default Optional<Integer> getInt(String key) {
+ try {
+ return get(key).map(Integer::parseInt);
+ } catch (NumberFormatException e) {
+ throw new IllegalStateException(String.format("The property '%s' is not an int value: %s", key, e.getMessage()));
+ }
+ }
+
+ /**
+ * Effective value as {@code long}.
+ * @return the value as {@code long}. If the property does not have value nor default value, then {@code empty} is returned.
+ * @throws NumberFormatException if value is not empty and is not a parsable {@code long}
+ */
+ default Optional<Long> getLong(String key) {
+ try {
+ return get(key).map(Long::parseLong);
+ } catch (NumberFormatException e) {
+ throw new IllegalStateException(String.format("The property '%s' is not an long value: %s", key, e.getMessage()));
+ }
+ }
+
+ /**
+ * Effective value as {@code Float}.
+ * @return the value as {@code Float}. If the property does not have value nor default value, then {@code empty} is returned.
+ * @throws NumberFormatException if value is not empty and is not a parsable number
+ */
+ default Optional<Float> getFloat(String key) {
+ try {
+ return get(key).map(Float::valueOf);
+ } catch (NumberFormatException e) {
+ throw new IllegalStateException(String.format("The property '%s' is not an float value: %s", key, e.getMessage()));
+ }
+ }
+
+ /**
+ * Effective value as {@code Double}.
+ * @return the value as {@code Double}. If the property does not have value nor default value, then {@code empty} is returned.
+ * @throws NumberFormatException if value is not empty and is not a parsable number
+ */
+ default Optional<Double> getDouble(String key) {
+ try {
+ return get(key).map(Double::valueOf);
+ } catch (NumberFormatException e) {
+ throw new IllegalStateException(String.format("The property '%s' is not an double value: %s", key, e.getMessage()));
+ }
+ }
+
+}
import java.util.List;
import org.sonar.api.PropertyType;
-import org.sonar.api.batch.ScannerSide;
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.server.ServerSide;
import static org.sonar.api.PropertyType.SINGLE_SELECT_LIST;
/**
- * If batch extensions use this component, then batch must be executed with administrator rights (see properties sonar.login and sonar.password)
- *
* @since 3.2
*/
-@ScannerSide
@ServerSide
@ComputeEngineSide
public class EmailSettings {
+++ /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.api.config;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-
-import static java.util.Collections.unmodifiableMap;
-
-/**
- * In-memory map-based implementation of {@link Settings}. It must be used
- * <b>only for unit tests</b>. This is not the implementation
- * deployed at runtime, so non-test code must never cast
- * {@link Settings} to {@link MapSettings}.
- *
- * @since 6.1
- */
-public class MapSettings extends Settings {
-
- private final Map<String, String> props = new HashMap<>();
-
- public MapSettings() {
- super(new PropertyDefinitions(), new Encryption(null));
- }
-
- public MapSettings(PropertyDefinitions definitions) {
- super(definitions, new Encryption(null));
- }
-
- @Override
- protected Optional<String> get(String key) {
- return Optional.ofNullable(props.get(key));
- }
-
- @Override
- protected void set(String key, String value) {
- props.put(key, value);
- }
-
- @Override
- protected void remove(String key) {
- props.remove(key);
- }
-
- @Override
- public Map<String, String> getProperties() {
- return unmodifiableMap(props);
- }
-
- /**
- * Delete all properties
- */
- public MapSettings clear() {
- props.clear();
- return this;
- }
-}
import static org.sonar.api.PropertyType.SINGLE_SELECT_LIST;
/**
- * Declare a plugin property. Values are available at runtime through the component {@link Settings}.
+ * Declare a plugin property. Values are available at runtime through the components {@link Settings} or {@link org.sonar.api.Configuration.SettingsReader}.
* <br>
* It's the programmatic alternative to the annotation {@link org.sonar.api.Property}. It is more
* testable and adds new features like sub-categories and ordering.
return byCategory;
}
+ @CheckForNull
public String getDefaultValue(String key) {
PropertyDefinition def = get(key);
if (def == null) {
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.server.ServerSide;
import org.sonar.api.utils.DateUtils;
+import org.sonarsource.api.sonarlint.SonarLintSide;
import static java.util.Objects.requireNonNull;
import static org.apache.commons.lang.StringUtils.trim;
/**
- * Component to get effective settings. Values of properties depend on the runtime environment:
- * <ul>
- * <li>project settings in scanner.</li>
- * <li>global settings in web server. It does not allow to get the settings overridden on projects.</li>
- * <li>project settings in Compute Engine.</li>
- * </ul>
- *
- * <h3>Usage</h3>
- * <pre>
- * public class MyExtension {
- *
- * private final Settings settings;
- *
- * public MyExtension(Settings settings) {
- * this.settings = settings;
- * }
- * public void doSomething() {
- * String fooValue = settings.getString("sonar.foo");
- * // ..
- * }
- * }
- * </pre>
- *
- * <h3>Scanner example</h3>
- * Scanner sensor can get the reference on Settings directly through SensorContext,
- * without injecting the component into constructor.
- *
- * <pre>
- * public class MySensor implements Sensor {
- * {@literal @}Override
- * public void execute(SensorContext context) {
- * String fooValue = context.settings().getString("sonar.foo");
- * // ..
- * }
- * }
- * </pre>
- *
- * <p>
- * For testing, and only for testing, the in-memory implementation {@link MapSettings} can be used.
- * <pre>
- * {@literal @}Test
- * public void my_test() {
- * Settings settings = new MapSettings();
- * settings.setProperty("foo", "bar");
- * MyExtension underTest = new MyExtension(settings);
- * // ...
- * }
- * </pre>
- *
- * History - this class is abstract since 6.1.
- *
- * @see MapSettings
- * @see PropertyDefinition
- * @since 2.12
+ * @deprecated since 6.5 use {@link Configuration}
*/
-@ScannerSide
@ServerSide
@ComputeEngineSide
+@ScannerSide
+@SonarLintSide
+@Deprecated
public abstract class Settings {
private final PropertyDefinitions definitions;
--- /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.api.config.internal;
+
+import java.util.Optional;
+import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
+
+/**
+ * Used to help migration from {@link Settings} to {@link Configuration}
+ */
+public class ConfigurationBridge implements Configuration {
+
+ private final Settings settings;
+
+ public ConfigurationBridge(Settings settings) {
+ this.settings = settings;
+ }
+
+ @Override
+ public Optional<String> get(String key) {
+ return Optional.ofNullable(settings.getString(key));
+ }
+
+ @Override
+ public boolean hasKey(String key) {
+ return settings.hasKey(key);
+ }
+
+ @Override
+ public String[] getStringArray(String key) {
+ return settings.getStringArray(key);
+ }
+
+}
--- /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.api.config.internal;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import org.sonar.api.config.Configuration;
+import org.sonar.api.config.Encryption;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.api.config.Settings;
+
+import static java.util.Collections.unmodifiableMap;
+
+/**
+ * In-memory map-based implementation of {@link Settings}. It must be used
+ * <b>only for unit tests</b>. This is not the implementation
+ * deployed at runtime, so non-test code must never cast
+ * {@link Settings} to {@link MapSettings}.
+ *
+ * @since 6.1
+ */
+public class MapSettings extends Settings {
+
+ private final Map<String, String> props = new HashMap<>();
+ private final ConfigurationBridge configurationBridge;
+
+ public MapSettings() {
+ this(new PropertyDefinitions());
+ }
+
+ public MapSettings(PropertyDefinitions definitions) {
+ super(definitions, new Encryption(null));
+ configurationBridge = new ConfigurationBridge(this);
+ }
+
+ @Override
+ protected Optional<String> get(String key) {
+ return Optional.ofNullable(props.get(key));
+ }
+
+ @Override
+ protected void set(String key, String value) {
+ props.put(key, value);
+ }
+
+ @Override
+ protected void remove(String key) {
+ props.remove(key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return unmodifiableMap(props);
+ }
+
+ /**
+ * Delete all properties
+ */
+ public MapSettings clear() {
+ props.clear();
+ return this;
+ }
+
+ /**
+ * @return a {@link Configuration} proxy on top of this existing {@link Settings} implementation. Changes are reflected in the {@link Configuration} object.
+ * @since 6.5
+ */
+ public Configuration asConfig() {
+ return configurationBridge;
+ }
+}
--- /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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.api.config.internal;
+
+import javax.annotation.ParametersAreNonnullByDefault;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.ScannerSide;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
/**
* Configuration of file inclusions and exclusions.
*/
@ScannerSide
public class FileExclusions {
- private final Settings settings;
+ private final Configuration settings;
- public FileExclusions(Settings settings) {
+ public FileExclusions(Configuration settings) {
this.settings = settings;
}
import org.junit.Test;
import org.sonar.api.batch.bootstrap.internal.ProjectBuilderContext;
import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.core.Is.is;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.api.batch.sensor.internal.SensorStorage;
import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
@Test
public void save_no_tokens() {
SensorStorage sensorStorage = mock(SensorStorage.class);
- DefaultCpdTokens tokens = new DefaultCpdTokens(new MapSettings(), sensorStorage)
+ DefaultCpdTokens tokens = new DefaultCpdTokens(new MapSettings().asConfig(), sensorStorage)
.onFile(INPUT_FILE);
tokens.save();
@Test
public void save_one_token() {
SensorStorage sensorStorage = mock(SensorStorage.class);
- DefaultCpdTokens tokens = new DefaultCpdTokens(new MapSettings(), sensorStorage)
+ DefaultCpdTokens tokens = new DefaultCpdTokens(new MapSettings().asConfig(), sensorStorage)
.onFile(INPUT_FILE)
.addToken(INPUT_FILE.newRange(1, 2, 1, 5), "foo");
@Test
public void handle_exclusions_by_pattern() {
SensorStorage sensorStorage = mock(SensorStorage.class);
- Settings settings = new MapSettings();
+ MapSettings settings = new MapSettings();
settings.setProperty("sonar.cpd.exclusions", "src/Foo.java,another");
- DefaultCpdTokens tokens = new DefaultCpdTokens(settings, sensorStorage)
+ DefaultCpdTokens tokens = new DefaultCpdTokens(settings.asConfig(), sensorStorage)
.onFile(INPUT_FILE)
.addToken(INPUT_FILE.newRange(1, 2, 1, 5), "foo");
@Test
public void save_many_tokens() {
SensorStorage sensorStorage = mock(SensorStorage.class);
- DefaultCpdTokens tokens = new DefaultCpdTokens(new MapSettings(), sensorStorage)
+ DefaultCpdTokens tokens = new DefaultCpdTokens(new MapSettings().asConfig(), sensorStorage)
.onFile(INPUT_FILE)
.addToken(INPUT_FILE.newRange(1, 2, 1, 5), "foo")
.addToken(INPUT_FILE.newRange(1, 6, 1, 10), "bar")
@Test
public void basic_validation() {
SensorStorage sensorStorage = mock(SensorStorage.class);
- DefaultCpdTokens tokens = new DefaultCpdTokens(new MapSettings(), sensorStorage);
+ DefaultCpdTokens tokens = new DefaultCpdTokens(new MapSettings().asConfig(), sensorStorage);
try {
tokens.save();
fail("Expected exception");
@Test
public void validate_tokens_order() {
SensorStorage sensorStorage = mock(SensorStorage.class);
- DefaultCpdTokens tokens = new DefaultCpdTokens(new MapSettings(), sensorStorage)
+ DefaultCpdTokens tokens = new DefaultCpdTokens(new MapSettings().asConfig(), sensorStorage)
.onFile(INPUT_FILE)
.addToken(INPUT_FILE.newRange(1, 6, 1, 10), "bar");
import org.sonar.api.batch.sensor.highlighting.TypeOfText;
import org.sonar.api.batch.sensor.issue.NewIssue;
import org.sonar.api.batch.sensor.symbol.NewSymbolTable;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.SonarException;
import org.junit.Test;
import org.sonar.api.CoreProperties;
+import org.sonar.api.config.internal.MapSettings;
import static org.assertj.core.api.Assertions.assertThat;
+++ /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.api.config;
-
-import java.util.Date;
-import org.assertj.core.data.Offset;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.Properties;
-import org.sonar.api.Property;
-import org.sonar.api.PropertyType;
-import org.sonar.api.utils.DateUtils;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class MapSettingsTest {
-
- private PropertyDefinitions definitions;
-
- @Properties({
- @Property(key = "hello", name = "Hello", defaultValue = "world"),
- @Property(key = "date", name = "Date", defaultValue = "2010-05-18"),
- @Property(key = "datetime", name = "DateTime", defaultValue = "2010-05-18T15:50:45+0100"),
- @Property(key = "boolean", name = "Boolean", defaultValue = "true"),
- @Property(key = "falseboolean", name = "False Boolean", defaultValue = "false"),
- @Property(key = "integer", name = "Integer", defaultValue = "12345"),
- @Property(key = "array", name = "Array", defaultValue = "one,two,three"),
- @Property(key = "multi_values", name = "Array", defaultValue = "1,2,3", multiValues = true),
- @Property(key = "sonar.jira", name = "Jira Server", type = PropertyType.PROPERTY_SET, propertySetKey = "jira"),
- @Property(key = "newKey", name = "New key", deprecatedKey = "oldKey"),
- @Property(key = "newKeyWithDefaultValue", name = "New key with default value", deprecatedKey = "oldKeyWithDefaultValue", defaultValue = "default_value"),
- @Property(key = "new_multi_values", name = "New multi values", defaultValue = "1,2,3", multiValues = true, deprecatedKey = "old_multi_values")
- })
- private static class Init {
- }
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @Before
- public void init_definitions() {
- definitions = new PropertyDefinitions();
- definitions.addComponent(Init.class);
- }
-
- @Test
- public void default_values_should_be_loaded_from_definitions() {
- Settings settings = new MapSettings(definitions);
- assertThat(settings.getDefaultValue("hello")).isEqualTo("world");
- }
-
- @Test
- public void set_property_int() {
- Settings settings = new MapSettings();
- settings.setProperty("foo", 123);
- assertThat(settings.getInt("foo")).isEqualTo(123);
- assertThat(settings.getString("foo")).isEqualTo("123");
- assertThat(settings.getBoolean("foo")).isFalse();
- }
-
- @Test
- public void default_number_values_are_zero() {
- Settings settings = new MapSettings();
- assertThat(settings.getInt("foo")).isEqualTo(0);
- assertThat(settings.getLong("foo")).isEqualTo(0L);
- }
-
- @Test
- public void getInt_value_must_be_valid() {
- thrown.expect(NumberFormatException.class);
-
- Settings settings = new MapSettings();
- settings.setProperty("foo", "not a number");
- settings.getInt("foo");
- }
-
- @Test
- public void all_values_should_be_trimmed_set_property() {
- Settings settings = new MapSettings();
- settings.setProperty("foo", " FOO ");
- assertThat(settings.getString("foo")).isEqualTo("FOO");
- }
-
- @Test
- public void test_get_default_value() {
- Settings settings = new MapSettings(definitions);
- assertThat(settings.getDefaultValue("unknown")).isNull();
- }
-
- @Test
- public void test_get_string() {
- Settings settings = new MapSettings(definitions);
- settings.setProperty("hello", "Russia");
- assertThat(settings.getString("hello")).isEqualTo("Russia");
- }
-
- @Test
- public void setProperty_date() {
- Settings settings = new MapSettings();
- Date date = DateUtils.parseDateTime("2010-05-18T15:50:45+0100");
- settings.setProperty("aDate", date);
- settings.setProperty("aDateTime", date, true);
-
- assertThat(settings.getString("aDate")).isEqualTo("2010-05-18");
- assertThat(settings.getString("aDateTime")).startsWith("2010-05-18T");
- }
-
- @Test
- public void test_get_date() {
- Settings settings = new MapSettings(definitions);
- assertThat(settings.getDate("unknown")).isNull();
- assertThat(settings.getDate("date").getDate()).isEqualTo(18);
- assertThat(settings.getDate("date").getMonth()).isEqualTo(4);
- }
-
- @Test
- public void test_get_date_not_found() {
- Settings settings = new MapSettings(definitions);
- assertThat(settings.getDate("unknown")).isNull();
- }
-
- @Test
- public void test_get_datetime() {
- Settings settings = new MapSettings(definitions);
- assertThat(settings.getDateTime("unknown")).isNull();
- assertThat(settings.getDateTime("datetime").getDate()).isEqualTo(18);
- assertThat(settings.getDateTime("datetime").getMonth()).isEqualTo(4);
- assertThat(settings.getDateTime("datetime").getMinutes()).isEqualTo(50);
- }
-
- @Test
- public void test_get_double() {
- Settings settings = new MapSettings();
- settings.setProperty("from_double", 3.14159);
- settings.setProperty("from_string", "3.14159");
- assertThat(settings.getDouble("from_double")).isEqualTo(3.14159, Offset.offset(0.00001));
- assertThat(settings.getDouble("from_string")).isEqualTo(3.14159, Offset.offset(0.00001));
- assertThat(settings.getDouble("unknown")).isNull();
- }
-
- @Test
- public void test_get_float() {
- Settings settings = new MapSettings();
- settings.setProperty("from_float", 3.14159f);
- settings.setProperty("from_string", "3.14159");
- assertThat(settings.getDouble("from_float")).isEqualTo(3.14159f, Offset.offset(0.00001));
- assertThat(settings.getDouble("from_string")).isEqualTo(3.14159f, Offset.offset(0.00001));
- assertThat(settings.getDouble("unknown")).isNull();
- }
-
- @Test
- public void test_get_bad_float() {
- Settings settings = new MapSettings();
- settings.setProperty("foo", "bar");
-
- thrown.expect(IllegalStateException.class);
- thrown.expectMessage("The property 'foo' is not a float value");
- settings.getFloat("foo");
- }
-
- @Test
- public void test_get_bad_double() {
- Settings settings = new MapSettings();
- settings.setProperty("foo", "bar");
-
- thrown.expect(IllegalStateException.class);
- thrown.expectMessage("The property 'foo' is not a double value");
- settings.getDouble("foo");
- }
-
- @Test
- public void testSetNullFloat() {
- Settings settings = new MapSettings();
- settings.setProperty("foo", (Float) null);
- assertThat(settings.getFloat("foo")).isNull();
- }
-
- @Test
- public void testSetNullDouble() {
- Settings settings = new MapSettings();
- settings.setProperty("foo", (Double) null);
- assertThat(settings.getDouble("foo")).isNull();
- }
-
- @Test
- public void getStringArray() {
- Settings settings = new MapSettings(definitions);
- String[] array = settings.getStringArray("array");
- assertThat(array).isEqualTo(new String[] {"one", "two", "three"});
- }
-
- @Test
- public void setStringArray() {
- Settings settings = new MapSettings(definitions);
- settings.setProperty("multi_values", new String[] {"A", "B"});
- String[] array = settings.getStringArray("multi_values");
- assertThat(array).isEqualTo(new String[] {"A", "B"});
- }
-
- @Test
- public void setStringArrayTrimValues() {
- Settings settings = new MapSettings(definitions);
- settings.setProperty("multi_values", new String[] {" A ", " B "});
- String[] array = settings.getStringArray("multi_values");
- assertThat(array).isEqualTo(new String[] {"A", "B"});
- }
-
- @Test
- public void setStringArrayEscapeCommas() {
- Settings settings = new MapSettings(definitions);
- settings.setProperty("multi_values", new String[] {"A,B", "C,D"});
- String[] array = settings.getStringArray("multi_values");
- assertThat(array).isEqualTo(new String[] {"A,B", "C,D"});
- }
-
- @Test
- public void setStringArrayWithEmptyValues() {
- Settings settings = new MapSettings(definitions);
- settings.setProperty("multi_values", new String[] {"A,B", "", "C,D"});
- String[] array = settings.getStringArray("multi_values");
- assertThat(array).isEqualTo(new String[] {"A,B", "", "C,D"});
- }
-
- @Test
- public void setStringArrayWithNullValues() {
- Settings settings = new MapSettings(definitions);
- settings.setProperty("multi_values", new String[] {"A,B", null, "C,D"});
- String[] array = settings.getStringArray("multi_values");
- assertThat(array).isEqualTo(new String[] {"A,B", "", "C,D"});
- }
-
- @Test(expected = IllegalStateException.class)
- public void shouldFailToSetArrayValueOnSingleValueProperty() {
- Settings settings = new MapSettings(definitions);
- settings.setProperty("array", new String[] {"A", "B", "C"});
- }
-
- @Test
- public void getStringArray_no_value() {
- Settings settings = new MapSettings();
- String[] array = settings.getStringArray("array");
- assertThat(array).isEmpty();
- }
-
- @Test
- public void shouldTrimArray() {
- Settings settings = new MapSettings();
- settings.setProperty("foo", " one, two, three ");
- String[] array = settings.getStringArray("foo");
- assertThat(array).isEqualTo(new String[] {"one", "two", "three"});
- }
-
- @Test
- public void shouldKeepEmptyValuesWhenSplitting() {
- Settings settings = new MapSettings();
- settings.setProperty("foo", " one, , two");
- String[] array = settings.getStringArray("foo");
- assertThat(array).isEqualTo(new String[] {"one", "", "two"});
- }
-
- @Test
- public void testDefaultValueOfGetString() {
- Settings settings = new MapSettings(definitions);
- assertThat(settings.getString("hello")).isEqualTo("world");
- }
-
- @Test
- public void set_property_boolean() {
- Settings settings = new MapSettings();
- settings.setProperty("foo", true);
- settings.setProperty("bar", false);
- assertThat(settings.getBoolean("foo")).isTrue();
- assertThat(settings.getBoolean("bar")).isFalse();
- assertThat(settings.getString("foo")).isEqualTo("true");
- assertThat(settings.getString("bar")).isEqualTo("false");
- }
-
- @Test
- public void ignore_case_of_boolean_values() {
- Settings settings = new MapSettings();
- settings.setProperty("foo", "true");
- settings.setProperty("bar", "TRUE");
- // labels in UI
- settings.setProperty("baz", "True");
-
- assertThat(settings.getBoolean("foo")).isTrue();
- assertThat(settings.getBoolean("bar")).isTrue();
- assertThat(settings.getBoolean("baz")).isTrue();
- }
-
- @Test
- public void get_boolean() {
- Settings settings = new MapSettings(definitions);
- assertThat(settings.getBoolean("boolean")).isTrue();
- assertThat(settings.getBoolean("falseboolean")).isFalse();
- assertThat(settings.getBoolean("unknown")).isFalse();
- assertThat(settings.getBoolean("hello")).isFalse();
- }
-
- @Test
- public void shouldCreateByIntrospectingComponent() {
- Settings settings = new MapSettings();
- settings.getDefinitions().addComponent(MyComponent.class);
-
- // property definition has been loaded, ie for default value
- assertThat(settings.getDefaultValue("foo")).isEqualTo("bar");
- }
-
- @Property(key = "foo", name = "Foo", defaultValue = "bar")
- public static class MyComponent {
-
- }
-
- @Test
- public void getStringLines_no_value() {
- assertThat(new MapSettings().getStringLines("foo")).hasSize(0);
- }
-
- @Test
- public void getStringLines_single_line() {
- Settings settings = new MapSettings();
- settings.setProperty("foo", "the line");
- assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"the line"});
- }
-
- @Test
- public void getStringLines_linux() {
- Settings settings = new MapSettings();
- settings.setProperty("foo", "one\ntwo");
- assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two"});
-
- settings.setProperty("foo", "one\ntwo\n");
- assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two"});
- }
-
- @Test
- public void getStringLines_windows() {
- Settings settings = new MapSettings();
- settings.setProperty("foo", "one\r\ntwo");
- assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two"});
-
- settings.setProperty("foo", "one\r\ntwo\r\n");
- assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two"});
- }
-
- @Test
- public void getStringLines_mix() {
- Settings settings = new MapSettings();
- settings.setProperty("foo", "one\r\ntwo\nthree");
- assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two", "three"});
- }
-
- @Test
- public void getKeysStartingWith() {
- Settings settings = new MapSettings();
- settings.setProperty("sonar.jdbc.url", "foo");
- settings.setProperty("sonar.jdbc.username", "bar");
- settings.setProperty("sonar.security", "admin");
-
- assertThat(settings.getKeysStartingWith("sonar")).containsOnly("sonar.jdbc.url", "sonar.jdbc.username", "sonar.security");
- assertThat(settings.getKeysStartingWith("sonar.jdbc")).containsOnly("sonar.jdbc.url", "sonar.jdbc.username");
- assertThat(settings.getKeysStartingWith("other")).hasSize(0);
- }
-
- @Test
- public void should_fallback_deprecated_key_to_default_value_of_new_key() {
- Settings settings = new MapSettings(definitions);
-
- assertThat(settings.getString("newKeyWithDefaultValue")).isEqualTo("default_value");
- assertThat(settings.getString("oldKeyWithDefaultValue")).isEqualTo("default_value");
- }
-
- @Test
- public void should_fallback_deprecated_key_to_new_key() {
- Settings settings = new MapSettings(definitions);
- settings.setProperty("newKey", "value of newKey");
-
- assertThat(settings.getString("newKey")).isEqualTo("value of newKey");
- assertThat(settings.getString("oldKey")).isEqualTo("value of newKey");
- }
-
- @Test
- public void should_load_value_of_deprecated_key() {
- // it's used for example when deprecated settings are set through command-line
- Settings settings = new MapSettings(definitions);
- settings.setProperty("oldKey", "value of oldKey");
-
- assertThat(settings.getString("newKey")).isEqualTo("value of oldKey");
- assertThat(settings.getString("oldKey")).isEqualTo("value of oldKey");
- }
-
- @Test
- public void should_load_values_of_deprecated_key() {
- Settings settings = new MapSettings(definitions);
- settings.setProperty("oldKey", "a,b");
-
- assertThat(settings.getStringArray("newKey")).containsOnly("a", "b");
- assertThat(settings.getStringArray("oldKey")).containsOnly("a", "b");
- }
-
- @Test
- public void should_support_deprecated_props_with_multi_values() {
- Settings settings = new MapSettings(definitions);
- settings.setProperty("new_multi_values", new String[] {" A ", " B "});
- assertThat(settings.getStringArray("new_multi_values")).isEqualTo(new String[] {"A", "B"});
- assertThat(settings.getStringArray("old_multi_values")).isEqualTo(new String[] {"A", "B"});
- }
-}
--- /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.api.config.internal;
+
+import java.util.Date;
+import org.assertj.core.data.Offset;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.Properties;
+import org.sonar.api.Property;
+import org.sonar.api.PropertyType;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
+import org.sonar.api.utils.DateUtils;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class MapSettingsTest {
+
+ private PropertyDefinitions definitions;
+
+ @Properties({
+ @Property(key = "hello", name = "Hello", defaultValue = "world"),
+ @Property(key = "date", name = "Date", defaultValue = "2010-05-18"),
+ @Property(key = "datetime", name = "DateTime", defaultValue = "2010-05-18T15:50:45+0100"),
+ @Property(key = "boolean", name = "Boolean", defaultValue = "true"),
+ @Property(key = "falseboolean", name = "False Boolean", defaultValue = "false"),
+ @Property(key = "integer", name = "Integer", defaultValue = "12345"),
+ @Property(key = "array", name = "Array", defaultValue = "one,two,three"),
+ @Property(key = "multi_values", name = "Array", defaultValue = "1,2,3", multiValues = true),
+ @Property(key = "sonar.jira", name = "Jira Server", type = PropertyType.PROPERTY_SET, propertySetKey = "jira"),
+ @Property(key = "newKey", name = "New key", deprecatedKey = "oldKey"),
+ @Property(key = "newKeyWithDefaultValue", name = "New key with default value", deprecatedKey = "oldKeyWithDefaultValue", defaultValue = "default_value"),
+ @Property(key = "new_multi_values", name = "New multi values", defaultValue = "1,2,3", multiValues = true, deprecatedKey = "old_multi_values")
+ })
+ private static class Init {
+ }
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Before
+ public void init_definitions() {
+ definitions = new PropertyDefinitions();
+ definitions.addComponent(Init.class);
+ }
+
+ @Test
+ public void default_values_should_be_loaded_from_definitions() {
+ Settings settings = new MapSettings(definitions);
+ assertThat(settings.getDefaultValue("hello")).isEqualTo("world");
+ }
+
+ @Test
+ public void set_property_int() {
+ Settings settings = new MapSettings();
+ settings.setProperty("foo", 123);
+ assertThat(settings.getInt("foo")).isEqualTo(123);
+ assertThat(settings.getString("foo")).isEqualTo("123");
+ assertThat(settings.getBoolean("foo")).isFalse();
+ }
+
+ @Test
+ public void default_number_values_are_zero() {
+ Settings settings = new MapSettings();
+ assertThat(settings.getInt("foo")).isEqualTo(0);
+ assertThat(settings.getLong("foo")).isEqualTo(0L);
+ }
+
+ @Test
+ public void getInt_value_must_be_valid() {
+ thrown.expect(NumberFormatException.class);
+
+ Settings settings = new MapSettings();
+ settings.setProperty("foo", "not a number");
+ settings.getInt("foo");
+ }
+
+ @Test
+ public void all_values_should_be_trimmed_set_property() {
+ Settings settings = new MapSettings();
+ settings.setProperty("foo", " FOO ");
+ assertThat(settings.getString("foo")).isEqualTo("FOO");
+ }
+
+ @Test
+ public void test_get_default_value() {
+ Settings settings = new MapSettings(definitions);
+ assertThat(settings.getDefaultValue("unknown")).isNull();
+ }
+
+ @Test
+ public void test_get_string() {
+ Settings settings = new MapSettings(definitions);
+ settings.setProperty("hello", "Russia");
+ assertThat(settings.getString("hello")).isEqualTo("Russia");
+ }
+
+ @Test
+ public void setProperty_date() {
+ Settings settings = new MapSettings();
+ Date date = DateUtils.parseDateTime("2010-05-18T15:50:45+0100");
+ settings.setProperty("aDate", date);
+ settings.setProperty("aDateTime", date, true);
+
+ assertThat(settings.getString("aDate")).isEqualTo("2010-05-18");
+ assertThat(settings.getString("aDateTime")).startsWith("2010-05-18T");
+ }
+
+ @Test
+ public void test_get_date() {
+ Settings settings = new MapSettings(definitions);
+ assertThat(settings.getDate("unknown")).isNull();
+ assertThat(settings.getDate("date").getDate()).isEqualTo(18);
+ assertThat(settings.getDate("date").getMonth()).isEqualTo(4);
+ }
+
+ @Test
+ public void test_get_date_not_found() {
+ Settings settings = new MapSettings(definitions);
+ assertThat(settings.getDate("unknown")).isNull();
+ }
+
+ @Test
+ public void test_get_datetime() {
+ Settings settings = new MapSettings(definitions);
+ assertThat(settings.getDateTime("unknown")).isNull();
+ assertThat(settings.getDateTime("datetime").getDate()).isEqualTo(18);
+ assertThat(settings.getDateTime("datetime").getMonth()).isEqualTo(4);
+ assertThat(settings.getDateTime("datetime").getMinutes()).isEqualTo(50);
+ }
+
+ @Test
+ public void test_get_double() {
+ Settings settings = new MapSettings();
+ settings.setProperty("from_double", 3.14159);
+ settings.setProperty("from_string", "3.14159");
+ assertThat(settings.getDouble("from_double")).isEqualTo(3.14159, Offset.offset(0.00001));
+ assertThat(settings.getDouble("from_string")).isEqualTo(3.14159, Offset.offset(0.00001));
+ assertThat(settings.getDouble("unknown")).isNull();
+ }
+
+ @Test
+ public void test_get_float() {
+ Settings settings = new MapSettings();
+ settings.setProperty("from_float", 3.14159f);
+ settings.setProperty("from_string", "3.14159");
+ assertThat(settings.getDouble("from_float")).isEqualTo(3.14159f, Offset.offset(0.00001));
+ assertThat(settings.getDouble("from_string")).isEqualTo(3.14159f, Offset.offset(0.00001));
+ assertThat(settings.getDouble("unknown")).isNull();
+ }
+
+ @Test
+ public void test_get_bad_float() {
+ Settings settings = new MapSettings();
+ settings.setProperty("foo", "bar");
+
+ thrown.expect(IllegalStateException.class);
+ thrown.expectMessage("The property 'foo' is not a float value");
+ settings.getFloat("foo");
+ }
+
+ @Test
+ public void test_get_bad_double() {
+ Settings settings = new MapSettings();
+ settings.setProperty("foo", "bar");
+
+ thrown.expect(IllegalStateException.class);
+ thrown.expectMessage("The property 'foo' is not a double value");
+ settings.getDouble("foo");
+ }
+
+ @Test
+ public void testSetNullFloat() {
+ Settings settings = new MapSettings();
+ settings.setProperty("foo", (Float) null);
+ assertThat(settings.getFloat("foo")).isNull();
+ }
+
+ @Test
+ public void testSetNullDouble() {
+ Settings settings = new MapSettings();
+ settings.setProperty("foo", (Double) null);
+ assertThat(settings.getDouble("foo")).isNull();
+ }
+
+ @Test
+ public void getStringArray() {
+ Settings settings = new MapSettings(definitions);
+ String[] array = settings.getStringArray("array");
+ assertThat(array).isEqualTo(new String[] {"one", "two", "three"});
+ }
+
+ @Test
+ public void setStringArray() {
+ Settings settings = new MapSettings(definitions);
+ settings.setProperty("multi_values", new String[] {"A", "B"});
+ String[] array = settings.getStringArray("multi_values");
+ assertThat(array).isEqualTo(new String[] {"A", "B"});
+ }
+
+ @Test
+ public void setStringArrayTrimValues() {
+ Settings settings = new MapSettings(definitions);
+ settings.setProperty("multi_values", new String[] {" A ", " B "});
+ String[] array = settings.getStringArray("multi_values");
+ assertThat(array).isEqualTo(new String[] {"A", "B"});
+ }
+
+ @Test
+ public void setStringArrayEscapeCommas() {
+ Settings settings = new MapSettings(definitions);
+ settings.setProperty("multi_values", new String[] {"A,B", "C,D"});
+ String[] array = settings.getStringArray("multi_values");
+ assertThat(array).isEqualTo(new String[] {"A,B", "C,D"});
+ }
+
+ @Test
+ public void setStringArrayWithEmptyValues() {
+ Settings settings = new MapSettings(definitions);
+ settings.setProperty("multi_values", new String[] {"A,B", "", "C,D"});
+ String[] array = settings.getStringArray("multi_values");
+ assertThat(array).isEqualTo(new String[] {"A,B", "", "C,D"});
+ }
+
+ @Test
+ public void setStringArrayWithNullValues() {
+ Settings settings = new MapSettings(definitions);
+ settings.setProperty("multi_values", new String[] {"A,B", null, "C,D"});
+ String[] array = settings.getStringArray("multi_values");
+ assertThat(array).isEqualTo(new String[] {"A,B", "", "C,D"});
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void shouldFailToSetArrayValueOnSingleValueProperty() {
+ Settings settings = new MapSettings(definitions);
+ settings.setProperty("array", new String[] {"A", "B", "C"});
+ }
+
+ @Test
+ public void getStringArray_no_value() {
+ Settings settings = new MapSettings();
+ String[] array = settings.getStringArray("array");
+ assertThat(array).isEmpty();
+ }
+
+ @Test
+ public void shouldTrimArray() {
+ Settings settings = new MapSettings();
+ settings.setProperty("foo", " one, two, three ");
+ String[] array = settings.getStringArray("foo");
+ assertThat(array).isEqualTo(new String[] {"one", "two", "three"});
+ }
+
+ @Test
+ public void shouldKeepEmptyValuesWhenSplitting() {
+ Settings settings = new MapSettings();
+ settings.setProperty("foo", " one, , two");
+ String[] array = settings.getStringArray("foo");
+ assertThat(array).isEqualTo(new String[] {"one", "", "two"});
+ }
+
+ @Test
+ public void testDefaultValueOfGetString() {
+ Settings settings = new MapSettings(definitions);
+ assertThat(settings.getString("hello")).isEqualTo("world");
+ }
+
+ @Test
+ public void set_property_boolean() {
+ Settings settings = new MapSettings();
+ settings.setProperty("foo", true);
+ settings.setProperty("bar", false);
+ assertThat(settings.getBoolean("foo")).isTrue();
+ assertThat(settings.getBoolean("bar")).isFalse();
+ assertThat(settings.getString("foo")).isEqualTo("true");
+ assertThat(settings.getString("bar")).isEqualTo("false");
+ }
+
+ @Test
+ public void ignore_case_of_boolean_values() {
+ Settings settings = new MapSettings();
+ settings.setProperty("foo", "true");
+ settings.setProperty("bar", "TRUE");
+ // labels in UI
+ settings.setProperty("baz", "True");
+
+ assertThat(settings.getBoolean("foo")).isTrue();
+ assertThat(settings.getBoolean("bar")).isTrue();
+ assertThat(settings.getBoolean("baz")).isTrue();
+ }
+
+ @Test
+ public void get_boolean() {
+ Settings settings = new MapSettings(definitions);
+ assertThat(settings.getBoolean("boolean")).isTrue();
+ assertThat(settings.getBoolean("falseboolean")).isFalse();
+ assertThat(settings.getBoolean("unknown")).isFalse();
+ assertThat(settings.getBoolean("hello")).isFalse();
+ }
+
+ @Test
+ public void shouldCreateByIntrospectingComponent() {
+ Settings settings = new MapSettings();
+ settings.getDefinitions().addComponent(MyComponent.class);
+
+ // property definition has been loaded, ie for default value
+ assertThat(settings.getDefaultValue("foo")).isEqualTo("bar");
+ }
+
+ @Property(key = "foo", name = "Foo", defaultValue = "bar")
+ public static class MyComponent {
+
+ }
+
+ @Test
+ public void getStringLines_no_value() {
+ assertThat(new MapSettings().getStringLines("foo")).hasSize(0);
+ }
+
+ @Test
+ public void getStringLines_single_line() {
+ Settings settings = new MapSettings();
+ settings.setProperty("foo", "the line");
+ assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"the line"});
+ }
+
+ @Test
+ public void getStringLines_linux() {
+ Settings settings = new MapSettings();
+ settings.setProperty("foo", "one\ntwo");
+ assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two"});
+
+ settings.setProperty("foo", "one\ntwo\n");
+ assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two"});
+ }
+
+ @Test
+ public void getStringLines_windows() {
+ Settings settings = new MapSettings();
+ settings.setProperty("foo", "one\r\ntwo");
+ assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two"});
+
+ settings.setProperty("foo", "one\r\ntwo\r\n");
+ assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two"});
+ }
+
+ @Test
+ public void getStringLines_mix() {
+ Settings settings = new MapSettings();
+ settings.setProperty("foo", "one\r\ntwo\nthree");
+ assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two", "three"});
+ }
+
+ @Test
+ public void getKeysStartingWith() {
+ Settings settings = new MapSettings();
+ settings.setProperty("sonar.jdbc.url", "foo");
+ settings.setProperty("sonar.jdbc.username", "bar");
+ settings.setProperty("sonar.security", "admin");
+
+ assertThat(settings.getKeysStartingWith("sonar")).containsOnly("sonar.jdbc.url", "sonar.jdbc.username", "sonar.security");
+ assertThat(settings.getKeysStartingWith("sonar.jdbc")).containsOnly("sonar.jdbc.url", "sonar.jdbc.username");
+ assertThat(settings.getKeysStartingWith("other")).hasSize(0);
+ }
+
+ @Test
+ public void should_fallback_deprecated_key_to_default_value_of_new_key() {
+ Settings settings = new MapSettings(definitions);
+
+ assertThat(settings.getString("newKeyWithDefaultValue")).isEqualTo("default_value");
+ assertThat(settings.getString("oldKeyWithDefaultValue")).isEqualTo("default_value");
+ }
+
+ @Test
+ public void should_fallback_deprecated_key_to_new_key() {
+ Settings settings = new MapSettings(definitions);
+ settings.setProperty("newKey", "value of newKey");
+
+ assertThat(settings.getString("newKey")).isEqualTo("value of newKey");
+ assertThat(settings.getString("oldKey")).isEqualTo("value of newKey");
+ }
+
+ @Test
+ public void should_load_value_of_deprecated_key() {
+ // it's used for example when deprecated settings are set through command-line
+ Settings settings = new MapSettings(definitions);
+ settings.setProperty("oldKey", "value of oldKey");
+
+ assertThat(settings.getString("newKey")).isEqualTo("value of oldKey");
+ assertThat(settings.getString("oldKey")).isEqualTo("value of oldKey");
+ }
+
+ @Test
+ public void should_load_values_of_deprecated_key() {
+ Settings settings = new MapSettings(definitions);
+ settings.setProperty("oldKey", "a,b");
+
+ assertThat(settings.getStringArray("newKey")).containsOnly("a", "b");
+ assertThat(settings.getStringArray("oldKey")).containsOnly("a", "b");
+ }
+
+ @Test
+ public void should_support_deprecated_props_with_multi_values() {
+ Settings settings = new MapSettings(definitions);
+ settings.setProperty("new_multi_values", new String[] {" A ", " B "});
+ assertThat(settings.getStringArray("new_multi_values")).isEqualTo(new String[] {"A", "B"});
+ assertThat(settings.getStringArray("old_multi_values")).isEqualTo(new String[] {"A", "B"});
+ }
+}
import org.junit.Test;
import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import static org.assertj.core.api.Assertions.assertThat;
public class FileExclusionsTest {
@Test
public void ignore_inclusion_of_world() {
- Settings settings = new MapSettings();
+ MapSettings settings = new MapSettings();
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*");
settings.setProperty(CoreProperties.PROJECT_TEST_INCLUSIONS_PROPERTY, "**/*");
- assertThat(new FileExclusions(settings).sourceInclusions()).isEmpty();
- assertThat(new FileExclusions(settings).testInclusions()).isEmpty();
+ assertThat(new FileExclusions(settings.asConfig()).sourceInclusions()).isEmpty();
+ assertThat(new FileExclusions(settings.asConfig()).testInclusions()).isEmpty();
}
@Test
public void load_inclusions() {
- Settings settings = new MapSettings();
+ MapSettings settings = new MapSettings();
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Foo.java");
settings.setProperty(CoreProperties.PROJECT_TEST_INCLUSIONS_PROPERTY, "**/*FooTest.java");
- FileExclusions moduleExclusions = new FileExclusions(settings);
+ FileExclusions moduleExclusions = new FileExclusions(settings.asConfig());
assertThat(moduleExclusions.sourceInclusions()).containsOnly("**/*Foo.java");
assertThat(moduleExclusions.testInclusions()).containsOnly("**/*FooTest.java");
@Test
public void load_exclusions() {
- Settings settings = new MapSettings();
+ MapSettings settings = new MapSettings();
settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*Foo.java");
settings.setProperty(CoreProperties.PROJECT_TEST_EXCLUSIONS_PROPERTY, "**/*FooTest.java");
- FileExclusions moduleExclusions = new FileExclusions(settings);
+ FileExclusions moduleExclusions = new FileExclusions(settings.asConfig());
assertThat(moduleExclusions.sourceInclusions()).isEmpty();
assertThat(moduleExclusions.sourceExclusions()).containsOnly("**/*Foo.java");
package org.sonar.batch.bootstrapper;
import com.google.common.base.Throwables;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
package org.sonar.batch.bootstrapper;
import com.google.common.annotations.VisibleForTesting;
-
import java.util.HashMap;
import java.util.Map;
import javax.annotation.CheckForNull;
package org.sonar.scanner;
import java.util.Date;
+import java.util.Optional;
import org.picocontainer.Startable;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.ScannerSide;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
+import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.SonarException;
import org.sonar.api.utils.System2;
@ScannerSide
public class ProjectAnalysisInfo implements Startable {
private final System2 system2;
- private Settings settings;
+ private Configuration settings;
private Date analysisDate;
private String analysisVersion;
- public ProjectAnalysisInfo(Settings settings, System2 system2) {
+ public ProjectAnalysisInfo(Configuration settings, System2 system2) {
this.settings = settings;
this.system2 = system2;
}
}
private Date loadAnalysisDate() {
+ Optional<String> value = settings.get(CoreProperties.PROJECT_DATE_PROPERTY);
+ if (!value.isPresent()) {
+ return new Date(system2.now());
+ }
Date date;
try {
// sonar.projectDate may have been specified as a time
- date = settings.getDateTime(CoreProperties.PROJECT_DATE_PROPERTY);
+ return DateUtils.parseDateTime(value.get());
} catch (SonarException e) {
// this is probably just a date
- date = settings.getDate(CoreProperties.PROJECT_DATE_PROPERTY);
- }
- if (date == null) {
- date = new Date(system2.now());
- settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, date, true);
+ return DateUtils.parseDate(value.get());
}
- return date;
}
private String loadAnalysisVersion() {
- return settings.getString(CoreProperties.PROJECT_VERSION_PROPERTY);
+ return settings.get(CoreProperties.PROJECT_VERSION_PROPERTY).orElse(null);
}
@Override
*/
package org.sonar.scanner.analysis;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.picocontainer.PicoContainer;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
import org.picocontainer.ComponentLifecycle;
+import org.picocontainer.PicoContainer;
import org.picocontainer.injectors.ProviderAdapter;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.utils.TempFolder;
import org.sonar.api.utils.internal.DefaultTempFolder;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-
public class AnalysisTempFolderProvider extends ProviderAdapter implements ComponentLifecycle<TempFolder> {
static final String TMP_NAME = ".sonartmp";
private DefaultTempFolder projectTempFolder;
package org.sonar.scanner.bootstrap;
import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.home.cache.FileCache;
import org.sonar.home.cache.FileCacheBuilder;
public class FileCacheProvider extends ProviderAdapter {
private FileCache cache;
- public FileCache provide(Settings settings) {
+ public FileCache provide(Configuration settings) {
if (cache == null) {
- String home = settings.getString("sonar.userHome");
+ String home = settings.get("sonar.userHome").orElse(null);
cache = new FileCacheBuilder(new Slf4jLogger()).setUserHome(home).build();
}
return cache;
--- /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.bootstrap;
+
+import com.google.common.collect.ImmutableMap;
+import java.util.Collections;
+import java.util.Map;
+import javax.annotation.concurrent.Immutable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.batch.AnalysisMode;
+import org.sonar.api.config.Encryption;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.scanner.config.DefaultConfiguration;
+
+@Immutable
+public class GlobalConfiguration extends DefaultConfiguration {
+
+ private static final Logger LOG = LoggerFactory.getLogger(GlobalConfiguration.class);
+
+ private static final String JDBC_SPECIFIC_MESSAGE = "It will be ignored. There is no longer any DB connection to the SQ database.";
+ /**
+ * A map of dropped properties as key and specific message to display for that property
+ * (what will happen, what should the user do, ...) as a value
+ */
+ private static final Map<String, String> DROPPED_PROPERTIES = ImmutableMap.of(
+ "sonar.jdbc.url", JDBC_SPECIFIC_MESSAGE,
+ "sonar.jdbc.username", JDBC_SPECIFIC_MESSAGE,
+ "sonar.jdbc.password", JDBC_SPECIFIC_MESSAGE);
+
+ private final Map<String, String> serverSideSettings;
+
+ public GlobalConfiguration(PropertyDefinitions propertyDefinitions, Encryption encryption, AnalysisMode mode,
+ Map<String, String> settings, Map<String, String> serverSideSettings) {
+ super(propertyDefinitions, encryption, mode, settings);
+ this.serverSideSettings = serverSideSettings;
+
+ get(CoreProperties.PERMANENT_SERVER_ID).ifPresent(v -> LOG.info("Server id: {}", v));
+ new DroppedPropertyChecker(getProperties(), DROPPED_PROPERTIES).checkDroppedProperties();
+ }
+
+ public Map<String, String> getServerSideSettings() {
+ return Collections.unmodifiableMap(serverSideSettings);
+ }
+
+}
--- /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.bootstrap;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.picocontainer.injectors.ProviderAdapter;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.scanner.repository.settings.SettingsLoader;
+
+public class GlobalConfigurationProvider extends ProviderAdapter {
+
+ private GlobalConfiguration globalSettings;
+
+ public GlobalConfiguration provide(SettingsLoader loader, GlobalProperties globalProps, PropertyDefinitions propertyDefinitions, GlobalMode mode) {
+ if (globalSettings == null) {
+
+ Map<String, String> serverSideSettings = loader.load(null);
+
+ Map<String, String> settings = new LinkedHashMap<>();
+ settings.putAll(serverSideSettings);
+ settings.putAll(globalProps.properties());
+
+ globalSettings = new GlobalConfiguration(propertyDefinitions, globalProps.getEncryption(), mode, settings, serverSideSettings);
+ }
+ return globalSettings;
+ }
+}
new SonarQubeVersion(apiVersion),
SonarRuntimeImpl.forSonarQube(apiVersion, SonarQubeSide.SCANNER),
StoragesManager.class,
- GlobalSettings.class,
+ MutableGlobalSettings.class,
+ new GlobalConfigurationProvider(),
new ScannerWsClientProvider(),
DefaultServer.class,
new GlobalTempFolderProvider(),
*/
package org.sonar.scanner.bootstrap;
-import org.sonar.api.CoreProperties;
-
import java.util.Map;
+import org.sonar.api.CoreProperties;
/**
* Immutable batch properties that are not specific to a task (for example
+++ /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.bootstrap;
-
-import com.google.common.collect.ImmutableMap;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Encryption;
-import org.sonar.api.config.PropertyDefinitions;
-import org.sonar.api.config.Settings;
-import org.sonar.api.utils.MessageException;
-import org.sonar.scanner.repository.settings.SettingsLoader;
-
-public class GlobalSettings extends Settings {
-
- private static final Logger LOG = LoggerFactory.getLogger(GlobalSettings.class);
-
- private static final String JDBC_SPECIFIC_MESSAGE = "It will be ignored. There is no longer any DB connection to the SQ database.";
- /**
- * A map of dropped properties as key and specific message to display for that property
- * (what will happen, what should the user do, ...) as a value
- */
- private static final Map<String, String> DROPPED_PROPERTIES = ImmutableMap.of(
- "sonar.jdbc.url", JDBC_SPECIFIC_MESSAGE,
- "sonar.jdbc.username", JDBC_SPECIFIC_MESSAGE,
- "sonar.jdbc.password", JDBC_SPECIFIC_MESSAGE);
-
- private final Map<String, String> serverSideSettings;
-
- private final GlobalProperties bootstrapProps;
- private final GlobalMode mode;
- private final Map<String, String> properties = new HashMap<>();
-
- public GlobalSettings(GlobalProperties bootstrapProps, PropertyDefinitions propertyDefinitions,
- SettingsLoader settingsLoader, GlobalMode mode) {
-
- super(propertyDefinitions, new Encryption(bootstrapProps.property(CoreProperties.ENCRYPTION_SECRET_KEY_PATH)));
- this.mode = mode;
- this.bootstrapProps = bootstrapProps;
- this.serverSideSettings = ImmutableMap.copyOf(settingsLoader.load(null));
- init();
- new DroppedPropertyChecker(this.getProperties(), DROPPED_PROPERTIES).checkDroppedProperties();
- }
-
- private void init() {
- addProperties(serverSideSettings);
- addProperties(bootstrapProps.properties());
-
- if (hasKey(CoreProperties.PERMANENT_SERVER_ID)) {
- LOG.info("Server id: " + getString(CoreProperties.PERMANENT_SERVER_ID));
- }
- }
-
- public Map<String, String> getServerSideSettings() {
- return serverSideSettings;
- }
-
- @Override
- protected Optional<String> get(String key) {
- if (mode.isIssues() && key.endsWith(".secured") && !key.contains(".license")) {
- throw MessageException.of("Access to the secured property '" + key
- + "' is not possible in issues mode. The SonarQube plugin which requires this property must be deactivated in issues mode.");
- }
- return Optional.ofNullable(properties.get(key));
- }
-
- @Override
- public Map<String, String> getProperties() {
- return properties;
- }
-
- @Override
- protected void set(String key, String value) {
- properties.put(key, value);
- }
-
- @Override
- protected void remove(String key) {
- properties.remove(key);
- }
-}
package org.sonar.scanner.bootstrap;
import com.google.common.collect.Lists;
-import org.sonar.api.batch.ScannerSide;
+import java.util.List;
import org.sonar.api.ExtensionProvider;
import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.batch.ScannerSide;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Metric;
import org.sonar.api.measures.Metrics;
-import java.util.List;
-
@ScannerSide
@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
public class MetricProvider extends ExtensionProvider {
--- /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.bootstrap;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import org.sonar.api.batch.AnalysisMode;
+import org.sonar.api.config.Settings;
+import org.sonar.api.utils.MessageException;
+
+/**
+ * @deprecated since 6.5 {@link GlobalConfiguration} used to be mutable, so keep a mutable copy for backward compatibility.
+ */
+@Deprecated
+public class MutableGlobalSettings extends Settings {
+
+ private final AnalysisMode mode;
+ private final Map<String, String> mutableProperties = new HashMap<>();
+
+ public MutableGlobalSettings(GlobalConfiguration globalSettings) {
+ super(globalSettings.getDefinitions(), globalSettings.getEncryption());
+ this.mutableProperties.putAll(globalSettings.getProperties());
+ this.mode = globalSettings.getMode();
+ }
+
+ @Override
+ protected Optional<String> get(String key) {
+ if (mode.isIssues() && key.endsWith(".secured") && !key.contains(".license")) {
+ throw MessageException.of("Access to the secured property '" + key
+ + "' is not possible in issues mode. The SonarQube plugin which requires this property must be deactivated in issues mode.");
+ }
+ return Optional.ofNullable(mutableProperties.get(key));
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return mutableProperties;
+ }
+
+ @Override
+ protected void set(String key, String value) {
+ mutableProperties.put(key, value);
+ }
+
+ @Override
+ protected void remove(String key) {
+ mutableProperties.remove(key);
+ }
+}
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
-
import javax.annotation.Nullable;
import org.apache.commons.lang.ClassUtils;
import org.sonar.api.batch.CheckProject;
*/
package org.sonar.scanner.bootstrap;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.sonar.api.batch.ScannerSide;
import org.sonar.api.utils.ZipUtils;
import org.sonar.core.platform.ExplodedPlugin;
-import org.sonar.core.platform.PluginJarExploder;
import org.sonar.core.platform.PluginInfo;
+import org.sonar.core.platform.PluginJarExploder;
import org.sonar.home.cache.FileCache;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
import static org.sonar.core.util.FileUtils.deleteQuietly;
@ScannerSide
import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import com.google.common.base.Splitter;
-
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
-
import javax.annotation.Nonnull;
-
-import org.apache.commons.lang.StringUtils;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.ScannerSide;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
+
import static com.google.common.collect.Sets.newHashSet;
/**
private final Set<String> blacks = newHashSet();
private final GlobalMode mode;
- public ScannerPluginPredicate(Settings settings, GlobalMode mode) {
+ public ScannerPluginPredicate(Configuration settings, GlobalMode mode) {
this.mode = mode;
if (mode.isPreview() || mode.isIssues()) {
// These default values are not supported by Settings because the class CorePlugin
return blacks;
}
- private static List<String> propertyValues(Settings settings, String key, String defaultValue) {
- String s = StringUtils.defaultIfEmpty(settings.getString(key), defaultValue);
+ private static List<String> propertyValues(Configuration settings, String key, String defaultValue) {
+ String s = settings.get(key).orElse(defaultValue);
return StreamSupport.stream(Splitter.on(",").trimResults().omitEmptyStrings().split(s).spliterator(), false)
.collect(Collectors.toList());
}
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-
import javax.annotation.CheckForNull;
-
import org.picocontainer.Startable;
import org.sonar.api.Plugin;
import org.sonar.api.utils.log.Logger;
*/
package org.sonar.scanner.bootstrap;
-import org.sonar.api.config.Encryption;
-
-import javax.annotation.Nullable;
-
import java.util.HashMap;
import java.util.Map;
+import javax.annotation.Nullable;
+import org.sonar.api.config.Encryption;
/**
* Properties that are coming from bootstrapper.
this.properties = decryptedProps;
}
+ public Encryption getEncryption() {
+ return encryption;
+ }
+
public Map<String, String> properties() {
return properties;
}
--- /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.config;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class CsvParser {
+
+ public static String[] parseLine(String line) {
+ List<String> result = new ArrayList<>();
+
+ AtomicInteger i = new AtomicInteger(0);
+ while (true) {
+ String cell = parseNextCell(line, i);
+ if (cell == null)
+ break;
+ result.add(cell);
+ }
+
+ return result.toArray(new String[0]);
+ }
+
+ // returns iterator after delimiter or after end of string
+ private static String parseNextCell(String line, AtomicInteger i) {
+ if (i.get() >= line.length())
+ return null;
+
+ if (line.charAt(i.get()) != '"')
+ return parseNotEscapedCell(line, i);
+ else
+ return parseEscapedCell(line, i);
+ }
+
+ // returns iterator after delimiter or after end of string
+ private static String parseNotEscapedCell(String line, AtomicInteger i) {
+ StringBuilder sb = new StringBuilder();
+ while (true) {
+ if (i.get() >= line.length()) {
+ // return iterator after end of string
+ break;
+ }
+ if (line.charAt(i.get()) == ',') {
+ // return iterator after delimiter
+ i.incrementAndGet();
+ break;
+ }
+ sb.append(line.charAt(i.get()));
+ i.incrementAndGet();
+ }
+ return sb.toString();
+ }
+
+ // returns iterator after delimiter or after end of string
+ private static String parseEscapedCell(String line, AtomicInteger i) {
+ i.incrementAndGet(); // omit first character (quotation mark)
+ StringBuilder sb = new StringBuilder();
+ while (true) {
+ if (i.get() >= line.length()) {
+ break;
+ }
+ if (line.charAt(i.get()) == '"') {
+ i.incrementAndGet(); // we're more interested in the next character
+ if (i.get() >= line.length()) {
+ // quotation mark was closing cell
+ // return iterator after end of string
+ break;
+ }
+ if (line.charAt(i.get()) == ',') {
+ // quotation mark was closing cell
+ // return iterator after delimiter
+ i.incrementAndGet();
+ break;
+ }
+ if (line.charAt(i.get()) == '"') {
+ // it was doubled (escaped) quotation mark
+ // do nothing -- we've already skipped first quotation mark
+ }
+
+ }
+ sb.append(line.charAt(i.get()));
+ i.incrementAndGet();
+ }
+
+ return sb.toString();
+ }
+}
--- /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.config;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import javax.annotation.concurrent.Immutable;
+import org.apache.commons.lang.ArrayUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.batch.AnalysisMode;
+import org.sonar.api.config.Configuration;
+import org.sonar.api.config.Encryption;
+import org.sonar.api.config.PropertyDefinition;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.api.utils.MessageException;
+
+import static java.util.Objects.requireNonNull;
+import static org.apache.commons.lang.StringUtils.trim;
+
+@Immutable
+public abstract class DefaultConfiguration implements Configuration {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DefaultConfiguration.class);
+
+ private final PropertyDefinitions definitions;
+ private final Encryption encryption;
+ private final AnalysisMode mode;
+ private final Map<String, String> properties = new HashMap<>();
+
+ public DefaultConfiguration(PropertyDefinitions propertyDefinitions, Encryption encryption, AnalysisMode mode, Map<String, String> props) {
+ this.definitions = requireNonNull(propertyDefinitions);
+ this.encryption = encryption;
+ this.mode = mode;
+ props.forEach((k, v) -> {
+ String validKey = definitions.validKey(k);
+ properties.put(validKey, trim(v));
+ });
+ }
+
+ public AnalysisMode getMode() {
+ return mode;
+ }
+
+ public Encryption getEncryption() {
+ return encryption;
+ }
+
+ public PropertyDefinitions getDefinitions() {
+ return definitions;
+ }
+
+ public Map<String, String> getProperties() {
+ return Collections.unmodifiableMap(properties);
+ }
+
+ @Override
+ public boolean hasKey(String key) {
+ return properties.containsKey(key);
+ }
+
+ @Override
+ public Optional<String> get(String key) {
+ String effectiveKey = definitions.validKey(key);
+ PropertyDefinition def = definitions.get(effectiveKey);
+ if (def != null && def.multiValues()) {
+ LOG.warn("Access to the multi-valued property '{}' should be made using 'getStringArray' method. The SonarQube plugin using this property should be updated.");
+ }
+ return getInternal(effectiveKey);
+ }
+
+ @Override
+ public String[] getStringArray(String key) {
+ String effectiveKey = definitions.validKey(key);
+ PropertyDefinition def = definitions.get(effectiveKey);
+ if (def != null && !def.multiValues()) {
+ LOG.warn("Property '{}' is not declared as multi-valued but was read using 'getStringArray' method. The SonarQube plugin declaring this property should be updated.");
+ }
+ Optional<String> value = getInternal(key);
+ if (value.isPresent()) {
+ return CsvParser.parseLine(value.get());
+ }
+ return ArrayUtils.EMPTY_STRING_ARRAY;
+ }
+
+ private Optional<String> getInternal(String key) {
+ if (mode.isIssues() && key.endsWith(".secured") && !key.contains(".license")) {
+ throw MessageException.of("Access to the secured property '" + key
+ + "' is not possible in issues mode. The SonarQube plugin which requires this property must be deactivated in issues mode.");
+ }
+ Optional<String> value = Optional.ofNullable(properties.get(key));
+ if (!value.isPresent()) {
+ // default values cannot be encrypted, so return value as-is.
+ return Optional.ofNullable(definitions.getDefaultValue(key));
+ }
+ if (encryption.isEncrypted(value.get())) {
+ try {
+ return Optional.of(encryption.decrypt(value.get()));
+ } catch (Exception e) {
+ throw new IllegalStateException("Fail to decrypt the property " + key + ". Please check your secret key.", e);
+ }
+ }
+ return value;
+ }
+
+}
--- /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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.scanner.config;
+
+import javax.annotation.ParametersAreNonnullByDefault;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputComponent;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.duplications.block.Block;
private final SonarCpdBlockIndex index;
private final ReportPublisher publisher;
private final InputComponentStore componentStore;
- private final Settings settings;
+ private final Configuration settings;
private final ProgressReport progressReport;
private int count;
private int total;
- public CpdExecutor(Settings settings, SonarCpdBlockIndex index, ReportPublisher publisher, InputComponentStore inputComponentCache) {
+ public CpdExecutor(Configuration settings, SonarCpdBlockIndex index, ReportPublisher publisher, InputComponentStore inputComponentCache) {
this.settings = settings;
this.index = index;
this.publisher = publisher;
* @return
*/
int getMinimumTokens(String languageKey) {
- int minimumTokens = settings.getInt("sonar.cpd." + languageKey + ".minimumTokens");
- if (minimumTokens == 0) {
- minimumTokens = 100;
- }
-
- return minimumTokens;
+ return settings.getInt("sonar.cpd." + languageKey + ".minimumTokens").orElse(100);
}
@VisibleForTesting
package org.sonar.scanner.cpd;
import com.google.common.base.Predicate;
-import org.sonar.duplications.index.CloneGroup;
-
import javax.annotation.Nullable;
+import org.sonar.duplications.index.CloneGroup;
public final class DuplicationPredicates {
*/
package org.sonar.scanner.cpd.deprecated;
-import org.sonar.api.batch.ScannerSide;
-import org.sonar.api.batch.CpdMapping;
-
import javax.annotation.CheckForNull;
+import org.sonar.api.batch.CpdMapping;
+import org.sonar.api.batch.ScannerSide;
@ScannerSide
public class CpdMappings {
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.duplications.block.Block;
private final CpdMappings mappings;
private final FileSystem fs;
- private final Settings settings;
+ private final Configuration settings;
private final SonarCpdBlockIndex index;
- public DefaultCpdBlockIndexer(CpdMappings mappings, FileSystem fs, Settings settings, SonarCpdBlockIndex index) {
+ public DefaultCpdBlockIndexer(CpdMappings mappings, FileSystem fs, Configuration settings, SonarCpdBlockIndex index) {
this.mappings = mappings;
this.fs = fs;
this.settings = settings;
@VisibleForTesting
int getBlockSize(String languageKey) {
- int blockSize = settings.getInt("sonar.cpd." + languageKey + ".minimumLines");
- if (blockSize == 0) {
- blockSize = getDefaultBlockSize(languageKey);
- }
- return blockSize;
+ return settings.getInt("sonar.cpd." + languageKey + ".minimumLines").orElse(getDefaultBlockSize(languageKey));
}
@VisibleForTesting
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.duplications.block.Block;
private static final int BLOCK_SIZE = 10;
private final FileSystem fs;
- private final Settings settings;
+ private final Configuration settings;
private final SonarCpdBlockIndex index;
- public JavaCpdBlockIndexer(FileSystem fs, Settings settings, SonarCpdBlockIndex index) {
+ public JavaCpdBlockIndexer(FileSystem fs, Configuration settings, SonarCpdBlockIndex index) {
this.fs = fs;
this.settings = settings;
this.index = index;
import java.util.Iterator;
import java.util.Set;
import java.util.stream.Collectors;
-import org.apache.commons.lang.StringUtils;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.duplications.block.Block;
private static final Logger LOG = Loggers.get(SonarCpdBlockIndex.class);
private final CloneIndex mem = new PackedMemoryCloneIndex();
private final ReportPublisher publisher;
- private final Settings settings;
+ private final Configuration settings;
// Files already tokenized
private final Set<InputFile> indexedFiles = new HashSet<>();
- public SonarCpdBlockIndex(ReportPublisher publisher, Settings settings) {
+ public SonarCpdBlockIndex(ReportPublisher publisher, Configuration settings) {
this.publisher = publisher;
this.settings = settings;
}
return indexedFiles.contains(inputFile);
}
- public static boolean isCrossProjectDuplicationEnabled(Settings settings) {
- return settings.getBoolean(CoreProperties.CPD_CROSS_PROJECT)
+ public static boolean isCrossProjectDuplicationEnabled(Configuration settings) {
+ return settings.getBoolean(CoreProperties.CPD_CROSS_PROJECT).orElse(false)
// No cross project duplication for branches
- && StringUtils.isBlank(settings.getString(CoreProperties.PROJECT_BRANCH_PROPERTY));
+ && !settings.get(CoreProperties.PROJECT_BRANCH_PROPERTY).isPresent();
}
public Collection<Block> getByInputFile(String resourceKey) {
import org.sonar.api.batch.fs.InputPath;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.sensor.internal.SensorStorage;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.api.design.Dependency;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MeasuresFilter;
private final DefaultIndex index;
private final InputModule module;
- public DeprecatedSensorContext(InputModule module, DefaultIndex index, Settings settings, FileSystem fs, ActiveRules activeRules,
+ public DeprecatedSensorContext(InputModule module, DefaultIndex index, Configuration config, org.sonar.api.config.Settings mutableSettings, FileSystem fs, ActiveRules activeRules,
AnalysisMode analysisMode, SensorStorage sensorStorage, SonarRuntime sonarRuntime) {
- super(module, settings, fs, activeRules, analysisMode, sensorStorage, sonarRuntime);
+ super(module, config, mutableSettings, fs, activeRules, analysisMode, sensorStorage, sonarRuntime);
this.index = index;
this.module = module;
}
import com.google.common.collect.Maps;
import java.util.Map;
import javax.annotation.CheckForNull;
-
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.fs.InputPath;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
*/
package org.sonar.scanner.events;
-import org.sonar.api.batch.events.EventHandler;
-
import java.util.ArrayList;
import java.util.List;
+import org.sonar.api.batch.events.EventHandler;
/**
* Dispatches {@link BatchEvent}s. Eases decoupling by allowing objects to interact without having direct dependencies upon one another, and
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.SensorDescriptor;
+import org.sonar.api.config.Configuration;
import org.sonar.api.config.PropertyDefinition;
-import org.sonar.api.config.Settings;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
@Deprecated
static final String OLD_OVERALL_COVERAGE_REPORT_PATHS_PROPERTY_KEY = "sonar.genericcoverage.overallReportPaths";
- private final Settings settings;
+ private final Configuration settings;
- public GenericCoverageSensor(Settings settings) {
+ public GenericCoverageSensor(Configuration settings) {
this.settings = settings;
}
loadDeprecated(reportPaths, OLD_IT_COVERAGE_REPORT_PATHS_PROPERTY_KEY);
loadDeprecated(reportPaths, OLD_OVERALL_COVERAGE_REPORT_PATHS_PROPERTY_KEY);
if (!reportPaths.isEmpty()) {
- settings.setProperty(REPORT_PATHS_PROPERTY_KEY, reportPaths.stream().collect(Collectors.joining(",")));
+ // settings.setProperty(REPORT_PATHS_PROPERTY_KEY, reportPaths.stream().collect(Collectors.joining(",")));
}
}
import java.util.ArrayList;
import java.util.Collection;
import java.util.stream.Collectors;
-
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;
*/
package org.sonar.scanner.issue;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.batch.bootstrapper.IssueListener;
import org.sonar.api.batch.rule.Rule;
import org.sonar.api.batch.rule.Rules;
-
+import org.sonar.api.rule.RuleKey;
+import org.sonar.batch.bootstrapper.IssueListener;
import org.sonar.scanner.issue.tracking.TrackedIssue;
public class DefaultIssueCallback implements IssueCallback {
*/
package org.sonar.scanner.issue;
-import org.sonar.api.scan.issue.filter.IssueFilter;
-
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-
import org.sonar.api.scan.issue.filter.FilterableIssue;
+import org.sonar.api.scan.issue.filter.IssueFilter;
import org.sonar.api.scan.issue.filter.IssueFilterChain;
public class DefaultIssueFilterChain implements IssueFilterChain {
*/
package org.sonar.scanner.issue;
-import org.sonar.api.issue.Issue;
-import org.sonar.api.issue.ProjectIssues;
-import org.sonar.scanner.issue.tracking.TrackedIssue;
-
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
-
import javax.annotation.Nullable;
+import org.sonar.api.issue.Issue;
+import org.sonar.api.issue.ProjectIssues;
+import org.sonar.scanner.issue.tracking.TrackedIssue;
/**
* Expose list of issues for the current project
import java.util.Date;
import java.util.List;
import java.util.Map;
-
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.IssueComment;
*/
package org.sonar.scanner.issue;
-import org.sonar.api.issue.Issue;
-import org.sonar.api.issue.batch.IssueFilter;
-import org.sonar.api.issue.batch.IssueFilterChain;
-
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import org.sonar.api.issue.Issue;
+import org.sonar.api.issue.batch.IssueFilter;
+import org.sonar.api.issue.batch.IssueFilterChain;
/**
* @deprecated since 5.3
*/
package org.sonar.scanner.issue;
+import java.util.Collection;
import org.sonar.api.batch.ScannerSide;
import org.sonar.scanner.issue.tracking.TrackedIssue;
import org.sonar.scanner.storage.Storage;
import org.sonar.scanner.storage.Storages;
-import java.util.Collection;
/**
* Shared issues among all project modules
*/
package org.sonar.scanner.issue;
-import org.sonar.api.scan.issue.filter.FilterableIssue;
-
-import org.sonar.api.scan.issue.filter.IssueFilterChain;
-import org.sonar.scanner.ProjectAnalysisInfo;
-import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.api.batch.ScannerSide;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.issue.Issue;
+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.protocol.output.ScannerReport;
@ScannerSide
public class IssueFilters {
package org.sonar.scanner.issue;
import com.google.common.base.Strings;
-
import org.sonar.api.batch.fs.TextRange;
import org.sonar.api.batch.fs.internal.DefaultInputComponent;
import org.sonar.api.batch.rule.ActiveRule;
*/
package org.sonar.scanner.issue.ignore;
-import org.sonar.api.batch.fs.InputComponent;
-import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.scan.issue.filter.FilterableIssue;
-
import javax.annotation.CheckForNull;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.sonar.api.batch.fs.InputComponent;
+import org.sonar.api.batch.fs.InputFile;
+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.issue.ignore.pattern.IssueInclusionPatternInitializer;
*/
package org.sonar.scanner.issue.ignore;
-import org.sonar.api.scan.issue.filter.FilterableIssue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+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.issue.ignore.pattern.IssuePattern;
package org.sonar.scanner.issue.ignore.pattern;
import com.google.common.annotations.VisibleForTesting;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.batch.ScannerSide;
-import org.sonar.api.config.Settings;
-
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
+import org.apache.commons.lang.StringUtils;
+import org.sonar.api.batch.ScannerSide;
+import org.sonar.api.config.Configuration;
import static com.google.common.base.MoreObjects.firstNonNull;
@ScannerSide
public abstract class AbstractPatternInitializer {
- private Settings settings;
+ private Configuration settings;
private List<IssuePattern> multicriteriaPatterns;
- protected AbstractPatternInitializer(Settings settings) {
+ protected AbstractPatternInitializer(Configuration settings) {
this.settings = settings;
initPatterns();
}
- protected Settings getSettings() {
+ protected Configuration getSettings() {
return settings;
}
protected final void initPatterns() {
// Patterns Multicriteria
multicriteriaPatterns = new ArrayList<>();
- String patternConf = StringUtils.defaultIfBlank(settings.getString(getMulticriteriaConfigurationKey()), "");
- for (String id : StringUtils.split(patternConf, ',')) {
+ for (String id : settings.getStringArray(getMulticriteriaConfigurationKey())) {
String propPrefix = getMulticriteriaConfigurationKey() + "." + id + ".";
- String resourceKeyPattern = settings.getString(propPrefix + "resourceKey");
- String ruleKeyPattern = settings.getString(propPrefix + "ruleKey");
+ String resourceKeyPattern = settings.get(propPrefix + "resourceKey").orElse(null);
+ String ruleKeyPattern = settings.get(propPrefix + "ruleKey").orElse(null);
String lineRange = "*";
String[] fields = new String[] {resourceKeyPattern, ruleKeyPattern, lineRange};
PatternDecoder.checkRegularLineConstraints(StringUtils.join(fields, ","), fields);
*/
package org.sonar.scanner.issue.ignore.pattern;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.config.Settings;
-import org.sonar.core.config.IssueExclusionProperties;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import org.apache.commons.lang.StringUtils;
+import org.sonar.api.config.Configuration;
+import org.sonar.core.config.IssueExclusionProperties;
import static com.google.common.base.Strings.nullToEmpty;
private List<BlockIssuePattern> blockPatterns;
private List<String> allFilePatterns;
- public IssueExclusionPatternInitializer(Settings settings) {
+ public IssueExclusionPatternInitializer(Configuration settings) {
super(settings);
loadFileContentPatterns();
}
private final void loadFileContentPatterns() {
// Patterns Block
blockPatterns = new ArrayList<>();
- String patternConf = StringUtils.defaultIfBlank(getSettings().getString(IssueExclusionProperties.PATTERNS_BLOCK_KEY), "");
- for (String id : StringUtils.split(patternConf, ',')) {
+ for (String id : getSettings().getStringArray(IssueExclusionProperties.PATTERNS_BLOCK_KEY)) {
String propPrefix = IssueExclusionProperties.PATTERNS_BLOCK_KEY + "." + id + ".";
- String beginBlockRegexp = getSettings().getString(propPrefix + IssueExclusionProperties.BEGIN_BLOCK_REGEXP);
- String endBlockRegexp = getSettings().getString(propPrefix + IssueExclusionProperties.END_BLOCK_REGEXP);
+ String beginBlockRegexp = getSettings().get(propPrefix + IssueExclusionProperties.BEGIN_BLOCK_REGEXP).orElse(null);
+ String endBlockRegexp = getSettings().get(propPrefix + IssueExclusionProperties.END_BLOCK_REGEXP).orElse(null);
String[] fields = new String[] {beginBlockRegexp, endBlockRegexp};
PatternDecoder.checkDoubleRegexpLineConstraints(StringUtils.join(fields, ","), fields);
BlockIssuePattern pattern = new BlockIssuePattern(nullToEmpty(beginBlockRegexp), nullToEmpty(endBlockRegexp));
// Patterns All File
allFilePatterns = new ArrayList<>();
- patternConf = StringUtils.defaultIfBlank(getSettings().getString(IssueExclusionProperties.PATTERNS_ALLFILE_KEY), "");
- for (String id : StringUtils.split(patternConf, ',')) {
+ for (String id : getSettings().getStringArray(IssueExclusionProperties.PATTERNS_ALLFILE_KEY)) {
String propPrefix = IssueExclusionProperties.PATTERNS_ALLFILE_KEY + "." + id + ".";
- String allFileRegexp = getSettings().getString(propPrefix + IssueExclusionProperties.FILE_REGEXP);
+ String allFileRegexp = getSettings().get(propPrefix + IssueExclusionProperties.FILE_REGEXP).orElse(null);
PatternDecoder.checkWholeFileRegexp(allFileRegexp);
allFilePatterns.add(nullToEmpty(allFileRegexp));
}
*/
package org.sonar.scanner.issue.ignore.pattern;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
public class IssueInclusionPatternInitializer extends AbstractPatternInitializer {
- public IssueInclusionPatternInitializer(Settings settings) {
+ public IssueInclusionPatternInitializer(Configuration settings) {
super(settings);
}
package org.sonar.scanner.issue.ignore.pattern;
import com.google.common.collect.Sets;
-
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
package org.sonar.scanner.issue.ignore.pattern;
import com.google.common.base.Preconditions;
-
import java.util.LinkedHashSet;
import java.util.Set;
*/
package org.sonar.scanner.issue.ignore.pattern;
+import com.google.common.annotations.VisibleForTesting;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
-
import org.apache.commons.lang.StringUtils;
-import com.google.common.annotations.VisibleForTesting;
-
public class PatternDecoder {
private static final String LINE_RANGE_REGEXP = "\\[((\\d+|\\d+-\\d+),?)*\\]";
private static final String CONFIG_FORMAT_ERROR_PREFIX = "Exclusions > Issues : Invalid format. ";
*/
package org.sonar.scanner.issue.ignore.pattern;
-import org.sonar.api.rule.RuleKey;
-
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
-
import java.util.Collection;
import java.util.Set;
-
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+import org.sonar.api.rule.RuleKey;
public class PatternMatcher {
import java.util.ArrayList;
import java.util.List;
-
import javax.annotation.CheckForNull;
-
import org.apache.commons.lang.StringUtils;
import org.sonar.api.batch.fs.internal.FileMetadata.CharHandler;
import org.sonar.scanner.issue.ignore.pattern.BlockIssuePattern;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
-
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*/
package org.sonar.scanner.issue.tracking;
-import org.sonarqube.ws.client.GetRequest;
-
-import java.io.IOException;
-import java.io.Reader;
-
import com.google.common.base.Splitter;
import com.google.common.collect.Iterators;
+import java.io.IOException;
+import java.io.Reader;
import org.apache.commons.io.IOUtils;
import org.sonar.api.utils.log.Loggers;
import org.sonar.api.utils.log.Profiler;
import org.sonar.scanner.bootstrap.ScannerWsClient;
import org.sonar.scanner.util.ScannerUtils;
+import org.sonarqube.ws.client.GetRequest;
public class DefaultServerLineHashesLoader implements ServerLineHashesLoader {
private ScannerWsClient wsClient;
*/
package org.sonar.scanner.issue.tracking;
-import org.sonar.core.issue.tracking.Trackable;
-import org.sonar.core.issue.tracking.BlockHashSequence;
-import org.sonar.core.issue.tracking.LineHashSequence;
-
import java.util.Collection;
import java.util.List;
-
+import org.sonar.core.issue.tracking.BlockHashSequence;
import org.sonar.core.issue.tracking.Input;
+import org.sonar.core.issue.tracking.LineHashSequence;
+import org.sonar.core.issue.tracking.Trackable;
public class IssueTrackingInput<T extends Trackable> implements Input<T> {
*/
package org.sonar.scanner.issue.tracking;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import javax.annotation.Nullable;
import org.sonar.api.batch.ScannerSide;
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.fs.internal.DefaultInputComponent;
import org.sonar.scanner.report.ReportPublisher;
import org.sonar.scanner.scan.filesystem.InputComponentStore;
import org.sonar.scanner.util.ProgressReport;
-import javax.annotation.Nullable;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
@ScannerSide
public class IssueTransition {
import java.util.Date;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.rule.RuleKey;
import org.sonar.scanner.protocol.output.ScannerReport.Component;
import org.sonar.scanner.protocol.output.ScannerReport.Metadata;
import org.sonar.scanner.protocol.output.ScannerReport.Symbol;
+import org.sonar.scanner.protocol.output.ScannerReportReader;
import org.sonar.scanner.report.ReportPublisher;
import org.sonar.scanner.report.ScannerReportUtils;
import org.sonar.scanner.scan.ProjectScanContainer;
import org.sonar.scanner.scan.filesystem.InputComponentStore;
-import org.sonar.scanner.protocol.output.ScannerReportReader;
import static org.apache.commons.lang.StringUtils.isNotEmpty;
package org.sonar.scanner.phases;
import com.google.common.collect.Lists;
+import java.util.Collection;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.batch.Initializer;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.utils.log.Profiler;
import org.sonar.scanner.bootstrap.ScannerExtensionDictionnary;
import org.sonar.scanner.events.EventBus;
-import java.util.Collection;
public class InitializersExecutor {
*/
package org.sonar.scanner.phases;
+import java.util.List;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.events.SensorsPhaseHandler;
-import java.util.List;
-
class SensorsPhaseEvent extends AbstractPhaseEvent<SensorsPhaseHandler>
implements org.sonar.api.batch.events.SensorsPhaseHandler.SensorsPhaseEvent {
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
-
import javax.annotation.Nullable;
import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.postjob.PostJobContext;
import org.sonar.api.batch.postjob.issue.PostJobIssue;
import org.sonar.api.batch.rule.Severity;
+import org.sonar.api.config.Configuration;
import org.sonar.api.config.Settings;
import org.sonar.api.rule.RuleKey;
import org.sonar.scanner.issue.IssueCache;
public class DefaultPostJobContext implements PostJobContext {
- private final Settings settings;
+ private final Configuration config;
private final IssueCache cache;
private final AnalysisMode analysisMode;
private InputComponentStore inputComponentStore;
+ private final Settings mutableSettings;
- public DefaultPostJobContext(Settings settings, IssueCache cache, InputComponentStore inputComponentStore, AnalysisMode analysisMode) {
- this.settings = settings;
+ public DefaultPostJobContext(Configuration config, Settings mutableSettings, IssueCache cache, InputComponentStore inputComponentStore,
+ AnalysisMode analysisMode) {
+ this.config = config;
+ this.mutableSettings = mutableSettings;
this.cache = cache;
this.inputComponentStore = inputComponentStore;
this.analysisMode = analysisMode;
@Override
public Settings settings() {
- return settings;
+ return mutableSettings;
+ }
+
+ @Override
+ public Configuration config() {
+ return config;
}
@Override
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.core.platform.PluginInfo;
-import org.sonar.scanner.bootstrap.GlobalSettings;
+import org.sonar.scanner.bootstrap.GlobalConfiguration;
import org.sonar.scanner.bootstrap.ScannerPluginRepository;
import org.sonar.scanner.protocol.output.ScannerReportWriter;
import org.sonar.scanner.repository.ProjectRepositories;
private final AnalysisMode mode;
private final System2 system;
private final ProjectRepositories projectRepos;
- private final GlobalSettings globalSettings;
+ private final GlobalConfiguration globalSettings;
private ScannerReportWriter writer;
public AnalysisContextReportPublisher(AnalysisMode mode, ScannerPluginRepository pluginRepo, System2 system,
- ProjectRepositories projectRepos, GlobalSettings globalSettings) {
+ ProjectRepositories projectRepos, GlobalConfiguration globalSettings) {
this.mode = mode;
this.pluginRepo = pluginRepo;
this.system = system;
import java.util.Collection;
import java.util.stream.Collectors;
-
import javax.annotation.CheckForNull;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
import org.sonar.core.util.CloseableIterator;
import org.sonar.scanner.protocol.output.ScannerReport;
-import org.sonar.scanner.protocol.output.ScannerReportReader;
import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType;
import org.sonar.scanner.protocol.output.ScannerReport.ComponentLink;
import org.sonar.scanner.protocol.output.ScannerReport.ComponentLink.ComponentLinkType;
import org.sonar.scanner.protocol.output.ScannerReport.Issue;
+import org.sonar.scanner.protocol.output.ScannerReportReader;
import org.sonar.scanner.protocol.output.ScannerReportWriter;
/**
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-
import javax.annotation.Nonnull;
-import org.sonar.api.config.Settings;
+import org.sonar.scanner.config.DefaultConfiguration;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReportWriter;
import org.sonar.scanner.repository.ContextPropertiesCache;
public class ContextPropertiesPublisher implements ReportPublisherStep {
private final ContextPropertiesCache cache;
- private final Settings settings;
+ private final DefaultConfiguration config;
- public ContextPropertiesPublisher(ContextPropertiesCache cache, Settings settings) {
+ public ContextPropertiesPublisher(ContextPropertiesCache cache, DefaultConfiguration config) {
this.cache = cache;
- this.settings = settings;
+ this.config = config;
}
@Override
// properties that are automatically included to report so that
// they can be included to webhook payloads
- Stream<ScannerReport.ContextProperty> fromSettings = settings.getProperties().entrySet().stream()
+ Stream<ScannerReport.ContextProperty> fromSettings = config.getProperties().entrySet().stream()
.filter(e -> e.getKey().startsWith(ANALYSIS_PROPERTY_PREFIX))
.map(transformer);
private final ScannerReport.ContextProperty.Builder builder = ScannerReport.ContextProperty.newBuilder();
@Override
- public ScannerReport.ContextProperty apply(@Nonnull Map.Entry<String, String> input) {
+ public ScannerReport.ContextProperty apply(@Nonnull Map.Entry<String, String> input) {
return builder.clear().setKey(input.getKey()).setValue(input.getValue()).build();
}
}
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.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.scanner.ProjectAnalysisInfo;
import org.sonar.scanner.cpd.index.SonarCpdBlockIndex;
import org.sonar.scanner.protocol.output.ScannerReport;
public class MetadataPublisher implements ReportPublisherStep {
- private final Settings settings;
+ private final Configuration settings;
private final ModuleQProfiles qProfiles;
private final ProjectAnalysisInfo projectAnalysisInfo;
private final InputModuleHierarchy moduleHierarchy;
- public MetadataPublisher(ProjectAnalysisInfo projectAnalysisInfo, InputModuleHierarchy moduleHierarchy, Settings settings, ModuleQProfiles qProfiles) {
+ public MetadataPublisher(ProjectAnalysisInfo projectAnalysisInfo, InputModuleHierarchy moduleHierarchy, Configuration settings, ModuleQProfiles qProfiles) {
this.projectAnalysisInfo = projectAnalysisInfo;
this.moduleHierarchy = moduleHierarchy;
this.settings = settings;
.setCrossProjectDuplicationActivated(SonarCpdBlockIndex.isCrossProjectDuplicationEnabled(settings))
.setRootComponentRef(rootProject.batchId());
- String organization = settings.getString(CoreProperties.PROJECT_ORGANIZATION_PROPERTY);
- if (organization != null) {
- builder.setOrganizationKey(organization);
- }
+ settings.get(CoreProperties.PROJECT_ORGANIZATION_PROPERTY).ifPresent(builder::setOrganizationKey);
String branch = rootDef.getBranch();
if (branch != null) {
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.ScannerSide;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.api.platform.Server;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.TempFolder;
public static final String VERBOSE_KEY = "sonar.verbose";
public static final String METADATA_DUMP_FILENAME = "report-task.txt";
- private final Settings settings;
+ private final Configuration settings;
private final ScannerWsClient wsClient;
private final AnalysisContextReportPublisher contextPublisher;
private final ImmutableProjectReactor projectReactor;
private File reportDir;
private ScannerReportWriter writer;
- public ReportPublisher(Settings settings, ScannerWsClient wsClient, Server server, AnalysisContextReportPublisher contextPublisher,
+ public ReportPublisher(Configuration settings, ScannerWsClient wsClient, Server server, AnalysisContextReportPublisher contextPublisher,
ImmutableProjectReactor projectReactor, DefaultAnalysisMode analysisMode, TempFolder temp, ReportPublisherStep[] publishers) {
this.settings = settings;
this.wsClient = wsClient;
}
private boolean shouldKeepReport() {
- return settings.getBoolean(KEEP_REPORT_PROP_KEY) || settings.getBoolean(VERBOSE_KEY);
+ return settings.getBoolean(KEEP_REPORT_PROP_KEY).orElse(false) || settings.getBoolean(VERBOSE_KEY).orElse(false);
}
private File generateReportFile() {
PostRequest.Part filePart = new PostRequest.Part(MediaTypes.ZIP, report);
PostRequest post = new PostRequest("api/ce/submit")
.setMediaType(MediaTypes.PROTOBUF)
- .setParam("organization", settings.getString(CoreProperties.PROJECT_ORGANIZATION_PROPERTY))
+ .setParam("organization", settings.get(CoreProperties.PROJECT_ORGANIZATION_PROPERTY).orElse(null))
.setParam("projectKey", projectDefinition.getKey())
.setParam("projectName", projectDefinition.getOriginalName())
.setParam("projectBranch", projectDefinition.getBranch())
Map<String, String> metadata = new LinkedHashMap<>();
String effectiveKey = projectReactor.getRoot().getKeyWithBranch();
- if (settings.hasKey(CoreProperties.PROJECT_ORGANIZATION_PROPERTY)) {
- metadata.put("organization", settings.getString(CoreProperties.PROJECT_ORGANIZATION_PROPERTY));
- }
+ settings.get(CoreProperties.PROJECT_ORGANIZATION_PROPERTY).ifPresent(org -> metadata.put("organization", org));
metadata.put("projectKey", effectiveKey);
metadata.put("serverUrl", publicUrl);
metadata.put("serverVersion", server.getVersion());
import java.util.HashSet;
import java.util.Set;
import java.util.stream.StreamSupport;
-
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.fs.internal.DefaultInputComponent;
import org.sonar.api.test.CoverageBlock;
import org.sonar.scanner.protocol.output.ScannerReport.CoverageDetail;
import org.sonar.scanner.protocol.output.ScannerReport.Test;
import org.sonar.scanner.protocol.output.ScannerReport.Test.TestStatus;
-import org.sonar.scanner.scan.filesystem.InputComponentStore;
import org.sonar.scanner.protocol.output.ScannerReportWriter;
+import org.sonar.scanner.scan.filesystem.InputComponentStore;
import static java.util.stream.Collectors.toList;
import java.util.function.BinaryOperator;
import javax.annotation.Nullable;
import org.apache.commons.io.IOUtils;
-import org.sonar.api.config.Settings;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.config.Configuration;
import org.sonar.api.utils.MessageException;
import org.sonar.scanner.bootstrap.ScannerWsClient;
import org.sonarqube.ws.QualityProfiles.SearchWsResponse;
public class DefaultQualityProfileLoader implements QualityProfileLoader {
private static final String WS_URL = "/api/qualityprofiles/search.protobuf";
- private final Settings settings;
+ private final Configuration settings;
private final ScannerWsClient wsClient;
- public DefaultQualityProfileLoader(Settings settings, ScannerWsClient wsClient) {
+ public DefaultQualityProfileLoader(Configuration settings, ScannerWsClient wsClient) {
this.settings = settings;
this.wsClient = wsClient;
}
}
private Optional<String> getOrganizationKey() {
- return Optional.ofNullable(settings.getString("sonar.organization"));
+ return settings.get(CoreProperties.PROJECT_ORGANIZATION_PROPERTY);
}
private Map<String, QualityProfile> call(String url) {
*/
package org.sonar.scanner.repository;
-import org.sonar.api.utils.log.Profiler;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
+import org.picocontainer.injectors.ProviderAdapter;
import org.sonar.api.batch.bootstrap.ProjectKey;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
-import org.picocontainer.injectors.ProviderAdapter;
+import org.sonar.api.utils.log.Profiler;
+import org.sonar.scanner.analysis.DefaultAnalysisMode;
public class ProjectRepositoriesProvider extends ProviderAdapter {
private static final Logger LOG = Loggers.get(ProjectRepositoriesProvider.class);
*/
package org.sonar.scanner.repository;
-import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
-
-import javax.annotation.Nullable;
-
import java.util.List;
+import javax.annotation.Nullable;
+import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
public interface QualityProfileLoader {
List<QualityProfile> load(String projectKey, @Nullable String profileName);
*/
package org.sonar.scanner.repository.language;
-import org.picocontainer.Startable;
-
-import org.sonar.api.resources.Languages;
-
-import javax.annotation.CheckForNull;
-
import java.util.ArrayList;
import java.util.Collection;
+import javax.annotation.CheckForNull;
+import org.picocontainer.Startable;
+import org.sonar.api.resources.Languages;
/**
* Languages repository using {@link Languages}
*/
package org.sonar.scanner.repository.language;
-import org.sonar.api.batch.ScannerSide;
-
-import javax.annotation.CheckForNull;
-
import java.util.Collection;
+import javax.annotation.CheckForNull;
+import org.sonar.api.batch.ScannerSide;
/**
* Languages repository
*/
package org.sonar.scanner.rule;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
import org.apache.commons.io.IOUtils;
import org.sonar.scanner.bootstrap.ScannerWsClient;
+import org.sonarqube.ws.Rules.ListResponse;
import org.sonarqube.ws.Rules.ListResponse.Rule;
import org.sonarqube.ws.client.GetRequest;
-import org.sonarqube.ws.Rules.ListResponse;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.List;
public class DefaultRulesLoader implements RulesLoader {
private static final String RULES_SEARCH_URL = "/api/rules/list.protobuf";
*/
package org.sonar.scanner.rule;
-import org.sonar.api.utils.DateUtils;
-
-import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
-import org.sonar.api.batch.ScannerSide;
-
-import javax.annotation.CheckForNull;
-
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import javax.annotation.CheckForNull;
+import org.sonar.api.batch.ScannerSide;
+import org.sonar.api.utils.DateUtils;
+import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
/**
* Lists the Quality profiles enabled on the current module.
package org.sonar.scanner.rule;
import com.google.common.base.MoreObjects;
-
import java.util.Date;
public class QProfile {
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.ScannerSide;
import org.sonar.api.batch.fs.FileSystem;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.api.utils.MessageException;
import static org.apache.commons.lang.StringUtils.isNotEmpty;
private static final Logger LOG = LoggerFactory.getLogger(QProfileVerifier.class);
- private final Settings settings;
+ private final Configuration settings;
private final FileSystem fs;
private final ModuleQProfiles profiles;
- public QProfileVerifier(Settings settings, FileSystem fs, ModuleQProfiles profiles) {
+ public QProfileVerifier(Configuration settings, FileSystem fs, ModuleQProfiles profiles) {
this.settings = settings;
this.fs = fs;
this.profiles = profiles;
@VisibleForTesting
void execute(Logger logger) {
- String defaultName = settings.getString(ModuleQProfiles.SONAR_PROFILE_PROP);
+ String defaultName = settings.get(ModuleQProfiles.SONAR_PROFILE_PROP).orElse(null);
boolean defaultNameUsed = StringUtils.isBlank(defaultName);
for (String lang : fs.languages()) {
QProfile profile = profiles.findByLanguage(lang);
import java.util.Collection;
import java.util.Collections;
import java.util.stream.Collectors;
-
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.picocontainer.injectors.ProviderAdapter;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.rule.ActiveRules;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.rules.ActiveRule;
import org.sonar.api.rules.Rule;
private RulesProfile singleton = null;
- public RulesProfile provide(ModuleQProfiles qProfiles, ActiveRules activeRules, Settings settings) {
+ public RulesProfile provide(ModuleQProfiles qProfiles, ActiveRules activeRules, Configuration settings) {
if (singleton == null) {
- String lang = settings.getString(CoreProperties.PROJECT_LANGUAGE_PROPERTY);
+ String lang = settings.get(CoreProperties.PROJECT_LANGUAGE_PROPERTY).orElse(null);
if (StringUtils.isNotBlank(lang)) {
// Backward-compatibility with single-language modules
singleton = loadSingleLanguageProfile(qProfiles, activeRules, lang);
*/
package org.sonar.scanner.rule;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.rules.Rule;
import org.sonar.api.utils.SonarException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
/**
* This wrapper is used to try to preserve backward compatibility for plugins that used to
* depends on {@link org.sonar.api.profiles.RulesProfile}
*/
package org.sonar.scanner.rule;
+import java.util.List;
+import org.picocontainer.injectors.ProviderAdapter;
+import org.sonar.api.batch.rule.Rules;
+import org.sonar.api.batch.rule.internal.NewRule;
+import org.sonar.api.batch.rule.internal.RulesBuilder;
+import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.api.utils.log.Profiler;
-
-import java.util.List;
-
import org.sonarqube.ws.Rules.ListResponse.Rule;
-import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.batch.rule.internal.RulesBuilder;
-import org.sonar.api.batch.rule.internal.NewRule;
-import org.sonar.api.batch.rule.Rules;
public class RulesProvider extends ProviderAdapter {
private static final Logger LOG = Loggers.get(RulesProvider.class);
*/
package org.sonar.scanner.scan;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
import java.nio.file.Path;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-
import javax.annotation.CheckForNull;
-
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.InputModule;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
import org.sonar.api.scan.filesystem.PathResolver;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.Multimap;
-
public class DefaultInputModuleHierarchy implements InputModuleHierarchy {
private final PathResolver pathResolver = new PathResolver();
private DefaultInputModule root;
import org.sonar.api.scan.filesystem.FileExclusions;
import org.sonar.core.platform.ComponentContainer;
import org.sonar.scanner.DefaultFileLinesContextFactory;
-import org.sonar.scanner.bootstrap.ScannerExtensionDictionnary;
import org.sonar.scanner.bootstrap.ExtensionInstaller;
import org.sonar.scanner.bootstrap.ExtensionUtils;
+import org.sonar.scanner.bootstrap.ScannerExtensionDictionnary;
import org.sonar.scanner.deprecated.DeprecatedSensorContext;
import org.sonar.scanner.deprecated.perspectives.ScannerPerspectives;
import org.sonar.scanner.events.EventBus;
// still injected by some plugins
new Project(module.definition()),
module,
- ModuleSettings.class);
+ MutableModuleSettings.class,
+ new ModuleSettingsProvider());
if (getComponentByType(AnalysisMode.class).isIssues()) {
add(IssuesPhaseExecutor.class,
*/
package org.sonar.scanner.scan;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
import java.util.Map;
-import java.util.Optional;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.config.Settings;
-import org.sonar.api.utils.MessageException;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
-import org.sonar.scanner.bootstrap.GlobalSettings;
-import org.sonar.scanner.report.AnalysisContextReportPublisher;
-import org.sonar.scanner.repository.ProjectRepositories;
+import org.sonar.api.batch.AnalysisMode;
+import org.sonar.api.config.Encryption;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.scanner.config.DefaultConfiguration;
-/**
- * @since 2.12
- */
-public class ModuleSettings extends Settings {
-
- private final ProjectRepositories projectRepos;
- private final DefaultAnalysisMode analysisMode;
- private final Map<String, String> properties = new HashMap<>();
-
- public ModuleSettings(GlobalSettings batchSettings, ProjectDefinition moduleDefinition, ProjectRepositories projectSettingsRepo,
- DefaultAnalysisMode analysisMode, AnalysisContextReportPublisher contextReportPublisher) {
- super(batchSettings.getDefinitions(), batchSettings.getEncryption());
- this.projectRepos = projectSettingsRepo;
- this.analysisMode = analysisMode;
-
- init(moduleDefinition, batchSettings);
- contextReportPublisher.dumpModuleSettings(moduleDefinition);
- }
-
- private ModuleSettings init(ProjectDefinition moduleDefinition, GlobalSettings batchSettings) {
- addProjectProperties(moduleDefinition, batchSettings);
- addBuildProperties(moduleDefinition);
- return this;
- }
-
- private void addProjectProperties(ProjectDefinition def, GlobalSettings batchSettings) {
- addProperties(batchSettings.getProperties());
- do {
- if (projectRepos.moduleExists(def.getKeyWithBranch())) {
- addProperties(projectRepos.settings(def.getKeyWithBranch()));
- break;
- }
- def = def.getParent();
- } while (def != null);
- }
+public class ModuleSettings extends DefaultConfiguration {
- private void addBuildProperties(ProjectDefinition project) {
- List<ProjectDefinition> orderedProjects = getTopDownParentProjects(project);
- for (ProjectDefinition p : orderedProjects) {
- addProperties(p.properties());
- }
+ public ModuleSettings(PropertyDefinitions propertyDefinitions, Encryption encryption, AnalysisMode mode, Map<String, String> props) {
+ super(propertyDefinitions, encryption, mode, props);
}
- /**
- * From root to given project
- */
- static List<ProjectDefinition> getTopDownParentProjects(ProjectDefinition project) {
- List<ProjectDefinition> result = new ArrayList<>();
- ProjectDefinition p = project;
- while (p != null) {
- result.add(0, p);
- p = p.getParent();
- }
- return result;
- }
-
- @Override
- protected Optional<String> get(String key) {
- if (analysisMode.isIssues() && key.endsWith(".secured") && !key.contains(".license")) {
- throw MessageException.of("Access to the secured property '" + key
- + "' is not possible in issues mode. The SonarQube plugin which requires this property must be deactivated in issues mode.");
- }
- return Optional.ofNullable(properties.get(key));
- }
-
- @Override
- protected void set(String key, String value) {
- properties.put(key, value);
- }
-
- @Override
- protected void remove(String key) {
- properties.remove(key);
- }
-
- @Override
- public Map<String, String> getProperties() {
- return properties;
- }
}
--- /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;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import org.picocontainer.injectors.ProviderAdapter;
+import org.sonar.api.batch.AnalysisMode;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.scanner.bootstrap.GlobalConfiguration;
+import org.sonar.scanner.report.AnalysisContextReportPublisher;
+import org.sonar.scanner.repository.ProjectRepositories;
+
+public class ModuleSettingsProvider extends ProviderAdapter {
+
+ private ModuleSettings projectSettings;
+
+ public ModuleSettings provide(GlobalConfiguration globalSettings, ProjectDefinition moduleDefinition, ProjectRepositories projectRepos,
+ AnalysisMode analysisMode, AnalysisContextReportPublisher contextReportPublisher) {
+ if (projectSettings == null) {
+
+ Map<String, String> settings = new LinkedHashMap<>();
+ settings.putAll(globalSettings.getProperties());
+ settings.putAll(addServerSidePropertiesIfModuleExists(projectRepos, moduleDefinition));
+ addScannerSideProperties(settings, moduleDefinition);
+ contextReportPublisher.dumpModuleSettings(moduleDefinition);
+
+ projectSettings = new ModuleSettings(globalSettings.getDefinitions(), globalSettings.getEncryption(), analysisMode, settings);
+ }
+ return projectSettings;
+ }
+
+ private Map<String, String> addServerSidePropertiesIfModuleExists(ProjectRepositories projectRepos, ProjectDefinition def) {
+ if (projectRepos.moduleExists(def.getKeyWithBranch())) {
+ return projectRepos.settings(def.getKeyWithBranch());
+ } else {
+ // Module doesn't exist on server. Try to add parent server settings as inheritance.
+ ProjectDefinition parentDef = def.getParent();
+ if (parentDef != null) {
+ return addServerSidePropertiesIfModuleExists(projectRepos, parentDef);
+ }
+ return Collections.emptyMap();
+ }
+ }
+
+ private void addScannerSideProperties(Map<String, String> settings, ProjectDefinition project) {
+ List<ProjectDefinition> orderedProjects = getTopDownParentProjects(project);
+ for (ProjectDefinition p : orderedProjects) {
+ settings.putAll(p.properties());
+ }
+ }
+
+ /**
+ * From root to given project
+ */
+ static List<ProjectDefinition> getTopDownParentProjects(ProjectDefinition project) {
+ List<ProjectDefinition> result = new ArrayList<>();
+ ProjectDefinition p = project;
+ while (p != null) {
+ result.add(0, p);
+ p = p.getParent();
+ }
+ return result;
+ }
+}
--- /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;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.config.Settings;
+import org.sonar.api.utils.MessageException;
+import org.sonar.scanner.analysis.DefaultAnalysisMode;
+import org.sonar.scanner.bootstrap.MutableGlobalSettings;
+import org.sonar.scanner.repository.ProjectRepositories;
+
+/**
+ * @deprecated since 6.5 {@link ModuleSettings} used to be mutable, so keep a mutable copy for backward compatibility.
+ */
+@Deprecated
+public class MutableModuleSettings extends Settings {
+
+ private final ProjectRepositories projectRepos;
+ private final DefaultAnalysisMode analysisMode;
+ private final Map<String, String> properties = new HashMap<>();
+
+ public MutableModuleSettings(MutableGlobalSettings batchSettings, ProjectDefinition moduleDefinition, ProjectRepositories projectSettingsRepo,
+ DefaultAnalysisMode analysisMode) {
+ super(batchSettings.getDefinitions(), batchSettings.getEncryption());
+ this.projectRepos = projectSettingsRepo;
+ this.analysisMode = analysisMode;
+
+ init(moduleDefinition, batchSettings);
+ }
+
+ private MutableModuleSettings init(ProjectDefinition moduleDefinition, MutableGlobalSettings batchSettings) {
+ addProjectProperties(moduleDefinition, batchSettings);
+ addBuildProperties(moduleDefinition);
+ return this;
+ }
+
+ private void addProjectProperties(ProjectDefinition def, MutableGlobalSettings batchSettings) {
+ addProperties(batchSettings.getProperties());
+ do {
+ if (projectRepos.moduleExists(def.getKeyWithBranch())) {
+ addProperties(projectRepos.settings(def.getKeyWithBranch()));
+ break;
+ }
+ def = def.getParent();
+ } while (def != null);
+ }
+
+ private void addBuildProperties(ProjectDefinition project) {
+ List<ProjectDefinition> orderedProjects = getTopDownParentProjects(project);
+ for (ProjectDefinition p : orderedProjects) {
+ addProperties(p.properties());
+ }
+ }
+
+ /**
+ * From root to given project
+ */
+ static List<ProjectDefinition> getTopDownParentProjects(ProjectDefinition project) {
+ List<ProjectDefinition> result = new ArrayList<>();
+ ProjectDefinition p = project;
+ while (p != null) {
+ result.add(0, p);
+ p = p.getParent();
+ }
+ return result;
+ }
+
+ @Override
+ protected Optional<String> get(String key) {
+ if (analysisMode.isIssues() && key.endsWith(".secured") && !key.contains(".license")) {
+ throw MessageException.of("Access to the secured property '" + key
+ + "' is not possible in issues mode. The SonarQube plugin which requires this property must be deactivated in issues mode.");
+ }
+ return Optional.ofNullable(properties.get(key));
+ }
+
+ @Override
+ protected void set(String key, String value) {
+ properties.put(key, value);
+ }
+
+ @Override
+ protected void remove(String key) {
+ properties.remove(key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+}
--- /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;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.config.Settings;
+import org.sonar.api.utils.MessageException;
+import org.sonar.scanner.analysis.DefaultAnalysisMode;
+import org.sonar.scanner.bootstrap.MutableGlobalSettings;
+import org.sonar.scanner.repository.ProjectRepositories;
+
+/**
+ * @deprecated since 6.5 {@link ProjectSettings} used to be mutable, so keep a mutable copy for backward compatibility.
+ */
+@Deprecated
+public class MutableProjectSettings extends Settings {
+
+ private final DefaultAnalysisMode mode;
+ private final Map<String, String> properties = new HashMap<>();
+
+ public MutableProjectSettings(ProjectReactor reactor, MutableGlobalSettings mutableGlobalSettings, ProjectRepositories projectRepositories, DefaultAnalysisMode mode) {
+ super(mutableGlobalSettings.getDefinitions(), mutableGlobalSettings.getEncryption());
+ this.mode = mode;
+ addProperties(mutableGlobalSettings.getProperties());
+ addProperties(projectRepositories.settings(reactor.getRoot().getKeyWithBranch()));
+ addProperties(reactor.getRoot().properties());
+ }
+
+ @Override
+ protected Optional<String> get(String key) {
+ if (mode.isIssues() && key.endsWith(".secured") && !key.contains(".license")) {
+ throw MessageException.of("Access to the secured property '" + key
+ + "' is not possible in issues mode. The SonarQube plugin which requires this property must be deactivated in issues mode.");
+ }
+ return Optional.ofNullable(properties.get(key));
+ }
+
+ @Override
+ protected void set(String key, String value) {
+ properties.put(key, value);
+ }
+
+ @Override
+ protected void remove(String key) {
+ properties.remove(key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+}
package org.sonar.scanner.scan;
import java.lang.reflect.Method;
-
import org.sonar.api.batch.bootstrap.ProjectBuilder;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.batch.bootstrap.internal.ProjectBuilderContext;
*/
package org.sonar.scanner.scan;
-import org.sonar.home.cache.DirectoryLock;
-import org.sonar.scanner.bootstrap.Slf4jLogger;
-import org.picocontainer.Startable;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
-
import java.io.IOException;
import java.nio.channels.OverlappingFileLockException;
import java.nio.file.Files;
import java.nio.file.Path;
+import org.picocontainer.Startable;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.home.cache.DirectoryLock;
+import org.sonar.scanner.bootstrap.Slf4jLogger;
public class ProjectLock implements Startable {
private final DirectoryLock lock;
*/
package org.sonar.scanner.scan;
-import org.sonar.api.utils.MessageException;
import com.google.common.base.Joiner;
-
import java.util.ArrayList;
import java.util.List;
-
import javax.annotation.Nullable;
-
import org.apache.commons.lang.StringUtils;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.config.Settings;
+import org.sonar.api.utils.MessageException;
import org.sonar.core.component.ComponentKeys;
import org.sonar.scanner.analysis.DefaultAnalysisMode;
package org.sonar.scanner.scan;
import com.google.common.annotations.VisibleForTesting;
-
import org.apache.commons.lang.StringUtils;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.InstantiationStrategy;
ContextPropertiesCache.class,
ContextPropertiesPublisher.class,
- ProjectSettings.class,
+ MutableProjectSettings.class,
+ new ProjectSettingsProvider(),
// Report
ScannerMetrics.class,
*/
package org.sonar.scanner.scan;
-import java.util.HashMap;
import java.util.Map;
-import java.util.Optional;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.api.config.Settings;
-import org.sonar.api.utils.MessageException;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
-import org.sonar.scanner.bootstrap.GlobalSettings;
-import org.sonar.scanner.repository.ProjectRepositories;
+import org.sonar.api.batch.AnalysisMode;
+import org.sonar.api.config.Encryption;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.scanner.config.DefaultConfiguration;
-public class ProjectSettings extends Settings {
+public class ProjectSettings extends DefaultConfiguration {
- private final GlobalSettings globalSettings;
- private final ProjectRepositories projectRepositories;
- private final DefaultAnalysisMode mode;
- private final Map<String, String> properties = new HashMap<>();
-
- public ProjectSettings(ProjectReactor reactor, GlobalSettings globalSettings, ProjectRepositories projectRepositories, DefaultAnalysisMode mode) {
- super(globalSettings.getDefinitions(), globalSettings.getEncryption());
- this.mode = mode;
- this.globalSettings = globalSettings;
- this.projectRepositories = projectRepositories;
- init(reactor);
- }
-
- private void init(ProjectReactor reactor) {
- addProperties(globalSettings.getProperties());
-
- addProperties(projectRepositories.settings(reactor.getRoot().getKeyWithBranch()));
-
- addProperties(reactor.getRoot().properties());
- }
-
- @Override
- protected Optional<String> get(String key) {
- if (mode.isIssues() && key.endsWith(".secured") && !key.contains(".license")) {
- throw MessageException.of("Access to the secured property '" + key
- + "' is not possible in issues mode. The SonarQube plugin which requires this property must be deactivated in issues mode.");
- }
- return Optional.ofNullable(properties.get(key));
- }
-
- @Override
- protected void set(String key, String value) {
- properties.put(key, value);
+ public ProjectSettings(PropertyDefinitions propertyDefinitions, Encryption encryption, AnalysisMode mode, Map<String, String> props) {
+ super(propertyDefinitions, encryption, mode, props);
}
- @Override
- protected void remove(String key) {
- properties.remove(key);
- }
-
- @Override
- public Map<String, String> getProperties() {
- return properties;
- }
}
--- /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;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.picocontainer.injectors.ProviderAdapter;
+import org.sonar.api.batch.AnalysisMode;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.scanner.bootstrap.GlobalConfiguration;
+import org.sonar.scanner.repository.ProjectRepositories;
+
+public class ProjectSettingsProvider extends ProviderAdapter {
+
+ private ProjectSettings projectSettings;
+
+ public ProjectSettings provide(ProjectReactor reactor, GlobalConfiguration globalSettings, ProjectRepositories projectRepositories, AnalysisMode mode) {
+ if (projectSettings == null) {
+
+ Map<String, String> settings = new LinkedHashMap<>();
+ settings.putAll(globalSettings.getProperties());
+ settings.putAll(projectRepositories.settings(reactor.getRoot().getKeyWithBranch()));
+ settings.putAll(reactor.getRoot().properties());
+
+ projectSettings = new ProjectSettings(globalSettings.getDefinitions(), globalSettings.getEncryption(), mode, settings);
+ }
+ return projectSettings;
+ }
+}
*/
package org.sonar.scanner.scan;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.core.util.FileUtils;
-import org.sonar.home.cache.DirectoryLock;
-
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Iterator;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.core.util.FileUtils;
+import org.sonar.home.cache.DirectoryLock;
public class WorkDirectoryCleaner {
private Path workDir;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
-
import org.sonar.api.batch.fs.InputComponent;
/**
*/
package org.sonar.scanner.scan.filesystem;
-import static java.nio.charset.StandardCharsets.UTF_16;
-import static java.nio.charset.StandardCharsets.UTF_16LE;
-import static java.nio.charset.StandardCharsets.UTF_16BE;
-import static java.nio.charset.StandardCharsets.UTF_8;
-
import java.nio.charset.Charset;
import java.util.Arrays;
-
import javax.annotation.CheckForNull;
-
import org.apache.commons.io.ByteOrderMark;
import org.sonar.scanner.scan.filesystem.CharsetValidation.Result;
import org.sonar.scanner.scan.filesystem.CharsetValidation.Validation;
+import static java.nio.charset.StandardCharsets.UTF_16;
+import static java.nio.charset.StandardCharsets.UTF_16BE;
+import static java.nio.charset.StandardCharsets.UTF_16LE;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
public class ByteCharsetDetector {
// these needs to be sorted by longer first!
private static final ByteOrderMark[] boms = {ByteOrderMark.UTF_8, ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE,
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
-
import javax.annotation.CheckForNull;
-
import org.apache.commons.io.ByteOrderMark;
import org.apache.commons.io.IOUtils;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.api.utils.MessageException;
import org.sonar.scanner.analysis.DefaultAnalysisMode;
import org.sonar.scanner.repository.ProjectRepositories;
private String moduleKey;
private FileIndexer indexer;
- private Settings settings;
+ private Configuration settings;
private List<File> sourceDirsOrFiles = new ArrayList<>();
private List<File> testDirsOrFiles = new ArrayList<>();
private Charset charset = null;
public DefaultModuleFileSystem(ModuleInputComponentStore moduleInputFileCache, DefaultInputModule module,
- Settings settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, DefaultAnalysisMode mode,
+ Configuration settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, DefaultAnalysisMode mode,
ProjectRepositories projectRepositories) {
super(initializer.baseDir(), moduleInputFileCache);
setFields(module, settings, indexer, initializer, mode, projectRepositories);
@VisibleForTesting
public DefaultModuleFileSystem(DefaultInputModule module,
- Settings settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, DefaultAnalysisMode mode,
+ Configuration settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, DefaultAnalysisMode mode,
ProjectRepositories projectRepositories) {
super(initializer.baseDir().toPath());
setFields(module, settings, indexer, initializer, mode, projectRepositories);
}
private void setFields(DefaultInputModule module,
- Settings settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, DefaultAnalysisMode mode,
+ Configuration settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, DefaultAnalysisMode mode,
ProjectRepositories projectRepositories) {
this.moduleKey = module.key();
this.settings = settings;
@Override
public Charset encoding() {
if (charset == null) {
- String encoding = settings.getString(CoreProperties.ENCODING_PROPERTY);
+ String encoding = settings.get(CoreProperties.ENCODING_PROPERTY).orElse(null);
if (StringUtils.isNotEmpty(encoding)) {
charset = Charset.forName(StringUtils.trim(encoding));
} else {
*/
package org.sonar.scanner.scan.filesystem;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystemLoopException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.ScannerSide;
import org.sonar.api.batch.fs.IndexedFile;
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.batch.fs.InputFileFilter;
import org.sonar.api.utils.MessageException;
import org.sonar.scanner.scan.DefaultComponentTree;
import org.sonar.scanner.util.ProgressReport;
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
-
/**
* Index input files into {@link InputComponentStore}.
*/
import java.nio.charset.Charset;
import java.nio.file.Path;
-
import javax.annotation.CheckForNull;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultIndexedFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.api.scan.filesystem.PathResolver;
public class InputFileBuilder {
private final boolean preloadMetadata;
public InputFileBuilder(DefaultInputModule module, PathResolver pathResolver, LanguageDetection langDetection, MetadataGenerator metadataGenerator,
- BatchIdGenerator idGenerator, Settings settings) {
+ BatchIdGenerator idGenerator, Configuration settings) {
this.moduleKey = module.key();
this.moduleBaseDir = module.definition().getBaseDir().toPath();
this.pathResolver = pathResolver;
this.langDetection = langDetection;
this.metadataGenerator = metadataGenerator;
this.idGenerator = idGenerator;
- this.preloadMetadata = settings.getBoolean(PRELOAD_FILE_METADATA_KEY);
+ this.preloadMetadata = settings.getBoolean(PRELOAD_FILE_METADATA_KEY).orElse(false);
}
@CheckForNull
import org.sonar.api.batch.ScannerSide;
import org.sonar.api.batch.fs.internal.DefaultIndexedFile;
import org.sonar.api.batch.fs.internal.PathPattern;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.api.utils.MessageException;
import org.sonar.scanner.repository.language.Language;
import org.sonar.scanner.repository.language.LanguagesRepository;
private final List<String> languagesToConsider = new ArrayList<>();
private final String forcedLanguage;
- public LanguageDetection(Settings settings, LanguagesRepository languages) {
+ public LanguageDetection(Configuration settings, LanguagesRepository languages) {
for (Language language : languages.all()) {
String[] filePatterns = settings.getStringArray(getFileLangPatternPropKey(language.key()));
PathPattern[] pathPatterns = PathPattern.create(filePatterns);
}
}
- forcedLanguage = StringUtils.defaultIfBlank(settings.getString(CoreProperties.PROJECT_LANGUAGE_PROPERTY), null);
+ forcedLanguage = StringUtils.defaultIfBlank(settings.get(CoreProperties.PROJECT_LANGUAGE_PROPERTY).orElse(null), null);
// First try with lang patterns
if (forcedLanguage != null) {
if (!patternsByLanguage.containsKey(forcedLanguage)) {
*/
package org.sonar.scanner.scan.filesystem;
+import com.google.common.annotations.VisibleForTesting;
import java.io.InputStream;
import java.nio.charset.Charset;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.InputFile.Type;
import org.sonar.api.batch.fs.internal.Metadata;
import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader;
-import com.google.common.annotations.VisibleForTesting;
-
class MetadataGenerator {
private static final Logger LOG = LoggerFactory.getLogger(MetadataGenerator.class);
@VisibleForTesting
package org.sonar.scanner.scan.filesystem;
import java.util.function.Predicate;
-
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.measure.MetricFinder;
import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
import org.sonar.scanner.storage.Storage;
-import org.sonar.scanner.storage.Storages;
import org.sonar.scanner.storage.Storage.Entry;
+import org.sonar.scanner.storage.Storages;
/**
* Cache of all measures. This cache is shared amongst all project modules.
import org.sonar.api.Properties;
import org.sonar.api.Property;
import org.sonar.api.PropertyType;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.api.rule.Severity;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
public static final String CONSOLE_REPORT_ENABLED_KEY = "sonar.issuesReport.console.enable";
private static final int LEFT_PAD = 10;
- private Settings settings;
+ private Configuration settings;
private IssueCache issueCache;
private InputComponentStore componentStore;
@VisibleForTesting
- public ConsoleReport(Settings settings, IssueCache issueCache, InputComponentStore componentStore) {
+ public ConsoleReport(Configuration settings, IssueCache issueCache, InputComponentStore componentStore) {
this.settings = settings;
this.issueCache = issueCache;
this.componentStore = componentStore;
@Override
public void execute() {
- if (settings.getBoolean(CONSOLE_REPORT_ENABLED_KEY)) {
+ if (settings.getBoolean(CONSOLE_REPORT_ENABLED_KEY).orElse(false)) {
LOG.warn("Console report is deprecated. Use SonarLint CLI to have local reports of issues");
Report r = new Report();
r.setNoFile(!componentStore.allFilesToPublish().iterator().hasNext());
import org.sonar.api.Property;
import org.sonar.api.PropertyType;
import org.sonar.api.batch.fs.FileSystem;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
+import org.sonar.api.utils.MessageException;
@Properties({
@Property(key = HtmlReport.HTML_REPORT_ENABLED_KEY, defaultValue = "false", name = "Enable HTML report", description = "Set this to true to generate an HTML report",
public static final String HTML_REPORT_NAME_DEFAULT = "issues-report";
public static final String HTML_REPORT_LIGHTMODE_ONLY = "sonar.issuesReport.lightModeOnly";
- private final Settings settings;
+ private final Configuration settings;
private final FileSystem fs;
private final IssuesReportBuilder builder;
private final SourceProvider sourceProvider;
private final RuleNameProvider ruleNameProvider;
- public HtmlReport(Settings settings, FileSystem fs, IssuesReportBuilder builder, SourceProvider sourceProvider, RuleNameProvider ruleNameProvider) {
+ public HtmlReport(Configuration settings, FileSystem fs, IssuesReportBuilder builder, SourceProvider sourceProvider, RuleNameProvider ruleNameProvider) {
this.settings = settings;
this.fs = fs;
this.builder = builder;
@Override
public void execute() {
- if (settings.getBoolean(HTML_REPORT_ENABLED_KEY)) {
+ if (settings.getBoolean(HTML_REPORT_ENABLED_KEY).orElse(false)) {
LOG.warn("HTML report is deprecated. Use SonarLint CLI to have local reports of issues");
IssuesReport report = builder.buildReport();
print(report);
public void print(IssuesReport report) {
File reportFileDir = getReportFileDir();
- String reportName = settings.getString(HTML_REPORT_NAME_KEY);
+ String reportName = settings.get(HTML_REPORT_NAME_KEY).orElseThrow(() -> MessageException.of("Missing report name. Please set property '" + HTML_REPORT_NAME_KEY + "'"));
if (!isLightModeOnly()) {
File reportFile = new File(reportFileDir, reportName + ".html");
LOG.debug("Generating HTML Report to: " + reportFile.getAbsolutePath());
}
private File getReportFileDir() {
- String reportFileDirStr = settings.getString(HTML_REPORT_LOCATION_KEY);
+ String reportFileDirStr = settings.get(HTML_REPORT_LOCATION_KEY)
+ .orElseThrow(() -> MessageException.of("Missing report location. Please set property '" + HTML_REPORT_LOCATION_KEY + "'"));
File reportFileDir = new File(reportFileDirStr);
if (!reportFileDir.isAbsolute()) {
reportFileDir = new File(fs.workDir(), reportFileDirStr);
}
public boolean isLightModeOnly() {
- return settings.getBoolean(HTML_REPORT_LIGHTMODE_ONLY);
+ return settings.getBoolean(HTML_REPORT_LIGHTMODE_ONLY).orElse(false);
}
}
import java.util.Date;
import java.util.List;
import java.util.Map;
-
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.rule.Rule;
import org.sonar.api.rules.RulePriority;
import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
import org.sonar.api.batch.rule.Rule;
import org.sonar.api.batch.rule.Rules;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.api.platform.Server;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.text.JsonWriter;
static final String SONAR_REPORT_EXPORT_PATH = "sonar.report.export.path";
private static final Logger LOG = LoggerFactory.getLogger(JSONReport.class);
- private final Settings settings;
+ private final Configuration settings;
private final FileSystem fileSystem;
private final Server server;
private final Rules rules;
private final InputModuleHierarchy moduleHierarchy;
private final InputComponentTree inputComponentTree;
- public JSONReport(InputModuleHierarchy moduleHierarchy, Settings settings, FileSystem fileSystem, Server server, Rules rules, IssueCache issueCache,
+ public JSONReport(InputModuleHierarchy moduleHierarchy, Configuration settings, FileSystem fileSystem, Server server, Rules rules, IssueCache issueCache,
DefaultInputModule rootModule, InputComponentStore componentStore, InputComponentTree inputComponentTree) {
this.moduleHierarchy = moduleHierarchy;
this.settings = settings;
@Override
public void execute() {
- String exportPath = settings.getString(SONAR_REPORT_EXPORT_PATH);
- if (exportPath != null) {
- exportResults(exportPath);
- }
+ settings.get(SONAR_REPORT_EXPORT_PATH).ifPresent(this::exportResults);
}
private void exportResults(String exportPath) {
*/
package org.sonar.scanner.scan.report;
-import org.sonar.api.batch.rule.Rule;
-
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
+import org.sonar.api.batch.rule.Rule;
import org.sonar.api.rules.RulePriority;
/**
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nullable;
-
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.fs.InputDir;
import org.sonar.api.batch.fs.InputFile;
*/
package org.sonar.scanner.scan.report;
-import org.sonar.api.batch.rule.Rule;
-
-import org.sonar.api.batch.rule.Rules;
+import javax.annotation.CheckForNull;
import org.apache.commons.lang.StringEscapeUtils;
import org.sonar.api.batch.ScannerSide;
+import org.sonar.api.batch.rule.Rule;
+import org.sonar.api.batch.rule.Rules;
import org.sonar.api.rule.RuleKey;
-import javax.annotation.CheckForNull;
-
@ScannerSide
public class RuleNameProvider {
private Rules rules;
*/
package org.sonar.scanner.scan.report;
-import org.sonar.api.batch.rule.Rule;
-
import org.apache.commons.lang.builder.ToStringBuilder;
+import org.sonar.api.batch.rule.Rule;
public final class RuleReport {
private final ReportRuleKey reportRuleKey;
import org.sonar.api.utils.log.Loggers;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReport.Changesets.Builder;
-import org.sonar.scanner.util.ProgressReport;
import org.sonar.scanner.protocol.output.ScannerReportWriter;
+import org.sonar.scanner.util.ProgressReport;
class DefaultBlameOutput implements BlameOutput {
import org.sonar.api.Property;
import org.sonar.api.PropertyType;
import org.sonar.api.batch.AnalysisMode;
-import org.sonar.api.batch.ScannerSide;
import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.batch.ScannerSide;
import org.sonar.api.batch.scm.ScmProvider;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.scanner.scan.ImmutableProjectReactor;
public static final String FORCE_RELOAD_KEY = "sonar.scm.forceReloadAll";
private final ImmutableProjectReactor projectReactor;
- private final Settings settings;
+ private final Configuration settings;
private final Map<String, ScmProvider> providerPerKey = new LinkedHashMap<>();
private final AnalysisMode analysisMode;
private ScmProvider provider;
- public ScmConfiguration(ImmutableProjectReactor projectReactor, AnalysisMode analysisMode, Settings settings, ScmProvider... providers) {
+ public ScmConfiguration(ImmutableProjectReactor projectReactor, AnalysisMode analysisMode, Configuration settings, ScmProvider... providers) {
this.projectReactor = projectReactor;
this.analysisMode = analysisMode;
this.settings = settings;
}
}
- public ScmConfiguration(ImmutableProjectReactor projectReactor, AnalysisMode analysisMode, Settings settings) {
+ public ScmConfiguration(ImmutableProjectReactor projectReactor, AnalysisMode analysisMode, Configuration settings) {
this(projectReactor, analysisMode, settings, new ScmProvider[0]);
}
return;
}
if (settings.hasKey(CoreProperties.SCM_PROVIDER_KEY)) {
- String forcedProviderKey = settings.getString(CoreProperties.SCM_PROVIDER_KEY);
- setProviderIfSupported(forcedProviderKey);
+ settings.get(CoreProperties.SCM_PROVIDER_KEY).ifPresent(this::setProviderIfSupported);
} else {
autodetection();
if (this.provider == null) {
}
private void considerOldScmUrl() {
- if (settings.hasKey(CoreProperties.LINKS_SOURCES_DEV)) {
- String url = settings.getString(CoreProperties.LINKS_SOURCES_DEV);
+ settings.get(CoreProperties.LINKS_SOURCES_DEV).ifPresent(url -> {
if (StringUtils.startsWith(url, "scm:")) {
String[] split = url.split(":");
if (split.length > 1) {
setProviderIfSupported(split[1]);
}
}
- }
-
+ });
}
private void autodetection() {
}
public boolean isDisabled() {
- return settings.getBoolean(CoreProperties.SCM_DISABLED_KEY);
+ return settings.getBoolean(CoreProperties.SCM_DISABLED_KEY).orElse(false);
}
public boolean forceReloadAll() {
- return settings.getBoolean(FORCE_RELOAD_KEY);
+ return settings.getBoolean(FORCE_RELOAD_KEY).orElse(false);
}
@Override
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.scanner.protocol.output.ScannerReport;
+import org.sonar.scanner.protocol.output.ScannerReport.Changesets.Builder;
import org.sonar.scanner.protocol.output.ScannerReportWriter;
import org.sonar.scanner.report.ReportPublisher;
-import org.sonar.scanner.protocol.output.ScannerReport.Changesets.Builder;
import org.sonar.scanner.repository.FileData;
import org.sonar.scanner.repository.ProjectRepositories;
import org.sonar.scanner.scan.filesystem.DefaultModuleFileSystem;
import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
import org.sonar.api.batch.sensor.symbol.NewSymbolTable;
import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable;
+import org.sonar.api.config.Configuration;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.Version;
import org.sonar.scanner.sensor.noop.NoOpNewAnalysisError;
private static final NoOpNewCpdTokens NO_OP_NEW_CPD_TOKENS = new NoOpNewCpdTokens();
private static final NoOpNewAnalysisError NO_OP_NEW_ANALYSIS_ERROR = new NoOpNewAnalysisError();
- private final Settings settings;
+ private final Settings mutableSettings;
private final FileSystem fs;
private final ActiveRules activeRules;
private final SensorStorage sensorStorage;
private final AnalysisMode analysisMode;
private final InputModule module;
private final SonarRuntime sonarRuntime;
+ private final Configuration config;
- public DefaultSensorContext(InputModule module, Settings settings, FileSystem fs, ActiveRules activeRules, AnalysisMode analysisMode, SensorStorage sensorStorage,
+ public DefaultSensorContext(InputModule module, Configuration config, Settings mutableSettings, FileSystem fs, ActiveRules activeRules,
+ AnalysisMode analysisMode, SensorStorage sensorStorage,
SonarRuntime sonarRuntime) {
this.module = module;
- this.settings = settings;
+ this.config = config;
+ this.mutableSettings = mutableSettings;
this.fs = fs;
this.activeRules = activeRules;
this.analysisMode = analysisMode;
@Override
public Settings settings() {
- return settings;
+ return mutableSettings;
+ }
+
+ @Override
+ public Configuration config() {
+ return config;
}
@Override
if (analysisMode.isIssues()) {
return NO_OP_NEW_CPD_TOKENS;
}
- return new DefaultCpdTokens(settings, sensorStorage);
+ return new DefaultCpdTokens(config, sensorStorage);
}
@Override
import org.sonar.api.batch.sensor.measure.Measure;
import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.utils.KeyValueFormat;
import org.sonar.api.utils.log.Logger;
private final MeasureCache measureCache;
private final SonarCpdBlockIndex index;
private final ContextPropertiesCache contextPropertiesCache;
- private final Settings settings;
+ private final Configuration settings;
private final ScannerMetrics scannerMetrics;
private final Map<Metric<?>, Metric<?>> deprecatedCoverageMetricMapping = new HashMap<>();
private final Set<Metric<?>> coverageMetrics = new HashSet<>();
private Set<String> alreadyLogged = new HashSet<>();
public DefaultSensorStorage(MetricFinder metricFinder, ModuleIssues moduleIssues,
- Settings settings,
+ Configuration settings,
CoverageExclusions coverageExclusions, ReportPublisher reportPublisher,
MeasureCache measureCache, SonarCpdBlockIndex index,
ContextPropertiesCache contextPropertiesCache, ScannerMetrics scannerMetrics) {
if (component.isFile()) {
((DefaultInputFile) component).setPublish(true);
}
-
+
if (isDeprecatedMetric(measure.metric().key())) {
logOnce(measure.metric().key(), "Metric '{}' is deprecated. Provided value is ignored.", measure.metric().key());
return;
@VisibleForTesting
int getBlockSize(String languageKey) {
- int blockSize = settings.getInt("sonar.cpd." + languageKey + ".minimumLines");
- if (blockSize == 0) {
- blockSize = DefaultCpdBlockIndexer.getDefaultBlockSize(languageKey);
- }
- return blockSize;
+ return settings.getInt("sonar.cpd." + languageKey + ".minimumLines").orElse(DefaultCpdBlockIndexer.getDefaultBlockSize(languageKey));
}
@Override
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
@ScannerSide
public class SensorOptimizer {
private final FileSystem fs;
private final ActiveRules activeRules;
- private final Settings settings;
+ private final Configuration config;
- public SensorOptimizer(FileSystem fs, ActiveRules activeRules, Settings settings) {
+ public SensorOptimizer(FileSystem fs, ActiveRules activeRules, Configuration config) {
this.fs = fs;
this.activeRules = activeRules;
- this.settings = settings;
+ this.config = config;
}
/**
private boolean settingsCondition(DefaultSensorDescriptor descriptor) {
if (!descriptor.properties().isEmpty()) {
for (String propertyKey : descriptor.properties()) {
- if (!settings.hasKey(propertyKey)) {
+ if (!config.hasKey(propertyKey)) {
return false;
}
}
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
import org.sonar.api.utils.WildcardPattern;
public class CoverageExclusions implements Startable {
private static final Logger LOG = LoggerFactory.getLogger(CoverageExclusions.class);
- private final Settings settings;
+ private final Configuration settings;
private Collection<WildcardPattern> exclusionPatterns;
- public CoverageExclusions(Settings settings) {
+ public CoverageExclusions(Configuration settings) {
this.settings = settings;
}
*/
package org.sonar.scanner.source;
+import com.google.common.collect.Sets;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.StreamSupport;
-
import org.sonar.api.batch.Phase;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.scanner.scan.measure.MeasureCache;
import org.sonar.scanner.sensor.coverage.CoverageExclusions;
-import com.google.common.collect.Sets;
-
@Phase(name = Phase.Name.POST)
public final class ZeroCoverageSensor implements Sensor {
import com.persistit.encoding.CoderManager;
import com.persistit.encoding.ValueCoder;
import com.persistit.exception.PersistitException;
-
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.InstantiationStrategy;
-import org.sonar.api.config.EmailSettings;
import org.sonar.api.task.Task;
import org.sonar.api.task.TaskDefinition;
import org.sonar.api.utils.MessageException;
private void addCoreComponents() {
add(new TaskProperties(taskProperties, getParent().getComponentByType(GlobalProperties.class).property(CoreProperties.ENCRYPTION_SECRET_KEY_PATH)));
- add(EmailSettings.class);
}
private void addTaskExtensions() {
import java.util.Collection;
import java.util.Map;
import java.util.SortedMap;
-import org.sonar.api.batch.ScannerSide;
import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.batch.ScannerSide;
import org.sonar.api.task.Task;
import org.sonar.api.task.TaskDefinition;
package org.sonar.batch.bootstrapper;
import org.junit.Test;
-import org.sonar.batch.bootstrapper.Batch;
-import org.sonar.batch.bootstrapper.EnvironmentInformation;
-import org.sonar.batch.bootstrapper.LogOutput;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
package org.sonar.batch.bootstrapper;
import org.junit.Test;
-import org.sonar.batch.bootstrapper.EnvironmentInformation;
import static org.assertj.core.api.Assertions.assertThat;
import ch.qos.logback.classic.spi.ILoggingEvent;
import org.junit.Before;
import org.junit.Test;
-import org.sonar.batch.bootstrapper.LogCallbackAppender;
-import org.sonar.batch.bootstrapper.LogOutput;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
*/
package org.sonar.scanner;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
-
import org.junit.Test;
import org.sonar.api.CoreProperties;
-import org.sonar.api.config.MapSettings;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.System2;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
public class ProjectAnalysisInfoTest {
@Test
public void testSimpleDate() {
- Settings settings = new MapSettings();
+ MapSettings settings = new MapSettings();
settings.appendProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01");
settings.appendProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "version");
System2 system = mock(System2.class);
- ProjectAnalysisInfo info = new ProjectAnalysisInfo(settings, system);
+ ProjectAnalysisInfo info = new ProjectAnalysisInfo(settings.asConfig(), system);
info.start();
LocalDate date = LocalDate.of(2017, 1, 1);
*/
package org.sonar.scanner;
+import java.io.InputStream;
+import java.io.Reader;
import org.apache.commons.lang.StringUtils;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.sonarqube.ws.client.WsRequest;
import org.sonarqube.ws.client.WsResponse;
-import java.io.InputStream;
-import java.io.Reader;
-
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.mock;
*/
package org.sonar.scanner.analysis;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-
-import org.sonar.api.batch.bootstrap.ProjectReactor;
+import java.io.File;
+import java.io.IOException;
import org.junit.Before;
-import org.sonar.api.utils.TempFolder;
-import org.sonar.scanner.analysis.AnalysisTempFolderProvider;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.utils.TempFolder;
-import java.io.File;
-import java.io.IOException;
-
-import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.mock;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class AnalysisTempFolderProviderTest {
*/
package org.sonar.scanner.analysis;
-import org.junit.Rule;
-import org.junit.rules.ExpectedException;
+import java.util.HashMap;
+import java.util.Map;
import javax.annotation.Nullable;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.sonar.api.CoreProperties;
-import org.sonar.scanner.analysis.AnalysisProperties;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
import org.sonar.scanner.bootstrap.GlobalProperties;
-import java.util.HashMap;
-import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
-import org.sonar.scanner.bootstrap.DroppedPropertyChecker;
import static org.assertj.core.api.Assertions.assertThat;
import org.sonar.api.batch.ScannerSide;
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.server.ServerSide;
-import org.sonar.scanner.bootstrap.ExtensionUtils;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.home.cache.FileCache;
import static org.assertj.core.api.Assertions.assertThat;
@Test
public void provide() {
FileCacheProvider provider = new FileCacheProvider();
- FileCache cache = provider.provide(new MapSettings());
+ FileCache cache = provider.provide(new MapSettings().asConfig());
assertThat(cache).isNotNull();
assertThat(cache.getDir()).isNotNull().exists();
@Test
public void keep_singleton_instance() {
FileCacheProvider provider = new FileCacheProvider();
- Settings settings = new MapSettings();
- FileCache cache1 = provider.provide(settings);
- FileCache cache2 = provider.provide(settings);
+ MapSettings settings = new MapSettings();
+ FileCache cache1 = provider.provide(settings.asConfig());
+ FileCache cache2 = provider.provide(settings.asConfig());
assertThat(cache1).isSameAs(cache2);
}
@Test
public void honor_sonarUserHome() throws IOException {
FileCacheProvider provider = new FileCacheProvider();
- Settings settings = new MapSettings();
+ MapSettings settings = new MapSettings();
File f = temp.newFolder();
settings.appendProperty("sonar.userHome", f.getAbsolutePath());
- FileCache cache = provider.provide(settings);
+ FileCache cache = provider.provide(settings.asConfig());
assertThat(cache.getDir()).isEqualTo(new File(f, "cache"));
}
--- /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.bootstrap;
+
+import com.google.common.collect.ImmutableMap;
+import java.util.Collections;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.api.utils.log.LogTester;
+import org.sonar.api.utils.log.LoggerLevel;
+import org.sonar.scanner.repository.settings.SettingsLoader;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class GlobalConfigurationProviderTest {
+
+ public static final String SOME_VALUE = "some_value";
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+ @Rule
+ public LogTester logTester = new LogTester();
+
+ SettingsLoader settingsLoader;
+ GlobalProperties bootstrapProps;
+
+ private GlobalMode mode;
+
+ @Before
+ public void prepare() {
+ settingsLoader = mock(SettingsLoader.class);
+ bootstrapProps = new GlobalProperties(Collections.<String, String>emptyMap());
+ mode = mock(GlobalMode.class);
+ }
+
+ @Test
+ public void should_load_global_settings() {
+ when(settingsLoader.load(null)).thenReturn(ImmutableMap.of("sonar.cpd.cross", "true"));
+
+ GlobalConfiguration globalConfig = new GlobalConfigurationProvider().provide(settingsLoader, bootstrapProps, new PropertyDefinitions(), mode);
+
+ assertThat(globalConfig.get("sonar.cpd.cross")).hasValue("true");
+ }
+
+ @Test
+ public void should_log_warn_msg_for_each_jdbc_property_if_present() {
+ when(settingsLoader.load(null)).thenReturn(ImmutableMap.of("sonar.jdbc.url", SOME_VALUE,
+ "sonar.jdbc.username", SOME_VALUE,
+ "sonar.jdbc.password", SOME_VALUE));
+
+ new GlobalConfigurationProvider().provide(settingsLoader, bootstrapProps, new PropertyDefinitions(), mode);
+
+ assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly(
+ "Property 'sonar.jdbc.url' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.",
+ "Property 'sonar.jdbc.username' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.",
+ "Property 'sonar.jdbc.password' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.");
+ }
+}
import org.sonar.api.batch.BatchSide;
import org.sonar.api.utils.TempFolder;
import org.sonar.core.util.UuidFactory;
-import org.sonar.scanner.bootstrap.GlobalContainer;
import static org.assertj.core.api.Assertions.assertThat;
*/
package org.sonar.scanner.bootstrap;
+import java.util.HashMap;
+import java.util.Map;
import org.junit.Rule;
+import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.CoreProperties;
-import org.sonar.scanner.bootstrap.GlobalMode;
-import org.sonar.scanner.bootstrap.GlobalProperties;
-import org.junit.Test;
-
-import java.util.HashMap;
-import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
package org.sonar.scanner.bootstrap;
import com.google.common.collect.Maps;
-import org.junit.Test;
-import org.sonar.scanner.bootstrap.GlobalProperties;
import java.util.Map;
+import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
+++ /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.bootstrap;
-
-import com.google.common.collect.ImmutableMap;
-import java.util.Collections;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.config.PropertyDefinitions;
-import org.sonar.api.utils.log.LogTester;
-import org.sonar.api.utils.log.LoggerLevel;
-import org.sonar.scanner.repository.settings.SettingsLoader;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class GlobalSettingsTest {
-
- public static final String SOME_VALUE = "some_value";
- @Rule
- public ExpectedException thrown = ExpectedException.none();
- @Rule
- public LogTester logTester = new LogTester();
-
- SettingsLoader settingsLoader;
- GlobalProperties bootstrapProps;
-
- private GlobalMode mode;
-
- @Before
- public void prepare() {
- settingsLoader = mock(SettingsLoader.class);
- bootstrapProps = new GlobalProperties(Collections.<String, String>emptyMap());
- mode = mock(GlobalMode.class);
- }
-
- @Test
- public void should_load_global_settings() {
- when(settingsLoader.load(null)).thenReturn(ImmutableMap.of("sonar.cpd.cross", "true"));
-
- GlobalSettings batchSettings = new GlobalSettings(bootstrapProps, new PropertyDefinitions(), settingsLoader, mode);
-
- assertThat(batchSettings.getBoolean("sonar.cpd.cross")).isTrue();
- }
-
- @Test
- public void should_log_warn_msg_for_each_jdbc_property_if_present() {
- when(settingsLoader.load(null)).thenReturn(ImmutableMap.of("sonar.jdbc.url", SOME_VALUE,
- "sonar.jdbc.username", SOME_VALUE,
- "sonar.jdbc.password", SOME_VALUE));
-
- new GlobalSettings(bootstrapProps, new PropertyDefinitions(), settingsLoader, mode);
-
- assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly(
- "Property 'sonar.jdbc.url' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.",
- "Property 'sonar.jdbc.username' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.",
- "Property 'sonar.jdbc.password' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.");
- }
-}
*/
package org.sonar.scanner.bootstrap;
-import org.sonar.api.utils.System2;
-import org.apache.commons.io.FileUtils;
-import org.sonar.api.utils.TempFolder;
-import org.sonar.scanner.bootstrap.GlobalProperties;
-import org.sonar.scanner.bootstrap.GlobalTempFolderProvider;
import com.google.common.collect.ImmutableMap;
-import org.sonar.api.CoreProperties;
-
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.attribute.FileTime;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.assertj.core.api.Assertions.assertThat;
+import org.apache.commons.io.FileUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.utils.System2;
+import org.sonar.api.utils.TempFolder;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class GlobalTempFolderProviderTest {
@Rule
*/
package org.sonar.scanner.bootstrap;
+import java.util.Arrays;
+import java.util.List;
import org.junit.Test;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Metric;
import org.sonar.api.measures.Metrics;
-import org.sonar.scanner.bootstrap.MetricProvider;
-import java.util.Arrays;
-import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import org.sonar.core.platform.PluginInfo;
import org.sonar.home.cache.FileCache;
import org.sonar.home.cache.FileCacheBuilder;
-import org.sonar.scanner.bootstrap.ScannerPluginJarExploder;
-import org.sonar.scanner.bootstrap.Slf4jLogger;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
public class ScannerPluginPredicateTest {
- Settings settings = new MapSettings();
- GlobalMode mode = mock(GlobalMode.class);
+ private MapSettings settings = new MapSettings();
+ private GlobalMode mode = mock(GlobalMode.class);
@Test
public void accept_if_no_inclusions_nor_exclusions() {
- ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings, mode);
+ ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings.asConfig(), mode);
assertThat(predicate.getWhites()).isEmpty();
assertThat(predicate.getBlacks()).isEmpty();
assertThat(predicate.apply("pmd")).isTrue();
@Test
public void exclude_buildbreaker_in_preview_mode() {
when(mode.isPreview()).thenReturn(true);
- ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings, mode);
+ ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings.asConfig(), mode);
assertThat(predicate.apply("buildbreaker")).isFalse();
}
settings
.setProperty(CoreProperties.PREVIEW_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs")
.setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "cobertura,pmd");
- ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings, mode);
+ ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings.asConfig(), mode);
assertThat(predicate.apply("pmd")).isTrue();
}
settings
.setProperty(CoreProperties.PREVIEW_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs")
.setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "cobertura");
- ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings, mode);
+ ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings.asConfig(), mode);
assertThat(predicate.apply("checkstyle")).isTrue();
assertThat(predicate.apply("pmd")).isTrue();
assertThat(predicate.apply("cobertura")).isFalse();
settings
.setProperty(CoreProperties.PREVIEW_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs")
.setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "cobertura");
- ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings, mode);
+ ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings.asConfig(), mode);
assertThat(predicate.apply("checkstyle")).isTrue();
assertThat(predicate.apply("pmd")).isTrue();
assertThat(predicate.apply("cobertura")).isFalse();
public void test_exclusions_without_any_inclusions() {
when(mode.isPreview()).thenReturn(true);
settings.setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
- ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings, mode);
+ ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings.asConfig(), mode);
assertThat(predicate.apply("checkstyle")).isFalse();
assertThat(predicate.apply("pmd")).isFalse();
assertThat(predicate.apply("cobertura")).isTrue();
settings
.setProperty(CoreProperties.PREVIEW_INCLUDE_PLUGINS, "checkstyle, pmd, findbugs")
.setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "cobertura, pmd");
- ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings, mode);
+ ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings.asConfig(), mode);
assertThat(predicate.apply("pmd")).isTrue();
}
import org.sonar.api.Plugin;
import org.sonar.core.platform.PluginInfo;
import org.sonar.core.platform.PluginLoader;
-import org.sonar.scanner.bootstrap.ScannerPluginRepository;
-import org.sonar.scanner.bootstrap.PluginInstaller;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
package org.sonar.scanner.cpd;
import org.junit.Test;
-import org.sonar.scanner.cpd.CpdComponents;
import static org.assertj.core.api.Assertions.assertThat;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
-import org.sonar.api.config.MapSettings;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import static org.mockito.Mockito.when;
public class CpdExecutorTest {
- private CpdExecutor executor;
- private Settings settings;
- private SonarCpdBlockIndex index;
- private ReportPublisher publisher;
-
@Rule
public LogTester logTester = new LogTester();
@Rule
public ExpectedException thrown = ExpectedException.none();
+ private CpdExecutor executor;
+ private MapSettings settings;
+ private SonarCpdBlockIndex index;
+ private ReportPublisher publisher;
private ScannerReportReader reader;
private DefaultInputFile batchComponent1;
private DefaultInputFile batchComponent2;
settings = new MapSettings();
publisher = mock(ReportPublisher.class);
when(publisher.getWriter()).thenReturn(new ScannerReportWriter(outputDir));
- index = new SonarCpdBlockIndex(publisher, settings);
+ index = new SonarCpdBlockIndex(publisher, settings.asConfig());
componentStore = new InputComponentStore(new PathResolver());
- executor = new CpdExecutor(settings, index, publisher, componentStore);
+ executor = new CpdExecutor(settings.asConfig(), index, publisher, componentStore);
reader = new ScannerReportReader(outputDir);
componentStore.put(TestInputFileBuilder.newDefaultInputModule("foo", baseDir));
import com.google.common.base.Predicate;
import org.junit.Test;
import org.sonar.duplications.index.CloneGroup;
-import org.sonar.scanner.cpd.DuplicationPredicates;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.log.LogTester;
import static org.assertj.core.api.Assertions.assertThat;
public class DefaultCpdBlockIndexerTest {
private DefaultCpdBlockIndexer engine;
- private Settings settings;
+ private MapSettings settings;
@Rule
public LogTester logTester = new LogTester();
@Before
public void init() {
settings = new MapSettings();
- engine = new DefaultCpdBlockIndexer(null, null, settings, null);
+ engine = new DefaultCpdBlockIndexer(null, null, settings.asConfig(), null);
}
@Test
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
-import org.sonar.api.config.MapSettings;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.duplications.block.Block;
import org.sonar.scanner.cpd.index.SonarCpdBlockIndex;
@Captor
private ArgumentCaptor<List<Block>> blockCaptor;
- private Settings settings;
+ private MapSettings settings;
private JavaCpdBlockIndexer engine;
private InputFile file;
FileUtils.copyURLToFile(this.getClass().getResource("ManyStatements.java"), ioFile);
settings = new MapSettings();
- engine = new JavaCpdBlockIndexer(fs, settings, index);
+ engine = new JavaCpdBlockIndexer(fs, settings.asConfig(), index);
}
@Test
public void languageSupported() {
- JavaCpdBlockIndexer engine = new JavaCpdBlockIndexer(mock(FileSystem.class), new MapSettings(), index);
+ JavaCpdBlockIndexer engine = new JavaCpdBlockIndexer(mock(FileSystem.class), new MapSettings().asConfig(), index);
assertThat(engine.isLanguageSupported(JAVA)).isTrue();
assertThat(engine.isLanguageSupported("php")).isFalse();
}
package org.sonar.scanner.events;
import org.junit.Test;
-import org.sonar.scanner.events.BatchStepEvent;
-import org.sonar.scanner.events.BatchStepHandler;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import org.junit.Test;
import org.sonar.api.batch.events.EventHandler;
-import org.sonar.scanner.events.BatchEvent;
-import org.sonar.scanner.events.EventBus;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.sensor.internal.SensorContextTester;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.scanner.deprecated.test.TestPlanBuilder;
*/
package org.sonar.scanner.index;
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
import org.junit.After;
-
-import org.junit.Before;
import org.junit.AfterClass;
+import org.junit.Before;
import org.junit.BeforeClass;
-import com.google.common.collect.ImmutableMap;
+import org.junit.ClassRule;
+import org.junit.rules.TemporaryFolder;
import org.sonar.api.CoreProperties;
import org.sonar.scanner.bootstrap.GlobalProperties;
import org.sonar.scanner.bootstrap.GlobalTempFolderProvider;
import org.sonar.scanner.storage.Storages;
import org.sonar.scanner.storage.StoragesManager;
-import java.util.Map;
-
-import org.junit.ClassRule;
-import org.junit.rules.TemporaryFolder;
public abstract class AbstractCachesTest {
@ClassRule
import java.io.IOException;
import java.util.Collections;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.Test;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.scanner.ProjectAnalysisInfo;
-import org.sonar.scanner.issue.DefaultFilterableIssue;
import org.sonar.scanner.protocol.Constants.Severity;
import org.sonar.scanner.protocol.output.ScannerReport.Issue;
import org.sonar.scanner.protocol.output.ScannerReport.TextRange;
*/
package org.sonar.scanner.issue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
+import com.google.common.collect.ImmutableList;
+import java.util.LinkedList;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import org.sonar.api.batch.rule.Rule;
+import org.sonar.api.batch.rule.Rules;
import org.sonar.api.rule.RuleKey;
import org.sonar.batch.bootstrapper.IssueListener;
import org.sonar.batch.bootstrapper.IssueListener.Issue;
-import org.mockito.MockitoAnnotations;
-import org.mockito.Mock;
-import org.sonar.api.batch.rule.Rules;
-import org.sonar.scanner.issue.DefaultIssueCallback;
-import org.sonar.scanner.issue.IssueCache;
import org.sonar.scanner.issue.tracking.TrackedIssue;
-import org.junit.Before;
-import com.google.common.collect.ImmutableList;
-
-import java.util.LinkedList;
-import java.util.List;
-import static org.mockito.Matchers.any;
import static org.assertj.core.api.Assertions.assertThat;
-import org.junit.Test;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class DefaultIssueCallbackTest {
@Mock
*/
package org.sonar.scanner.issue;
-import org.sonar.api.scan.issue.filter.FilterableIssue;
-
import org.junit.Test;
+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.issue.DefaultIssueFilterChain;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
package org.sonar.scanner.issue;
import com.google.common.collect.Lists;
+import java.util.Arrays;
+import java.util.List;
import org.junit.Test;
import org.sonar.api.issue.Issue;
-import org.sonar.core.issue.DefaultIssue;
-import org.sonar.scanner.issue.DefaultProjectIssues;
-import org.sonar.scanner.issue.IssueCache;
-import org.sonar.scanner.issue.tracking.TrackedIssue;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.Severity;
-
-import java.util.Arrays;
-import java.util.List;
+import org.sonar.core.issue.DefaultIssue;
+import org.sonar.scanner.issue.tracking.TrackedIssue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import org.sonar.api.issue.Issue;
import org.sonar.api.rule.RuleKey;
import org.sonar.scanner.ProjectAnalysisInfo;
-import org.sonar.scanner.issue.DeprecatedIssueAdapterForFilter;
import org.sonar.scanner.protocol.Constants.Severity;
import org.sonar.scanner.protocol.output.ScannerReport.TextRange;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.batch.IssueFilter;
import org.sonar.api.issue.batch.IssueFilterChain;
-import org.sonar.scanner.issue.DeprecatedIssueFilterChain;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.Severity;
import org.sonar.api.utils.MessageException;
-import org.sonar.scanner.issue.IssueFilters;
-import org.sonar.scanner.issue.ModuleIssues;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.report.ReportPublisher;
import org.junit.Test;
import org.sonar.api.issue.Issue;
import org.sonar.api.rule.RuleKey;
-import org.sonar.scanner.issue.TrackedIssueAdapter;
import org.sonar.scanner.issue.tracking.TrackedIssue;
import static org.assertj.core.api.Assertions.assertThat;
*/
package org.sonar.scanner.issue.ignore;
-import org.sonar.api.scan.issue.filter.FilterableIssue;
-
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
-import org.sonar.api.scan.issue.filter.IssueFilterChain;
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.api.rule.RuleKey;
+import org.sonar.api.scan.issue.filter.FilterableIssue;
+import org.sonar.api.scan.issue.filter.IssueFilterChain;
import org.sonar.api.utils.WildcardPattern;
-import org.sonar.scanner.issue.ignore.EnforceIssuesFilter;
import org.sonar.scanner.issue.ignore.pattern.IssueInclusionPatternInitializer;
import org.sonar.scanner.issue.ignore.pattern.IssuePattern;
import org.sonar.scanner.scan.filesystem.InputComponentStore;
*/
package org.sonar.scanner.issue.ignore;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.scan.issue.filter.FilterableIssue;
-
import org.junit.Before;
import org.junit.Test;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.scan.issue.filter.FilterableIssue;
import org.sonar.api.scan.issue.filter.IssueFilterChain;
-import org.sonar.scanner.issue.ignore.IgnoreIssuesFilter;
import org.sonar.scanner.issue.ignore.pattern.IssuePattern;
import org.sonar.scanner.issue.ignore.pattern.PatternMatcher;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class IgnoreIssuesFilterTest {
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.config.PropertyDefinitions;
-import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.core.config.IssueExclusionProperties;
import static org.assertj.core.api.Assertions.assertThat;
public class IssueExclusionPatternInitializerTest {
private IssueExclusionPatternInitializer patternsInitializer;
- private Settings settings;
+ private MapSettings settings;
@Before
public void init() {
@Test
public void testNoConfiguration() {
- patternsInitializer = new IssueExclusionPatternInitializer(settings);
+ patternsInitializer = new IssueExclusionPatternInitializer(settings.asConfig());
assertThat(patternsInitializer.hasConfiguredPatterns()).isFalse();
assertThat(patternsInitializer.getMulticriteriaPatterns().size()).isEqualTo(0);
}
settings.setProperty("sonar.issue.ignore" + ".multicriteria", "1");
settings.setProperty("sonar.issue.ignore" + ".multicriteria" + ".1." + "resourceKey", "");
settings.setProperty("sonar.issue.ignore" + ".multicriteria" + ".1." + "ruleKey", "*");
- patternsInitializer = new IssueExclusionPatternInitializer(settings);
+ patternsInitializer = new IssueExclusionPatternInitializer(settings.asConfig());
}
@Test(expected = IllegalStateException.class)
settings.setProperty("sonar.issue.ignore" + ".multicriteria", "1");
settings.setProperty("sonar.issue.ignore" + ".multicriteria" + ".1." + "resourceKey", "*");
settings.setProperty("sonar.issue.ignore" + ".multicriteria" + ".1." + "ruleKey", "");
- patternsInitializer = new IssueExclusionPatternInitializer(settings);
+ patternsInitializer = new IssueExclusionPatternInitializer(settings.asConfig());
}
@Test
settings.setProperty(IssueExclusionProperties.PATTERNS_BLOCK_KEY + ".2." + IssueExclusionProperties.END_BLOCK_REGEXP, "// FOO-ON");
settings.setProperty(IssueExclusionProperties.PATTERNS_BLOCK_KEY + ".3." + IssueExclusionProperties.BEGIN_BLOCK_REGEXP, "// IGNORE-TO-EOF");
settings.setProperty(IssueExclusionProperties.PATTERNS_BLOCK_KEY + ".3." + IssueExclusionProperties.END_BLOCK_REGEXP, "");
- patternsInitializer = new IssueExclusionPatternInitializer(settings);
+ patternsInitializer = new IssueExclusionPatternInitializer(settings.asConfig());
assertThat(patternsInitializer.hasConfiguredPatterns()).isTrue();
assertThat(patternsInitializer.hasFileContentPattern()).isTrue();
settings.setProperty(IssueExclusionProperties.PATTERNS_BLOCK_KEY, "1");
settings.setProperty(IssueExclusionProperties.PATTERNS_BLOCK_KEY + ".1." + IssueExclusionProperties.BEGIN_BLOCK_REGEXP, "");
settings.setProperty(IssueExclusionProperties.PATTERNS_BLOCK_KEY + ".1." + IssueExclusionProperties.END_BLOCK_REGEXP, "// SONAR-ON");
- patternsInitializer = new IssueExclusionPatternInitializer(settings);
+ patternsInitializer = new IssueExclusionPatternInitializer(settings.asConfig());
}
@Test
settings.setProperty(IssueExclusionProperties.PATTERNS_ALLFILE_KEY, "1,2");
settings.setProperty(IssueExclusionProperties.PATTERNS_ALLFILE_KEY + ".1." + IssueExclusionProperties.FILE_REGEXP, "@SONAR-IGNORE-ALL");
settings.setProperty(IssueExclusionProperties.PATTERNS_ALLFILE_KEY + ".2." + IssueExclusionProperties.FILE_REGEXP, "//FOO-IGNORE-ALL");
- patternsInitializer = new IssueExclusionPatternInitializer(settings);
+ patternsInitializer = new IssueExclusionPatternInitializer(settings.asConfig());
assertThat(patternsInitializer.hasConfiguredPatterns()).isTrue();
assertThat(patternsInitializer.hasFileContentPattern()).isTrue();
public void shouldLogInvalidAllFilePattern() {
settings.setProperty(IssueExclusionProperties.PATTERNS_ALLFILE_KEY, "1");
settings.setProperty(IssueExclusionProperties.PATTERNS_ALLFILE_KEY + ".1." + IssueExclusionProperties.FILE_REGEXP, "");
- patternsInitializer = new IssueExclusionPatternInitializer(settings);
+ patternsInitializer = new IssueExclusionPatternInitializer(settings.asConfig());
}
}
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.config.PropertyDefinitions;
-import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.core.config.IssueExclusionProperties;
import static org.assertj.core.api.Assertions.assertThat;
public class IssueInclusionPatternInitializerTest {
private IssueInclusionPatternInitializer patternsInitializer;
- private Settings settings;
+ private MapSettings settings;
@Before
public void init() {
settings = new MapSettings(new PropertyDefinitions(IssueExclusionProperties.all()));
- patternsInitializer = new IssueInclusionPatternInitializer(settings);
+ patternsInitializer = new IssueInclusionPatternInitializer(settings.asConfig());
}
@Test
*/
package org.sonar.scanner.issue.ignore.pattern;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
import org.junit.Test;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.Rule;
import static org.assertj.core.api.Assertions.assertThat;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
public class IssuePatternTest {
@Test
package org.sonar.scanner.issue.ignore.pattern;
import org.junit.Test;
-import org.sonar.scanner.issue.ignore.pattern.LineRange;
import static org.assertj.core.api.Assertions.assertThat;
package org.sonar.scanner.issue.ignore.pattern;
import org.junit.Test;
-import org.sonar.scanner.issue.ignore.pattern.PatternDecoder;
import static org.assertj.core.api.Assertions.assertThat;
*/
package org.sonar.scanner.issue.ignore.pattern;
-import org.sonar.scanner.issue.ignore.pattern.IssuePattern;
-import org.sonar.scanner.issue.ignore.pattern.LineRange;
-import org.sonar.scanner.issue.ignore.pattern.PatternMatcher;
import com.google.common.collect.Sets;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.rules.Rule;
-
import java.util.Collections;
import java.util.Set;
-
import javax.annotation.Nullable;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.rules.Rule;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
-
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
package org.sonar.scanner.issue.ignore.scanner;
import com.google.common.io.Resources;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.sonar.api.batch.fs.internal.FileMetadata;
-import org.sonar.scanner.issue.ignore.pattern.IssueExclusionPatternInitializer;
-import org.sonar.scanner.issue.ignore.pattern.LineRange;
-import org.sonar.scanner.issue.ignore.pattern.PatternMatcher;
-import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsRegexpScanner;
-import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader.DoubleRegexpMatcher;
-
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.sonar.api.batch.fs.internal.FileMetadata;
+import org.sonar.scanner.issue.ignore.pattern.IssueExclusionPatternInitializer;
+import org.sonar.scanner.issue.ignore.pattern.LineRange;
+import org.sonar.scanner.issue.ignore.pattern.PatternMatcher;
+import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader.DoubleRegexpMatcher;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.mockito.Mockito.times;
package org.sonar.scanner.issue.tracking;
import org.junit.Test;
-import org.sonar.scanner.issue.tracking.FileHashes;
-import org.sonar.scanner.issue.tracking.RollingFileHashes;
import static org.apache.commons.codec.digest.DigestUtils.md5Hex;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
-
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
*/
package org.sonar.scanner.issue.tracking;
-import static org.assertj.core.api.Assertions.assertThat;
-
import org.junit.Test;
-import org.sonar.scanner.issue.tracking.FileHashes;
-import org.sonar.scanner.issue.tracking.TrackedIssue;
+
+import static org.assertj.core.api.Assertions.assertThat;
public class TrackedIssueTest {
@Test
*/
package org.sonar.scanner.mediumtest;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
-
import org.sonar.batch.bootstrapper.LogOutput;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.HashMultimap;
public class LogOutputRecorder implements LogOutput {
private final Multimap<String, String> recordedByLevel = HashMultimap.create();
package org.sonar.scanner.mediumtest.fs;
import com.google.common.collect.ImmutableMap;
-
+import java.io.File;
+import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Random;
-
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.junit.After;
import org.sonar.xoo.XooPlugin;
import org.sonar.xoo.rule.XooRulesDefinition;
-import java.io.File;
-import java.io.IOException;
-
import static org.assertj.core.api.Assertions.assertThat;
public class FileSystemMediumTest {
*/
package org.sonar.scanner.mediumtest.fs;
-import org.junit.rules.ExpectedException;
-
+import java.io.File;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
-import java.io.File;
-
import org.junit.After;
import org.junit.Before;
-import org.junit.Test;
import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.sonar.scanner.mediumtest.ScannerMediumTester;
import org.sonar.scanner.mediumtest.issuesmode.IssueModeAndReportsMediumTest;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.bootstrap.ProjectBuilder;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
public class ProjectBuilderMediumTest {
*/
package org.sonar.scanner.mediumtest.issues;
-import org.junit.rules.TemporaryFolder;
+import com.google.common.collect.ImmutableMap;
+import java.io.File;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
-import com.google.common.collect.ImmutableMap;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.sonar.api.CoreProperties;
import org.sonar.batch.bootstrapper.IssueListener;
import org.sonar.scanner.mediumtest.ScannerMediumTester;
import org.sonar.scanner.mediumtest.TaskResult;
import org.sonar.xoo.XooPlugin;
import org.sonar.xoo.rule.XooRulesDefinition;
-import org.apache.commons.io.FileUtils;
-import org.junit.Test;
-import java.io.File;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
*/
package org.sonar.scanner.mediumtest.issuesmode;
-import org.apache.commons.io.filefilter.FileFilterUtils;
-import org.apache.commons.io.FileUtils;
-import org.sonar.xoo.rule.XooRulesDefinition;
import com.google.common.collect.ImmutableMap;
+import java.io.File;
+import java.util.Date;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.FileFilterUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.CoreProperties;
import org.sonar.api.utils.log.LogTester;
-import org.sonar.scanner.mediumtest.ScannerMediumTester;
import org.sonar.scanner.issue.tracking.TrackedIssue;
+import org.sonar.scanner.mediumtest.ScannerMediumTester;
import org.sonar.scanner.mediumtest.TaskResult;
import org.sonar.xoo.XooPlugin;
-
-import java.io.File;
-import java.util.Date;
+import org.sonar.xoo.rule.XooRulesDefinition;
import static org.assertj.core.api.Assertions.assertThat;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.batch.bootstrapper.IssueListener;
-import org.sonar.scanner.mediumtest.ScannerMediumTester;
import org.sonar.scanner.issue.tracking.TrackedIssue;
+import org.sonar.scanner.mediumtest.ScannerMediumTester;
import org.sonar.scanner.mediumtest.TaskResult;
import org.sonar.scanner.protocol.Constants.Severity;
import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue;
*/
package org.sonar.scanner.mediumtest.issuesmode;
+import com.google.common.collect.ImmutableMap;
+import java.io.File;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
-
-import java.io.File;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import com.google.common.collect.ImmutableMap;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.sonar.xoo.XooPlugin;
import org.sonar.xoo.rule.XooRulesDefinition;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class NoPreviousAnalysisTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.fs.internal.FileMetadata;
import org.sonar.api.utils.log.LogTester;
-import org.sonar.scanner.mediumtest.ScannerMediumTester;
import org.sonar.scanner.issue.tracking.TrackedIssue;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.ScannerMediumTester;
import org.sonar.scanner.mediumtest.ScannerMediumTester.TaskBuilder;
+import org.sonar.scanner.mediumtest.TaskResult;
import org.sonar.scanner.protocol.Constants.Severity;
import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue;
import org.sonar.scanner.repository.FileData;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
-
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FileUtils;
import org.assertj.core.util.Files;
import org.sonar.scanner.mediumtest.ScannerMediumTester.TaskBuilder;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReport.Changesets.Changeset;
-import org.sonar.scanner.repository.FileData;
import org.sonar.scanner.protocol.output.ScannerReport.Component;
import org.sonar.scanner.protocol.output.ScannerReportReader;
+import org.sonar.scanner.repository.FileData;
import org.sonar.xoo.XooPlugin;
import org.sonar.xoo.rule.XooRulesDefinition;
*/
package org.sonar.scanner.mediumtest.tests;
-import org.hamcrest.Description;
-
-import org.hamcrest.TypeSafeMatcher;
-import org.junit.Rule;
-import org.junit.rules.ExpectedException;
import com.google.common.collect.ImmutableMap;
+import java.io.File;
+import java.io.IOException;
import org.apache.commons.io.FileUtils;
+import org.hamcrest.Description;
+import org.hamcrest.TypeSafeMatcher;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.scanner.mediumtest.ScannerMediumTester;
import org.sonar.scanner.mediumtest.TaskResult;
import org.sonar.xoo.XooPlugin;
-import java.io.File;
-import java.io.IOException;
-
import static org.assertj.core.api.Assertions.assertThat;
public class CoveragePerTestMediumTest {
*/
package org.sonar.scanner.phases;
+import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.batch.PostJob;
import org.sonar.api.resources.Project;
import org.sonar.scanner.bootstrap.ScannerExtensionDictionnary;
import org.sonar.scanner.events.EventBus;
-import org.sonar.scanner.phases.PostJobsExecutor;
-import java.util.Arrays;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.eq;
-import static org.mockito.Mockito.any;
public class PostJobsExecutorTest {
PostJobsExecutor executor;
import java.io.IOException;
import java.util.Collections;
-import org.junit.*;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
import org.sonar.scanner.sensor.SensorStrategy;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class SensorsExecutorTest {
@Rule
import org.junit.Test;
import org.sonar.api.CoreProperties;
import org.sonar.api.SonarQubeSide;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.internal.SonarRuntimeImpl;
import org.sonar.api.utils.Version;
import org.sonar.scanner.bootstrap.ScannerWsClient;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.api.batch.postjob.issue.PostJobIssue;
import org.sonar.api.batch.rule.Severity;
-import org.sonar.api.config.MapSettings;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.scanner.issue.IssueCache;
import org.sonar.scanner.issue.tracking.TrackedIssue;
private IssueCache issueCache;
private InputComponentStore componentStore;
private DefaultPostJobContext context;
- private Settings settings;
+ private MapSettings settings;
private AnalysisMode analysisMode;
@Before
componentStore = new InputComponentStore(new PathResolver());
settings = new MapSettings();
analysisMode = mock(AnalysisMode.class);
- context = new DefaultPostJobContext(settings, issueCache, componentStore, analysisMode);
+ context = new DefaultPostJobContext(settings.asConfig(), settings, issueCache, componentStore, analysisMode);
}
@Test
import org.junit.rules.ExpectedException;
import org.sonar.api.batch.postjob.internal.DefaultPostJobDescriptor;
import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import static org.assertj.core.api.Assertions.assertThat;
*/
package org.sonar.scanner.profiling;
-import static org.assertj.core.api.Assertions.assertThat;
-
+import com.google.common.collect.Maps;
import java.util.List;
import java.util.Map;
-
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.scanner.bootstrap.GlobalProperties;
import org.sonar.scanner.events.BatchStepEvent;
-import com.google.common.collect.Maps;
+import static org.assertj.core.api.Assertions.assertThat;
public class PhasesSumUpTimeProfilerTest {
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReportReader;
import org.sonar.scanner.protocol.output.ScannerReportWriter;
-import org.sonar.scanner.report.ActiveRulesPublisher;
import static org.assertj.core.api.Assertions.assertThat;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.core.platform.PluginInfo;
-import org.sonar.scanner.bootstrap.GlobalSettings;
+import org.sonar.scanner.bootstrap.GlobalConfiguration;
import org.sonar.scanner.bootstrap.ScannerPluginRepository;
import org.sonar.scanner.protocol.output.ScannerReportWriter;
import org.sonar.scanner.repository.ProjectRepositories;
private AnalysisMode analysisMode = mock(AnalysisMode.class);
private System2 system2;
private ProjectRepositories projectRepos;
- private GlobalSettings globalSettings;
+ private GlobalConfiguration globalSettings;
@Before
public void prepare() throws Exception {
system2 = mock(System2.class);
when(system2.properties()).thenReturn(new Properties());
projectRepos = mock(ProjectRepositories.class);
- globalSettings = mock(GlobalSettings.class);
+ globalSettings = mock(GlobalConfiguration.class);
publisher = new AnalysisContextReportPublisher(analysisMode, pluginRepo, system2, projectRepos, globalSettings);
}
import java.io.File;
import java.io.IOException;
import java.util.Collections;
-
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReport.Component;
import org.sonar.scanner.protocol.output.ScannerReport.ComponentLink.ComponentLinkType;
-import org.sonar.scanner.report.ComponentsPublisher;
-import org.sonar.scanner.scan.DefaultComponentTree;
import org.sonar.scanner.protocol.output.ScannerReportReader;
import org.sonar.scanner.protocol.output.ScannerReportWriter;
+import org.sonar.scanner.scan.DefaultComponentTree;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import com.google.common.collect.Lists;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
-import org.sonar.api.config.Settings;
+import org.sonar.scanner.config.DefaultConfiguration;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReportWriter;
import org.sonar.scanner.repository.ContextPropertiesCache;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class ContextPropertiesPublisherTest {
@Rule
private ScannerReportWriter writer = mock(ScannerReportWriter.class);
private ContextPropertiesCache cache = new ContextPropertiesCache();
- private Settings settings = new MapSettings();
- private ContextPropertiesPublisher underTest = new ContextPropertiesPublisher(cache, settings);
+ private DefaultConfiguration config = mock(DefaultConfiguration.class);
+ private Map<String, String> props = new HashMap<>();
+ private ContextPropertiesPublisher underTest = new ContextPropertiesPublisher(cache, config);
+
+ @Before
+ public void prepareMock() {
+ when(config.getProperties()).thenReturn(props);
+ }
@Test
public void publish_writes_properties_to_report() {
@Test
public void publish_settings_prefixed_with_sonar_analysis_for_webhooks() {
- settings.setProperty("foo", "should not be exported");
- settings.setProperty("sonar.analysis.revision", "ab45b3");
- settings.setProperty("sonar.analysis.build.number", "B123");
+ props.put("foo", "should not be exported");
+ props.put("sonar.analysis.revision", "ab45b3");
+ props.put("sonar.analysis.build.number", "B123");
underTest.publish(writer);
import org.junit.rules.TemporaryFolder;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.config.MapSettings;
-import org.sonar.api.config.Settings;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.scanner.ProjectAnalysisInfo;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReportReader;
private ProjectDefinition projectDef;
private DefaultInputModule rootModule;
private MetadataPublisher underTest;
- private Settings settings;
+ private MapSettings settings;
private ModuleQProfiles qProfiles;
private ProjectAnalysisInfo projectAnalysisInfo;
private InputModuleHierarchy inputModuleHierarchy;
when(inputModuleHierarchy.root()).thenReturn(rootModule);
settings = new MapSettings();
qProfiles = mock(ModuleQProfiles.class);
- underTest = new MetadataPublisher(projectAnalysisInfo, inputModuleHierarchy, settings, qProfiles);
+ underTest = new MetadataPublisher(projectAnalysisInfo, inputModuleHierarchy, settings.asConfig(), qProfiles);
}
@Test
import org.mockito.Mockito;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.PropertyDefinitions;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.platform.Server;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.TempFolder;
public ExpectedException exception = ExpectedException.none();
DefaultAnalysisMode mode = mock(DefaultAnalysisMode.class);
- Settings settings = new MapSettings(new PropertyDefinitions(CorePropertyDefinitions.all()));
+ MapSettings settings = new MapSettings(new PropertyDefinitions(CorePropertyDefinitions.all()));
ScannerWsClient wsClient;
Server server = mock(Server.class);
ImmutableProjectReactor reactor = mock(ImmutableProjectReactor.class);
@Test
public void log_and_dump_information_about_report_uploading() throws IOException {
- ReportPublisher underTest = new ReportPublisher(settings, wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]);
+ ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]);
settings.setProperty(CoreProperties.PROJECT_ORGANIZATION_PROPERTY, "MyOrg");
underTest.logSuccess("TASK-123");
@Test
public void parse_upload_error_message() throws IOException {
- ReportPublisher underTest = new ReportPublisher(settings, wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]);
+ ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]);
HttpException ex = new HttpException("url", 404, "{\"errors\":[{\"msg\":\"Organization with key 'MyOrg' does not exist\"}]}");
WsResponse response = mock(WsResponse.class);
when(response.failIfNotSuccessful()).thenThrow(ex);
@Test
public void log_public_url_if_defined() throws IOException {
when(server.getPublicRootUrl()).thenReturn("https://publicserver/sonarqube");
- ReportPublisher underTest = new ReportPublisher(settings, wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]);
+ ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]);
underTest.logSuccess("TASK-123");
@Test
public void fail_if_public_url_malformed() throws IOException {
when(server.getPublicRootUrl()).thenReturn("invalid");
- ReportPublisher underTest = new ReportPublisher(settings, wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]);
+ ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]);
exception.expect(MessageException.class);
exception.expectMessage("Failed to parse public URL set in SonarQube server: invalid");
@Test
public void log_but_not_dump_information_when_report_is_not_uploaded() {
- ReportPublisher underTest = new ReportPublisher(settings, wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]);
+ ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]);
underTest.logSuccess(/* report not uploaded, no server task */null);
settings.setProperty("sonar.batch.keepReport", true);
Path reportDir = temp.getRoot().toPath().resolve("batch-report");
Files.createDirectory(reportDir);
- ReportPublisher underTest = new ReportPublisher(settings, wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]);
+ ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]);
underTest.start();
underTest.stop();
public void should_delete_report_by_default() throws IOException {
Path reportDir = temp.getRoot().toPath().resolve("batch-report");
Files.createDirectory(reportDir);
- ReportPublisher job = new ReportPublisher(settings, wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]);
+ ReportPublisher job = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]);
job.start();
job.stop();
@Test
public void test_ws_parameters() throws Exception {
- ReportPublisher underTest = new ReportPublisher(settings, wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]);
+ ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]);
settings.setProperty(CoreProperties.PROJECT_ORGANIZATION_PROPERTY, "MyOrg");
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.MapSettings;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.MessageException;
import org.sonar.scanner.WsTestUtil;
import org.sonar.scanner.bootstrap.ScannerWsClient;
public ExpectedException exception = ExpectedException.none();
private ScannerWsClient wsClient = mock(ScannerWsClient.class);
- private Settings settings = new MapSettings();
- private DefaultQualityProfileLoader underTest = new DefaultQualityProfileLoader(settings, wsClient);
+ private MapSettings settings = new MapSettings();
+ private DefaultQualityProfileLoader underTest = new DefaultQualityProfileLoader(settings.asConfig(), wsClient);
@Test
public void load_gets_profiles_for_specified_project_and_profile_name() throws IOException {
*/
package org.sonar.scanner.repository;
-import java.util.Date;
-import com.google.common.collect.Table;
import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.Table;
+import java.util.Date;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.sonar.api.batch.bootstrap.ProjectKey;
import org.sonar.scanner.analysis.DefaultAnalysisMode;
-import org.sonar.scanner.repository.FileData;
-import org.sonar.scanner.repository.ProjectRepositories;
-import org.sonar.scanner.repository.ProjectRepositoriesLoader;
-import org.sonar.scanner.repository.ProjectRepositoriesProvider;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.eq;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.scanner.analysis.AnalysisProperties;
-import org.sonar.scanner.repository.ProjectRepositories;
-import org.sonar.scanner.repository.QualityProfileLoader;
-import org.sonar.scanner.repository.QualityProfileProvider;
import org.sonar.scanner.rule.ModuleQProfiles;
import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
import org.mockito.MockitoAnnotations;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.rule.RuleKey;
-import org.sonar.scanner.rule.ActiveRulesProvider;
-import org.sonar.scanner.rule.DefaultActiveRulesLoader;
-import org.sonar.scanner.rule.LoadedActiveRule;
-import org.sonar.scanner.rule.ModuleQProfiles;
import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
import static org.assertj.core.api.Assertions.assertThat;
package org.sonar.scanner.rule;
import org.junit.Test;
-import static org.assertj.core.api.Assertions.*;
+
+import static org.assertj.core.api.Assertions.assertThat;
public class QProfileTest {
@Test
import org.slf4j.Logger;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
-import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.MessageException;
import static org.mockito.Mockito.mock;
private DefaultFileSystem fs;
private ModuleQProfiles profiles;
- private Settings settings = new MapSettings();
+ private MapSettings settings = new MapSettings();
@Before
public void before() throws Exception {
fs.add(new TestInputFileBuilder("foo", "src/Bar.java").setLanguage("java").build());
fs.add(new TestInputFileBuilder("foo", "src/Baz.cbl").setLanguage("cobol").build());
- QProfileVerifier profileLogger = new QProfileVerifier(settings, fs, profiles);
+ QProfileVerifier profileLogger = new QProfileVerifier(settings.asConfig(), fs, profiles);
Logger logger = mock(Logger.class);
profileLogger.execute(logger);
settings.setProperty("sonar.profile", "Unknown");
- QProfileVerifier profileLogger = new QProfileVerifier(settings, fs, profiles);
+ QProfileVerifier profileLogger = new QProfileVerifier(settings.asConfig(), fs, profiles);
thrown.expect(MessageException.class);
thrown.expectMessage("sonar.profile was set to 'Unknown' but didn't match any profile for any language. Please check your configuration.");
public void should_not_fail_if_no_language_on_project() {
settings.setProperty("sonar.profile", "Unknown");
- QProfileVerifier profileLogger = new QProfileVerifier(settings, fs, profiles);
+ QProfileVerifier profileLogger = new QProfileVerifier(settings.asConfig(), fs, profiles);
profileLogger.execute();
settings.setProperty("sonar.profile", "My Java profile");
- QProfileVerifier profileLogger = new QProfileVerifier(settings, fs, profiles);
+ QProfileVerifier profileLogger = new QProfileVerifier(settings.asConfig(), fs, profiles);
profileLogger.execute();
}
*/
package org.sonar.scanner.rule;
-import org.sonar.api.batch.rule.internal.RulesBuilder;
-
-import org.sonar.api.batch.rule.Rules;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.api.batch.rule.Rules;
+import org.sonar.api.batch.rule.internal.RulesBuilder;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.RuleQuery;
-import org.sonar.scanner.rule.RuleFinderCompatibility;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
import org.junit.Test;
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
-import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.rule.RuleKey;
public class RulesProfileProviderTest {
- ModuleQProfiles qProfiles = mock(ModuleQProfiles.class);
- Settings settings = new MapSettings();
- RulesProfileProvider provider = new RulesProfileProvider();
+ private ModuleQProfiles qProfiles = mock(ModuleQProfiles.class);
+ private MapSettings settings = new MapSettings();
+ private RulesProfileProvider provider = new RulesProfileProvider();
@Test
public void merge_profiles() {
QProfile qProfile = new QProfile().setKey("java-sw").setName("Sonar way").setLanguage("java");
when(qProfiles.findAll()).thenReturn(Arrays.asList(qProfile));
- RulesProfile profile = provider.provide(qProfiles, new ActiveRulesBuilder().build(), settings);
+ RulesProfile profile = provider.provide(qProfiles, new ActiveRulesBuilder().build(), settings.asConfig());
// merge of all profiles
assertThat(profile).isNotNull().isInstanceOf(RulesProfileWrapper.class);
QProfile qProfile = new QProfile().setKey("java-sw").setName("Sonar way").setLanguage("java");
when(qProfiles.findByLanguage("java")).thenReturn(qProfile);
- RulesProfile profile = provider.provide(qProfiles, new ActiveRulesBuilder().build(), settings);
+ RulesProfile profile = provider.provide(qProfiles, new ActiveRulesBuilder().build(), settings.asConfig());
// no merge, directly the old hibernate profile
assertThat(profile).isNotNull();
ActiveRulesBuilder activeRulesBuilder = new ActiveRulesBuilder();
activeRulesBuilder.create(RuleKey.of("java", "S001")).setTemplateRuleKey("T001").setLanguage("java").activate();
- RulesProfile profile = provider.provide(qProfiles, activeRulesBuilder.build(), settings);
+ RulesProfile profile = provider.provide(qProfiles, activeRulesBuilder.build(), settings.asConfig());
assertThat(profile.getActiveRule("java", "S001").getRule().getTemplate().getKey()).isEqualTo("T001");
}
package org.sonar.scanner.rule;
import com.google.common.collect.Lists;
+import org.junit.Test;
import org.sonar.api.batch.rule.Rules;
-import org.sonar.scanner.rule.RulesLoader;
-import org.sonar.scanner.rule.RulesProvider;
+import org.sonarqube.ws.Rules.ListResponse.Rule;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.when;
import static org.mockito.Mockito.mock;
-import org.sonarqube.ws.Rules.ListResponse.Rule;
-import org.junit.Test;
+import static org.mockito.Mockito.when;
public class RulesProviderTest {
@Test
*/
package org.sonar.scanner.scan;
-import static org.assertj.core.api.Assertions.assertThat;
-
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.batch.fs.internal.DefaultInputComponent;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class DefaultComponentTreeTest {
private DefaultComponentTree tree;
*/
package org.sonar.scanner.scan;
-import static org.assertj.core.api.Assertions.assertThat;
-
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class DefaultInputModuleHierarchyTest {
private DefaultInputModuleHierarchy moduleHierarchy;
+++ /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;
-
-import com.google.common.collect.HashBasedTable;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableTable;
-import com.google.common.collect.Table;
-import java.util.List;
-import java.util.Map;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.config.PropertyDefinitions;
-import org.sonar.api.utils.MessageException;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
-import org.sonar.scanner.bootstrap.GlobalMode;
-import org.sonar.scanner.bootstrap.GlobalProperties;
-import org.sonar.scanner.bootstrap.GlobalSettings;
-import org.sonar.scanner.report.AnalysisContextReportPublisher;
-import org.sonar.scanner.repository.FileData;
-import org.sonar.scanner.repository.ProjectRepositories;
-import org.sonar.scanner.repository.settings.SettingsLoader;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class ModuleSettingsTest {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- private DefaultAnalysisMode mode;
-
- @Before
- public void before() {
- mode = mock(DefaultAnalysisMode.class);
- }
-
- private ProjectRepositories createSettings(String module, Map<String, String> settingsMap) {
- Table<String, String, FileData> fileData = ImmutableTable.of();
- Table<String, String, String> settings = HashBasedTable.create();
-
- for (Map.Entry<String, String> e : settingsMap.entrySet()) {
- settings.put(module, e.getKey(), e.getValue());
- }
- return new ProjectRepositories(settings, fileData, null);
- }
-
- @Test
- public void testOrderedProjects() {
- ProjectDefinition grandParent = ProjectDefinition.create();
- ProjectDefinition parent = ProjectDefinition.create();
- ProjectDefinition child = ProjectDefinition.create();
- grandParent.addSubProject(parent);
- parent.addSubProject(child);
-
- List<ProjectDefinition> hierarchy = ModuleSettings.getTopDownParentProjects(child);
- assertThat(hierarchy.get(0)).isEqualTo(grandParent);
- assertThat(hierarchy.get(1)).isEqualTo(parent);
- assertThat(hierarchy.get(2)).isEqualTo(child);
- }
-
- @Test
- public void test_loading_of_module_settings() {
- GlobalSettings globalSettings = newGlobalSettings(ImmutableMap.of(
- "overridding", "batch",
- "on-batch", "true"));
-
- ProjectRepositories projRepos = createSettings("struts-core", ImmutableMap.of("on-module", "true", "overridding", "module"));
-
- ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");
-
- ModuleSettings moduleSettings = new ModuleSettings(globalSettings, module, projRepos, mode, mock(AnalysisContextReportPublisher.class));
-
- assertThat(moduleSettings.getString("overridding")).isEqualTo("module");
- assertThat(moduleSettings.getString("on-batch")).isEqualTo("true");
- assertThat(moduleSettings.getString("on-module")).isEqualTo("true");
- }
-
- // SONAR-6386
- @Test
- public void test_loading_of_parent_module_settings_for_new_module() {
- GlobalSettings globalSettings = newGlobalSettings(ImmutableMap.of(
- "overridding", "batch",
- "on-batch", "true"));
-
- ProjectRepositories projRepos = createSettings("struts", ImmutableMap.of("on-module", "true", "overridding", "module"));
-
- ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");
- ProjectDefinition.create().setKey("struts").addSubProject(module);
-
- ModuleSettings moduleSettings = new ModuleSettings(globalSettings, module, projRepos, mode, mock(AnalysisContextReportPublisher.class));
-
- assertThat(moduleSettings.getString("overridding")).isEqualTo("module");
- assertThat(moduleSettings.getString("on-batch")).isEqualTo("true");
- assertThat(moduleSettings.getString("on-module")).isEqualTo("true");
- }
-
- @Test
- public void should_not_fail_when_accessing_secured_properties() {
- GlobalSettings globalSettings = newGlobalSettings(ImmutableMap.of(
- "sonar.foo.secured", "bar"));
-
- ProjectRepositories projSettingsRepo = createSettings("struts-core", ImmutableMap.of("sonar.foo.license.secured", "bar2"));
-
- ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");
-
- ModuleSettings moduleSettings = new ModuleSettings(globalSettings, module, projSettingsRepo, mode, mock(AnalysisContextReportPublisher.class));
-
- assertThat(moduleSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
- assertThat(moduleSettings.getString("sonar.foo.secured")).isEqualTo("bar");
- }
-
- @Test
- public void should_fail_when_accessing_secured_properties_in_issues() {
- GlobalSettings globalSettings = newGlobalSettings(ImmutableMap.of(
- "sonar.foo.secured", "bar"));
-
- ProjectRepositories projSettingsRepo = createSettings("struts-core", ImmutableMap.of("sonar.foo.license.secured", "bar2"));
-
- when(mode.isIssues()).thenReturn(true);
-
- ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");
-
- ModuleSettings moduleSettings = new ModuleSettings(globalSettings, module, projSettingsRepo, mode, mock(AnalysisContextReportPublisher.class));
-
- assertThat(moduleSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
-
- thrown.expect(MessageException.class);
- thrown
- .expectMessage(
- "Access to the secured property 'sonar.foo.secured' is not possible in issues mode. The SonarQube plugin which requires this property must be deactivated in issues mode.");
- moduleSettings.getString("sonar.foo.secured");
- }
-
- private GlobalSettings newGlobalSettings(Map<String, String> props) {
- GlobalProperties globalProps = new GlobalProperties(props);
- return new GlobalSettings(globalProps, new PropertyDefinitions(),
- mock(SettingsLoader.class), new GlobalMode(globalProps));
- }
-}
--- /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;
+
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableTable;
+import com.google.common.collect.Table;
+import java.util.List;
+import java.util.Map;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.api.utils.MessageException;
+import org.sonar.scanner.analysis.DefaultAnalysisMode;
+import org.sonar.scanner.bootstrap.GlobalConfiguration;
+import org.sonar.scanner.bootstrap.GlobalConfigurationProvider;
+import org.sonar.scanner.bootstrap.GlobalMode;
+import org.sonar.scanner.bootstrap.GlobalProperties;
+import org.sonar.scanner.bootstrap.MutableGlobalSettings;
+import org.sonar.scanner.repository.FileData;
+import org.sonar.scanner.repository.ProjectRepositories;
+import org.sonar.scanner.repository.settings.SettingsLoader;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class MutableModuleSettingsTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private DefaultAnalysisMode mode;
+
+ @Before
+ public void before() {
+ mode = mock(DefaultAnalysisMode.class);
+ }
+
+ private ProjectRepositories createSettings(String module, Map<String, String> settingsMap) {
+ Table<String, String, FileData> fileData = ImmutableTable.of();
+ Table<String, String, String> settings = HashBasedTable.create();
+
+ for (Map.Entry<String, String> e : settingsMap.entrySet()) {
+ settings.put(module, e.getKey(), e.getValue());
+ }
+ return new ProjectRepositories(settings, fileData, null);
+ }
+
+ @Test
+ public void testOrderedProjects() {
+ ProjectDefinition grandParent = ProjectDefinition.create();
+ ProjectDefinition parent = ProjectDefinition.create();
+ ProjectDefinition child = ProjectDefinition.create();
+ grandParent.addSubProject(parent);
+ parent.addSubProject(child);
+
+ List<ProjectDefinition> hierarchy = MutableModuleSettings.getTopDownParentProjects(child);
+ assertThat(hierarchy.get(0)).isEqualTo(grandParent);
+ assertThat(hierarchy.get(1)).isEqualTo(parent);
+ assertThat(hierarchy.get(2)).isEqualTo(child);
+ }
+
+ @Test
+ public void test_loading_of_module_settings() {
+ GlobalConfiguration globalSettings = newGlobalSettings(ImmutableMap.of(
+ "overridding", "batch",
+ "on-batch", "true"));
+
+ ProjectRepositories projRepos = createSettings("struts-core", ImmutableMap.of("on-module", "true", "overridding", "module"));
+
+ ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");
+
+ MutableModuleSettings moduleSettings = new MutableModuleSettings(new MutableGlobalSettings(globalSettings), module, projRepos, mode);
+
+ assertThat(moduleSettings.getString("overridding")).isEqualTo("module");
+ assertThat(moduleSettings.getString("on-batch")).isEqualTo("true");
+ assertThat(moduleSettings.getString("on-module")).isEqualTo("true");
+ }
+
+ // SONAR-6386
+ @Test
+ public void test_loading_of_parent_module_settings_for_new_module() {
+ GlobalConfiguration globalSettings = newGlobalSettings(ImmutableMap.of(
+ "overridding", "batch",
+ "on-batch", "true"));
+
+ ProjectRepositories projRepos = createSettings("struts", ImmutableMap.of("on-module", "true", "overridding", "module"));
+
+ ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");
+ ProjectDefinition.create().setKey("struts").addSubProject(module);
+
+ MutableModuleSettings moduleSettings = new MutableModuleSettings(new MutableGlobalSettings(globalSettings), module, projRepos, mode);
+
+ assertThat(moduleSettings.getString("overridding")).isEqualTo("module");
+ assertThat(moduleSettings.getString("on-batch")).isEqualTo("true");
+ assertThat(moduleSettings.getString("on-module")).isEqualTo("true");
+ }
+
+ @Test
+ public void should_not_fail_when_accessing_secured_properties() {
+ GlobalConfiguration globalSettings = newGlobalSettings(ImmutableMap.of("sonar.foo.secured", "bar"));
+
+ ProjectRepositories projSettingsRepo = createSettings("struts-core", ImmutableMap.of("sonar.foo.license.secured", "bar2"));
+
+ ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");
+
+ MutableModuleSettings moduleSettings = new MutableModuleSettings(new MutableGlobalSettings(globalSettings), module, projSettingsRepo, mode);
+
+ assertThat(moduleSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
+ assertThat(moduleSettings.getString("sonar.foo.secured")).isEqualTo("bar");
+ }
+
+ @Test
+ public void should_fail_when_accessing_secured_properties_in_issues() {
+ GlobalConfiguration globalSettings = newGlobalSettings(ImmutableMap.of(
+ "sonar.foo.secured", "bar"));
+
+ ProjectRepositories projSettingsRepo = createSettings("struts-core", ImmutableMap.of("sonar.foo.license.secured", "bar2"));
+
+ when(mode.isIssues()).thenReturn(true);
+
+ ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");
+
+ MutableModuleSettings moduleSettings = new MutableModuleSettings(new MutableGlobalSettings(globalSettings), module, projSettingsRepo, mode);
+
+ assertThat(moduleSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
+
+ thrown.expect(MessageException.class);
+ thrown
+ .expectMessage(
+ "Access to the secured property 'sonar.foo.secured' is not possible in issues mode. The SonarQube plugin which requires this property must be deactivated in issues mode.");
+ moduleSettings.getString("sonar.foo.secured");
+ }
+
+ private GlobalConfiguration newGlobalSettings(Map<String, String> props) {
+ GlobalProperties globalProps = new GlobalProperties(props);
+ return new GlobalConfigurationProvider().provide(mock(SettingsLoader.class), globalProps, new PropertyDefinitions(),
+ new GlobalMode(globalProps));
+ }
+}
--- /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;
+
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.ImmutableTable;
+import com.google.common.collect.Table;
+import java.util.Collections;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.api.utils.MessageException;
+import org.sonar.api.utils.log.LogTester;
+import org.sonar.scanner.analysis.DefaultAnalysisMode;
+import org.sonar.scanner.bootstrap.GlobalConfiguration;
+import org.sonar.scanner.bootstrap.GlobalConfigurationProvider;
+import org.sonar.scanner.bootstrap.GlobalMode;
+import org.sonar.scanner.bootstrap.GlobalProperties;
+import org.sonar.scanner.bootstrap.MutableGlobalSettings;
+import org.sonar.scanner.repository.FileData;
+import org.sonar.scanner.repository.ProjectRepositories;
+import org.sonar.scanner.repository.settings.SettingsLoader;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class MutableProjectSettingsTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+ @Rule
+ public LogTester logTester = new LogTester();
+
+ private ProjectRepositories projectRef;
+ private ProjectDefinition project;
+ private GlobalConfiguration bootstrapProps;
+ private Table<String, String, FileData> emptyFileData;
+ private Table<String, String, String> emptySettings;
+
+ private GlobalMode globalMode;
+ private DefaultAnalysisMode mode;
+
+ @Before
+ public void prepare() {
+ emptyFileData = ImmutableTable.of();
+ emptySettings = ImmutableTable.of();
+ project = ProjectDefinition.create().setKey("struts");
+ globalMode = mock(GlobalMode.class);
+ mode = mock(DefaultAnalysisMode.class);
+ bootstrapProps = new GlobalConfigurationProvider().provide(mock(SettingsLoader.class), new GlobalProperties(Collections.<String, String>emptyMap()), new PropertyDefinitions(),
+ globalMode);
+ }
+
+ @Test
+ public void should_load_project_props() {
+ project.setProperty("project.prop", "project");
+
+ projectRef = new ProjectRepositories(emptySettings, emptyFileData, null);
+ MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, mode);
+
+ assertThat(batchSettings.getString("project.prop")).isEqualTo("project");
+ }
+
+ @Test
+ public void should_load_project_root_settings() {
+ Table<String, String, String> settings = HashBasedTable.create();
+ settings.put("struts", "sonar.cpd.cross", "true");
+ settings.put("struts", "sonar.java.coveragePlugin", "jacoco");
+
+ projectRef = new ProjectRepositories(settings, emptyFileData, null);
+ MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, mode);
+ assertThat(batchSettings.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
+ }
+
+ @Test
+ public void should_load_project_root_settings_on_branch() {
+ project.setProperty(CoreProperties.PROJECT_BRANCH_PROPERTY, "mybranch");
+
+ Table<String, String, String> settings = HashBasedTable.create();
+ settings.put("struts:mybranch", "sonar.cpd.cross", "true");
+ settings.put("struts:mybranch", "sonar.java.coveragePlugin", "jacoco");
+
+ projectRef = new ProjectRepositories(settings, emptyFileData, null);
+
+ MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, mode);
+
+ assertThat(batchSettings.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
+ }
+
+ @Test
+ public void should_not_fail_when_accessing_secured_properties() {
+ Table<String, String, String> settings = HashBasedTable.create();
+ settings.put("struts", "sonar.foo.secured", "bar");
+ settings.put("struts", "sonar.foo.license.secured", "bar2");
+
+ projectRef = new ProjectRepositories(settings, emptyFileData, null);
+ MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, mode);
+
+ assertThat(batchSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
+ assertThat(batchSettings.getString("sonar.foo.secured")).isEqualTo("bar");
+ }
+
+ @Test
+ public void should_fail_when_accessing_secured_properties_in_issues_mode() {
+ Table<String, String, String> settings = HashBasedTable.create();
+ settings.put("struts", "sonar.foo.secured", "bar");
+ settings.put("struts", "sonar.foo.license.secured", "bar2");
+
+ when(mode.isIssues()).thenReturn(true);
+
+ projectRef = new ProjectRepositories(settings, emptyFileData, null);
+ MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, mode);
+
+ assertThat(batchSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
+ thrown.expect(MessageException.class);
+ thrown
+ .expectMessage(
+ "Access to the secured property 'sonar.foo.secured' is not possible in issues mode. The SonarQube plugin which requires this property must be deactivated in issues mode.");
+ batchSettings.getString("sonar.foo.secured");
+ }
+
+}
*/
package org.sonar.scanner.scan;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.utils.MessageException;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+
public class ProjectBuildersExecutorTest {
private ProjectReactor reactor;
*/
package org.sonar.scanner.scan;
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.home.cache.DirectoryLock;
-import org.sonar.scanner.scan.ProjectLock;
-import java.io.File;
-import java.nio.file.Files;
-import java.nio.file.Path;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.assertj.core.api.Assertions.assertThat;
-import org.junit.Test;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.rules.TemporaryFolder;
public class ProjectLockTest {
@Rule
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.MessageException;
import org.sonar.scanner.analysis.DefaultAnalysisMode;
import org.sonar.api.ServerExtension;
import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.api.task.TaskExtension;
-import org.sonar.scanner.scan.ProjectScanContainer;
import static org.assertj.core.api.Assertions.assertThat;
+++ /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;
-
-import com.google.common.collect.HashBasedTable;
-import com.google.common.collect.ImmutableTable;
-import com.google.common.collect.Table;
-import java.util.Collections;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.api.config.PropertyDefinitions;
-import org.sonar.api.utils.MessageException;
-import org.sonar.api.utils.log.LogTester;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
-import org.sonar.scanner.bootstrap.GlobalMode;
-import org.sonar.scanner.bootstrap.GlobalProperties;
-import org.sonar.scanner.bootstrap.GlobalSettings;
-import org.sonar.scanner.repository.FileData;
-import org.sonar.scanner.repository.ProjectRepositories;
-import org.sonar.scanner.repository.settings.SettingsLoader;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class ProjectSettingsTest {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
- @Rule
- public LogTester logTester = new LogTester();
-
- private ProjectRepositories projectRef;
- private ProjectDefinition project;
- private GlobalSettings bootstrapProps;
- private Table<String, String, FileData> emptyFileData;
- private Table<String, String, String> emptySettings;
-
- private GlobalMode globalMode;
- private DefaultAnalysisMode mode;
-
- @Before
- public void prepare() {
- emptyFileData = ImmutableTable.of();
- emptySettings = ImmutableTable.of();
- project = ProjectDefinition.create().setKey("struts");
- globalMode = mock(GlobalMode.class);
- mode = mock(DefaultAnalysisMode.class);
- bootstrapProps = new GlobalSettings(new GlobalProperties(Collections.<String, String>emptyMap()), new PropertyDefinitions(), mock(SettingsLoader.class), globalMode);
- }
-
- @Test
- public void should_load_project_props() {
- project.setProperty("project.prop", "project");
-
- projectRef = new ProjectRepositories(emptySettings, emptyFileData, null);
- ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, projectRef, mode);
-
- assertThat(batchSettings.getString("project.prop")).isEqualTo("project");
- }
-
- @Test
- public void should_load_project_root_settings() {
- Table<String, String, String> settings = HashBasedTable.create();
- settings.put("struts", "sonar.cpd.cross", "true");
- settings.put("struts", "sonar.java.coveragePlugin", "jacoco");
-
- projectRef = new ProjectRepositories(settings, emptyFileData, null);
- ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, projectRef, mode);
- assertThat(batchSettings.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
- }
-
- @Test
- public void should_load_project_root_settings_on_branch() {
- project.setProperty(CoreProperties.PROJECT_BRANCH_PROPERTY, "mybranch");
-
- Table<String, String, String> settings = HashBasedTable.create();
- settings.put("struts:mybranch", "sonar.cpd.cross", "true");
- settings.put("struts:mybranch", "sonar.java.coveragePlugin", "jacoco");
-
- projectRef = new ProjectRepositories(settings, emptyFileData, null);
-
- ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, projectRef, mode);
-
- assertThat(batchSettings.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
- }
-
- @Test
- public void should_not_fail_when_accessing_secured_properties() {
- Table<String, String, String> settings = HashBasedTable.create();
- settings.put("struts", "sonar.foo.secured", "bar");
- settings.put("struts", "sonar.foo.license.secured", "bar2");
-
- projectRef = new ProjectRepositories(settings, emptyFileData, null);
- ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, projectRef, mode);
-
- assertThat(batchSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
- assertThat(batchSettings.getString("sonar.foo.secured")).isEqualTo("bar");
- }
-
- @Test
- public void should_fail_when_accessing_secured_properties_in_issues_mode() {
- Table<String, String, String> settings = HashBasedTable.create();
- settings.put("struts", "sonar.foo.secured", "bar");
- settings.put("struts", "sonar.foo.license.secured", "bar2");
-
- when(mode.isIssues()).thenReturn(true);
-
- projectRef = new ProjectRepositories(settings, emptyFileData, null);
- ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, projectRef, mode);
-
- assertThat(batchSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
- thrown.expect(MessageException.class);
- thrown
- .expectMessage(
- "Access to the secured property 'sonar.foo.secured' is not possible in issues mode. The SonarQube plugin which requires this property must be deactivated in issues mode.");
- batchSettings.getString("sonar.foo.secured");
- }
-
-}
*/
package org.sonar.scanner.scan;
+import java.io.File;
+import java.io.IOException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.home.cache.DirectoryLock;
-import org.sonar.scanner.scan.WorkDirectoryCleaner;
-import java.io.File;
-import java.io.IOException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
-import org.sonar.scanner.scan.filesystem.AdditionalFilePredicates;
import static org.assertj.core.api.Assertions.assertThat;
*/
package org.sonar.scanner.scan.filesystem;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyBoolean;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-
import org.apache.commons.io.ByteOrderMark;
import org.junit.Before;
import org.junit.Test;
import org.sonar.scanner.scan.filesystem.CharsetValidation.Result;
import org.sonar.scanner.scan.filesystem.CharsetValidation.Validation;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
public class ByteCharsetDetectorTest {
private CharsetValidation validation;
private ByteCharsetDetector charsets;
*/
package org.sonar.scanner.scan.filesystem;
-import static java.nio.charset.StandardCharsets.US_ASCII;
-import static java.nio.charset.StandardCharsets.UTF_16;
-import static java.nio.charset.StandardCharsets.UTF_16BE;
-import static java.nio.charset.StandardCharsets.UTF_16LE;
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.assertj.core.api.Assertions.assertThat;
-
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Paths;
import java.util.List;
import java.util.Random;
-
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
+import static java.nio.charset.StandardCharsets.US_ASCII;
+import static java.nio.charset.StandardCharsets.UTF_16;
+import static java.nio.charset.StandardCharsets.UTF_16BE;
+import static java.nio.charset.StandardCharsets.UTF_16LE;
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class CharsetDetectorTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
*/
package org.sonar.scanner.scan.filesystem;
-import static org.assertj.core.api.Assertions.assertThat;
-
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.ByteBuffer;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
-
import org.apache.commons.lang.StringUtils;
import org.junit.Before;
import org.junit.Test;
import org.sonar.scanner.scan.filesystem.CharsetValidation.Validation;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class CharsetValidationTest {
private CharsetValidation charsets;
import org.sonar.api.batch.fs.IndexedFile;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultIndexedFile;
-import org.sonar.api.config.MapSettings;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.scan.filesystem.FileExclusions;
import static org.assertj.core.api.Assertions.assertThat;
@Rule
public TemporaryFolder temp = new TemporaryFolder();
private Path moduleBaseDir;
+ private MapSettings settings;
+ private ExclusionFilters filter;
@Before
public void setUp() throws IOException {
+ settings = new MapSettings();
moduleBaseDir = temp.newFolder().toPath();
+ filter = new ExclusionFilters(new FileExclusions(settings.asConfig()));
}
@Test
public void no_inclusions_nor_exclusions() throws IOException {
- ExclusionFilters filter = new ExclusionFilters(new FileExclusions(new MapSettings()));
filter.prepare();
-
IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/FooDao.java");
assertThat(filter.accept(indexedFile, InputFile.Type.MAIN)).isTrue();
assertThat(filter.accept(indexedFile, InputFile.Type.TEST)).isTrue();
@Test
public void match_inclusion() throws IOException {
- Settings settings = new MapSettings();
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Dao.java");
- ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
filter.prepare();
IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/FooDao.java");
@Test
public void match_at_least_one_inclusion() throws IOException {
- Settings settings = new MapSettings();
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Dao.java,**/*Dto.java");
- ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
-
filter.prepare();
IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/Foo.java");
@Test
public void match_exclusions() throws IOException {
- Settings settings = new MapSettings();
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "src/main/java/**/*");
settings.setProperty(CoreProperties.PROJECT_TEST_INCLUSIONS_PROPERTY, "src/test/java/**/*");
settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*Dao.java");
- ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
-
filter.prepare();
IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/FooDao.java");
public void match_exclusion_by_absolute_path() throws IOException {
File excludedFile = new File(moduleBaseDir.toString(), "src/main/java/org/bar/Bar.java");
- Settings settings = new MapSettings();
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "src/main/java/**/*");
settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "file:" + excludedFile.getAbsolutePath());
- ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
-
filter.prepare();
IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/org/bar/Foo.java");
@Test
public void trim_pattern() {
- Settings settings = new MapSettings();
settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, " **/*Dao.java ");
- ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings));
assertThat(filter.prepareMainExclusions()[0].toString()).isEqualTo("**/*Dao.java");
}
*/
package org.sonar.scanner.scan.filesystem;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
-
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.batch.fs.InputFile.Type;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.config.MapSettings;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.scan.filesystem.PathResolver;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
public class InputFileBuilderTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
LanguageDetection langDetection = mock(LanguageDetection.class);
MetadataGenerator metadataGenerator = mock(MetadataGenerator.class);
BatchIdGenerator idGenerator = new BatchIdGenerator();
- Settings settings = new MapSettings();
- builder = new InputFileBuilder(module, pathResolver, langDetection, metadataGenerator, idGenerator, settings);
+ MapSettings settings = new MapSettings();
+ builder = new InputFileBuilder(module, pathResolver, langDetection, metadataGenerator, idGenerator, settings.asConfig());
}
@Test
import java.io.File;
import java.io.IOException;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.fs.internal.DefaultIndexedFile;
-import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Languages;
import org.sonar.api.utils.MessageException;
@Rule
public ExpectedException thrown = ExpectedException.none();
+ private MapSettings settings;
+
+ @Before
+ public void setUp() throws IOException {
+ settings = new MapSettings();
+ }
+
@Test
public void test_sanitizeExtension() throws Exception {
assertThat(LanguageDetection.sanitizeExtension(".cbl")).isEqualTo("cbl");
@Test
public void search_by_file_extension() throws Exception {
LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java", "jav"), new MockLanguage("cobol", "cbl", "cob")));
- LanguageDetection detection = new LanguageDetection(new MapSettings(), languages);
+ LanguageDetection detection = new LanguageDetection(settings.asConfig(), languages);
assertThat(detection.language(newIndexedFile("Foo.java"))).isEqualTo("java");
assertThat(detection.language(newIndexedFile("src/Foo.java"))).isEqualTo("java");
@Test
public void should_not_fail_if_no_language() throws Exception {
- LanguageDetection detection = spy(new LanguageDetection(new MapSettings(), new DefaultLanguagesRepository(new Languages())));
+ LanguageDetection detection = spy(new LanguageDetection(settings.asConfig(), new DefaultLanguagesRepository(new Languages())));
assertThat(detection.language(newIndexedFile("Foo.java"))).isNull();
}
public void plugin_can_declare_a_file_extension_twice_for_case_sensitivity() throws Exception {
LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("abap", "abap", "ABAP")));
- LanguageDetection detection = new LanguageDetection(new MapSettings(), languages);
+ LanguageDetection detection = new LanguageDetection(settings.asConfig(), languages);
assertThat(detection.language(newIndexedFile("abc.abap"))).isEqualTo("abap");
}
LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java"), new MockLanguage("abap")));
// No side-effect on non-ABAP projects
- LanguageDetection detection = new LanguageDetection(new MapSettings(), languages);
+ LanguageDetection detection = new LanguageDetection(settings.asConfig(), languages);
assertThat(detection.language(newIndexedFile("abc"))).isNull();
assertThat(detection.language(newIndexedFile("abc.abap"))).isNull();
assertThat(detection.language(newIndexedFile("abc.java"))).isEqualTo("java");
- Settings settings = new MapSettings();
settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "abap");
- detection = new LanguageDetection(settings, languages);
+ detection = new LanguageDetection(settings.asConfig(), languages);
assertThat(detection.language(newIndexedFile("abc"))).isEqualTo("abap");
assertThat(detection.language(newIndexedFile("abc.txt"))).isEqualTo("abap");
assertThat(detection.language(newIndexedFile("abc.java"))).isEqualTo("abap");
public void force_language_using_deprecated_property() throws Exception {
LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java"), new MockLanguage("php", "php")));
- Settings settings = new MapSettings();
settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "java");
- LanguageDetection detection = new LanguageDetection(settings, languages);
+ LanguageDetection detection = new LanguageDetection(settings.asConfig(), languages);
assertThat(detection.language(newIndexedFile("abc"))).isNull();
assertThat(detection.language(newIndexedFile("abc.php"))).isNull();
assertThat(detection.language(newIndexedFile("abc.java"))).isEqualTo("java");
thrown.expectMessage("You must install a plugin that supports the language 'unknown'");
LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java"), new MockLanguage("php", "php")));
- Settings settings = new MapSettings();
settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "unknown");
- new LanguageDetection(settings, languages);
+ new LanguageDetection(settings.asConfig(), languages);
}
@Test
public void fail_if_conflicting_language_suffix() throws Exception {
LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("xml", "xhtml"), new MockLanguage("web", "xhtml")));
- LanguageDetection detection = new LanguageDetection(new MapSettings(), languages);
+ LanguageDetection detection = new LanguageDetection(settings.asConfig(), languages);
try {
detection.language(newIndexedFile("abc.xhtml"));
fail();
public void solve_conflict_using_filepattern() throws Exception {
LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("xml", "xhtml"), new MockLanguage("web", "xhtml")));
- Settings settings = new MapSettings();
settings.setProperty("sonar.lang.patterns.xml", "xml/**");
settings.setProperty("sonar.lang.patterns.web", "web/**");
- LanguageDetection detection = new LanguageDetection(settings, languages);
+ LanguageDetection detection = new LanguageDetection(settings.asConfig(), languages);
assertThat(detection.language(newIndexedFile("xml/abc.xhtml"))).isEqualTo("xml");
assertThat(detection.language(newIndexedFile("web/abc.xhtml"))).isEqualTo("web");
}
@Test
public void fail_if_conflicting_filepattern() throws Exception {
LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("abap", "abap"), new MockLanguage("cobol", "cobol")));
- Settings settings = new MapSettings();
settings.setProperty("sonar.lang.patterns.abap", "*.abap,*.txt");
settings.setProperty("sonar.lang.patterns.cobol", "*.cobol,*.txt");
- LanguageDetection detection = new LanguageDetection(settings, languages);
+ LanguageDetection detection = new LanguageDetection(settings.asConfig(), languages);
assertThat(detection.language(newIndexedFile("abc.abap"))).isEqualTo("abap");
assertThat(detection.language(newIndexedFile("abc.cobol"))).isEqualTo("cobol");
*/
package org.sonar.scanner.scan.filesystem;
-import static org.apache.commons.codec.digest.DigestUtils.md5Hex;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
-
import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.junit.Before;
import org.sonar.scanner.issue.ignore.pattern.PatternMatcher;
import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader;
+import static org.apache.commons.codec.digest.DigestUtils.md5Hex;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
public class MetadataGeneratorTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
import org.junit.Test;
import org.sonar.scanner.repository.ProjectRepositories;
-import org.sonar.scanner.scan.filesystem.StatusDetection;
-import org.sonar.scanner.scan.filesystem.StatusDetectionFactory;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.scanner.repository.FileData;
import org.sonar.scanner.repository.ProjectRepositories;
-import org.sonar.scanner.scan.filesystem.StatusDetection;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
-import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.rule.Severity;
import org.sonar.api.utils.log.LogTester;
import org.sonar.scanner.issue.IssueCache;
@Rule
public LogTester logTester = new LogTester();
- private Settings settings;
+ private MapSettings settings;
private IssueCache issueCache;
private InputComponentStore inputPathCache;
private ConsoleReport report;
settings = new MapSettings();
issueCache = mock(IssueCache.class);
inputPathCache = mock(InputComponentStore.class);
- report = new ConsoleReport(settings, issueCache, inputPathCache);
+ report = new ConsoleReport(settings.asConfig(), issueCache, inputPathCache);
}
@Test
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.api.batch.rule.Rules;
import org.sonar.api.batch.rule.internal.RulesBuilder;
-import org.sonar.api.config.MapSettings;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.issue.Issue;
import org.sonar.api.platform.Server;
import org.sonar.api.rule.RuleKey;
@Rule
public TemporaryFolder temp = new TemporaryFolder();
- JSONReport jsonReport;
- DefaultFileSystem fs;
- Server server = mock(Server.class);
- Rules rules = mock(Rules.class);
- Settings settings = new MapSettings();
- IssueCache issueCache = mock(IssueCache.class);
+ private JSONReport jsonReport;
+ private DefaultFileSystem fs;
+ private Server server = mock(Server.class);
+ private Rules rules = mock(Rules.class);
+ private MapSettings settings = new MapSettings();
+ private IssueCache issueCache = mock(IssueCache.class);
private InputModuleHierarchy moduleHierarchy;
@Before
RulesBuilder builder = new RulesBuilder();
builder.add(RuleKey.of("squid", "AvoidCycles")).setName("Avoid Cycles");
rules = builder.build();
- jsonReport = new JSONReport(moduleHierarchy, settings, fs, server, rules, issueCache, rootModule, inputComponentStore, inputComponentTree);
+ jsonReport = new JSONReport(moduleHierarchy, settings.asConfig(), fs, server, rules, issueCache, rootModule, inputComponentStore, inputComponentTree);
}
@Test
*/
package org.sonar.scanner.scan.report;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.assertj.core.api.Assertions.assertThat;
-
-import static org.mockito.Matchers.any;
-
-import org.sonar.api.rule.RuleKey;
-import org.sonar.scanner.scan.report.RuleNameProvider;
-import org.sonar.api.batch.rule.Rule;
-import org.junit.Test;
import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.batch.rule.Rule;
import org.sonar.api.batch.rule.Rules;
+import org.sonar.api.rule.RuleKey;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class RuleNameProviderTest {
- RuleNameProvider provider;
- Rules rules;
- Rule rule;
- RuleKey ruleKey;
+ private RuleNameProvider provider;
+ private Rules rules;
+ private Rule rule;
+ private RuleKey ruleKey;
@Before
public void setUp() {
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.api.batch.scm.BlameLine;
-import org.sonar.scanner.scm.DefaultBlameOutput;
public class DefaultBlameOutputTest {
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
import org.sonar.api.batch.sensor.internal.SensorStorage;
-import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.internal.SonarRuntimeImpl;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.utils.Version;
private ActiveRules activeRules;
private DefaultFileSystem fs;
private DefaultSensorContext adaptor;
- private Settings settings;
+ private MapSettings settings;
private SensorStorage sensorStorage;
private AnalysisMode analysisMode;
private SonarRuntime runtime;
sensorStorage = mock(SensorStorage.class);
analysisMode = mock(AnalysisMode.class);
runtime = SonarRuntimeImpl.forSonarQube(Version.parse("5.5"), SonarQubeSide.SCANNER);
- adaptor = new DefaultSensorContext(mock(InputModule.class), settings, fs, activeRules, analysisMode, sensorStorage, runtime);
+ adaptor = new DefaultSensorContext(mock(InputModule.class), settings.asConfig(), settings, fs, activeRules, analysisMode, sensorStorage, runtime);
}
@Test
import org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting;
import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable;
-import org.sonar.api.config.MapSettings;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.utils.KeyValueFormat;
import org.sonar.core.metric.ScannerMetrics;
public ExpectedException thrown = ExpectedException.none();
private DefaultSensorStorage underTest;
- private Settings settings;
+ private MapSettings settings;
private ModuleIssues moduleIssues;
private MeasureCache measureCache;
private ContextPropertiesCache contextPropertiesCache = new ContextPropertiesCache();
ReportPublisher reportPublisher = mock(ReportPublisher.class);
when(reportPublisher.getWriter()).thenReturn(new ScannerReportWriter(temp.newFolder()));
underTest = new DefaultSensorStorage(metricFinder,
- moduleIssues, settings, coverageExclusions, reportPublisher, measureCache,
+ moduleIssues, settings.asConfig(), coverageExclusions, reportPublisher, measureCache,
mock(SonarCpdBlockIndex.class), contextPropertiesCache, new ScannerMetrics());
}
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
-import org.sonar.api.config.Settings;
-import org.sonar.api.config.MapSettings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.rule.RuleKey;
import static org.assertj.core.api.Assertions.assertThat;
private DefaultFileSystem fs;
private SensorOptimizer optimizer;
- private Settings settings;
+ private MapSettings settings;
@Before
public void prepare() throws Exception {
fs = new DefaultFileSystem(temp.newFolder().toPath());
settings = new MapSettings();
- optimizer = new SensorOptimizer(fs, new ActiveRulesBuilder().build(), settings);
+ optimizer = new SensorOptimizer(fs, new ActiveRulesBuilder().build(), settings.asConfig());
}
@Test
.create(RuleKey.of("repo1", "foo"))
.activate()
.build();
- optimizer = new SensorOptimizer(fs, activeRules, settings);
+ optimizer = new SensorOptimizer(fs, activeRules, settings.asConfig());
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
.create(RuleKey.of("squid", "rule"))
.activate()
.build();
- optimizer = new SensorOptimizer(fs, activeRules, settings);
+ optimizer = new SensorOptimizer(fs, activeRules, settings.asConfig());
assertThat(optimizer.shouldExecute(descriptor)).isTrue();
}
import org.junit.Test;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.config.PropertyDefinitions;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.internal.MapSettings;
import org.sonar.core.config.ExclusionProperties;
import static org.assertj.core.api.Assertions.assertThat;
public class CoverageExclusionsTest {
- private Settings settings;
+ private MapSettings settings;
private CoverageExclusions coverageExclusions;
@Before
public void prepare() {
settings = new MapSettings(new PropertyDefinitions(ExclusionProperties.all()));
- coverageExclusions = new CoverageExclusions(settings);
+ coverageExclusions = new CoverageExclusions(settings.asConfig());
}
@Test
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting;
import org.sonar.api.batch.sensor.internal.SensorStorage;
-import org.sonar.scanner.source.DefaultHighlightable;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import org.sonar.api.source.Symbol;
import org.sonar.api.source.Symbolizable;
import org.sonar.scanner.sensor.DefaultSensorStorage;
-import org.sonar.scanner.source.DefaultSymbolizable;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable;
import org.sonar.api.source.Symbol;
import org.sonar.api.source.Symbolizable;
-import org.sonar.scanner.source.DeprecatedDefaultSymbolTable;
import static org.assertj.core.api.Assertions.assertThat;
import com.google.common.collect.Iterables;
import org.junit.Test;
import org.sonar.scanner.index.AbstractCachesTest;
-import org.sonar.scanner.storage.Storage;
import org.sonar.scanner.storage.Storage.Entry;
import static org.assertj.core.api.Assertions.assertThat;
*/
package org.sonar.scanner.storage;
+import java.io.File;
import org.junit.Test;
import org.sonar.scanner.index.AbstractCachesTest;
-import java.io.File;
import static org.assertj.core.api.Assertions.assertThat;
*/
package org.sonar.scanner.storage;
-import java.io.Serializable;
-
import com.persistit.exception.PersistitException;
+import java.io.Serializable;
import org.junit.Test;
import org.sonar.scanner.index.AbstractCachesTest;
-import org.sonar.scanner.storage.Storage;
-import org.sonar.scanner.storage.Storages;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import org.sonar.api.task.TaskDefinition;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
-import org.sonar.scanner.task.ListTask;
-import org.sonar.scanner.task.Tasks;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import org.junit.rules.ExpectedException;
import org.sonar.api.task.Task;
import org.sonar.api.task.TaskDefinition;
-import org.sonar.scanner.task.ListTask;
-import org.sonar.scanner.task.ScanTask;
-import org.sonar.scanner.task.Tasks;
import static org.assertj.core.api.Assertions.assertThat;
package org.sonar.scanner.util;
import org.junit.Test;
-import org.sonar.scanner.util.ScannerUtils;
import static org.assertj.core.api.Assertions.assertThat;