Search in sources :

Example 16 with JpsLibrary

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

the class AndroidBuilderTest method test3.

public void test3() throws Exception {
    final MyExecutor executor = new MyExecutor("com.example.simple");
    final JpsModule module = setUpSimpleAndroidStructure(new String[] { "src", "resources" }, executor, null).getFirst();
    module.addSourceRoot(JpsPathUtil.pathToUrl(getProjectPath("tests")), JavaSourceRootType.TEST_SOURCE);
    final JpsLibrary lib1 = module.addModuleLibrary("lib1", JpsJavaLibraryType.INSTANCE);
    lib1.addRoot(getProjectPath("external_jar1.jar"), JpsOrderRootType.COMPILED);
    final JpsLibrary lib2 = module.addModuleLibrary("lib2", JpsJavaLibraryType.INSTANCE);
    lib2.addRoot(new File(getProjectPath("libs/external_jar2.jar")), JpsOrderRootType.COMPILED);
    module.getDependenciesList().addLibraryDependency(lib1);
    rebuildAll();
    checkBuildLog(executor, "expected_log");
    assertOutput(module, TestFileSystemItem.fs().file("java_resource1.txt").dir("com").dir("example").file("java_resource3.txt").dir("simple").file("BuildConfig.class").file("R.class").file("MyActivity.class").end().end().end().archive("module.apk").file("resource_inside_jar1.txt").file("java_resource1.txt").dir("com").dir("example").file("java_resource3.txt").end().end().file("META-INF").file("res_apk_entry", "res_apk_entry_content").file("classes.dex", "classes_dex_content"));
    checkMakeUpToDate(executor);
    module.getDependenciesList().addLibraryDependency(lib2);
    executor.clear();
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_1");
    assertOutput(module, TestFileSystemItem.fs().file("java_resource1.txt").file("com").archive("module.apk").file("resource_inside_jar2.txt").file("java_resource1.txt").file("com").file("META-INF").file("res_apk_entry", "res_apk_entry_content").file("classes.dex", "classes_dex_content"));
    checkMakeUpToDate(executor);
    change(getProjectPath("resources/com/example/java_resource3.txt"));
    executor.clear();
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_2");
    assertOutput(module, TestFileSystemItem.fs().file("java_resource1.txt").file("com").archive("module.apk").file("resource_inside_jar2.txt").file("java_resource1.txt").file("com").file("META-INF").file("res_apk_entry", "res_apk_entry_content").file("classes.dex", "classes_dex_content"));
    checkMakeUpToDate(executor);
    assertTrue(FileUtil.delete(new File(getProjectPath("external_jar1.jar"))));
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_3");
    assertOutput(module, TestFileSystemItem.fs().file("java_resource1.txt").file("com").archive("module.apk").file("resource_inside_jar1.txt").file("resource_inside_jar2.txt").file("java_resource1.txt").file("com").file("META-INF").file("res_apk_entry", "res_apk_entry_content").file("classes.dex", "classes_dex_content"));
    checkMakeUpToDate(executor);
    assertTrue(FileUtil.delete(new File(getProjectPath("src/java_resource1.txt"))));
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_4");
    assertOutput(module, TestFileSystemItem.fs().file("com").archive("module.apk").file("resource_inside_jar1.txt").file("resource_inside_jar2.txt").file("com").file("META-INF").file("res_apk_entry", "res_apk_entry_content").file("classes.dex", "classes_dex_content"));
    checkMakeUpToDate(executor);
    module.removeSourceRoot(JpsPathUtil.pathToUrl(getProjectPath("resources")), JavaSourceRootType.SOURCE);
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_5");
    checkMakeUpToDate(executor);
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary)

Example 17 with JpsLibrary

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

the class AndroidBuilderTest method test7.

public void test7() throws Exception {
    final boolean[] class1Deleted = { false };
    final MyExecutor executor = new MyExecutor("com.example.simple") {

        @Override
        protected void doCheckJar(@NotNull String jarId, @NotNull String jarPath) {
            if ("library_package_jar".equals(jarId)) {
                File tmpDir = null;
                try {
                    tmpDir = FileUtil.createTempDirectory("library_package_jar_checking", "tmp");
                    final File jar = new File(tmpDir, "file.jar");
                    FileUtil.copy(new File(jarPath), jar);
                    TestFileSystemBuilder fs = TestFileSystemItem.fs().archive("file.jar").dir("lib").file("MyLibClass.class");
                    if (!class1Deleted[0]) {
                        fs = fs.file("MyLibClass1.class");
                    }
                    assertOutput(tmpDir.getPath(), fs);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } finally {
                    if (tmpDir != null) {
                        FileUtil.delete(tmpDir);
                    }
                }
            }
        }
    };
    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", new String[] { "src" }, "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;
    rebuildAll();
    checkBuildLog(executor, "expected_log");
    assertEquals(Collections.singleton("library_package_jar"), executor.getCheckedJars());
    checkMakeUpToDate(executor);
    appModule.getDependenciesList().addModuleDependency(libModule);
    makeAll();
    checkBuildLog(executor, "expected_log_1");
    assertTrue(executor.getCheckedJars().isEmpty());
    checkMakeUpToDate(executor);
    change(getProjectPath("lib/src/lib/MyLibClass.java"));
    makeAll();
    checkBuildLog(executor, "expected_log_2");
    assertEquals(Collections.singleton("library_package_jar"), executor.getCheckedJars());
    checkMakeUpToDate(executor);
    assertTrue(FileUtil.delete(new File(getProjectPath("lib/src/lib/MyLibClass1.java"))));
    class1Deleted[0] = true;
    makeAll();
    checkBuildLog(executor, "expected_log_2");
    assertEquals(Collections.singleton("library_package_jar"), executor.getCheckedJars());
    checkMakeUpToDate(executor);
    assertTrue(FileUtil.delete(new File(getProjectPath("lib/src/lib/MyLibClass.java"))));
    makeAll();
    checkBuildLog(executor, "expected_log_3");
    assertTrue(executor.getCheckedJars().isEmpty());
    checkMakeUpToDate(executor);
    final JpsLibrary appLib = appModule.addModuleLibrary("appLib", JpsJavaLibraryType.INSTANCE);
    appLib.addRoot(getProjectPath("lib/external_jar.jar"), JpsOrderRootType.COMPILED);
    appModule.getDependenciesList().addLibraryDependency(appLib);
    final JpsLibrary libLib = libModule.addModuleLibrary("libLib", JpsJavaLibraryType.INSTANCE);
    libLib.addRoot(new File(getProjectPath("lib/external_jar.jar")), JpsOrderRootType.COMPILED);
    libModule.getDependenciesList().addLibraryDependency(libLib);
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_4");
    assertTrue(executor.getCheckedJars().isEmpty());
    checkMakeUpToDate(executor);
}
Also used : TestFileSystemBuilder(com.intellij.util.io.TestFileSystemBuilder) JpsSimpleElement(org.jetbrains.jps.model.JpsSimpleElement) JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties) NotNull(org.jetbrains.annotations.NotNull) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsAndroidModuleExtensionImpl(org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary)

