Search in sources :

Example 1 with PomData

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

the class TransformPom method check.

/**
 * Check if the pom should be transformed for the given plugin.
 */
public boolean check(Map<String, Object> info) {
    boolean mustTransformPom = false;
    // TODO future versions of DEFAULT_PARENT_GROUP/ARTIFACT may be able to use this as well
    PomData pomData = (PomData) info.get("pomData");
    MavenCoordinates parent = pomData.parent;
    MavenCoordinates coreCoordinates = (MavenCoordinates) info.get("coreCoordinates");
    boolean isDeclarativePipeline = parent.matches("org.jenkinsci.plugins", "pipeline-model-parent");
    boolean isCB = parent.matches("com.cloudbees.jenkins.plugins", "jenkins-plugins") || // TODO ought to analyze the chain of parent POMs, which would lead to com.cloudbees.jenkins.plugins:jenkins-plugins in this case:
    parent.matches("com.cloudbees.operations-center.common", "operations-center-parent") || parent.matches("com.cloudbees.operations-center.client", "operations-center-parent-client");
    boolean isBO = parent.matches("io.jenkins.blueocean", "blueocean-parent");
    boolean isStructs = parent.matches("org.jenkins-ci.plugins", "structs-parent");
    boolean pluginPOM = parent.matches("org.jenkins-ci.plugins", "plugin");
    boolean parentV2 = parent.compareVersionTo("2.0") >= 0;
    boolean parentUnder233 = parentV2 && parent.compareVersionTo(PLUGINS_PARENT_POM_FOR_CORE_WITHOUT_WAR_TEST) < 0;
    boolean coreRequiresNewParentPOM = coreCoordinates.compareVersionTo(CORE_NEW_PARENT_POM) >= 0;
    boolean coreRequiresPluginOver233 = coreCoordinates.compareVersionTo(CORE_WITHOUT_WAR_FOR_TEST) >= 0;
    if (isDeclarativePipeline || isBO || isCB || isStructs || (pluginPOM && parentV2)) {
        List<String> argsToMod = (List<String>) info.get("args");
        argsToMod.add("-Djenkins.version=" + coreCoordinates.version);
        // There are rules that avoid dependencies on a higher java level. Depending on the baselines and target cores
        // the plugin may be Java 6 and the dependencies bring Java 7
        argsToMod.add("-Denforcer.skip=true");
        info.put("args", argsToMod);
        if (coreRequiresPluginOver233 && pluginPOM && parentUnder233) {
            info.put(NEW_PLUGINS_PARENT_VERSION_KEY, PLUGINS_PARENT_POM_FOR_CORE_WITHOUT_WAR_TEST);
            mustTransformPom = true;
        }
    } else if (coreRequiresNewParentPOM && pluginPOM && !parentV2) {
        throw new RuntimeException("New parent POM required for core >= 1.646");
    } else {
        mustTransformPom = true;
    }
    return mustTransformPom;
}
Also used : MavenCoordinates(org.jenkins.tools.test.model.MavenCoordinates) PomData(org.jenkins.tools.test.model.PomData) List(java.util.List)

Example 2 with PomData

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

use of org.jenkins.tools.test.model.PomData 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)

Aggregations

MavenCoordinates (org.jenkins.tools.test.model.MavenCoordinates)3 PomData (org.jenkins.tools.test.model.PomData)3 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 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 JarFile (java.util.jar.JarFile)1 JSONObject (net.sf.json.JSONObject)1 RawInputStreamFacade (org.codehaus.plexus.util.io.RawInputStreamFacade)1 PomExecutionException (org.jenkins.tools.test.exception.PomExecutionException)1 ExternalMavenRunner (org.jenkins.tools.test.maven.ExternalMavenRunner)1 InternalMavenRunner (org.jenkins.tools.test.maven.InternalMavenRunner)1 MavenRunner (org.jenkins.tools.test.maven.MavenRunner)1