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

new version - untested

parent 3430daf4
Copyright 2019 ETSI
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
/*
* Copyright 2020 ETSI
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package fr.emse.gitlab.saref;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.emse.gitlab.saref.SAREFPipeline.Mode;
/**
*
* @author Maxime Lefrançois, Omar Qawasmeh
*
*/
public class CLIExecution {
private static final Logger LOG = LoggerFactory.getLogger(CLIExecution.class);
private static final String ARG_IGNORE_EXAMPLES = "e";
private static final String ARG_IGNORE_EXAMPLES_LONG = "no-examples";
private static final String ARG_IGNORE_EXAMPLES_MAN = "Do not check examples";
private static final String ARG_IGNORE_SITE = "s";
private static final String ARG_IGNORE_SITE_LONG = "no-site";
private static final String ARG_IGNORE_SITE_MAN = "Do not generate the static portal";
private static final String ARG_IGNORE_TERMS = "t";
private static final String ARG_IGNORE_TERMS_LONG = "no-terms";
private static final String ARG_IGNORE_TERMS_MAN = "Do not generate the static portal for terms";
private static final Options OPTIONS = new Options()
.addOption(ARG_IGNORE_EXAMPLES, ARG_IGNORE_EXAMPLES_LONG, false, ARG_IGNORE_EXAMPLES_MAN)
.addOption(ARG_IGNORE_TERMS, ARG_IGNORE_TERMS_LONG, false, ARG_IGNORE_TERMS_MAN)
.addOption(ARG_IGNORE_SITE, ARG_IGNORE_SITE_LONG, false, ARG_IGNORE_SITE_MAN);
public static SAREFPipeline getSAREFPipeline(String[] args) throws RuntimeException {
if (args.length == 0) {
displayHelp(-1);
}
final Mode mode;
final boolean ignoreExamples;
final boolean ignoreTerms;
final boolean ignoreSite;
final File directory;
try {
switch (args[0]) {
case "develop":
mode = Mode.DEVELOP;
break;
case "portal":
mode = Mode.PORTAL;
break;
case "release":
mode = Mode.RELEASE;
break;
case "clean":
mode = Mode.CLEAN;
break;
case "help":
displayHelp(0);
throw new RuntimeException();
default:
LOG.error(String.format("<mode> %s is invalid. Valid modes are develop, portal, release, help.", args[0]));
displayHelp(-1);
throw new RuntimeException();
}
DefaultParser commandLineParser = new DefaultParser();
String[] options = Arrays.copyOfRange(args, 1, args.length);
CommandLine cl = commandLineParser.parse(OPTIONS, options, true);
String dirName = "";
if(!cl.getArgList().isEmpty()) {
dirName = cl.getArgList().get(0);
}
directory = new File(dirName).getCanonicalFile();
if (!directory.isDirectory()) {
LOG.error("The directory does not exist " + directory);
System.exit(-1);
}
ignoreExamples = cl.hasOption(ARG_IGNORE_EXAMPLES);
ignoreTerms = cl.hasOption(ARG_IGNORE_TERMS);
ignoreSite = cl.hasOption(ARG_IGNORE_SITE);
return new SAREFPipeline(directory, mode, ignoreExamples, ignoreTerms, ignoreSite);
} catch (IOException | ParseException ex) {
LOG.debug("Exception while parsing arguments", ex);
throw new RuntimeException();
}
}
private static void displayHelp(int returnCode) {
try {
String helpHeader = IOUtils.toString(
CLIExecution.class.getClassLoader().getResourceAsStream("cli/helpHeader.txt"), StandardCharsets.UTF_8);
String helpCmdLineSyntax = IOUtils.toString(
CLIExecution.class.getClassLoader().getResourceAsStream("cli/helpCmdLineSyntax.txt"),
StandardCharsets.UTF_8);
String helpFooter = IOUtils.toString(
CLIExecution.class.getClassLoader().getResourceAsStream("cli/helpFooter.txt"), StandardCharsets.UTF_8);
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(helpCmdLineSyntax, helpHeader, OPTIONS, helpFooter);
System.exit(returnCode);
} catch (IOException ex) {
LOG.debug("Exception while displaying help", ex);
throw new RuntimeException();
}
}
}
/**
*
*/
package fr.emse.gitlab.saref;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
/**
* @author Omar Qawasmeh
*
*/
public class CMDConfigurations {
public static final String ARG_HELP = "h";
public static final String ARG_HELP_LONG = "help";
public static final String ARG_HELP_MAN = "Show help";
public static final String ARG_INIT = "i";
public static final String ARG_INIT_LONG = "init";
public static final String ARG_INIT_MAN = "Initialize a new SAREF extension development in the current directory";
public static final String ARG_DIRECTORY = "d";
public static final String ARG_DIRECTORY_DEFAULT = "";
public static final String ARG_DIRECTORY_LONG = "dir";
public static final String ARG_DIRECTORY_MAN = "Location of the SAREF extension directory (default is .)";
public static final String ARG_REMOTE_ONLY = "r";
public static final String ARG_REMOTE_ONLY_LONG = "remote-only";
public static final String ARG_REMOTE_ONLY_MAN = "Do not check the directory itself. Only consider the repositories listed in the `.saref-repositories.yml` document. Used to generate the website for several extensions.";
public static final String ARG_IGNORE_GIT = "g";
public static final String ARG_IGNORE_GIT_LONG = "no-git";
public static final String ARG_IGNORE_GIT_MAN = "Only check the current state of the repository";
public static final String ARG_IGNORE_EXAMPLES = "e";
public static final String ARG_IGNORE_EXAMPLES_LONG = "ignore-examples";
public static final String ARG_IGNORE_EXAMPLES_MAN = "Only check the SAREF extension ontology. Ignore the examples.";
public static final String ARG_NO_SITE = "s";
public static final String ARG_NO_SITE_LONG = "no-site";
public static final String ARG_NO_SITE_MAN = "Do not generate the static website";
public static final String ARG_IGNORE_TERMS = "t";
public static final String ARG_IGNORE_TERMS_LONG = "no-terms";
public static final String ARG_IGNORE_TERMS_MAN = "Do not generate the website for terms";
public static final String ARG_INCLUDE_MASTER = "m";
public static final String ARG_INCLUDE_MASTER_LONG = "master";
public static final String ARG_INCLUDE_MASTER_MAN = "Check the master branches of the remote repositories listed in the `.saref-repositories.yml` document";
public static final String ARG_RELEASE = "x";
public static final String ARG_RELEASE_LONG = "release";
public static final String ARG_RELEASE_MAN = "Run in strict mode, only when on a branch `prerelease-vx.y.z` or `release-vx.y.z`";
public static final String ARG_VERBOSE = "v";
public static final String ARG_VERBOSE_LONG = "verbose";
public static final String ARG_VERBOSE_MAN = "Use verbose mode. (For example, use SPARQL-Generate in --debug-template mode when generating the documentation)";
public static CommandLine parseArguments(String[] args) throws ParseException {
DefaultParser commandLineParser = new DefaultParser();
CommandLine cl = commandLineParser.parse(getCMDOptions(), args);
return cl;
}
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_DIRECTORY, ARG_DIRECTORY_LONG, true, ARG_DIRECTORY_MAN)
.addOption(ARG_REMOTE_ONLY, ARG_REMOTE_ONLY_LONG, false, ARG_REMOTE_ONLY_MAN)
.addOption(ARG_IGNORE_EXAMPLES, ARG_IGNORE_EXAMPLES_LONG, false, ARG_IGNORE_EXAMPLES_MAN)
.addOption(ARG_IGNORE_TERMS, ARG_IGNORE_TERMS_LONG, false, ARG_IGNORE_TERMS_MAN)
.addOption(ARG_IGNORE_GIT, ARG_IGNORE_GIT_LONG, false, ARG_IGNORE_GIT_MAN)
.addOption(ARG_NO_SITE, ARG_NO_SITE_LONG, false, ARG_NO_SITE_MAN)
.addOption(ARG_INCLUDE_MASTER, ARG_INCLUDE_MASTER_LONG, false, ARG_INCLUDE_MASTER_MAN)
.addOption(ARG_RELEASE, ARG_RELEASE_LONG, false, ARG_RELEASE_MAN)
.addOption(ARG_VERBOSE, ARG_VERBOSE_LONG, false, ARG_VERBOSE_MAN);
}
public static void displayHelp() {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("java -jar saref-pipeline.jar", getCMDOptions());
System.exit(-1);
}
}
package fr.emse.gitlab.saref;
import java.io.File;
import java.nio.file.FileSystems;
import java.nio.file.PathMatcher;
import java.util.regex.Pattern;
public class Constants {
public final static String BASE = "https://saref.etsi.org/";
public final static String BASE_DOC = BASE + "documentation/";
public final static String LOGGER_BASE = "fr.emse.gitlab.saref.logger";
public final static String SAREF_PORTAL_STATIC_GIT = "https://gitlab.emse.fr/saref/saref-portal-static.git";
// public final static String SAREF_PORTAL_STATIC_GIT = "https://forge.etsi.org/rep/SAREF/saref-portal-static.git"; // uncomment when the project is public
public static final String REGEX_EXT = "(?<ext>core|saref4[a-z0-9]{4})";
public static final String REGEX_VERSION = "v(?<major>[1-9][0-9]*)\\.(?<minor>[0-9]+)\\.(?<patch>[0-9]+)";
public static final String REGEX_ONTO_SERIES_URI = "^" + BASE + REGEX_EXT + "/$";
public static final String REGEX_ONTO_URI = "^" + BASE + "(?<ext>core|saref4[a-z]{4})/(example/[^/]+[#/])?$";
// output
public static final String TARGET_DIR = "target";
public static final String DATASET_DIR = TARGET_DIR + File.separator + "tdb";
public static final String LOG_FILE_NAME = TARGET_DIR + File.separator + "output.log";
public static final String SITE_DIR = TARGET_DIR + File.separator + "site";
public static final String STATIC_TARGET_DIR = SITE_DIR + File.separator + "static";
public static final String CONFIG = BASE + "config";
}
/*
* Copyright 2020 ETSI
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package fr.emse.gitlab.saref;
import static fr.emse.gitlab.saref.CMDConfigurations.ARG_DIRECTORY;
import static fr.emse.gitlab.saref.CMDConfigurations.ARG_DIRECTORY_DEFAULT;
import static fr.emse.gitlab.saref.CMDConfigurations.ARG_HELP;
import static fr.emse.gitlab.saref.CMDConfigurations.ARG_IGNORE_EXAMPLES;
import static fr.emse.gitlab.saref.CMDConfigurations.ARG_IGNORE_GIT;
import static fr.emse.gitlab.saref.CMDConfigurations.ARG_IGNORE_TERMS;
import static fr.emse.gitlab.saref.CMDConfigurations.ARG_INCLUDE_MASTER;
import static fr.emse.gitlab.saref.CMDConfigurations.ARG_NO_SITE;
import static fr.emse.gitlab.saref.CMDConfigurations.ARG_REMOTE_ONLY;
import static fr.emse.gitlab.saref.CMDConfigurations.ARG_VERBOSE;
import java.awt.Desktop;
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.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.PathMatcher;
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;
import java.util.Map;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.ParseException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.jena.atlas.io.IndentedWriter;
import org.apache.jena.atlas.web.TypedInputStream;
import org.apache.jena.graph.NodeFactory;
import org.apache.jena.query.Dataset;
import org.apache.jena.query.ReadWrite;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.ResIterator;
import org.apache.jena.sparql.core.Var;
import org.apache.jena.sparql.engine.binding.Binding;
import org.apache.jena.sparql.engine.binding.BindingHashMap;
import org.apache.jena.sparql.util.Context;
import org.apache.jena.tdb.TDBFactory;
import org.apache.jena.vocabulary.RDF;
import org.apache.log4j.Layout;
import org.apache.log4j.PatternLayout;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.CheckoutConflictException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRefNameException;
import org.eclipse.jgit.api.errors.RefAlreadyExistsException;
import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.emse.ci.sparqlext.SPARQLExt;
import fr.emse.ci.sparqlext.engine.PlanFactory;
import fr.emse.ci.sparqlext.engine.RootPlan;
import fr.emse.ci.sparqlext.stream.LocationMapperAccept;
import fr.emse.ci.sparqlext.stream.LocatorFileAccept;
import fr.emse.ci.sparqlext.stream.LookUpRequest;
import fr.emse.ci.sparqlext.stream.SPARQLExtStreamManager;
import fr.emse.ci.sparqlext.utils.ContextUtils;
import fr.emse.ci.sparqlext.utils.VarUtils;
import fr.emse.gitlab.saref.entities.git.Repositories;
import fr.emse.gitlab.saref.entities.git.Repository;
import fr.emse.gitlab.saref.entities.git.Version;
import fr.emse.gitlab.saref.entities.tests.TestSuites;
import fr.emse.gitlab.saref.jobs.CheckConfig;
import fr.emse.gitlab.saref.jobs.CheckOWLProfile;
import fr.emse.gitlab.saref.jobs.CheckRepositoryStructure;
import fr.emse.gitlab.saref.jobs.CheckoutJob;
import fr.emse.gitlab.saref.jobs.GeneratePortal;
import fr.emse.gitlab.saref.jobs.ReadExamples;
import fr.emse.gitlab.saref.jobs.ReadOntology;
import fr.emse.gitlab.saref.jobs.ReadRepositories;
import fr.emse.gitlab.saref.utils.TestSuitesAppender;
import fr.emse.gitlab.saref.vocabs.EX;
/**
*
* @author Maxime Lefrançois
*
*/
public class Main {
static final Logger LOG = LoggerFactory.getLogger(Constants.LOGGER_BASE + ".Main");
public final static String BASE_DOC = Constants.BASE + "documentation/";
public static final PathMatcher ttlMatcher = FileSystems.getDefault().getPathMatcher("glob:**/*.ttl");
private static TestSuites testSuites = new TestSuites("SAREF pipeline");
private static final Map<String, String> testSuiteNames = new HashMap<>();
private static File directory;
private static File target;
private static SPARQLExtStreamManager streamManager;
private static boolean openBrowser = true;
private static Dataset dataset;
private static Var VAR_TEST_SUITES = VarUtils.allocVar("testsuites");
static boolean remoteOnly;
static boolean ignoreGit;
static boolean includeMaster;
static boolean generateSite;
static boolean ignoreTerms;
static boolean ignoreExamples;
static boolean verbose;
public static void main(String[] args) throws IOException, InterruptedException, URISyntaxException, JAXBException,
ParseException, RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException,
CheckoutConflictException, GitAPIException {
CommandLine cl = CMDConfigurations.parseArguments(args);
if (cl.getOptions().length == 0 || cl.hasOption(ARG_HELP)) {
CMDConfigurations.displayHelp();
return;
}
String dirName = cl.getOptionValue(ARG_DIRECTORY, ARG_DIRECTORY_DEFAULT);
directory = new File(dirName).getCanonicalFile();
if (!directory.isDirectory()) {
LOG.error("The directory does not exist " + directory);
System.exit(-1);
}
remoteOnly = cl.hasOption(ARG_REMOTE_ONLY);
ignoreGit = cl.hasOption(ARG_IGNORE_GIT);
includeMaster = cl.hasOption(ARG_INCLUDE_MASTER);
generateSite = !cl.hasOption(ARG_NO_SITE);
ignoreExamples = cl.hasOption(ARG_IGNORE_EXAMPLES);
ignoreTerms = cl.hasOption(ARG_IGNORE_TERMS);
verbose = cl.hasOption(ARG_VERBOSE);
setLogAppenders();
prepareDirectory();
streamManager = initializeStreamManager();
dataset = createFreshDataset();
LOG.info("Starting pipeline in " + directory);
Repositories repositories;
try {
repositories = new ReadRepositories("Fetching required repositories").readRepositories(directory,
remoteOnly, ignoreGit, includeMaster);
} catch (Exception ex) {
reportAndExit(-1);
return;
}
if (repositories.getDefaultRepository() != null) {
Repository repository = repositories.getDefaultRepository();
boolean checkExamples = !ignoreExamples;
testRepository(repository, checkExamples);
}
for (Repository repository : repositories.getNamedRepositories()) {
boolean checkExamples = !ignoreExamples && remoteOnly;
testRepository(repository, checkExamples);
}
checkOWLProfile();
new CheckConfig().doJob(dataset, ignoreExamples);
if (generateSite) {
new GeneratePortal("Generate static files for the portal", streamManager).doJob(dataset, directory, verbose,
ignoreExamples, ignoreTerms);
}
if (repositories.getDefaultRepository() != null && !ignoreGit) {
Repository repository = repositories.getDefaultRepository();
resetCheckout(repository);
}
for (Repository repository : repositories.getNamedRepositories()) {
resetCheckout(repository);
}
testSuites.clean();
reportAndExit((int) -Math.signum(testSuites.getErrors() + testSuites.getFailures()));
}
private static void setLogAppenders() throws IOException {
File logFile = new File(directory, Constants.LOG_FILE_NAME);
Layout layout = new PatternLayout("%d{mm:ss,SSS} %t %-5p %c:%L - %m%n");
org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();
rootLogger.addAppender(new org.apache.log4j.RollingFileAppender(layout, logFile.getAbsolutePath(), false));
org.apache.log4j.Logger loggerBase = org.apache.log4j.Logger.getLogger(Constants.LOGGER_BASE);
TestSuitesAppender appender = new TestSuitesAppender(testSuites);
loggerBase.addAppender(appender);
}
private static void prepareDirectory() throws IOException {
target = new File(directory, Constants.TARGET_DIR);
File site = new File(directory, Constants.SITE_DIR);
FileUtils.forceMkdir(target);
if (generateSite) {
try (Git git = Git.cloneRepository().setURI(Constants.SAREF_PORTAL_STATIC_GIT).setDirectory(site).call()) {
LOG.info(String.format("Cloning site repository %s", Constants.SAREF_PORTAL_STATIC_GIT));
} catch (Exception ex) {
try (Git git = Git.open(site)) {
git.pull().call();
LOG.info(String.format("Pulling site repository %s", Constants.SAREF_PORTAL_STATIC_GIT));
} catch (Exception e) {
throw new IOException(String.format("Failed to clone or pull site repository %s", Constants.SAREF_PORTAL_STATIC_GIT), e);
}
}
}
}
private static Dataset createFreshDataset() throws IOException {
File datasetDir = new File(directory, Constants.DATASET_DIR);
FileUtils.forceMkdir(datasetDir);
dataset = TDBFactory.createDataset(datasetDir.getAbsolutePath());
dataset.begin(ReadWrite.WRITE);
dataset.getDefaultModel().removeAll();
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());
dataset.commit();
return dataset;
}
private static void testRepository(Repository repository, boolean checkExamples) {
for (Version version : repository.getVersions()) {
try {
String versionTestSuiteName = version.toString() + " - testing repository structure";
new CheckoutJob(versionTestSuiteName).checkoutVersion(version);
new CheckRepositoryStructure(versionTestSuiteName).check(version);
} catch (SAREFPipelineException ex) {
LOG.error("Error while testing repository structure " + version, ex);
continue;
}
try {
String ontologyTestSuiteName = version.toString() + " - testing ontology file";
testSuiteNames.put(version.getUri(), ontologyTestSuiteName);
new ReadOntology(ontologyTestSuiteName).doJob(dataset, version);
} catch (SAREFPipelineException ex) {
LOG.error(version.toString() + " Found errors for " + version.toString()
+ ". This version and all the examples will be ignored.", ex);
contin