aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-10-04 14:42:30 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-10-04 15:16:53 +0200
commit61efd4090dbbb72060c26e3b89c162cc622e2c80 (patch)
tree41b1e0c26e98d2535dcb981f50c9d7f275f9c110 /sonar-batch
parent194e962f659f8949496b510d8ed0988c34c374f1 (diff)
downloadsonarqube-61efd4090dbbb72060c26e3b89c162cc622e2c80.tar.gz
sonarqube-61efd4090dbbb72060c26e3b89c162cc622e2c80.zip
SONAR-2602 the extensions Language must not be declared with InstantiationStrategy=PER_BATCH
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java3
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java12
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/ProjectInitializer.java (renamed from sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectInitializer.java)16
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/DefaultProfileLoaderTest.java10
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java9
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java28
8 files changed, 51 insertions, 35 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java
index 645907de581..b598f81a9ad 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java
@@ -22,7 +22,6 @@ package org.sonar.batch.bootstrap;
import org.sonar.api.Plugins;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Metric;
-import org.sonar.api.resources.Languages;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.ResourceTypes;
import org.sonar.batch.DefaultFileLinesContextFactory;
@@ -84,7 +83,6 @@ public class BatchModule extends Module {
addCoreSingleton(DefaultNotificationManager.class);
addCoreSingleton(DefaultUserFinder.class);
addCoreSingleton(ResourceTypes.class);
- addCoreSingleton(Languages.class);
addCoreMetrics();
addBatchExtensions();
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java
index 9b4cf76d9e1..02cb458c473 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java
@@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory;
import org.sonar.api.batch.BatchExtensionDictionnary;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.profiles.RulesProfile;
+import org.sonar.api.resources.Languages;
import org.sonar.api.resources.Project;
import org.sonar.api.utils.IocContainer;
import org.sonar.batch.*;
@@ -63,7 +64,6 @@ public class ProjectModule extends Module {
addCoreSingleton(projectDefinition);
addCoreSingleton(project);
addCoreSingleton(project.getConfiguration());
- addCoreSingleton(ProjectInitializer.class);
addCoreSingleton(ProjectSettings.class);
addCoreSingleton(UnsupportedProperties.class);
addCoreSingleton(IocContainer.class);
@@ -71,6 +71,7 @@ public class ProjectModule extends Module {
for (Object component : projectDefinition.getContainerExtensions()) {
addCoreSingleton(component);
}
+ addCoreSingleton(Languages.class);
addCoreSingleton(DefaultProjectClasspath.class);
addCoreSingleton(DefaultProjectFileSystem2.class);
addCoreSingleton(RulesDao.class);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java b/sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java
index 09496102faf..d470a9cdb02 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java
@@ -27,7 +27,6 @@ import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Project;
-import org.sonar.batch.bootstrap.ProjectInitializer;
import org.sonar.core.config.ConfigurationUtils;
import org.sonar.core.properties.PropertiesDao;
import org.sonar.core.properties.PropertyDto;
@@ -43,15 +42,12 @@ public class ProjectSettings extends Settings {
private ProjectDefinition projectDefinition;
private PropertiesDao propertiesDao;
- public ProjectSettings(PropertyDefinitions definitions, ProjectDefinition projectDefinition, PropertiesDao propertiesDao, Project project, ProjectInitializer initializer) {
+ public ProjectSettings(PropertyDefinitions definitions, ProjectDefinition projectDefinition, PropertiesDao propertiesDao, Project project) {
super(definitions);
this.deprecatedCommonsConf = project.getConfiguration(); // Configuration is not a parameter to be sure that the project conf is used, not the global one
this.projectDefinition = projectDefinition;
this.propertiesDao = propertiesDao;
load();
-
- // TODO should be refactored in a clean way
- initializer.execute(project, this);
}
public ProjectSettings load() {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java b/sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java
index 767b43cffbe..e57e8e3fd80 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java
@@ -22,6 +22,7 @@ package org.sonar.batch.phases;
import com.google.common.collect.Lists;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.resources.Project;
+import org.sonar.batch.phases.ProjectInitializer;
import org.sonar.batch.events.EventBus;
import org.sonar.batch.index.DefaultIndex;
import org.sonar.batch.index.PersistenceManager;
@@ -34,7 +35,7 @@ public final class Phases {
public static Collection<Class> getPhaseClasses(boolean dryRun) {
List<Class> classes = Lists.<Class>newArrayList(DecoratorsExecutor.class, MavenPhaseExecutor.class, MavenPluginsConfigurator.class,
PostJobsExecutor.class, SensorsExecutor.class,
- InitializersExecutor.class);
+ InitializersExecutor.class, ProjectInitializer.class);
if (!dryRun) {
classes.add(UpdateStatusJob.class);
}
@@ -52,12 +53,13 @@ public final class Phases {
private PersistenceManager persistenceManager;
private SensorContext sensorContext;
private DefaultIndex index;
+ private ProjectInitializer pi;
public Phases(DecoratorsExecutor decoratorsExecutor, MavenPhaseExecutor mavenPhaseExecutor,
MavenPluginsConfigurator mavenPluginsConfigurator, InitializersExecutor initializersExecutor,
PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor,
PersistenceManager persistenceManager, SensorContext sensorContext, DefaultIndex index,
- EventBus eventBus, UpdateStatusJob updateStatusJob) {
+ EventBus eventBus, UpdateStatusJob updateStatusJob, ProjectInitializer pi) {
this.decoratorsExecutor = decoratorsExecutor;
this.mavenPhaseExecutor = mavenPhaseExecutor;
this.mavenPluginsConfigurator = mavenPluginsConfigurator;
@@ -69,21 +71,23 @@ public final class Phases {
this.index = index;
this.eventBus = eventBus;
this.updateStatusJob = updateStatusJob;
+ this.pi = pi;
}
public Phases(DecoratorsExecutor decoratorsExecutor, MavenPhaseExecutor mavenPhaseExecutor,
MavenPluginsConfigurator mavenPluginsConfigurator, InitializersExecutor initializersExecutor,
PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor,
PersistenceManager persistenceManager, SensorContext sensorContext, DefaultIndex index,
- EventBus eventBus) {
+ EventBus eventBus, ProjectInitializer pi) {
this(decoratorsExecutor, mavenPhaseExecutor, mavenPluginsConfigurator, initializersExecutor, postJobsExecutor,
- sensorsExecutor, persistenceManager, sensorContext, index, eventBus, null);
+ sensorsExecutor, persistenceManager, sensorContext, index, eventBus, null, pi);
}
/**
* Executed on each module
*/
public void execute(Project project) {
+ pi.execute(project);
eventBus.fireEvent(new ProjectAnalysisEvent(project, true));
mavenPluginsConfigurator.execute(project);
mavenPhaseExecutor.execute(project);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectInitializer.java b/sonar-batch/src/main/java/org/sonar/batch/phases/ProjectInitializer.java
index f20751864cb..7e5cabb7afc 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectInitializer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/ProjectInitializer.java
@@ -17,13 +17,14 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.batch.bootstrap;
+package org.sonar.batch.phases;
-import org.apache.commons.lang.StringUtils;
import org.sonar.api.BatchComponent;
-import org.sonar.api.resources.*;
+import org.sonar.api.resources.Language;
+import org.sonar.api.resources.Languages;
+import org.sonar.api.resources.Project;
import org.sonar.api.utils.SonarException;
-import org.sonar.batch.config.ProjectSettings;
+import org.sonar.batch.bootstrap.DryRun;
import org.sonar.core.resource.ResourceDao;
import org.sonar.core.resource.ResourceDto;
@@ -42,12 +43,11 @@ public class ProjectInitializer implements BatchComponent {
this.languages = languages;
}
- public void execute(Project project, ProjectSettings settings) {
- initLanguage(project, settings);
+ public void execute(Project project) {
+ initLanguage(project);
}
- private void initLanguage(Project project, ProjectSettings settings) {
- project.setLanguageKey(StringUtils.defaultIfBlank(settings.getString("sonar.language"), Java.KEY));
+ private void initLanguage(Project project) {
Language language = languages.get(project.getLanguageKey());
if (language == null) {
throw new SonarException("Language with key '" + project.getLanguageKey() + "' not found");
diff --git a/sonar-batch/src/test/java/org/sonar/batch/DefaultProfileLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/DefaultProfileLoaderTest.java
index fcf5c004ea7..410e8032ac7 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/DefaultProfileLoaderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/DefaultProfileLoaderTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.batch;
+import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -40,7 +41,7 @@ public class DefaultProfileLoaderTest {
public ExpectedException thrown = ExpectedException.none();
private ProfilesDao dao;
- private Project javaProject = new Project("project").setLanguageKey(Java.KEY);
+ private Project javaProject = newProject(Java.KEY);
@Before
public void setUp() {
@@ -73,11 +74,16 @@ public class DefaultProfileLoaderTest {
*/
@Test
public void should_give_explicit_message_if_default_profile_not_found() {
- Project cobolProject = new Project("cobol-javaProject").setLanguageKey("cobol");
+ Project cobolProject = newProject("cobol");
thrown.expect(SonarException.class);
thrown.expectMessage("You must install a plugin that supports the language 'cobol'");
new DefaultProfileLoader(dao, new Settings()).load(cobolProject);
}
+ private Project newProject(String language) {
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ configuration.setProperty("sonar.language", language);
+ return new Project("project").setConfiguration(configuration);
+ }
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java
index 374dc7e8f92..5690e949b4b 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java
@@ -21,6 +21,7 @@ package org.sonar.batch.bootstrap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
+import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.maven.project.MavenProject;
import org.junit.Test;
import org.sonar.api.BatchExtension;
@@ -101,12 +102,16 @@ public class ProjectExtensionInstallerTest {
}
private static Project newJavaProject() {
- Project project = new Project("foo").setLanguageKey(Java.KEY).setAnalysisType(Project.AnalysisType.DYNAMIC);
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ configuration.setProperty("sonar.language", Java.KEY);
+ Project project = new Project("foo").setConfiguration(configuration).setAnalysisType(Project.AnalysisType.DYNAMIC);
return project;
}
private static Project newGroovyProject() {
- return new Project("foo").setLanguageKey("grvy").setAnalysisType(Project.AnalysisType.DYNAMIC);
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ configuration.setProperty("sonar.language", "grvy");
+ return new Project("foo").setConfiguration(configuration).setAnalysisType(Project.AnalysisType.DYNAMIC);
}
@Test
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java
index 75f86585fed..21cd76173d4 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.batch.index;
+import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.database.model.ResourceModel;
@@ -43,22 +44,22 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
@Before
public void before() throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
- singleProject = new Project("foo");
- singleProject.setName("Foo").setDescription("some description").setLanguageKey("java").setAnalysisDate(format.parse("25/12/2010"));
+ singleProject = newProject("foo", "java");
+ singleProject.setName("Foo").setDescription("some description").setAnalysisDate(format.parse("25/12/2010"));
- multiModuleProject = new Project("root");
- multiModuleProject.setName("Root").setLanguageKey("java").setAnalysisDate(format.parse("25/12/2010"));
+ multiModuleProject = newProject("root", "java");
+ multiModuleProject.setName("Root").setAnalysisDate(format.parse("25/12/2010"));
- moduleA = new Project("a");
- moduleA.setName("A").setLanguageKey("java").setAnalysisDate(format.parse("25/12/2010"));
+ moduleA = newProject("a", "java");
+ moduleA.setName("A").setAnalysisDate(format.parse("25/12/2010"));
moduleA.setParent(multiModuleProject);
- moduleB = new Project("b");
- moduleB.setName("B").setLanguageKey("java").setAnalysisDate(format.parse("25/12/2010"));
+ moduleB = newProject("b", "java");
+ moduleB.setName("B").setAnalysisDate(format.parse("25/12/2010"));
moduleB.setParent(multiModuleProject);
- moduleB1 = new Project("b1");
- moduleB1.setName("B1").setLanguageKey("java").setAnalysisDate(format.parse("25/12/2010"));
+ moduleB1 = newProject("b1", "java");
+ moduleB1.setName("B1").setAnalysisDate(format.parse("25/12/2010"));
moduleB1.setParent(moduleB);
}
@@ -100,7 +101,6 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
// check that the directory is attached to the project
checkTables("shouldSaveNewDirectory", new String[] {"build_date", "created_at"}, "projects", "snapshots");
}
-
@Test
public void shouldSaveNewLibrary() {
setupData("shared");
@@ -153,4 +153,10 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
checkTables("shouldRemoveRootIndexIfResourceIsProject", new String[] {"build_date", "created_at"}, "projects", "snapshots");
}
+ private static Project newProject(String key, String language) {
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ configuration.setProperty("sonar.language", language);
+ return new Project(key).setConfiguration(configuration).setAnalysisType(Project.AnalysisType.DYNAMIC);
+ }
+
}