提交 0dd2dbc0 编写于 作者: K Kohsuke Kawaguchi

[FIXED JENKINS-23197] add timestamp to node-offline message

Merge pull request #1605.
......@@ -55,6 +55,9 @@ Upcoming changes</a>
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=rfe>
add datestamp to node-offline message
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-23917">issue 23917</a>)
<li class=rfe>
Larger minimum popup menu height.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-27067">issue 27067</a>)
......
......@@ -29,11 +29,13 @@ import hudson.Functions;
import hudson.model.Computer;
import hudson.model.User;
import org.acegisecurity.Authentication;
import org.jvnet.localizer.Localizable;
import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.export.Exported;
import javax.annotation.Nonnull;
import java.util.Date;
/**
* Represents a cause that puts a {@linkplain Computer#isOffline() computer offline}.
*
......@@ -41,13 +43,34 @@ import org.kohsuke.stapler.export.Exported;
* <p>
* {@link OfflineCause} must have <tt>cause.jelly</tt> that renders a cause
* into HTML. This is used to tell users why the node is put offline.
* This view should render a block element like DIV.
* This view should render a block element like DIV.
*
* @author Kohsuke Kawaguchi
* @since 1.320
*/
@ExportedBean
public abstract class OfflineCause {
protected final long timestamp = System.currentTimeMillis();
/**
* Timestamp in which the event happened.
*
* @since 1.612
*/
@Exported
public long getTimestamp() {
return timestamp;
}
/**
* Same as {@link #getTimestamp()} but in a different type.
*
* @since 1.612
*/
public final @Nonnull Date getTime() {
return new Date(timestamp);
}
/**
* {@link OfflineCause} that renders a static text,
* but without any further UI.
......
......@@ -23,6 +23,13 @@ THE SOFTWARE.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<p class="warning"><j:out value="${it}" /></p>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<div class="warning">
<div class="timestamp">
<i:formatDate value="${it.time}" type="both" dateStyle="medium" timeStyle="medium"/>
</div>
<div class="message">
<j:out value="${it}" />
</div>
</div>
</j:jelly>
......@@ -103,7 +103,7 @@ public class NodeTest {
computer.doToggleOffline("original message");
cause = (UserCause) computer.getOfflineCause();
assertEquals("Disconnected by someone@somewhere.com : original message", cause.toString());
assertTrue(cause.toString(), cause.toString().matches("^.*?Disconnected by someone@somewhere.com : original message"));
assertEquals(someone, cause.getUser());
final User root = User.get("root@localhost");
......@@ -111,7 +111,7 @@ public class NodeTest {
computer.doChangeOfflineCause("new message");
cause = (UserCause) computer.getOfflineCause();
assertEquals("Disconnected by root@localhost : new message", cause.toString());
assertTrue(cause.toString(), cause.toString().matches("^.*?Disconnected by root@localhost : new message"));
assertEquals(root, cause.getUser());
computer.doToggleOffline(null);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册