Search in sources :

Example 1 with XspTranspiler

use of org.openntf.nsfodp.transpiler.XspTranspiler in project org.openntf.nsfodp by OpenNTF.

the class TranspilerApplication method start.

@Override
public Object start(IApplicationContext context) throws Exception {
    String notesIni = System.getenv(NSFODPConstants.PROP_NOTESINI);
    if (notesIni != null && !notesIni.isEmpty()) {
        // $NON-NLS-1$
        String execDir = System.getenv("Notes_ExecDirectory");
        // $NON-NLS-1$
        DominoAPI.get().NotesInitExtended(execDir, "=" + notesIni);
    }
    NotesThread.sinitThread();
    try {
        Path xspSourceRoot = toPath(System.getenv(NSFODPConstants.PROP_XSP_SOURCE_ROOT));
        Path ccSourceRoot = toPath(System.getenv(NSFODPConstants.PROP_CC_SOURCE_ROOT));
        List<Path> updateSites = toPaths(System.getenv(NSFODPConstants.PROP_UPDATESITE));
        Path outputDirectory = toPath(System.getenv(NSFODPConstants.PROP_OUTPUTFILE));
        IProgressMonitor mon = new PrintStreamProgressMonitor(System.out);
        XspTranspiler transpiler = new XspTranspiler(TranspilerActivator.instance.getBundle().getBundleContext(), xspSourceRoot, ccSourceRoot, mon);
        if (updateSites != null && !updateSites.isEmpty()) {
            updateSites.stream().map(FilesystemUpdateSite::new).forEach(transpiler::addUpdateSite);
        }
        exec.submit(() -> {
            try {
                Path javaSourceRoot = transpiler.transpile();
                Files.walk(javaSourceRoot, FileVisitOption.FOLLOW_LINKS).forEach(p -> {
                    Path relativePath = javaSourceRoot.relativize(p);
                    Path dest = outputDirectory.resolve(relativePath);
                    try {
                        if (Files.isDirectory(p)) {
                            Files.createDirectories(dest);
                        } else {
                            Files.copy(p, dest, StandardCopyOption.REPLACE_EXISTING);
                        }
                    } catch (IOException e) {
                        throw new UncheckedIOException(e);
                    }
                });
                mon.done();
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }).get();
        // $NON-NLS-1$
        System.out.println(getClass().getName() + "#end");
        exec.shutdownNow();
        exec.awaitTermination(30, TimeUnit.SECONDS);
        return EXIT_OK;
    } finally {
        NotesThread.stermThread();
    }
}
Also used : Path(java.nio.file.Path) TranspilerActivator(org.openntf.nsfodp.transpiler.TranspilerActivator) StandardCopyOption(java.nio.file.StandardCopyOption) JsonJavaFactory(com.ibm.commons.util.io.json.JsonJavaFactory) IApplication(org.eclipse.equinox.app.IApplication) Path(java.nio.file.Path) ExecutorService(java.util.concurrent.ExecutorService) Files(java.nio.file.Files) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) NSFODPConstants(org.openntf.nsfodp.commons.NSFODPConstants) Executors(java.util.concurrent.Executors) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JsonParser(com.ibm.commons.util.io.json.JsonParser) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) DominoAPI(com.darwino.domino.napi.DominoAPI) JsonException(com.ibm.commons.util.io.json.JsonException) FilesystemUpdateSite(org.openntf.nsfodp.compiler.update.FilesystemUpdateSite) FileVisitOption(java.nio.file.FileVisitOption) Paths(java.nio.file.Paths) NotesThread(lotus.domino.NotesThread) XspTranspiler(org.openntf.nsfodp.transpiler.XspTranspiler) IApplicationContext(org.eclipse.equinox.app.IApplicationContext) PrintStreamProgressMonitor(org.openntf.nsfodp.commons.PrintStreamProgressMonitor) Collections(java.util.Collections) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PrintStreamProgressMonitor(org.openntf.nsfodp.commons.PrintStreamProgressMonitor) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) XspTranspiler(org.openntf.nsfodp.transpiler.XspTranspiler) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) JsonException(com.ibm.commons.util.io.json.JsonException)

Aggregations

DominoAPI (com.darwino.domino.napi.DominoAPI)1 JsonException (com.ibm.commons.util.io.json.JsonException)1 JsonJavaFactory (com.ibm.commons.util.io.json.JsonJavaFactory)1 JsonParser (com.ibm.commons.util.io.json.JsonParser)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 FileVisitOption (java.nio.file.FileVisitOption)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 StandardCopyOption (java.nio.file.StandardCopyOption)1 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 NotesThread (lotus.domino.NotesThread)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1