Search in sources :

Example 1 with NDXLImporter

use of org.openntf.nsfodp.commons.odp.notesapi.NDXLImporter in project org.openntf.nsfodp by OpenNTF.

the class ODPCompiler method importBasicElements.

private void importBasicElements(NDXLImporter importer, NDatabase database) throws Exception {
    subTask(Messages.ODPCompiler_importingDesignElements);
    List<Integer> noteIds = new ArrayList<>();
    try (Stream<Path> dxlElements = odp.getDirectDXLElements()) {
        dxlElements.filter(p -> {
            try {
                return Files.size(p) > 0;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }).forEach(p -> {
            try {
                try (InputStream is = NSFODPUtil.newInputStream(p)) {
                    noteIds.addAll(importDxl(importer, is, database, MessageFormat.format(Messages.ODPCompiler_basicElementLabel, odp.getBaseDirectory().relativize(p))));
                }
            } catch (Exception e) {
                throw new RuntimeException("Exception while importing element " + odp.getBaseDirectory().relativize(p), e);
            }
        });
    }
    if (isCompileBasicElementLotusScript()) {
        compileLotusScript(database, noteIds, false);
    }
}
Also used : Path(java.nio.file.Path) Arrays(java.util.Arrays) Date(java.util.Date) NDominoException(org.openntf.nsfodp.commons.odp.notesapi.NDominoException) FileResource(org.openntf.nsfodp.commons.odp.FileResource) NNote(org.openntf.nsfodp.commons.odp.notesapi.NNote) NotesAPI(org.openntf.nsfodp.commons.odp.notesapi.NotesAPI) CustomControl(org.openntf.nsfodp.commons.odp.CustomControl) ByteArrayInputStream(java.io.ByteArrayInputStream) Document(org.w3c.dom.Document) Map(java.util.Map) Bundle(org.osgi.framework.Bundle) Path(java.nio.file.Path) XPage(org.openntf.nsfodp.commons.odp.XPage) DynamicFacesClassLoader(com.ibm.xsp.extlib.interpreter.DynamicFacesClassLoader) DateFormat(java.text.DateFormat) JavaSourceClassLoader(com.ibm.xsp.extlib.javacompiler.JavaSourceClassLoader) MultiPathResourceBundleSource(org.openntf.nsfodp.compiler.util.MultiPathResourceBundleSource) PrintWriter(java.io.PrintWriter) Os(com.ibm.domino.napi.c.Os) Collection(java.util.Collection) NsfNote(org.openntf.nsfodp.commons.h.NsfNote) DFLAGPAT_SACTIONS_DESIGN(org.openntf.nsfodp.commons.h.StdNames.DFLAGPAT_SACTIONS_DESIGN) CompilerUtil(org.openntf.nsfodp.compiler.util.CompilerUtil) Set(java.util.Set) Collectors(java.util.stream.Collectors) XSPCompilationResult(org.openntf.nsfodp.commons.odp.XSPCompilationResult) FileNotFoundException(java.io.FileNotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) BundleContext(org.osgi.framework.BundleContext) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) NSFODPUtil(org.openntf.nsfodp.commons.NSFODPUtil) FacesClassLoader(com.ibm.xsp.library.FacesClassLoader) FacesSharableRegistry(com.ibm.xsp.registry.FacesSharableRegistry) LotusScriptLibrary(org.openntf.nsfodp.commons.odp.LotusScriptLibrary) NDXLImporter(org.openntf.nsfodp.commons.odp.notesapi.NDXLImporter) CompositeComponentDefinitionImpl(com.ibm.xsp.registry.CompositeComponentDefinitionImpl) Queue(java.util.Queue) Pattern(java.util.regex.Pattern) ODPUtil(org.openntf.nsfodp.commons.odp.util.ODPUtil) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AbstractSplitDesignElement(org.openntf.nsfodp.commons.odp.AbstractSplitDesignElement) NDatabase(org.openntf.nsfodp.commons.odp.notesapi.NDatabase) DXLError(org.openntf.nsfodp.compiler.dxl.DxlImporterLog.DXLError) JavaCompilerException(com.ibm.xsp.extlib.javacompiler.JavaCompilerException) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) Function(java.util.function.Function) StandardCopyOption(java.nio.file.StandardCopyOption) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) StdNames(org.openntf.nsfodp.commons.h.StdNames) DxlImporterLog(org.openntf.nsfodp.compiler.dxl.DxlImporterLog) OnDiskProject(org.openntf.nsfodp.commons.odp.OnDiskProject) ConfigParserFactory(com.ibm.xsp.registry.parse.ConfigParserFactory) NLotusScriptCompilationException(org.openntf.nsfodp.commons.odp.notesapi.NLotusScriptCompilationException) ConfigParser(com.ibm.xsp.registry.parse.ConfigParser) OutputStream(java.io.OutputStream) LibraryFragmentImpl(com.ibm.xsp.registry.LibraryFragmentImpl) Properties(java.util.Properties) Files(java.nio.file.Files) StringWriter(java.io.StringWriter) DXLUtil(org.openntf.nsfodp.commons.dxl.DXLUtil) IOException(java.io.IOException) JavaSource(org.openntf.nsfodp.commons.odp.JavaSource) DXLFatalError(org.openntf.nsfodp.compiler.dxl.DxlImporterLog.DXLFatalError) UpdatableLibrary(com.ibm.xsp.registry.UpdatableLibrary) Element(org.w3c.dom.Element) StringUtil(com.ibm.commons.util.StringUtil) NException(com.ibm.domino.napi.NException) StreamUtil(com.ibm.commons.util.io.StreamUtil) NSFODPDomUtil(org.openntf.nsfodp.commons.xml.NSFODPDomUtil) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) InputStream(java.io.InputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) NDominoException(org.openntf.nsfodp.commons.odp.notesapi.NDominoException) FileNotFoundException(java.io.FileNotFoundException) JavaCompilerException(com.ibm.xsp.extlib.javacompiler.JavaCompilerException) NLotusScriptCompilationException(org.openntf.nsfodp.commons.odp.notesapi.NLotusScriptCompilationException) IOException(java.io.IOException) NException(com.ibm.domino.napi.NException)

