mirror of
https://gitee.com/dcren/initializr.git
synced 2026-02-25 21:22:58 +08:00
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:
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user