Skip to content

Commit

Permalink
added plugin codenarc
Browse files Browse the repository at this point in the history
  • Loading branch information
zhurlik committed Jan 16, 2019
1 parent 7aa99d6 commit 806c9f7
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 54 deletions.
22 changes: 5 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@ plugins {
id 'groovy'
id 'jacoco'
id 'com.github.kt3k.coveralls'
id 'checkstyle'
id 'com.github.spotbugs'
id 'maven'
id 'codenarc'
}

repositories {
mavenCentral()
jcenter()
}

checkstyle {
toolVersion = '8.15'
}

spotbugs {
toolVersion = '3.1.10'
excludeFilter = file("$rootProject.projectDir/config/spotbugs/exclude.xml")
codenarc {
// TODO: fix all issues
ignoreFailures = true
configFile = file("${project.projectDir}/config/codenarc/codenarc.groovy")
}

jacocoTestReport {
Expand All @@ -32,14 +28,6 @@ jacocoTestReport {
}
}

// To generate an HTML report instead of XML
tasks.withType(com.github.spotbugs.SpotBugsTask) {
reports {
xml.enabled = false
html.enabled = true
}
}

group = 'com.github.zhurlik'

targetCompatibility = VERSION_1_7
Expand Down
17 changes: 17 additions & 0 deletions config/codenarc/codenarc.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ruleset {
description 'Grails-CodeNarc Project RuleSet'

ruleset('rulesets/basic.xml')
ruleset('rulesets/braces.xml')
ruleset('rulesets/convention.xml')
ruleset('rulesets/design.xml')
ruleset('rulesets/dry.xml')
ruleset('rulesets/exceptions.xml')
ruleset('rulesets/formatting.xml')
ruleset('rulesets/generic.xml')
ruleset('rulesets/imports.xml')
ruleset('rulesets/naming.xml')
ruleset('rulesets/unnecessary.xml')
ruleset('rulesets/unused.xml')
ruleset('rulesets/grails.xml')
}
6 changes: 0 additions & 6 deletions config/spotbugs/exclude.xml

This file was deleted.

5 changes: 0 additions & 5 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ pluginManagement {
useVersion '2.8.2'
}

// spotbugs
if (requested.id.id == 'com.github.spotbugs') {
useVersion '1.6.9'
}

// plugin-publish
if (requested.id.id == 'com.gradle.plugin-publish') {
useVersion '0.10.0'
Expand Down
12 changes: 9 additions & 3 deletions src/main/groovy/com/github/zhurlik/JBossModulesPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ import org.gradle.api.Project
import org.gradle.api.tasks.bundling.Compression
import org.gradle.api.tasks.bundling.Tar

import static java.io.File.separator
import java.nio.file.Paths

/**
* Gradle plugin to make JBoss Modules.
*
* @author zhurlik@gmail.com
*/
@Slf4j('logger')
class JBossModulesPlugin implements Plugin<Project> {

private static final String MODULES = 'modules'

@Override
void apply(final Project project) {
logger.info '>> Plugin: JBoss Modules'
Expand All @@ -42,8 +46,10 @@ class JBossModulesPlugin implements Plugin<Project> {
project.jbossrepos.each { JBossServer server ->
project.distributions.create(server.name)
project.distributions[server.name].baseName = server.name
project.distributions[server.name].contents.from([project.buildDir.path, 'install', server.name, 'modules'].join(separator)) {
into 'modules'
project.distributions[server.name].contents.from(
Paths.get(project.buildDir.path, 'install', server.name, MODULES).toFile()
) {
into MODULES
}

// {server.name}DistTar/Zip tasks depend on checkModules to be able to create modules
Expand Down
55 changes: 32 additions & 23 deletions src/main/groovy/com/github/zhurlik/tag/ModuleTag.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import groovy.xml.MarkupBuilder

import java.util.function.Consumer
import java.util.function.Supplier
import java.util.stream.Stream

import static com.github.zhurlik.Ver.V_1_7
import static com.github.zhurlik.Ver.V_1_8
Expand Down Expand Up @@ -40,29 +41,18 @@ class ModuleTag {

if (version.isValid(txt)) {
return Optional.of({
final JBossModule jbModule = new JBossModule(xml.@'name'.text())
final JBossModule jbModule = initJBossModule(xml)
jbModule.ver = version

xml.attributes().each() {
switch (it.key) {
case 'slot': jbModule.slot = it.value
break
case 'name': jbModule.moduleName = it.value
jbModule.name = it.value
break
case 'version': jbModule.version = it.value
break
}
}

jbModule.mainClass = xml.'main-class'.@name

PropertiesTag.parse(xml).accept(jbModule)
ResourcesTag.parse(xml).accept(jbModule)
ExportsTag.parse(xml).accept(jbModule)
PermissionsTag.parse(xml).accept(jbModule)
DependenciesTag.parse(xml).accept(jbModule)
ProvidesTag.parse(xml).accept(jbModule)
Stream.of(
PropertiesTag.parse(xml),
ResourcesTag.parse(xml),
ExportsTag.parse(xml),
PermissionsTag.parse(xml),
DependenciesTag.parse(xml),
ProvidesTag.parse(xml)
).forEach({ final Consumer<JBossModule> action ->
action.accept(jbModule)
})

log.debug '>> Module: \'{}\' has been created', jbModule.name

Expand All @@ -73,8 +63,27 @@ class ModuleTag {
}
}

private static JBossModule initJBossModule(final GPathResult xml) {
final JBossModule jbModule = new JBossModule(xml.@'name'.text())
xml.attributes().each() {
switch (it.key) {
case 'slot': jbModule.slot = it.value
break
case 'name': jbModule.moduleName = it.value
jbModule.name = it.value
break
case 'version': jbModule.version = it.value
break
}
}

jbModule.mainClass = xml.'main-class'.@name

return jbModule
}

/**
* Specifies the main class of this module; used to run the module from the command-line (optional).
* Specifies the main class of this module; used to run the module from the command-line (optional).
* <br/>
* See <xsd:element name="main-class" type="classNameType" minOccurs="0">
*
Expand Down

0 comments on commit 806c9f7

Please sign in to comment.