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

net.dongliu.prettypb.maven.ProtocCompileMojo Maven / Gradle / Ivy

There is a newer version: 0.3.5
Show newest version
package net.dongliu.prettypb.maven;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;

import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.Set;

/**
 * This mojo executes the {@code protoc} compiler for genemaven-javadoc-pluginrating java sources
 * from protocol buffer definitions. It also searches dependency artifacts for
 * proto files and includes them in the protopath so that they can be
 * referenced. Finally, it adds the proto files to the project as resources so
 * that they are included in the final artifact.
 *
 * @phase generate-sources
 * @goal compile
 * @requiresDependencyResolution compile
 */

public final class ProtocCompileMojo extends AbstractProtocMojo {

    /**
     * The source directories containing the sources to be compiled.
     *
     * @parameter default-value="${basedir}/src/main/proto"
     * @required
     */
    private File protoSourceRoot;

    /**
     * This is the directory into which the {@code .java} will be created.
     *
     * @parameter default-value="${project.build.directory}/generated-sources/protoc"
     * @required
     */
    private File outputDirectory;

    @Override
    protected Set getDependencyArtifacts() {
        //TODO: get dependency
        return Collections.emptySet();
    }

    @Override
    protected File getOutputDirectory() {
        return outputDirectory;
    }

    @Override
    protected File getProtoSourceRoot() {
        return protoSourceRoot;
    }

    @Override
    protected void attachFiles() {
        project.addCompileSourceRoot(outputDirectory.getAbsolutePath());
        projectHelper.addResource(project, protoSourceRoot.getAbsolutePath(),
                Arrays.asList("**/*.proto"), Collections.emptyList());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy