Sbt Plugin, Default File SettingKey - sbt

I have a settingKey that I have defined in project/build.scala
val databasePropertiesFile = settingKey[File]("The file we use to grab the database login configuration.")
And I want to assign it a default value based on the sourceDirctory, something like this, but it doesn't compile:
databasePropertiesFile := {
sourceDirectory / "db/devel.properties"
}
What is the magic I must perform to set a default File?

The magic is ".value":
databasePropertiesFile := {
sourceDirectory.value / "db" / "devel.properties"
}

Related

How to pass a parameter from the Jupyter backend to a frontend extension

I currently have a value that is stored as an environment variable the environment where a jupyter server is running. I would like to somehow pass that value to a frontend extension. It does not have to read the environment variable in real time, I am fine with just using the value of the variable at startup. Is there a canonical way to pass parameters a frontend extension on startup? Would appreciate an examples of both setting the parameter from the backend and accessing it from the frontend.
[update]
I have posted a solution that works for nbextentions, but I can't seem to find the equivalent pattern for labextensions (typescript), any help there would be much appreciated.
I was able to do this by adding the following code to my jupter_notebook_config.py
from notebook.services.config import ConfigManager
cm = ConfigManager()
cm.update('notebook', {'variable_being_set': value})
Then I had the parameters defined in my extension in my main.js
// define default values for config parameters
var params = {
variable_being_set : 'default'
};
// to be called once config is loaded, this updates default config vals
// with the ones specified by the server's config file
var update_params = function() {
var config = Jupyter.notebook.config;
for (var key in params) {
if (config.data.hasOwnProperty(key) ){
params[key] = config.data[key];
}
}
};
I also have the parameters declared in my main.yaml
Parameters:
- name: variable_being_set
description: ...
input_type: text
default: `default_value`
This took some trial and error to find out because there is very little documentation on the ConfigManager class and none of it has an end-to-end example.

custom logging does not works when set in systemProperties

I want to change log configuration for a node for that I have written a custom xml file where I have changed some configuration related to some specific module and rolling policies and I am using command: java -Dlog4j.configurationFile=custom-log.xml -jar corda.jar
This works fine with my custom configuration, but when I set same configuration in systemProperties section of node.conf as:
systemProperties = {
-Dlog4j.configurationFile = custom-log.xml
}
It does not follow my custom logging configuration. Can you help me with this?
Instead of
systemProperties = {
-Dlog4j.configurationFile = custom-log.xml
}
pass it as this:
systemProperties = {
log4j.configurationFile = custom-log.xml
}
-D is automatically appended

Can I use wildcards in appname when creating a rule

Can I use "*" in application name. Something like:
{ rule = { name = "Appname*" },
The code uses Lua's string.match, so the patterns that are explained at http://lua-users.org/wiki/PatternsTutorial can be used. For your case that should be "Appname.*", if I'm reading this correctly.

How to pass _OPTIONS to included premake4 scripts?

I've got a main premake4.lua script:
solution "MySolution"
language "c++"
newoption = {
trigger = "my-option",
description = "This is an option"
}
include "../my_library"
I would like to pivot logic in the included script ( ../my_library/premake4.lua ) based on the contents of _OPTIONS:
if _OPTIONS["my-option"] then
project "myStaticLibrary"
kind "StaticLib"
else
project "mySharedLibrary"
kind "SharedLib"
end
files "foo.cpp"
How to get _OPTIONS in the scope of the included premake4 script?
You don't need to do anything. _OPTIONS is a global variable and will be accessible to all of your scripts automatically. Are you seeing otherwise?
I'm answering my own question just in case anyone else is tempted to solve things in the same way. I was Doing It Wrong. After struggling with it my final solution defined multiple configurations:
-- the main script
solution "MySolution"
language "c++"
configurations { "Release", "Debug", "ReleaseDLL", "DebugDLL" }
configuration { "Release", "ReleaseDLL" }
flags { "Optimize" }
configuration { "Debug", "DebugDLL" }
flags { }
defines {"_DEBUG=1"}
configuration {}
include "../my_library"
The included script specified the kind according to configuration:
-- the included script
project "myStaticLibrary"
configuration { "*" }
kind "StaticLib"
configuration { "*DLL" }
kind "SharedLib"
configuration {}
files "foo.cpp"
And to to build the right targets the config is specified at the make:
premake4 gmake
cd gmake
make config=release
make config=debug
make config=releasedll
make config=debugdll

How to load setting values from a Java properties file?

Is there a way for me to dynamically load a setting value from a properties file?
I mean, instead of hardcoding into build.sbt
name := "helloWorld"
Have some application.properties file with
name=helloWorld
And then, in the build.sbt file, have name := application.properties["name"]
(last example is purely schematic, but I hope the idea was clear)
You can create a setting key which holds properties read from a file.
import java.util.Properties
val appProperties = settingKey[Properties]("The application properties")
appProperties := {
val prop = new Properties()
IO.load(prop, new File("application.properties"))
prop
}
name := appProperties.value.getProperty("name")
Cheating a bit on the answer from #daniel-olszewski.
In project/build.sbt declare dependency on Typesafe Config:
libraryDependencies += "com.typesafe" % "config" % "1.2.1"
In build.sbt load properties using Typesafe Config and set settings:
import com.typesafe.config.{ConfigFactory, Config}
lazy val appProperties = settingKey[Config]("The application properties")
appProperties := {
ConfigFactory.load()
}
name := {
try {
appProperties.value.getString("name")
} catch {
case _: Exception => "<empty>"
}
}
You could define a def that would set values from the properties, too.

Resources