Search in sources :

Example 1 with PluginInfos

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()));
}
Also used : TestStatus(org.jenkins.tools.test.model.TestStatus) MavenCoordinates(org.jenkins.tools.test.model.MavenCoordinates) PluginInfos(org.jenkins.tools.test.model.PluginInfos) Date(java.util.Date) PluginCompatResult(org.jenkins.tools.test.model.PluginCompatResult) Key(com.google.appengine.api.datastore.Key)

Example 2 with PluginInfos

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("]");
}
Also used : PluginInfos(org.jenkins.tools.test.model.PluginInfos)

Example 3 with PluginInfos

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++;
        }
    }
}
Also used : PluginCompatReport(org.jenkins.tools.test.model.PluginCompatReport) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) PluginInfos(org.jenkins.tools.test.model.PluginInfos) PluginCompatResult(org.jenkins.tools.test.model.PluginCompatResult)

Example 4 with PluginInfos

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;
}
Also used : TestStatus(org.jenkins.tools.test.model.TestStatus) PomData(org.jenkins.tools.test.model.PomData) HashMap(java.util.HashMap) MavenRunner(org.jenkins.tools.test.maven.MavenRunner) InternalMavenRunner(org.jenkins.tools.test.maven.InternalMavenRunner) ExternalMavenRunner(org.jenkins.tools.test.maven.ExternalMavenRunner) PluginCompatTesterConfig(org.jenkins.tools.test.model.PluginCompatTesterConfig) ArrayList(java.util.ArrayList) PomExecutionException(org.jenkins.tools.test.exception.PomExecutionException) Properties(java.util.Properties) MavenCoordinates(org.jenkins.tools.test.model.MavenCoordinates) PluginCompatTesterHooks(org.jenkins.tools.test.model.hook.PluginCompatTesterHooks) PluginInfos(org.jenkins.tools.test.model.PluginInfos) PluginCompatResult(org.jenkins.tools.test.model.PluginCompatResult) PluginCompatReport(org.jenkins.tools.test.model.PluginCompatReport) Plugin(hudson.model.UpdateSite.Plugin) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) VersionNumber(hudson.util.VersionNumber) PluginRemoting(org.jenkins.tools.test.model.PluginRemoting) RawInputStreamFacade(org.codehaus.plexus.util.io.RawInputStreamFacade) JSONObject(net.sf.json.JSONObject) JarFile(java.util.jar.JarFile) File(java.io.File) UpdateSite(hudson.model.UpdateSite) Map(java.util.Map) HashMap(java.util.HashMap) TestExecutionResult(org.jenkins.tools.test.model.TestExecutionResult) Plugin(hudson.model.UpdateSite.Plugin)

Example 5 with PluginInfos

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("]");
}
Also used : PluginInfos(org.jenkins.tools.test.model.PluginInfos)

Aggregations

PluginInfos (org.jenkins.tools.test.model.PluginInfos)5 PluginCompatResult (org.jenkins.tools.test.model.PluginCompatResult)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 MavenCoordinates (org.jenkins.tools.test.model.MavenCoordinates)2 PluginCompatReport (org.jenkins.tools.test.model.PluginCompatReport)2 TestStatus (org.jenkins.tools.test.model.TestStatus)2 Key (com.google.appengine.api.datastore.Key)1 UpdateSite (hudson.model.UpdateSite)1 Plugin (hudson.model.UpdateSite.Plugin)1 VersionNumber (hudson.util.VersionNumber)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Properties (java.util.Properties)1 JarFile (java.util.jar.JarFile)1 JSONObject (net.sf.json.JSONObject)1