-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support TDB load and save apps and gradle tasks
- Loading branch information
Showing
20 changed files
with
1,397 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
subprojects { | ||
group = 'io.opencaesar.owl' | ||
version = '2.9.0' | ||
version = '2.10.0' | ||
|
||
ext.versions = [ | ||
owl: '5.1.17', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="bin/main" path="src/main/java"> | ||
<attributes> | ||
<attribute name="gradle_scope" value="main"/> | ||
<attribute name="gradle_used_by_scope" value="main,test"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/"/> | ||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/> | ||
<classpathentry kind="output" path="bin/default"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>owl-tdb-gradle</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
connection.project.dir=.. | ||
eclipse.preferences.version=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
eclipse.preferences.version=1 | ||
encoding/<project>=UTF-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 | ||
org.eclipse.jdt.core.compiler.compliance=17 | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning | ||
org.eclipse.jdt.core.compiler.release=enabled | ||
org.eclipse.jdt.core.compiler.source=17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
ext.title = 'OWL Load Gradle' | ||
description = 'A gradle interface to OWL Load' | ||
|
||
dependencies { | ||
implementation gradleApi() | ||
implementation project (':owl-tdb') | ||
implementation "xml-resolver:xml-resolver:${versions.xmlresolver}" | ||
implementation "commons-io:commons-io:${versions.commonsIo}" | ||
} |
206 changes: 206 additions & 0 deletions
206
owl-tdb-gradle/src/main/java/io/opencaesar/owl/tdb/OwlTdbLoadTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
/** | ||
* Copyright 2024 California Institute of Technology ("Caltech"). | ||
* U.S. Government sponsorship acknowledged. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.opencaesar.owl.tdb; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.GradleException; | ||
import org.gradle.api.file.DirectoryProperty; | ||
import org.gradle.api.provider.ListProperty; | ||
import org.gradle.api.provider.Property; | ||
import org.gradle.api.tasks.Input; | ||
import org.gradle.api.tasks.InputDirectory; | ||
import org.gradle.api.tasks.InputFile; | ||
import org.gradle.api.tasks.Optional; | ||
import org.gradle.api.tasks.OutputDirectory; | ||
import org.gradle.api.tasks.TaskAction; | ||
import org.gradle.work.Incremental; | ||
import org.gradle.work.InputChanges; | ||
|
||
/** | ||
* Gradle task to load Owl files to a TDB dataset | ||
*/ | ||
public abstract class OwlTdbLoadTask extends DefaultTask { | ||
|
||
/** | ||
* Creates a new OwlTdbLoadTask object | ||
*/ | ||
public OwlTdbLoadTask() { | ||
getOutputs().upToDateWhen(task -> { | ||
boolean incremental = getIncremental().isPresent() ? getIncremental().get() : true; | ||
if (incremental) { | ||
getInputFolder().set(getCatalogPath().get().getParentFile()); | ||
} | ||
return incremental; | ||
}); | ||
} | ||
|
||
/** | ||
* Path to a folder representing the TDB dataset (Required). | ||
* | ||
* @return String Property | ||
*/ | ||
@OutputDirectory | ||
public abstract Property<File> getDatasetPath(); | ||
|
||
/** | ||
* Path to an Apache catalog for OWL files (Required). | ||
* | ||
* @return File Property | ||
*/ | ||
@InputFile | ||
public abstract Property<File> getCatalogPath(); | ||
|
||
/** | ||
* File extensions for the loaded Owl files (optional, default is both owl and ttl, options: owl, rdf, xml, rj, ttl, n3, nt, trig, nq, trix, jsonld, fss). | ||
* | ||
* @return List of Strings Property | ||
*/ | ||
@Optional | ||
@Input | ||
public abstract ListProperty<String> getFileExtensions(); | ||
|
||
/** | ||
* A list of ontology IRIs to load (Optional). | ||
* | ||
* @return List of Strings | ||
*/ | ||
@Optional | ||
@Input | ||
public abstract ListProperty<String> getIris(); | ||
|
||
/** | ||
* A text file listing all ontology IRIs (one per line) to load (Optional). | ||
* | ||
* @return RegularFile Property | ||
*/ | ||
@Optional | ||
@InputFile | ||
public abstract Property<File> getIrisPath(); | ||
|
||
/** | ||
* Whether to load to named graphs (Optional, default is true). | ||
* | ||
* @return Boolean Property | ||
*/ | ||
@Optional | ||
@Input | ||
public abstract Property<Boolean> getLoadToNamedGraphs(); | ||
|
||
/** | ||
* Whether to load to the default graph (Optional, default is true). | ||
* | ||
* @return Boolean Property | ||
*/ | ||
@Optional | ||
@Input | ||
public abstract Property<Boolean> getLoadToDefaultGraph(); | ||
|
||
/** | ||
* Whether to load the dataset incrementally | ||
* | ||
* @return Boolean property | ||
*/ | ||
@Optional | ||
@Input | ||
public abstract Property<Boolean> getIncremental(); | ||
|
||
/** | ||
* The optional gradle task debug property (default is false). | ||
* | ||
* @return Boolean Property | ||
*/ | ||
@Optional | ||
@Input | ||
public abstract Property<Boolean> getDebug(); | ||
|
||
/** | ||
* The folder of input files for incremental load | ||
* | ||
* @return DirectoryProperty | ||
*/ | ||
@Incremental | ||
@InputDirectory | ||
@Optional | ||
protected abstract DirectoryProperty getInputFolder(); | ||
|
||
/** | ||
* The gradle task action logic. | ||
* | ||
* @param inputChanges The input changes | ||
*/ | ||
@TaskAction | ||
public void run(InputChanges inputChanges) { | ||
final ArrayList<String> args = new ArrayList<>(); | ||
args.add("-cm"); | ||
args.add(OwlTdbApp.Command.load.toString()); | ||
|
||
if (getDatasetPath().isPresent()) { | ||
args.add("-ds"); | ||
args.add(getDatasetPath().get().getAbsolutePath()); | ||
} | ||
if (getCatalogPath().isPresent()) { | ||
args.add("-c"); | ||
args.add(getCatalogPath().get().getAbsolutePath()); | ||
} | ||
if (getFileExtensions().isPresent()) { | ||
getFileExtensions().get().forEach(ext -> { | ||
args.add("-e"); | ||
args.add(ext); | ||
}); | ||
} | ||
if (getIris().isPresent()) { | ||
getIris().get().forEach(iri -> { | ||
args.add("-i"); | ||
args.add(iri); | ||
}); | ||
} | ||
if (getIrisPath().isPresent()) { | ||
args.add("-p"); | ||
args.add(getIrisPath().get().getAbsolutePath()); | ||
} | ||
if (getLoadToNamedGraphs().isPresent()) { | ||
args.add("-ng"); | ||
args.add(getLoadToNamedGraphs().get() ? "true" : "false"); | ||
} | ||
if (getLoadToDefaultGraph().isPresent()) { | ||
args.add("-dg"); | ||
args.add(getLoadToDefaultGraph().get() ? "true" : "false"); | ||
} | ||
if (getDebug().isPresent()) { | ||
if ( getDebug().get()) { | ||
args.add("-d"); | ||
} | ||
} | ||
|
||
try { | ||
if (getIncremental().isPresent() && !getIncremental().get()) { | ||
OwlTdbApp.main(args.toArray(new String[0])); | ||
} else { // run incrementally by default | ||
final Set<File> deltas = new HashSet<>(); | ||
inputChanges.getFileChanges(getInputFolder()).forEach(f -> deltas.add(f.getFile())); | ||
OwlTdbApp.mainWithDeltas(deltas, args.toArray(new String[0])); | ||
} | ||
} catch (Exception e) { | ||
throw new GradleException(e.getLocalizedMessage(), e); | ||
} | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
owl-tdb-gradle/src/main/java/io/opencaesar/owl/tdb/OwlTdbSaveTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/** | ||
* Copyright 2024 California Institute of Technology ("Caltech"). | ||
* U.S. Government sponsorship acknowledged. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.opencaesar.owl.tdb; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
|
||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.GradleException; | ||
import org.gradle.api.provider.Property; | ||
import org.gradle.api.tasks.Input; | ||
import org.gradle.api.tasks.InputDirectory; | ||
import org.gradle.api.tasks.Optional; | ||
import org.gradle.api.tasks.OutputFile; | ||
import org.gradle.api.tasks.TaskAction; | ||
import org.gradle.work.InputChanges; | ||
|
||
/** | ||
* Gradle task to save Owl files from a TDB dataset | ||
*/ | ||
public abstract class OwlTdbSaveTask extends DefaultTask { | ||
|
||
/** | ||
* Creates a new OwlTdbSaveTask object | ||
*/ | ||
public OwlTdbSaveTask() { | ||
getOutputs().upToDateWhen(task -> false); | ||
} | ||
|
||
|
||
/** | ||
* Path to a folder representing the TDB dataset (Required). | ||
* | ||
* @return String Property | ||
*/ | ||
@InputDirectory | ||
public abstract Property<File> getDatasetPath(); | ||
|
||
/** | ||
* Path to an Apache catalog for OWL files (Required). | ||
* | ||
* @return File Property | ||
*/ | ||
@OutputFile | ||
public abstract Property<File> getCatalogPath(); | ||
|
||
/** | ||
* File extension for the saved Owl files (optional, default is ttl, options: owl, rdf, xml, rj, ttl, n3, nt, trig, nq, trix, jsonld, fss). | ||
* | ||
* @return List of Strings Property | ||
*/ | ||
@Optional | ||
@Input | ||
public abstract Property<String> getFileExtension(); | ||
|
||
/** | ||
* The optional debug property (default is false). | ||
* | ||
* @return Boolean Property | ||
*/ | ||
@Optional | ||
@Input | ||
public abstract Property<Boolean> getDebug(); | ||
|
||
/** | ||
* The gradle task action logic. | ||
* | ||
* @param inputChanges The input changes | ||
*/ | ||
@TaskAction | ||
public void run(InputChanges inputChanges) { | ||
final ArrayList<String> args = new ArrayList<>(); | ||
args.add("-cm"); | ||
args.add(OwlTdbApp.Command.save.toString()); | ||
|
||
if (getDatasetPath().isPresent()) { | ||
args.add("-ds"); | ||
args.add(getDatasetPath().get().getAbsolutePath()); | ||
} | ||
if (getCatalogPath().isPresent()) { | ||
args.add("-c"); | ||
args.add(getCatalogPath().get().getAbsolutePath()); | ||
} | ||
if (getFileExtension().isPresent()) { | ||
args.add("-e"); | ||
args.add(getFileExtension().get()); | ||
} | ||
if (getDebug().isPresent()) { | ||
if ( getDebug().get()) { | ||
args.add("-d"); | ||
} | ||
} | ||
|
||
try { | ||
OwlTdbApp.main(args.toArray(new String[0])); | ||
} catch (Exception e) { | ||
throw new GradleException(e.getLocalizedMessage(), e); | ||
} | ||
} | ||
} |
Oops, something went wrong.