if (DialogDisplayer.getDefault().notify( dd ).equals( DialogDescriptor.OK_OPTION )) {
final Set<String> libraries = new HashSet<>( pn.getLibraries() );
if (libraries.size() > 0) {
final String npmPath = Npm.getDefault().exe( );
final AtomicInteger jobs = new AtomicInteger();
final ProgressHandle h = ProgressHandleFactory.createHandle( NbBundle.getMessage( AddLibraryAction.class,
"MSG_RUNNING_NPM", libraries.size(), project.getDisplayName() ) ); //NOI18N
RequestProcessor.getDefault().post( new Runnable() {
@Override
public void run () {
final int totalLibs = libraries.size();
try {
h.start( totalLibs * 2 );
for (String lib : libraries) {
int job = jobs.incrementAndGet();
ExternalProcessBuilder epb = new ExternalProcessBuilder( npmPath ) //NOI18N
.addArgument( "install" ) //NOI18N
.addArgument( lib )
.workingDirectory( FileUtil.toFile( project.getProjectDirectory() ) );
final String libraryName = lib;
ExecutionDescriptor des = new ExecutionDescriptor().controllable( true ).showProgress( true ).showSuspended( true ).frontWindow( false ).controllable( true ).optionsPath( "Advanced/Node" ).postExecution( new Runnable() {
@Override
public void run () {
try {
int ct = jobs.decrementAndGet();
if (ct == 0) {
try {
project.getProjectDirectory().refresh();
FileObject fo = project.getProjectDirectory().getFileObject( NodeJSProjectFactory.NODE_MODULES_FOLDER );
if (fo != null && fo.isValid()) {
fo.refresh();
}
root.updateChildren();
} finally {
h.finish();
}
} else {
h.progress( NbBundle.getMessage( ProjectNodeKey.class,
"PROGRESS_LIBS_REMAINING", totalLibs - ct ), totalLibs - ct ); //NOI18N
h.setDisplayName( libraryName );
}
} finally {
List<LibraryAndVersion> l = libraries( project );
updateDependencies( project, l);
}
}
} ).charset( Charset.forName( "UTF-8" ) ).frontWindowOnError( true ); //NOI18N
ExecutionService service = ExecutionService.newService( epb, des, lib );
service.run();
}
} finally {
h.finish();
}
}
} );
}
}