Skip to content

Commit ad4ab3b

Browse files
committed
Use fenced code blocks in README
1 parent a79009c commit ad4ab3b

File tree

1 file changed

+78
-58
lines changed

1 file changed

+78
-58
lines changed

README.md

Lines changed: 78 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,74 +8,86 @@ JadConfig is a minimalistic annotation-driven configuration parsing framework fo
88

99
Here is a quick example of a Java class used as configuration bean:
1010

11-
public class ConfigurationBean {
12-
@Parameter("my.stringList")
13-
public List<String> myList = new ArrayList<String>();
11+
```java
12+
public class ConfigurationBean {
13+
@Parameter("my.stringList")
14+
public List<String> myList = new ArrayList<String>();
1415

15-
@Parameter("my.integer")
16-
public int myInteger = 1;
16+
@Parameter("my.integer")
17+
public int myInteger = 1;
1718

18-
@Parameter(value = "my.uri", required = true)
19-
public URI myURI;
20-
}
19+
@Parameter(value = "my.uri", required = true)
20+
public URI myURI;
21+
}
22+
```
2123

2224
and how you initialize it with JadConfig:
2325

24-
ConfigurationBean bean = new ConfigurationBean();
25-
new JadConfig(new PropertiesRepository("my.properties"), bean).process();
26+
```java
27+
ConfigurationBean bean = new ConfigurationBean();
28+
new JadConfig(new PropertiesRepository("my.properties"), bean).process();
2629

27-
Assert.assertNotNull(bean.myList);
30+
Assert.assertNotNull(bean.myList);
31+
```
2832

2933

3034
You can also use multiple repositories as source for your configuration (first match wins):
3135

32-
ConfigurationBean bean = new ConfigurationBean();
33-
new JadConfig(
34-
Arrays.asList(
35-
new EnvironmentRepository(),
36-
new PropertiesRepository("my.properties")
37-
),
38-
bean)
39-
.process();
36+
```java
37+
ConfigurationBean bean = new ConfigurationBean();
38+
new JadConfig(
39+
Arrays.asList(
40+
new EnvironmentRepository(),
41+
new PropertiesRepository("my.properties")
42+
),
43+
bean)
44+
.process();
4045

41-
Assert.assertNotNull(bean.myList);
46+
Assert.assertNotNull(bean.myList);
47+
```
4248

4349
### Joda-Time
4450

4551
JadConfig optionally supports [Joda-Time](http://www.joda.org/joda-time/). In order to use it just add the Joda-Time
4652
dependency to your `pom.xml`:
4753

48-
<dependency>
49-
<groupId>joda-time</groupId>
50-
<artifactId>joda-time</artifactId>
51-
<version>2.9</version>
52-
</dependency>
53-
54+
```xml
55+
<dependency>
56+
<groupId>joda-time</groupId>
57+
<artifactId>joda-time</artifactId>
58+
<version>2.9</version>
59+
</dependency>
60+
```
5461

5562
And register `JodaTimeConverterFactory` with the JadConfig instance:
5663

64+
```java
5765
JadConfig jadConfig = new JadConfig(repository, configurationBean);
5866
jadConfig.addConverterFactory(new JodaTimeConverterFactory());
5967
jadConfig.process();
68+
```
6069

6170

6271
### Guava
6372

6473
JadConfig optionally supports some data types from [Google Guava](https://github.com/google/guava/). In order to use
6574
it just add the Google Guava dependency to your `pom.xml`:
6675

67-
<dependency>
68-
<groupId>com.google.guava</groupId>
69-
<artifactId>guava</artifactId>
70-
<version>18.0</version>
71-
</dependency>
72-
76+
```xml
77+
<dependency>
78+
<groupId>com.google.guava</groupId>
79+
<artifactId>guava</artifactId>
80+
<version>18.0</version>
81+
</dependency>
82+
```
7383

7484
And register `GuavaConverterFactory` with the JadConfig instance:
7585

76-
JadConfig jadConfig = new JadConfig(repository, configurationBean);
77-
jadConfig.addConverterFactory(new GuavaConverterFactory());
78-
jadConfig.process();
86+
```java
87+
JadConfig jadConfig = new JadConfig(repository, configurationBean);
88+
jadConfig.addConverterFactory(new GuavaConverterFactory());
89+
jadConfig.process();
90+
```
7991

8092

8193
Currently the following data types are being supported:
@@ -95,39 +107,45 @@ Currently the following data types are being supported:
95107
JadConfig optionally supports registering named bindings in [Google Guice](https://github.com/google/guice/). In order
96108
to use it just add the Google Guice dependency to your `pom.xml`:
97109

98-
<dependency>
99-
<groupId>com.google.inject</groupId>
100-
<artifactId>guice</artifactId>
101-
<version>4.0</version>
102-
</dependency>
110+
```xml
111+
<dependency>
112+
<groupId>com.google.inject</groupId>
113+
<artifactId>guice</artifactId>
114+
<version>4.0</version>
115+
</dependency>
116+
```
103117

104118

105119
And register `NamedConfigParametersModule` with the Guice Injector:
106120

121+
```java
107122
Injector injector = Guice.createInjector(new NamedConfigParametersModule(Collections.singleton(configurationBean)));
123+
```
108124

109125

110126
The name of the bindings are identical to the `@Parameter` name.
111127

112128
Example:
113129

114-
public class MyConfigBean {
115-
@Parameter("my.custom.config")
116-
public String customConfig;
117-
}
130+
```java
131+
public class MyConfigBean {
132+
@Parameter("my.custom.config")
133+
public String customConfig;
134+
}
118135

119-
// Create injector and register NamedConfigParametersModule.
120-
// [...]
136+
// Create injector and register NamedConfigParametersModule.
137+
// [...]
121138

122-
public class MyClass {
123-
@Inject
124-
public MyClass(@Named("my.custom.config") String customConfig) {
125-
// ...
126-
}
139+
public class MyClass {
140+
@Inject
141+
public MyClass(@Named("my.custom.config") String customConfig) {
142+
// ...
127143
}
144+
}
128145

129-
// MyClass will be instantiated with the value of customConfig from the MyConfigBean instance.
130-
MyClass myClass = injector.getInstance(MyClass.class);
146+
// MyClass will be instantiated with the value of customConfig from the MyConfigBean instance.
147+
MyClass myClass = injector.getInstance(MyClass.class);
148+
```
131149

132150
Please note that nullable properties which should be injected by Guice have to be annotated with `@Nullable`,
133151
see [UseNullable](https://github.com/google/guice/wiki/UseNullable) in the Guice wiki for details.
@@ -137,11 +155,13 @@ see [UseNullable](https://github.com/google/guice/wiki/UseNullable) in the Guice
137155

138156
To use JadConfig in your project using Maven add the following lines into the dependencies section of your `pom.xml`:
139157

140-
<dependency>
141-
<groupId>org.graylog</groupId>
142-
<artifactId>jadconfig</artifactId>
143-
<version>1.0.0</version>
144-
</dependency>
158+
```xml
159+
<dependency>
160+
<groupId>org.graylog</groupId>
161+
<artifactId>jadconfig</artifactId>
162+
<version>1.0.0</version>
163+
</dependency>
164+
```
145165

146166

147167
## Support

0 commit comments

Comments
 (0)