zentol commented on a change in pull request #12484: URL: https://github.com/apache/flink/pull/12484#discussion_r436067756
########## File path: flink-end-to-end-tests/flink-end-to-end-tests-common/src/main/java/org/apache/flink/tests/util/flink/LocalStandaloneFlinkResourceFactory.java ########## @@ -33,19 +37,83 @@ public final class LocalStandaloneFlinkResourceFactory implements FlinkResourceFactory { private static final Logger LOG = LoggerFactory.getLogger(LocalStandaloneFlinkResourceFactory.class); + private static final ParameterProperty<Path> PROJECT_ROOT_DIRECTORY = new ParameterProperty<>("rootDir", Paths::get); private static final ParameterProperty<Path> DISTRIBUTION_DIRECTORY = new ParameterProperty<>("distDir", Paths::get); private static final ParameterProperty<Path> DISTRIBUTION_LOG_BACKUP_DIRECTORY = new ParameterProperty<>("logBackupDir", Paths::get); @Override public FlinkResource create(FlinkResourceSetup setup) { Optional<Path> distributionDirectory = DISTRIBUTION_DIRECTORY.get(); if (!distributionDirectory.isPresent()) { - throw new IllegalArgumentException("The distDir property was not set. You can set it when running maven via -DdistDir=<path> ."); + // distDir was not explicitly set, let's search for it + + Path projectRootPath; + Optional<Path> projectRoot = PROJECT_ROOT_DIRECTORY.get(); + if (projectRoot.isPresent()) { + // running with maven + projectRootPath = projectRoot.get(); + } else { + // running in the IDE; working directory is test module + Optional<Path> projectRootDirectory = findProjectRootDirectory(Paths.get("").toAbsolutePath()); + // this distinction is required in case this class is used outside of Flink + if (projectRootDirectory.isPresent()) { + projectRootPath = projectRootDirectory.get(); + } else { + throw new IllegalArgumentException( + "The 'distDir' property was not set and the flink-dist module could not be found automatically." + + " Please point the 'distDir' property to the directory containing distribution; you can set it when running maven via -DdistDir=<path> ."); + } + } + Optional<Path> distribution = findDistribution(projectRootPath); + if (!distribution.isPresent()) { + throw new IllegalArgumentException( + "The 'distDir' property was not set and a distribution could not be found automatically." + + " Please point the 'distDir' property to the directory containing distribution; you can set it when running maven via -DdistDir=<path> ."); + } else { + distributionDirectory = distribution; + } } Optional<Path> logBackupDirectory = DISTRIBUTION_LOG_BACKUP_DIRECTORY.get(); if (!logBackupDirectory.isPresent()) { LOG.warn("Property {} not set, logs will not be backed up in case of test failures.", DISTRIBUTION_LOG_BACKUP_DIRECTORY.getPropertyName()); } return new LocalStandaloneFlinkResource(distributionDirectory.get(), logBackupDirectory.orElse(null), setup); } + + public static void main(String[] args) { + System.out.println(findProjectRootDirectory(Paths.get("").toAbsolutePath())); + } Review comment: whoops, ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org