Search in sources :

Example 1 with PluginCompatTesterConfig

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

the class PluginCompatTesterCli method main.

public static void main(String[] args) throws IOException, PlexusContainerException, MavenEmbedderException {
    CliOptions options = new CliOptions();
    JCommander jcommander = null;
    try {
        jcommander = new JCommander(options, args);
    } catch (ParameterException e) {
        System.err.println(e.getMessage());
        if (jcommander == null) {
            jcommander = new JCommander(options);
        }
        jcommander.usage();
        System.exit(1);
    }
    if (options.isPrintHelp()) {
        jcommander.usage();
        System.exit(0);
    }
    options.getWorkDirectory().mkdirs();
    File reportFile = null;
    if (!"NOREPORT".equals(options.getReportFile().getName())) {
        reportFile = options.getReportFile();
    }
    if (reportFile != null) {
        // Check the format requirement
        File parentFile = reportFile.getParentFile();
        if (parentFile == null) {
            throw new IllegalArgumentException("The -reportFile value '" + reportFile + "' does not have a directory specification. " + "A path should be something like 'out/pct-report.xml'");
        }
    }
    String updateCenterUrl = options.getUpdateCenterUrl();
    String parentCoordinates = options.getParentCoord();
    File war = options.getWar();
    if (war != null) {
        if (updateCenterUrl != null || parentCoordinates != null) {
            throw new IllegalStateException("Cannot specify -war together with either -updateCenterUrl or -parentCoordinates");
        }
    }
    // We may need this data even in the -war mode
    if (updateCenterUrl == null) {
        updateCenterUrl = PluginCompatTesterConfig.DEFAULT_UPDATE_CENTER_URL;
    }
    if (parentCoordinates == null) {
        parentCoordinates = PluginCompatTesterConfig.DEFAULT_PARENT_GAV;
    }
    PluginCompatTesterConfig config = new PluginCompatTesterConfig(updateCenterUrl, parentCoordinates, options.getWorkDirectory(), reportFile, options.getM2SettingsFile());
    config.setWar(war);
    config.setExternalMaven(options.getExternalMaven());
    if (options.getIncludePlugins() != null && !options.getIncludePlugins().isEmpty()) {
        config.setIncludePlugins(Arrays.asList(options.getIncludePlugins().toLowerCase().split(",")));
    }
    if (options.getExcludePlugins() != null && !options.getExcludePlugins().isEmpty()) {
        config.setExcludePlugins(Arrays.asList(options.getExcludePlugins().toLowerCase().split(",")));
    }
    if (options.getSkipTestCache() != null) {
        config.setSkipTestCache(Boolean.valueOf(options.getSkipTestCache()).booleanValue());
    }
    if (options.getTestCacheTimeout() != null) {
        config.setTestCacheTimeout(options.getTestCacheTimeout().longValue());
    }
    if (options.getCacheThresholdStatus() != null) {
        config.setCacheThresholStatus(TestStatus.valueOf(options.getCacheThresholdStatus()));
    }
    if (options.getGaeBaseUrl() != null) {
        config.setGaeBaseUrl(options.getGaeBaseUrl());
    }
    if (options.getGaeSecurityToken() != null) {
        config.setGaeSecurityToken(options.getGaeSecurityToken());
    }
    if (options.getHookPrefixes() != null && !options.getHookPrefixes().isEmpty()) {
        config.setHookPrefixes(Arrays.asList(options.getHookPrefixes().split(",")));
    }
    if (options.getLocalCheckoutDir() != null && !options.getLocalCheckoutDir().isEmpty()) {
        config.setLocalCheckoutDir(options.getLocalCheckoutDir());
    }
    PluginCompatTester tester = new PluginCompatTester(config);
    tester.testPlugins();
}
Also used : PluginCompatTesterConfig(org.jenkins.tools.test.model.PluginCompatTesterConfig) JCommander(com.beust.jcommander.JCommander) ParameterException(com.beust.jcommander.ParameterException) File(java.io.File)

Example 2 with PluginCompatTesterConfig

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

the class PluginCompatTesterTest method testWithUrl.

