Skip to content
Permalink
Browse files

[JENKINS-38085] Revert to default way of loading the script and CSS

A custom approach was previously used to load the script and CSS for displaying
the timestamps. It caused the script and CSS to be reloaded when the Timestamper
plugin is upgraded or downgraded, rather than being cached for the next day.

It seems this doesn't work for everyone (JENKINS-38085), so I'm reverting back
to the default behaviour. Note that it is known to work with HTTPS and through a
HTTPS proxy (JENKINS-35315) at least for some users.

As a result, the TimestampAnnotatorFactory class will have to be manually
renamed each time the script or CSS is changed in a new release.
  • Loading branch information
StevenGBrown committed Sep 14, 2016
1 parent c31dc95 commit bb7e2ce76a86127ffa3de95a4aec9d6419a38412
@@ -24,28 +24,14 @@
package hudson.plugins.timestamper.annotator;

import hudson.Extension;
import hudson.Util;
import hudson.PluginWrapper;
import hudson.console.ConsoleAnnotator;
import hudson.console.ConsoleAnnotatorFactory;
import hudson.plugins.timestamper.format.TimestampFormat;
import hudson.plugins.timestamper.format.TimestampFormatProvider;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;

import jenkins.YesNoMaybe;
import jenkins.model.Jenkins;

import org.kohsuke.stapler.ResponseImpl;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.WebMethod;

import com.google.common.net.HttpHeaders;

/**
* Provides the initial {@link TimestampAnnotator} for an annotated console
@@ -113,70 +99,4 @@ public String getPlainTextUrl() {
TimestampFormat format = TimestampFormatProvider.get();
return format.getPlainTextUrl();
}

/**
* {@inheritDoc}
*/
@Override
public boolean hasScript() {
return true;
}

/**
* {@inheritDoc}
*/
@Override
public boolean hasStylesheet() {
return true;
}

/**
* {@inheritDoc}
*/
@Override
@WebMethod(name = "script.js")
public void doScriptJs(StaplerRequest req, StaplerResponse rsp)
throws IOException, ServletException {

// This URL is cached for one day. Redirect to a URL which includes the
// plug-in version and is cached for 1 year. The script will be downloaded
// again when the plug-in version changes.
String url = req.getContextPath() + getResourcePath()
+ "/plugin/timestamper/annotator.js";

// Send the redirect manually and allow the relative URL to be handled by
// the browser. Do not use the sendRedirect method, which resolves the
// relative URL to an absolute URL within the servlet container and so
// gives the wrong result when running behind a proxy. Redirects to
// relative URLs are allowed by RFC 7231 and the most popular web browsers.
// https://en.wikipedia.org/wiki/HTTP_location
rsp.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
rsp.setHeader(HttpHeaders.LOCATION, ResponseImpl.encode(url));
}

/**
* {@inheritDoc}
*/
@Override
@WebMethod(name = "style.css")
public void doStyleCss(StaplerRequest req, StaplerResponse rsp)
throws IOException, ServletException {
// See the comments in doScriptJs for more details.
String url = req.getContextPath() + getResourcePath()
+ "/plugin/timestamper/style.css";
rsp.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
rsp.setHeader(HttpHeaders.LOCATION, ResponseImpl.encode(url));
}

private String getResourcePath() {
Jenkins jenkins = Jenkins.getInstance();
if (jenkins != null) {
PluginWrapper plugin = jenkins.getPluginManager()
.getPlugin("timestamper");
if (plugin != null) {
return "/static/" + Util.rawEncode(plugin.getVersion());
}
}
return Jenkins.RESOURCE_PATH;
}
}
@@ -22,6 +22,11 @@
* THE SOFTWARE.
*/

/*
When changing this file, also rename the TimestampAnnotatorFactory class so
that the changes take effect when upgrading the Timestamper plugin.
*/

(function() {

// Cookie is renewed each time the page is opened and expires after 2 years
@@ -0,0 +1,36 @@
/*
* The MIT License
*
* Copyright (c) 2016 Steven G. Brown
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

/*
When changing this file, also rename the TimestampAnnotatorFactory class so
that the changes take effect when upgrading the Timestamper plugin.
*/

/* Override style changes made by the AnsiColor plugin. */
.timestamp {
color: #333;
background-color: white;
font-weight: normal;
display: inline-block;
}

This file was deleted.

0 comments on commit bb7e2ce

Please sign in to comment.
You can’t perform that action at this time.