Skip to content

Commit

Permalink
upgrade to release versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Aklakan committed May 24, 2024
1 parent 0add4c6 commit c0db0a4
Show file tree
Hide file tree
Showing 17 changed files with 388 additions and 47 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ results.tsv
.vscode
dependency-reduced-pom.xml


.travis.yml

15 changes: 15 additions & 0 deletions docs/lsq-maven-plugin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
layout: default
title: Overview
nav_order: 10
---

# LSQ Maven Plugin

The [Linked SPARQL Queries](https://lsq.aksw.org/) (LSQ) Maven Plugin features the goals:

* `rdfize`: Extracts SPARQL queries from Web server logs (e.g. Apache, Virtuoso) and emits quad-based RDF data. Each graph corresponds to one query.
* `benchmark`: Takes a SPARQL query log as input and runs the queries against a configured endpoint.
The query log may be supplied in various formats, including that of the output of `rdfize`.


2 changes: 1 addition & 1 deletion lsq-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<inceptionYear>2024</inceptionYear>

<properties>
<lsq.version>2.0.0-RC3-SNAPSHOT</lsq.version>
<lsq.version>2.0.0-RC3</lsq.version>

<jenax.version>5.0.0-1</jenax.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.aksw.maven.plugin.lsq;

import org.aksw.jenax.arq.dataset.api.DatasetOneNg;
import org.aksw.jenax.arq.dataset.impl.DatasetGraphOneNgImpl;
import org.aksw.jenax.arq.dataset.impl.DatasetOneNgImpl;
import org.apache.jena.rdf.model.RDFNode;

public class DatasetOneNgImplBackport {
public static DatasetOneNg naturalDataset(RDFNode resource) {
return new DatasetOneNgImpl(DatasetGraphOneNgImpl.create(resource.asNode(), resource.getModel().getGraph()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.aksw.maven.plugin.lsq;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.AtomicMoveNotSupportedException;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Function;

import org.aksw.commons.lambda.throwing.ThrowingConsumer;

/** FIXME Delete this class as it has been moved to aksw-commons */
public class FileUtilsBackport {
public static void moveAtomicIfSupported(Consumer<String> warnCallback, Path source, Path target) throws IOException {
try {
Files.move(source, target, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
} catch (AtomicMoveNotSupportedException e) {
if (warnCallback != null) {
warnCallback.accept(String.format("Atomic move from %s to %s failed, falling back to copy", source, target));
}
Files.move(source, target, StandardCopyOption.REPLACE_EXISTING);
}
}

/** Actions if the target already exists */
public static enum OverwriteMode {
/** Raise an error */
ERROR,

/** Overwrite the target */
OVERWRITE,

/** Skip the write */
SKIP
}

public static void safeCreate(Path target, OverwriteMode overwriteAction, ThrowingConsumer<OutputStream> writer) throws Exception {
safeCreate(target, null, overwriteAction, writer);
}

public static void safeCreate(Path target, Function<OutputStream, OutputStream> encoder, OverwriteMode overwriteAction, ThrowingConsumer<OutputStream> writer) throws Exception {
Objects.requireNonNull(overwriteAction);

String fileName = target.getFileName().toString();
String tmpFileName = "." + fileName + ".tmp"; // + new Random().nextInt();
Path tmpFile = target.resolveSibling(tmpFileName);

Boolean fileExists = OverwriteMode.SKIP.equals(overwriteAction) || OverwriteMode.ERROR.equals(overwriteAction)
? Files.exists(target)
: null;

// Check whether the target already exists before we start writing the tmpFile
if (Boolean.TRUE.equals(fileExists) && OverwriteMode.ERROR.equals(overwriteAction)) {
throw new FileAlreadyExistsException(target.toAbsolutePath().toString());
}

if (!(Boolean.TRUE.equals(fileExists) && OverwriteMode.SKIP.equals(overwriteAction))) {
Path parent = target.getParent();
if (parent != null) {
Files.createDirectories(parent);
}

boolean allowOverwrite = OverwriteMode.OVERWRITE.equals(overwriteAction);
// What to do if the tmp file already exists?
try (OutputStream raw = Files.newOutputStream(tmpFile, allowOverwrite ? StandardOpenOption.CREATE : StandardOpenOption.CREATE_NEW);
OutputStream out = encoder != null ? encoder.apply(raw) : raw) {
writer.accept(out);
out.flush();
}
moveAtomicIfSupported(null, tmpFile, target);
}
}

/** Delete a path if it is an empty directory */
public void deleteDirectoryIfEmpty(Path path) throws IOException {
boolean isDirectory = Files.isDirectory(path);
if (isDirectory) {
boolean isEmpty = Files.list(path).count() == 0;
if (isEmpty) {
Files.delete(path);
}
}
}

}
Loading

0 comments on commit c0db0a4

Please sign in to comment.