Skip to content

Commit 2f9968e

Browse files
authored
Merge pull request #20 from rchougule/publishing
BrowserStack Report Publisher
2 parents 49144dd + be04bb5 commit 2f9968e

File tree

48 files changed

+2422
-1300
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2422
-1300
lines changed

pom.xml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111

1212
<artifactId>browserstack-integration</artifactId>
13-
<version>1.1.6-SNAPSHOT</version>
13+
<version>1.1.6</version>
1414
<packaging>hpi</packaging>
1515

1616
<name>BrowserStack</name>
@@ -138,13 +138,13 @@
138138
<dependency>
139139
<groupId>com.browserstack</groupId>
140140
<artifactId>automate-client-java</artifactId>
141-
<version>0.4</version>
141+
<version>0.5</version>
142142
</dependency>
143143

144144
<dependency>
145145
<groupId>com.browserstack</groupId>
146146
<artifactId>browserstack-local-java</artifactId>
147-
<version>1.0.2</version>
147+
<version>1.0.3</version>
148148
</dependency>
149149

150150
<dependency>
@@ -233,6 +233,25 @@
233233
<version>1.7</version>
234234
</dependency>
235235

236+
<dependency>
237+
<groupId>com.fasterxml.jackson.core</groupId>
238+
<artifactId>jackson-core</artifactId>
239+
<version>2.1.0</version>
240+
</dependency>
241+
<dependency>
242+
<groupId>com.fasterxml.jackson.core</groupId>
243+
<artifactId>jackson-databind</artifactId>
244+
<version>2.1.0</version>
245+
</dependency>
246+
247+
<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
248+
<dependency>
249+
<groupId>com.squareup.okhttp3</groupId>
250+
<artifactId>okhttp</artifactId>
251+
<version>3.14.9</version>
252+
</dependency>
253+
254+
236255
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
237256
<dependency>
238257
<groupId>commons-io</groupId>

src/main/java/com/browserstack/automate/ci/common/AutomateTestCase.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package com.browserstack.automate.ci.common;
22

3-
import org.apache.commons.lang.StringUtils;
4-
53
import com.browserstack.automate.ci.common.logger.PluginLogger;
4+
import org.apache.commons.lang.StringUtils;
65

76
import java.io.Serializable;
87
import java.util.regex.Matcher;
@@ -50,10 +49,6 @@ public AutomateTestCase(String sessionId, String packageName, String className,
5049
this.testHash = null;
5150
}
5251

