Commit f8ad8593 authored by Ivan Kylchik's avatar Ivan Kylchik Committed by intellij-monorepo-bot
Browse files

Add new target to generate Kotlin IDE maven artifacts

(cherry picked from commit 1e661def5c717d0c9f3d319b29fcda02c2831055)

GitOrigin-RevId: 6026f8211fb362f641f7b1cfb36bb5f5720e9228
parent 6185710a
Showing with 16 additions and 10 deletions
+16 -10
...@@ -32,11 +32,13 @@ import org.jetbrains.jps.model.module.JpsModuleDependency ...@@ -32,11 +32,13 @@ import org.jetbrains.jps.model.module.JpsModuleDependency
@CompileStatic @CompileStatic
class MavenArtifactsBuilder { class MavenArtifactsBuilder {
/** second component of module names which describes a common group rather than a specific framework and therefore should be excluded from artifactId */ /** second component of module names which describes a common group rather than a specific framework and therefore should be excluded from artifactId */
private static final Set<String> COMMON_GROUP_NAMES = ["platform", "vcs", "tools", "clouds"] as Set<String> private static final Set<String> COMMON_GROUP_NAMES = ["platform", "vcs", "tools", "clouds", "gradle", "compiler-plugins"] as Set<String>
private final BuildContext buildContext private final BuildContext buildContext
private final boolean forKotlin
MavenArtifactsBuilder(BuildContext buildContext) { MavenArtifactsBuilder(BuildContext buildContext, boolean forKotlin = false) {
this.buildContext = buildContext this.buildContext = buildContext
this.forKotlin = forKotlin
} }
void generateMavenArtifacts(List<String> namesOfModulesToPublish, String outputDir) { void generateMavenArtifacts(List<String> namesOfModulesToPublish, String outputDir) {
...@@ -124,17 +126,20 @@ class MavenArtifactsBuilder { ...@@ -124,17 +126,20 @@ class MavenArtifactsBuilder {
dependency dependency
} }
static MavenCoordinates generateMavenCoordinates(String moduleName, BuildMessages messages, String version) { static MavenCoordinates generateMavenCoordinates(String moduleName, BuildMessages messages, String version, boolean forKotlin = false) {
def names = moduleName.split("\\.") def names = moduleName.split("\\.")
if (names.size() < 2) { if (names.size() < 2) {
messages.error("Cannot generate Maven artifacts: incorrect module name '${moduleName}'") messages.error("Cannot generate Maven artifacts: incorrect module name '${moduleName}'")
} }
String groupId = "com.jetbrains.${names.take(2).join(".")}" String groupId = forKotlin ? "org.jetbrains.kotlin" : "org.jetbrains.${names.take(2).join(".")}"
def firstMeaningful = names.size() > 2 && COMMON_GROUP_NAMES.contains(names[1]) ? 2 : 1 def firstMeaningful = names.size() > 2 && COMMON_GROUP_NAMES.contains(names[1]) ? 2 : 1
String artifactId = names.drop(firstMeaningful).collectMany { String[] artifactIds = names.drop(firstMeaningful)
splitByCamelHumpsMergingNumbers(it).collect {it.toLowerCase(Locale.US)} if (!forKotlin) {
}.join("-") artifactIds = artifactIds.collectMany {
return new MavenCoordinates(groupId, artifactId, version) splitByCamelHumpsMergingNumbers(it).collect {it.toLowerCase(Locale.US)}
}
}
return new MavenCoordinates(groupId, artifactIds.join("-"), version)
} }
private static List<String> splitByCamelHumpsMergingNumbers(String s) { private static List<String> splitByCamelHumpsMergingNumbers(String s) {
...@@ -203,7 +208,7 @@ class MavenArtifactsBuilder { ...@@ -203,7 +208,7 @@ class MavenArtifactsBuilder {
Set<JpsModule> computationInProgress) { Set<JpsModule> computationInProgress) {
if (results.containsKey(module)) return results[module] if (results.containsKey(module)) return results[module]
if (nonMavenizableModules.contains(module)) return null if (nonMavenizableModules.contains(module)) return null
if (!module.name.startsWith("intellij.")) { if (!forKotlin && !module.name.startsWith("intellij.")) {
buildContext.messages.warning(" module '$module.name' doesn't belong to IntelliJ project so it cannot be published") buildContext.messages.warning(" module '$module.name' doesn't belong to IntelliJ project so it cannot be published")
return null return null
} }
...@@ -219,6 +224,7 @@ class MavenArtifactsBuilder { ...@@ -219,6 +224,7 @@ class MavenArtifactsBuilder {
scopedDependencies(module).each { dependency, scope -> scopedDependencies(module).each { dependency, scope ->
if (dependency instanceof JpsModuleDependency) { if (dependency instanceof JpsModuleDependency) {
def depModule = (dependency as JpsModuleDependency).module def depModule = (dependency as JpsModuleDependency).module
if (forKotlin && depModule.name.startsWith("intellij.")) return
if (computationInProgress.contains(depModule)) { if (computationInProgress.contains(depModule)) {
/* /*
It's forbidden to have compile-time circular dependencies in IntelliJ project, but there are some cycles with runtime scope It's forbidden to have compile-time circular dependencies in IntelliJ project, but there are some cycles with runtime scope
...@@ -255,7 +261,7 @@ class MavenArtifactsBuilder { ...@@ -255,7 +261,7 @@ class MavenArtifactsBuilder {
nonMavenizableModules << module nonMavenizableModules << module
return null return null
} }
def artifactData = new MavenArtifactData(generateMavenCoordinates(module.name, buildContext.messages, buildContext.buildNumber), dependencies) def artifactData = new MavenArtifactData(generateMavenCoordinates(module.name, buildContext.messages, buildContext.buildNumber, forKotlin), dependencies)
results[module] = artifactData results[module] = artifactData
return artifactData return artifactData
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment