public Gav pathToGav()

in indexer-core/src/main/java/org/apache/maven/index/artifact/M2GavCalculator.java [36:127]


    public Gav pathToGav(String str) {
        try {
            String s = str.startsWith("/") ? str.substring(1) : str;

            int vEndPos = s.lastIndexOf('/');

            if (vEndPos == -1) {
                return null;
            }

            int aEndPos = s.lastIndexOf('/', vEndPos - 1);

            if (aEndPos == -1) {
                return null;
            }

            int gEndPos = s.lastIndexOf('/', aEndPos - 1);

            if (gEndPos == -1) {
                return null;
            }

            String groupId = s.substring(0, gEndPos).replace('/', '.');
            String artifactId = s.substring(gEndPos + 1, aEndPos);
            String version = s.substring(aEndPos + 1, vEndPos);
            String fileName = s.substring(vEndPos + 1);

            boolean checksum = false;
            boolean signature = false;
            Gav.HashType checksumType = null;
            Gav.SignatureType signatureType = null;
            if (s.endsWith(".md5")) {
                checksum = true;
                checksumType = Gav.HashType.md5;
                s = s.substring(0, s.length() - 4);
            } else if (s.endsWith(".sha1")) {
                checksum = true;
                checksumType = Gav.HashType.sha1;
                s = s.substring(0, s.length() - 5);
            } else if (s.endsWith(".sha256")) {
                checksum = true;
                checksumType = Gav.HashType.sha256;
                s = s.substring(0, s.length() - 7);
            } else if (s.endsWith(".sha512")) {
                checksum = true;
                checksumType = Gav.HashType.sha512;
                s = s.substring(0, s.length() - 7);
            }

            if (s.endsWith(".asc")) {
                signature = true;
                signatureType = Gav.SignatureType.gpg;
                s = s.substring(0, s.length() - 4);
            }

            if (s.endsWith("maven-metadata.xml")
                    || (fileName.startsWith("maven-metadata-") && fileName.contains(".xml"))
                    || (fileName.startsWith("_") && fileName.endsWith(".repositories"))) {
                return null;
            }

            boolean snapshot = version.endsWith("SNAPSHOT");

            if (snapshot) {
                return getSnapshotGav(
                        s,
                        vEndPos,
                        groupId,
                        artifactId,
                        version,
                        fileName,
                        checksum,
                        signature,
                        checksumType,
                        signatureType);
            } else {
                return getReleaseGav(
                        s,
                        vEndPos,
                        groupId,
                        artifactId,
                        version,
                        fileName,
                        checksum,
                        signature,
                        checksumType,
                        signatureType);
            }
        } catch (NumberFormatException | StringIndexOutOfBoundsException e) {
            return null;
        }
    }