mirror of
https://github.com/HighCapable/SweetDependency.git
synced 2025-09-04 01:35:46 +08:00
refactor: replace not to !
This commit is contained in:
@@ -4,7 +4,7 @@ project.description=An easy autowire and manage dependencies Gradle plugin.
|
||||
project.url=https://github.com/HighCapable/SweetDependency
|
||||
project.groupName=com.highcapable.sweetdependency
|
||||
project.moduleName=sweet-dependency
|
||||
project.version=1.0.2
|
||||
project.version=1.0.2-debug
|
||||
project.licence.name=Apache License 2.0
|
||||
project.licence.url=https://github.com/HighCapable/SweetDependency/blob/master/LICENSE
|
||||
project.developer.id="0"
|
||||
|
@@ -267,7 +267,7 @@ internal data class RepositoryDocument(
|
||||
}; nodeName = name
|
||||
if (url.isNotBlank() && path.isNotBlank()) SError.make("There can only be one \"url\" and \"path\" parameter of \"$name\"")
|
||||
if (path.isNotBlank() && (path.startsWith("https://") || path.startsWith("http://"))) SError.make("Invalid repository path: $path")
|
||||
if (url.isNotBlank() && url.startsWith("https://").not() && url.startsWith("http://").not()) SError.make("Invalid repository URL: $url")
|
||||
if (url.isNotBlank() && !url.startsWith("https://") && !url.startsWith("http://")) SError.make("Invalid repository URL: $url")
|
||||
if (path.isNotBlank()) path = path.parseUnixFileSeparator()
|
||||
}
|
||||
}
|
@@ -170,7 +170,7 @@ internal data class RootConfigDocument(
|
||||
artifact.alias.checkingName("$typeName \"$dependencyName\" alias", isCheckMultiName = true)
|
||||
artifact.versions().forEach { (name, _) -> name.checkingName("$typeName \"$dependencyName\" version alias") }
|
||||
if (artifact.alias.isNotBlank())
|
||||
if (checkDuplicateAlias.contains(artifact.alias).not())
|
||||
if (!checkDuplicateAlias.contains(artifact.alias))
|
||||
checkDuplicateAlias[artifact.alias] = dependencyName.current
|
||||
else SError.make(
|
||||
"Duplicated alias \"${artifact.alias}\", " +
|
||||
@@ -230,7 +230,7 @@ internal data class RootConfigDocument(
|
||||
if (artifact.versionRef.isNotBlank())
|
||||
versions()[artifact.versionRef]?.also { artifact.version = it } ?: resolveVersionRef()
|
||||
else SError.make("Missing declared version when configuring $typeName \"$dependencyName\"")
|
||||
else if (artifact.version().isBlank.not() && artifact.versionRef.isNotBlank() && duplicate.not())
|
||||
else if (!artifact.version().isBlank && artifact.versionRef.isNotBlank() && !duplicate)
|
||||
SError.make("$firstTypeName \"$dependencyName\" can only have one \"version\" or \"version-ref\" node, please delete one")
|
||||
}
|
||||
currentDependencies.eachDependencies { dependencyName, artifact ->
|
||||
|
@@ -64,7 +64,7 @@ internal data class VersionFilterDocument(
|
||||
* 当前是否不存在排除列表
|
||||
* @return [Boolean]
|
||||
*/
|
||||
internal fun isNotEmpty() = isEmpty().not()
|
||||
internal fun isNotEmpty() = !isEmpty()
|
||||
|
||||
/**
|
||||
* 依赖于当前 [version] 提供的版本并在 [all] 中排除 (不区分大小写)
|
||||
@@ -74,7 +74,7 @@ internal data class VersionFilterDocument(
|
||||
* @return [ExclusionList]
|
||||
*/
|
||||
internal fun depends(version: DependencyVersion) = clone().apply {
|
||||
if (version.isAutowire.not() && version.isBlank.not()) all().removeAll { version.deployed.lowercase().contains(it.lowercase()) }
|
||||
if (!version.isAutowire && !version.isBlank) all().removeAll { version.deployed.lowercase().contains(it.lowercase()) }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -158,12 +158,12 @@ internal class RootConfigDocumentMapping internal constructor(private val config
|
||||
}
|
||||
}
|
||||
pluginsContents.onEachIndexed { index, content ->
|
||||
if ((content.trim().startsWith(VERSION_NODE_CONTENT) && content.startsWith(SPACE_OF_4)).not()) return@onEachIndexed
|
||||
if (!(content.trim().startsWith(VERSION_NODE_CONTENT) && content.startsWith(SPACE_OF_4))) return@onEachIndexed
|
||||
pluginsMapping[pluginsLine].versionLine = index + pluginsStartLine
|
||||
pluginsLine++
|
||||
}.clear()
|
||||
librariesContents.onEachIndexed { index, content ->
|
||||
if ((content.trim().startsWith(VERSION_NODE_CONTENT) && content.startsWith(SPACE_OF_6)).not()) return@onEachIndexed
|
||||
if (!(content.trim().startsWith(VERSION_NODE_CONTENT) && content.startsWith(SPACE_OF_6))) return@onEachIndexed
|
||||
librariesMapping[librariesLine].versionLine = index + librariesStartLine
|
||||
librariesLine++
|
||||
}.clear()
|
||||
|
@@ -42,13 +42,13 @@ internal object Environment {
|
||||
* 获取 [SweetDependency] 缓存存放目录
|
||||
* @return [File]
|
||||
*/
|
||||
private val memoryDir get() = "${GradleHelper.rootDir.absolutePath}/$MEMORY_DIR_PATH".toFile().also { if (it.exists().not()) it.mkdirs() }
|
||||
private val memoryDir get() = "${GradleHelper.rootDir.absolutePath}/$MEMORY_DIR_PATH".toFile().also { if (!it.exists()) it.mkdirs() }
|
||||
|
||||
/**
|
||||
* 获取 [SweetDependency] 功能存放目录
|
||||
* @return [File]
|
||||
*/
|
||||
private val resourcesDir get() = "${GradleHelper.rootDir.absolutePath}/$RESOURCES_DIR_PATH".toFile().also { if (it.exists().not()) it.mkdirs() }
|
||||
private val resourcesDir get() = "${GradleHelper.rootDir.absolutePath}/$RESOURCES_DIR_PATH".toFile().also { if (!it.exists()) it.mkdirs() }
|
||||
|
||||
/**
|
||||
* 获取系统信息
|
||||
|
@@ -51,7 +51,7 @@ internal open class ExternalDependencyDelegate internal constructor(
|
||||
|
||||
override fun getVersion(): String {
|
||||
val notation = spliceToDependencyNotation(groupId, artifactId)
|
||||
if (version == DependencyVersion.AUTOWIRE_VERSION_NAME && GradleTaskManager.isInternalRunningTask.not()) SError.make(
|
||||
if (version == DependencyVersion.AUTOWIRE_VERSION_NAME && !GradleTaskManager.isInternalRunningTask) SError.make(
|
||||
"""
|
||||
This library "$notation" is not autowired and cannot be deployed
|
||||
You can try the following solutions to resolve this problem:
|
||||
|
@@ -54,7 +54,7 @@ internal class DependencyVersion(internal var actual: String, optionalType: Opti
|
||||
if (current.startsWith("<") && current.endsWith(">"))
|
||||
if (current != NO_SPECIFIC_VERSION_NAME && current != LATEST_VERSION_NAME)
|
||||
SError.make("The parameter \"$current\" is not recognized as any available function")
|
||||
if (isOptional.not()) when (optionalType) {
|
||||
if (!isOptional) when (optionalType) {
|
||||
OptionalUpdateType.NONE -> {}
|
||||
OptionalUpdateType.NORMAL -> actual = "$OPTIONAL_VERSION_NORMAL_PREFIX$actual"
|
||||
OptionalUpdateType.PERMANENT -> actual = "$OPTIONAL_VERSION_PERMANENT_PREFIX$actual"
|
||||
@@ -102,7 +102,7 @@ internal class DependencyVersion(internal var actual: String, optionalType: Opti
|
||||
* 如果为 [isNoSpecific] 则会返回空
|
||||
* @return [String]
|
||||
*/
|
||||
internal val deployed get() = current.takeIf { isNoSpecific.not() } ?: ""
|
||||
internal val deployed get() = current.takeIf { !isNoSpecific } ?: ""
|
||||
|
||||
/**
|
||||
* 获取存在版本
|
||||
|
@@ -38,7 +38,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\"")
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,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\"")
|
||||
}
|
||||
}
|
||||
|
@@ -64,7 +64,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) }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,7 +115,7 @@ internal fun Project.libraries(isUseCache: Boolean = true) =
|
||||
* @return [Boolean]
|
||||
*/
|
||||
fun Dependency.checkingValid() = when (this) {
|
||||
is ExternalDependency -> group.isNullOrBlank().not() && name.isNullOrBlank().not()
|
||||
is ExternalDependency -> !group.isNullOrBlank() && !name.isNullOrBlank()
|
||||
is FileCollectionDependency -> runCatching { files.files.isNotEmpty() }.getOrNull() ?: false
|
||||
else -> true
|
||||
}
|
||||
@@ -186,5 +186,5 @@ internal fun PluginDependenciesSpec.applyPlugin(alias: Any) = when (alias) {
|
||||
private fun PluginManager.findPluginId(plugin: Plugin<*>) = runCatching {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val pluginIds = (this as PluginManagerInternal).findPluginIdForClass(GeneratedSubclasses.unpackType(plugin) as Class<Plugin<*>>)
|
||||
if (pluginIds.isEmpty.not()) pluginIds.get() else null
|
||||
if (!pluginIds.isEmpty) pluginIds.get() else null
|
||||
}.getOrNull()?.id ?: ""
|
@@ -97,7 +97,7 @@ internal object DependencyManager {
|
||||
* @param isGroovyOnly 是否仅为 Groovy 创建 - 默认是
|
||||
*/
|
||||
fun Project.deployAutowire(extension: ExtensionAware, isGroovyOnly: Boolean = true) {
|
||||
if (isGroovyOnly.not() || (isGroovyOnly && buildFile.name.endsWith(".gradle")))
|
||||
if (!isGroovyOnly || buildFile.name.endsWith(".gradle"))
|
||||
extension.getOrCreate<SweetDependencyAutowireExtension>(SweetDependencyAutowireExtension.NAME, this)
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ internal object DependencyManager {
|
||||
var updLbrariesCount = 0
|
||||
val needUpdateDependencies = mutableMapOf<String, Pair<DependencyName, DependencyVersion>>()
|
||||
findByType { _, artifact ->
|
||||
artifact.version().isNoSpecific.not() && (artifact.versionRef.isBlank() &&
|
||||
!artifact.version().isNoSpecific && (artifact.versionRef.isBlank() &&
|
||||
((updateMode.updateType == DependencyUpdateMode.UpdateType.UPDATE_ALL ||
|
||||
(updateMode.updateType == DependencyUpdateMode.UpdateType.UPDATE_OPTIONAL &&
|
||||
(artifact.version().isOptional || artifact.version().isAutowire)) ||
|
||||
@@ -213,7 +213,7 @@ internal object DependencyManager {
|
||||
if (SweetDependencyConfigs.configs.isEnableDependenciesAutowireLog)
|
||||
logIfNeeded(msg = "Autowiring logs have been automatically written to: ${DependencyAutowireLogHelper.logFile}", SLog.LINK)
|
||||
SweetDependencyConfigs.documentMapping.updateDependencies(needUpdateDependencies)
|
||||
if (isRunningOnSync.not()) SLog.warn(
|
||||
if (!isRunningOnSync) SLog.warn(
|
||||
"""
|
||||
**************************** NOTICE ****************************
|
||||
${needUpdateDependencies.size} dependencies (plugins: $updPluginsCount, libraries: $updLbrariesCount) has been changed
|
||||
@@ -316,9 +316,9 @@ internal object DependencyManager {
|
||||
isAutoUpdate: Boolean,
|
||||
result: (newVersion: DependencyVersion) -> Unit
|
||||
) = when {
|
||||
currentVersion.isAutowire.not() && versions.contains(currentVersion).not() ->
|
||||
!currentVersion.isAutowire && !versions.contains(currentVersion) ->
|
||||
SLog.warn("$positionTagName > MISSING ${dependencyName.description} version $currentVersion, available are $versions")
|
||||
currentVersion.isAutowire.not() && alternateVersions.isNotEmpty() && alternateVersions.all { versions.contains(it) }.not() ->
|
||||
!currentVersion.isAutowire && alternateVersions.isNotEmpty() && !alternateVersions.all { versions.contains(it) } ->
|
||||
SLog.warn("$positionTagName > MISSING ${dependencyName.description} version alias $alternateVersions, available are $versions")
|
||||
latestVersion != currentVersion -> when {
|
||||
currentVersion.isAutowire -> {
|
||||
|
@@ -90,7 +90,7 @@ internal object RepositoryManager {
|
||||
document.nodeName.noBlank()?.also { docName -> this.name = docName }
|
||||
if (this is AuthenticationSupported && document.credentials.let { it.username.isNotBlank() || it.password.isNotBlank() })
|
||||
credentials { this.username = document.credentials.username; this.password = document.credentials.password }
|
||||
if (document.content.isEmpty().not()) content {
|
||||
if (!document.content.isEmpty()) content {
|
||||
/**
|
||||
* 使用 ":" 分割字符串
|
||||
* @param size 期望的个数
|
||||
|
@@ -85,7 +85,7 @@ internal object Dependencies {
|
||||
* 当前是否不存在依赖
|
||||
* @return [Boolean]
|
||||
*/
|
||||
internal fun isNotEmpty() = isEmpty().not()
|
||||
internal fun isNotEmpty() = !isEmpty()
|
||||
|
||||
/**
|
||||
* 查找是否存在指定的依赖
|
||||
|
@@ -59,7 +59,7 @@ internal object Repositories {
|
||||
* 当前是否不存在存储库
|
||||
* @return [Boolean]
|
||||
*/
|
||||
internal fun isNotEmpty() = isEmpty().not()
|
||||
internal fun isNotEmpty() = !isEmpty()
|
||||
|
||||
/**
|
||||
* 生成存储库数组
|
||||
|
@@ -50,7 +50,7 @@ internal object DependencyAutowireLogHelper {
|
||||
* @param toVersion 最终版本
|
||||
*/
|
||||
internal fun record(dependencyName: DependencyName, fromVersion: DependencyVersion, toVersion: DependencyVersion) {
|
||||
if (SweetDependencyConfigs.configs.isEnableDependenciesAutowireLog.not()) return
|
||||
if (!SweetDependencyConfigs.configs.isEnableDependenciesAutowireLog) return
|
||||
val versionInfo = if (fromVersion.isAutowire)
|
||||
"autowire version \"$toVersion\""
|
||||
else "update version \"$fromVersion\" -> \"$toVersion\""
|
||||
|
@@ -141,7 +141,7 @@ internal object DependencyDeployHelper {
|
||||
*/
|
||||
internal fun resolveAccessors(rootProject: Project) {
|
||||
val librariesOption = SweetDependencyConfigs.document.preferences().dependenciesNamespace.libraries
|
||||
if (librariesOption.isEnable.not()) {
|
||||
if (!librariesOption.isEnable) {
|
||||
accessorsPomData.relativePomPath.toFile().takeIf { it.exists() }?.deleteRecursively()
|
||||
accessorsGenerator.clearGeneratedData()
|
||||
return
|
||||
@@ -198,7 +198,7 @@ internal object DependencyDeployHelper {
|
||||
*/
|
||||
internal fun resolveAutowire(project: Project = ProjectTransaction.current, params: Array<out String>): Any {
|
||||
if (params.isEmpty()) SError.make("The autowire function need a param to resolve library")
|
||||
return if (params[0].let { it.contains("/").not() && it.contains("\\").not() && it.startsWith("(").not() && it.endsWith(")").not() }) {
|
||||
return if (params[0].let { !it.contains("/") && !it.contains("\\") && !it.startsWith("(") && !it.endsWith(")") }) {
|
||||
if (params.size > 2) SError.make("The autowire function currently does not support more than 2 params of external dependency")
|
||||
val entry = Dependencies.findLibraries { key, value -> params[0] == key.current || params[0] == value.alias }.single()
|
||||
?: SError.make("Failed to resolve library \"${params[0]}\", also tried alias")
|
||||
@@ -210,7 +210,7 @@ internal object DependencyDeployHelper {
|
||||
params.forEach { param ->
|
||||
val relativePath = if (param.startsWith("(") && param.endsWith(")")) param.replace("(", "").replace(")", "") else param
|
||||
it.addAll(relativePath.toAbsoluteFilePaths(project.projectDir.absolutePath).onEach { path ->
|
||||
if (path.toFile().isValidZip().not()) SError.make(
|
||||
if (!path.toFile().isValidZip()) SError.make(
|
||||
"""
|
||||
Invalid library at file path $path
|
||||
The file collection dependency needs to be a valid zip package
|
||||
|
@@ -70,7 +70,7 @@ internal object MavenParser {
|
||||
* @return [MavenMetadata]
|
||||
*/
|
||||
private fun String.toMetadata(currentVersion: DependencyVersion) = runCatching {
|
||||
if ((contains("<metadata ") || contains("<metadata>")).not() || endsWith("</metadata>").not()) return@runCatching MavenMetadata()
|
||||
if (!(contains("<metadata ") || contains("<metadata>")) || !endsWith("</metadata>")) return@runCatching MavenMetadata()
|
||||
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(InputSource(StringReader(this))).let { document ->
|
||||
val lastUpdated = document.getElementsByTagName("lastUpdated").item(0)?.textContent?.toLongOrNull() ?: 0L
|
||||
val versionNodeList = document.getElementsByTagName("version")
|
||||
|
@@ -42,7 +42,7 @@ internal fun ISweetDependencyConfigs.build() = configFilePath.loadOrCreateEmpty(
|
||||
*/
|
||||
private fun String.loadOrCreateEmpty(): RootConfigDocument {
|
||||
toFile().apply {
|
||||
if (name.endsWith(".yaml").not() && name.endsWith(".yml").not())
|
||||
if (!name.endsWith(".yaml") && !name.endsWith(".yml"))
|
||||
SError.make("Config file name must be end with \".yaml\" or \".yml\"")
|
||||
}.createTemplateFileOrNot()
|
||||
return Yaml.loadFromFile<RootConfigDocument>(path = this)
|
||||
@@ -56,11 +56,11 @@ private fun File.createTemplateFileOrNot() {
|
||||
}
|
||||
runCatching {
|
||||
when {
|
||||
exists().not() && parentFile.exists().not() -> {
|
||||
!exists() && !parentFile.exists() -> {
|
||||
parentFile.mkdirs()
|
||||
createTemplateFile()
|
||||
}
|
||||
exists().not() -> createTemplateFile()
|
||||
!exists() -> createTemplateFile()
|
||||
exists() && isDirectory -> SError.make("Tries to create file path is a directory")
|
||||
}
|
||||
}.onFailure { SError.make("Could not automatically created config file: $absolutePath", it) }
|
||||
|
@@ -100,7 +100,7 @@ internal class LibrariesAccessorsGenerator {
|
||||
*/
|
||||
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)
|
||||
}
|
||||
|
||||
|
@@ -70,7 +70,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 "" }
|
||||
}
|
||||
|
@@ -63,7 +63,7 @@ internal class SweetDependencyExtensionImpl : BaseExtensionImpl() {
|
||||
""".trimIndent(), noTag = true
|
||||
)
|
||||
}
|
||||
if (GradleHelper.version.let { it.startsWith("7.") || it.startsWith("8.") }.not()) SError.make(
|
||||
if (GradleHelper.version.let { it.startsWith("7.") || !it.startsWith("8.") }) SError.make(
|
||||
"${SweetDependency.TAG} ${SweetDependency.VERSION} " +
|
||||
"does not support Gradle ${GradleHelper.version}, please update Gradle or plugin version"
|
||||
)
|
||||
@@ -91,7 +91,7 @@ internal class SweetDependencyExtensionImpl : BaseExtensionImpl() {
|
||||
*/
|
||||
private fun configureProject(configs: ISweetDependencyConfigs) {
|
||||
SLog.isVerboseMode = configs.isEnableVerboseMode
|
||||
if (isPluginLoaded.not() || GradleHelper.isSyncMode.not()) SLog.verbose(SweetDependency.bannerContent, noTag = true)
|
||||
if (!isPluginLoaded || !GradleHelper.isSyncMode) SLog.verbose(SweetDependency.bannerContent, noTag = true)
|
||||
if (isPluginLoaded) return
|
||||
isPluginLoaded = true
|
||||
SLog.verbose("Welcome to ${SweetDependency.TAG} ${SweetDependency.VERSION}! Using Gradle ${GradleHelper.version}")
|
||||
|
@@ -56,7 +56,7 @@ internal fun String.parseUnixFileSeparator() = replace("\\", "/")
|
||||
*/
|
||||
internal fun String.toRelativeFilePath(basePath: String, rootPath: String = "") =
|
||||
parseFileSeparator().runCatching {
|
||||
if (rootPath.isNotBlank() && contains(rootPath).not()) return this
|
||||
if (rootPath.isNotBlank() && !contains(rootPath)) return this
|
||||
return Paths.get(basePath).relativize(Paths.get(this)).toString()
|
||||
}.getOrNull() ?: parseFileSeparator()
|
||||
|
||||
@@ -107,8 +107,8 @@ internal fun String.toAbsoluteFilePaths(basePath: String) =
|
||||
* @return [Boolean]
|
||||
*/
|
||||
internal fun File.isValidZip(): Boolean {
|
||||
if (isFile.not()) return true
|
||||
if (exists().not()) return false
|
||||
if (!isFile) return true
|
||||
if (!exists()) return false
|
||||
return runCatching { ZipFile(this).use {}; true }.getOrNull() ?: false
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ internal fun File.isValidZip(): Boolean {
|
||||
* - 如果文件不存在 - 返回 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() {
|
||||
|
@@ -60,7 +60,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() }
|
||||
@@ -100,7 +100,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)
|
||||
@@ -160,7 +160,7 @@ internal object CodeCompiler {
|
||||
* @throws SweetDependencyUnresolvedException 如果编译输出目录不存在
|
||||
*/
|
||||
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