Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/src/main/java/hudson/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1779,6 +1779,10 @@ public static SimplePageDecorator getSimplePageDecorator() {
return SimplePageDecorator.first();
}

public static List<SimplePageDecorator> getSimplePageDecorators() {
return SimplePageDecorator.all();
}

public static List<Descriptor<Cloud>> getCloudDescriptors() {
return Cloud.all();
}
Expand Down
20 changes: 13 additions & 7 deletions core/src/main/java/jenkins/model/SimplePageDecorator.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
*/
package jenkins.model;

import hudson.DescriptorExtensionList;
import hudson.ExtensionPoint;
import hudson.model.Describable;
import hudson.model.Descriptor;

import java.util.List;

/**
* Participates in the rendering of the login page
*
Expand Down Expand Up @@ -56,17 +58,21 @@ public final String getUrl() {
return "descriptor/"+clazz.getName();
}

/**
* Returns all login page decorators.
* @since TODO
*/
public static List<SimplePageDecorator> all() {
return Jenkins.get().getDescriptorList(SimplePageDecorator.class);
}

/**
* The first found LoginDecarator, there can only be one.
* @return the first found {@link SimplePageDecorator}
*/
public static SimplePageDecorator first(){
DescriptorExtensionList<SimplePageDecorator, SimplePageDecorator> descriptorList = Jenkins.getInstanceOrNull().<SimplePageDecorator, SimplePageDecorator>getDescriptorList(SimplePageDecorator.class);
if (descriptorList.size() >= 1) {
return descriptorList.get(0);
} else {
return null;
}
List<SimplePageDecorator> decorators = all();
return decorators.isEmpty() ? null : decorators.get(0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ THE SOFTWARE.
<!-- in case of error we want to surround the form elements with an error hint -->
<j:set var="inputClass" value="${data.errorMessage!=null ? 'danger' : 'normal'}"/>
<j:set var="simpleDecorator" value="${h.simplePageDecorator}"/>
<j:set var="simpleDecorators" value="${h.simplePageDecorators}"/>
<html lang="${request.getLocale().toLanguageTag()}">
<head data-rooturl="${rootURL}" data-resurl="${resURL}" resURL="${resURL}">
<title>${%Create an account! [Jenkins]}</title>
Expand Down Expand Up @@ -292,6 +293,11 @@ THE SOFTWARE.
}
</script>
</j:if>
<div class="footer">
<j:forEach var="decorator" items="${simpleDecorators}">
<st:include it="${decorator}" page="simple-footer.jelly" optional="true"/>
</j:forEach>
</div>
</form>
</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/resources/jenkins/model/Jenkins/login.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ THE SOFTWARE.
<!-- in case of error we want to surround the form elements with an error hint -->
<j:set var="inputClass" value="${error ? 'danger' : 'normal'}"/>
<j:set var="simpleDecorator" value="${h.simplePageDecorator}"/>
<j:set var="simpleDecorators" value="${h.simplePageDecorators}"/>
<!-- real deal starting here -->
<html lang="${request.getLocale().toLanguageTag()}">
<head data-rooturl="${rootURL}" data-resurl="${resURL}" resURL="${resURL}">
Expand Down Expand Up @@ -145,8 +146,9 @@ THE SOFTWARE.
</j:forEach>

<div class="footer">

<st:include it="${simpleDecorator}" page="simple-footer.jelly" optional="true"/>
<j:forEach var="decorator" items="${simpleDecorators}">
<st:include it="${decorator}" page="simple-footer.jelly" optional="true"/>
</j:forEach>
</div>

</div>
Expand Down
4 changes: 4 additions & 0 deletions core/src/test/java/hudson/UtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import static org.hamcrest.CoreMatchers.startsWith;
import static org.junit.Assert.*;

import jenkins.junit.Retry;
import jenkins.junit.RetryRule;
import org.apache.commons.io.FileUtils;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
Expand All @@ -73,6 +75,7 @@
public class UtilTest {

@Rule public TemporaryFolder tmp = new TemporaryFolder();
@Rule public RetryRule retry = new RetryRule();

@Test
public void testReplaceMacro() {
Expand Down Expand Up @@ -352,6 +355,7 @@ public void testDeleteContentsRecursive() throws Exception {
}

@Test
@Retry
public void testDeleteContentsRecursive_onWindows() throws Exception {
Assume.assumeTrue(Functions.isWindows());
final File dir = tmp.newFolder();
Expand Down
46 changes: 46 additions & 0 deletions core/src/test/java/jenkins/junit/Retry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* The MIT License
*
* Copyright (c) 2018 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.junit;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Combined with {@link RetryRule}, retries failing test methods. Note that tests that fail with
* {@link org.junit.AssumptionViolatedException} are not retried.
*/
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface Retry {
/**
* Number of times to retry test method or individual tests in a class before giving up.
* Set this to 0 to disable retries (e.g., to override a test class's @Retry annotation or similar).
*/
int value() default 2;
}
65 changes: 65 additions & 0 deletions core/src/test/java/jenkins/junit/RetryRule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* The MIT License
*
* Copyright (c) 2018 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.junit;

import org.junit.AssumptionViolatedException;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

public class RetryRule implements TestRule {

@Override
public Statement apply(Statement base, Description description) {
Retry retryForAllMethods = description.getTestClass().getAnnotation(Retry.class);
Retry retryMethod = description.getAnnotation(Retry.class);
int retries = 0;
if (retryMethod != null) {
retries = retryMethod.value();
} else if (retryForAllMethods != null) {
retries = retryForAllMethods.value();
}
int maxEvaluationAttempts = retries + 1;
return new Statement() {
@Override
public void evaluate() throws Throwable {
Throwable caught = null;
for (int i = 0; i < maxEvaluationAttempts; i++) {
try {
base.evaluate();
return;
} catch (AssumptionViolatedException e) {
return;
} catch (Throwable e) {
e.printStackTrace();
caught = e;
}
}
System.err.println(description.getDisplayName() + " retry count exhausted");
throw caught;
}
};
}
}