import org.eclipse.osgi.service.datalocation.Location;
import org.simantics.application.arguments.Arguments;
import org.simantics.application.arguments.IArgumentFactory;
-import org.simantics.application.arguments.IArgumentFactory.StringArgumentFactory;
import org.simantics.application.arguments.IArgumentFactory.NoValueArgumentFactory;
+import org.simantics.application.arguments.IArgumentFactory.StringArgumentFactory;
import org.simantics.application.arguments.IArguments;
import org.simantics.application.arguments.SimanticsArguments;
import org.simantics.internal.Activator;
+import org.simantics.scl.runtime.SCLContext;
+import org.simantics.scl.runtime.reporting.SCLReportingHandler;
+import org.simantics.scl.runtime.tuple.Tuple0;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final IArgumentFactory<String> OUTPUT = new StringArgumentFactory("-o");
private static final IArgumentFactory<Boolean> VERBOSE = new NoValueArgumentFactory("-v");
+ /**
+ * The -f argument specifies an SCL function that shall be executed after the
+ * platform has been started and before the platform is shutdown.
+ *
+ * <p>
+ * The function must be:
+ * <ol>
+ * <li>a parameterless function</li>
+ * <li>a function with <code><Proc></code> effect only</li>. It must internally invoke
+ * <code>syncWrite</code> etc. to have other effects.
+ * </ol>
+ *
+ * <p>
+ * This means the function must have the following signature:
+ * <code>func :: <Proc> ()</code>
+ */
+ private static final IArgumentFactory<String> FUNCTION = new StringArgumentFactory("-f");
+
IArgumentFactory<?>[] accepted = {
SimanticsArguments.RECOVERY_POLICY_FIX_ERRORS,
SimanticsArguments.ONTOLOGY_RECOVERY_POLICY_REINSTALL,
SimanticsArguments.DATABASE_ID,
OUTPUT,
VERBOSE,
+ FUNCTION,
};
private static String currentLocalDateTimeStamp() {
IArguments parsedArgs = Arguments.parse(args, accepted);
Path output = constructOutputPath(workspace, parsedArgs);
+ LOGGER.info("Selected output file: {} ", output);
// Create database and indexes
IProgressMonitor progress = parsedArgs.contains(VERBOSE)
? new TimingProgressMonitor()
: new NullProgressMonitor();
Simantics.startUpHeadless(parsedArgs, progress);
+
+ if (parsedArgs.contains(FUNCTION)) {
+ String func = parsedArgs.get(FUNCTION);
+ String[] moduleAndFunc = splitFunction(func);
+ if (moduleAndFunc != null) {
+ try {
+ LOGGER.info("Invoking SCL function {}/{}", moduleAndFunc[0], moduleAndFunc[1]);
+ SCLContext.getCurrent().put(SCLReportingHandler.REPORTING_HANDLER, SCLReportingHandler.DEFAULT);
+ Simantics.applySCL(moduleAndFunc[0], moduleAndFunc[1], Tuple0.INSTANCE);
+ } catch (Throwable t) {
+ LOGGER.error("Invocation failed", t);
+ }
+ } else {
+ LOGGER.error("SCL function '{}' not invocable for baselining the database", func);
+ }
+ }
+
Simantics.shutdown(progress);
// Create the baseline package file
Path actualOutput = DatabaseBaselines.packageBaseline(workspace, output);
- System.out.println("OK " + actualOutput.toAbsolutePath());
+ System.out.println("OK " + actualOutput.normalize().toAbsolutePath());
return IApplication.EXIT_OK;
} catch (Exception e) {
}
}
+ private String[] splitFunction(String func) {
+ int l = func.lastIndexOf('/');
+ if (l < 0)
+ return null;
+ return new String[] { func.substring(0, l), func.substring(l+1) };
+ }
+
@Override
public void stop() {
}