@Test public void testBeforeRunnerStart() throws Exception { BuildRunnerContextImpl runner = EasyMock.createMock(BuildRunnerContextImpl.class); HashMap<String, String> runnerParameters = Maps.newHashMap(); runnerParameters.put(ConstantValues.BUILD_NAME, "buildName"); runnerParameters.put(ConstantValues.BUILD_NUMBER, "123123"); runnerParameters.put(ConstantValues.PROP_BUILD_TIMESTAMP, "asdsafasdf"); runnerParameters.put(ConstantValues.PROP_VCS_REVISION, "asdasdasd"); runnerParameters.put(RunnerParameterKeys.GRADLE_INTEGRATION, Boolean.TRUE.toString()); runnerParameters.put(RunnerParameterKeys.URL, "someUrl"); runnerParameters.put(RunnerParameterKeys.ENABLE_RELEASE_MANAGEMENT, Boolean.TRUE.toString()); runnerParameters.put("ui.gradleRunner.additional.gradle.cmd.params", "cmdParam"); runnerParameters.put("ui.gradleRunner.gradle.tasks.names", "someTask"); EasyMock.expect(runner.getRunnerParameters()).andReturn(runnerParameters).anyTimes(); EasyMock.expect(runner.getConfigParameters()).andReturn(Maps.<String, String>newHashMap()).anyTimes(); EasyMock.expect(runner.getParametersResolver()).andReturn(EasyMock.createMock(ValueResolver.class)).anyTimes(); runner.addRunnerParameter("ui.gradleRunner.gradle.tasks.names", "someTask artifactoryPublish"); EasyMock.expectLastCall(); runner.addRunnerParameter(EasyMock.eq("ui.gradleRunner.additional.gradle.cmd.params"), EasyMock.matches("cmdParam -I .+ -DbuildInfoConfig.propertiesFile=.+")); EasyMock.expectLastCall(); BuildParametersMap buildParametersMap = EasyMock.createMock(BuildParametersMap.class); EasyMock.expect(buildParametersMap.getAllParameters()).andReturn(Maps.<String, String>newHashMap()).anyTimes(); EasyMock.expect(runner.getBuildParameters()).andReturn(buildParametersMap).anyTimes(); EasyMock.expect(runner.getRunType()).andReturn(RunTypeUtils.GRADLE_RUNNER); AgentRunningBuild agentRunningBuild = EasyMock.createMock(AgentRunningBuild.class); EasyMock.expect(agentRunningBuild.getBuildLogger()) .andReturn(EasyMock.createMock(BuildProgressLogger.class)).anyTimes(); File tempDir = Files.createTempDir(); File buildTempDir = Files.createTempDir(); new File(tempDir, ConstantValues.GRADLE_PROPERTIES_FILE_NAME).createNewFile(); EasyMock.expect(runner.getWorkingDirectory()).andReturn(tempDir); EasyMock.expect(agentRunningBuild.getSharedConfigParameters()).andReturn(Maps.<String, String>newHashMap()); EasyMock.expect(agentRunningBuild.getBuildTempDirectory()).andReturn(buildTempDir).times(2); BuildAgentConfiguration buildAgentConfiguration = EasyMock.createMock(BuildAgentConfiguration.class); EasyMock.expect(buildAgentConfiguration.getAgentPluginsDirectory()).andReturn(Files.createTempDir()); EasyMock.expect(agentRunningBuild.getAgentConfiguration()).andReturn(buildAgentConfiguration); EasyMock.expect(runner.getBuild()).andReturn(agentRunningBuild).times(4); watcher.addNewArtifactsPath(EasyMock.isA(String.class)); EasyMock.expectLastCall(); EasyMock.replay(runner, buildParametersMap, agentRunningBuild, watcher, buildAgentConfiguration); listener.beforeRunnerStart(runner); EasyMock.verify(runner, buildParametersMap, agentRunningBuild, watcher, buildAgentConfiguration); }
@Override public void beforeRunnerStart(@NotNull BuildRunnerContext runner) { super.beforeRunnerStart(runner); Map<String, String> runnerParameters = runner.getRunnerParameters(); String runType = runner.getRunType(); if (RunTypeUtils.isGradleWithExtractorActivated(runType, runnerParameters)) { String selectedServerUrl = runnerParameters.get(URL); boolean validServerUrl = StringUtils.isNotBlank(selectedServerUrl); AgentRunningBuild build = runner.getBuild(); BuildProgressLogger logger = build.getBuildLogger(); if (!validServerUrl) { String skipLogMessage = runnerParameters.get(PROP_SKIP_LOG_MESSAGE); if (StringUtils.isNotBlank(skipLogMessage)) { logger.warning(skipLogMessage); } } else { if (Boolean.valueOf(runnerParameters.get(RunnerParameterKeys.ENABLE_RELEASE_MANAGEMENT))) { File workingDirectory = runner.getWorkingDirectory(); File gradleProperties = new File(workingDirectory, ConstantValues.GRADLE_PROPERTIES_FILE_NAME); if (!gradleProperties.exists()) { String errorMessage = "Unable to find the gradle release management properties file at '" + gradleProperties.getAbsolutePath() + "'."; logger.error(errorMessage); logger.buildFailureDescription(errorMessage); logger.exception(new FileNotFoundException(errorMessage)); return; } File gradlePropertiesPacked; try { gradlePropertiesPacked = ArchiveUtil.packFile(gradleProperties); } catch (IOException e) { String errorMessage = "Unable to publish the '" + ConstantValues.GRADLE_PROPERTIES_FILE_NAME + "' file to the server: " + e.getMessage(); logger.error(errorMessage); logger.buildFailureDescription(errorMessage); logger.exception(e); return; } watcher.addNewArtifactsPath(gradlePropertiesPacked.getAbsolutePath() + "=>.teamcity"); } addBuildInfoTaskAndInitScript(runner); } } }
GradleBuildInfoAgentListener extends ArtifactoryAgentLifeCycleAdapter { @Override public void beforeRunnerStart(@NotNull BuildRunnerContext runner) { super.beforeRunnerStart(runner); Map<String, String> runnerParameters = runner.getRunnerParameters(); String runType = runner.getRunType(); if (RunTypeUtils.isGradleWithExtractorActivated(runType, runnerParameters)) { String selectedServerUrl = runnerParameters.get(URL); boolean validServerUrl = StringUtils.isNotBlank(selectedServerUrl); AgentRunningBuild build = runner.getBuild(); BuildProgressLogger logger = build.getBuildLogger(); if (!validServerUrl) { String skipLogMessage = runnerParameters.get(PROP_SKIP_LOG_MESSAGE); if (StringUtils.isNotBlank(skipLogMessage)) { logger.warning(skipLogMessage); } } else { if (Boolean.valueOf(runnerParameters.get(RunnerParameterKeys.ENABLE_RELEASE_MANAGEMENT))) { File workingDirectory = runner.getWorkingDirectory(); File gradleProperties = new File(workingDirectory, ConstantValues.GRADLE_PROPERTIES_FILE_NAME); if (!gradleProperties.exists()) { String errorMessage = "Unable to find the gradle release management properties file at '" + gradleProperties.getAbsolutePath() + "'."; logger.error(errorMessage); logger.buildFailureDescription(errorMessage); logger.exception(new FileNotFoundException(errorMessage)); return; } File gradlePropertiesPacked; try { gradlePropertiesPacked = ArchiveUtil.packFile(gradleProperties); } catch (IOException e) { String errorMessage = "Unable to publish the '" + ConstantValues.GRADLE_PROPERTIES_FILE_NAME + "' file to the server: " + e.getMessage(); logger.error(errorMessage); logger.buildFailureDescription(errorMessage); logger.exception(e); return; } watcher.addNewArtifactsPath(gradlePropertiesPacked.getAbsolutePath() + "=>.teamcity"); } addBuildInfoTaskAndInitScript(runner); } } } }
GradleBuildInfoAgentListener extends ArtifactoryAgentLifeCycleAdapter { @Override public void beforeRunnerStart(@NotNull BuildRunnerContext runner) { super.beforeRunnerStart(runner); Map<String, String> runnerParameters = runner.getRunnerParameters(); String runType = runner.getRunType(); if (RunTypeUtils.isGradleWithExtractorActivated(runType, runnerParameters)) { String selectedServerUrl = runnerParameters.get(URL); boolean validServerUrl = StringUtils.isNotBlank(selectedServerUrl); AgentRunningBuild build = runner.getBuild(); BuildProgressLogger logger = build.getBuildLogger(); if (!validServerUrl) { String skipLogMessage = runnerParameters.get(PROP_SKIP_LOG_MESSAGE); if (StringUtils.isNotBlank(skipLogMessage)) { logger.warning(skipLogMessage); } } else { if (Boolean.valueOf(runnerParameters.get(RunnerParameterKeys.ENABLE_RELEASE_MANAGEMENT))) { File workingDirectory = runner.getWorkingDirectory(); File gradleProperties = new File(workingDirectory, ConstantValues.GRADLE_PROPERTIES_FILE_NAME); if (!gradleProperties.exists()) { String errorMessage = "Unable to find the gradle release management properties file at '" + gradleProperties.getAbsolutePath() + "'."; logger.error(errorMessage); logger.buildFailureDescription(errorMessage); logger.exception(new FileNotFoundException(errorMessage)); return; } File gradlePropertiesPacked; try { gradlePropertiesPacked = ArchiveUtil.packFile(gradleProperties); } catch (IOException e) { String errorMessage = "Unable to publish the '" + ConstantValues.GRADLE_PROPERTIES_FILE_NAME + "' file to the server: " + e.getMessage(); logger.error(errorMessage); logger.buildFailureDescription(errorMessage); logger.exception(e); return; } watcher.addNewArtifactsPath(gradlePropertiesPacked.getAbsolutePath() + "=>.teamcity"); } addBuildInfoTaskAndInitScript(runner); } } } GradleBuildInfoAgentListener(@NotNull EventDispatcher<AgentLifeCycleListener> dispatcher,
                                        @NotNull ArtifactsWatcher watcher); }
