]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2602 the extensions Language must not be declared with InstantiationStrategy...
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 4 Oct 2012 12:42:30 +0000 (14:42 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 4 Oct 2012 13:16:53 +0000 (15:16 +0200)
15 files changed:
plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/CpdSensorTest.java
plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/SonarBridgeEngineTest.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectInitializer.java [deleted file]
sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectModule.java
sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java
sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java
sonar-batch/src/main/java/org/sonar/batch/phases/ProjectInitializer.java [new file with mode: 0644]
sonar-batch/src/test/java/org/sonar/batch/DefaultProfileLoaderTest.java
sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java
sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java
sonar-plugin-api/src/main/java/org/sonar/api/resources/AbstractLanguage.java
sonar-plugin-api/src/main/java/org/sonar/api/resources/Language.java
sonar-plugin-api/src/main/java/org/sonar/api/resources/Languages.java
sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java

index 66e946c6d4914c5f3a660e7ffe215ea821ef20ea..d49dd75daf213ce5d54c09c0091cb012e18cc282 100644 (file)
@@ -65,16 +65,18 @@ public class CpdSensorTest {
   }
 
   @Test
-  public void skipByLanguage() {
-    PropertiesConfiguration conf = new PropertiesConfiguration();
-    conf.setProperty("sonar.cpd.skip", "false");
-    conf.setProperty("sonar.cpd.php.skip", "true");
-
-    Project phpProject = createPhpProject().setConfiguration(conf);
-    Project javaProject = createJavaProject().setConfiguration(conf);
+  public void shouldSkipByLanguage() {
 
+    Project phpProject = createPhpProject();
+    phpProject.getConfiguration().setProperty("sonar.cpd.skip", "false");
+    phpProject.getConfiguration().setProperty("sonar.cpd.php.skip", "true");
     assertTrue(sensor.isSkipped(phpProject));
+
+    Project javaProject = createJavaProject();
+    javaProject.getConfiguration().setProperty("sonar.cpd.skip", "false");
+    javaProject.getConfiguration().setProperty("sonar.cpd.php.skip", "true");
     assertFalse(sensor.isSkipped(javaProject));
+
   }
 
   @Test
@@ -87,12 +89,16 @@ public class CpdSensorTest {
   }
 
   private Project createJavaProject() {
-    return new Project("java_project").setLanguageKey("java").setLanguage(Java.INSTANCE);
+    PropertiesConfiguration conf = new PropertiesConfiguration();
+    conf.setProperty("sonar.language", "java");
+    return new Project("java_project").setConfiguration(conf).setLanguage(Java.INSTANCE);
   }
 
   private Project createPhpProject() {
+    PropertiesConfiguration conf = new PropertiesConfiguration();
+    conf.setProperty("sonar.language", "php");
     Language phpLanguage = mock(Language.class);
-    return new Project("php_project").setLanguageKey("php").setLanguage(phpLanguage);
+    return new Project("php_project").setConfiguration(conf).setLanguage(phpLanguage);
   }
 
 }
index b036804b74e41d07d2111e0ad6b52011ffa9ed73..c36facc230ab6d26bcb40502752ae04634c0f517 100644 (file)
@@ -39,31 +39,35 @@ public class SonarBridgeEngineTest {
 
   @Test
   public void defaultMinimumTokens() {
-    Project project = new Project("foo").setConfiguration(new PropertiesConfiguration());
+    Project project = newProject("foo", "java");
 
     assertThat(SonarBridgeEngine.getMinimumTokens(project), is(CoreProperties.CPD_MINIMUM_TOKENS_DEFAULT_VALUE));
   }
 
   @Test
   public void generalMinimumTokens() {
-    PropertiesConfiguration conf = new PropertiesConfiguration();
-    conf.setProperty("sonar.cpd.minimumTokens", "33");
-    Project project = new Project("foo").setConfiguration(conf);
+    Project project = newProject("foo", "java");
+    project.getConfiguration().setProperty("sonar.cpd.minimumTokens", "33");
 
     assertThat(SonarBridgeEngine.getMinimumTokens(project), is(33));
   }
 
   @Test
   public void minimumTokensByLanguage() {
-    PropertiesConfiguration conf = new PropertiesConfiguration();
-    conf.setProperty("sonar.cpd.java.minimumTokens", "42");
-    conf.setProperty("sonar.cpd.php.minimumTokens", "33");
-
-    Project javaProject = new Project("foo").setLanguageKey("java").setConfiguration(conf);
-    Project phpProject = new Project("foo").setLanguageKey("php").setConfiguration(conf);
-
+    Project javaProject = newProject("foo", "java");
+    javaProject.getConfiguration().setProperty("sonar.cpd.java.minimumTokens", "42");
+    javaProject.getConfiguration().setProperty("sonar.cpd.php.minimumTokens", "33");
     assertThat(SonarBridgeEngine.getMinimumTokens(javaProject), is(42));
+
+    Project phpProject = newProject("foo", "php");
+    phpProject.getConfiguration().setProperty("sonar.cpd.java.minimumTokens", "42");
+    phpProject.getConfiguration().setProperty("sonar.cpd.php.minimumTokens", "33");
     assertThat(SonarBridgeEngine.getMinimumTokens(phpProject), is(33));
   }
 
+  private static Project newProject(String key, String language) {
+    PropertiesConfiguration conf = new PropertiesConfiguration();
+    conf.setProperty("sonar.language", language);
+    return new Project(key).setConfiguration(conf).setAnalysisType(Project.AnalysisType.DYNAMIC);
+  }
 }
index 645907de5812ed5c983af8e662519768088f4859..b598f81a9ad1ee1f26bfe019c1e5987911a6b038 100644 (file)
@@ -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/ProjectInitializer.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectInitializer.java
deleted file mode 100644 (file)
index f207518..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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 Languages languages;
-
-  public ProjectInitializer(ResourceDao resourceDao, DryRun dryRun, Languages languages) {
-    this.resourceDao = resourceDao;
-    this.dryRun = dryRun;
-    this.languages = languages;
-  }
-
-  public void execute(Project project, ProjectSettings settings) {
-    initLanguage(project, settings);
-  }
-
-  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);
-    }
-
-  }
-}
index 9b4cf76d9e1d4fe673b1444c836fe6165e5ecfb2..02cb458c4734436444b3fe25e5a33ff59c8a3ad9 100644 (file)
@@ -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);
index 09496102faff5253ed9925194b2c80c8e3bf3d11..d470a9cdb02135dd0777f836dd69440891067d08 100644 (file)
@@ -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() {
index 767b43cffbe6159e54cc3789d0de9cad1663f3d5..e57e8e3fd8021150074ed800eabf77b5ad56712a 100644 (file)
@@ -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/phases/ProjectInitializer.java b/sonar-batch/src/main/java/org/sonar/batch/phases/ProjectInitializer.java
new file mode 100644 (file)
index 0000000..7e5cabb
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * 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.phases;
+
+import org.sonar.api.BatchComponent;
+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.bootstrap.DryRun;
+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 Languages languages;
+
+  public ProjectInitializer(ResourceDao resourceDao, DryRun dryRun, Languages languages) {
+    this.resourceDao = resourceDao;
+    this.dryRun = dryRun;
+    this.languages = languages;
+  }
+
+  public void execute(Project project) {
+    initLanguage(project);
+  }
+
+  private void initLanguage(Project project) {
+    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);
+    }
+
+  }
+}
index fcf5c004ea7bd2aae4a967d9a05a60d50f87ae88..410e8032ac7e773b075e375bf2cc3a09624655e6 100644 (file)
@@ -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);
+  }
 }
