Skip to content

Commit

Permalink
[FIXED JENKINS-8579] defined a mechanism to replace some of the key U…
Browse files Browse the repository at this point in the history
…I text.

I wasn't initially planning to do this, but it turns out more people needed this feature than I thought.

I left the text as is, but defined a mechanism to override this in the plugin, in a possibly context sensitive way. For example, a plugin can replace this text on a job-by-job basis, or by looking at some property/builder/etc.
  • Loading branch information
kohsuke committed Apr 19, 2011
1 parent f0dcd84 commit c83d119
Show file tree
Hide file tree
Showing 40 changed files with 476 additions and 300 deletions.
13 changes: 13 additions & 0 deletions core/src/main/java/hudson/model/AbstractProject.java
Expand Up @@ -70,6 +70,8 @@
import hudson.triggers.SCMTrigger;
import hudson.triggers.Trigger;
import hudson.triggers.TriggerDescriptor;
import hudson.util.AlternativeUiTextProvider;
import hudson.util.AlternativeUiTextProvider.Message;
import hudson.util.DescribableList;
import hudson.util.EditDistance;
import hudson.util.FormValidation;
Expand Down Expand Up @@ -353,6 +355,15 @@ public String getPronoun() {
return Messages.AbstractProject_Pronoun();
}

/**
* Gets the human readable display name to be rendered in the "Build Now" link.
*
* @since 1.401
*/
public String getBuildNowText() {
return AlternativeUiTextProvider.get(BUILD_NOW_TEXT,this,Messages.AbstractProject_BuildNow());
}

/**
* Returns the root project value.
*
Expand Down Expand Up @@ -1910,6 +1921,8 @@ public int compare(Integer o1, Integer o2) {
*/
public static final Permission ABORT = BUILD;

public static final Message<AbstractProject> BUILD_NOW_TEXT = new Message<AbstractProject>();

/**
* Used for CLI binding.
*/
Expand Down
109 changes: 109 additions & 0 deletions core/src/main/java/hudson/util/AlternativeUiTextProvider.java
@@ -0,0 +1,109 @@
/*
* The MIT License
*
* Copyright (c) 2011, CloudBees, Inc.
*
* 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.
*/
package hudson.util;

import hudson.Extension;
import hudson.ExtensionList;
import hudson.ExtensionPoint;
import hudson.model.AbstractProject;
import hudson.model.Hudson;

