Search in sources :

Example 6 with JpsSimpleElement

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

the class AndroidBuilderTest method test5.

public void test5() 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;
    rebuildAll();
    checkBuildLog(executor, "expected_log");
    checkMakeUpToDate(executor);
    appModule.getDependenciesList().addModuleDependency(libModule);
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_1");
    checkMakeUpToDate(executor);
    final JpsAndroidModuleExtension appExtension = AndroidJpsUtil.getExtension(appModule);
    assert appExtension != null;
    final JpsAndroidModuleProperties appProps = ((JpsAndroidModuleExtensionImpl) appExtension).getProperties();
    appProps.myIncludeAssetsFromLibraries = true;
    makeAll();
    checkBuildLog(executor, "expected_log_2");
    checkMakeUpToDate(executor);
    rebuildAll();
    checkBuildLog(executor, "expected_log_7");
    checkMakeUpToDate(executor);
    change(getProjectPath("lib/assets/lib_asset.txt"));
    makeAll();
    checkBuildLog(executor, "expected_log_3");
    checkMakeUpToDate(executor);
    change(getProjectPath("app/assets/app_asset.txt"));
    makeAll();
    checkBuildLog(executor, "expected_log_3");
    checkMakeUpToDate(executor);
    change(getProjectPath("lib/res/values/strings.xml"));
    makeAll();
    checkBuildLog(executor, "expected_log_4");
    checkMakeUpToDate(executor);
    change(getProjectPath("app/res/values/strings.xml"));
    makeAll();
    checkBuildLog(executor, "expected_log_5");
    checkMakeUpToDate(executor);
    assertTrue(FileUtil.delete(new File(getProjectPath("lib/assets"))));
    makeAll();
    checkBuildLog(executor, "expected_log_6");
    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)

Example 7 with JpsSimpleElement

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

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

the class DependencyResolvingBuilder method checkDependencies.

private static void checkDependencies(CompileContext context, ModuleChunk chunk) throws Exception {
    final Collection<JpsTypedLibrary<JpsSimpleElement<RepositoryLibraryDescriptor>>> libs = getRepositoryLibraries(chunk);
    if (!libs.isEmpty()) {
        final ArtifactRepositoryManager repoManager = getRepositoryManager(context);
        for (JpsTypedLibrary<JpsSimpleElement<RepositoryLibraryDescriptor>> lib : libs) {
            final RepositoryLibraryDescriptor descriptor = lib.getProperties().getData();
            final ResourceGuard guard = ResourceGuard.get(context, descriptor);
            if (guard.requestProcessing(context.getCancelStatus())) {
                try {
                    final Collection<File> required = lib.getFiles(JpsOrderRootType.COMPILED);
                    for (Iterator<File> it = required.iterator(); it.hasNext(); ) {
                        if (it.next().exists()) {
                            // leaving only non-existing stuff requiring synchronization
                            it.remove();
                        }
                    }
                    if (!required.isEmpty()) {
                        final Collection<File> resolved = repoManager.resolveDependency(descriptor.getGroupId(), descriptor.getArtifactId(), descriptor.getVersion());
                        if (!resolved.isEmpty()) {
                            syncPaths(required, resolved);
                        } else {
                            LOG.info("No artifacts were resolved for repository dependency " + descriptor.getMavenId());
                        }
                    }
                } finally {
                    guard.finish();
                }
            }
        }
    }
}
Also used : JpsTypedLibrary(org.jetbrains.jps.model.library.JpsTypedLibrary) ArtifactRepositoryManager(org.jetbrains.idea.maven.aether.ArtifactRepositoryManager) RepositoryLibraryDescriptor(org.jetbrains.jps.maven.model.RepositoryLibraryDescriptor) JpsSimpleElement(org.jetbrains.jps.model.JpsSimpleElement) File(java.io.File)

Example 10 with JpsSimpleElement

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

the class AndroidBuilderTest method testMaven.

public void testMaven() throws Exception {
    createMavenConfigFile();
    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("lib2", new String[] { "src" }, "lib", "lib2", androidSdk).getFirst();
    final JpsModule libModule1 = addAndroidModule("lib1", new String[] { "src" }, "lib1", "lib1", androidSdk).getFirst();
    JpsMavenExtensionService.getInstance().getOrCreateExtension(appModule);
    final MavenProjectConfiguration mavenConf = ((JpsMavenExtensionServiceImpl) JpsMavenExtensionService.getInstance()).getMavenProjectConfiguration(myDataStorageRoot);
    addMavenResourcesConf(mavenConf, "app");
    addMavenResourcesConf(mavenConf, "lib2");
    addMavenResourcesConf(mavenConf, "lib1");
    final JpsAndroidModuleExtension libExtension = AndroidJpsUtil.getExtension(libModule);
    assert libExtension != null;
    final JpsAndroidModuleProperties libProps = ((JpsAndroidModuleExtensionImpl) libExtension).getProperties();
    libProps.PROJECT_TYPE = PROJECT_TYPE_LIBRARY;
    final JpsAndroidModuleExtension libExtension1 = AndroidJpsUtil.getExtension(libModule1);
    assert libExtension1 != null;
    final JpsAndroidModuleProperties libProps1 = ((JpsAndroidModuleExtensionImpl) libExtension1).getProperties();
    libProps1.PROJECT_TYPE = PROJECT_TYPE_LIBRARY;
    appModule.getDependenciesList().addModuleDependency(libModule);
    libModule.getDependenciesList().addModuleDependency(libModule1);
    rebuildAll();
    checkBuildLog(executor, "expected_log");
    assertOutput(appModule, TestFileSystemItem.fs().file("com").archive("app.apk").dir("lib").file("lib_resource.txt").end().dir("com").file("app_resource.txt").end().file("META-INF").file("res_apk_entry", "res_apk_entry_content").file("classes.dex", "classes_dex_content"));
    checkMakeUpToDate(executor);
    JpsMavenExtensionService.getInstance().getOrCreateExtension(libModule);
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_1");
    checkMakeUpToDate(executor);
    final JpsModule nonMavenAppModule = addAndroidModule("non_maven_app", new String[] { "src" }, "app", "non_maven_app", androidSdk).getFirst();
    nonMavenAppModule.getDependenciesList().addModuleDependency(libModule);
    final JpsModule libModule2 = addAndroidModule("lib3", new String[] { "src" }, "lib1", "lib3", androidSdk).getFirst();
    final JpsAndroidModuleExtension libExtension2 = AndroidJpsUtil.getExtension(libModule2);
    assert libExtension2 != null;
    final JpsAndroidModuleProperties libProps2 = ((JpsAndroidModuleExtensionImpl) libExtension2).getProperties();
    libProps2.PROJECT_TYPE = PROJECT_TYPE_LIBRARY;
    libModule1.getDependenciesList().addModuleDependency(libModule2);
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_2");
}
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