RemoteRepository getDeploymentRepository()

in src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java [311:385]


    RemoteRepository getDeploymentRepository(boolean isSnapshot) throws MojoException {
        RemoteRepository repo = null;

        String altDeploymentRepo;
        if (isSnapshot && altSnapshotDeploymentRepository != null) {
            altDeploymentRepo = altSnapshotDeploymentRepository;
        } else if (!isSnapshot && altReleaseDeploymentRepository != null) {
            altDeploymentRepo = altReleaseDeploymentRepository;
        } else {
            altDeploymentRepo = altDeploymentRepository;
        }

        if (altDeploymentRepo != null) {
            getLog().info("Using alternate deployment repository " + altDeploymentRepo);

            Matcher matcher = ALT_LEGACY_REPO_SYNTAX_PATTERN.matcher(altDeploymentRepo);

            if (matcher.matches()) {
                String id = matcher.group(1).trim();
                String layout = matcher.group(2).trim();
                String url = matcher.group(3).trim();

                if ("default".equals(layout)) {
                    getLog().warn("Using legacy syntax for alternative repository. " + "Use \"" + id + "::" + url
                            + "\" instead.");
                    repo = createDeploymentArtifactRepository(id, url);
                } else {
                    throw new MojoException(
                            altDeploymentRepo,
                            "Invalid legacy syntax and layout for repository.",
                            "Invalid legacy syntax and layout for alternative repository. Use \"" + id + "::" + url
                                    + "\" instead, and only default layout is supported.");
                }
            } else {
                matcher = ALT_REPO_SYNTAX_PATTERN.matcher(altDeploymentRepo);

                if (!matcher.matches()) {
                    throw new MojoException(
                            altDeploymentRepo,
                            "Invalid syntax for repository.",
                            "Invalid syntax for alternative repository. Use \"id::url\".");
                } else {
                    String id = matcher.group(1).trim();
                    String url = matcher.group(2).trim();

                    repo = createDeploymentArtifactRepository(id, url);
                }
            }
        }

        if (repo == null) {
            DistributionManagement dm = project.getModel().getDistributionManagement();
            if (dm != null) {
                if (isSnapshot
                        && dm.getSnapshotRepository() != null
                        && isNotEmpty(dm.getSnapshotRepository().getId())
                        && isNotEmpty(dm.getSnapshotRepository().getUrl())) {
                    repo = session.createRemoteRepository(dm.getSnapshotRepository());
                } else if (dm.getRepository() != null
                        && isNotEmpty(dm.getRepository().getId())
                        && isNotEmpty(dm.getRepository().getUrl())) {
                    repo = session.createRemoteRepository(dm.getRepository());
                }
            }
        }

        if (repo == null) {
            String msg = "Deployment failed: repository element was not specified in the POM inside"
                    + " distributionManagement element or in -DaltDeploymentRepository=id::url parameter";

            throw new MojoException(msg);
        }

        return repo;
    }