Skip to content

Commit

Permalink
Replaced Job.logRotator with BuildDiscarderProperty.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Oct 27, 2015
1 parent 600b1f0 commit 1cbbb23
Show file tree
Hide file tree
Showing 72 changed files with 161 additions and 53 deletions.
4 changes: 4 additions & 0 deletions core/src/main/java/hudson/Functions.java
Expand Up @@ -851,6 +851,10 @@ public static List<JobPropertyDescriptor> getJobPropertyDescriptors(Class<? exte
return JobPropertyDescriptor.getPropertyDescriptors(clazz);
}

public static List<JobPropertyDescriptor> getJobPropertyDescriptors(Job job) {
return DescriptorVisibilityFilter.apply(job, JobPropertyDescriptor.getPropertyDescriptors(job.getClass()));
}

public static List<Descriptor<BuildWrapper>> getBuildWrapperDescriptors(AbstractProject<?,?> project) {
return BuildWrappers.getFor(project);
}
Expand Down
30 changes: 18 additions & 12 deletions core/src/main/java/hudson/model/Job.java
Expand Up @@ -26,6 +26,7 @@
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import hudson.BulkChange;

import hudson.EnvVars;
import hudson.Extension;
Expand Down Expand Up @@ -104,6 +105,7 @@
import javax.annotation.Nonnull;

import static javax.servlet.http.HttpServletResponse.*;
import jenkins.model.BuildDiscarderProperty;
import jenkins.model.ModelObjectWithChildren;
import jenkins.model.RunIdMigrator;
import jenkins.model.lazy.LazyBuildMixIn;
Expand Down Expand Up @@ -147,6 +149,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
*/
private transient volatile boolean holdOffBuildUntilUserSave;

/** @deprecated Replaced by {@link BuildDiscarderProperty} */
private volatile BuildDiscarder logRotator;

/**
Expand Down Expand Up @@ -424,15 +427,24 @@ public synchronized void updateNextBuildNumber(int next) throws IOException {
}

/**
* Returns the configured build discarder for this job, or null if none.
* Returns the configured build discarder for this job, via {@link BuildDiscarderProperty}, or null if none.
*/
public BuildDiscarder getBuildDiscarder() {
return logRotator;
BuildDiscarderProperty prop = getProperty(BuildDiscarderProperty.class);
return prop != null ? prop.getStrategy() : /* settings compatibility */ logRotator;
}

public void setBuildDiscarder(BuildDiscarder bd) throws IOException {
this.logRotator = bd;
save();
BulkChange bc = new BulkChange(this);
try {
removeProperty(BuildDiscarderProperty.class);
if (bd != null) {
addProperty(new BuildDiscarderProperty(bd));
}
bc.commit();
} finally {
bc.abort();
}
}

/**
Expand All @@ -444,9 +456,8 @@ public void setBuildDiscarder(BuildDiscarder bd) throws IOException {
*/
@Deprecated
public LogRotator getLogRotator() {
if (logRotator instanceof LogRotator)
return (LogRotator) logRotator;
return null;
BuildDiscarder buildDiscarder = getBuildDiscarder();
return buildDiscarder instanceof LogRotator ? (LogRotator) buildDiscarder : null;
}

