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

modularized pipeline

parent 3559c90c
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.emse.gitlab.saref</groupId>
<artifactId>saref-pipeline</artifactId>
<version>1.0-SNAPSHOT</version>
<name>saref-pipeline</name>
<developers>
<developer>
<name>Omar Qawasmeh</name>
<email>omar.alqawasmeh@emse.fr</email>
<url>https://perso.univ-st-etienne.fr/alo09685/</url>
<organization>Ecole des mines de Saint-Etienne</organization>
<organizationUrl>http://www.mines-stetienne.fr/</organizationUrl>
<timezone>+1</timezone>
</developer>
<developer>
<name>Maxime Lefrançois</name>
<email>maxime.lefrancois@emse.fr</email>
<url>http://www.maxime-lefrancois.info/</url>
<organization>Ecole des mines de Saint-Etienne</organization>
<organizationUrl>http://www.mines-stetienne.fr/</organizationUrl>
<timezone>+1</timezone>
</developer>
</developers>
<organization>
<name>École des Mines de Saint-Étienne</name>
<url>http://www.mines-stetienne.fr/</url>
</organization>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ssZ</maven.build.timestamp.format>
<jdk.version>1.8</jdk.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<sparql-generate.version>2.0-SNAPSHOT</sparql-generate.version>
</properties>
<dependencies>
<!-- <dependency> -->
<!-- <groupId>org.topbraid</groupId> -->
<!-- <artifactId>shacl</artifactId> -->
<!-- <version>1.3.1</version> -->
<!-- </dependency> -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-tdb</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>fr.emse.ci</groupId>
<artifactId>sparql-generate-jena</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>fr.emse.ci</groupId>
<artifactId>sparql-generate-markdown</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<!-- see Porcelain https://git-scm.com/book/uz/v2/Appendix-B%3A-Embedding-Git-in-your-Applications-JGit -->
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>5.2.1.201812262042-r</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
<type>jar</type>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>fr.emse.gitlab.saref.Main
</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>fr.emse.gitlab.saref</groupId>
<artifactId>saref-pipeline-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../saref-pipeline-parent/pom.xml</relativePath>
</parent>
<artifactId>saref-pipeline-cli</artifactId>
<name>SAREF-Pipeline-cli</name>
<packaging>jar</packaging>
<developers>
<developer>
<name>Omar Qawasmeh</name>
<email>omar.alqawasmeh@emse.fr</email>
<url>https://perso.univ-st-etienne.fr/alo09685/</url>
<organization>Ecole des mines de Saint-Etienne</organization>
<organizationUrl>http://www.mines-stetienne.fr/</organizationUrl>
<timezone>+1</timezone>
</developer>
</developers>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<!-- see Porcelain https://git-scm.com/book/uz/v2/Appendix-B%3A-Embedding-Git-in-your-Applications-JGit -->
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>5.2.1.201812262042-r</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>fr.emse.gitlab.saref</groupId>
<artifactId>saref-pipeline-core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>fr.emse.gitlab.saref.Main
</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
/**
*
*/
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 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);
}
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 static fr.emse.gitlab.saref.CMDConfigurations.*;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
......@@ -12,14 +14,16 @@ 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.log4j.Layout;
import org.apache.log4j.PatternLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.emse.gitlab.saref.api.JobRunner;
import fr.emse.gitlab.saref.entities.TestSuites;
import fr.emse.gitlab.saref.jobs.JobRunner;
import fr.emse.gitlab.saref.jobs.library.ReadOntologies;
import fr.emse.gitlab.saref.jobs.library.RepositoryStructureChecker;
import fr.emse.gitlab.saref.utils.SAREF;
......@@ -34,7 +38,22 @@ public class Main {
private static File directory;
private static File target;
public static void main(String[] args) throws IOException, InterruptedException, URISyntaxException, JAXBException {
public static void main(String[] args) throws IOException, InterruptedException, URISyntaxException, JAXBException, ParseException {
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);
if (dirName.equals("")) {
dirName = ARG_DIRECTORY_DEFAULT;
}
if (args.length == 0) {
directory = new File("").getAbsoluteFile();
} else if (args.length > 1) {
......@@ -45,8 +64,8 @@ public class Main {
}
target = new File(directory, "target");
FileUtils.forceDelete(target);
FileUtils.forceMkdir(target);
File logFile = new File(directory, "target/output.log");
ROOT_LOGGER.addAppender(new org.apache.log4j.RollingFileAppender(LAYOUT, logFile.getAbsolutePath(), false));
......
......@@ -4,6 +4,8 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -12,13 +14,31 @@ import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.riot.Lang;
import fr.emse.gitlab.saref.jobs.AbstractJobRunner;
import fr.emse.gitlab.saref.utils.SAREF;
public class ReadOntologies extends AbstractJobRunner {
static final Map<String, String> PREFIXES = new HashMap<String, String>();
static {
PREFIXES.put("owl", "http://www.w3.org/2002/07/owl#");
PREFIXES.put("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
PREFIXES.put("xsd", "http://www.w3.org/2001/XMLSchema#");
PREFIXES.put("dcterms", "http://purl.org/dc/terms/");
PREFIXES.put("vann", "http://purl.org/vocab/vann/");
PREFIXES.put("foaf", "http://xmlns.com/foaf/0.1/");
PREFIXES.put("schema", "http://schema.org/");
PREFIXES.put("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
PREFIXES.put("voaf", "http://purl.org/vocommons/voaf#");
PREFIXES.put("dce", "http://purl.org/dc/elements/1.1/");
PREFIXES.put("dct", "http://purl.org/dc/terms/");
PREFIXES.put("xml", "http://www.w3.org/XML/1998/namespace/");
PREFIXES.put("saref", "https://saref.etsi.org/core/");
}
public ReadOntologies(File dir) {
super(dir);
}
}
@Override
protected void doJob0() {
String repoName = getRepoName();
......@@ -30,10 +50,28 @@ public class ReadOntologies extends AbstractJobRunner {
private void checkOntology(String ontologyName) {
File ontologyFile = new File(directory, "ontology/" + ontologyName);
Model model = ModelFactory.createDefaultModel();
try(FileInputStream input = new FileInputStream(ontologyFile)) {
try (FileInputStream input = new FileInputStream(ontologyFile)) {
model.read(input, null, Lang.TTL.getLabel());
} catch ( Exception ex) {
} catch (Exception ex) {
error("Exception while reading the ontology file", ex);
return;
}
final Map<String, String> prefixes = model.getNsPrefixMap();
for(String s : PREFIXES.keySet()) {
if(prefixes.containsKey(s)) {
if(!prefixes.get(s).equals(PREFIXES.get(s))) {
failure(String.format("Prefix `%s:` in the ontology file is expected to be equal to `<%s>`. Got: `<%s>`", s, PREFIXES.get(s), prefixes.get(s)));
}
}
}
for(Map.Entry<String, String> entry : prefixes.entrySet()) {
String s = entry.getKey();
String l = entry.getValue();
if(l.contains("saref")) {
if(!l.matches(SAREF.REGEX_ONTO_SERIES_URI)) {
failure(String.format("Prefix `%s:` in the ontology file contains string \"saref\", but does not seem to match the official SAREF ontologies namespaces: `\\\\%s\\\\`. Got: `<%s>`", s, SAREF.REGEX_ONTO_SERIES_URI, l));
}
}
}
}
......@@ -42,16 +80,17 @@ public class ReadOntologies extends AbstractJobRunner {
try {
Files.walk(dir.toPath()).filter(p -> {
return p.endsWith(".ttl");
}).forEach(p->{
}).forEach(p -> {
File exampleFile = p.toFile();
Model model = ModelFactory.createDefaultModel();
try(FileInputStream input = new FileInputStream(exampleFile)) {
try (FileInputStream input = new FileInputStream(exampleFile)) {
model.read(input, null, Lang.TTL.getLabel());
} catch ( Exception ex) {
failure(String.format("Exception while reading the example file %s", exampleFile.toString()), ex.getClass().getSimpleName(), ex.getMessage());
} catch (Exception ex) {
failure(String.format("Exception while reading the example file %s", exampleFile.toString()),
ex.getClass().getSimpleName(), ex.getMessage());
}
});
} catch(IOException ex) {
} catch (IOException ex) {
error("Exception while walking the example directory", ex);
}
}
......
package fr.emse.gitlab.saref.utils;
import java.util.regex.Pattern;
public class SAREF {
public final static String BASE = "https://saref.etsi.org/";
public static final String REGEX_EXT = "(?<ext>core|saref4[a-z][a-z][a-z][a-z])";
public static final String REGEX_VERSION = "v(?<major>[1-9][0-9]*)\\.(?<minor>[0-9]+)\\.(?<patch>[0-9]+)";
public static final String REGEX_RELEASE_BRANCH = "^refs/remotes/origin/release-" + REGEX_VERSION + "$";
public static final Pattern REGEX_RELEASE_BRANCH_PATTERN = Pattern.compile(REGEX_RELEASE_BRANCH);
public static final String REGEX_TERM_URI = "^" + BASE + REGEX_EXT + "/(?<localName>[^/]+)$";
public static final Pattern REGEX_TERM_PATTERN = Pattern.compile(REGEX_TERM_URI);
public static final String REGEX_ONTO_URI = "^" + BASE + REGEX_EXT + "/" + REGEX_VERSION + "/$";
public static final Pattern REGEX_ONTO_PATTERN = Pattern.compile(REGEX_ONTO_URI);
public static final String REGEX_ONTO_SERIES_URI = "^" + BASE + REGEX_EXT + "/$";
public static final Pattern REGEX_ONTO_SERIES_PATTERN = Pattern.compile(REGEX_ONTO_SERIES_URI);
}
//module fr.emse.gitlab.saref.climodule {
// requires fr.emse.gitlab.saref.api;
// requires fr.emse.gitlab.saref.entities;
//}
\ No newline at end of file
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>fr.emse.gitlab.saref</groupId>
<artifactId>saref-pipeline-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../saref-pipeline-parent/pom.xml</relativePath>
</parent>
<artifactId>saref-pipeline-core</artifactId>
<name>SAREF-Pipeline-core</name>
<packaging>jar</packaging>
<developers>
<developer>
<name>Omar Qawasmeh</name>
<email>omar.alqawasmeh@emse.fr</email>
<url>https://perso.univ-st-etienne.fr/alo09685/</url>
<organization>Ecole des mines de Saint-Etienne</organization>
<organizationUrl>http://www.mines-stetienne.fr/</organizationUrl>
<timezone>+1</timezone>
</developer>
</developers>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.10.1</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package fr.emse.gitlab.saref.jobs;
package fr.emse.gitlab.saref.api;
import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import fr.emse.gitlab.saref.api.JobRunner;
import fr.emse.gitlab.saref.entities.TestCase;
import fr.emse.gitlab.saref.entities.TestCase.Status;
import fr.emse.gitlab.saref.entities.TestSuite;
......
package fr.emse.gitlab.saref.jobs;
package fr.emse.gitlab.saref.api;
import fr.emse.gitlab.saref.entities.TestSuites;
......
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