use of org.jenkins.tools.test.model.PluginInfos in project plugin-compat-tester by jenkinsci.
the class WritePCTResultServlet method service.
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// Current servlet is secured !
SecuritySupport.ensureTokenIsValid(req);
// Parsing request...
String pluginName = req.getParameter("pluginName");
String pluginVersion = req.getParameter("pluginVersion");
String pluginUrl = req.getParameter("pluginUrl");
TestStatus status = TestStatus.valueOf(req.getParameter("status"));
String errorMessages = req.getParameter("errMsg");
List<String> warningMessages = null;
if (req.getParameterValues("warnMsgs") != null) {
warningMessages = Arrays.asList(req.getParameterValues("warnMsgs"));
}
String dateTimestampStr = req.getParameter("timestamp");
Date date = null;
if (dateTimestampStr == null) {
// If date is not set, use NOW
date = new Date();
} else {
date = new Date(Long.valueOf(dateTimestampStr));
}
String buildLogPath = req.getParameter("buildLogPath");
PluginInfos pluginInfos = new PluginInfos(pluginName, pluginVersion, pluginUrl);
MavenCoordinates mavenCoords = MavenCoordinates.fromGAV(req.getParameter("mavenGAV"));
PluginCompatResult result = new PluginCompatResult(mavenCoords, status, errorMessages, warningMessages, buildLogPath, date);
// Now, persisting result data into datastore !
Key resultKey = PluginCompatResultDAO.INSTANCE.persist(pluginInfos, result);
String logContent = req.getParameter("logContent");
if (logContent != null && buildLogPath != null) {
LogsDAO.INSTANCE.persistBuildLog(buildLogPath, logContent, resultKey);
}
resp.getWriter().print(String.format("id=%d", resultKey.getId()));
}
use of org.jenkins.tools.test.model.PluginInfos in project plugin-compat-tester by jenkinsci.
the class JsonUtil method toJson.
public static void toJson(Writer w, Set<PluginInfos> pluginInfos) throws IOException {
w.write("[");
for (Iterator<PluginInfos> piIter = pluginInfos.iterator(); piIter.hasNext(); ) {
PluginInfos pi = piIter.next();
w.write(String.format("{\"name\":\"%s\",\"version\":\"%s\",\"url\":\"%s\"}", pi.pluginName, pi.pluginVersion, pi.pluginUrl));
if (piIter.hasNext()) {
w.write(",");
}
}
w.write("]");
}
use of org.jenkins.tools.test.model.PluginInfos in project plugin-compat-tester by jenkinsci.
the class DataImporter method importExistingReport.
public void importExistingReport(File reportFile, Long startingOffset) throws IOException {
PluginCompatReport report = PluginCompatReport.fromXml(reportFile);
int plannedRequestsCount = 0;
for (Map.Entry<PluginInfos, List<PluginCompatResult>> test : report.getPluginCompatTests().entrySet()) {
plannedRequestsCount += test.getValue().size();
}
long i = 0;
boolean startingBuildLogConstraintVerified = startingBuildLog == null;
for (Map.Entry<PluginInfos, List<PluginCompatResult>> test : report.getPluginCompatTests().entrySet()) {
for (PluginCompatResult pluginCompatResult : test.getValue()) {
if (i >= startingOffset.longValue()) {
if (startingBuildLog != null && startingBuildLog.equals(pluginCompatResult.getBuildLogPath())) {
startingBuildLogConstraintVerified = true;
}
if (startingBuildLogConstraintVerified) {
importPluginCompatResult(pluginCompatResult, test.getKey(), reportFile.getParentFile());
System.out.println(String.format("Executed request %d / %d", i, plannedRequestsCount));
}
}
i++;
}
}
}
use of org.jenkins.tools.test.model.PluginInfos in project plugin-compat-tester by jenkinsci.
the class PluginCompatTester method testPlugins.
public PluginCompatReport testPlugins() throws PlexusContainerException, IOException, MavenEmbedderException {
File war = config.getWar();
if (war != null) {
populateSplits(war);
} else {
// TODO find a way to load the local version of jenkins.war acc. to UC metadata
splits = HISTORICAL_SPLITS;
splitCycles = HISTORICAL_SPLIT_CYCLES;
}
PluginCompatTesterHooks pcth = new PluginCompatTesterHooks(config.getHookPrefixes());
// Providing XSL Stylesheet along xml report file
if (config.reportFile != null) {
if (config.isProvideXslReport()) {
File xslFilePath = PluginCompatReport.getXslFilepath(config.reportFile);
FileUtils.copyStreamToFile(new RawInputStreamFacade(getXslTransformerResource().getInputStream()), xslFilePath);
}
}
DataImporter dataImporter = null;
if (config.getGaeBaseUrl() != null && config.getGaeSecurityToken() != null) {
dataImporter = new DataImporter(config.getGaeBaseUrl(), config.getGaeSecurityToken());
}
// Determine the plugin data
// Used to track real plugin groupIds from WARs
HashMap<String, String> pluginGroupIds = new HashMap<String, String>();
UpdateSite.Data data = config.getWar() == null ? extractUpdateCenterData(pluginGroupIds) : scanWAR(config.getWar(), pluginGroupIds);
final Map<String, Plugin> pluginsToCheck;
final List<String> pluginsToInclude = config.getIncludePlugins();
if (data.plugins.isEmpty() && pluginsToInclude != null && !pluginsToInclude.isEmpty()) {
// Update Center returns empty info OR the "-war" option is specified for WAR without bundled plugins
// TODO: Ideally we should do this tweak in any case, so that we can test custom plugins with Jenkins cores before unbundling
// But it will require us to always poll the update center...
System.out.println("WAR file does not contain plugin info, will try to extract it from UC for included plugins");
pluginsToCheck = new HashMap<>(pluginsToInclude.size());
UpdateSite.Data ucData = extractUpdateCenterData(pluginGroupIds);
for (String plugin : pluginsToInclude) {
UpdateSite.Plugin pluginData = ucData.plugins.get(plugin);
if (pluginData != null) {
System.out.println("Adding " + plugin + " to the test scope");
pluginsToCheck.put(plugin, pluginData);
}
}
} else {
pluginsToCheck = data.plugins;
}
if (pluginsToCheck.isEmpty()) {
throw new IOException("List of plugins to check is empty, it is not possible to run PCT");
}
PluginCompatReport report = PluginCompatReport.fromXml(config.reportFile);
SortedSet<MavenCoordinates> testedCores = config.getWar() == null ? generateCoreCoordinatesToTest(data, report) : coreVersionFromWAR(data);
MavenRunner.Config mconfig = new MavenRunner.Config();
mconfig.userSettingsFile = config.getM2SettingsFile();
// TODO REMOVE
mconfig.userProperties.put("failIfNoTests", "false");
mconfig.userProperties.put("argLine", "-XX:MaxPermSize=128m");
String mavenPropertiesFilePath = this.config.getMavenPropertiesFile();
if (StringUtils.isNotBlank(mavenPropertiesFilePath)) {
File file = new File(mavenPropertiesFilePath);
if (file.exists()) {
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(file);
Properties properties = new Properties();
properties.load(fileInputStream);
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
mconfig.userProperties.put((String) entry.getKey(), (String) entry.getValue());
}
} finally {
IOUtils.closeQuietly(fileInputStream);
}
} else {
System.out.println("File " + mavenPropertiesFilePath + " not exists");
}
}
SCMManagerFactory.getInstance().start();
for (MavenCoordinates coreCoordinates : testedCores) {
System.out.println("Starting plugin tests on core coordinates : " + coreCoordinates.toString());
for (Plugin plugin : pluginsToCheck.values()) {
if (config.getIncludePlugins() == null || config.getIncludePlugins().contains(plugin.name.toLowerCase())) {
PluginInfos pluginInfos = new PluginInfos(plugin.name, plugin.version, plugin.url);
if (config.getExcludePlugins() != null && config.getExcludePlugins().contains(plugin.name.toLowerCase())) {
System.out.println("Plugin " + plugin.name + " is in excluded plugins => test skipped !");
continue;
}
String errorMessage = null;
TestStatus status = null;
MavenCoordinates actualCoreCoordinates = coreCoordinates;
PluginRemoting remote;
if (localCheckoutProvided() && onlyOnePluginIncluded()) {
// Only one plugin and checkout directory provided
remote = new PluginRemoting(new File(config.getLocalCheckoutDir(), "pom.xml"));
} else if (localCheckoutProvided()) {
// local directory provided for more than one plugin, so each plugin is allocated in localCheckoutDir/plugin-name
// If there is no subdirectory for the plugin, it will be cloned from scm
File pomFile = new File(new File(config.getLocalCheckoutDir(), plugin.name), "pom.xml");
if (pomFile.exists()) {
remote = new PluginRemoting(pomFile);
} else {
remote = new PluginRemoting(plugin.url);
}
} else {
// Only one plugin but checkout directory not provided or
// more than a plugin and no local checkout directory provided
remote = new PluginRemoting(plugin.url);
}
PomData pomData;
try {
pomData = remote.retrievePomData();
System.out.println("detected parent POM " + pomData.parent.toGAV());
if ((pomData.parent.groupId.equals(PluginCompatTesterConfig.DEFAULT_PARENT_GROUP) && pomData.parent.artifactId.equals(PluginCompatTesterConfig.DEFAULT_PARENT_ARTIFACT) || pomData.parent.groupId.equals("org.jvnet.hudson.plugins")) && coreCoordinates.version.matches("1[.][0-9]+[.][0-9]+") && new VersionNumber(coreCoordinates.version).compareTo(new VersionNumber("1.485")) < 0) {
// TODO unless 1.480.3+
System.out.println("Cannot test against " + coreCoordinates.version + " due to lack of deployed POM for " + coreCoordinates.toGAV());
actualCoreCoordinates = new MavenCoordinates(coreCoordinates.groupId, coreCoordinates.artifactId, coreCoordinates.version.replaceFirst("[.][0-9]+$", ""));
}
} catch (Throwable t) {
status = TestStatus.INTERNAL_ERROR;
errorMessage = t.getMessage();
pomData = null;
}
if (!config.isSkipTestCache() && report.isCompatTestResultAlreadyInCache(pluginInfos, actualCoreCoordinates, config.getTestCacheTimeout(), config.getCacheThresholStatus())) {
System.out.println("Cache activated for plugin " + pluginInfos.pluginName + " => test skipped !");
// Don't do anything : we are in the cached interval ! :-)
continue;
}
List<String> warningMessages = new ArrayList<String>();
if (errorMessage == null) {
try {
TestExecutionResult result = testPluginAgainst(actualCoreCoordinates, plugin, mconfig, pomData, pluginsToCheck, pluginGroupIds, pcth);
// If no PomExecutionException, everything went well...
status = TestStatus.SUCCESS;
warningMessages.addAll(result.pomWarningMessages);
} catch (PomExecutionException e) {
if (!e.succeededPluginArtifactIds.contains("maven-compiler-plugin")) {
status = TestStatus.COMPILATION_ERROR;
} else if (!e.succeededPluginArtifactIds.contains("maven-surefire-plugin")) {
status = TestStatus.TEST_FAILURES;
} else {
// Can this really happen ???
status = TestStatus.SUCCESS;
}
errorMessage = e.getErrorMessage();
warningMessages.addAll(e.getPomWarningMessages());
} catch (Error e) {
// Rethrow the error ... something is wrong !
throw e;
} catch (Throwable t) {
status = TestStatus.INTERNAL_ERROR;
errorMessage = t.getMessage();
}
}
File buildLogFile = createBuildLogFile(config.reportFile, plugin.name, plugin.version, actualCoreCoordinates);
String buildLogFilePath = "";
if (buildLogFile.exists()) {
buildLogFilePath = createBuildLogFilePathFor(pluginInfos.pluginName, pluginInfos.pluginVersion, actualCoreCoordinates);
}
PluginCompatResult result = new PluginCompatResult(actualCoreCoordinates, status, errorMessage, warningMessages, buildLogFilePath);
report.add(pluginInfos, result);
// Adding result to GAE
if (dataImporter != null) {
dataImporter.importPluginCompatResult(result, pluginInfos, config.reportFile.getParentFile());
// TODO: import log files
}
if (config.reportFile != null) {
if (!config.reportFile.exists()) {
FileUtils.fileWrite(config.reportFile.getAbsolutePath(), "");
}
report.save(config.reportFile);
}
} else {
System.out.println("Plugin " + plugin.name + " not in included plugins => test skipped !");
}
}
}
// Generating HTML report if needed
if (config.reportFile != null) {
if (config.isGenerateHtmlReport()) {
generateHtmlReportFile();
}
}
return report;
}
use of org.jenkins.tools.test.model.PluginInfos in project plugin-compat-tester by jenkinsci.
the class JsonUtil method toJson.
public static void toJson(Writer w, Map<PluginInfos, List<PluginCompatResult>> pluginCompatTests) throws IOException {
w.write("[");
for (Iterator<PluginInfos> piIter = pluginCompatTests.keySet().iterator(); piIter.hasNext(); ) {
PluginInfos pi = piIter.next();
w.write(String.format("{\"plugin\":\"%s:%s\",\"results\":", pi.pluginName, pi.pluginVersion));
toJson(w, pluginCompatTests.get(pi));
w.write("}");
if (piIter.hasNext()) {
w.write(",");
}
}
w.write("]");
}
Aggregations