"Fossies" - the Fresh Open Source Software Archive

Member "flutter-1.22.4/dev/tools/java_and_objc_doc.dart" (13 Nov 2020, 2785 Bytes) of package /linux/misc/flutter-1.22.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Dart source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Copyright 2014 The Flutter Authors. All rights reserved.
    2 // Use of this source code is governed by a BSD-style license that can be
    3 // found in the LICENSE file.
    4 
    5 import 'dart:async';
    6 import 'dart:io';
    7 import 'dart:math';
    8 
    9 import 'package:archive/archive.dart';
   10 import 'package:http/http.dart' as http;
   11 
   12 const String kDocRoot = 'dev/docs/doc';
   13 
   14 /// This script downloads an archive of Javadoc and objc doc for the engine from
   15 /// the artifact store and extracts them to the location used for Dartdoc.
   16 Future<void> main(List<String> args) async {
   17   final String engineVersion = File('bin/internal/engine.version').readAsStringSync().trim();
   18 
   19   final String javadocUrl = 'https://storage.googleapis.com/flutter_infra/flutter/$engineVersion/android-javadoc.zip';
   20   generateDocs(javadocUrl, 'javadoc', 'io/flutter/view/FlutterView.html');
   21 
   22   final String objcdocUrl = 'https://storage.googleapis.com/flutter_infra/flutter/$engineVersion/ios-objcdoc.zip';
   23   generateDocs(objcdocUrl, 'objcdoc', 'Classes/FlutterViewController.html');
   24 }
   25 
   26 /// Fetches the zip archive at the specified url.
   27 ///
   28 /// Returns null if the archive fails to download after [maxTries] attempts.
   29 Future<Archive> fetchArchive(String url, int maxTries) async {
   30   List<int> responseBytes;
   31   for (int i = 0; i < maxTries; i++) {
   32     final http.Response response = await http.get(url);
   33     if (response.statusCode == 200) {
   34       responseBytes = response.bodyBytes;
   35       break;
   36     }
   37     stderr.writeln('Failed attempt ${i+1} to fetch $url.');
   38 
   39     // On failure print a short snipped from the body in case it's helpful.
   40     final int bodyLength = min(1024, response.body.length);
   41     stderr.writeln('Response status code ${response.statusCode}. Body: ' + response.body.substring(0, bodyLength));
   42     sleep(const Duration(seconds: 1));
   43   }
   44   return responseBytes == null ? null : ZipDecoder().decodeBytes(responseBytes);
   45 }
   46 
   47 Future<void> generateDocs(String url, String docName, String checkFile) async {
   48   const int maxTries = 5;
   49   final Archive archive = await fetchArchive(url, maxTries);
   50   if (archive == null) {
   51     stderr.writeln('Failed to fetch zip archive from: $url after $maxTries attempts. Giving up.');
   52     exit(1);
   53   }
   54 
   55   final Directory output = Directory('$kDocRoot/$docName');
   56   print('Extracting $docName to ${output.path}');
   57   output.createSync(recursive: true);
   58 
   59   for (final ArchiveFile af in archive) {
   60     if (!af.name.endsWith('/')) {
   61       final File file = File('${output.path}/${af.name}');
   62       file.createSync(recursive: true);
   63       file.writeAsBytesSync(af.content as List<int>);
   64     }
   65   }
   66 
   67   final File testFile = File('${output.path}/$checkFile');
   68   if (!testFile.existsSync()) {
   69     print('Expected file ${testFile.path} not found');
   70     exit(1);
   71   }
   72   print('$docName ready to go!');
   73 }