Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
野花太放肆
jenkins
提交
c1c97974
J
jenkins
项目概览
野花太放肆
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c1c97974
编写于
2月 05, 2013
作者:
R
Ryan Campbell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
API for updating update sites programatically, enabling automated plugin updates and installation.
上级
9a95d233
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
111 addition
and
2 deletion
+111
-2
core/src/main/java/hudson/model/UpdateCenter.java
core/src/main/java/hudson/model/UpdateCenter.java
+40
-0
core/src/main/java/hudson/model/UpdateSite.java
core/src/main/java/hudson/model/UpdateSite.java
+49
-2
test/src/test/java/hudson/model/UpdateSiteTest.java
test/src/test/java/hudson/model/UpdateSiteTest.java
+16
-0
test/src/test/resources/hudson/model/update-center.json
test/src/test/resources/hudson/model/update-center.json
+3
-0
test/src/test/resources/hudson/model/update-center.json.html
test/src/test/resources/hudson/model/update-center.json.html
+3
-0
未找到文件。
core/src/main/java/hudson/model/UpdateCenter.java
浏览文件 @
c1c97974
...
...
@@ -41,6 +41,7 @@ import hudson.model.UpdateSite.Plugin;
import
hudson.model.listeners.SaveableListener
;
import
hudson.security.ACL
;
import
hudson.util.DaemonThreadFactory
;
import
hudson.util.FormValidation
;
import
hudson.util.HttpResponses
;
import
hudson.util.IOException2
;
import
hudson.util.PersistedList
;
...
...
@@ -76,6 +77,7 @@ import java.util.Map;
import
java.util.Set
;
import
java.util.TreeSet
;
import
java.util.Vector
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Future
;
...
...
@@ -130,6 +132,18 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas
}
}));
/**
* An {@link ExecutorService} for updating UpdateSites.
*/
protected
final
ExecutorService
updateService
=
Executors
.
newCachedThreadPool
(
new
DaemonThreadFactory
(
new
ThreadFactory
()
{
public
Thread
newThread
(
Runnable
r
)
{
Thread
t
=
new
Thread
(
r
);
t
.
setName
(
"Update site data downloader"
);
return
t
;
}
}));
/**
* List of created {@link UpdateCenterJob}s. Access needs to be synchronized.
*/
...
...
@@ -602,6 +616,32 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas
return
new
ArrayList
<
Plugin
>(
pluginMap
.
values
());
}
/**
* Ensure that all UpdateSites are up to date, without requiring a user to
* browse to the instance.
*
* @return a list of {@link FormValidation} for each updated Update Site
* @throws ExecutionException
* @throws InterruptedException
* @since 1.501
*
*/
public
List
<
FormValidation
>
updateAllSites
()
throws
InterruptedException
,
ExecutionException
{
List
<
Future
<
FormValidation
>>
futures
=
new
ArrayList
<
Future
<
FormValidation
>>();
for
(
UpdateSite
site
:
getSites
())
{
Future
<
FormValidation
>
future
=
site
.
updateDirectly
();
if
(
future
!=
null
)
{
futures
.
add
(
future
);
}
}
List
<
FormValidation
>
results
=
new
ArrayList
<
FormValidation
>();
for
(
Future
<
FormValidation
>
f
:
futures
)
{
results
.
add
(
f
.
get
());
}
return
results
;
}
/**
...
...
core/src/main/java/hudson/model/UpdateSite.java
浏览文件 @
c1c97974
...
...
@@ -27,6 +27,7 @@ package hudson.model;
import
hudson.PluginManager
;
import
hudson.PluginWrapper
;
import
hudson.ProxyConfiguration
;
import
hudson.lifecycle.Lifecycle
;
import
hudson.model.UpdateCenter.UpdateCenterJob
;
import
hudson.util.FormValidation
;
...
...
@@ -41,14 +42,18 @@ import net.sf.json.JSONException;
import
net.sf.json.JSONObject
;
import
org.kohsuke.stapler.DataBoundConstructor
;
import
org.kohsuke.stapler.HttpResponse
;
import
org.kohsuke.stapler.Stapler
;
import
org.kohsuke.stapler.StaplerRequest
;
import
org.kohsuke.stapler.export.Exported
;
import
org.kohsuke.stapler.export.ExportedBean
;
import
org.kohsuke.stapler.interceptor.RequirePOST
;
import
java.io.BufferedInputStream
;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.security.GeneralSecurityException
;
import
java.util.ArrayList
;
import
java.util.Collections
;
...
...
@@ -57,6 +62,7 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.TreeMap
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.Future
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
...
...
@@ -144,12 +150,53 @@ public class UpdateSite {
return
dataTimestamp
;
}
/**
* Update the json file from the given URL if the file
* does not exist, or is otherwise due for update.
*
* @return null if no updates are necessary, or the future result
* @since 1.501
*/
public
Future
<
FormValidation
>
updateDirectly
()
{
if
(!
getDataFile
().
exists
()
||
isDue
())
{
return
Jenkins
.
getInstance
().
getUpdateCenter
().
updateService
.
submit
(
new
Callable
<
FormValidation
>()
{
public
FormValidation
call
()
throws
Exception
{
URL
src
=
new
URL
(
getUrl
());
URLConnection
conn
=
ProxyConfiguration
.
open
(
src
);
BufferedInputStream
is
=
new
BufferedInputStream
(
conn
.
getInputStream
());
try
{
// remove non-json characters from update center
is
.
mark
(
1
);
for
(
int
r
=
is
.
read
();
r
>
0
&&
(
char
)
r
!=
'{'
;
r
=
is
.
read
())
{
is
.
mark
(
1
);
}
is
.
reset
();
return
updateData
(
is
);
}
finally
{
if
(
is
!=
null
)
is
.
close
();
}
}
});
}
return
null
;
}
/**
* This is the endpoint that receives the update center data file from the browser.
*/
public
FormValidation
doPostBack
(
StaplerRequest
req
)
throws
IOException
,
GeneralSecurityException
{
dataTimestamp
=
System
.
currentTimeMillis
();
String
json
=
IOUtils
.
toString
(
req
.
getInputStream
(),
"UTF-8"
);
return
updateData
(
req
.
getInputStream
());
}
private
FormValidation
updateData
(
java
.
io
.
InputStream
is
)
throws
IOException
{
dataTimestamp
=
System
.
currentTimeMillis
();
String
json
=
IOUtils
.
toString
(
is
,
"UTF-8"
);
JSONObject
o
=
JSONObject
.
fromObject
(
json
);
int
v
=
o
.
getInt
(
"updateCenterVersion"
);
...
...
@@ -158,7 +205,7 @@ public class UpdateSite {
if
(
signatureCheck
)
{
FormValidation
e
=
verifySignature
(
o
);
if
(
e
.
kind
!=
Kind
.
OK
)
{
if
(
e
.
kind
!=
Kind
.
OK
&&
Stapler
.
getCurrentRequest
()
!=
null
)
{
LOGGER
.
severe
(
e
.
renderHtml
());
return
e
;
}
...
...
test/src/test/java/hudson/model/UpdateSiteTest.java
浏览文件 @
c1c97974
...
...
@@ -28,6 +28,7 @@ import com.gargoylesoftware.htmlunit.HttpMethod;
import
com.gargoylesoftware.htmlunit.Page
;
import
com.gargoylesoftware.htmlunit.WebRequestSettings
;
import
hudson.model.UpdateSite.Data
;
import
hudson.util.FormValidation
;
import
hudson.util.PersistedList
;
import
java.net.URL
;
import
java.util.Arrays
;
...
...
@@ -64,4 +65,19 @@ public class UpdateSiteTest {
assertEquals
(
"http://nowhere.net/dummy.hpi"
,
data
.
plugins
.
get
(
"dummy"
).
url
);
}
@Test
public
void
updateDirectlyWithJson
()
throws
Exception
{
UpdateSite
us
=
new
UpdateSite
(
"default"
,
UpdateSiteTest
.
class
.
getResource
(
"update-center.json"
).
toExternalForm
());
assertNull
(
us
.
getPlugin
(
"AdaptivePlugin"
));
FormValidation
result
=
us
.
updateDirectly
().
get
();
assertTrue
(
result
.
equals
(
FormValidation
.
ok
()));
assertNotNull
(
us
.
getPlugin
(
"AdaptivePlugin"
));
}
@Test
public
void
updateDirectlyWithHtml
()
throws
Exception
{
UpdateSite
us
=
new
UpdateSite
(
"default"
,
UpdateSiteTest
.
class
.
getResource
(
"update-center.json"
).
toExternalForm
());
assertNull
(
us
.
getPlugin
(
"AdaptivePlugin"
));
FormValidation
result
=
us
.
updateDirectly
().
get
();
assertTrue
(
result
.
equals
(
FormValidation
.
ok
()));
assertNotNull
(
us
.
getPlugin
(
"AdaptivePlugin"
));
}
}
test/src/test/resources/hudson/model/update-center.json
0 → 100644
浏览文件 @
c1c97974
此差异已折叠。
点击以展开。
test/src/test/resources/hudson/model/update-center.json.html
0 → 100644
浏览文件 @
c1c97974
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录