Skip to content

Commit

Permalink
Prevent docker access when running AOT processing on tests
Browse files Browse the repository at this point in the history
Closes gh-37097
  • Loading branch information
mhalbritter committed Sep 5, 2023
1 parent 1a2919b commit d310fb6
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,21 @@ private <C extends Container<?>> ContainerConnectionSource<?> createSource(Field
field.getDeclaringClass().getName(), Container.class.getName()));
Class<C> containerType = (Class<C>) fieldValue.getClass();
C container = (C) fieldValue;
return new ContainerConnectionSource<>("test", origin, containerType, container.getDockerImageName(),
annotation, () -> container);
// container.getDockerImageName() fails if there is no running docker environment
// When running tests that doesn't matter, but running AOT processing should be
// possible without a Docker environment
String dockerImageName = isAotProcessingInProgress() ? null : container.getDockerImageName();
return new ContainerConnectionSource<>("test", origin, containerType, dockerImageName, annotation,
() -> container);
}

private Object getFieldValue(Field field) {
ReflectionUtils.makeAccessible(field);
return ReflectionUtils.getField(field, null);
}

private boolean isAotProcessingInProgress() {
return Boolean.getBoolean("spring.aot.processing");
}

}

0 comments on commit d310fb6

Please sign in to comment.