Skip to contentPackage: OWL2JavaMojo
OWL2JavaMojo
Coverage
1: /**
2: * Copyright (C) 2016 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.config.TransformationConfiguration;
17: import cz.cvut.kbss.jopa.owl2java.cli.PropertiesType;
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:
37: @Parameter(alias = MAPPING_FILE_PARAM)
38: private String pMappingFile;
39:
40: @Parameter(alias = PACKAGE_PARAM)
41: private String pPackage;
42:
43: @Parameter(alias = CONTEXT_PARAM)
44: private String pContextName;
45:
46: @Parameter(alias = ONTOLOGY_PARAM)
47: private String pOntologyIRI;
48:
49: @Parameter(alias = OUTPUT_PARAM)
50: private String pOutputDirectory;
51:
52: @Parameter(alias = W_OWLAPI_PARAM, defaultValue = "false")
53: private boolean pWithOWLAPI;
54:
55: @Parameter(alias = ALL_IC_PARAM, defaultValue = "false")
56: private boolean pWholeOntologyAsICS;
57:
58: @Parameter(alias = VOCABULARY_PARAM, defaultValue = "false")
59: private boolean pVocabularyOnly;
60:
61: @Parameter(alias = IGNORE_FAILED_IMPORTS_PARAM, defaultValue = "false")
62: private boolean ignoreFailedImports;
63:
64: @Parameter(alias = PROPERTIES_TYPE, defaultValue = "string")
65: private String pPropertiesType;
66:
67: @Parameter(alias = GENERATE_JAVADOC, defaultValue = "true")
68: private boolean generateJavadoc;
69:
70: @Override
71: public void execute() {
72: OWL2JavaTransformer owl2java = new OWL2JavaTransformer();
73:
74: printParameterValues();
75:
76:• if (pOntologyIRI == null) {
77: getLog().error("The parameter 'ontology-iri' is invalid. Must not be null.");
78: getLog().error("Skipping OWL2Java transformation.");
79: return;
80: }
81: owl2java.ignoreMissingImports(ignoreFailedImports);
82:
83:• if (pMappingFile != null && !pMappingFile.isEmpty()) {
84: owl2java.setOntology(pOntologyIRI, pMappingFile);
85: } else {
86: owl2java.setOntology(pOntologyIRI, null);
87: }
88:
89: final TransformationConfiguration.TransformationConfigurationBuilder builder =
90: TransformationConfiguration.builder();
91:• if (!pWholeOntologyAsICS) {
92: builder.context(pContextName);
93: }
94:
95:• if (pPropertiesType != null) {
96: builder.propertiesType(PropertiesType.valueOf(pPropertiesType));
97: }
98:
99: final TransformationConfiguration config =
100: builder.packageName(pPackage).targetDir(pOutputDirectory).addOwlapiIris(pWithOWLAPI)
101: .generateJavadoc(generateJavadoc).build();
102:
103:• if (pVocabularyOnly) {
104: owl2java.generateVocabulary(config);
105: } else {
106: owl2java.transform(config);
107: }
108:
109: getLog().info("OWL2Java successfully generated!");
110: }
111:
112: private void printParameterValues() {
113: getLog().info(MAPPING_FILE_PARAM + ": " + pMappingFile);
114: getLog().info(PACKAGE_PARAM + ": " + pPackage);
115: getLog().info(CONTEXT_PARAM + ": " + pContextName);
116: getLog().info(ONTOLOGY_PARAM + ": " + pOntologyIRI);
117: getLog().info(OUTPUT_PARAM + ": " + pOutputDirectory);
118: getLog().info(W_OWLAPI_PARAM + ": " + pWithOWLAPI);
119: getLog().info(ALL_IC_PARAM + ": " + pWholeOntologyAsICS);
120: getLog().info(VOCABULARY_PARAM + ": " + pVocabularyOnly);
121: getLog().info(IGNORE_FAILED_IMPORTS_PARAM + ": " + ignoreFailedImports);
122: getLog().info(PROPERTIES_TYPE + ": " + pPropertiesType);
123: getLog().info(GENERATE_JAVADOC + ": " + generateJavadoc);
124: }
125: }