@@ -5,12 +5,13 @@ import * as fse from "fs-extra";
5
5
import * as _ from "lodash" ;
6
6
import * as minimatch from "minimatch" ;
7
7
import * as path from "path" ;
8
- import { Disposable , ExtensionContext , Uri , window , workspace , WorkspaceFolder } from "vscode" ;
8
+ import { commands , Disposable , ExtensionContext , Uri , window , workspace , WorkspaceFolder } from "vscode" ;
9
9
import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper" ;
10
10
import { Commands } from "../commands" ;
11
11
import { Jdtls } from "../java/jdtls" ;
12
12
import { Settings } from "../settings" ;
13
13
import { Utility } from "../utility" ;
14
+ import { ContainerNode } from "../views/containerNode" ;
14
15
import { DataNode } from "../views/dataNode" ;
15
16
16
17
export class LibraryController implements Disposable {
@@ -24,13 +25,24 @@ export class LibraryController implements Disposable {
24
25
this . removeLibrary ( Uri . parse ( node . uri ) . fsPath ) ) ,
25
26
instrumentOperationAsVsCodeCommand ( Commands . JAVA_PROJECT_REFRESH_LIBRARIES , ( ) =>
26
27
this . refreshLibraries ( ) ) ,
28
+ instrumentOperationAsVsCodeCommand ( Commands . JAVA_MAVEN_PROJECT_ADD_DEPENDENCY , ( node : ContainerNode ) =>
29
+ this . addMavenDependency ( node ) ) ,
27
30
) ;
28
31
}
29
32
30
33
public dispose ( ) {
31
34
this . disposable . dispose ( ) ;
32
35
}
33
36
37
+ public async addMavenDependency ( node : ContainerNode ) {
38
+ const pomPath : string = path . join ( node . projectBasePath , "pom.xml" ) ;
39
+ if ( await fse . pathExists ( pomPath ) ) {
40
+ commands . executeCommand ( "maven.project.addDependency" , { pomPath } ) ;
41
+ } else {
42
+ commands . executeCommand ( "maven.project.addDependency" ) ;
43
+ }
44
+ }
45
+
34
46
public async addLibraries ( libraryGlobs ?: string [ ] ) {
35
47
if ( ! libraryGlobs ) {
36
48
libraryGlobs = [ ] ;
0 commit comments