diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-09-08 18:25:06 +0400 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-09-08 18:47:51 +0400 |
commit | 157058813dd0bae520ac4273aa454b73b7e246d4 (patch) | |
tree | 650f23fb8858c3be0c519d3e0871039250c74d65 /sonar-batch | |
parent | 4d72a556429e94837eca3159b471518ae9221626 (diff) | |
download | sonarqube-157058813dd0bae520ac4273aa454b73b7e246d4.tar.gz sonarqube-157058813dd0bae520ac4273aa454b73b7e246d4.zip |
SONAR-2744 Fix regression in usage of 'sonar.phase'
Diffstat (limited to 'sonar-batch')
6 files changed, 32 insertions, 22 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/AbstractMavenPluginExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/AbstractMavenPluginExecutor.java index 2c4c0d12ed8..fdd219cecf6 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/AbstractMavenPluginExecutor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/AbstractMavenPluginExecutor.java @@ -35,17 +35,14 @@ public abstract class AbstractMavenPluginExecutor implements MavenPluginExecutor public final MavenPluginHandler execute(Project project, ProjectDefinition projectDefinition, MavenPluginHandler handler) { for (String goal : handler.getGoals()) { MavenPlugin plugin = MavenPlugin.getPlugin(project.getPom(), handler.getGroupId(), handler.getArtifactId()); - execute(project, getGoal(handler.getGroupId(), handler.getArtifactId(), (plugin!=null && plugin.getPlugin()!=null ? plugin.getPlugin().getVersion() : null), goal)); + execute(project, + projectDefinition, + getGoal(handler.getGroupId(), handler.getArtifactId(), (plugin != null && plugin.getPlugin() != null ? plugin.getPlugin().getVersion() : null), goal)); } - - if (project.getPom()!=null) { - MavenProjectConverter.synchronizeFileSystem(project.getPom(), projectDefinition); - } - return handler; } - public final void execute(Project project, String goal) { + public final void execute(Project project, ProjectDefinition projectDefinition, String goal) { TimeProfiler profiler = new TimeProfiler().start("Execute " + goal); ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader(); try { @@ -57,6 +54,10 @@ public abstract class AbstractMavenPluginExecutor implements MavenPluginExecutor Thread.currentThread().setContextClassLoader(currentClassLoader); profiler.stop(); } + + if (project.getPom() != null) { + MavenProjectConverter.synchronizeFileSystem(project.getPom(), projectDefinition); + } } public abstract void concreteExecute(MavenProject pom, String goal) throws Exception; diff --git a/sonar-batch/src/main/java/org/sonar/batch/FakeMavenPluginExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/FakeMavenPluginExecutor.java index 539d2962ec2..c8e0bc75ea7 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/FakeMavenPluginExecutor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/FakeMavenPluginExecutor.java @@ -24,7 +24,7 @@ import org.sonar.api.batch.maven.MavenPluginHandler; import org.sonar.api.resources.Project; public final class FakeMavenPluginExecutor implements MavenPluginExecutor { - public void execute(Project project, String goal) { + public void execute(Project project, ProjectDefinition projectDef, String goal) { // do nothing } diff --git a/sonar-batch/src/main/java/org/sonar/batch/MavenPluginExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/MavenPluginExecutor.java index 891c9fd1c4b..bc095fe0625 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/MavenPluginExecutor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/MavenPluginExecutor.java @@ -26,7 +26,7 @@ import org.sonar.api.resources.Project; public interface MavenPluginExecutor extends BatchComponent { - void execute(Project project, String goal); + void execute(Project project, ProjectDefinition def, String goal); MavenPluginHandler execute(Project project, ProjectDefinition def, MavenPluginHandler handler); diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/MavenPhaseExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/MavenPhaseExecutor.java index a20548145a3..c3f2ad5cf90 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/MavenPhaseExecutor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/phases/MavenPhaseExecutor.java @@ -21,6 +21,7 @@ package org.sonar.batch.phases; import org.apache.commons.lang.StringUtils; import org.sonar.api.BatchComponent; +import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.resources.Project; import org.sonar.batch.MavenPluginExecutor; @@ -29,15 +30,17 @@ public class MavenPhaseExecutor implements BatchComponent { public static final String PROP_PHASE = "sonar.phase"; private MavenPluginExecutor executor; + private ProjectDefinition projectDef; - public MavenPhaseExecutor(MavenPluginExecutor executor) { + public MavenPhaseExecutor(ProjectDefinition projectDef, MavenPluginExecutor executor) { + this.projectDef = projectDef; this.executor = executor; } public void execute(Project project) { String mavenPhase = (String) project.getProperty(PROP_PHASE); if (!StringUtils.isBlank(mavenPhase)) { - executor.execute(project, mavenPhase); + executor.execute(project, projectDef, mavenPhase); } } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BootstrapModuleTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BootstrapModuleTest.java index ff62f837bbd..f92f6084c35 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BootstrapModuleTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BootstrapModuleTest.java @@ -19,6 +19,9 @@ */ package org.sonar.batch.bootstrap; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + import org.junit.Test; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.bootstrap.ProjectReactor; @@ -26,13 +29,10 @@ import org.sonar.api.batch.maven.MavenPluginHandler; import org.sonar.api.resources.Project; import org.sonar.batch.MavenPluginExecutor; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - public class BootstrapModuleTest { class MyMavenPluginExecutor implements MavenPluginExecutor { - public void execute(Project project, String goal) { + public void execute(Project project, ProjectDefinition projectDef, String goal) { } public MavenPluginHandler execute(Project project, ProjectDefinition projectDef, MavenPluginHandler handler) { diff --git a/sonar-batch/src/test/java/org/sonar/batch/phases/MavenPhaseExecutorTest.java b/sonar-batch/src/test/java/org/sonar/batch/phases/MavenPhaseExecutorTest.java index 49effe0b450..28cb920be2a 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/phases/MavenPhaseExecutorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/phases/MavenPhaseExecutorTest.java @@ -19,32 +19,38 @@ */ package org.sonar.batch.phases; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + import org.apache.commons.configuration.PropertiesConfiguration; import org.junit.Test; +import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.resources.Project; import org.sonar.batch.MavenPluginExecutor; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.*; - public class MavenPhaseExecutorTest { @Test public void doNothingIfNoPhase() { + ProjectDefinition projectDef = ProjectDefinition.create(); MavenPluginExecutor mavenPluginExecutor = mock(MavenPluginExecutor.class); - MavenPhaseExecutor phaseExecutor = new MavenPhaseExecutor(mavenPluginExecutor); + MavenPhaseExecutor phaseExecutor = new MavenPhaseExecutor(projectDef, mavenPluginExecutor); Project project = new Project("key"); phaseExecutor.execute(project); - verify(mavenPluginExecutor, never()).execute(eq(project), anyString()); + verify(mavenPluginExecutor, never()).execute(eq(project), eq(projectDef), anyString()); } @Test public void executePhase() { + ProjectDefinition projectDef = ProjectDefinition.create(); MavenPluginExecutor mavenPluginExecutor = mock(MavenPluginExecutor.class); - MavenPhaseExecutor phaseExecutor = new MavenPhaseExecutor(mavenPluginExecutor); + MavenPhaseExecutor phaseExecutor = new MavenPhaseExecutor(projectDef, mavenPluginExecutor); Project project = new Project("key"); PropertiesConfiguration conf = new PropertiesConfiguration(); @@ -53,6 +59,6 @@ public class MavenPhaseExecutorTest { phaseExecutor.execute(project); - verify(mavenPluginExecutor).execute(project, "myphase"); + verify(mavenPluginExecutor).execute(project, projectDef, "myphase"); } } |