Use plugin-generator-api in yang-maven-plugin
[yangtools.git] / plugin / yang-maven-plugin / src / main / java / org / opendaylight / yangtools / yang2sources / plugin / FileGeneratorTaskFactory.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang2sources.plugin;
9
10 import com.google.common.base.MoreObjects.ToStringHelper;
11 import org.apache.maven.project.MavenProject;
12 import org.opendaylight.yangtools.concepts.Identifiable;
13 import org.opendaylight.yangtools.plugin.generator.api.FileGenerator;
14 import org.opendaylight.yangtools.plugin.generator.api.FileGeneratorException;
15 import org.opendaylight.yangtools.plugin.generator.api.FileGeneratorFactory;
16
17 /**
18  * Bridge to a {@link FileGenerator} instance.
19  *
20  * @author Robert Varga
21  */
22 final class FileGeneratorTaskFactory extends GeneratorTaskFactory implements Identifiable<String> {
23     private final FileGeneratorArg arg;
24     private final FileGenerator gen;
25
26     private FileGeneratorTaskFactory(final FileGenerator gen, final FileGeneratorArg arg) {
27         super(gen.importResolutionMode());
28         this.arg = arg;
29         this.gen = gen;
30     }
31
32     static FileGeneratorTaskFactory of(final FileGeneratorFactory factory, final FileGeneratorArg arg)
33             throws FileGeneratorException {
34         return new FileGeneratorTaskFactory(factory.newFileGenerator(arg.getConfiguration()), arg);
35     }
36
37     @Override
38     public String getIdentifier() {
39         return arg.getIdentifier();
40     }
41
42     @Override
43     FileGeneratorTask createTask(final MavenProject project, final ContextHolder context) {
44         return new FileGeneratorTask(this, context, project);
45     }
46
47     @Override
48     FileGenerator generator() {
49         return gen;
50     }
51
52     @Override
53     ToStringHelper addToStringProperties(final ToStringHelper helper) {
54         return super.addToStringProperties(helper).add("argument", arg);
55     }
56 }