Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package fr.emse.gitlab.saref;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
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.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;
public class Main {
static final Logger LOG = LoggerFactory.getLogger(Main.class);
private static final Layout LAYOUT = new PatternLayout("%d{mm:ss,SSS} %t %-5p %c:%L - %m%n");
private static final org.apache.log4j.Logger ROOT_LOGGER = org.apache.log4j.Logger.getRootLogger();
private static TestSuites testSuites = new TestSuites();
private static File directory;
private static File target;
public static void main(String[] args) throws IOException, InterruptedException, URISyntaxException, JAXBException {
if (args.length == 0) {
directory = new File("").getAbsoluteFile();
} else if (args.length > 1) {
throw new IllegalArgumentException(
"Expecting at most one argument: the location of the SAREF directory where to run the pipeline");
} else {
directory = new File(args[0]).getAbsoluteFile();
}
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));
LOG.info("Starting pipeline");
JobRunner checker = new RepositoryStructureChecker(directory);
checker.doJob(testSuites);
if(testSuites.getErrors() > 0) {
reportAndExit(-1);
}
checker = new ReadOntologies(directory);
checker.doJob(testSuites);
reportAndExit(0);
}
private static void reportAndExit(int code) {
try {
File report = new File(target, "report_output.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(TestSuites.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
jaxbMarshaller.marshal(testSuites, report);
jaxbMarshaller.marshal(testSuites, System.out);
final StringWriter sw = new StringWriter();
jaxbMarshaller.marshal(testSuites, sw);
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
Desktop.getDesktop().browse(new URI(SAREF.BASE + "report.html?report=" + URLEncoder.encode(sw.toString(), "UTF-8")));
}
} catch(JAXBException | URISyntaxException | IOException ex) {
LOG.error("Exception:", ex);
ex.printStackTrace();
}
System.exit(code);
}
// private static void testRead() {
// try {
// JAXBContext jaxbContext = JAXBContext.newInstance(TestSuite.class);
// Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
//
// TestCase testCase = (TestCase) jaxbUnmarshaller.unmarshal(target);
//
// } catch (JAXBException e) {
// e.printStackTrace();
// }
// }
}