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

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

package org.xolstice.maven.plugin.protobuf;

/*
 * Copyright (c) 2018 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.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;

import java.io.File;

/**
 * This mojo executes the {@code protoc} compiler for generating main JavaScript sources
 * from protocol buffer definitions. It also searches dependency artifacts for
 * {@code .proto} files and includes them in the {@code proto_path} so that they can be
 * referenced. Finally, it adds the {@code .proto} files to the project as resources so
 * that they are included in the final artifact.
 *
 * @since 0.6.0
 */
@Mojo(
        name = "compile-js",
        defaultPhase = LifecyclePhase.GENERATE_SOURCES,
        requiresDependencyResolution = ResolutionScope.COMPILE,
        threadSafe = true
)
public final class ProtocCompileJavaScriptMojo extends AbstractProtocCompileMojo {

    /**
     * This is the directory into which the {@code .js} will be created.
     */
    @Parameter(
            required = true,
            property = "javaScriptOutputDirectory",
            defaultValue = "${project.build.directory}/generated-sources/protobuf/js"
    )
    private File outputDirectory;

    /**
     * Additional comma-separated options to be passed to the JavaScript generator.
     * Cannot contain colon (:) symbols.
     */
    @Parameter(
            required = false,
            property = "javaScriptOptions"
    )
    private String javaScriptOptions;

    @Override
    protected void addProtocBuilderParameters(final Protoc.Builder protocBuilder) {
        super.addProtocBuilderParameters(protocBuilder);
        if (javaScriptOptions != null) {
            protocBuilder.setNativePluginParameter(javaScriptOptions);
        }
        protocBuilder.setJavaScriptOutputDirectory(getOutputDirectory());
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy