@SuppressWarnings({"unchecked"})
  private <T> ContainerBuildPlan runPluginExtension(
      Optional<Class<T>> extraConfigType,
      JibGradlePluginExtension<?> extension,
      ExtensionConfiguration config,
      ContainerBuildPlan buildPlan)
      throws JibPluginExtensionException {
    T extraConfig = null;
    Optional<Object> configs = config.getExtraConfiguration();
    if (configs.isPresent()) {
      if (!extraConfigType.isPresent()) {
        throw new IllegalArgumentException(
            "extension "
                + extension.getClass().getSimpleName()
                + " does not expect extension-specific configuration; remove the inapplicable "
                + "'pluginExtension.configuration' from Gradle build script");
      } else {
        // configs.get() is of type Action, so this cast always succeeds.
        // (Note generic <T> is erased at runtime.)
        Action<T> action = (Action<T>) configs.get();
        extraConfig = project.getObjects().newInstance(extraConfigType.get(), project);
        action.execute(extraConfig);
      }
    }

    try {
      return ((JibGradlePluginExtension<T>) extension)
          .extendContainerBuildPlan(
              buildPlan,
              config.getProperties(),
              Optional.ofNullable(extraConfig),
              () -> project,
              new PluginExtensionLogger(this::log));
    } catch (RuntimeException ex) {
      throw new JibPluginExtensionException(
          extension.getClass(), "extension crashed: " + ex.getMessage(), ex);
    }
  }
Returns the input files for a task. These files include the gradle {@link
org.gradle.api.artifacts.Configuration}, output directories (classes, resources, etc.) of the
main {@link org.gradle.api.tasks.SourceSet}, and any extraDirectories defined by the user to
include in the container.

@param project the gradle project
@param extraDirectories the image's configured extra directories
@return the input files
jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleProjectProperties.java