1.1 --- a/nodejs/manifest.mf Sun Jul 08 20:46:58 2012 -0400
1.2 +++ b/nodejs/manifest.mf Mon Jul 09 10:51:03 2012 -0400
1.3 @@ -3,5 +3,6 @@
1.4 OpenIDE-Module-Layer: org/netbeans/modules/nodejs/layer.xml
1.5 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/nodejs/Bundle.properties
1.6 OpenIDE-Module-Requires: org.openide.modules.os.Unix
1.7 -OpenIDE-Module-Specification-Version: 1.19
1.8 +OpenIDE-Module-Specification-Version: 1.20
1.9
1.10 +
2.1 --- a/nodejs/nbproject/project.xml Sun Jul 08 20:46:58 2012 -0400
2.2 +++ b/nodejs/nbproject/project.xml Mon Jul 09 10:51:03 2012 -0400
2.3 @@ -74,7 +74,7 @@
2.4 <compile-dependency/>
2.5 <run-dependency>
2.6 <release-version>1</release-version>
2.7 - <specification-version>1.24</specification-version>
2.8 + <specification-version>1.27</specification-version>
2.9 </run-dependency>
2.10 </dependency>
2.11 <dependency>
3.1 --- a/nodejs/src/org/netbeans/modules/nodejs/Bundle.properties Sun Jul 08 20:46:58 2012 -0400
3.2 +++ b/nodejs/src/org/netbeans/modules/nodejs/Bundle.properties Mon Jul 09 10:51:03 2012 -0400
3.3 @@ -69,3 +69,4 @@
3.4 INFO_MAIN_CLASS_WHITESPACE=Run arguments will be separated on whitespace characters; file paths with spaces not supported yet.
3.5 TTL_PROJECT_RENAME=Rename Project
3.6 LBL_PROJECT_RENAME=New Project Name
3.7 +INSTALL_LIB=npm install {0}
4.1 --- a/nodejs/src/org/netbeans/modules/nodejs/NodeSharabilityQuery.java Sun Jul 08 20:46:58 2012 -0400
4.2 +++ b/nodejs/src/org/netbeans/modules/nodejs/NodeSharabilityQuery.java Mon Jul 09 10:51:03 2012 -0400
4.3 @@ -42,22 +42,25 @@
4.4 package org.netbeans.modules.nodejs;
4.5
4.6 import java.io.File;
4.7 -import org.netbeans.api.queries.SharabilityQuery;
4.8 -import org.netbeans.spi.queries.SharabilityQueryImplementation;
4.9 +import java.net.URI;
4.10 +import org.netbeans.api.queries.SharabilityQuery.Sharability;
4.11 +import org.netbeans.spi.queries.SharabilityQueryImplementation2;
4.12 +import org.openide.util.Utilities;
4.13 import org.openide.util.lookup.ServiceProvider;
4.14
4.15 /**
4.16 *
4.17 * @author Tim Boudreau
4.18 */
4.19 -@ServiceProvider(service=SharabilityQueryImplementation.class)
4.20 -public class NodeSharabilityQuery implements SharabilityQueryImplementation {
4.21 +@ServiceProvider(service=SharabilityQueryImplementation2.class)
4.22 +public class NodeSharabilityQuery implements SharabilityQueryImplementation2 {
4.23
4.24 @Override
4.25 - public int getSharability(File file) {
4.26 + public Sharability getSharability(URI uri) {
4.27 + File file = Utilities.toFile(uri);
4.28 if (".nbrun".equals(file.getName()) && new File(file.getParent(), "package.json").exists()) {
4.29 - return SharabilityQuery.NOT_SHARABLE;
4.30 + return Sharability.NOT_SHARABLE;
4.31 }
4.32 - return SharabilityQuery.UNKNOWN;
4.33 + return Sharability.UNKNOWN;
4.34 }
4.35 }
5.1 --- a/nodejs/src/org/netbeans/modules/nodejs/ProjectRootNode.java Sun Jul 08 20:46:58 2012 -0400
5.2 +++ b/nodejs/src/org/netbeans/modules/nodejs/ProjectRootNode.java Mon Jul 09 10:51:03 2012 -0400
5.3 @@ -44,16 +44,21 @@
5.4 import java.awt.datatransfer.Transferable;
5.5 import java.awt.event.ActionEvent;
5.6 import java.io.IOException;
5.7 +import java.nio.charset.Charset;
5.8 import java.util.ArrayList;
5.9 import java.util.Arrays;
5.10 import java.util.HashSet;
5.11 import java.util.List;
5.12 import java.util.ResourceBundle;
5.13 import java.util.Set;
5.14 +import java.util.concurrent.atomic.AtomicInteger;
5.15 import java.util.logging.Level;
5.16 import java.util.logging.Logger;
5.17 import javax.swing.AbstractAction;
5.18 import javax.swing.Action;
5.19 +import org.netbeans.api.extexecution.ExecutionDescriptor;
5.20 +import org.netbeans.api.extexecution.ExecutionService;
5.21 +import org.netbeans.api.extexecution.ExternalProcessBuilder;
5.22 import org.netbeans.api.progress.ProgressHandle;
5.23 import org.netbeans.api.progress.ProgressHandleFactory;
5.24 import org.netbeans.api.project.ProjectUtils;
5.25 @@ -75,7 +80,6 @@
5.26 import org.openide.nodes.Children;
5.27 import org.openide.nodes.Node;
5.28 import org.openide.util.Exceptions;
5.29 -import org.openide.util.Lookup;
5.30 import org.openide.util.NbBundle;
5.31 import org.openide.util.RequestProcessor;
5.32 import org.openide.util.actions.SystemAction;
5.33 @@ -133,47 +137,42 @@
5.34 if (DialogDisplayer.getDefault().notify(dd).equals(DialogDescriptor.OK_OPTION)) {
5.35 final Set<String> libraries = new HashSet<String>(pn.getLibraries());
5.36 if (libraries.size() > 0) {
5.37 + final AtomicInteger jobs = new AtomicInteger();
5.38 RequestProcessor.getDefault().post(new Runnable() {
5.39
5.40 @Override
5.41 public void run() {
5.42 - ProgressHandle h = ProgressHandleFactory.createHandle(NbBundle.getMessage(ProjectRootNode.class,
5.43 + final ProgressHandle h = ProgressHandleFactory.createHandle(NbBundle.getMessage(ProjectRootNode.class,
5.44 "MSG_RUNNING_NPM", libraries.size(), project.getDisplayName())); //NOI18N
5.45 + final int totalLibs = libraries.size();
5.46 try {
5.47 - h.start((libraries.size() * 2) + 1);
5.48 - List<Process> p = new ArrayList<Process>();
5.49 - int uc = 0;
5.50 - try {
5.51 - for (String lib : libraries) {
5.52 - h.progress(lib, ++uc);
5.53 - ProcessBuilder pb = new ProcessBuilder("npm", "install", lib); //NOI18N
5.54 - pb.directory(FileUtil.toFile(project.getProjectDirectory()));
5.55 - try {
5.56 - Process proc = pb.start();
5.57 - p.add(proc);
5.58 - } catch (IOException ex) {
5.59 - Exceptions.printStackTrace(ex);
5.60 + h.start(totalLibs * 2);
5.61 + for (String lib : libraries) {
5.62 + int job = jobs.incrementAndGet();
5.63 + ExternalProcessBuilder epb = new ExternalProcessBuilder("npm").addArgument("install").addArgument(lib).workingDirectory(FileUtil.toFile(project.getProjectDirectory()));
5.64 + final String libraryName = lib;
5.65 + ExecutionDescriptor des = new ExecutionDescriptor().controllable(true).showProgress(true).showSuspended(true).frontWindow(false).controllable(true).optionsPath("Advanced/Node").postExecution(new Runnable(){
5.66 + @Override
5.67 + public void run() {
5.68 + int ct = jobs.decrementAndGet();
5.69 + if (ct == 0) {
5.70 + h.finish();
5.71 + project.getProjectDirectory().refresh();
5.72 + FileObject fo = project.getProjectDirectory().getFileObject("node_modules"); //NOI18N
5.73 + if (fo != null) {
5.74 + fo.refresh();
5.75 + }
5.76 + Children ch = NodeFactorySupport.createCompositeChildren(project, "Project/NodeJS/Nodes"); //NOI18N
5.77 + setChildren(ch);
5.78 + } else {
5.79 + h.progress(NbBundle.getMessage(ProjectRootNode.class, "PROGRESS_LIBS_REMAINING", totalLibs - ct), totalLibs - ct); //NOI18N
5.80 + h.setDisplayName(libraryName);
5.81 + }
5.82 }
5.83 - }
5.84 - int ct = libraries.size() + 1;
5.85 - for (Process proc : p) {
5.86 - try {
5.87 - proc.waitFor();
5.88 - h.progress(NbBundle.getMessage(ProjectRootNode.class, "PROGRESS_LIBS_REMAINING", ct--), ++uc); //NOI18N
5.89 - } catch (InterruptedException ex) {
5.90 - Logger.getLogger(ProjectRootNode.class.getName()).log(Level.INFO, null, ex);
5.91 - }
5.92 - }
5.93 - } finally {
5.94 - project.getProjectDirectory().refresh();
5.95 - FileObject fo = project.getProjectDirectory().getFileObject("node_modules"); //NOI18N
5.96 - if (fo != null) {
5.97 - fo.refresh();
5.98 - }
5.99 + }).charset(Charset.forName("UTF-8")).frontWindowOnError(true);
5.100 + ExecutionService service = ExecutionService.newService(epb, des, lib);
5.101 + service.run();
5.102 }
5.103 - h.progress(NbBundle.getMessage(ProjectRootNode.class, "PROGRESS_REFRESH_PROJECT"), ++uc);
5.104 - Children ch = NodeFactorySupport.createCompositeChildren(project, "Project/NodeJS/Nodes"); //NOI18N
5.105 - setChildren(ch);
5.106 } finally {
5.107 h.finish();
5.108 }