public void execute()

in src/main/java/org/apache/maven/plugins/install/InstallFileMojo.java [153:261]


    public void execute() {
        if (!Files.exists(file)) {
            String message = "The specified file '" + file + "' does not exist";
            log.error(message);
            throw new MojoException(message);
        }

        Session session = this.session;

        List<ProducedArtifact> installableArtifacts = new ArrayList<>();

        // Override the default local repository
        if (localRepositoryPath != null) {
            session = session.withLocalRepository(session.createLocalRepository(localRepositoryPath));

            log.debug("localRepoPath: " + localRepositoryPath);
        }

        Path deployedPom;
        Path temporaryPom = null;
        if (pomFile != null) {
            deployedPom = pomFile;
            processModel(readModel(deployedPom));
        } else {
            if (!Boolean.TRUE.equals(generatePom)) {
                temporaryPom = readingPomFromJarFile();
                deployedPom = temporaryPom;
                if (deployedPom != null) {
                    log.debug("Using JAR embedded POM as pomFile");
                }
            } else {
                deployedPom = null;
            }
        }

        if (groupId == null || artifactId == null || version == null || packaging == null) {
            throw new MojoException("The artifact information is incomplete: 'groupId', 'artifactId', "
                    + "'version' and 'packaging' are required.");
        }

        if (!isValidId(groupId) || !isValidId(artifactId) || !isValidVersion(version)) {
            throw new MojoException("The artifact information is not valid: uses invalid characters.");
        }

        boolean isFilePom = classifier == null && "pom".equals(packaging);
        ProducedArtifact artifact = session.createProducedArtifact(
                groupId, artifactId, version, classifier, isFilePom ? "pom" : getExtension(file), packaging);

        if (file.equals(getLocalRepositoryFile(artifact))) {
            throw new MojoException("Cannot install artifact. "
                    + "Artifact is already in the local repository.\n\nFile in question is: " + file + "\n");
        }

        ArtifactManager artifactManager = session.getService(ArtifactManager.class);
        artifactManager.setPath(artifact, file);
        installableArtifacts.add(artifact);

        ProducedArtifact pomArtifact = null;
        if (!isFilePom) {
            pomArtifact = session.createProducedArtifact(groupId, artifactId, version, null, "pom", null);
            if (deployedPom != null) {
                artifactManager.setPath(pomArtifact, deployedPom);
                installableArtifacts.add(pomArtifact);
            } else {
                temporaryPom = generatePomFile();
                deployedPom = temporaryPom;
                artifactManager.setPath(pomArtifact, deployedPom);
                if (Boolean.TRUE.equals(generatePom)
                        || (generatePom == null && !Files.exists(getLocalRepositoryFile(pomArtifact)))) {
                    log.debug("Installing generated POM");
                    installableArtifacts.add(pomArtifact);
                } else if (generatePom == null) {
                    log.debug("Skipping installation of generated POM, already present in local repository");
                }
            }
        }

        if (sources != null) {
            ProducedArtifact sourcesArtifact =
                    session.createProducedArtifact(groupId, artifactId, version, "sources", "jar", null);
            artifactManager.setPath(sourcesArtifact, sources);
            installableArtifacts.add(sourcesArtifact);
        }

        if (javadoc != null) {
            ProducedArtifact javadocArtifact =
                    session.createProducedArtifact(groupId, artifactId, version, "javadoc", "jar", null);
            artifactManager.setPath(javadocArtifact, javadoc);
            installableArtifacts.add(javadocArtifact);
        }

        try {
            ArtifactInstaller artifactInstaller = session.getService(ArtifactInstaller.class);
            artifactInstaller.install(session, installableArtifacts);
        } catch (ArtifactInstallerException e) {
            throw new MojoException(e.getMessage(), e);
        } finally {
            if (temporaryPom != null) {
                try {
                    Files.deleteIfExists(temporaryPom);
                } catch (IOException e) {
                    // ignore
                }
                if (pomArtifact != null) {
                    artifactManager.setPath(pomArtifact, null);
                }
            }
        }
    }