Skip to content

Commit 1990c8b

Browse files
committed
attempt to update midscribe project to newest midpoint (+ midpoint parent)
1 parent 7769e0b commit 1990c8b

24 files changed

+301
-261
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE suppressions PUBLIC
3+
"-//Checkstyle//DTD SuppressionFilter Configuration 1.0//EN"
4+
"https://checkstyle.org/dtds/suppressions_1_0.dtd">
5+
<suppressions>
6+
<suppress files="[/\\]generated[/\\]" checks=".*"/>
7+
<suppress files="[/\\]generated-sources[/\\]" checks=".*"/>
8+
<suppress files="[/\\]annotation_3[/\\]" checks="ConstantName"/>
9+
<suppress files="[/\\]query_3[/\\]" checks="ConstantName|AvoidNestedBlocks|NeedBraces"/>
10+
<suppress files="[/\\]types_3[/\\]" checks="ConstantName|AvoidNestedBlocks|NeedBraces"/>
11+
<suppress files="[/\\]public[/\\]query-3\.xsd$" checks="NewlineAtEndOfFile"/>
12+
<suppress files="[/\\]public[/\\]types-3\.xsd$" checks="NewlineAtEndOfFile"/>
13+
<suppress files="[/\\]public[/\\]annotation-3\.xsd$" checks="NewlineAtEndOfFile"/>
14+
<suppress files="[/\\]test[/\\]foo.*-1\.xsd$" checks="NewlineAtEndOfFile"/>
15+
<suppress files="[/\\]com[/\\]evolveum[/\\]midpoint[/\\]prism[/\\]delta[/\\]builder[/\\]" checks="TypeName"/>
16+
<suppress files="[/\\]com[/\\]evolveum[/\\]midpoint[/\\]prism[/\\]query[/\\]builder[/\\]" checks="TypeName"/>
17+
<suppress files="[/\\]com[/\\]evolveum[/\\]midpoint[/\\]prism[/\\]impl[/\\]query[/\\]builder[/\\]" checks="TypeName"/>
18+
<suppress files="[/\\]resources[/\\]localization[/\\]Midpoint.*\.properties" checks="NewlineAtEndOfFile"/>
19+
20+
<!-- TODO: added for tests in 2020, but I hope at least AvoidNestedBlocks could go away (Virgo) -->
21+
<!-- For tests we use a lot of _ in various names and for good reason, so we want to ignore Name rules -->
22+
<suppress files="[/\\]src[/\\]test[/\\]" checks="MethodName|ConstantName|LocalVariableName|AvoidNestedBlocks"/>
23+
24+
<!-- This will be gone anyway. Sooner or later. -->
25+
<suppress files="[/\\]com[/\\]evolveum[/\\]midpoint[/\\]model[/\\]api[/\\]ModelPort\.java$" checks="InterfaceIsType"/>
26+
<suppress files="[/\\]com[/\\]evolveum[/\\]midpoint[/\\]report[/\\]api[/\\]ReportPort\.java$" checks="InterfaceIsType"/>
27+
</suppressions>

