Improved logging.
This commit is contained in:
parent
352bdaeb0d
commit
dafbaaff0f
8 changed files with 41 additions and 38 deletions
10
.idea/compiler.xml
generated
Normal file
10
.idea/compiler.xml
generated
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<bytecodeTargetLevel>
|
||||||
|
<module name="semver" target="1.8" />
|
||||||
|
<module name="semver.main" target="1.8" />
|
||||||
|
<module name="semver.test" target="1.8" />
|
||||||
|
</bytecodeTargetLevel>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -96,29 +96,15 @@ open class SemverConfig @Inject constructor(
|
||||||
val separator: String
|
val separator: String
|
||||||
get() = semVersion.separator
|
get() = semVersion.separator
|
||||||
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return mapOf(
|
return "SemverConfig(semVersion=$semVersion, properties='$properties', semverKey='$semverKey'," +
|
||||||
Pair("properties", properties),
|
" majorKey='$majorKey', minorKey='$minorKey', patchKey='$patchKey', preReleaseKey='$preReleaseKey'," +
|
||||||
Pair("semverKey", semverKey),
|
" preReleasePrefixKey='$preReleasePrefixKey', buildMetaKey='$buildMetaKey'," +
|
||||||
Pair("majorKey", majorKey),
|
" buildMetaPrefixKey='$buildMetaPrefixKey', separatorKey='$separatorKey', keysPrefix='$keysPrefix'," +
|
||||||
Pair("minorKey", minorKey),
|
" semver='$semver', version='$version', major=$major, minor=$minor, patch=$patch," +
|
||||||
Pair("patchKey", patchKey),
|
" preRelease='$preRelease', buildMeta='$buildMeta', preReleasePrefix='$preReleasePrefix'," +
|
||||||
Pair("preReleaseKey", preReleaseKey),
|
" buildMetaPrefix='$buildMetaPrefix', separator='$separator')"
|
||||||
Pair("preReleasePrefixKey", preReleasePrefixKey),
|
|
||||||
Pair("buildMetaKey", buildMetaKey),
|
|
||||||
Pair("buildMetaPrefixKey", buildMetaPrefixKey),
|
|
||||||
Pair("separator", separatorKey),
|
|
||||||
Pair("keysPrefix", keysPrefix),
|
|
||||||
Pair("semver", semver),
|
|
||||||
Pair("major", major),
|
|
||||||
Pair("minor", minor),
|
|
||||||
Pair("patch", patch),
|
|
||||||
Pair("preRelease", preRelease),
|
|
||||||
Pair("buildMeta", buildMeta),
|
|
||||||
Pair("preReleasePrefix", preReleasePrefix),
|
|
||||||
Pair("buildMetaPrefix", buildMetaPrefix),
|
|
||||||
Pair("separator", separator)
|
|
||||||
).toString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ open class SemverIncrementBuildMetaTask @Inject constructor(
|
||||||
if (version.buildMeta != buildMeta) {
|
if (version.buildMeta != buildMeta) {
|
||||||
version.buildMeta = buildMeta
|
version.buildMeta = buildMeta
|
||||||
project.version = version.semver
|
project.version = version.semver
|
||||||
logger.lifecycle("Version: ${project.version}")
|
if (logger.isLifecycleEnabled) logger.lifecycle("Version: ${project.version}")
|
||||||
Utils.saveProperties(project.projectDir, config, version)
|
Utils.saveProperties(project.projectDir, config, version)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ open class SemverIncrementTask @Inject constructor(
|
||||||
isPatch = type == SemverConfig.DEFAULT_PATCH_KEY
|
isPatch = type == SemverConfig.DEFAULT_PATCH_KEY
|
||||||
)
|
)
|
||||||
project.version = version.semver
|
project.version = version.semver
|
||||||
logger.lifecycle("Version: ${project.version}")
|
if (logger.isLifecycleEnabled) logger.lifecycle("Version: ${project.version}")
|
||||||
Utils.saveProperties(project.projectDir, config, version)
|
Utils.saveProperties(project.projectDir, config, version)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.gradle.api.Plugin
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.util.GradleVersion
|
import org.gradle.util.GradleVersion
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
class SemverPlugin : Plugin<Project> {
|
class SemverPlugin : Plugin<Project> {
|
||||||
private val simpleName = SemverPlugin::class.simpleName
|
private val simpleName = SemverPlugin::class.simpleName
|
||||||
private var version = Version()
|
private var version = Version()
|
||||||
|
@ -60,7 +61,7 @@ class SemverPlugin : Plugin<Project> {
|
||||||
private fun afterEvaluate(project: Project) {
|
private fun afterEvaluate(project: Project) {
|
||||||
val propsFile = Utils.getPropertiesFile(project.projectDir, config.properties)
|
val propsFile = Utils.getPropertiesFile(project.projectDir, config.properties)
|
||||||
|
|
||||||
if (project.version != "unspecified") {
|
if (project.version != "unspecified" && project.logger.isWarnEnabled) {
|
||||||
project.logger.warn(
|
project.logger.warn(
|
||||||
"Please specify the version in ${propsFile.name} and remove it from ${project.buildFile.name}"
|
"Please specify the version in ${propsFile.name} and remove it from ${project.buildFile.name}"
|
||||||
)
|
)
|
||||||
|
@ -69,10 +70,12 @@ class SemverPlugin : Plugin<Project> {
|
||||||
propsFile.apply {
|
propsFile.apply {
|
||||||
val isNew = !exists()
|
val isNew = !exists()
|
||||||
|
|
||||||
|
if (project.logger.isInfoEnabled) {
|
||||||
project.logger.info(
|
project.logger.info(
|
||||||
"[$simpleName] Attempting to read properties from: `$absoluteFile`. " +
|
"[$simpleName] Attempting to read properties from: `$absoluteFile`. " +
|
||||||
"[exists: $isNew, isFile: $isFile, canRead: ${canRead()}]"
|
"[exists: $isNew, isFile: $isFile, canRead: ${canRead()}]"
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
val props = Utils.loadProperties(this)
|
val props = Utils.loadProperties(this)
|
||||||
val requiredProps = setOf(
|
val requiredProps = setOf(
|
||||||
|
@ -89,10 +92,14 @@ class SemverPlugin : Plugin<Project> {
|
||||||
}
|
}
|
||||||
|
|
||||||
project.version = version.semver
|
project.version = version.semver
|
||||||
|
if (project.logger.isInfoEnabled) {
|
||||||
project.logger.info("[$simpleName] Project version set to: ${project.version}")
|
project.logger.info("[$simpleName] Project version set to: ${project.version}")
|
||||||
|
}
|
||||||
|
|
||||||
if (!hasReqProps || !isFile) {
|
if (!hasReqProps || !isFile) {
|
||||||
|
if (project.logger.isInfoEnabled) {
|
||||||
project.logger.info("[$simpleName] Saving version properties to `$absoluteFile`.")
|
project.logger.info("[$simpleName] Saving version properties to `$absoluteFile`.")
|
||||||
|
}
|
||||||
Utils.saveProperties(project.projectDir, config, version)
|
Utils.saveProperties(project.projectDir, config, version)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,11 +38,11 @@ import java.util.Properties
|
||||||
|
|
||||||
internal class SortedProperties : Properties() {
|
internal class SortedProperties : Properties() {
|
||||||
override val entries: MutableSet<MutableMap.MutableEntry<Any, Any>>
|
override val entries: MutableSet<MutableMap.MutableEntry<Any, Any>>
|
||||||
get() = super.entries.sortedWith(Comparator { a, b -> a.toString().compareTo(b.toString()) }).toMutableSet()
|
get() = super.entries.sortedWith { a, b -> a.toString().compareTo(b.toString()) }.toMutableSet()
|
||||||
|
|
||||||
override fun keys(): Enumeration<Any> {
|
override fun keys(): Enumeration<Any> {
|
||||||
val keys = Collections.list(super.keys())
|
val keys = Collections.list(super.keys())
|
||||||
keys.sortWith(Comparator { a, b -> a.toString().compareTo(b.toString()) })
|
keys.sortWith { a, b -> a.toString().compareTo(b.toString()) }
|
||||||
return Collections.enumeration(keys)
|
return Collections.enumeration(keys)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,12 +148,12 @@ object Utils {
|
||||||
version.buildMeta = ""
|
version.buildMeta = ""
|
||||||
|
|
||||||
if (parts.size > min) {
|
if (parts.size > min) {
|
||||||
when {
|
when (parts.size) {
|
||||||
parts.size == max -> {
|
max -> {
|
||||||
version.preRelease = parts[3]
|
version.preRelease = parts[3]
|
||||||
version.buildMeta = parts[4]
|
version.buildMeta = parts[4]
|
||||||
}
|
}
|
||||||
parts.size == 4 -> {
|
4 -> {
|
||||||
if (input.endsWith(version.buildMetaPrefix + parts[3])) {
|
if (input.endsWith(version.buildMetaPrefix + parts[3])) {
|
||||||
version.buildMeta = parts[3]
|
version.buildMeta = parts[3]
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -71,7 +71,7 @@ class SemverConfigTest {
|
||||||
assertEquals(config.properties, "version.properties", "config.properties should be version.properties")
|
assertEquals(config.properties, "version.properties", "config.properties should be version.properties")
|
||||||
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
config.toString().contains("properties=${SemverConfig.DEFAULT_PROPERTIES}"),
|
config.toString().contains("properties='${SemverConfig.DEFAULT_PROPERTIES}'"),
|
||||||
"toString contains default properties"
|
"toString contains default properties"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue