Handle both snapshots and releases enabled flags in Maven Pom

This commit improves the handling of repositories with Maven.
Previously, the writer wrongly assumed that the default for releases
and snapshots are true and false respectively. However, both defaults
are true which means that snapshots repository are considered for
releases, and releases repositories are considered for snapshots.

MavenRepository has now separate flags for those and the writer makes
sure to only update the `enabled` flag if the chosen value is not
true. This doesn't increase the content for repository definitions
while offering better performance for dependencies resolution.

Closes gh-1226
This commit is contained in:
Stephane Nicoll
2021-04-20 20:20:41 +02:00
parent 88d6e79fca
commit 17df3b9b5d
23 changed files with 303 additions and 84 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -230,7 +230,16 @@ public class InitializrMetadataTestBuilder {
return this;
}
public InitializrMetadataTestBuilder addRepository(String id, String name, String url, boolean snapshotsEnabled) {
public InitializrMetadataTestBuilder addReleasesRepository(String id, String name, String url) {
return addRepository(id, name, url, true, false);
}
public InitializrMetadataTestBuilder addSnapshotsRepository(String id, String name, String url) {
return addRepository(id, name, url, false, true);
}
public InitializrMetadataTestBuilder addRepository(String id, String name, String url, boolean releasesEnabled,
boolean snapshotsEnabled) {
this.builder.withCustomizer((it) -> {
Repository repo = new Repository();
repo.setName(name);
@@ -240,6 +249,7 @@ public class InitializrMetadataTestBuilder {
catch (MalformedURLException ex) {
throw new IllegalArgumentException("Cannot create URL", ex);
}
repo.setReleasesEnabled(releasesEnabled);
repo.setSnapshotsEnabled(snapshotsEnabled);
it.getConfiguration().getEnv().getRepositories().put(id, repo);
});

View File

@@ -432,6 +432,14 @@ public class MavenBuildAssert extends AbstractTextAssert<MavenBuildAssert> {
throw new IllegalStateException("Cannot parse URL", ex);
}
}
NodeList releases = element.getElementsByTagName("releases");
if (releases.getLength() > 0) {
Element releasesElement = (Element) releases.item(0);
NodeList releasesEnabled = releasesElement.getElementsByTagName("enabled");
if (releasesEnabled.getLength() > 0) {
repository.setReleasesEnabled("true".equals(releasesEnabled.item(0).getTextContent()));
}
}
NodeList snapshots = element.getElementsByTagName("snapshots");
if (snapshots.getLength() > 0) {
Element snapshotsElement = (Element) snapshots.item(0);