-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add provide generated ecu.test reports step (#159)
- Loading branch information
Showing
19 changed files
with
657 additions
and
68 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
.../de/tracetronic/jenkins/plugins/ecutestexecution/steps/ProvideGeneratedReportsStep.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright (c) 2024 tracetronic GmbH | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
package de.tracetronic.jenkins.plugins.ecutestexecution.steps | ||
|
||
import com.google.common.collect.ImmutableSet | ||
import de.tracetronic.jenkins.plugins.ecutestexecution.util.ZipUtil | ||
import hudson.EnvVars | ||
import hudson.Extension | ||
import hudson.Launcher | ||
import hudson.model.TaskListener | ||
import org.jenkinsci.plugins.workflow.steps.StepDescriptor | ||
import org.kohsuke.stapler.DataBoundConstructor | ||
import org.kohsuke.stapler.DataBoundSetter | ||
|
||
import java.nio.file.FileSystems | ||
import java.nio.file.Path | ||
import java.nio.file.PathMatcher | ||
import java.nio.file.Paths | ||
import java.util.zip.ZipFile | ||
|
||
class ProvideGeneratedReportsStep extends AbstractProvideExecutionFilesStep { | ||
private static final String ICON_NAME = 'generateReport' | ||
private static final String OUT_DIR_NAME = "Generated ecu.test Reports" | ||
private static final String SUPPORT_VERSION = "2024.3" | ||
private String selectedReportTypes | ||
|
||
@DataBoundConstructor | ||
ProvideGeneratedReportsStep() { | ||
super() | ||
this.selectedReportTypes = DescriptorImpl.getSelectedReportTypes() | ||
iconName = ICON_NAME | ||
outDirName = OUT_DIR_NAME | ||
supportVersion = SUPPORT_VERSION | ||
} | ||
|
||
String getSelectedReportTypes() { | ||
return this.selectedReportTypes | ||
} | ||
|
||
@DataBoundSetter | ||
void setSelectedReportTypes(String selectedReportTypes) { | ||
this.selectedReportTypes = (selectedReportTypes != null) ? selectedReportTypes : DescriptorImpl.getSelectedReportTypes() | ||
} | ||
|
||
protected ArrayList<String> processReport(File reportFile, String reportDirName, String outDirPath, TaskListener listener) { | ||
ArrayList<String> generatedZipPaths = new ArrayList<>() | ||
ZipFile reportZip = new ZipFile(reportFile) | ||
Set<String> targetFolderPaths = new HashSet<>() | ||
|
||
String reportTypes = selectedReportTypes.replace("*", "[^/\\\\]*") | ||
List<String> reportTypesList = reportTypes.split(",\\s*") | ||
reportZip.entries().each { entry -> | ||
Path entryPath = Paths.get(entry.name) | ||
String path = entryPath.getParent().toString() | ||
for (String reportTypeStr : reportTypesList) { | ||
String pattern = "regex:(.+(/|\\\\))?${reportTypeStr}" | ||
PathMatcher matcher = FileSystems.getDefault().getPathMatcher(pattern) | ||
if (entryPath.getParent() && matcher.matches(entryPath.getParent())) { | ||
targetFolderPaths.add(path) | ||
} | ||
} | ||
} | ||
|
||
for (String path : targetFolderPaths) { | ||
def outputFile = new File("${outDirPath}/${reportDirName}/${path}.zip") | ||
outputFile.parentFile.mkdirs() | ||
def zipPath = ZipUtil.recreateWithPath(reportFile, path, outputFile,true) | ||
generatedZipPaths.add(zipPath) | ||
} | ||
|
||
|
||
if (generatedZipPaths.isEmpty()) { | ||
listener.logger.println("[WARNING] Could not find any matching generated report files in ${reportDirName}!") | ||
} | ||
|
||
return generatedZipPaths | ||
} | ||
|
||
@Extension | ||
static final class DescriptorImpl extends StepDescriptor { | ||
|
||
static String getSelectedReportTypes() { | ||
return GenerateReportsStep.DescriptorImpl.REPORT_GENERATORS.collect { it + "*" }.join(", ") | ||
} | ||
|
||
@Override | ||
String getFunctionName() { | ||
'ttProvideGeneratedReports' | ||
} | ||
|
||
@Override | ||
String getDisplayName() { | ||
'[TT] Provide generated ecu.test reports as job artifacts.' | ||
} | ||
|
||
@Override | ||
Set<? extends Class<?>> getRequiredContext() { | ||
return ImmutableSet.of(Launcher.class, EnvVars.class, TaskListener.class) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...acetronic/jenkins/plugins/ecutestexecution/steps/ProvideGeneratedReportsStep/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form"> | ||
<f:description>${%step.description} | ||
<b>${%step.compatNote}</b> | ||
</f:description> | ||
<f:entry title="${%selectedReportTypes.title}" description="${%selectedReportTypes.description}" | ||
field="selectedReportTypes"> | ||
<f:textbox value="${descriptor.getSelectedReportTypes()}"/> | ||
</f:entry> | ||
<f:advanced> | ||
<f:property field="publishConfig"/> | ||
</f:advanced> | ||
</j:jelly> |
4 changes: 4 additions & 0 deletions
4
...onic/jenkins/plugins/ecutestexecution/steps/ProvideGeneratedReportsStep/config.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
step.description=This step provides all custom generated ecu.test reports as job artifacts. | ||
step.compatNote=This feature is only available for ecu.test 2024.3 or higher! | ||
selectedReportTypes.title=Select Generated Reports | ||
selectedReportTypes.description=Comma separated list of generated report folder names that should be provided as zip in Jenkins. It is possible to use * to match multiple reports. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.