Skip to content

Commit a00482d

Browse files
committed
Merge branch 'updater-v1'
* HTTPS check, use appropriate URLs * refresh update site URLs... .. if the protocol does not match the system .. if the URL got updated on the list of update sites
2 parents e54f769 + 85632fa commit a00482d

16 files changed

+904
-156
lines changed

pom.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@
4242
<role>maintainer</role>
4343
</roles>
4444
</developer>
45+
<developer>
46+
<id>frauzufall</id>
47+
<name>Deborah Schmidt</name>
48+
<url>https://imagej.net/User:Frauzufall</url>
49+
<roles>
50+
<role>developer</role>
51+
<role>debugger</role>
52+
<role>reviewer</role>
53+
<role>support</role>
54+
<role>maintainer</role>
55+
</roles>
56+
</developer>
4557
</developers>
4658
<contributors>
4759
<contributor>
@@ -72,6 +84,11 @@
7284
<url>https://imagej.net/User:Hinerm</url>
7385
<properties><id>hinerm</id></properties>
7486
</contributor>
87+
<contributor>
88+
<name>Matthias Arzt</name>
89+
<url>https://imagej.net/User:Maarzt</url>
90+
<properties><id>maarzt</id></properties>
91+
</contributor>
7592
</contributors>
7693

7794
<mailingLists>
@@ -129,6 +146,12 @@ Institute of Molecular Cell Biology and Genetics.</license.copyrightOwners>
129146
<artifactId>scijava-common</artifactId>
130147
</dependency>
131148

149+
<dependency>
150+
<groupId>commons-lang</groupId>
151+
<artifactId>commons-lang</artifactId>
152+
<version>2.6</version>
153+
</dependency>
154+
132155
<!-- Test scope dependencies -->
133156
<dependency>
134157
<groupId>junit</groupId>

src/main/java/net/imagej/updater/CommandLine.java

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,16 @@
6666
import net.imagej.updater.FileObject.Status;
6767
import net.imagej.updater.FileObject.Version;
6868
import net.imagej.updater.FilesCollection.Filter;
69-
import net.imagej.updater.util.Downloadable;
70-
import net.imagej.updater.util.Downloader;
71-
import net.imagej.updater.util.Progress;
72-
import net.imagej.updater.util.StderrProgress;
73-
import net.imagej.updater.util.UpdaterUserInterface;
74-
import net.imagej.updater.util.UpdaterUtil;
69+
import net.imagej.updater.util.*;
7570

7671
import org.scijava.log.LogService;
7772
import org.scijava.util.AppUtils;
7873
import org.scijava.util.FileUtils;
7974
import org.scijava.util.IteratorPlus;
8075
import org.scijava.util.POM;
76+
import org.xml.sax.SAXException;
77+
78+
import javax.xml.parsers.ParserConfigurationException;
8179

8280
/**
8381
* This is the command-line interface into the ImageJ Updater.
@@ -1286,6 +1284,46 @@ public void removeUploadSite(final String... names) {
12861284
}
12871285
}
12881286

1287+
public void refreshUpdateSites(List<String> list) {
1288+
boolean simulate = false, updateall = false;
1289+
while (list.size() > 0 && list.get(0).startsWith("-")) {
1290+
final String option = list.remove(0);
1291+
if ("--simulate".equals(option)) {
1292+
simulate = true;
1293+
continue;
1294+
}
1295+
if ("--updateall".equals(option)) {
1296+
updateall = true;
1297+
continue;
1298+
}
1299+
throw die("Unknown option: " + option);
1300+
}
1301+
try {
1302+
files.tryLoadingCollection();
1303+
} catch (ParserConfigurationException | SAXException e) {
1304+
e.printStackTrace();
1305+
}
1306+
HTTPSUtil.checkHTTPSSupport(log);
1307+
List< URLChange > urlChanges = AvailableSites.initializeAndAddSites(files, log);
1308+
if(updateall) {
1309+
urlChanges.forEach( change -> change.setApproved(true));
1310+
}
1311+
else {
1312+
urlChanges.forEach( change -> change.setApproved(change.isRecommended()));
1313+
}
1314+
urlChanges.forEach(change -> {
1315+
UpdateSite site = change.updateSite();
1316+
if(change.isApproved()) {
1317+
System.out.println(" [UPDATE] " + site.getName() + ": " + site.getURL() + " -> " + change.getNewURL());
1318+
} else {
1319+
System.out.println(" [KEEP] " + site.getName() + ": " + site.getURL() + " (new: " + change.getNewURL() + ")");
1320+
}
1321+
});
1322+
if(!simulate) {
1323+
AvailableSites.applySitesURLUpdates(files, urlChanges);
1324+
}
1325+
}
1326+
12891327
@Deprecated
12901328
public static CommandLine getInstance() {
12911329
try {
@@ -1359,7 +1397,8 @@ public void usage() {
13591397
+ "\tupload-complete-site [--simulate] [--force] [--force-shadow] [--platforms <platform>[,<platform>...]] <name>\n"
13601398
+ "\tlist-update-sites [<nick>...]\n"
13611399
+ "\tadd-update-site <nick> <url> [<host> <upload-directory>]\n"
1362-
+ "\tedit-update-site <nick> <url> [<host> <upload-directory>]");
1400+
+ "\tedit-update-site <nick> <url> [<host> <upload-directory>]\n"
1401+
+ "\trefresh-update-sites [--simulate] [--updateall]");
13631402
}
13641403

13651404
public static void main(final String... args) {
@@ -1468,6 +1507,8 @@ private static void main(final File ijDir, final int columnCount,
14681507
instance.addOrEditUploadSite(makeList(args, 1), false);
14691508
} else if (command.equals("remove-update-site")) {
14701509
instance.removeUploadSite(makeList(args, 1));
1510+
} else if (command.equals("refresh-update-sites")) {
1511+
instance.refreshUpdateSites(makeList(args, 1));
14711512
// hidden commands, i.e. not for public consumption
14721513
} else if (command.equals("history")) {
14731514
instance.history(makeList(args, 1));

src/main/java/net/imagej/updater/DefaultUpdateService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
import net.imagej.updater.util.AvailableSites;
4040

41+
import net.imagej.updater.util.HTTPSUtil;
4142
import org.scijava.app.AppService;
4243
import org.scijava.command.CommandService;
4344
import org.scijava.event.EventHandler;
@@ -122,6 +123,7 @@ private synchronized void initFilesCollection() {
122123
final FilesCollection fc = new FilesCollection(rootDir());
123124

124125
// parse the official list of update sites
126+
HTTPSUtil.checkHTTPSSupport(log);
125127
AvailableSites.initializeAndAddSites(fc);
126128

127129
// parse the user's update site database (db.xml.gz)

src/main/java/net/imagej/updater/FilesCollection.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@
6363
import net.imagej.updater.action.Remove;
6464
import net.imagej.updater.action.Uninstall;
6565
import net.imagej.updater.action.Upload;
66-
import net.imagej.updater.util.DependencyAnalyzer;
67-
import net.imagej.updater.util.Progress;
68-
import net.imagej.updater.util.UpdateCanceledException;
69-
import net.imagej.updater.util.UpdaterUtil;
66+
import net.imagej.updater.util.*;
7067

7168
import org.scijava.log.LogService;
7269
import org.xml.sax.SAXException;
@@ -1123,7 +1120,7 @@ public void remove() {
11231120
};
11241121
}
11251122

1126-
public String downloadIndexAndChecksum(final Progress progress) throws ParserConfigurationException, SAXException {
1123+
public void tryLoadingCollection() throws ParserConfigurationException, SAXException {
11271124
try {
11281125
read();
11291126
}
@@ -1132,12 +1129,14 @@ public String downloadIndexAndChecksum(final Progress progress) throws ParserCon
11321129
// make sure that the Fiji update site is enabled
11331130
UpdateSite fiji = getUpdateSite("Fiji", true);
11341131
if (fiji == null) {
1135-
addUpdateSite("Fiji", "http://update.fiji.sc/", null, null, 0);
1132+
addUpdateSite("Fiji", HTTPSUtil.getProtocol() + "update.fiji.sc/", null, null, 0);
11361133
}
11371134
}
11381135
}
11391136
catch (final IOException e) { /* ignore */ }
1137+
}
11401138

1139+
public String reloadCollectionAndChecksum(final Progress progress) {
11411140
// clear the files
11421141
clear();
11431142

@@ -1146,8 +1145,8 @@ public String downloadIndexAndChecksum(final Progress progress) throws ParserCon
11461145
try {
11471146
downloader.start(false);
11481147
} catch (final UpdateCanceledException e) {
1149-
downloader.done();
1150-
throw e;
1148+
downloader.done();
1149+
throw e;
11511150
}
11521151
new Checksummer(this, progress).updateFromLocal();
11531152

@@ -1163,6 +1162,11 @@ public String downloadIndexAndChecksum(final Progress progress) throws ParserCon
11631162
return downloader.getWarnings();
11641163
}
11651164

1165+
public String downloadIndexAndChecksum(final Progress progress) throws ParserConfigurationException, SAXException {
1166+
tryLoadingCollection();
1167+
return reloadCollectionAndChecksum(progress);
1168+
}
1169+
11661170
public List<Conflict> getConflicts() {
11671171
return conflicts;
11681172
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2009 - 2019 Board of Regents of the University of
6+
* Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
7+
* Institute of Molecular Cell Biology and Genetics.
8+
* %%
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
* #L%
30+
*/
31+
32+
package net.imagej.updater;
33+
34+
import java.util.Optional;
35+
36+
/**
37+
* Class indicating automated changes to an update site.
38+
* These changes need to get approved for active updates.
39+
*
40+
* @author Deborah Schmidt
41+
*/
42+
public class URLChange {
43+
44+
private final UpdateSite site;
45+
46+
private final String newUrl;
47+
48+
private final boolean recommended;
49+
50+
private boolean approved = false;
51+
52+
/**
53+
* Proposes a new URL for this update site. The new URL will not be marked as recommended if:
54+
* - the current update site URL is a mirror URL OR
55+
* - the site is on the list of available update sites and the URL got manually modified
56+
* @param newUrl the new URL
57+
*/
58+
public static Optional< URLChange > create(UpdateSite site, String newUrl) {
59+
newUrl = UpdateSite.format(newUrl);
60+
if(site.getURL().equals(newUrl)) return Optional.empty();
61+
return Optional.of( new URLChange(site, newUrl) );
62+
}
63+
64+
private URLChange(UpdateSite site, String newUrl) {
65+
this.site = site;
66+
this.newUrl = newUrl;
67+
this.recommended = !site.shouldKeepURL() && ! isMirror(site);
68+
this.approved = recommended && ! site.isActive();
69+
}
70+
71+
public UpdateSite updateSite()
72+
{
73+
return site;
74+
}
75+
76+
public boolean isApproved() {
77+
return approved;
78+
}
79+
80+
public void applyIfApproved() {
81+
if(newUrl == null) return;
82+
if(approved) {
83+
site.setURL(newUrl);
84+
site.setKeepURL(false);
85+
}
86+
}
87+
88+
public String toString() {
89+
return "new URL: " + newUrl + ", " + " approved: " + approved;
90+
}
91+
92+
public void setApproved(boolean approved) {
93+
this.approved = approved;
94+
}
95+
96+
public String getNewURL() {
97+
return newUrl;
98+
}
99+
100+
public boolean isRecommended() {
101+
return recommended;
102+
}
103+
104+
/**
105+
* Helper function checking if an update site URL is a known mirror URL.
106+
*/
107+
private static boolean isMirror(UpdateSite site) {
108+
// NB: This might be changed into an extensible list of mirrors in the future.
109+
return site.getURL().startsWith("https://downloads.micron.ox.ac.uk");
110+
}
111+
112+
}

src/main/java/net/imagej/updater/UpToDate.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545

4646
import javax.xml.parsers.ParserConfigurationException;
4747

48+
import net.imagej.updater.util.AvailableSites;
49+
import net.imagej.updater.util.HTTPSUtil;
4850
import net.imagej.updater.util.UpdaterUtil;
4951

5052
import org.scijava.util.AppUtils;
@@ -108,6 +110,10 @@ public static Result check(final File ijRoot) throws IOException,
108110
plugins.read();
109111
}
110112
catch (final FileNotFoundException e) { /* ignore */}
113+
HTTPSUtil.checkHTTPSSupport(null);
114+
if(AvailableSites.hasUpdateSiteURLUpdates(plugins)) {
115+
return Result.UPDATEABLE;
116+
}
111117
for (final String name : plugins.getUpdateSiteNames(false)) {
112118
final UpdateSite updateSite = plugins.getUpdateSite(name, true);
113119
final long lastModified =

0 commit comments

Comments
 (0)