use of org.apache.maven.model.Scm in project m2e-core by eclipse-m2e.
the class MavenProjectPomScanner method run.
public void run(IProgressMonitor monitor) throws InterruptedException {
for (Dependency d : dependencies) {
if (monitor.isCanceled()) {
throw new InterruptedException();
}
try {
Model model = resolveModel(d.getGroupId(), d.getArtifactId(), d.getVersion(), monitor);
if (model == null) {
String msg = "Can't resolve " + d.getArtifactId();
Exception error = new Exception(msg);
log.error(msg, error);
addError(error);
continue;
}
Scm scm = resolveScm(model, monitor);
if (scm == null) {
String msg = "No SCM info for " + d.getArtifactId();
Exception error = new Exception(msg);
log.error(msg, error);
addError(error);
continue;
}
String tag = scm.getTag();
log.info(d.getArtifactId());
log.info("Connection: {}", scm.getConnection());
log.info(" dev: {}", scm.getDeveloperConnection());
log.info(" url: {}", scm.getUrl());
log.info(" tag: {}", tag);
String connection;
if (developer) {
connection = scm.getDeveloperConnection();
if (connection == null) {
String msg = d.getArtifactId() + " doesn't specify developer SCM connection";
Exception error = new Exception(msg);
log.error(msg, error);
addError(error);
continue;
}
} else {
connection = scm.getConnection();
if (connection == null) {
String msg = d.getArtifactId() + " doesn't specify SCM connection";
Exception error = new Exception(msg);
log.error(msg, error);
addError(error);
continue;
}
}
if (connection.endsWith("/")) {
// $NON-NLS-1$
connection = connection.substring(0, connection.length() - 1);
}
// $NON-NLS-1$
int n = connection.lastIndexOf("/");
// $NON-NLS-1$
String label = (n == -1 ? connection : connection.substring(n)) + "/" + IMavenConstants.POM_FILE_NAME;
addProject(new MavenProjectScmInfo(label, model, null, tag, connection, connection));
} catch (Exception ex) {
addError(ex);
String msg = "Error reading " + d.getArtifactId();
log.error(msg, ex);
}
}
}
use of org.apache.maven.model.Scm in project buck by facebook.
the class Pom method merge.
private Model merge(Model first, @Nullable Model second) {
if (second == null) {
return first;
}
Model model = first.clone();
//---- Values from ModelBase
List<String> modules = second.getModules();
if (modules != null) {
for (String module : modules) {
model.addModule(module);
}
}
DistributionManagement distributionManagement = second.getDistributionManagement();
if (distributionManagement != null) {
model.setDistributionManagement(distributionManagement);
}
Properties properties = second.getProperties();
if (properties != null) {
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
model.addProperty((String) entry.getKey(), (String) entry.getValue());
}
}
DependencyManagement dependencyManagement = second.getDependencyManagement();
if (dependencyManagement != null) {
model.setDependencyManagement(dependencyManagement);
}
List<Dependency> dependencies = second.getDependencies();
if (dependencies != null) {
for (Dependency dependency : dependencies) {
model.addDependency(dependency);
}
}
List<Repository> repositories = second.getRepositories();
if (repositories != null) {
for (Repository repository : repositories) {
model.addRepository(repository);
}
}
List<Repository> pluginRepositories = second.getPluginRepositories();
if (pluginRepositories != null) {
for (Repository pluginRepository : pluginRepositories) {
model.addPluginRepository(pluginRepository);
}
}
// Ignore reports, reporting, and locations
//----- From Model
Parent parent = second.getParent();
if (parent != null) {
model.setParent(parent);
}
Organization organization = second.getOrganization();
if (organization != null) {
model.setOrganization(organization);
}
List<License> licenses = second.getLicenses();
Set<String> currentLicenseUrls = new HashSet<>();
if (model.getLicenses() != null) {
for (License license : model.getLicenses()) {
currentLicenseUrls.add(license.getUrl());
}
}
if (licenses != null) {
for (License license : licenses) {
if (!currentLicenseUrls.contains(license.getUrl())) {
model.addLicense(license);
currentLicenseUrls.add(license.getUrl());
}
}
}
List<Developer> developers = second.getDevelopers();
Set<String> currentDevelopers = new HashSet<>();
if (model.getDevelopers() != null) {
for (Developer developer : model.getDevelopers()) {
currentDevelopers.add(developer.getName());
}
}
if (developers != null) {
for (Developer developer : developers) {
if (!currentDevelopers.contains(developer.getName())) {
model.addDeveloper(developer);
currentDevelopers.add(developer.getName());
}
}
}
List<Contributor> contributors = second.getContributors();
Set<String> currentContributors = new HashSet<>();
if (model.getContributors() != null) {
for (Contributor contributor : model.getContributors()) {
currentDevelopers.add(contributor.getName());
}
}
if (contributors != null) {
for (Contributor contributor : contributors) {
if (!currentContributors.contains(contributor.getName())) {
model.addContributor(contributor);
currentContributors.add(contributor.getName());
}
}
}
List<MailingList> mailingLists = second.getMailingLists();
if (mailingLists != null) {
for (MailingList mailingList : mailingLists) {
model.addMailingList(mailingList);
}
}
Prerequisites prerequisites = second.getPrerequisites();
if (prerequisites != null) {
model.setPrerequisites(prerequisites);
}
Scm scm = second.getScm();
if (scm != null) {
model.setScm(scm);
}
String url = second.getUrl();
if (url != null) {
model.setUrl(url);
}
String description = second.getDescription();
if (description != null) {
model.setDescription(description);
}
IssueManagement issueManagement = second.getIssueManagement();
if (issueManagement != null) {
model.setIssueManagement(issueManagement);
}
CiManagement ciManagement = second.getCiManagement();
if (ciManagement != null) {
model.setCiManagement(ciManagement);
}
Build build = second.getBuild();
if (build != null) {
model.setBuild(build);
}
List<Profile> profiles = second.getProfiles();
Set<String> currentProfileIds = new HashSet<>();
if (model.getProfiles() != null) {
for (Profile profile : model.getProfiles()) {
currentProfileIds.add(profile.getId());
}
}
if (profiles != null) {
for (Profile profile : profiles) {
if (!currentProfileIds.contains(profile.getId())) {
model.addProfile(profile);
currentProfileIds.add(profile.getId());
}
}
}
return model;
}
use of org.apache.maven.model.Scm in project fabric8-maven-plugin by fabric8io.
the class MavenScmEnricher method getAnnotations.
@Override
public Map<String, String> getAnnotations(Kind kind) {
Map<String, String> annotations = new HashMap<>();
if (kind.isController() || kind == Kind.SERVICE) {
MavenProject rootProject = getProject();
if (hasScm(rootProject)) {
Scm scm = rootProject.getScm();
String connectionUrl = scm.getConnection();
String devConnectionUrl = scm.getDeveloperConnection();
String url = scm.getUrl();
String tag = scm.getTag();
if (StringUtils.isNotEmpty(connectionUrl)) {
annotations.put(SCM_CONNECTION, connectionUrl);
}
if (StringUtils.isNotEmpty(devConnectionUrl)) {
annotations.put(SCM_DEVELOPER_CONNECTION, devConnectionUrl);
}
if (StringUtils.isNotEmpty(tag)) {
annotations.put(SCM_TAG, tag);
}
if (StringUtils.isNotEmpty(url)) {
annotations.put(SCM_URL, url);
}
}
}
return annotations;
}
use of org.apache.maven.model.Scm in project fabric8-maven-plugin by fabric8io.
the class MavenScmEnricherTest method testMavenScmAll.
@Test
public void testMavenScmAll() {
final MavenProject project = new MavenProject();
final Scm scm = new Scm();
scm.setConnection("scm:git:git://github.com/fabric8io/fabric8-maven-plugin.git");
scm.setDeveloperConnection("scm:git:git://github.com/fabric8io/fabric8-maven-plugin.git");
scm.setTag("HEAD");
scm.setUrl("git://github.com/fabric8io/fabric8-maven-plugin.git");
project.setScm(scm);
// Setup mock behaviour
new Expectations() {
{
{
context.getProject();
result = project;
}
}
};
MavenScmEnricher mavenScmEnricher = new MavenScmEnricher(context);
KubernetesListBuilder builder = new KubernetesListBuilder().withItems(new DeploymentBuilder().withNewMetadata().withName("foo").endMetadata().build());
mavenScmEnricher.create(PlatformMode.kubernetes, builder);
Map<String, String> scmAnnotations = builder.buildFirstItem().getMetadata().getAnnotations();
assertNotNull(scmAnnotations);
Assert.assertEquals(2, scmAnnotations.size());
assertEquals("HEAD", scmAnnotations.get(Fabric8Annotations.SCM_TAG.value()));
assertEquals("git://github.com/fabric8io/fabric8-maven-plugin.git", scmAnnotations.get(Fabric8Annotations.SCM_URL.value()));
}
use of org.apache.maven.model.Scm in project fabric8-maven-plugin by fabric8io.
the class MavenScmEnricherTest method testMavenScmOnlyUrl.
@Test
public void testMavenScmOnlyUrl() {
final MavenProject project = new MavenProject();
final Scm scm = new Scm();
scm.setDeveloperConnection("scm:git:git://github.com/fabric8io/fabric8-maven-plugin.git");
project.setScm(scm);
// Setup mock behaviour
new Expectations() {
{
{
context.getProject();
result = project;
}
}
};
MavenScmEnricher mavenScmEnricher = new MavenScmEnricher(context);
KubernetesListBuilder builder = new KubernetesListBuilder().withItems(new DeploymentBuilder().withNewMetadata().withName("foo").endMetadata().build());
mavenScmEnricher.create(PlatformMode.kubernetes, builder);
Map<String, String> scmAnnotations = builder.buildFirstItem().getMetadata().getAnnotations();
assertNotNull(scmAnnotations);
Assert.assertEquals(1, scmAnnotations.size());
assertEquals("HEAD", scmAnnotations.get(Fabric8Annotations.SCM_TAG.value()));
}
Aggregations