Skip to content

Commit

Permalink
Upgrade to Spring Java Format 0.0.39
Browse files Browse the repository at this point in the history
Closes gh-358
  • Loading branch information
wilkinsona committed Jul 12, 2023
1 parent 5e5ddd3 commit bad9f8a
Show file tree
Hide file tree
Showing 21 changed files with 128 additions and 101 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
id 'java-gradle-plugin'
id 'maven-publish'

id 'io.spring.javaformat' version '0.0.34'
id 'io.spring.javaformat' version '0.0.39'
id 'io.spring.nohttp' version '0.0.10'
id 'org.asciidoctor.jvm.convert' version '3.3.2'
}
Expand Down Expand Up @@ -65,7 +65,7 @@ def mavenRepackJar = tasks.register("mavenRepackJar", Jar) { repackJar ->
dependencies {
asciidoctorExt 'io.spring.asciidoctor.backends:spring-asciidoctor-backends:0.0.4'

checkstyle 'io.spring.javaformat:spring-javaformat-checkstyle:0.0.34'
checkstyle 'io.spring.javaformat:spring-javaformat-checkstyle:0.0.39'

implementation(files(mavenRepackJar))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class DependencyManagementPlugin implements Plugin<Project> {
public void apply(Project project) {
InternalComponents internalComponents = new InternalComponents(project);
DependencyManagementExtension dependencyManagementExtension = internalComponents
.getDependencyManagementExtension();
.getDependencyManagementExtension();
project.getExtensions().add("dependencyManagement", dependencyManagementExtension);
internalComponents.createDependencyManagementReportTask("dependencyManagement");
project.getConfigurations().all(internalComponents.getImplicitDependencyManagementCollector());
Expand All @@ -47,19 +47,21 @@ public void apply(Project project) {
private void configurePomCustomization(Project project,
DependencyManagementExtension dependencyManagementExtension) {
PomDependencyManagementConfigurer pomConfigurer = dependencyManagementExtension.getPomConfigurer();
project.getPlugins().withType(MavenPublishPlugin.class,
(mavenPublishPlugin) -> configurePublishingExtension(project, pomConfigurer));
project.getPlugins()
.withType(MavenPublishPlugin.class,
(mavenPublishPlugin) -> configurePublishingExtension(project, pomConfigurer));
}

private void configurePublishingExtension(Project project, PomDependencyManagementConfigurer extension) {
project.getExtensions().configure(PublishingExtension.class,
(publishingExtension) -> configurePublications(publishingExtension, extension));
project.getExtensions()
.configure(PublishingExtension.class,
(publishingExtension) -> configurePublications(publishingExtension, extension));
}

private void configurePublications(PublishingExtension publishingExtension,
PomDependencyManagementConfigurer extension) {
publishingExtension.getPublications().withType(MavenPublication.class,
(mavenPublication) -> mavenPublication.getPom().withXml(extension));
publishingExtension.getPublications()
.withType(MavenPublication.class, (mavenPublication) -> mavenPublication.getPom().withXml(extension));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public DependencyManagementApplier(Project project, DependencyManagementContaine
public void execute(Configuration configuration) {
logger.info("Applying dependency management to configuration '{}' in project '{}'", configuration.getName(),
this.project.getName());
configuration.getIncoming().beforeResolve((resolvableDependencies) -> this.dependencyManagementContainer
configuration.getIncoming()
.beforeResolve((resolvableDependencies) -> this.dependencyManagementContainer
.getManagedVersionsForConfiguration(configuration));
VersionConfiguringAction versionConfiguringAction = new VersionConfiguringAction(this.project,
this.dependencyManagementContainer, configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
class ExclusionResolver {

private static final Set<String> IGNORED_SCOPES = Collections
.unmodifiableSet(new HashSet<>(Arrays.asList("provided", "test")));
.unmodifiableSet(new HashSet<>(Arrays.asList("provided", "test")));

private final Map<String, Exclusions> exclusionsCache = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void add(String dependency, Collection<Exclusion> exclusionsForDependency) {
return;
}
this.exclusionsByDependency.computeIfAbsent(dependency, (key) -> new HashSet<>())
.addAll(exclusionsForDependency);
.addAll(exclusionsForDependency);
}

void addAll(Exclusions exclusions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
final class Versions {

private static final Set<String> DYNAMIC_PREFIXES = Collections
.unmodifiableSet(new HashSet<>(Arrays.asList("latest.", "[", "]", "(")));
.unmodifiableSet(new HashSet<>(Arrays.asList("latest.", "[", "]", "(")));

private Versions() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,13 @@ private io.spring.gradle.dependencymanagement.org.apache.maven.model.building.Mo
private FileModelSource resolveModel(String coordinates, Consumer<String> versionHandler) {
Dependency dependency = this.project.getDependencies().create(coordinates);
Configuration configuration = this.configurationContainer.newConfiguration(dependency);
versionHandler.accept(configuration.getResolvedConfiguration().getResolvedArtifacts().iterator().next()
.getModuleVersion().getId().getVersion());
versionHandler.accept(configuration.getResolvedConfiguration()
.getResolvedArtifacts()
.iterator()
.next()
.getModuleVersion()
.getId()
.getVersion());
return new FileModelSource(configuration.resolve().iterator().next());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ public MavenPomResolver(Project project, DependencyManagementConfigurationContai

@Override
public List<Pom> resolvePomsLeniently(List<PomReference> pomReferences) {
return createPoms(createConfiguration(pomReferences).getResolvedConfiguration().getLenientConfiguration()
.getArtifacts(Specs.SATISFIES_ALL), pomReferences, new MapPropertySource(Collections.emptyMap()));
return createPoms(createConfiguration(pomReferences).getResolvedConfiguration()
.getLenientConfiguration()
.getArtifacts(Specs.SATISFIES_ALL), pomReferences, new MapPropertySource(Collections.emptyMap()));
}

@Override
Expand Down Expand Up @@ -146,17 +147,21 @@ private List<Dependency> getManagedDependencies(Model model) {
if (model.getDependencyManagement() == null || model.getDependencyManagement().getDependencies() == null) {
return Collections.emptyList();
}
return model.getDependencyManagement().getDependencies().stream().map(this::createDependency)
.collect(Collectors.toList());
return model.getDependencyManagement()
.getDependencies()
.stream()
.map(this::createDependency)
.collect(Collectors.toList());
}

private Dependency createDependency(
io.spring.gradle.dependencymanagement.org.apache.maven.model.Dependency dependency) {
Set<Exclusion> exclusions = new LinkedHashSet<>();
if (dependency.getExclusions() != null) {
dependency.getExclusions().stream()
.map((exclusion) -> new Exclusion(exclusion.getGroupId(), exclusion.getArtifactId()))
.forEach(exclusions::add);
dependency.getExclusions()
.stream()
.map((exclusion) -> new Exclusion(exclusion.getGroupId(), exclusion.getArtifactId()))
.forEach(exclusions::add);
}
Coordinates coordinates = new Coordinates(dependency.getGroupId(), dependency.getArtifactId(),
dependency.getVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ public CompositePropertySource(PropertySource... delegates) {

@Override
public Object getProperty(String name) {
return this.delegates.stream().map((delegate) -> delegate.getProperty(name)).filter(Objects::nonNull)
.findFirst().orElse(null);
return this.delegates.stream()
.map((delegate) -> delegate.getProperty(name))
.filter(Objects::nonNull)
.findFirst()
.orElse(null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ public void setDependencyManagementContainer(DependencyManagementContainer depen
public void report() {
this.renderer.startProject(getProject());
Map<String, String> globalManagedVersions = this.dependencyManagementContainer
.getManagedVersionsForConfiguration(null);
.getManagedVersionsForConfiguration(null);
this.renderer.renderGlobalManagedVersions(globalManagedVersions);
Set<Configuration> configurations = new TreeSet<>(Comparator.comparing(Configuration::getName));
configurations.addAll(getProject().getConfigurations());
for (Configuration configuration : configurations) {
Map<String, String> managedVersions = this.dependencyManagementContainer
.getManagedVersionsForConfiguration(configuration);
.getManagedVersionsForConfiguration(configuration);
this.renderer.renderConfigurationManagedVersions(managedVersions, configuration, globalManagedVersions);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void bomWithNoDependencyManagementCanBeImportedAndItsPropertiesUsed() {
void springCloudStarterParentBomCanBeImportedAndUsedForDependencyManagement() {
this.gradleBuild.runner().withArguments("managedVersions").build();
assertThat(readLines("managed-versions.txt"))
.contains("org.springframework.cloud:spring-cloud-starter-eureka-server -> 1.0.0.M3");
.contains("org.springframework.cloud:spring-cloud-starter-eureka-server -> 1.0.0.M3");
}

@Test
Expand Down Expand Up @@ -352,7 +352,7 @@ void managedVersionsOfAConfigurationCanBeAccessed() {
void dependencyWithAMissingComponentInItsStringIdentifierProducesAHelpfulError() {
String output = this.gradleBuild.runner().withArguments("build").buildAndFail().getOutput();
assertThat(output)
.contains("Dependency identifier 'a:1.0' is malformed. The required form is 'group:name:version'");
.contains("Dependency identifier 'a:1.0' is malformed. The required form is 'group:name:version'");
}

@Test
Expand All @@ -365,7 +365,7 @@ void dependencyWithAMissingComponentInItsMapIdentifierProducesAHelpfulError() {
void dynamicVersionIsNotAddedToDependencyManagement() {
this.gradleBuild.runner().withArguments("managedVersions").build();
assertThat(readLines("managed-versions.txt"))
.noneMatch((line) -> line.startsWith("commons-logging:commons-logging ->"));
.noneMatch((line) -> line.startsWith("commons-logging:commons-logging ->"));
}

@Test
Expand Down Expand Up @@ -501,8 +501,8 @@ private void writeLines(Path path, String... lines) {

private List<String> readLines(String filename) {
try {
return Files.readAllLines(
this.gradleBuild.runner().getProjectDir().toPath().resolve(Paths.get("build", filename)));
return Files
.readAllLines(this.gradleBuild.runner().getProjectDir().toPath().resolve(Paths.get("build", filename)));
}
catch (IOException ex) {
throw new RuntimeException(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void whenPluginIsAppliedThenDependencyManagementExtensionIsAdded() {
void whenPluginIsAppliedThenPomConfigurerIsAvailable() {
this.project.getPlugins().apply(DependencyManagementPlugin.class);
assertThat(this.project.getExtensions().findByType(DependencyManagementExtension.class).getPomConfigurer())
.isNotNull();
.isNotNull();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ public void beforeEach(ExtensionContext context) throws Exception {
Store store = context.getStore(Namespace.create(GradleBuild.class));
Project project = new Project();
store.put("project", project);
this.runner = GradleRunner.create().withPluginClasspath().withProjectDir(project.dir.toFile())
.withArguments("-PmavenRepo=" + new File("src/test/resources/maven-repo").getAbsolutePath());
this.runner = GradleRunner.create()
.withPluginClasspath()
.withProjectDir(project.dir.toFile())
.withArguments("-PmavenRepo=" + new File("src/test/resources/maven-repo").getAbsolutePath());
Class<?> testClass = context.getRequiredTestClass();
String methodName = context.getRequiredTestMethod().getName();
InputStream input = testClass.getResourceAsStream(initials(testClass) + "/" + methodName + ".gradle");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ class GradleVersionCompatibilityIntegrationTests {
@ParameterizedTest(name = "Gradle {0}")
@MethodSource("gradleVersions")
void pluginIsCompatible(String gradleVersion) {
BuildResult result = this.gradleBuild.runner().withGradleVersion(gradleVersion).withArguments("resolve")
.build();
BuildResult result = this.gradleBuild.runner()
.withGradleVersion(gradleVersion)
.withArguments("resolve")
.build();
assertThat(result.task(":resolve").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ void usingImportedPropertiesDoesNotPreventFurtherConfigurationOfThePublishingExt
}

private NodeAssert generatedPom() {
return new NodeAssert(this.gradleBuild.runner().getProjectDir().toPath()
.resolve(Paths.get("build", "publications", "mavenJava", "pom-default.xml")));
return new NodeAssert(this.gradleBuild.runner()
.getProjectDir()
.toPath()
.resolve(Paths.get("build", "publications", "mavenJava", "pom-default.xml")));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private static Document read(Path xmlFile) {
private static Document read(String xmlContent) {
try {
return FACTORY.newDocumentBuilder()
.parse(new ByteArrayInputStream(xmlContent.getBytes(StandardCharsets.UTF_8)));
.parse(new ByteArrayInputStream(xmlContent.getBytes(StandardCharsets.UTF_8)));
}
catch (Exception ex) {
throw new RuntimeException(ex);
Expand Down
Loading

0 comments on commit bad9f8a

Please sign in to comment.