Skip to content

Commit

Permalink
Merge pull request #33 from wuan/coveralls_support
Browse files Browse the repository at this point in the history
support coveralls
  • Loading branch information
wuan committed Dec 1, 2015
2 parents ab5a054 + a5a5d1c commit 03c8a64
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 23 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
language: java
install: "mvn install -DskipTests=true"
script: "mvn test -e"
script: "mvn -e clean test jacoco:report coveralls:report"
jdk:
- oraclejdk7
- oraclejdk8
- openjdk7

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Java Config-Builder [![Build Status](https://travis-ci.org/TNG/config-builder.png?branch=master)](https://travis-ci.org/TNG/config-builder)
Java Config-Builder [![Build Status](https://travis-ci.org/TNG/config-builder.svg?branch=coveralls_support)](https://travis-ci.org/TNG/config-builder) [![Coverage Status](https://coveralls.io/repos/wuan/config-builder/badge.svg?branch=coveralls_support&service=github)](https://coveralls.io/github/wuan/config-builder?branch=coveralls_support)
==================

#### Table of Contents
Expand Down
18 changes: 18 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,24 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.0.0</version>
</plugin>
</plugins>
</build>

Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/tngtech/configbuilder/ConfigBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@
* Builds a config object.
* ConfigBuilder instantiates a class and sets fields of the instance by parsing annotations and
* loading values from properties files or the command line. It validates the instance by parsing JSR303 constraint annotations.<p>
* <p/>
*
* Fields of the config class can have the following annotations:<br>
* {@link com.tngtech.configbuilder.annotation.valueextractor.DefaultValue}<br>
* {@link com.tngtech.configbuilder.annotation.valueextractor.PropertyValue}<br>
* {@link com.tngtech.configbuilder.annotation.valueextractor.CommandLineValue}<br>
* {@link com.tngtech.configbuilder.annotation.valueextractor.SystemPropertyValue}<br>
* {@link com.tngtech.configbuilder.annotation.valueextractor.EnvironmentVariableValue}<br>
* {@link LoadingOrder}<p>
* <p/>
* {@link LoadingOrder}<br>
*
* Properties files are loaded with a PropertyLoader using its default config. In order to change settings for the PropertyLoader, the config class may be annotated with<br>
* {@link com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertiesFiles}<br>
* {@link com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyLocations}<br>
* {@link com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertySuffixes}<br>
* {@link com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyExtension}<p>
* <p/>
* {@link com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyExtension}<br>
*
* To specify a global order for parsing {@link com.tngtech.configbuilder.annotation.valueextractor.ValueExtractorAnnotation} annotations, annotate the class with <br>
* {@link LoadingOrder}<p>
* <p/>
* {@link LoadingOrder}<br>
*
* To specify your own error messages file (which is loaded by the PropertyLoader with the same settings as other the properties files), annotate the class with <br>
* {@link ErrorMessageFile}<p>
* {@link ErrorMessageFile}<br>
*
* @param <T> The type of the config class which shall be instantiated.
* @author Matthias Bollwein
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public CommandLine getCommandLine(Class configClass, String[] args) {
public Options getOptions(Class configClass) {
Options options = configBuilderFactory.createInstance(Options.class);
for (Field field : annotationHelper.getFieldsAnnotatedWith(configClass, CommandLineValue.class)) {
if (field.isSynthetic()) {
continue;
}
options.addOption(getOption(field));
}
return options;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/tngtech/configbuilder/util/FieldSetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public FieldSetter(ConfigBuilderFactory configBuilderFactory) {
public void setFields(T instanceOfConfigClass, BuilderConfiguration builderConfiguration) {

for (Field field : getInheritedPrivateFields(instanceOfConfigClass.getClass())) {
if (field.isSynthetic()) {
continue;
}

if (annotationHelper.fieldHasAnnotationAnnotatedWith(field, ValueExtractorAnnotation.class)) {
Object value = fieldValueExtractor.extractValue(field, builderConfiguration);
value = fieldValueTransformer.transformFieldValue(field, value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tngtech.configbuilder;


import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.tngtech.configbuilder.testclasses.TestConfig;
Expand All @@ -13,14 +14,17 @@

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.unitils.reflectionassert.ReflectionAssert.assertReflectionEquals;
import static org.unitils.reflectionassert.ReflectionAssert.assertLenientEquals;

@RunWith(Parameterized.class)
public class ConfigBuilderIntegrationTest {
Expand Down Expand Up @@ -64,7 +68,7 @@ public ConfigBuilderIntegrationTest(Class configClass, Object configInstance) {

@Test
public void testConfigBuilderWithParameters() {
ConfigBuilder configBuilder = new ConfigBuilder(configClass);
ConfigBuilder configBuilder = ConfigBuilder.on(configClass);
String[] args = new String[]{"-u", "--collection", "first entry,second entry"};
Object result = configBuilder.withCommandLineArgs(args).build();
assertReflectionEquals(configInstance, result);
Expand All @@ -86,11 +90,12 @@ public void testWithImportedConfig() {

TestConfig importedTestConfig = new TestConfig();
importedTestConfig.setSomeNumber(5);
importedTestConfig.setStringCollection(Lists.newArrayList("/mnt","/home"));
importedTestConfig.setStringCollection(Lists.newArrayList("/mnt", "/home"));

TestConfig expectedTestConfig = new TestConfig();
expectedTestConfig.setSomeNumber(5);
expectedTestConfig.setPathCollection(Sets.newHashSet(Paths.get("/mnt"), Paths.get("/home")));
List<Path> paths = Arrays.asList(Paths.get("/mnt"), Paths.get("/home"));
expectedTestConfig.setPathCollection(Sets.newLinkedHashSet(paths));
expectedTestConfig.setCopiedStringCollection(importedTestConfig.getStringCollection());
expectedTestConfig.setSomeString("Hello, World!");
expectedTestConfig.setBoolean(true);
Expand All @@ -100,12 +105,11 @@ public void testWithImportedConfig() {
expectedTestConfig.setHomeDir(Paths.get(home));
expectedTestConfig.setSystemProperty(userLanguage);


ConfigBuilder configBuilder = new ConfigBuilder(configClass);
ConfigBuilder configBuilder = ConfigBuilder.on(configClass);
String[] args = new String[]{"-u", "--collection", "collection,two"};

Object result = configBuilder.withCommandLineArgs(args).withImportedConfiguration(importedTestConfig).build();
assertReflectionEquals(expectedTestConfig, result);
assertLenientEquals(expectedTestConfig, result);
assertTrue(outContent.toString().contains("config validated"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
import com.tngtech.propertyloader.impl.filters.VariableResolvingFilter;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.*;

@PropertyExtension("testproperties")
@PropertySuffixes(extraSuffixes = {"test"})
Expand Down Expand Up @@ -66,7 +63,7 @@ public TestConfig transform(String input) {

@DefaultValue("/etc,/usr")
@ImportedValue("stringCollection")
private HashSet<Path> pathCollection;
private Set<Path> pathCollection;

@ImportedValue("stringCollection")
private Iterable<String> copiedStringCollection;
Expand Down Expand Up @@ -116,7 +113,7 @@ public Collection<Path> getPathCollection() {
return pathCollection;
}

public void setPathCollection(HashSet<Path> pathCollection) {
public void setPathCollection(Set<Path> pathCollection) {
this.pathCollection = pathCollection;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ private static class TestConfigForIllegalArgumentException {
}

private static class TestConfigWithoutAnnotations {

public String testString = "testString";
}

Expand Down

0 comments on commit 03c8a64

Please sign in to comment.