Search in sources :

Example 1 with JpsSimpleElement

use of org.jetbrains.jps.model.JpsSimpleElement in project intellij-community by JetBrains.

the class DependencyResolvingBuilder method getRepositoryLibraries.

@NotNull
private static Collection<JpsTypedLibrary<JpsSimpleElement<RepositoryLibraryDescriptor>>> getRepositoryLibraries(ModuleChunk chunk) {
    final Collection<JpsTypedLibrary<JpsSimpleElement<RepositoryLibraryDescriptor>>> result = new SmartHashSet<>();
    for (JpsModule module : chunk.getModules()) {
        for (JpsDependencyElement dep : module.getDependenciesList().getDependencies()) {
            if (dep instanceof JpsLibraryDependency) {
                final JpsLibrary _lib = ((JpsLibraryDependency) dep).getLibrary();
                final JpsTypedLibrary<JpsSimpleElement<RepositoryLibraryDescriptor>> lib = _lib != null ? _lib.asTyped(JpsMavenRepositoryLibraryType.INSTANCE) : null;
                if (lib != null) {
                    result.add(lib);
                }
            }
        }
    }
    return result;
}
Also used : JpsLibraryDependency(org.jetbrains.jps.model.module.JpsLibraryDependency) SmartHashSet(com.intellij.util.containers.SmartHashSet) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsTypedLibrary(org.jetbrains.jps.model.library.JpsTypedLibrary) JpsDependencyElement(org.jetbrains.jps.model.module.JpsDependencyElement) RepositoryLibraryDescriptor(org.jetbrains.jps.maven.model.RepositoryLibraryDescriptor) JpsSimpleElement(org.jetbrains.jps.model.JpsSimpleElement) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with JpsSimpleElement

use of org.jetbrains.jps.model.JpsSimpleElement 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 3 with JpsSimpleElement

use of org.jetbrains.jps.model.JpsSimpleElement in project intellij-community by JetBrains.

the class JpsPluginProjectSerializationTest method testLoadProject.