/**
* Provides the alternative text to be rendered in the UI.
*
* <p>
* In a few limited places in Jenkins, we want to provide an ability for plugins to replace
* the text to be shown in the UI. Since each such case is rather trivial and can't justify
* its own extension point, we consolidate all such use cases into a single extension point.
*
* <p>
* Each such overridable UI text can have a context, which represents some information
* that enables the {@link AlternativeUiTextProvider} to make intelligent decision. This
* is normally some kind of a model object, such as {@link AbstractProject}.
*
* <p>
* To define a new UI text that can be overridable by {@link AlternativeUiTextProvider},
* define a constant of {@link Message} (parameterized with the context object type),
* then call {@link #get(Message, Object)} to obtain a text.
*
* <p>
* To define an implementation that overrides text, define a subtype and put @{@link Extension} on it.
* See {@link AbstractProject#getBuildNowText()} as an example.
*
* @author Kohsuke Kawaguchi
* @since 1.401
*/
public abstract class AlternativeUiTextProvider implements ExtensionPoint {
/**
* Provides an opportunity to override the message text.
*
* @param text
* Always non-null. Caller should pass in a {@link Message} constant that
* represents the text that we are being considered.
* @param context
* Context object. See class javadoc above.
*/
public abstract <T> String getText(Message<T> text, T context);

/**
* All the registered extension point instances.
*/
public static ExtensionList<AlternativeUiTextProvider> all() {
return Hudson.getInstance().getExtensionList(AlternativeUiTextProvider.class);
}

public static <T> String get(Message<T> text, T context, String defaultValue) {
String s = get(text,context);
return s!=null ? s : defaultValue;
}

/**
* Consults all the existing {@link AlternativeUiTextProvider} and return an override, if any,
* or null.
*/
public static <T> String get(Message<T> text, T context) {
for (AlternativeUiTextProvider p : all()) {
String s = p.getText(text, context);
if (s!=null)
return s;
}
return null;
}

/**
* @param <T>
* Context object type. Use {@link Void} to indicate that there's no context.
*/
public static class Message<T> {
// decided not to retain T as Class so that we can have Message<List<Foo>>, for example.

/**
* Assists pattern matching in the {@link AlternativeUiTextProvider} implementation.
*/
@SuppressWarnings({"unchecked"})
public T cast(Object context) {
return (T)context;
}
}
}
Expand Up @@ -42,7 +42,7 @@ THE SOFTWARE.
</l:task>
<j:if test="${it.configurable}">
<j:if test="${it.buildable}">
<l:task icon="images/24x24/clock.gif" href="${url}/build?delay=0sec" title="${%Build Now}"
<l:task icon="images/24x24/clock.gif" href="${url}/build?delay=0sec" title="${it.buildNowText}"
onclick="${it.parameterized?null:'return build(this)'}" permission="${it.BUILD}" />
<script>
function build(a) {
Expand Down
Expand Up @@ -20,4 +20,4 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

delete=Delete {0}
delete=Delete {0}
Expand Up @@ -21,7 +21,6 @@
# THE SOFTWARE.

Back\ to\ Dashboard=Retornar al Panell de Control
Build\ Now=Construir Ara
Build\ scheduled=Pla de construcci\u00F3
Changes=Canvis
Configure=Configurar
Expand Down
Expand Up @@ -29,4 +29,3 @@ Workspace=Arbejdsomr\u00e5de
Build\ scheduled=Byg skeduleret
View\ Configuration=Vis konfiguration
Wipe\ Out\ Workspace=Slet arbejdsomr\u00e5det
Build\ Now=Byg nu
Expand Up @@ -24,7 +24,6 @@ Back\ to\ Dashboard= Zur
Status=Status
Changes=Änderungen
Workspace=Arbeitsbereich
Build\ Now=Jetzt bauen
delete=Löschen
Configure=Konfigurieren
View\ Configuration=Konfiguration anzeigen
Expand Down
Expand Up @@ -20,7 +20,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

Build\ Now=Ejecutar ahora
Build\ scheduled=Ejecuci\u00F3n agendada
Changes=Cambios
Configure=Configurar
Expand Down
Expand Up @@ -21,7 +21,6 @@
# THE SOFTWARE.

Back\ to\ Dashboard=Takaisin kojetauluun
Build\ Now=K\u00E4\u00E4nn\u00E4 nyt
Build\ scheduled=K\u00E4\u00E4nn\u00F6s on jonossa
Changes=Muutokste
Configure=Muokkaa
Expand Down
Expand Up @@ -24,7 +24,6 @@ Back\ to\ Dashboard=Retour au tableau de bord
Status=Statut
Changes=Modifications
Workspace=Espace de travail
Build\ Now=Lancer un build
delete=Supprimer ce {0}
Configure=Configurer
Build\ scheduled=Build programmé
Expand Down
Expand Up @@ -21,7 +21,6 @@
# THE SOFTWARE.

Back\ to\ Dashboard=Vissza a M\u0171szerfalhoz
Build\ Now=\u00C9p\u00EDt\u00E9s Most
Build\ scheduled=Id\u0151z\u00EDtett \u00E9p\u00EDt\u00E9s
Changes=V\u00E1ltoz\u00E1sok
Configure=Be\u00E1ll\u00EDt\u00E1sok
Expand Down
Expand Up @@ -21,7 +21,6 @@
# THE SOFTWARE.

Back\ to\ Dashboard=Ritorna alla Dashboard
Build\ Now=Effettua build
Build\ scheduled=Pianifica build
Changes=Modifiche
Configure=Configura
Expand Down
Expand Up @@ -25,8 +25,7 @@ Status=\u72b6\u614b
Changes=\u5909\u66f4
Workspace=\u30ef\u30fc\u30af\u30b9\u30da\u30fc\u30b9
Wipe\ Out\ Workspace=\u30ef\u30fc\u30af\u30b9\u30da\u30fc\u30b9\u306e\u30af\u30ea\u30a2
Build\ Now=\u30d3\u30eb\u30c9\u5b9f\u884c
delete={0}\u306e\u524a\u9664
Configure=\u8a2d\u5b9a
Build\ scheduled=\u30d3\u30eb\u30c9\u304c\u30b9\u30b1\u30b8\u30e5\u30fc\u30eb\u3055\u308c\u307e\u3057\u305f
View\ Configuration=\u8a2d\u5b9a\u306e\u53c2\u7167
View\ Configuration=\u8a2d\u5b9a\u306e\u53c2\u7167
Expand Up @@ -26,6 +26,5 @@ Build\ scheduled=Bouwpoging gepland
Changes=Wijzigingen
Wipe\ Out\ Workspace=Verwijder Werkplaats
Workspace=Werkplaats
Build\ Now=Start nu een bouwpoging
delete=Verwijder {0}
Configure=Configureer
Expand Up @@ -26,7 +26,6 @@ Build\ scheduled=Constru\u00e7\u00e3 agendada
Changes=Mudan\u00e7as
Wipe\ Out\ Workspace=Limpar Workspace
Workspace=\u00c1rea de Trabalho
Build\ Now=Construir Agora
delete=Excluir {0}
Configure=Configurar
View\ Configuration= Configurar a View
Expand Up @@ -25,7 +25,6 @@ Status=\u0421\u0442\u0430\u0442\u0443\u0441
Changes=\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f
Wipe\ Out\ Workspace=\u041E\u0447\u0438\u0441\u0442\u0438\u0442\u044C \u0440\u0430\u0431\u043E\u0447\u0435\u0435 \u043F\u0440\u043E\u0441\u0442\u0440\u0430\u043D\u0441\u0442\u0432\u043E
Workspace=\u0421\u0431\u043E\u0440\u043E\u0447\u043D\u0430\u044F \u0434\u0438\u0440\u0435\u043A\u0442\u043E\u0440\u0438\u044F
Build\ Now=\u0421\u043E\u0431\u0440\u0430\u0442\u044C \u0441\u0435\u0439\u0447\u0430\u0441
delete=\u0423\u0434\u0430\u043B\u0438\u0442\u044C {0}
Configure=\u041D\u0430\u0441\u0442\u0440\u043E\u0438\u0442\u044C \u041F\u0440\u043E\u0435\u043A\u0442
Build\ scheduled=\u0421\u0431\u043e\u0440\u043a\u0430 \u0437\u0430\u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0430
Expand Up @@ -21,7 +21,6 @@
# THE SOFTWARE.

Back\ to\ Dashboard=Nazaj na Zapisnik
Build\ Now=Prevedi takoj
Build\ scheduled=Buildaj ob umiku
Changes=Spremembe
Configure=Nastavitve
Expand Down
Expand Up @@ -21,7 +21,6 @@
# THE SOFTWARE.

Back\ to\ Dashboard=Tillbaka till instrumentpanelen
Build\ Now=Starta bygge nu
Build\ scheduled=Jobb schemalagt
Changes=F\u00F6r\u00E4ndringar
Configure=Konfigurera
Expand Down
Expand Up @@ -25,6 +25,5 @@ Back\ to\ Dashboard=Kontrol Merkezi''ne D\u00f6n
Status=Durum
Changes=De\u011fi\u015fiklikler
Workspace=\u00c7al\u0131\u015fma Alan\u0131
Build\ Now=\u015eimdi Yap\u0131land\u0131r
Configure=Konfig\u00fcrasyonu D\u00fczenle
Build\ scheduled=Yap\u0131land\u0131rma planland\u0131
Expand Up @@ -21,7 +21,6 @@
# THE SOFTWARE.

Back\ to\ Dashboard=\u8fd4\u56de
Build\ Now=\u7acb\u5373\u6784\u5efa
Build\ scheduled=\u6784\u5efa\u8ba1\u5212
Changes=\u53d8\u66f4\u96c6
Configure=\u8bbe\u7f6e
Expand Down
Expand Up @@ -21,7 +21,6 @@
# THE SOFTWARE.

Back\ to\ Dashboard=\u56DE\u5230\u5100\u8868\u677F
Build\ Now=\u99AC\u4E0A\u5EFA\u69CB
Changes=\u8B8A\u66F4
Configure=\u8A2D\u5B9A
Status=\u72C0\u614B
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/hudson/model/Messages.properties
Expand Up @@ -32,6 +32,7 @@ AbstractProject.AwaitingBuildForWorkspace=Awaiting build to get a workspace.
AbstractProject.Pronoun=Project
AbstractProject.Aborted=Aborted
AbstractProject.BuildInProgress=Build #{0} is already in progress{1}
AbstractProject.BuildNow=Build Now
AbstractProject.UpstreamBuildInProgress=Upstream project {0} is already building.
AbstractProject.DownstreamBuildInProgress=Downstream project {0} is already building.
AbstractProject.Disabled=Build disabled
Expand Down
@@ -0,0 +1 @@
AbstractProject.BuildNow=Construir Ara
Expand Up @@ -246,3 +246,4 @@ Hudson.NoSuchDirectory=Intet direktorie ved navn: {0}
LoadStatistics.Legends.BusyExecutors=Optagede afviklere
HealthReport.EmptyString=
MultiStageTimeSeries.EMPTY_STRING=
AbstractProject.BuildNow=Byg nu
Expand Up @@ -279,3 +279,4 @@ Cause.UserCause.ShortDescription=Gestartet durch Benutzer {0}
Cause.RemoteCause.ShortDescription=Gestartet durch entfernten Rechner {0}
Cause.RemoteCause.ShortDescriptionWithNote=Gestartet durch entfernten Rechner {0} mit Hinweis: {1}

AbstractProject.BuildNow=Jetzt bauen
Expand Up @@ -287,3 +287,4 @@ AbstractProject.AwaitingBuildForWorkspace=El trabajo est
Run.ArtifactsPermission.Description=\
Este permiso sirve para poder utilizar los artefactos producidos en los proyectos.
AbstractProject.AssignedLabelString.InvalidBooleanExpression=Expresión booleana incorrecta: {0}
AbstractProject.BuildNow=Ejecutar ahora
@@ -0,0 +1 @@
AbstractProject.BuildNow=K\u00E4\u00E4nn\u00E4 nyt
Expand Up @@ -182,3 +182,4 @@ Cause.LegacyCodeCause.ShortDescription=Ce job a \u00e9t\u00e9 lanc\u00e9 par du
Cause.UpstreamCause.ShortDescription=D\u00e9marr\u00e9 par le projet amont "{0}" de num\u00e9ro de build {1}
Cause.UserCause.ShortDescription=D\u00e9marr\u00e9 par l''utilisateur {0}
Cause.RemoteCause.ShortDescription=D\u00e9marr\u00e9 \u00e0 distance par {0}
AbstractProject.BuildNow=Lancer un build
@@ -0,0 +1 @@
AbstractProject.BuildNow=\u00C9p\u00EDt\u00E9s Most
@@ -0,0 +1 @@
AbstractProject.BuildNow=Effettua build
Expand Up @@ -275,3 +275,4 @@ CLI.online-node.shortDescription=\u76f4\u524d\u306b\u5b9f\u884c\u3057\u305f"onli
CLI.offline-node.shortDescription="online-node"\u30b3\u30de\u30f3\u30c9\u304c\u5b9f\u884c\u3055\u308c\u308b\u307e\u3067\u3001\u30d3\u30eb\u30c9\u3092\u5b9f\u884c\u3059\u308b\u30ce\u30fc\u30c9\u306e\u4f7f\u7528\u3092\u4e00\u6642\u7684\u306b\u505c\u6b62\u3057\u307e\u3059\u3002

BuildAuthorizationToken.InvalidTokenProvided=\u8a8d\u8a3c\u30c8\u30fc\u30af\u30f3\u304c\u9593\u9055\u3063\u3066\u3044\u307e\u3059\u3002
AbstractProject.BuildNow=\u30d3\u30eb\u30c9\u5b9f\u884c
Expand Up @@ -104,3 +104,4 @@ Permalink.LastBuild=Laatste bouwpoging
Permalink.LastStableBuild=Laatste stabiele bouwpoging
Permalink.LastSuccessfulBuild=Laatste succesvolle bouwpoging
Permalink.LastFailedBuild=Laatst gefaalde bouwpoging
AbstractProject.BuildNow=Start nu een bouwpoging
Expand Up @@ -396,3 +396,4 @@ Label.GroupOf=Grupo de {0}
Queue.AllNodesOffline=Todos os rotulos ''{0}'' est\u00e3o offline.
# Busy executors
LoadStatistics.Legends.BusyExecutors=Executores ocupados.
AbstractProject.BuildNow=Construir Agora
Expand Up @@ -104,3 +104,4 @@ Permalink.LastBuild=\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u044
Permalink.LastStableBuild=\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u0430\u044f \u0441\u0431\u043e\u0440\u043a\u0430
Permalink.LastSuccessfulBuild=\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0443\u0441\u043f\u0435\u0448\u043d\u0430\u044f \u0441\u0431\u043e\u0440\u043a\u0430
Permalink.LastFailedBuild=\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0432\u0448\u0430\u044f\u0441\u044f \u0441\u0431\u043e\u0440\u043a\u0430
AbstractProject.BuildNow=\u0421\u043E\u0431\u0440\u0430\u0442\u044C \u0441\u0435\u0439\u0447\u0430\u0441
@@ -0,0 +1 @@
AbstractProject.BuildNow=Prevedi takoj
@@ -0,0 +1 @@
AbstractProject.BuildNow=Starta bygge nu
Expand Up @@ -105,3 +105,4 @@ Permalink.LastBuild=Son yap\u0131land\u0131rma
Permalink.LastStableBuild=Son stabil yap\u0131land\u0131rma
Permalink.LastSuccessfulBuild=Son ba\u015far\u0131l\u0131 yap\u0131land\u0131rma
Permalink.LastFailedBuild=Son ba\u015far\u0131s\u0131z yap\u0131land\u0131rma
AbstractProject.BuildNow=\u015eimdi Yap\u0131land\u0131r

0 comments on commit c83d119

Please sign in to comment.