@@ -5,12 +5,13 @@ import * as fse from "fs-extra";
55import * as _ from "lodash" ;
66import * as minimatch from "minimatch" ;
77import * 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" ;
99import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper" ;
1010import { Commands } from "../commands" ;
1111import { Jdtls } from "../java/jdtls" ;
1212import { Settings } from "../settings" ;
1313import { Utility } from "../utility" ;
14+ import { ContainerNode } from "../views/containerNode" ;
1415import { DataNode } from "../views/dataNode" ;
1516
1617export class LibraryController implements Disposable {
@@ -24,13 +25,24 @@ export class LibraryController implements Disposable {
2425 this . removeLibrary ( Uri . parse ( node . uri ) . fsPath ) ) ,
2526 instrumentOperationAsVsCodeCommand ( Commands . JAVA_PROJECT_REFRESH_LIBRARIES , ( ) =>
2627 this . refreshLibraries ( ) ) ,
28+ instrumentOperationAsVsCodeCommand ( Commands . JAVA_MAVEN_PROJECT_ADD_DEPENDENCY , ( node : ContainerNode ) =>
29+ this . addMavenDependency ( node ) ) ,
2730 ) ;
2831 }
2932
3033 public dispose ( ) {
3134 this . disposable . dispose ( ) ;
3235 }
3336
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+
3446 public async addLibraries ( libraryGlobs ?: string [ ] ) {
3547 if ( ! libraryGlobs ) {
3648 libraryGlobs = [ ] ;
0 commit comments