Example 2 with NDXLImporter

use of org.openntf.nsfodp.commons.odp.notesapi.NDXLImporter in project org.openntf.nsfodp by OpenNTF.

the class ODPCompiler method importEarlyBasicElements.

private void importEarlyBasicElements(NDXLImporter importer, NDatabase database) throws Exception {
    subTask(Messages.ODPCompiler_importingEarlyDesignElements);
    List<Integer> noteIds = new ArrayList<>();
    try (Stream<Path> dxlElements = odp.getDirectEarlyDXLElements()) {
        dxlElements.filter(p -> {
            try {
                return Files.size(p) > 0;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }).forEach(p -> {
            try {
                try (InputStream is = NSFODPUtil.newInputStream(p)) {
                    noteIds.addAll(importDxl(importer, is, database, MessageFormat.format(Messages.ODPCompiler_basicElementLabel, odp.getBaseDirectory().relativize(p))));
                }
            } catch (Exception e) {
                throw new RuntimeException("Exception while importing element " + odp.getBaseDirectory().relativize(p), e);
            }
        });
    }
}
Also used : Path(java.nio.file.Path) Arrays(java.util.Arrays) Date(java.util.Date) NDominoException(org.openntf.nsfodp.commons.odp.notesapi.NDominoException) FileResource(org.openntf.nsfodp.commons.odp.FileResource) NNote(org.openntf.nsfodp.commons.odp.notesapi.NNote) NotesAPI(org.openntf.nsfodp.commons.odp.notesapi.NotesAPI) CustomControl(org.openntf.nsfodp.commons.odp.CustomControl) ByteArrayInputStream(java.io.ByteArrayInputStream) Document(org.w3c.dom.Document) Map(java.util.Map) Bundle(org.osgi.framework.Bundle) Path(java.nio.file.Path) XPage(org.openntf.nsfodp.commons.odp.XPage) DynamicFacesClassLoader(com.ibm.xsp.extlib.interpreter.DynamicFacesClassLoader) DateFormat(java.text.DateFormat) JavaSourceClassLoader(com.ibm.xsp.extlib.javacompiler.JavaSourceClassLoader) MultiPathResourceBundleSource(org.openntf.nsfodp.compiler.util.MultiPathResourceBundleSource) PrintWriter(java.io.PrintWriter) Os(com.ibm.domino.napi.c.Os) Collection(java.util.Collection) NsfNote(org.openntf.nsfodp.commons.h.NsfNote) DFLAGPAT_SACTIONS_DESIGN(org.openntf.nsfodp.commons.h.StdNames.DFLAGPAT_SACTIONS_DESIGN) CompilerUtil(org.openntf.nsfodp.compiler.util.CompilerUtil) Set(java.util.Set) Collectors(java.util.stream.Collectors) XSPCompilationResult(org.openntf.nsfodp.commons.odp.XSPCompilationResult) FileNotFoundException(java.io.FileNotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) BundleContext(org.osgi.framework.BundleContext) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) NSFODPUtil(org.openntf.nsfodp.commons.NSFODPUtil) FacesClassLoader(com.ibm.xsp.library.FacesClassLoader) FacesSharableRegistry(com.ibm.xsp.registry.FacesSharableRegistry) LotusScriptLibrary(org.openntf.nsfodp.commons.odp.LotusScriptLibrary) NDXLImporter(org.openntf.nsfodp.commons.odp.notesapi.NDXLImporter) CompositeComponentDefinitionImpl(com.ibm.xsp.registry.CompositeComponentDefinitionImpl) Queue(java.util.Queue) Pattern(java.util.regex.Pattern) ODPUtil(org.openntf.nsfodp.commons.odp.util.ODPUtil) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AbstractSplitDesignElement(org.openntf.nsfodp.commons.odp.AbstractSplitDesignElement) NDatabase(org.openntf.nsfodp.commons.odp.notesapi.NDatabase) DXLError(org.openntf.nsfodp.compiler.dxl.DxlImporterLog.DXLError) JavaCompilerException(com.ibm.xsp.extlib.javacompiler.JavaCompilerException) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) Function(java.util.function.Function) StandardCopyOption(java.nio.file.StandardCopyOption) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) StdNames(org.openntf.nsfodp.commons.h.StdNames) DxlImporterLog(org.openntf.nsfodp.compiler.dxl.DxlImporterLog) OnDiskProject(org.openntf.nsfodp.commons.odp.OnDiskProject) ConfigParserFactory(com.ibm.xsp.registry.parse.ConfigParserFactory) NLotusScriptCompilationException(org.openntf.nsfodp.commons.odp.notesapi.NLotusScriptCompilationException) ConfigParser(com.ibm.xsp.registry.parse.ConfigParser) OutputStream(java.io.OutputStream) LibraryFragmentImpl(com.ibm.xsp.registry.LibraryFragmentImpl) Properties(java.util.Properties) Files(java.nio.file.Files) StringWriter(java.io.StringWriter) DXLUtil(org.openntf.nsfodp.commons.dxl.DXLUtil) IOException(java.io.IOException) JavaSource(org.openntf.nsfodp.commons.odp.JavaSource) DXLFatalError(org.openntf.nsfodp.compiler.dxl.DxlImporterLog.DXLFatalError) UpdatableLibrary(com.ibm.xsp.registry.UpdatableLibrary) Element(org.w3c.dom.Element) StringUtil(com.ibm.commons.util.StringUtil) NException(com.ibm.domino.napi.NException) StreamUtil(com.ibm.commons.util.io.StreamUtil) NSFODPDomUtil(org.openntf.nsfodp.commons.xml.NSFODPDomUtil) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) InputStream(java.io.InputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) NDominoException(org.openntf.nsfodp.commons.odp.notesapi.NDominoException) FileNotFoundException(java.io.FileNotFoundException) JavaCompilerException(com.ibm.xsp.extlib.javacompiler.JavaCompilerException) NLotusScriptCompilationException(org.openntf.nsfodp.commons.odp.notesapi.NLotusScriptCompilationException) IOException(java.io.IOException) NException(com.ibm.domino.napi.NException)

