Skip to content

Commit

Permalink
Adjusted automatic ArchUnit-Example update to include 3 sets of examp…
Browse files Browse the repository at this point in the history
…les for plain, junit4 and junit5. Also added news article about release.

Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
  • Loading branch information
codecholeric committed Aug 19, 2018
1 parent 0c3238f commit e8f597c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 21 deletions.
66 changes: 45 additions & 21 deletions build-steps/release/update-examples.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import java.util.regex.Pattern

final String archunitExamplesGitRepo = 'https://github.com/TNG/ArchUnit-Examples.git'
final File checkoutDir = new File(project.buildDir, 'example-update')
final List<String> exampleFolders = ['example-plain', 'example-junit4', 'example-junit5']

task checkoutArchUnitExample {
doLast {
Expand All @@ -13,38 +14,61 @@ task checkoutArchUnitExample {

task copyArchUnitExampleSrc(dependsOn: checkoutArchUnitExample) {
doLast {
def targetSource = new File(checkoutDir, 'src')
targetSource.deleteDir()
copy {
from new File(project(':archunit-example').projectDir, 'src')
into targetSource
exampleFolders.each { exampleFolder ->
def targetSource = new File(new File(checkoutDir, exampleFolder), 'src')
targetSource.deleteDir()
copy {
from new File(project(':archunit-example:example-plain').projectDir, 'src/main')
into new File(targetSource, 'main')
}
copy {
from new File(project(":archunit-example:${exampleFolder}").projectDir, 'src/test')
into new File(targetSource, 'test')
}
}
}
}

task removeArchUnitExampleCategory(dependsOn: copyArchUnitExampleSrc) {
doLast {
new File(checkoutDir, 'src/test/java/com/tngtech/archunit/exampletest/Example.java').delete()
def removeLines = { File file, List<String> linesToRemove ->
def regex = "(${linesToRemove.collect { Pattern.quote(it) }.join('|')})\n"
file.text = file.text.replaceAll(regex, '')
}

def removeLines = { File file, List<String> linesToRemove ->
def regex = "(${linesToRemove.collect { Pattern.quote(it) }.join('|')})\n"
file.text = file.text.replaceAll(regex, '')
}
def removeExampleCategory = { File baseDir, String categoryFqn ->
new File(baseDir, "src/test/java/${categoryFqn.replace('.', '/')}.java").delete()

new File(checkoutDir, 'src').traverse(type: FileType.FILES, nameFilter: { it.endsWith('.java') }) { File file ->
removeLines(file, [
'@Category(Example.class)',
'import org.junit.experimental.categories.Category;',
'import com.tngtech.archunit.exampletest.Example;'
])
}
new File(baseDir, 'src').traverse(type: FileType.FILES, nameFilter: { it.endsWith('.java') }) { File file ->
removeLines(file, [
'@Category(Example.class)',
'import org.junit.experimental.categories.Category;',
"import ${categoryFqn};"
])
}
}

def removeExampleTag = { File baseDir ->
new File(baseDir, 'src').traverse(type: FileType.FILES, nameFilter: { it.endsWith('.java') }) { File file ->
removeLines(file, [
'@ArchTag("example")',
'import com.tngtech.archunit.junit.ArchTag;'
])
}
}

task removeArchUnitExampleCategory(dependsOn: copyArchUnitExampleSrc) {
doLast {
removeExampleCategory(new File(checkoutDir, 'example-plain'), 'com.tngtech.archunit.exampletest.Example')
removeExampleCategory(new File(checkoutDir, 'example-junit4'), 'com.tngtech.archunit.exampletest.junit4.Example')
removeExampleTag(new File(checkoutDir, 'example-junit5'))
}
}

task updateArchUnitExampleVersion(dependsOn: checkoutArchUnitExample) {
doLast {
def buildFile = new File(checkoutDir, 'build.gradle')
buildFile.text = buildFile.text.replaceAll(/(com\.tngtech\.archunit:archunit-junit4:)[\d.]*/, "\$1${version}")
exampleFolders.each { exampleFolder ->
def buildFile = new File(new File(checkoutDir, exampleFolder), 'build.gradle')
buildFile.text = buildFile.text.replaceAll(/(com\.tngtech\.archunit:archunit[^:]*:)[\d.]*/, "\$1${version}")
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions docs/_posts/2018-08-19-release-v0.9.0.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
layout: splash
title: "New release of ArchUnit (v0.9.0)"
date: 2018-08-19 18:00:00
categories: news release
---

A new release of ArchUnit (v0.9.0) is out. For details see [the release on GitHub](https://github.com/TNG/ArchUnit/releases/tag/v0.9.0 "ArchUnit v0.9.0 on GitHub").

0 comments on commit e8f597c

Please sign in to comment.