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

org.opendaylight.yangtools.yang2sources.plugin.ConfigArg Maven / Gradle / Ivy

Go to download

This plugin is a wrapper for "yang to source code" generation. It can be configured by a set of third-party code generators and resource providers. For further info see available goals. Sample usage: TODO: add sample usage when finished

There is a newer version: 14.0.4
Show newest version
/*
 * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.yangtools.yang2sources.plugin;

import static java.util.Objects.requireNonNull;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import org.apache.maven.project.MavenProject;

/**
 * Base complex configuration arguments.
 */
public abstract class ConfigArg {
    private final File outputBaseDir;

    public ConfigArg(final String outputBaseDir) {
        this.outputBaseDir = outputBaseDir == null ? null : new File(outputBaseDir);
    }

    public File getOutputBaseDir(final MavenProject project) {
        if (outputBaseDir == null) {
            return null;
        }
        return outputBaseDir.isAbsolute() ? outputBaseDir : new File(project.getBasedir(), outputBaseDir.getPath());
    }

    public abstract void check();

    /**
     * Configuration argument for code generator class and output directory.
     */
    public static final class CodeGeneratorArg extends ConfigArg {

        private final Map additionalConfiguration = new HashMap<>();

        private String codeGeneratorClass;
        private File resourceBaseDir;

        public CodeGeneratorArg() {
            super(null);
        }

        public CodeGeneratorArg(final String codeGeneratorClass) {
            this(codeGeneratorClass, null);
        }

        public CodeGeneratorArg(final String codeGeneratorClass, final String outputBaseDir) {
            super(outputBaseDir);
            this.codeGeneratorClass = codeGeneratorClass;
        }

        public CodeGeneratorArg(final String codeGeneratorClass, final String outputBaseDir,
                final String resourceBaseDir) {
            super(outputBaseDir);
            this.codeGeneratorClass = codeGeneratorClass;
            this.resourceBaseDir = new File(resourceBaseDir);
        }

        @Override
        public void check() {
            requireNonNull(codeGeneratorClass, "codeGeneratorClass for CodeGenerator cannot be null");
        }

        public String getCodeGeneratorClass() {
            return codeGeneratorClass;
        }

        public File getResourceBaseDir(final MavenProject project) {
            if (resourceBaseDir == null) {
                // if it has not been set, use a default (correctly dealing with target/ VS target-ide)
                return new GeneratedDirectories(project).getYangServicesDir();
            }

            return resourceBaseDir.isAbsolute() ? resourceBaseDir
                        : new File(project.getBasedir(), resourceBaseDir.getPath());
        }

        public Map getAdditionalConfiguration() {
            return additionalConfiguration;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy