aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/pom.xml22
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchDatabase.java47
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchDatabaseSessionFactory.java41
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/DatabaseCompatibility.java100
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/DefaultAnalysisMode.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java7
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java42
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java195
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcLeakPrevention.java72
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java125
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java168
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java164
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/components/Period.java49
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java91
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/components/package-info.java23
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDate.java70
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDays.java77
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysis.java62
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersion.java63
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersion.java61
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PeriodsDefinition.java95
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/report/MeasuresPublisher.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java12
-rw-r--r--sonar-batch/src/main/resources/org/sonar/batch/bootstrapper/logback.xml11
-rw-r--r--sonar-batch/src/main/resources/org/sonar/batch/logback.xml11
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchDatabaseSessionFactoryTest.java36
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchDatabaseTest.java42
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/DatabaseCompatibilityTest.java136
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java17
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/JdbcDriverHolderTest.java121
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java108
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java231
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java105
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java111
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDateTest.java62
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDaysTest.java113
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysisTest.java56
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest.java73
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersionTest.java57
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PeriodsDefinitionTest.java76
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java21
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java14
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java3
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/report/MeasuresPublisherTest.java5
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/report/MetadataPublisherTest.java3
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java12
49 files changed, 30 insertions, 2997 deletions
diff --git a/sonar-batch/pom.xml b/sonar-batch/pom.xml
index db21e928a97..fdc637497e1 100644
--- a/sonar-batch/pom.xml
+++ b/sonar-batch/pom.xml
@@ -107,28 +107,6 @@
<artifactId>freemarker</artifactId>
</dependency>
- <!-- hibernate -->
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-annotations</artifactId>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-commons-annotations</artifactId>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-entitymanager</artifactId>
- </dependency>
- <dependency>
- <groupId>geronimo-spec</groupId>
- <artifactId>geronimo-spec-jta</artifactId>
- </dependency>
-
<!-- unit tests -->
<dependency>
<groupId>org.codehaus.sonar</groupId>
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java
index 53b2f2c1bb1..353bf44c9c7 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java
@@ -22,7 +22,6 @@ package org.sonar.batch.bootstrap;
import com.google.common.collect.Lists;
import java.util.Collection;
import java.util.List;
-import org.sonar.batch.components.TimeMachineConfiguration;
import org.sonar.batch.compute.BranchCoverageDecorator;
import org.sonar.batch.compute.CommentDensityDecorator;
import org.sonar.batch.compute.CoverageDecorator;
@@ -94,8 +93,7 @@ public class BatchComponents {
OverallBranchCoverageDecorator.class,
CommentDensityDecorator.class,
DirectoriesDecorator.class,
- FilesDecorator.class,
- TimeMachineConfiguration.class
+ FilesDecorator.class
);
components.addAll(CorePropertyDefinitions.all());
// CPD
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchDatabase.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchDatabase.java
deleted file mode 100644
index 1907c948578..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchDatabase.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.batch.bootstrap;
-
-import java.util.Properties;
-import org.sonar.api.config.Settings;
-import org.sonar.core.persistence.DefaultDatabase;
-
-/**
- * @since 2.12
- */
-public class BatchDatabase extends DefaultDatabase {
-
- public BatchDatabase(Settings settings,
- // The dependency on JdbcDriverHolder is required to be sure that the JDBC driver
- // has been downloaded and injected into classloader
- JdbcDriverHolder jdbcDriverHolder) {
- super(settings);
- }
-
- @Override
- protected void doCompleteProperties(Properties properties) {
- // two connections are required : one for Hibernate, and one for MyBatis for regular operations
- // Note that Hibernate will be removed soon
- properties.setProperty("sonar.jdbc.initialSize", "2");
- properties.setProperty("sonar.jdbc.maxActive", "2");
- // SONAR-2965
- properties.setProperty("sonar.jdbc.defaultAutoCommit", "false");
- }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchDatabaseSessionFactory.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchDatabaseSessionFactory.java
deleted file mode 100644
index 1178041b439..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchDatabaseSessionFactory.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.batch.bootstrap;
-
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.jpa.session.DatabaseSessionFactory;
-
-public class BatchDatabaseSessionFactory implements DatabaseSessionFactory {
-
- private DatabaseSession session;
-
- public BatchDatabaseSessionFactory(DatabaseSession session) {
- this.session = session;
- }
-
- @Override
- public DatabaseSession getSession() {
- return session;
- }
-
- @Override
- public void clear() {
- }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DatabaseCompatibility.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DatabaseCompatibility.java
deleted file mode 100644
index 2ff8d69fb5b..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DatabaseCompatibility.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * 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.batch.bootstrap;
-
-import com.google.common.annotations.VisibleForTesting;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.batch.BatchSide;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
-import org.sonar.api.database.DatabaseProperties;
-import org.sonar.api.utils.MessageException;
-import org.sonar.core.persistence.DatabaseVersion;
-import org.sonar.core.properties.PropertiesDao;
-
-/**
- * Detects if database is not up-to-date with the version required by the batch.
- */
-@BatchSide
-public class DatabaseCompatibility {
-
- private DatabaseVersion version;
- private Settings settings;
- private PropertiesDao propertiesDao;
- private ServerClient server;
- private DefaultAnalysisMode analysisMode;
-
- public DatabaseCompatibility(DatabaseVersion version, ServerClient server, Settings settings, PropertiesDao propertiesDao, DefaultAnalysisMode mode) {
- this.version = version;
- this.server = server;
- this.settings = settings;
- this.propertiesDao = propertiesDao;
- this.analysisMode = mode;
- }
-
- public void start() {
- if (!analysisMode.isPreview()) {
- checkCorrectServerId();
- checkDatabaseStatus();
- }
- }
-
- private void checkCorrectServerId() {
- if (!propertiesDao.selectGlobalProperty(CoreProperties.SERVER_ID).getValue().equals(getServerId())) {
- StringBuilder message = new StringBuilder("The current batch process and the configured remote server do not share the same DB configuration.\n");
- message.append("\t- Batch side: ");
- message.append(settings.getString(DatabaseProperties.PROP_URL));
- message.append(" (");
- String userName = settings.getString(DatabaseProperties.PROP_USER);
- message.append(userName == null ? "sonar" : userName);
- message.append(" / *****)\n\t- Server side: check the configuration at ");
- message.append(server.getURL());
- message.append("/system\n");
- throw MessageException.of(message.toString());
- }
- }
-
- private String getServerId() {
- String remoteServerInfo = server.request("/api/server");
- // don't use JSON utilities to extract ID from such a small string
- return extractServerId(remoteServerInfo);
- }
-
- @VisibleForTesting
- String extractServerId(String remoteServerInfo) {
- String partialId = StringUtils.substringAfter(remoteServerInfo, "\"id\":\"");
- return StringUtils.substringBefore(partialId, "\"");
- }
-
- private void checkDatabaseStatus() {
- DatabaseVersion.Status status = version.getStatus();
- if (status == DatabaseVersion.Status.REQUIRES_DOWNGRADE) {
- throw MessageException.of("Database relates to a more recent version of SonarQube. Please check your settings (JDBC settings, version of Maven plugin)");
- }
- if (status == DatabaseVersion.Status.REQUIRES_UPGRADE) {
- throw MessageException.of("Database must be upgraded. Please browse " + server.getURL() + "/setup");
- }
- if (status != DatabaseVersion.Status.UP_TO_DATE) {
- // Support other future values
- throw MessageException.of("Unknown database status: " + status);
- }
- }
-
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DefaultAnalysisMode.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DefaultAnalysisMode.java
index b13e7b8bab4..c6b70402b95 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DefaultAnalysisMode.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DefaultAnalysisMode.java
@@ -43,10 +43,6 @@ public class DefaultAnalysisMode implements AnalysisMode {
init(props);
}
- public boolean isDb() {
- return !preview && !incremental && !mediumTestMode;
- }
-
@Override
public boolean isPreview() {
return preview || incremental;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java
index 165aa83e649..2899ede562b 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java
@@ -19,6 +19,8 @@
*/
package org.sonar.batch.bootstrap;
+import java.util.List;
+import javax.annotation.Nullable;
import org.sonar.api.ExtensionProvider;
import org.sonar.api.Plugin;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
@@ -26,10 +28,6 @@ import org.sonar.core.platform.ComponentContainer;
import org.sonar.core.platform.PluginInfo;
import org.sonar.core.platform.PluginRepository;
-import javax.annotation.Nullable;
-
-import java.util.List;
-
public class ExtensionInstaller {
private final PluginRepository pluginRepository;
@@ -72,7 +70,6 @@ public class ExtensionInstaller {
private void doInstall(ComponentContainer container, ExtensionMatcher matcher, @Nullable PluginInfo pluginInfo, Object extension) {
if (ExtensionUtils.supportsEnvironment(extension, env)
- && (analysisMode.isDb() || !ExtensionUtils.requiresDB(extension))
&& matcher.accept(extension)) {
container.addExtension(pluginInfo, extension);
} else {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java
index 5731dc37b97..9df655680d1 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java
@@ -22,7 +22,6 @@ package org.sonar.batch.bootstrap;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.batch.BatchSide;
import org.sonar.api.batch.InstantiationStrategy;
-import org.sonar.api.batch.RequiresDB;
import org.sonar.api.batch.SupportedEnvironment;
import org.sonar.api.utils.AnnotationUtils;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
@@ -58,10 +57,6 @@ public class ExtensionUtils {
return false;
}
- public static boolean requiresDB(Object extension) {
- return AnnotationUtils.getAnnotation(extension, RequiresDB.class) != null;
- }
-
public static boolean isMavenExtensionOnly(Object extension) {
SupportedEnvironment env = AnnotationUtils.getAnnotation(extension, SupportedEnvironment.class);
return env != null && env.value().length == 1 && StringUtils.equalsIgnoreCase("maven", env.value()[0]);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
index 94d6effc42d..424d0d644e5 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
@@ -19,22 +19,14 @@
*/
package org.sonar.batch.bootstrap;
-import org.sonar.batch.index.CachesManager;
-
import java.util.List;
import java.util.Map;
-
import org.sonar.api.CoreProperties;
import org.sonar.api.Plugin;
import org.sonar.api.utils.Durations;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.UriReader;
-import org.sonar.batch.components.PastSnapshotFinder;
-import org.sonar.batch.deprecated.components.PastSnapshotFinderByDate;
-import org.sonar.batch.deprecated.components.PastSnapshotFinderByDays;
-import org.sonar.batch.deprecated.components.PastSnapshotFinderByPreviousAnalysis;
-import org.sonar.batch.deprecated.components.PastSnapshotFinderByPreviousVersion;
-import org.sonar.batch.deprecated.components.PastSnapshotFinderByVersion;
+import org.sonar.batch.index.CachesManager;
import org.sonar.batch.issue.tracking.DefaultServerLineHashesLoader;
import org.sonar.batch.issue.tracking.ServerLineHashesLoader;
import org.sonar.batch.platform.DefaultServer;
@@ -47,21 +39,14 @@ import org.sonar.batch.repository.ProjectRepositoriesLoader;
import org.sonar.batch.repository.ServerIssuesLoader;
import org.sonar.batch.repository.user.UserRepository;
import org.sonar.batch.scan.ProjectScanContainer;
-import org.sonar.core.cluster.NullQueue;
import org.sonar.core.config.Logback;
import org.sonar.core.i18n.DefaultI18n;
-import org.sonar.core.i18n.RuleI18nManager;
-import org.sonar.core.persistence.DaoUtils;
-import org.sonar.core.persistence.DatabaseVersion;
-import org.sonar.core.persistence.MyBatis;
import org.sonar.core.platform.ComponentContainer;
import org.sonar.core.platform.PluginClassloaderFactory;
import org.sonar.core.platform.PluginInfo;
import org.sonar.core.platform.PluginLoader;
import org.sonar.core.platform.PluginRepository;
import org.sonar.core.util.DefaultHttpDownloader;
-import org.sonar.jpa.session.DefaultDatabaseConnector;
-import org.sonar.jpa.session.JpaDatabaseSession;
public class GlobalContainer extends ComponentContainer {
@@ -85,10 +70,6 @@ public class GlobalContainer extends ComponentContainer {
DefaultAnalysisMode analysisMode = new DefaultAnalysisMode(bootstrapProps.properties());
add(bootstrapProps, analysisMode);
addBootstrapComponents();
- if (analysisMode.isDb()) {
- addDatabaseComponents();
- }
-
}
private void addBootstrapComponents() {
@@ -131,27 +112,6 @@ public class GlobalContainer extends ComponentContainer {
}
}
- private void addDatabaseComponents() {
- add(
- JdbcDriverHolder.class,
- BatchDatabase.class,
- MyBatis.class,
- NullQueue.class,
- DatabaseVersion.class,
- DatabaseCompatibility.class,
- DefaultDatabaseConnector.class,
- JpaDatabaseSession.class,
- BatchDatabaseSessionFactory.class,
- DaoUtils.getDaoClasses(),
- RuleI18nManager.class,
- PastSnapshotFinderByDate.class,
- PastSnapshotFinderByDays.class,
- PastSnapshotFinderByPreviousAnalysis.class,
- PastSnapshotFinderByVersion.class,
- PastSnapshotFinderByPreviousVersion.class,
- PastSnapshotFinder.class);
- }
-
@Override
protected void doAfterStart() {
installPlugins();
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java
deleted file mode 100644
index b47590b75a7..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * 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.batch.bootstrap;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Strings;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.utils.SonarException;
-import org.sonar.home.cache.FileCache;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-
-/**
- * Contains and provides class loader extended with the JDBC Driver hosted on the server-side.
- */
-public class JdbcDriverHolder {
-
- private static final Logger LOG = LoggerFactory.getLogger(JdbcDriverHolder.class);
-
- private ServerClient serverClient;
- private DefaultAnalysisMode analysisMode;
- private FileCache fileCache;
-
- // initialized in start()
- private JdbcDriverClassLoader classLoader = null;
-
- public JdbcDriverHolder(FileCache fileCache, DefaultAnalysisMode analysisMode, ServerClient serverClient) {
- this.serverClient = serverClient;
- this.analysisMode = analysisMode;
- this.fileCache = fileCache;
- }
-
- public void start() {
- if (!analysisMode.isPreview()) {
- try {
- LOG.info("Install JDBC driver");
- String[] nameAndHash = downloadJdbcDriverIndex();
- if (nameAndHash.length > 0) {
- String filename = nameAndHash[0];
- String hash = nameAndHash[1];
-
- File jdbcDriver = fileCache.get(filename, hash, new FileCache.Downloader() {
- @Override
- public void download(String filename, File toFile) throws IOException {
- String url = "/deploy/" + filename;
- if (LOG.isDebugEnabled()) {
- LOG.debug("Download {} to {}", url, toFile.getAbsolutePath());
- } else {
- LOG.info("Download {}", filename);
- }
- serverClient.download(url, toFile);
- }
- });
- classLoader = initClassloader(jdbcDriver);
- }
- } catch (SonarException e) {
- throw e;
- } catch (Exception e) {
- throw new SonarException("Fail to install JDBC driver", e);
- }
- }
- }
-
- @VisibleForTesting
- JdbcDriverClassLoader getClassLoader() {
- return classLoader;
- }
-
- @VisibleForTesting
- static JdbcDriverClassLoader initClassloader(File jdbcDriver) {
- JdbcDriverClassLoader classLoader;
- try {
- ClassLoader parentClassLoader = JdbcDriverHolder.class.getClassLoader();
- classLoader = new JdbcDriverClassLoader(jdbcDriver.toURI().toURL(), parentClassLoader);
-
- } catch (MalformedURLException e) {
- throw new SonarException("Fail to get URL of : " + jdbcDriver.getAbsolutePath(), e);
- }
-
- // set as the current context classloader for hibernate, else it does not find the JDBC driver.
- Thread.currentThread().setContextClassLoader(classLoader);
- return classLoader;
- }
-
- /**
- * This method automatically invoked by PicoContainer and unregisters JDBC drivers, which were forgotten.
- * <p>
- * Dynamically loaded JDBC drivers can not be simply used and this is a well known problem of {@link java.sql.DriverManager},
- * so <a href="http://stackoverflow.com/questions/288828/how-to-use-a-jdbc-driver-from-an-arbitrary-location">workaround is to use proxy</a>.
- * However DriverManager also contains memory leak, thus not only proxy, but also original driver must be unregistered,
- * otherwise our class loader would be kept in memory.
- * </p>
- * <p>
- * This operation contains unnecessary complexity because:
- * <ul>
- * <li>DriverManager checks the class loader of the calling class. Thus we can't simply ask it about deregistration.</li>
- * <li>We can't use reflection against DriverManager, since it would create a dependency on DriverManager implementation,
- * which can be changed (like it was done - compare Java 1.5 and 1.6).</li>
- * <li>So we use companion - {@link JdbcLeakPrevention}. But we can't just create an instance,
- * since it will be loaded by parent class loader and again will not pass DriverManager's check.
- * So, we load the bytes via our parent class loader, but define the class with this class loader
- * thus JdbcLeakPrevention looks like our class to the DriverManager.</li>
- * </li>
- * </p>
- */
- public void stop() {
- if (classLoader != null) {
- classLoader.clearReferencesJdbc();
- if (Thread.currentThread().getContextClassLoader() == classLoader) {
- Thread.currentThread().setContextClassLoader(classLoader.getParent());
- }
- classLoader = null;
- }
- }
-
- private String[] downloadJdbcDriverIndex() {
- String url = "/deploy/jdbc-driver.txt";
- try {
- LOG.debug("Download index of jdbc-driver");
- String indexContent = serverClient.request(url);
- // File is empty when H2 is used
- if (Strings.isNullOrEmpty(indexContent)) {
- return new String[] {};
- }
- return indexContent.split("\\|");
- } catch (Exception e) {
- throw new SonarException("Fail to download jdbc-driver index: " + url, e);
- }
- }
-
- static class JdbcDriverClassLoader extends URLClassLoader {
-
- public JdbcDriverClassLoader(URL jdbcDriver, ClassLoader parent) {
- super(new URL[] {jdbcDriver}, parent);
- }
-
- public void clearReferencesJdbc() {
- InputStream is = getResourceAsStream("org/sonar/batch/bootstrap/JdbcLeakPrevention.class");
- byte[] classBytes = new byte[2048];
- int offset = 0;
- try {
- int read = is.read(classBytes, offset, classBytes.length - offset);
- while (read > -1) {
- offset += read;
- if (offset == classBytes.length) {
- // Buffer full - double size
- byte[] tmp = new byte[classBytes.length * 2];
- System.arraycopy(classBytes, 0, tmp, 0, classBytes.length);
- classBytes = tmp;
- }
- read = is.read(classBytes, offset, classBytes.length - offset);
- }
-
- Class<?> lpClass = defineClass("org.sonar.batch.bootstrap.JdbcLeakPrevention", classBytes, 0, offset, this.getClass().getProtectionDomain());
- Object obj = lpClass.newInstance();
-
- obj.getClass().getMethod("unregisterDrivers").invoke(obj);
- } catch (Exception e) {
- LOG.warn("JDBC driver deregistration failed", e);
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException ioe) {
- LOG.warn(ioe.getMessage(), ioe);
- }
- }
- }
- }
- }
-
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcLeakPrevention.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcLeakPrevention.java
deleted file mode 100644
index 17a80a26d5f..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcLeakPrevention.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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.batch.bootstrap;
-
-import java.sql.Driver;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Companion of {@link JdbcDriverHolder} and allows it to deregister JDBC drivers.
- * <p>
- * Some hacks are involved in the loading of the class - see {@link JdbcDriverHolder#stop()},
- * so this class can refer to classes only from java.* package and must not be referred from other classes.
- * Placement and naming of this class and methods are very important, since it loaded and invoked via reflection.
- * </p>
- */
-public class JdbcLeakPrevention {
-
- /**
- * @return names of the drivers that have been unregistered
- */
- public List<String> unregisterDrivers() throws SQLException {
- Set<Driver> registeredDrivers = registeredDrivers();
-
- List<String> unregisteredNames = new ArrayList<>();
- Enumeration<Driver> drivers = DriverManager.getDrivers();
- while (drivers.hasMoreElements()) {
- Driver driver = drivers.nextElement();
- if (driver.getClass().getClassLoader() != this.getClass().getClassLoader()) {
- continue;
- }
- if (registeredDrivers.contains(driver)) {
- unregisteredNames.add(driver.getClass().getCanonicalName());
- }
- DriverManager.deregisterDriver(driver);
- }
- return unregisteredNames;
- }
-
- private static Set<Driver> registeredDrivers() {
- Set<Driver> registeredDrivers = new HashSet<>();
- Enumeration<Driver> drivers = DriverManager.getDrivers();
- while (drivers.hasMoreElements()) {
- Driver driver = drivers.nextElement();
- registeredDrivers.add(driver);
- }
- return registeredDrivers;
- }
-
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java
deleted file mode 100644
index b2d2c185f1c..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * 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.batch.components;
-
-import com.google.common.collect.Maps;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import javax.annotation.Nullable;
-import javax.persistence.Query;
-import org.apache.commons.lang.ObjectUtils;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.batch.BatchSide;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.measures.MetricFinder;
-import org.sonar.api.resources.Resource;
-
-/**
- * Can't be moved. Used by devcockpit.
- */
-@BatchSide
-public class PastMeasuresLoader {
-
- private Map<Integer, Metric> metricByIds;
- private DatabaseSession session;
-
- public PastMeasuresLoader(DatabaseSession session, MetricFinder metricFinder) {
- this(session, metricFinder.findAll());
- }
-
- PastMeasuresLoader(DatabaseSession session, Collection<Metric> metrics) {
- this.session = session;
- this.metricByIds = Maps.newHashMap();
- for (Metric metric : metrics) {
- if (metric.isNumericType()) {
- metricByIds.put(metric.getId(), metric);
- }
- }
- }
-
- public Collection<Metric> getMetrics() {
- return metricByIds.values();
- }
-
- public List<Object[]> getPastMeasures(Resource resource, PastSnapshot projectPastSnapshot) {
- if (projectPastSnapshot != null && projectPastSnapshot.getProjectSnapshot() != null) {
- return getPastMeasures(resource.getEffectiveKey(), resource.getPath(), projectPastSnapshot.getProjectSnapshot());
- }
- return Collections.emptyList();
- }
-
- public List<Object[]> getPastMeasures(String resourceKey, Snapshot projectPastSnapshot) {
- return getPastMeasures(resourceKey, null, projectPastSnapshot);
- }
-
- public List<Object[]> getPastMeasures(String resourceKey, @Nullable String path, Snapshot projectPastSnapshot) {
- String sql = "select m.metric_id, m.characteristic_id, m.person_id, m.rule_id, m.value from project_measures m, snapshots s" +
- " where m.snapshot_id=s.id and m.metric_id in (:metricIds) " +
- " and (s.root_snapshot_id=:rootSnapshotId or s.id=:rootSnapshotId) " +
- " and s.status=:status and s.project_id=(select p.id from projects p where p.kee=:resourceKey"
- + (StringUtils.isNotBlank(path) ? " and p.path=:path" : "")
- + ")";
- Query q = session.createNativeQuery(sql)
- .setParameter("metricIds", metricByIds.keySet())
- .setParameter("rootSnapshotId", ObjectUtils.defaultIfNull(projectPastSnapshot.getRootId(), projectPastSnapshot.getId()))
- .setParameter("resourceKey", resourceKey)
- .setParameter("status", Snapshot.STATUS_PROCESSED);
- if (StringUtils.isNotBlank(path)) {
- q.setParameter("path", path);
- }
- return q.getResultList();
- }
-
- public static int getMetricId(Object[] row) {
- // can be BigDecimal on Oracle
- return ((Number) row[0]).intValue();
- }
-
- public static Integer getCharacteristicId(Object[] row) {
- // can be BigDecimal on Oracle
- Number number = (Number) row[1];
- return number != null ? number.intValue() : null;
- }
-
- public static Integer getPersonId(Object[] row) {
- // can be BigDecimal on Oracle
- Number number = (Number) row[2];
- return number != null ? number.intValue() : null;
- }
-
- public static Integer getRuleId(Object[] row) {
- // can be BigDecimal on Oracle
- Number number = (Number) row[3];
- return number != null ? number.intValue() : null;
- }
-
- public static boolean hasValue(Object[] row) {
- return row[4] != null;
- }
-
- public static double getValue(Object[] row) {
- return ((Number) row[4]).doubleValue();
- }
-
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java
deleted file mode 100644
index 719800f8231..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * 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.batch.components;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.builder.ReflectionToStringBuilder;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.utils.DateUtils;
-
-import javax.annotation.Nullable;
-
-import java.util.Calendar;
-import java.util.Date;
-
-import static org.sonar.api.utils.DateUtils.longToDate;
-
-/**
- * Used by devcockpit
- */
-public class PastSnapshot {
-
- private int index;
- private String mode;
- private String modeParameter;
- private Snapshot projectSnapshot;
- private Date targetDate = null;
-
- public PastSnapshot(String mode, @Nullable Date targetDate, @Nullable Snapshot projectSnapshot) {
- this.mode = mode;
- if (targetDate != null) {
- this.targetDate = org.apache.commons.lang.time.DateUtils.truncate(targetDate, Calendar.SECOND);
- }
- this.projectSnapshot = projectSnapshot;
- }
-
- public PastSnapshot(String mode, @Nullable Date targetDate) {
- this(mode, targetDate, null);
- }
-
- /**
- * See SONAR-2428 : even if previous analysis does not exist (no snapshot and no target date), we should perform comparison.
- */
- public PastSnapshot(String mode) {
- this(mode, null, null);
- }
-
- public PastSnapshot setIndex(int index) {
- this.index = index;
- return this;
- }
-
- public int getIndex() {
- return index;
- }
-
- public boolean isRelatedToSnapshot() {
- return projectSnapshot != null;
- }
-
- public Snapshot getProjectSnapshot() {
- return projectSnapshot;
- }
-
- public Date getDate() {
- return projectSnapshot != null ? longToDate(projectSnapshot.getCreatedAtMs()) : null;
- }
-
- public PastSnapshot setMode(String mode) {
- this.mode = mode;
- return this;
- }
-
- public String getMode() {
- return mode;
- }
-
- public String getModeParameter() {
- return modeParameter;
- }
-
- public PastSnapshot setModeParameter(String s) {
- this.modeParameter = s;
- return this;
- }
-
- public Integer getProjectSnapshotId() {
- return projectSnapshot != null ? projectSnapshot.getId() : null;
- }
-
- public String getQualifier() {
- return projectSnapshot != null ? projectSnapshot.getQualifier() : null;
- }
-
- /**
- * @deprecated in 4.2. Target date should only be used in labels.
- */
- @Deprecated
- public Date getTargetDate() {
- return targetDate;
- }
-
- public PastSnapshot clonePastSnapshot() {
- PastSnapshot clone = new PastSnapshot(mode, targetDate, projectSnapshot);
- clone.setIndex(index);
- clone.setModeParameter(modeParameter);
- return clone;
- }
-
- @Override
- public String toString() {
- if (StringUtils.equals(mode, CoreProperties.TIMEMACHINE_MODE_VERSION)) {
- String label = String.format("Compare to version %s", modeParameter);
- if (targetDate != null) {
- label += String.format(" (%s)", DateUtils.formatDate(getDate()));
- }
- return label;
- }
- if (StringUtils.equals(mode, CoreProperties.TIMEMACHINE_MODE_DAYS)) {
- String label = String.format("Compare over %s days (%s", modeParameter, DateUtils.formatDate(targetDate));
- if (isRelatedToSnapshot()) {
- label += ", analysis of " + getDate();
- }
- label += ")";
- return label;
- }
- if (StringUtils.equals(mode, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS)) {
- String label = "Compare to previous analysis";
- if (isRelatedToSnapshot()) {
- label += String.format(" (%s)", DateUtils.formatDate(getDate()));
- }
- return label;
- }
- if (StringUtils.equals(mode, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION)) {
- String label = "Compare to previous version";
- if (isRelatedToSnapshot()) {
- label += String.format(" (%s)", DateUtils.formatDate(getDate()));
- }
- return label;
- }
- if (StringUtils.equals(mode, CoreProperties.TIMEMACHINE_MODE_DATE)) {
- String label = "Compare to date " + DateUtils.formatDate(targetDate);
- if (isRelatedToSnapshot()) {
- label += String.format(" (analysis of %s)", DateUtils.formatDate(getDate()));
- }
- return label;
- }
- return ReflectionToStringBuilder.toString(this);
- }
-
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java
deleted file mode 100644
index 3fb39b25569..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * 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.batch.components;
-
-import com.google.common.base.Strings;
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.BatchSide;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.batch.deprecated.components.PastSnapshotFinderByDate;
-import org.sonar.batch.deprecated.components.PastSnapshotFinderByDays;
-import org.sonar.batch.deprecated.components.PastSnapshotFinderByPreviousAnalysis;
-import org.sonar.batch.deprecated.components.PastSnapshotFinderByPreviousVersion;
-import org.sonar.batch.deprecated.components.PastSnapshotFinderByVersion;
-
-import javax.annotation.Nullable;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-/**
- * Can't be moved since it is used by devcockpit.
- */
-@BatchSide
-public class PastSnapshotFinder {
-
- private static final Logger LOG = LoggerFactory.getLogger(PastSnapshotFinder.class);
-
- private PastSnapshotFinderByDays finderByDays;
- private PastSnapshotFinderByVersion finderByVersion;
- private PastSnapshotFinderByDate finderByDate;
- private PastSnapshotFinderByPreviousAnalysis finderByPreviousAnalysis;
- private PastSnapshotFinderByPreviousVersion finderByPreviousVersion;
-
- public PastSnapshotFinder(PastSnapshotFinderByDays finderByDays, PastSnapshotFinderByVersion finderByVersion,
- PastSnapshotFinderByDate finderByDate, PastSnapshotFinderByPreviousAnalysis finderByPreviousAnalysis,
- PastSnapshotFinderByPreviousVersion finderByPreviousVersion) {
- this.finderByDays = finderByDays;
- this.finderByVersion = finderByVersion;
- this.finderByDate = finderByDate;
- this.finderByPreviousAnalysis = finderByPreviousAnalysis;
- this.finderByPreviousVersion = finderByPreviousVersion;
- }
-
- public PastSnapshot find(Snapshot projectSnapshot, @Nullable String rootQualifier, Settings settings, int index) {
- String propertyValue = getPropertyValue(rootQualifier, settings, index);
- PastSnapshot pastSnapshot = find(projectSnapshot, index, propertyValue);
- if (pastSnapshot == null && StringUtils.isNotBlank(propertyValue)) {
- LOG.debug("Property " + CoreProperties.TIMEMACHINE_PERIOD_PREFIX + index + " is not valid: " + propertyValue);
- }
- return pastSnapshot;
- }
-
- public PastSnapshot find(Snapshot projectSnapshot, Settings settings, int index) {
- return find(projectSnapshot, null, settings, index);
- }
-
- static String getPropertyValue(@Nullable String rootQualifier, Settings settings, int index) {
- String value = settings.getString(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + index);
- // For periods 4 and 5 we're searching for a property prefixed by the qualifier
- if (index > 3 && Strings.isNullOrEmpty(value)) {
- value = settings.getString(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + index + "." + rootQualifier);
- }
- return value;
- }
-
- public PastSnapshot findPreviousAnalysis(Snapshot projectSnapshot) {
- return finderByPreviousAnalysis.findByPreviousAnalysis(projectSnapshot);
- }
-
- @Nullable
- public PastSnapshot find(Snapshot projectSnapshot, int index, String property) {
- if (StringUtils.isBlank(property)) {
- return null;
- }
-
- PastSnapshot result = findByDays(projectSnapshot, property);
- if (result == null) {
- result = findByDate(projectSnapshot, property);
- if (result == null) {
- result = findByPreviousAnalysis(projectSnapshot, property);
- if (result == null) {
- result = findByPreviousVersion(projectSnapshot, property);
- if (result == null) {
- result = findByVersion(projectSnapshot, property);
- }
- }
- }
- }
-
- if (result != null) {
- result.setIndex(index);
- }
-
- return result;
- }
-
- @Nullable
- private PastSnapshot findByPreviousAnalysis(Snapshot projectSnapshot, String property) {
- PastSnapshot pastSnapshot = null;
- if (StringUtils.equals(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, property)) {
- pastSnapshot = finderByPreviousAnalysis.findByPreviousAnalysis(projectSnapshot);
- }
- return pastSnapshot;
- }
-
- @Nullable
- private PastSnapshot findByPreviousVersion(Snapshot projectSnapshot, String property) {
- PastSnapshot pastSnapshot = null;
- if (StringUtils.equals(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, property)) {
- pastSnapshot = finderByPreviousVersion.findByPreviousVersion(projectSnapshot);
- }
- return pastSnapshot;
- }
-
- @Nullable
- private PastSnapshot findByDate(Snapshot projectSnapshot, String property) {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
- try {
- Date date = format.parse(property);
- return finderByDate.findByDate(projectSnapshot, date);
-
- } catch (ParseException e) {
- return null;
- }
- }
-
- private PastSnapshot findByVersion(Snapshot projectSnapshot, String property) {
- return finderByVersion.findByVersion(projectSnapshot, property);
- }
-
- @Nullable
- private PastSnapshot findByDays(Snapshot projectSnapshot, String property) {
- try {
- int days = Integer.parseInt(property);
- return finderByDays.findFromDays(projectSnapshot, days);
-
- } catch (NumberFormatException e) {
- return null;
- }
- }
-
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/Period.java b/sonar-batch/src/main/java/org/sonar/batch/components/Period.java
deleted file mode 100644
index 1b40539d4f5..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/components/Period.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.batch.components;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-import java.util.Date;
-
-/**
- * Used by devcockpit
- */
-public class Period {
-
- private int index;
- private Date date;
-
- public Period(int index, @Nullable Date date) {
- this.index = index;
- this.date = date;
- }
-
- public int getIndex() {
- return index;
- }
-
- @CheckForNull
- public Date getDate() {
- return date;
- }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java b/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java
deleted file mode 100644
index bb7deaa741e..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * 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.batch.components;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.BatchSide;
-import org.sonar.api.batch.RequiresDB;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.batch.deprecated.components.PeriodsDefinition;
-
-import javax.annotation.CheckForNull;
-
-import java.util.List;
-
-import static com.google.common.collect.Lists.newLinkedList;
-import static org.sonar.api.utils.DateUtils.longToDate;
-
-@RequiresDB
-@BatchSide
-public class TimeMachineConfiguration {
-
- private static final Logger LOG = LoggerFactory.getLogger(TimeMachineConfiguration.class);
-
- private final DatabaseSession session;
- private final PeriodsDefinition periodsDefinition;
-
- private List<Period> periods;
- private List<PastSnapshot> modulePastSnapshots;
-
- public TimeMachineConfiguration(DatabaseSession session, PeriodsDefinition periodsDefinition) {
- this.session = session;
- this.periodsDefinition = periodsDefinition;
- initModulePastSnapshots();
- }
-
- private void initModulePastSnapshots() {
- periods = newLinkedList();
- modulePastSnapshots = newLinkedList();
- for (PastSnapshot projectPastSnapshot : periodsDefinition.getRootProjectPastSnapshots()) {
- Snapshot snapshot = findSnapshot(projectPastSnapshot.getProjectSnapshot());
-
- PastSnapshot pastSnapshot = projectPastSnapshot.clonePastSnapshot();
- modulePastSnapshots.add(pastSnapshot);
- // When no snapshot is found, date of the period is null
- periods.add(new Period(pastSnapshot.getIndex(), snapshot != null ? longToDate(snapshot.getCreatedAtMs()) : null));
- LOG.info(pastSnapshot.toString());
- }
- }
-
- /**
- * Only used to get the real date of the snapshot on the current period.
- * The date is used to calculate new_violations measures
- */
- @CheckForNull
- private Snapshot findSnapshot(Snapshot projectSnapshot) {
- String hql = "from " + Snapshot.class.getSimpleName() + " where resourceId=:resourceId and (rootId=:rootSnapshotId or id=:rootSnapshotId)";
- List<Snapshot> snapshots = session.createQuery(hql)
- .setParameter("resourceId", projectSnapshot.getResourceId())
- .setParameter("rootSnapshotId", projectSnapshot.getId())
- .setMaxResults(1)
- .getResultList();
- return snapshots.isEmpty() ? null : snapshots.get(0);
- }
-
- public List<Period> periods() {
- return periods;
- }
-
- public List<PastSnapshot> getProjectPastSnapshots() {
- return modulePastSnapshots;
- }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/components/package-info.java
deleted file mode 100644
index 01d489e8f68..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/components/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * 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.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.batch.components;
-
-import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDate.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDate.java
deleted file mode 100644
index da44d6b4314..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDate.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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.batch.deprecated.components;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-import javax.annotation.CheckForNull;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.BatchSide;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.utils.DateUtils;
-import org.sonar.batch.components.PastSnapshot;
-
-import static org.sonar.api.utils.DateUtils.dateToLong;
-
-@BatchSide
-public class PastSnapshotFinderByDate {
-
- private DatabaseSession session;
-
- public PastSnapshotFinderByDate(DatabaseSession session) {
- this.session = session;
- }
-
- public PastSnapshot findByDate(Snapshot projectSnapshot, Date date) {
- Integer projectId = projectSnapshot != null ? projectSnapshot.getResourceId() : null;
- return findByDate(projectId, date);
- }
-
- PastSnapshot findByDate(Integer projectId, Date date) {
- Snapshot snapshot = null;
- if (projectId != null) {
- snapshot = findSnapshot(projectId, date);
- }
- SimpleDateFormat format = new SimpleDateFormat(DateUtils.DATE_FORMAT);
- return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DATE, date, snapshot).setModeParameter(format.format(date));
- }
-
- @CheckForNull
- private Snapshot findSnapshot(Integer projectId, Date date) {
- String hql = "from " + Snapshot.class.getSimpleName() + " where createdAt>=:date AND resourceId=:resourceId AND status=:status order by createdAt asc";
- List<Snapshot> snapshots = session.createQuery(hql)
- .setParameter("date", dateToLong(date))
- .setParameter("resourceId", projectId)
- .setParameter("status", Snapshot.STATUS_PROCESSED)
- .setMaxResults(1)
- .getResultList();
-
- return snapshots.isEmpty() ? null : snapshots.get(0);
- }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDays.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDays.java
deleted file mode 100644
index ed68dedceac..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDays.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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.batch.deprecated.components;
-
-import java.util.Date;
-import java.util.List;
-import javax.annotation.CheckForNull;
-import org.apache.commons.lang.time.DateUtils;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.BatchSide;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.batch.components.PastSnapshot;
-
-@BatchSide
-public class PastSnapshotFinderByDays {
-
- private DatabaseSession session;
-
- public PastSnapshotFinderByDays(DatabaseSession session) {
- this.session = session;
- }
-
- public PastSnapshot findFromDays(Snapshot projectSnapshot, int days) {
- Date targetDate = DateUtils.addDays(projectSnapshot.getCreatedAt(), -days);
- String hql = "from " + Snapshot.class.getSimpleName() + " where resourceId=:resourceId AND status=:status AND createdAt<:date order by createdAt asc";
- List<Snapshot> snapshots = session.createQuery(hql)
- .setParameter("date", projectSnapshot.getCreatedAtMs())
- .setParameter("resourceId", projectSnapshot.getResourceId())
- .setParameter("status", Snapshot.STATUS_PROCESSED)
- .getResultList();
-
- Snapshot snapshot = getNearestToTarget(snapshots, targetDate);
- return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DAYS, targetDate, snapshot).setModeParameter(String.valueOf(days));
- }
-
- @CheckForNull
- static Snapshot getNearestToTarget(List<Snapshot> snapshots, Date currentDate, int distanceInDays) {
- Date targetDate = DateUtils.addDays(currentDate, -distanceInDays);
- return getNearestToTarget(snapshots, targetDate);
- }
-
- @CheckForNull
- static Snapshot getNearestToTarget(List<Snapshot> snapshots, Date targetDate) {
- long bestDistance = Long.MAX_VALUE;
- Snapshot nearest = null;
- for (Snapshot snapshot : snapshots) {
- long distance = distance(snapshot.getCreatedAt(), targetDate);
- if (distance <= bestDistance) {
- bestDistance = distance;
- nearest = snapshot;
- }
- }
- return nearest;
- }
-
- static long distance(Date d1, Date d2) {
- return Math.abs(d1.getTime() - d2.getTime());
- }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysis.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysis.java
deleted file mode 100644
index 54661f5e85f..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysis.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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.batch.deprecated.components;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.BatchSide;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.utils.DateUtils;
-import org.sonar.batch.components.PastSnapshot;
-
-import static org.sonar.api.utils.DateUtils.longToDate;
-
-@BatchSide
-public class PastSnapshotFinderByPreviousAnalysis {
-
- private DatabaseSession session;
-
- public PastSnapshotFinderByPreviousAnalysis(DatabaseSession session) {
- this.session = session;
- }
-
- public PastSnapshot findByPreviousAnalysis(Snapshot projectSnapshot) {
- String hql = "from " + Snapshot.class.getSimpleName()
- + " where createdAt<:date AND resourceId=:resourceId AND status=:status and last=:last order by createdAt desc";
- List<Snapshot> snapshots = session.createQuery(hql)
- .setParameter("date", projectSnapshot.getCreatedAtMs())
- .setParameter("resourceId", projectSnapshot.getResourceId())
- .setParameter("status", Snapshot.STATUS_PROCESSED)
- .setParameter("last", true)
- .setMaxResults(1)
- .getResultList();
-
- if (snapshots.isEmpty()) {
- return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
- }
- Snapshot snapshot = snapshots.get(0);
- Date targetDate = longToDate(snapshot.getCreatedAtMs());
- SimpleDateFormat format = new SimpleDateFormat(DateUtils.DATE_FORMAT);
- return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, targetDate, snapshot).setModeParameter(format.format(targetDate));
- }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersion.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersion.java
deleted file mode 100644
index 03232c177d3..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersion.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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.batch.deprecated.components;
-
-import org.sonar.api.batch.BatchSide;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.batch.components.PastSnapshot;
-import org.sonar.core.event.db.EventMapper;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.MyBatis;
-
-import static org.sonar.api.utils.DateUtils.longToDate;
-
-@BatchSide
-public class PastSnapshotFinderByPreviousVersion {
-
- private final DatabaseSession session;
- private final MyBatis mybatis;
-
- public PastSnapshotFinderByPreviousVersion(DatabaseSession session, MyBatis mybatis) {
- this.session = session;
- this.mybatis = mybatis;
- }
-
- public PastSnapshot findByPreviousVersion(Snapshot projectSnapshot) {
- String currentVersion = projectSnapshot.getVersion();
- Integer resourceId = projectSnapshot.getResourceId();
- Long snapshotId;
- // Commit Hibernate transaction to avoid lock of project table
- session.commit();
- try (DbSession dbSession = mybatis.openSession(false)) {
- snapshotId = dbSession.getMapper(EventMapper.class).findSnapshotIdOfPreviousVersion(resourceId, currentVersion);
- }
-
- if (snapshotId == null) {
- return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION);
- }
-
- Snapshot snapshot = session.getSingleResult(Snapshot.class, "id", snapshotId.intValue());
-
- return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, longToDate(snapshot.getCreatedAtMs()), snapshot).setModeParameter(snapshot.getVersion());
- }
-
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersion.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersion.java
deleted file mode 100644
index 516e4ae97bc..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersion.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.batch.deprecated.components;
-
-import java.util.Date;
-import java.util.List;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.BatchSide;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.batch.components.PastSnapshot;
-
-import static org.sonar.api.utils.DateUtils.longToDate;
-
-@BatchSide
-public class PastSnapshotFinderByVersion {
-
- private final DatabaseSession session;
-
- public PastSnapshotFinderByVersion(DatabaseSession session) {
- this.session = session;
- }
-
- public PastSnapshot findByVersion(Snapshot projectSnapshot, String version) {
- String hql = "from " + Snapshot.class.getSimpleName() + " where version=:version AND resourceId=:resourceId AND status=:status order by createdAt desc";
- List<Snapshot> snapshots = session.createQuery(hql)
- .setParameter("version", version)
- .setParameter("resourceId", projectSnapshot.getResourceId())
- .setParameter("status", Snapshot.STATUS_PROCESSED)
- .setMaxResults(1)
- .getResultList();
-
- PastSnapshot result;
- if (snapshots.isEmpty()) {
- result = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION);
- } else {
- Snapshot snapshot = snapshots.get(0);
- Date targetDate = longToDate(snapshot.getCreatedAtMs());
- result = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION, targetDate, snapshot).setModeParameter(version);
- }
- return result;
- }
-
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PeriodsDefinition.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PeriodsDefinition.java
deleted file mode 100644
index e72f1eb11eb..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PeriodsDefinition.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * 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.batch.deprecated.components;
-
-import java.util.List;
-import javax.persistence.Query;
-import org.sonar.api.batch.BatchSide;
-import org.sonar.api.config.Settings;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.batch.DefaultProjectTree;
-import org.sonar.batch.components.PastSnapshot;
-import org.sonar.batch.components.PastSnapshotFinder;
-
-import static com.google.common.collect.Lists.newLinkedList;
-import static org.sonar.api.utils.DateUtils.dateToLong;
-
-@BatchSide
-public class PeriodsDefinition {
-
- private static final int NUMBER_OF_VARIATION_SNAPSHOTS = 5;
-
- private DatabaseSession session;
-
- private DefaultProjectTree projectTree;
- private final Settings settings;
-
- private List<PastSnapshot> projectPastSnapshots;
-
- public PeriodsDefinition(DatabaseSession session, DefaultProjectTree projectTree, Settings settings,
- PastSnapshotFinder pastSnapshotFinder) {
- this.session = session;
- this.projectTree = projectTree;
- this.settings = settings;
- initPastSnapshots(pastSnapshotFinder, projectTree.getRootProject().getQualifier());
- }
-
- private void initPastSnapshots(PastSnapshotFinder pastSnapshotFinder, String rootQualifier) {
- Snapshot projectSnapshot = buildProjectSnapshot();
- projectPastSnapshots = newLinkedList();
- if (projectSnapshot != null) {
- for (int index = 1; index <= NUMBER_OF_VARIATION_SNAPSHOTS; index++) {
- PastSnapshot pastSnapshot = pastSnapshotFinder.find(projectSnapshot, rootQualifier, settings, index);
- // SONAR-4700 Add a past snapshot only if it exists
- if (pastSnapshot != null && pastSnapshot.getProjectSnapshot() != null) {
- projectPastSnapshots.add(pastSnapshot);
- }
- }
- }
- }
-
- private Snapshot buildProjectSnapshot() {
- Query query = session
- .createNativeQuery("select p.id from projects p where p.kee=:resourceKey and p.enabled=:enabled");
- query.setParameter("resourceKey", projectTree.getRootProject().getKey());
- query.setParameter("enabled", Boolean.TRUE);
-
- Snapshot snapshot = null;
- Number projectId = session.getSingleResult(query, null);
- if (projectId != null) {
- snapshot = new Snapshot();
- snapshot.setResourceId(projectId.intValue());
- snapshot.setCreatedAtMs(dateToLong(projectTree.getRootProject().getAnalysisDate()));
- snapshot.setBuildDateMs(System.currentTimeMillis());
- snapshot.setVersion(projectTree.getRootProject().getAnalysisVersion());
- }
- return snapshot;
- }
-
- /**
- * @return past snapshots of root project
- */
- public List<PastSnapshot> getRootProjectPastSnapshots() {
- return projectPastSnapshots;
- }
-
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/MeasuresPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/MeasuresPublisher.java
index 8a8ae99436a..858f081417a 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/report/MeasuresPublisher.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/report/MeasuresPublisher.java
@@ -56,7 +56,7 @@ public class MeasuresPublisher implements ReportPublisherStep {
batchMeasures = Iterables.filter(batchMeasures, new Predicate<Measure>() {
@Override
public boolean apply(Measure input) {
- // Reload Metric to have all Hibernate fields populated
+ // Reload Metric to have all fields populated
input.setMetric(metricFinder.findByKey(input.getMetricKey()));
return shouldPersistMeasure(resource.resource(), input);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
index c4524dca799..c98d992a5cf 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
@@ -82,7 +82,6 @@ import org.sonar.batch.sensor.coverage.CoverageExclusions;
import org.sonar.batch.source.HighlightableBuilder;
import org.sonar.batch.source.SymbolizableBuilder;
import org.sonar.core.platform.ComponentContainer;
-import org.sonar.core.timemachine.Periods;
public class ModuleScanContainer extends ComponentContainer {
private static final Logger LOG = LoggerFactory.getLogger(ModuleScanContainer.class);
@@ -113,7 +112,6 @@ public class ModuleScanContainer extends ComponentContainer {
add(
EventBus.class,
- Periods.class,
PhaseExecutor.class,
RuleFinderCompatibility.class,
PostJobsExecutor.class,
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
index 53aa790b4a4..a224d4a3fb8 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
@@ -42,9 +42,7 @@ import org.sonar.batch.bootstrap.ExtensionMatcher;
import org.sonar.batch.bootstrap.ExtensionUtils;
import org.sonar.batch.bootstrap.MetricProvider;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
-import org.sonar.batch.components.PastMeasuresLoader;
import org.sonar.batch.deprecated.components.DefaultResourceCreationLock;
-import org.sonar.batch.deprecated.components.PeriodsDefinition;
import org.sonar.batch.duplication.DuplicationCache;
import org.sonar.batch.events.EventBus;
import org.sonar.batch.index.BatchComponentCache;
@@ -103,9 +101,6 @@ public class ProjectScanContainer extends ComponentContainer {
add(component);
}
addBatchComponents();
- if (analysisMode.isDb()) {
- addDataBaseComponents();
- }
addBatchExtensions();
Settings settings = getComponentByType(Settings.class);
if (settings != null && settings.getBoolean(CoreProperties.PROFILING_LOG_PROPERTY)) {
@@ -181,9 +176,6 @@ public class ProjectScanContainer extends ComponentContainer {
Languages.class,
DefaultLanguagesRepository.class,
- // Differential periods
- PeriodsDefinition.class,
-
// Measures
MeasureCache.class,
@@ -206,10 +198,6 @@ public class ProjectScanContainer extends ComponentContainer {
ScanTaskObservers.class);
}
- private void addDataBaseComponents() {
- add(PastMeasuresLoader.class);
- }
-
private void addBatchExtensions() {
getComponentByType(ExtensionInstaller.class).install(this, new BatchExtensionFilter());
}
diff --git a/sonar-batch/src/main/resources/org/sonar/batch/bootstrapper/logback.xml b/sonar-batch/src/main/resources/org/sonar/batch/bootstrapper/logback.xml
index 1f6425e75c5..4cda7344a24 100644
--- a/sonar-batch/src/main/resources/org/sonar/batch/bootstrapper/logback.xml
+++ b/sonar-batch/src/main/resources/org/sonar/batch/bootstrapper/logback.xml
@@ -18,14 +18,6 @@
</encoder>
</appender>
- <logger name="org.hibernate.cache.ReadWriteCache">
- <!-- removing "An item was expired by the cache while it was locked (increase your cache timeout)" msg -->
- <level value="ERROR"/>
- </logger>
- <logger name="org.hibernate">
- <level value="WARN"/>
- </logger>
-
<!-- BeanUtils generate to many DEBUG logs when sonar.verbose is set -->
<logger name="org.apache.commons.beanutils.converters">
<level value="WARN"/>
@@ -33,9 +25,6 @@
<!-- sonar.showSql -->
<!-- see also org.sonar.core.persistence.MyBatis#configureLogback() -->
- <logger name="org.hibernate.SQL">
- <level value="${SQL_LOGGER_LEVEL:-ERROR}"/>
- </logger>
<logger name="org.mybatis">
<level value="${SQL_LOGGER_LEVEL:-WARN}"/>
</logger>
diff --git a/sonar-batch/src/main/resources/org/sonar/batch/logback.xml b/sonar-batch/src/main/resources/org/sonar/batch/logback.xml
index 9766143b225..8efa6dfeaad 100644
--- a/sonar-batch/src/main/resources/org/sonar/batch/logback.xml
+++ b/sonar-batch/src/main/resources/org/sonar/batch/logback.xml
@@ -14,14 +14,6 @@
</encoder>
</appender>
- <logger name="org.hibernate.cache.ReadWriteCache">
- <!-- removing "An item was expired by the cache while it was locked (increase your cache timeout)" msg -->
- <level value="ERROR"/>
- </logger>
- <logger name="org.hibernate">
- <level value="WARN"/>
- </logger>
-
<!-- BeanUtils generate to many DEBUG logs when sonar.verbose is set -->
<logger name="org.apache.commons.beanutils.converters">
<level value="WARN"/>
@@ -29,9 +21,6 @@
<!-- sonar.showSql -->
<!-- see also org.sonar.core.persistence.MyBatis#configureLogback() -->
- <logger name="org.hibernate.SQL">
- <level value="ERROR"/>
- </logger>
<logger name="org.apache.ibatis">
<level value="WARN"/>
</logger>
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchDatabaseSessionFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchDatabaseSessionFactoryTest.java
deleted file mode 100644
index 7106ac25ff7..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchDatabaseSessionFactoryTest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.batch.bootstrap;
-
-import org.junit.Test;
-import org.sonar.api.database.DatabaseSession;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-public class BatchDatabaseSessionFactoryTest {
- @Test
- public void getSession() {
- DatabaseSession session = mock(DatabaseSession.class);
- BatchDatabaseSessionFactory factory = new BatchDatabaseSessionFactory(session);
-
- assertThat(factory.getSession()).isSameAs(session);
- }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchDatabaseTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchDatabaseTest.java
deleted file mode 100644
index ed3d0dc1f06..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchDatabaseTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.batch.bootstrap;
-
-import org.junit.Test;
-import org.sonar.api.config.Settings;
-
-import java.util.Properties;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-public class BatchDatabaseTest {
- @Test
- public void should_init_at_least_two_connections() {
- BatchDatabase db = new BatchDatabase(new Settings(), mock(JdbcDriverHolder.class));
- Properties props = new Properties();
-
- db.doCompleteProperties(props);
-
- assertThat(Integer.parseInt(props.getProperty("sonar.jdbc.initialSize"))).isGreaterThanOrEqualTo(2);
- assertThat(Integer.parseInt(props.getProperty("sonar.jdbc.maxActive"))).isGreaterThanOrEqualTo(2);
- }
-
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DatabaseCompatibilityTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DatabaseCompatibilityTest.java
deleted file mode 100644
index e0ea0d6a440..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DatabaseCompatibilityTest.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * 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.batch.bootstrap;
-
-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.DatabaseProperties;
-import org.sonar.api.utils.MessageException;
-import org.sonar.core.persistence.DatabaseVersion;
-import org.sonar.core.properties.PropertiesDao;
-import org.sonar.core.properties.PropertyDto;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class DatabaseCompatibilityTest {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- DatabaseVersion databaseVersion;
- ServerClient server;
- Settings settings;
- PropertiesDao propertiesDao;
-
- private DefaultAnalysisMode mode;
-
- @Before
- public void init() {
- server = mock(ServerClient.class);
- when(server.getURL()).thenReturn("http://localhost:9000");
- when(server.request("/api/server")).thenReturn("{\"id\":\"123456\",\"version\":\"3.1\",\"status\":\"UP\"}");
-
- settings = new Settings();
- settings.setProperty(DatabaseProperties.PROP_URL, "jdbc:postgresql://localhost/foo");
- settings.setProperty(DatabaseProperties.PROP_USER, "bar");
-
- propertiesDao = mock(PropertiesDao.class);
- when(propertiesDao.selectGlobalProperty(CoreProperties.SERVER_ID)).thenReturn(new PropertyDto().setValue("123456"));
-
- mode = mock(DefaultAnalysisMode.class);
-
- databaseVersion = mock(DatabaseVersion.class);
- }
-
- @Test
- public void shouldFailIfRequiresDowngrade() {
- when(databaseVersion.getStatus()).thenReturn(DatabaseVersion.Status.REQUIRES_DOWNGRADE);
-
- thrown.expect(MessageException.class);
- thrown.expectMessage("Database relates to a more recent version of SonarQube. Please check your settings (JDBC settings, version of Maven plugin)");
-
- new DatabaseCompatibility(databaseVersion, server, settings, propertiesDao, mode).start();
- }
-
- @Test
- public void shouldFailIfRequiresUpgrade() {
- when(databaseVersion.getStatus()).thenReturn(DatabaseVersion.Status.REQUIRES_UPGRADE);
-
- thrown.expect(MessageException.class);
- thrown.expectMessage("Database must be upgraded.");
-
- new DatabaseCompatibility(databaseVersion, server, settings, propertiesDao, mode).start();
- }
-
- @Test
- public void shouldFailIfNotSameServerId() {
- when(propertiesDao.selectGlobalProperty(CoreProperties.SERVER_ID)).thenReturn(new PropertyDto().setValue("11111111"));
-
- thrown.expect(MessageException.class);
- thrown.expectMessage("The current batch process and the configured remote server do not share the same DB configuration.");
- thrown.expectMessage("- Batch side: jdbc:postgresql://localhost/foo (bar / *****)");
- thrown.expectMessage("- Server side: check the configuration at http://localhost:9000/system");
-
- new DatabaseCompatibility(databaseVersion, server, settings, propertiesDao, mode).start();
- }
-
- @Test
- public void shouldUseDefaultUserNameWhenFaillingIfNotSameServerIdAndNoUserNameFound() {
- when(propertiesDao.selectGlobalProperty(CoreProperties.SERVER_ID)).thenReturn(new PropertyDto().setValue("11111111"));
-
- settings.removeProperty(DatabaseProperties.PROP_USER);
-
- thrown.expect(MessageException.class);
- thrown.expectMessage("- Batch side: jdbc:postgresql://localhost/foo (sonar / *****)");
-
- new DatabaseCompatibility(databaseVersion, server, settings, propertiesDao, mode).start();
- }
-
- @Test
- public void shouldFailIfCantGetServerId() {
- when(server.request("/api/server")).thenThrow(new IllegalStateException());
-
- thrown.expect(IllegalStateException.class);
-
- new DatabaseCompatibility(mock(DatabaseVersion.class), server, settings, propertiesDao, mode).start();
- }
-
- @Test
- public void shouldDoNothingIfUpToDate() {
- when(databaseVersion.getStatus()).thenReturn(DatabaseVersion.Status.UP_TO_DATE);
- new DatabaseCompatibility(databaseVersion, server, settings, propertiesDao, mode).start();
- // no error
- }
-
- @Test
- public void should_not_verify_compatibility_if_preview() {
- settings.setProperty(CoreProperties.SERVER_ID, "11111111");
- when(mode.isPreview()).thenReturn(true);
-
- new DatabaseCompatibility(databaseVersion, server, settings, propertiesDao, mode).start();
-
- // no failure
- }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java
index 5118c2426f4..39fc0210624 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java
@@ -22,10 +22,9 @@ package org.sonar.batch.bootstrap;
import org.junit.Test;
import org.sonar.api.BatchComponent;
import org.sonar.api.batch.BatchSide;
-import org.sonar.api.server.ServerSide;
import org.sonar.api.batch.InstantiationStrategy;
-import org.sonar.api.batch.RequiresDB;
import org.sonar.api.batch.SupportedEnvironment;
+import org.sonar.api.server.ServerSide;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
import static org.assertj.core.api.Assertions.assertThat;
@@ -81,14 +80,6 @@ public class ExtensionUtilsTest {
assertThat(ExtensionUtils.isMavenExtensionOnly(new BuildToolService())).isFalse();
}
- @Test
- public void shouldRequiresDB() {
- assertThat(ExtensionUtils.requiresDB(BatchService.class)).isFalse();
- assertThat(ExtensionUtils.requiresDB(new BatchService())).isFalse();
- assertThat(ExtensionUtils.requiresDB(PersistentService.class)).isTrue();
- assertThat(ExtensionUtils.requiresDB(new PersistentService())).isTrue();
- }
-
@BatchSide
@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
public static class BatchService {
@@ -126,10 +117,4 @@ public class ExtensionUtilsTest {
public static class BuildToolService {
}
-
- @BatchSide
- @RequiresDB
- public static class PersistentService {
-
- }
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/JdbcDriverHolderTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/JdbcDriverHolderTest.java
deleted file mode 100644
index 17c2096ba29..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/JdbcDriverHolderTest.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * 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.batch.bootstrap;
-
-import com.google.common.io.Resources;
-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.home.cache.FileCache;
-
-import java.io.File;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-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.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-
-public class JdbcDriverHolderTest {
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- ClassLoader initialThreadClassloader;
- private DefaultAnalysisMode mode;
-
- @Before
- public void before() {
- initialThreadClassloader = Thread.currentThread().getContextClassLoader();
- mode = mock(DefaultAnalysisMode.class);
- }
-
- @After
- public void after() {
- Thread.currentThread().setContextClassLoader(initialThreadClassloader);
- }
-
- @Test
- public void extend_classloader_with_jdbc_driver() {
- FileCache cache = mock(FileCache.class);
-
- File fakeDriver = new File(Resources.getResource(JdbcDriverHolderTest.class, "JdbcDriverHolderTest/jdbc-driver.jar").getFile());
- when(cache.get(eq("ojdbc14.jar"), eq("fakemd5"), any(FileCache.Downloader.class))).thenReturn(fakeDriver);
-
- /* jdbc-driver.jar has just one file /foo/foo.txt */
- assertThat(Thread.currentThread().getContextClassLoader().getResource("foo/foo.txt")).isNull();
-
- ServerClient server = mock(ServerClient.class);
- when(server.request("/deploy/jdbc-driver.txt")).thenReturn("ojdbc14.jar|fakemd5");
- when(server.request("/deploy/ojdbc14.jar")).thenReturn("fakecontent");
-
- JdbcDriverHolder holder = new JdbcDriverHolder(cache, mode, server);
- holder.start();
-
- assertThat(holder.getClassLoader().getResource("foo/foo.txt")).isNotNull();
- assertThat(Thread.currentThread().getContextClassLoader()).isSameAs(holder.getClassLoader());
- assertThat(holder.getClassLoader().getParent()).isSameAs(getClass().getClassLoader());
-
- holder.stop();
- assertThat(Thread.currentThread().getContextClassLoader()).isSameAs(getClass().getClassLoader());
- assertThat(holder.getClassLoader()).isNull();
- }
-
- @Test
- public void do_nothing_when_jdbc_driver_file_is_empty() {
- FileCache cache = mock(FileCache.class);
-
- ServerClient server = mock(ServerClient.class);
- when(server.request("/deploy/jdbc-driver.txt")).thenReturn("");
-
- JdbcDriverHolder holder = new JdbcDriverHolder(cache, mode, server);
- holder.start();
-
- verify(server, never()).download(anyString(), any(File.class));
- verifyZeroInteractions(cache);
- assertThat(holder.getClassLoader()).isNull();
- }
-
- @Test
- public void be_disabled_if_preview() {
- FileCache cache = mock(FileCache.class);
- when(mode.isPreview()).thenReturn(true);
- ServerClient server = mock(ServerClient.class);
- JdbcDriverHolder holder = new JdbcDriverHolder(cache, mode, server);
-
- holder.start();
-
- assertThat(holder.getClassLoader()).isNull();
- verifyZeroInteractions(server);
-
- // no error during stop
- holder.stop();
- }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java
deleted file mode 100644
index 60d8a465971..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * 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.batch.components;
-
-import org.junit.Test;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.measures.Metric;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import java.util.Arrays;
-import java.util.List;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.hasItems;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
-
-public class PastMeasuresLoaderTest extends AbstractDbUnitTestCase {
-
- private static final int PROJECT_SNAPSHOT_ID = 1000;
- private static final String PROJECT_KEY = "project";
- private static final String FILE_KEY = "project:org.foo.Bar";
-
- @Test
- public void shouldGetPastResourceMeasures() {
- setupData("shared");
-
- List<Metric> metrics = selectMetrics();
- Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", PROJECT_SNAPSHOT_ID);
-
- PastMeasuresLoader loader = new PastMeasuresLoader(getSession(), metrics);
- List<Object[]> measures = loader.getPastMeasures(FILE_KEY, projectSnapshot);
- assertThat(measures.size(), is(2));
-
- Object[] pastMeasure = measures.get(0);
- assertThat(PastMeasuresLoader.getMetricId(pastMeasure), is(1));
- assertThat(PastMeasuresLoader.getCharacteristicId(pastMeasure), nullValue());
- assertThat(PastMeasuresLoader.getPersonId(pastMeasure), nullValue());
- assertThat(PastMeasuresLoader.getValue(pastMeasure), is(5.0));
-
- pastMeasure = measures.get(1);
- assertThat(PastMeasuresLoader.getMetricId(pastMeasure), is(2));
- assertThat(PastMeasuresLoader.getCharacteristicId(pastMeasure), nullValue());
- assertThat(PastMeasuresLoader.getPersonId(pastMeasure), nullValue());
- assertThat(PastMeasuresLoader.getValue(pastMeasure), is(60.0));
- }
-
- @Test
- public void shouldGetPastProjectMeasures() {
- setupData("shared");
-
- List<Metric> metrics = selectMetrics();
- Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", PROJECT_SNAPSHOT_ID);
-
- PastMeasuresLoader loader = new PastMeasuresLoader(getSession(), metrics);
- List<Object[]> measures = loader.getPastMeasures(PROJECT_KEY, projectSnapshot);
- assertThat(measures.size(), is(2));
-
- Object[] pastMeasure = measures.get(0);
- assertThat(PastMeasuresLoader.getMetricId(pastMeasure), is(1));
- assertThat(PastMeasuresLoader.getCharacteristicId(pastMeasure), nullValue());
- assertThat(PastMeasuresLoader.getPersonId(pastMeasure), nullValue());
- assertThat(PastMeasuresLoader.getValue(pastMeasure), is(60.0));
-
- pastMeasure = measures.get(1);
- assertThat(PastMeasuresLoader.getMetricId(pastMeasure), is(2));
- assertThat(PastMeasuresLoader.getCharacteristicId(pastMeasure), nullValue());
- assertThat(PastMeasuresLoader.getPersonId(pastMeasure), nullValue());
- assertThat(PastMeasuresLoader.getValue(pastMeasure), is(80.0));
- }
-
- @Test
- public void shouldKeepOnlyNumericalMetrics() {
- Metric ncloc = new Metric("ncloc", Metric.ValueType.INT);
- ncloc.setId(1);
- Metric complexity = new Metric("complexity", Metric.ValueType.INT);
- complexity.setId(2);
- Metric data = new Metric("data", Metric.ValueType.DATA);
- data.setId(3);
- List<Metric> metrics = Arrays.asList(ncloc, complexity, data);
-
- PastMeasuresLoader loader = new PastMeasuresLoader(getSession(), metrics);
-
- assertThat(loader.getMetrics().size(), is(2));
- assertThat(loader.getMetrics(), hasItems(ncloc, complexity));
- }
-
- private List<Metric> selectMetrics() {
- return getSession().getResults(Metric.class);
- }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java
deleted file mode 100644
index 8d8506a063a..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * 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.batch.components;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.ArgumentMatcher;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.utils.DateUtils;
-import org.sonar.batch.deprecated.components.PastSnapshotFinderByDate;
-import org.sonar.batch.deprecated.components.PastSnapshotFinderByDays;
-import org.sonar.batch.deprecated.components.PastSnapshotFinderByPreviousAnalysis;
-import org.sonar.batch.deprecated.components.PastSnapshotFinderByPreviousVersion;
-import org.sonar.batch.deprecated.components.PastSnapshotFinderByVersion;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import static junit.framework.Assert.assertNull;
-import static org.hamcrest.Matchers.nullValue;
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsNot.not;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class PastSnapshotFinderTest {
-
- @Mock
- private PastSnapshotFinderByDays finderByDays;
- @Mock
- private PastSnapshotFinderByDate finderByDate;
- @Mock
- private PastSnapshotFinderByVersion finderByVersion;
- @Mock
- private PastSnapshotFinderByPreviousAnalysis finderByPreviousAnalysis;
- @Mock
- private PastSnapshotFinderByPreviousVersion finderByPreviousVersion;
-
- private PastSnapshotFinder finder;
-
- @Before
- public void initFinders() {
- MockitoAnnotations.initMocks(this);
-
- finder = new PastSnapshotFinder(finderByDays, finderByVersion, finderByDate, finderByPreviousAnalysis, finderByPreviousVersion);
- }
-
- @Test
- public void should_find() {
- Settings settings = new Settings().setProperty("sonar.timemachine.period5", "1.2");
-
- when(finderByVersion.findByVersion(null, "1.2")).thenReturn(new PastSnapshot("version", new Date(), new Snapshot()));
-
- PastSnapshot variationSnapshot = finder.find(null, null, settings, 5);
-
- verify(finderByVersion).findByVersion(null, "1.2");
- assertThat(variationSnapshot.getIndex(), is(5));
- assertThat(variationSnapshot.getMode(), is("version"));
- assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue()));
- }
-
- @Test
- public void should_find_with_qualifier_suffix() {
- Settings settings = new Settings().setProperty("sonar.timemachine.period5.TRK", "1.2");
-
- when(finderByVersion.findByVersion(null, "1.2")).thenReturn(new PastSnapshot("version", new Date(), new Snapshot()));
-
- PastSnapshot variationSnapshot = finder.find(null, "TRK", settings, 5);
-
- verify(finderByVersion).findByVersion(null, "1.2");
- assertThat(variationSnapshot.getIndex(), is(5));
- assertThat(variationSnapshot.getMode(), is("version"));
- assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue()));
- }
-
- @Test
- public void should_find_by_number_of_days() {
- when(finderByDays.findFromDays(null, 30)).thenReturn(new PastSnapshot("days", null).setModeParameter("30"));
-
- PastSnapshot variationSnapshot = finder.find(null, 1, "30");
-
- verify(finderByDays).findFromDays(null, 30);
- assertNotNull(variationSnapshot);
- assertThat(variationSnapshot.getIndex(), is(1));
- assertThat(variationSnapshot.getMode(), is("days"));
- assertThat(variationSnapshot.getModeParameter(), is("30"));
- }
-
- @Test
- public void should_not_find_by_number_of_days() {
- PastSnapshot variationSnapshot = finder.find(null, 1, "30");
-
- verify(finderByDays).findFromDays(null, 30);
- assertNull(variationSnapshot);
- }
-
- @Test
- 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()));
-
- PastSnapshot variationSnapshot = finder.find(null, 2, "2010-05-18");
-
- verify(finderByDate).findByDate(any(Snapshot.class), argThat(new ArgumentMatcher<Date>() {
- @Override
- public boolean matches(Object o) {
- return o.equals(date);
- }
- }));
- assertThat(variationSnapshot.getIndex(), is(2));
- assertThat(variationSnapshot.getMode(), is("date"));
- assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue()));
- }
-
- @Test
- public void should_not_find_by_date() {
- when(finderByDate.findByDate(any(Snapshot.class), any(Date.class))).thenReturn(null);
-
- PastSnapshot variationSnapshot = finder.find(null, 2, "2010-05-18");
-
- verify(finderByDate).findByDate(any(Snapshot.class), any(Date.class));
- assertNull(variationSnapshot);
- }
-
- @Test
- public void should_find_by_previous_analysis() {
- final Date date = DateUtils.parseDate("2010-05-18");
- Snapshot snapshot = new Snapshot();
- snapshot.setCreatedAtMs(date.getTime());
- when(finderByPreviousAnalysis.findByPreviousAnalysis(null)).thenReturn(new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, date, snapshot));
-
- PastSnapshot variationSnapshot = finder.find(null, 2, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
-
- verify(finderByPreviousAnalysis).findByPreviousAnalysis(null);
- assertThat(variationSnapshot.getIndex(), is(2));
- assertThat(variationSnapshot.getMode(), is(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS));
- assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue()));
- }
-
- @Test
- public void should_not_find_previous_analysis() {
- when(finderByPreviousAnalysis.findByPreviousAnalysis(null)).thenReturn(null);
-
- PastSnapshot variationSnapshot = finder.find(null, 2, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
-
- verify(finderByPreviousAnalysis).findByPreviousAnalysis(null);
-
- assertNull(variationSnapshot);
- }
-
- @Test
- public void should_find_by_previous_version() throws ParseException {
- final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
- final Date date = format.parse("2010-05-18");
- Snapshot snapshot = new Snapshot();
- snapshot.setCreatedAtMs(date.getTime());
- when(finderByPreviousVersion.findByPreviousVersion(null)).thenReturn(new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, date, snapshot));
-
- PastSnapshot variationSnapshot = finder.find(null, 2, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION);
-
- verify(finderByPreviousVersion).findByPreviousVersion(null);
- assertThat(variationSnapshot.getIndex(), is(2));
- assertThat(variationSnapshot.getMode(), is(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION));
- assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue()));
- }
-
- @Test
- public void should_find_by_version() {
- when(finderByVersion.findByVersion(null, "1.2")).thenReturn(new PastSnapshot("version", new Date(), new Snapshot()));
-
- PastSnapshot variationSnapshot = finder.find(null, 2, "1.2");
-
- verify(finderByVersion).findByVersion(null, "1.2");
- assertThat(variationSnapshot.getIndex(), is(2));
- assertThat(variationSnapshot.getMode(), is("version"));
- assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue()));
- }
-
- @Test
- public void should_not_find_version() {
- when(finderByVersion.findByVersion(null, "1.2")).thenReturn(null);
-
- PastSnapshot variationSnapshot = finder.find(null, 2, "1.2");
-
- verify(finderByVersion).findByVersion(null, "1.2");
- assertNull(variationSnapshot);
- }
-
- @Test
- public void should_not_fail_if_unknown_format() {
- // should not be called
- when(finderByPreviousAnalysis.findByPreviousAnalysis(null)).thenReturn(new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, new Date(), new Snapshot()));
-
- assertNull(finder.find(null, 2, "foooo"));
- }
-
- @Test
- public void should_get_property_value() {
- Settings settings = new Settings().setProperty("sonar.timemachine.period1", "5");
-
- assertThat(PastSnapshotFinder.getPropertyValue("FIL", settings, 1), is("5"));
- assertThat(PastSnapshotFinder.getPropertyValue("FIL", settings, 999), nullValue());
- }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java
deleted file mode 100644
index 3d38431f780..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * 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.batch.components;
-
-import org.junit.Test;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.Qualifiers;
-
-import java.util.Date;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class PastSnapshotTest {
-
- @Test
- public void test_some_setters_and_getters() {
- Snapshot snapshot = new Snapshot().setQualifier(Qualifiers.FILE).setCreatedAtMs(System.currentTimeMillis());
- snapshot.setId(10);
- PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION, new Date(),
- snapshot)
- .setModeParameter("2.3")
- .setIndex(1);
-
- assertThat(pastSnapshot.getModeParameter()).isEqualTo("2.3");
- assertThat(pastSnapshot.getIndex()).isEqualTo(1);
- assertThat(pastSnapshot.getQualifier()).isEqualTo(Qualifiers.FILE);
- assertThat(pastSnapshot.getDate()).isNotNull();
- assertThat(pastSnapshot.getProjectSnapshotId()).isEqualTo(10);
- }
-
- @Test
- public void test_some_setters_and_getters_with_empty_snapshot() {
- PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION);
-
- assertThat(pastSnapshot.getQualifier()).isNull();
- assertThat(pastSnapshot.getDate()).isNull();
- assertThat(pastSnapshot.getProjectSnapshotId()).isNull();
- }
-
- @Test
- public void testToStringForVersion() {
- PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION, new Date(), new Snapshot().setCreatedAtMs(System.currentTimeMillis())).setModeParameter("2.3");
- assertThat(pastSnapshot.toString()).startsWith("Compare to version 2.3");
- }
-
- @Test
- public void testToStringForVersionWithoutDate() {
- PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION).setModeParameter("2.3");
- assertThat(pastSnapshot.toString()).isEqualTo("Compare to version 2.3");
- }
-
- @Test
- public void testToStringForNumberOfDays() {
- PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DAYS, new Date()).setModeParameter("30");
- assertThat(pastSnapshot.toString()).startsWith("Compare over 30 days (");
- }
-
- @Test
- public void testToStringForNumberOfDaysWithSnapshot() {
- PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DAYS, new Date(), new Snapshot().setCreatedAtMs(System.currentTimeMillis())).setModeParameter("30");
- assertThat(pastSnapshot.toString()).startsWith("Compare over 30 days (");
- }
-
- @Test
- public void testToStringForDate() {
- PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DATE, new Date());
- assertThat(pastSnapshot.toString()).startsWith("Compare to date ");
- }
-
- @Test
- public void testToStringForDateWithSnapshot() {
- PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DATE, new Date(), new Snapshot().setCreatedAtMs(System.currentTimeMillis()));
- assertThat(pastSnapshot.toString()).startsWith("Compare to date ");
- }
-
- @Test
- public void testToStringForPreviousAnalysis() {
- PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, new Date(), new Snapshot().setCreatedAtMs(System.currentTimeMillis()));
- assertThat(pastSnapshot.toString()).startsWith("Compare to previous analysis ");
- }
-
- @Test
- public void testToStringForPreviousAnalysisWithoutDate() {
- PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
- assertThat(pastSnapshot.toString()).isEqualTo("Compare to previous analysis");
- }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java
deleted file mode 100644
index b4a7daac7d5..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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.batch.components;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.batch.deprecated.components.PeriodsDefinition;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import java.util.Date;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class TimeMachineConfigurationTest extends AbstractDbUnitTestCase {
-
- private PeriodsDefinition periodsDefinition;
-
- @Before
- public void before() {
- setupData("shared");
- periodsDefinition = mock(PeriodsDefinition.class);
- }
-
- @Test
- public void get_project_past_snapshot() {
- Snapshot projectSnapshot = new Snapshot();
- projectSnapshot.setId(1010);
- projectSnapshot.setResourceId(1);
- PastSnapshot projectPastSnapshot = new PastSnapshot("mode", new Date(), projectSnapshot);
-
- when(periodsDefinition.getRootProjectPastSnapshots()).thenReturn(newArrayList(projectPastSnapshot));
-
- TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(getSession(), periodsDefinition);
- assertThat(timeMachineConfiguration.periods()).hasSize(1);
- assertThat(timeMachineConfiguration.periods().get(0).getDate()).isNotNull();
- assertThat(timeMachineConfiguration.getProjectPastSnapshots()).hasSize(1);
- assertThat(timeMachineConfiguration.getProjectPastSnapshots().get(0).getProjectSnapshot().getId()).isEqualTo(1010);
- }
-
- @Test
- public void get_module_past_snapshot() {
- Snapshot projectSnapshot = new Snapshot();
- projectSnapshot.setId(1010);
- projectSnapshot.setResourceId(2);
- PastSnapshot projectPastSnapshot = new PastSnapshot("mode", new Date(), projectSnapshot);
-
- when(periodsDefinition.getRootProjectPastSnapshots()).thenReturn(newArrayList(projectPastSnapshot));
-
- TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(getSession(), periodsDefinition);
- assertThat(timeMachineConfiguration.periods()).hasSize(1);
- assertThat(timeMachineConfiguration.periods().get(0).getDate()).isNotNull();
- assertThat(timeMachineConfiguration.getProjectPastSnapshots()).hasSize(1);
- assertThat(timeMachineConfiguration.getProjectPastSnapshots().get(0).getProjectSnapshot().getId()).isEqualTo(1010);
- }
-
- @Test
- public void complete_past_snapshot_from_project_past_snapshot() {
- Snapshot projectSnapshot = new Snapshot();
- projectSnapshot.setId(1010);
-
- PastSnapshot projectPastSnapshot = new PastSnapshot("mode", new Date(), projectSnapshot);
- projectPastSnapshot.setIndex(1);
- projectPastSnapshot.setMode("mode");
- projectPastSnapshot.setModeParameter("modeParam");
-
- when(periodsDefinition.getRootProjectPastSnapshots()).thenReturn(newArrayList(projectPastSnapshot));
-
- TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(getSession(), periodsDefinition);
- assertThat(timeMachineConfiguration.getProjectPastSnapshots()).hasSize(1);
- assertThat(timeMachineConfiguration.getProjectPastSnapshots().get(0).getProjectSnapshot().getId()).isEqualTo(1010);
- assertThat(timeMachineConfiguration.getProjectPastSnapshots().get(0).getIndex()).isEqualTo(1);
- assertThat(timeMachineConfiguration.getProjectPastSnapshots().get(0).getMode()).isEqualTo("mode");
- assertThat(timeMachineConfiguration.getProjectPastSnapshots().get(0).getModeParameter()).isEqualTo("modeParam");
- }
-
- @Test
- public void get_no_date_on_new_project() {
- Snapshot projectSnapshot = new Snapshot();
- projectSnapshot.setId(1010);
-
- PastSnapshot projectPastSnapshot = new PastSnapshot("mode", new Date(), projectSnapshot);
-
- when(periodsDefinition.getRootProjectPastSnapshots()).thenReturn(newArrayList(projectPastSnapshot));
-
- TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(getSession(), periodsDefinition);
- assertThat(timeMachineConfiguration.periods()).hasSize(1);
- assertThat(timeMachineConfiguration.periods().get(0).getDate()).isNull();
- }
-
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDateTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDateTest.java
deleted file mode 100644
index 7ab4b0e76e8..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDateTest.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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.batch.deprecated.components;
-
-import org.junit.Test;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.batch.components.PastSnapshot;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
-public class PastSnapshotFinderByDateTest extends AbstractDbUnitTestCase {
- public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
-
- @Test
- public void shouldFindDate() throws ParseException {
- setupData("shared");
-
- Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010);
- PastSnapshotFinderByDate finder = new PastSnapshotFinderByDate(getSession());
-
- Date date = DATE_FORMAT.parse("2008-11-22");
-
- PastSnapshot pastSnapshot = finder.findByDate(projectSnapshot, date);
- assertThat(pastSnapshot.getProjectSnapshotId(), is(1006));
- }
-
- @Test
- public void shouldFindNearestLaterDate() throws ParseException {
- setupData("shared");
-
- Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010);
- PastSnapshotFinderByDate finder = new PastSnapshotFinderByDate(getSession());
-
- Date date = DATE_FORMAT.parse("2008-11-24");
-
- PastSnapshot pastSnapshot = finder.findByDate(projectSnapshot, date);
- assertThat(pastSnapshot.getProjectSnapshotId(), is(1009));
- }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDaysTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDaysTest.java
deleted file mode 100644
index 6117905e446..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDaysTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * 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.batch.deprecated.components;
-
-import org.hamcrest.core.IsNull;
-import org.junit.Test;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertThat;
-
-public class PastSnapshotFinderByDaysTest extends AbstractDbUnitTestCase {
-
- private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
-
- @Test
- public void shouldGetNextSnapshot() {
- setupData("shared");
-
- Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1009); // 2008-11-16
- PastSnapshotFinderByDays finder = new PastSnapshotFinderByDays(getSession());
-
- assertThat(finder.findFromDays(projectSnapshot, 50).getProjectSnapshotId(), is(1000));
- }
-
- @Test
- public void shouldIgnoreUnprocessedSnapshots() {
- setupData("shared");
-
- Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1009); // 2008-11-16
- PastSnapshotFinderByDays finder = new PastSnapshotFinderByDays(getSession());
-
- assertThat(finder.findFromDays(projectSnapshot, 7).getProjectSnapshotId(), is(1006));
- }
-
- @Test
- public void shouldNotFindSelf() {
- setupData("shouldNotFindSelf");
-
- Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1009); // 2008-11-16
- PastSnapshotFinderByDays finder = new PastSnapshotFinderByDays(getSession());
-
- assertThat(finder.findFromDays(projectSnapshot, 1).getProjectSnapshot(), nullValue());
- }
-
- @Test
- public void shouldLocateNearestSnapshotBefore() throws ParseException {
- Date current = dateFormat.parse("2010-10-20");
- // distance: 15 => target is 2010-10-05
-
- List<Snapshot> snapshots = Arrays.asList(
- newSnapshot(1, "2010-09-30"),
- newSnapshot(2, "2010-10-03"),// -2 days
- newSnapshot(3, "2010-10-08"),// +3 days
- newSnapshot(4, "2010-10-12") // + 7 days
- );
- assertThat(PastSnapshotFinderByDays.getNearestToTarget(snapshots, current, 15).getId(), is(2));
- }
-
- @Test
- public void shouldLocateNearestSnapshotAfter() throws ParseException {
- Date current = dateFormat.parse("2010-10-20");
- // distance: 15 => target is 2010-10-05
-
- List<Snapshot> snapshots = Arrays.asList(
- newSnapshot(1, "2010-09-30"),
- newSnapshot(2, "2010-10-01"),// -4 days
- newSnapshot(3, "2010-10-08"),// +3 days
- newSnapshot(4, "2010-10-12") // + 7 days
- );
- assertThat(PastSnapshotFinderByDays.getNearestToTarget(snapshots, current, 15).getId(), is(3));
- }
-
- @Test
- public void shouldReturnNullIfNoSnapshots() throws ParseException {
- Date current = dateFormat.parse("2010-10-20");
- List<Snapshot> snapshots = Collections.emptyList();
- assertThat(PastSnapshotFinderByDays.getNearestToTarget(snapshots, current, 15), IsNull.nullValue());
- }
-
- private Snapshot newSnapshot(int id, String date) throws ParseException {
- Snapshot snapshot = new Snapshot();
- snapshot.setId(id);
- snapshot.setCreatedAtMs(dateFormat.parse(date).getTime());
- return snapshot;
- }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysisTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysisTest.java
deleted file mode 100644
index f228d3b8ab8..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysisTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.batch.deprecated.components;
-
-import org.junit.Test;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.batch.components.PastSnapshot;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.core.IsNull.nullValue;
-import static org.junit.Assert.assertThat;
-
-public class PastSnapshotFinderByPreviousAnalysisTest extends AbstractDbUnitTestCase {
-
- @Test
- public void shouldFindPreviousAnalysis() {
- setupData("shouldFindPreviousAnalysis");
-
- Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010);
- PastSnapshotFinderByPreviousAnalysis finder = new PastSnapshotFinderByPreviousAnalysis(getSession());
-
- PastSnapshot pastSnapshot = finder.findByPreviousAnalysis(projectSnapshot);
- assertThat(pastSnapshot.getProjectSnapshotId(), is(1009));
- }
-
- @Test
- public void shouldReturnPastSnapshotEvenWhenNoPreviousAnalysis() {
- setupData("shouldNotFindPreviousAnalysis");
-
- Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010);
- PastSnapshotFinderByPreviousAnalysis finder = new PastSnapshotFinderByPreviousAnalysis(getSession());
-
- PastSnapshot pastSnapshot = finder.findByPreviousAnalysis(projectSnapshot);
- assertThat(pastSnapshot.isRelatedToSnapshot(), is(false));
- assertThat(pastSnapshot.getProjectSnapshot(), nullValue());
- assertThat(pastSnapshot.getDate(), nullValue());
- }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest.java
deleted file mode 100644
index bd71b0b4351..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * 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.batch.deprecated.components;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.batch.components.PastSnapshot;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class PastSnapshotFinderByPreviousVersionTest extends AbstractDbUnitTestCase {
-
- private PastSnapshotFinderByPreviousVersion finder;
-
- @Before
- public void before() {
- finder = new PastSnapshotFinderByPreviousVersion(getSession(), getMyBatis());
- }
-
- @Test
- public void shouldFindByPreviousVersion() {
- setupData("with-previous-version");
-
- Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1003);
- PastSnapshot foundSnapshot = finder.findByPreviousVersion(currentProjectSnapshot);
- assertThat(foundSnapshot.getProjectSnapshotId()).isEqualTo(1001);
- assertThat(foundSnapshot.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION);
- assertThat(foundSnapshot.getModeParameter()).isEqualTo("1.1");
- }
-
- @Test
- public void shouldFindByPreviousVersionWhenPreviousVersionDeleted() {
- setupData("with-previous-version-deleted");
-
- Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1003);
- PastSnapshot foundSnapshot = finder.findByPreviousVersion(currentProjectSnapshot);
- assertThat(foundSnapshot.getProjectSnapshotId()).isEqualTo(1000);
- assertThat(foundSnapshot.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION);
- assertThat(foundSnapshot.getModeParameter()).isEqualTo("1.0");
- }
-
- @Test
- public void testWithNoPreviousVersion() {
- setupData("no-previous-version");
-
- Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1003);
- PastSnapshot foundSnapshot = finder.findByPreviousVersion(currentProjectSnapshot);
- assertThat(foundSnapshot.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION);
- assertThat(foundSnapshot.getProjectSnapshot()).isNull();
- assertThat(foundSnapshot.getModeParameter()).isNull();
- }
-
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersionTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersionTest.java
deleted file mode 100644
index 85411b26cf7..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersionTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.batch.deprecated.components;
-
-import org.junit.Test;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.batch.components.PastSnapshot;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class PastSnapshotFinderByVersionTest extends AbstractDbUnitTestCase {
-
- @Test
- public void shouldFindByVersion() {
- setupData("shared");
-
- Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010);
- PastSnapshotFinderByVersion finder = new PastSnapshotFinderByVersion(getSession());
-
- PastSnapshot foundSnapshot = finder.findByVersion(currentProjectSnapshot, "1.1");
- assertThat(foundSnapshot.getProjectSnapshotId()).isEqualTo(1009);
- assertThat(foundSnapshot.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_VERSION);
- }
-
- @Test
- public void testIfNoVersionFound() {
- setupData("shared");
-
- Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010);
- PastSnapshotFinderByVersion finder = new PastSnapshotFinderByVersion(getSession());
-
- PastSnapshot foundSnapshot = finder.findByVersion(currentProjectSnapshot, "2.1");
- assertThat(foundSnapshot.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_VERSION);
- assertThat(foundSnapshot.getProjectSnapshot()).isNull();
- assertThat(foundSnapshot.getModeParameter()).isNull();
- }
-
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PeriodsDefinitionTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PeriodsDefinitionTest.java
deleted file mode 100644
index 373398f8edc..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PeriodsDefinitionTest.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * 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.batch.deprecated.components;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.ArgumentMatcher;
-import org.sonar.api.config.Settings;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.Project;
-import org.sonar.batch.DefaultProjectTree;
-import org.sonar.batch.components.PastSnapshotFinder;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-
-public class PeriodsDefinitionTest extends AbstractDbUnitTestCase {
-
- private Settings settings;
- private PastSnapshotFinder pastSnapshotFinder;
-
- @Before
- public void before() {
- setupData("shared");
- settings = new Settings();
- pastSnapshotFinder = mock(PastSnapshotFinder.class);
- }
-
- @Test
- public void should_init_past_snapshots() {
- DefaultProjectTree projectTree = mock(DefaultProjectTree.class);
- when(projectTree.getRootProject()).thenReturn(new Project("my:project"));
- new PeriodsDefinition(getSession(), projectTree, settings, pastSnapshotFinder);
-
- verify(pastSnapshotFinder).find(argThat(new ArgumentMatcher<Snapshot>() {
- @Override
- public boolean matches(Object o) {
- return ((Snapshot) o).getResourceId() == 1 /* see database in shared.xml */;
- }
- }), anyString(), eq(settings), eq(1));
- }
-
- @Test
- public void should_not_init_past_snapshots_if_first_analysis() {
- DefaultProjectTree projectTree = mock(DefaultProjectTree.class);
- when(projectTree.getRootProject()).thenReturn(new Project("new:project"));
-
- new PeriodsDefinition(getSession(), projectTree, settings, pastSnapshotFinder);
-
- verifyZeroInteractions(pastSnapshotFinder);
- }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java
index c9f3fa89e73..d859b83ce47 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java
@@ -26,7 +26,6 @@ import org.junit.rules.TemporaryFolder;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Directory;
import org.sonar.api.resources.Java;
import org.sonar.api.resources.Project;
@@ -56,33 +55,33 @@ public class ComponentsPublisherTest {
Project root = new Project("foo").setName("Root project").setDescription("Root description")
.setAnalysisDate(DateUtils.parseDate(("2012-12-12")));
root.setId(1).setUuid("PROJECT_UUID");
- resourceCache.add(root, null).setSnapshot(new Snapshot().setId(11));
+ resourceCache.add(root, null);
Project module1 = new Project("module1").setName("Module1").setDescription("Module description");
module1.setParent(root);
module1.setId(2).setUuid("MODULE_UUID");
- resourceCache.add(module1, root).setSnapshot(new Snapshot().setId(12));
+ resourceCache.add(module1, root);
rootDef.addSubProject(ProjectDefinition.create().setKey("module1"));
Directory dir = Directory.create("src");
dir.setEffectiveKey("module1:src");
dir.setId(3).setUuid("DIR_UUID");
- resourceCache.add(dir, module1).setSnapshot(new Snapshot().setId(13));
+ resourceCache.add(dir, module1);
org.sonar.api.resources.File file = org.sonar.api.resources.File.create("src/Foo.java", Java.INSTANCE, false);
file.setEffectiveKey("module1:src/Foo.java");
file.setId(4).setUuid("FILE_UUID");
- resourceCache.add(file, dir).setSnapshot(new Snapshot().setId(14)).setInputPath(new DefaultInputFile("module1", "src/Foo.java").setLines(2));
+ resourceCache.add(file, dir).setInputPath(new DefaultInputFile("module1", "src/Foo.java").setLines(2));
org.sonar.api.resources.File fileWithoutLang = org.sonar.api.resources.File.create("src/make", null, false);
fileWithoutLang.setEffectiveKey("module1:src/make");
fileWithoutLang.setId(5).setUuid("FILE_WITHOUT_LANG_UUID");
- resourceCache.add(fileWithoutLang, dir).setSnapshot(new Snapshot().setId(15)).setInputPath(new DefaultInputFile("module1", "src/make").setLines(10));
+ resourceCache.add(fileWithoutLang, dir).setInputPath(new DefaultInputFile("module1", "src/make").setLines(10));
org.sonar.api.resources.File testFile = org.sonar.api.resources.File.create("test/FooTest.java", Java.INSTANCE, true);
testFile.setEffectiveKey("module1:test/FooTest.java");
testFile.setId(6).setUuid("TEST_FILE_UUID");
- resourceCache.add(testFile, dir).setSnapshot(new Snapshot().setId(16)).setInputPath(new DefaultInputFile("module1", "test/FooTest.java").setLines(4));
+ resourceCache.add(testFile, dir).setInputPath(new DefaultInputFile("module1", "test/FooTest.java").setLines(4));
ImmutableProjectReactor reactor = new ImmutableProjectReactor(rootDef);
@@ -123,14 +122,14 @@ public class ComponentsPublisherTest {
Project root = new Project("foo:my_branch").setName("Root project")
.setAnalysisDate(DateUtils.parseDate(("2012-12-12")));
root.setId(1).setUuid("PROJECT_UUID");
- resourceCache.add(root, null).setSnapshot(new Snapshot().setId(11));
+ resourceCache.add(root, null);
rootDef.properties().put(CoreProperties.LINKS_HOME_PAGE, "http://home");
rootDef.properties().put(CoreProperties.PROJECT_BRANCH_PROPERTY, "my_branch");
Project module1 = new Project("module1:my_branch").setName("Module1");
module1.setParent(root);
module1.setId(2).setUuid("MODULE_UUID");
- resourceCache.add(module1, root).setSnapshot(new Snapshot().setId(12));
+ resourceCache.add(module1, root);
ProjectDefinition moduleDef = ProjectDefinition.create().setKey("module1");
moduleDef.properties().put(CoreProperties.LINKS_CI, "http://ci");
rootDef.addSubProject(moduleDef);
@@ -138,12 +137,12 @@ public class ComponentsPublisherTest {
Directory dir = Directory.create("src");
dir.setEffectiveKey("module1:my_branch:my_branch:src");
dir.setId(3).setUuid("DIR_UUID");
- resourceCache.add(dir, module1).setSnapshot(new Snapshot().setId(13));
+ resourceCache.add(dir, module1);
org.sonar.api.resources.File file = org.sonar.api.resources.File.create("src/Foo.java", Java.INSTANCE, false);
file.setEffectiveKey("module1:my_branch:my_branch:src/Foo.java");
file.setId(4).setUuid("FILE_UUID");
- resourceCache.add(file, dir).setSnapshot(new Snapshot().setId(14)).setInputPath(new DefaultInputFile("module1", "src/Foo.java").setLines(2));
+ resourceCache.add(file, dir).setInputPath(new DefaultInputFile("module1", "src/Foo.java").setLines(2));
ImmutableProjectReactor reactor = new ImmutableProjectReactor(rootDef);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java
index b8e4b7acfb3..c257614fe7c 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java
@@ -19,13 +19,17 @@
*/
package org.sonar.batch.report;
+import java.io.File;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.database.model.Snapshot;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.resources.Project;
@@ -36,12 +40,6 @@ import org.sonar.batch.protocol.output.BatchReportReader;
import org.sonar.batch.protocol.output.BatchReportWriter;
import org.sonar.batch.scan.measure.MeasureCache;
-import java.io.File;
-import java.io.InputStream;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
@@ -62,7 +60,7 @@ public class CoveragePublisherTest {
Project p = new Project("foo").setAnalysisDate(new Date(1234567L));
BatchComponentCache resourceCache = new BatchComponentCache();
sampleFile = org.sonar.api.resources.File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php");
- resourceCache.add(p, null).setSnapshot(new Snapshot().setId(2));
+ resourceCache.add(p, null);
resourceCache.add(sampleFile, null).setInputPath(new DefaultInputFile("foo", "src/Foo.php").setLines(5));
measureCache = mock(MeasureCache.class);
when(measureCache.byMetric(anyString(), anyString())).thenReturn(Collections.<Measure>emptyList());
diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java
index a27ce7d2447..3e0f79030bf 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/report/IssuesPublisherTest.java
@@ -28,7 +28,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Project;
import org.sonar.api.rule.RuleKey;
import org.sonar.batch.index.BatchComponentCache;
@@ -60,7 +59,7 @@ public class IssuesPublisherTest {
project = new Project("foo").setAnalysisDate(new Date(1234567L));
BatchComponentCache componentCache = new BatchComponentCache();
org.sonar.api.resources.Resource sampleFile = org.sonar.api.resources.File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php");
- componentCache.add(project, null).setSnapshot(new Snapshot().setId(2));
+ componentCache.add(project, null);
componentCache.add(sampleFile, project);
issueCache = mock(IssueCache.class);
when(issueCache.byComponent(anyString())).thenReturn(Collections.<DefaultIssue>emptyList());
diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/MeasuresPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/MeasuresPublisherTest.java
index c4faec31bce..157f1e60f62 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/report/MeasuresPublisherTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/report/MeasuresPublisherTest.java
@@ -20,7 +20,6 @@
package org.sonar.batch.report;
import java.io.File;
-import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
@@ -28,11 +27,9 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import org.sonar.api.database.model.Snapshot;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.Metric;
-import org.sonar.api.measures.Metric.Level;
import org.sonar.api.measures.Metric.ValueType;
import org.sonar.api.measures.MetricFinder;
import org.sonar.api.resources.Project;
@@ -64,7 +61,7 @@ public class MeasuresPublisherTest {
Project p = new Project("foo").setAnalysisDate(new Date(1234567L));
BatchComponentCache resourceCache = new BatchComponentCache();
sampleFile = org.sonar.api.resources.File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php");
- resourceCache.add(p, null).setSnapshot(new Snapshot().setId(2));
+ resourceCache.add(p, null);
resourceCache.add(sampleFile, null);
measureCache = mock(MeasureCache.class);
when(measureCache.byResource(any(Resource.class))).thenReturn(Collections.<Measure>emptyList());
diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/MetadataPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/MetadataPublisherTest.java
index 23f9860660a..7e67177a5ec 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/report/MetadataPublisherTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/report/MetadataPublisherTest.java
@@ -31,7 +31,6 @@ import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.rule.internal.DefaultActiveRules;
import org.sonar.api.batch.rule.internal.NewActiveRule;
-import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Project;
import org.sonar.batch.index.BatchComponentCache;
import org.sonar.batch.protocol.output.BatchReport;
@@ -58,7 +57,7 @@ public class MetadataPublisherTest {
project = new Project("foo").setAnalysisDate(new Date(1234567L));
BatchComponentCache componentCache = new BatchComponentCache();
org.sonar.api.resources.Resource sampleFile = org.sonar.api.resources.File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php");
- componentCache.add(project, null).setSnapshot(new Snapshot().setId(2));
+ componentCache.add(project, null);
componentCache.add(sampleFile, project);
underTest = new MetadataPublisher(componentCache, new ImmutableProjectReactor(projectDef), activeRules);
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java
index 0125a4bb5ba..83f58a78afe 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java
@@ -19,23 +19,21 @@
*/
package org.sonar.batch.report;
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Date;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Qualifiers;
import org.sonar.batch.index.BatchComponentCache;
import org.sonar.batch.protocol.output.BatchReportWriter;
-import java.io.File;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-
import static org.assertj.core.api.Assertions.assertThat;
public class SourcePublisherTest {
@@ -57,7 +55,7 @@ public class SourcePublisherTest {
BatchComponentCache resourceCache = new BatchComponentCache();
sampleFile = org.sonar.api.resources.File.create("src/Foo.php");
sampleFile.setEffectiveKey("foo:src/Foo.php");
- resourceCache.add(p, null).setSnapshot(new Snapshot().setId(2));
+ resourceCache.add(p, null);
File baseDir = temp.newFolder();
sourceFile = new File(baseDir, "src/Foo.php");
resourceCache.add(sampleFile, null).setInputPath(