Search in sources :

Example 1 with PrintStreamProgressMonitor

use of org.openntf.nsfodp.commons.PrintStreamProgressMonitor 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)

Example 2 with PrintStreamProgressMonitor

use of org.openntf.nsfodp.commons.PrintStreamProgressMonitor in project org.openntf.nsfodp by OpenNTF.

the class CompilerApplication 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");
        try (NotesAPI api = NotesAPI.get()) {
            // $NON-NLS-1$
            api.NotesInitExtended(execDir, "=" + notesIni);
        }
    }
    try {
        NotesThread.sinitThread();
    } catch (Exception e) {
        // Known exception message during Notes initialization - error code 0x0102
        if (String.valueOf(e.getMessage()).endsWith(" - err 258")) {
            // $NON-NLS-1$
            throw new Exception("Encountered Notes exception ERR_PROTECTED (0x0102): Cannot write or create file (file or disk is read-only)");
        }
        throw e;
    }
    try {
        Path odpDirectory = toPath(System.getenv(NSFODPConstants.PROP_ODPDIRECTORY));
        List<Path> updateSites = toPaths(System.getenv(NSFODPConstants.PROP_UPDATESITE));
        Path outputFile = toPath(System.getenv(NSFODPConstants.PROP_OUTPUTFILE));
        IProgressMonitor mon = new PrintStreamProgressMonitor(System.out);
        OnDiskProject odp = new OnDiskProject(odpDirectory);
        ODPCompiler compiler = new ODPCompiler(ODPCompilerActivator.instance.getBundle().getBundleContext(), odp, mon);
        // See if the client requested a specific compiler level
        String compilerLevel = System.getenv(NSFODPConstants.PROP_COMPILERLEVEL);
        if (StringUtil.isNotEmpty(compilerLevel)) {
            compiler.setCompilerLevel(compilerLevel);
        }
        String appendTimestamp = System.getenv(NSFODPConstants.PROP_APPENDTIMESTAMPTOTITLE);
        if ("true".equals(appendTimestamp)) {
            // $NON-NLS-1$
            compiler.setAppendTimestampToTitle(true);
        }
        String templateName = System.getenv(NSFODPConstants.PROP_TEMPLATENAME);
        if (StringUtil.isNotEmpty(templateName)) {
            compiler.setTemplateName(templateName);
            String templateVersion = System.getenv(NSFODPConstants.PROP_TEMPLATEVERSION);
            if (StringUtil.isNotEmpty(templateVersion)) {
                compiler.setTemplateVersion(templateVersion);
            }
        }
        String setXspOptions = System.getenv(NSFODPConstants.PROP_SETPRODUCTIONXSPOPTIONS);
        if ("true".equals(setXspOptions)) {
            // $NON-NLS-1$
            compiler.setSetProductionXspOptions(true);
        }
        String odsRelease = System.getenv(NSFODPConstants.PROP_ODSRELEASE);
        if (StringUtil.isNotEmpty(odsRelease)) {
            compiler.setOdsRelease(odsRelease);
        }
        String compileBasicLs = System.getenv(NSFODPConstants.PROP_COMPILEBASICLS);
        if ("true".equals(compileBasicLs)) {
            // $NON-NLS-1$
            compiler.setCompileBasicElementLotusScript(true);
        }
        if (updateSites != null && !updateSites.isEmpty()) {
            updateSites.stream().map(FilesystemUpdateSite::new).forEach(compiler::addUpdateSite);
        }
        exec.submit(() -> {
            try {
                Path nsf = compiler.compile();
                Files.move(nsf, outputFile, StandardCopyOption.REPLACE_EXISTING);
                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) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PrintStreamProgressMonitor(org.openntf.nsfodp.commons.PrintStreamProgressMonitor) OnDiskProject(org.openntf.nsfodp.commons.odp.OnDiskProject) ODPCompiler(org.openntf.nsfodp.compiler.ODPCompiler) JsonException(com.ibm.commons.util.io.json.JsonException) NotesAPI(org.openntf.nsfodp.commons.odp.notesapi.NotesAPI)

Aggregations

JsonException (com.ibm.commons.util.io.json.JsonException)2 Path (java.nio.file.Path)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 PrintStreamProgressMonitor (org.openntf.nsfodp.commons.PrintStreamProgressMonitor)2 DominoAPI (com.darwino.domino.napi.DominoAPI)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 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