All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jetbrains.plugin.structure.ide.layout.PluginFactory.kt Maven / Gradle / Ivy

There is a newer version: 3.289
Show newest version
package com.jetbrains.plugin.structure.ide.layout

import com.jetbrains.plugin.structure.base.utils.simpleName
import com.jetbrains.plugin.structure.ide.getCommonParentDirectory
import com.jetbrains.plugin.structure.intellij.platform.BundledModulesManager
import com.jetbrains.plugin.structure.intellij.platform.LayoutComponent.Plugin
import com.jetbrains.plugin.structure.intellij.resources.ResourceResolver
import com.jetbrains.plugin.structure.intellij.version.IdeVersion
import com.jetbrains.plugin.structure.jar.PLUGIN_XML
import java.nio.file.Path

internal class PluginFactory(private val pluginLoader: LayoutComponentLoader) : LayoutComponentFactory {
  override fun read(
    layoutComponent: Plugin,
    idePath: Path,
    ideVersion: IdeVersion,
    resourceResolver: ResourceResolver,
    moduleManager: BundledModulesManager
  ): PluginWithArtifactPathResult? {

    return getRelativePluginDirectory(layoutComponent)
      ?.let { idePath.resolve(it) }
      ?.let { pluginLoader.load(pluginArtifactPath = it, PLUGIN_XML, resourceResolver, ideVersion) }
  }

  private fun getRelativePluginDirectory(pluginComponent: Plugin): Path? {
    val commonParent = getCommonParentDirectory(pluginComponent.getClasspath()) ?: return null
    return if (commonParent.simpleName == "lib") commonParent.parent else commonParent
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy