org.opendaylight.yangtools.yang2sources.plugin.FileGeneratorArg Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yang-maven-plugin Show documentation
Show all versions of yang-maven-plugin Show documentation
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
/*
* Copyright (c) 2020 PANTHEON.tech, s.r.o. 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 com.google.common.base.Verify.verifyNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Maps;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.apache.maven.plugins.annotations.Parameter;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Identifiable;
import org.opendaylight.yangtools.concepts.WritableObject;
public final class FileGeneratorArg implements Identifiable, WritableObject {
@Parameter
private final Map configuration = new HashMap<>();
@Parameter(required = true)
private String identifier;
public FileGeneratorArg() {
// Default constructor
}
public FileGeneratorArg(final String identifier) {
this.identifier = requireNonNull(identifier);
}
public FileGeneratorArg(final String identifier, final Map configuration) {
this(identifier);
this.configuration.putAll(configuration);
}
@Override
public String getIdentifier() {
return verifyNotNull(identifier);
}
public @NonNull Map getConfiguration() {
return Collections.unmodifiableMap(configuration);
}
@Override
public int hashCode() {
return getIdentifier().hashCode() + configuration.hashCode();
}
@Override
public boolean equals(final Object obj) {
return this == obj || obj instanceof FileGeneratorArg other && getIdentifier().equals(other.getIdentifier())
&& configuration.equals(other.getConfiguration());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this).add("id", identifier).add("configuration", configuration).toString();
}
public static @NonNull FileGeneratorArg readFrom(final DataInput in) throws IOException {
final var identifier = in.readUTF();
final var size = in.readInt();
final var configuration = Maps.newHashMapWithExpectedSize(size);
for (int i = 0; i < size; ++i) {
configuration.put(in.readUTF(), in.readUTF());
}
return new FileGeneratorArg(identifier, configuration);
}
@Override
public void writeTo(final DataOutput out) throws IOException {
out.writeUTF(identifier);
out.writeInt(configuration.size());
for (String key : configuration.keySet().stream().sorted().toList()) {
out.writeUTF(key);
out.writeUTF(configuration.getOrDefault(key, ""));
}
}
}