diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eb1b47c98..78b33548a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,7 +30,7 @@ jobs: - name: Setup Java uses: actions/setup-java@v1 with: - java-version: 1.8 + java-version: 17 - name: Setup Gradle Cache uses: actions/cache@v2 diff --git a/.github/workflows/detekt.yml b/.github/workflows/detekt.yml index 1d82b5641..781c0e887 100644 --- a/.github/workflows/detekt.yml +++ b/.github/workflows/detekt.yml @@ -14,7 +14,7 @@ jobs: - name: Setup Java uses: actions/setup-java@v1 with: - java-version: 1.8 + java-version: 17 - name: Setup Gradle Cache uses: actions/cache@v2 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8cde48bb7..2ba62db28 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -28,7 +28,7 @@ jobs: - name: Setup Java uses: actions/setup-java@v1 with: - java-version: 1.8 + java-version: 17 - name: Setup Gradle Cache uses: actions/cache@v2 diff --git a/src/main/kotlin/snyk/container/KubernetesImageCache.kt b/src/main/kotlin/snyk/container/KubernetesImageCache.kt index 8a8451b6d..e4c98e26a 100644 --- a/src/main/kotlin/snyk/container/KubernetesImageCache.kt +++ b/src/main/kotlin/snyk/container/KubernetesImageCache.kt @@ -9,7 +9,6 @@ import com.intellij.openapi.vfs.VirtualFile import com.intellij.util.RunnableCallable import com.intellij.util.concurrency.NonUrgentExecutor import com.jetbrains.rd.util.concurrentMapOf -import snyk.container.YAMLImageExtractor.extractFromFile @Service class KubernetesImageCache(val project: Project) { @@ -23,7 +22,7 @@ class KubernetesImageCache(val project: Project) { fun scanProjectForKubernetesFiles() { val callable = RunnableCallable { ProjectRootManager.getInstance(project).fileIndex.iterateContent { virtualFile -> - extractFromFile(virtualFile, project) + extractFromFileAndAddToCache(virtualFile) true } } @@ -49,13 +48,13 @@ class KubernetesImageCache(val project: Project) { fun updateCache(files: Set) { files.forEach { file -> - extractFromFile(file) + extractFromFileAndAddToCache(file) } } /** public for Tests only */ - fun extractFromFile(file: VirtualFile) { - val extractFromFile = extractFromFile(file, project) + fun extractFromFileAndAddToCache(file: VirtualFile) { + val extractFromFile = YAMLImageExtractor.extractFromFile(file, project) if (extractFromFile.isNotEmpty()) { logger.debug("${if (images.contains(file)) "updated" else "added"} $file in cache") images[file] = extractFromFile diff --git a/src/test/kotlin/snyk/container/ContainerBulkFileListenerTest.kt b/src/test/kotlin/snyk/container/ContainerBulkFileListenerTest.kt index 0b462417d..8bcd70fc0 100644 --- a/src/test/kotlin/snyk/container/ContainerBulkFileListenerTest.kt +++ b/src/test/kotlin/snyk/container/ContainerBulkFileListenerTest.kt @@ -156,7 +156,7 @@ class ContainerBulkFileListenerTest : BasePlatformTestCase() { getSnykCachedResults(project)?.currentContainerResult = fakeContainerResult toolWindowPanel.getRootContainerIssuesTreeNode().add(ContainerImageTreeNode(issuesForImage, project) {}) - getKubernetesImageCache(project)?.extractFromFile(addedPsiFile.virtualFile) + getKubernetesImageCache(project)?.extractFromFileAndAddToCache(addedPsiFile.virtualFile) } fun `test ContainerResults should drop cache and mark rescanNeeded when Container supported file CHANGED`() { diff --git a/src/test/kotlin/snyk/container/ContainerServiceIntegTest.kt b/src/test/kotlin/snyk/container/ContainerServiceIntegTest.kt index 2690b8076..03949b80a 100644 --- a/src/test/kotlin/snyk/container/ContainerServiceIntegTest.kt +++ b/src/test/kotlin/snyk/container/ContainerServiceIntegTest.kt @@ -111,7 +111,7 @@ class ContainerServiceIntegTest : LightPlatform4TestCase() { val file = createFile(fileName, podYaml()) val cache = spyk(KubernetesImageCache(project)) cut.setKubernetesImageCache(cache) - cache.extractFromFile(file.virtualFile) + cache.extractFromFileAndAddToCache(file.virtualFile) return cache } diff --git a/src/test/kotlin/snyk/container/KubernetesImageCacheIntegTest.kt b/src/test/kotlin/snyk/container/KubernetesImageCacheIntegTest.kt index b1bba33bc..af7a85968 100644 --- a/src/test/kotlin/snyk/container/KubernetesImageCacheIntegTest.kt +++ b/src/test/kotlin/snyk/container/KubernetesImageCacheIntegTest.kt @@ -51,7 +51,7 @@ class KubernetesImageCacheIntegTest : LightPlatform4TestCase() { @Test fun `extractFromFile should find yaml files and extract images`() { val file = createFile(fileName, podYaml()).virtualFile - cut.extractFromFile(file) + cut.extractFromFileAndAddToCache(file) val images = cut.getKubernetesWorkloadImages() assertEquals(1, images.size) @@ -149,7 +149,7 @@ class KubernetesImageCacheIntegTest : LightPlatform4TestCase() { fun `should return Kubernetes Workload Files`() { val file = createFile(fileName, podYaml()).virtualFile - cut.extractFromFile(file) + cut.extractFromFileAndAddToCache(file) val files: Set = cut.getKubernetesWorkloadFilesFromCache() assertEquals(1, files.size) @@ -160,7 +160,7 @@ class KubernetesImageCacheIntegTest : LightPlatform4TestCase() { fun `should not parse non yaml files`() { val file = createFile("not-a-yaml-file.zaml", podYaml()).virtualFile - cut.extractFromFile(file) + cut.extractFromFileAndAddToCache(file) val files: Set = cut.getKubernetesWorkloadFilesFromCache() assertEmpty(files) @@ -170,7 +170,7 @@ class KubernetesImageCacheIntegTest : LightPlatform4TestCase() { fun `should return Kubernetes Workload Image Names`() { val file = createFile(fileName, podYaml()).virtualFile - cut.extractFromFile(file) + cut.extractFromFileAndAddToCache(file) val images: Set = cut.getKubernetesWorkloadImageNamesFromCache() assertEquals(1, images.size) @@ -181,7 +181,7 @@ class KubernetesImageCacheIntegTest : LightPlatform4TestCase() { fun `should return Kubernetes Workload Images with correct line number`() { val file = createFile(fileName, podYaml()).virtualFile - cut.extractFromFile(file) + cut.extractFromFileAndAddToCache(file) val images: Set = cut.getKubernetesWorkloadImages() assertEquals(1, images.size) @@ -192,7 +192,7 @@ class KubernetesImageCacheIntegTest : LightPlatform4TestCase() { fun `should remove file from cache when all images from file (cached before) been removed`() { val psiFile = createFile(fileName, podYaml()) val virtualFile = psiFile.virtualFile - cut.extractFromFile(virtualFile) + cut.extractFromFileAndAddToCache(virtualFile) val controlImages: Set = cut.getKubernetesWorkloadImages() assertEquals(1, controlImages.size) @@ -201,7 +201,7 @@ class KubernetesImageCacheIntegTest : LightPlatform4TestCase() { ?.setText("") } FileDocumentManager.getInstance().saveAllDocuments() - cut.extractFromFile(virtualFile) + cut.extractFromFileAndAddToCache(virtualFile) val images = cut.getKubernetesWorkloadImages() assertEquals(0, images.size) @@ -212,14 +212,14 @@ class KubernetesImageCacheIntegTest : LightPlatform4TestCase() { private fun executeExtract(yaml: String): Set { val file = createFile(fileName, yaml).virtualFile - cut.extractFromFile(file) + cut.extractFromFileAndAddToCache(file) return cut.getKubernetesWorkloadImageNamesFromCache() } @Test fun `extract images from Helm generated yaml with image names inside quotes`() { val file = createFile(fileName, helmYaml()).virtualFile - cut.extractFromFile(file) + cut.extractFromFileAndAddToCache(file) val images = cut.getKubernetesWorkloadImages() assertEquals(1, images.size) @@ -229,7 +229,7 @@ class KubernetesImageCacheIntegTest : LightPlatform4TestCase() { @Test fun `no images extracted from yaml with invalid image names`() { val file = createFile(fileName, singleQuoteImageNameBrokenYaml()).virtualFile - cut.extractFromFile(file) + cut.extractFromFileAndAddToCache(file) val images = cut.getKubernetesWorkloadImages() assertEquals(0, images.size) @@ -239,7 +239,7 @@ class KubernetesImageCacheIntegTest : LightPlatform4TestCase() { fun `distinct Kubernetes Workload Image Names for calling CLI`() { val file = createFile(fileName, duplicatedImageNameYaml()).virtualFile - cut.extractFromFile(file) + cut.extractFromFileAndAddToCache(file) val images: Set = cut.getKubernetesWorkloadImageNamesFromCache() assertEquals(1, images.size) @@ -250,7 +250,7 @@ class KubernetesImageCacheIntegTest : LightPlatform4TestCase() { fun `image Path followed by comment is extracted`() { val file = createFile(fileName, imagePathFollowedByCommentYaml()).virtualFile - cut.extractFromFile(file) + cut.extractFromFileAndAddToCache(file) val images: Set = cut.getKubernetesWorkloadImageNamesFromCache() assertEquals(1, images.size) @@ -261,7 +261,7 @@ class KubernetesImageCacheIntegTest : LightPlatform4TestCase() { fun `image Path commented is NOT extracted`() { val file = createFile(fileName, imagePathCommentedYaml()).virtualFile - cut.extractFromFile(file) + cut.extractFromFileAndAddToCache(file) val images: Set = cut.getKubernetesWorkloadImageNamesFromCache() assertEquals(0, images.size) @@ -271,7 +271,7 @@ class KubernetesImageCacheIntegTest : LightPlatform4TestCase() { fun `image Path with port and tag is extracted`() { val file = createFile(fileName, imagePathWithPortAndTagYaml()).virtualFile - cut.extractFromFile(file) + cut.extractFromFileAndAddToCache(file) val images: Set = cut.getKubernetesWorkloadImageNamesFromCache() assertEquals(1, images.size) @@ -282,7 +282,7 @@ class KubernetesImageCacheIntegTest : LightPlatform4TestCase() { fun `image Path with digest is extracted`() { val file = createFile(fileName, imagePathWithDigestYaml()).virtualFile - cut.extractFromFile(file) + cut.extractFromFileAndAddToCache(file) val images: Set = cut.getKubernetesWorkloadImageNamesFromCache() assertEquals(1, images.size)