-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: extract ecosystem enum [OSM-2231]
Adding new ecosystem support in small steps because the diff for the original work is too massive. First baby step = introducing the Ecosystem enum and extracting the file matching logic to it.
- Loading branch information
1 parent
4adb712
commit 00d2a7b
Showing
4 changed files
with
68 additions
and
41 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
core/src/main/java/io/snyk/plugins/artifactory/scanner/Ecosystem.java
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,39 @@ | ||
package io.snyk.plugins.artifactory.scanner; | ||
|
||
import io.snyk.plugins.artifactory.configuration.PluginConfiguration; | ||
|
||
import java.util.Optional; | ||
|
||
public enum Ecosystem { | ||
|
||
MAVEN(PluginConfiguration.SCANNER_PACKAGE_TYPE_MAVEN), | ||
NPM(PluginConfiguration.SCANNER_PACKAGE_TYPE_NPM), | ||
PYPI(PluginConfiguration.SCANNER_PACKAGE_TYPE_PYPI), | ||
; | ||
|
||
private final PluginConfiguration configProperty; | ||
|
||
Ecosystem(PluginConfiguration configProperty) { | ||
this.configProperty = configProperty; | ||
} | ||
|
||
public PluginConfiguration getConfigProperty() { | ||
return configProperty; | ||
} | ||
|
||
static Optional<Ecosystem> fromPackagePath(String path) { | ||
if (path.endsWith(".jar")) { | ||
return Optional.of(MAVEN); | ||
} | ||
|
||
if (path.endsWith(".tgz")) { | ||
return Optional.of(NPM); | ||
} | ||
|
||
if (path.endsWith(".whl") || path.endsWith(".tar.gz") || path.endsWith(".zip") || path.endsWith(".egg")) { | ||
return Optional.of(PYPI); | ||
} | ||
|
||
return Optional.empty(); | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
core/src/test/java/io/snyk/plugins/artifactory/scanner/EcosystemTest.java
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,19 @@ | ||
package io.snyk.plugins.artifactory.scanner; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class EcosystemTest { | ||
|
||
@Test | ||
void testGetScannerForPackageType() { | ||
assertEquals(Ecosystem.MAVEN, Ecosystem.fromPackagePath("myArtifact.jar").orElse(null)); | ||
assertEquals(Ecosystem.NPM, Ecosystem.fromPackagePath("myArtifact.tgz").orElse(null)); | ||
assertEquals(Ecosystem.PYPI, Ecosystem.fromPackagePath("myArtifact.whl").orElse(null)); | ||
assertEquals(Ecosystem.PYPI, Ecosystem.fromPackagePath("myArtifact.tar.gz").orElse(null)); | ||
assertEquals(Ecosystem.PYPI, Ecosystem.fromPackagePath("myArtifact.zip").orElse(null)); | ||
assertEquals(Ecosystem.PYPI, Ecosystem.fromPackagePath("myArtifact.egg").orElse(null)); | ||
assertNull(Ecosystem.fromPackagePath("file.txt").orElse(null)); | ||
} | ||
} |
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