public File findMatchingPom()

in maven-release-manager/src/main/java/org/apache/maven/shared/release/util/PomFinder.java [99:151]


    public File findMatchingPom(File startDirectory) {
        if (!startDirectory.exists()) {
            return null;
        }

        if (!startDirectory.isDirectory()) {
            log.error("PomFinder must be started with a directory! Got " + startDirectory.getAbsolutePath());
            return null;
        }

        if (foundPomInfo == null) {
            log.error("Please run parsePom first!");
            return null;
        }

        // look for the file in the current directory
        File matchingPom = new File(startDirectory, foundPomInfo.getFileName());
        if (matchingPom.exists()) {
            PomInfo pi = null;
            try {
                pi = readPomInfo(matchingPom);
            } catch (Exception e) {
                log.warn("Error while parsing pom file", e);
                // do nothing, just continue with the search
                // this might happen if a build contains unfinished pom.xml
                // files in integration tests, etc
            }

            if (pi == null || !pi.equals(foundPomInfo)) {
                matchingPom = null;
            }
        } else {
            matchingPom = null;
        }

        if (matchingPom == null) {
            String[] childFiles = startDirectory.list();
            if (childFiles != null) {
                for (String childFile : childFiles) {
                    File subDir = new File(startDirectory, childFile);
                    if (subDir.isDirectory() && !subDir.isHidden()) {
                        matchingPom = findMatchingPom(subDir);
                    }

                    if (matchingPom != null) {
                        break;
                    }
                }
            }
        }

        return matchingPom;
    }