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
|
||||
get() = semVersion.separator
|
||||
|
||||
|
||||
override fun toString(): String {
|
||||
return mapOf(
|
||||
Pair("properties", properties),
|
||||
Pair("semverKey", semverKey),
|
||||
Pair("majorKey", majorKey),
|
||||
Pair("minorKey", minorKey),
|
||||
Pair("patchKey", patchKey),
|
||||
Pair("preReleaseKey", preReleaseKey),
|
||||
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()
|
||||
return "SemverConfig(semVersion=$semVersion, properties='$properties', semverKey='$semverKey'," +
|
||||
" majorKey='$majorKey', minorKey='$minorKey', patchKey='$patchKey', preReleaseKey='$preReleaseKey'," +
|
||||
" preReleasePrefixKey='$preReleasePrefixKey', buildMetaKey='$buildMetaKey'," +
|
||||
" buildMetaPrefixKey='$buildMetaPrefixKey', separatorKey='$separatorKey', keysPrefix='$keysPrefix'," +
|
||||
" semver='$semver', version='$version', major=$major, minor=$minor, patch=$patch," +
|
||||
" preRelease='$preRelease', buildMeta='$buildMeta', preReleasePrefix='$preReleasePrefix'," +
|
||||
" buildMetaPrefix='$buildMetaPrefix', separator='$separator')"
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ open class SemverIncrementBuildMetaTask @Inject constructor(
|
|||
if (version.buildMeta != buildMeta) {
|
||||
version.buildMeta = buildMeta
|
||||
project.version = version.semver
|
||||
logger.lifecycle("Version: ${project.version}")
|
||||
if (logger.isLifecycleEnabled) logger.lifecycle("Version: ${project.version}")
|
||||
Utils.saveProperties(project.projectDir, config, version)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ open class SemverIncrementTask @Inject constructor(
|
|||
isPatch = type == SemverConfig.DEFAULT_PATCH_KEY
|
||||
)
|
||||
project.version = version.semver
|
||||
logger.lifecycle("Version: ${project.version}")
|
||||
if (logger.isLifecycleEnabled) logger.lifecycle("Version: ${project.version}")
|
||||
Utils.saveProperties(project.projectDir, config, version)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.gradle.api.Plugin
|
|||
import org.gradle.api.Project
|
||||
import org.gradle.util.GradleVersion
|
||||
|
||||
@Suppress("unused")
|
||||
class SemverPlugin : Plugin<Project> {
|
||||
private val simpleName = SemverPlugin::class.simpleName
|
||||
private var version = Version()
|
||||
|
@ -60,7 +61,7 @@ class SemverPlugin : Plugin<Project> {
|
|||
private fun afterEvaluate(project: Project) {
|
||||
val propsFile = Utils.getPropertiesFile(project.projectDir, config.properties)
|
||||
|
||||
if (project.version != "unspecified") {
|
||||
if (project.version != "unspecified" && project.logger.isWarnEnabled) {
|
||||
project.logger.warn(
|
||||
"Please specify the version in ${propsFile.name} and remove it from ${project.buildFile.name}"
|
||||
)
|
||||
|
@ -69,10 +70,12 @@ class SemverPlugin : Plugin<Project> {
|
|||
propsFile.apply {
|
||||
val isNew = !exists()
|
||||
|
||||
project.logger.info(
|
||||
"[$simpleName] Attempting to read properties from: `$absoluteFile`. " +
|
||||
"[exists: $isNew, isFile: $isFile, canRead: ${canRead()}]"
|
||||
)
|
||||
if (project.logger.isInfoEnabled) {
|
||||
project.logger.info(
|
||||
"[$simpleName] Attempting to read properties from: `$absoluteFile`. " +
|
||||
"[exists: $isNew, isFile: $isFile, canRead: ${canRead()}]"
|
||||
)
|
||||
}
|
||||
|
||||
val props = Utils.loadProperties(this)
|
||||
val requiredProps = setOf(
|
||||
|
@ -89,10 +92,14 @@ class SemverPlugin : Plugin<Project> {
|
|||
}
|
||||
|
||||
project.version = version.semver
|
||||
project.logger.info("[$simpleName] Project version set to: ${project.version}")
|
||||
if (project.logger.isInfoEnabled) {
|
||||
project.logger.info("[$simpleName] Project version set to: ${project.version}")
|
||||
}
|
||||
|
||||
if (!hasReqProps || !isFile) {
|
||||
project.logger.info("[$simpleName] Saving version properties to `$absoluteFile`.")
|
||||
if (project.logger.isInfoEnabled) {
|
||||
project.logger.info("[$simpleName] Saving version properties to `$absoluteFile`.")
|
||||
}
|
||||
Utils.saveProperties(project.projectDir, config, version)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,11 +38,11 @@ import java.util.Properties
|
|||
|
||||
internal class SortedProperties : Properties() {
|
||||
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> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,12 +148,12 @@ object Utils {
|
|||
version.buildMeta = ""
|
||||
|
||||
if (parts.size > min) {
|
||||
when {
|
||||
parts.size == max -> {
|
||||
when (parts.size) {
|
||||
max -> {
|
||||
version.preRelease = parts[3]
|
||||
version.buildMeta = parts[4]
|
||||
}
|
||||
parts.size == 4 -> {
|
||||
4 -> {
|
||||
if (input.endsWith(version.buildMetaPrefix + parts[3])) {
|
||||
version.buildMeta = parts[3]
|
||||
} else {
|
||||
|
|
|
@ -71,7 +71,7 @@ class SemverConfigTest {
|
|||
assertEquals(config.properties, "version.properties", "config.properties should be version.properties")
|
||||
|
||||
assertTrue(
|
||||
config.toString().contains("properties=${SemverConfig.DEFAULT_PROPERTIES}"),
|
||||
config.toString().contains("properties='${SemverConfig.DEFAULT_PROPERTIES}'"),
|
||||
"toString contains default properties"
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue