Search in sources :

Example 6 with MavenCoordinates

use of org.jenkins.tools.test.model.MavenCoordinates in project plugin-compat-tester by jenkinsci.

the class ScmConnectionSpecialCasesTest method runComputeScmConnectionAgainst.

private static void runComputeScmConnectionAgainst(String scmUrlToTest, String artifactId, String expectedComputedScmUrl) {
    PomData pom = new PomData(artifactId, scmUrlToTest, new MavenCoordinates("", "", ""));
    PluginRemoting.computeScmConnection(pom);
    assertThat(pom.getConnectionUrl(), is(equalTo(expectedComputedScmUrl)));
}
Also used : MavenCoordinates(org.jenkins.tools.test.model.MavenCoordinates) PomData(org.jenkins.tools.test.model.PomData)

Example 7 with MavenCoordinates

use of org.jenkins.tools.test.model.MavenCoordinates in project plugin-compat-tester by jenkinsci.

the class MultiParentCompileHook method action.

@Override
public Map<String, Object> action(Map<String, Object> moreInfo) throws Exception {
    try {
        System.out.println("Executing multi-parent compile hook");
        PluginCompatTesterConfig config = (PluginCompatTesterConfig) moreInfo.get("config");
        MavenCoordinates core = (MavenCoordinates) moreInfo.get("core");
        runner = config.getExternalMaven() == null ? new InternalMavenRunner() : new ExternalMavenRunner(config.getExternalMaven());
        mavenConfig = getMavenConfig(config);
        File pluginDir = (File) moreInfo.get("pluginDir");
        System.out.println("Plugin dir is " + pluginDir);
        if (config.getLocalCheckoutDir() != null) {
            Path pluginSourcesDir = config.getLocalCheckoutDir().toPath();
            boolean isMultipleLocalPlugins = config.getIncludePlugins() != null && config.getIncludePlugins().size() > 1;
            // If not it must be located on the parent of the localCheckoutDir
            if (!isMultipleLocalPlugins) {
                pluginSourcesDir = pluginSourcesDir.getParent();
            }
            // Copy the file if it exists
            Files.walk(pluginSourcesDir, 1).filter(this::isEslintFile).forEach(eslintrc -> copy(eslintrc, pluginDir));
        }
        // We need to compile before generating effective pom overriding jenkins.version
        // only if the plugin is not already compiled
        boolean ranCompile = moreInfo.containsKey(OVERRIDE_DEFAULT_COMPILE) ? (boolean) moreInfo.get(OVERRIDE_DEFAULT_COMPILE) : false;
        if (!ranCompile) {
            compile(mavenConfig, pluginDir);
            moreInfo.put(OVERRIDE_DEFAULT_COMPILE, true);
        }
        System.out.println("Executed multi-parent compile hook");
        return moreInfo;
    // Exceptions get swallowed, so we print to console here and rethrow again
    } catch (Exception e) {
        System.out.println("Exception executing hook");
        System.out.println(e);
        throw e;
    }
}
Also used : Path(java.nio.file.Path) PluginCompatTesterConfig(org.jenkins.tools.test.model.PluginCompatTesterConfig) MavenCoordinates(org.jenkins.tools.test.model.MavenCoordinates) ExternalMavenRunner(org.jenkins.tools.test.maven.ExternalMavenRunner) InternalMavenRunner(org.jenkins.tools.test.maven.InternalMavenRunner) File(java.io.File) PomExecutionException(org.jenkins.tools.test.exception.PomExecutionException) IOException(java.io.IOException)

Example 8 with MavenCoordinates

use of org.jenkins.tools.test.model.MavenCoordinates 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 9 with MavenCoordinates

use of org.jenkins.tools.test.model.MavenCoordinates in project plugin-compat-tester by jenkinsci.

the class DataProviderServlet method doGet.

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String type = request.getParameter("type");
    response.setContentType("application/json");
    Writer out = response.getWriter();
    if ("cores".equals(type)) {
        SortedSet<MavenCoordinates> cores = PluginCompatResultDAO.INSTANCE.findAllCores();
        out.write("{\"cores\":");
        JsonUtil.toJson(out, cores);
        out.write("}");
    } else if ("pluginInfos".equals(type)) {
        SortedSet<String> pluginInfoNames = PluginCompatResultDAO.INSTANCE.findAllPluginInfoNames();
        out.write("{");
        JsonUtil.displayMessages(out, "pluginInfos", pluginInfoNames);
        out.write("}");
    }
    out.flush();
}
Also used : MavenCoordinates(org.jenkins.tools.test.model.MavenCoordinates) SortedSet(java.util.SortedSet) Writer(java.io.Writer)

Example 10 with MavenCoordinates

use of org.jenkins.tools.test.model.MavenCoordinates in project plugin-compat-tester by jenkinsci.

the class JsonUtil method toJson.

public static void toJson(Writer w, SortedSet<MavenCoordinates> testedCoreCoordinates) throws IOException {
    w.write("[");
    for (Iterator<MavenCoordinates> coordIter = testedCoreCoordinates.iterator(); coordIter.hasNext(); ) {
        MavenCoordinates coord = coordIter.next();
        w.write(String.format("{\"g\":\"%s\",\"a\":\"%s\",\"v\":\"%s\"}", coord.groupId, coord.artifactId, coord.version));
        if (coordIter.hasNext()) {
            w.write(",");
        }
    }
    w.write("]");
}
Also used : MavenCoordinates(org.jenkins.tools.test.model.MavenCoordinates)

Aggregations

MavenCoordinates (org.jenkins.tools.test.model.MavenCoordinates)10 PomData (org.jenkins.tools.test.model.PomData)3 File (java.io.File)2 IOException (java.io.IOException)2 PomExecutionException (org.jenkins.tools.test.exception.PomExecutionException)2 ExternalMavenRunner (org.jenkins.tools.test.maven.ExternalMavenRunner)2 InternalMavenRunner (org.jenkins.tools.test.maven.InternalMavenRunner)2 PluginCompatResult (org.jenkins.tools.test.model.PluginCompatResult)2 PluginCompatTesterConfig (org.jenkins.tools.test.model.PluginCompatTesterConfig)2 PluginInfos (org.jenkins.tools.test.model.PluginInfos)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 FileInputStream (java.io.FileInputStream)1 Writer (java.io.Writer)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1