// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.testrunner;
import com.yahoo.vespa.defaults.Defaults;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;
/**
* Generates a pom.xml file that sets up build profile to test against the provided
* jar artifacts.
*
* @author valerijf
*/
public class PomXmlGenerator {
private static final String PROPERTY_TEMPLATE =
" <%ARTIFACT_ID%.path>%JAR_PATH%%ARTIFACT_ID%.path>\n";
private static final String TEST_ARTIFACT_GROUP_ID = "com.yahoo.vespa.testrunner.test";
private static final String DEPENDENCY_TEMPLATE =
" \n" +
" " + TEST_ARTIFACT_GROUP_ID + "\n" +
" %ARTIFACT_ID%\n" +
" system\n" +
" test-jar\n" +
" test\n" +
" ${%ARTIFACT_ID%.path}\n" +
" \n";
private static final String DEPENDENCY_TO_SCAN_TEMPLATE =
" " + TEST_ARTIFACT_GROUP_ID + ":%ARTIFACT_ID%\n";
private static final String POM_XML_TEMPLATE =
"\n" +
"\n" +
" 4.0.0\n" +
" com.yahoo.vespa\n" +
" tester-application\n" +
" 1.0.0\n" +
"\n" +
" \n" +
" 5.8.1\n" +
" 2.22.0\n" +
"%PROPERTIES%" +
" \n" +
"\n" +
" \n" +
" \n" +
" org.junit.vintage\n" +
" junit-vintage-engine\n" +
" ${junit_version}\n" +
" test\n" +
" \n" +
" \n" +
" org.junit.jupiter\n" +
" junit-jupiter-engine\n" +
" ${junit_version}\n" +
" test\n" +
" \n" +
"%DEPENDENCIES%" +
" \n" +
"\n" +
" \n" +
" \n" +
" \n" +
" org.apache.maven.plugins\n" +
" maven-surefire-plugin\n" +
" ${surefire_version}\n" +
" \n" +
" \n" +
"%DEPENDENCIES_TO_SCAN%" +
" \n" +
" %GROUPS%\n" +
" ${env.TEST_DIR}\n" +
" false\n" +
" false\n" +
" \n" +
" " + Defaults.getDefaults().underVespaHome("lib64") + "\n" +
" \n" +
" \n" +
" \n" +
" \n" +
" org.apache.maven.plugins\n" +
" maven-surefire-report-plugin\n" +
" ${surefire_version}\n" +
" \n" +
" ${env.TEST_DIR}\n" +
" \n" +
" \n" +
" \n" +
" \n" +
"\n";
static String generatePomXml(TestProfile testProfile, List artifacts, Path testArtifact) {
String properties = artifacts.stream()
.map(path -> PROPERTY_TEMPLATE
.replace("%ARTIFACT_ID%", path.getFileName().toString())
.replace("%JAR_PATH%", path.toString()))
.collect(Collectors.joining());
String dependencies = artifacts.stream()
.map(path -> DEPENDENCY_TEMPLATE
.replace("%ARTIFACT_ID%", path.getFileName().toString()))
.collect(Collectors.joining());
String dependenciesToScan =
DEPENDENCY_TO_SCAN_TEMPLATE
.replace("%ARTIFACT_ID%", testArtifact.getFileName().toString());
return POM_XML_TEMPLATE
.replace("%PROPERTIES%", properties)
.replace("%DEPENDENCIES_TO_SCAN%", dependenciesToScan)
.replace("%DEPENDENCIES%", dependencies)
.replace("%GROUPS%", testProfile.group());
}
private PomXmlGenerator() {}
}