Skip to content

Commit

Permalink
added PackagingMethod.PluginModule for plugin model v2 #SCL-21681
Browse files Browse the repository at this point in the history
  • Loading branch information
SrTobi committed Sep 30, 2024
1 parent 6fcf6e4 commit c0dbf2e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@ packageMethod := PackagingMethod.Standalone()
// specify in which project to merge into
packageMethod := PackagingMethod.MergeIntoParent()

// This packages all projects that are marked with the same moduleName into
// a module jar under lib/modules/<moduleName>.jar
// Modules are a new mechanism in intellij to better configure dependencies
// between plugins and builtin modules.
packageMethod := PackagingMethod.PluginModule("moduleName")

// merge all dependencies of this project in a standalone jar
// being used together with assembleLibraries setting allows sbt-assembly like packaging
// the project may contain classes but they will be ignored during packaging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ object PackagingMethod {
final case class DepsOnly(targetPath: String = "") extends PackagingMethod
final case class MergeIntoOther(project: Project) extends PackagingMethod
final case class Standalone(targetPath: String = "", static: Boolean = false) extends PackagingMethod
final case class PluginModule(moduleName: String, static: Boolean = false) extends PackagingMethod
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class LinearMappingsBuilder(override val outputDir: File, log: PluginLogger) ext
case PackagingMethod.Standalone(targetPath, isStatic) =>
val target = outputDir / targetPath
addProductDirs(node, target, isStatic)
case PackagingMethod.PluginModule(moduleName, isStatic) =>
val target = outputDir / mkPluginModulePath(moduleName)
addProductDirs(node, target, isStatic)
case PackagingMethod.Skip() => throw new MappingBuildException("Unreachable")
}
}
Expand All @@ -63,6 +66,8 @@ class LinearMappingsBuilder(override val outputDir: File, log: PluginLogger) ext
def collectCandidate(nodes: Seq[PackagedProjectNode]): PackagedProjectNode = {
if (nodes.isEmpty)
throw new MappingBuildException(s"No standalone-packaged parents found for $node")

// note that we do not package into parent with PackagingMethod.PluginModule. For this explicilty use PluginModule
val candidates = nodes.filter(_.packagingOptions.packageMethod.isInstanceOf[PackagingMethod.Standalone]).distinct
if (candidates.size > 1)
throw new MappingBuildException(s"Multiple direct parents package into standalone jar ($node) (use MergeIntoOther): $candidates")
Expand Down Expand Up @@ -148,9 +153,12 @@ class LinearMappingsBuilder(override val outputDir: File, log: PluginLogger) ext
mkProjectJarDefaultPath(node)
case PackagingMethod.Standalone(nonEmptyPath, _) =>
nonEmptyPath
case PackagingMethod.PluginModule(moduleName, _) =>
mkPluginModulePath(moduleName)
}

private def mkProjectJarDefaultPath(node: ProjectNode): String = s"lib/${node.name}.jar"
private def mkPluginModulePath(moduleName: String): String = s"lib/modules/$moduleName.jar"

private def fixPaths(str: String): String = System.getProperty("os.name") match {
case os if os.startsWith("Windows") => str.replace('/', '\\')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ sealed trait PackagingMethod
object PackagingMethod {
final case class Skip() extends PackagingMethod
final case class MergeIntoParent() extends PackagingMethod
final case class DepsOnly(targetPath: String = "") extends PackagingMethod
final case class DepsOnly(targetPath: String) extends PackagingMethod
final case class MergeIntoOther(project: PackagedProjectNode) extends PackagingMethod
final case class Standalone(targetPath: String = "", static: Boolean = false) extends PackagingMethod
final case class Standalone(targetPath: String, static: Boolean) extends PackagingMethod
final case class PluginModule(moduleName: String, static: Boolean) extends PackagingMethod
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,7 @@ class SbtPackagingStructureExtractor(override val rootProject: ProjectRef,
structure.PackagingMethod.Standalone(targetPath, static)
case packaging.PackagingMethod.MergeIntoOther(project) =>
structure.PackagingMethod.MergeIntoOther(findProjectRef(project).map(projectCache).getOrElse(???))
case packaging.PackagingMethod.PluginModule(moduleName, static) =>
structure.PackagingMethod.PluginModule(moduleName, static)
}
}

0 comments on commit c0dbf2e

Please sign in to comment.