Browse Source

Add nullability annotations to smoke-test/spring-boot-smoke-test-bootstrap-registry

See gh-46587
pull/46818/head
Moritz Halbritter 4 months ago
parent
commit
d63955d4f1
  1. 3
      smoke-test/spring-boot-smoke-test-bootstrap-registry/src/main/java/smoketest/bootstrapregistry/app/MySubversionClient.java
  2. 20
      smoke-test/spring-boot-smoke-test-bootstrap-registry/src/main/java/smoketest/bootstrapregistry/app/package-info.java
  3. 6
      smoke-test/spring-boot-smoke-test-bootstrap-registry/src/main/java/smoketest/bootstrapregistry/external/svn/SubversionBootstrap.java
  4. 6
      smoke-test/spring-boot-smoke-test-bootstrap-registry/src/main/java/smoketest/bootstrapregistry/external/svn/SubversionClient.java
  5. 8
      smoke-test/spring-boot-smoke-test-bootstrap-registry/src/main/java/smoketest/bootstrapregistry/external/svn/SubversionConfigDataLoader.java
  6. 10
      smoke-test/spring-boot-smoke-test-bootstrap-registry/src/main/java/smoketest/bootstrapregistry/external/svn/SubversionConfigDataResource.java
  7. 4
      smoke-test/spring-boot-smoke-test-bootstrap-registry/src/main/java/smoketest/bootstrapregistry/external/svn/SubversionServerCertificate.java
  8. 3
      smoke-test/spring-boot-smoke-test-bootstrap-registry/src/main/java/smoketest/bootstrapregistry/external/svn/package-info.java

3
smoke-test/spring-boot-smoke-test-bootstrap-registry/src/main/java/smoketest/bootstrapregistry/app/MySubversionClient.java

