mirror of
https://gitee.com/dcren/initializr.git
synced 2025-09-19 01:58:16 +08:00
Add HELP.md to .gitignore if necessary
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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
|
||||
*
|
||||
* http://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.initializr.generator.spring.documentation;
|
||||
|
||||
import io.spring.initializr.generator.spring.scm.git.GitIgnore;
|
||||
import io.spring.initializr.generator.spring.scm.git.GitIgnoreCustomizer;
|
||||
|
||||
/**
|
||||
* A {@link GitIgnoreCustomizer} that adds {@code HELP.md} to the ignore list when
|
||||
* applicable.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class HelpDocumentGitIgnoreCustomizer implements GitIgnoreCustomizer {
|
||||
|
||||
private final HelpDocument document;
|
||||
|
||||
HelpDocumentGitIgnoreCustomizer(HelpDocument document) {
|
||||
this.document = document;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(GitIgnore gitIgnore) {
|
||||
if (!this.document.isEmpty()) {
|
||||
gitIgnore.getGeneral().add("HELP.md");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -33,12 +33,17 @@ import org.springframework.context.annotation.Import;
|
||||
public class HelpDocumentProjectGenerationConfiguration {
|
||||
|
||||
@Bean
|
||||
public HelpDocumentProjectContributor helpDocumentProjectContributor(
|
||||
MustacheTemplateRenderer templateRenderer,
|
||||
public HelpDocument helpDocument(MustacheTemplateRenderer templateRenderer,
|
||||
ObjectProvider<HelpDocumentCustomizer> helpDocumentCustomizers) {
|
||||
HelpDocument helpDocument = new HelpDocument(templateRenderer);
|
||||
helpDocumentCustomizers.orderedStream()
|
||||
.forEach((customizer) -> customizer.customize(helpDocument));
|
||||
return helpDocument;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HelpDocumentProjectContributor helpDocumentProjectContributor(
|
||||
HelpDocument helpDocument) {
|
||||
return new HelpDocumentProjectContributor(helpDocument);
|
||||
}
|
||||
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package io.spring.initializr.generator.spring.documentation;
|
||||
|
||||
import io.spring.initializr.generator.project.ResolvedProjectDescription;
|
||||
import io.spring.initializr.generator.spring.scm.git.GitIgnoreCustomizer;
|
||||
import io.spring.initializr.metadata.InitializrMetadata;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -36,4 +37,9 @@ public class HelpDocumentProjectGenerationDefaultContributorsConfiguration {
|
||||
return new RequestedDependenciesHelpDocumentCustomizer(description, metadata);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public GitIgnoreCustomizer helpDocumentGitIgnoreCustomizer(HelpDocument document) {
|
||||
return new HelpDocumentGitIgnoreCustomizer(document);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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
|
||||
*
|
||||
* http://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.initializr.generator.spring.documentation;
|
||||
|
||||
import io.spring.initializr.generator.io.template.MustacheTemplateRenderer;
|
||||
import io.spring.initializr.generator.spring.scm.git.GitIgnore;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link HelpDocumentGitIgnoreCustomizer}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class HelpDocumentGitIgnoreCustomizerTests {
|
||||
|
||||
private final GitIgnore gitIgnore = new GitIgnore();
|
||||
|
||||
@Test
|
||||
void gitIgnoreIsUpdatedWithNonEmptyHelpDocument() {
|
||||
HelpDocument document = new HelpDocument(mock(MustacheTemplateRenderer.class));
|
||||
document.addSection((writer) -> writer.println("test"));
|
||||
new HelpDocumentGitIgnoreCustomizer(document).customize(this.gitIgnore);
|
||||
assertThat(this.gitIgnore.getGeneral().getItems()).containsOnly("HELP.md");
|
||||
}
|
||||
|
||||
@Test
|
||||
void gitIgnoreIsNotUpdatedWithEmptyHelpDocument() {
|
||||
HelpDocument document = new HelpDocument(mock(MustacheTemplateRenderer.class));
|
||||
new HelpDocumentGitIgnoreCustomizer(document).customize(this.gitIgnore);
|
||||
assertThat(this.gitIgnore.getGeneral().getItems()).isEmpty();
|
||||
}
|
||||
|
||||
}
|
@@ -20,6 +20,7 @@ import java.nio.file.Path;
|
||||
|
||||
import io.spring.initializr.generator.io.template.MustacheTemplateRenderer;
|
||||
import io.spring.initializr.generator.project.ProjectDescription;
|
||||
import io.spring.initializr.generator.spring.scm.git.GitIgnoreCustomizer;
|
||||
import io.spring.initializr.generator.spring.test.InitializrMetadataTestBuilder;
|
||||
import io.spring.initializr.generator.test.project.ProjectAssetTester;
|
||||
import io.spring.initializr.metadata.Dependency;
|
||||
@@ -74,4 +75,13 @@ class HelpDocumentProjectGenerationConfigurationTests {
|
||||
.containsOnly("HELP.md");
|
||||
}
|
||||
|
||||
@Test
|
||||
void helpDocumentIsAddedToGitIgnore() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
GitIgnoreCustomizer gitIgnoreCustomizer = this.projectTester.generate(description,
|
||||
(context) -> context.getBean(GitIgnoreCustomizer.class));
|
||||
assertThat(gitIgnoreCustomizer)
|
||||
.isInstanceOf(HelpDocumentGitIgnoreCustomizer.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user