Skip to content

Commit 3ffaf3e

Browse files
committed
standalone jar (no dependencies) fix #633
1 parent d294115 commit 3ffaf3e

File tree

11 files changed

+73
-62
lines changed

11 files changed

+73
-62
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ language: java
33
jdk:
44
- oraclejdk8
55
after_success:
6-
- mvn clean cobertura:cobertura coveralls:cobertura
6+
- mvn clean install cobertura:cobertura coveralls:cobertura

handlebars-guava-cache/src/main/java/com/github/jknack/handlebars/cache/GuavaTemplateCache.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
*/
1818
package com.github.jknack.handlebars.cache;
1919

20-
import static org.apache.commons.lang3.Validate.notNull;
21-
2220
import java.io.IOException;
2321
import java.util.concurrent.ExecutionException;
2422

@@ -28,6 +26,7 @@
2826
import com.github.jknack.handlebars.io.ReloadableTemplateSource;
2927
import com.github.jknack.handlebars.io.TemplateSource;
3028
import com.google.common.cache.Cache;
29+
import static java.util.Objects.requireNonNull;
3130

3231
/**
3332
* An implementation of {@link TemplateCache} built on top of Guava. If {@link #setReload(boolean)}
@@ -53,7 +52,7 @@ public class GuavaTemplateCache implements TemplateCache {
5352
* @param cache The guava cache to use. Required.
5453
*/
5554
public GuavaTemplateCache(final Cache<TemplateSource, Template> cache) {
56-
this.cache = notNull(cache, "The cache is required.");
55+
this.cache = requireNonNull(cache, "The cache is required.");
5756
}
5857

