Skip to content

Commit 05bb3d8

Browse files
committed
Adds a log4j-transform-cli tool
This PR adds a simple `picocli`-based tool to access the Configuration Converter API from the command line. Currently, two commands are available: - `configFile listFormats` lists the available configuration file formats. - `configFile convert` converts configuration files from one format to another (e.g., a Log4j 1 Properties file to a Log4j 2 Core XML file). Part of apache/logging-log4j2#3220
1 parent 0c98111 commit 05bb3d8

26 files changed

+614
-3
lines changed

antora-playbook.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ content:
2525
- url: .
2626
branches: HEAD
2727
start_paths:
28+
- log4j-transform-cli/target/generated-site/antora
2829
- target/generated-site/antora
2930
edit_url:
3031

log4j-converter-config/src/main/java/org/apache/logging/converter/config/ConfigurationConverter.java

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

1919
import java.io.InputStream;
2020
import java.io.OutputStream;
21+
import java.util.Map;
2122
import java.util.Set;
2223
import org.apache.logging.converter.config.internal.DefaultConfigurationConverter;
2324

@@ -55,4 +56,12 @@ void convert(InputStream inputStream, String inputFormat, OutputStream outputStr
5556
* Returns the list of supported output formats.
5657
*/
5758
Set<String> getSupportedOutputFormats();
59+
60+
/**
61+
* Associates each supported format symbol with a description.
62+
* <p>
63+
* For self-documentation purposes.
64+
* </p>
65+
*/
66+
Map<String, String> getFormatDescriptions();
5867
}

log4j-converter-config/src/main/java/org/apache/logging/converter/config/internal/DefaultConfigurationConverter.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public final class DefaultConfigurationConverter implements ConfigurationConvert
5454

5555
private final Map<String, ConfigurationParser> parsers = new HashMap<>();
5656
private final Map<String, ConfigurationWriter> writers = new HashMap<>();
57+
private final Map<String, String> descriptions = new HashMap<>();
5758

5859
private DefaultConfigurationConverter() {
5960
ServiceLoader.load(ConfigurationParser.class).forEach(parser -> parsers.put(parser.getInputFormat(), parser));
@@ -62,6 +63,10 @@ private DefaultConfigurationConverter() {
6263
parsers.put(mapper.getInputFormat(), mapper);
6364
writers.put(mapper.getOutputFormat(), mapper);
6465
});
66+
parsers.values()
67+
.forEach(parser -> descriptions.put(parser.getInputFormat(), parser.getInputFormatDescription()));
68+
writers.values()
69+
.forEach(writer -> descriptions.put(writer.getOutputFormat(), writer.getOutputFormatDescription()));
6570
}
6671

6772
@Override
@@ -98,4 +103,9 @@ public Set<String> getSupportedInputFormats() {
98103
public Set<String> getSupportedOutputFormats() {
99104
return Collections.unmodifiableSet(writers.keySet());
100105
}
106+
107+
@Override
108+
public Map<String, String> getFormatDescriptions() {
109+
return Collections.unmodifiableMap(descriptions);
110+
}
101111
}

log4j-converter-config/src/main/java/org/apache/logging/converter/config/internal/v1/PropertiesV1ConfigurationParser.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public String getInputFormat() {
5656
return LOG4J_V1_PROPERTIES_FORMAT;
5757
}
5858

59+
@Override
60+
public String getInputFormatDescription() {
61+
return "Log4j 1 Properties configuration file format.";
62+
}
63+
5964
@Override
6065
public ConfigurationNode parse(InputStream inputStream) throws IOException {
6166
Properties properties = new Properties();

log4j-converter-config/src/main/java/org/apache/logging/converter/config/internal/v1/XmlV1ConfigurationParser.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public String getInputFormat() {
6161
return LOG4J_V1_XML_FORMAT;
6262
}
6363

64+
@Override
65+
public String getInputFormatDescription() {
66+
return "Log4j 1 XML configuration file format.";
67+
}
68+
6469
@Override
6570
public ConfigurationNode parse(InputStream inputStream) throws IOException {
6671
DocumentBuilder documentBuilder = XmlUtils.createDocumentBuilderV1();

log4j-converter-config/src/main/java/org/apache/logging/converter/config/internal/v2/JsonConfigurationMapper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@ public JsonConfigurationMapper() {
3434
public String getFormat() {
3535
return LOG4J_V2_JSON_FORMAT;
3636
}
37+
38+
@Override
39+
public String getFormatDescription() {
40+
return "Log4j Core 2 JSON configuration format.";
41+
}
3742
}

log4j-converter-config/src/main/java/org/apache/logging/converter/config/internal/v2/PropertiesV2ConfigurationParser.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public String getInputFormat() {
7070
return LOG4J_V2_PROPERTIES_FORMAT;
7171
}
7272

73+
@Override
74+
public String getInputFormatDescription() {
75+
return "Log4j Core 2 Properties configuration format.";
76+
}
77+
7378
@Override
7479
public ConfigurationNode parse(InputStream inputStream) throws IOException {
7580
Properties rootProperties = new Properties();

log4j-converter-config/src/main/java/org/apache/logging/converter/config/internal/v2/XmlConfigurationMapper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ public String getFormat() {
108108
return LOG4J_V2_XML_FORMAT;
109109
}
110110

111+
@Override
112+
public String getFormatDescription() {
113+
return "Log4j Core 2 XML configuration format.";
114+
}
115+
111116
private static XMLStreamWriter createStreamWriter(OutputStream outputStream) throws IOException {
112117
XMLOutputFactory outputFactory = XMLOutputFactory.newFactory();
113118
try {

log4j-converter-config/src/main/java/org/apache/logging/converter/config/internal/v2/YamlConfigurationMapper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,9 @@ public YamlConfigurationMapper() {
4040
public String getFormat() {
4141
return LOG4J_V2_YAML_FORMAT;
4242
}
43+
44+
@Override
45+
public String getFormatDescription() {
46+
return "Log4j Core 2 YAML configuration format.";
47+
}
4348
}

log4j-converter-config/src/main/java/org/apache/logging/converter/config/internal/v3/PropertiesV3ConfigurationMapper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public String getFormat() {
4444
return LOG4J_V3_PROPERTIES_FORMAT;
4545
}
4646

47+
@Override
48+
public String getFormatDescription() {
49+
return "Log4j Core 3 Properties configuration format.";
50+
}
51+
4752
@Override
4853
public ConfigurationNode parse(InputStream inputStream) throws IOException {
4954
return super.parse(inputStream);

0 commit comments

Comments
 (0)