Skip to content

Commit

Permalink
Fix incremental build in all owl-tools
Browse files Browse the repository at this point in the history
  • Loading branch information
melaasar committed Apr 20, 2022
1 parent bd78648 commit c60053c
Show file tree
Hide file tree
Showing 10 changed files with 396 additions and 575 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
subprojects {
group = 'io.opencaesar.owl'
version = '1.0.0'
version = '1.0.1'

ext.versions = [
owl: '5.1.17',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,62 +1,58 @@
package io.opencaesar.owl.fuseki;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.RegularFile;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputDirectory;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;

public abstract class StartFusekiTask extends DefaultTask {

private final static Logger LOGGER = Logger.getLogger(StartFusekiTask.class);

static {
DOMConfigurator.configure(ClassLoader.getSystemClassLoader().getResource("startfuseki.log4j2.properties"));
}

@InputFile
public abstract RegularFileProperty getConfigurationPath();

// contributes to the output file property
public File outputFolderPath;
@OutputDirectory
public abstract DirectoryProperty getOutputFolderPath();

/*
As a side effect, set the outputFile property to FusekiApp.PID_FILENAME.
*/
@SuppressWarnings({ "unused", "deprecation" })
public void setOutputFolderPath(File path) {
outputFolderPath = path;
if (null != outputFolderPath) {
File pidFile = outputFolderPath.toPath().resolve(FusekiApp.PID_FILENAME).toFile();
LOGGER.info("StartFuseki(" + getName() + ") Configure outputFile = " + pidFile);
getOutputFile().fileValue(pidFile);
}
}

/**
* Since this Gradle property is configured as a side effect of configuring the output folder, it is not publicly exposed to users.
* @return The configured output file.
*/
@OutputFile
protected abstract RegularFileProperty getOutputFile();

@Input
@Optional
@Input
public abstract Property<Boolean> getWebUI();

@Input
@Optional
@Input
public abstract Property<Boolean> getDebug();

@OutputFile
protected Provider<RegularFile> getOutputFile() throws IOException {
if (getOutputFolderPath().isPresent()) {
var pidRegularFile = getOutputFolderPath().file(FusekiApp.PID_FILENAME);
var pidFile = pidRegularFile.get().getAsFile();
if (pidFile.exists()) {
java.util.Optional<Long> pid = FusekiApp.findFusekiProcessId(pidFile);
if (pid.isPresent()) {
java.util.Optional<ProcessHandle> ph = FusekiApp.findProcess(pid.get());
if (!ph.isPresent()) {
pidFile.delete();
}
}
}
return pidRegularFile;
}
return null;
}

@TaskAction
public void run() {
final ArrayList<String> args = new ArrayList<>();
Expand All @@ -66,9 +62,9 @@ public void run() {
args.add("-g");
args.add(getConfigurationPath().get().getAsFile().getAbsolutePath());
}
if (null != outputFolderPath) {
if (getOutputFolderPath().isPresent()) {
args.add("-o");
args.add(outputFolderPath.getAbsolutePath());
args.add(getOutputFolderPath().get().getAsFile().getAbsolutePath());
}
if (getWebUI().isPresent() && getWebUI().get()) {
args.add("-ui");
Expand All @@ -80,8 +76,8 @@ public void run() {
FusekiApp.main(args.toArray(new String[0]));

// Delete the 'fuseki.stopped' file to enable stopFuseki again.
if (null != outputFolderPath) {
File stoppedFile = outputFolderPath.toPath().resolve(FusekiApp.STOPPED_FILENAME).toFile();
if (getOutputFolderPath().isPresent()) {
File stoppedFile = getOutputFolderPath().get().getAsFile().toPath().resolve(FusekiApp.STOPPED_FILENAME).toFile();
if (stoppedFile.exists())
stoppedFile.delete();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,23 @@
package io.opencaesar.owl.fuseki;

import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;

import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.file.DirectoryProperty;
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;

public abstract class StopFusekiTask extends DefaultTask {

private final static Logger LOGGER = Logger.getLogger(StopFusekiTask.class);
@InputDirectory
public abstract DirectoryProperty getOutputFolderPath();

static {
DOMConfigurator.configure(ClassLoader.getSystemClassLoader().getResource("stopfuseki.log4j2.properties"));
}

// contributes to the output file property
public File outputFolderPath;

/*
As a side effect, set the output file property to FusekiApp.STOPPED_FILENAME.
*/
@SuppressWarnings({ "unused", "deprecation" })
public void setOutputFolderPath(File path) {
outputFolderPath = path;
if (null != outputFolderPath) {
File stopFile = outputFolderPath.toPath().resolve(FusekiApp.STOPPED_FILENAME).toFile();
LOGGER.info("StopFuseki(" + getName() + ") Configure outputFile = " + stopFile);
getOutputFile().fileValue(stopFile);
}
}

/**
* Since this Gradle property is configured as a side effect of configuring the output folder,
* it is not publicly exposed to users.
* @return The configured output file.
*/
@OutputFile
protected abstract RegularFileProperty getOutputFile();

@Input
@Optional
@Input
public abstract Property<Boolean> getDebug();

@SuppressWarnings({ "deprecation" })
Expand All @@ -58,29 +26,15 @@ public void run() {
final ArrayList<String> args = new ArrayList<>();
args.add("-c");
args.add(FusekiApp.Command.stop.toString());
if (null != outputFolderPath) {
if (getOutputFolderPath().isPresent()) {
args.add("-o");
args.add(outputFolderPath.getAbsolutePath());
args.add(getOutputFolderPath().get().getAsFile().getAbsolutePath());
}
if (getDebug().isPresent() && getDebug().get()) {
args.add("-d");
}
try {
FusekiApp.main(args.toArray(new String[0]));
// Generate a unique output for gradle incremental execution support.
if (getOutputFile().isPresent()) {
File output = getOutputFile().get().getAsFile();
LOGGER.info("StopFuseki("+getName()+") Generate output file: " + output);
try (PrintStream ps = new PrintStream(new FileOutputStream(output))) {
ps.println(getTaskIdentity().uniqueId);
}
}
// Delete the 'fuseki.pid' file to enable startFuseki again.
if (null != outputFolderPath) {
File pidFile = outputFolderPath.toPath().resolve(FusekiApp.PID_FILENAME).toFile();
if (pidFile.exists())
pidFile.delete();
}
} catch (Exception e) {
throw new GradleException(e.getLocalizedMessage(), e);
}
Expand Down
Loading

0 comments on commit c60053c

Please sign in to comment.