diff --git a/src/main/groovy/org/boozallen/plugins/jte/job/TemplateFlowDefinition.groovy b/src/main/groovy/org/boozallen/plugins/jte/job/TemplateFlowDefinition.groovy index 1cc9115c..95b32918 100644 --- a/src/main/groovy/org/boozallen/plugins/jte/job/TemplateFlowDefinition.groovy +++ b/src/main/groovy/org/boozallen/plugins/jte/job/TemplateFlowDefinition.groovy @@ -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. diff --git a/src/main/groovy/org/boozallen/plugins/jte/util/FileSystemCacheKey.groovy b/src/main/groovy/org/boozallen/plugins/jte/util/FileSystemCacheKey.groovy index 0b9ff486..84ed8cd3 100644 --- a/src/main/groovy/org/boozallen/plugins/jte/util/FileSystemCacheKey.groovy +++ b/src/main/groovy/org/boozallen/plugins/jte/util/FileSystemCacheKey.groovy @@ -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}, @@ -113,4 +128,4 @@ class FileSystemCacheKey { result = 31 * result + (scmRevision != null ? scmRevision.hashCode() : 0) return result } -} +} \ No newline at end of file diff --git a/src/main/groovy/org/boozallen/plugins/jte/util/FileSystemWrapperFactory.groovy b/src/main/groovy/org/boozallen/plugins/jte/util/FileSystemWrapperFactory.groovy index 8a3abcab..16f955c8 100644 --- a/src/main/groovy/org/boozallen/plugins/jte/util/FileSystemWrapperFactory.groovy +++ b/src/main/groovy/org/boozallen/plugins/jte/util/FileSystemWrapperFactory.groovy @@ -54,7 +54,23 @@ class FileSystemWrapperFactory { *
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.
*/ - private static MapThis 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.
+ * + *It uses the {@link Map#entrySet()} combined with {@link java.util.Map.Entry#removeIf(Predicate)} + * to efficiently remove the matching entries from the cache.
+ * + * @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 @@ -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") @@ -166,9 +181,4 @@ class FileSystemWrapperFactory { return fsw } } - - static void clearCache(FlowExecutionOwner owner) { - cache.entrySet().removeIf { entry -> entry.getKey().getOwner() == owner } - } - }