index 374dc7e8f9269ceb4e83dd4c60a9ef173867a7c1..5690e949b4bdc4844bb3a1a376744915995ff5f2 100644 (file)
@@ -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
index 75f86585fed8c34c8f9b7da3dc45a14a4265bd89..21cd76173d4148e945151faa6708385f557b20d4 100644 (file)
@@ -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);
+  }
+
 }
index 267e945a2845152672ad717bf90303357358a07c..e23da992fa57c7977e59cb3e0a016ccd13b1f2f1 100644 (file)
@@ -48,7 +48,7 @@ public abstract class AbstractLanguage implements Language {
    * @param name the display name of the language in the interface
    */
   public AbstractLanguage(String key, String name) {
-    Preconditions.checkArgument(key.length() < 21, "The following language key exceeds 20 characters: '" + key + "'");
+    Preconditions.checkArgument(key.length() <= 20, "The following language key exceeds 20 characters: '" + key + "'");
     this.key = key.toLowerCase(Locale.ENGLISH);
     this.name = name;
   }
index 5544ee479cffe7da0300802f4934146db43cd413..6aee345fe1f3d8e4d1bc2b812aefd632064d7acf 100644 (file)
@@ -21,14 +21,12 @@ package org.sonar.api.resources;
 
 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 {
 
   /**
index 01fbc5ddedc945d898242cae2b863ac6d6f457e6..920cbc6b27bc7b2faba2ef4715ec38eff3abe482 100644 (file)
@@ -35,7 +35,6 @@ import org.sonar.api.batch.InstantiationStrategy;
  * 
  * @since 1.10
  */
-@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
 public class Languages implements BatchComponent, ServerComponent {
 
   private final Map<String, Language> map = Maps.newHashMap();
index 7edac70d88d5411989138b94c6d76f3a6af8081b..fc39d34827d364399025f252ac8752c9675bf08c 100644 (file)
@@ -98,7 +98,6 @@ public class Project extends Resource {
   private String description;
   private String packaging;
   private Language language;
-  private String languageKey;
   private Date analysisDate;
   private AnalysisType analysisType;
   private String analysisVersion;
@@ -260,15 +259,7 @@ public class Project extends Resource {
    * @return the language key
    */
   public String getLanguageKey() {
-    return languageKey;
-  }
-
-  /**
-   * For internal use only.
-   */
-  public Project setLanguageKey(String languageKey) {
-    this.languageKey = languageKey;
-    return this;
+    return configuration.getString("sonar.language", Java.KEY);
   }
 
   /**