diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-09-28 11:23:39 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-09-28 11:24:33 +0200 |
commit | 67f0a5eb565ecefbcd5d0ed836012bbb61196bea (patch) | |
tree | 174a62f624bfa3ce3df64a2c472541954ebab4b0 /sonar-batch | |
parent | 8cd5a9d5523f1efa5f0ff3cfa6d196590f856845 (diff) | |
download | sonarqube-67f0a5eb565ecefbcd5d0ed836012bbb61196bea.tar.gz sonarqube-67f0a5eb565ecefbcd5d0ed836012bbb61196bea.zip |
SONAR-2602 persist project language before execution of extensions
Diffstat (limited to 'sonar-batch')
4 files changed, 80 insertions, 22 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 b598f81a9ad..645907de581 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,6 +22,7 @@ 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; @@ -83,6 +84,7 @@ 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/ProjectInitializer.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectInitializer.java new file mode 100644 index 00000000000..f6ee4c48af9 --- /dev/null +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectInitializer.java @@ -0,0 +1,73 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.batch.bootstrap; + +import org.apache.commons.lang.StringUtils; +import org.sonar.api.BatchComponent; +import org.sonar.api.resources.*; +import org.sonar.api.utils.SonarException; +import org.sonar.batch.config.ProjectSettings; +import org.sonar.core.resource.ResourceDao; +import org.sonar.core.resource.ResourceDto; + +/** + * Should be dropped when org.sonar.api.resources.Project is fully refactored. + */ +public class ProjectInitializer implements BatchComponent { + + private ResourceDao resourceDao; + private DryRun dryRun; + private ProjectFileSystem fileSystem; + private Languages languages; + + public ProjectInitializer(ResourceDao resourceDao, DryRun dryRun, ProjectFileSystem fileSystem, Languages languages) { + this.resourceDao = resourceDao; + this.dryRun = dryRun; + this.fileSystem = fileSystem; + this.languages = languages; + } + + public void execute(Project project, ProjectSettings settings) { + initLanguage(project, settings); + initFileSystem(project); + } + + private void initLanguage(Project project, ProjectSettings settings) { + project.setLanguageKey(StringUtils.defaultIfBlank(settings.getString("sonar.language"), Java.KEY)); + Language language = languages.get(project.getLanguageKey()); + if (language == null) { + throw new SonarException("Language with key '" + project.getLanguageKey() + "' not found"); + } + project.setLanguage(language); + if (!dryRun.isEnabled() && project.getId() != null) { + ResourceDto dto = resourceDao.getResource(project.getId()); + dto.setLanguage(project.getLanguageKey()); + resourceDao.insertOrUpdate(dto); + } + + } + + private void initFileSystem(Project project) { + // TODO See http://jira.codehaus.org/browse/SONAR-2126 + // previously MavenProjectBuilder was responsible for creation of ProjectFileSystem + project.setFileSystem(fileSystem); + + } +} 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 390bba94cf5..09cc6ce69f7 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,12 +24,8 @@ 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.Language; -import org.sonar.api.resources.Languages; import org.sonar.api.resources.Project; -import org.sonar.api.resources.ProjectFileSystem; import org.sonar.api.utils.IocContainer; -import org.sonar.api.utils.SonarException; import org.sonar.batch.*; import org.sonar.batch.components.TimeMachineConfiguration; import org.sonar.batch.config.ProjectSettings; @@ -66,6 +62,7 @@ public class ProjectModule extends Module { addCoreSingleton(projectDefinition); addCoreSingleton(project); addCoreSingleton(project.getConfiguration()); + addCoreSingleton(ProjectInitializer.class); addCoreSingleton(ProjectSettings.class); addCoreSingleton(IocContainer.class); @@ -84,7 +81,6 @@ public class ProjectModule extends Module { addCoreSingleton(org.sonar.api.database.daos.MeasuresDao.class); addCoreSingleton(ProfilesDao.class); addCoreSingleton(DefaultSensorContext.class); - addCoreSingleton(Languages.class); addCoreSingleton(BatchExtensionDictionnary.class); addCoreSingleton(DefaultTimeMachine.class); addCoreSingleton(ViolationFilters.class); @@ -120,22 +116,12 @@ public class ProjectModule extends Module { */ @Override protected void doStart() { - Language language = getComponentByType(Languages.class).get(project.getLanguageKey()); - if (language == null) { - throw new SonarException("Language with key '" + project.getLanguageKey() + "' not found"); - } - project.setLanguage(language); - DefaultIndex index = getComponentByType(DefaultIndex.class); index.setCurrentProject(project, getComponentByType(ResourceFilters.class), getComponentByType(ViolationFilters.class), getComponentByType(RulesProfile.class)); - // TODO See http://jira.codehaus.org/browse/SONAR-2126 - // previously MavenProjectBuilder was responsible for creation of ProjectFileSystem - project.setFileSystem(getComponentByType(ProjectFileSystem.class)); - getComponentByType(Phases.class).execute(project); } } 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 aca22d363f4..95822bcb32a 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 @@ -28,6 +28,7 @@ import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.config.Settings; import org.sonar.api.resources.Java; 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,19 +44,15 @@ public class ProjectSettings extends Settings { private ProjectDefinition projectDefinition; private PropertiesDao propertiesDao; - public ProjectSettings(PropertyDefinitions definitions, ProjectDefinition projectDefinition, PropertiesDao propertiesDao, Project project) { + public ProjectSettings(PropertyDefinitions definitions, ProjectDefinition projectDefinition, PropertiesDao propertiesDao, Project project, ProjectInitializer initializer) { 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(); - updateProject(project); - } - private void updateProject(Project project) { - // The class org.sonar.api.batch.Project should be deeply refactored and should load language from settings. - // Meanwhile the language must be updated : - project.setLanguageKey(StringUtils.defaultIfBlank(getString("sonar.language"), Java.KEY)); + // TODO should be refactored in a clean way + initializer.execute(project, this); } public ProjectSettings load() { |