mirror of
https://github.com/HighCapable/SweetProperty.git
synced 2025-09-04 01:35:37 +08:00
refactor: replace not to !
This commit is contained in:
@@ -48,7 +48,7 @@ internal class ProjectDescriptor private constructor() {
|
||||
it.type = Type.SETTINGS
|
||||
it.name = name.noBlank() ?: settings.rootProject.name
|
||||
it.currentDir = (if (isRootProject) settings.rootProject else settings.findProject(name))?.projectDir
|
||||
?: SError.make("Project \"$name\" not found${if (name.startsWith(":").not()) ", $subProjectNotice" else ""}")
|
||||
?: SError.make("Project \"$name\" not found${if (!name.startsWith(":")) ", $subProjectNotice" else ""}")
|
||||
it.rootDir = settings.rootDir
|
||||
it.homeDir = settings.gradle.gradleUserHomeDir
|
||||
}
|
||||
|
@@ -37,7 +37,7 @@ import org.gradle.api.plugins.ExtensionAware
|
||||
*/
|
||||
internal fun ExtensionAware.getOrCreate(name: String, clazz: Class<*>, vararg args: Any?) = name.toSafeExtName().let { sName ->
|
||||
runCatching { extensions.create(sName, clazz, *args).asExtension() }.getOrElse {
|
||||
if ((it is IllegalArgumentException && it.message?.startsWith("Cannot add extension with name") == true).not()) throw it
|
||||
if (!(it is IllegalArgumentException && it.message?.startsWith("Cannot add extension with name") == true)) throw it
|
||||
runCatching { extensions.getByName(sName).asExtension() }.getOrNull() ?: SError.make("Create or get extension failed with name \"$sName\"")
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ internal fun ExtensionAware.getOrCreate(name: String, clazz: Class<*>, vararg ar
|
||||
*/
|
||||
internal inline fun <reified T> ExtensionAware.getOrCreate(name: String, vararg args: Any?) = name.toSafeExtName().let { sName ->
|
||||
runCatching { extensions.create(sName, T::class.java, *args) as T }.getOrElse {
|
||||
if ((it is IllegalArgumentException && it.message?.startsWith("Cannot add extension with name") == true).not()) throw it
|
||||
if (!(it is IllegalArgumentException && it.message?.startsWith("Cannot add extension with name") == true)) throw it
|
||||
runCatching { extensions.getByName(sName) as? T? }.getOrNull() ?: SError.make("Create or get extension failed with name \"$sName\"")
|
||||
}
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ internal fun Project.fullName(isUseColon: Boolean = true): String {
|
||||
project.parent?.also { if (it != it.rootProject) fetchChild(it) }
|
||||
baseNames.add(project.name)
|
||||
}; fetchChild(project = this)
|
||||
return buildString { baseNames.onEach { append(":$it") }.clear() }.let { if (isUseColon && isRoot.not()) it else it.drop(1) }
|
||||
return buildString { baseNames.onEach { append(":$it") }.clear() }.let { if (isUseColon && !isRoot) it else it.drop(1) }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -474,13 +474,13 @@ open class SweetPropertyConfigureExtension internal constructor() {
|
||||
|
||||
/** 检查合法包名 */
|
||||
fun String.checkingValidPackageName() {
|
||||
if (isNotBlank() && matches("^[a-zA-Z_][a-zA-Z0-9_]*(\\.[a-zA-Z_][a-zA-Z0-9_]*)*$".toRegex()).not())
|
||||
if (isNotBlank() && !matches("^[a-zA-Z_][a-zA-Z0-9_]*(\\.[a-zA-Z_][a-zA-Z0-9_]*)*$".toRegex()))
|
||||
SError.make("Invalid package name \"$this\"")
|
||||
}
|
||||
|
||||
/** 检查合法类名 */
|
||||
fun String.checkingValidClassName() {
|
||||
if (isNotBlank() && matches("^[a-zA-Z][a-zA-Z0-9_]*$".toRegex()).not())
|
||||
if (isNotBlank() && !matches("^[a-zA-Z][a-zA-Z0-9_]*$".toRegex()))
|
||||
SError.make("Invalid class name \"$this\"")
|
||||
}
|
||||
|
||||
|
@@ -98,7 +98,7 @@ internal class PropertiesAccessorsGenerator {
|
||||
*/
|
||||
private inline fun noRepeated(vararg tags: String, block: () -> Unit) {
|
||||
val allTag = tags.joinToString("-")
|
||||
if (usedSuccessiveTags.contains(allTag).not()) block()
|
||||
if (!usedSuccessiveTags.contains(allTag)) block()
|
||||
usedSuccessiveTags.add(allTag)
|
||||
}
|
||||
|
||||
@@ -313,12 +313,12 @@ internal class PropertiesAccessorsGenerator {
|
||||
}
|
||||
noRepeated(className, nextMethodName, nextClassName) {
|
||||
getOrCreateClassSpec(className, accessorsName).apply {
|
||||
if (isPreLastIndex.not()) {
|
||||
if (!isPreLastIndex) {
|
||||
addSuccessiveField(nextAccessorsName, nextClassName)
|
||||
addSuccessiveMethod(nextAccessorsName, nextMethodName, nextClassName)
|
||||
} else addFinalValueMethod(successiveName, lastMethodName, lastClassName, value)
|
||||
}
|
||||
if (isPreLastIndex.not()) preAddConstructorSpecNames.add(className to nextClassName)
|
||||
if (!isPreLastIndex) preAddConstructorSpecNames.add(className to nextClassName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -52,7 +52,7 @@ internal fun Any.parseTypedValue(isAutoConversion: Boolean): Pair<KClass<*>, Str
|
||||
it.drop(1).dropLast(1)
|
||||
} else it.replace("\"", "\\\"")
|
||||
}
|
||||
if (isAutoConversion.not()) return Pair(String::class, "\"$valueString\"")
|
||||
if (!isAutoConversion) return Pair(String::class, "\"$valueString\"")
|
||||
val typeSpec = when {
|
||||
isStringType -> String::class
|
||||
valueString.trim().toIntOrNull() != null -> Int::class
|
||||
@@ -62,6 +62,6 @@ internal fun Any.parseTypedValue(isAutoConversion: Boolean): Pair<KClass<*>, Str
|
||||
valueString.trim() == "true" || valueString.trim() == "false" -> Boolean::class
|
||||
else -> String::class
|
||||
}; return Pair(typeSpec, if (typeSpec == String::class) "\"$valueString\"" else valueString.let {
|
||||
if (typeSpec == Long::class && it.endsWith("L").not()) "${it}L" else it
|
||||
if (typeSpec == Long::class && !it.endsWith("L")) "${it}L" else it
|
||||
})
|
||||
}
|
@@ -73,7 +73,7 @@ internal object PluginUpdateHelper {
|
||||
* @return [String]
|
||||
*/
|
||||
private fun String.findLatest() = runCatching {
|
||||
if ((contains("<metadata ") || contains("<metadata>")).not() || endsWith("</metadata>").not()) return@runCatching ""
|
||||
if (!(contains("<metadata ") || contains("<metadata>")) || !endsWith("</metadata>")) return@runCatching ""
|
||||
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(InputSource(StringReader(this))).let { document ->
|
||||
document.getElementsByTagName("latest")?.let { if (it.length > 0) it.item(0)?.textContent ?: "" else "" }
|
||||
}
|
||||
|
@@ -103,7 +103,7 @@ internal object PropertiesDeployHelper {
|
||||
internal fun initialize(settings: Settings, configs: ISweetPropertyConfigs) {
|
||||
this.configs = configs
|
||||
checkingConfigsModified(settings)
|
||||
if (configs.isEnable.not()) return
|
||||
if (!configs.isEnable) return
|
||||
generatedAccessors(settings)
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ internal object PropertiesDeployHelper {
|
||||
* @param rootProject 当前根项目
|
||||
*/
|
||||
internal fun resolve(rootProject: Project) {
|
||||
if (configs.isEnable.not()) return
|
||||
if (!configs.isEnable) return
|
||||
resolveAccessors(rootProject)
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ internal object PropertiesDeployHelper {
|
||||
* @param rootProject 当前根项目
|
||||
*/
|
||||
internal fun deploy(rootProject: Project) {
|
||||
if (configs.isEnable.not()) return
|
||||
if (!configs.isEnable) return
|
||||
deployAccessors(rootProject)
|
||||
deploySourcesCode(rootProject)
|
||||
}
|
||||
@@ -153,13 +153,13 @@ internal object PropertiesDeployHelper {
|
||||
allConfigs.add(configs.global.buildScript)
|
||||
}
|
||||
configs.projects.forEach { (name, subConfigs) ->
|
||||
if (subConfigs.buildScript.isEnable.not()) return@forEach
|
||||
if (!subConfigs.buildScript.isEnable) return@forEach
|
||||
allProperties.add(generatedProperties(subConfigs.buildScript, ProjectDescriptor.create(settings, name)))
|
||||
allConfigs.add(subConfigs.buildScript)
|
||||
}
|
||||
if (isConfigsModified.not() &&
|
||||
if (!isConfigsModified &&
|
||||
allProperties == cachedSettingsProperties &&
|
||||
accessorsDir.resolve(accessorsPomData.relativePomPath).isEmpty().not()
|
||||
!accessorsDir.resolve(accessorsPomData.relativePomPath).isEmpty()
|
||||
) return
|
||||
cachedSettingsProperties = allProperties
|
||||
accessorsGenerator.build(allConfigs, allProperties).compile(accessorsPomData, accessorsDir.absolutePath, accessorsGenerator.compileStubFiles)
|
||||
@@ -170,7 +170,7 @@ internal object PropertiesDeployHelper {
|
||||
* @param rootProject 当前根项目
|
||||
*/
|
||||
private fun resolveAccessors(rootProject: Project) {
|
||||
if (accessorsDir.resolve(accessorsPomData.relativePomPath).isEmpty().not())
|
||||
if (!accessorsDir.resolve(accessorsPomData.relativePomPath).isEmpty())
|
||||
rootProject.addDependencyToBuildScript(accessorsDir.absolutePath, accessorsPomData)
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ internal object PropertiesDeployHelper {
|
||||
/** 部署扩展方法 */
|
||||
fun Project.deploy() {
|
||||
val configs = configs.with(this).buildScript
|
||||
if (configs.isEnable.not()) return
|
||||
if (!configs.isEnable) return
|
||||
val className = accessorsGenerator.propertiesClass(configs.name)
|
||||
val accessorsClass = loadBuildScriptClass(className) ?: SError.make(
|
||||
"""
|
||||
@@ -206,9 +206,9 @@ internal object PropertiesDeployHelper {
|
||||
fun Project.generate() {
|
||||
val configs = configs.with(this).sourcesCode
|
||||
val outputDir = file(configs.generateDirPath)
|
||||
if (configs.isEnable.not()) return
|
||||
if (!configs.isEnable) return
|
||||
val properties = generatedProperties(configs, ProjectDescriptor.create(project = this))
|
||||
if (isConfigsModified.not() && properties == cachedProjectProperties[fullName()] && outputDir.isEmpty().not()) {
|
||||
if (!isConfigsModified && properties == cachedProjectProperties[fullName()] && !outputDir.isEmpty()) {
|
||||
if (configs.isEnable) configureSourceSets(project = this)
|
||||
return
|
||||
}; outputDir.apply { if (exists()) deleteRecursively() }
|
||||
|
@@ -52,7 +52,7 @@ internal fun String.parseUnixFileSeparator() = replace("\\", "/")
|
||||
* - 如果文件不存在 - 返回 true
|
||||
* @return [Boolean]
|
||||
*/
|
||||
internal fun File.isEmpty() = exists().not() || isDirectory.not() || listFiles().isNullOrEmpty()
|
||||
internal fun File.isEmpty() = !exists() || !isDirectory || listFiles().isNullOrEmpty()
|
||||
|
||||
/** 删除目录下的空子目录 */
|
||||
internal fun File.deleteEmptyRecursively() {
|
||||
|
@@ -59,7 +59,7 @@ internal object CodeCompiler {
|
||||
if (files.isEmpty()) {
|
||||
if (outputDir.exists()) outputDir.deleteRecursively()
|
||||
return
|
||||
} else outputDir.also { if (it.exists().not()) it.mkdirs() }
|
||||
} else outputDir.also { if (!it.exists()) it.mkdirs() }
|
||||
val outputBuildDir = "$outputDirPath/build".toFile().also { if (it.exists()) it.deleteRecursively(); it.mkdirs() }
|
||||
val outputClassesDir = "${outputBuildDir.absolutePath}/classes".toFile().apply { mkdirs() }
|
||||
val outputSourcesDir = "${outputBuildDir.absolutePath}/sources".toFile().apply { mkdirs() }
|
||||
@@ -99,7 +99,7 @@ internal object CodeCompiler {
|
||||
* @param sourcesDir 编译源码目录
|
||||
*/
|
||||
private fun createJarAndPom(pomData: MavenPomData, outputDir: File, buildDir: File, classesDir: File, sourcesDir: File) {
|
||||
val pomDir = outputDir.resolve(pomData.relativePomPath).also { if (it.exists().not()) it.mkdirs() }
|
||||
val pomDir = outputDir.resolve(pomData.relativePomPath).also { if (!it.exists()) it.mkdirs() }
|
||||
packageToJar(classesDir, pomDir, pomData, isSourcesJar = false)
|
||||
packageToJar(sourcesDir, pomDir, pomData, isSourcesJar = true)
|
||||
writePom(pomDir, pomData)
|
||||
@@ -159,7 +159,7 @@ internal object CodeCompiler {
|
||||
* @throws IllegalStateException 如果编译输出目录不存在
|
||||
*/
|
||||
private fun packageToJar(buildDir: File, outputDir: File, pomData: MavenPomData, isSourcesJar: Boolean) {
|
||||
if (buildDir.exists().not()) SError.make("Jar file output path not found: ${buildDir.absolutePath}")
|
||||
if (!buildDir.exists()) SError.make("Jar file output path not found: ${buildDir.absolutePath}")
|
||||
val jarFile = outputDir.resolve("${pomData.artifactId}-${pomData.version}${if (isSourcesJar) "-sources" else ""}.jar")
|
||||
if (jarFile.exists()) jarFile.delete()
|
||||
ZipFile(jarFile).addFolder(buildDir, ZipParameters().apply { isIncludeRootFolder = false })
|
||||
|
Reference in New Issue
Block a user