Skip to content

Commit

Permalink
Merge pull request #17 from jenkinsci/release
Browse files Browse the repository at this point in the history
Added License Path Parameter
  • Loading branch information
mrdailey99 authored Jan 5, 2024
2 parents 705774e + cf49ce7 commit 91b13f4
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 17 deletions.
Binary file modified plugin-files/provar-automation.hpi
Binary file not shown.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@
<changelist>999999-SNAPSHOT</changelist>

<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
<jenkins.version>2.387.3</jenkins.version>
<jenkins.version>2.401.3</jenkins.version>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<!-- Pick up common dependencies for the selected LTS line: https://github.com/jenkinsci/bom#usage -->
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.387.x</artifactId>
<version>2102.v854b_fec19c92</version>
<artifactId>bom-2.401.x</artifactId>
<version>2675.v1515e14da_7a_6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
1 change: 1 addition & 0 deletions source-files/build_folders_provar_plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
pluginOutputlevel="WARNING"
stopTestRunOnError="false"
secretsPassword="${secrets.password}"
licensePath="${env.LICENSE_PATH}"
>
<fileset dir="${testproject.home}/tests/${env.TEST_FOLDER}"/>

Expand Down
1 change: 1 addition & 0 deletions source-files/build_provar_plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
pluginOutputlevel="WARNING"
stopTestRunOnError="false"
secretsPassword="${secrets.password}"
licensePath="${env.LICENSE_PATH}"
>
<fileset id="testplan" dir="${testproject.home}/plans/${env.TEST_PLAN}"/>
<planFeature name="PDF" type="OUTPUT" enabled="true"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{"list":[{"id":"latest","name":"latest","url":"https://provar-installers.s3-us-west-2.amazonaws.com/latest/Provar_ANT_latest.zip"},
{"id":"2.11.3","name":"2.11.3","url":"https://provar-installers.s3-us-west-2.amazonaws.com/2.11.3/Provar_ANT_2.11.3.11.zip"},
{"id":"2.11.2","name":"2.11.2","url":"https://provar-installers.s3-us-west-2.amazonaws.com/2.11.2/Provar_ANT_2.11.2.05.zip"},
{"id":"2.11.1","name":"2.11.1","url":"https://provar-installers.s3-us-west-2.amazonaws.com/2.11.1/Provar_ANT_2.11.1.04.zip"},
{"id":"2.10.2","name":"2.10.2","url":"https://provar-installers.s3-us-west-2.amazonaws.com/2.10.2/Provar_ANT_2.10.2.07.zip"},
Expand Down
43 changes: 34 additions & 9 deletions src/main/java/io/jenkins/plugins/ProvarAutomation.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public enum ResultsPathSettings {
private final ResultsPathSettings resultsPathSetting;
@NonNull
private final String projectName;
@NonNull
private final String licensePath;

@DataBoundConstructor
public ProvarAutomation(@NonNull String provarAutomationName,
Expand All @@ -99,17 +101,19 @@ public ProvarAutomation(@NonNull String provarAutomationName,
@NonNull Secret secretsPassword,
@NonNull SalesforceMetadataCacheSettings salesforceMetadataCacheSetting,
@NonNull ResultsPathSettings resultsPathSetting,
@NonNull String projectName) {
@NonNull String projectName,
@NonNull String licensePath) {
this.provarAutomationName = provarAutomationName;
this.buildFile = Util.fixEmptyAndTrim(buildFile);
this.testPlan = Util.fixEmptyAndTrim(testPlan);
this.testFolder = Util.fixEmptyAndTrim(testFolder);
this.buildFile = Objects.requireNonNull(buildFile);
this.testPlan = Objects.requireNonNull(testPlan);
this.testFolder = Objects.requireNonNull(testFolder);
this.browser = browser;
this.environment = environment;
this.secretsPassword = Objects.requireNonNull(secretsPassword);
this.salesforceMetadataCacheSetting = salesforceMetadataCacheSetting;
this.resultsPathSetting = resultsPathSetting;
this.projectName = projectName;
this.licensePath = Objects.requireNonNull(licensePath);
}

/**
Expand Down Expand Up @@ -150,6 +154,8 @@ public Secret getSecretsPassword() {
public ResultsPathSettings getResultsPathSetting() { return resultsPathSetting; }
@NonNull
public String getProjectName() { return projectName; }
@NonNull
public String getLicensePath() { return licensePath; }

@Override
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
Expand All @@ -170,19 +176,22 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListene
listener.getLogger().println("Running the build file: " + buildFile);
listener.getLogger().println("Executing test plan: " + testPlan);
listener.getLogger().println("Executing test folder: " + testFolder);

listener.getLogger().println("Target environment: " + environment);
listener.getLogger().println("Target browser: " + browser);
if (secretsPassword.getPlainText() != null) {
listener.getLogger().println("Project is encrypted! Thank you for being secure.");
}
listener.getLogger().println("Salesforce Metadata Cache Setting: " + salesforceMetadataCacheSetting);
listener.getLogger().println("Results Path Setting: " + resultsPathSetting);
String licensePath = env.expand(this.licensePath);
if (licensePath.isEmpty()) {

Check warning on line 187 in src/main/java/io/jenkins/plugins/ProvarAutomation.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 187 is only partially covered, one branch is missing
licensePath = DescriptorImpl.defaultLicensePath;

Check warning on line 188 in src/main/java/io/jenkins/plugins/ProvarAutomation.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 188 is not covered by tests
}
listener.getLogger().println("Execution license path being used: " + licensePath);

listener.getLogger().println("Workspace: " + workspaceFilePath);
ArgumentListBuilder args = new ArgumentListBuilder();


// Allow empty build parameters to be used in property replacements.
// The env.override/overrideAll methods remove the property if it's an empty string.
for (Map.Entry<String, String> e : build.getBuildVariables().entrySet()) {
Expand Down Expand Up @@ -212,14 +221,14 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListene

// Some default/empty value handling for test plans/folders
// ProvarProject/tests/ will run all tests
if (testPlan != null) {
if (!testPlan.isEmpty()) {

Check warning on line 224 in src/main/java/io/jenkins/plugins/ProvarAutomation.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 224 is only partially covered, one branch is missing
env.put("TEST_PLAN", testPlan);
} else {
env.put("TEST_PLAN", " ");
}
if (testFolder.equalsIgnoreCase("All")) {
env.put("TEST_FOLDER", "/");
} else if (testFolder != null) {
} else if (!testFolder.isEmpty()) {

Check warning on line 231 in src/main/java/io/jenkins/plugins/ProvarAutomation.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 231 is not covered by tests
env.put("TEST_FOLDER", testFolder);
} else {
env.put("TEST_FOLDER", " ");
Expand All @@ -232,6 +241,7 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListene
env.put("CACHE_SETTING", salesforceMetadataCacheSetting.name());
env.put("RESULTS_PATH_SETTING", resultsPathSetting.name());
env.put("PROJECT_NAME", projectName);
env.put("LICENSE_PATH", licensePath);

VariableResolver<String> vr = new VariableResolver.ByMap<>(env);
FilePath buildFilePath = buildFilePath(build.getModuleRoot(), buildFile, env.expand(projectName));
Expand Down Expand Up @@ -433,6 +443,18 @@ public FormValidation doCheckProjectName(@QueryParameter String value)

return FormValidation.ok();
}
@POST
public FormValidation doCheckLicensePath(@QueryParameter String value)
throws IOException, ServletException {
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {

Check warning on line 449 in src/main/java/io/jenkins/plugins/ProvarAutomation.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 449 is only partially covered, one branch is missing
return FormValidation.ok();

Check warning on line 450 in src/main/java/io/jenkins/plugins/ProvarAutomation.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 450 is not covered by tests
}
if (value.length() == 0) {

Check warning on line 452 in src/main/java/io/jenkins/plugins/ProvarAutomation.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 452 is only partially covered, one branch is missing
return FormValidation.warning(Messages.ProvarAutomation_DescriptorImpl_warnings_missingLicensePath());

Check warning on line 453 in src/main/java/io/jenkins/plugins/ProvarAutomation.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 453 is not covered by tests
}

return FormValidation.ok();
}

@Override
public boolean isApplicable(Class<? extends AbstractProject> aClass) {
Expand All @@ -450,14 +472,17 @@ public boolean configure(StaplerRequest req, JSONObject json) throws FormExcepti
return true;
}


public static final String defaultProvarAutomationName = "";
public static final String defaultProjectName = "ProvarProject";
public static final String defaultBuildFile = "build.xml";
public static final Browser defaultBrowser = Browser.Chrome_Headless;
public static final String defaultEnvironment = "";
public static final String defaultTestPlan = "Regression";
public static final String defaultTestFolder = "All";
static String windowsLicensePath = "C:\\Users\\" + System.getProperty("user.name") + "\\Provar\\.licenses";
static String unixLicensePath = System.getenv("HOME") + "/Provar/.licenses";
static String osName = System.getProperty("os.name");
public static final String defaultLicensePath = osName.contains("Windows") ? windowsLicensePath : unixLicensePath;

Check warning on line 485 in src/main/java/io/jenkins/plugins/ProvarAutomation.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 485 is only partially covered, one branch is missing
public static final SalesforceMetadataCacheSettings defaultSalesforceMetadataCacheSetting = SalesforceMetadataCacheSettings.Reuse;
public static final ResultsPathSettings defaultResultsPathSetting = ResultsPathSettings.Increment;

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/io/jenkins/plugins/Messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ProvarAutomation.DescriptorImpl.warnings.missingTestFolder=Test Folder is missin
ProvarAutomation.DescriptorImpl.warnings.missingTestPlan=Test Plan name is missing
ProvarAutomation.DescriptorImpl.warnings.noSecretsPassword=Your project is missing a secrets password
ProvarAutomation.DescriptorImpl.warnings.projectFolderMissing=Project folder name is missing, make sure the root of your repo contains a Provar Project
ProvarAutomation.DescriptorImpl.warnings.missingLicensePath=License path is missing
ProvarAutomation.DescriptorImpl.DisplayName=Run Provar Automation Tests
ProvarAutomation.ToolInstallation.DescriptorImpl.DisplayName=Provar Automation CLI
ProvarAutomation.AntExecutionFailed=command execution failed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,15 @@ THE SOFTWARE.
description="${%TestFolderDescr}">
<f:textbox default="${descriptor.defaultTestFolder}"/>
</f:entry>
<f:entry title="${%LicensePath}" field="licensePath"
description="${%LicensePathDescr}">
<f:textbox default="${descriptor.defaultLicensePath}"/>
</f:entry>
<f:entry title="${%SecretsPassword}" field="secretsPassword"
description="${%SecretsPasswordDescr}">
<f:password />
</f:entry>

</f:section>

<f:section title="Environment Settings">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ SecretsPasswordDescr=The secrets password used to encrypt the project
SalesforceMetadataCacheSetting=Salesforce Metadata Cache Setting
SalesforceMetadataCacheSettingDescr=The Salesforce metadata cache refresh setting
ResultsPathSetting=Test Results Path Setting
ResultsPathSettingDescr=How to handle the results directory before the next run
ResultsPathSettingDescr=How to handle the results directory before the next run
LicensePath=Execution License Path
LicensePathDescr=The path of the '.licenses' directory on the machine being used to run Provar tests
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div>
The name of the build file. Must end with '.xml'.
The name of the build file. Can end with '.xml' or just be the base file name.
This task assumes it is contained in the <code>ANT</code> folder of your <code>Project Name</code> directory.
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
The path of your license directory on the machine being used to run the tests. <br>
Your license directory should contain a ".licenses" folder. <br>
If left empty, will default to $USER_HOME/Provar/.licenses.
</div>
24 changes: 21 additions & 3 deletions src/test/java/io/jenkins/plugins/ProvarAutomationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public class ProvarAutomationTest {
final String testPlan = "Regression";
final String testFolder = "all";
final String environment = "Dev";
static String windowsLicensePath = "C:/Users/" + System.getProperty("user.name") + "/Provar/.licenses";
static String unixLicensePath = System.getenv("HOME") + "/Provar/.licenses";
static String osName = System.getProperty("os.name");
final String licensePath = osName.contains("Windows") ? windowsLicensePath : unixLicensePath;
final ProvarAutomation.Browser browser = ProvarAutomation.Browser.Safari;
final Secret secretsPassword = Secret.fromString("ProvarSecretsPasssword");
final ProvarAutomation.SalesforceMetadataCacheSettings salesforceMetadataCacheSetting = ProvarAutomation.SalesforceMetadataCacheSettings.Reload;
Expand All @@ -61,7 +65,7 @@ public class ProvarAutomationTest {
@Test
public void testConfigRoundtrip() throws Exception {
FreeStyleProject p = jr.createFreeStyleProject();
p.getBuildersList().add(new ProvarAutomation(provarAutomationName, buildFile, testPlan, testFolder, environment, browser, secretsPassword, salesforceMetadataCacheSetting, resultsPathSetting, projectName));
p.getBuildersList().add(new ProvarAutomation(provarAutomationName, buildFile, testPlan, testFolder, environment, browser, secretsPassword, salesforceMetadataCacheSetting, resultsPathSetting, projectName, licensePath));

WebClient webClient = jr.createWebClient();
HtmlPage page = webClient.getPage(p,"configure");
Expand All @@ -81,6 +85,7 @@ public void testConfigRoundtrip() throws Exception {
assertEquals(salesforceMetadataCacheSetting,pa.getSalesforceMetadataCacheSetting());
assertEquals(resultsPathSetting,pa.getResultsPathSetting());
assertEquals(projectName,pa.getProjectName());
assertEquals(licensePath, pa.getLicensePath());
}
// TODO: Add tests for validations of file paths, specifically the build file.

Check warning on line 90 in src/test/java/io/jenkins/plugins/ProvarAutomationTest.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: Add tests for validations of file paths, specifically the build file.
// TODO: Add testing for downloading of Provar CLI, extraction, and env var set.

Check warning on line 91 in src/test/java/io/jenkins/plugins/ProvarAutomationTest.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: Add testing for downloading of Provar CLI, extraction, and env var set.
Expand All @@ -91,7 +96,7 @@ public void testConfigRoundtrip() throws Exception {
@Test
public void testBuild() throws Exception {
FreeStyleProject project = jr.createFreeStyleProject();
ProvarAutomation builder = new ProvarAutomation(provarAutomationName, buildFile, testPlan, testFolder, environment, browser, secretsPassword, salesforceMetadataCacheSetting, resultsPathSetting, projectName);
ProvarAutomation builder = new ProvarAutomation(provarAutomationName, buildFile, testPlan, testFolder, environment, browser, secretsPassword, salesforceMetadataCacheSetting, resultsPathSetting, projectName, licensePath);
project.getBuildersList().add(builder);
FreeStyleBuild build = jr.assertBuildStatus(Result.FAILURE, project.scheduleBuild2(quietPeriod).get());
jr.assertLogContains("Running the build file: " + buildFile, build);
Expand All @@ -103,8 +108,20 @@ public void testBuild() throws Exception {
jr.assertLogContains("Results Path Setting: " + resultsPathSetting, build);
jr.assertLogContains("Project Folder: " + projectName, build);
jr.assertLogContains("Project is encrypted! Thank you for being secure.", build);
jr.assertLogContains("Execution license path being used: " + licensePath, build);
}

// TODO: Add test for license path and license file

Check warning on line 114 in src/test/java/io/jenkins/plugins/ProvarAutomationTest.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: Add test for license path and license file
// @Test
// public void testLicense() throws Exception {
///* FreeStyleProject project = jr.createFreeStyleProject();
// ProvarAutomation builder = new ProvarAutomation(provarAutomationName, buildFile, testPlan, testFolder, environment, browser, secretsPassword, salesforceMetadataCacheSetting, resultsPathSetting, projectName, licensePath);
// project.getBuildersList().add(builder);
// FreeStyleBuild build = jr.assertBuildStatus(Result.FAILURE, project.scheduleBuild2(quietPeriod).get());
// Path path = Paths.get("does-not-exist.txt");
// assertFalse(Files.exists(path));*/
// }

@Test
public void testScriptedPipeline() throws Exception {
String agentLabel = "my-agent";
Expand All @@ -121,7 +138,8 @@ public void testScriptedPipeline() throws Exception {
+ " secretsPassword: '" + secretsPassword + "',\n"
+ " salesforceMetadataCacheSetting: '" + salesforceMetadataCacheSetting + "',\n"
+ " resultsPathSetting: '" + resultsPathSetting + "',\n"
+ " projectName: '" + projectName + "'\n"
+ " projectName: '" + projectName + "',\n"
+ " licensePath: '" + licensePath + "'\n"
+ "}";
job.setDefinition(new CpsFlowDefinition(pipelineScript, true));

Expand Down

0 comments on commit 91b13f4

Please sign in to comment.