Skip to content

Commit

Permalink
Remove dead code for obsolete versions (#1690)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Aug 27, 2024
1 parent f4955f4 commit 96378c1
Show file tree
Hide file tree
Showing 39 changed files with 66 additions and 473 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
import org.jenkinsci.test.acceptance.po.Job;
import org.jenkinsci.test.acceptance.po.WorkflowJob;
import org.jenkinsci.test.acceptance.utils.PipelineTestUtils;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.NoSuchFrameException;

@WithPlugins({"workflow-job", "workflow-cps", "workflow-basic-steps", "workflow-durable-task-step"})
public class AbstractPipelineTest extends AbstractJUnitTest {
Expand Down Expand Up @@ -72,28 +70,8 @@ protected void assertJavadoc(final Job job) {

find(by.link(JAVADOC_ACTION)).click();

/*
Same approach as https://github.com/jenkinsci/acceptance-test-harness/blob/b47dcb9a8abb771718a391372faf612a0734e76a/src/test/java/plugins/JavadocPluginTest.java#L92
Why do we check in such way?
The java version of the Jenkins under test could be different that the one in use by this code, the ATH code.
See: https://github.com/jenkinsci/acceptance-test-harness/blob/39cbea43b73d32a0912d613a41e08ba9b54aad1d/src/main/java/org/jenkinsci/test/acceptance/controller/LocalController.java#L190
In addition, the way javadoc is generated depends on the java version and the number of packages generated, one
or more packages.
See: https://issues.jenkins-ci.org/browse/JENKINS-32619?focusedCommentId=311819&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-311819
So even though it's not the most refined way to check the right generation of the javadoc, this way doesn't
need to call a groovy script for checking the java version neither checking the number of packages generated.
*/

try {
// Former behavior, javadoc generating frames and plugin without redirection
driver.switchTo().frame("classFrame");
} catch (NoSuchFrameException e) {
try {
// With Java11 a link to the package-summary is shown, no frames
find(by.partialLinkText("package-summary.html")).click();
} catch (NoSuchElementException nse) {
}
}
find(by.href("index-all.html")).click();
find(by.href("io/jenkins/tools/package-summary.html")).click();

assertThat(driver, hasContent("io.jenkins.tools"));
}
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/jenkinsci/test/acceptance/Matchers.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jenkinsci.test.acceptance;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import hudson.util.VersionNumber;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
Expand Down Expand Up @@ -229,11 +228,8 @@ public static Matcher<Login> hasInvalidLoginInformation() {
return new Matcher<Login>("has invalid login information message") {
@Override
public boolean matchesSafely(final Login login) {
String invalidLoginMessage = login.getJenkins().getVersion().isOlderThan(new VersionNumber("2.128"))
? "Invalid login information. Please try again."
: "Invalid username or password";
try {
login.find(by.xpath("//div[contains(text(), '%s')]", invalidLoginMessage));
login.find(by.xpath("//div[contains(text(), '%s')]", "Invalid username or password"));
return true;
} catch (NoSuchElementException e) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.lang.ProcessBuilder.Redirect;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
Expand All @@ -21,8 +18,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.SystemUtils;
import org.codehaus.plexus.util.Expand;
import org.codehaus.plexus.util.StringUtils;
import org.jenkinsci.test.acceptance.junit.FailureDiagnostics;
Expand Down Expand Up @@ -137,15 +132,6 @@ public void removeLogListener(LogListener l) {
logWatcher.removeLogListener(l);
}

/**
* @deprecated Will not work correctly in Jenkins 2.33 and later. Apparently unused anyway.
*/
@Deprecated
public File getSlaveJarPath() {
return new File(getJenkinsHome(),"war/WEB-INF/slave.jar"); // TODO look for war/WEB-INF/lib/remoting-*.jar instead
}


public File getJenkinsHome() {
return jenkinsHome;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.cloudbees.sdk.extensibility.Extension;
import com.google.inject.Injector;
import hudson.util.VersionNumber;
import jakarta.inject.Inject;
import java.io.File;
import java.io.IOException;
Expand All @@ -13,11 +12,9 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.jar.JarFile;
import java.util.logging.Logger;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.jenkinsci.test.acceptance.utils.IOUtil;
import org.jenkinsci.utils.process.CommandBuilder;
import org.jenkinsci.utils.process.ProcessInputStream;

Expand All @@ -33,8 +30,6 @@ public class WinstoneController extends LocalController {
// options to the JVM that can be added on a testcase basis in code
private final List<String> JAVA_OPTS = new ArrayList<>();

private static final VersionNumber v2339 = new VersionNumber("2.339");

private File portFile;

protected static List<String> envVarOpts(String jenkins_opts) {
Expand All @@ -61,14 +56,6 @@ public WinstoneController(Injector i, int httpPort) {
this.httpPort = httpPort;
}

@Override
public void startNow() throws IOException {
if (httpPort == 0 && !supportsPortFileName()) {
httpPort = IOUtil.randomTcpPort();
}
super.startNow();
}

@Override
protected void onReady() throws IOException {
if (this.httpPort == 0 && portFile != null) {
Expand All @@ -92,11 +79,9 @@ public ProcessInputStream startProcess() throws IOException{
cb.addAll(JAVA_OPTS);
cb.add("-Duser.language=en",
"-Djenkins.formelementpath.FormElementPathPageDecorator.enabled=true");
if (supportsPortFileName()) {
portFile = File.createTempFile("jenkins-port", ".txt");
portFile.deleteOnExit();
cb.add("-Dwinstone.portFileName=" + portFile.getAbsolutePath());
}
portFile = File.createTempFile("jenkins-port", ".txt");
portFile.deleteOnExit();
cb.add("-Dwinstone.portFileName=" + portFile.getAbsolutePath());
cb.add("-jar", war,
"--httpPort=" + httpPort
);
Expand All @@ -107,14 +92,6 @@ public ProcessInputStream startProcess() throws IOException{
return cb.popen();
}

private boolean supportsPortFileName() throws IOException {
try (JarFile warFile = new JarFile(war)) {
String jenkinsVersion = warFile.getManifest().getMainAttributes().getValue("Jenkins-Version");
VersionNumber version = new VersionNumber(jenkinsVersion);
return version.compareTo(v2339) >= 0;
}
}

@Override
public URL getUrl() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.apache.commons.io.IOUtils;
import org.jenkinsci.test.acceptance.po.Jenkins;
import org.jenkinsci.test.acceptance.po.JenkinsLogger;
import org.openqa.selenium.WebElement;

abstract public class AuditTrailLogger extends JenkinsLogger {

Expand All @@ -43,49 +42,13 @@ private AuditTrailLogger(Jenkins jenkins, String name) {
}

public static AuditTrailLogger create(Jenkins jenkins) {
if (jenkins.getPlugin("audit-trail").isNewerThan("2.0")) {
return new ExposedFile(jenkins);
}

final SystemLogger logger = new SystemLogger(jenkins);

logger.waitFor().until(() -> {
logger.open();
return logger.getElement(by.xpath("//h1[text()='%s']", logger.name));
});
return logger;
return new ExposedFile(jenkins);
}

public abstract List<String> getEvents();

/**
* Audit Trail pre 2.0 uses system logger.
*/
private static class SystemLogger extends AuditTrailLogger {

public SystemLogger(Jenkins jenkins) {
super(jenkins, "Audit Trail");
}

@Override
public List<String> getEvents() {
open();
List<String> events = new ArrayList<>();
for (WebElement e : all(by.css("#main-panel pre"))) {
Matcher m = LOG_PATTERN.matcher(e.getText());
if (!m.matches()) {
continue; // Earlier versions used one element per log entry newer use two
}
events.add(m.group(1));
}
return events;
}
}

/**
* Expose file through /userContent/ and wrap in Logger.
* <p>
* Traditional logger in no longer created after Audit Trail 2.0
*/
private static class ExposedFile extends AuditTrailLogger {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,7 @@ private void ensureActive() {
}

private void chooseStrategy(String name) {
// JENKINS-20164
if (job.getJenkins().getPlugin("build-timeout").isNewerThan("1.14")) {
control("/").select(name);
} else {
choose(name);
}
control("/").select(name);
}

public void abortBuild() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jenkinsci.test.acceptance.plugins.config_file_provider;

import hudson.util.VersionNumber;
import org.jenkinsci.test.acceptance.po.CodeMirror;
import org.jenkinsci.test.acceptance.po.Describable;

Expand All @@ -15,18 +14,10 @@ public CustomConfig(ConfigFileProvider context, String id) {
}

/**
* From config-file-provider:3.8.0, the content box of the custom files is a CodeMirror object instead of a textarea
* @param customContent the content to set
*/
@Override
public void content(String customContent) {
final String PATH = "/config/content";
boolean contentIsOldTextArea = this.getJenkins().getPlugin("config-file-provider").getVersion().isOlderThan(new VersionNumber("3.8.0"));

if (contentIsOldTextArea) {
control(PATH).set(customContent);
} else {
new CodeMirror(this, PATH).set(customContent);
}
new CodeMirror(this, "/config/content").set(customContent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import java.net.URL;
import org.jenkinsci.test.acceptance.po.ConfigurablePageObject;
import org.jenkinsci.test.acceptance.po.Jenkins;
import org.openqa.selenium.NoSuchElementException;


public class DomainPage extends ConfigurablePageObject {

Expand Down Expand Up @@ -43,12 +41,7 @@ public void save() {
if (this.onDomainConfigurationPage()) {
clickButton("Save");
} else {
try {
clickButton("Create");
} catch (NoSuchElementException e) {
// prior to credentials:1105.vb_4e24a_c78b_81 once it makes it to LTS remove fallback
clickButton("OK");
}
clickButton("Create");
}

assertThat(driver, not(hasContent("This page expects a form submission")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.jenkinsci.test.acceptance.po.PageAreaImpl;
import org.jenkinsci.test.acceptance.po.PageObject;
import org.openqa.selenium.By;
Expand Down Expand Up @@ -54,8 +53,6 @@ public List<String> getHeaders() {
public List<String> getJobIDs() {
return find(projectStatusTable).findElements(By.xpath(".//tr"))
.stream()
// ignore the header row from <2.321
.filter(tr -> !StringUtils.contains(tr.getAttribute("class"), "header"))
.map(el -> el.getAttribute("id"))
.map(s -> s.replaceFirst(JOB_ID_PREFIX, ""))
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jenkinsci.test.acceptance.plugins.email_ext;

import org.jenkinsci.test.acceptance.po.*;
import org.openqa.selenium.NoSuchElementException;

/**
* @author Kohsuke Kawaguchi
Expand All @@ -22,14 +21,7 @@ public void setRecipient(String r) {
recipient.set(r);

ensureAdvancedOpened();
// since 2.38 refactored to hetero-list, recepients ware preselected
try {
control("project_triggers/sendToList").check();
} catch (NoSuchElementException ex) {
// some later releases do not preselect recipients
control("project_triggers/hetero-list-add[recipientProviders]").selectDropdownMenu("Recipient List");

}
control("project_triggers/hetero-list-add[recipientProviders]").selectDropdownMenu("Recipient List");
}

public void ensureAdvancedOpened() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import org.jenkinsci.test.acceptance.po.JenkinsConfig;
import org.jenkinsci.test.acceptance.po.PageAreaImpl;
import org.openqa.selenium.NoSuchElementException;

public class GlobalConfig extends PageAreaImpl {

Expand Down Expand Up @@ -54,9 +53,6 @@ public void auth(String name, String passwd) {
}

private void ensureAdvanced() {
try {
control("advanced-button").click();
} catch(NoSuchElementException ignored) {
}
control("advanced-button").click();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import org.jenkinsci.test.acceptance.po.*;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.support.ui.Select;

@Describable("Git")
Expand Down Expand Up @@ -63,24 +62,12 @@ public GitScm branch(String branch) {
}

public GitScm localBranch(String branch) {
try {
advanced();
control("localBranch").set(branch);
}
catch (NoSuchElementException ex) { // Git 2.0
addBehaviour(CheckoutToLocalBranch.class).name.set(branch);
}
addBehaviour(CheckoutToLocalBranch.class).name.set(branch);
return this;
}

public GitScm localDir(String dir) {
try {
advanced();
control("relativeTargetDir").set(dir);
}
catch (NoSuchElementException ex) { // Git 2.0
addBehaviour(CheckoutToLocalDir.class).name.set(dir);
}
addBehaviour(CheckoutToLocalDir.class).name.set(dir);
return this;
}

Expand Down
Loading

0 comments on commit 96378c1

Please sign in to comment.