@Test
public void testWithUrl() throws Throwable {
    List<String> includedPlugins = new ArrayList<String>() {

        {
            /*add("scm-sync-configuration");*/
            add("accurev");
        /*add("active-directory"); add("analysis-collector");*/
        }
    };
    PluginCompatTesterConfig config = new PluginCompatTesterConfig(testFolder.getRoot(), new File("../reports/PluginCompatReport.xml"), new ClassPathResource("m2-settings.xml").getFile());
    config.setIncludePlugins(includedPlugins);
    config.setSkipTestCache(true);
    config.setCacheThresholStatus(TestStatus.TEST_FAILURES);
    config.setTestCacheTimeout(345600000);
    config.setParentVersion("1.410");
    config.setGenerateHtmlReport(true);
    PluginCompatTester tester = new PluginCompatTester(config);
    tester.testPlugins();
}
Also used : PluginCompatTesterConfig(org.jenkins.tools.test.model.PluginCompatTesterConfig) ArrayList(java.util.ArrayList) File(java.io.File) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 3 with PluginCompatTesterConfig

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

the class ExampleMultiParent method action.

/*
     * No check implementation is required because transformedPlugins
     * returns your specific list.
     */
/**
 * Point to the shared location.  Check if this needs to be downloaded.
 */
public Map<String, Object> action(Map<String, Object> moreInfo) throws Exception {
    PluginCompatTesterConfig config = (PluginCompatTesterConfig) moreInfo.get("config");
    Plugin currentPlugin = (Plugin) moreInfo.get("plugin");
    // Determine if we need to run the download; only run for first identified plugin in the series
    if (firstRun) {
        System.out.println("Preparing for Multimodule checkout.");
        // Checkout to the parent directory. All other processes will be on the child directory
        File parentPath = new File(config.workDirectory.getAbsolutePath() + "/" + parentName);
        System.out.println("Checking out from SCM connection URL : " + parentUrl + " (" + parentName + "-" + currentPlugin.version + ")");
        ScmManager scmManager = SCMManagerFactory.getInstance().createScmManager();
        ScmRepository repository = scmManager.makeScmRepository(parentUrl);
        CheckOutScmResult result = scmManager.checkOut(repository, new ScmFileSet(parentPath), new ScmTag(parentName + "-" + currentPlugin.version));
        if (!result.isSuccess()) {
            throw new RuntimeException(result.getProviderMessage() + "||" + result.getCommandOutput());
        }
    }
    // Checkout already happened, don't run through again
    moreInfo.put("runCheckout", false);
    firstRun = false;
    // Change the "download"" directory; after download, it's simply used for reference
    File childPath = new File(config.workDirectory.getAbsolutePath() + "/" + parentName + "/" + currentPlugin.name);
    moreInfo.put("checkoutDir", childPath);
    return moreInfo;
}
Also used : PluginCompatTesterConfig(org.jenkins.tools.test.model.PluginCompatTesterConfig) ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmTag(org.apache.maven.scm.ScmTag) ScmManager(org.apache.maven.scm.manager.ScmManager) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) File(java.io.File) Plugin(hudson.model.UpdateSite.Plugin)

Example 4 with PluginCompatTesterConfig

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

the class MultiParentCompileHook method getMavenConfig.

private MavenRunner.Config getMavenConfig(PluginCompatTesterConfig config) throws IOException {
    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 = 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");
        }
    }
    return mconfig;
}
Also used : ExternalMavenRunner(org.jenkins.tools.test.maven.ExternalMavenRunner) MavenRunner(org.jenkins.tools.test.maven.MavenRunner) InternalMavenRunner(org.jenkins.tools.test.maven.InternalMavenRunner) PluginCompatTesterConfig(org.jenkins.tools.test.model.PluginCompatTesterConfig) Properties(java.util.Properties) File(java.io.File) Map(java.util.Map) FileInputStream(java.io.FileInputStream)

Example 5 with PluginCompatTesterConfig

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

Aggregations

File (java.io.File)6 PluginCompatTesterConfig (org.jenkins.tools.test.model.PluginCompatTesterConfig)6 ScmFileSet (org.apache.maven.scm.ScmFileSet)2 ScmTag (org.apache.maven.scm.ScmTag)2 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)2 ScmManager (org.apache.maven.scm.manager.ScmManager)2 ScmRepository (org.apache.maven.scm.repository.ScmRepository)2 ExternalMavenRunner (org.jenkins.tools.test.maven.ExternalMavenRunner)2 InternalMavenRunner (org.jenkins.tools.test.maven.InternalMavenRunner)2 JCommander (com.beust.jcommander.JCommander)1 ParameterException (com.beust.jcommander.ParameterException)1 UpdateSite (hudson.model.UpdateSite)1 Plugin (hudson.model.UpdateSite.Plugin)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Properties (java.util.Properties)1 PomExecutionException (org.jenkins.tools.test.exception.PomExecutionException)1