Example 3 with NDXLImporter

use of org.openntf.nsfodp.commons.odp.notesapi.NDXLImporter in project org.openntf.nsfodp by OpenNTF.

the class ODPCompiler method compile.

/**
 * Runs the compilation process:
 *
 * <ol>
 * 	<li>Installs all bundles from the provided update sites</li>
 *	<li>Initializes plugin contributions from installed bundles</li>
 * 	<li>Compiles all XPage artifacts</li>
 * 	<li>Constructs the NSF from the on-disk project</li>
 * 	<li>Uninstalls any installed bundles</li>
 * </ol>
 *
 * @param cl the base {@link ClassLoader} to use during compilation
 * @return a {@link Path} representing the created database
 * @throws Exception if there is a problem compiling any component
 * @since 1.0.0
 */
public synchronized Path compile(ClassLoader cl) throws Exception {
    Collection<Bundle> bundles = installBundles();
    JavaSourceClassLoader classLoader = null;
    Set<Path> cleanup = new HashSet<>();
    try {
        boolean hasXPages = odp.hasXPagesElements();
        if (hasXPages) {
            initRegistry();
            Collection<String> dependencies = buildDependenciesCollection(cleanup);
            dependencies.addAll(ODPUtil.expandRequiredBundles(bundleContext, odp.getRequiredBundles()));
            // Add any Jars from the ODP
            for (Path jar : odp.getJars()) {
                // If the path is inside a JAR, extract it
                if ("jar".equals(jar.toUri().getScheme())) {
                    // $NON-NLS-1$
                    // $NON-NLS-1$
                    Path tempJar = Files.createTempFile(NSFODPUtil.getTempDirectory(), jar.getFileName().toString(), ".jar");
                    cleanup.add(tempJar);
                    Files.copy(jar, tempJar, StandardCopyOption.REPLACE_EXISTING);
                    // $NON-NLS-1$
                    dependencies.add("jar:" + tempJar.toUri());
                } else {
                    // $NON-NLS-1$
                    dependencies.add("jar:" + jar.toUri());
                }
            }
            String[] classPath = dependencies.toArray(new String[dependencies.size()]);
            List<String> options = Stream.concat(compilerOptions.stream(), // $NON-NLS-1$ //$NON-NLS-2$
            Stream.of("-source", compilerLevel, "-target", compilerLevel)).collect(Collectors.toList());
            classLoader = new JavaSourceClassLoader(cl, options, classPath);
            // Bar loading of different-version SSJS classes from ndext
            // $NON-NLS-1$
            classLoader.getJavaFileManager().setNonDelegatingPackages(Arrays.asList("com.ibm.jscript"));
            // Compile Java classes
            compileJavaSources(classLoader);
            compileCustomControls(classLoader);
            compileXPages(classLoader);
        }
        try (NotesAPI session = NotesAPI.get()) {
            Path file = createDatabase(session);
            try (NDatabase database = session.openDatabase("", file.toAbsolutePath().toString())) {
                // $NON-NLS-1$
                try (NDXLImporter importer = session.createDXLImporter()) {
                    importDbProperties(importer, database);
                    importEarlyBasicElements(importer, database);
                    importLotusScriptLibraries(importer, database);
                    importBasicElements(importer, database);
                    importFileResources(importer, database);
                    importDbScript(importer, database);
                    if (hasXPages) {
                        Set<String> compiledClassNames = new HashSet<>(classLoader.getCompiledClassNames());
                        importCustomControls(importer, database, classLoader, compiledClassNames);
                        importXPages(importer, database, classLoader, compiledClassNames);
                        importJavaElements(importer, database, classLoader, compiledClassNames);
                    }
                    // Append a timestamp if requested
                    if (this.isAppendTimestampToTitle()) {
                        // $NON-NLS-1$
                        database.setTitle(database.getTitle() + " - " + TIMESTAMP.get().format(new Date()));
                    }
                    // Set the template info if requested
                    String templateName = this.getTemplateName();
                    if (StringUtil.isNotEmpty(templateName)) {
                        // $NON-NLS-1$
                        int noteId = database.getSharedFieldNoteID("$TemplateBuild");
                        NNote doc;
                        if (noteId != 0) {
                            doc = database.getNoteByID(noteId);
                        } else {
                            // Import an empty one
                            try (InputStream is = ODPCompiler.class.getResourceAsStream("/dxl/TemplateBuild.xml")) {
                                // $NON-NLS-1$
                                // $NON-NLS-1$
                                String dxl = StreamUtil.readString(is, "UTF-8");
                                // $NON-NLS-1$
                                List<Integer> ids = importDxl(importer, dxl, database, "$TemplateBuild blank field");
                                doc = database.getNoteByID(ids.get(0));
                            }
                        }
                        String version = this.getTemplateVersion();
                        if (StringUtil.isNotEmpty(version)) {
                            // $NON-NLS-1$
                            doc.set("$TemplateBuild", version);
                        }
                        // $NON-NLS-1$
                        doc.set("$TemplateBuildName", templateName);
                        // $NON-NLS-1$
                        doc.set("$TemplateBuildDate", new Date());
                        doc.save();
                    }
                }
            }
            return file;
        }
    } catch (JavaCompilerException e) {
        StringWriter o = new StringWriter();
        PrintWriter errOut = new PrintWriter(o);
        e.printExtraInformation(errOut);
        throw new RuntimeException(MessageFormat.format(Messages.ODPCompiler_javaCompilationFailed, o), e);
    } finally {
        uninstallBundles(bundles);
        if (classLoader != null) {
            classLoader.close();
        }
        NSFODPUtil.deltree(cleanup);
    }
}
Also used : NDXLImporter(org.openntf.nsfodp.commons.odp.notesapi.NDXLImporter) NNote(org.openntf.nsfodp.commons.odp.notesapi.NNote) StringWriter(java.io.StringWriter) HashSet(java.util.HashSet) NotesAPI(org.openntf.nsfodp.commons.odp.notesapi.NotesAPI) PrintWriter(java.io.PrintWriter) Path(java.nio.file.Path) JavaSourceClassLoader(com.ibm.xsp.extlib.javacompiler.JavaSourceClassLoader) Bundle(org.osgi.framework.Bundle) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Date(java.util.Date) JavaCompilerException(com.ibm.xsp.extlib.javacompiler.JavaCompilerException) NDatabase(org.openntf.nsfodp.commons.odp.notesapi.NDatabase)

