Merge branch '3.1.x'

This commit is contained in:
Phillip Webb
2023-08-13 19:15:56 -07:00
11 changed files with 51 additions and 66 deletions

View File

@@ -96,20 +96,15 @@ class ImportAutoConfigurationImportSelector extends AutoConfigurationImportSelec
if (classes.length > 0) {
return Arrays.asList(classes);
}
Collection<String> factoryNames = loadFactoryNames(source);
return factoryNames.stream().map((name) -> {
if (name.startsWith(OPTIONAL_PREFIX)) {
name = name.substring(OPTIONAL_PREFIX.length());
if (!present(name)) {
return null;
}
}
return name;
}).filter(Objects::nonNull).toList();
return loadFactoryNames(source).stream().map(this::mapFactoryName).filter(Objects::nonNull).toList();
}
protected Collection<String> loadFactoryNames(Class<?> source) {
return ImportCandidates.load(source, getBeanClassLoader()).getCandidates();
private String mapFactoryName(String name) {
if (!name.startsWith(OPTIONAL_PREFIX)) {
return name;
}
name = name.substring(OPTIONAL_PREFIX.length());
return (!present(name)) ? null : name;
}
private boolean present(String className) {
@@ -117,6 +112,10 @@ class ImportAutoConfigurationImportSelector extends AutoConfigurationImportSelec
return new ClassPathResource(resourcePath).exists();
}
protected Collection<String> loadFactoryNames(Class<?> source) {
return ImportCandidates.load(source, getBeanClassLoader()).getCandidates();
}
@Override
protected Set<String> getExclusions(AnnotationMetadata metadata, AnnotationAttributes attributes) {
Set<String> exclusions = new LinkedHashSet<>();

View File

@@ -113,13 +113,11 @@ public class JobLauncherApplicationRunner
@Override
public void afterPropertiesSet() {
if (this.jobs.size() > 1 && !StringUtils.hasText(this.jobName)) {
throw new IllegalArgumentException("Job name must be specified in case of multiple jobs");
}
Assert.isTrue(this.jobs.size() <= 1 || StringUtils.hasText(this.jobName),
"Job name must be specified in case of multiple jobs");
if (StringUtils.hasText(this.jobName)) {
if (!isLocalJob(this.jobName) && !isRegisteredJob(this.jobName)) {
throw new IllegalArgumentException("No job found with name '" + this.jobName + "'");
}
Assert.isTrue(isLocalJob(this.jobName) || isRegisteredJob(this.jobName),
() -> "No job found with name '" + this.jobName + "'");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 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.