@ -16,12 +16,13 @@
package smoketest.bootstrapregistry.app; package smoketest.bootstrapregistry.app;
import org.jspecify.annotations.Nullable;
import smoketest.bootstrapregistry.external.svn.SubversionClient; import smoketest.bootstrapregistry.external.svn.SubversionClient;
import smoketest.bootstrapregistry.external.svn.SubversionServerCertificate; import smoketest.bootstrapregistry.external.svn.SubversionServerCertificate;
public class MySubversionClient extends SubversionClient { public class MySubversionClient extends SubversionClient {
public MySubversionClient(SubversionServerCertificate serverCertificate) { public MySubversionClient(@Nullable SubversionServerCertificate serverCertificate) {
super(serverCertificate); super(serverCertificate);
} }

20
smoke-test/spring-boot-smoke-test-bootstrap-registry/src/main/java/smoketest/bootstrapregistry/app/package-info.java

@ -0,0 +1,20 @@
/*
* Copyright 2012-present 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NullMarked
package smoketest.bootstrapregistry.app;
import org.jspecify.annotations.NullMarked;

6
smoke-test/spring-boot-smoke-test-bootstrap-registry/src/main/java/smoketest/bootstrapregistry/external/svn/SubversionBootstrap.java vendored

@ -18,6 +18,8 @@ package smoketest.bootstrapregistry.external.svn;
import java.util.function.Function; import java.util.function.Function;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.BootstrapContext; import org.springframework.boot.BootstrapContext;
import org.springframework.boot.BootstrapRegistryInitializer; import org.springframework.boot.BootstrapRegistryInitializer;
@ -38,13 +40,13 @@ public final class SubversionBootstrap {
* @return a {@link BootstrapRegistryInitializer} instance * @return a {@link BootstrapRegistryInitializer} instance
*/ */
public static BootstrapRegistryInitializer withCustomClient( public static BootstrapRegistryInitializer withCustomClient(
Function<SubversionServerCertificate, SubversionClient> clientFactory) { Function<@Nullable SubversionServerCertificate, SubversionClient> clientFactory) {
return (registry) -> registry.register(SubversionClient.class, return (registry) -> registry.register(SubversionClient.class,
(bootstrapContext) -> createSubversionClient(bootstrapContext, clientFactory)); (bootstrapContext) -> createSubversionClient(bootstrapContext, clientFactory));
} }
private static SubversionClient createSubversionClient(BootstrapContext bootstrapContext, private static SubversionClient createSubversionClient(BootstrapContext bootstrapContext,
Function<SubversionServerCertificate, SubversionClient> clientFactory) { Function<@Nullable SubversionServerCertificate, SubversionClient> clientFactory) {
return clientFactory.apply(bootstrapContext.get(SubversionServerCertificate.class)); return clientFactory.apply(bootstrapContext.get(SubversionServerCertificate.class));
} }

6
smoke-test/spring-boot-smoke-test-bootstrap-registry/src/main/java/smoketest/bootstrapregistry/external/svn/SubversionClient.java vendored

@ -16,6 +16,8 @@
package smoketest.bootstrapregistry.external.svn; package smoketest.bootstrapregistry.external.svn;
import org.jspecify.annotations.Nullable;
/** /**
* A client that can connect to a subversion server. * A client that can connect to a subversion server.
* *
@ -23,9 +25,9 @@ package smoketest.bootstrapregistry.external.svn;
*/ */
public class SubversionClient { public class SubversionClient {
private final SubversionServerCertificate serverCertificate; private final @Nullable SubversionServerCertificate serverCertificate;
public SubversionClient(SubversionServerCertificate serverCertificate) { public SubversionClient(@Nullable SubversionServerCertificate serverCertificate) {
this.serverCertificate = serverCertificate; this.serverCertificate = serverCertificate;
} }

8
smoke-test/spring-boot-smoke-test-bootstrap-registry/src/main/java/smoketest/bootstrapregistry/external/svn/SubversionConfigDataLoader.java vendored

@ -30,6 +30,7 @@ import org.springframework.boot.context.config.ConfigDataLocationNotFoundExcepti
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource; import org.springframework.core.env.PropertySource;
import org.springframework.util.Assert;
/** /**
* {@link ConfigDataLoader} for subversion. * {@link ConfigDataLoader} for subversion.
@ -55,15 +56,16 @@ class SubversionConfigDataLoader implements ConfigDataLoader<SubversionConfigDat
context.getBootstrapContext() context.getBootstrapContext()
.registerIfAbsent(SubversionServerCertificate.class, InstanceSupplier.of(resource.getServerCertificate())); .registerIfAbsent(SubversionServerCertificate.class, InstanceSupplier.of(resource.getServerCertificate()));
SubversionClient client = context.getBootstrapContext().get(SubversionClient.class); SubversionClient client = context.getBootstrapContext().get(SubversionClient.class);
Assert.state(client != null, "'client' must not be null");
String loaded = client.load(resource.getLocation()); String loaded = client.load(resource.getLocation());
PropertySource<?> propertySource = new MapPropertySource("svn", Collections.singletonMap("svn", loaded)); PropertySource<?> propertySource = new MapPropertySource("svn", Collections.singletonMap("svn", loaded));
return new ConfigData(Collections.singleton(propertySource)); return new ConfigData(Collections.singleton(propertySource));
} }
private static void onBootstrapContextClosed(BootstrapContextClosedEvent event) { private static void onBootstrapContextClosed(BootstrapContextClosedEvent event) {
event.getApplicationContext() SubversionClient subversionClient = event.getBootstrapContext().get(SubversionClient.class);
.getBeanFactory() Assert.state(subversionClient != null, "'subversionClient' must not be null");
.registerSingleton("subversionClient", event.getBootstrapContext().get(SubversionClient.class)); event.getApplicationContext().getBeanFactory().registerSingleton("subversionClient", subversionClient);
} }
} }

10
smoke-test/spring-boot-smoke-test-bootstrap-registry/src/main/java/smoketest/bootstrapregistry/external/svn/SubversionConfigDataResource.java vendored

@ -16,6 +16,8 @@
package smoketest.bootstrapregistry.external.svn; package smoketest.bootstrapregistry.external.svn;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.context.config.ConfigDataResource; import org.springframework.boot.context.config.ConfigDataResource;
/** /**
@ -27,9 +29,9 @@ class SubversionConfigDataResource extends ConfigDataResource {
private final String location; private final String location;
private final SubversionServerCertificate serverCertificate; private final @Nullable SubversionServerCertificate serverCertificate;
SubversionConfigDataResource(String location, String serverCertificate) { SubversionConfigDataResource(String location, @Nullable String serverCertificate) {
this.location = location; this.location = location;
this.serverCertificate = SubversionServerCertificate.of(serverCertificate); this.serverCertificate = SubversionServerCertificate.of(serverCertificate);
} }
@ -38,12 +40,12 @@ class SubversionConfigDataResource extends ConfigDataResource {
return this.location; return this.location;
} }
SubversionServerCertificate getServerCertificate() { @Nullable SubversionServerCertificate getServerCertificate() {
return this.serverCertificate; return this.serverCertificate;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }

4
smoke-test/spring-boot-smoke-test-bootstrap-registry/src/main/java/smoketest/bootstrapregistry/external/svn/SubversionServerCertificate.java vendored

@ -16,6 +16,8 @@
package smoketest.bootstrapregistry.external.svn; package smoketest.bootstrapregistry.external.svn;
import org.jspecify.annotations.Nullable;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
@ -36,7 +38,7 @@ public class SubversionServerCertificate {
return this.data; return this.data;
} }
public static SubversionServerCertificate of(String data) { public static @Nullable SubversionServerCertificate of(@Nullable String data) {
return StringUtils.hasText(data) ? new SubversionServerCertificate(data) : null; return StringUtils.hasText(data) ? new SubversionServerCertificate(data) : null;
} }

3
smoke-test/spring-boot-smoke-test-bootstrap-registry/src/main/java/smoketest/bootstrapregistry/external/svn/package-info.java vendored

@ -17,4 +17,7 @@
/** /**
* An example of a hypothetical library that supports subversion. * An example of a hypothetical library that supports subversion.
*/ */
@NullMarked
package smoketest.bootstrapregistry.external.svn; package smoketest.bootstrapregistry.external.svn;
import org.jspecify.annotations.NullMarked;

Loading…
Cancel
Save