-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...ite/src/main/java/io/spring/start/site/extension/dependency/htmx/HtmxBuildCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2012-2024 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. | ||
*/ | ||
|
||
package io.spring.start.site.extension.dependency.htmx; | ||
|
||
import io.spring.initializr.generator.buildsystem.Build; | ||
import io.spring.initializr.generator.buildsystem.Dependency; | ||
import io.spring.initializr.generator.spring.build.BuildCustomizer; | ||
|
||
/** | ||
* A {@link BuildCustomizer} that replaces {@code htmx-spring-boot} with | ||
* {@code htmx-spring-boot-thymeleaf} if Thymeleaf is selected. | ||
* | ||
* @author Moritz Halbritter | ||
*/ | ||
class HtmxBuildCustomizer implements BuildCustomizer<Build> { | ||
|
||
@Override | ||
public void customize(Build build) { | ||
if (build.dependencies().has("thymeleaf")) { | ||
Dependency htmx = build.dependencies().get("htmx"); | ||
build.dependencies().remove("htmx"); | ||
build.dependencies() | ||
.add("htmx-thymeleaf", | ||
Dependency.withCoordinates(htmx.getGroupId(), "htmx-spring-boot-thymeleaf") | ||
.version(htmx.getVersion()) | ||
.build()); | ||
} | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...va/io/spring/start/site/extension/dependency/htmx/HtmxProjectGenerationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2012-2024 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. | ||
*/ | ||
|
||
package io.spring.start.site.extension.dependency.htmx; | ||
|
||
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* Configuration for generation of projects that depend on htmx. | ||
* | ||
* @author Moritz Halbritter | ||
*/ | ||
@Configuration(proxyBeanMethods = false) | ||
@ConditionalOnRequestedDependency("htmx") | ||
class HtmxProjectGenerationConfiguration { | ||
|
||
@Bean | ||
HtmxBuildCustomizer htmxBuildCustomizer() { | ||
return new HtmxBuildCustomizer(); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
start-site/src/main/java/io/spring/start/site/extension/dependency/htmx/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright 2012-2022 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. | ||
*/ | ||
|
||
/** | ||
* Extensions for generation of projects that depend on htmx. | ||
*/ | ||
package io.spring.start.site.extension.dependency.htmx; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...rc/test/java/io/spring/start/site/extension/dependency/htmx/HtmxBuildCustomizerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2012-2024 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. | ||
*/ | ||
|
||
package io.spring.start.site.extension.dependency.htmx; | ||
|
||
import io.spring.initializr.metadata.Dependency; | ||
import io.spring.initializr.web.project.ProjectRequest; | ||
import io.spring.start.site.extension.AbstractExtensionTests; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Tests for {@link HtmxBuildCustomizer}. | ||
* | ||
* @author Moritz Halbritter | ||
*/ | ||
class HtmxBuildCustomizerTests extends AbstractExtensionTests { | ||
|
||
private final Dependency htmx = Dependency.withId("htmx", "io.github.wimdeblauwe", "htmx-spring-boot"); | ||
|
||
private final Dependency htmxThymeleaf = Dependency.withId("htmx", "io.github.wimdeblauwe", | ||
"htmx-spring-boot-thymeleaf"); | ||
|
||
@Test | ||
void shouldUseHtmxThymleafIfThymeleafIsSelected() { | ||
ProjectRequest request = createProjectRequest("htmx", "thymeleaf"); | ||
assertThat(mavenPom(request)).doesNotHaveDependency(this.htmx.getGroupId(), this.htmx.getArtifactId()) | ||
.hasDependency(this.htmxThymeleaf); | ||
} | ||
|
||
@Test | ||
void shouldUsePlainHtmxIfThymeleafIsNotSelected() { | ||
ProjectRequest request = createProjectRequest("htmx"); | ||
assertThat(mavenPom(request)) | ||
.doesNotHaveDependency(this.htmxThymeleaf.getGroupId(), this.htmxThymeleaf.getArtifactId()) | ||
.hasDependency(this.htmx); | ||
} | ||
|
||
@Test | ||
void shouldNotAddHtmx() { | ||
ProjectRequest request = createProjectRequest("web"); | ||
assertThat(mavenPom(request)).doesNotHaveDependency(this.htmx.getGroupId(), this.htmx.getArtifactId()) | ||
.doesNotHaveDependency(this.htmxThymeleaf.getGroupId(), this.htmxThymeleaf.getArtifactId()); | ||
} | ||
|
||
} |