build scripts: simplify code which check library licenses

IdeaUltimateProjectStructureTest guaranties that unnamed module libraries in IntelliJ project have only one root.

GitOrigin-RevId: 94c332a8bd5f0ed57e24d0e36fc42e73ee611363
This commit is contained in:
nik
2019-10-03 09:05:01 +00:00
committed by intellij-monorepo-bot
parent 7d2d9e0997
commit 6feb15bf5d
3 changed files with 11 additions and 16 deletions
@@ -16,7 +16,6 @@
package org.jetbrains.intellij.build.impl
import com.google.gson.GsonBuilder
import com.intellij.util.containers.ContainerUtil
import groovy.text.SimpleTemplateEngine
import groovy.transform.CompileStatic
import org.jetbrains.intellij.build.BuildMessages
@@ -60,9 +59,8 @@ class LibraryLicensesListGenerator {
Map<String, String> usedLibraries = [:]
usedModules.each { JpsModule module ->
JpsJavaExtensionService.dependencies(module).includedIn(JpsJavaClasspathKind.PRODUCTION_RUNTIME).getLibraries().each { item ->
getLibraryNames(item).forEach { String name ->
usedLibraries[name] = module.name
}
def libraryName = getLibraryName(item)
usedLibraries[libraryName] = module.name
}
}
@@ -82,12 +80,13 @@ class LibraryLicensesListGenerator {
return licenses
}
static List<String> getLibraryNames(JpsLibrary lib) {
static String getLibraryName(JpsLibrary lib) {
def name = lib.name
if (name.startsWith("#")) {
return ContainerUtil.map(lib.getFiles(JpsOrderRootType.COMPILED), {f->f.getName()})
//unnamed module libraries in IntelliJ project may have only one root
return lib.getFiles(JpsOrderRootType.COMPILED).first().name
}
return Collections.singletonList(name)
return name
}
void generateHtml(String filePath) {
@@ -245,10 +245,7 @@ class MavenArtifactsBuilder {
dependencies << createArtifactDependencyByLibrary(typed.properties.data, scope)
}
else if (!isOptionalDependency(library)) {
List<String> names = LibraryLicensesListGenerator.getLibraryNames(library)
for (n in names) {
buildContext.messages.warning(" module '$module.name' depends on non-maven library $n")
}
buildContext.messages.warning(" module '$module.name' depends on non-maven library ${LibraryLicensesListGenerator.getLibraryName(library)}")
mavenizable = false
}
}
@@ -24,15 +24,14 @@ class LibraryLicensesTester(private val project: JpsProject, private val license
val librariesWithLicenses = licenses.flatMapTo(THashSet()) { it.libraryNames }
for ((jpsLibrary, jpsModule) in libraries) {
for (libName in LibraryLicensesListGenerator.getLibraryNames(jpsLibrary)) {
if (libName !in librariesWithLicenses) {
collector.addError(AssertionFailedError("""
|License isn't specified for '$libName' library (used in module '${jpsModule.name}' in ${jpsModule.contentRootsList.urls})
val libraryName = LibraryLicensesListGenerator.getLibraryName(jpsLibrary)
if (libraryName !in librariesWithLicenses) {
collector.addError(AssertionFailedError("""
|License isn't specified for '$libraryName' library (used in module '${jpsModule.name}' in ${jpsModule.contentRootsList.urls})
|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()))
}
}
}
}