Commit a2cde1df authored by Maxime Lefrançois's avatar Maxime Lefrançois

soon over ? getting tired

parent 95b2eae4
Pipeline #3828 passed with stage
in 2 minutes and 1 second
...@@ -86,8 +86,11 @@ public class CLIExecution implements SAREFCredentialsProvider { ...@@ -86,8 +86,11 @@ public class CLIExecution implements SAREFCredentialsProvider {
case "develop": case "develop":
mode = Mode.DEVELOP; mode = Mode.DEVELOP;
break; break;
case "portal": case "prerelease-portal":
mode = Mode.PORTAL; mode = Mode.PRERELEASE_PORTAL;
break;
case "release-portal":
mode = Mode.RELEASE_PORTAL;
break; break;
case "release": case "release":
mode = Mode.RELEASE; mode = Mode.RELEASE;
...@@ -99,7 +102,7 @@ public class CLIExecution implements SAREFCredentialsProvider { ...@@ -99,7 +102,7 @@ public class CLIExecution implements SAREFCredentialsProvider {
displayHelp(0); displayHelp(0);
throw new RuntimeException(); throw new RuntimeException();
default: default:
LOG.error(String.format("<mode> %s is invalid. Valid modes are develop, portal, release, help.", args[0])); LOG.error(String.format("<mode> %s is invalid. Valid modes are develop, portal, prerelease-portal, release-portal, help.", args[0]));
displayHelp(-1); displayHelp(-1);
throw new RuntimeException(); throw new RuntimeException();
} }
......
...@@ -67,6 +67,9 @@ public class SAREF { ...@@ -67,6 +67,9 @@ public class SAREF {
public static final String LOGGER_BASE = "SAREF Pipeline: "; public static final String LOGGER_BASE = "SAREF Pipeline: ";
public static final String NAME_SITE = "site"; public static final String NAME_SITE = "site";
public static final String NAME_SOURCES = "sources";
public static final String NAME_SOURCES_PORTAL = "portal";
// project acronym // project acronym
public static final String REGEX_ACRONYM_VAR = "acronym"; public static final String REGEX_ACRONYM_VAR = "acronym";
......
...@@ -56,7 +56,7 @@ public class SAREFPipeline { ...@@ -56,7 +56,7 @@ public class SAREFPipeline {
private static final String NAME_LOG_FILE = "output.log"; private static final String NAME_LOG_FILE = "output.log";
public static enum Mode { public static enum Mode {
DEVELOP, RELEASE, PORTAL, CLEAN DEVELOP, RELEASE, PRERELEASE_PORTAL, RELEASE_PORTAL, CLEAN
} }
private final TestSuites testSuites = new TestSuites("SAREF pipeline"); private final TestSuites testSuites = new TestSuites("SAREF pipeline");
...@@ -131,7 +131,7 @@ public class SAREFPipeline { ...@@ -131,7 +131,7 @@ public class SAREFPipeline {
sourcesManager.checkTerms(); sourcesManager.checkTerms();
sourcesManager.generateSite(); sourcesManager.generateSite();
sourcesManager.resetCheckout(); sourcesManager.resetCheckout();
if(mode == Mode.PORTAL) { if(mode == Mode.PRERELEASE_PORTAL || mode == Mode.RELEASE_PORTAL) {
datasetManager = new DatasetManager(this, logger); datasetManager = new DatasetManager(this, logger);
datasetManager.createDataset(); datasetManager.createDataset();
} }
......
...@@ -118,10 +118,14 @@ public class Clause_9_4_5_Checker extends AbstractClauseChecker { ...@@ -118,10 +118,14 @@ public class Clause_9_4_5_Checker extends AbstractClauseChecker {
} }
}); });
} }
checkOops(); try {
checkOops();
} catch (Exception ex) {
logWarning(getMessage(MESSAGE.oopsError), ex);
}
} }
public void checkOops() throws SAREFPipelineException { public void checkOops() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
String onto = ""; String onto = "";
......
...@@ -25,7 +25,11 @@ ...@@ -25,7 +25,11 @@
*/ */
package fr.emse.gitlab.saref.checkers; package fr.emse.gitlab.saref.checkers;
import java.io.*; import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystems; import java.nio.file.FileSystems;
import java.nio.file.PathMatcher; import java.nio.file.PathMatcher;
...@@ -97,8 +101,14 @@ public class Clause_9_5_Checker extends AbstractClauseChecker { ...@@ -97,8 +101,14 @@ public class Clause_9_5_Checker extends AbstractClauseChecker {
return; return;
} }
readTests(); // generates the RDF model for the tests readTests(); // generates the RDF model for the tests
callThemis(); // uses the RDF model for the tests and sends it to ThemisOWL profile, consistency, lack of pitfalls and class satisfiability
testsRDFaGenerator(); // this generates the html file with rdfa embedded. try {
callThemis(); // uses the RDF model for the tests and sends it to ThemisOWL profile, consistency, lack of pitfalls and class satisfiability
testsRDFaGenerator(); // this generates the html file with rdfa embedded.
} catch (Exception ex) {
logWarning(getMessage(MESSAGE.themis), ex);
}
} catch (IOException ex) { } catch (IOException ex) {
logError(getMessage(MESSAGE.ioexception)); logError(getMessage(MESSAGE.ioexception));
} }
......
...@@ -46,7 +46,8 @@ public class FunctionalitiesPanel extends JPanel { ...@@ -46,7 +46,8 @@ public class FunctionalitiesPanel extends JPanel {
final JButton fileChooser; final JButton fileChooser;
final JRadioButton develop; final JRadioButton develop;
final JRadioButton release; final JRadioButton release;
final JRadioButton portal; final JRadioButton prerelease_portal;
final JRadioButton release_portal;
final JCheckBox ignoreSite; final JCheckBox ignoreSite;
final JCheckBox ignoreExamples; final JCheckBox ignoreExamples;
final JCheckBox ignoreTerms; final JCheckBox ignoreTerms;
...@@ -78,26 +79,38 @@ public class FunctionalitiesPanel extends JPanel { ...@@ -78,26 +79,38 @@ public class FunctionalitiesPanel extends JPanel {
} }
} }
}); });
portal = new JRadioButton(SAREF.getMessage("portal")); prerelease_portal = new JRadioButton(SAREF.getMessage("prerelease_portal"));
portal.setToolTipText(SAREF.getMessage("portal_tooltip")); prerelease_portal.setToolTipText(SAREF.getMessage("prerelease_portal_tooltip"));
portal.addActionListener(new ActionListener() { prerelease_portal.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if(portal.isSelected()) { if(prerelease_portal.isSelected()) {
mainFrame.setMode(Mode.PORTAL); mainFrame.setMode(Mode.PRERELEASE_PORTAL);
}
}
});
release_portal = new JRadioButton(SAREF.getMessage("release_portal"));
release_portal.setToolTipText(SAREF.getMessage("release_portal_tooltip"));
release_portal.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(release_portal.isSelected()) {
mainFrame.setMode(Mode.RELEASE_PORTAL);
} }
} }
}); });
ButtonGroup modeGroup = new ButtonGroup(); ButtonGroup modeGroup = new ButtonGroup();
modeGroup.add(develop); modeGroup.add(develop);
modeGroup.add(release); modeGroup.add(release);
modeGroup.add(portal); modeGroup.add(prerelease_portal);
modeGroup.add(release_portal);
JPanel panel2 = new JPanel(); JPanel panel2 = new JPanel();
panel2.setLayout(new BoxLayout(panel2, BoxLayout.Y_AXIS)); panel2.setLayout(new BoxLayout(panel2, BoxLayout.Y_AXIS));
panel2.add(new JLabel(SAREF.getMessage("modes"))); panel2.add(new JLabel(SAREF.getMessage("modes")));
panel2.add(develop); panel2.add(develop);
panel2.add(release); panel2.add(release);
panel2.add(portal); panel2.add(prerelease_portal);
panel2.add(release_portal);
add(panel2); add(panel2);
ignoreSite = new JCheckBox(SAREF.getMessage("ignoreSite"), false); ignoreSite = new JCheckBox(SAREF.getMessage("ignoreSite"), false);
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
package fr.emse.gitlab.saref.managers; package fr.emse.gitlab.saref.managers;
import java.io.File; import java.io.File;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
...@@ -39,10 +38,6 @@ import org.apache.jena.query.text.TextDatasetFactory; ...@@ -39,10 +38,6 @@ import org.apache.jena.query.text.TextDatasetFactory;
import org.apache.jena.query.text.TextIndex; import org.apache.jena.query.text.TextIndex;
import org.apache.jena.query.text.TextIndexConfig; import org.apache.jena.query.text.TextIndexConfig;
import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.riot.Lang;
import org.apache.jena.tdb.TDBFactory; import org.apache.jena.tdb.TDBFactory;
import org.apache.jena.vocabulary.DCTerms; import org.apache.jena.vocabulary.DCTerms;
import org.apache.jena.vocabulary.OWL; import org.apache.jena.vocabulary.OWL;
...@@ -50,9 +45,7 @@ import org.apache.jena.vocabulary.OWL2; ...@@ -50,9 +45,7 @@ import org.apache.jena.vocabulary.OWL2;
import org.apache.jena.vocabulary.RDF; import org.apache.jena.vocabulary.RDF;
import org.apache.jena.vocabulary.RDFS; import org.apache.jena.vocabulary.RDFS;
import org.apache.lucene.analysis.en.EnglishAnalyzer; import org.apache.lucene.analysis.en.EnglishAnalyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.store.SimpleFSDirectory; import org.apache.lucene.store.SimpleFSDirectory;
import org.slf4j.Logger; import org.slf4j.Logger;
......
...@@ -122,7 +122,7 @@ public class OntologyManager extends SAREFErrorLogger { ...@@ -122,7 +122,7 @@ public class OntologyManager extends SAREFErrorLogger {
try { try {
return ONTOLOGY_MANAGER.loadOntologyFromOntologyDocument(iri); return ONTOLOGY_MANAGER.loadOntologyFromOntologyDocument(iri);
} catch (OWLOntologyCreationException ex) { } catch (OWLOntologyCreationException ex) {
log(logger, getMessage(MESSAGE.loading_error), ex, Mode.DEVELOP, Mode.RELEASE, Mode.PORTAL); log(logger, getMessage(MESSAGE.loading_error), ex, Mode.DEVELOP, Mode.RELEASE, Mode.PRERELEASE_PORTAL, Mode.RELEASE_PORTAL);
return null; return null;
} }
} }
...@@ -136,7 +136,7 @@ public class OntologyManager extends SAREFErrorLogger { ...@@ -136,7 +136,7 @@ public class OntologyManager extends SAREFErrorLogger {
try { try {
return ONTOLOGY_MANAGER.loadOntologyFromOntologyDocument(IRI.create(example.getIRI())); return ONTOLOGY_MANAGER.loadOntologyFromOntologyDocument(IRI.create(example.getIRI()));
} catch (OWLOntologyCreationException ex) { } catch (OWLOntologyCreationException ex) {
log(logger, getMessage(MESSAGE.loading_error), ex, Mode.DEVELOP, Mode.RELEASE, Mode.PORTAL); log(logger, getMessage(MESSAGE.loading_error), ex, Mode.DEVELOP, Mode.RELEASE, Mode.PRERELEASE_PORTAL, Mode.RELEASE_PORTAL);
return null; return null;
} }
} }
...@@ -147,7 +147,7 @@ public class OntologyManager extends SAREFErrorLogger { ...@@ -147,7 +147,7 @@ public class OntologyManager extends SAREFErrorLogger {
try { try {
return gen.getExplanations(axiomInconsistent, 10); return gen.getExplanations(axiomInconsistent, 10);
} catch (Exception ex) { } catch (Exception ex) {
log(logger, getMessage(MESSAGE.reasoning_error), ex, Mode.DEVELOP, Mode.RELEASE, Mode.PORTAL); log(logger, getMessage(MESSAGE.reasoning_error), ex, Mode.DEVELOP, Mode.RELEASE, Mode.PRERELEASE_PORTAL, Mode.RELEASE_PORTAL);
return null; return null;
} }
} }
......
...@@ -100,8 +100,7 @@ public class RepositoryFactory extends SAREFErrorLogger { ...@@ -100,8 +100,7 @@ public class RepositoryFactory extends SAREFErrorLogger {
log(msg, Mode.DEVELOP, Mode.RELEASE); log(msg, Mode.DEVELOP, Mode.RELEASE);
throw new SAREFPipelineException(msg); throw new SAREFPipelineException(msg);
} else { } else {
log(getMessage(MESSAGE.source_name, SAREF.REGEX_NAME_PROJECT, name), Mode.DEVELOP, Mode.RELEASE, logError(getMessage(MESSAGE.source_name, SAREF.REGEX_NAME_PROJECT, name));
Mode.PORTAL);
return null; return null;
} }
...@@ -135,7 +134,7 @@ public class RepositoryFactory extends SAREFErrorLogger { ...@@ -135,7 +134,7 @@ public class RepositoryFactory extends SAREFErrorLogger {
if (!m.find()) { if (!m.find()) {
if (isTarget && pipeline.mode == Mode.RELEASE) { if (isTarget && pipeline.mode == Mode.RELEASE) {
final String msg = String.format(getMessage(MESSAGE.release_branch, originalBranch)); final String msg = String.format(getMessage(MESSAGE.release_branch, originalBranch));
errorLogger.warn(msg); errorLogger.error(msg);
throw new SAREFPipelineException(msg); throw new SAREFPipelineException(msg);
} }
originalVersionName = guessVersion(project, directory); originalVersionName = guessVersion(project, directory);
...@@ -205,6 +204,18 @@ public class RepositoryFactory extends SAREFErrorLogger { ...@@ -205,6 +204,18 @@ public class RepositoryFactory extends SAREFErrorLogger {
for (Ref ref : allBranches) { for (Ref ref : allBranches) {
Matcher m = pattern.matcher(ref.getName()); Matcher m = pattern.matcher(ref.getName());
if (m.find()) { if (m.find()) {
String branchType = m.group(REGEX_VERSION_BRANCH_VAR);
// only consider release branches when running in RELEASE_PORTAL mode
if(pipeline.mode == Mode.RELEASE_PORTAL && !branchType.equals("release")) {
continue;
}
// only consider prerelease and release branches when running in PRERELEASE_PORTAL mode
if(pipeline.mode == Mode.PRERELEASE_PORTAL && branchType.equals("develop")) {
continue;
}
int major = Integer.parseInt(m.group(SAREF.REGEX_VERSION_MAJOR_VAR)); int major = Integer.parseInt(m.group(SAREF.REGEX_VERSION_MAJOR_VAR));
int minor = Integer.parseInt(m.group(SAREF.REGEX_VERSION_MINOR_VAR)); int minor = Integer.parseInt(m.group(SAREF.REGEX_VERSION_MINOR_VAR));
int patch = Integer.parseInt(m.group(SAREF.REGEX_VERSION_PATCH_VAR)); int patch = Integer.parseInt(m.group(SAREF.REGEX_VERSION_PATCH_VAR));
...@@ -215,7 +226,7 @@ public class RepositoryFactory extends SAREFErrorLogger { ...@@ -215,7 +226,7 @@ public class RepositoryFactory extends SAREFErrorLogger {
versionBuilder = new VersionBuilder(repository, versionName); versionBuilder = new VersionBuilder(repository, versionName);
versionBuilders.put(versionName, versionBuilder); versionBuilders.put(versionName, versionBuilder);
} }
switch (m.group(REGEX_VERSION_BRANCH_VAR)) { switch (branchType) {
case "develop": case "develop":
versionBuilder.developRef = ref; versionBuilder.developRef = ref;
break; break;
......
...@@ -42,7 +42,6 @@ import org.slf4j.Logger; ...@@ -42,7 +42,6 @@ import org.slf4j.Logger;
import fr.emse.gitlab.saref.SAREF; import fr.emse.gitlab.saref.SAREF;
import fr.emse.gitlab.saref.SAREFErrorLogger; import fr.emse.gitlab.saref.SAREFErrorLogger;
import fr.emse.gitlab.saref.SAREFPipeline; import fr.emse.gitlab.saref.SAREFPipeline;
import fr.emse.gitlab.saref.SAREFPipeline.Mode;
import fr.emse.gitlab.saref.SAREFPipelineException; import fr.emse.gitlab.saref.SAREFPipelineException;
import fr.emse.gitlab.saref.entities.SAREFExample; import fr.emse.gitlab.saref.entities.SAREFExample;
import fr.emse.gitlab.saref.entities.SAREFProject; import fr.emse.gitlab.saref.entities.SAREFProject;
...@@ -99,8 +98,7 @@ public class RepositoryManager extends SAREFErrorLogger { ...@@ -99,8 +98,7 @@ public class RepositoryManager extends SAREFErrorLogger {
return; return;
} }
SAREFVersion version = repository.getVersions().get(versionName); SAREFVersion version = repository.getVersions().get(versionName);
boolean prereleaseOnly = pipeline.mode == Mode.RELEASE || pipeline.mode == Mode.PORTAL; Ref ref = sourcesManager.getRef(version);
Ref ref = sourcesManager.getRef(version, prereleaseOnly);
if(ref == null) { if(ref == null) {
throw new SAREFPipelineException(); throw new SAREFPipelineException();
} }
...@@ -111,7 +109,7 @@ public class RepositoryManager extends SAREFErrorLogger { ...@@ -111,7 +109,7 @@ public class RepositoryManager extends SAREFErrorLogger {
currentVersionName = versionName; currentVersionName = versionName;
} catch (IOException | GitAPIException ex) { } catch (IOException | GitAPIException ex) {
String msg = getMessage(MESSAGE.checkout, repository.getProject().getName(), versionName); String msg = getMessage(MESSAGE.checkout, repository.getProject().getName(), versionName);
log(msg, ex, Mode.DEVELOP, Mode.RELEASE, Mode.PORTAL); logError(msg, ex);
throw new SAREFPipelineException(msg, ex); throw new SAREFPipelineException(msg, ex);
} }
} }
...@@ -128,7 +126,7 @@ public class RepositoryManager extends SAREFErrorLogger { ...@@ -128,7 +126,7 @@ public class RepositoryManager extends SAREFErrorLogger {
git.checkout().setName(originalBranch).call(); git.checkout().setName(originalBranch).call();
} catch (IOException | GitAPIException ex) { } catch (IOException | GitAPIException ex) {
String msg = getMessage(MESSAGE.reset, originalBranch); String msg = getMessage(MESSAGE.reset, originalBranch);
log(msg, ex, Mode.DEVELOP, Mode.RELEASE, Mode.PORTAL); logError(msg, ex);
throw new SAREFPipelineException(msg, ex); throw new SAREFPipelineException(msg, ex);
} }
} }
...@@ -154,7 +152,7 @@ public class RepositoryManager extends SAREFErrorLogger { ...@@ -154,7 +152,7 @@ public class RepositoryManager extends SAREFErrorLogger {
private void loadVersions(Git git, SAREFRepository repository) throws GitAPIException { private void loadVersions(Git git, SAREFRepository repository) throws GitAPIException {
for (SAREFVersion version : repository.getVersions().values()) { for (SAREFVersion version : repository.getVersions().values()) {
Ref ref = sourcesManager.getRef(version, false); Ref ref = sourcesManager.getRef(version);
if(ref == null) { if(ref == null) {
continue; continue;
} }
......
...@@ -32,10 +32,9 @@ import java.io.IOException; ...@@ -32,10 +32,9 @@ import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.jena.atlas.io.IndentedWriter; import org.apache.jena.atlas.io.IndentedWriter;
import org.apache.jena.graph.NodeFactory; import org.apache.jena.graph.NodeFactory;
...@@ -77,30 +76,27 @@ public class SiteManager extends SAREFErrorLogger { ...@@ -77,30 +76,27 @@ public class SiteManager extends SAREFErrorLogger {
private static final String EXAMPLE_QUERY = DOC_BASE + "example/main.rqg"; private static final String EXAMPLE_QUERY = DOC_BASE + "example/main.rqg";
private static final Var VAR_EXAMPLE = VarUtils.allocVar("example"); private static final Var VAR_EXAMPLE = VarUtils.allocVar("example");
private static final String NAME_STATIC = "static";
private static final String NAME_REPORT_HTML = "report.html"; private static final String NAME_REPORT_HTML = "report.html";
private static final String HTACCESS_HTML = "RewriteCond %{HTTP_ACCEPT} !(application/rdf\\+xml|text/turtle|text/n3|application/n\\-triples|application/ld\\+json)"; private static final String HTACCESS_PATH = "RewriteCond %{REQUEST_URI} ^(.*/)?[^/]*$\n";
private static final String HTACCESS_RDFXML = "RewriteCond %{HTTP_ACCEPT} application/rdf\\+xml";
private static final String HTACCESS_TURTLE = "RewriteCond %{HTTP_ACCEPT} text/turtle";
private static final String HTACCESS_N3 = "RewriteCond %{HTTP_ACCEPT} text/n3";
private static final String HTACCESS_NTRIPLE = "RewriteCond %{HTTP_ACCEPT} application/n-triples";
private static final String HTACCESS_JSONLD = "RewriteCond %{HTTP_ACCEPT} application/ld\\+json";
private static final SPARQLExtStreamManager STREAM_MANAGER_BASE = StreamManagerFactory.get(); private static final SPARQLExtStreamManager STREAM_MANAGER_BASE = StreamManagerFactory.get();
public final File siteDir; public final File siteDir;
public final File sourcesDir;
private final File reportFileHTML; private final File reportFileHTML;
private final RootPlan planForTerm; private final RootPlan planForTerm;
private final RootPlan planForOntologyVersion; private final RootPlan planForOntologyVersion;
private final RootPlan planForExample; private final RootPlan planForExample;
private static enum MESSAGE { private static enum MESSAGE {
prepare_error; prepare_target_error, prepare_portal_error;
} }
public SiteManager(SAREFPipeline pipeline, Logger errorLogger) throws IOException { public SiteManager(SAREFPipeline pipeline, Logger errorLogger) throws IOException {
super(pipeline, errorLogger); super(pipeline, errorLogger);
siteDir = new File(pipeline.targetDir, SAREF.NAME_SITE); siteDir = new File(pipeline.targetDir, SAREF.NAME_SITE);
sourcesDir = new File(pipeline.targetDir, SAREF.NAME_SOURCES);
reportFileHTML = new File(siteDir, NAME_REPORT_HTML); reportFileHTML = new File(siteDir, NAME_REPORT_HTML);
String query = IOUtils.toString(STREAM_MANAGER_BASE.open(new LookUpRequest(TERM_QUERY, SPARQLExt.MEDIA_TYPE)), String query = IOUtils.toString(STREAM_MANAGER_BASE.open(new LookUpRequest(TERM_QUERY, SPARQLExt.MEDIA_TYPE)),
...@@ -120,12 +116,29 @@ public class SiteManager extends SAREFErrorLogger { ...@@ -120,12 +116,29 @@ public class SiteManager extends SAREFErrorLogger {
* Prepare the site folder and clone the saref-portal-static project repository. * Prepare the site folder and clone the saref-portal-static project repository.
*/ */
public void prepareSite() throws SAREFPipelineException { public void prepareSite() throws SAREFPipelineException {
try (Git git = Git.cloneRepository().setURI(SAREF.SAREF_PORTAL_STATIC_GIT).setDirectory(siteDir).call()) { if(pipeline.mode == Mode.DEVELOP || pipeline.mode == Mode.RELEASE) {
} catch (Exception ex) { File portalSourcesDir = new File(sourcesDir, SAREF.NAME_SOURCES_PORTAL);
try (Git git = Git.open(siteDir)) { try (Git git = Git.cloneRepository().setURI(SAREF.SAREF_PORTAL_STATIC_GIT).setDirectory(portalSourcesDir).call()) {
git.pull().call(); File portal = new File(portalSourcesDir, SAREF.NAME_SOURCES_PORTAL);
FileUtils.copyDirectory(portal, siteDir);
} catch (Exception ex) {
try (Git git = Git.open(portalSourcesDir)) {
git.pull().call();
File portal = new File(portalSourcesDir, SAREF.NAME_SOURCES_PORTAL);
FileUtils.copyDirectory(portal, siteDir);
} catch (Exception e) {
String msg = getMessage(MESSAGE.prepare_target_error, SAREF.SAREF_PORTAL_STATIC_GIT);
logError(msg, e);
throw new SAREFPipelineException(msg, e);
}
}
} else {
try {
File portal = new File(pipeline.directory, SAREF.NAME_SOURCES_PORTAL);
FileUtils.copyDirectory(portal, siteDir);
} catch (Exception e) { } catch (Exception e) {
String msg = getMessage(MESSAGE.prepare_error, SAREF.SAREF_PORTAL_STATIC_GIT); // should have a folder portal
String msg = getMessage(MESSAGE.prepare_target_error, SAREF.SAREF_PORTAL_STATIC_GIT);
logError(msg, e); logError(msg, e);
throw new SAREFPipelineException(msg, e); throw new SAREFPipelineException(msg, e);
} }
...@@ -188,71 +201,50 @@ public class SiteManager extends SAREFErrorLogger { ...@@ -188,71 +201,50 @@ public class SiteManager extends SAREFErrorLogger {
public void generateHtaccess() { public void generateHtaccess() {
File htaccess = new File(siteDir, ".htaccess"); File htaccess = new File(siteDir, ".htaccess");
try (FileWriter writer = new FileWriter(htaccess)) { try (FileWriter writer = new FileWriter(htaccess)) {
writer.write("RewriteEngine on\nDirectorySlash Off\n\n"); writer.write("RewriteRule ^sources/(.*)$ https://forge.etsi.org/rep/SAREF/$1 [R=302]\n\n");
writer.write("nRewriteRule ^sources/(.*)$ https://forge.etsi.org/rep/SAREF/$1 [R=302,NE]\\n"); // redirect the sources
writer.write(HTACCESS_HTML);
writer.write("\nRewriteRule ^(.*)\\.conneg$ /$1.html\n");
writer.write(HTACCESS_JSONLD);
writer.write("\nRewriteRule ^(.*)\\.conneg$ /$1.jsonld\n");
writer.write(HTACCESS_N3);
writer.write("\nRewriteRule ^(.*)\\.conneg$ /$1.n3\n");
writer.write(HTACCESS_NTRIPLE);
writer.write("\nRewriteRule ^(.*)\\.conneg$ /$1.nt\n");
writer.write(HTACCESS_RDFXML);
writer.write("\nRewriteRule ^(.*)\\.conneg$ /$1.rdf\n");
writer.write(HTACCESS_TURTLE);
writer.write("\nRewriteRule ^(.*)\\.conneg$ /$1.ttl\n");
writer.write("\n");
for (RepositoryManager repositoryManager : pipeline.getSourcesManager().getSourceRepositoryManagers()) {
SAREFRepository repository = repositoryManager.getRepository();
SAREFProject project = repository.getProject();
SAREFVersion lastVersion = repository.getVersions().lastEntry().getValue();
// redirects core to core/v3.1.1/ writer.write(
// redirects core/ to core/v3.1.1/ "Header set Content-disposition \"expr=attachement; filename=%{resp:Content-Location}\" \"expr=%{resp:Content-Location} =~ /.(rdf|nt|n3)$/\"\n");
writer.write(String.format("RewriteRule ^%s/?$ /%s/ [R=302,NE]\n", project.getPath(), lastVersion.getVersionPath())); writer.write(
"Header set Content-disposition \"expr=inline; filename=%{resp:Content-Location}\" \"expr= %{resp:Content-Location} =~ /.+/ && !( %{resp:Content-Location} =~ /.(rdf|nt|n3)$/ )\"\n\n");
// redirects core/Sensor to core/Sensor.conneg
String choiceOfTerms = repository.getTerms().values().stream().map(SAREFTerm::getLocalName)
.collect(Collectors.joining("|", "(", ")"));
writer.write(String.format("RewriteCond %%{REQUEST_URI} ^/%s/%s$\n", project.getPath(), choiceOfTerms));
writer.write(String.format("RewriteRule ^%s/(.*)$ /%s/$1.conneg\n\n", project.getPath(), project.getPath()));
// redirects core.ttl to core/v1.1.1.ttl if (pipeline.getSourcesManager().getTargetRepositoryManager() != null) {
writer.write(String.format("RewriteRule ^%s\\.([^\\./]+)$ /%s.$1 [R=302,NE]\n\n", writeHtaccess(writer, pipeline.getSourcesManager().getTargetRepositoryManager());
project.getPath(), lastVersion.getVersionPath())); }
for (RepositoryManager repositoryManager : pipeline.getSourcesManager().getSourceRepositoryManagers()) {
for (SAREFVersion version : repository.getVersions().values()) { writeHtaccess(writer, repositoryManager);
writer.write(String.format("RewriteRule ^%s/?$ /%s/%s.conneg\n",
version.getVersionPath(), version.getVersionPath(), project.getOntologyFileName()));
// redirects core/v1.1.1.ttl to core/v1.1.1/saref.ttl
writer.write(String.format("RewriteRule ^%s\\.([^\\./]+)$ /%s/%s.$1 [R=302,NE]\n",
version.getVersionPath(), version.getVersionPath(), project.getOntologyFileName()));
// redirects core/v1.1.1/saref to core/v1.1.1/saref.conneg
writer.write(String.format("RewriteRule ^%s/%s$ /%s/%s.conneg\n",
version.getVersionPath(), project.getOntologyFileName(), version.getVersionPath(),
project.getOntologyFileName()));
// redirects core/v1.1.1/tests to core/v1.1.1/tests.conneg
writer.write(String.format("RewriteRule ^%s/tests$ /%s/tests.conneg\n",
version.getVersionPath(), version.getVersionPath()));
// redirects core/v1.1.1/requirements to core/v1.1.1/requirements.conneg
writer.write(String.format("RewriteRule ^%s/requirements$ /%s/requirements.conneg\n",
version.getVersionPath(), version.getVersionPath()));
for (SAREFExample example : version.getExamples().values()) {
writer.write(String.format("RewriteRule ^%s/example/%s$ /%s/example/%s.conneg\n",
version.getVersionPath(), example.getName(), version.getVersionPath(),
example.getName()));
}
writer.write("\n\n");
}
} }
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
private void writeHtaccess(FileWriter writer, RepositoryManager repositoryManager) throws IOException {
SAREFRepository repository = repositoryManager.getRepository();
SAREFProject project = repository.getProject();
if(repository.getVersions().isEmpty()) {
return;
}
SAREFVersion lastVersion = repository.getVersions().lastEntry().getValue();
// redirects core/ to core/v3.1.1/
writer.write(HTACCESS_PATH);
writer.write(
String.format("RewriteRule ^%s/$ %%1%s/ [R=302]\n", project.getPath(), lastVersion.getVersionName()));
// redirects core.ttl to core/v1.1.1.ttl
writer.write(HTACCESS_PATH);
writer.write(String.format("RewriteRule ^%s\\.([^\\./]+)$ %%1%s/%s.$1 [R=302]\n\n", project.getPath(),
lastVersion.getVersionPath(), project.getOntologyFileName()));
for (SAREFVersion version : repository.getVersions().values()) {
// redirects core/v3.1.1/ to core/v3.1.1/saref.conneg
writer.write(HTACCESS_PATH);
writer.write(String.format("RewriteRule ^%s/$ %%1%s\n", version.getVersionPath(),
project.getOntologyFileName()));
// redirects core/v1.1.1.ttl to core/v1.1.1/saref.ttl
writer.write(HTACCESS_PATH);
writer.write(String.format("RewriteRule ^%s\\.([^\\./]+)$ %%1%s/%s.$1 [R=302]\n", version.getVersionPath(),
version.getVersionName(), project.getOntologyFileName()));
writer.write("\n");
}
writer.write("\n");
}
} }
...@@ -72,7 +72,6 @@ public class SourcesManager extends SAREFErrorLogger { ...@@ -72,7 +72,6 @@ public class SourcesManager extends SAREFErrorLogger {
private static final Logger LOG = LoggerFactory.getLogger(SourcesManager.class); private static final Logger LOG = LoggerFactory.getLogger(SourcesManager.class);
private static final String CONFIGURATION_FILE_NAME = ".saref-repositories.yml"; private static final String CONFIGURATION_FILE_NAME = ".saref-repositories.yml";
private static final String NAME_SOURCES = "sources";