/**
Expand Down Expand Up @@ -1185,11 +1196,6 @@ public synchronized void doConfigSubmit(StaplerRequest req,
try {
setDisplayName(json.optString("displayNameOrNull"));

if (json.optBoolean("logrotate"))
logRotator = req.bindJSON(BuildDiscarder.class, json.optJSONObject("buildDiscarder"));
else
logRotator = null;

DescribableList<JobProperty<?>, JobPropertyDescriptor> t = new DescribableList<JobProperty<?>, JobPropertyDescriptor>(NOOP,getAllProperties());
JSONObject jsonProperties = json.optJSONObject("properties");
if (jsonProperties != null) {
Expand Down
78 changes: 78 additions & 0 deletions core/src/main/java/jenkins/model/BuildDiscarderProperty.java
@@ -0,0 +1,78 @@
/*
* The MIT License
*
* Copyright 2015 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 jenkins.model;

import hudson.Extension;
import hudson.model.Descriptor;
import hudson.model.DescriptorVisibilityFilter;
import hudson.model.Items;
import hudson.model.Job;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* Defines a {@link BuildDiscarder}.
*/
public class BuildDiscarderProperty extends OptionalJobProperty<Job<?,?>> {

private final BuildDiscarder strategy;

@DataBoundConstructor
public BuildDiscarderProperty(BuildDiscarder strategy) {
this.strategy = strategy;
}

public BuildDiscarder getStrategy() {
return strategy;
}

@Extension
public static class DescriptorImpl extends OptionalJobPropertyDescriptor {

@Override
public String getDisplayName() {
return Messages.BuildDiscarderProperty_displayName();
}

static {
Items.XSTREAM2.addCompatibilityAlias("org.jenkinsci.plugins.workflow.job.properties.BuildDiscarderProperty", BuildDiscarderProperty.class);
}

}

@Extension
public static class ConditionallyHidden extends DescriptorVisibilityFilter {

@SuppressWarnings("rawtypes")
@Override
public boolean filter(Object context, Descriptor descriptor) {
if (descriptor instanceof DescriptorImpl && context instanceof Job) {
return ((Job) context).supportsLogRotator();
}
return true;
}

}

}
12 changes: 1 addition & 11 deletions core/src/main/resources/hudson/model/Job/configure.jelly
Expand Up @@ -45,17 +45,7 @@ THE SOFTWARE.
<f:textarea name="description" value="${it.description}" codemirror-mode="${app.markupFormatter.codeMirrorMode}" codemirror-config="${app.markupFormatter.codeMirrorConfig}" previewEndpoint="/markupFormatter/previewDescription"/>
</f:entry>

<j:if test="${it.supportsLogRotator()}">
<!-- log rotator -->
<f:optionalBlock name="logrotate"
help="/help/project-config/log-rotation.html"
title="${%Discard Old Builds}" checked="${it.buildDiscarder!=null}" inline="true">
<f:dropdownDescriptorSelector field="buildDiscarder" title="${%Strategy}"/>
</f:optionalBlock>
</j:if>

<!-- job property configurations. This should have been <f:descriptorList> -->
<f:descriptorList field="properties" descriptors="${h.getJobPropertyDescriptors(it.getClass())}" forceRowSet="true" />
<f:descriptorList field="properties" descriptors="${h.getJobPropertyDescriptors(it)}" forceRowSet="true"/>

<!-- additional entries from derived classes -->
<st:include page="configure-entries.jelly" />
Expand Down
Expand Up @@ -21,7 +21,6 @@
# THE SOFTWARE.

Description=\u041E\u043F\u0438\u0441\u0430\u043D\u0438\u0435
Discard\ Old\ Builds=\u041F\u0440\u0435\u043D\u0435\u0431\u0440\u0435\u0433\u0432\u0430\u043D\u0435 \u043D\u0430 \u0441\u0442\u0430\u0440\u0438\u0442\u0435 \u0431\u0438\u043B\u0434\u043E\u0432\u0435
LOADING=\u0417\u0430\u0440\u0435\u0436\u0434\u0430\u043D\u0435
Save=\u0417\u0430\u043F\u0438\u0448\u0438
name=\u0438\u043C\u0435
@@ -1,6 +1,5 @@
# This file is under the MIT License by authors

Description=Popis
Discard\ Old\ Builds=Zahodit star\u00E9 sestaven\u00ED
LOADING=Nahr\u00E1v\u00E1n\u00ED
name=jm\u00E9no
Expand Up @@ -22,7 +22,6 @@

