net.java.jpatch.maven.ReleaseInfoMojo.java Source code

Java tutorial

Introduction

Here is the source code for net.java.jpatch.maven.ReleaseInfoMojo.java

Source

/*
 * Copyright 2012 Andrej Petras <andrej@ajka-andrej.com>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.java.jpatch.maven;

import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import net.java.jpatch.maven.common.AbstractMavenMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;

/**
 * The release information.
 * 
 * @author Andrej Petras <andrej@ajka-andrej.com>
 * 
 * @goal release-info
 * @threadSafe 
 * @phase compile
 */
public class ReleaseInfoMojo extends AbstractMavenMojo {

    /**
     * Show information about the release package.
     * 
     * @throws MojoExecutionException if the method fails.
     * @throws MojoFailureException if the method fails.
     */
    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {

        // Setup the release artifact and open release properties file
        Properties releaseProperties = setupReleaseArtifact();

        // Creates temporary keys set.
        Set<Object> keys = new HashSet<Object>(releaseProperties.keySet());

        // Write information to the console
        getLog().info("Create:\t" + releaseProperties.getProperty(RELEASE_PROPERTY_DATE));
        keys.remove(RELEASE_PROPERTY_DATE);

        getLog().info("User:\t" + releaseProperties.getProperty(RELEASE_PROPERTY_USER_NAME));
        keys.remove(RELEASE_PROPERTY_USER_NAME);

        getLog().info("Java:\t" + releaseProperties.getProperty(RELEASE_PROPERTY_JAVA_VERSION));
        keys.remove(RELEASE_PROPERTY_JAVA_VERSION);

        getLog().info("Os:\t" + releaseProperties.getProperty(RELEASE_PROPERTY_OS_NAME));
        keys.remove(RELEASE_PROPERTY_OS_NAME);

        getLog().info("Projects");

        // Load projects
        List<MavenProject> mavenProjects = loadMavenProjects();

        // Filter the projects
        List<MavenProject> filterProjects = filterMavenProjects(mavenProjects, getPackages());

        // Show the list of projects
        for (MavenProject project : filterProjects) {
            keys.remove(project.getId());
            String revision = releaseProperties.getProperty(project.getId(), null);
            if (revision == null) {
                getLog().warn("Missing revision number for the project " + project.getId());
            } else {
                getLog().info(project.getId() + " r:" + revision);
            }
        }

        // Show list of missing keys.
        if (!keys.isEmpty()) {
            getLog().warn("To many keys in the release properties");
            for (Object key : keys) {
                getLog().warn(
                        "key:" + key + ",value:" + releaseProperties.getProperty(key.toString(), "").toString());
            }
        }
    }

}