Skip to content

Avoid raw type warnings #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
private String issueStatus;
private String statusColor;
private String issueSummary;
private Job job; // the same as project if it's not a matrix build
private Job project;
private Job<?, ?> job; // the same as project if it's not a matrix build
private Job<?, ?> project;

/**
* Getter for issue status, called from issueStatus.jelly
Expand Down Expand Up @@ -93,57 +93,58 @@
public JiraTestAction(JiraTestData testData, CaseResult test) {
project = initProject();
if (project instanceof MatrixProject) {
job = (Job) Jenkins.get().getItemByFullName(testData.getEnvVars().get("JOB_NAME"));
job = (Job<?, ?>)
Jenkins.get().getItemByFullName(testData.getEnvVars().get("JOB_NAME"));
} else {
job = project;
}

if (project == null || job == null) {
// fix for interaction with Test stability history plugin
return;
}

this.testData = testData;
this.test = test;
for (String key : JiraUtils.searchIssueKeys(job, testData.getEnvVars(), test)) {
issueKey = key;
IssueRestClient issueRestClient =
JiraUtils.getJiraDescriptor().getRestClient().getIssueClient();
try {
Issue issue = issueRestClient.getIssue(key).claim();
issueStatus = issue.getStatus().getName();
issueSummary = issue.getSummary();
JiraTestDataPublisher.JiraTestDataPublisherDescriptor jiraDescriptor = JiraUtils.getJiraDescriptor();
if (jiraDescriptor.getStatusesMap() != null) {
FullStatus status = jiraDescriptor.getStatusesMap().get(issueStatus);
statusColor = status != null ? status.getColorName() : null;
}
} catch (Exception e) {
JiraUtils.logError("The issue might be deleted, or there is no internet connection, etc.", e);
}
}
}

/**
* Method for initializing the project. Used in constructor only.
* @return
*/
private Job initProject() {
private Job<?, ?> initProject() {
if (Stapler.getCurrentRequest2() == null) {
return null;
}

List<Ancestor> ancestors = Stapler.getCurrentRequest2().getAncestors();
for (Ancestor ancestor : ancestors) {
if (ancestor.getObject() instanceof AbstractProject) {
return (AbstractProject) ancestor.getObject();
return (AbstractProject<?, ?>) ancestor.getObject();
}
}

Job lastAncestor = null;
Job<?, ?> lastAncestor = null;
for (Ancestor ancestor : ancestors) {
if (ancestor.getObject() instanceof Job) {
lastAncestor = (Job) ancestor.getObject();
lastAncestor = (Job<?, ?>) ancestor.getObject();

Check warning on line 147 in src/main/java/org/jenkinsci/plugins/JiraTestResultReporter/JiraTestAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 96-147 are not covered by tests
}
}
return lastAncestor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.DescriptorExtensionList;
import hudson.EnvVars;
import hudson.Extension;
import hudson.FilePath;
Expand Down Expand Up @@ -156,7 +157,7 @@
* Getter for the project associated with this publisher
* @return
*/
private @CheckForNull AbstractProject getJobName() {
private @CheckForNull AbstractProject<?, ?> getJobName() {
StaplerRequest2 currentRequest = Stapler.getCurrentRequest2();
return currentRequest != null ? currentRequest.findAncestorObject(AbstractProject.class) : null;
}
Expand Down Expand Up @@ -231,34 +232,34 @@

if (Stapler.getCurrentRequest2() != null) {
// classic job - e.g. Freestyle project, Matrix project, etc.
AbstractProject project = Stapler.getCurrentRequest2().findAncestorObject(AbstractProject.class);
AbstractProject<?, ?> project = Stapler.getCurrentRequest2().findAncestorObject(AbstractProject.class);
TestToIssueMapping.getInstance().register(project);
JobConfigMapping.getInstance().saveConfig(project, getJobConfig());
} else {
// pipeline invocation
pipelineInvocation = true;
}
}

/**
* Method invoked for contributing data to this run, see Jenkins documentation for details about arguments
* @param run
* @param workspace
* @param launcher
* @param listener
* @param testResult
* @return a JiraTestData object
* @throws IOException
* @throws InterruptedException
*/
@Override
public TestResultAction.Data contributeTestData(
Run<?, ?> run, @NonNull FilePath workspace, Launcher launcher, TaskListener listener, TestResult testResult)
throws IOException, InterruptedException {

EnvVars envVars = run.getEnvironment(listener);
Job job = run.getParent();
Job project;
Job<?, ?> job = run.getParent();

Check warning on line 261 in src/main/java/org/jenkinsci/plugins/JiraTestResultReporter/JiraTestDataPublisher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 235-261 are not covered by tests
Job<?, ?> project;
if (job instanceof MatrixConfiguration) {
project = ((MatrixConfiguration) job).getParent();
} else {
Expand Down Expand Up @@ -312,7 +313,11 @@
}

private boolean unlinkIssuesForPassedTests(
TaskListener listener, Job project, Job job, EnvVars envVars, List<CaseResult> testCaseResults) {
TaskListener listener,
Job<?, ?> project,
Job<?, ?> job,
EnvVars envVars,
List<CaseResult> testCaseResults) {
boolean unlinked = false;
for (CaseResult test : testCaseResults) {
if (test.isPassed() && TestToIssueMapping.getInstance().getTestIssueKey(job, test.getId()) != null) {
Expand All @@ -327,8 +332,11 @@
}

private boolean resolveIssues(
TaskListener listener, Job project, Job job, EnvVars envVars, List<CaseResult> testCaseResults) {

TaskListener listener,
Job<?, ?> project,
Job<?, ?> job,
EnvVars envVars,
List<CaseResult> testCaseResults) {
boolean solved = false;
try {
for (CaseResult test : testCaseResults) {
Expand Down Expand Up @@ -366,7 +374,7 @@
return solved;
}

private boolean cleanJobCacheFile(TaskListener listener, Job job, List<CaseResult> testCaseResults) {
private boolean cleanJobCacheFile(TaskListener listener, Job<?, ?> job, List<CaseResult> testCaseResults) {
boolean cleanUp = false;
try {
cleanUp = JiraUtils.cleanJobCacheFile(testCaseResults, job);
Expand All @@ -379,7 +387,11 @@
}

private boolean raiseIssues(
TaskListener listener, Job project, Job job, EnvVars envVars, List<CaseResult> testCaseResults) {
TaskListener listener,
Job<?, ?> project,
Job<?, ?> job,
EnvVars envVars,
List<CaseResult> testCaseResults) {
boolean raised = false;
try {
for (CaseResult test : testCaseResults) {
Expand Down Expand Up @@ -847,7 +859,7 @@
* Getter for the descriptors required for the hetero-list in job config page (config.jelly)
* @return
*/
public List getListDescriptors() {
public DescriptorExtensionList<AbstractFields, ?> getListDescriptors() {
return Jenkins.get().getDescriptorList(AbstractFields.class);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ public static String getErrorMessage(RestClientException e, String newLine) {
return errorMessages.toString();
}

public static String createIssue(Job job, EnvVars envVars, CaseResult test) throws RestClientException {
public static String createIssue(Job<?, ?> job, EnvVars envVars, CaseResult test) throws RestClientException {
return createIssue(job, job, envVars, test, JiraIssueTrigger.JOB, Collections.emptyList());
}

public static boolean cleanJobCacheFile(List<CaseResult> testCaseResults, Job testJob) {
public static boolean cleanJobCacheFile(List<CaseResult> testCaseResults, Job<?, ?> testJob) {
List<String> testNames = testCaseResults.stream()
.filter(CaseResult::isFailed)
.map(CaseResult::getId)
Expand Down Expand Up @@ -153,7 +153,12 @@ public static boolean cleanJobCacheFile(List<CaseResult> testCaseResults, Job te
}

public static String createIssue(
Job job, Job project, EnvVars envVars, CaseResult test, JiraIssueTrigger trigger, List<String> attachments)
Job<?, ?> job,
Job<?, ?> project,
EnvVars envVars,
CaseResult test,
JiraIssueTrigger trigger,
List<String> attachments)
throws RestClientException {
synchronized (test.getId()) { // avoid creating duplicated issues
if (TestToIssueMapping.getInstance().getTestIssueKey(job, test.getId()) != null) {
Expand Down Expand Up @@ -194,7 +199,8 @@ public static String createIssue(
* @return related issue keys from issue map or from Jira server
* @throws RestClientException
*/
public static Set<String> searchIssueKeys(Job job, EnvVars envVars, CaseResult test) throws RestClientException {
public static Set<String> searchIssueKeys(Job<?, ?> job, EnvVars envVars, CaseResult test)
throws RestClientException {
synchronized (test.getId()) {
Set<String> issueKeys = new HashSet<>();
String issueKey = TestToIssueMapping.getInstance().getTestIssueKey(job, test.getId());
Expand All @@ -215,7 +221,7 @@ public static Set<String> searchIssueKeys(Job job, EnvVars envVars, CaseResult t
}

private static IssueInput createIssueInput(
Job project, TestResult test, EnvVars envVars, JiraIssueTrigger trigger) {
Job<?, ?> project, TestResult test, EnvVars envVars, JiraIssueTrigger trigger) {
final IssueInputBuilder newIssueBuilder = new IssueInputBuilder(
JobConfigMapping.getInstance().getProjectKey(project),
JobConfigMapping.getInstance().getIssueType(project));
Expand Down Expand Up @@ -304,7 +310,7 @@ private static String createIssueInput(IssueInput issueInput, CaseResult test, L
* @param envVars the environment variables
* @return a SearchResult. Empty SearchResult means nothing was found.
*/
public static SearchResult findIssues(Job project, TestResult test, EnvVars envVars, IssueInput issueInput)
public static SearchResult findIssues(Job<?, ?> project, TestResult test, EnvVars envVars, IssueInput issueInput)
throws RestClientException {
String projectKey = JobConfigMapping.getInstance().getProjectKey(project);
FieldInput fi = JiraTestDataPublisher.JiraTestDataPublisherDescriptor.templates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
private JobConfigMapping() {
configMap = new HashMap<String, JobConfigEntry>();

for (Job project : Jenkins.get().getItems(Job.class)) {
for (Job<?, ?> project : Jenkins.get().getItems(Job.class)) {

Check warning on line 265 in src/main/java/org/jenkinsci/plugins/JiraTestResultReporter/JobConfigMapping.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 265 is not covered by tests
JobConfigEntry entry = load(project);
if (entry != null) {
configMap.put(project.getFullName(), entry);
Expand All @@ -275,11 +275,11 @@
* @param project
* @return
*/
private String getPathToFile(Job project) {
private String getPathToFile(Job<?, ?> project) {
return project.getRootDir().toPath().resolve(CONFIGS_FILE).toString();
}

private String getPathToJsonFile(Job project) {
private String getPathToJsonFile(Job<?, ?> project) {
return project.getRootDir().toPath().resolve(CONFIGS_FILE).toString() + ".json";
}

Expand All @@ -289,7 +289,7 @@
* @param project
* @return the loaded JobConfigEntry, or null if there was no file, or it could not be loaded
*/
private JobConfigEntry loadBackwardsCompatible(Job project) {
private JobConfigEntry loadBackwardsCompatible(Job<?, ?> project) {
try {
FileInputStream fileIn = new FileInputStream(getPathToFile(project));
ObjectInputStream in = new ObjectInputStream(fileIn);
Expand Down Expand Up @@ -317,7 +317,7 @@
* @param project
* @return the loaded JobConfigEntry, or null if there was no file, or it could not be loaded
*/
private JobConfigEntry load(Job project) {
private JobConfigEntry load(Job<?, ?> project) {
JobConfigEntry entry = null;
try {
Gson gson = new GsonBuilder()
Expand Down Expand Up @@ -345,7 +345,7 @@
/**
* Method for saving the map, called every time the map changes
*/
private void save(Job project, JobConfigEntry entry) {
private void save(Job<?, ?> project, JobConfigEntry entry) {
try {
Gson gson = new GsonBuilder()
.registerTypeAdapter(AbstractFields.class, new FieldConfigsJsonAdapter())
Expand All @@ -369,7 +369,7 @@
* @param configs
*/
public synchronized void saveConfig(
Job project,
Job<?, ?> project,
String projectKey,
Long issueType,
List<AbstractFields> configs,
Expand All @@ -393,7 +393,7 @@
/**
* Method for setting the last configuration made for a project
*/
public synchronized void saveConfig(Job project, JobConfigEntry entry) {
public synchronized void saveConfig(Job<?, ?> project, JobConfigEntry entry) {
if (project == null) {
return;
}
Expand All @@ -404,7 +404,7 @@
save(project, entry);
}

private JobConfigEntry getJobConfigEntry(@CheckForNull Job project) {
private JobConfigEntry getJobConfigEntry(@CheckForNull Job<?, ?> project) {
if (project == null) {
return null;
}
Expand All @@ -422,7 +422,7 @@
* @param project
* @return
*/
public List<AbstractFields> getConfig(Job project) {
public List<AbstractFields> getConfig(Job<?, ?> project) {
JobConfigEntry entry = getJobConfigEntry(project);
return entry != null ? entry.getConfigs() : null;
}
Expand All @@ -432,7 +432,7 @@
* @param project
* @return
*/
public Long getIssueType(Job project) {
public Long getIssueType(Job<?, ?> project) {
JobConfigEntry entry = getJobConfigEntry(project);
return entry != null ? entry.getIssueType() : null;
}
Expand All @@ -442,32 +442,32 @@
* @param project
* @return
*/
public String getProjectKey(Job project) {
public String getProjectKey(Job<?, ?> project) {
JobConfigEntry entry = getJobConfigEntry(project);
return entry != null ? entry.getProjectKey() : null;
}

public boolean getAutoRaiseIssue(Job project) {
public boolean getAutoRaiseIssue(Job<?, ?> project) {
JobConfigEntry entry = getJobConfigEntry(project);
return entry != null ? entry.getAutoRaiseIssue() : false;
}

public boolean getAutoResolveIssue(Job project) {
public boolean getAutoResolveIssue(Job<?, ?> project) {
JobConfigEntry entry = getJobConfigEntry(project);
return entry != null ? entry.getAutoResolveIssue() : false;
}

public boolean getAutoUnlinkIssue(Job project) {
public boolean getAutoUnlinkIssue(Job<?, ?> project) {
JobConfigEntry entry = getJobConfigEntry(project);
return entry != null ? entry.getAutoUnlinkIssue() : false;
}

public boolean getAdditionalAttachments(Job project) {
public boolean getAdditionalAttachments(Job<?, ?> project) {
JobConfigEntry entry = getJobConfigEntry(project);
return entry != null ? entry.getAdditionalAttachments() : false;
}

public boolean getOverrideResolvedIssues(Job project) {
public boolean getOverrideResolvedIssues(Job<?, ?> project) {
JobConfigEntry entry = getJobConfigEntry(project);
return entry != null ? entry.getOverrideResolvedIssues() : false;
}
Expand All @@ -477,7 +477,7 @@
* @param project
* @return
*/
public Pattern getIssueKeyPattern(Job project) {
public Pattern getIssueKeyPattern(Job<?, ?> project) {
JobConfigEntry entry = getJobConfigEntry(project);
return entry != null ? entry.getIssueKeyPattern() : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,99 +113,101 @@
private void listInfo(Map.Entry<String, CimFieldInfo> entry) {
System.out.println(entry.getValue().getName() + " :: "
+ entry.getValue().getSchema().getType());
if (entry.getValue().getAllowedValues() != null) {
for (Object o : entry.getValue().getAllowedValues()) {
Iterable<?> allowedValues = entry.getValue().getAllowedValues();
if (allowedValues != null) {
for (Object o : allowedValues) {
System.out.println("\t" + o);
}
}
}
}

/**
* Method for removing the cache entry
* @param projectKey
* @param issueType
*/
public void removeCacheEntry(String projectKey, String issueType) {
if (fieldConfigCache.containsKey(projectKey)
&& fieldConfigCache.get(projectKey).containsKey(issueType)) {
synchronized (fieldConfigCache.get(projectKey)) {
fieldConfigCache.get(projectKey).remove(issueType);
}
}
}

/**
* Getter for a cache entry, it will first look in the map too see if there is an entry associated with the
* arguments, if not it will make the request for the metadata, create the entry, store it in the map and return it
* @param projectKey
* @param issueType
* @return
*/
public CacheEntry getCacheEntry(String projectKey, String issueType) {
CacheEntry cacheEntry;
try {
cacheEntry = fieldConfigCache.get(projectKey).get(issueType);
if (cacheEntry == null) {
fieldConfigCache.get(projectKey).remove(issueType);
} else {
return cacheEntry;
}
} catch (NullPointerException e) {
// Absent project key or issue type
}

if (!fieldConfigCache.containsKey(projectKey)) {
synchronized (fieldConfigCache) {
if (!fieldConfigCache.containsKey(projectKey)) {
fieldConfigCache.put(projectKey, new HashMap<String, CacheEntry>());
}
}
}

HashMap<String, CacheEntry> issueTypeToFields = fieldConfigCache.get(projectKey);
cacheEntry = issueTypeToFields.get(issueType);
if (cacheEntry == null) {
synchronized (issueTypeToFields) {
if (!issueTypeToFields.containsKey(issueType)) {
IssueRestClient issueRestClient =
JiraUtils.getJiraDescriptor().getRestClient().getIssueClient();
Iterable<CimProject> metadata;
try {
metadata = issueRestClient
.getCreateIssueMetadata(new GetCreateIssueMetadataOptions(
Collections.singletonList(
GetCreateIssueMetadataOptions.EXPAND_PROJECTS_ISSUETYPES_FIELDS),
null,
Collections.singletonList(Long.parseLong(issueType)),
Collections.singletonList(projectKey),
null))
.claim();
} catch (Exception e) {
JiraUtils.logError("ERROR: Unknown error", e);
return null;
}

cacheEntry = new CacheEntry(metadata);
issueTypeToFields.put(issueType, cacheEntry);
return cacheEntry;
}
}
cacheEntry = issueTypeToFields.get(issueType);
}

return cacheEntry;
}

/**
* Method for printing the metadata
* @param entry
*/
private void listInfo(Map.Entry<String, CimFieldInfo> entry) {
System.out.println(entry.getValue().getName() + " :: "
+ entry.getValue().getSchema().getType());
if (entry.getValue().getAllowedValues() != null) {
for (Object o : entry.getValue().getAllowedValues()) {
Iterable<?> allowedValues = entry.getValue().getAllowedValues();
if (allowedValues != null) {
for (Object o : allowedValues) {

Check warning on line 210 in src/main/java/org/jenkinsci/plugins/JiraTestResultReporter/MetadataCache.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 116-210 are not covered by tests
System.out.println("\t" + o);
}
}
Expand Down
Loading