From 45ec0e364af3377c3f93cd1179bbe9e5bf4191db Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Tue, 1 Aug 2017 16:34:10 +0300 Subject: [PATCH] Remove Gradle plugin dependency on Apache Commons We have used `commons-lang` to detect if current OS is a Windows. `org.apache.commons.lang.SystemUtils` also tries to parse JDK version in `clinit` and, as of AC version 2.4, fails on JDK 9. I preferred to remove the dependency completely and copy an implementation of `isWindows` from Intellij platform, because the code is quite simple and minimizing unnecessary dependencies will help to avoid compatibility problems in future. Gradle plugin also declares a dependency on `commons-io`, but it seems unused, so the dependency is also removed. #KT-18832 fixed --- .../tools/kotlin-gradle-plugin/build.gradle | 3 --- .../plugin/KotlinGradleBuildServices.kt | 4 ++-- .../kotlin/gradle/utils/systemUtils.kt | 23 +++++++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/utils/systemUtils.kt diff --git a/libraries/tools/kotlin-gradle-plugin/build.gradle b/libraries/tools/kotlin-gradle-plugin/build.gradle index 400ca62519f..fe713be446f 100644 --- a/libraries/tools/kotlin-gradle-plugin/build.gradle +++ b/libraries/tools/kotlin-gradle-plugin/build.gradle @@ -35,9 +35,6 @@ dependencies { compile "org.jetbrains.kotlin:kotlin-compiler-runner:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-annotation-processing:$kotlin_version" - compile 'commons-io:commons-io:2.4' - compile 'commons-lang:commons-lang:2.4' - compileOnly 'com.android.tools.build:gradle:2.0.0' compileOnly 'org.codehaus.groovy:groovy-all:2.3.9' compileOnly 'org.jetbrains.kotlin:gradle-api:2.2' diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinGradleBuildServices.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinGradleBuildServices.kt index d1171f89556..1b73053e74b 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinGradleBuildServices.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinGradleBuildServices.kt @@ -16,7 +16,6 @@ package org.jetbrains.kotlin.gradle.plugin -import org.apache.commons.lang.SystemUtils import org.gradle.BuildAdapter import org.gradle.BuildResult import org.gradle.api.invocation.Gradle @@ -27,6 +26,7 @@ import org.jetbrains.kotlin.com.intellij.openapi.vfs.impl.jar.CoreJarFileSystem import org.jetbrains.kotlin.compilerRunner.DELETED_SESSION_FILE_PREFIX import org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile +import org.jetbrains.kotlin.gradle.utils.isWindows import org.jetbrains.kotlin.incremental.BuildCacheStorage import org.jetbrains.kotlin.incremental.multiproject.ArtifactDifferenceRegistryProvider import org.jetbrains.kotlin.incremental.relativeToRoot @@ -190,7 +190,7 @@ internal class CompilerServicesCleanup() { // clearing jar cache to avoid problems like KT-9440 (unable to clean/rebuild a project due to locked jar file) // problem is known to happen only on windows - the reason (seems) related to http://bugs.java.com/view_bug.do?bug_id=6357433 // clean cache only when running on windows - if (SystemUtils.IS_OS_WINDOWS) { + if (isWindows) { cleanJarCache() } diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/utils/systemUtils.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/utils/systemUtils.kt new file mode 100644 index 00000000000..01dfef71c74 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/utils/systemUtils.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.gradle.utils + +import java.util.* + +// Based on org.jetbrains.kotlin.com.intellij.openapi.util.SystemInfoRt from Intellij platform +internal val isWindows: Boolean = + System.getProperty("os.name")?.toLowerCase(Locale.US)?.startsWith("windows") ?: false