Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert "Merge pull request #201 from saucelabs/alexh-sc-5"" #206

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 15 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<!-- Baseline Jenkins version you use to build the plugin. Users must have this version or newer to run. -->
<jenkins.baseline>2.452</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.4</jenkins.version>
<ci-sauce.version>1.179</ci-sauce.version>
<saucerest.version>2.4.0</saucerest.version>
<ci-sauce.version>2.0</ci-sauce.version>
<saucerest.version>2.5.3</saucerest.version>
</properties>


Expand Down Expand Up @@ -104,7 +104,7 @@
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>1.9.21</version>
<version>1.9.25</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down Expand Up @@ -310,6 +310,12 @@
<version>2.0.21</version>
</dependency>

<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<version>3.9.1</version>
</dependency>

<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-test-harness-tools</artifactId>
Expand All @@ -322,6 +328,12 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.moshi</groupId>
<artifactId>moshi</artifactId>
<version>1.15.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.saucelabs.jenkins;

import com.saucelabs.ci.sauceconnect.SauceConnectFourManager;
import com.saucelabs.ci.sauceconnect.SauceConnectManager;
import org.apache.commons.lang.StringUtils;

/**
* @author Ross Rowe
*/
public class HudsonSauceConnectFourManager extends SauceConnectFourManager {
public class HudsonSauceConnectManager extends SauceConnectManager {

private String workingDirectory;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.saucelabs.jenkins;

import com.saucelabs.ci.sauceconnect.SauceConnectFourManager;
import com.saucelabs.ci.sauceconnect.SauceConnectManager;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

Expand All @@ -13,7 +13,7 @@ public class HudsonSauceManagerFactory {

private Lock accessLock = new ReentrantLock();

private SauceConnectFourManager sauceConnectFourManager;
private SauceConnectManager sauceConnectManager;

public static HudsonSauceManagerFactory getInstance() {
return INSTANCE;
Expand All @@ -22,14 +22,14 @@ public static HudsonSauceManagerFactory getInstance() {
private HudsonSauceManagerFactory() {
}

public SauceConnectFourManager createSauceConnectFourManager() {
public SauceConnectManager createSauceConnectManager() {
accessLock.lock();
try {
if (sauceConnectFourManager == null)
if (sauceConnectManager == null)
{
sauceConnectFourManager = new HudsonSauceConnectFourManager();
sauceConnectManager = new HudsonSauceConnectManager();
}
return sauceConnectFourManager;
return sauceConnectManager;
} finally {
accessLock.unlock();
}
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/com/saucelabs/jenkins/pipeline/SauceConnectStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import com.cloudbees.plugins.credentials.common.StandardUsernameListBoxModel;
import com.saucelabs.ci.sauceconnect.AbstractSauceTunnelManager;
import com.saucelabs.ci.sauceconnect.SauceConnectFourManager;
import com.saucelabs.ci.sauceconnect.SauceConnectManager;
import com.saucelabs.jenkins.HudsonSauceManagerFactory;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
Expand Down Expand Up @@ -107,11 +107,6 @@ public Boolean getUseLatestSauceConnect() {
return useLatestSauceConnect;
}

@DataBoundSetter
public void setUseLatestSauceConnect(Boolean useLatestSauceConnect) {
this.useLatestSauceConnect = useLatestSauceConnect;
}

public Boolean getVerboseLogging() {
return verboseLogging;
}
Expand Down Expand Up @@ -174,7 +169,7 @@ private static final class SauceStartConnectHandler extends MasterToSlaveCallabl

@Override
public Void call() throws AbstractSauceTunnelManager.SauceConnectException {
SauceConnectFourManager sauceTunnelManager = getSauceTunnelManager();
SauceConnectManager sauceTunnelManager = getSauceTunnelManager();
sauceTunnelManager.setSauceRest(sauceCredentials.getSauceREST(proxy));
sauceTunnelManager.setUseLatestSauceConnect(useLatestSauceConnect);
sauceTunnelManager.openConnection(
Expand Down Expand Up @@ -208,7 +203,7 @@ private static final class SauceStopConnectHandler extends MasterToSlaveCallable

@Override
public Void call() throws AbstractSauceTunnelManager.SauceConnectException {
SauceConnectFourManager sauceTunnelManager = getSauceTunnelManager();
SauceConnectManager sauceTunnelManager = getSauceTunnelManager();
sauceTunnelManager.setSauceRest(sauceCredentials.getSauceREST(proxy));
sauceTunnelManager.closeTunnelsForPlan(
sauceCredentials.getUsername(),
Expand Down Expand Up @@ -324,8 +319,8 @@ public void stop(@NonNull Throwable cause) throws Exception {

}

public static SauceConnectFourManager getSauceTunnelManager() {
return HudsonSauceManagerFactory.getInstance().createSauceConnectFourManager();
public static SauceConnectManager getSauceTunnelManager() {
return HudsonSauceManagerFactory.getInstance().createSauceConnectManager();
}

private static final class Callback extends BodyExecutionCallback.TailCall {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.cloudbees.plugins.credentials.common.StandardUsernameListBoxModel;
import com.saucelabs.ci.Browser;
import com.saucelabs.ci.sauceconnect.AbstractSauceTunnelManager;
import com.saucelabs.jenkins.HudsonSauceConnectFourManager;
import com.saucelabs.jenkins.HudsonSauceConnectManager;
import com.saucelabs.jenkins.HudsonSauceManagerFactory;
import com.saucelabs.saucerest.DataCenter;
import com.saucelabs.saucerest.SauceException;
Expand Down Expand Up @@ -191,6 +191,14 @@
/** Indicates whether Sauce Connect should be started as part of the build. */
private boolean enableSauceConnect;

private static Map<String, String> endpointToRegion = Map.of(
"https://saucelabs.com/", "us-west",
"https://eu-central-1.saucelabs.com/", "eu-central",
"https://us-east-4.saucelabs.com/", "us-east",
// Deprecated endpoint but it hasn't been removed from Sauce Credentials yet
"https://us-east-1.saucelabs.com/", "us-east"
);

/** Host location of the selenium server. */
private String seleniumHost;

Expand Down Expand Up @@ -340,7 +348,7 @@
* @throws ComponentLookupException see plexus
*/
public static AbstractSauceTunnelManager getSauceTunnelManager() throws ComponentLookupException {
return HudsonSauceManagerFactory.getInstance().createSauceConnectFourManager();
return HudsonSauceManagerFactory.getInstance().createSauceConnectManager();
}

@Override
Expand Down Expand Up @@ -392,7 +400,7 @@
}

build.getBuildVariables().put(SAUCE_REST_ENDPOINT, restEndpoint);
resolvedOptions = resolvedOptions + " -x " + restEndpoint + "rest/v1";
resolvedOptions = resolvedOptions + " --region " + this.endpointToRegion.get(restEndpoint);

try {
if (condition != null) {
Expand Down Expand Up @@ -925,10 +933,6 @@
return useLatestSauceConnect;
}

public void setUseLatestSauceConnect(boolean useLatestSauceConnect) {
this.useLatestSauceConnect = useLatestSauceConnect;
}

public boolean isUseGeneratedTunnelIdentifier() {
return useGeneratedTunnelIdentifier;
}
Expand Down Expand Up @@ -1170,142 +1174,142 @@
try {
listener.getLogger().println("Launching Sauce Connect on " + getCurrentHostName());
sauceTunnelManager = getSauceTunnelManager();
if (sauceTunnelManager instanceof HudsonSauceConnectFourManager
if (sauceTunnelManager instanceof HudsonSauceConnectManager

Check warning on line 1177 in src/main/java/hudson/plugins/sauce_ondemand/SauceOnDemandBuildWrapper.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 1177 is only partially covered, 3 branches are missing
&& workingDirectory != null) {
((HudsonSauceConnectFourManager) sauceTunnelManager)
((HudsonSauceConnectManager) sauceTunnelManager)
.setWorkingDirectory(workingDirectory);
((HudsonSauceConnectFourManager) sauceTunnelManager)
((HudsonSauceConnectManager) sauceTunnelManager)
.setUseLatestSauceConnect(useLatestSauceConnect);
}
sauceTunnelManager.setSauceRest(new JenkinsSauceREST(username, key, dataCenter, proxy));
if (StringUtils.isBlank(username)) {
listener.getLogger().println("Username not set, not starting Sauce Connect");
} else if (StringUtils.isBlank(key)) {
listener.getLogger().println("Access key not set, not starting Sauce Connect");
} else if (StringUtils.isBlank(dataCenter.server)) {
listener.getLogger().println("Data center not set, not starting Sauce Connect");
}
} catch (ComponentLookupException e) {
throw new AbstractSauceTunnelManager.SauceConnectException(e);
}

if (maxRetries > 0) {
int retryCount = 0;
while (retryCount < maxRetries) {
try {
sauceTunnelManager.openConnection(
username,
key,
dataCenter,
port,
sauceConnectJar,
options,
listener.getLogger(),
verboseLogging,
sauceConnectPath);
return this;
} catch (AbstractSauceTunnelManager.SauceConnectDidNotStartException e) {
retryCount++;
if (retryCount >= maxRetries) {
throw new AbstractSauceTunnelManager.SauceConnectException(e);
} else {
listener
.getLogger()
.println(
String.format(
"Error launching Sauce Connect, trying %s time(s) more.",
(maxRetries - retryCount)));
}
try {
Thread.sleep((long) 1000 * retryWaitTime);
} catch (InterruptedException ie) {
throw new AbstractSauceTunnelManager.SauceConnectException(ie);
}
}
}
} else {
sauceTunnelManager.openConnection(
username,
key,
dataCenter,
port,
sauceConnectJar,
options,
listener.getLogger(),
verboseLogging,
sauceConnectPath);
}
return this;
}
}

/** Plugin descriptor, which adds the plugin details to the Jenkins job configuration page. */
@Extension
public static class DescriptorImpl extends Descriptor<BuildWrapper> {
/**
* @return text to be displayed within Jenkins job configuration
*/
@Override
public String getDisplayName() {
return "Sauce Labs Support";
}

/**
* @return the list of supported Appium browsers
*/
public List<Browser> getAppiumBrowsers() {
try {
return PluginImpl.BROWSER_FACTORY.getAppiumBrowsers();
} catch (IOException e) {
logger.log(Level.SEVERE, "Error retreiving response", e);
} catch (JSONException e) {
logger.log(Level.SEVERE, "Error parsing JSON response", e);
}
return Collections.emptyList();
}

/**
* @return the list of supported WebDriver browsers
*/
public List<Browser> getWebDriverBrowsers() {
try {
return PluginImpl.BROWSER_FACTORY.getWebDriverBrowsers();
} catch (IOException e) {
logger.log(Level.SEVERE, "Error retreiving response", e);
} catch (JSONException e) {
logger.log(Level.SEVERE, "Error parsing JSON response", e);
}
return Collections.emptyList();
}

/**
* @return the list of supported WebDriver browsers
*/
public Map<String, List<Browser>> getWebDriverMap() {
try {
Map<String, List<Browser>> map = new HashMap<String, List<Browser>>();
for (Browser browser : PluginImpl.BROWSER_FACTORY.getWebDriverBrowsers()) {
List<Browser> browsers = map.get(browser.getOs());
if (browsers == null) {
browsers = new ArrayList<Browser>();
map.put(browser.getOs(), browsers);
}
browsers.add(browser);
}
return map;
} catch (IOException e) {
logger.log(Level.SEVERE, "Error retreiving response", e);
} catch (JSONException e) {
logger.log(Level.SEVERE, "Error parsing JSON response", e);
}
return Collections.emptyMap();
}

/**
* @return Sauce Connect version
*/
public String getSauceConnectVersion() {
return HudsonSauceConnectFourManager.CURRENT_SC_VERSION;
return HudsonSauceConnectManager.CURRENT_SC_VERSION;

Check warning on line 1312 in src/main/java/hudson/plugins/sauce_ondemand/SauceOnDemandBuildWrapper.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 1179-1312 are not covered by tests
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hudson.plugins.sauce_ondemand;

import com.saucelabs.ci.sauceconnect.SauceConnectFourManager;
import com.saucelabs.ci.sauceconnect.SauceConnectManager;
import com.saucelabs.jenkins.HudsonSauceManagerFactory;
import hudson.FilePath;
import hudson.matrix.MatrixBuild;
Expand Down Expand Up @@ -190,7 +190,7 @@ public void doGenerateSupportZip(StaplerRequest req, StaplerResponse rsp) throws
Permission p = Project.CONFIGURE;
ac.checkPermission(p);

SauceConnectFourManager manager = HudsonSauceManagerFactory.getInstance().createSauceConnectFourManager();
SauceConnectManager manager = HudsonSauceManagerFactory.getInstance().createSauceConnectManager();
SauceOnDemandBuildWrapper sauceBuildWrapper = getBuildWrapper();
Run<?, ?> build = job.getLastBuild();

Expand Down Expand Up @@ -231,7 +231,7 @@ public void doGenerateSupportZip(StaplerRequest req, StaplerResponse rsp) throws
}

public static class BuildSupportZipUtils {
public static void buildSauceConnectLog(ZipOutputStream zipOutputStream, SauceConnectFourManager manager, AbstractBuild build, SauceOnDemandBuildWrapper sauceBuildWrapper) throws IOException, InterruptedException {
public static void buildSauceConnectLog(ZipOutputStream zipOutputStream, SauceConnectManager manager, AbstractBuild build, SauceOnDemandBuildWrapper sauceBuildWrapper) throws IOException, InterruptedException {
if (sauceBuildWrapper.isEnableSauceConnect()) {
File sauceConnectLogFile = manager.getSauceConnectLogFile(sauceBuildWrapper.getOptions());
if (sauceBuildWrapper.isLaunchSauceConnectOnSlave()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import org.junit.Before;
import org.junit.Test;

public class HudsonSauceConnectFourManagerTest {
public class HudsonSauceConnectManagerTest {

private HudsonSauceConnectFourManager manager;
private HudsonSauceConnectManager manager;

@Before
public void setUp() throws Exception {
this.manager = new HudsonSauceConnectFourManager();
this.manager = new HudsonSauceConnectManager();
}

@Test
Expand All @@ -30,4 +30,4 @@ public void specificWorkingDirectory() throws Exception {
this.manager.setWorkingDirectory("/path");
assertEquals("/path", this.manager.getSauceConnectWorkingDirectory());
}
}
}
16 changes: 8 additions & 8 deletions src/test/java/com/saucelabs/jenkins/pipeline/SauceStepTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.saucelabs.ci.sauceconnect.SauceConnectFourManager;
import com.saucelabs.ci.sauceconnect.SauceConnectManager;
import com.saucelabs.jenkins.HudsonSauceManagerFactory;
import com.saucelabs.saucerest.DataCenter;

Expand Down Expand Up @@ -35,11 +35,11 @@ public void setUp() throws Exception {
}
}

private void storeDummyManager(SauceConnectFourManager sauceConnectFourManager) throws Exception {
private void storeDummyManager(SauceConnectManager sauceConnectManager) throws Exception {
HudsonSauceManagerFactory factory = HudsonSauceManagerFactory.getInstance();
Field field = HudsonSauceManagerFactory.class.getDeclaredField("sauceConnectFourManager");
Field field = HudsonSauceManagerFactory.class.getDeclaredField("sauceConnectManager");
field.setAccessible(true);
field.set(factory, sauceConnectFourManager);
field.set(factory, sauceConnectManager);
}

@Test
Expand Down Expand Up @@ -96,13 +96,13 @@ public void sauceConnectWithGlobalOptionsTest() throws Exception {
String credentialsId =
SauceCredentials.migrateToCredentials("fakeuser", "fakekey", null, "unittest");

SauceConnectFourManager sauceConnectFourManager = Mockito.mock(SauceConnectFourManager.class);
SauceConnectManager sauceConnectManager = Mockito.mock(SauceConnectManager.class);

storeDummyManager(sauceConnectFourManager);
storeDummyManager(sauceConnectManager);

// stubbing appears before the actual execution
Mockito.when(
sauceConnectFourManager.openConnection(
sauceConnectManager.openConnection(
Mockito.anyString(),
Mockito.anyString(),
Mockito.any(DataCenter.class),
Expand Down Expand Up @@ -131,7 +131,7 @@ public void sauceConnectWithGlobalOptionsTest() throws Exception {
r.assertLogContains("USERNAME=fakeuser", run);
r.assertLogContains("ACCESS_KEY=fakekey", run);

Mockito.verify(sauceConnectFourManager)
Mockito.verify(sauceConnectManager)
.openConnection(
Mockito.eq("fakeuser"),
Mockito.eq("fakekey"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hudson.plugins.sauce_ondemand;

import com.saucelabs.ci.sauceconnect.SauceConnectFourManager;
import com.saucelabs.ci.sauceconnect.SauceConnectManager;
import java.io.File;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -10,7 +10,7 @@
*/
public class ExtractSauceConnectTest {

private SauceConnectFourManager manager = new SauceConnectFourManager();
private SauceConnectManager manager = new SauceConnectManager();

@Before
public void setUp() throws Exception {
Expand All @@ -20,11 +20,11 @@ public void setUp() throws Exception {
@Test
public void linux() throws Exception {
File workingDirectory = new File(System.getProperty("java.io.tmpdir"));
manager.extractZipFile(workingDirectory, SauceConnectFourManager.OperatingSystem.LINUX);
manager.extractZipFile(workingDirectory, SauceConnectManager.OperatingSystem.LINUX_AMD64);
}

@Test
public void windows() throws Exception {
manager.extractZipFile(new File(System.getProperty("java.io.tmpdir")), SauceConnectFourManager.OperatingSystem.WINDOWS);
manager.extractZipFile(new File(System.getProperty("java.io.tmpdir")), SauceConnectManager.OperatingSystem.WINDOWS_AMD64);
}
}
Loading
Loading