Example 4 with NDXLImporter

use of org.openntf.nsfodp.commons.odp.notesapi.NDXLImporter in project org.openntf.nsfodp by OpenNTF.

the class ODPCompiler method importDxl.

/**
 * @param importer the importer to use during the process
 * @param dxl an XML {@link InputStream} to import
 * @param database the database to import to
 * @param name a human-readable name of the element, for logging
 * @return a {@link List} of imported note IDs
 * @since 3.4.0
 */
private List<Integer> importDxl(NDXLImporter importer, InputStream dxl, NDatabase database, String name) throws Exception {
    try {
        Collection<Integer> imported = new HashSet<>();
        imported.addAll(importer.importDxl(database, dxl));
        String logXml = importer.getResultLogXML();
        if (StringUtil.isNotEmpty(logXml)) {
            DxlImporterLog log = DxlImporterLog.forXml(logXml);
            if (log.getErrors() != null && !log.getErrors().isEmpty()) {
                String msg = log.getErrors().stream().map(e -> StringUtil.format("{2} (line={0}, column={1})", e.getLine(), e.getColumn(), e.getText())).collect(// $NON-NLS-1$
                Collectors.joining(", "));
                throw new Exception(MessageFormat.format("Exception importing {0}: {1}", name, msg));
            } else if (log.getFatalErrors() != null && !log.getFatalErrors().isEmpty()) {
                String msg = log.getFatalErrors().stream().map(DXLFatalError::getText).collect(// $NON-NLS-1$
                Collectors.joining(", "));
                throw new Exception(MessageFormat.format("Exception importing {0}: {1}", name, msg));
            }
        }
        List<Integer> importedIds = new ArrayList<>();
        for (Integer noteId : imported) {
            importedIds.add(noteId);
            try (NNote note = database.getNoteByID(noteId)) {
                note.sign();
                note.save();
            }
        }
        return importedIds;
    } catch (Exception ne) {
        if (ne.getMessage().contains("DXL importer operation failed")) {
            // $NON-NLS-1$
            throw new RuntimeException(MessageFormat.format(Messages.ODPCompiler_dxlImportFailed, name, importer.getResultLogXML()), ne);
        }
        throw ne;
    }
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) NDominoException(org.openntf.nsfodp.commons.odp.notesapi.NDominoException) FileResource(org.openntf.nsfodp.commons.odp.FileResource) NNote(org.openntf.nsfodp.commons.odp.notesapi.NNote) NotesAPI(org.openntf.nsfodp.commons.odp.notesapi.NotesAPI) CustomControl(org.openntf.nsfodp.commons.odp.CustomControl) ByteArrayInputStream(java.io.ByteArrayInputStream) Document(org.w3c.dom.Document) Map(java.util.Map) Bundle(org.osgi.framework.Bundle) Path(java.nio.file.Path) XPage(org.openntf.nsfodp.commons.odp.XPage) DynamicFacesClassLoader(com.ibm.xsp.extlib.interpreter.DynamicFacesClassLoader) DateFormat(java.text.DateFormat) JavaSourceClassLoader(com.ibm.xsp.extlib.javacompiler.JavaSourceClassLoader) MultiPathResourceBundleSource(org.openntf.nsfodp.compiler.util.MultiPathResourceBundleSource) PrintWriter(java.io.PrintWriter) Os(com.ibm.domino.napi.c.Os) Collection(java.util.Collection) NsfNote(org.openntf.nsfodp.commons.h.NsfNote) DFLAGPAT_SACTIONS_DESIGN(org.openntf.nsfodp.commons.h.StdNames.DFLAGPAT_SACTIONS_DESIGN) CompilerUtil(org.openntf.nsfodp.compiler.util.CompilerUtil) Set(java.util.Set) Collectors(java.util.stream.Collectors) XSPCompilationResult(org.openntf.nsfodp.commons.odp.XSPCompilationResult) FileNotFoundException(java.io.FileNotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) BundleContext(org.osgi.framework.BundleContext) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) NSFODPUtil(org.openntf.nsfodp.commons.NSFODPUtil) FacesClassLoader(com.ibm.xsp.library.FacesClassLoader) FacesSharableRegistry(com.ibm.xsp.registry.FacesSharableRegistry) LotusScriptLibrary(org.openntf.nsfodp.commons.odp.LotusScriptLibrary) NDXLImporter(org.openntf.nsfodp.commons.odp.notesapi.NDXLImporter) CompositeComponentDefinitionImpl(com.ibm.xsp.registry.CompositeComponentDefinitionImpl) Queue(java.util.Queue) Pattern(java.util.regex.Pattern) ODPUtil(org.openntf.nsfodp.commons.odp.util.ODPUtil) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AbstractSplitDesignElement(org.openntf.nsfodp.commons.odp.AbstractSplitDesignElement) NDatabase(org.openntf.nsfodp.commons.odp.notesapi.NDatabase) DXLError(org.openntf.nsfodp.compiler.dxl.DxlImporterLog.DXLError) JavaCompilerException(com.ibm.xsp.extlib.javacompiler.JavaCompilerException) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) Function(java.util.function.Function) StandardCopyOption(java.nio.file.StandardCopyOption) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) StdNames(org.openntf.nsfodp.commons.h.StdNames) DxlImporterLog(org.openntf.nsfodp.compiler.dxl.DxlImporterLog) OnDiskProject(org.openntf.nsfodp.commons.odp.OnDiskProject) ConfigParserFactory(com.ibm.xsp.registry.parse.ConfigParserFactory) NLotusScriptCompilationException(org.openntf.nsfodp.commons.odp.notesapi.NLotusScriptCompilationException) ConfigParser(com.ibm.xsp.registry.parse.ConfigParser) OutputStream(java.io.OutputStream) LibraryFragmentImpl(com.ibm.xsp.registry.LibraryFragmentImpl) Properties(java.util.Properties) Files(java.nio.file.Files) StringWriter(java.io.StringWriter) DXLUtil(org.openntf.nsfodp.commons.dxl.DXLUtil) IOException(java.io.IOException) JavaSource(org.openntf.nsfodp.commons.odp.JavaSource) DXLFatalError(org.openntf.nsfodp.compiler.dxl.DxlImporterLog.DXLFatalError) UpdatableLibrary(com.ibm.xsp.registry.UpdatableLibrary) Element(org.w3c.dom.Element) StringUtil(com.ibm.commons.util.StringUtil) NException(com.ibm.domino.napi.NException) StreamUtil(com.ibm.commons.util.io.StreamUtil) NSFODPDomUtil(org.openntf.nsfodp.commons.xml.NSFODPDomUtil) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) InputStream(java.io.InputStream) NNote(org.openntf.nsfodp.commons.odp.notesapi.NNote) DXLFatalError(org.openntf.nsfodp.compiler.dxl.DxlImporterLog.DXLFatalError) DxlImporterLog(org.openntf.nsfodp.compiler.dxl.DxlImporterLog) ArrayList(java.util.ArrayList) NDominoException(org.openntf.nsfodp.commons.odp.notesapi.NDominoException) FileNotFoundException(java.io.FileNotFoundException) JavaCompilerException(com.ibm.xsp.extlib.javacompiler.JavaCompilerException) NLotusScriptCompilationException(org.openntf.nsfodp.commons.odp.notesapi.NLotusScriptCompilationException) IOException(java.io.IOException) NException(com.ibm.domino.napi.NException) HashSet(java.util.HashSet)