GradleBuildInfoAgentListener extends ArtifactoryAgentLifeCycleAdapter { @Override public void beforeRunnerStart(@NotNull BuildRunnerContext runner) { super.beforeRunnerStart(runner); Map<String, String> runnerParameters = runner.getRunnerParameters(); String runType = runner.getRunType(); if (RunTypeUtils.isGradleWithExtractorActivated(runType, runnerParameters)) { String selectedServerUrl = runnerParameters.get(URL); boolean validServerUrl = StringUtils.isNotBlank(selectedServerUrl); AgentRunningBuild build = runner.getBuild(); BuildProgressLogger logger = build.getBuildLogger(); if (!validServerUrl) { String skipLogMessage = runnerParameters.get(PROP_SKIP_LOG_MESSAGE); if (StringUtils.isNotBlank(skipLogMessage)) { logger.warning(skipLogMessage); } } else { if (Boolean.valueOf(runnerParameters.get(RunnerParameterKeys.ENABLE_RELEASE_MANAGEMENT))) { File workingDirectory = runner.getWorkingDirectory(); File gradleProperties = new File(workingDirectory, ConstantValues.GRADLE_PROPERTIES_FILE_NAME); if (!gradleProperties.exists()) { String errorMessage = "Unable to find the gradle release management properties file at '" + gradleProperties.getAbsolutePath() + "'."; logger.error(errorMessage); logger.buildFailureDescription(errorMessage); logger.exception(new FileNotFoundException(errorMessage)); return; } File gradlePropertiesPacked; try { gradlePropertiesPacked = ArchiveUtil.packFile(gradleProperties); } catch (IOException e) { String errorMessage = "Unable to publish the '" + ConstantValues.GRADLE_PROPERTIES_FILE_NAME + "' file to the server: " + e.getMessage(); logger.error(errorMessage); logger.buildFailureDescription(errorMessage); logger.exception(e); return; } watcher.addNewArtifactsPath(gradlePropertiesPacked.getAbsolutePath() + "=>.teamcity"); } addBuildInfoTaskAndInitScript(runner); } } } GradleBuildInfoAgentListener(@NotNull EventDispatcher<AgentLifeCycleListener> dispatcher,
                                        @NotNull ArtifactsWatcher watcher); @Override void beforeRunnerStart(@NotNull BuildRunnerContext runner); }