Strategy=Strategi
name={0} navn
Discard\ Old\ Builds=Fjern Gamle Byg
Save=Gem
LOADING=INDL\u00c6SER
Description=Beskrivelse
Expand Up @@ -23,6 +23,5 @@
Strategy=Strategie
name={0}name
Description=Beschreibung
Discard\ Old\ Builds=Alte Builds verwerfen
Save=Speichern
LOADING=LADE DATEN
Expand Up @@ -22,7 +22,6 @@

Strategy=Estrategia
name={0} nombre
Discard\ Old\ Builds=Desechar ejecuciones antiguas
Save=Guardar
Description=Descripción
LOADING=CARGANDO
@@ -1,6 +1,5 @@
# This file is under the MIT License by authors

Description=Descripci\u00F3n
Discard\ Old\ Builds=Descargar build antiguos
LOADING=CARGANDO
name={0} nombre
@@ -1,6 +1,5 @@
# This file is under the MIT License by authors

Description=Kirjeldus
Discard\ Old\ Builds=Eemalda vanad bildid
LOADING=Laen
name={0} nimi
Expand Up @@ -21,5 +21,4 @@
# THE SOFTWARE.

Description=Kuvaus
Discard\ Old\ Builds=H\u00E4vit\u00E4 vanhat k\u00E4\u00E4nn\u00F6kset
Save=Tallenna
Expand Up @@ -22,7 +22,6 @@

name=Nom du {0}
Description=Description
Discard\ Old\ Builds=Supprimer les anciens builds
Save=Sauver
LOADING=CHARGEMENT
Strategy=Strat\u00E9gie
@@ -1,6 +1,5 @@
# This file is under the MIT License by authors

Description=\u05EA\u05D0\u05D5\u05E8
Discard\ Old\ Builds=\u05D4\u05E9\u05DE\u05D3 \u05D1\u05E0\u05D9\u05D5\u05EA \u05D9\u05E9\u05E0\u05D5\u05EA
LOADING=\u05D8\u05D5\u05E2\u05DF
name=\u05E9\u05DD {0}
@@ -1,7 +1,6 @@
# This file is under the MIT License by authors

Description=Le\u00EDr\u00E1s
Discard\ Old\ Builds=R\u00E9gi \u00E9p\u00EDt\u00E9sek t\u00F6rl\u00E9se
LOADING=BET\u00D6LT\u00C9S
Strategy=Strat\u00E9gia
name={0} n\u00E9v
Expand Up @@ -21,7 +21,6 @@
# THE SOFTWARE.

Description=Descrizione
Discard\ Old\ Builds=Elimina Build Precedenti
LOADING=CARICAMENTO
Save=Salva
Strategy=Strategia
Expand Down
Expand Up @@ -22,7 +22,6 @@

name={0}\u540d
Description=\u8aac\u660e
Discard\ Old\ Builds=\u53e4\u3044\u30d3\u30eb\u30c9\u306e\u7834\u68c4
Save=\u4fdd\u5b58
LOADING=\u30ed\u30fc\u30c9\u4e2d...
Strategy=\u65b9\u91dd
Strategy=\u65b9\u91dd
Expand Up @@ -21,7 +21,6 @@
# THE SOFTWARE.

Description=\uC124\uBA85
Discard\ Old\ Builds=\uC624\uB798\uB41C \uBE4C\uB4DC \uC0AD\uC81C
LOADING=\uBD88\uB7EC\uC624\uB294 \uC911
Save=\uC800\uC7A5
Strategy=\uC804\uB7B5
Expand Down
@@ -1,7 +1,6 @@
# This file is under the MIT License by authors

Description=Apra\u0161ymas
Discard\ Old\ Builds=Pa\u0161alinti senus darbus
LOADING=\u012EKELIAMA
Save=\u012Era\u0161yti
Strategy=Strategija
Expand Down
Expand Up @@ -21,7 +21,6 @@
# THE SOFTWARE.

Description=Apraksts
Discard\ Old\ Builds=Dz\u0113st vecos b\u016Bv\u0113jumus
LOADING=IEL\u0100D\u0112
Save=Saglab\u0101t
name={0} nosaukums
Expand Up @@ -21,6 +21,5 @@
# THE SOFTWARE.

