How to include the application's version number in a Scala.js program? - sbt

Basically, I'm curious if something like SBT including the version number in a program is possible for Scala.js. The proposed solution doesn't work in scala.js, apparently due the the absence of the getPackage method:
[error] Referring to non-existent method java.lang.Class.getPackage()java.lang.Package

Use sbt-buildinfo for that. The Usage section of the readme contains everything you need.

Related

'XrmFakedContext' does not cointain a definition for 'ExecutePluginWith'

I'm trying to upgrade a unit test project to the latest version of FakeXrmEasy 2.1.2 and I'm getting the error below:
'XrmFakedContext' does not cointain a definition for 'ExecutePluginWith' and no accessible extension method 'ExecutePluginWith' accepting a first argument of type 'XrmFakedContext' could be found
Any ideas what I'm missing?
This might happen because some methods were moved into dedicated namespaces and so some extra using statements might be necessary.
Please try adding these usings:
using FakeXrmEasy.Abstractions.Plugins;
using FakeXrmEasy.Plugins;
Also please check the documentation site with other steps that might be useful. In particular the Quick Guide to migrate in 6 steps is probably an essential resource:
https://dynamicsvalue.github.io/fake-xrm-easy-docs/quickstart/migrating-from-1x/

Meteor Testing Using Spies

I'm using Velocity with the mike:mocha framework and the chai assertions. Everything is working great, but when it comes time to do stubbing, mocking and spying, I've hit a bit of a roadblock. These aren't core features of mike:mocha or chai, so I found practicalmeteor:chai, which should/may have added spies.
My first stab at finding out whether this is true was to write the following code:
it 'calls update when both documents are present but different', ->
spies.create('log', console, 'log')
which gives me:
ReferenceError: spies is not defined
at packages/velocity:test-proxy/tests/mocha/server/charger_server_doc_spec.coffee:88:9
at wrappedFunc (packages/mike:mocha/server.js:200:1)
at runWithEnvironment (packages/mike:mocha/server.js:156:1)
That implies to me that I've misunderstood what practicalmeteor:chai provides, however, the code I showed in the first example is copied verbatim from the README.
Question: Any tips on getting this to work? Is it a load order issue? The code on Github shows spies and so on are implemented in this package. So I'm a bit stuck.
Thanks!
The package practicalmeteor:chai does not include the practicalmeteor:sinon package which is required to get the spies API included.
They are separate packages because you may not have to use spies when creating basic tests with chai.
If you look at the package.js file in the practicalmeteor:chai package, it does not include the sinon files.
So, just running meteor add practicalmeteor:sinon should solve your problem.

Flyway Mysql multiline comment directive not parsed

I am wondering if there is any news for multi line comment directive support for MySql.
I believe the problem is related to:
Mysql dump comments directives and simple comments
Basically it seems SqlScript/MySQLSqlStatementBuilder fail in recognizing as directive a statement in the format:
/*!50001 <STATEMENT SPLITTED IN
MULTI
LINES> */;
I am using version 2.2.1
Additional notes:
the same goes for previous versions (2.1.1), and issues are multiple and not only related to comment directives; theu are also hard to debug because of missing exception trace.
Basically I think parser cannot currently handle pretty standard mysql scripts created with mysqldump; this IMO is a necessary feature for any usage in existing projects at least.
If anybody has suggestions to overcome these issues, it would be highly appreciated.
I am using Flyway 2.1.1 API in Java.
What I am doing is parsing a dump file (only the schema structure) and replace the version dependant comments.
This solution is pretty bad, but waiting for a better support of MySQL dump in Flyway, I didn't find anything else...

Setting system properties with "sbt run"

I'm using a pretty recent version of SBT (seems to be hard to figure out what the version is). I want to pass system properties to my application with sbt run as follows:
sbt -Dmyprop=x run
How could I do that?
SBT's runner doesn't normally create new processes, so you also have to tell it to do this if you want to set the arguments that are passed. You can add something like this to your build settings:
fork := true
javaOptions := Seq("-Dmx=1024M")
There's more detail on forking processes in the SBT documentation.
I found the best way to be adding this to build.sbt:
// important to use ~= so that any other initializations aren't dropped
// the _ discards the meaningless () value previously assigned to 'initialize'
initialize ~= { _ =>
System.setProperty( "config.file", "debug.conf" )
}
Related: When doing this to change the Typesafe Configuration that gets loaded (my use case), one needs to also manually include the default config. For this, the Typesafe Configuration's suggested include "application" wasn't enough but include classpath("application.conf") worked. Thought to mention since some others may well be wanting to override system properties for precisely the same reason.
Source: discussion on the sbt mailing list
Thanks for the pointer, this actually helped me solve a somewhat related problem with Scala Tests.
It turned out that sbt does fork the tests when there are sub-projects (see my code) and some of the tests fail to pick up the system property.
So in sbt -Dsomething="some value" test, some of the tests would fail when failing to find something in the system properties (that happened to be my DB URI, so it kinda mattered!)
This was driving me nuts, so I thought I'd post it here for future reference for others (as #akauppi correctly noted, chances are high that "others" may well be me in a few weeks!).
The fix was to add the following to build.st:
fork in Test := false
I think the best is to use the JAVA_OPTS environment variable:
#update the java options (maybe to keep previous options)
export JAVA_OPTS="${JAVA_OPTS} -Dmyprop=x"
#now run without any extra option
sbt run
You can pass system properties at the end of the sbt command:
sbt run -Dmyprop=x
If you have to pass program parameters into a stage, just pass system properties after the quotes again:
sbt "runMain com.example.MyClass -p param-value" -Dmyprop=x

How to create a directory in Lua?

Is it possible to create a directory in lua ? If so, how ?
You may find the LuaFileSystem library useful. It has a mkdir function.
require "lfs"
lfs.mkdir("/path/to/dir")
There's a "system" call (or something like that, this is from memory) which you should be able to use to run an arbitrary program, which could include the mkdir command.
EDIT: I found my Programming in Lua book. On page 203, it mentions how you could use an
os.execute("mkdir " .. dirname)
to "fake" a directory creation command.
EDIT 2: Take note of Jonas Thiem's warning that this command can be abused if the directory name comes from an untrusted source!
You may also want to look at Lua/APR, the Apache Portable Runtime binding for Lua. The docs can be found at here
One of the reasons I use Lua is that I can write code that runs across multiple OSes. I was using LFS for some time, but have found that using Lua/APR provides a more platform-neutral library. And there are lots of other useful routines in the APR.
You can use the paths package instead. Then you can simply do:
require 'paths'
paths.mkdir('your/dir')

Resources