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

The newest version!
package com.jetbrains.plugin.structure.ide.layout

import com.jetbrains.plugin.structure.base.problems.MissedFile
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.plugin.PluginFileNotFoundException
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? {
    val relativePluginDir = getRelativePluginDirectory(layoutComponent) ?: return null
    val pluginDir = idePath.resolve(relativePluginDir)
    return try {
      pluginLoader.load(pluginArtifactPath = pluginDir, PLUGIN_XML, resourceResolver, ideVersion)
    } catch (e: PluginFileNotFoundException) {
      PluginWithArtifactPathResult.Failure(pluginDir, layoutComponent.name, MissedFile(pluginDir.toString()))
    }
  }

  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