protected void doExecute()

in src/main/java/org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java [236:371]


    protected void doExecute() throws MojoExecutionException, MojoFailureException {
        if (settings.isOffline()) {
            throw new MojoFailureException("Cannot deploy artifacts when Maven is in offline mode");
        }

        initProperties();

        validateArtifactInformation();

        if (!file.exists()) {
            throw new MojoFailureException(file.getPath() + " not found.");
        }

        // create artifacts
        List<Artifact> artifacts = new ArrayList<>();

        // main artifact
        ArtifactHandler handler = artifactHandlerManager.getArtifactHandler(packaging);
        Artifact main = new DefaultArtifact(
                        groupId,
                        artifactId,
                        classifier == null || classifier.trim().isEmpty() ? handler.getClassifier() : classifier,
                        handler.getExtension(),
                        version)
                .setFile(file);

        File localRepoFile = new File(
                session.getRepositorySession().getLocalRepository().getBasedir(),
                session.getRepositorySession().getLocalRepositoryManager().getPathForLocalArtifact(main));
        if (file.equals(localRepoFile)) {
            throw new MojoFailureException("Cannot deploy artifact from the local repository: " + file);
        }
        artifacts.add(main);

        if (!"pom".equals(packaging)) {
            if (pomFile == null && generatePom) {
                pomFile = generatePomFile();
            }
            if (pomFile != null) {
                artifacts.add(
                        new DefaultArtifact(main.getGroupId(), main.getArtifactId(), null, "pom", main.getVersion())
                                .setFile(pomFile));
            }
        }

        if (sources != null) {
            artifacts.add(
                    new DefaultArtifact(main.getGroupId(), main.getArtifactId(), "sources", "jar", main.getVersion())
                            .setFile(sources));
        }

        if (javadoc != null) {
            artifacts.add(
                    new DefaultArtifact(main.getGroupId(), main.getArtifactId(), "javadoc", "jar", main.getVersion())
                            .setFile(javadoc));
        }

        if (files != null) {
            if (types == null) {
                throw new MojoExecutionException("You must specify 'types' if you specify 'files'");
            }
            if (classifiers == null) {
                throw new MojoExecutionException("You must specify 'classifiers' if you specify 'files'");
            }
            String[] files = this.files.split(",", -1);
            String[] types = this.types.split(",", -1);
            String[] classifiers = this.classifiers.split(",", -1);
            if (types.length != files.length) {
                throw new MojoExecutionException("You must specify the same number of entries in 'files' and "
                        + "'types' (respectively " + files.length + " and " + types.length + " entries )");
            }
            if (classifiers.length != files.length) {
                throw new MojoExecutionException("You must specify the same number of entries in 'files' and "
                        + "'classifiers' (respectively " + files.length + " and " + classifiers.length + " entries )");
            }
            for (int i = 0; i < files.length; i++) {
                File file = new File(files[i]);
                if (!file.isFile()) {
                    // try relative to the project basedir just in case
                    file = new File(project.getBasedir(), files[i]);
                }
                if (file.isFile()) {
                    Artifact artifact;
                    String ext =
                            artifactHandlerManager.getArtifactHandler(types[i]).getExtension();
                    if (StringUtils.isWhitespace(classifiers[i])) {
                        artifact = new DefaultArtifact(
                                main.getGroupId(), main.getArtifactId(), null, ext, main.getVersion());
                    } else {
                        artifact = new DefaultArtifact(
                                main.getGroupId(), main.getArtifactId(), classifiers[i], ext, main.getVersion());
                    }
                    artifacts.add(artifact.setFile(file));
                } else {
                    throw new MojoExecutionException("Specified side artifact " + file + " does not exist");
                }
            }
        } else {
            if (types != null) {
                throw new MojoExecutionException("You must specify 'files' if you specify 'types'");
            }
            if (classifiers != null) {
                throw new MojoExecutionException("You must specify 'files' if you specify 'classifiers'");
            }
        }

        // sign all
        AbstractGpgSigner signer = newSigner(null);
        signer.setOutputDirectory(ascDirectory);
        signer.setBaseDirectory(new File("").getAbsoluteFile());

        getLog().info("Signer '" + signer.signerName() + "' is signing " + artifacts.size() + " file"
                + ((artifacts.size() > 1) ? "s" : "") + " with key " + signer.getKeyInfo());

        ArrayList<Artifact> signatures = new ArrayList<>();
        for (Artifact a : artifacts) {
            signatures.add(new DefaultArtifact(
                            a.getGroupId(),
                            a.getArtifactId(),
                            a.getClassifier(),
                            a.getExtension() + AbstractGpgSigner.SIGNATURE_EXTENSION,
                            a.getVersion())
                    .setFile(signer.generateSignatureForArtifact(a.getFile())));
        }
        artifacts.addAll(signatures);

        // deploy all
        RemoteRepository deploymentRepository = repositorySystem.newDeploymentRepository(
                session.getRepositorySession(), new RemoteRepository.Builder(repositoryId, "default", url).build());
        try {
            deploy(deploymentRepository, artifacts);
        } catch (DeploymentException e) {
            throw new MojoExecutionException(
                    "Error deploying attached artifacts " + artifacts + ": " + e.getMessage(), e);
        }
    }