engine_dependency_proxy_test.dart 2.95 KB
Newer Older
1 2 3 4
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'dart:convert';
6 7 8 9
import 'dart:io';

import 'package:flutter_devicelab/framework/apk_utils.dart';
import 'package:flutter_devicelab/framework/framework.dart';
10
import 'package:flutter_devicelab/framework/task_result.dart';
11 12 13 14 15 16 17 18 19 20 21
import 'package:flutter_devicelab/framework/utils.dart';
import 'package:path/path.dart' as path;

final String gradlew = Platform.isWindows ? 'gradlew.bat' : 'gradlew';
final String gradlewExecutable = Platform.isWindows ? '.\\$gradlew' : './$gradlew';

/// Tests that we respect storage proxy URLs in gradle dependencies.
Future<void> main() async {
  await task(() async {
    section('Find Java');

22
    final String? javaHome = await findJavaHome();
23
    if (javaHome == null) {
24
      return TaskResult.failure('Could not find Java');
25
    }
26 27 28 29 30 31 32
    print('\nUsing JAVA_HOME=$javaHome');

    section('Create project');
    await runProjectTest((FlutterProject flutterProject) async {
      await inDirectory(path.join(flutterProject.rootPath, 'android'), () async {
        section('Insert gradle testing script');
        final File build = File(path.join(
33
	    flutterProject.rootPath, 'android', 'app', 'build.gradle'));
34 35 36 37 38 39 40 41 42 43 44 45 46
        build.writeAsStringSync(
          '''
task printEngineMavenUrl() {
    doLast {
        println project.repositories.find { it.name == 'maven' }.url
    }
}
          ''',
          mode: FileMode.append,
          flush: true,
        );

        section('Checking default maven URL');
47
        String gradleOutput = await eval(
48 49 50
          gradlewExecutable,
          <String>['printEngineMavenUrl', '-q'],
        );
51 52 53 54
        const LineSplitter splitter = LineSplitter();
        List<String> outputLines = splitter.convert(gradleOutput);
        String mavenUrl = outputLines.last;
        print('Returned maven url: $mavenUrl');
55 56 57

        if (mavenUrl != 'https://storage.googleapis.com/download.flutter.io') {
          throw TaskResult.failure('Expected Android engine maven dependency URL to '
58 59
              'resolve to https://storage.googleapis.com/download.flutter.io. Got '
              '$mavenUrl instead');
60 61
        }

62
        section('Checking overridden maven URL');
63 64 65 66 67 68 69 70 71
        gradleOutput = await eval(
	    gradlewExecutable,
	    <String>['printEngineMavenUrl','-q'],
	    environment: <String, String>{
              'FLUTTER_STORAGE_BASE_URL': 'https://my.special.proxy',
            }
	);
        outputLines = splitter.convert(gradleOutput);
        mavenUrl = outputLines.last;
72 73

        if (mavenUrl != 'https://my.special.proxy/download.flutter.io') {
74 75 76 77 78
          throw TaskResult.failure(
	      'Expected overridden Android engine maven '
              'dependency URL to resolve to proxy location '
              'https://my.special.proxy/download.flutter.io. Got '
              '$mavenUrl instead');
79 80 81 82 83 84
        }
      });
    });
    return TaskResult.success(null);
  });
}