Search in sources :

Example 1 with JpsCompositePackagingElement

use of org.jetbrains.jps.model.artifact.elements.JpsCompositePackagingElement in project intellij-community by JetBrains.

the class JpsPluginSyntheticArtifactProvider method createArtifact.

private static JpsArtifact createArtifact(JpsModule module, JpsPluginModuleProperties properties) {
    JpsPackagingElementFactory factory = JpsPackagingElementFactory.getInstance();
    JpsCompositePackagingElement root = factory.createArtifactRoot();
    String pluginXmlUrl = properties.getPluginXmlUrl();
    if (pluginXmlUrl != null) {
        String pluginXmlPath = JpsPathUtil.urlToPath(pluginXmlUrl);
        JpsCompositePackagingElement metaInfDir = factory.getOrCreateDirectory(root, "META-INF");
        metaInfDir.addChild(factory.createFileCopy(pluginXmlPath, null));
        File pluginXmlFile = JpsPathUtil.urlToFile(pluginXmlUrl);
        if (pluginXmlFile.exists()) {
            try {
                Element rootElement = JDOMUtil.load(pluginXmlFile);
                for (Element dependsElement : JDOMUtil.getChildren(rootElement, "depends")) {
                    String relativePath = dependsElement.getAttributeValue("config-file");
                    if (relativePath != null) {
                        File dependencyFile = new File(pluginXmlFile.getParent(), FileUtil.toSystemDependentName(relativePath));
                        String dependencyPath = FileUtil.toSystemIndependentName(dependencyFile.getAbsolutePath());
                        metaInfDir.addChild(factory.createFileCopy(dependencyPath, null));
                    }
                }
            } catch (JDOMException | IOException e) {
                LOG.info(e);
            }
        }
    }
    JpsJavaDependenciesEnumerator enumerator = JpsJavaExtensionService.dependencies(module).recursively().includedIn(JpsJavaClasspathKind.PRODUCTION_RUNTIME);
    JpsCompositePackagingElement classesDir = factory.getOrCreateDirectory(root, "classes");
    for (JpsModule depModule : enumerator.getModules()) {
        if (depModule.getModuleType().equals(JpsJavaModuleType.INSTANCE)) {
            classesDir.addChild(JpsJavaExtensionService.getInstance().createProductionModuleOutput(depModule.createReference()));
        }
    }
    classesDir.addChild(JpsJavaExtensionService.getInstance().createProductionModuleOutput(module.createReference()));
    for (JpsLibrary library : enumerator.getLibraries()) {
        JpsCompositePackagingElement parent;
        if (hasDirsOnly(library)) {
            parent = classesDir;
        } else {
            parent = factory.getOrCreateDirectory(root, "lib");
        }
        parent.addChild(factory.createLibraryElement(library.createReference()));
    }
    String name = module.getName() + ":plugin";
    JpsArtifact artifact = JpsArtifactService.getInstance().createArtifact(name, root, DirectoryArtifactType.INSTANCE, JpsElementFactory.getInstance().createDummyElement());
    JpsSdk<JpsSimpleElement<JpsIdeaSdkProperties>> sdk = module.getSdk(JpsIdeaSdkType.INSTANCE);
    if (sdk != null) {
        String sandboxHome = sdk.getSdkProperties().getData().getSandboxHome();
        if (sandboxHome != null) {
            artifact.setOutputPath(sandboxHome + "/plugins/" + module.getName());
        }
    }
    return artifact;
}
Also used : JpsCompositePackagingElement(org.jetbrains.jps.model.artifact.elements.JpsCompositePackagingElement) JpsSimpleElement(org.jetbrains.jps.model.JpsSimpleElement) Element(org.jdom.Element) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) JpsSimpleElement(org.jetbrains.jps.model.JpsSimpleElement) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsPackagingElementFactory(org.jetbrains.jps.model.artifact.elements.JpsPackagingElementFactory) File(java.io.File) JpsJavaDependenciesEnumerator(org.jetbrains.jps.model.java.JpsJavaDependenciesEnumerator) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) JpsCompositePackagingElement(org.jetbrains.jps.model.artifact.elements.JpsCompositePackagingElement)

Example 2 with JpsCompositePackagingElement

use of org.jetbrains.jps.model.artifact.elements.JpsCompositePackagingElement in project intellij-community by JetBrains.

the class RebuildArtifactOnConfigurationChangeTest method testAddRootChangingRootIndices.

public void testAddRootChangingRootIndices() {
    String file1 = createFile("d1/a/b/1.txt");
    String file2 = createFile("d2/x/y/2.txt");
    JpsArtifact a = addArtifact(root().fileCopy(file1).fileCopy(file2));
    buildAll();
    assertOutput(a, fs().file("1.txt").file("2.txt"));
    JpsCompositePackagingElement root = a.getRootElement();
    assertEquals(2, root.getChildren().size());
    JpsPackagingElement last = root.getChildren().get(1);
    root.removeChild(last);
    String file3 = createFile("d3/1/2/3.txt");
    root.addChild(JpsPackagingElementFactory.getInstance().createFileCopy(file3, null));
    root.addChild(last);
    buildAll();
    assertOutput(a, fs().file("1.txt").file("2.txt").file("3.txt"));
}
Also used : JpsPackagingElement(org.jetbrains.jps.model.artifact.elements.JpsPackagingElement) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) JpsCompositePackagingElement(org.jetbrains.jps.model.artifact.elements.JpsCompositePackagingElement)

Example 3 with JpsCompositePackagingElement

use of org.jetbrains.jps.model.artifact.elements.JpsCompositePackagingElement in project intellij-community by JetBrains.

the class JpsArtifactOutputPackagingElementImpl method getSubstitution.

@Override
public List<JpsPackagingElement> getSubstitution() {
    JpsArtifact artifact = getArtifactReference().resolve();
    if (artifact == null)
        return Collections.emptyList();
    JpsCompositePackagingElement rootElement = artifact.getRootElement();
    if (rootElement instanceof JpsArtifactRootElement) {
        return new ArrayList<>(rootElement.getChildren());
    } else {
        return Collections.<JpsPackagingElement>singletonList(rootElement);
    }
}
Also used : JpsPackagingElement(org.jetbrains.jps.model.artifact.elements.JpsPackagingElement) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) ArrayList(java.util.ArrayList) JpsArtifactRootElement(org.jetbrains.jps.model.artifact.elements.JpsArtifactRootElement) JpsCompositePackagingElement(org.jetbrains.jps.model.artifact.elements.JpsCompositePackagingElement)

Aggregations

JpsArtifact (org.jetbrains.jps.model.artifact.JpsArtifact)3 JpsCompositePackagingElement (org.jetbrains.jps.model.artifact.elements.JpsCompositePackagingElement)3 JpsPackagingElement (org.jetbrains.jps.model.artifact.elements.JpsPackagingElement)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Element (org.jdom.Element)1 JDOMException (org.jdom.JDOMException)1 JpsSimpleElement (org.jetbrains.jps.model.JpsSimpleElement)1 JpsArtifactRootElement (org.jetbrains.jps.model.artifact.elements.JpsArtifactRootElement)1 JpsPackagingElementFactory (org.jetbrains.jps.model.artifact.elements.JpsPackagingElementFactory)1 JpsJavaDependenciesEnumerator (org.jetbrains.jps.model.java.JpsJavaDependenciesEnumerator)1 JpsLibrary (org.jetbrains.jps.model.library.JpsLibrary)1 JpsModule (org.jetbrains.jps.model.module.JpsModule)1