Example 5 with NDXLImporter

use of org.openntf.nsfodp.commons.odp.notesapi.NDXLImporter in project org.openntf.nsfodp by OpenNTF.

the class ODPCompiler method importJavaElements.

private void importJavaElements(NDXLImporter importer, NDatabase database, JavaSourceClassLoader classLoader, Set<String> compiledClassNames) throws Exception {
    subTask(Messages.ODPCompiler_importingJava);
    Map<Path, List<JavaSource>> javaSourceFiles = odp.getJavaSourceFiles();
    for (Map.Entry<Path, List<JavaSource>> entry : javaSourceFiles.entrySet()) {
        for (JavaSource source : entry.getValue()) {
            Path filePath = entry.getKey().relativize(source.getDataFile());
            String className = ODPUtil.toJavaClassName(filePath);
            compiledClassNames.remove(className);
            byte[] byteCode = classLoader.getClassByteCode(className);
            Document dxlDoc = source.getDxl();
            // $NON-NLS-1$
            DXLUtil.writeItemFileData(dxlDoc, "$ClassData0", byteCode);
            // $NON-NLS-1$
            DXLUtil.writeItemNumber(dxlDoc, "$ClassSize0", byteCode.length);
            List<String> classIndexItem = new ArrayList<>();
            // $NON-NLS-1$
            classIndexItem.add("WEB-INF/classes/" + ODPUtil.toJavaPath(className));
            // Also look for any inner classes that were compiled
            List<String> innerClasses = classLoader.getCompiledClassNames().stream().filter(// $NON-NLS-1$ //$NON-NLS-2$
            cname -> cname.matches("^" + Pattern.quote(className) + "[\\.\\$].+$")).collect(Collectors.toList());
            for (int i = 0; i < innerClasses.size(); i++) {
                String innerClassName = innerClasses.get(i);
                compiledClassNames.remove(innerClassName);
                byte[] innerByteCode = classLoader.getClassByteCode(innerClassName);
                // $NON-NLS-1$
                DXLUtil.writeItemFileData(dxlDoc, "$ClassData" + (i + 1), innerByteCode);
                // $NON-NLS-1$
                DXLUtil.writeItemNumber(dxlDoc, "$ClassSize" + (i + 1), innerByteCode.length);
                // $NON-NLS-1$
                classIndexItem.add("WEB-INF/classes/" + ODPUtil.toJavaPath(innerClassName));
            }
            // $NON-NLS-1$
            DXLUtil.writeItemString(dxlDoc, "$ClassIndexItem", true, classIndexItem.toArray(new CharSequence[classIndexItem.size()]));
            importDxl(importer, NSFODPDomUtil.getXmlString(dxlDoc, null), database, MessageFormat.format(Messages.ODPCompiler_javaClassLabel, className));
        }
    }
    // Create standalone class files for remaining classes
    for (String leftoverClassName : compiledClassNames) {
        // $NON-NLS-1$
        String fileName = "WEB-INF/classes/" + ODPUtil.toJavaPath(leftoverClassName);
        byte[] leftoverByteCode = classLoader.getClassByteCode(leftoverClassName);
        // $NON-NLS-1$ //$NON-NLS-2$
        CompilerUtil.importFileResource(importer, leftoverByteCode, database, fileName, "~C4g", "w");
    }
}
Also used : Path(java.nio.file.Path) Arrays(java.util.Arrays) Date(java.util.Date) NDominoException(org.openntf.nsfodp.commons.odp.notesapi.NDominoException) FileResource(org.openntf.nsfodp.commons.odp.FileResource) NNote(org.openntf.nsfodp.commons.odp.notesapi.NNote) NotesAPI(org.openntf.nsfodp.commons.odp.notesapi.NotesAPI) CustomControl(org.openntf.nsfodp.commons.odp.CustomControl) ByteArrayInputStream(java.io.ByteArrayInputStream) Document(org.w3c.dom.Document) Map(java.util.Map) Bundle(org.osgi.framework.Bundle) Path(java.nio.file.Path) XPage(org.openntf.nsfodp.commons.odp.XPage) DynamicFacesClassLoader(com.ibm.xsp.extlib.interpreter.DynamicFacesClassLoader) DateFormat(java.text.DateFormat) JavaSourceClassLoader(com.ibm.xsp.extlib.javacompiler.JavaSourceClassLoader) MultiPathResourceBundleSource(org.openntf.nsfodp.compiler.util.MultiPathResourceBundleSource) PrintWriter(java.io.PrintWriter) Os(com.ibm.domino.napi.c.Os) Collection(java.util.Collection) NsfNote(org.openntf.nsfodp.commons.h.NsfNote) DFLAGPAT_SACTIONS_DESIGN(org.openntf.nsfodp.commons.h.StdNames.DFLAGPAT_SACTIONS_DESIGN) CompilerUtil(org.openntf.nsfodp.compiler.util.CompilerUtil) Set(java.util.Set) Collectors(java.util.stream.Collectors) XSPCompilationResult(org.openntf.nsfodp.commons.odp.XSPCompilationResult) FileNotFoundException(java.io.FileNotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) BundleContext(org.osgi.framework.BundleContext) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) NSFODPUtil(org.openntf.nsfodp.commons.NSFODPUtil) FacesClassLoader(com.ibm.xsp.library.FacesClassLoader) FacesSharableRegistry(com.ibm.xsp.registry.FacesSharableRegistry) LotusScriptLibrary(org.openntf.nsfodp.commons.odp.LotusScriptLibrary) NDXLImporter(org.openntf.nsfodp.commons.odp.notesapi.NDXLImporter) CompositeComponentDefinitionImpl(com.ibm.xsp.registry.CompositeComponentDefinitionImpl) Queue(java.util.Queue) Pattern(java.util.regex.Pattern) ODPUtil(org.openntf.nsfodp.commons.odp.util.ODPUtil) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AbstractSplitDesignElement(org.openntf.nsfodp.commons.odp.AbstractSplitDesignElement) NDatabase(org.openntf.nsfodp.commons.odp.notesapi.NDatabase) DXLError(org.openntf.nsfodp.compiler.dxl.DxlImporterLog.DXLError) JavaCompilerException(com.ibm.xsp.extlib.javacompiler.JavaCompilerException) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) Function(java.util.function.Function) StandardCopyOption(java.nio.file.StandardCopyOption) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) StdNames(org.openntf.nsfodp.commons.h.StdNames) DxlImporterLog(org.openntf.nsfodp.compiler.dxl.DxlImporterLog) OnDiskProject(org.openntf.nsfodp.commons.odp.OnDiskProject) ConfigParserFactory(com.ibm.xsp.registry.parse.ConfigParserFactory) NLotusScriptCompilationException(org.openntf.nsfodp.commons.odp.notesapi.NLotusScriptCompilationException) ConfigParser(com.ibm.xsp.registry.parse.ConfigParser) OutputStream(java.io.OutputStream) LibraryFragmentImpl(com.ibm.xsp.registry.LibraryFragmentImpl) Properties(java.util.Properties) Files(java.nio.file.Files) StringWriter(java.io.StringWriter) DXLUtil(org.openntf.nsfodp.commons.dxl.DXLUtil) IOException(java.io.IOException) JavaSource(org.openntf.nsfodp.commons.odp.JavaSource) DXLFatalError(org.openntf.nsfodp.compiler.dxl.DxlImporterLog.DXLFatalError) UpdatableLibrary(com.ibm.xsp.registry.UpdatableLibrary) Element(org.w3c.dom.Element) StringUtil(com.ibm.commons.util.StringUtil) NException(com.ibm.domino.napi.NException) StreamUtil(com.ibm.commons.util.io.StreamUtil) NSFODPDomUtil(org.openntf.nsfodp.commons.xml.NSFODPDomUtil) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) JavaSource(org.openntf.nsfodp.commons.odp.JavaSource) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

