<artifactId>sonar-plugin-api</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
</exclusion>
</exclusions>
</dependency>
- <dependency>
- <groupId>commons-configuration</groupId>
- <artifactId>commons-configuration</artifactId>
- <version>1.6</version>
- <exclusions>
- <exclusion>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </exclusion>
- <exclusion>
- <!-- See SONAR-2512 -->
- <groupId>commons-beanutils</groupId>
- <artifactId>commons-beanutils-core</artifactId>
- </exclusion>
- <exclusion>
- <groupId>commons-digester</groupId>
- <artifactId>commons-digester</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
</dependency>
- <dependency>
- <groupId>commons-configuration</groupId>
- <artifactId>commons-configuration</artifactId>
- </dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
package org.sonar.server.platform;
import com.google.common.collect.Lists;
-import org.apache.commons.configuration.BaseConfiguration;
import org.sonar.api.config.EmailSettings;
import org.sonar.api.issue.action.Actions;
import org.sonar.api.platform.ComponentContainer;
import org.sonar.core.metric.DefaultMetricFinder;
import org.sonar.core.notification.DefaultNotificationManager;
import org.sonar.core.permission.PermissionFacade;
-import org.sonar.core.persistence.*;
+import org.sonar.core.persistence.DaoUtils;
+import org.sonar.core.persistence.DatabaseVersion;
+import org.sonar.core.persistence.DefaultDatabase;
+import org.sonar.core.persistence.MyBatis;
+import org.sonar.core.persistence.PreviewDatabaseFactory;
+import org.sonar.core.persistence.SemaphoreUpdater;
+import org.sonar.core.persistence.SemaphoresImpl;
import org.sonar.core.preview.PreviewCache;
import org.sonar.core.profiling.Profiling;
import org.sonar.core.purge.PurgeProfiler;
import org.sonar.server.component.DefaultComponentFinder;
import org.sonar.server.component.DefaultRubyComponentService;
import org.sonar.server.component.persistence.ComponentDao;
-import org.sonar.server.component.ws.*;
+import org.sonar.server.component.ws.ComponentAppAction;
+import org.sonar.server.component.ws.ComponentsWs;
+import org.sonar.server.component.ws.EventsWs;
+import org.sonar.server.component.ws.ProjectsWs;
+import org.sonar.server.component.ws.ResourcesWs;
import org.sonar.server.config.ws.PropertiesWs;
import org.sonar.server.db.DatabaseChecker;
import org.sonar.server.db.DbClient;
import org.sonar.server.db.EmbeddedDatabaseFactory;
import org.sonar.server.db.migrations.DatabaseMigrations;
import org.sonar.server.db.migrations.DatabaseMigrator;
-import org.sonar.server.debt.*;
+import org.sonar.server.debt.DebtCharacteristicsXMLImporter;
+import org.sonar.server.debt.DebtModelBackup;
+import org.sonar.server.debt.DebtModelLookup;
+import org.sonar.server.debt.DebtModelOperations;
+import org.sonar.server.debt.DebtModelPluginRepository;
+import org.sonar.server.debt.DebtModelService;
+import org.sonar.server.debt.DebtModelXMLExporter;
+import org.sonar.server.debt.DebtRulesXMLImporter;
import org.sonar.server.duplication.ws.DuplicationsJsonWriter;
import org.sonar.server.duplication.ws.DuplicationsParser;
import org.sonar.server.duplication.ws.DuplicationsWs;
-import org.sonar.server.issue.*;
+import org.sonar.server.issue.ActionService;
+import org.sonar.server.issue.AssignAction;
+import org.sonar.server.issue.CommentAction;
+import org.sonar.server.issue.DefaultIssueFinder;
+import org.sonar.server.issue.InternalRubyIssueService;
+import org.sonar.server.issue.IssueBulkChangeService;
+import org.sonar.server.issue.IssueChangelogFormatter;
+import org.sonar.server.issue.IssueChangelogService;
+import org.sonar.server.issue.IssueCommentService;
+import org.sonar.server.issue.IssueService;
+import org.sonar.server.issue.IssueStatsFinder;
+import org.sonar.server.issue.PlanAction;
+import org.sonar.server.issue.PublicRubyIssueService;
+import org.sonar.server.issue.ServerIssueStorage;
+import org.sonar.server.issue.SetSeverityAction;
+import org.sonar.server.issue.TransitionAction;
import org.sonar.server.issue.actionplan.ActionPlanService;
import org.sonar.server.issue.actionplan.ActionPlanWs;
import org.sonar.server.issue.db.IssueDao;
import org.sonar.server.platform.ws.RestartHandler;
import org.sonar.server.platform.ws.ServerWs;
import org.sonar.server.platform.ws.SystemWs;
-import org.sonar.server.plugins.*;
+import org.sonar.server.plugins.InstalledPluginReferentialFactory;
+import org.sonar.server.plugins.PluginDownloader;
+import org.sonar.server.plugins.ServerExtensionInstaller;
+import org.sonar.server.plugins.ServerPluginJarInstaller;
+import org.sonar.server.plugins.ServerPluginJarsInstaller;
+import org.sonar.server.plugins.ServerPluginRepository;
+import org.sonar.server.plugins.UpdateCenterClient;
+import org.sonar.server.plugins.UpdateCenterMatrixFactory;
import org.sonar.server.qualitygate.QgateProjectFinder;
import org.sonar.server.qualitygate.QualityGates;
import org.sonar.server.qualitygate.RegisterQualityGates;
-import org.sonar.server.qualitygate.ws.*;
-import org.sonar.server.qualityprofile.*;
+import org.sonar.server.qualitygate.ws.QGatesAppAction;
+import org.sonar.server.qualitygate.ws.QGatesCopyAction;
+import org.sonar.server.qualitygate.ws.QGatesCreateAction;
+import org.sonar.server.qualitygate.ws.QGatesCreateConditionAction;
+import org.sonar.server.qualitygate.ws.QGatesDeleteConditionAction;
+import org.sonar.server.qualitygate.ws.QGatesDeselectAction;
+import org.sonar.server.qualitygate.ws.QGatesDestroyAction;
+import org.sonar.server.qualitygate.ws.QGatesListAction;
+import org.sonar.server.qualitygate.ws.QGatesRenameAction;
+import org.sonar.server.qualitygate.ws.QGatesSearchAction;
+import org.sonar.server.qualitygate.ws.QGatesSelectAction;
+import org.sonar.server.qualitygate.ws.QGatesSetAsDefaultAction;
+import org.sonar.server.qualitygate.ws.QGatesShowAction;
+import org.sonar.server.qualitygate.ws.QGatesUnsetDefaultAction;
+import org.sonar.server.qualitygate.ws.QGatesUpdateConditionAction;
+import org.sonar.server.qualitygate.ws.QGatesWs;
+import org.sonar.server.qualityprofile.BuiltInProfiles;
+import org.sonar.server.qualityprofile.QProfileBackuper;
+import org.sonar.server.qualityprofile.QProfileCopier;
+import org.sonar.server.qualityprofile.QProfileExporters;
+import org.sonar.server.qualityprofile.QProfileFactory;
+import org.sonar.server.qualityprofile.QProfileLoader;
+import org.sonar.server.qualityprofile.QProfileLookup;
+import org.sonar.server.qualityprofile.QProfileProjectLookup;
+import org.sonar.server.qualityprofile.QProfileProjectOperations;
+import org.sonar.server.qualityprofile.QProfileRepositoryExporter;
+import org.sonar.server.qualityprofile.QProfileReset;
+import org.sonar.server.qualityprofile.QProfileService;
+import org.sonar.server.qualityprofile.QProfiles;
+import org.sonar.server.qualityprofile.RegisterQualityProfiles;
+import org.sonar.server.qualityprofile.RuleActivator;
+import org.sonar.server.qualityprofile.RuleActivatorContextFactory;
import org.sonar.server.qualityprofile.db.ActiveRuleDao;
import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
import org.sonar.server.qualityprofile.index.ActiveRuleNormalizer;
-import org.sonar.server.qualityprofile.ws.*;
-import org.sonar.server.rule.*;
+import org.sonar.server.qualityprofile.ws.BulkRuleActivationActions;
+import org.sonar.server.qualityprofile.ws.ProfilesWs;
+import org.sonar.server.qualityprofile.ws.QProfileRestoreBuiltInAction;
+import org.sonar.server.qualityprofile.ws.QProfilesWs;
+import org.sonar.server.qualityprofile.ws.RuleActivationActions;
+import org.sonar.server.rule.DefaultRuleFinder;
+import org.sonar.server.rule.DeprecatedRulesDefinition;
+import org.sonar.server.rule.RegisterRules;
+import org.sonar.server.rule.RubyRuleService;
+import org.sonar.server.rule.RuleCreator;
+import org.sonar.server.rule.RuleDefinitionsLoader;
+import org.sonar.server.rule.RuleDeleter;
+import org.sonar.server.rule.RuleOperations;
+import org.sonar.server.rule.RuleRepositories;
+import org.sonar.server.rule.RuleService;
+import org.sonar.server.rule.RuleUpdater;
import org.sonar.server.rule.db.RuleDao;
import org.sonar.server.rule.index.RuleIndex;
import org.sonar.server.rule.index.RuleNormalizer;
-import org.sonar.server.rule.ws.*;
-import org.sonar.server.search.*;
+import org.sonar.server.rule.ws.ActiveRuleCompleter;
+import org.sonar.server.rule.ws.AppAction;
+import org.sonar.server.rule.ws.DeleteAction;
+import org.sonar.server.rule.ws.RuleMapping;
+import org.sonar.server.rule.ws.RulesWebService;
+import org.sonar.server.rule.ws.SearchAction;
+import org.sonar.server.rule.ws.TagsAction;
+import org.sonar.server.rule.ws.UpdateAction;
+import org.sonar.server.search.IndexClient;
+import org.sonar.server.search.IndexQueue;
+import org.sonar.server.search.IndexSynchronizer;
+import org.sonar.server.search.SearchClient;
+import org.sonar.server.search.SearchHealth;
import org.sonar.server.source.CodeColorizers;
import org.sonar.server.source.DeprecatedSourceDecorator;
import org.sonar.server.source.HtmlSourceDecorator;
import org.sonar.server.source.ws.ScmWriter;
import org.sonar.server.source.ws.ShowAction;
import org.sonar.server.source.ws.SourcesWs;
-import org.sonar.server.startup.*;
+import org.sonar.server.startup.CleanPreviewAnalysisCache;
+import org.sonar.server.startup.CopyRequirementsFromCharacteristicsToRules;
+import org.sonar.server.startup.GeneratePluginIndex;
+import org.sonar.server.startup.GwtPublisher;
+import org.sonar.server.startup.JdbcDriverDeployer;
+import org.sonar.server.startup.LogServerId;
+import org.sonar.server.startup.RegisterDashboards;
+import org.sonar.server.startup.RegisterDebtModel;
+import org.sonar.server.startup.RegisterMetrics;
+import org.sonar.server.startup.RegisterNewMeasureFilters;
+import org.sonar.server.startup.RegisterPermissionTemplates;
+import org.sonar.server.startup.RegisterServletFilters;
+import org.sonar.server.startup.RenameDeprecatedPropertyKeys;
+import org.sonar.server.startup.ServerMetadataPersister;
import org.sonar.server.test.CoverageService;
-import org.sonar.server.test.ws.*;
+import org.sonar.server.test.ws.CoverageShowAction;
+import org.sonar.server.test.ws.CoverageWs;
+import org.sonar.server.test.ws.TestsCoveredFilesAction;
+import org.sonar.server.test.ws.TestsShowAction;
+import org.sonar.server.test.ws.TestsTestCasesAction;
+import org.sonar.server.test.ws.TestsWs;
import org.sonar.server.text.MacroInterpreter;
import org.sonar.server.text.RubyTextService;
import org.sonar.server.ui.JRubyI18n;
import org.sonar.server.ui.PageDecorations;
import org.sonar.server.ui.Views;
import org.sonar.server.updatecenter.ws.UpdateCenterWs;
-import org.sonar.server.user.*;
+import org.sonar.server.user.DefaultUserService;
+import org.sonar.server.user.DoPrivileged;
+import org.sonar.server.user.GroupMembershipFinder;
+import org.sonar.server.user.GroupMembershipService;
+import org.sonar.server.user.NewUserNotifier;
+import org.sonar.server.user.SecurityRealmFactory;
import org.sonar.server.user.ws.FavoritesWs;
import org.sonar.server.user.ws.UserPropertiesWs;
import org.sonar.server.user.ws.UsersWs;
-import org.sonar.server.util.*;
+import org.sonar.server.util.BooleanTypeValidation;
+import org.sonar.server.util.FloatTypeValidation;
+import org.sonar.server.util.IntegerTypeValidation;
+import org.sonar.server.util.StringListTypeValidation;
+import org.sonar.server.util.StringTypeValidation;
+import org.sonar.server.util.TextTypeValidation;
+import org.sonar.server.util.TypeValidations;
import org.sonar.server.ws.ListingWs;
import org.sonar.server.ws.WebServiceEngine;
Collection level1Components() {
List components = Lists.newArrayList(rootComponents);
components.addAll(Arrays.asList(
- new BaseConfiguration(),
ServerSettings.class,
ServerImpl.class,
Logback.class,
*/
package org.sonar.server.platform;
-import org.apache.commons.configuration.Configuration;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
-import javax.annotation.Nullable;
-
import java.util.Collections;
import java.util.Map;
import java.util.Properties;
public class ServerSettings extends Settings {
private final Properties properties;
- private Configuration deprecatedConfiguration;
- public ServerSettings(PropertyDefinitions definitions, Configuration deprecatedConfiguration, Properties properties) {
+ public ServerSettings(PropertyDefinitions definitions, Properties properties) {
super(definitions);
- this.deprecatedConfiguration = deprecatedConfiguration;
this.properties = properties;
load(Collections.<String, String>emptyMap());
// Secret key is loaded from conf/sonar.properties
return this;
}
-
- @Override
- protected void doOnSetProperty(String key, @Nullable String value) {
- deprecatedConfiguration.setProperty(key, value);
- }
-
- @Override
- protected void doOnRemoveProperty(String key) {
- deprecatedConfiguration.clearProperty(key);
- }
-
- @Override
- protected void doOnClearProperties() {
- deprecatedConfiguration.clear();
- }
}
package org.sonar.server.platform;
import com.google.common.collect.ImmutableMap;
-import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentMatcher;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.argThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class PersistentSettingsTest {
settings = new ServerSettings(
new PropertyDefinitions(),
- new PropertiesConfiguration(),
new Properties());
}
public void load_database_properties_at_startup() {
when(dao.selectGlobalProperties()).thenReturn(Arrays.asList(
new PropertyDto().setKey("in_db").setValue("bar")
- ));
+ ));
PersistentSettings persistentSettings = new PersistentSettings(dao, settings);
persistentSettings.start();
package org.sonar.server.platform;
import com.google.common.collect.ImmutableMap;
-import org.apache.commons.configuration.BaseConfiguration;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.config.PropertyDefinitions;
properties.put("hello", "world");
properties.put("in_file", "true");
properties.put("ServerSettingsTestEnv", "in_file");
- settings = new ServerSettings(new PropertyDefinitions(), new BaseConfiguration(), properties);
+ settings = new ServerSettings(new PropertyDefinitions(), properties);
}
@Test
assertThat(settings.getString("in_file")).isEqualTo("true");
}
- @Test
- public void synchronize_deprecated_commons_configuration() {
- BaseConfiguration deprecated = new BaseConfiguration();
- ServerSettings settings = new ServerSettings(new PropertyDefinitions(), deprecated, properties);
-
- assertThat(settings.getString("in_file")).isEqualTo("true");
- assertThat(deprecated.getString("in_file")).isEqualTo("true");
-
- assertThat(deprecated.getString("foo")).isNull();
- settings.setProperty("foo", "bar");
- assertThat(deprecated.getString("foo")).isEqualTo("bar");
- settings.removeProperty("foo");
- assertThat(deprecated.getString("foo")).isNull();
- }
}
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
- <groupId>commons-configuration</groupId>
- <artifactId>commons-configuration</artifactId>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
*/
package org.sonar.batch;
-import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.project.MavenProject;
import org.slf4j.Logger;
checkCurrentAnalysisIsTheLatestOne(project.getKey(), analysisDate);
project
- // will be populated by ProjectSettings
- .setConfiguration(new PropertiesConfiguration())
.setAnalysisDate(analysisDate)
.setAnalysisVersion(loadAnalysisVersion())
.setAnalysisType(loadAnalysisType());
Snapshot lastSnapshot = databaseSession.getSingleResult(Snapshot.class, "resourceId", persistedProject.getId(), "last", true);
if (lastSnapshot != null && !lastSnapshot.getCreatedAt().before(analysisDate)) {
throw new IllegalArgumentException(
- "'sonar.projectDate' property cannot be older than the date of the last known quality snapshot on this project. Value: '"+
+ "'sonar.projectDate' property cannot be older than the date of the last known quality snapshot on this project. Value: '" +
settings.getString(CoreProperties.PROJECT_DATE_PROPERTY) + "'. " +
- "Latest quality snapshot: '"+ DateUtils.formatDate(lastSnapshot.getCreatedAt()) +"'. This property may only be used to rebuild the past in a chronological order."
- );
+ "Latest quality snapshot: '" + DateUtils.formatDate(lastSnapshot.getCreatedAt()) + "'. This property may only be used to rebuild the past in a chronological order.");
}
}
*/
package org.sonar.batch.bootstrap;
-import org.apache.commons.configuration.PropertiesConfiguration;
import org.sonar.api.CoreProperties;
import org.sonar.api.Plugin;
import org.sonar.api.config.EmailSettings;
private void addBootstrapComponents() {
add(
- new PropertiesConfiguration(),
new BootstrapProperties(bootstrapProperties),
AnalysisMode.class,
BatchPluginRepository.class,
*/
package org.sonar.batch.bootstrap;
-import org.apache.commons.configuration.Configuration;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.MessageException;
import org.sonar.batch.protocol.input.GlobalReferentials;
-import javax.annotation.Nullable;
-
public class GlobalSettings extends Settings {
- private Configuration deprecatedConfiguration;
-
private final BootstrapProperties bootstrapProps;
private final GlobalReferentials globalReferentials;
private final AnalysisMode mode;
public GlobalSettings(BootstrapProperties bootstrapProps, PropertyDefinitions propertyDefinitions,
- GlobalReferentials globalReferentials, Configuration deprecatedConfiguration, AnalysisMode mode) {
+ GlobalReferentials globalReferentials, AnalysisMode mode) {
super(propertyDefinitions);
this.mode = mode;
getEncryption().setPathToSecretKey(bootstrapProps.property(CoreProperties.ENCRYPTION_SECRET_KEY_PATH));
this.bootstrapProps = bootstrapProps;
this.globalReferentials = globalReferentials;
- this.deprecatedConfiguration = deprecatedConfiguration;
init();
}
addProperties(bootstrapProps.properties());
}
- @Override
- protected void doOnSetProperty(String key, @Nullable String value) {
- deprecatedConfiguration.setProperty(key, value);
- }
-
- @Override
- protected void doOnRemoveProperty(String key) {
- deprecatedConfiguration.clearProperty(key);
- }
-
- @Override
- protected void doOnClearProperties() {
- deprecatedConfiguration.clear();
- }
-
@Override
protected void doOnGetProperties(String key) {
if (mode.isPreview() && key.endsWith(".secured") && !key.contains(".license")) {
package org.sonar.batch.components;
import com.google.common.base.Strings;
-import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.database.model.Snapshot;
import javax.annotation.Nullable;
+
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
private PastSnapshotFinderByPreviousVersion finderByPreviousVersion;
public PastSnapshotFinder(PastSnapshotFinderByDays finderByDays, PastSnapshotFinderByVersion finderByVersion,
- PastSnapshotFinderByDate finderByDate, PastSnapshotFinderByPreviousAnalysis finderByPreviousAnalysis,
- PastSnapshotFinderByPreviousVersion finderByPreviousVersion) {
+ PastSnapshotFinderByDate finderByDate, PastSnapshotFinderByPreviousAnalysis finderByPreviousAnalysis,
+ PastSnapshotFinderByPreviousVersion finderByPreviousVersion) {
this.finderByDays = finderByDays;
this.finderByVersion = finderByVersion;
this.finderByDate = finderByDate;
this.finderByPreviousVersion = finderByPreviousVersion;
}
- /**
- * @deprecated since 3.6. Replaced by {@link #find(Snapshot projectSnapshot, String rootQualifier, Settings settings, int index) }
- */
- @Deprecated
- public PastSnapshot find(Snapshot projectSnapshot, Configuration conf, int index) {
- String propertyValue = getPropertyValue(conf, index);
- PastSnapshot pastSnapshot = find(projectSnapshot, index, propertyValue);
- if (pastSnapshot == null && StringUtils.isNotBlank(propertyValue)) {
- LoggerFactory.getLogger(PastSnapshotFinder.class).debug("Property " + CoreProperties.TIMEMACHINE_PERIOD_PREFIX + index + " is not valid: " + propertyValue);
- }
- return pastSnapshot;
- }
-
- /**
- * @deprecated since 3.6. Replace by {@link #getPropertyValue(String rootQualifier, Settings settings, int index) }
- */
- @Deprecated
- static String getPropertyValue(Configuration conf, int index) {
- String defaultValue = null;
- switch (index) {
- case 1:
- defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_1;
- break;
- case 2:
- defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_2;
- break;
- case 3:
- defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_3;
- break;
- case 4:
- defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_4;
- break;
- case 5:
- defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_5;
- break;
- }
- return conf.getString(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + index, defaultValue);
- }
-
public PastSnapshot find(Snapshot projectSnapshot, @Nullable String rootQualifier, Settings settings, int index) {
String propertyValue = getPropertyValue(rootQualifier, settings, index);
PastSnapshot pastSnapshot = find(projectSnapshot, index, propertyValue);
}
public void execute(Project project) {
+ project.setSettings(settings);
if (project.getLanguage() == null) {
initDeprecatedLanguage(project);
}
import org.sonar.api.platform.ComponentContainer;
import org.sonar.api.resources.Project;
import org.sonar.api.scan.filesystem.FileExclusions;
-import org.sonar.batch.*;
+import org.sonar.batch.DefaultProjectClasspath;
+import org.sonar.batch.DefaultSensorContext;
+import org.sonar.batch.DefaultTimeMachine;
+import org.sonar.batch.ProjectTree;
+import org.sonar.batch.ResourceFilters;
+import org.sonar.batch.ViolationFilters;
import org.sonar.batch.bootstrap.BatchExtensionDictionnary;
import org.sonar.batch.bootstrap.ExtensionInstaller;
import org.sonar.batch.bootstrap.ExtensionMatcher;
import org.sonar.batch.bootstrap.ExtensionUtils;
import org.sonar.batch.components.TimeMachineConfiguration;
-import org.sonar.batch.debt.*;
+import org.sonar.batch.debt.DebtDecorator;
+import org.sonar.batch.debt.IssueChangelogDebtCalculator;
+import org.sonar.batch.debt.NewDebtDecorator;
+import org.sonar.batch.debt.SqaleRatingDecorator;
+import org.sonar.batch.debt.SqaleRatingSettings;
import org.sonar.batch.events.EventBus;
import org.sonar.batch.index.DefaultIndex;
import org.sonar.batch.index.ResourcePersister;
import org.sonar.batch.qualitygate.GenerateQualityGateEvents;
import org.sonar.batch.qualitygate.QualityGateProvider;
import org.sonar.batch.qualitygate.QualityGateVerifier;
-import org.sonar.batch.rule.*;
-import org.sonar.batch.scan.filesystem.*;
+import org.sonar.batch.rule.ActiveRulesProvider;
+import org.sonar.batch.rule.ModuleQProfiles;
+import org.sonar.batch.rule.QProfileDecorator;
+import org.sonar.batch.rule.QProfileEventsDecorator;
+import org.sonar.batch.rule.QProfileSensor;
+import org.sonar.batch.rule.QProfileVerifier;
+import org.sonar.batch.rule.RulesProfileProvider;
+import org.sonar.batch.scan.filesystem.ComponentIndexer;
+import org.sonar.batch.scan.filesystem.DefaultModuleFileSystem;
+import org.sonar.batch.scan.filesystem.DeprecatedFileFilters;
+import org.sonar.batch.scan.filesystem.ExclusionFilters;
+import org.sonar.batch.scan.filesystem.FileIndexer;
+import org.sonar.batch.scan.filesystem.FileSystemLogger;
+import org.sonar.batch.scan.filesystem.InputFileBuilderFactory;
+import org.sonar.batch.scan.filesystem.LanguageDetectionFactory;
+import org.sonar.batch.scan.filesystem.ModuleFileSystemInitializer;
+import org.sonar.batch.scan.filesystem.ModuleInputFileCache;
+import org.sonar.batch.scan.filesystem.PreviousFileHashLoader;
+import org.sonar.batch.scan.filesystem.ProjectFileSystemAdapter;
+import org.sonar.batch.scan.filesystem.StatusDetectionFactory;
import org.sonar.batch.scan.report.JsonReport;
import org.sonar.batch.scan2.AnalyzerOptimizer;
import org.sonar.core.component.ScanPerspectives;
ProjectDefinition moduleDefinition = getComponentByType(ProjectTree.class).getProjectDefinition(module);
add(
moduleDefinition,
- module.getConfiguration(),
module,
ModuleSettings.class);
package org.sonar.batch.scan;
import com.google.common.collect.Lists;
-import org.apache.commons.configuration.Configuration;
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.batch.bootstrap.GlobalSettings;
import org.sonar.batch.protocol.input.ProjectReferentials;
-import javax.annotation.Nullable;
-
import java.util.List;
/**
*/
public class ModuleSettings extends Settings {
- private final Configuration deprecatedCommonsConf;
private final ProjectReferentials projectReferentials;
private AnalysisMode analysisMode;
- public ModuleSettings(GlobalSettings batchSettings, ProjectDefinition project, Configuration deprecatedCommonsConf, ProjectReferentials projectReferentials,
+ public ModuleSettings(GlobalSettings batchSettings, ProjectDefinition project, ProjectReferentials projectReferentials,
AnalysisMode analysisMode) {
super(batchSettings.getDefinitions());
this.projectReferentials = projectReferentials;
getEncryption().setPathToSecretKey(batchSettings.getString(CoreProperties.ENCRYPTION_SECRET_KEY_PATH));
LoggerFactory.getLogger(ModuleSettings.class).info("Load module settings");
- this.deprecatedCommonsConf = deprecatedCommonsConf;
init(project, batchSettings);
}
return result;
}
- @Override
- protected void doOnSetProperty(String key, @Nullable String value) {
- deprecatedCommonsConf.setProperty(key, value);
- }
-
- @Override
- protected void doOnRemoveProperty(String key) {
- deprecatedCommonsConf.clearProperty(key);
- }
-
- @Override
- protected void doOnClearProperties() {
- deprecatedCommonsConf.clear();
- }
-
@Override
protected void doOnGetProperties(String key) {
if (analysisMode.isPreview() && key.endsWith(".secured") && !key.contains(".license")) {
*/
package org.sonar.batch.scan;
-import org.apache.commons.configuration.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import org.sonar.batch.bootstrap.GlobalSettings;
import org.sonar.batch.protocol.input.ProjectReferentials;
-import javax.annotation.Nullable;
-
public class ProjectSettings extends Settings {
private static final Logger LOG = LoggerFactory.getLogger(ProjectSettings.class);
- private Configuration deprecatedConfiguration;
-
private final GlobalSettings globalSettings;
private final ProjectReferentials projectReferentials;
private final AnalysisMode mode;
public ProjectSettings(ProjectReactor reactor, GlobalSettings globalSettings, PropertyDefinitions propertyDefinitions,
- ProjectReferentials projectReferentials, Configuration deprecatedConfiguration, AnalysisMode mode) {
+ ProjectReferentials projectReferentials, AnalysisMode mode) {
super(propertyDefinitions);
this.mode = mode;
getEncryption().setPathToSecretKey(globalSettings.getString(CoreProperties.ENCRYPTION_SECRET_KEY_PATH));
this.globalSettings = globalSettings;
this.projectReferentials = projectReferentials;
- this.deprecatedConfiguration = deprecatedConfiguration;
init(reactor);
}
addProperties(reactor.getRoot().getProperties());
}
- @Override
- protected void doOnSetProperty(String key, @Nullable String value) {
- deprecatedConfiguration.setProperty(key, value);
- }
-
- @Override
- protected void doOnRemoveProperty(String key) {
- deprecatedConfiguration.clearProperty(key);
- }
-
- @Override
- protected void doOnClearProperties() {
- deprecatedConfiguration.clear();
- }
-
@Override
protected void doOnGetProperties(String key) {
if (mode.isPreview() && key.endsWith(".secured") && !key.contains(".license")) {
*/
package org.sonar.batch.bootstrap;
-import org.apache.commons.configuration.BaseConfiguration;
-import org.apache.commons.configuration.Configuration;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
GlobalReferentials globalRef;
ProjectDefinition project = ProjectDefinition.create().setKey("struts");
- Configuration deprecatedConf = new BaseConfiguration();
BootstrapProperties bootstrapProps;
private AnalysisMode mode;
public void should_load_global_settings() {
globalRef.globalSettings().put("sonar.cpd.cross", "true");
- GlobalSettings batchSettings = new GlobalSettings(bootstrapProps, new PropertyDefinitions(), globalRef, deprecatedConf, mode);
+ GlobalSettings batchSettings = new GlobalSettings(bootstrapProps, new PropertyDefinitions(), globalRef, mode);
assertThat(batchSettings.getBoolean("sonar.cpd.cross")).isTrue();
}
*/
package org.sonar.batch.components;
-import org.apache.commons.configuration.BaseConfiguration;
-import org.apache.commons.configuration.Configuration;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentMatcher;
assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue()));
}
- @Test
- public void should_find_with_configuration() {
- Configuration conf = new BaseConfiguration();
- conf.addProperty("sonar.timemachine.period1", "1.2");
- conf.addProperty("sonar.timemachine.period2", "1.2");
- conf.addProperty("sonar.timemachine.period3", "1.2");
- conf.addProperty("sonar.timemachine.period4", "1.2");
- conf.addProperty("sonar.timemachine.period5", "1.2");
-
- when(finderByVersion.findByVersion(null, "1.2")).thenReturn(new PastSnapshot("version", new Date(), new Snapshot()));
-
- PastSnapshot variationSnapshot = finder.find(null, conf, 1);
-
- verify(finderByVersion).findByVersion(null, "1.2");
- assertThat(variationSnapshot.getIndex(), is(1));
- assertThat(variationSnapshot.getMode(), is("version"));
- assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue()));
-
- assertThat(finder.find(null, conf, 2).getIndex(), is(2));
- assertThat(finder.find(null, conf, 3).getIndex(), is(3));
- assertThat(finder.find(null, conf, 4).getIndex(), is(4));
- assertThat(finder.find(null, conf, 5).getIndex(), is(5));
- }
-
@Test
public void should_find_by_number_of_days() {
when(finderByDays.findFromDays(null, 30)).thenReturn(new PastSnapshot("days", null).setModeParameter("30"));
public void should_find_by_date() throws ParseException {
final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
final Date date = format.parse("2010-05-18");
- when(finderByDate.findByDate((Snapshot)null, date)).thenReturn(new PastSnapshot("date", date, new Snapshot()));
+ when(finderByDate.findByDate((Snapshot) null, date)).thenReturn(new PastSnapshot("date", date, new Snapshot()));
PastSnapshot variationSnapshot = finder.find(null, 2, "2010-05-18");
Settings settings = new Settings().setProperty("sonar.timemachine.period1", "5");
assertThat(PastSnapshotFinder.getPropertyValue("FIL", settings, 1), is("5"));
- assertThat(PastSnapshotFinder.getPropertyValue("FIL",settings, 999), nullValue());
+ assertThat(PastSnapshotFinder.getPropertyValue("FIL", settings, 999), nullValue());
}
}
*/
package org.sonar.batch.index;
-import org.apache.commons.configuration.PropertiesConfiguration;
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.config.Settings;
import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.resources.Directory;
import org.sonar.api.resources.File;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
}
private static Project newProject(String key, String language) {
- PropertiesConfiguration configuration = new PropertiesConfiguration();
- configuration.setProperty("sonar.language", language);
- return new Project(key).setConfiguration(configuration).setAnalysisType(Project.AnalysisType.DYNAMIC);
+ Settings settings = new Settings();
+ settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, language);
+ return new Project(key).setSettings(settings).setAnalysisType(Project.AnalysisType.DYNAMIC);
}
private static Project newCopyProject(String key, String language, int copyResourceId) {
- PropertiesConfiguration configuration = new PropertiesConfiguration();
- configuration.setProperty("sonar.language", language);
- return new CopyProject(key, copyResourceId).setConfiguration(configuration).setAnalysisType(Project.AnalysisType.DYNAMIC);
+ Settings settings = new Settings();
+ settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, language);
+ return new CopyProject(key, copyResourceId).setSettings(settings).setAnalysisType(Project.AnalysisType.DYNAMIC);
}
private static class CopyProject extends Project implements ResourceCopy {
*/
package org.sonar.batch.index;
-import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.slf4j.Logger;
+import org.sonar.api.CoreProperties;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile;
+import org.sonar.api.config.Settings;
import org.sonar.api.resources.Project;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
}
private static Project newProject(String key, String language) {
- PropertiesConfiguration configuration = new PropertiesConfiguration();
- configuration.setProperty("sonar.language", language);
- return new Project(key).setConfiguration(configuration).setAnalysisType(Project.AnalysisType.DYNAMIC);
+ Settings settings = new Settings();
+ settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, language);
+ return new Project(key).setSettings(settings).setAnalysisType(Project.AnalysisType.DYNAMIC);
}
}
package org.sonar.batch.scan;
import com.google.common.collect.ImmutableMap;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
projectRef.addSettings("struts-core", ImmutableMap.of("on-module", "true", "overridding", "module"));
ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");
- Configuration deprecatedConf = new PropertiesConfiguration();
- ModuleSettings moduleSettings = new ModuleSettings(batchSettings, module, deprecatedConf, projectRef, mode);
+ ModuleSettings moduleSettings = new ModuleSettings(batchSettings, module, projectRef, mode);
assertThat(moduleSettings.getString("overridding")).isEqualTo("module");
assertThat(moduleSettings.getString("on-batch")).isEqualTo("true");
assertThat(moduleSettings.getString("on-module")).isEqualTo("true");
- assertThat(deprecatedConf.getString("overridding")).isEqualTo("module");
- assertThat(deprecatedConf.getString("on-batch")).isEqualTo("true");
- assertThat(deprecatedConf.getString("on-module")).isEqualTo("true");
}
@Test
projectRef.addSettings("struts-core", ImmutableMap.of("sonar.foo.license.secured", "bar2"));
ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");
- Configuration deprecatedConf = new PropertiesConfiguration();
- ModuleSettings moduleSettings = new ModuleSettings(batchSettings, module, deprecatedConf, projectRef, mode);
+ ModuleSettings moduleSettings = new ModuleSettings(batchSettings, module, projectRef, mode);
assertThat(moduleSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
assertThat(moduleSettings.getString("sonar.foo.secured")).isEqualTo("bar");
when(mode.isPreview()).thenReturn(true);
ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");
- Configuration deprecatedConf = new PropertiesConfiguration();
- ModuleSettings moduleSettings = new ModuleSettings(batchSettings, module, deprecatedConf, projectRef, mode);
+ ModuleSettings moduleSettings = new ModuleSettings(batchSettings, module, projectRef, mode);
assertThat(moduleSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
*/
package org.sonar.batch.scan;
-import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.BatchExtension;
parentContainer.add(System2.INSTANCE);
parentContainer.add(bootstrapProperties);
parentContainer.add(analysisMode);
- parentContainer.add(new PropertiesConfiguration());
GlobalReferentials globalRef = new GlobalReferentials();
- settings = new GlobalSettings(bootstrapProperties, new PropertyDefinitions(), globalRef, new PropertiesConfiguration(), analysisMode);
+ settings = new GlobalSettings(bootstrapProperties, new PropertyDefinitions(), globalRef, analysisMode);
parentContainer.add(settings);
ProjectReferentialsLoader projectReferentialsLoader = new ProjectReferentialsLoader() {
@Override
package org.sonar.batch.scan;
import com.google.common.collect.ImmutableMap;
-import org.apache.commons.configuration.BaseConfiguration;
-import org.apache.commons.configuration.Configuration;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
ProjectReferentials projectRef;
ProjectDefinition project = ProjectDefinition.create().setKey("struts");
- Configuration deprecatedConf = new BaseConfiguration();
GlobalSettings bootstrapProps;
private AnalysisMode mode;
public void prepare() {
projectRef = new ProjectReferentials();
mode = mock(AnalysisMode.class);
- bootstrapProps = new GlobalSettings(new BootstrapProperties(Collections.<String, String>emptyMap()), new PropertyDefinitions(), new GlobalReferentials(), deprecatedConf, mode);
+ bootstrapProps = new GlobalSettings(new BootstrapProperties(Collections.<String, String>emptyMap()), new PropertyDefinitions(), new GlobalReferentials(), mode);
}
@Test
public void should_load_project_props() {
project.setProperty("project.prop", "project");
- ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), projectRef, deprecatedConf, mode);
+ ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), projectRef, mode);
assertThat(batchSettings.getString("project.prop")).isEqualTo("project");
}
public void should_load_project_root_settings() {
projectRef.addSettings("struts", ImmutableMap.of("sonar.cpd.cross", "true", "sonar.java.coveragePlugin", "jacoco"));
- ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), projectRef, deprecatedConf, mode);
+ ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), projectRef, mode);
assertThat(batchSettings.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
}
projectRef.addSettings("struts:mybranch", ImmutableMap.of("sonar.cpd.cross", "true", "sonar.java.coveragePlugin", "jacoco"));
- ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), projectRef, deprecatedConf, mode);
+ ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), projectRef, mode);
assertThat(batchSettings.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
}
public void should_not_fail_when_accessing_secured_properties() {
projectRef.addSettings("struts", ImmutableMap.of("sonar.foo.secured", "bar", "sonar.foo.license.secured", "bar2"));
- ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), projectRef, deprecatedConf, mode);
+ ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), projectRef, mode);
assertThat(batchSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
assertThat(batchSettings.getString("sonar.foo.secured")).isEqualTo("bar");
when(mode.isPreview()).thenReturn(true);
- ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), projectRef, deprecatedConf, mode);
+ ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), projectRef, mode);
assertThat(batchSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
thrown.expect(MessageException.class);
batchSettings.getString("sonar.foo.secured");
}
- @Test
- public void should_forward_to_deprecated_commons_configuration() {
- projectRef.addSettings("struts", ImmutableMap.of("sonar.cpd.cross", "true", "sonar.java.coveragePlugin", "jacoco"));
-
- ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), projectRef, deprecatedConf, mode);
-
- assertThat(deprecatedConf.getString("sonar.cpd.cross")).isEqualTo("true");
- assertThat(deprecatedConf.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
-
- batchSettings.removeProperty("sonar.cpd.cross");
- assertThat(deprecatedConf.getString("sonar.cpd.cross")).isNull();
- assertThat(deprecatedConf.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
-
- batchSettings.clear();
- assertThat(deprecatedConf.getString("sonar.cpd.cross")).isNull();
- assertThat(deprecatedConf.getString("sonar.java.coveragePlugin")).isNull();
- }
-
}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.database.configuration;
-
-import org.apache.commons.configuration.BaseConfiguration;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.jpa.session.DatabaseSessionFactory;
-
-import java.util.List;
-
-/**
- * IMPORTANT : This class can't be moved to org.sonar.jpa.dao for backward-compatibility reasons.
- * This class is still used in some plugins.
- *
- * @since 1.10
- * @deprecated in 3.7. Replaced by {@link org.sonar.api.config.Settings}
- */
-@Deprecated
-public class DatabaseConfiguration extends BaseConfiguration {
- private DatabaseSessionFactory sessionFactory;
- private DatabaseSession session;
-
- public DatabaseConfiguration(DatabaseSessionFactory sessionFactory) {
- this.sessionFactory = sessionFactory;
- load();
- }
-
- public DatabaseConfiguration(DatabaseSession session) {
- this.session = session;
- load();
- }
-
- public final void load() {
- clear();
-
- // Ugly workaround before the move to myBatis
- // Session is not up-to-date when Ruby on Rails inserts new rows in its own transaction. Seems like
- // Hibernate keeps a cache...
- getSession().commit();
-
- List<Property> properties = getSession()
- .createQuery("from " + Property.class.getSimpleName() + " p where p.resourceId is null and p.userId is null")
- .getResultList();
-
- if (properties != null) {
- for (Property property : properties) {
- setProperty(property.getKey(), property.getValue());
- }
- }
- }
-
- private DatabaseSession getSession() {
- if (session != null) {
- return session;
- }
- return sessionFactory.getSession();
- }
-}
* This class is still used in some plugins.
*
* @since 1.10
+ * @deprecated since 5.0 Hibernate is deprecated
*/
+@Deprecated
@Entity
@Table(name = "properties")
public class Property extends BaseIdentifiable {
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.database.configuration;
-
-import org.junit.Test;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-public class DatabaseConfigurationTest extends AbstractDbUnitTestCase {
-
- @Test
- public void shouldLoadPropertiesFromDatabase() {
- setupData("some-properties");
-
- DatabaseConfiguration configuration = new DatabaseConfiguration(getSessionFactory());
-
- assertEquals("value1", configuration.getString("key1"));
- assertEquals("value2", configuration.getString("key2"));
- assertNull(configuration.getString("keyxxxx"));
- }
-}
package org.sonar.api.resources;
import com.google.common.collect.Lists;
-import org.apache.commons.lang.StringUtils;
import java.util.Collection;
import java.util.List;
// utility class with only static methods
}
- /**
- * @deprecated since 2.6 use JavaUtils.getTargetVersion() instead.
- */
- @Deprecated
- public static String getJavaVersion(Project project) {
- String version = project.getConfiguration() != null ? project.getConfiguration().getString("sonar.java.target") : null;
- return StringUtils.isNotBlank(version) ? version : "1.5";
- }
-
- /**
- * @deprecated since 2.6 use JavaUtils.getSourceVersion() instead.
- */
- @Deprecated
- public static String getJavaSourceVersion(Project project) {
- String version = project.getConfiguration() != null ? project.getConfiguration().getString("sonar.java.source") : null;
- return StringUtils.isNotBlank(version) ? version : "1.5";
- }
-
/**
* @since 2.7
* @deprecated in 4.2. Replaced by org.sonar.api.resources.InputFileUtils#toFiles()
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.utils;
-
-import com.google.common.collect.Maps;
-import org.apache.commons.io.FilenameUtils;
-import org.apache.commons.lang.StringUtils;
-import org.codehaus.staxmate.in.SMHierarchicCursor;
-import org.codehaus.staxmate.in.SMInputCursor;
-import org.sonar.api.batch.SensorContext;
-import org.sonar.api.measures.CoverageMeasuresBuilder;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.resources.Resource;
-
-import javax.xml.stream.XMLStreamException;
-
-import java.io.File;
-import java.text.ParseException;
-import java.util.Map;
-
-import static java.util.Locale.ENGLISH;
-import static org.sonar.api.utils.ParsingUtils.parseNumber;
-
-/**
- * @since 3.7
- * @deprecated in 4.2. This class should be handled internally by plugins
- */
-@Deprecated
-public class CoberturaReportParserUtils {
-
- private CoberturaReportParserUtils() {
- }
-
- public interface FileResolver {
-
- /**
- * Return a SonarQube file resource from a filename present in Cobertura report
- */
- Resource resolve(String filename);
- }
-
- /**
- * Parse a Cobertura xml report and create measures accordingly
- */
- public static void parseReport(File xmlFile, final SensorContext context, final FileResolver fileResolver) {
- try {
- StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() {
-
- public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException {
- rootCursor.advance();
- collectPackageMeasures(rootCursor.descendantElementCursor("package"), context, fileResolver);
- }
- });
- parser.parse(xmlFile);
- } catch (XMLStreamException e) {
- throw new XmlParserException(e);
- }
- }
-
- private static void collectPackageMeasures(SMInputCursor pack, SensorContext context, final FileResolver fileResolver) throws XMLStreamException {
- while (pack.getNext() != null) {
- Map<String, CoverageMeasuresBuilder> builderByFilename = Maps.newHashMap();
- collectFileMeasures(pack.descendantElementCursor("class"), builderByFilename);
- for (Map.Entry<String, CoverageMeasuresBuilder> entry : builderByFilename.entrySet()) {
- String filename = sanitizeFilename(entry.getKey());
- Resource file = fileResolver.resolve(filename);
- if (fileExists(context, file)) {
- for (Measure measure : entry.getValue().createMeasures()) {
- context.saveMeasure(file, measure);
- }
- }
- }
- }
- }
-
- private static boolean fileExists(SensorContext context, Resource file) {
- return context.getResource(file) != null;
- }
-
- private static void collectFileMeasures(SMInputCursor clazz, Map<String, CoverageMeasuresBuilder> builderByFilename) throws XMLStreamException {
- while (clazz.getNext() != null) {
- String fileName = clazz.getAttrValue("filename");
- CoverageMeasuresBuilder builder = builderByFilename.get(fileName);
- if (builder == null) {
- builder = CoverageMeasuresBuilder.create();
- builderByFilename.put(fileName, builder);
- }
- collectFileData(clazz, builder);
- }
- }
-
- private static void collectFileData(SMInputCursor clazz, CoverageMeasuresBuilder builder) throws XMLStreamException {
- SMInputCursor line = clazz.childElementCursor("lines").advance().childElementCursor("line");
- while (line.getNext() != null) {
- int lineId = Integer.parseInt(line.getAttrValue("number"));
- try {
- builder.setHits(lineId, (int) parseNumber(line.getAttrValue("hits"), ENGLISH));
- } catch (ParseException e) {
- throw new XmlParserException(e);
- }
-
- String isBranch = line.getAttrValue("branch");
- String text = line.getAttrValue("condition-coverage");
- if (StringUtils.equals(isBranch, "true") && StringUtils.isNotBlank(text)) {
- String[] conditions = StringUtils.split(StringUtils.substringBetween(text, "(", ")"), "/");
- builder.setConditions(lineId, Integer.parseInt(conditions[1]), Integer.parseInt(conditions[0]));
- }
- }
- }
-
- private static String sanitizeFilename(String s) {
- String fileName = FilenameUtils.removeExtension(s);
- fileName = fileName.replace('/', '.').replace('\\', '.');
- return fileName;
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.plugins.cobertura.api;
-
-import org.sonar.api.batch.SensorContext;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.utils.CoberturaReportParserUtils;
-import org.sonar.api.utils.CoberturaReportParserUtils.FileResolver;
-
-import java.io.File;
-
-/**
- * @since 2.4
- * @deprecated since 3.7 Used to keep backward compatibility since extraction
- * of Cobertura plugin.
- */
-@Deprecated
-public abstract class AbstractCoberturaParser {
-
- public void parseReport(File xmlFile, final SensorContext context) {
- CoberturaReportParserUtils.parseReport(xmlFile, context, new FileResolver() {
- @Override
- public Resource resolve(String filename) {
- return getResource(filename);
- }
- });
- }
-
- protected abstract Resource getResource(String fileName);
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.plugins.cobertura.api;
-
-import org.sonar.api.batch.maven.MavenPlugin;
-import org.sonar.api.batch.maven.MavenUtils;
-import org.sonar.api.resources.Project;
-import org.sonar.api.utils.Logs;
-
-import java.io.File;
-
-/**
- * @since 2.4
- * @deprecated since 3.7 Used to keep backward compatibility since extraction
- * of Cobertura plugin. Should be duplicated in each project.
- */
-@Deprecated
-public final class CoberturaUtils {
-
- public static final String COBERTURA_GROUP_ID = MavenUtils.GROUP_ID_CODEHAUS_MOJO;
- public static final String COBERTURA_ARTIFACT_ID = "cobertura-maven-plugin";
- public static final String COBERTURA_REPORT_PATH_PROPERTY = "sonar.cobertura.reportPath";
-
- /**
- * @deprecated in 2.8, because assumes that Sonar executed from Maven. Not used any more in sonar-cobertura-plugin.
- * See http://jira.codehaus.org/browse/SONAR-2321
- * Used in groovy and flex plugins.
- */
- @Deprecated
- public static File getReport(Project project) {
- File report = getReportFromProperty(project);
- if (report == null) {
- report = getReportFromPluginConfiguration(project);
- }
- if (report == null) {
- report = getReportFromDefaultPath(project);
- }
-
- if (report == null || !report.exists() || !report.isFile()) {
- Logs.INFO.warn("Cobertura report not found at {}", report);
- report = null;
- }
- return report;
- }
-
- private static File getReportFromProperty(Project project) {
- String path = (String) project.getProperty(COBERTURA_REPORT_PATH_PROPERTY);
- if (path != null) {
- return project.getFileSystem().resolvePath(path);
- }
- return null;
- }
-
- private static File getReportFromPluginConfiguration(Project project) {
- MavenPlugin mavenPlugin = MavenPlugin.getPlugin(project.getPom(), COBERTURA_GROUP_ID, COBERTURA_ARTIFACT_ID);
- if (mavenPlugin != null) {
- String path = mavenPlugin.getParameter("outputDirectory");
- if (path != null) {
- return new File(project.getFileSystem().resolvePath(path), "coverage.xml");
- }
- }
- return null;
- }
-
- private static File getReportFromDefaultPath(Project project) {
- return new File(project.getFileSystem().getReportOutputDir(), "cobertura/coverage.xml");
- }
-
- private CoberturaUtils() {
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.utils;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.batch.SensorContext;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.resources.JavaPackage;
-import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.resources.Scopes;
-import org.sonar.api.test.IsMeasure;
-import org.sonar.api.test.IsResource;
-import org.sonar.api.utils.CoberturaReportParserUtils.FileResolver;
-
-import java.io.File;
-import java.net.URISyntaxException;
-
-import static org.hamcrest.Matchers.is;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyDouble;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class CoberturaReportParserUtilsTest {
-
- private SensorContext context;
-
- @Before
- public void setUp() {
- context = mock(SensorContext.class);
- }
-
- private static FileResolver JAVA_FILE_RESOLVER = new FileResolver() {
-
- @Override
- public Resource resolve(String filename) {
- return new org.sonar.api.resources.File(filename);
- }
- };
-
- @Test
- public void doNotCollectProjectCoverage() throws URISyntaxException {
- CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER);
-
- verify(context, never()).saveMeasure(eq(CoreMetrics.COVERAGE), anyDouble());
- }
-
- @Test
- public void doNotCollectProjectLineCoverage() throws URISyntaxException {
- CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER);
-
- verify(context, never()).saveMeasure(eq(CoreMetrics.LINE_COVERAGE), anyDouble());
- verify(context, never()).saveMeasure(argThat(new IsMeasure(CoreMetrics.COVERAGE_LINE_HITS_DATA)));
- }
-
- @Test
- public void doNotCollectProjectBranchCoverage() throws URISyntaxException {
- CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER);
-
- verify(context, never()).saveMeasure(eq(CoreMetrics.BRANCH_COVERAGE), anyDouble());
- }
-
- @Test
- public void collectPackageLineCoverage() throws URISyntaxException {
- CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER);
-
- verify(context, never()).saveMeasure((Resource) argThat(is(JavaPackage.class)), eq(CoreMetrics.LINE_COVERAGE), anyDouble());
- verify(context, never()).saveMeasure((Resource) argThat(is(JavaPackage.class)), eq(CoreMetrics.UNCOVERED_LINES), anyDouble());
- }
-
- @Test
- public void collectPackageBranchCoverage() throws URISyntaxException {
- CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER);
-
- verify(context, never()).saveMeasure((Resource) argThat(is(JavaPackage.class)), eq(CoreMetrics.BRANCH_COVERAGE), anyDouble());
- verify(context, never()).saveMeasure((Resource) argThat(is(JavaPackage.class)), eq(CoreMetrics.UNCOVERED_CONDITIONS), anyDouble());
- }
-
- @Test
- public void packageCoverageIsCalculatedLaterByDecorator() throws URISyntaxException {
- CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER);
-
- verify(context, never()).saveMeasure((Resource) argThat(is(JavaPackage.class)), eq(CoreMetrics.COVERAGE), anyDouble());
- }
-
- @Test
- public void collectFileLineCoverage() throws URISyntaxException {
- when(context.getResource(any(Resource.class))).thenReturn(new org.sonar.api.resources.File("org.sonar.MyClass"));
- CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER);
-
- final org.sonar.api.resources.File file = new org.sonar.api.resources.File("org.apache.commons.chain.config.ConfigParser");
- verify(context).saveMeasure(eq(file), argThat(new IsMeasure(CoreMetrics.LINES_TO_COVER, 30.0)));
- verify(context).saveMeasure(eq(file), argThat(new IsMeasure(CoreMetrics.UNCOVERED_LINES, 5.0)));
- }
-
- @Test
- public void collectFileBranchCoverage() throws URISyntaxException {
- when(context.getResource(any(Resource.class))).thenReturn(new org.sonar.api.resources.File("org.sonar.MyClass"));
- CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER);
-
- final org.sonar.api.resources.File file = new org.sonar.api.resources.File("org.apache.commons.chain.config.ConfigParser");
- verify(context).saveMeasure(eq(file), argThat(new IsMeasure(CoreMetrics.CONDITIONS_TO_COVER, 6.0)));
- verify(context).saveMeasure(eq(file), argThat(new IsMeasure(CoreMetrics.UNCOVERED_CONDITIONS, 2.0)));
- }
-
- @Test
- public void testDoNotSaveMeasureOnResourceWhichDoesntExistInTheContext() throws URISyntaxException {
- when(context.getResource(any(Resource.class))).thenReturn(null);
- CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER);
- verify(context, never()).saveMeasure(any(Resource.class), any(Measure.class));
- }
-
- @Test
- public void javaInterfaceHasNoCoverage() throws URISyntaxException {
- CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER);
-
- final org.sonar.api.resources.File interfaze = new org.sonar.api.resources.File("org.apache.commons.chain.Chain");
- verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.COVERAGE)));
-
- verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.LINE_COVERAGE)));
- verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.LINES_TO_COVER)));
- verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.UNCOVERED_LINES)));
-
- verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.BRANCH_COVERAGE)));
- verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.CONDITIONS_TO_COVER)));
- verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.UNCOVERED_CONDITIONS)));
- }
-
- @Test
- public void shouldInsertCoverageAtFileLevel() throws URISyntaxException {
- File coverage = new File(getClass().getResource(
- "/org/sonar/api/utils/CoberturaReportParserUtilsTest/shouldInsertCoverageAtFileLevel/coverage.xml").toURI());
- when(context.getResource(any(Resource.class))).thenReturn(new org.sonar.api.resources.File("org.sonar.MyClass"));
- CoberturaReportParserUtils.parseReport(coverage, context, JAVA_FILE_RESOLVER);
-
- verify(context).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.InnerClass")),
- argThat(new IsMeasure(CoreMetrics.LINES_TO_COVER, 35.0)));
- verify(context).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.InnerClass")),
- argThat(new IsMeasure(CoreMetrics.UNCOVERED_LINES, 22.0)));
-
- verify(context).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.InnerClass")),
- argThat(new IsMeasure(CoreMetrics.CONDITIONS_TO_COVER, 4.0)));
- verify(context).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.InnerClass")),
- argThat(new IsMeasure(CoreMetrics.UNCOVERED_CONDITIONS, 3.0)));
-
- verify(context, never()).saveMeasure(
- argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.InnerClass$InnerClassInside")),
- argThat(new IsMeasure(CoreMetrics.LINES_TO_COVER)));
- verify(context, never()).saveMeasure(
- argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.InnerClass$InnerClassInside")),
- argThat(new IsMeasure(CoreMetrics.CONDITIONS_TO_COVER)));
- verify(context, never()).saveMeasure(
- argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.InnerClass$InnerClassInside")),
- argThat(new IsMeasure(CoreMetrics.UNCOVERED_CONDITIONS)));
- verify(context, never()).saveMeasure(
- argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.InnerClass$InnerClassInside")),
- argThat(new IsMeasure(CoreMetrics.UNCOVERED_LINES)));
-
- verify(context, never()).saveMeasure(
- argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.PrivateClass")),
- argThat(new IsMeasure(CoreMetrics.LINES_TO_COVER)));
- verify(context, never()).saveMeasure(
- argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.PrivateClass")),
- argThat(new IsMeasure(CoreMetrics.CONDITIONS_TO_COVER)));
- verify(context, never()).saveMeasure(
- argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.PrivateClass")),
- argThat(new IsMeasure(CoreMetrics.UNCOVERED_CONDITIONS)));
- verify(context, never()).saveMeasure(
- argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.PrivateClass")),
- argThat(new IsMeasure(CoreMetrics.UNCOVERED_LINES)));
-
- verify(context)
- .saveMeasure(
- eq(new org.sonar.api.resources.File("org.sonar.samples.InnerClass")),
- argThat(new IsMeasure(
- CoreMetrics.COVERAGE_LINE_HITS_DATA,
- "22=2;25=0;26=0;29=0;30=0;31=0;34=1;35=1;36=1;37=0;39=1;41=1;44=2;46=1;47=1;50=0;51=0;52=0;53=0;55=0;57=0;60=0;61=0;64=1;71=1;73=1;76=0;77=0;80=0;81=0;85=0;87=0;91=0;93=0;96=1")));
- }
-
- @Test
- public void collectFileLineHitsData() throws URISyntaxException {
- when(context.getResource(any(Resource.class))).thenReturn(new org.sonar.api.resources.File("org.sonar.MyClass"));
- CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER);
- verify(context).saveMeasure(
- eq(new org.sonar.api.resources.File("org.apache.commons.chain.impl.CatalogBase")),
- argThat(new IsMeasure(CoreMetrics.COVERAGE_LINE_HITS_DATA,
- "48=117;56=234;66=0;67=0;68=0;84=999;86=999;98=318;111=18;121=0;122=0;125=0;126=0;127=0;128=0;131=0;133=0")));
- }
-
- @Test
- public void shouldNotCountTwiceAnonymousClasses() throws URISyntaxException {
- File coverage = new File(getClass().getResource("/org/sonar/api/utils/CoberturaReportParserUtilsTest/shouldNotCountTwiceAnonymousClasses.xml").toURI());
- when(context.getResource(any(Resource.class))).thenReturn(new org.sonar.api.resources.File("org.sonar.samples.MyClass"));
- CoberturaReportParserUtils.parseReport(coverage, context, JAVA_FILE_RESOLVER);
-
- verify(context).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.MyFile")),
- argThat(new IsMeasure(CoreMetrics.LINES_TO_COVER, 5.0))); // do not count line 26 twice
- }
-
- private File getCoverageReport() throws URISyntaxException {
- return new File(getClass().getResource("/org/sonar/api/utils/CoberturaReportParserUtilsTest/commons-chain-coverage.xml").toURI());
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.plugins.cobertura.api;
-
-import org.apache.maven.project.MavenProject;
-import org.junit.Test;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.ProjectFileSystem;
-import org.sonar.api.test.MavenTestUtils;
-
-import java.io.File;
-import java.net.URISyntaxException;
-
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class CoberturaUtilsTest {
- @Test
- public void shouldGetReportPathFromProperty() throws URISyntaxException {
- ProjectFileSystem fileSystem = mock(ProjectFileSystem.class);
- when(fileSystem.resolvePath("foo")).thenReturn(getCoverageReport());
-
- Project project = mock(Project.class);
- when(project.getFileSystem()).thenReturn(fileSystem);
- when(project.getProperty(CoberturaUtils.COBERTURA_REPORT_PATH_PROPERTY)).thenReturn("foo");
-
- File report = CoberturaUtils.getReport(project);
- verify(fileSystem).resolvePath("foo");
- assertNotNull(report);
- }
-
- @Test
- public void shouldGetReportPathFromPom() {
- MavenProject pom = MavenTestUtils.loadPom("/org/sonar/plugins/cobertura/CoberturaSensorTest/shouldGetReportPathFromPom/pom.xml");
-
- ProjectFileSystem fileSystem = mock(ProjectFileSystem.class);
-
- Project project = mock(Project.class);
- when(project.getPom()).thenReturn(pom);
- when(project.getFileSystem()).thenReturn(fileSystem);
-
- CoberturaUtils.getReport(project);
-
- verify(fileSystem).resolvePath("overridden/dir");
- }
-
- private File getCoverageReport() throws URISyntaxException {
- return new File(getClass().getResource("/org/sonar/plugins/cobertura/CoberturaSensorTest/commons-chain-coverage.xml").toURI());
- }
-}
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-deprecated</artifactId>
</dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ </dependency>
<!-- unit tests -->
<dependency>
}
public static String getSourceVersion(Project project) {
- String version = project.getConfiguration() != null ? project.getConfiguration().getString(JAVA_SOURCE_PROPERTY) : null;
+ String version = project.getSettings() != null ? project.getSettings().getString(JAVA_SOURCE_PROPERTY) : null;
return StringUtils.isNotBlank(version) ? version : JAVA_SOURCE_DEFAULT_VALUE;
}
public static String getTargetVersion(Project project) {
- String version = project.getConfiguration() != null ? project.getConfiguration().getString(JAVA_TARGET_PROPERTY) : null;
+ String version = project.getSettings() != null ? project.getSettings().getString(JAVA_TARGET_PROPERTY) : null;
return StringUtils.isNotBlank(version) ? version : JAVA_TARGET_DEFAULT_VALUE;
}
}
*/
package org.sonar.java.api;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
-import org.apache.commons.configuration.BaseConfiguration;
import org.junit.Test;
+import org.sonar.api.config.Settings;
import org.sonar.api.resources.Project;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
public class JavaUtilsTest {
@Test
@Test
public void shouldReturnDefaultJavaVersion() {
- BaseConfiguration configuration = new BaseConfiguration();
- Project project = new Project("").setConfiguration(configuration);
+ Settings configuration = new Settings();
+ Project project = new Project("").setSettings(configuration);
assertThat(JavaUtils.getSourceVersion(project), is("1.5"));
assertThat(JavaUtils.getTargetVersion(project), is("1.5"));
@Test
public void shouldReturnSpecifiedJavaVersion() {
- BaseConfiguration configuration = new BaseConfiguration();
- Project project = new Project("").setConfiguration(configuration);
+ Settings configuration = new Settings();
+ Project project = new Project("").setSettings(configuration);
configuration.setProperty(JavaUtils.JAVA_SOURCE_PROPERTY, "1.4");
configuration.setProperty(JavaUtils.JAVA_TARGET_PROPERTY, "1.6");
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>commons-configuration</groupId>
- <artifactId>commons-configuration</artifactId>
- </dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ </dependency>
<dependency>
<groupId>jfree</groupId>
<artifactId>jfreechart</artifactId>
*/
package org.sonar.api.batch;
-import org.apache.commons.configuration.Configuration;
import org.sonar.api.measures.FormulaContext;
import org.sonar.api.measures.Metric;
import org.sonar.api.resources.Resource;
return decoratorContext.getResource();
}
- /**
- * @deprecated in 3.7. Use {@link org.sonar.api.config.Settings}.
- */
- @Deprecated
- public Configuration getConfiguration() {
- return decoratorContext.getProject().getConfiguration();
- }
-
public void setMetric(Metric metric) {
this.metric = metric;
}
*/
package org.sonar.api.measures;
-import org.apache.commons.configuration.Configuration;
import org.sonar.api.resources.Resource;
/**
Resource getResource();
- /**
- * @deprecated in 3.7. Use {@link org.sonar.api.config.Settings}.
- */
- @Deprecated
- Configuration getConfiguration();
-
}
import org.sonar.api.config.PropertyDefinitions;
import javax.annotation.Nullable;
+
import java.util.Collection;
import java.util.List;
try {
pico.stop();
-
} catch (RuntimeException e) {
if (!swallowException) {
throw PicoUtils.propagate(e);
public ComponentContainer addExtension(@Nullable PluginMetadata plugin, Object extension) {
Object key = componentKeys.of(extension);
- pico.as(Characteristics.CACHE).addComponent(key, extension);
+ try {
+ pico.as(Characteristics.CACHE).addComponent(key, extension);
+ } catch (Throwable t) {
+ throw new IllegalStateException("Unable to register extension " + getName(extension), t);
+ }
declareExtension(plugin, extension);
return this;
}
+ private String getName(Object extension) {
+ if (extension instanceof Class) {
+ return ((Class) extension).getName();
+ }
+ return getName(extension.getClass());
+ }
+
public void declareExtension(@Nullable PluginMetadata plugin, Object extension) {
propertyDefinitions.addComponent(extension, plugin != null ? plugin.getName() : "");
}
*/
package org.sonar.api.resources;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.maven.project.MavenProject;
import org.sonar.api.CoreProperties;
import org.sonar.api.component.Component;
+import org.sonar.api.config.Settings;
import java.util.ArrayList;
import java.util.Date;
private MavenProject pom;
private String branch;
private ProjectFileSystem fileSystem;
- private Configuration configuration;
private String name;
private String description;
private String packaging;
private Date analysisDate;
private AnalysisType analysisType;
private String analysisVersion;
+ private Settings settings;
// modules tree
private Project parent;
*/
@Deprecated
public String getLanguageKey() {
- return configuration.getString(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "");
+ if (settings == null) {
+ throw new IllegalStateException("Project is not yet initialized");
+ }
+ return StringUtils.defaultIfEmpty(settings.getString(CoreProperties.PROJECT_LANGUAGE_PROPERTY), "");
+ }
+
+ /**
+ * Internal use
+ */
+ public Project setSettings(Settings settings) {
+ this.settings = settings;
+ return this;
+ }
+
+ /**
+ * Internal use for backward compatibility. Settings should be retrieved as an IoC dependency.
+ * @deprecated since 5.0
+ */
+ @Deprecated
+ public Settings getSettings() {
+ return settings;
}
/**
return modules;
}
- /**
- * @return whether to use external source for rules configuration
- * @deprecated since 2.5. See discussion from http://jira.codehaus.org/browse/SONAR-1873
- */
- @Deprecated
- public boolean getReuseExistingRulesConfig() {
- return configuration != null && configuration.getBoolean(CoreProperties.REUSE_RULES_CONFIGURATION_PROPERTY, false);
- }
-
/**
* @return the current version of the project
*/
return analysisDate;
}
- /**
- * Patterns of resource exclusion as defined in project settings page.
- *
- * @since 3.3 also applies exclusions in general settings page and global exclusions.
- * @deprecated replaced by {@link org.sonar.api.scan.filesystem.FileExclusions} in version 3.5
- */
- @Deprecated
- public String[] getExclusionPatterns() {
- return trimExclusions(ImmutableList.<String>builder()
- .add(configuration.getStringArray(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY))
- .add(configuration.getStringArray(CoreProperties.GLOBAL_EXCLUSIONS_PROPERTY)).build());
- }
-
- /**
- * Patterns of test exclusion as defined in project settings page.
- * Also applies exclusions in general settings page and global exclusions.
- *
- * @since 3.3
- * @deprecated replaced by {@link org.sonar.api.scan.filesystem.FileExclusions} in version 3.5
- */
- @Deprecated
- public String[] getTestExclusionPatterns() {
- return trimExclusions(ImmutableList.<String>builder()
- .add(configuration.getStringArray(CoreProperties.PROJECT_TEST_EXCLUSIONS_PROPERTY))
- .add(configuration.getStringArray(CoreProperties.GLOBAL_TEST_EXCLUSIONS_PROPERTY)).build());
- }
-
- // http://jira.codehaus.org/browse/SONAR-2261 - exclusion must be trimmed
- private static String[] trimExclusions(List<String> exclusions) {
- List<String> trimmed = Lists.newArrayList();
- for (String exclusion : exclusions) {
- trimmed.add(StringUtils.trim(exclusion));
- }
- return trimmed.toArray(new String[trimmed.size()]);
- }
-
- /**
- * Set exclusion patterns. Configuration is not saved, so this method must be used ONLY IN UNIT TESTS.
- * @deprecated replaced by {@link org.sonar.api.scan.filesystem.FileExclusions} in version 3.5
- */
- @Deprecated
- public Project setExclusionPatterns(String[] s) {
- throw new UnsupportedOperationException("deprecated in 3.5");
- }
-
/**
* Note: it's better to get a reference on ProjectFileSystem as an IoC dependency (constructor parameter)
* @deprecated replaced by {@link org.sonar.api.scan.filesystem.ModuleFileSystem} in 3.5
return pom;
}
- /**
- * @return the project configuration
- * @deprecated since 2.12. The component org.sonar.api.config.Settings must be used.
- */
- @Deprecated
- public Configuration getConfiguration() {
- return configuration;
- }
-
- /**
- * For internal use only.
- */
- public final Project setConfiguration(Configuration configuration) {
- this.configuration = configuration;
- return this;
- }
-
- /**
- * @deprecated since 3.6. Replaced by {@link org.sonar.api.config.Settings}.
- */
- @Deprecated
- public Object getProperty(String key) {
- return configuration != null ? configuration.getProperty(key) : null;
- }
-
public static Project createFromMavenIds(String groupId, String artifactId) {
return new Project(String.format(MAVEN_KEY_FORMAT, groupId, artifactId));
}
*/
package org.sonar.api.resources;
-import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Test;
-import org.sonar.api.CoreProperties;
import org.sonar.api.test.MavenTestUtils;
import static org.fest.assertions.Assertions.assertThat;
public class ProjectTest {
- PropertiesConfiguration conf = new PropertiesConfiguration();
@Test
public void equalsProject() {
assertThat(project.getKey()).isEqualTo("my:artifact");
}
- /**
- * See http://jira.codehaus.org/browse/SONAR-2261
- * Note that several exclusions separated by comma would be correctly trimmed by commons-configuration library.
- * So issue is only with a single pattern, which contains spaces.
- */
- @Test
- public void shouldTrimExclusionPatterns() {
- conf.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, " **/*Foo.java , **/Bar.java ");
- conf.setProperty(CoreProperties.GLOBAL_EXCLUSIONS_PROPERTY, " **/*Test.java ");
-
- Project project = new Project("foo").setConfiguration(conf);
- String[] exclusions = project.getExclusionPatterns();
-
- assertThat(exclusions).containsOnly("**/*Foo.java", "**/Bar.java", "**/*Test.java");
- }
-
- @Test
- public void testNoExclusionPatterns() {
- Project project = new Project("key").setConfiguration(conf);
-
- assertThat(project.getExclusionPatterns()).isEmpty();
- assertThat(project.getTestExclusionPatterns()).isEmpty();
- }
-
- @Test
- public void should_exclude_many_patterns() {
- conf.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*,foo,*/bar");
- conf.setProperty(CoreProperties.GLOBAL_EXCLUSIONS_PROPERTY, "*/exclude");
-
- Project project = new Project("key").setConfiguration(conf);
-
- assertThat(project.getExclusionPatterns()).containsOnly("**/*", "foo", "*/bar", "*/exclude");
- }
-
- @Test
- public void should_exclude_test_patterns() {
- conf.setProperty(CoreProperties.PROJECT_TEST_EXCLUSIONS_PROPERTY, "**/*Test.java, **/*IntegrationTest.java");
- conf.setProperty(CoreProperties.GLOBAL_TEST_EXCLUSIONS_PROPERTY, "**/*FunctionalTest.java");
-
- Project project = new Project("key").setConfiguration(conf);
-
- assertThat(project.getTestExclusionPatterns()).containsOnly("**/*Test.java", "**/*IntegrationTest.java", "**/*FunctionalTest.java");
- }
}
*/
package org.sonar.api.test;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.MapConfiguration;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.MavenProject;
-import org.sonar.api.CoreProperties;
import org.sonar.api.batch.maven.MavenUtils;
import org.sonar.api.resources.InputFile;
import org.sonar.api.resources.Language;
public static Project loadProjectFromPom(Class clazz, String path) {
MavenProject pom = loadPom(clazz, path);
- Configuration configuration = new MapConfiguration(pom.getProperties());
Project project = new Project(pom.getGroupId() + ":" + pom.getArtifactId())
- .setPom(pom)
- .setConfiguration(configuration);
- configuration.setProperty("sonar.java.source", MavenUtils.getJavaSourceVersion(pom));
- configuration.setProperty("sonar.java.target", MavenUtils.getJavaVersion(pom));
- configuration.setProperty(CoreProperties.ENCODING_PROPERTY, MavenUtils.getSourceEncoding(pom));
+ .setPom(pom);
+ // configuration.setProperty("sonar.java.source", MavenUtils.getJavaSourceVersion(pom));
+ // configuration.setProperty("sonar.java.target", MavenUtils.getJavaVersion(pom));
+ // configuration.setProperty(CoreProperties.ENCODING_PROPERTY, MavenUtils.getSourceEncoding(pom));
project.setFileSystem(new MavenModuleFileSystem(pom));
return project;
}
public List<File> getSourceFiles(Language... langs) {
- return new ArrayList(FileUtils.listFiles(getSourceDirs().get(0), new String[]{"java"}, true));
+ return new ArrayList(FileUtils.listFiles(getSourceDirs().get(0), new String[] {"java"}, true));
}
public List<File> getJavaSourceFiles() {
}
public List<File> getTestFiles(Language... langs) {
- return new ArrayList(FileUtils.listFiles(getTestDirs().get(0), new String[]{"java"}, true));
+ return new ArrayList(FileUtils.listFiles(getTestDirs().get(0), new String[] {"java"}, true));
}
public boolean hasTestFiles(Language lang) {
*/
package org.sonar.api.test;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.MapConfiguration;
import org.apache.maven.project.MavenProject;
-import static org.mockito.Mockito.when;
import org.sonar.api.resources.Project;
-import java.util.Properties;
+import static org.mockito.Mockito.when;
public class ProjectTestBuilder {
private MavenProject pom = MavenTestUtils.mockPom("jar");
- private Configuration conf = new MapConfiguration(new Properties());
-
public Project build() {
when(pom.getGroupId()).thenReturn("mygroup");
when(pom.getArtifactId()).thenReturn("myartifact");
when(pom.isExecutionRoot()).thenReturn(true);
- return new Project("mygroup:myartifact").setPom(pom).setConfiguration(conf);
+ return new Project("mygroup:myartifact").setPom(pom);
}
}