Skip to content

Commit

Permalink
Fix Apache Jena in write command for GraalVM build
Browse files Browse the repository at this point in the history
  • Loading branch information
atextor committed Oct 26, 2020
1 parent 58583e7 commit fe83c14
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 1 deletion.
1 change: 1 addition & 0 deletions cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies {
implementation(deps.owlapi) {
exclude group: 'org.slf4j', module: 'slf4j-simple'
}
implementation(deps.jena_core)
implementation(deps.vavr)
implementation(deps.picocli)
implementation(deps.logback)
Expand Down
6 changes: 6 additions & 0 deletions cli/src/main/java/de/atextor/owlcli/AbstractCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.google.common.collect.ImmutableSet;
import io.vavr.control.Try;
import org.apache.jena.sys.JenaSystem;
import org.semanticweb.owlapi.io.OWLParserFactory;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLOntology;
Expand Down Expand Up @@ -196,4 +197,9 @@ public Try<OWLOntology> loadOntology( final InputStream inputStream ) {
return Try.failure( exception );
}
}

protected void initJena() {
JenaSystem.setSubsystemRegistry( new StaticJenaSubsystemRegistry() );
JenaSystem.init();
}
}
2 changes: 2 additions & 0 deletions cli/src/main/java/de/atextor/owlcli/OWLCLIWriteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public void run() {
.outputFormat( outputFormat )
.inputFormat( inputFormat );

initJena();

final RdfWriter writer = new RdfWriter();

if ( input.toLowerCase().startsWith( "http:" ) || input.toLowerCase().startsWith( "https:" ) ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* This file is part of OWL-CLI.
* The contents of this file are subject to the LGPL License, Version 3.0.
* Copyright (c) 2020, Andreas Textor.
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
* You should have received a copy of the GNU General Public License along with this program. If not, see http://www
* .gnu.org/licenses/.
*/

package de.atextor.owlcli;

import org.apache.jena.sys.InitJenaCore;
import org.apache.jena.sys.JenaSubsystemLifecycle;
import org.apache.jena.sys.JenaSubsystemRegistry;

import java.util.ArrayList;
import java.util.List;

/**
* This class implements Jena's internal module registry, but unlike the default implementation
* {@link org.apache.jena.sys.JenaSubsystemRegistryBasic}, it does not depend on the service loader
* mechanism, which is disabled in OWL-CLI's GraalVM build.
* <p>
* The modules list therefore must contain all classes that are mentioned in the respective
* META-INF/services/org.apache.jena.sys.JenaSubsystemLifcycle of the used Jena dependencies.
*/
public class StaticJenaSubsystemRegistry implements JenaSubsystemRegistry {
private final List<JenaSubsystemLifecycle> modules = List.of( new InitJenaCore() );

@Override
public void load() {
// Nothing to do
}

@Override
public void add( final JenaSubsystemLifecycle module ) {
// Nothing to do
}

@Override
public boolean isRegistered( final JenaSubsystemLifecycle module ) {
return modules.contains( module );
}

@Override
public void remove( final JenaSubsystemLifecycle module ) {
// Nothing to do
}

@Override
public int size() {
return modules.size();
}

@Override
public boolean isEmpty() {
return modules.isEmpty();
}

@Override
public List<JenaSubsystemLifecycle> snapshot() {
return new ArrayList<>( modules );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@
"allDeclaredMethods":true,
"allPublicMethods":true
},
{
"name":"de.atextor.owlcli.OWLCLIWriteCommand",
"allDeclaredFields":true,
"allDeclaredMethods":true
},
{
"name":"java.lang.Object",
"allDeclaredFields":true,
Expand Down Expand Up @@ -336,6 +341,21 @@
"name":"java.time.ZonedDateTime",
"methods":[{"name":"parse","parameterTypes":["java.lang.CharSequence"] }]
},
{
"name":"org.apache.jena.ext.com.google.common.cache.Striped64",
"fields":[
{"name":"base", "allowUnsafeAccess":true},
{"name":"busy", "allowUnsafeAccess":true}
]
},
{
"name":"org.apache.jena.n3.N3TurtleJenaWriter",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"org.apache.jena.n3.turtle.TurtleReader",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"org.semanticweb.owlapi.apibinding.OWLManager$InjectorConstants",
"fields":[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"resources":[
{"pattern":"\\QMETA-INF/services/org.apache.jena.sys.JenaSubsystemLifecycle\\E"},
{"pattern":"\\Qorg/apache/jena/jena-properties.xml\\E"},
{"pattern":"\\Qorg/slf4j/impl/StaticLoggerBinder.class\\E"}
],
"bundles": [
{"name":"com.sun.org.apache.xerces.internal.impl.msg.XMLMessages"}
{"name":"com.sun.org.apache.xerces.internal.impl.msg.XMLMessages"},
{"name":"org.apache.jena.ext.xerces.impl.xpath.regex.message"}
]
}

0 comments on commit fe83c14

Please sign in to comment.