public void testLoadProject() {
    loadProject("plugins/devkit/jps-plugin/testData/pluginProject/pluginProject.ipr");
    JpsModule module = assertOneElement(myProject.getModules());
    assertEquals(JpsPluginModuleType.INSTANCE, module.getModuleType());
    JpsTypedModule<JpsSimpleElement<JpsPluginModuleProperties>> pluginModule = module.asTyped(JpsPluginModuleType.INSTANCE);
    assertNotNull(pluginModule);
    String url = pluginModule.getProperties().getData().getPluginXmlUrl();
    assertEquals(getUrl("META-INF/plugin.xml"), url);
    JpsTypedLibrary<JpsSdk<JpsDummyElement>> javaSdk = myModel.getGlobal().addSdk("1.6", null, null, JpsJavaSdkType.INSTANCE);
    JpsSimpleElement<JpsIdeaSdkProperties> properties = JpsElementFactory.getInstance().createSimpleElement(new JpsIdeaSdkProperties(null, "1.6"));
    JpsTypedLibrary<JpsSdk<JpsSimpleElement<JpsIdeaSdkProperties>>> pluginSdk = myModel.getGlobal().addSdk("IDEA plugin SDK", null, null, JpsIdeaSdkType.INSTANCE, properties);
    assertSame(pluginSdk.getProperties(), module.getSdk(JpsIdeaSdkType.INSTANCE));
    assertSame(javaSdk.getProperties(), module.getSdk(JpsJavaSdkType.INSTANCE));
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsSimpleElement(org.jetbrains.jps.model.JpsSimpleElement) JpsSdk(org.jetbrains.jps.model.library.sdk.JpsSdk)

Example 4 with JpsSimpleElement

use of org.jetbrains.jps.model.JpsSimpleElement in project android by JetBrains.

the class AndroidJpsUtil method getAndroidPlatform.

@Nullable
public static AndroidPlatform getAndroidPlatform(@NotNull JpsModule module, @Nullable CompileContext context, String builderName) {
    final JpsSdk<JpsSimpleElement<JpsAndroidSdkProperties>> sdk = module.getSdk(JpsAndroidSdkType.INSTANCE);
    if (sdk == null) {
        if (context != null) {
            context.processMessage(new CompilerMessage(builderName, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.sdk.not.specified", module.getName())));
        }
        return null;
    }
    final Pair<IAndroidTarget, AndroidSdkHandler> pair = getAndroidTarget(sdk, context, builderName);
    if (pair == null) {
        if (context != null) {
            context.processMessage(new CompilerMessage(builderName, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.sdk.invalid", module.getName())));
        }
        return null;
    }
    return new AndroidPlatform(sdk, pair.getFirst(), pair.getSecond());
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) JpsSimpleElement(org.jetbrains.jps.model.JpsSimpleElement) IAndroidTarget(com.android.sdklib.IAndroidTarget) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with JpsSimpleElement

use of org.jetbrains.jps.model.JpsSimpleElement in project android by JetBrains.

the class AndroidBuilderTest method testManifestMerging.

public void testManifestMerging() throws Exception {
    final MyExecutor executor = new MyExecutor("com.example.simple");
    final JpsSdk<JpsSimpleElement<JpsAndroidSdkProperties>> androidSdk = addJdkAndAndroidSdk();
    addPathPatterns(executor, androidSdk);
    final JpsModule appModule = addAndroidModule("app", new String[] { "src" }, "app", "app", androidSdk).getFirst();
    final JpsModule libModule = addAndroidModule("lib", ArrayUtil.EMPTY_STRING_ARRAY, "lib", "lib", androidSdk).getFirst();
    final JpsAndroidModuleExtension libExtension = AndroidJpsUtil.getExtension(libModule);
    assert libExtension != null;
    final JpsAndroidModuleProperties libProps = ((JpsAndroidModuleExtensionImpl) libExtension).getProperties();
    libProps.PROJECT_TYPE = PROJECT_TYPE_LIBRARY;
    appModule.getDependenciesList().addModuleDependency(libModule);
    final JpsAndroidModuleExtension appExtension = AndroidJpsUtil.getExtension(appModule);
    assert appExtension != null;
    final JpsAndroidModuleProperties appProps = ((JpsAndroidModuleExtensionImpl) appExtension).getProperties();
    appProps.ENABLE_MANIFEST_MERGING = true;
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log");
    checkMakeUpToDate(executor);
    appProps.ENABLE_MANIFEST_MERGING = false;
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_1");
    checkMakeUpToDate(executor);
    appProps.ENABLE_MANIFEST_MERGING = true;
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_2");
    checkMakeUpToDate(executor);
    change(getProjectPath("app/AndroidManifest.xml"));
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_3");
    checkMakeUpToDate(executor);
    change(getProjectPath("lib/AndroidManifest.xml"));
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_4");
    checkMakeUpToDate(executor);
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsAndroidModuleExtensionImpl(org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl) JpsSimpleElement(org.jetbrains.jps.model.JpsSimpleElement) JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties)

Aggregations

JpsSimpleElement (org.jetbrains.jps.model.JpsSimpleElement)14 JpsModule (org.jetbrains.jps.model.module.JpsModule)10 JpsAndroidModuleExtensionImpl (org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl)7 JpsAndroidModuleProperties (org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties)7 JpsLibrary (org.jetbrains.jps.model.library.JpsLibrary)7 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 File (java.io.File)2 Element (org.jdom.Element)2 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)2 RepositoryLibraryDescriptor (org.jetbrains.jps.maven.model.RepositoryLibraryDescriptor)2 JpsTypedLibrary (org.jetbrains.jps.model.library.JpsTypedLibrary)2 IAndroidTarget (com.android.sdklib.IAndroidTarget)1 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)1 SmartHashSet (com.intellij.util.containers.SmartHashSet)1 TestFileSystemBuilder (com.intellij.util.io.TestFileSystemBuilder)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 JDOMException (org.jdom.JDOMException)1 ArtifactRepositoryManager (org.jetbrains.idea.maven.aether.ArtifactRepositoryManager)1