Skip to content

Commit 735ad65

Browse files
committed
Use spring-boot-ldap if Boot 4.0.x is selected
com.unboundid:unboundid-ldapsdk is an optional dependency of spring-boot-ldap, LdapUnboundIdBuildCustomizer takes care of adding it if necessary. See gh-1861
1 parent f2e59af commit 735ad65

File tree

5 files changed

+118
-2
lines changed

5 files changed

+118
-2
lines changed

start-site/src/main/java/io/spring/start/site/extension/dependency/DependencyProjectGenerationConfiguration.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818

1919
import io.spring.initializr.generator.buildsystem.gradle.GradleBuildSystem;
2020
import io.spring.initializr.generator.condition.ConditionalOnBuildSystem;
21+
import io.spring.initializr.generator.condition.ConditionalOnPlatformVersion;
2122
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency;
2223
import io.spring.initializr.generator.io.template.MustacheTemplateRenderer;
2324
import io.spring.initializr.generator.project.ProjectDescription;
2425
import io.spring.initializr.generator.project.ProjectGenerationConfiguration;
2526
import io.spring.initializr.metadata.InitializrMetadata;
27+
import io.spring.start.site.extension.dependency.ldap.LdapUnboundIdBuildCustomizer;
2628
import io.spring.start.site.extension.dependency.liquibase.LiquibaseProjectContributor;
2729
import io.spring.start.site.extension.dependency.lombok.LombokGradleBuildCustomizer;
2830
import io.spring.start.site.extension.dependency.mybatis.MyBatisTestBuildCustomizer;
@@ -121,4 +123,11 @@ public SpringShellTestBuildCustomizer springShellTestBuildCustomizer() {
121123
return new SpringShellTestBuildCustomizer();
122124
}
123125

126+
@Bean
127+
@ConditionalOnRequestedDependency("unboundid-ldap")
128+
@ConditionalOnPlatformVersion("4.0.0-M1")
129+
LdapUnboundIdBuildCustomizer ldapUnboundIdBuildCustomizer() {
130+
return new LdapUnboundIdBuildCustomizer();
131+
}
132+
124133
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2012 - present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.start.site.extension.dependency.ldap;
18+
19+
import io.spring.initializr.generator.buildsystem.Build;
20+
import io.spring.initializr.generator.buildsystem.DependencyScope;
21+
import io.spring.initializr.generator.spring.build.BuildCustomizer;
22+
23+
/**
24+
* {@link BuildCustomizer} to add {@code com.unboundid:unboundid-ldapsdk}.
25+
*
26+
* @author Moritz Halbritter
27+
*/
28+
public class LdapUnboundIdBuildCustomizer implements BuildCustomizer<Build> {
29+
30+
@Override
31+
public void customize(Build build) {
32+
build.dependencies()
33+
.add("unboundid-ldapsdk", "com.unboundid", "unboundid-ldapsdk", DependencyScope.TEST_COMPILE);
34+
}
35+
36+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2012 - present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Extensions for generation of projects that depend on LDAP.
19+
*/
20+
package io.spring.start.site.extension.dependency.ldap;

start-site/src/main/resources/application.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,8 +1148,12 @@ initializr:
11481148
- name: Embedded LDAP Server
11491149
id: unboundid-ldap
11501150
description: Provides a platform neutral way for running a LDAP server in unit tests.
1151-
groupId: com.unboundid
1152-
artifactId: unboundid-ldapsdk
1151+
mappings:
1152+
- compatibilityRange: "[3.4.0,4.0.0-M1)"
1153+
group-id: com.unboundid
1154+
artifact-id: unboundid-ldapsdk
1155+
groupId: org.springframework.boot
1156+
artifactId: spring-boot-ldap
11531157
scope: test
11541158
starter: false
11551159
links:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2012 - present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.start.site.extension.dependency.ldap;
18+
19+
import io.spring.initializr.web.project.ProjectRequest;
20+
import io.spring.start.site.SupportedBootVersion;
21+
import io.spring.start.site.extension.AbstractExtensionTests;
22+
import org.junit.jupiter.api.Test;
23+
24+
import static org.assertj.core.api.Assertions.assertThat;
25+
26+
/**
27+
* Tests for {@link LdapUnboundIdBuildCustomizer}.
28+
*
29+
* @author Moritz Halbritter
30+
*/
31+
class LdapUnboundIdBuildCustomizerTests extends AbstractExtensionTests {
32+
33+
@Test
34+
void shouldAddUnboundIdIfBoot4orLaterIsUsed() {
35+
ProjectRequest request = createProjectRequest(SupportedBootVersion.V4_0, "unboundid-ldap");
36+
assertThat(mavenPom(request)).hasDependency("org.springframework.boot", "spring-boot-ldap", null, "test")
37+
.hasDependency("com.unboundid", "unboundid-ldapsdk", null, "test");
38+
}
39+
40+
@Test
41+
void shouldNotAddSpringBootLdapIfNotUsingBoot4() {
42+
ProjectRequest request = createProjectRequest(SupportedBootVersion.V3_5, "unboundid-ldap");
43+
assertThat(mavenPom(request)).doesNotHaveDependency("org.springframework.boot", "spring-boot-ldap")
44+
.hasDependency("com.unboundid", "unboundid-ldapsdk", null, "test");
45+
}
46+
47+
}

0 commit comments

Comments
 (0)