summaryrefslogtreecommitdiff
path: root/build-system/integration-test/application/src/test/java/com/android/build/gradle/integration/dependencies/AppWithProvidedLibTest.java
blob: a090520f62f23117f5b0682a203e011f68c3659a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.build.gradle.integration.dependencies;

import static com.android.build.gradle.integration.common.fixture.GradleTestProject.builder;
import static com.android.build.gradle.integration.common.truth.TruthHelper.assertThat;

import com.android.build.gradle.integration.common.fixture.GradleBuildResult;
import com.android.build.gradle.integration.common.fixture.GradleTestProject;
import com.android.build.gradle.integration.common.fixture.ModelContainer;
import com.android.build.gradle.integration.common.utils.TestFileUtils;
import com.android.builder.model.AndroidProject;
import com.android.utils.FileUtils;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;

/** test for compileOnly library in app */
public class AppWithProvidedLibTest {

    @ClassRule
    public static GradleTestProject project =
            builder()
                    .fromTestProject("dynamicApp")
                    .create();

    static ModelContainer<AndroidProject> modelContainer;

    @BeforeClass
    public static void setUp() throws Exception {
        // create a library module.
        File rootFolder = project.getSettingsFile().getParentFile();
        File libFolder = new File(rootFolder, "library");
        FileUtils.mkdirs(libFolder);

        Files.asCharSink(new File(libFolder, "build.gradle"), Charsets.UTF_8)
                .write(
                        "apply plugin: 'com.android.library'\n"
                                + "\n"
                                + "android {\n"
                                + "    namespace 'com.example.android.multiproject.library.base'\n"
                                + "    compileSdkVersion rootProject.latestCompileSdk\n"
                                + "\n"
                                + "}\n");
        final File mainFolder = new File(libFolder, "src/main");
        FileUtils.mkdirs(mainFolder);
        Files.asCharSink(new File(mainFolder, "AndroidManifest.xml"), Charsets.UTF_8)
                .write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<manifest />\n");

        TestFileUtils.appendToFile(project.getSettingsFile(), "\ninclude 'library'");
        TestFileUtils.appendToFile(
                project.getSubproject("app").getBuildFile(),
                "\n" + "dependencies {\n" + "    compileOnly project(\":library\")\n" + "}\n");
        modelContainer =
                project.model().withFullDependencies().ignoreSyncIssues().fetchAndroidProjects();
    }

    @AfterClass
    public static void cleanUp() {
        project = null;
        modelContainer = null;
    }

    @Test
    public void checkBuildFailure() throws IOException, InterruptedException {
        GradleBuildResult result = project.executor().expectFailure().run("app:assemble");

        assertThat(result.getFailureMessage())
                .isEqualTo(
                        "The following Android dependencies are set to compileOnly which is not supported:\n"
                                + "-> :library");
    }

    @Test
    @Ignore("b/68754628, b/128449813")
    public void checkModelFailedToLoad() throws Exception {
        // TODO: full dependency should show us broken provided only dependency.
        //final AndroidProject androidProject = modelContainer.getOnlyModelMap().get(":app");
        //assertThat(androidProject).hasIssueSize(2);
        //assertThat(androidProject).hasIssue(
        //        SyncIssue.SEVERITY_ERROR,
        //        SyncIssue.TYPE_NON_JAR_PROVIDED_DEP,
        //        "projectWithModules:library:unspecified:debug@aar");
        //assertThat(androidProject).hasIssue(
        //        SyncIssue.SEVERITY_ERROR,
        //        SyncIssue.TYPE_NON_JAR_PROVIDED_DEP,
        //        "projectWithModules:library:unspecified:release@aar");
    }
}