config/checkstyle/checkstyle.xml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
4+
"https://checkstyle.org/dtds/configuration_1_3.dtd">
5+
<!-- Based on checkstyle/src/main/resources/sun_checks.xml -->
6+
<!-- See https://checkstyle.sourceforge.io/checks.html for explanation -->
7+
<module name="Checker">
8+
<!--
9+
<property name="basedir" value="${basedir}"/>
10+
-->
11+
<property name="severity" value="error"/>
12+
13+
<!-- Also need to add suffixes to parent pom.xml in checkstyle plugin configuration -->
14+
<property name="fileExtensions" value="java, properties, xml, xsd, wsdl, json, yml, yaml"/>
15+
16+
<!-- Excludes all 'module-info.java' files -->
17+
<!-- See https://checkstyle.org/config_filefilters.html -->
18+
<module name="BeforeExecutionExclusionFileFilter">
19+
<property name="fileNamePattern" value="module\-info\.java$"/>
20+
</module>
21+
22+
<!-- Checks that property files contain the same keys. -->
23+
<!-- See https://checkstyle.org/config_misc.html#Translation -->
24+
<module name="Translation"/>
25+
26+
<!-- Checks for whitespace. We indent by spaces, not tabs. -->
27+
<module name="FileTabCharacter"/>
28+
<module name="NewlineAtEndOfFile">
29+
<!-- Make this explicit due to some problems on Windows -->
30+
<property name="lineSeparator" value="lf_cr_crlf" />
31+
</module>
32+
33+
<module name="TreeWalker">
34+
35+
<module name="ConstantName"/>
36+
<module name="LocalFinalVariableName"/>
37+
<module name="LocalVariableName"/>
38+
<module name="MemberName"/>
39+
<module name="MethodName"/>
40+
<module name="PackageName"/>
41+
<module name="StaticVariableName"/>
42+
<module name="TypeName"/>
43+
<module name="RedundantImport"/>
44+
<module name="AvoidNestedBlocks"/>
45+
<module name="EmptyBlock">
46+
<property name="option" value="text"/>
47+
</module>
48+
<module name="EmptyStatement"/>
49+
<module name="EqualsHashCode"/>
50+
<module name="SimplifyBooleanExpression"/>
51+
<module name="SimplifyBooleanReturn"/>
52+
<module name="InterfaceIsType"/>
53+
<module name="ArrayTypeStyle"/>
54+
<module name="UpperEll"/>
55+
56+
<!-- TODO: enable later (problem: eclipse equals() code)
57+
<module name="NeedBraces">
58+
<property name="allowSingleLineStatement" value="true"/>
59+
</module>
60+
-->
61+
62+
<!-- TODO: enable later (problem: too many of those)
63+
<module name="FinalClass"/>
64+
<module name="RedundantModifier"/>
65+
-->
66+
67+
68+
<!-- TODO: enable those MUCH later
69+
<module name="UnusedImports">
70+
<property name="processJavadoc" value="false"/>
71+
</module> -->
72+
73+
</module>
74+
75+
</module>

midscribe-cmd/pom.xml

+14-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.evolveum.midpoint</groupId>
99
<artifactId>midscribe</artifactId>
10-
<version>4.4-SNAPSHOT</version>
10+
<version>4.10-SNAPSHOT</version>
1111
</parent>
1212

1313
<artifactId>midscribe-cmd</artifactId>
@@ -77,15 +77,28 @@
7777
<version>${project.version}</version>
7878
</dependency>
7979

80+
<dependency>
81+
<groupId>commons-io</groupId>
82+
<artifactId>commons-io</artifactId>
83+
</dependency>
8084
<dependency>
8185
<groupId>com.beust</groupId>
8286
<artifactId>jcommander</artifactId>
8387
</dependency>
88+
<dependency>
89+
<groupId>org.jetbrains</groupId>
90+
<artifactId>annotations</artifactId>
91+
</dependency>
8492

8593
<dependency>
8694
<groupId>org.testng</groupId>
8795
<artifactId>testng</artifactId>
8896
<scope>test</scope>
8997
</dependency>
98+
<dependency>
99+
<groupId>com.evolveum.commons</groupId>
100+
<artifactId>test-ng</artifactId>
101+
<scope>test</scope>
102+
</dependency>
90103
</dependencies>
91104
</project>

