diff --git a/lib/src/common/project.dart b/lib/src/common/project.dart index 96bb8cf..64b315d 100644 --- a/lib/src/common/project.dart +++ b/lib/src/common/project.dart @@ -366,7 +366,7 @@ extension on Directory { userHome.error, ); - return _kradleCacheDirectoryOrThrow( + return _kradleCacheDirectory( kradleHome, () => throw KlutterException(errorMessage)); } } @@ -382,7 +382,7 @@ extension on File { /// is not resolved or does not exist. Directory get defaultKradleCache { final userHome = _userHomeOrError; - return _kradleCacheDirectoryOrThrow( + return _kradleCacheDirectory( _kradleCacheFromEnvironmentPropertyOrNull(userHome.userHome), () { throw KlutterException( _defaultKradleCacheBecauseCachePropertyNotFoundErrorMessage( @@ -404,7 +404,7 @@ extension on File { kradleEnvPropertyUserHome, userHome.userHome!) : null; - return _kradleCacheDirectoryOrThrow( + return _kradleCacheDirectory( cachePropertyResolved, () => throw KlutterException( _configuredKradleHomeErrorMessage( @@ -415,7 +415,7 @@ extension on File { ); } - return _kradleCacheDirectoryOrThrow(cacheProperty, () {}); + return _kradleCacheDirectory(cacheProperty, () {}); } /// Return value of property cache or null. @@ -434,9 +434,8 @@ String _extractPropertyValue(String line) => String? _kradleCacheFromEnvironmentPropertyOrNull(String? userHomeOrNull) => userHomeOrNull == null ? null : "$userHomeOrNull/.kradle/cache".normalize; -/// Returns the kradle cache directory or throws a [KlutterException] -/// if the directory could not be determined or if it does not exist. -Directory _kradleCacheDirectoryOrThrow( +/// Returns the kradle cache directory and creates it if it does not exist. +Directory _kradleCacheDirectory( String? pathToKradleCache, void Function() onNullValue, ) { @@ -444,8 +443,7 @@ Directory _kradleCacheDirectoryOrThrow( onNullValue(); } - return Directory(pathToKradleCache!.normalize).normalizeToFolder - ..verifyFolderExists; + return Directory(pathToKradleCache!.normalize).normalizeToFolder..maybeCreate; } /// Determine the user home directory by checking environment variables. diff --git a/test/src/common/project_kradle_test.dart b/test/src/common/project_kradle_test.dart index 61b5f7a..8eb5788 100644 --- a/test/src/common/project_kradle_test.dart +++ b/test/src/common/project_kradle_test.dart @@ -208,18 +208,25 @@ void main() { }); test( - "When kradle.env contains cache property and the file is not found then an exception is thrown", + "When kradle.env contains cache property and the directory is not found then it is created", () { + final dotKradleDirectory = Directory.systemTemp.resolveFolder(".kradle")..createSync(); + final cacheDirectory = Directory("${dotKradleDirectory.absolutePath}/cache".normalize); final rootDirectory = _newProjectFolder; setPlatformMacos(rootDirectory); createCacheFolder(rootDirectory); createKradleEnv( rootDirectory, - contents: "cache=foo/bar/.kradle/cache", + contents: "cache=${cacheDirectory.absolutePath}", ); - expect(() => rootDirectory.kradleCache, throwsA(predicate((e) { - return e is KlutterException && e.cause.contains("Path does not exist: "); - }))); + + expect(cacheDirectory.existsSync(), false); + + // when + rootDirectory.kradleCache; + + // then + expect(cacheDirectory.existsSync(), true); }); tearDownAll(() { diff --git a/test/src/systemtest/e2e_test.dart b/test/src/systemtest/e2e_test.dart index 69eb537..6f54fd6 100644 --- a/test/src/systemtest/e2e_test.dart +++ b/test/src/systemtest/e2e_test.dart @@ -216,7 +216,10 @@ Future createFlutterPlugin({ for(final task in tasks) { final res = await task.execute(root); - //assert(res.isOk, res.message); + if(!res.isOk) { + print(task); + assert(res.isOk,res.message); + } } }