Search in sources :

Example 1 with JpsAndroidModuleProperties

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

the class AndroidFacetModuleSetupStep method configureFacet.

private static void configureFacet(@NotNull AndroidFacet facet, @NotNull AndroidModuleModel androidModel) {
    JpsAndroidModuleProperties facetProperties = facet.getProperties();
    facetProperties.ALLOW_USER_CONFIGURATION = false;
    facetProperties.PROJECT_TYPE = androidModel.getProjectType();
    File modulePath = androidModel.getRootDirPath();
    SourceProvider sourceProvider = androidModel.getDefaultSourceProvider();
    facetProperties.MANIFEST_FILE_RELATIVE_PATH = relativePath(modulePath, sourceProvider.getManifestFile());
    facetProperties.RES_FOLDER_RELATIVE_PATH = relativePath(modulePath, sourceProvider.getResDirectories());
    facetProperties.ASSETS_FOLDER_RELATIVE_PATH = relativePath(modulePath, sourceProvider.getAssetsDirectories());
    syncSelectedVariant(facetProperties, androidModel);
    facet.setAndroidModel(androidModel);
    androidModel.syncSelectedVariantAndTestArtifact(facet);
}
Also used : SourceProvider(com.android.builder.model.SourceProvider) JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties) File(java.io.File)

Example 2 with JpsAndroidModuleProperties

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

the class AndroidModuleModel method syncSelectedVariantAndTestArtifact.

public void syncSelectedVariantAndTestArtifact(@NotNull AndroidFacet facet) {
    Variant variant = getSelectedVariant();
    JpsAndroidModuleProperties state = facet.getProperties();
    state.SELECTED_BUILD_VARIANT = variant.getName();
    AndroidArtifact mainArtifact = variant.getMainArtifact();
    // When multi test artifacts are enabled, test tasks are computed dynamically.
    updateGradleTaskNames(state, mainArtifact, null);
}
Also used : JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties)

Example 3 with JpsAndroidModuleProperties

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

the class GradleBuildInvoker method findAndAddGradleBuildTasks.

private static void findAndAddGradleBuildTasks(@NotNull Module module, @NotNull BuildMode buildMode, @NotNull List<String> tasks, @NotNull TestCompileType testCompileType) {
    GradleFacet gradleFacet = GradleFacet.getInstance(module);
    if (gradleFacet == null) {
        return;
    }
    String gradlePath = gradleFacet.getConfiguration().GRADLE_PROJECT_PATH;
    if (isEmpty(gradlePath)) {
        // Gradle project path is never, ever null. If the path is empty, it shows as ":". We had reports of this happening. It is likely that
        // users manually added the Android-Gradle facet to a project. After all it is likely not to be a Gradle module. Better quit and not
        // build the module.
        String msg = String.format("Module '%1$s' does not have a Gradle path. It is likely that this module was manually added by the user.", module.getName());
        getLogger().info(msg);
        return;
    }
    AndroidFacet androidFacet = AndroidFacet.getInstance(module);
    if (androidFacet != null) {
        JpsAndroidModuleProperties properties = androidFacet.getProperties();
        AndroidModuleModel androidModel = AndroidModuleModel.get(module);
        switch(buildMode) {
            // Intentional fall-through.
            case CLEAN:
            case SOURCE_GEN:
                addAfterSyncTasks(tasks, gradlePath, properties);
                addAfterSyncTasksForTestArtifacts(tasks, gradlePath, testCompileType, androidModel);
                break;
            case ASSEMBLE:
                tasks.add(createBuildTask(gradlePath, properties.ASSEMBLE_TASK_NAME));
                // Add assemble tasks for tests.
                if (testCompileType != TestCompileType.NONE) {
                    for (BaseArtifact artifact : getArtifactsForTestCompileType(testCompileType, androidModel)) {
                        addTaskIfSpecified(tasks, gradlePath, artifact.getAssembleTaskName());
                    }
                }
                break;
            default:
                addAfterSyncTasks(tasks, gradlePath, properties);
                addAfterSyncTasksForTestArtifacts(tasks, gradlePath, testCompileType, androidModel);
                // no *.class files and would be just a waste of time.
                if (testCompileType != TestCompileType.UNIT_TESTS) {
                    addTaskIfSpecified(tasks, gradlePath, properties.COMPILE_JAVA_TASK_NAME);
                }
                // Add compile tasks for tests.
                for (BaseArtifact artifact : getArtifactsForTestCompileType(testCompileType, androidModel)) {
                    addTaskIfSpecified(tasks, gradlePath, artifact.getCompileTaskName());
                }
                break;
        }
    } else {
        JavaFacet javaFacet = JavaFacet.getInstance(module);
        if (javaFacet != null && javaFacet.getConfiguration().BUILDABLE) {
            String gradleTaskName = javaFacet.getGradleTaskName(buildMode);
            if (gradleTaskName != null) {
                tasks.add(createBuildTask(gradlePath, gradleTaskName));
            }
            if (testCompileType == TestCompileType.UNIT_TESTS) {
                tasks.add(createBuildTask(gradlePath, JavaFacet.TEST_CLASSES_TASK_NAME));
            }
        }
    }
}
Also used : JavaFacet(com.android.tools.idea.gradle.project.facet.java.JavaFacet) GradleFacet(com.android.tools.idea.gradle.project.facet.gradle.GradleFacet) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties) BaseArtifact(com.android.builder.model.BaseArtifact) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 4 with JpsAndroidModuleProperties

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

