Loading pom.xml +30 −8 Original line number Diff line number Diff line Loading @@ -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> Loading @@ -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 Loading src/main/java/fr/emse/gitlab/saref/CMDConfigurations.java +1 −1 Original line number Diff line number Diff line Loading @@ -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) Loading src/main/java/fr/emse/gitlab/saref/Main.java +40 −24 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } Loading @@ -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()); Loading Loading @@ -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("\\", "/"); 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; } Loading @@ -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); Loading Loading @@ -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); Loading @@ -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(); Loading src/main/java/fr/emse/gitlab/saref/UnzipFile.java 0 → 100644 +48 −0 Original line number Diff line number Diff line 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 src/main/java/fr/emse/gitlab/saref/entities/git/Repository.java +5 −5 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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 Loading
pom.xml +30 −8 Original line number Diff line number Diff line Loading @@ -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> Loading @@ -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 Loading
src/main/java/fr/emse/gitlab/saref/CMDConfigurations.java +1 −1 Original line number Diff line number Diff line Loading @@ -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) Loading
src/main/java/fr/emse/gitlab/saref/Main.java +40 −24 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } Loading @@ -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()); Loading Loading @@ -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("\\", "/"); 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; } Loading @@ -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); Loading Loading @@ -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); Loading @@ -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(); Loading
src/main/java/fr/emse/gitlab/saref/UnzipFile.java 0 → 100644 +48 −0 Original line number Diff line number Diff line 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
src/main/java/fr/emse/gitlab/saref/entities/git/Repository.java +5 −5 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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