midscribe-cmd/src/main/java/com/evolveum/midscribe/cmd/CmdGenerateOptions.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,22 @@ public class CmdGenerateOptions extends GenerateOptions {
3838
public static final String P_PROPERTIES_FILE = "-pf";
3939
public static final String P_PROPERTIES_FILE_LONG = "--properties-file";
4040

41+
42+
public static class ExportFormatConverter extends EnumConverterValidator<ExportFormat> {
43+
44+
public ExportFormatConverter() {
45+
super(ExportFormat.class);
46+
}
47+
}
48+
4149
@Parameter(names = {P_TEMPLATE, P_TEMPLATE_LONG}, descriptionKey = "generate.template")
4250
@Override
4351
public void setTemplate(File template) {
4452
super.setTemplate(template);
4553
}
4654

47-
@Parameter(names = {P_EXPORT_FORMAT, P_EXPORT_FORMAT_LONG}, descriptionKey = "generate.exportFormat")
55+
@Parameter(names = {P_EXPORT_FORMAT, P_EXPORT_FORMAT_LONG}, descriptionKey = "generate.exportFormat",
56+
converter = ExportFormatConverter.class, validateWith = ExportFormatConverter.class)
4857
@Override
4958
public void setExportFormat(ExportFormat exportFormat) {
5059
super.setExportFormat(exportFormat);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.evolveum.midscribe.cmd;
2+
3+
import com.beust.jcommander.IParameterValidator;
4+
import com.beust.jcommander.IStringConverter;
5+
import com.beust.jcommander.ParameterException;
6+
import org.jetbrains.annotations.NotNull;
7+
8+
import java.util.Arrays;
9+
10+
public class EnumConverterValidator<T extends Enum> implements IStringConverter<T>, IParameterValidator {
11+
12+
private Class<T> enumClass;
13+
14+
public EnumConverterValidator(@NotNull Class<T> enumClass) {
15+
this.enumClass = enumClass;
16+
}
17+
18+
@Override
19+
public void validate(String name, String value) throws ParameterException {
20+
T converted = convert(value);
21+
if (converted == null) {
22+
throw new ParameterException("Unknown value '" + value + "', supported values: " +
23+
Arrays.toString(
24+
Arrays.stream(enumClass.getEnumConstants())
25+
.map(c -> c.name().toLowerCase())
26+
.toArray()));
27+
}
28+
}
29+
30+
@Override
31+
public T convert(String value) {
32+
if (value == null) {
33+
return null;
34+
}
35+
36+
for (T t : enumClass.getEnumConstants()) {
37+
if (t.name().equalsIgnoreCase(value)) {
38+
return t;
39+
}
40+
}
41+
42+
return null;
43+
}
44+
}

midscribe-cmd/src/main/resources/messages.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ generate.exportFormat=Export format
1010
generate.sourceDirectory=Source directory
1111
generate.include=Include
1212
generate.exclude=Exclude
13-
generate.propertiesFile=Properties file
13+
generate.propertiesFile=Properties file
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
project.name=John Doe Example Project
22
project.version=29301.2.2.2
33
project.author=Cpt. Granko
4-
project.date=1. 4. 2038
4+
project.date=1. 4. 2038

midscribe-cmd/testng-unit.xml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright (C) 2010-2020 Evolveum and contributors
4+
~
5+
~ This work is dual-licensed under the Apache License 2.0
6+
~ and European Union Public License. See LICENSE file for details.
7+
-->
8+
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
9+
<suite name="unit" parallel="none" verbose="1">
10+
<test name="Default" preserve-order="true" parallel="none" verbose="10">
11+
<classes>
12+
<class name="com.evolveum.midscribe.cmd.CmdTest"/>
13+
</classes>
14+
</test>
15+
</suite>

midscribe-core/pom.xml

+19-11
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,44 @@
77
<parent>
88
<groupId>com.evolveum.midpoint</groupId>
99
<artifactId>midscribe</artifactId>
10-
<version>4.4-SNAPSHOT</version>
10+
<version>4.10-SNAPSHOT</version>
1111
</parent>
1212

1313
<artifactId>midscribe-core</artifactId>
1414

1515
<dependencies>
1616
<dependency>
17-
<groupId>org.slf4j</groupId>
18-
<artifactId>slf4j-api</artifactId>
17+
<groupId>com.evolveum.prism</groupId>
18+
<artifactId>prism-api</artifactId>
1919
</dependency>
2020
<dependency>
21-
<groupId>org.slf4j</groupId>
22-
<artifactId>jcl-over-slf4j</artifactId>
23-
</dependency>
24-
<dependency>
25-
<groupId>org.slf4j</groupId>
26-
<artifactId>log4j-over-slf4j</artifactId>
21+
<groupId>com.evolveum.commons</groupId>
22+
<artifactId>util</artifactId>
2723
</dependency>
24+
2825
<dependency>
29-
<groupId>ch.qos.logback</groupId>
30-
<artifactId>logback-classic</artifactId>
26+
<groupId>org.apache.commons</groupId>
27+
<artifactId>commons-lang3</artifactId>
3128
</dependency>
3229

3330
<dependency>
3431
<groupId>commons-io</groupId>
3532
<artifactId>commons-io</artifactId>
3633
</dependency>
3734

35+
<dependency>
36+
<groupId>org.asciidoctor</groupId>
37+
<artifactId>asciidoctorj-api</artifactId>
38+
</dependency>
3839
<dependency>
3940
<groupId>org.asciidoctor</groupId>
4041
<artifactId>asciidoctorj</artifactId>
42+
<scope>runtime</scope>
4143
</dependency>
4244
<dependency>
4345
<groupId>org.asciidoctor</groupId>
4446
<artifactId>asciidoctorj-pdf</artifactId>
47+
<scope>runtime</scope>
4548
</dependency>
4649

4750
<dependency>
@@ -65,5 +68,10 @@
6568
<artifactId>testng</artifactId>
6669
<scope>test</scope>
6770
</dependency>
71+
<dependency>
72+
<groupId>com.evolveum.commons</groupId>
73+
<artifactId>test-ng</artifactId>
74+
<scope>test</scope>
75+
</dependency>
6876
</dependencies>
6977
</project>

midscribe-core/src/main/java/com/evolveum/midscribe/generator/Generator.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import java.lang.reflect.Constructor;
88
import java.lang.reflect.InvocationTargetException;
99
import java.nio.charset.StandardCharsets;
10-
import java.util.Collections;
11-
import java.util.HashMap;
1210
import java.util.Map;
1311
import java.util.Properties;
1412

@@ -24,14 +22,12 @@ public class Generator {
2422
private static final Map<ExportFormat, Class<? extends Exporter>> EXPORTERS;
2523

2624
static {
27-
Map<ExportFormat, Class<? extends Exporter>> exporters = new HashMap<>();
28-
exporters.put(ExportFormat.PDF, PdfExporter.class);
29-
exporters.put(ExportFormat.HTML, HtmlExporter.class);
30-
31-
EXPORTERS = Collections.unmodifiableMap(exporters);
25+
EXPORTERS = Map.ofEntries(
26+
Map.entry(ExportFormat.PDF, PdfExporter.class),
27+
Map.entry(ExportFormat.HTML, HtmlExporter.class));
3228
}
3329

34-
private GenerateOptions configuration;
30+
private final GenerateOptions configuration;
3531

3632
private LogListener logListener;
3733

@@ -94,7 +90,8 @@ private Exporter createExporter(ExportFormat format) {
9490
exporter.setLogListener(logListener);
9591

9692
return exporter;
97-
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException ex) {
93+
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException |
94+
IllegalAccessException ex) {
9895
LOG.error("Couldn't create formatter of type " + clazz);
9996
return null;
10097
}
@@ -137,7 +134,7 @@ private File createFile(File file) throws IOException {
137134
private MidPointObjectStore createObjectStore() throws Exception {
138135
MidPointObjectStore store = configuration.getObjectStoreInstance();
139136
if (store != null) {
140-
LOG.debug("Using midPoint store instance: {}" + store.getClass().getName());
137+
LOG.debug("Using midPoint store instance: {}", store.getClass().getName());
141138
return store;
142139
}
143140

midscribe-core/src/main/java/com/evolveum/midscribe/generator/GeneratorProperties.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
/**
77
* Created by Viliam Repan (lazyman).
88
*/
9-
public interface GeneratorProperties {
9+
public final class GeneratorProperties {
1010

11-
String VELOCITY_START_TEMPLATE = "velocity.start.template";
11+
public static final String VELOCITY_START_TEMPLATE = "velocity.start.template";
1212

13-
String VELOCITY_START_TEMPLATE_DEFAULT = "/template/documentation.vm";
13+
public static final String VELOCITY_START_TEMPLATE_DEFAULT = "/template/documentation.vm";
1414

15-
String VELOCITY_ADDITIONAL_VARIABLES = "velocity.additional.variables";
15+
public static final String VELOCITY_ADDITIONAL_VARIABLES = "velocity.additional.variables";
1616

17-
Map<String, Object> VELOCITY_ADDITIONAL_VARIABLES_DEFAULT = new HashMap<>();
17+
public static final Map<String, Object> VELOCITY_ADDITIONAL_VARIABLES_DEFAULT = new HashMap<>();
1818
}

midscribe-core/src/main/java/com/evolveum/midscribe/generator/HtmlExporter.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ public void export(File adocFile, File output) throws IOException {
2828
.safe(SafeMode.UNSAFE)
2929
.toDir(dir)
3030
.toFile(file)
31-
.headerFooter(true)
31+
.standalone(true)
3232
.build();
3333
// .templateDir(new File("./src/test/resources/css"));
3434

35-
Asciidoctor doctor = createAsciidoctor();
36-
37-
doctor.convertFile(adocFile, options);
35+
try (Asciidoctor doctor = createAsciidoctor()) {
36+
doctor.convertFile(adocFile, options);
37+
}
3838
}
3939
}

0 commit comments

Comments
 (0)