Example 18 with JpsLibrary

use of org.jetbrains.jps.model.library.JpsLibrary in project intellij-elixir by KronicDeth.

the class Builder method erlangSdkNameToErlExePath.

@NotNull
private static String erlangSdkNameToErlExePath(@NotNull String erlangSdkName, @NotNull JpsModule module) throws LibraryNotFound, FileNotFoundException, AccessDeniedException {
    JpsLibraryCollection libraryCollection = module.getProject().getModel().getGlobal().getLibraryCollection();
    JpsLibrary erlangSdkLibrary = libraryCollection.findLibrary(erlangSdkName);
    String erlExePath;
    if (erlangSdkLibrary != null) {
        erlExePath = erlangSdkLibraryToErlExePath(erlangSdkLibrary);
    } else {
        throw new LibraryNotFound(erlangSdkName);
    }
    return erlExePath;
}
Also used : JpsLibraryCollection(org.jetbrains.jps.model.library.JpsLibraryCollection) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with JpsLibrary

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

the class AndroidAarDepsBuildTarget method doComputeRootDescriptors.

@NotNull
@Override
protected List<BuildRootDescriptor> doComputeRootDescriptors(JpsModel model, ModuleExcludeIndex index, IgnoredFileIndex ignoredFileIndex, BuildDataPaths dataPaths) {
    final Set<JpsLibrary> libraries = JpsJavaExtensionService.getInstance().enumerateDependencies(Collections.singleton(myModule)).runtimeOnly().productionOnly().getLibraries();
    final List<BuildRootDescriptor> result = new ArrayList<BuildRootDescriptor>();
    for (JpsLibrary library : libraries) {
        final Pair<File, List<File>> pair = AndroidJpsUtil.getResDirAndJarsIfAar(library);
        final List<File> jars = pair != null ? pair.getSecond() : null;
        if (jars != null) {
            for (File jar : jars) {
                result.add(new BuildRootDescriptorImpl(this, jar));
            }
        }
    }
    return result;
}
Also used : BuildRootDescriptorImpl(org.jetbrains.jps.builders.impl.BuildRootDescriptorImpl) BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with JpsLibrary

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

the class AndroidDexBuilder method getJavaExecutable.

@Nullable
private static String getJavaExecutable(@NotNull AndroidPlatform platform, @NotNull CompileContext context, @NotNull String builderName) {
    final JpsSdk<JpsSimpleElement<JpsAndroidSdkProperties>> sdk = platform.getSdk();
    final String jdkName = sdk.getSdkProperties().getData().getJdkName();
    final JpsLibrary javaSdk = context.getProjectDescriptor().getModel().getGlobal().getLibraryCollection().findLibrary(jdkName);
    if (javaSdk == null || !javaSdk.getType().equals(JpsJavaSdkType.INSTANCE)) {
        context.processMessage(new CompilerMessage(builderName, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.java.sdk.not.specified", jdkName)));
        return null;
    }
    return JpsJavaSdkType.getJavaExecutable((JpsSdk<?>) javaSdk.getProperties());
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) JpsSimpleElement(org.jetbrains.jps.model.JpsSimpleElement) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JpsLibrary (org.jetbrains.jps.model.library.JpsLibrary)41 JpsModule (org.jetbrains.jps.model.module.JpsModule)11 File (java.io.File)10 Element (org.jdom.Element)8 NotNull (org.jetbrains.annotations.NotNull)7 JpsSimpleElement (org.jetbrains.jps.model.JpsSimpleElement)7 JpsLibraryRoot (org.jetbrains.jps.model.library.JpsLibraryRoot)6 JpsAndroidModuleExtensionImpl (org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl)5 JpsAndroidModuleProperties (org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties)5 JpsElement (org.jetbrains.jps.model.JpsElement)5 JpsDummyElement (org.jetbrains.jps.model.JpsDummyElement)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Nullable (org.jetbrains.annotations.Nullable)3 JpsDependencyElement (org.jetbrains.jps.model.module.JpsDependencyElement)3 JpsLibraryDependency (org.jetbrains.jps.model.module.JpsLibraryDependency)3 Logger (com.intellij.openapi.diagnostic.Logger)2 SystemInfo (com.intellij.openapi.util.SystemInfo)2 JpsElementFactory (org.jetbrains.jps.model.JpsElementFactory)2 JpsSdkReference (org.jetbrains.jps.model.library.sdk.JpsSdkReference)2