Description=Beskrivelse
Discard\ Old\ Builds=Slett gamle bygg
LOADING=LASTER
name={0} navn
Expand Up @@ -23,6 +23,5 @@
Strategy=Strategie
name={0} naam
Description=Omschrijving
Discard\ Old\ Builds=Oude builds automatisch verwijderen
LOADING=LADEN
Save=Opslaan
Expand Up @@ -21,7 +21,6 @@
# THE SOFTWARE.

Description=Opis
Discard\ Old\ Builds=Porzu\u0107 stare buildy
LOADING=\u0141ADOWANIE
Save=Zapisz
Strategy=Strategia
Expand Down
Expand Up @@ -23,6 +23,5 @@
Strategy=Estrat\u00E9gia
name=Nome do {0}
Description=Descri\u00e7\u00e3o
Discard\ Old\ Builds=Descartar builds antigos
Save=Salvar
LOADING=CARREGANDO
@@ -1,6 +1,5 @@
# This file is under the MIT License by authors

Description=Descri\u00E7\u00E3o
Discard\ Old\ Builds=Descartar compila\u00E7\u00F5es antigas
LOADING=A CARREGAR
name={0} nome
@@ -1,7 +1,6 @@
# This file is under the MIT License by authors

Description=Descriere
Discard\ Old\ Builds=Anuleaza Build-urile vechi
LOADING=SE INCARCA
Strategy=Strategie
name=numele {0}
Expand Up @@ -23,6 +23,5 @@
Strategy=\u0421\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f
name={0}
Description=\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435
Discard\ Old\ Builds=\u0423\u0434\u0430\u043b\u044f\u0442\u044c \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0435 \u0441\u0431\u043e\u0440\u043a\u0438
LOADING=\u0417\u0410\u0413\u0420\u0423\u0417\u041a\u0410
Save=\u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c
@@ -1,7 +1,6 @@
# This file is under the MIT License by authors

Description=Popis
Discard\ Old\ Builds=Vymazanie star\u00FDch zostaven\u00ED
LOADING=Nahr\u00E1vanie
Strategy=Strat\u00E9gia
name={0} meno
Expand Up @@ -21,7 +21,6 @@
# THE SOFTWARE.

Description=Beskrivning
Discard\ Old\ Builds=Ta bort gamla byggen
LOADING=LADDAR
Save=Spara
Strategy=Strategi
Expand Down
Expand Up @@ -23,6 +23,5 @@
Strategy=Strateji
name={0} isim
Description=A\u00e7\u0131klama
Discard\ Old\ Builds=Eski Yap\u0131land\u0131rmalardan Kurtul
LOADING=Y\u00DCKLEN\u0130YOR
Save=Kaydet
@@ -1,7 +1,6 @@
# This file is under the MIT License by authors

Description=\u041E\u043F\u0438\u0441
Discard\ Old\ Builds=\u0421\u043A\u0430\u0441\u0443\u0432\u0430\u0442\u0438 \u0441\u0442\u0430\u0440\u0456 \u0431\u0456\u043B\u0434\u0438
LOADING=\u0417\u0410\u0412\u0410\u041D\u0422\u0410\u0416\u0423\u0404\u0422\u042C\u0421\u042F
Save=\u0417\u0431\u0435\u0440\u0435\u0433\u0442\u0438
Strategy=\u0421\u0442\u0440\u0430\u0442\u0435\u0433\u0456\u044F
Expand Down
Expand Up @@ -21,7 +21,6 @@
# THE SOFTWARE.

Description=\u63CF\u8FF0
Discard\ Old\ Builds=\u4E22\u5F03\u65E7\u7684\u6784\u5EFA
LOADING=\u52A0\u8F7D\u4E2D
Save=\u4FDD\u5B58
Strategy=\u7B56\u7565
Expand Down

0 comments on commit 1cbbb23

Please sign in to comment.