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)));
}
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;
}
}
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;
}
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();
}
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("]");
}
Aggregations