Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
iantabolt committed Oct 6, 2017
2 parents 3448ef5 + 1b7460b commit 3d44d90
Show file tree
Hide file tree
Showing 30 changed files with 916 additions and 163 deletions.
23 changes: 22 additions & 1 deletion HOCON.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
- [Include syntax](#include-syntax)
- [Include semantics: merging](#include-semantics-merging)
- [Include semantics: substitution](#include-semantics-substitution)
- [Include semantics: missing files](#include-semantics-missing-files)
- [Include semantics: missing files and required files](#include-semantics-missing-files-and-required-files)
- [Include semantics: file formats and extensions](#include-semantics-file-formats-and-extensions)
- [Include semantics: locating resources](#include-semantics-locating-resources)
- [Conversion of numerically-indexed objects to arrays](#conversion-of-numerically-indexed-objects-to-arrays)
Expand All @@ -47,6 +47,7 @@
- [Substitution fallback to environment variables](#substitution-fallback-to-environment-variables)
- [hyphen-separated vs. camelCase](#hyphen-separated-vs-camelcase)
- [Note on Java properties similarity](#note-on-java-properties-similarity)
- [Note on Windows and case sensitivity of environment variables](#note-on-windows-and-case-sensitivity-of-environment-variables)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down Expand Up @@ -1295,7 +1296,27 @@ must be lowercase. Exactly these strings are supported:
- `m`, `minute`, `minutes`
- `h`, `hour`, `hours`
- `d`, `day`, `days`

### Period Format

Similar to the `getDuration()` method, there is a `getPeriod()` method
available for getting time units as a `java.time.Period`.

This can use the general "units format" described above; bare
numbers are taken to be in days, while strings are
parsed as a number plus an optional unit string.

The supported unit strings for period are case sensitive and
must be lowercase. Exactly these strings are supported:

- `d`, `day`, `days`
- `w`, `week`, `weeks`
- `m`, `mo`, `month`, `months` (note that if you are using `getTemporal()`
which may return either a `java.time.Duration` or a `java.time.Period`
you will want to use `mo` rather than `m` to prevent your unit being
parsed as minutes)
- `y`, `year`, `years`

### Size in bytes format

Implementations may wish to support a `getBytes()` returning a
Expand Down
14 changes: 14 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# 1.3.2: October 6, 2017

- environment variables are now able to be resolved to lists in
the same fashion as system properties.
- added `getPeriod()` which returns time units as
`java.time.Period`. Currently supported periods are days, weeks,
months and years. [More information here](HOCON.md#period-format).
- `ConfigResolveOptions` now has `appendResolver(...)` which allows
having custom behavior when unresolved substitutions are encountered
during resolution.
- Config Beans now support `Set` collection.
- a few other small bugfixes. All of the fixed issues can be found
in the [milestone page](https://github.com/typesafehub/config/milestone/1?closed=1).

# 1.3.1: September 24, 2016

- added `include required("foo")` syntax to specify includes that
Expand Down
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ to merge it in.
- [Java (yep!) wrappers for the Java library](#java-yep-wrappers-for-the-java-library)
- [Scala wrappers for the Java library](#scala-wrappers-for-the-java-library)
- [Clojure wrappers for the Java library](#clojure-wrappers-for-the-java-library)
- [Kotlin wrappers for the Java library](#kotlin-wrappers-for-the-java-library)
- [Scala port](#scala-port)
- [Ruby port](#ruby-port)
- [Puppet module](#puppet-module)
- [Python port](#python-port)
- [C++ port](#c-port)
- [JavaScript port](#javascript-port)
- [Linting tool](#linting-tool)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
Expand Down Expand Up @@ -196,7 +198,7 @@ There isn't a schema language or anything like that. However, two
suggested tools are:

- use the
[checkValid() method](http://typesafehub.github.com/config/latest/api/com/typesafe/config/Config.html#checkValid%28com.typesafe.config.Config,%20java.lang.String...%29)
[checkValid() method](http://typesafehub.github.io/config/latest/api/com/typesafe/config/Config.html#checkValid-com.typesafe.config.Config-java.lang.String...-)
- access your config through a Settings class with a field for
each setting, and instantiate it on startup (immediately
throwing an exception if any settings are missing)
Expand Down Expand Up @@ -251,7 +253,8 @@ library examples in `examples/` show how to accept a custom config
while defaulting to `ConfigFactory.load()`.

For applications using `application.{conf,json,properties}`,
system properties can be used to force a different config source:
system properties can be used to force a different config source
(e.g. from command line `-Dconfig.file=path/to/config-file`):

- `config.resource` specifies a resource name - not a
basename, i.e. `application.conf` not `application`
Expand Down Expand Up @@ -837,16 +840,23 @@ format.
* Ficus https://github.com/ceedubs/ficus
* configz https://github.com/arosien/configz
* configs https://github.com/kxbmap/configs
* config-annotation https://github.com/wacai/config-annotation
* PureConfig https://github.com/melrief/pureconfig
 * config-annotation https://github.com/zhongl/config-annotation
* PureConfig https://github.com/pureconfig/pureconfig
* Simple Scala Config https://github.com/ElderResearch/ssc
* konfig https://github.com/vpon/konfig
* ScalaConfig https://github.com/andr83/scalaconfig
* static-config https://github.com/Krever/static-config
* validated-config https://github.com/carlpulley/validated-config
* Cedi Config https://github.com/ccadllc/cedi-config
* Cfg https://github.com/carueda/cfg

#### Clojure wrappers for the Java library

* beamly-core.config https://github.com/beamly/beamly-core.config


#### Kotlin wrappers for the Java library
* config4k https://github.com/config4k/config4k

#### Scala port

* SHocon https://github.com/unicredit/shocon (work with both Scala and Scala.Js)
Expand All @@ -867,7 +877,10 @@ format.

* https://github.com/puppetlabs/cpp-hocon

#### JavaScript port

* https://github.com/yellowblood/hocon-js (missing features, under development)

#### Linting tool

* A web based linting tool http://www.hoconlint.com/

65 changes: 65 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,75 @@ scalacOptions in GlobalScope in Test := Seq("-unchecked", "-deprecation", "-feat

scalaVersion in ThisBuild := "2.10.4"

val sonatype = new PublishToSonatype {
def projectUrl = "https://github.com/typesafehub/config"
def developerId = "havocp"
def developerName = "Havoc Pennington"
def developerUrl = "http://ometer.com/"
def scmUrl = "git://github.com/typesafehub/config.git"
}

lazy val commonSettings: Seq[Setting[_]] = Def.settings(
unpublished,
javaVersionPrefix in javaVersionCheck := None
)

lazy val root = (project in file("."))
.settings(
commonSettings,
aggregate in doc := false,
doc := (doc in (configLib, Compile)).value,
aggregate in packageDoc := false,
packageDoc := (packageDoc in (configLib, Compile)).value,
aggregate in checkstyle := false,
checkstyle := (checkstyle in (configLib, Compile)).value
)
.aggregate(
testLib, configLib,
simpleLibScala, simpleAppScala, complexAppScala,
simpleLibJava, simpleAppJava, complexAppJava
)

lazy val configLib = Project("config", file("config"))
.settings(
sonatype.settings,
osgiSettings,
OsgiKeys.exportPackage := Seq("com.typesafe.config", "com.typesafe.config.impl"),
publish := sys.error("use publishSigned instead of plain publish"),
publishLocal := sys.error("use publishLocalSigned instead of plain publishLocal")
)
.enablePlugins(SbtOsgi)
.dependsOn(testLib % "test->test")

def proj(id: String, base: File) = Project(id, base) settings commonSettings

lazy val testLib = proj("config-test-lib", file("test-lib"))

lazy val simpleLibScala = proj("config-simple-lib-scala", file("examples/scala/simple-lib")) dependsOn configLib
lazy val simpleAppScala = proj("config-simple-app-scala", file("examples/scala/simple-app")) dependsOn simpleLibScala
lazy val complexAppScala = proj("config-complex-app-scala", file("examples/scala/complex-app")) dependsOn simpleLibScala

lazy val simpleLibJava = proj("config-simple-lib-java", file("examples/java/simple-lib")) dependsOn configLib
lazy val simpleAppJava = proj("config-simple-app-java", file("examples/java/simple-app")) dependsOn simpleLibJava
lazy val complexAppJava = proj("config-complex-app-java", file("examples/java/complex-app")) dependsOn simpleLibJava

useGpg := true

aggregate in PgpKeys.publishSigned := false
PgpKeys.publishSigned := (PgpKeys.publishSigned in configLib).value

aggregate in PgpKeys.publishLocalSigned := false
PgpKeys.publishLocalSigned := (PgpKeys.publishLocalSigned in configLib).value

val unpublished = Seq(
// no artifacts in this project
publishArtifact := false,
// make-pom has a more specific publishArtifact setting already
// so needs specific override
publishArtifact in makePom := false,
// no docs to publish
publishArtifact in packageDoc := false,
// can't seem to get rid of ivy files except by no-op'ing the entire publish task
publish := {},
publishLocal := {}
)
6 changes: 5 additions & 1 deletion config/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ ScalariformKeys.preferences in Compile := formatPrefs
ScalariformKeys.preferences in Test := formatPrefs

fork in test := true
fork in Test := true
fork in run := true
fork in run in Test := true

//env vars for tests
envVars in Test ++= Map("testList.0" -> "0", "testList.1" -> "1")

autoScalaLibrary := false
crossPaths := false

Expand Down Expand Up @@ -58,7 +62,7 @@ checkstyle in Compile := {
}

// add checkstyle as a dependency of doc
doc in Compile <<= (doc in Compile).dependsOn(checkstyle in Compile)
doc in Compile := ((doc in Compile).dependsOn(checkstyle in Compile)).value

findbugsSettings
findbugsReportType := Some(ReportType.Html)
Expand Down
40 changes: 40 additions & 0 deletions config/src/main/java/com/typesafe/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package com.typesafe.config;

import java.time.Duration;
import java.time.Period;
import java.time.temporal.TemporalAmount;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -793,6 +795,44 @@ public interface Config extends ConfigMergeable {
*/
Duration getDuration(String path);

/**
* Gets a value as a java.time.Period. If the value is
* already a number, then it's taken as days; if it's
* a string, it's parsed understanding units suffixes like
* "10d" or "5w" as documented in the <a
* href="https://github.com/typesafehub/config/blob/master/HOCON.md">the
* spec</a>. This method never returns null.
*
* @since 1.3.0
*
* @param path
* path expression
* @return the period value at the requested path
* @throws ConfigException.Missing
* if value is absent or null
* @throws ConfigException.WrongType
* if value is not convertible to Long or String
* @throws ConfigException.BadValue
* if value cannot be parsed as a number of the given TimeUnit
*/
Period getPeriod(String path);

/**
* Gets a value as a java.time.temporal.TemporalAmount.
* This method will first try get get the value as a java.time.Duration, and if unsuccessful,
* then as a java.time.Period.
* This means that values like "5m" will be parsed as 5 minutes rather than 5 months
* @param path path expression
* @return the temporal value at the requested path
* @throws ConfigException.Missing
* if value is absent or null
* @throws ConfigException.WrongType
* if value is not convertible to Long or String
* @throws ConfigException.BadValue
* if value cannot be parsed as a TemporalAmount
*/
TemporalAmount getTemporal(String path);

/**
* Gets a list value (with any element type) as a {@link ConfigList}, which
* implements {@code java.util.List<ConfigValue>}. Throws if the path is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ public static void invalidateCaches() {
// We rely on this having the side effect that it drops
// all caches
ConfigImpl.reloadSystemPropertiesConfig();
ConfigImpl.reloadEnvVariablesConfig();
}

/**
Expand Down
Loading

0 comments on commit 3d44d90

Please sign in to comment.