package jetbrains.mps.build.mps.util; /*Generated by MPS */ import jetbrains.mps.generator.template.TemplateQueryContext; import org.jetbrains.mps.openapi.model.SNode; import jetbrains.mps.util.containers.ConcurrentHashSet; import jetbrains.mps.build.util.GenerationUtil; import java.util.List; import jetbrains.mps.internal.collections.runtime.ListSequence; import java.util.ArrayList; import jetbrains.mps.internal.collections.runtime.Sequence; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations; import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory; import org.jetbrains.mps.openapi.language.SAbstractConcept; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations; import jetbrains.mps.internal.collections.runtime.IWhereFilter; import jetbrains.mps.build.mps.behavior.BuildMps_IdeaPluginContent__BehaviorDescriptor; import jetbrains.mps.build.util.DependenciesHelper; import jetbrains.mps.internal.collections.runtime.ISelector; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations; import jetbrains.mps.build.behavior.BuildLayout_PathElement__BehaviorDescriptor; public class ModulePlugins { private static final String KEY = "modulePluginDependency"; private final TemplateQueryContext myContext; private final SNode myInitialProject; private final ConcurrentHashSet<SNode> myDependency; public ModulePlugins(SNode initialProject, TemplateQueryContext context) { myContext = context; myInitialProject = initialProject; myDependency = GenerationUtil.<SNode>getSessionSet(initialProject, context, ModulePlugins.KEY); } public void collect(MPSModulesClosure closure) { List<SNode> initialPlugins = ListSequence.fromList(new ArrayList<SNode>()); for (final SNode module : Sequence.fromIterable(closure.getAllModules())) { List<SNode> projectPlugins = SNodeOperations.getNodeDescendants(SNodeOperations.cast(SNodeOperations.getContainingRoot(module), MetaAdapterFactory.getConcept(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x4df58c6f18f84a13L, "jetbrains.mps.build.structure.BuildProject")), MetaAdapterFactory.getConcept(0xcf935df46994e9cL, 0xa132fa109541cba3L, 0x5b7be37b4de9bb74L, "jetbrains.mps.build.mps.structure.BuildMps_IdeaPlugin"), false, new SAbstractConcept[]{}); for (SNode plugin : ListSequence.fromList(projectPlugins)) { if (ListSequence.fromList(SLinkOperations.getChildren(plugin, MetaAdapterFactory.getContainmentLink(0xcf935df46994e9cL, 0xa132fa109541cba3L, 0x5b7be37b4de9bb74L, 0x5b7be37b4de9bbeaL, "content"))).findFirst(new IWhereFilter<SNode>() { public boolean accept(SNode it) { return (boolean) BuildMps_IdeaPluginContent__BehaviorDescriptor.exports_id5FtnUVJQES1.invoke(it, module); } }) != null) { ListSequence.fromList(initialPlugins).addElement(plugin); break; } } } myDependency.addAll(initialPlugins); RequiredPlugins requiredPlugins = new RequiredPlugins(myContext, myInitialProject, initialPlugins); for (SNode plugin : Sequence.fromIterable(requiredPlugins.returnDependencies())) { myDependency.add(plugin); } } public Iterable<SNode> getDependency() { // XXX here, usage suggests return value may list elements from transient (non-original) model return myDependency; } public String[] getPluginPaths() { final DependenciesHelper helper = new DependenciesHelper(myContext, myInitialProject); return Sequence.fromIterable(this.getDependency()).select(new ISelector<SNode, String>() { public String select(SNode it) { SNode layoutNode = helper.getArtifact(it); if ((layoutNode == null)) { myContext.showWarningMessage(myInitialProject, "The plugin '" + SPropertyOperations.getString(it, MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name")) + "' was not found in the layout of `" + SPropertyOperations.getString(myInitialProject, MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name")) + "'"); return null; } String val = BuildLayout_PathElement__BehaviorDescriptor.location_id6b4RkXS8sT2.invoke(layoutNode, helper, it); if (val == null) { myContext.showWarningMessage(myInitialProject, "Found no location for plugin '" + SPropertyOperations.getString(it, MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name")) + "'"); return null; } return val; } }).where(new IWhereFilter<String>() { public boolean accept(String it) { return (it != null && it.length() > 0); } }).sort(new ISelector<String, String>() { public String select(String it) { return it; } }, true).toGenericArray(String.class); } }