org.apache.maven.model.building.ModelProcessor Java Examples

The following examples show how to use org.apache.maven.model.building.ModelProcessor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GitVersioningModelProcessor.java    From maven-git-versioning-extension with MIT License 4 votes vote down vote up
public Model processModel(Model projectModel, Map<String, ?> options) throws IOException {
    if (this.disabled) {
        return projectModel;
    }

    final Source pomSource = (Source) options.get(ModelProcessor.SOURCE);
    if (pomSource != null) {
        projectModel.setPomFile(new File(pomSource.getLocation()));
    }

    try {
        if (!initialized) {
            logger.info("");
            String extensionId = BuildProperties.projectArtifactId() + ":" + BuildProperties.projectVersion();
            logger.info(extensionLogFormat(extensionId));

            try {
                mavenSession = sessionScope.scope(Key.get(MavenSession.class), null).get();
            } catch (OutOfScopeException ex) {
                logger.warn("skip - no maven session present");
                disabled = true;
                return projectModel;
            }

            if (parseBoolean(getCommandOption(OPTION_NAME_DISABLE))) {
                logger.info("skip - versioning is disabled");
                disabled = true;
                return projectModel;
            }

            File executionRootDirectory = new File(mavenSession.getRequest().getBaseDirectory());
            logger.debug("executionRootDirectory: " + executionRootDirectory.toString());

            mvnDirectory = findMvnDirectory(executionRootDirectory);
            logger.debug("mvnDirectory: " + mvnDirectory.toString());

            String configFileName = BuildProperties.projectArtifactId() + ".xml";
            File configFile = new File(mvnDirectory, configFileName);
            logger.debug("configFile: " + configFile.toString());
            config = loadConfig(configFile);

            gitDirectory = findGitDir(executionRootDirectory);
            if (gitDirectory == null || !gitDirectory.exists()) {
                logger.warn("skip - project is not part of a git repository");
                disabled = true;
                return projectModel;
            }

            logger.debug("gitDirectory: " + gitDirectory.toString());

            gitVersionDetails = getGitVersionDetails(config, executionRootDirectory);

            logger.info("Adjusting project models...");
            logger.info("");
            initialized = true;
        }

        return processModel(projectModel);
    } catch (Exception e) {
        throw new IOException("Git Versioning Model Processor", e);
    }
}