Skip to content

Commit ea84795

Browse files
FatmeFatme
Fatme
authored and
Fatme
committed
Merge pull request #673 from NativeScript/fatme/validate-library-path
Validate library path
2 parents 1ce8d9e + c3b233c commit ea84795

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

lib/commands/add-library.ts

+18-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import Future = require("fibers/future");
77
export class AddLibraryCommand implements ICommand {
88
constructor(private $platformService: IPlatformService,
99
private $errors: IErrors,
10-
private $logger: ILogger) { }
10+
private $logger: ILogger,
11+
private $fs: IFileSystem) { }
1112

1213
allowedParameters: ICommandParameter[] = [];
1314

@@ -21,12 +22,22 @@ export class AddLibraryCommand implements ICommand {
2122
}
2223

2324
canExecute(args: string[]): IFuture<boolean> {
24-
if (args.length !== 2) {
25-
this.$errors.fail("This command needs two parameters.");
26-
}
27-
28-
this.$platformService.validatePlatformInstalled(args[0]);
29-
return Future.fromResult(true);
25+
return (() => {
26+
if (args.length !== 2) {
27+
this.$errors.fail("This command needs two parameters.");
28+
}
29+
30+
let libraryPath = path.resolve(args[1]);
31+
if(!this.$fs.exists(path.join(libraryPath, "project.properties")).wait()) {
32+
let files = this.$fs.enumerateFilesInDirectorySync(libraryPath);
33+
if(!_.any(files, file => path.extname(file) === ".jar")) {
34+
this.$errors.failWithoutHelp("Invalid library path. Ensure that the library path is the file path to a directory containing one or more `*.jar` files or to a directory containing the `project.properties` files.");
35+
}
36+
}
37+
38+
this.$platformService.validatePlatformInstalled(args[0]);
39+
return true;
40+
}).future<boolean>()();
3041
}
3142
}
3243
$injector.registerCommand("library|add", AddLibraryCommand);

0 commit comments

Comments
 (0)