Skip to content

Package: OWL2JavaMojo

OWL2JavaMojo

nameinstructionbranchcomplexitylinemethod
OWL2JavaMojo()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
execute()
M: 108 C: 0
0%
M: 12 C: 0
0%
M: 7 C: 0
0%
M: 26 C: 0
0%
M: 1 C: 0
0%
getPackage()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
printParameterValues()
M: 112 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 18 C: 0
0%
M: 1 C: 0
0%
setPackage(String)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * JOPA
3: * Copyright (C) 2023 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.jopa.maven;
19:
20: import cz.cvut.kbss.jopa.owl2java.OWL2JavaTransformer;
21: import cz.cvut.kbss.jopa.owl2java.cli.PropertiesType;
22: import cz.cvut.kbss.jopa.owl2java.config.TransformationConfiguration;
23: import org.apache.maven.plugin.AbstractMojo;
24: import org.apache.maven.plugins.annotations.LifecyclePhase;
25: import org.apache.maven.plugins.annotations.Mojo;
26: import org.apache.maven.plugins.annotations.Parameter;
27:
28: @Mojo(name = "owl2java-transform", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
29: public class OWL2JavaMojo extends AbstractMojo {
30:
31: private static final String MAPPING_FILE_PARAM = "mapping-file";
32: private static final String PACKAGE_PARAM = "package";
33: private static final String CONTEXT_PARAM = "context-name";
34: private static final String ONTOLOGY_PARAM = "ontology-iri";
35: private static final String OUTPUT_PARAM = "output-directory";
36: private static final String W_OWLAPI_PARAM = "with-owlapi";
37: private static final String ALL_IC_PARAM = "whole-ontology-as-ics";
38: private static final String VOCABULARY_PARAM = "vocabulary-only";
39: private static final String IGNORE_FAILED_IMPORTS_PARAM = "ignore-failed-imports";
40: private static final String PROPERTIES_TYPE = "properties-type";
41: private static final String GENERATE_JAVADOC = "javadoc-from-rdfs-comment";
42: private static final String PREFER_MULTILINGUAL_STRINGS = "prefer-multilingual-strings";
43: private static final String GENERATE_ANNOTATION_FIELDS = "generate-annotation-fields";
44: private static final String GENERATE_THING = "generate-thing";
45: private static final String ONTOLOGY_PREFIX_PROPERTY = "ontology-prefix-property";
46: private static final String ALWAYS_USE_PREFIXES = "always-use-prefixes";
47: private static final String PREFIX_MAPPING_FILE = "prefix-mapping-file";
48:
49: @Parameter(name = MAPPING_FILE_PARAM)
50: private String mappingFile;
51:
52: @Parameter(name = PACKAGE_PARAM, required = true)
53: private String pPackage;
54:
55: @Parameter(name = CONTEXT_PARAM)
56: private String contextName;
57:
58: @Parameter(name = ONTOLOGY_PARAM)
59: private String ontologyIri;
60:
61: @Parameter(name = OUTPUT_PARAM, defaultValue = "${project.basedir}/src/main/generated-sources")
62: private String outputDirectory;
63:
64: @Parameter(name = W_OWLAPI_PARAM, defaultValue = "false")
65: private boolean withOwlapi;
66:
67: @Parameter(name = ALL_IC_PARAM, defaultValue = "false")
68: private boolean wholeOntologyAsIcs;
69:
70: @Parameter(name = VOCABULARY_PARAM, defaultValue = "false")
71: private boolean vocabularyOnly;
72:
73: @Parameter(name = IGNORE_FAILED_IMPORTS_PARAM, defaultValue = "false")
74: private boolean ignoreFailedImports;
75:
76: @Parameter(name = PROPERTIES_TYPE, defaultValue = "string")
77: private String propertiesType;
78:
79: @Parameter(name = GENERATE_JAVADOC, defaultValue = "true")
80: private boolean javadocFromRdfsComment;
81:
82: @Parameter(name = PREFER_MULTILINGUAL_STRINGS, defaultValue = "true")
83: private boolean preferMultilingualStrings;
84:
85: @Parameter(name = GENERATE_ANNOTATION_FIELDS, defaultValue = "true")
86: private boolean generateAnnotationFields;
87:
88: @Parameter(name = GENERATE_THING, defaultValue = "true")
89: private boolean generateThing;
90:
91: @Parameter(name = ONTOLOGY_PREFIX_PROPERTY)
92: private String ontologyPrefixProperty;
93:
94: @Parameter(name = ALWAYS_USE_PREFIXES, defaultValue = "true")
95: private boolean alwaysUsePrefixes;
96:
97: @Parameter(name = PREFIX_MAPPING_FILE)
98: private String prefixMappingFile;
99:
100: @Override
101: public void execute() {
102: OWL2JavaTransformer owl2java = new OWL2JavaTransformer();
103:
104: printParameterValues();
105:
106:• if (ontologyIri == null) {
107: getLog().error("The parameter 'ontology-iri' is invalid. Must not be null.");
108: getLog().error("Skipping OWL2Java transformation.");
109: return;
110: }
111: owl2java.ignoreMissingImports(ignoreFailedImports);
112:
113:• if (mappingFile != null && !mappingFile.isEmpty()) {
114: owl2java.setOntology(ontologyIri, mappingFile);
115: } else {
116: owl2java.setOntology(ontologyIri, null);
117: }
118:
119: final TransformationConfiguration.TransformationConfigurationBuilder builder =
120: TransformationConfiguration.builder();
121:• if (!wholeOntologyAsIcs) {
122: builder.context(contextName);
123: }
124:
125:• if (propertiesType != null) {
126: builder.propertiesType(PropertiesType.valueOf(propertiesType));
127: }
128:
129: final TransformationConfiguration config =
130: builder.packageName(pPackage).targetDir(outputDirectory).addOwlapiIris(withOwlapi)
131: .generateJavadoc(javadocFromRdfsComment).preferMultilingualStrings(preferMultilingualStrings)
132: .generateAnnotationFields(generateAnnotationFields).generateThing(generateThing)
133: .ontologyPrefixProperty(ontologyPrefixProperty).alwaysUseOntologyPrefix(alwaysUsePrefixes)
134: .prefixMappingFile(prefixMappingFile).build();
135:
136:• if (vocabularyOnly) {
137: owl2java.generateVocabulary(config);
138: } else {
139: owl2java.transform(config);
140: }
141:
142: getLog().info("OWL2Java successfully generated!");
143: }
144:
145: private void printParameterValues() {
146: Utils.logParameterValue(MAPPING_FILE_PARAM, mappingFile, getLog());
147: Utils.logParameterValue(PACKAGE_PARAM, pPackage, getLog());
148: Utils.logParameterValue(CONTEXT_PARAM, contextName, getLog());
149: Utils.logParameterValue(ONTOLOGY_PARAM, ontologyIri, getLog());
150: Utils.logParameterValue(OUTPUT_PARAM, outputDirectory, getLog());
151: Utils.logParameterValue(W_OWLAPI_PARAM, withOwlapi, getLog());
152: Utils.logParameterValue(ALL_IC_PARAM, wholeOntologyAsIcs, getLog());
153: Utils.logParameterValue(VOCABULARY_PARAM, vocabularyOnly, getLog());
154: Utils.logParameterValue(IGNORE_FAILED_IMPORTS_PARAM, ignoreFailedImports, getLog());
155: Utils.logParameterValue(PROPERTIES_TYPE, propertiesType, getLog());
156: Utils.logParameterValue(GENERATE_JAVADOC, javadocFromRdfsComment, getLog());
157: Utils.logParameterValue(PREFER_MULTILINGUAL_STRINGS, preferMultilingualStrings, getLog());
158: Utils.logParameterValue(GENERATE_ANNOTATION_FIELDS, generateAnnotationFields, getLog());
159: Utils.logParameterValue(GENERATE_THING, generateThing, getLog());
160: Utils.logParameterValue(ONTOLOGY_PREFIX_PROPERTY, ontologyPrefixProperty, getLog());
161: Utils.logParameterValue(ALWAYS_USE_PREFIXES, alwaysUsePrefixes, getLog());
162: Utils.logParameterValue(PREFIX_MAPPING_FILE, prefixMappingFile, getLog());
163: }
164:
165: public String getPackage() {
166: return pPackage;
167: }
168:
169: public void setPackage(String pPackage) {
170: this.pPackage = pPackage;
171: }
172: }