Skip to content

Commit 97ef015

Browse files
committed
Merge pull request #9 from rspieldenner/jackson
Remove jackson dependency
2 parents 80fed40 + 2abd3d0 commit 97ef015

File tree

7 files changed

+110
-78
lines changed

7 files changed

+110
-78
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
1.1.4 / 2016/03/22
2+
==================
3+
- Remove dependency on jackson libraries
4+
15
1.1.3 / 2016/03/21
26
==================
37
- Publish nebula.resolution-rules-producer to gradle plugin portal

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The [Blacklist Plugin](https://github.com/nebula-plugins/gradle-blacklist-plugin
2121
}
2222
2323
dependencies {
24-
classpath 'com.netflix.nebula:gradle-resolution-rules-plugin:1.1.3'
24+
classpath 'com.netflix.nebula:gradle-resolution-rules-plugin:1.1.4'
2525
}
2626
}
2727
@@ -32,7 +32,7 @@ Or using the Gradle plugin portal:
3232

3333
```groovy
3434
plugins {
35-
id 'nebula.resolution-rules' version '1.1.3'
35+
id 'nebula.resolution-rules' version '1.1.4'
3636
}
3737
```
3838

@@ -138,7 +138,7 @@ The `nebula.resolution-rules-producer` plugin is provided to facilitate creation
138138
}
139139
140140
dependencies {
141-
classpath 'com.netflix.nebula:gradle-resolution-rules-plugin:1.1.3'
141+
classpath 'com.netflix.nebula:gradle-resolution-rules-plugin:1.1.4'
142142
}
143143
}
144144
@@ -149,7 +149,7 @@ Or using the Gradle plugin portal:
149149

150150
```groovy
151151
plugins {
152-
id 'nebula.resolution-rules-producer' version '1.1.3'
152+
id 'nebula.resolution-rules-producer' version '1.1.4'
153153
}
154154
```
155155

@@ -176,7 +176,7 @@ Once configured, run the following:
176176
"module" : "asm:asm",
177177
"with" : "org.ow2.asm:asm",
178178
"reason" : "The asm group id changed for 4.0 and later",
179-
"author" : "Danny Thomas <dmthomas@gmail.com>",
179+
"author" : "Example Person <person@example.org>",
180180
"date" : "2015-10-07T20:21:20.368Z"
181181
}
182182
],
@@ -185,29 +185,29 @@ Once configured, run the following:
185185
"module" : "bouncycastle:bcprov-jdk15",
186186
"with" : "org.bouncycastle:bcprov-jdk15:latest.release",
187187
"reason" : "The latest version of BC is required, using the new coordinate",
188-
"author" : "Danny Thomas <dmthomas@gmail.com>",
188+
"author" : "Example Person <person@example.org>",
189189
"date" : "2015-10-07T20:21:20.368Z"
190190
}
191191
],
192192
"deny": [
193193
{
194194
"module": "com.google.guava:guava:19.0-rc2",
195195
"reason" : "Guava 19.0-rc2 is not permitted",
196-
"author" : "Danny Thomas <dmthomas@gmail.com>",
196+
"author" : "Example Person <person@example.org>",
197197
"date" : "2015-10-07T20:21:20.368Z"
198198
},
199199
{
200200
"module": "com.sun.jersey:jersey-bundle",
201201
"reason" : "jersey-bundle is a fat jar that includes non-relocated (shaded) third party classes, which can cause duplicated classes on the classpath. Please specify the jersey- libraries you need directly",
202-
"author" : "Danny Thomas <dmthomas@gmail.com>",
202+
"author" : "Example Person <person@example.org>",
203203
"date" : "2015-10-07T20:21:20.368Z"
204204
}
205205
],
206206
"reject": [
207207
{
208208
"module": "com.google.guava:guava:12.0",
209209
"reason" : "Guava 12.0 significantly regressed LocalCache performance",
210-
"author" : "Danny Thomas <dmthomas@gmail.com>",
210+
"author" : "Example Person <person@example.org>",
211211
"date" : "2015-10-07T20:21:20.368Z"
212212
}
213213
],

build.gradle

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,9 @@ plugins {
4545
}
4646

4747
dependencies {
48+
compile gradleApi()
49+
compile localGroovy()
4850
compile 'joda-time:joda-time:2.8.2'
49-
compile 'com.fasterxml.jackson.datatype:jackson-datatype-joda:2.6.3'
50-
}
51-
52-
// Attempt to get out of Gradle dependency hell (at least somewhat reflect the runtime classloading scheme) by forcefully ordering Gradle dependencies last
53-
54-
configurations {
55-
gradleApi
56-
}
57-
58-
dependencies {
59-
gradleApi gradleApi()
60-
gradleApi localGroovy()
61-
}
62-
63-
sourceSets.each {
64-
it.compileClasspath = it.compileClasspath - configurations.gradleApi + configurations.gradleApi
65-
it.runtimeClasspath = it.runtimeClasspath - configurations.gradleApi + configurations.gradleApi
6651
}
6752

