import re


def getJUnitVersion(commandsList):
    """ Find the junit version

    Parameters
    ----------
    commandsList : list of str
        A list of the parts of a command for running junit

    Returns
    -------
    None, int, or str
        Returns None if it cannot find the string junit in the classpath string
        Returns -1 if it cannot find a string of the format `junit-\d+\.\d+`
        Returns a str of the major junit verison

    """
    if any(c.startswith("-classpath") or c.startswith("-cp") for c in commandsList):
        classpaths = [c for c in commandsList if c.startswith("-classpath") or c.startswith("-cp")]
        if len(classpaths) == 1:
            splits = classpaths[0].split(" ")
            if len(splits) == 2:
                cp = splits[1].split(":")
                if any(p.find("junit") >= 0 for p in cp):
                    junitPaths = [p for p in cp if p.find("junit") >= 0]
                    match = [re.search(r"junit-(\d+\.\d+)", p) for p in junitPaths]
                    match = [m for m in match if m]
                    match = [int(re.sub(r"(\d+).\d+", r"\1", m.group(1))) for m in match]
                    matchset = set(match)
                    if len(matchset) == 1:
                        return list(match)[0]
                    return -1