blob: e232e523cbf1baa38f696f5ae608451f2523d7ec (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
// 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 =
" <dependency>\n" +
" <groupId>" + TEST_ARTIFACT_GROUP_ID + "</groupId>\n" +
" <artifactId>%ARTIFACT_ID%</artifactId>\n" +
" <scope>system</scope>\n" +
" <type>test-jar</type>\n" +
" <version>test</version>\n" +
" <systemPath>${%ARTIFACT_ID%.path}</systemPath>\n" +
" </dependency>\n";
private static final String DEPENDENCY_TO_SCAN_TEMPLATE =
" <dependency>" + TEST_ARTIFACT_GROUP_ID + ":%ARTIFACT_ID%</dependency>\n";
private static final String POM_XML_TEMPLATE =
"<?xml version=\"1.0\"?>\n" +
"<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" +
" <modelVersion>4.0.0</modelVersion>\n" +
" <groupId>com.yahoo.vespa</groupId>\n" +
" <artifactId>tester-application</artifactId>\n" +
" <version>1.0.0</version>\n" +
"\n" +
" <properties>\n" +
" <junit_version>5.8.1</junit_version>\n" +
" <surefire_version>2.22.0</surefire_version>\n" +
"%PROPERTIES%" +
" </properties>\n" +
"\n" +
" <dependencies>\n" +
" <dependency>\n" +
" <groupId>org.junit.vintage</groupId>\n" +
" <artifactId>junit-vintage-engine</artifactId>\n" +
" <version>${junit_version}</version>\n" +
" <scope>test</scope>\n" +
" </dependency>\n" +
" <dependency>\n" +
" <groupId>org.junit.jupiter</groupId>\n" +
" <artifactId>junit-jupiter-engine</artifactId>\n" +
" <version>${junit_version}</version>\n" +
" <scope>test</scope>\n" +
" </dependency>\n" +
"%DEPENDENCIES%" +
" </dependencies>\n" +
"\n" +
" <build>\n" +
" <plugins>\n" +
" <plugin>\n" +
" <groupId>org.apache.maven.plugins</groupId>\n" +
" <artifactId>maven-surefire-plugin</artifactId>\n" +
" <version>${surefire_version}</version>\n" +
" <configuration>\n" +
" <dependenciesToScan>\n" +
"%DEPENDENCIES_TO_SCAN%" +
" </dependenciesToScan>\n" +
" <groups>%GROUPS%</groups>\n" +
" <reportsDirectory>${env.TEST_DIR}</reportsDirectory>\n" +
" <redirectTestOutputToFile>false</redirectTestOutputToFile>\n" +
" <trimStackTrace>false</trimStackTrace>\n" +
" <environmentVariables>\n" +
" <LD_LIBRARY_PATH>" + Defaults.getDefaults().underVespaHome("lib64") + "</LD_LIBRARY_PATH>\n" +
" </environmentVariables>\n" +
" </configuration>\n" +
" </plugin>\n" +
" <plugin>\n" +
" <groupId>org.apache.maven.plugins</groupId>\n" +
" <artifactId>maven-surefire-report-plugin</artifactId>\n" +
" <version>${surefire_version}</version>\n" +
" <configuration>\n" +
" <reportsDirectory>${env.TEST_DIR}</reportsDirectory>\n" +
" </configuration>\n" +
" </plugin>\n" +
" </plugins>\n" +
" </build>\n" +
"</project>\n";
static String generatePomXml(TestProfile testProfile, List<Path> 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() {}
}
|