Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit bc54830

Browse files
committed
Merge remote-tracking branch 'origin/v2'
2 parents bdf52c1 + 3b54ca7 commit bc54830

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1810
-1059
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Change log
2+
3+
4+
All notable changes to the LaunchDarkly Java SDK will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org).
5+
6+
## [2.0.0] - 2016-08-08
7+
### Added
8+
- Support for multivariate feature flags. New methods `boolVariation`, `jsonVariation` and `intVariation` and `doubleVariation` for multivariates.
9+
- Added `LDClientInterface`, an interface suitable for mocking `LDClient`.
10+
11+
### Changed
12+
- The `Feature` data model has been replaced with `FeatureFlag`. `FeatureFlag` is not generic.
13+
- The `allFlags` method now returns a `Map<String, JsonElement>` to support multivariate flags.
14+
15+
### Deprecated
16+
- The `toggle` call has been deprecated in favor of `boolVariation`.
17+
18+
### Removed
19+
- The `getFlag` call has been removed.
20+
- The `debugStreaming` configuration option has been removed.

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Contributing to the LaunchDarkly SDK for Java
2+
================================================
3+
4+
We encourage pull-requests and other contributions from the community. We've also published an [SDK contributor's guide](http://docs.launchdarkly.com/v1.0/docs/sdk-contributors-guide) that provides a detailed explanation of how our SDKs work.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2014 Catamorphic, Co.
1+
Copyright 2016 Catamorphic, Co.
22

33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.

README.md

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ Quick setup
1111
<dependency>
1212
<groupId>com.launchdarkly</groupId>
1313
<artifactId>launchdarkly-client</artifactId>
14-
<version>1.0.2</version>
14+
<version>2.0.0</version>
1515
</dependency>
1616

1717
1. Import the LaunchDarkly package:
1818

1919
import com.launchdarkly.client.*;
2020

21-
2. Create a new LDClient with your API key:
21+
2. Create a new LDClient with your SDK key:
2222

23-
LDClient ldClient = new LDClient("YOUR_API_KEY");
23+
LDClient ldClient = new LDClient("YOUR_SDK_KEY");
2424

2525
Your first feature flag
2626
-----------------------
@@ -29,36 +29,14 @@ Your first feature flag
2929
2. In your application code, use the feature's key to check wthether the flag is on for each user:
3030

3131
LDUser user = new LDUser(username);
32-
boolean showFeature = ldClient.toggle("your.feature.key", user, false);
32+
boolean showFeature = ldClient.boolVariation("your.feature.key", user, false);
3333
if (showFeature) {
3434
// application code to show the feature
3535
}
3636
else {
3737
// the code to run if the feature is off
3838
}
3939

40-
Troubleshooting
41-
---------------
42-
1. Json parsing exception: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was....ExceptionType: com.google.gson.JsonSyntaxException
43-
Make sure your build tool is bringing in the proper version of Gson. The LaunchDarkly SDK may have problems with versions earlier than 2.2.4. To enforce the proper version add this dependency:
44-
```
45-
<dependency>
46-
<groupId>com.google.code.gson</groupId>
47-
<artifactId>gson</artifactId>
48-
<version>2.2.4</version>
49-
</dependency>
50-
```
51-
52-
1. SSL exceptions when calling toggle():
53-
Make sure your build tool is bringing in the proper version of the Apache http client. The LaunchDarkly SDK may have problems with versions earlier than 4.3.6. To enforce the proper version add this dependency:
54-
```
55-
<dependency>
56-
<groupId>org.apache.httpcomponents</groupId>
57-
<artifactId>httpclient</artifactId>
58-
<version>4.3.6</version>
59-
</dependency>
60-
```
61-
6240
Learn more
6341
----------
6442

build.gradle

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,38 @@ repositories {
1919

2020
allprojects {
2121
group = 'com.launchdarkly'
22-
version = "1.0.2"
22+
version = "2.0.0-SNAPSHOT"
2323
sourceCompatibility = 1.7
2424
targetCompatibility = 1.7
2525
}
2626

2727
dependencies {
28-
compile "org.apache.httpcomponents:httpclient:4.3.6"
29-
compile "org.apache.httpcomponents:httpclient-cache:4.3.6"
30-
compile "commons-codec:commons-codec:1.5"
31-
compile "com.google.code.gson:gson:2.2.4"
28+
compile "org.apache.httpcomponents:httpclient:4.5.2"
29+
compile "org.apache.httpcomponents:httpclient-cache:4.5.2"
30+
compile "commons-codec:commons-codec:1.10"
31+
compile "com.google.code.gson:gson:2.6.2"
3232
compile "com.google.guava:guava:19.0"
33-
compile "org.slf4j:slf4j-api:1.7.7"
33+
compile "joda-time:joda-time:2.9.3"
34+
compile "org.slf4j:slf4j-api:1.7.21"
3435
compile group: "com.launchdarkly", name: "okhttp-eventsource", version: "0.2.1", changing: true
35-
compile "redis.clients:jedis:2.8.0"
36+
compile "redis.clients:jedis:2.8.1"
3637
testCompile "org.easymock:easymock:3.4"
3738
testCompile 'junit:junit:4.12'
3839
testRuntime "ch.qos.logback:logback-classic:1.1.7"
3940
}
4041

4142
jar {
42-
baseName = 'launchdarkly-client'
43-
manifest {
44-
attributes("Implementation-Version": version)
45-
}
43+
baseName = 'launchdarkly-client'
44+
// thin classifier means that the non-shaded non-fat jar is still available
45+
// but is opt-in since users will have to specify it.
46+
classifier = 'thin'
47+
manifest {
48+
attributes("Implementation-Version": version)
49+
}
4650
}
4751

4852
task wrapper(type: Wrapper) {
49-
gradleVersion = '2.0'
53+
gradleVersion = '2.14-rc-3'
5054
}
5155

5256
buildscript {
@@ -56,7 +60,7 @@ buildscript {
5660
mavenLocal()
5761
}
5862
dependencies {
59-
classpath 'org.ajoberstar:gradle-git:0.12.0'
63+
classpath 'org.ajoberstar:gradle-git:1.5.0-rc.1'
6064
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3'
6165
}
6266
}
@@ -89,7 +93,35 @@ githubPages {
8993
}
9094

9195
shadowJar {
92-
classifier = 'all'
96+
baseName = 'launchdarkly-client'
97+
//no classifier means that the fat + shaded jar becomes the default artifact
98+
classifier = ''
99+
100+
// Shade all jars except for launchdarkly
101+
relocate('com', 'com.launchdarkly.shaded.com') {
102+
exclude("com.launchdarkly.client.*")
103+
exclude("com.google.gson.*")
104+
exclude("com.google.gson.annotations.*")
105+
exclude("com.google.gson.internal.*")
106+
exclude("com.google.gson.internal.bind.*")
107+
exclude("com.google.gson.internal.bind.util.*")
108+
exclude("com.google.gson.internal.bind.util.*")
109+
exclude("com.google.gson.reflect.*")
110+
exclude("com.google.gson.stream.*")
111+
}
112+
relocate('okhttp3', 'com.launchdarkly.shaded.okhttp3')
113+
relocate('okio', 'com.launchdarkly.shaded.okio')
114+
relocate('org', 'com.launchdarkly.shaded.org') {
115+
exclude("org.slf4j.*")
116+
exclude("org.slf4j.event.*")
117+
exclude("org.slf4j.helpers.*")
118+
exclude("org.slf4j.spi.*")
119+
}
120+
relocate('redis', 'com.launchdarkly.shaded.redis')
121+
122+
manifest {
123+
attributes("Implementation-Version": version)
124+
}
93125
}
94126

95127
test {

gradle/wrapper/gradle-wrapper.jar

2.26 KB
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Aug 11 16:15:27 PDT 2014
1+
#Tue Jun 07 10:02:02 PDT 2016
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-rc-3-all.zip

gradlew

Lines changed: 26 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.launchdarkly.client;
2+
3+
import com.google.gson.JsonArray;
4+
import com.google.gson.JsonElement;
5+
import com.google.gson.JsonPrimitive;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
9+
import java.util.List;
10+
11+
class Clause {
12+
private final static Logger logger = LoggerFactory.getLogger(Clause.class);
13+
14+
private String attribute;
15+
private Operator op;
16+
private List<JsonPrimitive> values; //interpreted as an OR of values
17+
private boolean negate;
18+
19+
boolean matchesUser(LDUser user) {
20+
JsonElement userValue = user.getValueForEvaluation(attribute);
21+
if (userValue == null) {
22+
return false;
23+
}
24+
25+
if (userValue.isJsonArray()) {
26+
JsonArray array = userValue.getAsJsonArray();
27+
for (JsonElement jsonElement : array) {
28+
if (!jsonElement.isJsonPrimitive()) {
29+
logger.error("Invalid custom attribute value in user object: " + jsonElement);
30+
return false;
31+
}
32+
if (matchAny(jsonElement.getAsJsonPrimitive())) {
33+
return maybeNegate(true);
34+
}
35+
}
36+
return maybeNegate(false);
37+
} else if (userValue.isJsonPrimitive()) {
38+
return maybeNegate(matchAny(userValue.getAsJsonPrimitive()));
39+
}
40+
logger.warn("Got unexpected user attribute type: " + userValue.getClass().getName() + " for user key: "
41+
+ user.getKey() + " and attribute: " + attribute);
42+
return false;
43+
}
44+
45+
private boolean matchAny(JsonPrimitive userValue) {
46+
for (JsonPrimitive v : values) {
47+
if (op.apply(userValue, v)) {
48+
return true;
49+
}
50+
}
51+
return false;
52+
}
53+
54+
private boolean maybeNegate(boolean b) {
55+
if (negate)
56+
return !b;
57+
else
58+
return b;
59+
}
60+
61+
62+
}

0 commit comments

Comments
 (0)