Unverified Commit 106b8eb9 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Revert "Reduce some direct package:archive usage (#44608)" (#45291)

This reverts commit 6b5634fe.
parent 6b5634fe
......@@ -249,7 +249,6 @@ class _WindowsUtils extends OperatingSystemUtils {
@override
void zip(Directory data, File zipFile) {
// TODO(jonahwilliams): investigate whether we can remove this dependency with https://github.com/flutter/flutter/issues/45278
final Archive archive = Archive();
for (FileSystemEntity entity in data.listSync(recursive: true)) {
if (entity is! File) {
......
......@@ -5,6 +5,7 @@
import 'dart:async';
import 'dart:typed_data';
import 'package:archive/archive.dart';
import 'package:build_daemon/client.dart';
import 'package:build_daemon/constants.dart' as daemon;
import 'package:build_daemon/data/build_status.dart';
......@@ -406,6 +407,33 @@ class DebugAssetServer extends AssetServer {
return Response.ok(file.readAsBytesSync(), headers: <String, String>{
'Content-Type': 'text/javascript',
});
} else if (request.url.path.endsWith('part.js')) {
// Lazily unpack any deferred imports in release/profile mode. These are
// placed into an archive by build_runner, and are named based on the main
// entrypoint + a "part" suffix (Though the actual names are arbitrary).
// To make this easier to deal with they are copied into a temp directory.
if (partFiles == null) {
final File dart2jsArchive = fs.file(fs.path.join(
flutterProject.dartTool.path,
'build',
'flutter_web',
'${flutterProject.manifest.appName}',
'lib',
'${targetBaseName}_web_entrypoint.dart.js.tar.gz',
));
if (dart2jsArchive.existsSync()) {
final Archive archive = TarDecoder().decodeBytes(dart2jsArchive.readAsBytesSync());
partFiles = fs.systemTempDirectory.createTempSync('flutter_tool.')
..createSync();
for (ArchiveFile file in archive) {
partFiles.childFile(file.name).writeAsBytesSync(file.content as List<int>);
}
}
}
final String fileName = fs.path.basename(request.url.path);
return Response.ok(partFiles.childFile(fileName).readAsBytesSync(), headers: <String, String>{
'Content-Type': 'text/javascript',
});
} else if (request.url.path.contains('require.js')) {
final File file = fs.file(fs.path.join(
artifacts.getArtifactPath(Artifact.engineDartSdkPath),
......
......@@ -2,11 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:archive/archive.dart';
import '../base/file_system.dart';
import '../base/os.dart';
import '../base/version.dart';
import '../convert.dart';
import '../doctor.dart';
import '../globals.dart';
class IntelliJPlugins {
IntelliJPlugins(this.pluginsPath);
......@@ -55,25 +56,18 @@ class IntelliJPlugins {
final String jarPath = packageName.endsWith('.jar')
? fs.path.join(pluginsPath, packageName)
: fs.path.join(pluginsPath, packageName, 'lib', '$packageName.jar');
// TODO(danrubel): look for a better way to extract a single 2K file from the zip
// rather than reading the entire file into memory.
try {
final Directory tempDirectory = fs.systemTempDirectory
.createTempSync('flutter_tools_intellij.')
..createSync(recursive: true);
os.unzip(fs.file(jarPath), tempDirectory);
final File file = tempDirectory
.childDirectory('META-INF')
.childFile('plugin.xml');
final String content = file.readAsStringSync();
final Archive archive =
ZipDecoder().decodeBytes(fs.file(jarPath).readAsBytesSync());
final ArchiveFile file = archive.findFile('META-INF/plugin.xml');
final String content = utf8.decode(file.content as List<int>);
const String versionStartTag = '<version>';
final int start = content.indexOf(versionStartTag);
final int end = content.indexOf('</version>', start);
try {
tempDirectory.deleteSync(recursive: true);
} on Exception catch (_) {
printTrace('Failed to delete temp directory: ${tempDirectory?.path}');
}
return content.substring(start + versionStartTag.length, end);
} on Exception catch (_) {
} catch (_) {
return null;
}
}
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:convert';
import 'package:archive/archive.dart';
import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/os.dart';
import 'package:flutter_tools/src/doctor.dart';
import 'package:flutter_tools/src/intellij/intellij.dart';
import 'package:mockito/mockito.dart';
import '../../src/common.dart';
import '../../src/context.dart';
const String dartPluginContents = '''<idea-plugin version="2">
<name>Dart</name>
<version>162.2485</version>
</idea-plugin>
''';
const String flutterPluginContents = r'''
<idea-plugin version="2">
<name>Flutter</name>
<version>0.1.3</version>
</idea-plugin>
''';
void main() {
testUsingContext('IntelliJ plugins found', () async {
fs.directory(fs.path.join(_kPluginsPath, 'Dart'))
.createSync(recursive: true);
fs.file(fs.path.join(_kPluginsPath, 'flutter-intellij.jar'))
.createSync(recursive: true);
when(os.unzip(any, any)).thenAnswer((Invocation invocation) {
final File file = invocation.positionalArguments.first as File;
final Directory destination = invocation.positionalArguments.last as Directory;
destination
.childDirectory('META-INF')
.childFile('plugin.xml')
..createSync(recursive: true)
..writeAsStringSync(file.path.contains('Dart')
? dartPluginContents
: flutterPluginContents);
});
FileSystem fs;
final IntelliJPlugins plugins = IntelliJPlugins(_kPluginsPath);
void writeFileCreatingDirectories(String path, List<int> bytes) {
final File file = fs.file(path);
file.parent.createSync(recursive: true);
file.writeAsBytesSync(bytes);
}
final List<ValidationMessage> messages = <ValidationMessage>[];
plugins.validatePackage(messages, <String>['Dart'], 'Dart');
plugins.validatePackage(messages,
<String>['flutter-intellij', 'flutter-intellij.jar'], 'Flutter',
minVersion: IntelliJPlugins.kMinFlutterPluginVersion);
setUp(() {
fs = MemoryFileSystem();
});
ValidationMessage message = messages
.firstWhere((ValidationMessage m) => m.message.startsWith('Dart '));
group('IntelliJ', () {
group('plugins', () {
testUsingContext('found', () async {
final IntelliJPlugins plugins = IntelliJPlugins(_kPluginsPath);
expect(message.message, 'Dart plugin version 162.2485');
message = messages.firstWhere(
(ValidationMessage m) => m.message.startsWith('Flutter '));
final Archive dartJarArchive =
buildSingleFileArchive('META-INF/plugin.xml', r'''
<idea-plugin version="2">
<name>Dart</name>
<version>162.2485</version>
</idea-plugin>
''');
writeFileCreatingDirectories(
fs.path.join(_kPluginsPath, 'Dart', 'lib', 'Dart.jar'),
ZipEncoder().encode(dartJarArchive));
expect(message.message, contains('Flutter plugin version 0.1.3'));
expect(message.message, contains('recommended minimum version'));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
ProcessManager: () => FakeProcessManager.any(),
OperatingSystemUtils: () => MockOperatingSystemUtils(),
final Archive flutterJarArchive =
buildSingleFileArchive('META-INF/plugin.xml', r'''
<idea-plugin version="2">
<name>Flutter</name>
<version>0.1.3</version>
</idea-plugin>
''');
writeFileCreatingDirectories(
fs.path.join(_kPluginsPath, 'flutter-intellij.jar'),
ZipEncoder().encode(flutterJarArchive));
final List<ValidationMessage> messages = <ValidationMessage>[];
plugins.validatePackage(messages, <String>['Dart'], 'Dart');
plugins.validatePackage(messages,
<String>['flutter-intellij', 'flutter-intellij.jar'], 'Flutter',
minVersion: IntelliJPlugins.kMinFlutterPluginVersion);
ValidationMessage message = messages
.firstWhere((ValidationMessage m) => m.message.startsWith('Dart '));
expect(message.message, 'Dart plugin version 162.2485');
message = messages.firstWhere(
(ValidationMessage m) => m.message.startsWith('Flutter '));
expect(message.message, contains('Flutter plugin version 0.1.3'));
expect(message.message, contains('recommended minimum version'));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('not found', () async {
final IntelliJPlugins plugins = IntelliJPlugins(_kPluginsPath);
final List<ValidationMessage> messages = <ValidationMessage>[];
plugins.validatePackage(messages, <String>['Dart'], 'Dart');
plugins.validatePackage(messages,
<String>['flutter-intellij', 'flutter-intellij.jar'], 'Flutter',
minVersion: IntelliJPlugins.kMinFlutterPluginVersion);
ValidationMessage message = messages
.firstWhere((ValidationMessage m) => m.message.startsWith('Dart '));
expect(message.message, contains('Dart plugin not installed'));
message = messages.firstWhere(
(ValidationMessage m) => m.message.startsWith('Flutter '));
expect(message.message, contains('Flutter plugin not installed'));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
});
});
});
}
testUsingContext('IntelliJ plugins not found', () async {
final IntelliJPlugins plugins = IntelliJPlugins(_kPluginsPath);
final List<ValidationMessage> messages = <ValidationMessage>[];
plugins.validatePackage(messages, <String>['Dart'], 'Dart');
plugins.validatePackage(messages,
<String>['flutter-intellij', 'flutter-intellij.jar'], 'Flutter',
minVersion: IntelliJPlugins.kMinFlutterPluginVersion);
ValidationMessage message = messages
.firstWhere((ValidationMessage m) => m.message.startsWith('Dart '));
const String _kPluginsPath = '/data/intellij/plugins';
expect(message.message, contains('Dart plugin not installed'));
Archive buildSingleFileArchive(String path, String content) {
final Archive archive = Archive();
message = messages.firstWhere(
(ValidationMessage m) => m.message.startsWith('Flutter '));
final List<int> bytes = utf8.encode(content);
archive.addFile(ArchiveFile(path, bytes.length, bytes));
expect(message.message, contains('Flutter plugin not installed'));
}, overrides: <Type, Generator>{
OperatingSystemUtils: () => MockOperatingSystemUtils(),
FileSystem: () => MemoryFileSystem(),
ProcessManager: () => FakeProcessManager.any(),
});
return archive;
}
class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {}
const String _kPluginsPath = '/data/intellij/plugins';
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment