提交 a7a4104f 编写于 作者: K kohsuke

defining more fields related to capturing installation status

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@9886 71c3de6d-444a-0410-be80-ed276b4c234a
上级 b2c1a8de
......@@ -15,6 +15,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
......@@ -78,6 +79,11 @@ public class UpdateCenter {
*/
private final Vector<InstallationStatus> installationStatuses = new Vector<InstallationStatus>();
/**
* Plugin being installed, if any.
*/
private volatile Installing installing;
/**
* Returns true if it's time for us to check for new version.
*/
......@@ -88,6 +94,32 @@ public class UpdateCenter {
return due;
}
/**
* Returns the list of {@link InstallationStatus} representing completed installation attempts.
*/
public List<InstallationStatus> getInstallationStatuses() {
synchronized (installationStatuses) {
return new ArrayList<InstallationStatus>(installationStatuses);
}
}
/**
* If there's any installation in progress, return it. Otherwise null.
*/
public Installing getInstalling() {
return installing;
}
/**
* Gets the list of plugins whose installation is pending.
*
* @return
* can be empty but never null.
*/
public Plugin[] getPending() {
return installerService.getQueue().toArray(new Plugin[0]);
}
/**
* This is the endpoint that receives the update center data file from the browser.
*/
......@@ -273,7 +305,9 @@ public class UpdateCenter {
// In the future if we are to open up update center to 3rd party, we need more elaborate scheme
// like signing to ensure the safety of the bits.
CountingInputStream in = new CountingInputStream(new URL(url).openStream());
URLConnection con = new URL(url).openConnection();
int total = con.getContentLength();
CountingInputStream in = new CountingInputStream(con.getInputStream());
byte[] buf = new byte[8192];
int len;
......@@ -283,6 +317,8 @@ public class UpdateCenter {
while((len=in.read(buf))>=0) {
out.write(buf,0,len);
installing = new Installing(Plugin.this,
total==-1 ? -1 : in.getCount()*100/total );
}
in.close();
......@@ -299,6 +335,8 @@ public class UpdateCenter {
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Failed to install "+name,e);
installationStatuses.add(new Failure(Plugin.this,e));
} finally {
installing = null;
}
}
});
......@@ -307,6 +345,8 @@ public class UpdateCenter {
/**
* Indicates the status or the result of a plugin installation.
* <p>
* Instances of this class is immutable.
*/
public abstract class InstallationStatus {
/**
......@@ -340,6 +380,21 @@ public class UpdateCenter {
}
}
/**
* Installation of a plugin is in progress.
*/
public class Installing extends InstallationStatus {
/**
* % completed download, or -1 if the percentage is not known.
*/
public final int percentage;
public Installing(Plugin plugin, int percentage) {
super(plugin);
this.percentage = percentage;
}
}
private static final long DAY = DAYS.toMillis(1);
private static final Logger LOGGER = Logger.getLogger(UpdateCenter.class.getName());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册