org.sonar.mojo.bootstrap.BootstrapPomBuilder Maven / Gradle / Ivy
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.mojo.bootstrap;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.model.Repository;
import org.apache.maven.project.MavenProject;
import org.sonar.commons.ServerHttpClient;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class BootstrapPomBuilder {
private ServerHttpClient server;
private static final String REPOSITORY__ID = "sonar-runtime";
public BootstrapPomBuilder(ServerHttpClient server) {
this.server = server;
}
public MavenProject build(ArtifactRepositoryFactory repoFactory, MavenProject project) throws IOException {
//MavenProject project = (MavenProject) project.clone();
return addInternalDependencies(repoFactory, project);
}
private MavenProject addInternalDependencies(ArtifactRepositoryFactory repoFactory, MavenProject project) throws IOException {
checkIfInternalRepositoryIsAlreadyDefined(project);
List pluginRepositories = new ArrayList();
ArtifactRepository repository = repoFactory.createArtifactRepository("sonar-runtime", server.getMavenRepositoryUrl(),
new DefaultRepositoryLayout(),
new ArtifactRepositoryPolicy(false, "never", "ignore"), // snapshot
new ArtifactRepositoryPolicy(true, "never", "ignore")); // release
pluginRepositories.add(repository);
pluginRepositories.addAll(project.getPluginArtifactRepositories());
project.setPluginArtifactRepositories(pluginRepositories);
List artifactRepositories = new ArrayList();
artifactRepositories.add(repository);
artifactRepositories.addAll(project.getRemoteArtifactRepositories());
project.setRemoteArtifactRepositories(artifactRepositories);
return project;
}
private void checkIfInternalRepositoryIsAlreadyDefined(MavenProject project) {
for (Repository repository : (List) project.getRepositories()) {
if (REPOSITORY__ID.equals(repository.getId())) {
throw new RuntimeException("Pom already defines a repository with id '" + REPOSITORY__ID + "', please remove it.");
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy