Skip to content

Method: execute()

1: /**
2: * Copyright (C) 2020 Czech Technical University in Prague
3: * <p>
4: * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
5: * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
6: * version.
7: * <p>
8: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10: * details. You should have received a copy of the GNU General Public License along with this program. If not, see
11: * <http://www.gnu.org/licenses/>.
12: */
13: package cz.cvut.kbss.jopa.maven;
14:
15: import cz.cvut.kbss.jopa.owl2java.OWL2JavaTransformer;
16: import cz.cvut.kbss.jopa.owl2java.cli.PropertiesType;
17: import cz.cvut.kbss.jopa.owl2java.config.TransformationConfiguration;
18: import org.apache.maven.plugin.AbstractMojo;
19: import org.apache.maven.plugins.annotations.Mojo;
20: import org.apache.maven.plugins.annotations.Parameter;
21:
22: @Mojo(name = "owl2java-transform")
23: public class OWL2JavaMojo extends AbstractMojo {
24:
25: private static final String MAPPING_FILE_PARAM = "mapping-file";
26: private static final String PACKAGE_PARAM = "package";
27: private static final String CONTEXT_PARAM = "context-name";
28: private static final String ONTOLOGY_PARAM = "ontology-iri";
29: private static final String OUTPUT_PARAM = "output-directory";
30: private static final String W_OWLAPI_PARAM = "with-owlapi";
31: private static final String ALL_IC_PARAM = "whole-ontology-as-ics";
32: private static final String VOCABULARY_PARAM = "vocabulary-only";
33: private static final String IGNORE_FAILED_IMPORTS_PARAM = "ignore-failed-imports";
34: private static final String PROPERTIES_TYPE = "properties-type";
35: private static final String GENERATE_JAVADOC = "javadoc-from-rdfs-comment";
36: private static final String PREFER_MULTILINGUAL_STRINGS = "prefer-multilingual-strings";
37:
38: @Parameter(alias = MAPPING_FILE_PARAM)
39: private String pMappingFile;
40:
41: @Parameter(alias = PACKAGE_PARAM)
42: private String pPackage;
43:
44: @Parameter(alias = CONTEXT_PARAM)
45: private String pContextName;
46:
47: @Parameter(alias = ONTOLOGY_PARAM)
48: private String pOntologyIRI;
49:
50: @Parameter(alias = OUTPUT_PARAM)
51: private String pOutputDirectory;
52:
53: @Parameter(alias = W_OWLAPI_PARAM, defaultValue = "false")
54: private boolean pWithOWLAPI;
55:
56: @Parameter(alias = ALL_IC_PARAM, defaultValue = "false")
57: private boolean pWholeOntologyAsICS;
58:
59: @Parameter(alias = VOCABULARY_PARAM, defaultValue = "false")
60: private boolean pVocabularyOnly;
61:
62: @Parameter(alias = IGNORE_FAILED_IMPORTS_PARAM, defaultValue = "false")
63: private boolean ignoreFailedImports;
64:
65: @Parameter(alias = PROPERTIES_TYPE, defaultValue = "string")
66: private String pPropertiesType;
67:
68: @Parameter(alias = GENERATE_JAVADOC, defaultValue = "true")
69: private boolean generateJavadoc;
70:
71: @Parameter(alias = PREFER_MULTILINGUAL_STRINGS, defaultValue = "true")
72: private boolean preferMultilingualStrings;
73:
74: @Override
75: public void execute() {
76: OWL2JavaTransformer owl2java = new OWL2JavaTransformer();
77:
78: printParameterValues();
79:
80:• if (pOntologyIRI == null) {
81: getLog().error("The parameter 'ontology-iri' is invalid. Must not be null.");
82: getLog().error("Skipping OWL2Java transformation.");
83: return;
84: }
85: owl2java.ignoreMissingImports(ignoreFailedImports);
86:
87:• if (pMappingFile != null && !pMappingFile.isEmpty()) {
88: owl2java.setOntology(pOntologyIRI, pMappingFile);
89: } else {
90: owl2java.setOntology(pOntologyIRI, null);
91: }
92:
93: final TransformationConfiguration.TransformationConfigurationBuilder builder =
94: TransformationConfiguration.builder();
95:• if (!pWholeOntologyAsICS) {
96: builder.context(pContextName);
97: }
98:
99:• if (pPropertiesType != null) {
100: builder.propertiesType(PropertiesType.valueOf(pPropertiesType));
101: }
102:
103: final TransformationConfiguration config =
104: builder.packageName(pPackage).targetDir(pOutputDirectory).addOwlapiIris(pWithOWLAPI)
105: .generateJavadoc(generateJavadoc).preferMultilingualStrings(preferMultilingualStrings).build();
106:
107:• if (pVocabularyOnly) {
108: owl2java.generateVocabulary(config);
109: } else {
110: owl2java.transform(config);
111: }
112:
113: getLog().info("OWL2Java successfully generated!");
114: }
115:
116: private void printParameterValues() {
117: getLog().info(MAPPING_FILE_PARAM + ": " + pMappingFile);
118: getLog().info(PACKAGE_PARAM + ": " + pPackage);
119: getLog().info(CONTEXT_PARAM + ": " + pContextName);
120: getLog().info(ONTOLOGY_PARAM + ": " + pOntologyIRI);
121: getLog().info(OUTPUT_PARAM + ": " + pOutputDirectory);
122: getLog().info(W_OWLAPI_PARAM + ": " + pWithOWLAPI);
123: getLog().info(ALL_IC_PARAM + ": " + pWholeOntologyAsICS);
124: getLog().info(VOCABULARY_PARAM + ": " + pVocabularyOnly);
125: getLog().info(IGNORE_FAILED_IMPORTS_PARAM + ": " + ignoreFailedImports);
126: getLog().info(PROPERTIES_TYPE + ": " + pPropertiesType);
127: getLog().info(GENERATE_JAVADOC + ": " + generateJavadoc);
128: getLog().info(PREFER_MULTILINGUAL_STRINGS + ": " + preferMultilingualStrings);
129: }
130: }