use of org.openntf.nsfodp.commons.odp.notesapi.NDatabase 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);
}
}
use of org.openntf.nsfodp.commons.odp.notesapi.NDatabase in project org.openntf.nsfodp by OpenNTF.
the class ODPCompiler method compileLotusScript.
private void compileLotusScript(NDatabase database, List<Integer> noteIds, boolean retry) {
if (!noteIds.isEmpty()) {
try {
// $NON-NLS-1$
Class.forName("lotus.domino.websvc.client.Stub");
} catch (ClassNotFoundException e) {
subTask(Messages.ODPCompiler_webServiceNotFound1);
subTask(Messages.ODPCompiler_webServiceNotFound2);
return;
}
subTask(Messages.ODPCompiler_compilingLotusScript);
// In lieu of a dependency graph, just keep bashing at the list until it's done
Queue<Integer> remaining = new ArrayDeque<>(noteIds);
Map<Integer, String> titles = new HashMap<>();
for (int i = 0; i < noteIds.size(); i++) {
Queue<Integer> nextPass = new ArrayDeque<>();
Integer noteId;
while ((noteId = remaining.poll()) != null) {
String title = null;
try (NNote note = database.getNoteByID(noteId)) {
// Check to see if this is the Shared Actions note, which we should skip to avoid trouble
if ((note.getNoteClassValue() & NsfNote.NOTE_CLASS_NONPRIV) == NsfNote.NOTE_CLASS_FORM) {
String flags = note.getAsString(StdNames.DESIGN_FLAGS, ' ');
if (NSFODPUtil.matchesFlagsPattern(flags, DFLAGPAT_SACTIONS_DESIGN)) {
continue;
}
}
// $NON-NLS-1$
title = note.get("$TITLE", String.class);
titles.put(noteId, title);
note.compileLotusScript();
note.sign();
note.save();
} catch (NLotusScriptCompilationException err) {
nextPass.add(noteId);
// $NON-NLS-1$
titles.put(noteId, title + " - " + err);
} catch (NDominoException err) {
if (err.getStatus() == 12051) {
// Same as above, but not encapsulated
// $NON-NLS-1$
titles.put(noteId, title + " - " + err);
nextPass.add(noteId);
} else if (err.getStatus() == 0x222) {
// Note item not found - occurs for non-LS elements
} else {
throw err;
}
}
}
remaining = nextPass;
if (nextPass.isEmpty()) {
break;
}
}
if (!retry && !remaining.isEmpty()) {
String notes = remaining.stream().map(// $NON-NLS-1$ //$NON-NLS-2$
noteId -> "Note ID " + noteId + ": " + titles.get(noteId)).collect(// $NON-NLS-1$
Collectors.joining("\n"));
throw new RuntimeException(MessageFormat.format(Messages.ODPCompiler_unableToCompileLotusScript, notes));
}
}
}
use of org.openntf.nsfodp.commons.odp.notesapi.NDatabase 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);
}
});
}
}
use of org.openntf.nsfodp.commons.odp.notesapi.NDatabase in project org.openntf.nsfodp by OpenNTF.
the class ExporterApplication 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);
}
}
String databasePath = System.getenv(NSFODPConstants.PROP_EXPORTER_DATABASE_PATH);
if (databasePath == null) {
throw new IllegalArgumentException(MessageFormat.format(Messages.ExporterApplication_dbPathCannotBeEmpty, NSFODPConstants.PROP_EXPORTER_DATABASE_PATH));
}
Path odpDir = Paths.get(System.getenv(NSFODPConstants.PROP_OUTPUTFILE));
// $NON-NLS-1$
boolean binaryDxl = "true".equals(System.getenv(NSFODPConstants.PROP_EXPORTER_BINARY_DXL));
// $NON-NLS-1$
boolean swiperFilter = "true".equals(System.getenv(NSFODPConstants.PROP_EXPORTER_SWIPER_FILTER));
// $NON-NLS-1$
boolean richTextAsItemData = "true".equals(System.getenv(NSFODPConstants.PROP_RICH_TEXT_AS_ITEM_DATA));
String projectName = System.getenv(NSFODPConstants.PROP_PROJECT_NAME);
NotesThread runner = new NotesThread(() -> {
try (NotesAPI session = NotesAPI.get()) {
try (NDatabase database = session.openDatabase(databasePath)) {
ODPExporter exporter = new ODPExporter(database);
exporter.setBinaryDxl(binaryDxl);
exporter.setSwiperFilter(swiperFilter);
exporter.setRichTextAsItemData(richTextAsItemData);
exporter.setProjectName(projectName);
Path result = exporter.export();
// $NON-NLS-1$
Path eclipseProject = odpDir.resolve(".project");
if (Files.exists(eclipseProject)) {
// $NON-NLS-1$ //$NON-NLS-2$
Path tempPath = Files.createTempFile("nsfodp", ".project");
Files.move(eclipseProject, tempPath, StandardCopyOption.REPLACE_EXISTING);
eclipseProject = tempPath;
} else {
eclipseProject = null;
}
if (Files.exists(odpDir)) {
NSFODPUtil.deltree(Collections.singleton(odpDir));
}
Files.createDirectories(odpDir);
NSFODPUtil.moveDirectory(result, odpDir);
if (eclipseProject != null) {
// $NON-NLS-1$
Files.move(eclipseProject, odpDir.resolve(".project"), StandardCopyOption.REPLACE_EXISTING);
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
});
runner.run();
runner.join();
return EXIT_OK;
}
use of org.openntf.nsfodp.commons.odp.notesapi.NDatabase 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);
}
}
Aggregations