6853
facets {

src/functionalTest/groovy/nebula/plugin/resolutionrules/AlignRulesSpec.groovy

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2016 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package nebula.plugin.resolutionrules
217

318
import nebula.test.IntegrationSpec

src/main/groovy/nebula/plugin/resolutionrules/ResolutionRulesPlugin.groovy

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 Netflix, Inc.
2+
* Copyright 2015-2016 Netflix, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,13 +14,9 @@
1414
* limitations under the License.
1515
*
1616
*/
17-
1817
package nebula.plugin.resolutionrules
1918

20-
import com.fasterxml.jackson.annotation.JsonInclude
21-
import com.fasterxml.jackson.databind.ObjectMapper
22-
import com.fasterxml.jackson.databind.SerializationFeature
23-
import com.fasterxml.jackson.datatype.joda.JodaModule
19+
import groovy.json.JsonSlurper
2420
import org.gradle.api.Plugin
2521
import org.gradle.api.Project
2622
import org.gradle.api.artifacts.Configuration
@@ -44,7 +40,6 @@ class ResolutionRulesPlugin implements Plugin<Project> {
4440

4541
private Rules rulesFromConfiguration(Configuration configuration) {
4642
List<Rules> rules = new ArrayList<Rules>();
47-
ObjectMapper mapper = createMapper()
4843
Set<File> files = configuration.resolve()
4944
if (files.isEmpty()) {
5045
logger.warn("No resolution rules have been added to the '{}' configuration", configuration.name)
@@ -53,7 +48,7 @@ class ResolutionRulesPlugin implements Plugin<Project> {
5348
if (file.name.endsWith(".json")) {
5449
ResolutionJsonValidator.validateJsonFile(file)
5550
logger.info("Using $file as a dependency rules source")
56-
rules.add(mapper.readValue(file, Rules))
51+
rules.add(parseJsonFile(file))
5752
} else if (file.name.endsWith(".jar") || file.name.endsWith(".zip")) {
5853
logger.info("Using $file as a dependency rules source")
5954
ZipFile jar = new ZipFile(file)
@@ -63,7 +58,7 @@ class ResolutionRulesPlugin implements Plugin<Project> {
6358
ZipEntry entry = entries.nextElement()
6459
if (entry.name.endsWith(".json")) {
6560
ResolutionJsonValidator.validateJsonStream(jar.getInputStream(entry))
66-
rules.add(mapper.readValue(jar.getInputStream(entry), Rules))
61+
rules.add(parseJsonStream(jar.getInputStream(entry)))
6762
}
6863
}
6964
} finally {
@@ -76,6 +71,29 @@ class ResolutionRulesPlugin implements Plugin<Project> {
7671
return flattenRules(rules)
7772
}
7873

74+
static Rules parseJsonFile(File file) {
75+
rulesFromJson(new JsonSlurper().parse(file))
76+
}
77+
78+
static Rules parseJsonText(String json) {
79+
rulesFromJson(new JsonSlurper().parseText(json))
80+
}
81+
82+
static Rules parseJsonStream(InputStream stream) {
83+
rulesFromJson(new JsonSlurper().parse(stream))
84+
}
85+
86+
static Rules rulesFromJson(Map json) {
87+
Rules rules = new Rules()
88+
rules.replace = json.replace.collect { new ReplaceRule(it) }
89+
rules.substitute = json.substitute.collect { new SubstituteRule(it) }
90+
rules.reject = json.reject.collect { new RejectRule(it) }
91+
rules.deny = json.deny.collect { new DenyRule(it) }
92+
rules.align = json.align.collect { new AlignRule(it) }
93+
94+
rules
95+
}
96+
7997
private static Rules flattenRules(Iterable<Rules> rules) {
8098
List<ReplaceRule> replace = rules.collectMany { it.replace }.flatten() as List<ReplaceRule>
8199
List<SubstituteRule> substitute = rules.collectMany { it.substitute }.flatten() as List<SubstituteRule>
@@ -85,14 +103,6 @@ class ResolutionRulesPlugin implements Plugin<Project> {
85103
return new Rules(replace: replace, substitute: substitute, reject: reject, deny: deny, align: align)
86104
}
87105

88-
private static ObjectMapper createMapper() {
89-
ObjectMapper mapper = new ObjectMapper()
90-
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
91-
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
92-
.registerModule(new JodaModule())
93-
return mapper
94-
}
95-
96106
private void applyRules(Rules rules, Project project) {
97107
rules.projectRules().each { it.apply(project) }
98108
project.configurations.all({ configuration ->

src/main/groovy/nebula/plugin/resolutionrules/Rules.groovy

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 Netflix, Inc.
2+
* Copyright 2015-2016 Netflix, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -12,20 +12,17 @@
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
15-
*
1615
*/
17-
1816
package nebula.plugin.resolutionrules
1917

20-
import nebula.plugin.resolutionrules.ModuleIdentifier
21-
import nebula.plugin.resolutionrules.ModuleVersionIdentifier
2218
import org.gradle.api.Project
2319
import org.gradle.api.artifacts.*
2420
import org.gradle.api.artifacts.component.ComponentSelector
2521
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
2622
import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.VersionInfo
2723
import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.DefaultVersionComparator
2824
import org.joda.time.DateTime
25+
import org.joda.time.DateTimeZone
2926

3027
public class Rules {
3128
List<ReplaceRule> replace
@@ -59,13 +56,28 @@ interface ProjectConfigurationRule {
5956
public void apply(Project project, Configuration configuration)
6057
}
6158

62-
class ReplaceRule implements ProjectRule {
63-
String module
64-
String with
59+
abstract class BaseRule {
6560
String reason
6661
String author
6762
DateTime date
6863

64+
BaseRule(Map map) {
65+
reason = map.reason
66+
author = map.author
67+
date = new DateTime(map.date).toDateTime(DateTimeZone.UTC)
68+
}
69+
}
70+
71+
class ReplaceRule extends BaseRule implements ProjectRule {
72+
String module
73+
String with
74+
75+
ReplaceRule(Map map) {
76+
super(map)
77+
module = map.module
78+
with = map.with
79+
}
80+
6981
public void apply(Project project) {
7082
ModuleIdentifier moduleId = ModuleIdentifier.valueOf(module)
7183
ModuleIdentifier withModuleId = ModuleIdentifier.valueOf(with)
@@ -76,12 +88,15 @@ class ReplaceRule implements ProjectRule {
7688
}
7789
}
7890

79-
class SubstituteRule implements ConfigurationRule {
91+
class SubstituteRule extends BaseRule implements ConfigurationRule {
8092
String module
8193
String with
82-
String reason
83-
String author
84-
DateTime date
94+
95+
SubstituteRule(Map map) {
96+
super(map)
97+
module = map.module
98+
with = map.with
99+
}
85100

86101
public void apply(Configuration configuration) {
87102
ResolutionStrategy resolutionStrategy = configuration.resolutionStrategy
@@ -103,11 +118,13 @@ class SubstituteRule implements ConfigurationRule {
103118
}
104119
}
105120

106-
class RejectRule implements ConfigurationRule {
121+
class RejectRule extends BaseRule implements ConfigurationRule {
107122
String module
108-
String reason
109-
String author
110-
DateTime date
123+
124+
RejectRule(Map map) {
125+
super(map)
126+
module = map.module
127+
}
111128

112129
public void apply(Configuration configuration) {
113130
ModuleVersionIdentifier moduleId = ModuleVersionIdentifier.valueOf(module)
@@ -122,11 +139,13 @@ class RejectRule implements ConfigurationRule {
122139
}
123140
}
124141

125-
class DenyRule implements ConfigurationRule {
142+
class DenyRule extends BaseRule implements ConfigurationRule {
126143
String module
127-
String reason
128-
String author
129-
DateTime date
144+
145+
DenyRule(Map map) {
146+
super(map)
147+
module = map.module
148+
}
130149

131150
@Override
132151
public void apply(Configuration configuration) {
@@ -140,13 +159,17 @@ class DenyRule implements ConfigurationRule {
140159
}
141160
}
142161

143-
class AlignRule implements ProjectConfigurationRule {
162+
class AlignRule extends BaseRule implements ProjectConfigurationRule {
144163
String group
145-
Collection<String> includes = []
146-
Collection<String> excludes = []
147-
String reason
148-
String author
149-
DateTime date
164+
Collection<String> includes
165+
Collection<String> excludes
166+
167+
AlignRule(Map map) {
168+
super(map)
169+
group = map.group
170+
includes = map.includes ?: []
171+
excludes = map.excludes ?: []
172+
}
150173

151174
boolean resolvedMatches(ResolvedDependency dep) {
152175
ruleMatches(dep.moduleGroup, dep.moduleName)

src/test/groovy/nebula/plugin/resolutionrules/RulesTest.groovy

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717

1818
package nebula.plugin.resolutionrules
1919

20-
import com.fasterxml.jackson.annotation.JsonInclude
21-
import com.fasterxml.jackson.databind.ObjectMapper
22-
import com.fasterxml.jackson.databind.SerializationFeature
23-
import com.fasterxml.jackson.datatype.joda.JodaModule
20+
import groovy.json.JsonSlurper
2421
import spock.lang.Specification
2522

2623
/**
@@ -44,14 +41,12 @@ class RulesTest extends Specification {
4441
"deny": [],
4542
"align": []
4643
}"""
47-
ObjectMapper mapper = new ObjectMapper()
48-
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
49-
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
50-
.registerModule(new JodaModule())
5144

52-
Rules rules = mapper.readValue(json, Rules)
45+
46+
Rules rules = ResolutionRulesPlugin.parseJsonText(json)
5347

5448
then:
5549
!rules.replace.isEmpty()
50+
rules.replace[0].class == ReplaceRule
5651
}
5752
}

0 commit comments

Comments
 (0)