forked from spring-io/initializr
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See spring-iogh-1079
- Loading branch information
Showing
5 changed files
with
208 additions
and
3 deletions.
There are no files selected for viewing
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
46 changes: 46 additions & 0 deletions
46
...erator/src/main/java/io/spring/initializr/generator/buildsystem/gradle/GradleSnippet.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,46 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package io.spring.initializr.generator.buildsystem.gradle; | ||
|
||
import java.util.Set; | ||
import java.util.function.Consumer; | ||
|
||
import io.spring.initializr.generator.io.IndentingWriter; | ||
|
||
/** | ||
* @author Stephane Nicoll | ||
*/ | ||
public class GradleSnippet { | ||
|
||
private final Set<String> importedTypes; | ||
|
||
private final Consumer<IndentingWriter> writer; | ||
|
||
GradleSnippet(Set<String> importedTypes, Consumer<IndentingWriter> writer) { | ||
this.importedTypes = Set.copyOf(importedTypes); | ||
this.writer = writer; | ||
} | ||
|
||
Set<String> getImportedTypes() { | ||
return this.importedTypes; | ||
} | ||
|
||
public void apply(IndentingWriter indentingWriter) { | ||
this.writer.accept(indentingWriter); | ||
} | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
...c/main/java/io/spring/initializr/generator/buildsystem/gradle/GradleSnippetContainer.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,74 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package io.spring.initializr.generator.buildsystem.gradle; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.function.Consumer; | ||
import java.util.stream.Stream; | ||
|
||
import io.spring.initializr.generator.io.IndentingWriter; | ||
|
||
/** | ||
* @author Stephane Nicoll | ||
*/ | ||
public class GradleSnippetContainer { | ||
|
||
private final List<GradleSnippet> snippets = new ArrayList<>(); | ||
|
||
/** | ||
* Specify if this container is empty. | ||
* @return {@code true} if no task is registered | ||
*/ | ||
public boolean isEmpty() { | ||
return this.snippets.isEmpty(); | ||
} | ||
|
||
/** | ||
* Return the {@link GradleSnippet Gradle snippets} to apply. | ||
* @return the gradle snippets | ||
*/ | ||
public Stream<GradleSnippet> values() { | ||
return this.snippets.stream(); | ||
} | ||
|
||
/** | ||
* Return the fully qualified name of types to import. | ||
* @return the imported types | ||
*/ | ||
public Stream<String> importedTypes() { | ||
return this.snippets.stream().map(GradleSnippet::getImportedTypes).flatMap(Collection::stream); | ||
} | ||
|
||
/** | ||
* Register a {@code snippet} with the specified types to import. | ||
*/ | ||
public void add(Set<String> importedTypes, Consumer<IndentingWriter> writer) { | ||
this.snippets.add(new GradleSnippet(importedTypes, writer)); | ||
} | ||
|
||
/** | ||
* Register a {@code snippet} with no import. | ||
*/ | ||
public void add(Consumer<IndentingWriter> writer) { | ||
add(Collections.emptySet(), writer); | ||
} | ||
|
||
} |
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