Skip to content

Commit daf0015

Browse files
artembilangaryrussell
authored andcommitted
Add updateCopyrights Gradle task
To avoid extra manual task to check all the files for actual Copyright header an `updateCopyrights` is introduced to be performed before `processResources` and check modified classes via `Git status` command by the `grgit` plugin. The `updateCopyrights` task is enabled only locally: when it's not on Travis or Bamboo - no reason to infer code base when it is not going to be committed.
1 parent 53272fd commit daf0015

File tree

2 files changed

+48
-13
lines changed

2 files changed

+48
-13
lines changed

build.gradle

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ buildscript {
1313
plugins {
1414
id 'org.sonarqube' version '2.6.2'
1515
id 'org.asciidoctor.convert' version '1.5.9.2'
16+
id 'org.ajoberstar.grgit' version '3.0.0'
1617
}
1718

1819
description = 'Spring Integration'
@@ -25,6 +26,9 @@ ext {
2526
linkScmConnection = 'scm:git:git://github.com/spring-projects/spring-integration.git'
2627
linkScmDevConnection = 'scm:git:ssh://[email protected]:spring-projects/spring-integration.git'
2728
docResourcesVersion = '0.1.0.RELEASE'
29+
30+
modifiedFiles =
31+
files(grgit.status().unstaged.modified).filter{ f -> f.name.endsWith('.java') || f.name.endsWith('.kt') }
2832
}
2933

3034
allprojects {
@@ -188,26 +192,59 @@ subprojects { subproject ->
188192
[compileJava, compileTestJava]*.options*.compilerArgs = [xLintArg]
189193

190194
task checkTestConfigs {
191-
doLast {
192-
def configFiles = []
193-
sourceSets.test.java.srcDirs.each {
194-
fileTree(it).include('**/*.xml').exclude('**/log4j2-test.xml').each { configFile ->
195-
def configXml = new XmlParser(false, false).parse(configFile)
195+
def configFiles = []
196+
sourceSets.test.java.srcDirs.each {
197+
fileTree(it).include('**/*.xml').exclude('**/log4j2-test.xml').each { configFile ->
198+
def configXml = new XmlParser(false, false).parse(configFile)
196199

197-
if (configXml.@'xsi:schemaLocation' ==~ /.*spring-[a-z-]*\d\.\d\.xsd.*/) {
198-
configFiles << configFile
199-
}
200+
if (configXml.@'xsi:schemaLocation' ==~ /.*spring-[a-z-]*\d\.\d\.xsd.*/) {
201+
configFiles << configFile
200202
}
201203
}
202-
if (configFiles) {
204+
}
205+
inputs.files(configFiles)
206+
outputs.dir('build')
207+
doLast {
208+
if (!inputs.files.empty) {
203209
throw new InvalidUserDataException('Hardcoded XSD version in the config files:\n' +
204-
configFiles.collect {relativePath(it)}.join('\n') +
210+
inputs.files.collect {relativePath(it) }.join('\n') +
205211
'\nPlease, use versionless schemaLocations for Spring XSDs to avoid issues with builds ' +
206212
'on different versions of dependencies.')
207213
}
208214
}
209215
}
210216

217+
task updateCopyrights {
218+
onlyIf { !System.getenv('TRAVIS') && !System.getenv('bamboo_buildKey') }
219+
inputs.files(modifiedFiles.filter { f -> f.path.contains(subproject.name) })
220+
outputs.dir('build')
221+
222+
doLast {
223+
def now = Calendar.instance.get(Calendar.YEAR) as String
224+
inputs.files.each { file ->
225+
def line
226+
file.withReader { reader ->
227+
while (line = reader.readLine()) {
228+
def matcher = line =~ /Copyright (20\d\d)-?(20\d\d)?/
229+
if (matcher.count) {
230+
def beginningYear = matcher[0][1]
231+
if (now != beginningYear || now != matcher[0][2]) {
232+
def years = "$beginningYear-$now"
233+
def sourceCode = file.text
234+
sourceCode = sourceCode.replaceFirst(/20\d\d(-20\d\d)?/, years)
235+
file.write(sourceCode)
236+
println "Copyright updated for file: $file"
237+
}
238+
break
239+
}
240+
}
241+
}
242+
}
243+
}
244+
}
245+
246+
processResources.dependsOn updateCopyrights
247+
211248
jacocoTestReport {
212249
reports {
213250
xml.enabled false

spring-integration-amqp/src/test/java/org/springframework/integration/amqp/inbound/AmqpMessageSourceTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
import static org.mockito.Mockito.times;
2727
import static org.mockito.Mockito.verify;
2828

29-
import java.io.IOException;
3029
import java.util.concurrent.ExecutorService;
31-
import java.util.concurrent.TimeoutException;
3230

3331
import org.junit.Test;
3432

@@ -101,7 +99,7 @@ public void testRequeue() throws Exception {
10199
testNackOrRequeue(false);
102100
}
103101

104-
private void testNackOrRequeue(boolean requeue) throws IOException, TimeoutException {
102+
private void testNackOrRequeue(boolean requeue) throws Exception {
105103
Channel channel = mock(Channel.class);
106104
willReturn(true).given(channel).isOpen();
107105
Envelope envelope = new Envelope(123L, false, "ex", "rk");

0 commit comments

Comments
 (0)