Commit c5999c74 authored by Mikkel Nygaard Ravn's avatar Mikkel Nygaard Ravn Committed by GitHub

Add gradle wrapper to project template (#10928)

parent d97b13b5
0b5c1398d1d04ac245a310de98825cb7b3278e2a
......@@ -71,10 +71,11 @@ void ensureDirectoryExists(String filePath) {
}
}
/// Recursively copies `srcDir` to `destDir`.
/// Recursively copies `srcDir` to `destDir`, invoking [onFileCopied] if
/// specified for each source/destination file pair.
///
/// Creates `destDir` if needed.
void copyDirectorySync(Directory srcDir, Directory destDir) {
void copyDirectorySync(Directory srcDir, Directory destDir, [void onFileCopied(File srcFile, File destFile)]) {
if (!srcDir.existsSync())
throw new Exception('Source directory "${srcDir.path}" does not exist, nothing to copy');
......@@ -86,6 +87,7 @@ void copyDirectorySync(Directory srcDir, Directory destDir) {
if (entity is File) {
final File newFile = destDir.fileSystem.file(newPath);
newFile.writeAsBytesSync(entity.readAsBytesSync());
onFileCopied?.call(entity, newFile);
} else if (entity is Directory) {
copyDirectorySync(
entity, destDir.fileSystem.directory(newPath));
......
......@@ -47,6 +47,8 @@ abstract class OperatingSystemUtils {
void unzip(File file, Directory targetDirectory);
void unpack(File gzippedTarFile, Directory targetDirectory);
/// Returns a pretty name string for the current operating system.
///
/// If available, the detailed version of the OS is included.
......@@ -97,6 +99,12 @@ class _PosixUtils extends OperatingSystemUtils {
runSync(<String>['unzip', '-o', '-q', file.path, '-d', targetDirectory.path]);
}
// tar -xzf tarball -C dest
@override
void unpack(File gzippedTarFile, Directory targetDirectory) {
runSync(<String>['tar', '-xzf', gzippedTarFile.path, '-C', targetDirectory.path]);
}
@override
File makePipe(String path) {
runSync(<String>['mkfifo', path]);
......@@ -167,7 +175,18 @@ class _WindowsUtils extends OperatingSystemUtils {
@override
void unzip(File file, Directory targetDirectory) {
final Archive archive = new ZipDecoder().decodeBytes(file.readAsBytesSync());
_unpackArchive(archive, targetDirectory);
}
@override
void unpack(File gzippedTarFile, Directory targetDirectory) {
final Archive archive = new TarDecoder().decodeBytes(
new GZipDecoder().decodeBytes(gzippedTarFile.readAsBytesSync()),
);
_unpackArchive(archive, targetDirectory);
}
void _unpackArchive(Archive archive, Directory targetDirectory) {
for (ArchiveFile archiveFile in archive.files) {
// The archive package doesn't correctly set isFile.
if (!archiveFile.isFile || archiveFile.name.endsWith('/'))
......
This diff is collapsed.
......@@ -11,6 +11,7 @@ import '../android/android_sdk.dart' as android_sdk;
import '../android/gradle.dart' as gradle;
import '../base/common.dart';
import '../base/file_system.dart';
import '../base/os.dart';
import '../base/utils.dart';
import '../build_info.dart';
import '../cache.dart';
......@@ -167,6 +168,10 @@ class CreateCommand extends FlutterCommand {
}
generatedCount += _renderTemplate('create', appPath, templateContext);
generatedCount += _injectGradleWrapper(appPath);
if (appPath != dirPath) {
generatedCount += _injectGradleWrapper(dirPath);
}
if (argResults['with-driver-test']) {
final String testPath = fs.path.join(appPath, 'test_driver');
generatedCount += _renderTemplate('driver', testPath, templateContext);
......@@ -272,6 +277,22 @@ To edit platform code in an IDE see https://flutter.io/platform-plugins/#edit-co
final Template template = new Template.fromName(templateName);
return template.render(fs.directory(dirPath), context, overwriteExisting: false);
}
int _injectGradleWrapper(String projectDir) {
int filesCreated = 0;
copyDirectorySync(
cache.getArtifactDirectory('gradle_wrapper'),
fs.directory(fs.path.join(projectDir, 'android')),
(File sourceFile, File destinationFile) {
filesCreated++;
final String modes = sourceFile.statSync().modeString();
if (modes != null && modes.contains('x')) {
os.makeExecutable(destinationFile);
}
},
);
return filesCreated;
}
}
String _createAndroidIdentifier(String organization, String name) {
......
......@@ -69,20 +69,18 @@ Future<Null> parseServiceConfigs(
if (jars != null && serviceConfig['jars'] is Iterable) {
for (String jar in serviceConfig['jars'])
jars.add(fs.file(await getServiceFromUrl(jar, serviceRoot, service, unzip: false)));
jars.add(fs.file(await getServiceFromUrl(jar, serviceRoot, service)));
}
}
}
Future<String> getServiceFromUrl(
String url, String rootDir, String serviceName, { bool unzip: false }
) async {
Future<String> getServiceFromUrl(String url, String rootDir, String serviceName) async {
if (url.startsWith("android-sdk:") && androidSdk != null) {
// It's something shipped in the standard android SDK.
return url.replaceAll('android-sdk:', '${androidSdk.directory}/');
} else if (url.startsWith("http")) {
// It's a regular file to download.
return await cache.getThirdPartyFile(url, serviceName, unzip: unzip);
return await cache.getThirdPartyFile(url, serviceName);
} else {
// Assume url is a path relative to the service's root dir.
return fs.path.join(rootDir, url);
......
......@@ -4,7 +4,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
......@@ -26,7 +26,3 @@ subprojects {
task clean(type: Delete) {
delete rootProject.buildDir
}
task wrapper(type: Wrapper) {
gradleVersion = '2.14.1'
}
......@@ -4,7 +4,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.2-4'
}
}
......@@ -27,7 +27,3 @@ subprojects {
task clean(type: Delete) {
delete rootProject.buildDir
}
task wrapper(type: Wrapper) {
gradleVersion = '2.14.1'
}
......@@ -7,7 +7,3 @@
/build
/captures
GeneratedPluginRegistrant.java
/gradle
/gradlew
/gradlew.bat
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
......@@ -7,7 +7,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
......
......@@ -7,7 +7,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
......
......@@ -6,7 +6,3 @@
.DS_Store
/build
/captures
/gradle
/gradlew
/gradlew.bat
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
......@@ -48,6 +48,34 @@ void main() {
Platform: () => new FakePlatform()..environment = <String, String>{'FLUTTER_ALREADY_LOCKED': 'true'},
});
});
group('Cache', () {
test('should not be up to date, if some cached artifact is not', () {
final CachedArtifact artifact1 = new MockCachedArtifact();
final CachedArtifact artifact2 = new MockCachedArtifact();
when(artifact1.isUpToDate()).thenReturn(true);
when(artifact2.isUpToDate()).thenReturn(false);
final Cache cache = new Cache(artifacts: <CachedArtifact>[artifact1, artifact2]);
expect(cache.isUpToDate(), isFalse);
});
test('should be up to date, if all cached artifacts are', () {
final CachedArtifact artifact1 = new MockCachedArtifact();
final CachedArtifact artifact2 = new MockCachedArtifact();
when(artifact1.isUpToDate()).thenReturn(true);
when(artifact2.isUpToDate()).thenReturn(true);
final Cache cache = new Cache(artifacts: <CachedArtifact>[artifact1, artifact2]);
expect(cache.isUpToDate(), isTrue);
});
test('should update cached artifacts which are not up to date', () async {
final CachedArtifact artifact1 = new MockCachedArtifact();
final CachedArtifact artifact2 = new MockCachedArtifact();
when(artifact1.isUpToDate()).thenReturn(true);
when(artifact2.isUpToDate()).thenReturn(false);
final Cache cache = new Cache(artifacts: <CachedArtifact>[artifact1, artifact2]);
await cache.updateAll();
verifyNever(artifact1.update());
verify(artifact2.update());
});
});
}
class MockFileSystem extends MemoryFileSystem {
......@@ -65,3 +93,4 @@ class MockFile extends Mock implements File {
}
class MockRandomAccessFile extends Mock implements RandomAccessFile {}
class MockCachedArtifact extends Mock implements CachedArtifact {}
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