-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
ConfigPropertyWriterTask.java
59 lines (50 loc) · 1.7 KB
/
ConfigPropertyWriterTask.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.properties;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Map;
import java.util.function.BiConsumer;
import javax.inject.Inject;
import org.hibernate.orm.properties.processor.AsciiDocWriter;
import org.hibernate.orm.properties.processor.ConfigPropertyHolder;
import org.hibernate.orm.properties.processor.ConfigurationProperty;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import org.gradle.api.tasks.TaskAction;
/**
* Task that writes two asciidoc files from the collected config properties. One is for public configurations, another - for SPI.
*/
public class ConfigPropertyWriterTask extends DefaultTask {
private final Project project;
private final ConfigPropertyHolder properties;
private final String fileName = "configs";
@Inject
public ConfigPropertyWriterTask(Project project, ConfigPropertyHolder properties) {
this.project = project;
this.properties = properties;
}
@TaskAction
public void writeProperties() {
if ( properties.hasProperties() ) {
writeProperties(
fileName + ".asciidoc",
new AsciiDocWriter()
);
}
}
private void writeProperties(String fileName, BiConsumer<Map<String, ConfigurationProperty>, Writer> transformer) {
try ( Writer writer = new FileWriter( project.getBuildDir().toPath().resolve( fileName ).toFile() )
) {
properties.write( transformer, writer );
}
catch (IOException e) {
throw new RuntimeException( e );
}
}
}