refactor(dart): Using requirements for applicable and extractable.
package com.synopsys.integration.detectable.detectables.dart.pubspec;
import java.io.File;
-import java.util.Optional;
+import java.io.IOException;
+
+import org.jetbrains.annotations.Nullable;
import com.synopsys.integration.common.util.finder.FileFinder;
import com.synopsys.integration.detectable.Detectable;
@@ -11,8 +13,6 @@ import com.synopsys.integration.detectable.detectable.annotation.DetectableInfo;
import com.synopsys.integration.detectable.detectable.exception.DetectableException;
import com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException;
import com.synopsys.integration.detectable.detectable.result.DetectableResult;
-import com.synopsys.integration.detectable.detectable.result.FileNotFoundDetectableResult;
-import com.synopsys.integration.detectable.detectable.result.FilesNotFoundDetectableResult;
import com.synopsys.integration.detectable.detectable.result.PassedDetectableResult;
import com.synopsys.integration.detectable.detectable.result.PubSpecLockNotFoundDetectableResult;
import com.synopsys.integration.detectable.extraction.Extraction;
@@ -25,10 +25,11 @@ public class DartPubSpecLockDetectable extends Detectable {
private final FileFinder fileFinder;
- private Optional<File> pubspecYaml;
- private Optional<File> pubspecLock;
+ @Nullable
+ private File pubspecYaml;
+ private File pubspecLock;
- private PubSpecExtractor pubSpecExtractor;
+ private final PubSpecExtractor pubSpecExtractor;
public DartPubSpecLockDetectable(DetectableEnvironment environment, FileFinder fileFinder, PubSpecExtractor pubSpecExtractor) {
super(environment);
@@ -39,32 +40,20 @@ public class DartPubSpecLockDetectable extends Detectable {
@Override
public DetectableResult applicable() {
Requirements requirements = new Requirements(fileFinder, environment);
-
- pubspecYaml = requirements.optionalFile(PUBSPEC_YAML_FILENAME);
- pubspecLock = requirements.optionalFile(PUBSPEC_LOCK_FILENAME);
-
- if (pubspecYaml.isPresent() || pubspecLock.isPresent()) {
+ requirements.eitherFile(PUBSPEC_YAML_FILENAME, PUBSPEC_LOCK_FILENAME, yaml -> pubspecYaml = yaml, lock -> pubspecLock = lock);
return requirements.result();
- } else {
- return new FilesNotFoundDetectableResult(PUBSPEC_LOCK_FILENAME, PUBSPEC_YAML_FILENAME);
- }
}
@Override
public DetectableResult extractable() throws DetectableException {
- if (pubspecLock.isPresent() && pubspecYaml.isPresent()) {
- return new PassedDetectableResult();
- } else if (!pubspecLock.isPresent()) {
+ if (pubspecLock == null) {
return new PubSpecLockNotFoundDetectableResult(environment.getDirectory().getAbsolutePath());
- } else {
- return new FileNotFoundDetectableResult(PUBSPEC_YAML_FILENAME);
}
-
+ return new PassedDetectableResult();
}
@Override
- public Extraction extract(ExtractionEnvironment extractionEnvironment) throws ExecutableFailedException {
- // pubspec.yaml cannot be null - ac 9/8/21
- return pubSpecExtractor.extract(pubspecLock.orElse(null), pubspecYaml.orElse(null));
+ public Extraction extract(ExtractionEnvironment extractionEnvironment) throws ExecutableFailedException, IOException {
+ return pubSpecExtractor.extract(pubspecLock, pubspecYaml);
}
}
