2018-01-16 10:33:13 +02:00
|
|
|
import org.junit.Rule
|
2017-12-06 13:03:06 +02:00
|
|
|
import org.junit.Test
|
2018-01-16 16:03:00 +02:00
|
|
|
import org.junit.rules.RuleChain
|
2018-08-31 10:22:43 +02:00
|
|
|
|
2018-06-06 14:42:47 +02:00
|
|
|
import util.BasePiperTest
|
2018-06-06 11:19:19 +02:00
|
|
|
import util.JenkinsDockerExecuteRule
|
2018-08-31 10:22:43 +02:00
|
|
|
import util.JenkinsReadYamlRule
|
2018-06-06 14:42:47 +02:00
|
|
|
import util.JenkinsShellCallRule
|
2018-06-06 11:19:19 +02:00
|
|
|
import util.JenkinsStepRule
|
2018-06-06 14:42:47 +02:00
|
|
|
import util.Rules
|
2018-01-16 18:06:25 +02:00
|
|
|
|
2018-07-26 16:03:05 +02:00
|
|
|
import static org.hamcrest.Matchers.allOf
|
|
|
|
import static org.hamcrest.Matchers.containsString
|
|
|
|
import static org.hamcrest.Matchers.containsString
|
|
|
|
import static org.hamcrest.Matchers.not
|
2017-12-06 13:03:06 +02:00
|
|
|
import static org.junit.Assert.assertEquals
|
2018-07-26 16:03:05 +02:00
|
|
|
import static org.junit.Assert.assertThat
|
2017-12-06 13:03:06 +02:00
|
|
|
import static org.junit.Assert.assertTrue
|
|
|
|
|
2018-05-30 12:39:01 +02:00
|
|
|
class MavenExecuteTest extends BasePiperTest {
|
2017-12-06 13:03:06 +02:00
|
|
|
|
|
|
|
Map dockerParameters
|
2018-01-16 16:03:00 +02:00
|
|
|
|
2019-01-22 10:19:28 +02:00
|
|
|
private JenkinsShellCallRule shellRule = new JenkinsShellCallRule(this)
|
2019-01-22 10:26:08 +02:00
|
|
|
private JenkinsDockerExecuteRule dockerExecuteRule = new JenkinsDockerExecuteRule(this)
|
2019-01-22 10:25:42 +02:00
|
|
|
private JenkinsStepRule stepRule = new JenkinsStepRule(this)
|
2017-12-06 13:03:06 +02:00
|
|
|
|
2018-01-16 10:33:13 +02:00
|
|
|
@Rule
|
2018-06-06 11:19:19 +02:00
|
|
|
public RuleChain ruleChain = Rules
|
|
|
|
.getCommonRules(this)
|
2018-08-31 10:22:43 +02:00
|
|
|
.around(new JenkinsReadYamlRule(this))
|
2019-01-22 10:26:08 +02:00
|
|
|
.around(dockerExecuteRule)
|
2019-01-22 10:19:28 +02:00
|
|
|
.around(shellRule)
|
2019-01-22 10:25:42 +02:00
|
|
|
.around(stepRule)
|
2017-12-06 13:03:06 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
void testExecuteBasicMavenCommand() throws Exception {
|
2018-01-16 18:06:25 +02:00
|
|
|
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.mavenExecute(script: nullScript, goals: 'clean install')
|
2019-01-22 10:26:08 +02:00
|
|
|
assertEquals('maven:3.5-jdk-7', dockerExecuteRule.dockerParams.dockerImage)
|
2018-01-16 16:03:00 +02:00
|
|
|
|
2019-01-22 10:19:28 +02:00
|
|
|
assert shellRule.shell[0] == 'mvn --batch-mode -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn clean install'
|
2018-06-06 14:42:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testExecuteBasicMavenCommandWithDownloadLogsEnabled() throws Exception {
|
|
|
|
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.mavenExecute(script: nullScript, goals: 'clean install', logSuccessfulMavenTransfers: true)
|
2019-01-22 10:26:08 +02:00
|
|
|
assertEquals('maven:3.5-jdk-7', dockerExecuteRule.dockerParams.dockerImage)
|
2018-06-06 14:42:47 +02:00
|
|
|
|
2019-01-22 10:19:28 +02:00
|
|
|
assert shellRule.shell[0] == 'mvn --batch-mode clean install'
|
2017-12-06 13:03:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testExecuteMavenCommandWithParameter() throws Exception {
|
2018-01-16 18:06:25 +02:00
|
|
|
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.mavenExecute(
|
2018-05-30 12:39:01 +02:00
|
|
|
script: nullScript,
|
2018-01-16 18:06:25 +02:00
|
|
|
dockerImage: 'maven:3.5-jdk-8-alpine',
|
|
|
|
goals: 'clean install',
|
|
|
|
globalSettingsFile: 'globalSettingsFile.xml',
|
|
|
|
projectSettingsFile: 'projectSettingsFile.xml',
|
|
|
|
pomPath: 'pom.xml',
|
|
|
|
flags: '-o',
|
|
|
|
m2Path: 'm2Path',
|
|
|
|
defines: '-Dmaven.tests.skip=true')
|
2019-01-22 10:26:08 +02:00
|
|
|
assertEquals('maven:3.5-jdk-8-alpine', dockerExecuteRule.dockerParams.dockerImage)
|
2018-06-06 14:42:47 +02:00
|
|
|
String mvnCommand = "mvn --global-settings 'globalSettingsFile.xml' -Dmaven.repo.local='m2Path' --settings 'projectSettingsFile.xml' --file 'pom.xml' -o --batch-mode -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn clean install -Dmaven.tests.skip=true"
|
2019-01-22 10:19:28 +02:00
|
|
|
assertTrue(shellRule.shell.contains(mvnCommand))
|
2017-12-06 13:03:06 +02:00
|
|
|
}
|
2018-03-29 14:13:11 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
void testMavenCommandForwardsDockerOptions() throws Exception {
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.mavenExecute(script: nullScript, goals: 'clean install')
|
2019-01-22 10:26:08 +02:00
|
|
|
assertEquals('maven:3.5-jdk-7', dockerExecuteRule.dockerParams.dockerImage)
|
2018-03-29 14:13:11 +02:00
|
|
|
|
2019-01-22 10:19:28 +02:00
|
|
|
assertEquals('mvn --batch-mode -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn clean install', shellRule.shell[0])
|
2018-07-26 16:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testMavenCommandWithShortBatchModeFlag() throws Exception {
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.mavenExecute(script: nullScript, goals: 'clean install', flags: '-B')
|
2019-01-22 10:26:08 +02:00
|
|
|
assertEquals('maven:3.5-jdk-7', dockerExecuteRule.dockerParams.dockerImage)
|
2018-07-26 16:03:05 +02:00
|
|
|
|
2019-01-22 10:19:28 +02:00
|
|
|
assertEquals('mvn -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn clean install', shellRule.shell[0])
|
2018-07-26 16:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testMavenCommandWithFalsePositiveMinusBFlag() throws Exception {
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.mavenExecute(script: nullScript, goals: 'clean install', flags: '-Blah')
|
2019-01-22 10:26:08 +02:00
|
|
|
assertEquals('maven:3.5-jdk-7', dockerExecuteRule.dockerParams.dockerImage)
|
2018-07-26 16:03:05 +02:00
|
|
|
|
2019-01-22 10:19:28 +02:00
|
|
|
assertThat(shellRule.shell[0],
|
2018-07-26 16:03:05 +02:00
|
|
|
allOf(containsString('-Blah'),
|
|
|
|
containsString('--batch-mode')))
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testMavenCommandWithBatchModeMultiline() throws Exception {
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.mavenExecute(script: nullScript, goals: 'clean install', flags: ('''-B\\
|
2018-07-26 16:03:05 +02:00
|
|
|
|--show-version''' as CharSequence).stripMargin())
|
2019-01-22 10:19:28 +02:00
|
|
|
assertThat(shellRule.shell[0], not(containsString('--batch-mode')))
|
2018-03-29 14:13:11 +02:00
|
|
|
}
|
2017-12-06 13:03:06 +02:00
|
|
|
}
|