diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-03-16 15:35:26 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-06-03 12:09:14 +0200 |
commit | 5dd7b6e298dde08601a09a5acc11e215961a6c63 (patch) | |
tree | 5ed9dcead7a21020a1ad7988e40f29106debc8a5 /sonar-batch | |
parent | 4490f3161107ad197c736125c2ca551a1525c7d8 (diff) | |
download | sonarqube-5dd7b6e298dde08601a09a5acc11e215961a6c63.tar.gz sonarqube-5dd7b6e298dde08601a09a5acc11e215961a6c63.zip |
SONAR-3821 Drop any Maven dependency
Diffstat (limited to 'sonar-batch')
14 files changed, 6 insertions, 988 deletions
diff --git a/sonar-batch/pom.xml b/sonar-batch/pom.xml index 2deade811d3..668d8fd90fe 100644 --- a/sonar-batch/pom.xml +++ b/sonar-batch/pom.xml @@ -86,26 +86,6 @@ <artifactId>jul-to-slf4j</artifactId> </dependency> <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-plugin-api</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-core</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-compat</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.maven.shared</groupId> - <artifactId>maven-dependency-tree</artifactId> - <scope>provided</scope> - </dependency> - <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> </dependency> diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java index 412af2fce85..b2154d40aa3 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java @@ -20,7 +20,6 @@ package org.sonar.batch; import org.apache.commons.lang.StringUtils; -import org.apache.maven.project.MavenProject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.batch.BatchSide; @@ -64,18 +63,7 @@ public class ProjectConfigurator { public Project create(ProjectDefinition definition) { Project project = new Project(definition.getKey(), loadProjectBranch(), definition.getName()); - - // For backward compatibility we must set POM and actual packaging project.setDescription(StringUtils.defaultString(definition.getDescription())); - project.setPackaging("jar"); - - for (Object component : definition.getContainerExtensions()) { - if (component instanceof MavenProject) { - MavenProject pom = (MavenProject) component; - project.setPom(pom); - project.setPackaging(pom.getPackaging()); - } - } return project; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java index 5dd2b76f8b5..ab984c1c27d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java @@ -57,9 +57,6 @@ import org.sonar.batch.issue.tracking.IssueHandlers; import org.sonar.batch.issue.tracking.IssueTracking; import org.sonar.batch.issue.tracking.IssueTrackingDecorator; import org.sonar.batch.language.LanguageDistributionDecorator; -import org.sonar.batch.maven.MavenProjectBootstrapper; -import org.sonar.batch.maven.MavenProjectBuilder; -import org.sonar.batch.maven.MavenProjectConverter; import org.sonar.batch.qualitygate.GenerateQualityGateEvents; import org.sonar.batch.qualitygate.QualityGateVerifier; import org.sonar.batch.rule.QProfileEventsDecorator; @@ -85,10 +82,6 @@ public class BatchComponents { public static Collection all(DefaultAnalysisMode analysisMode) { List components = Lists.newArrayList( DefaultResourceTypes.get(), - - // Maven - MavenProjectBootstrapper.class, MavenProjectConverter.class, MavenProjectBuilder.class, - // SCM ScmConfiguration.class, ScmSensor.class, diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/DefaultProjectClasspath.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/DefaultProjectClasspath.java deleted file mode 100644 index f5a07c9889c..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/DefaultProjectClasspath.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.deprecated.components; - -import com.google.common.collect.Lists; -import org.apache.maven.project.MavenProject; -import org.sonar.api.batch.ProjectClasspath; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.resources.ProjectFileSystem; - -import javax.annotation.Nullable; - -import java.io.File; -import java.util.List; - -public class DefaultProjectClasspath extends ProjectClasspath { - - private ProjectDefinition def; - private ProjectFileSystem projectFileSystem; - - public DefaultProjectClasspath(ProjectDefinition def, ProjectFileSystem projectFileSystem) { - this(def, projectFileSystem, null); - } - - public DefaultProjectClasspath(ProjectDefinition def, ProjectFileSystem projectFileSystem, @Nullable MavenProject pom) { - super(pom); - this.def = def; - this.projectFileSystem = projectFileSystem; - } - - @Override - protected List<File> createElements() { - if (pom != null) { - return super.createElements(); - } else { - List<File> elements = Lists.newArrayList(); - for (String path : def.getBinaries()) { - elements.add(projectFileSystem.resolvePath(path)); - } - for (String path : def.getLibraries()) { - elements.add(projectFileSystem.resolvePath(path)); - } - return elements; - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/maven/MavenProjectBootstrapper.java b/sonar-batch/src/main/java/org/sonar/batch/maven/MavenProjectBootstrapper.java deleted file mode 100644 index 3cd1f9d5c7f..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/maven/MavenProjectBootstrapper.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.maven; - -import org.apache.maven.execution.MavenSession; -import org.apache.maven.project.MavenProject; -import org.sonar.api.batch.SupportedEnvironment; -import org.sonar.api.batch.bootstrap.ProjectBootstrapper; -import org.sonar.api.batch.bootstrap.ProjectReactor; - -import java.util.List; - -/** - * @deprecated since 4.3 kept only to support old version of SonarQube Mojo - */ -@Deprecated -@SupportedEnvironment("maven") -public class MavenProjectBootstrapper implements ProjectBootstrapper { - - private MavenSession session; - private MavenProjectConverter mavenProjectConverter; - - public MavenProjectBootstrapper(MavenSession session, MavenProjectConverter mavenProjectConverter) { - this.session = session; - this.mavenProjectConverter = mavenProjectConverter; - } - - @Override - public ProjectReactor bootstrap() { - // Don't use session.getTopLevelProject or session.getProjects to keep compatibility with Maven 2 - List<MavenProject> sortedProjects = session.getSortedProjects(); - MavenProject topLevelProject = null; - for (MavenProject project : sortedProjects) { - if (project.isExecutionRoot()) { - topLevelProject = project; - break; - } - } - if (topLevelProject == null) { - throw new IllegalStateException("Maven session does not declare a top level project"); - } - return new ProjectReactor(mavenProjectConverter.configure(sortedProjects, topLevelProject)); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/maven/MavenProjectBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/maven/MavenProjectBuilder.java deleted file mode 100644 index 7cbf3efc5f2..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/maven/MavenProjectBuilder.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.maven; - -import org.apache.maven.execution.MavenSession; -import org.apache.maven.project.MavenProject; -import org.sonar.api.batch.SupportedEnvironment; -import org.sonar.api.batch.bootstrap.ProjectBuilder; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.batch.bootstrap.ProjectReactor; - -import java.util.List; - -/** - * Class that inject MavenProject in each module container - */ -@SupportedEnvironment("maven") -public class MavenProjectBuilder extends ProjectBuilder { - - private final MavenSession mavenSession; - - public MavenProjectBuilder(MavenSession mavenSession) { - this.mavenSession = mavenSession; - } - - @Override - public void build(Context context) { - ProjectReactor reactor = context.projectReactor(); - for (ProjectDefinition moduleDef : reactor.getProjects()) { - setMavenProjectIfApplicable(moduleDef); - } - } - - private void setMavenProjectIfApplicable(ProjectDefinition definition) { - if (mavenSession != null) { - String moduleKey = definition.getKey(); - for (MavenProject mavenModule : (List<MavenProject>) mavenSession.getSortedProjects()) { - String mavenModuleKey = mavenModule.getGroupId() + ":" + mavenModule.getArtifactId(); - if (mavenModuleKey.equals(moduleKey) && !definition.getContainerExtensions().contains(mavenModule)) { - definition.addContainerExtension(mavenModule); - } - } - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/maven/MavenProjectConverter.java b/sonar-batch/src/main/java/org/sonar/batch/maven/MavenProjectConverter.java deleted file mode 100644 index ee78f0ea7c7..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/maven/MavenProjectConverter.java +++ /dev/null @@ -1,302 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.maven; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.collect.Collections2; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import org.apache.commons.lang.StringUtils; -import org.apache.maven.model.CiManagement; -import org.apache.maven.model.IssueManagement; -import org.apache.maven.model.Scm; -import org.apache.maven.project.MavenProject; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.SupportedEnvironment; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.batch.maven.MavenUtils; -import org.sonar.api.task.TaskExtension; -import org.sonar.api.utils.MessageException; -import org.sonar.java.api.JavaUtils; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -/** - * @deprecated since 4.3 kept only to support old version of SonarQube Mojo - */ -@Deprecated -@SupportedEnvironment("maven") -public class MavenProjectConverter implements TaskExtension { - - private static final String UNABLE_TO_DETERMINE_PROJECT_STRUCTURE_EXCEPTION_MESSAGE = "Unable to determine structure of project." + - " Probably you use Maven Advanced Reactor Options, which is not supported by SonarQube and should not be used."; - - public ProjectDefinition configure(List<MavenProject> poms, MavenProject root) { - // projects by canonical path to pom.xml - Map<String, MavenProject> paths = Maps.newHashMap(); - Map<MavenProject, ProjectDefinition> defs = Maps.newHashMap(); - - try { - configureModules(poms, paths, defs); - - rebuildModuleHierarchy(paths, defs); - } catch (IOException e) { - throw new IllegalStateException("Cannot configure project", e); - } - - ProjectDefinition rootProject = defs.get(root); - if (rootProject == null) { - throw new IllegalStateException(UNABLE_TO_DETERMINE_PROJECT_STRUCTURE_EXCEPTION_MESSAGE); - } - return rootProject; - } - - private void rebuildModuleHierarchy(Map<String, MavenProject> paths, Map<MavenProject, ProjectDefinition> defs) throws IOException { - for (Map.Entry<String, MavenProject> entry : paths.entrySet()) { - MavenProject pom = entry.getValue(); - for (Object m : pom.getModules()) { - String moduleId = (String) m; - File modulePath = new File(pom.getBasedir(), moduleId); - MavenProject module = findMavenProject(modulePath, paths); - - ProjectDefinition parentProject = defs.get(pom); - if (parentProject == null) { - throw new IllegalStateException(UNABLE_TO_DETERMINE_PROJECT_STRUCTURE_EXCEPTION_MESSAGE); - } - ProjectDefinition subProject = defs.get(module); - if (subProject == null) { - throw new IllegalStateException(UNABLE_TO_DETERMINE_PROJECT_STRUCTURE_EXCEPTION_MESSAGE); - } - parentProject.addSubProject(subProject); - } - } - } - - private void configureModules(List<MavenProject> poms, Map<String, MavenProject> paths, Map<MavenProject, ProjectDefinition> defs) throws IOException { - for (MavenProject pom : poms) { - paths.put(pom.getFile().getCanonicalPath(), pom); - ProjectDefinition def = ProjectDefinition.create(); - merge(pom, def); - defs.put(pom, def); - } - } - - private static MavenProject findMavenProject(final File modulePath, Map<String, MavenProject> paths) throws IOException { - if (modulePath.exists() && modulePath.isDirectory()) { - for (Map.Entry<String, MavenProject> entry : paths.entrySet()) { - String pomFileParentDir = new File(entry.getKey()).getParent(); - if (pomFileParentDir.equals(modulePath.getCanonicalPath())) { - return entry.getValue(); - } - } - return null; - } - return paths.get(modulePath.getCanonicalPath()); - } - - @VisibleForTesting - void merge(MavenProject pom, ProjectDefinition definition) { - String key = getSonarKey(pom); - // IMPORTANT NOTE : reference on properties from POM model must not be saved, - // instead they should be copied explicitly - see SONAR-2896 - definition - .setProperties(pom.getModel().getProperties()) - .setKey(key) - .setVersion(pom.getVersion()) - .setName(pom.getName()) - .setDescription(pom.getDescription()) - .addContainerExtension(pom); - guessJavaVersion(pom, definition); - guessEncoding(pom, definition); - convertMavenLinksToProperties(definition, pom); - synchronizeFileSystem(pom, definition); - } - - private static String getSonarKey(MavenProject pom) { - return new StringBuilder().append(pom.getGroupId()).append(":").append(pom.getArtifactId()).toString(); - } - - private static void guessEncoding(MavenProject pom, ProjectDefinition definition) { - // See http://jira.sonarsource.com/browse/SONAR-2151 - String encoding = MavenUtils.getSourceEncoding(pom); - if (encoding != null) { - definition.setProperty(CoreProperties.ENCODING_PROPERTY, encoding); - } - } - - private static void guessJavaVersion(MavenProject pom, ProjectDefinition definition) { - // See http://jira.sonarsource.com/browse/SONAR-2148 - // Get Java source and target versions from maven-compiler-plugin. - String version = MavenUtils.getJavaSourceVersion(pom); - if (version != null) { - definition.setProperty(JavaUtils.JAVA_SOURCE_PROPERTY, version); - } - version = MavenUtils.getJavaVersion(pom); - if (version != null) { - definition.setProperty(JavaUtils.JAVA_TARGET_PROPERTY, version); - } - } - - /** - * For SONAR-3676 - */ - private static void convertMavenLinksToProperties(ProjectDefinition definition, MavenProject pom) { - setPropertyIfNotAlreadyExists(definition, CoreProperties.LINKS_HOME_PAGE, pom.getUrl()); - - Scm scm = pom.getScm(); - if (scm == null) { - scm = new Scm(); - } - setPropertyIfNotAlreadyExists(definition, CoreProperties.LINKS_SOURCES, scm.getUrl()); - setPropertyIfNotAlreadyExists(definition, CoreProperties.LINKS_SOURCES_DEV, scm.getDeveloperConnection()); - - CiManagement ci = pom.getCiManagement(); - if (ci == null) { - ci = new CiManagement(); - } - setPropertyIfNotAlreadyExists(definition, CoreProperties.LINKS_CI, ci.getUrl()); - - IssueManagement issues = pom.getIssueManagement(); - if (issues == null) { - issues = new IssueManagement(); - } - setPropertyIfNotAlreadyExists(definition, CoreProperties.LINKS_ISSUE_TRACKER, issues.getUrl()); - } - - private static void setPropertyIfNotAlreadyExists(ProjectDefinition definition, String propertyKey, String propertyValue) { - if (StringUtils.isBlank(definition.properties().get(propertyKey))) { - definition.setProperty(propertyKey, StringUtils.defaultString(propertyValue)); - } - } - - public void synchronizeFileSystem(MavenProject pom, ProjectDefinition into) { - into.setBaseDir(pom.getBasedir()); - File buildDir = getBuildDir(pom); - if (buildDir != null) { - into.setBuildDir(buildDir); - into.setWorkDir(getSonarWorkDir(pom)); - } - into.setSourceDirs(toPaths(mainDirs(pom))); - into.setTestDirs(toPaths(testDirs(pom))); - File binaryDir = resolvePath(pom.getBuild().getOutputDirectory(), pom.getBasedir()); - if (binaryDir != null) { - into.addBinaryDir(binaryDir); - } - } - - public static File getSonarWorkDir(MavenProject pom) { - return new File(getBuildDir(pom), "sonar"); - } - - private static File getBuildDir(MavenProject pom) { - return resolvePath(pom.getBuild().getDirectory(), pom.getBasedir()); - } - - static File resolvePath(@Nullable String path, File basedir) { - if (path != null) { - File file = new File(StringUtils.trim(path)); - if (!file.isAbsolute()) { - try { - file = new File(basedir, path).getCanonicalFile(); - } catch (IOException e) { - throw new IllegalStateException("Unable to resolve path '" + path + "'", e); - } - } - return file; - } - return null; - } - - static List<File> resolvePaths(List<String> paths, File basedir) { - List<File> result = Lists.newArrayList(); - for (String path : paths) { - File dir = resolvePath(path, basedir); - if (dir != null) { - result.add(dir); - } - } - return result; - } - - private List<File> mainDirs(MavenProject pom) { - return sourceDirs(pom, ProjectDefinition.SOURCE_DIRS_PROPERTY, pom.getCompileSourceRoots()); - } - - private List<File> testDirs(MavenProject pom) { - return sourceDirs(pom, ProjectDefinition.TEST_DIRS_PROPERTY, pom.getTestCompileSourceRoots()); - } - - private List<File> sourceDirs(MavenProject pom, String propertyKey, List mavenDirs) { - List<String> paths; - String prop = pom.getProperties().getProperty(propertyKey); - if (prop != null) { - paths = Arrays.asList(StringUtils.split(prop, ",")); - // do not remove dirs that do not exist. They must be kept in order to - // notify users that value of sonar.sources has a typo. - return existingDirsOrFail(resolvePaths(paths, pom.getBasedir()), pom, propertyKey); - } - - List<File> dirs = resolvePaths(mavenDirs, pom.getBasedir()); - - // Maven provides some directories that do not exist. They - // should be removed - return keepExistingDirs(dirs); - } - - private List<File> existingDirsOrFail(List<File> dirs, MavenProject pom, String propertyKey) { - for (File dir : dirs) { - if (!dir.isDirectory() || !dir.exists()) { - throw MessageException.of(String.format( - "The directory '%s' does not exist for Maven module %s. Please check the property %s", - dir.getAbsolutePath(), pom.getId(), propertyKey)); - } - } - return dirs; - } - - private static List<File> keepExistingDirs(List<File> files) { - return Lists.newArrayList(Collections2.filter(files, new Predicate<File>() { - @Override - public boolean apply(File dir) { - return dir != null && dir.exists() && dir.isDirectory(); - } - })); - } - - private static String[] toPaths(Collection<File> dirs) { - Collection<String> paths = Collections2.transform(dirs, new Function<File, String>() { - @Override - public String apply(@Nonnull File dir) { - return dir.getAbsolutePath(); - } - }); - return paths.toArray(new String[paths.size()]); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/maven/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/maven/package-info.java deleted file mode 100644 index b595cf0548f..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/maven/package-info.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -/** - * This package is a part of bootstrap process, so we should take care about backward compatibility. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.maven; - -import javax.annotation.ParametersAreNonnullByDefault; - diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java index b1abb181f22..9ce20db1b1f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java @@ -35,7 +35,6 @@ import org.sonar.batch.bootstrap.ExtensionMatcher; import org.sonar.batch.bootstrap.ExtensionUtils; import org.sonar.batch.deprecated.DeprecatedSensorContext; import org.sonar.batch.deprecated.ResourceFilters; -import org.sonar.batch.deprecated.components.DefaultProjectClasspath; import org.sonar.batch.deprecated.components.DefaultTimeMachine; import org.sonar.batch.deprecated.perspectives.BatchPerspectives; import org.sonar.batch.events.EventBus; @@ -139,7 +138,6 @@ public class ModuleScanContainer extends ComponentContainer { ComponentIndexer.class, LanguageVerifier.class, FileSystemLogger.class, - DefaultProjectClasspath.class, DefaultModuleFileSystem.class, ModuleFileSystemInitializer.class, ProjectFileSystemAdapter.class, @@ -193,13 +191,7 @@ public class ModuleScanContainer extends ComponentContainer { installer.install(this, new ExtensionMatcher() { @Override public boolean accept(Object extension) { - if (ExtensionUtils.isBatchSide(extension) && ExtensionUtils.isInstantiationStrategy(extension, InstantiationStrategy.PER_PROJECT)) { - // Special use-case: the extension point ProjectBuilder is used in a Maven environment to define some - // new sub-projects without pom. - // Example : C# plugin adds sub-projects at runtime, even if they are not defined in root pom. - return !ExtensionUtils.isMavenExtensionOnly(extension) || module.getPom() != null; - } - return false; + return ExtensionUtils.isBatchSide(extension) && ExtensionUtils.isInstantiationStrategy(extension, InstantiationStrategy.PER_PROJECT); } }); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ProjectFileSystemAdapter.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ProjectFileSystemAdapter.java index 0617ea8e8fa..1254f67e315 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ProjectFileSystemAdapter.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ProjectFileSystemAdapter.java @@ -23,18 +23,11 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.CharEncoding; -import org.apache.maven.project.MavenProject; import org.sonar.api.batch.fs.FilePredicate; -import org.sonar.api.resources.InputFile; -import org.sonar.api.resources.Java; -import org.sonar.api.resources.Language; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.ProjectFileSystem; -import org.sonar.api.resources.Resource; +import org.sonar.api.resources.*; import org.sonar.api.scan.filesystem.PathResolver; import org.sonar.api.utils.SonarException; -import javax.annotation.Nullable; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; @@ -50,20 +43,14 @@ public class ProjectFileSystemAdapter implements ProjectFileSystem { private final DefaultModuleFileSystem target; private final PathResolver pathResolver = new PathResolver(); - private final MavenProject pom; - public ProjectFileSystemAdapter(DefaultModuleFileSystem target, Project project, @Nullable MavenProject pom) { + public ProjectFileSystemAdapter(DefaultModuleFileSystem target, Project project) { this.target = target; - this.pom = pom; // previously MavenProjectBuilder was responsible for creation of ProjectFileSystem project.setFileSystem(this); } - public ProjectFileSystemAdapter(DefaultModuleFileSystem target, Project project) { - this(target, project, null); - } - public void start() { // used to avoid NPE in Project#getFileSystem() } @@ -123,9 +110,6 @@ public class ProjectFileSystemAdapter implements ProjectFileSystem { @Override public File getReportOutputDir() { - if (pom != null) { - return resolvePath(pom.getReporting().getOutputDirectory()); - } // emulate Maven report output dir return new File(getBuildDir(), "site"); } @@ -209,7 +193,7 @@ public class ProjectFileSystemAdapter implements ProjectFileSystem { return Lists.newArrayList((Iterable) target.inputFiles(target.predicates().and( target.predicates().hasType(org.sonar.api.batch.fs.InputFile.Type.MAIN), target.predicates().hasLanguages(Arrays.asList(langs)) - ))); + ))); } @@ -218,7 +202,7 @@ public class ProjectFileSystemAdapter implements ProjectFileSystem { return Lists.newArrayList((Iterable) target.inputFiles(target.predicates().and( target.predicates().hasType(org.sonar.api.batch.fs.InputFile.Type.TEST), target.predicates().hasLanguages(Arrays.asList(langs)) - ))); + ))); } private FilePredicate newHasLanguagesPredicate(Language... languages) { diff --git a/sonar-batch/src/test/java/org/sonar/batch/maven/MavenProjectBootstrapperTest.java b/sonar-batch/src/test/java/org/sonar/batch/maven/MavenProjectBootstrapperTest.java deleted file mode 100644 index a4d344bdece..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/maven/MavenProjectBootstrapperTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.maven; - -import org.apache.maven.execution.MavenSession; -import org.apache.maven.project.MavenProject; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.batch.bootstrap.ProjectReactor; - -import java.util.Arrays; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class MavenProjectBootstrapperTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void bootstrap() { - ProjectDefinition def = mock(ProjectDefinition.class); - MavenSession session = mock(MavenSession.class); - MavenProject rootProject = new MavenProject(); - rootProject.setExecutionRoot(true); - List<MavenProject> projects = Arrays.asList(rootProject); - when(session.getSortedProjects()).thenReturn(projects); - - MavenProjectConverter pomConverter = mock(MavenProjectConverter.class); - when(pomConverter.configure(projects, rootProject)).thenReturn(def); - MavenProjectBootstrapper bootstrapper = new MavenProjectBootstrapper(session, pomConverter); - - ProjectReactor reactor = bootstrapper.bootstrap(); - - assertThat(reactor).isNotNull(); - verify(pomConverter).configure(projects, rootProject); - } - - @Test - public void should_fail_if_no_top_level_project() { - thrown.expect(IllegalStateException.class); - thrown.expectMessage("Maven session does not declare a top level project"); - - MavenSession session = mock(MavenSession.class); - MavenProjectConverter pomConverter = new MavenProjectConverter(); - MavenProjectBootstrapper bootstrapper = new MavenProjectBootstrapper(session, pomConverter); - - bootstrapper.bootstrap(); - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/maven/MavenProjectConverterTest.java b/sonar-batch/src/test/java/org/sonar/batch/maven/MavenProjectConverterTest.java deleted file mode 100644 index db3e3513e26..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/maven/MavenProjectConverterTest.java +++ /dev/null @@ -1,245 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.maven; - -import com.google.common.io.Resources; -import org.apache.commons.io.FileUtils; -import org.apache.maven.model.Model; -import org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; -import org.hamcrest.core.Is; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.bootstrap.ProjectDefinition; - -import java.io.File; -import java.io.IOException; -import java.io.StringReader; -import java.net.URISyntaxException; -import java.util.Arrays; -import java.util.Properties; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -public class MavenProjectConverterTest { - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - MavenProjectConverter converter = new MavenProjectConverter(); - - /** - * See SONAR-2681 - */ - @Test - public void shouldThrowExceptionWhenUnableToDetermineProjectStructure() { - MavenProject root = new MavenProject(); - root.setFile(new File("/foo/pom.xml")); - root.getBuild().setDirectory("target"); - root.getModules().add("module/pom.xml"); - - try { - converter.configure(Arrays.asList(root), root); - fail(); - } catch (IllegalStateException e) { - assertThat(e.getMessage(), containsString("Advanced Reactor Options")); - } - } - - @Test - public void shouldConvertModules() throws IOException { - File basedir = temp.newFolder(); - - MavenProject root = newMavenProject("com.foo", "parent", "1.0-SNAPSHOT"); - root.setFile(new File(basedir, "pom.xml")); - root.getBuild().setDirectory("target"); - root.getBuild().setOutputDirectory("target/classes"); - root.getModules().add("module/pom.xml"); - MavenProject module = newMavenProject("com.foo", "moduleA", "1.0-SNAPSHOT"); - module.setFile(new File(basedir, "module/pom.xml")); - module.getBuild().setDirectory("target"); - module.getBuild().setOutputDirectory("target/classes"); - ProjectDefinition project = converter.configure(Arrays.asList(root, module), root); - - assertThat(project.getSubProjects().size(), is(1)); - } - - private MavenProject newMavenProject(String groupId, String artifactId, String version) { - Model model = new Model(); - model.setGroupId(groupId); - model.setArtifactId(artifactId); - model.setVersion(version); - return new MavenProject(model); - } - - @Test - public void shouldConvertProperties() { - MavenProject pom = new MavenProject(); - pom.setGroupId("foo"); - pom.setArtifactId("bar"); - pom.setVersion("1.0.1"); - pom.setName("Test"); - pom.setDescription("just test"); - pom.setFile(new File("/foo/pom.xml")); - pom.getBuild().setDirectory("target"); - ProjectDefinition project = ProjectDefinition.create(); - converter.merge(pom, project); - - Properties properties = project.getProperties(); - assertThat(properties.getProperty(CoreProperties.PROJECT_KEY_PROPERTY), is("foo:bar")); - assertThat(properties.getProperty(CoreProperties.PROJECT_VERSION_PROPERTY), is("1.0.1")); - assertThat(properties.getProperty(CoreProperties.PROJECT_NAME_PROPERTY), is("Test")); - assertThat(properties.getProperty(CoreProperties.PROJECT_DESCRIPTION_PROPERTY), is("just test")); - } - - @Test - public void moduleNameShouldEqualArtifactId() throws Exception { - File rootDir = new File(Resources.getResource("org/sonar/batch/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/").toURI()); - MavenProject parent = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/pom.xml", true); - MavenProject module1 = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module1/pom.xml", false); - MavenProject module2 = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module2/pom.xml", false); - - ProjectDefinition rootDef = converter.configure(Arrays.asList(parent, module1, module2), parent); - - assertThat(rootDef.getSubProjects().size(), Is.is(2)); - assertThat(rootDef.getKey(), Is.is("org.test:parent")); - assertNull(rootDef.getParent()); - assertThat(rootDef.getBaseDir(), is(rootDir)); - - ProjectDefinition module1Def = rootDef.getSubProjects().get(0); - assertThat(module1Def.getKey(), Is.is("org.test:module1")); - assertThat(module1Def.getParent(), Is.is(rootDef)); - assertThat(module1Def.getBaseDir(), Is.is(new File(rootDir, "module1"))); - assertThat(module1Def.getSubProjects().size(), Is.is(0)); - } - - @Test - public void moduleNameDifferentThanArtifactId() throws Exception { - File rootDir = new File(Resources.getResource("org/sonar/batch/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/").toURI()); - MavenProject parent = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/pom.xml", true); - MavenProject module1 = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path1/pom.xml", false); - MavenProject module2 = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path2/pom.xml", false); - - ProjectDefinition rootDef = converter.configure(Arrays.asList(parent, module1, module2), parent); - - assertThat(rootDef.getSubProjects().size(), is(2)); - assertThat(rootDef.getKey(), is("org.test:parent")); - assertNull(rootDef.getParent()); - assertThat(rootDef.getBaseDir(), is(rootDir)); - - ProjectDefinition module1Def = rootDef.getSubProjects().get(0); - assertThat(module1Def.getKey(), Is.is("org.test:module1")); - assertThat(module1Def.getParent(), Is.is(rootDef)); - assertThat(module1Def.getBaseDir(), Is.is(new File(rootDir, "path1"))); - assertThat(module1Def.getSubProjects().size(), Is.is(0)); - } - - @Test - public void should_find_module_with_maven_project_file_naming_different_from_pom_xml() throws Exception { - File rootDir = new File(Resources.getResource("org/sonar/batch/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/").toURI()); - MavenProject parent = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/pom.xml", true); - MavenProject module = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/module/pom_having_different_name.xml", false); - - ProjectDefinition rootDef = converter.configure(Arrays.asList(parent, module), parent); - - assertThat(rootDef.getSubProjects().size(), Is.is(1)); - assertThat(rootDef.getKey(), Is.is("org.test:parent")); - assertNull(rootDef.getParent()); - assertThat(rootDef.getBaseDir(), is(rootDir)); - - ProjectDefinition module1Def = rootDef.getSubProjects().get(0); - assertThat(module1Def.getKey(), Is.is("org.test:module")); - assertThat(module1Def.getParent(), Is.is(rootDef)); - assertThat(module1Def.getBaseDir(), Is.is(new File(rootDir, "module"))); - assertThat(module1Def.getSubProjects().size(), Is.is(0)); - } - - @Test - public void testSingleProjectWithoutModules() throws Exception { - File rootDir = new File(Resources.getResource("org/sonar/batch/maven/MavenProjectConverterTest/singleProjectWithoutModules/").toURI()); - MavenProject pom = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/singleProjectWithoutModules/pom.xml", true); - - ProjectDefinition rootDef = converter.configure(Arrays.asList(pom), pom); - - assertThat(rootDef.getKey(), is("org.test:parent")); - assertThat(rootDef.getSubProjects().size(), is(0)); - assertNull(rootDef.getParent()); - assertThat(rootDef.getBaseDir(), is(rootDir)); - } - - @Test - public void shouldConvertLinksToProperties() throws Exception { - MavenProject pom = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/projectWithLinks/pom.xml", true); - - ProjectDefinition rootDef = converter.configure(Arrays.asList(pom), pom); - - Properties props = rootDef.getProperties(); - assertThat(props.getProperty(CoreProperties.LINKS_HOME_PAGE)).isEqualTo("http://home.com"); - assertThat(props.getProperty(CoreProperties.LINKS_CI)).isEqualTo("http://ci.com"); - assertThat(props.getProperty(CoreProperties.LINKS_ISSUE_TRACKER)).isEqualTo("http://issues.com"); - assertThat(props.getProperty(CoreProperties.LINKS_SOURCES)).isEqualTo("http://sources.com"); - assertThat(props.getProperty(CoreProperties.LINKS_SOURCES_DEV)).isEqualTo("http://sources-dev.com"); - } - - @Test - public void shouldNotConvertLinksToPropertiesIfPropertyAlreadyDefined() throws Exception { - MavenProject pom = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/projectWithLinksAndProperties/pom.xml", true); - - ProjectDefinition rootDef = converter.configure(Arrays.asList(pom), pom); - - Properties props = rootDef.getProperties(); - - // Those properties have been fed by the POM elements <ciManagement>, <issueManagement>, ... - assertThat(props.getProperty(CoreProperties.LINKS_CI)).isEqualTo("http://ci.com"); - assertThat(props.getProperty(CoreProperties.LINKS_ISSUE_TRACKER)).isEqualTo("http://issues.com"); - assertThat(props.getProperty(CoreProperties.LINKS_SOURCES_DEV)).isEqualTo("http://sources-dev.com"); - - // ... but those ones have been overridden by <properties> in the POM - assertThat(props.getProperty(CoreProperties.LINKS_SOURCES)).isEqualTo("http://sources.com-OVERRIDEN-BY-PROPS"); - assertThat(props.getProperty(CoreProperties.LINKS_HOME_PAGE)).isEqualTo("http://home.com-OVERRIDEN-BY-PROPS"); - } - - @Test - public void shouldLoadSourceEncoding() throws Exception { - MavenProject pom = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/sourceEncoding/pom.xml", true); - - ProjectDefinition rootDef = converter.configure(Arrays.asList(pom), pom); - - assertThat(rootDef.getProperties().getProperty(CoreProperties.ENCODING_PROPERTY)).isEqualTo("Shift_JIS"); - } - - private MavenProject loadPom(String pomPath, boolean isRoot) throws URISyntaxException, IOException, XmlPullParserException { - File pomFile = new File(getClass().getResource(pomPath).toURI()); - Model model = new MavenXpp3Reader().read(new StringReader(FileUtils.readFileToString(pomFile))); - MavenProject pom = new MavenProject(model); - pom.setFile(pomFile); - pom.getBuild().setDirectory("target"); - pom.setExecutionRoot(isRoot); - return pom; - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/maven/SonarMavenProjectBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/maven/SonarMavenProjectBuilderTest.java deleted file mode 100644 index 6b0c8f26bee..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/maven/SonarMavenProjectBuilderTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.maven; - -import org.apache.maven.execution.MavenSession; -import org.apache.maven.project.MavenProject; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.sonar.api.batch.bootstrap.ProjectDefinition; - -import java.util.Arrays; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class SonarMavenProjectBuilderTest { - - @Test - public void testSimpleProject() { - MavenSession session = mock(MavenSession.class); - MavenProject rootProject = mock(MavenProject.class); - when(rootProject.isExecutionRoot()).thenReturn(true); - when(session.getSortedProjects()).thenReturn(Arrays.asList(rootProject)); - - MavenProjectConverter mavenProjectConverter = mock(MavenProjectConverter.class); - ProjectDefinition projectDefinition = ProjectDefinition.create(); - when(mavenProjectConverter.configure(any(List.class), any(MavenProject.class))).thenReturn(projectDefinition); - MavenProjectBootstrapper builder = new MavenProjectBootstrapper(session, mavenProjectConverter); - - assertThat(builder.bootstrap().getRoot()).isEqualTo(projectDefinition); - - ArgumentCaptor<List> argument = ArgumentCaptor.forClass(List.class); - verify(mavenProjectConverter).configure(argument.capture(), eq(rootProject)); - assertThat(argument.getValue()).contains(rootProject); - } - - @Test - public void testMultimoduleProject() { - MavenSession session = mock(MavenSession.class); - MavenProject rootProject = mock(MavenProject.class); - MavenProject module1 = mock(MavenProject.class); - MavenProject module2 = mock(MavenProject.class); - when(rootProject.isExecutionRoot()).thenReturn(true); - when(module1.isExecutionRoot()).thenReturn(false); - when(module2.isExecutionRoot()).thenReturn(false); - when(session.getSortedProjects()).thenReturn(Arrays.asList(module1, module2, rootProject)); - - MavenProjectConverter mavenProjectConverter = mock(MavenProjectConverter.class); - ProjectDefinition projectDefinition = ProjectDefinition.create(); - when(mavenProjectConverter.configure(any(List.class), any(MavenProject.class))).thenReturn(projectDefinition); - MavenProjectBootstrapper builder = new MavenProjectBootstrapper(session, mavenProjectConverter); - - assertThat(builder.bootstrap().getRoot()).isEqualTo(projectDefinition); - - ArgumentCaptor<List> argument = ArgumentCaptor.forClass(List.class); - verify(mavenProjectConverter).configure(argument.capture(), eq(rootProject)); - assertThat(argument.getValue()).contains(module1, module2, rootProject); - } - -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/qualitygate/GenerateQualityGateEventsTest.java b/sonar-batch/src/test/java/org/sonar/batch/qualitygate/GenerateQualityGateEventsTest.java index ec10ba85a5c..3986b3092f8 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/qualitygate/GenerateQualityGateEventsTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/qualitygate/GenerateQualityGateEventsTest.java @@ -32,7 +32,6 @@ import org.sonar.core.notification.NotificationManager; import org.sonar.api.resources.File; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; -import org.sonar.api.test.ProjectTestBuilder; import org.sonar.batch.protocol.Constants.EventCategory; import org.sonar.batch.report.EventCache; @@ -65,7 +64,7 @@ public class GenerateQualityGateEventsTest { notificationManager = mock(NotificationManager.class); eventCache = mock(EventCache.class); decorator = new GenerateQualityGateEvents(qualityGate, timeMachine, notificationManager, eventCache); - project = new ProjectTestBuilder().build(); + project = new Project("mygroup:myartifact"); when(context.getResource()).thenReturn(project); } |