}
}
static synchronized List<LibraryAndVersion> updateDependencies ( NodeJSProject prj, List<LibraryAndVersion> onDisk, String... remove ) {
List<LibraryAndVersion> l = new ArrayList<>();
ProjectMetadataImpl metadata = prj.metadata();
Set<String> toRemove = new HashSet<>(Arrays.<String>asList(remove));
if (metadata != null) {
Map<String, Object> deps = metadata.getMap( "dependencies" );
if (deps != null) {
for (Map.Entry<String, Object> e : deps.entrySet()) {
if (toRemove.contains(e.getKey())) {
continue;
}
if (e.getValue() instanceof String) {
String ver = (String) e.getValue();
LibraryAndVersion dep = new LibraryAndVersion( e.getKey(), ver );
l.add( dep );
}
}
}
for (LibraryAndVersion v : onDisk) {
if (!l.contains( v )) {
if (v.version != null) {
// if (!v.version.startsWith( ">" ) && !v.version.startsWith( "=" ) && !v.version.startsWith( "<" ) && !v.version.startsWith( "~" )) { //NOI18N
// v.version = ">=" + v.version;
// }
l.add( v );
}
}
}
Collections.sort( l );
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
for (LibraryAndVersion lib : l) {
map.put( lib.name, lib.version );
}
Map m = metadata.getMap();
m.put( "dependencies", map );
try {
metadata.save();
} catch ( IOException ex ) {
Exceptions.printStackTrace( ex );
}
} else {
System.out.println( "project metadata was null" );