Skip to content

Commit

Permalink
Merge pull request #206 from saucelabs/alexh-restore-sc5
Browse files Browse the repository at this point in the history
Revert "Revert "Merge pull request #201 from saucelabs/alexh-sc-5""
  • Loading branch information
alexh-sauce authored Nov 15, 2024
2 parents dc61fe3 + f66b3c8 commit d3bc1b0
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 93 deletions.
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 @@ public class SauceOnDemandBuildWrapper extends BuildWrapper implements Serializa
/** 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 @@ private static String getCurrentHostName() {
* @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 @@ public Environment setUp(
}

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 @@ public boolean isUseLatestSauceConnect() {
return useLatestSauceConnect;
}

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

public boolean isUseGeneratedTunnelIdentifier() {
return useGeneratedTunnelIdentifier;
}
Expand Down Expand Up @@ -1170,11 +1174,11 @@ public SauceConnectHandler call() throws AbstractSauceTunnelManager.SauceConnect
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));
Expand Down Expand Up @@ -1305,7 +1309,7 @@ public Map<String, List<Browser>> getWebDriverMap() {
* @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

0 comments on commit d3bc1b0

Please sign in to comment.