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;
addCoreSingleton(DefaultNotificationManager.class);
addCoreSingleton(DefaultUserFinder.class);
addCoreSingleton(ResourceTypes.class);
+ addCoreSingleton(Languages.class);
addCoreMetrics();
addBatchExtensions();
}
--- /dev/null
+/*
+ * 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);
+
+ }
+}
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;
addCoreSingleton(projectDefinition);
addCoreSingleton(project);
addCoreSingleton(project.getConfiguration());
+ addCoreSingleton(ProjectInitializer.class);
addCoreSingleton(ProjectSettings.class);
addCoreSingleton(IocContainer.class);
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);
*/
@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);
}
}
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;
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() {
}
ResourceModel other = (ResourceModel) obj;
return new EqualsBuilder()
- .append(key, other.key)
- .append(enabled, other.enabled)
- .append(rootId, other.rootId)
- .isEquals();
+ .append(key, other.key)
+ .append(enabled, other.enabled)
+ .append(rootId, other.rootId)
+ .isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
- .append(key)
- .append(enabled)
- .append(rootId)
- .toHashCode();
+ .append(key)
+ .append(enabled)
+ .append(rootId)
+ .toHashCode();
}
@Override
public String toString() {
return new ToStringBuilder(this)
- .append("id", getId())
- .append("key", key)
- .append("scope", scope)
- .append("qualifier", qualifier)
- .append("name", name)
- .append("longName", longName)
- .append("lang", languageKey)
- .append("enabled", enabled)
- .append("rootId", rootId)
- .append("copyResourceId", copyResourceId)
- .append("personId", personId)
- .append("createdAt", createdAt)
- .toString();
+ .append("id", getId())
+ .append("key", key)
+ .append("scope", scope)
+ .append("qualifier", qualifier)
+ .append("name", name)
+ .append("longName", longName)
+ .append("lang", languageKey)
+ .append("enabled", enabled)
+ .append("rootId", rootId)
+ .append("copyResourceId", copyResourceId)
+ .append("personId", personId)
+ .append("createdAt", createdAt)
+ .toString();
}
@Override
import org.sonar.api.BatchExtension;
import org.sonar.api.ServerExtension;
+import org.sonar.api.batch.InstantiationStrategy;
/**
* The extension point to define a new language
*
* @since 1.10
*/
+@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
public interface Language extends BatchExtension, ServerExtension {
/**
import org.apache.commons.lang.ArrayUtils;
import org.sonar.api.BatchComponent;
import org.sonar.api.ServerComponent;
+import org.sonar.api.batch.InstantiationStrategy;
/**
* A class to store the list of languages
*
* @since 1.10
*/
+@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
public class Languages implements BatchComponent, ServerComponent {
private final Map<String, Language> map = Maps.newHashMap();