Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.*;
import java.util.concurrent.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.VisibleForTesting;
import org.slf4j.Logger;
Expand Down Expand Up @@ -184,7 +185,14 @@ public CodeTFResult execute(final List<Path> filePaths) {
Collection<DependencyGAV> deps =
projectProviders.stream()
.flatMap(
provider -> provider.getAllDependencies(projectDir, filePath).stream())
provider -> {
try {
return provider.getAllDependencies(projectDir, filePath).stream();
} catch (Exception e) {
log.error("Problem getting dependencies for file {}", filePath, e);
return Stream.empty();
}
})
.toList();

CodemodInvocationContext context =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public DependencyUpdateResult updateDependencies(
}

@Override
public Collection<DependencyGAV> getAllDependencies(Path projectDir, Path file) {
public Collection<DependencyGAV> getAllDependencies(final Path projectDir, final Path file) {
return List.of();
}
}
Expand All @@ -158,7 +158,41 @@ void it_generates_single_codemod_codetf() {

// should have just 1 entry because we only scanned javaFile1
List<CodeTFChangesetEntry> changeset = result.getChangeset();
assertThat(changeset.size()).isEqualTo(1);
assertThat(changeset).hasSize(1);
assertThat(changeset.get(0)).satisfies(DefaultCodemodExecutorTest::isJavaFile1ChangedCorrectly);
}

@Test
void it_works_despite_fail_prefetching_all_deps() {
FakeDepsProvider depsProvider =
new FakeDepsProvider() {
@Override
public Collection<DependencyGAV> getAllDependencies(
final Path projectDir, final Path file) {
throw new RuntimeException("failed to prefetch deps");
}
};

executor =
new DefaultCodemodExecutor(
repoDir,
includesEverything,
beforeAfterCodemod,
List.of(depsProvider),
List.of(),
fileCache,
javaParserFacade,
encodingDetector,
-1,
-1,
-1);

CodeTFResult result = executor.execute(List.of(javaFile1));
assertThat(result).satisfies(DefaultCodemodExecutorTest::hasBeforeAfterCodemodMetadata);

// should have just 1 entry because we only scanned javaFile1
List<CodeTFChangesetEntry> changeset = result.getChangeset();
assertThat(changeset).hasSize(1);
assertThat(changeset.get(0)).satisfies(DefaultCodemodExecutorTest::isJavaFile1ChangedCorrectly);
}

Expand Down Expand Up @@ -241,7 +275,7 @@ public CodeTFChange onChangeCreated(

// confirm the change was updated by the provider
List<CodeTFChangesetEntry> changeset = result.getChangeset();
assertThat(changeset.size()).isEqualTo(1);
assertThat(changeset).hasSize(1);
CodeTFChangesetEntry entry = changeset.get(0);
assertThat(entry.getChanges().get(0).getDescription()).isEqualTo("hi " + javaFile1.toString());
assertThat(entry.getChanges().get(0).getProperties()).hasSize(1);
Expand All @@ -256,7 +290,7 @@ void it_generates_all_files_codemod_codetf() {

// should have 2 entries for both javaFile1 and javaFile3
List<CodeTFChangesetEntry> changeset = result.getChangeset();
assertThat(changeset.size()).isEqualTo(2);
assertThat(changeset).hasSize(2);
assertThat(changeset.get(0)).satisfies(DefaultCodemodExecutorTest::isJavaFile1ChangedCorrectly);
assertThat(changeset.get(1)).satisfies(DefaultCodemodExecutorTest::isJavaFile3ChangedCorrectly);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ public Collection<DependencyGAV> getAllDependencies(final Path projectDir, final

return pomOperator.getAllFoundDependencies();
} catch (Exception e) {
throw new DependencyUpdateException("Failure when retrieving dependencies", e);
LOG.warn("Not all Maven dependencies could be found", e);
}
return Collections.emptyList();
}

private static final Logger LOG = LoggerFactory.getLogger(MavenProvider.class);
Expand Down
Loading