Browse Source

Some finishing touches to the updater.

Fix the some copy and paste errors.
Add to the updater module.
Move the pattern to a field.
pull/674/head
Greg Holmes 8 years ago
parent
commit
eb584e6bd3

+ 13
- 0
src/com/dmdirc/updater/UpdaterModule.java View File

@@ -28,6 +28,7 @@ import com.dmdirc.interfaces.config.IdentityController;
28 28
 import com.dmdirc.updater.checking.CheckResultConsolidator;
29 29
 import com.dmdirc.updater.checking.DMDircCheckStrategy;
30 30
 import com.dmdirc.updater.checking.NaiveConsolidator;
31
+import com.dmdirc.updater.checking.NightlyChecker;
31 32
 import com.dmdirc.updater.checking.UpdateCheckStrategy;
32 33
 import com.dmdirc.updater.components.ClientComponent;
33 34
 import com.dmdirc.updater.components.DefaultsComponent;
@@ -188,4 +189,16 @@ public class UpdaterModule {
188 189
         return strategy;
189 190
     }
190 191
 
192
+    /**
193
+     * Provides an {@link UpdateCheckStrategy} that the client should use for nightlies.
194
+     *
195
+     * @param strategy The strategy to provide.
196
+     *
197
+     * @return The strategy to use in the client.
198
+     */
199
+    @Provides(type = Provides.Type.SET)
200
+    public UpdateCheckStrategy getCheckStrategy(final NightlyChecker strategy) {
201
+        return strategy;
202
+    }
203
+
191 204
 }

+ 8
- 5
src/com/dmdirc/updater/checking/NightlyChecker.java View File

@@ -41,6 +41,7 @@ import java.util.HashMap;
41 41
 import java.util.List;
42 42
 import java.util.Map;
43 43
 import java.util.Objects;
44
+import java.util.function.Function;
44 45
 import java.util.regex.Matcher;
45 46
 import java.util.regex.Pattern;
46 47
 import java.util.stream.Collectors;
@@ -58,6 +59,9 @@ import static com.dmdirc.ClientModule.GlobalConfig;
58 59
 public class NightlyChecker implements UpdateCheckStrategy {
59 60
 
60 61
     private static final Logger LOG = LoggerFactory.getLogger(NightlyChecker.class);
62
+    /** Name matching regex. */
63
+    private final Pattern pattern = Pattern.compile(
64
+            "^(.*?)-([^-]+(-[0-9]+-g[0-9a-f]+)?)(-SNAPSHOT).jar?$");
61 65
     /** The URL to request to check for updates. */
62 66
     private static final String UPDATE_URL = "https://nightlies.dmdirc.com/json/latest";
63 67
     /** The update channel to check for updates on. */
@@ -74,12 +78,12 @@ public class NightlyChecker implements UpdateCheckStrategy {
74 78
     @Inject
75 79
     public NightlyChecker(@GlobalConfig final AggregateConfigProvider configProvider,
76 80
             final Downloader downloader) {
77
-        configProvider.getBinder().bind(this, DMDircCheckStrategy.class);
81
+        configProvider.getBinder().bind(this, NightlyChecker.class);
78 82
         this.downloader = downloader;
79 83
     }
80 84
 
81 85
     /**
82
-     * Sets the channel which will be used by the {@link DMDircCheckStrategy}.
86
+     * Sets the channel which will be used by the {@link NightlyChecker}.
83 87
      *
84 88
      * @param channel The new channel to use
85 89
      */
@@ -110,8 +114,7 @@ public class NightlyChecker implements UpdateCheckStrategy {
110 114
         resultsList.stream()
111 115
                 .filter(Objects::nonNull) //This is incase the JSON is broken
112 116
                 .forEach(e -> {
113
-            final Matcher matcher = Pattern.compile(
114
-                    "^(.*?)-([^-]+(-[0-9]+-g[0-9a-f]+)?)(-SNAPSHOT).jar?$").matcher(e.getName());
117
+            final Matcher matcher = pattern.matcher(e.getName());
115 118
             if (matcher.matches()) {
116 119
                 e.setOtherName(matcher.group(1));
117 120
                 e.setVersion(new Version(matcher.group(2)));
@@ -119,7 +122,7 @@ public class NightlyChecker implements UpdateCheckStrategy {
119 122
             }
120 123
         });
121 124
         final Map<String, NightlyResult> resultsMap = resultsList.stream()
122
-                .collect(Collectors.toMap(NightlyResult::getOtherName, n -> n));
125
+                .collect(Collectors.toMap(NightlyResult::getOtherName, Function.identity()));
123 126
         final Map<UpdateComponent, UpdateCheckResult> returns = new HashMap<>();
124 127
         components.forEach(e -> {
125 128
             if (resultsMap.containsKey(e.getName())) {

Loading…
Cancel
Save