the class BuildVariantsTest method testSwitchVariantWithFlavor.

@Ignore("failed in http://go/aj/job/studio-ui-test/389 and from IDEA")
@Test
public void testSwitchVariantWithFlavor() throws IOException {
    guiTest.importProjectAndWaitForProjectSyncToFinish("Flavoredlib");
    BuildVariantsToolWindowFixture buildVariants = guiTest.ideFrame().getBuildVariantsWindow();
    buildVariants.selectVariantForModule(MODULE_NAME, "flavor1Release");
    String generatedSourceDirPath = MODULE_NAME + "/build/generated/source/";
    Collection<String> sourceFolders = guiTest.ideFrame().getSourceFolderRelativePaths(MODULE_NAME, SOURCE);
    assertThat(sourceFolders).containsAllOf(generatedSourceDirPath + "r/flavor1/release", generatedSourceDirPath + "aidl/flavor1/release", generatedSourceDirPath + "buildConfig/flavor1/release", generatedSourceDirPath + "rs/flavor1/release", MODULE_NAME + "/src/flavor1Release/aidl", MODULE_NAME + "/src/flavor1Release/java", MODULE_NAME + "/src/flavor1Release/jni", MODULE_NAME + "/src/flavor1Release/rs");
    Module appModule = guiTest.ideFrame().getModule(MODULE_NAME);
    JpsAndroidModuleProperties androidFacetProperties = AndroidFacet.getInstance(appModule).getProperties();
    assertEquals("assembleFlavor1Release", androidFacetProperties.ASSEMBLE_TASK_NAME);
    // 'release' variant does not have the _android_test_ artifact.
    assertThat(androidFacetProperties.ASSEMBLE_TEST_TASK_NAME).isEmpty();
    buildVariants.selectVariantForModule(MODULE_NAME, "flavor1Debug");
    sourceFolders = guiTest.ideFrame().getSourceFolderRelativePaths(MODULE_NAME, SOURCE);
    assertThat(sourceFolders).containsAllOf(generatedSourceDirPath + "r/flavor1/debug", generatedSourceDirPath + "aidl/flavor1/debug", generatedSourceDirPath + "buildConfig/flavor1/debug", generatedSourceDirPath + "rs/flavor1/debug", MODULE_NAME + "/src/flavor1Debug/aidl", MODULE_NAME + "/src/flavor1Debug/java", MODULE_NAME + "/src/flavor1Debug/jni", MODULE_NAME + "/src/flavor1Debug/rs");
    assertEquals("assembleFlavor1Debug", androidFacetProperties.ASSEMBLE_TASK_NAME);
    // Verifies that https://code.google.com/p/android/issues/detail?id=83077 is not a bug.
    assertEquals("assembleFlavor1DebugAndroidTest", androidFacetProperties.ASSEMBLE_TEST_TASK_NAME);
}
Also used : JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties) Module(com.intellij.openapi.module.Module) BuildVariantsToolWindowFixture(com.android.tools.idea.tests.gui.framework.fixture.BuildVariantsToolWindowFixture) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with JpsAndroidModuleProperties

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

the class KeystoreUtils method getDebugKeystore.

/**
   * Get the debug keystore path.
   *
   * @return the keystore file.
   * @throws Exception if the keystore file could not be obtained.
   */
@NotNull
public static File getDebugKeystore(@NotNull AndroidFacet facet) throws Exception {
    File gradleDebugKeystore = getGradleDebugKeystore(facet);
    if (gradleDebugKeystore != null) {
        return gradleDebugKeystore;
    }
    JpsAndroidModuleProperties state = facet.getConfiguration().getState();
    if (state != null && !Strings.isNullOrEmpty(state.CUSTOM_DEBUG_KEYSTORE_PATH)) {
        return new File(state.CUSTOM_DEBUG_KEYSTORE_PATH);
    }
    return getOrCreateDefaultDebugKeystore();
}
Also used : JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties) GradleBuildFile(com.android.tools.idea.gradle.parser.GradleBuildFile) File(java.io.File) GradleSettingsFile(com.android.tools.idea.gradle.parser.GradleSettingsFile) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JpsAndroidModuleProperties (org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties)23 JpsAndroidModuleExtensionImpl (org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl)13 JpsModule (org.jetbrains.jps.model.module.JpsModule)13 JpsSimpleElement (org.jetbrains.jps.model.JpsSimpleElement)7 JpsLibrary (org.jetbrains.jps.model.library.JpsLibrary)5 NotNull (org.jetbrains.annotations.NotNull)4 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2 Module (com.intellij.openapi.module.Module)2 File (java.io.File)2 BaseArtifact (com.android.builder.model.BaseArtifact)1 SourceProvider (com.android.builder.model.SourceProvider)1 GradleBuildFile (com.android.tools.idea.gradle.parser.GradleBuildFile)1 GradleSettingsFile (com.android.tools.idea.gradle.parser.GradleSettingsFile)1 GradleFacet (com.android.tools.idea.gradle.project.facet.gradle.GradleFacet)1 JavaFacet (com.android.tools.idea.gradle.project.facet.java.JavaFacet)1 NdkFacet (com.android.tools.idea.gradle.project.facet.ndk.NdkFacet)1 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)1 GradleSyncState (com.android.tools.idea.gradle.project.sync.GradleSyncState)1 AndroidModel (com.android.tools.idea.model.AndroidModel)1