[b][url=/bee-config]Bee Config[/url][/b], the simple Scala API for loading configuration files, has needed very few changes over the last few months and is now in preparation for full release. It is feature-complete and mostly ready for production use. It now has a Maven/Ivy repository for automatic dependency. If no significant changes are needed during December, the first release candidate will be announced in a few weeks.
Version 1.4.2 of Bee Config is now available. This is a bugfix release. ConfigSource now has a canBeOpened method. SourceChangeDetector has been simplified by using the canBeOpened logic. ConfigSource has been modified to ensure that the counter is always updated. History of commits
Version 1.5.0 of Bee Config is now available. This brings full Java support, whilst carrying forward the excellent Scala api. In previous versions, file i/o, parsing and config manipulation were all written in Scala, which was less easy to use from Java programs. Now, a new ConfigJ class in Java emulates the Config class in Scala. The Java parser is shared by both. The file i/o and parsing have been back-ported to Java, although this will not be evident in existing Scala programs (unless they happen to use the underlying utility classes explicitly).
Version 1.5.3 of Bee Config is now available. This brings JavaBean integration, a new feature for those who would like easy configuration files combined with pojos with typed properties. The new feature allows you to load your Config from a file (or wherever) as normal, then use it to populate JavaBeans, which may themselves contain further JavaBeans. You can create your own JavaBean and pass it in. Or you can specify the class of the bean and it will be created reflectively for you.
Version 1.5.4 of Bee Config is now available. This brings support for Scala 2.11 as well as 2.10 and 2.9.x. Previous announcement: v1.5.3 History of commits
Version 1.5.5 of Bee Config is now available. This includes a small bugfix in the DimensionedValue class, which now treats kilograms (kg) as a special case. Previous announcement: v1.5.4 History of commits
The new Bee Config API provides an alternative to using java.util.Properties in Scala programs. The API provides a very simple Scala API for loading configuration files. Simplicity is the key! Often, java.util.Properties is still used in Scala applications, but it is often unsatisfactory. This API is broadly similar in intent, but pimped to work well in Scala. Features Config files are like properties files, except they are always Unicode.
© Copyright 2012 Rick Beton Published under The MIT License. The MIT License Copyright (c) 2012 Rick Beton <firstname.lastname@example.org> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
Thu, 20 Jun 2013 v1.4.0 Reloader enhanced to offer more robust multithreading support new SourceChangeDetector class hived off Reloader (it could be used for any file-based cache) Thu, 20 Jun 2013 v1.3.1 - New MutableConfig refactors out the parts of the JMX bean needed for mutability from the parts needed for JMX integration. Thu, 20 Jun 2013 v1.3.0 - added support for JMX (experimental): A Config instance can be inserted into a JMX MBean with operations that allow values to be queried and altered.
Config is loaded once only, when it is constructed. You can use Reloader to load changes on the fly if you want to. Reloader is constructed using a File or other source, and a max age in seconds import uk.co.bigbeeconsultants.bconfig.Reloader val reloader = Reloader(new File("src/test/resources/sample2.txt"), 10) Reloader wraps Config loading so that changes to the source can be reloaded dynamically. If the config file is edited whilst the application is running, the new values are loaded in.
A Config subsection is itself a Config instance - it’s easy to group your keys therefore. Here’s a sample file we’ll be discussing: xx.a.z1 = alpha-xx xx.a.z2 = beta-xx xx.b.z3 = gamma-xx xx.b.z4 = delta-xx [yy] a.z1 = alpha-yy a.z2 = beta-yy [zz] a.z1 = alpha-zz a.z2 = beta-zz There are two ways to deal with sections and hierarchies of settings. Prefixes The crudest is simply by choosing a common prefix on all the keys in the group.
Config extends ListMap, making it very easy to use. It assumed that you are familiar with Scala’s Map (and ListMap) collection classes. For clarity, the following examples have the explicit type declared on each val, which is not usually necessary in Scala. Here’s a sample file we’ll be discussing: a = something b = else easy = true tau = 6.2832 somewhen = 1979-05-27T07:32:00Z coronation = 1953-06-02 triangle = 3, 4, 5 actors = "\"Harry\", Daniel Radcliffe", "\"Ron\", Rupert Grint", "\"Hermione\", Emma Watson" timeout = 60s maxHeap = 2 GiB maxTemp = 90°C Simple Cases ∘ Load a string value directly.
Scala API Simply construct Config instances using the factory method. import uk.co.bigbeeconsultants.bconfig.Config val config = Config(new File("src/test/resources/sample1.txt")) You can create a new Config instance from a File or anything that provides an InputStream. Or use the Config.fromClasspath method to read a resource from the classpath. When constructing a Config, you can include another Config as a fallback source of default values; this too can have a fallback so a chain of any length of them is possible.
1. The Config File Writing your config file is easy. It’s like a java.util.Properties file except it must be Unicode (ISO-10646) encoding, not ISO-8859 or some such. Nowadays there are plenty of tools to transcode text files, notably uconv on Linux/Unix computers, various IDEs, native2ascii in the JDK tool suite may be useful in some cases. The config file may optionally start with a Unicode byte-order-mark (BOM) and this is required for automatic switching between UTF-8, UTF-16 and UTF-32.
Bintray Scala 2.11 Scala 2.10 Option 1: Maven / Ivy dependency Please use the Set Me Up link you’ll find on one of the ‘Download’ pages, above. Option 2: manual download Browse one of the ‘Download’ pages, above. Choose a version and navigate to the Files tab to find the jars. Download the jars and put them on your classpath. You need bee-config_1.X.X.jar and you may find the javadoc and source jars useful during development, too.
Bee Config provides a very simple Java and Scala API for loading configuration files. Config files become Maps Simplicity is the key! Still often used in Scala applications, java.util.Properties is rarely satisfactory. Bee Config is broadly similar in intent, but pimped to work well in Scala. Why is Bee Config different: well, Properties files are sooo 20th Century. We need something similar, something as simple but something refreshed. We need to move on from ASCII to Unicode.