Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/JENKINS-71007
Browse files Browse the repository at this point in the history
  • Loading branch information
rsandell committed Jul 19, 2023
2 parents da78df1 + 39403ae commit 26870c3
Show file tree
Hide file tree
Showing 20 changed files with 185 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .mvn/extensions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<extension>
<groupId>io.jenkins.tools.incrementals</groupId>
<artifactId>git-changelist-maven-extension</artifactId>
<version>1.4</version>
<version>1.6</version>
</extension>
</extensions>
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
buildPlugin(useContainerAgent: true, configurations: [
[ platform: 'linux', jdk: '8' ],
[ platform: 'linux', jdk: '11' ],
[platform: 'linux', jdk: 17],
[platform: 'linux', jdk: 11],
])
23 changes: 10 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.47</version>
<version>4.66</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -54,8 +54,8 @@
</developers>

<properties>
<jenkins.version>2.346.3</jenkins.version>
<revision>2.39.1</revision>
<jenkins.version>2.410</jenkins.version>
<revision>2.39.2</revision>
<changelist>-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<!--<java.level>8</java.level>-->
Expand Down Expand Up @@ -124,7 +124,6 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>support-core</artifactId>
<!--<version>2.75</version>-->
<optional>true</optional>
</dependency>
<dependency>
Expand Down Expand Up @@ -189,7 +188,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -204,7 +203,7 @@
wiremock-jre8 introduces many dependencies that interferes with jth and core functionality
during testing, the standalone jar shades all those so it doesn't break other tests.
-->
<version>2.28.1</version>
<version>2.35.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -231,10 +230,8 @@
<scope>test</scope>
</dependency>
<dependency>
<!-- TODO move to plugin dependencies (no server module yet)-->
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-core</artifactId>
<version>1.7.0</version>
<groupId>io.jenkins.plugins.mina-sshd-api</groupId>
<artifactId>mina-sshd-api-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -255,8 +252,8 @@
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.346.x</artifactId>
<version>1595.v8c71c13cc3a_9</version>
<artifactId>bom-2.401.x</artifactId>
<version>2244.vd60654536b_96</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -268,7 +265,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
<version>3.12.0</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public int getTimerUpdatePeriod() {
*/
public void setTimerUpdatePeriod(int timerUpdatePeriod) {
this.timerUpdatePeriod = timerUpdatePeriod;
scheduleProjectListUpdate(0);
scheduleProjectListUpdate(0, (int)TimeUnit.MINUTES.toSeconds(timerUpdatePeriod));
}

/**
Expand Down Expand Up @@ -180,7 +180,8 @@ public void initProjectListUpdater() {
return;
}
timer = new Timer(serverName);
scheduleProjectListUpdate(getConfig().getProjectListFetchDelay());
scheduleProjectListUpdate(getConfig().getProjectListFetchDelay(),
getConfig().getProjectListRefreshInterval());
} else {
logger.error("Can't create two timers for the same Gerrit instance: " + serverName);
}
Expand All @@ -207,8 +208,9 @@ public void cancelProjectListUpdater() {
* This method creates a timer that schedule the update of the gerrit project list.
*
* @param initDelay the initial delay, in seconds.
* @param updatePeriod the update period, in seconds.
*/
public void scheduleProjectListUpdate(int initDelay) {
public void scheduleProjectListUpdate(int initDelay, int updatePeriod) {
logger.info("Start timer to update project list");
if (timer != null) {
timer.cancel();
Expand All @@ -218,7 +220,7 @@ public void scheduleProjectListUpdate(int initDelay) {
public void run() {
tryLoadProjectList();
}
}, TimeUnit.SECONDS.toMillis(initDelay), TimeUnit.MINUTES.toMillis(timerUpdatePeriod));
}, TimeUnit.SECONDS.toMillis(initDelay), TimeUnit.SECONDS.toMillis(updatePeriod));
} else {
logger.error("Unable to schedule project list update task because timer is null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,15 @@ protected Integer getVerifiedValue(Result res, GerritTrigger trigger) {
/**
* Returns the minimum verified value for the build results in the memory.
* If no builds have contributed to verified value, this method returns null
* @param memoryImprint the memory.
* @param onlyBuilt only count builds that completed (no NOT_BUILT builds)
*
* @param memoryImprint the memory.
* @param onlyBuilt only count builds that completed (no NOT_BUILT builds)
* @param maxAllowedVerifiedValue Upper boundary on verified value.
* @return the lowest verified value.
*/
@CheckForNull
public Integer getMinimumVerifiedValue(MemoryImprint memoryImprint, boolean onlyBuilt) {
public Integer getMinimumVerifiedValue(MemoryImprint memoryImprint, boolean onlyBuilt,
Integer maxAllowedVerifiedValue) {
Integer verified = Integer.MAX_VALUE;
for (Entry entry : memoryImprint.getEntries()) {
if (entry == null) {
Expand Down Expand Up @@ -415,7 +418,7 @@ public Integer getMinimumVerifiedValue(MemoryImprint memoryImprint, boolean only
return null;
}

return verified;
return Math.min(verified, maxAllowedVerifiedValue);
}

/**
Expand Down Expand Up @@ -531,6 +534,7 @@ public String getBuildCompletedCommand(MemoryImprint memoryImprint, TaskListener
// builds were successful, unstable or failed, we find the minimum
// verified/code review value for the NOT_BUILT ones too.
boolean onlyCountBuilt = true;
Integer maxAllowedVerifiedValue = Integer.MAX_VALUE;
if (memoryImprint.wereAllBuildsSuccessful()) {
command = config.getGerritCmdBuildSuccessful();
} else if (memoryImprint.wereAnyBuildsFailed()) {
Expand All @@ -545,13 +549,17 @@ public String getBuildCompletedCommand(MemoryImprint memoryImprint, TaskListener
} else {
//Just as bad as failed for now.
command = config.getGerritCmdBuildFailed();
// Some builds could have failed, but are already deleted and not
// available for score calculation.
// Set pessimistic upper boundary on verified value.
maxAllowedVerifiedValue = config.getGerritBuildFailedVerifiedValue();
}

Integer verified = null;
Integer codeReview = null;
Notify notifyLevel = Notify.ALL;
if (memoryImprint.getEvent().isScorable()) {
verified = getMinimumVerifiedValue(memoryImprint, onlyCountBuilt);
verified = getMinimumVerifiedValue(memoryImprint, onlyCountBuilt, maxAllowedVerifiedValue);
codeReview = getMinimumCodeReviewValue(memoryImprint, onlyCountBuilt);
notifyLevel = getHighestNotificationLevel(memoryImprint, onlyCountBuilt);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected ReviewInput createReview() {
}
}
if (config.isRestVerified()) {
Integer verValue = parameterExpander.getMinimumVerifiedValue(memoryImprint, true);
Integer verValue = parameterExpander.getMinimumVerifiedValue(memoryImprint, true, Integer.MAX_VALUE);
if (verValue != null && verValue != Integer.MAX_VALUE) {
scoredLabels.add(new ReviewLabel(
LABEL_VERIFIED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@
<p:blockWrapperTd>
<f:textbox name="from"
value="${h.appendIfNotNull(t.from.hourAsString,'','00')}:${h.appendIfNotNull(t.from.minuteAsString,'','00')}"
checkUrl="'${rootURL}/${serverURL}/validTimeCheck?fromValue='+escape(Form.findMatchingInput(this,'from').value)
+'&amp;toValue='+escape(Form.findMatchingInput(this, 'to').value)"/>
checkUrl="'${rootURL}/${serverURL}/validTimeCheck?fromValue='+escape(findMatchingFormInput(this,'from').value)
+'&amp;toValue='+escape(findMatchingFormInput(this, 'to').value)"/>
</p:blockWrapperTd>
</p:blockWrapperTr>
<p:blockWrapperTr>
Expand All @@ -474,8 +474,8 @@
<p:blockWrapperTd>
<f:textbox name="to"
value="${h.appendIfNotNull(t.to.hourAsString,'','00')}:${h.appendIfNotNull(t.to.minuteAsString,'','01')}"
checkUrl="'${rootURL}/${serverURL}/validTimeCheck?fromValue='+escape(Form.findMatchingInput(this,'from').value)
+'&amp;toValue='+escape(Form.findMatchingInput(this, 'to').value)"/>
checkUrl="'${rootURL}/${serverURL}/validTimeCheck?fromValue='+escape(findMatchingFormInput(this,'from').value)
+'&amp;toValue='+escape(findMatchingFormInput(this, 'to').value)"/>
</p:blockWrapperTd>
</p:blockWrapperTr>
<!--used to display the form validation error -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@

import static com.sonymobile.tools.gerrit.gerritevents.mock.SshdServerMock.GERRIT_STREAM_EVENTS;

import com.gargoylesoftware.htmlunit.html.HtmlElement;
import org.htmlunit.html.HtmlElement;
import org.apache.sshd.server.SshServer;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput;
import org.htmlunit.FailingHttpStatusCodeException;
import org.htmlunit.html.HtmlForm;
import org.htmlunit.html.HtmlPage;
import org.htmlunit.html.HtmlRadioButtonInput;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritCause;
import com.sonyericsson.hudson.plugins.gerrit.trigger.mock.DuplicatesUtil;
import com.sonyericsson.hudson.plugins.gerrit.trigger.mock.Setup;
Expand Down Expand Up @@ -299,12 +299,12 @@ private void addNewServerWithDefaultConfigs(String serverName) throws Exception
HtmlPage page = j.createWebClient().getPage(url);
HtmlForm form = page.getFormByName(newServerFormName);

form.getInputByName(inputFormName).setValueAttribute(serverName);
form.getInputByName(inputFormName).setValue(serverName);

List<HtmlRadioButtonInput> radioButtons = form.getRadioButtonsByName(radioButtonName);
HtmlRadioButtonInput radioButtonDefaultConfig = null;
for (HtmlRadioButtonInput button : radioButtons) {
if (radioButtonDefaultConfigValue.equals(button.getValueAttribute())) {
if (radioButtonDefaultConfigValue.equals(button.getValue())) {
radioButtonDefaultConfig = button;
radioButtonDefaultConfig.setChecked(true);
}
Expand All @@ -326,19 +326,19 @@ private void addNewServerByCopyingConfig(String newServerName, String fromServer
HtmlPage page = j.createWebClient().getPage(url);
HtmlForm form = page.getFormByName(newServerFormName);

form.getInputByName(inputFormName).setValueAttribute(newServerName);
form.getInputByName(inputFormName).setValue(newServerName);

List<HtmlRadioButtonInput> radioButtons = form.getRadioButtonsByName(radioButtonName);
HtmlRadioButtonInput radioButtonCopy = null;
for (HtmlRadioButtonInput button : radioButtons) {
if (radioButtonCopyValue.equals(button.getValueAttribute())) {
if (radioButtonCopyValue.equals(button.getValue())) {
radioButtonCopy = button;
radioButtonCopy.setChecked(true);
}
}
assertTrue("Failed to choose 'Copy from Existing Server Configurations'", radioButtonCopy.isChecked());

form.getInputByName(fromInputFormName).setValueAttribute(fromServerName);
form.getInputByName(fromInputFormName).setValue(fromServerName);

j.submit(form);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.HttpMethod;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.util.UrlUtils;
import org.htmlunit.FailingHttpStatusCodeException;
import org.htmlunit.HttpMethod;
import org.htmlunit.Page;
import org.htmlunit.WebRequest;
import org.htmlunit.html.HtmlForm;
import org.htmlunit.html.HtmlPage;
import org.htmlunit.util.UrlUtils;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.concurrent.TimeoutException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -59,6 +60,8 @@ public class IntegrationTest {
*/
@Test
public void testChildBuildSeeParametersOfParentJob() throws Exception {
// CS IGNORE MagicNumber FOR NEXT 1 LINES. REASON: Non-magic number.
assumeTrue("TODO does not work on Java 17", Runtime.version().feature() < 17);
String gerritServerName = "";
GerritServer gerritServer = createMockGerritServer(gerritServerName);
PluginImpl.getInstance().addServer(gerritServer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ public void testCodeReview() {
}

/**
* Tests that {@link ParameterExpander#getMinimumVerifiedValue(BuildMemory.MemoryImprint, boolean)}
* Tests that {@link ParameterExpander#getMinimumVerifiedValue(BuildMemory.MemoryImprint, boolean, Integer)}
* returns {@link TestParameter#expectedVerified}.
*/
@Test
public void testVerified() {
IGerritHudsonTriggerConfig config = Setup.createConfig();
ParameterExpander instance = new ParameterExpander(config);
Integer result = instance.getMinimumVerifiedValue(parameter.memoryImprint, true);
Integer result = instance.getMinimumVerifiedValue(parameter.memoryImprint, true, Integer.MAX_VALUE);
if (parameter.expectedVerified == null) {
assertNull(result);
} else {
Expand Down

0 comments on commit 26870c3

Please sign in to comment.