@Test public void build() throws Exception { Maven.MavenInstallation tool = ToolInstallations.configureMaven3(); String name = tool.getName(); Maven.MavenInstallation.DescriptorImpl desc = Jenkins.getInstance().getDescriptorByType(Maven.MavenInstallation.DescriptorImpl.class); // Defensive - Maven doesn't have a symbol before 2.x, and other tools may still not have symbols after that. String type = desc.getId(); Set<String> symbols = SymbolLookup.getSymbolValue(desc); if (!symbols.isEmpty()) { type = symbols.iterator().next(); } WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition("node {def home = tool name: '" + name + "', type: '" + type + "'; def settings = readFile($/$home/conf/settings.xml/$).split(); echo settings[-1]}", true)); WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0)); r.assertLogContains("</settings>", b); List<FlowNode> coreStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), new NodeStepTypePredicate("tool")); assertThat(coreStepNodes, Matchers.hasSize(1)); assertEquals(name, ArgumentsAction.getStepArgumentsAsString(coreStepNodes.get(0))); }
@Test public void testTagTranslations() throws Exception { YamlToJson underTest = new YamlToJson.Default( ImmutableList.<YamlTransform>of( new HelperTransform("!freestyle", FreeStyleProject.class), new HelperTransform("!maven", Maven.class), new HelperTransform("!git", GitSCM.class) { @Override public String construct(String value) { assertEquals("scm", value); return clazz.getName(); } }, new HelperTransform("!shell", Shell.class), new HelperTransform("!trigger", BuildTrigger.class), new HelperTransform("!mailer", Mailer.class))); for (String test : TAG_TESTS) { testOneTranslation(underTest, test); } }
@Test public void testTagTranslations() throws Exception { JsonToYaml underTest = new JsonToYaml.Default( ImmutableList.<YamlTransform>of( new HelperTransform("!freestyle", FreeStyleProject.class), new HelperTransform("!maven", Maven.class), new HelperTransform("!git", GitSCM.class) { @Override public String represent(Class clazz) { assertEquals(this.clazz, clazz); return "scm"; } @Override public String construct(String value) { assertEquals("scm", value); return this.clazz.getName(); } }, new HelperTransform("!shell", Shell.class), new HelperTransform("!trigger", BuildTrigger.class), new HelperTransform("!mailer", Mailer.class))); for (String test : TAG_TESTS) { testOneTranslation(underTest, test); } }
@Test public void getDetails_Maven() { Maven maven = new Maven("targets", ""); assertEquals(maven.getTargets(), BuildStepDetailsProvider.resolveDetails(maven)); // Check that Maven doesn't use "Invoke top-level Maven targets", // but instead uses our custom message. assertThat(maven.getDescriptor().getDisplayName()) .isNotEqualTo(BuildStepDetailsProvider.resolveName(maven)); assertEquals(Messages.BuildStepDetailsProvider_MavenName(), BuildStepDetailsProvider.resolveName(maven)); assertEquals(ImmutableList.<String>of("mvn", "targets"), BuildStepDetailsProvider.resolveFullCmd(maven)); }
@Test @WithoutJenkins public void getDetails_noJenkins() { assertThat(BuildStepDetailsProvider.all()).isEmpty(); assertNull(BuildStepDetailsProvider.resolveDetails(mock(Maven.class))); assertNull(BuildStepDetailsProvider.resolveName(mock(BuildStep.class))); }
@Before public void setup() throws Exception { // Maven.MavenInstallation maven3 = ToolInstallations.configureMaven35(); Maven.MavenInstallation maven3 = ExtendedToolInstallations.configureMaven35(); mavenInstallationName = maven3.getName(); GlobalMavenConfig globalMavenConfig = jenkinsRule.get(GlobalMavenConfig.class); globalMavenConfig.setGlobalSettingsProvider(new DefaultGlobalSettingsProvider()); globalMavenConfig.setSettingsProvider(new DefaultSettingsProvider()); }
/** * Declare "Maven 3.5.0" as the "default" Maven installation in Jenkins and as the Maven installation named "apache-maven-3.5.0". * Note that both {@link hudson.tasks.Maven.MavenInstallation} share the same Maven binaries. * * @return the "apache-maven-3.5.0" Maven {@link hudson.tasks.Maven.MavenInstallation} * @throws Exception */ public static Maven.MavenInstallation configureMaven35() throws Exception { Maven.MavenInstallation mvn = ToolInstallations.configureDefaultMaven("apache-maven-3.5.0", Maven.MavenInstallation.MAVEN_30); Maven.MavenInstallation maven350 = new Maven.MavenInstallation("apache-maven-3.5.0", mvn.getHome(), JenkinsRule.NO_PROPERTIES); Jenkins.getInstance().getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(maven350); return maven350; }
@Test public void testBindJob_FullJob() throws Exception { JSONObject json = (JSONObject) JSONSerializer.toJSON(EMPTY_JSON); // TODO(mattmoor): The logic in hudson.scm.SCMS uses the index of the SCM // among the collection of compatible SCMS for the given project to // determine which class to bind instead of relying on the '$class' field. // I have prototyped a fix for this, but until it can be pushed back, // we cannot test this. // JSONObject scm = (JSONObject) JSONSerializer.toJSON(GITSCM_JSON); // json.put("scm", scm); JSONArray builders = (JSONArray) JSONSerializer.toJSON(BUILDERS2_JSON); json.put("builder", builders); JSONArray publishers = (JSONArray) JSONSerializer.toJSON(PUBLISHERS_JSON); json.put("publisher", publishers); Job job = underTest.bindJob(Jenkins.getInstance(), NAME, json); assertNotNull(job); assertThat(job, instanceOf(FreeStyleProject.class)); assertEquals(NAME, job.getName()); FreeStyleProject project = (FreeStyleProject) job; assertEquals(1, project.getBuilders().size()); assertThat(project.getBuilders().get(0), instanceOf(Maven.class)); // NOTE: getPublishers returns a Map, but the above returns a list assertEquals(1, project.getPublishers().values().size()); assertThat(project.getPublishers().values().toArray()[0], instanceOf(BuildTrigger.class)); }
/** * {@inheritDoc} */ @Override public String getDetails(Maven maven) { return maven.getTargets(); }
/** * {@inheritDoc} */ @Override public String getName(Maven maven) { return com.google.jenkins.plugins.deploy.Messages.BuildStepDetailsProvider_MavenName(); }
/** * {@inheritDoc} */ @Override public String getFullCmd(Maven maven) { return "mvn " + getDetails(maven); }
private Maven.DescriptorImpl getMavenDescriptor() { return Jenkins.getInstance().getDescriptorByType(Maven.DescriptorImpl.class); }
/** * @return maven installations on this instance */ private static MavenInstallation[] getMavenInstallations() { return Jenkins.getActiveInstance().getDescriptorByType(Maven.DescriptorImpl.class).getInstallations(); }