1.1 --- a/modulemanagement/src/org/netbeans/modules/modulemanagement/ModuleOptions.java Sat Aug 25 09:28:01 2012 +0200
1.2 +++ b/modulemanagement/src/org/netbeans/modules/modulemanagement/ModuleOptions.java Mon Aug 27 15:54:33 2012 +0200
1.3 @@ -41,22 +41,16 @@
1.4
1.5 package org.netbeans.modules.modulemanagement;
1.6
1.7 -import java.beans.PropertyChangeEvent;
1.8 -import java.beans.PropertyChangeListener;
1.9 -import java.io.File;
1.10 import java.io.IOException;
1.11 import java.io.PrintStream;
1.12 +import java.text.MessageFormat;
1.13 import java.util.Arrays;
1.14 -import java.util.Collection;
1.15 import java.util.Collections;
1.16 import java.util.HashSet;
1.17 -import java.util.Iterator;
1.18 import java.util.List;
1.19 import java.util.Map;
1.20 import java.util.Set;
1.21 -import java.util.jar.JarFile;
1.22 import java.util.logging.Logger;
1.23 -import java.util.regex.Matcher;
1.24 import java.util.regex.Pattern;
1.25 import java.util.regex.PatternSyntaxException;
1.26 import org.netbeans.api.autoupdate.*;
1.27 @@ -68,11 +62,6 @@
1.28 import org.netbeans.spi.sendopts.Option;
1.29 import org.netbeans.spi.sendopts.OptionGroups;
1.30 import org.netbeans.spi.sendopts.OptionProcessor;
1.31 -import org.openide.filesystems.FileLock;
1.32 -import org.openide.filesystems.FileObject;
1.33 -import org.openide.filesystems.FileSystem;
1.34 -import org.openide.filesystems.FileUtil;
1.35 -import org.openide.modules.ModuleInfo;
1.36 import org.openide.util.*;
1.37
1.38 import static org.netbeans.modules.modulemanagement.Bundle.*;
1.39 @@ -222,47 +211,8 @@
1.40 support.doOperation(null);
1.41 }
1.42
1.43 - @NbBundle.Messages({
1.44 - "MSG_UpdateNoMatch=Nothing to update. The pattern {0} has no match among available updates.",
1.45 - "MSG_Update=Will update {0}@{1} to version {2}"
1.46 - })
1.47 private void updateModules(Env env, String[] pattern) throws CommandException {
1.48 - Pattern[] pats = findMatcher(env, pattern);
1.49 -
1.50 - List<UpdateUnit> units = UpdateManager.getDefault().getUpdateUnits();
1.51 - OperationContainer<InstallSupport> operate = OperationContainer.createForInternalUpdate();
1.52 - for (UpdateUnit uu : units) {
1.53 - if (uu.getInstalled() == null) {
1.54 - continue;
1.55 - }
1.56 - final List<UpdateElement> updates = uu.getAvailableUpdates();
1.57 - if (updates.isEmpty()) {
1.58 - continue;
1.59 - }
1.60 - if (!matches(uu.getCodeName(), pats)) {
1.61 - continue;
1.62 - }
1.63 - final UpdateElement ue = updates.get(0);
1.64 - env.getOutputStream().println(
1.65 - Bundle.MSG_Update(uu.getCodeName(), uu.getInstalled().getSpecificationVersion(), ue.getSpecificationVersion()
1.66 - ));
1.67 - operate.add(ue);
1.68 - }
1.69 - final InstallSupport support = operate.getSupport();
1.70 - if (support == null) {
1.71 - env.getOutputStream().println(Bundle.MSG_UpdateNoMatch(Arrays.asList(pats)));
1.72 - return;
1.73 - }
1.74 - try {
1.75 - final Validator res1 = support.doDownload(null, true);
1.76 - Installer res2 = support.doValidate(res1, null);
1.77 - Restarter res3 = support.doInstall(res2, null);
1.78 - if (res3 != null) {
1.79 - support.doRestart(res3, null);
1.80 - }
1.81 - } catch (OperationException ex) {
1.82 - throw (CommandException)new CommandException(33, ex.getMessage()).initCause(ex);
1.83 - }
1.84 + installModules(env, pattern, true);
1.85 }
1.86
1.87 @NbBundle.Messages({
1.88 @@ -292,15 +242,21 @@
1.89 return false;
1.90 }
1.91
1.92 + private void install(Env env, String[] pattern) throws CommandException {
1.93 + installModules(env, pattern, false);
1.94 + }
1.95 +
1.96 @NbBundle.Messages({
1.97 "MSG_Installing=Installing {0}@{1}",
1.98 - "MSG_InstallNoMatch=Cannot install. No match for {0}."
1.99 + "MSG_InstallNoMatch=Cannot install. No match for {0}.",
1.100 + "MSG_UpdateNoMatch=Nothing to update. The pattern {0} has no match among available updates.",
1.101 + "MSG_Update=Will update {0}@{1} to version {2}"
1.102 })
1.103 - private void install(Env env, String[] pattern) throws CommandException {
1.104 + private void installModules(Env env, String[] pattern, boolean update) throws CommandException {
1.105 Pattern[] pats = findMatcher(env, pattern);
1.106
1.107 List<UpdateUnit> units = UpdateManager.getDefault().getUpdateUnits();
1.108 - OperationContainer<InstallSupport> operate = OperationContainer.createForInstall();
1.109 + OperationContainer<OperationSupport> operate = OperationContainer.createForDirectInstall();
1.110 for (UpdateUnit uu : units) {
1.111 if (uu.getInstalled() != null) {
1.112 continue;
1.113 @@ -312,21 +268,29 @@
1.114 continue;
1.115 }
1.116 UpdateElement ue = uu.getAvailableUpdates().get(0);
1.117 - env.getOutputStream().println(
1.118 + if (update) {
1.119 + env.getOutputStream().println(
1.120 + Bundle.MSG_Update(uu.getCodeName(), uu.getInstalled().getSpecificationVersion(), ue.getSpecificationVersion()));
1.121 + } else {
1.122 + env.getOutputStream().println(
1.123 Bundle.MSG_Installing(uu.getCodeName(), ue.getSpecificationVersion()));
1.124 + }
1.125 operate.add(ue);
1.126 }
1.127 - final InstallSupport support = operate.getSupport();
1.128 + final OperationSupport support = operate.getSupport();
1.129 if (support == null) {
1.130 - env.getOutputStream().println(Bundle.MSG_InstallNoMatch(Arrays.asList(pats)));
1.131 + if (update) {
1.132 + env.getOutputStream().println(Bundle.MSG_UpdateNoMatch(Arrays.asList(pats)));
1.133 + } else {
1.134 + env.getOutputStream().println(Bundle.MSG_InstallNoMatch(Arrays.asList(pats)));
1.135 + }
1.136 return;
1.137 }
1.138 try {
1.139 - final Validator res1 = support.doDownload(null, true);
1.140 - Installer res2 = support.doValidate(res1, null);
1.141 - Restarter res3 = support.doInstall(res2, null);
1.142 - if (res3 != null) {
1.143 - support.doRestart(res3, null);
1.144 + Restarter restarter = support.doOperation(null);
1.145 + assert restarter == null;
1.146 + if (restarter != null) {
1.147 + support.doRestart(restarter, null);
1.148 }
1.149 } catch (OperationException ex) {
1.150 throw (CommandException) new CommandException(33, ex.getMessage()).initCause(ex);