53-
public boolean hasTestHash() {
54-
return (testHash != null && testHash.length() > 0);
55-
}
56-
5752
public static String stripTestParams(String testCaseName) {
5853
if (StringUtils.isEmpty(testCaseName)) {
5954
return null;
@@ -122,4 +117,8 @@ private static AutomateTestCase parseTestCasePath(final String testCasePath, fin
122117

123118
return null;
124119
}
120+
121+
public boolean hasTestHash() {
122+
return (testHash != null && testHash.length() > 0);
123+
}
125124
}
Lines changed: 120 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
package com.browserstack.automate.ci.common;
22

3-
import static com.browserstack.automate.ci.common.logger.PluginLogger.log;
4-
import java.io.File;
5-
import java.io.IOException;
6-
import java.io.PrintStream;
7-
import java.util.ArrayList;
8-
import java.util.Map;
9-
import org.apache.commons.lang.StringUtils;
10-
import org.apache.tools.ant.FileScanner;
11-
import org.apache.tools.ant.types.FileSet;
123
import com.browserstack.automate.ci.jenkins.BrowserStackCredentials;
134
import com.browserstack.automate.ci.jenkins.local.JenkinsBrowserStackLocal;
145
import com.browserstack.automate.ci.jenkins.local.LocalConfig;
@@ -23,129 +14,145 @@
2314
import hudson.security.ACL;
2415
import hudson.util.FormValidation;
2516
import hudson.util.ListBoxModel;
17+
import org.apache.commons.lang.StringUtils;
18+
import org.apache.tools.ant.FileScanner;
19+
import org.apache.tools.ant.types.FileSet;
20+
21+
import java.io.File;
22+
import java.io.IOException;
23+
import java.io.PrintStream;
24+
import java.util.ArrayList;
25+
import java.util.Map;
26+
27+
import static com.browserstack.automate.ci.common.logger.PluginLogger.log;
2628

2729
public class BrowserStackBuildWrapperOperations {
28-
private BrowserStackCredentials credentials;
29-
private boolean isTearDownPhase;
30-
private PrintStream logger;
31-
private static final String ENV_JENKINS_BUILD_TAG = "BUILD_TAG";
32-
private LocalConfig localConfig;
33-
private JenkinsBrowserStackLocal browserstackLocal;
34-
35-
public BrowserStackBuildWrapperOperations(BrowserStackCredentials credentials,
36-
boolean isTearDownPhase, PrintStream logger, LocalConfig localConfig,
37-
JenkinsBrowserStackLocal browserStackLocal) {
38-
super();
39-
this.credentials = credentials;
40-
this.isTearDownPhase = isTearDownPhase;
41-
this.logger = logger;
42-
this.localConfig = localConfig;
43-
this.browserstackLocal = browserStackLocal;
44-
}
45-
46-
public void buildEnvVars(Map<String, String> env) {
47-
if (credentials != null) {
48-
if (credentials.hasUsername()) {
49-
String username = credentials.getUsername();
50-
51-
env.put(BrowserStackEnvVars.BROWSERSTACK_USER, username + "-jenkins");
52-
env.put(BrowserStackEnvVars.BROWSERSTACK_USERNAME, username + "-jenkins");
53-
logEnvVar(BrowserStackEnvVars.BROWSERSTACK_USERNAME, username);
54-
}
55-
56-
if (credentials.hasAccesskey()) {
57-
String accesskey = credentials.getDecryptedAccesskey();
58-
env.put(BrowserStackEnvVars.BROWSERSTACK_ACCESSKEY, accesskey);
59-
env.put(BrowserStackEnvVars.BROWSERSTACK_ACCESS_KEY, accesskey);
60-
logEnvVar(BrowserStackEnvVars.BROWSERSTACK_ACCESS_KEY, Tools.maskString(accesskey));
61-
}
30+
private static final String ENV_JENKINS_BUILD_TAG = "BUILD_TAG";
31+
private BrowserStackCredentials credentials;
32+
private boolean isTearDownPhase;
33+
private PrintStream logger;
34+
private LocalConfig localConfig;
35+
private JenkinsBrowserStackLocal browserstackLocal;
36+
37+
public BrowserStackBuildWrapperOperations(BrowserStackCredentials credentials,
38+
boolean isTearDownPhase, PrintStream logger, LocalConfig localConfig,
39+
JenkinsBrowserStackLocal browserStackLocal) {
40+
super();
41+
this.credentials = credentials;
42+
this.isTearDownPhase = isTearDownPhase;
43+
this.logger = logger;
44+
this.localConfig = localConfig;
45+
this.browserstackLocal = browserStackLocal;
6246
}
6347

64-
String buildTag = env.get(ENV_JENKINS_BUILD_TAG);
65-
if (buildTag != null) {
66-
env.put(BrowserStackEnvVars.BROWSERSTACK_BUILD, buildTag);
67-
logEnvVar(BrowserStackEnvVars.BROWSERSTACK_BUILD, buildTag);
48+
public static ListBoxModel doFillCredentialsIdItems(Item context) {
49+
if (context != null && !context.hasPermission(Item.CONFIGURE)) {
50+
return new StandardListBoxModel();
51+
}
52+
53+
return new StandardListBoxModel().withMatching(
54+
CredentialsMatchers.anyOf(CredentialsMatchers.instanceOf(BrowserStackCredentials.class)),
55+
CredentialsProvider.lookupCredentials(BrowserStackCredentials.class, context, ACL.SYSTEM,
56+
new ArrayList<DomainRequirement>()));
6857
}
6958

70-
String isLocalEnabled = localConfig != null ? "true" : "false";
71-
env.put(BrowserStackEnvVars.BROWSERSTACK_LOCAL, "" + isLocalEnabled);
72-
logEnvVar(BrowserStackEnvVars.BROWSERSTACK_LOCAL, isLocalEnabled);
59+
public static FormValidation doCheckLocalPath(final AbstractProject project,
60+
final String localPath) {
61+
final String path = Util.fixEmptyAndTrim(localPath);
62+
if (StringUtils.isBlank(path)) {
63+
return FormValidation.ok();
64+
}
7365

74-
String localIdentifier =
75-
(browserstackLocal != null) ? browserstackLocal.getLocalIdentifier() : "";
66+
try {
67+
File f = resolvePath(project, localPath);
68+
if (f != null) {
69+
return FormValidation.ok();
70+
}
71+
} catch (Exception e) {
72+
return FormValidation.error(e.getMessage());
73+
}
7674

77-
if (StringUtils.isNotBlank(localIdentifier)) {
78-
env.put(BrowserStackEnvVars.BROWSERSTACK_LOCAL_IDENTIFIER, localIdentifier);
79-
logEnvVar(BrowserStackEnvVars.BROWSERSTACK_LOCAL_IDENTIFIER, localIdentifier);
75+
return FormValidation.error("Invalid path.");
8076
}
81-
}
8277

83-
public void logEnvVar(String key, String value) {
84-
if (!isTearDownPhase) {
85-
log(logger, key + "=" + value);
86-
}
87-
}
78+
private static File resolvePath(final AbstractProject project, final String path)
79+
throws IOException, InterruptedException {
80+
File f = new File(path);
81+
if (f.isAbsolute() && (!f.isFile() || !f.canExecute())) {
82+
return null;
83+
}
8884

89-
public static ListBoxModel doFillCredentialsIdItems(Item context) {
90-
if (context != null && !context.hasPermission(Item.CONFIGURE)) {
91-
return new StandardListBoxModel();
92-
}
85+
// For absolute paths
86+
FormValidation validateExec = FormValidation.validateExecutable(path);
87+
if (validateExec.kind == FormValidation.Kind.OK) {
88+
return f;
89+
}
9390

94-
return new StandardListBoxModel().withMatching(
95-
CredentialsMatchers.anyOf(CredentialsMatchers.instanceOf(BrowserStackCredentials.class)),
96-
CredentialsProvider.lookupCredentials(BrowserStackCredentials.class, context, ACL.SYSTEM,
97-
new ArrayList<DomainRequirement>()));
98-
}
99-
100-
public static FormValidation doCheckLocalPath(final AbstractProject project,
101-
final String localPath) {
102-
final String path = Util.fixEmptyAndTrim(localPath);
103-
if (StringUtils.isBlank(path)) {
104-
return FormValidation.ok();
91+
// Ant style path definitions
92+
FilePath workspace = project.getSomeWorkspace();
93+
if (workspace != null) {
94+
File workspaceRoot = new File(workspace.toURI());
95+
FileSet fileSet = Util.createFileSet(workspaceRoot, path);
96+
FileScanner fs = fileSet.getDirectoryScanner();
97+
fs.setIncludes(new String[]{path});
98+
fs.scan();
99+
100+
String[] includedFiles = fs.getIncludedFiles();
101+
if (includedFiles.length > 0) {
102+
File includedFile = new File(workspaceRoot, includedFiles[0]);
103+
if (includedFile.exists() && includedFile.isFile() && includedFile.canExecute()) {
104+
return includedFile;
105+
}
106+
}
107+
}
108+
return null;
105109
}
106110

107-
try {
108-
File f = resolvePath(project, localPath);
109-
if (f != null) {
110-
return FormValidation.ok();
111-
}
112-
} catch (Exception e) {
113-
return FormValidation.error(e.getMessage());
114-
}
111+
public void buildEnvVars(Map<String, String> env) {
112+
if (credentials != null) {
113+
if (credentials.hasUsername()) {
114+
String username = credentials.getUsername();
115+
116+
env.put(BrowserStackEnvVars.BROWSERSTACK_USER, username + "-jenkins");
117+
env.put(BrowserStackEnvVars.BROWSERSTACK_USERNAME, username + "-jenkins");
118+
logEnvVar(BrowserStackEnvVars.BROWSERSTACK_USERNAME, username);
119+
}
120+
121+
if (credentials.hasAccesskey()) {
122+
String accesskey = credentials.getDecryptedAccesskey();
123+
env.put(BrowserStackEnvVars.BROWSERSTACK_ACCESSKEY, accesskey);
124+
env.put(BrowserStackEnvVars.BROWSERSTACK_ACCESS_KEY, accesskey);
125+
logEnvVar(BrowserStackEnvVars.BROWSERSTACK_ACCESS_KEY, Tools.maskString(accesskey));
126+
}
127+
}
115128

116-
return FormValidation.error("Invalid path.");
117-
}
129+
String buildTag = env.get(ENV_JENKINS_BUILD_TAG);
130+
if (buildTag != null) {
131+
env.put(BrowserStackEnvVars.BROWSERSTACK_BUILD, buildTag);
132+
logEnvVar(BrowserStackEnvVars.BROWSERSTACK_BUILD, buildTag);
118133

119-
private static File resolvePath(final AbstractProject project, final String path)
120-
throws IOException, InterruptedException {
121-
File f = new File(path);
122-
if (f.isAbsolute() && (!f.isFile() || !f.canExecute())) {
123-
return null;
124-
}
134+
// Maintaining build name separately to have more control over it.
135+
// To keep it consistent with other CI/CD plugins.
136+
env.put(BrowserStackEnvVars.BROWSERSTACK_BUILD_NAME, buildTag);
137+
logEnvVar(BrowserStackEnvVars.BROWSERSTACK_BUILD_NAME, buildTag);
138+
}
139+
140+
String isLocalEnabled = localConfig != null ? "true" : "false";
141+
env.put(BrowserStackEnvVars.BROWSERSTACK_LOCAL, "" + isLocalEnabled);
142+
logEnvVar(BrowserStackEnvVars.BROWSERSTACK_LOCAL, isLocalEnabled);
125143

126-
// For absolute paths
127-
FormValidation validateExec = FormValidation.validateExecutable(path);
128-
if (validateExec.kind == FormValidation.Kind.OK) {
129-
return f;
144+
String localIdentifier =
145+
(browserstackLocal != null) ? browserstackLocal.getLocalIdentifier() : "";
146+
147+
if (StringUtils.isNotBlank(localIdentifier)) {
148+
env.put(BrowserStackEnvVars.BROWSERSTACK_LOCAL_IDENTIFIER, localIdentifier);
149+
logEnvVar(BrowserStackEnvVars.BROWSERSTACK_LOCAL_IDENTIFIER, localIdentifier);
150+
}
130151
}
131152

132-
// Ant style path definitions
133-
FilePath workspace = project.getSomeWorkspace();
134-
if (workspace != null) {
135-
File workspaceRoot = new File(workspace.toURI());
136-
FileSet fileSet = Util.createFileSet(workspaceRoot, path);
137-
FileScanner fs = fileSet.getDirectoryScanner();
138-
fs.setIncludes(new String[] {path});
139-
fs.scan();
140-
141-
String[] includedFiles = fs.getIncludedFiles();
142-
if (includedFiles.length > 0) {
143-
File includedFile = new File(workspaceRoot, includedFiles[0]);
144-
if (includedFile.exists() && includedFile.isFile() && includedFile.canExecute()) {
145-
return includedFile;
153+
public void logEnvVar(String key, String value) {
154+
if (!isTearDownPhase) {
155+
log(logger, key + "=" + value);
146156
}
147-
}
148157
}
149-
return null;
150-
}
151158
}
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.browserstack.automate.ci.common;
22

33
public interface BrowserStackEnvVars {
4-
String BROWSERSTACK_USER = "BROWSERSTACK_USER";
5-
String BROWSERSTACK_USERNAME = "BROWSERSTACK_USERNAME";
6-
String BROWSERSTACK_ACCESSKEY = "BROWSERSTACK_ACCESSKEY";
7-
String BROWSERSTACK_ACCESS_KEY = "BROWSERSTACK_ACCESS_KEY";
8-
String BROWSERSTACK_LOCAL = "BROWSERSTACK_LOCAL";
9-
String BROWSERSTACK_LOCAL_IDENTIFIER = "BROWSERSTACK_LOCAL_IDENTIFIER";
10-
String BROWSERSTACK_BUILD = "BROWSERSTACK_BUILD";
11-
String BROWSERSTACK_APP_ID = "BROWSERSTACK_APP_ID";
4+
String BROWSERSTACK_USER = "BROWSERSTACK_USER";
5+
String BROWSERSTACK_USERNAME = "BROWSERSTACK_USERNAME";
6+
String BROWSERSTACK_ACCESSKEY = "BROWSERSTACK_ACCESSKEY";
7+
String BROWSERSTACK_ACCESS_KEY = "BROWSERSTACK_ACCESS_KEY";
8+
String BROWSERSTACK_LOCAL = "BROWSERSTACK_LOCAL";
9+
String BROWSERSTACK_LOCAL_IDENTIFIER = "BROWSERSTACK_LOCAL_IDENTIFIER";
10+
String BROWSERSTACK_BUILD = "BROWSERSTACK_BUILD";
11+
String BROWSERSTACK_BUILD_NAME = "BROWSERSTACK_BUILD_NAME";
12+
String BROWSERSTACK_APP_ID = "BROWSERSTACK_APP_ID";
1213
}

0 commit comments

Comments
 (0)