protected static File getJoinedFolder()

in src/main/java/org/apache/maven/shared/project/utils/ProjectUtils.java [275:308]


    protected static File getJoinedFolder( File lhs, File rhs )
    {
        File joinedFolder = null;

        Stack<File> lhsStack = new Stack<File>();

        File lhsAncestor = lhs;

        while ( lhsAncestor != null )
        {
            lhsAncestor = lhsStack.push( lhsAncestor ).getParentFile();
        }

        Stack<File> rhsStack = new Stack<File>();

        File rhsAncestor = rhs;

        while ( rhsAncestor != null )
        {
            rhsAncestor = rhsStack.push( rhsAncestor ).getParentFile();
        }

        while ( !lhsStack.isEmpty() && !rhsStack.isEmpty() )
        {
            File nextFile = lhsStack.pop();

            if ( nextFile.isDirectory() && nextFile.equals( rhsStack.pop() ) )
            {
                joinedFolder = nextFile;
            }
        }

        return joinedFolder;
    }