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

org.xolstice.maven.plugin.protobuf.AbstractProtocTestCompileMojo Maven / Gradle / Ivy

package org.xolstice.maven.plugin.protobuf;

/*
 * Copyright (c) 2019 Maven Protocol Buffers Plugin Authors. All rights reserved.
 *
 * 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.
 */

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugins.annotations.Parameter;

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

import static java.util.Arrays.asList;

/**
 * An abstract base mojo configuration for using {@code protoc} compiler with the test sources.
 *
 * @since 0.3.3
 */
public abstract class AbstractProtocTestCompileMojo extends AbstractProtocMojo {

    /**
     * The source directories containing the test {@code .proto} definitions to be compiled.
     */
    @Parameter(
            required = true,
            defaultValue = "${basedir}/src/test/proto"
    )
    private File protoTestSourceRoot;

    @Override
    protected void doAttachProtoSources() {
        projectHelper.addTestResource(project, getProtoSourceRoot().getAbsolutePath(),
                asList(getIncludes()), asList(getExcludes()));
    }

    @Override
    protected void doAttachGeneratedFiles() {
        final File outputDirectory = getOutputDirectory();
        project.addTestCompileSourceRoot(outputDirectory.getAbsolutePath());
        buildContext.refresh(outputDirectory);
    }

    @Override
    protected List getDependencyArtifacts() {
        return project.getTestArtifacts();
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy