src/main/java/ru/tohasan/App.java
/**
     * Method finds dependent modules on specified module in arguments.
     *
     * @param directoryName Full path to directory where need to find dependent modules.
     * @param dependencyName Module name (artifact id) of direct or indirect dependency of modules.
     * @param onlyModulesFromFile Path to file contains module names to search dependency among them.
     * @return Returns set of modules (exclude duplicates) dependent on specified artifact.
     */
Method finds dependent modules on specified module in arguments.
@param directoryName Full path to directory where need to find dependent modules.
@param dependencyName Module name (artifact id) of direct or indirect dependency of modules.
@param onlyModulesFromFile Path to file contains module names to search dependency among them.
@return Returns set of modules (exclude duplicates) dependent on specified artifact.
Method finds dependent modules on specified module in arguments . @param directoryName Full path to directory where need to find dependent modules . @param dependencyName Module name ( artifact id ) of direct or indirect dependency of modules . @param onlyModulesFromFile Path to file contains module names to search dependency among them . @return Returns set of modules ( exclude duplicates ) dependent on specified artifact .
private Set<File> findDependent(String directoryName, String dependencyName, String onlyModulesFromFile) {
        File dir = new File(directoryName);
        Collection<File> files = FileUtils.listFiles(
                dir,
                FileFilterUtils.nameFileFilter(POM_XML_PATTERN),
                TrueFileFilter.INSTANCE
        );
        List<String> onlyModules = new ArrayList<>();
        try {
             onlyModules = FileUtils.readLines(new File(onlyModulesFromFile));
        } catch (IOException e) {
            LOGGER.error("Error: {}", e);
        }
        DependencyFinder dependencyFinder = new DependencyFinder();
        Set<File> dependentFiles = dependencyFinder.findDependent(files, dependencyName, onlyModules);
        if (!dependentFiles.isEmpty()) {
            print(String.format("Dependents on %s:", dependencyName));
            List<String> moduleNames = new ArrayList<>();
            for (File dependentFile : dependentFiles) {
                moduleNames.add(String.format(
                        "    Module: %s [%s]",
                        dependencyFinder.getModuleName(dependentFile),
                        dependentFile.getAbsolutePath()
                ));
            }
            moduleNames.sort(Comparator.<String>naturalOrder());
            moduleNames.forEach(this::print);
        } else {
            print("There are no dependent modules on " + dependencyName);
        }
        print();
        print(String.format("Total count of processed files: %d", files.size()));
        return dependentFiles;
    }
private Set < File > findDependent ( String directoryName , String dependencyName , String onlyModulesFromFile ) { File dir = new File ( directoryName ) ; Collection < File > files = FileUtils . listFiles ( dir , FileFilterUtils . nameFileFilter ( POM_XML_PATTERN ) , TrueFileFilter . INSTANCE ) ; List < String > onlyModules = new ArrayList < > ( ) ; try { onlyModules = FileUtils . readLines ( new File ( onlyModulesFromFile ) ) ; } catch ( IOException e ) { LOGGER . error ( "Error: {}" , e ) ; } DependencyFinder dependencyFinder = new DependencyFinder ( ) ; Set < File > dependentFiles = dependencyFinder . findDependent ( files , dependencyName , onlyModules ) ; if ( ! dependentFiles . isEmpty ( ) ) { print ( String . format ( "Dependents on %s:" , dependencyName ) ) ; List < String > moduleNames = new ArrayList < > ( ) ; for ( File dependentFile : dependentFiles ) { moduleNames . add ( String . format ( "    Module: %s [%s]" , dependencyFinder . getModuleName ( dependentFile ) , dependentFile . getAbsolutePath ( ) ) ) ; } moduleNames . sort ( Comparator . < String > naturalOrder ( ) ) ; moduleNames . forEach ( this :: print ) ; } else { print ( "There are no dependent modules on " + dependencyName ) ; } print ( ) ; print ( String . format ( "Total count of processed files: %d" , files . size ( ) ) ) ; return dependentFiles ; }
Method finds dependent modules on specified module in arguments.
Method finds dependent modules on specified module in arguments .
// Find all pom.xml files // Calculate module name for each dependent module // Sort module names in natural order // Display names of dependent modules