Commit deaf0f1c authored by Maxime Lefrançois's avatar Maxime Lefrançois
Browse files

working as jar and as CLI

parent 9977ca86
......@@ -158,16 +158,16 @@
<artifactId>shacl</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlexplanation</artifactId>
<version>5.0.0</version>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlexplanation</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>org.semanticweb.hermit</artifactId>
<version>1.4.5.519</version>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>org.semanticweb.hermit</artifactId>
<version>1.4.5.519</version>
</dependency>
</dependencies>
......@@ -175,6 +175,27 @@
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<finalName>static</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/static/assembly.xml</descriptor>
</descriptors>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
</configuration>
<executions>
<execution>
<id>static</id>
<phase>process-resources</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
......@@ -187,7 +208,8 @@
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>fr.emse.gitlab.saref.Main
......
......@@ -46,7 +46,7 @@ public class CMDConfigurations {
public static Options getCMDOptions() {
return new Options().addOption(ARG_HELP, ARG_HELP_LONG, false, ARG_HELP_MAN)
.addOption(ARG_INIT, ARG_INIT_LONG, true, ARG_INIT_MAN)
// .addOption(ARG_INIT, ARG_INIT_LONG, true, ARG_INIT_MAN)
.addOption(ARG_DIRECTORY, ARG_DIRECTORY_LONG, true, ARG_DIRECTORY_MAN)
.addOption(ARG_INCLUDE_MASTER, ARG_INCLUDE_MASTER_LONG, false, ARG_INCLUDE_MASTER_MAN)
.addOption(ARG_INCLUDE_ALL, ARG_INCLUDE_ALL_LONG, false, ARG_INCLUDE_ALL_MAN)
......
......@@ -13,12 +13,17 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
......@@ -157,12 +162,12 @@ public class Main {
private static void prepareDirectory() throws IOException {
target = new File(directory, Constants.TARGET_DIR);
FileUtils.forceMkdir(target);
File siteDir = new File(directory, Constants.SITE_DIR);
File staticTargetDir = new File(directory, Constants.STATIC_TARGET_DIR);
FileUtils.forceMkdir(siteDir);
FileUtils.forceMkdir(staticTargetDir);
File staticDir = new File(Main.class.getClassLoader().getResource("static").getFile());
FileUtils.copyDirectory(staticDir, staticTargetDir);
File staticTargetZip = new File(directory, Constants.STATIC_TARGET_DIR + ".zip");
URL url = Main.class.getClassLoader().getResource("static.zip");
FileUtils.copyURLToFile(url, staticTargetZip);
UnzipFile.unzip(staticTargetZip, staticTargetDir);
FileUtils.deleteQuietly(staticTargetZip);
}
......@@ -171,8 +176,10 @@ public class Main {
dataset = TDBFactory.createDataset(Constants.DATASET_DIR);
dataset.begin(ReadWrite.WRITE);
dataset.getDefaultModel().removeAll();
for (Iterator<String> it = dataset.listNames(); it.hasNext();) {
String name = it.next();
List<String> toRemove = new ArrayList<>();
Iterator<String> it = dataset.listNames();
while(it.hasNext()) { toRemove.add(it.next()); }
for(String name : toRemove) {
dataset.removeNamedModel(name);
}
dataset.addNamedModel(Constants.CONFIG, ModelFactory.createDefaultModel());
......@@ -270,19 +277,29 @@ public class Main {
dataset.end();
}
private static SPARQLExtStreamManager initializeStreamManager() throws IOException {
File documentationDir = new File(Main.class.getClassLoader().getResource("documentation").getFile());
Path dirPath = Paths.get(documentationDir.toURI());
LocatorFileAccept locator = new LocatorFileAccept(documentationDir.toURI().getPath());
private static SPARQLExtStreamManager initializeStreamManager() throws IOException, URISyntaxException {
URI uri = Main.class.getClassLoader().getResource("documentation").toURI();
Path dirPath;
if(uri.getScheme().equals("jar")) {
FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.<String, Object>emptyMap());
dirPath = fileSystem.getPath("/documentation");
} else {
dirPath = Paths.get(uri);
}
LocatorFileAccept locator = new LocatorFileAccept(uri.getPath());
LocationMapperAccept mapper = new LocationMapperAccept();
SPARQLExtStreamManager sm = SPARQLExtStreamManager.makeStreamManager(locator);
sm.setLocationMapper(mapper);
Files.walk(dirPath).filter((p) -> {
return p.toFile().isFile();
}).forEach((p) -> {
String relativePath = dirPath.relativize(p).toString();
String fileurl = Constants.BASE_DOC + relativePath.replace("\\", "/");
mapper.addAltEntry(fileurl, p.toString());
Files.walk(dirPath).forEach((p) -> {
String relativePath = dirPath.relativize(p).toString().replace("\\", "/");
String fileurl = Constants.BASE_DOC + relativePath;
System.out.println("add alt entry " + fileurl + " -> " + p.toString());
if(uri.getScheme().equals("jar")) {
mapper.addAltEntry(fileurl, p.toString().substring(1));
} else {
mapper.addAltEntry(fileurl, p.toString());
}
// mapper.addAltEntry(fileurl, relativePath);
});
return sm;
}
......@@ -290,9 +307,9 @@ public class Main {
private static void resetCheckout(Repository repository) {
try(Git git = Git.open(repository.getDirectory())) {
RevCommit currentRevCommit = repository.getCurrentRevCommit();
if(currentRevCommit != null) {
git.checkout().setStartPoint(currentRevCommit).call();
String currentBranch = repository.getCurrentBranch();
if(currentBranch != null) {
git.checkout().setStartPoint(currentBranch).call();
}
} catch (IOException | GitAPIException ex) {
LOG.warn("Error while reseting repository " + repository, ex);
......@@ -320,7 +337,7 @@ public class Main {
List<Binding> bindings = new ArrayList<>();
bindings.add(binding);
String query = IOUtils.toString(
streamManager.open(new LookUpRequest("report/main.rqg", SPARQLExt.MEDIA_TYPE)),
streamManager.open(new LookUpRequest("documentation/report/main.rqg", SPARQLExt.MEDIA_TYPE)),
StandardCharsets.UTF_8);
RootPlan reportPlan = PlanFactory.create(query, Constants.BASE_DOC);
reportPlan.execTemplateStream(bindings, context);
......@@ -329,11 +346,10 @@ public class Main {
if (openBrowser) {
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
Desktop.getDesktop().browse(reportHTML.toURI());
// Desktop.getDesktop().browse(new URI(
// Constants.BASE + "report.html?report=" + URLEncoder.encode(sw.toString(), "UTF-8")));
} else {
System.out.println("\n\n\nURL to the SAREF pipeline report:\n" + reportHTML.toURI());
}
}
// } catch (JAXBException | URISyntaxException | IOException ex) {
} catch (JAXBException | IOException ex) {
LOG.error("Exception:", ex);
ex.printStackTrace();
......
package fr.emse.gitlab.saref;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.apache.commons.io.FileUtils;
public class UnzipFile {
public static void unzip(File fileZip, File destDir) throws IOException {
byte[] buffer = new byte[1024];
ZipInputStream zis = new ZipInputStream(new FileInputStream(fileZip));
ZipEntry zipEntry = zis.getNextEntry();
while (zipEntry != null) {
File newFile = newFile(destDir, zipEntry);
if(zipEntry.isDirectory()) {
FileUtils.forceMkdir(newFile);
} else {
FileOutputStream fos = new FileOutputStream(newFile);
int len;
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
}
zipEntry = zis.getNextEntry();
}
zis.closeEntry();
zis.close();
}
public static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException {
File destFile = new File(destinationDir, zipEntry.getName());
String destDirPath = destinationDir.getCanonicalPath();
String destFilePath = destFile.getCanonicalPath();
if (!destFilePath.startsWith(destDirPath + File.separator)) {
throw new IOException("Entry is outside of the target dir: " + zipEntry.getName());
}
return destFile;
}
}
\ No newline at end of file
......@@ -36,7 +36,7 @@ public class Repository {
private final File directory;
private final String name;
private List<Version> versions;
private RevCommit currentRevCommit;
private String currentBranch;
private transient Resource resource;
public Repository(File directory, String name) {
......@@ -104,12 +104,12 @@ public class Repository {
}
}
public void setCurrentRevCommit(RevCommit currentRevCommit) {
this.currentRevCommit = currentRevCommit;
public void setCurrentBranch(String currentBranch) {
this.currentBranch = currentBranch;
}
public RevCommit getCurrentRevCommit() {
return currentRevCommit;
public String getCurrentBranch() {
return currentBranch;
}
}
\ No newline at end of file
......@@ -4,6 +4,8 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Calendar;
......@@ -107,9 +109,8 @@ public class CheckRepositoryStructure extends JobRunner {
logger.warn("The directory must contain a file named `LICENSE`");
return;
}
File licenseModelFile = new File(
CheckRepositoryStructure.class.getClassLoader().getResource("LICENSE_MODEL").getFile());
try (BufferedReader licenseModelFileReader = new BufferedReader(new FileReader(licenseModelFile));
InputStream licenseModelFile = CheckRepositoryStructure.class.getClassLoader().getResourceAsStream("LICENSE_MODEL");
try (BufferedReader licenseModelFileReader = new BufferedReader(new InputStreamReader(licenseModelFile));
BufferedReader licenseFileReader = new BufferedReader(new FileReader(licenseFile));) {
// first line
......
......@@ -37,15 +37,15 @@ import fr.emse.gitlab.saref.vocabs.RDFP;
public class GeneratePortal extends JobRunner {
private static final String DOC_BASE = Constants.BASE + "documentation/";
private static final String TERM_QUERY = "term/main.rqg";
private static final String TERM_QUERY = "documentation/term/main.rqg";
private static final Var VAR_TERM = VarUtils.allocVar("term");
private final RootPlan planForTerm;
private static final String ONTO_QUERY = "ontology/main.rqg";
private static final String ONTO_QUERY = "documentation/ontology/main.rqg";
private static final Var VAR_VERSION_IRI = VarUtils.allocVar("versionIRI");
private final RootPlan planForOntologyVersion;
private static final String EXAMPLE_QUERY = "example/main.rqg";
private static final String EXAMPLE_QUERY = "documentation/example/main.rqg";
private static final Var VAR_EXAMPLE = VarUtils.allocVar("example");
private final RootPlan planForExample;
......
......@@ -166,8 +166,8 @@ public class ReadRepositories extends JobRunner {
logger.error("The git repository is not clean. All other branches will be ignored.");
throw new RuntimeException("The git repository is not clean. All other branches will be ignored.");
}
RevCommit currentRevCommit = git.log().call().iterator().next();
repository.setCurrentRevCommit(currentRevCommit);
String currentBranch = git.getRepository().getBranch();
repository.setCurrentBranch(currentBranch);
List<Ref> remoteBranches = git.branchList().setListMode(ListBranchCommand.ListMode.REMOTE).call();
for (Ref ref : remoteBranches) {
String branch = ref.getName();
......
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>static</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<outputDirectory></outputDirectory>
<directory>src/main/static</directory>
<excludes>
<exclude>assembly.xml</exclude>
</excludes>
</fileSet>
</fileSets>
</assembly>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment