diff --git a/.idea/modules.xml b/.idea/modules.xml index 1611ac98d111..683af7c30b71 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -216,6 +216,7 @@ + diff --git a/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/LibraryLicensesListGenerator.groovy b/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/LibraryLicensesListGenerator.groovy index ab7a30737233..cb858df90afc 100644 --- a/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/LibraryLicensesListGenerator.groovy +++ b/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/LibraryLicensesListGenerator.groovy @@ -39,13 +39,9 @@ class LibraryLicensesListGenerator { this.licensesList = licensesList } - private String getLibraryName(JpsLibrary lib) { + static String getLibraryName(JpsLibrary lib) { def name = lib.name if (name.startsWith("#")) { - if (lib.getRoots(JpsOrderRootType.COMPILED).size() != 1) { - def urls = lib.getRoots(JpsOrderRootType.COMPILED).collect { it.url } - messages.warning("Non-single entry module library $name: $urls"); - } File file = lib.getFiles(JpsOrderRootType.COMPILED)[0] return file.name } @@ -107,38 +103,5 @@ class LibraryLicensesListGenerator { out.close() } } - - void checkLibLicenses() { - def libraries = new HashSet() - def lib2Module = new HashMap(); - Set nonPublicModules = ["buildScripts", "build", "buildSrc", "testGuiFramework"] as Set - project.modules.findAll { !nonPublicModules.contains(it.name) && !it.name.contains("guitests") }.each { JpsModule module -> - JpsJavaExtensionService.dependencies(module).includedIn(JpsJavaClasspathKind.PRODUCTION_RUNTIME).getLibraries().each { - lib2Module[it] = module - libraries << it - } - } - - def libWithLicenses = licensesList.collectMany { it.libraryNames } as Set - - List withoutLicenses = [] - libraries.each { JpsLibrary lib -> - def name = getLibraryName(lib) - if (!libWithLicenses.contains(name)) { - withoutLicenses << "$name (used in module ${lib2Module[lib].name})".toString() - } - } - - if (!withoutLicenses.isEmpty()) { - def errorMessage = [] - errorMessage << "Licenses aren't specified for ${withoutLicenses.size()} libraries:" - withoutLicenses.sort(true, String.CASE_INSENSITIVE_ORDER) - withoutLicenses.each { errorMessage << it } - errorMessage << "If a library is packaged into IDEA installation information about its license must be added into one of *LibraryLicenses.groovy files" - errorMessage << "If a library is used in tests only change its scope to 'Test'" - errorMessage << "If a library is used for compilation only change its scope to 'Provided'" - messages.error(errorMessage.join("\n")) - } - } } diff --git a/platform/build-scripts/testFramework/buildScripts-testFramework.iml b/platform/build-scripts/testFramework/buildScripts-testFramework.iml new file mode 100644 index 000000000000..f00c74744740 --- /dev/null +++ b/platform/build-scripts/testFramework/buildScripts-testFramework.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/platform/build-scripts/testFramework/src/org/jetbrains/intellij/build/LibraryLicensesTester.kt b/platform/build-scripts/testFramework/src/org/jetbrains/intellij/build/LibraryLicensesTester.kt new file mode 100644 index 000000000000..f87f5fe3426b --- /dev/null +++ b/platform/build-scripts/testFramework/src/org/jetbrains/intellij/build/LibraryLicensesTester.kt @@ -0,0 +1,38 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ +package org.jetbrains.intellij.build + +import junit.framework.AssertionFailedError +import org.jetbrains.intellij.build.impl.LibraryLicensesListGenerator +import org.jetbrains.jps.model.JpsProject +import org.jetbrains.jps.model.java.JpsJavaClasspathKind +import org.jetbrains.jps.model.java.JpsJavaExtensionService +import org.jetbrains.jps.model.library.JpsLibrary +import org.jetbrains.jps.model.module.JpsModule +import org.junit.rules.ErrorCollector + +class LibraryLicensesTester(private val project: JpsProject, private val licenses: List) { + fun reportMissingLicenses(collector: ErrorCollector) { + val nonPublicModules = setOf("buildScripts", "build", "buildSrc", "testGuiFramework") + val libraries = HashMap() + project.modules.filter { it.name !in nonPublicModules && !it.name.contains("guitests") }.forEach { module -> + JpsJavaExtensionService.dependencies(module).includedIn(JpsJavaClasspathKind.PRODUCTION_RUNTIME).libraries.forEach { + libraries[it] = module + } + } + + val librariesWithLicenses = licenses.flatMapTo(HashSet()) { it.libraryNames } + libraries.entries.forEach { + val libName = LibraryLicensesListGenerator.getLibraryName(it.key) + if (libName !in librariesWithLicenses) { + collector.addError(AssertionFailedError(""" + |License isn't specified for '$libName' library (used in module '${it.value.name}') + |If a library is packaged into IDEA installation information about its license must be added into one of *LibraryLicenses.groovy files + |If a library is used in tests only change its scope to 'Test' + |If a library is used for compilation only change its scope to 'Provided' +""".trimMargin())) + } + } + } +} \ No newline at end of file