]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2298 Rename MavenProjectBuilder to ProjectBuilder
authorEvgeny Mandrikov <mandrikov@gmail.com>
Tue, 26 Apr 2011 19:48:49 +0000 (23:48 +0400)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Tue, 26 Apr 2011 19:48:49 +0000 (23:48 +0400)
14 files changed:
sonar-batch/src/main/java/org/sonar/batch/MavenProjectBuilder.java [deleted file]
sonar-batch/src/main/java/org/sonar/batch/ProjectBuilder.java [new file with mode: 0644]
sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java
sonar-batch/src/test/java/org/sonar/batch/MavenProjectBuilderTest.java [deleted file]
sonar-batch/src/test/java/org/sonar/batch/ProjectBuilderTest.java [new file with mode: 0644]
sonar-batch/src/test/java/org/sonar/batch/ProjectTreeTest.java
sonar-batch/src/test/resources/org/sonar/batch/MavenProjectBuilderTest/MavenPluginsConfiguratorTest/pom.xml [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/MavenProjectBuilderTest/isLatestAnalysis.xml [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/MavenProjectBuilderTest/isLatestAnalysisIfNeverAnalysed.xml [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/MavenProjectBuilderTest/isNotLatestAnalysis.xml [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/ProjectBuilderTest/MavenPluginsConfiguratorTest/pom.xml [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/ProjectBuilderTest/isLatestAnalysis.xml [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/ProjectBuilderTest/isLatestAnalysisIfNeverAnalysed.xml [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/ProjectBuilderTest/isNotLatestAnalysis.xml [new file with mode: 0644]

diff --git a/sonar-batch/src/main/java/org/sonar/batch/MavenProjectBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/MavenProjectBuilder.java
deleted file mode 100644 (file)
index 48bc417..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 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;
-
-import org.apache.commons.configuration.*;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.time.DateUtils;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.ResourceModel;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.Java;
-import org.sonar.api.resources.Project;
-import org.sonar.api.utils.SonarException;
-import org.sonar.batch.bootstrapper.ProjectDefinition;
-
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-// TODO Godin: rename to ProjectBuilder ?
-public class MavenProjectBuilder {
-
-  private DatabaseSession databaseSession;
-
-  public MavenProjectBuilder(DatabaseSession databaseSession) {
-    this.databaseSession = databaseSession;
-  }
-
-  public Project create(ProjectDefinition project) {
-    Configuration configuration = getStartupConfiguration(project);
-    return new Project(loadProjectKey(project), loadProjectBranch(configuration), loadProjectName(project))
-        .setDescription(project.getProperties().getProperty(CoreProperties.PROJECT_DESCRIPTION_PROPERTY))
-        .setPackaging("jar"); // FIXME http://jira.codehaus.org/browse/SONAR-2341
-  }
-
-  Configuration getStartupConfiguration(ProjectDefinition project) {
-    CompositeConfiguration configuration = new CompositeConfiguration();
-    configuration.addConfiguration(new SystemConfiguration());
-    configuration.addConfiguration(new EnvironmentConfiguration());
-    configuration.addConfiguration(new MapConfiguration(project.getProperties()));
-    return configuration;
-  }
-
-  private String getPropertyOrDie(ProjectDefinition project, String key) {
-    String value = project.getProperties().getProperty(key);
-    if (StringUtils.isBlank(value)) {
-      throw new SonarException("Property '" + key + "' must be specified");
-    }
-    return value;
-  }
-
-  String loadProjectKey(ProjectDefinition projectDefinition) {
-    return getPropertyOrDie(projectDefinition, CoreProperties.PROJECT_KEY_PROPERTY);
-  }
-
-  String loadProjectName(ProjectDefinition projectDefinition) {
-    return projectDefinition.getProperties().getProperty(
-        CoreProperties.PROJECT_NAME_PROPERTY,
-        "Unnamed - " + loadProjectKey(projectDefinition));
-  }
-
-  String loadProjectBranch(Configuration configuration) {
-    return configuration.getString(CoreProperties.PROJECT_BRANCH_PROPERTY, configuration.getString("branch" /* deprecated property */));
-  }
-
-  public void configure(Project project, ProjectDefinition def) {
-    ProjectConfiguration projectConfiguration = new ProjectConfiguration(databaseSession, project, def.getProperties());
-    configure(project, projectConfiguration);
-  }
-
-  void configure(Project project, Configuration projectConfiguration) {
-    Date analysisDate = loadAnalysisDate(projectConfiguration);
-    project.setConfiguration(projectConfiguration)
-        .setExclusionPatterns(loadExclusionPatterns(projectConfiguration))
-        .setAnalysisDate(analysisDate)
-        .setLatestAnalysis(isLatestAnalysis(project.getKey(), analysisDate))
-        .setAnalysisVersion(loadAnalysisVersion(projectConfiguration))
-        .setAnalysisType(loadAnalysisType(projectConfiguration))
-        .setLanguageKey(loadLanguageKey(projectConfiguration));
-  }
-
-  static String[] loadExclusionPatterns(Configuration configuration) {
-    String[] exclusionPatterns = configuration.getStringArray(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY);
-    if (exclusionPatterns == null) {
-      exclusionPatterns = new String[0];
-    }
-    return exclusionPatterns;
-  }
-
-  boolean isLatestAnalysis(String projectKey, Date analysisDate) {
-    ResourceModel persistedProject = databaseSession.getSingleResult(ResourceModel.class, "key", projectKey, "enabled", true);
-    if (persistedProject != null) {
-      Snapshot lastSnapshot = databaseSession.getSingleResult(Snapshot.class, "resourceId", persistedProject.getId(), "last", true);
-      return lastSnapshot == null || lastSnapshot.getCreatedAt().before(analysisDate);
-    }
-    return true;
-  }
-
-  Date loadAnalysisDate(Configuration configuration) {
-    String formattedDate = configuration.getString(CoreProperties.PROJECT_DATE_PROPERTY);
-    if (formattedDate == null) {
-      return new Date();
-    }
-
-    DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
-    try {
-      // see SONAR-908 make sure that a time is defined for the date.
-      Date date = DateUtils.setHours(format.parse(formattedDate), 0);
-      return DateUtils.setMinutes(date, 1);
-
-    } catch (ParseException e) {
-      throw new SonarException("The property " + CoreProperties.PROJECT_DATE_PROPERTY
-          + " does not respect the format yyyy-MM-dd (for example 2008-05-23) : " + formattedDate, e);
-    }
-  }
-
-  Project.AnalysisType loadAnalysisType(Configuration configuration) {
-    String value = configuration.getString(CoreProperties.DYNAMIC_ANALYSIS_PROPERTY);
-    if (value == null) {
-      return (configuration.getBoolean("sonar.light", false) ? Project.AnalysisType.STATIC : Project.AnalysisType.DYNAMIC);
-    }
-    if ("true".equals(value)) {
-      return Project.AnalysisType.DYNAMIC;
-    }
-    if ("reuseReports".equals(value)) {
-      return Project.AnalysisType.REUSE_REPORTS;
-    }
-    return Project.AnalysisType.STATIC;
-  }
-
-  String loadAnalysisVersion(Configuration configuration) {
-    return configuration.getString(CoreProperties.PROJECT_VERSION_PROPERTY);
-  }
-
-  String loadLanguageKey(Configuration configuration) {
-    return configuration.getString(CoreProperties.PROJECT_LANGUAGE_PROPERTY, Java.KEY);
-  }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectBuilder.java
new file mode 100644 (file)
index 0000000..c652ce8
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 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;
+
+import org.apache.commons.configuration.*;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.time.DateUtils;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.database.DatabaseSession;
+import org.sonar.api.database.model.ResourceModel;
+import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.resources.Java;
+import org.sonar.api.resources.Project;
+import org.sonar.api.utils.SonarException;
+import org.sonar.batch.bootstrapper.ProjectDefinition;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class ProjectBuilder {
+
+  private DatabaseSession databaseSession;
+
+  public ProjectBuilder(DatabaseSession databaseSession) {
+    this.databaseSession = databaseSession;
+  }
+
+  public Project create(ProjectDefinition project) {
+    Configuration configuration = getStartupConfiguration(project);
+    return new Project(loadProjectKey(project), loadProjectBranch(configuration), loadProjectName(project))
+        .setDescription(project.getProperties().getProperty(CoreProperties.PROJECT_DESCRIPTION_PROPERTY))
+        .setPackaging("jar");
+  }
+
+  Configuration getStartupConfiguration(ProjectDefinition project) {
+    CompositeConfiguration configuration = new CompositeConfiguration();
+    configuration.addConfiguration(new SystemConfiguration());
+    configuration.addConfiguration(new EnvironmentConfiguration());
+    configuration.addConfiguration(new MapConfiguration(project.getProperties()));
+    return configuration;
+  }
+
+  private String getPropertyOrDie(ProjectDefinition project, String key) {
+    String value = project.getProperties().getProperty(key);
+    if (StringUtils.isBlank(value)) {
+      throw new SonarException("Property '" + key + "' must be specified");
+    }
+    return value;
+  }
+
+  String loadProjectKey(ProjectDefinition projectDefinition) {
+    return getPropertyOrDie(projectDefinition, CoreProperties.PROJECT_KEY_PROPERTY);
+  }
+
+  String loadProjectName(ProjectDefinition projectDefinition) {
+    return projectDefinition.getProperties().getProperty(
+        CoreProperties.PROJECT_NAME_PROPERTY,
+        "Unnamed - " + loadProjectKey(projectDefinition));
+  }
+
+  String loadProjectBranch(Configuration configuration) {
+    return configuration.getString(CoreProperties.PROJECT_BRANCH_PROPERTY, configuration.getString("branch" /* deprecated property */));
+  }
+
+  public void configure(Project project, ProjectDefinition def) {
+    ProjectConfiguration projectConfiguration = new ProjectConfiguration(databaseSession, project, def.getProperties());
+    configure(project, projectConfiguration);
+  }
+
+  void configure(Project project, Configuration projectConfiguration) {
+    Date analysisDate = loadAnalysisDate(projectConfiguration);
+    project.setConfiguration(projectConfiguration)
+        .setExclusionPatterns(loadExclusionPatterns(projectConfiguration))
+        .setAnalysisDate(analysisDate)
+        .setLatestAnalysis(isLatestAnalysis(project.getKey(), analysisDate))
+        .setAnalysisVersion(loadAnalysisVersion(projectConfiguration))
+        .setAnalysisType(loadAnalysisType(projectConfiguration))
+        .setLanguageKey(loadLanguageKey(projectConfiguration));
+  }
+
+  static String[] loadExclusionPatterns(Configuration configuration) {
+    String[] exclusionPatterns = configuration.getStringArray(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY);
+    if (exclusionPatterns == null) {
+      exclusionPatterns = new String[0];
+    }
+    return exclusionPatterns;
+  }
+
+  boolean isLatestAnalysis(String projectKey, Date analysisDate) {
+    ResourceModel persistedProject = databaseSession.getSingleResult(ResourceModel.class, "key", projectKey, "enabled", true);
+    if (persistedProject != null) {
+      Snapshot lastSnapshot = databaseSession.getSingleResult(Snapshot.class, "resourceId", persistedProject.getId(), "last", true);
+      return lastSnapshot == null || lastSnapshot.getCreatedAt().before(analysisDate);
+    }
+    return true;
+  }
+
+  Date loadAnalysisDate(Configuration configuration) {
+    String formattedDate = configuration.getString(CoreProperties.PROJECT_DATE_PROPERTY);
+    if (formattedDate == null) {
+      return new Date();
+    }
+
+    DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+    try {
+      // see SONAR-908 make sure that a time is defined for the date.
+      Date date = DateUtils.setHours(format.parse(formattedDate), 0);
+      return DateUtils.setMinutes(date, 1);
+
+    } catch (ParseException e) {
+      throw new SonarException("The property " + CoreProperties.PROJECT_DATE_PROPERTY
+          + " does not respect the format yyyy-MM-dd (for example 2008-05-23) : " + formattedDate, e);
+    }
+  }
+
+  Project.AnalysisType loadAnalysisType(Configuration configuration) {
+    String value = configuration.getString(CoreProperties.DYNAMIC_ANALYSIS_PROPERTY);
+    if (value == null) {
+      return (configuration.getBoolean("sonar.light", false) ? Project.AnalysisType.STATIC : Project.AnalysisType.DYNAMIC);
+    }
+    if ("true".equals(value)) {
+      return Project.AnalysisType.DYNAMIC;
+    }
+    if ("reuseReports".equals(value)) {
+      return Project.AnalysisType.REUSE_REPORTS;
+    }
+    return Project.AnalysisType.STATIC;
+  }
+
+  String loadAnalysisVersion(Configuration configuration) {
+    return configuration.getString(CoreProperties.PROJECT_VERSION_PROPERTY);
+  }
+
+  String loadLanguageKey(Configuration configuration) {
+    return configuration.getString(CoreProperties.PROJECT_LANGUAGE_PROPERTY, Java.KEY);
+  }
+}
index ac2db745ec3e6fb389afc87c5512e006b22bb92e..72a599821e6d7a9ed5112430ca427d4f004f8526 100644 (file)
@@ -36,11 +36,11 @@ import java.util.*;
 public class ProjectTree {
 
   private List<Project> projects;
-  private MavenProjectBuilder projectBuilder;
+  private ProjectBuilder projectBuilder;
   private List<ProjectDefinition> definitions;
 
   public ProjectTree(Reactor sonarReactor, DatabaseSession databaseSession) {
-    this.projectBuilder = new MavenProjectBuilder(databaseSession);
+    this.projectBuilder = new ProjectBuilder(databaseSession);
     definitions = Lists.newArrayList();
     for (ProjectDefinition project : sonarReactor.getSortedProjects()) {
       collectProjects(project, definitions);
@@ -50,7 +50,7 @@ public class ProjectTree {
   /**
    * for unit tests
    */
-  protected ProjectTree(MavenProjectBuilder projectBuilder, List<MavenProject> poms) {
+  protected ProjectTree(ProjectBuilder projectBuilder, List<MavenProject> poms) {
     this.projectBuilder = projectBuilder;
     definitions = Lists.newArrayList();
     collectProjects(MavenProjectConverter.convert(poms), definitions);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/MavenProjectBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/MavenProjectBuilderTest.java
deleted file mode 100644 (file)
index 734f4e6..0000000
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 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;
-
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.CoreProperties;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-import org.sonar.api.resources.Java;
-import org.sonar.api.resources.Project;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-public class MavenProjectBuilderTest extends AbstractDbUnitTestCase {
-
-  private MavenProjectBuilder builder = null;
-
-  @Before
-  public void before() {
-    builder = new MavenProjectBuilder(getSession());
-  }
-
-  @Test
-  public void noExclusionPatterns() {
-    Project project = new Project("key");
-    builder.configure(project, new PropertiesConfiguration());
-
-    assertThat(project.getExclusionPatterns().length, is(0));
-  }
-
-  @Test
-  public void manyExclusionPatterns() {
-    PropertiesConfiguration configuration = new PropertiesConfiguration();
-    configuration.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*,foo,*/bar");
-
-    Project project = new Project("key");
-    builder.configure(project, configuration);
-
-    assertThat(project.getExclusionPatterns().length, is(3));
-    assertThat(project.getExclusionPatterns()[0], is("**/*"));
-    assertThat(project.getExclusionPatterns()[1], is("foo"));
-    assertThat(project.getExclusionPatterns()[2], is("*/bar"));
-  }
-
-  @Test
-  public void getLanguageFromConfiguration() {
-    PropertiesConfiguration configuration = new PropertiesConfiguration();
-    configuration.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "foo");
-
-    Project project = new Project("key");
-    builder.configure(project, configuration);
-
-    assertThat(project.getLanguageKey(), is("foo"));
-  }
-
-  @Test
-  public void defaultLanguageIsJava() {
-    Project project = new Project("key");
-    builder.configure(project, new PropertiesConfiguration());
-
-    assertThat(project.getLanguageKey(), is(Java.KEY));
-  }
-
-  @Test
-  public void analysisIsTodayByDefault() {
-    Project project = new Project("key");
-    builder.configure(project, new PropertiesConfiguration());
-    Date today = new Date();
-    assertTrue(today.getTime() - project.getAnalysisDate().getTime() < 1000);
-  }
-
-  @Test
-  public void analysisDateCouldBeExplicitlySet() {
-    PropertiesConfiguration configuration = new PropertiesConfiguration();
-    configuration.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2005-01-30");
-    Project project = new Project("key");
-    builder.configure(project, configuration);
-
-    assertEquals("30012005", new SimpleDateFormat("ddMMyyyy").format(project.getAnalysisDate()));
-  }
-
-  @Test(expected = RuntimeException.class)
-  public void failIfAnalyisDateIsNotValid() {
-    PropertiesConfiguration configuration = new PropertiesConfiguration();
-    configuration.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2005/30/01");
-    Project project = new Project("key");
-    builder.configure(project, configuration);
-
-    project.getAnalysisDate();
-  }
-
-  @Test
-  public void sonarLightIsDeprecated() {
-    PropertiesConfiguration configuration = new PropertiesConfiguration();
-    configuration.setProperty("sonar.light", "true");
-    Project project = new Project("key");
-    builder.configure(project, configuration);
-
-    assertThat(project.getAnalysisType(), is(Project.AnalysisType.STATIC));
-  }
-
-  @Test
-  public void defaultAnalysisTypeIsDynamic() {
-    Project project = new Project("key");
-    builder.configure(project, new PropertiesConfiguration());
-    assertThat(project.getAnalysisType(), is(Project.AnalysisType.DYNAMIC));
-  }
-
-  @Test
-  public void explicitDynamicAnalysis() {
-    PropertiesConfiguration configuration = new PropertiesConfiguration();
-    configuration.setProperty(CoreProperties.DYNAMIC_ANALYSIS_PROPERTY, "true");
-    Project project = new Project("key");
-    builder.configure(project, configuration);
-    assertThat(project.getAnalysisType(), is(Project.AnalysisType.DYNAMIC));
-  }
-
-  @Test
-  public void explicitStaticAnalysis() {
-    PropertiesConfiguration configuration = new PropertiesConfiguration();
-    configuration.setProperty(CoreProperties.DYNAMIC_ANALYSIS_PROPERTY, "false");
-    Project project = new Project("key");
-    builder.configure(project, configuration);
-    assertThat(project.getAnalysisType(), is(Project.AnalysisType.STATIC));
-  }
-
-  @Test
-  public void explicitDynamicAnalysisReusingReports() {
-    PropertiesConfiguration configuration = new PropertiesConfiguration();
-    configuration.setProperty(CoreProperties.DYNAMIC_ANALYSIS_PROPERTY, "reuseReports");
-    Project project = new Project("key");
-    builder.configure(project, configuration);
-    assertThat(project.getAnalysisType(), is(Project.AnalysisType.REUSE_REPORTS));
-  }
-
-  @Test
-  public void isDynamicAnalysis() {
-    assertThat(Project.AnalysisType.DYNAMIC.isDynamic(false), is(true));
-    assertThat(Project.AnalysisType.DYNAMIC.isDynamic(true), is(true));
-
-    assertThat(Project.AnalysisType.STATIC.isDynamic(false), is(false));
-    assertThat(Project.AnalysisType.STATIC.isDynamic(true), is(false));
-
-    assertThat(Project.AnalysisType.REUSE_REPORTS.isDynamic(false), is(false));
-    assertThat(Project.AnalysisType.REUSE_REPORTS.isDynamic(true), is(true));
-  }
-
-  @Test
-  public void isLatestAnalysis() {
-    setupData("isLatestAnalysis");
-
-    PropertiesConfiguration configuration = new PropertiesConfiguration();
-    configuration.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2010-12-25");
-
-    Project project = new Project("my:key");
-    builder.configure(project, configuration);
-
-    assertThat(project.isLatestAnalysis(), is(true));
-  }
-
-  @Test
-  public void isLatestAnalysisIfNeverAnalysed() {
-    setupData("isLatestAnalysisIfNeverAnalysed");
-
-    PropertiesConfiguration configuration = new PropertiesConfiguration();
-    configuration.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2010-12-25");
-
-    Project project = new Project("my:key");
-    builder.configure(project, configuration);
-
-    assertThat(project.isLatestAnalysis(), is(true));
-  }
-
-  @Test
-  public void isNotLatestAnalysis() {
-    setupData("isNotLatestAnalysis");
-
-    PropertiesConfiguration configuration = new PropertiesConfiguration();
-    configuration.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2005-12-25");
-
-    Project project = new Project("my:key");
-    builder.configure(project, configuration);
-
-    assertThat(project.isLatestAnalysis(), is(false));
-  }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/ProjectBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/ProjectBuilderTest.java
new file mode 100644 (file)
index 0000000..ffa872b
--- /dev/null
@@ -0,0 +1,210 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 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;
+
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.CoreProperties;
+import org.sonar.jpa.test.AbstractDbUnitTestCase;
+import org.sonar.api.resources.Java;
+import org.sonar.api.resources.Project;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class ProjectBuilderTest extends AbstractDbUnitTestCase {
+
+  private ProjectBuilder builder = null;
+
+  @Before
+  public void before() {
+    builder = new ProjectBuilder(getSession());
+  }
+
+  @Test
+  public void noExclusionPatterns() {
+    Project project = new Project("key");
+    builder.configure(project, new PropertiesConfiguration());
+
+    assertThat(project.getExclusionPatterns().length, is(0));
+  }
+
+  @Test
+  public void manyExclusionPatterns() {
+    PropertiesConfiguration configuration = new PropertiesConfiguration();
+    configuration.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*,foo,*/bar");
+
+    Project project = new Project("key");
+    builder.configure(project, configuration);
+
+    assertThat(project.getExclusionPatterns().length, is(3));
+    assertThat(project.getExclusionPatterns()[0], is("**/*"));
+    assertThat(project.getExclusionPatterns()[1], is("foo"));
+    assertThat(project.getExclusionPatterns()[2], is("*/bar"));
+  }
+
+  @Test
+  public void getLanguageFromConfiguration() {
+    PropertiesConfiguration configuration = new PropertiesConfiguration();
+    configuration.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "foo");
+
+    Project project = new Project("key");
+    builder.configure(project, configuration);
+
+    assertThat(project.getLanguageKey(), is("foo"));
+  }
+
+  @Test
+  public void defaultLanguageIsJava() {
+    Project project = new Project("key");
+    builder.configure(project, new PropertiesConfiguration());
+
+    assertThat(project.getLanguageKey(), is(Java.KEY));
+  }
+
+  @Test
+  public void analysisIsTodayByDefault() {
+    Project project = new Project("key");
+    builder.configure(project, new PropertiesConfiguration());
+    Date today = new Date();
+    assertTrue(today.getTime() - project.getAnalysisDate().getTime() < 1000);
+  }
+
+  @Test
+  public void analysisDateCouldBeExplicitlySet() {
+    PropertiesConfiguration configuration = new PropertiesConfiguration();
+    configuration.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2005-01-30");
+    Project project = new Project("key");
+    builder.configure(project, configuration);
+
+    assertEquals("30012005", new SimpleDateFormat("ddMMyyyy").format(project.getAnalysisDate()));
+  }
+
+  @Test(expected = RuntimeException.class)
+  public void failIfAnalyisDateIsNotValid() {
+    PropertiesConfiguration configuration = new PropertiesConfiguration();
+    configuration.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2005/30/01");
+    Project project = new Project("key");
+    builder.configure(project, configuration);
+
+    project.getAnalysisDate();
+  }
+
+  @Test
+  public void sonarLightIsDeprecated() {
+    PropertiesConfiguration configuration = new PropertiesConfiguration();
+    configuration.setProperty("sonar.light", "true");
+    Project project = new Project("key");
+    builder.configure(project, configuration);
+
+    assertThat(project.getAnalysisType(), is(Project.AnalysisType.STATIC));
+  }
+
+  @Test
+  public void defaultAnalysisTypeIsDynamic() {
+    Project project = new Project("key");
+    builder.configure(project, new PropertiesConfiguration());
+    assertThat(project.getAnalysisType(), is(Project.AnalysisType.DYNAMIC));
+  }
+
+  @Test
+  public void explicitDynamicAnalysis() {
+    PropertiesConfiguration configuration = new PropertiesConfiguration();
+    configuration.setProperty(CoreProperties.DYNAMIC_ANALYSIS_PROPERTY, "true");
+    Project project = new Project("key");
+    builder.configure(project, configuration);
+    assertThat(project.getAnalysisType(), is(Project.AnalysisType.DYNAMIC));
+  }
+
+  @Test
+  public void explicitStaticAnalysis() {
+    PropertiesConfiguration configuration = new PropertiesConfiguration();
+    configuration.setProperty(CoreProperties.DYNAMIC_ANALYSIS_PROPERTY, "false");
+    Project project = new Project("key");
+    builder.configure(project, configuration);
+    assertThat(project.getAnalysisType(), is(Project.AnalysisType.STATIC));
+  }
+
+  @Test
+  public void explicitDynamicAnalysisReusingReports() {
+    PropertiesConfiguration configuration = new PropertiesConfiguration();
+    configuration.setProperty(CoreProperties.DYNAMIC_ANALYSIS_PROPERTY, "reuseReports");
+    Project project = new Project("key");
+    builder.configure(project, configuration);
+    assertThat(project.getAnalysisType(), is(Project.AnalysisType.REUSE_REPORTS));
+  }
+
+  @Test
+  public void isDynamicAnalysis() {
+    assertThat(Project.AnalysisType.DYNAMIC.isDynamic(false), is(true));
+    assertThat(Project.AnalysisType.DYNAMIC.isDynamic(true), is(true));
+
+    assertThat(Project.AnalysisType.STATIC.isDynamic(false), is(false));
+    assertThat(Project.AnalysisType.STATIC.isDynamic(true), is(false));
+
+    assertThat(Project.AnalysisType.REUSE_REPORTS.isDynamic(false), is(false));
+    assertThat(Project.AnalysisType.REUSE_REPORTS.isDynamic(true), is(true));
+  }
+
+  @Test
+  public void isLatestAnalysis() {
+    setupData("isLatestAnalysis");
+
+    PropertiesConfiguration configuration = new PropertiesConfiguration();
+    configuration.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2010-12-25");
+
+    Project project = new Project("my:key");
+    builder.configure(project, configuration);
+
+    assertThat(project.isLatestAnalysis(), is(true));
+  }
+
+  @Test
+  public void isLatestAnalysisIfNeverAnalysed() {
+    setupData("isLatestAnalysisIfNeverAnalysed");
+
+    PropertiesConfiguration configuration = new PropertiesConfiguration();
+    configuration.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2010-12-25");
+
+    Project project = new Project("my:key");
+    builder.configure(project, configuration);
+
+    assertThat(project.isLatestAnalysis(), is(true));
+  }
+
+  @Test
+  public void isNotLatestAnalysis() {
+    setupData("isNotLatestAnalysis");
+
+    PropertiesConfiguration configuration = new PropertiesConfiguration();
+    configuration.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2005-12-25");
+
+    Project project = new Project("my:key");
+    builder.configure(project, configuration);
+
+    assertThat(project.isLatestAnalysis(), is(false));
+  }
+}
index c494dfb02bcd54568967472de981b58e7f4985a7..fc05f42a4ac959e18c241db9fffc05b6b8bdf401 100644 (file)
@@ -200,7 +200,7 @@ public class ProjectTreeTest extends AbstractDbUnitTestCase {
     return pom;
   }
 
-  private MavenProjectBuilder newProjectBuilder() {
-    return new MavenProjectBuilder(getSession());
+  private ProjectBuilder newProjectBuilder() {
+    return new ProjectBuilder(getSession());
   }
 }
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/MavenProjectBuilderTest/MavenPluginsConfiguratorTest/pom.xml b/sonar-batch/src/test/resources/org/sonar/batch/MavenProjectBuilderTest/MavenPluginsConfiguratorTest/pom.xml
deleted file mode 100644 (file)
index 2f95da1..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-  <modelVersion>4.0.0</modelVersion>
-  <groupId>mygroup</groupId>
-  <artifactId>myartifact</artifactId>
-  <packaging>jar</packaging>
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-checkstyle-plugin</artifactId>
-        <version>2.2</version>
-        <configuration>
-          <outputFileFormat>html</outputFileFormat>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
-</project>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/MavenProjectBuilderTest/isLatestAnalysis.xml b/sonar-batch/src/test/resources/org/sonar/batch/MavenProjectBuilderTest/isLatestAnalysis.xml
deleted file mode 100644 (file)
index 8742237..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<dataset>
-
-  <projects long_name="[null]" id="5" scope="PRJ" qualifier="TRK" kee="my:key"
-            name="My project" root_id="[null]"
-            description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]"/>
-
-  <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" depth="[null]" id="30" scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" version="[null]"
-             project_id="5" parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
-             path="[null]"/>
-
-  <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" depth="[null]" id="50" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" version="[null]"
-             project_id="5" parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="true"
-             path="[null]"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/MavenProjectBuilderTest/isLatestAnalysisIfNeverAnalysed.xml b/sonar-batch/src/test/resources/org/sonar/batch/MavenProjectBuilderTest/isLatestAnalysisIfNeverAnalysed.xml
deleted file mode 100644 (file)
index 525f998..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<dataset>
-
-  <!-- other project -->
-  <projects long_name="[null]" id="5" scope="PRJ" qualifier="TRK" kee="other:key"
-            name="My project" root_id="[null]"
-            description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]"/>
-
-  <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" depth="[null]" id="50" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" version="[null]"
-             project_id="5" parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="true"
-             path="[null]"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/MavenProjectBuilderTest/isNotLatestAnalysis.xml b/sonar-batch/src/test/resources/org/sonar/batch/MavenProjectBuilderTest/isNotLatestAnalysis.xml
deleted file mode 100644 (file)
index 679a9d9..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<dataset>
-
-  <projects long_name="[null]" id="5" scope="PRJ" qualifier="TRK" kee="my:key"
-            name="My project" root_id="[null]"
-            description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]"/>
-
-  <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" depth="[null]" id="30" scope="PRJ" qualifier="TRK" created_at="2010-11-01 13:58:00.00" version="[null]"
-             project_id="5" parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
-             path="[null]"/>
-
-  <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" depth="[null]" id="50" scope="PRJ" qualifier="TRK" created_at="2010-12-02 13:58:00.00" version="[null]"
-             project_id="5" parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="true"
-             path="[null]"/>
-</dataset>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/ProjectBuilderTest/MavenPluginsConfiguratorTest/pom.xml b/sonar-batch/src/test/resources/org/sonar/batch/ProjectBuilderTest/MavenPluginsConfiguratorTest/pom.xml
new file mode 100644 (file)
index 0000000..2f95da1
--- /dev/null
@@ -0,0 +1,19 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>mygroup</groupId>
+  <artifactId>myartifact</artifactId>
+  <packaging>jar</packaging>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-checkstyle-plugin</artifactId>
+        <version>2.2</version>
+        <configuration>
+          <outputFileFormat>html</outputFileFormat>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/ProjectBuilderTest/isLatestAnalysis.xml b/sonar-batch/src/test/resources/org/sonar/batch/ProjectBuilderTest/isLatestAnalysis.xml
new file mode 100644 (file)
index 0000000..8742237
--- /dev/null
@@ -0,0 +1,15 @@
+<dataset>
+
+  <projects long_name="[null]" id="5" scope="PRJ" qualifier="TRK" kee="my:key"
+            name="My project" root_id="[null]"
+            description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]"/>
+
+  <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" depth="[null]" id="30" scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" version="[null]"
+             project_id="5" parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+             path="[null]"/>
+
+  <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" depth="[null]" id="50" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" version="[null]"
+             project_id="5" parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="true"
+             path="[null]"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/ProjectBuilderTest/isLatestAnalysisIfNeverAnalysed.xml b/sonar-batch/src/test/resources/org/sonar/batch/ProjectBuilderTest/isLatestAnalysisIfNeverAnalysed.xml
new file mode 100644 (file)
index 0000000..525f998
--- /dev/null
@@ -0,0 +1,12 @@
+<dataset>
+
+  <!-- other project -->
+  <projects long_name="[null]" id="5" scope="PRJ" qualifier="TRK" kee="other:key"
+            name="My project" root_id="[null]"
+            description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]"/>
+
+  <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" depth="[null]" id="50" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" version="[null]"
+             project_id="5" parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="true"
+             path="[null]"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/ProjectBuilderTest/isNotLatestAnalysis.xml b/sonar-batch/src/test/resources/org/sonar/batch/ProjectBuilderTest/isNotLatestAnalysis.xml
new file mode 100644 (file)
index 0000000..679a9d9
--- /dev/null
@@ -0,0 +1,15 @@
+<dataset>
+
+  <projects long_name="[null]" id="5" scope="PRJ" qualifier="TRK" kee="my:key"
+            name="My project" root_id="[null]"
+            description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]"/>
+
+  <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" depth="[null]" id="30" scope="PRJ" qualifier="TRK" created_at="2010-11-01 13:58:00.00" version="[null]"
+             project_id="5" parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+             path="[null]"/>
+
+  <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" depth="[null]" id="50" scope="PRJ" qualifier="TRK" created_at="2010-12-02 13:58:00.00" version="[null]"
+             project_id="5" parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="true"
+             path="[null]"/>
+</dataset>
\ No newline at end of file