Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' into 0.6.0-work

  • Loading branch information...
commit 0c50085b5299332722cf7f84eae23a6942ba4610 2 parents eeba78f + bb71851
@codahale codahale authored
View
17 dropwizard-client/src/main/java/com/yammer/dropwizard/client/JerseyClient.java
@@ -1,5 +1,6 @@
package com.yammer.dropwizard.client;
+import com.sun.jersey.api.client.GenericType;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.client.apache4.ApacheHttpClient4;
import com.sun.jersey.client.apache4.ApacheHttpClient4Handler;
@@ -16,15 +17,31 @@ public JerseyClient(ApacheHttpClient4Handler root, ClientConfig config) {
return resource(uri).accept(acceptedMediaType).get(klass);
}
+ public <T> T get(URI uri, MediaType acceptedMediaType, GenericType<T> klass) {
+ return resource(uri).accept(acceptedMediaType).get(klass);
+ }
+
public <T> T put(URI uri, MediaType contentType, Object entity, Class<T> returnType) {
return resource(uri).type(contentType).put(returnType, entity);
}
+ public <T> T put(URI uri, MediaType contentType, Object entity, GenericType<T> returnType) {
+ return resource(uri).type(contentType).put(returnType, entity);
+ }
+
public <T> T post(URI uri, MediaType contentType, Object entity, Class<T> returnType) {
return resource(uri).type(contentType).post(returnType, entity);
}
+ public <T> T post(URI uri, MediaType contentType, Object entity, GenericType<T> returnType) {
+ return resource(uri).type(contentType).post(returnType, entity);
+ }
+
public <T> T delete(URI uri, Class<T> klass) {
return resource(uri).delete(klass);
}
+
+ public <T> T delete(URI uri, GenericType<T> klass) {
+ return resource(uri).delete(klass);
+ }
}
View
4 dropwizard-core/pom.xml
@@ -15,7 +15,7 @@
<jetty.version>8.1.5.v20120716</jetty.version>
<jackson.version>2.0.5</jackson.version>
<slf4j.version>1.6.6</slf4j.version>
- <logback.version>1.0.6</logback.version>
+ <logback.version>1.0.7</logback.version>
</properties>
<dependencies>
@@ -127,7 +127,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
- <version>13.0</version>
+ <version>13.0.1</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
View
4 dropwizard-core/src/main/java/com/yammer/dropwizard/AbstractService.java
@@ -190,12 +190,16 @@ public final void initializeWithBundles(T configuration, Environment environment
public final void run(String[] arguments) throws Exception {
if (isHelp(arguments)) {
UsagePrinter.printRootHelp(this);
+ if (arguments.length == 0) {
+ System.exit(1);
+ }
} else {
final Command cmd = commands.get(arguments[0]);
if (cmd != null) {
cmd.run(this, Arrays.copyOfRange(arguments, 1, arguments.length));
} else {
UsagePrinter.printRootHelp(this);
+ System.exit(1);
}
}
}
View
3  dropwizard-core/src/main/java/com/yammer/dropwizard/cli/ConfiguredCommand.java
@@ -45,7 +45,7 @@ protected ConfiguredCommand(String name,
// should typically have one of type parameters (first one) that matches:
for (Type param : ((ParameterizedType) t).getActualTypeArguments()) {
if (param instanceof Class<?>) {
- Class<?> cls = (Class<?>) param;
+ final Class<?> cls = (Class<?>) param;
if (Configuration.class.isAssignableFrom(cls)) {
return (Class<T>) cls;
}
@@ -91,6 +91,7 @@ protected final void run(AbstractService<?> service, CommandLine params) throws
}
} catch (ConfigurationException e) {
printHelp(e.getMessage(), service.getClass());
+ System.exit(1);
}
if (configuration != null) {
View
27 dropwizard-core/src/main/java/com/yammer/dropwizard/cli/UsagePrinter.java
@@ -4,6 +4,8 @@
import com.yammer.dropwizard.util.JarLocation;
import org.apache.commons.cli.HelpFormatter;
+import java.io.PrintWriter;
+
@SuppressWarnings("UseOfSystemOutOrSystemErr")
public class UsagePrinter {
private UsagePrinter() {
@@ -11,9 +13,9 @@ private UsagePrinter() {
}
public static void printRootHelp(AbstractService<?> service) {
- System.out.printf("java -jar %s <command> [arg1 arg2]\n\n", new JarLocation(service.getClass()));
- System.out.println("Commands");
- System.out.println("========\n");
+ System.err.printf("java -jar %s <command> [arg1 arg2]\n\n", new JarLocation(service.getClass()));
+ System.err.println("Commands");
+ System.err.println("========\n");
for (Command command : service.getCommands()) {
printCommandHelp(command, service.getClass());
@@ -27,15 +29,24 @@ public static void printCommandHelp(Command cmd, Class<?> klass) {
public static void printCommandHelp(Command cmd, Class<?> klass, String errorMessage) {
if (errorMessage != null) {
System.err.println(errorMessage);
- System.out.println();
+ System.err.println();
}
- System.out.println(formatTitle(cmd));
+ System.err.println(formatTitle(cmd));
final HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.setLongOptPrefix(" --");
- helpFormatter.printHelp(String.format("java -jar %s", cmd.getUsage(klass)),
- cmd.getOptionsWithHelp());
- System.out.println("\n");
+ final PrintWriter pw = new PrintWriter(System.err);
+ helpFormatter.printHelp(pw,
+ HelpFormatter.DEFAULT_WIDTH,
+ String.format("java -jar %s", cmd.getUsage(klass)),
+ null,
+ cmd.getOptionsWithHelp(),
+ HelpFormatter.DEFAULT_LEFT_PAD,
+ HelpFormatter.DEFAULT_DESC_PAD,
+ null,
+ false);
+ pw.flush();
+ System.err.println("\n");
}
private static String formatTitle(Command cmd) {
View
15 dropwizard-core/src/main/java/com/yammer/dropwizard/validation/Validator.java 100644 → 100755
@@ -9,6 +9,7 @@
import javax.validation.Path;
import javax.validation.Validation;
import javax.validation.ValidatorFactory;
+import javax.validation.groups.Default;
import java.util.Set;
import static java.lang.String.format;
@@ -28,8 +29,20 @@
* @return a list of error messages, if any, regarding {@code o}'s validity
*/
public <T> ImmutableList<String> validate(T o) {
+ return validate(o, Default.class);
+ }
+
+ /**
+ * Validates the given object, and returns a list of error messages, if any. If the returned
+ * list is empty, the object is valid.
+ * @param o a potentially-valid object
+ * @param groups group or list of groups targeted for validation (default to {@link javax.validation.groups.Default})
+ * @param <T> the type of object to validate
+ * @return a list of error messages, if any, regarding {@code o}'s validity
+ */
+ public <T> ImmutableList<String> validate(T o, Class<?>... groups) {
final Set<String> errors = Sets.newHashSet();
- final Set<ConstraintViolation<T>> violations = factory.getValidator().validate(o);
+ final Set<ConstraintViolation<T>> violations = factory.getValidator().validate(o,groups);
for (ConstraintViolation<T> v : violations) {
if (v.getConstraintDescriptor().getAnnotation() instanceof ValidationMethod) {
final ImmutableList<Path.Node> nodes = ImmutableList.copyOf(v.getPropertyPath());
View
2  dropwizard-db/pom.xml
@@ -20,7 +20,7 @@
<dependency>
<groupId>org.jdbi</groupId>
<artifactId>jdbi</artifactId>
- <version>2.38.1</version>
+ <version>2.39</version>
</dependency>
<dependency>
<groupId>com.yammer.metrics</groupId>
View
8 dropwizard-testing/src/main/java/com/yammer/dropwizard/testing/ResourceTest.java 100644 → 100755
@@ -27,6 +27,7 @@
private final Set<Class<?>> providers = Sets.newHashSet();
private final List<Module> modules = Lists.newArrayList();
private final Map<String, Boolean> features = Maps.newHashMap();
+ private final Map<String, Object> properties = Maps.newHashMap();
private JerseyTest test;
@@ -48,6 +49,10 @@ protected void addFeature(String feature, Boolean value) {
features.put(feature, value);
}
+ protected void addProperty(String property, Object value) {
+ properties.put(property, value);
+ }
+
protected Json getJson() {
final Json json = new Json();
for (Module module : modules) {
@@ -77,6 +82,9 @@ protected AppDescriptor configure() {
for (Map.Entry<String, Boolean> feature : features.entrySet()) {
config.getFeatures().put(feature.getKey(), feature.getValue());
}
+ for (Map.Entry<String, Object> property : properties.entrySet()) {
+ config.getProperties().put(property.getKey(), property.getValue());
+ }
config.getSingletons().add(new JacksonMessageBodyProvider(json));
config.getSingletons().addAll(singletons);
return new LowLevelAppDescriptor.Builder(config).build();
View
10 findbugs-exclude.xml
@@ -55,4 +55,14 @@
<Class name="~com\.yammer\.dropwizard\.providers\.OauthTokenProvider.*"/>
<Class name="~com\.yammer\.dropwizard\.ScalaService.*"/>
<Class name="~com\.yammer\.dropwizard\.Logging.*" />
+
+ <!-- we're intentionally using default encoding and System.exit -->
+ <Match>
+ <Class name="com.yammer.dropwizard.AbstractService"/>
+ <Bug pattern="DM_EXIT"/>
+ </Match>
+ <Match>
+ <Class name="com.yammer.dropwizard.cli.UsagePrinter"/>
+ <Bug pattern="DM_DEFAULT_ENCODING"/>
+ </Match>
</FindBugsFilter>
Please sign in to comment.
Something went wrong with that request. Please try again.