JavaCompilerException (com.ibm.xsp.extlib.javacompiler.JavaCompilerException)6 JavaSourceClassLoader (com.ibm.xsp.extlib.javacompiler.JavaSourceClassLoader)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 PrintWriter (java.io.PrintWriter)6 StringWriter (java.io.StringWriter)6 Path (java.nio.file.Path)6 Date (java.util.Date)6 HashSet (java.util.HashSet)6 StringUtil (com.ibm.commons.util.StringUtil)5 StreamUtil (com.ibm.commons.util.io.StreamUtil)5 NException (com.ibm.domino.napi.NException)5 Os (com.ibm.domino.napi.c.Os)5 DynamicFacesClassLoader (com.ibm.xsp.extlib.interpreter.DynamicFacesClassLoader)5 FacesClassLoader (com.ibm.xsp.library.FacesClassLoader)5 CompositeComponentDefinitionImpl (com.ibm.xsp.registry.CompositeComponentDefinitionImpl)5 FacesSharableRegistry (com.ibm.xsp.registry.FacesSharableRegistry)5 LibraryFragmentImpl (com.ibm.xsp.registry.LibraryFragmentImpl)5 UpdatableLibrary (com.ibm.xsp.registry.UpdatableLibrary)5 ConfigParser (com.ibm.xsp.registry.parse.ConfigParser)5