5958
@Override
@@ -68,8 +67,8 @@ public void evict(final TemplateSource source) {
6867

6968
@Override
7069
public Template get(final TemplateSource source, final Parser parser) throws IOException {
71-
notNull(source, "The source is required.");
72-
notNull(parser, "The parser is required.");
70+
requireNonNull(source, "The source is required.");
71+
requireNonNull(parser, "The parser is required.");
7372
try {
7473
return cache.get(key(source), () -> parser.parse(source));
7574
} catch (ExecutionException ex) {

handlebars-helpers/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
<artifactId>handlebars</artifactId>
2121
<version>${project.version}</version>
2222
</dependency>
23+
24+
<!-- commons-lang3 -->
25+
<dependency>
26+
<groupId>org.apache.commons</groupId>
27+
<artifactId>commons-lang3</artifactId>
28+
</dependency>
2329

2430
<dependency>
2531
<groupId>joda-time</groupId>

handlebars-humanize/src/main/java/com/github/jknack/handlebars/HumanizeHelper.java

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
*/
1818
package com.github.jknack.handlebars;
1919

20-
import static org.apache.commons.lang3.Validate.isTrue;
21-
import static org.apache.commons.lang3.Validate.notNull;
2220
import humanize.Humanize;
2321

2422
import java.io.IOException;
2523
import java.util.Date;
2624
import java.util.Locale;
2725

2826
import com.github.jknack.handlebars.internal.Locales;
27+
import static java.util.Objects.requireNonNull;
2928

3029
/**
3130
* Handlebars helper for the Humanize library.
@@ -51,7 +50,6 @@ public enum HumanizeHelper implements Helper<Object> {
5150
@Override
5251
public Object apply(final Object value, final Options options)
5352
throws IOException {
54-
isTrue(value instanceof Number, "found '%s', expected: 'number'", value);
5553
return Humanize.binaryPrefix((Number) value, resolveLocale(options));
5654
}
5755
},
@@ -71,7 +69,6 @@ public Object apply(final Object value, final Options options)
7169
@Override
7270
public Object apply(final Object value, final Options options)
7371
throws IOException {
74-
isTrue(value instanceof String, "found '%s', expected: 'string'", value);
7572
Boolean capFirst = options.hash("capFirst", true);
7673
return Humanize.camelize((String) value, capFirst);
7774
}
@@ -92,7 +89,6 @@ public Object apply(final Object value, final Options options)
9289
@Override
9390
public Object apply(final Object value, final Options options)
9491
throws IOException {
95-
isTrue(value instanceof String, "found '%s', expected: 'string'", value);
9692
return Humanize.capitalize((String) value);
9793
}
9894
},
@@ -112,7 +108,6 @@ public Object apply(final Object value, final Options options)
112108
@Override
113109
public Object apply(final Object value, final Options options)
114110
throws IOException {
115-
isTrue(value instanceof String, "found '%s', expected: 'string'", value);
116111
String replacement = options.hash("replacement", " ");
117112
return Humanize.decamelize((String) value, replacement);
118113
}
@@ -133,7 +128,6 @@ public Object apply(final Object value, final Options options)
133128
@Override
134129
public Object apply(final Object value, final Options options)
135130
throws IOException {
136-
isTrue(value instanceof Number, "found '%s', expected: 'number'", value);
137131
return Humanize.formatCurrency((Number) value, resolveLocale(options));
138132
}
139133
},
@@ -153,7 +147,6 @@ public Object apply(final Object value, final Options options)
153147
@Override
154148
public Object apply(final Object value, final Options options)
155149
throws IOException {
156-
isTrue(value instanceof Number, "found '%s', expected: 'number'", value);
157150
return Humanize.formatPercent((Number) value, resolveLocale(options));
158151
}
159152
},
@@ -174,7 +167,6 @@ public Object apply(final Object value, final Options options)
174167
@Override
175168
public Object apply(final Object value, final Options options)
176169
throws IOException {
177-
isTrue(value instanceof Number, "found '%s', expected: 'number'", value);
178170
return Humanize.metricPrefix((Number) value, resolveLocale(options));
179171
}
180172
},
@@ -194,7 +186,6 @@ public Object apply(final Object value, final Options options)
194186
@Override
195187
public Object apply(final Object value, final Options options)
196188
throws IOException {
197-
isTrue(value instanceof Date, "found '%s', expected: 'date'", value);
198189
return Humanize.naturalDay((Date) value);
199190
}
200191
},
@@ -216,7 +207,6 @@ public Object apply(final Object value, final Options options)
216207
@Override
217208
public Object apply(final Object value, final Options options)
218209
throws IOException {
219-
isTrue(value instanceof Date, "found '%s', expected: 'date'", value);
220210
return Humanize.naturalTime((Date) value, resolveLocale(options));
221211
}
222212
},
@@ -237,7 +227,6 @@ public Object apply(final Object value, final Options options)
237227
@Override
238228
public Object apply(final Object value, final Options options)
239229
throws IOException {
240-
isTrue(value instanceof Number, "found '%s', expected: 'number'", value);
241230
return Humanize.ordinal((Number) value, resolveLocale(options));
242231
}
243232
},
@@ -291,7 +280,6 @@ public Object apply(final Object value, final Options options)
291280
@Override
292281
public Object apply(final Object value, final Options options)
293282
throws IOException {
294-
isTrue(value instanceof String, "found '%s', expected: 'string'", value);
295283
return Humanize.pluralizeFormat((String) value, resolveLocale(options))
296284
.render(options.params);
297285
}
@@ -326,7 +314,6 @@ public Object apply(final Object value, final Options options)
326314
@Override
327315
public Object apply(final Object value, final Options options)
328316
throws IOException {
329-
isTrue(value instanceof String, "found '%s', expected: 'string'", value);
330317
return Humanize.slugify((String) value);
331318
}
332319
},
@@ -347,7 +334,6 @@ public Object apply(final Object value, final Options options)
347334
@Override
348335
public Object apply(final Object value, final Options options)
349336
throws IOException {
350-
isTrue(value instanceof Number, "found '%s', expected: 'number'", value);
351337
return Humanize.spellBigNumber((Number) value, resolveLocale(options));
352338
}
353339
},
@@ -368,7 +354,6 @@ public Object apply(final Object value, final Options options)
368354
@Override
369355
public Object apply(final Object value, final Options options)
370356
throws IOException {
371-
isTrue(value instanceof Number, "found '%s', expected: 'number'", value);
372357
return Humanize.spellDigit((Number) value, resolveLocale(options));
373358
}
374359
},
@@ -389,7 +374,6 @@ public Object apply(final Object value, final Options options)
389374
@Override
390375
public Object apply(final Object value, final Options options)
391376
throws IOException {
392-
isTrue(value instanceof String, "found '%s', expected: 'string'", value);
393377
return Humanize.titleize((String) value);
394378
}
395379
},
@@ -409,7 +393,6 @@ public Object apply(final Object value, final Options options)
409393
@Override
410394
public Object apply(final Object value, final Options options)
411395
throws IOException {
412-
isTrue(value instanceof String, "found '%s', expected: 'string'", value);
413396
return Humanize.transliterate((String) value);
414397
}
415398
},
@@ -429,7 +412,6 @@ public Object apply(final Object value, final Options options)
429412
@Override
430413
public Object apply(final Object value, final Options options)
431414
throws IOException {
432-
isTrue(value instanceof String, "found '%s', expected: 'string'", value);
433415
return Humanize.underscore((String) value);
434416
}
435417
},
@@ -450,11 +432,8 @@ public Object apply(final Object value, final Options options)
450432
@Override
451433
public Object apply(final Object value, final Options options)
452434
throws IOException {
453-
isTrue(value instanceof String, "found '%s', expected: 'string'", value);
454435
Number length = options.param(0, null);
455-
notNull(length, "found 'null', expected 'word wrap length'");
456-
isTrue(length.intValue() > 0, "found '%s', expected 'a positive number'",
457-
length);
436+
requireNonNull(length, "found 'null', expected 'word wrap length'");
458437
return Humanize.wordWrap((String) value, length.intValue());
459438
}
460439
};
@@ -476,7 +455,6 @@ protected static Locale resolveLocale(final Options options) {
476455
* @param handlebars The helper's owner.
477456
*/
478457
public static void register(final Handlebars handlebars) {
479-
notNull(handlebars, "A handlebars object is required.");
480458
for (HumanizeHelper helper : values()) {
481459
handlebars.registerHelper(helper.name(), helper);
482460
}

handlebars-jackson2/src/main/java/com/github/jknack/handlebars/Jackson2Helper.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
*/
1818
package com.github.jknack.handlebars;
1919

20-
import static org.apache.commons.lang3.StringUtils.isEmpty;
21-
import static org.apache.commons.lang3.Validate.notEmpty;
22-
import static org.apache.commons.lang3.Validate.notNull;
23-
2420
import java.io.IOException;
2521
import java.util.HashMap;
2622
import java.util.Map;
@@ -32,6 +28,7 @@
3228
import com.fasterxml.jackson.core.io.SegmentedStringWriter;
3329
import com.fasterxml.jackson.databind.ObjectMapper;
3430
import com.fasterxml.jackson.databind.ObjectWriter;
31+
import static java.util.Objects.requireNonNull;
3532

3633
/**
3734
* A Jackson 2.x helper.
@@ -152,7 +149,7 @@ public SerializableString getEscapeSequence(final int ch) {
152149
* @param objectMapper The object's mapper. Required.
153150
*/
154151
public Jackson2Helper(final ObjectMapper objectMapper) {
155-
mapper = notNull(objectMapper, "The object mapper is required.");
152+
mapper = requireNonNull(objectMapper, "The object mapper is required.");
156153
}
157154

158155
/**
@@ -173,7 +170,7 @@ public Object apply(final Object context, final Options options)
173170
try {
174171
final ObjectWriter writer;
175172
// do we need to use a view?
176-
if (!isEmpty(viewName)) {
173+
if (!Handlebars.Utils.isEmpty(viewName)) {
177174
Class<?> viewClass = alias.get(viewName);
178175
if (viewClass == null) {
179176
viewClass = getClass().getClassLoader().loadClass(viewName);
@@ -225,8 +222,8 @@ public Object apply(final Object context, final Options options)
225222
*/
226223
public Jackson2Helper viewAlias(final String alias,
227224
final Class<?> viewClass) {
228-
this.alias.put(notEmpty(alias, "A view alias is required."),
229-
notNull(viewClass, "A view class is required."));
225+
this.alias.put(requireNonNull(alias, "A view alias is required."),
226+
requireNonNull(viewClass, "A view class is required."));
230227
return this;
231228
}
232229
}

handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/HandlebarsView.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@
1717
*/
1818
package com.github.jknack.handlebars.springmvc;
1919

20-
import static org.apache.commons.lang3.Validate.notEmpty;
21-
import static org.apache.commons.lang3.Validate.notNull;
22-
2320
import java.io.IOException;
2421
import java.util.Locale;
2522
import java.util.Map;
2623

2724
import javax.servlet.http.HttpServletRequest;
2825
import javax.servlet.http.HttpServletResponse;
2926

27+
import static java.util.Objects.requireNonNull;
3028
import org.springframework.web.servlet.view.AbstractTemplateView;
3129

3230
import com.github.jknack.handlebars.Context;
@@ -86,7 +84,7 @@ public boolean checkResource(final Locale locale) {
8684
* @param template The compiled template. Required.
8785
*/
8886
void setTemplate(final Template template) {
89-
this.template = notNull(template, "A handlebars template is required.");
87+
this.template = requireNonNull(template, "A handlebars template is required.");
9088
}
9189

9290
/**
@@ -95,7 +93,7 @@ void setTemplate(final Template template) {
9593
* @param valueResolvers The value resolvers. Required.
9694
*/
9795
void setValueResolver(final ValueResolver... valueResolvers) {
98-
this.valueResolvers = notEmpty(valueResolvers,
96+
this.valueResolvers = requireNonNull(valueResolvers,
9997
"At least one value-resolver must be present.");
10098
}
10199

handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/HandlebarsViewResolver.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
*/
1818
package com.github.jknack.handlebars.springmvc;
1919

20-
import static org.apache.commons.lang3.Validate.notEmpty;
21-
import static org.apache.commons.lang3.Validate.notNull;
20+
import static java.util.Objects.requireNonNull;
2221

2322
import java.io.File;
2423
import java.io.IOException;
@@ -226,7 +225,7 @@ public void afterPropertiesSet() {
226225
TemplateLoader templateLoader = createTemplateLoader(getApplicationContext());
227226

228227
// Creates a new handlebars object.
229-
handlebars = notNull(createHandlebars(templateLoader),
228+
handlebars = requireNonNull(createHandlebars(templateLoader),
230229
"A handlebars object is required.");
231230
}
232231

@@ -335,7 +334,7 @@ public Handlebars getHandlebars() {
335334
* @param valueResolvers The value resolvers. Required.
336335
*/
337336
public void setValueResolvers(final ValueResolver... valueResolvers) {
338-
this.valueResolvers = notEmpty(valueResolvers,
337+
this.valueResolvers = requireNonNull(valueResolvers,
339338
"At least one value-resolver must be present.");
340339
}
341340

@@ -345,7 +344,7 @@ public void setValueResolvers(final ValueResolver... valueResolvers) {
345344
* @param formatters Formatters to add.
346345
*/
347346
public void setFormatters(final Formatter... formatters) {
348-
this.formatters = notEmpty(formatters,
347+
this.formatters = requireNonNull(formatters,
349348
"At least one formatter must be present.");
350349
}
351350

@@ -373,7 +372,7 @@ public void setFormatters(final Formatter... formatters) {
373372
* @param location A classpath location of the handlebar.js file.
374373
*/
375374
public void setHandlebarsJsFile(final String location) {
376-
this.handlebarsJsFile = notEmpty(location, "Location is required");
375+
this.handlebarsJsFile = requireNonNull(location, "Location is required");
377376
}
378377

379378
/**
@@ -393,7 +392,7 @@ public void setFailOnMissingFile(final boolean failOnMissingFile) {
393392
* @see Handlebars#registerHelper(String, Helper)
394393
*/
395394
public void setHelpers(final Map<String, Helper<?>> helpers) {
396-
notNull(helpers, "The helpers are required.");
395+
requireNonNull(helpers, "The helpers are required.");
397396
for (Entry<String, Helper<?>> helper : helpers.entrySet()) {
398397
registry.registerHelper(helper.getKey(), helper.getValue());
399398
}
@@ -407,7 +406,7 @@ public void setHelpers(final Map<String, Helper<?>> helpers) {
407406
* @see Handlebars#registerHelpers(Object)
408407
*/
409408
public void setHelperSources(final List<?> helpers) {
410-
notNull(helpers, "The helpers are required.");
409+
requireNonNull(helpers, "The helpers are required.");
411410
for (Object helper : helpers) {
412411
registry.registerHelpers(helper);
413412
}
@@ -607,7 +606,7 @@ public HandlebarsViewResolver registerDecorator(final String name, final Decorat
607606
}
608607

609608
@Override public HandlebarsViewResolver setCharset(final Charset charset) {
610-
this.charset = notNull(charset, "Charset required.");
609+
this.charset = requireNonNull(charset, "Charset required.");
611610
return this;
612611
}
613612
}

0 commit comments

Comments
 (0)