GradleBuildInfoAgentListener extends ArtifactoryAgentLifeCycleAdapter { @Override public void beforeRunnerStart(@NotNull BuildRunnerContext runner) { super.beforeRunnerStart(runner); Map<String, String> runnerParameters = runner.getRunnerParameters(); String runType = runner.getRunType(); if (RunTypeUtils.isGradleWithExtractorActivated(runType, runnerParameters)) { String selectedServerUrl = runnerParameters.get(URL); boolean validServerUrl = StringUtils.isNotBlank(selectedServerUrl); AgentRunningBuild build = runner.getBuild(); BuildProgressLogger logger = build.getBuildLogger(); if (!validServerUrl) { String skipLogMessage = runnerParameters.get(PROP_SKIP_LOG_MESSAGE); if (StringUtils.isNotBlank(skipLogMessage)) { logger.warning(skipLogMessage); } } else { if (Boolean.valueOf(runnerParameters.get(RunnerParameterKeys.ENABLE_RELEASE_MANAGEMENT))) { File workingDirectory = runner.getWorkingDirectory(); File gradleProperties = new File(workingDirectory, ConstantValues.GRADLE_PROPERTIES_FILE_NAME); if (!gradleProperties.exists()) { String errorMessage = "Unable to find the gradle release management properties file at '" + gradleProperties.getAbsolutePath() + "'."; logger.error(errorMessage); logger.buildFailureDescription(errorMessage); logger.exception(new FileNotFoundException(errorMessage)); return; } File gradlePropertiesPacked; try { gradlePropertiesPacked = ArchiveUtil.packFile(gradleProperties); } catch (IOException e) { String errorMessage = "Unable to publish the '" + ConstantValues.GRADLE_PROPERTIES_FILE_NAME + "' file to the server: " + e.getMessage(); logger.error(errorMessage); logger.buildFailureDescription(errorMessage); logger.exception(e); return; } watcher.addNewArtifactsPath(gradlePropertiesPacked.getAbsolutePath() + "=>.teamcity"); } addBuildInfoTaskAndInitScript(runner); } } } GradleBuildInfoAgentListener(@NotNull EventDispatcher<AgentLifeCycleListener> dispatcher,
                                        @NotNull ArtifactsWatcher watcher); @Override void beforeRunnerStart(@NotNull BuildRunnerContext runner);  }