All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.wisdom.maven.mojos.AbstractWisdomMojo Maven / Gradle / Ivy

There is a newer version: 0.10.0
Show newest version
/*
 * #%L
 * Wisdom-Framework
 * %%
 * Copyright (C) 2013 - 2014 Wisdom Framework
 * %%
 * 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.
 * #L%
 */
package org.wisdom.maven.mojos;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.BuildPluginManager;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;
import org.wisdom.maven.Constants;
import org.wisdom.maven.node.NodeManager;

import java.io.File;
import java.util.List;

/**
 * Shared logic, fields and methods between all Wisdom Mojos.
 */
public abstract class AbstractWisdomMojo extends AbstractMojo {

    /**
     * The maven project.
     */
    @Parameter(defaultValue = "${project}", readonly = true)
    public MavenProject project;

    /**
     * The project base directory.
     */
    @Parameter(defaultValue = "${basedir}", required = true, readonly = true)
    public File basedir;
    /**
     * The target directory of the project.
     */
    @Parameter(defaultValue = "${project.build.directory}", required = true, readonly = true)
    public File buildDirectory;

    /**
     * The current build session instance.
     */
    @Component
    public MavenSession session;

    /**
     * Maven ProjectHelper.
     */
    @Component
    public MavenProjectHelper projectHelper;

    /**
     * The plugin dependencies.
     */
    @Parameter(defaultValue = "${plugin.artifacts}")
    public List pluginDependencies;

    /**
     * The plugin.
     */
    @Parameter(defaultValue = "${plugin}")
    public PluginDescriptor plugin;

    /**
     * The Maven BuildPluginManager component.
     */
    @Component
    public BuildPluginManager pluginManager;

    /**
     * The repository system.
     */
    @Component
    public RepositorySystem repoSystem;

    /**
     * The session to access the repository system.
     */
    @Parameter(defaultValue = "${repositorySystemSession}", readonly = true)
    public RepositorySystemSession repoSession;

    /**
     * The list of remote repositories.
     */
    @Parameter(defaultValue = "${project.remoteProjectRepositories}", readonly = true)
    public List remoteRepos;

    /**
     * Indicates the location of the Wisdom directory to use. Generated artifacts (Bundles,
     * templates...) are copied to this directory.
     */
    @Parameter(defaultValue = "${wisdomDirectory}")
    public File wisdomDirectory;

    /**
     * Gets the root directory of the Wisdom server. Generally it's 'target/wisdom' except if the
     * {@link #wisdomDirectory} parameter is configured. In this case,
     * it returns the location specified by this parameter.
     *
     * @return the Wisdom's root.
     */
    public File getWisdomRootDirectory() {
        File wisdom;
        if (wisdomDirectory == null) {
            wisdom = new File(buildDirectory, Constants.WISDOM_DIRECTORY_NAME);
        } else {
            this.getLog().debug("Using Wisdom Directory : " + wisdomDirectory.getAbsolutePath());
            wisdom = wisdomDirectory;
        }

        if (wisdom.mkdirs()) {
            this.getLog().debug(wisdom.getAbsolutePath() + " directory created.");
        }
        return wisdom;
    }

    /**
     * The JAVA_HOME value.
     */
    @Parameter(defaultValue = "${java.home}", required = true, readonly = true)
    public File javaHome;


    /**
     * The Node manager.
     */
    private NodeManager node = new NodeManager(this);

    /**
     * @return the node manager.
     */
    public NodeManager getNodeManager() {
        return node;
    }

    /**
     * Sets the node manager. For testing purpose only.
     */
    public void setNodeManager(NodeManager manager) {
        this.node = manager;
    }

    /**
     * @return the directory in which internal assets are stored.
     */
    public File getInternalAssetsDirectory() {
        return new File(basedir, Constants.MAIN_RESOURCES_DIR + "/assets");
    }

    /**
     * @return the directory in which internal assets are copied.
     */
    public File getInternalAssetOutputDirectory() {
        return new File(buildDirectory, "classes/assets");
    }

    /**
     * @return the directory in which external assets are stored.
     */
    public File getExternalAssetsDirectory() {
        return new File(basedir, Constants.ASSETS_SRC_DIR);
    }

    /**
     * @return the directory in which external assets are copied.
     */
    public File getExternalAssetsOutputDirectory() {
        return new File(getWisdomRootDirectory(), Constants.ASSETS_DIR);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy