Skip to content

Commit

Permalink
resolver codenarc issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Echavarria committed Sep 16, 2024
1 parent ef34828 commit 0842bf6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,25 @@
*/
package org.boozallen.plugins.jte.job

import org.boozallen.plugins.jte.util.FileSystemWrapperFactory

import static org.jenkinsci.plugins.workflow.cps.persistence.PersistenceContext.JOB

import org.boozallen.plugins.jte.init.primitives.TemplatePrimitiveCollector
import org.jenkinsci.plugins.pipeline.modeldefinition.causes.RestartDeclarativePipelineCause
import org.jenkinsci.plugins.workflow.cps.replay.ReplayCause
import org.boozallen.plugins.jte.init.PipelineConfigurationAggregator
import org.boozallen.plugins.jte.init.PipelineTemplateResolver
import org.boozallen.plugins.jte.init.governance.config.dsl.PipelineConfigurationObject
import org.boozallen.plugins.jte.init.primitives.TemplatePrimitiveInjector
import hudson.model.Action
import hudson.model.Item
import hudson.model.Queue
import hudson.model.TaskListener
import org.boozallen.plugins.jte.init.PipelineConfigurationAggregator
import org.boozallen.plugins.jte.init.PipelineTemplateResolver
import org.boozallen.plugins.jte.init.governance.config.dsl.PipelineConfigurationObject
import org.boozallen.plugins.jte.init.primitives.TemplatePrimitiveCollector
import org.boozallen.plugins.jte.init.primitives.TemplatePrimitiveInjector

import org.jenkinsci.plugins.pipeline.modeldefinition.causes.RestartDeclarativePipelineCause
import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution
import org.jenkinsci.plugins.workflow.cps.CpsFlowFactoryAction2
import org.jenkinsci.plugins.workflow.cps.persistence.PersistIn
import org.jenkinsci.plugins.workflow.flow.FlowDefinition
import org.jenkinsci.plugins.workflow.flow.FlowExecution
import org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner
import org.jenkinsci.plugins.workflow.flow.FlowDurabilityHint
import org.jenkinsci.plugins.workflow.flow.DurabilityHintProvider
import org.jenkinsci.plugins.workflow.flow.GlobalDefaultFlowDurabilityLevel
import org.jenkinsci.plugins.workflow.cps.replay.ReplayCause
import org.jenkinsci.plugins.workflow.flow.*
import org.jenkinsci.plugins.workflow.job.WorkflowRun
import org.jenkinsci.plugins.workflow.cps.CpsFlowFactoryAction2

import static org.jenkinsci.plugins.workflow.cps.persistence.PersistenceContext.JOB

/**
* Defines a JTE Pipeline.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,36 @@ class FileSystemCacheKey {
* @return {@code true} if the provided object is equal to this instance, {@code false} otherwise.
*/
@Override
boolean equals(o) {
if (this.is(o)) return true
if (!(o instanceof FileSystemCacheKey)) return false
boolean equals(Object o) {
if (this == o) {
return true
}
if (!(o instanceof FileSystemCacheKey)) {
return false
}

FileSystemCacheKey that = (FileSystemCacheKey) o

if (owner != that.owner) return false
if (scm != that.scm) return false
if (scmHead != that.scmHead) return false
if (scmRevision != that.scmRevision) return false
if (scmSource != that.scmSource) return false
if (owner != that.owner) {
return false
}
if (scm != that.scm) {
return false
}
if (scmHead != that.scmHead) {
return false
}
if (scmRevision != that.scmRevision) {
return false
}
if (scmSource != that.scmSource) {
return false
}

return true
}


/**
* Generates a hash code for this FileSystemCacheKey instance.
* The hash code is computed based on the {@code owner}, {@code scm}, {@code scmSource},
Expand All @@ -113,4 +128,4 @@ class FileSystemCacheKey {
result = 31 * result + (scmRevision != null ? scmRevision.hashCode() : 0)
return result
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,23 @@ class FileSystemWrapperFactory {
* <p>This cache is a static attribute of the class, shared across all instances of {@code FileSystemCacheKey},
* and is initialized as an empty map, represented by {@code [:]}. It can grow dynamically as new entries are added during runtime.</p>
*/
private static Map<FileSystemCacheKey, FileSystemWrapper> cache = [:]
private final static Map<FileSystemCacheKey, FileSystemWrapper> cache = [:]

/**
* Clears the cache for a specific {@link FlowExecutionOwner}.
*
* <p>This method iterates through the cache entries and removes any entries where the
* {@link FileSystemCacheKey#getOwner()} matches the provided {@code owner}. This is useful
* for invalidating or cleaning up cache entries associated with a particular pipeline execution.</p>
*
* <p>It uses the {@link Map#entrySet()} combined with {@link java.util.Map.Entry#removeIf(Predicate)}
* to efficiently remove the matching entries from the cache.</p>
*
* @param owner the {@link FlowExecutionOwner} whose associated cache entries should be removed.
*/
static void clearCache(FlowExecutionOwner owner) {
cache.entrySet().removeIf { entry -> entry.getKey().getOwner() == owner }
}

/**
* Creates a FileSystemWrapper. Can either be provided an SCM directly
Expand Down Expand Up @@ -115,7 +131,6 @@ class FileSystemWrapperFactory {
}
Branch branch = property.getBranch()


SCMSource scmSource = parent.getSCMSource(branch.getSourceId())
if (!scmSource) {
throw new IllegalStateException("${branch.getSourceId()} not found")
Expand Down Expand Up @@ -166,9 +181,4 @@ class FileSystemWrapperFactory {
return fsw
}
}

static void clearCache(FlowExecutionOwner owner) {
cache.entrySet().removeIf { entry -> entry.getKey().getOwner() == owner }
}

}

0 comments on commit 0842bf6

Please sign in to comment.