2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang2sources.plugin;
10 import com.google.common.base.MoreObjects;
11 import com.google.common.base.MoreObjects.ToStringHelper;
12 import org.apache.maven.project.MavenProject;
13 import org.eclipse.jdt.annotation.NonNullByDefault;
14 import org.opendaylight.yangtools.plugin.generator.api.FileGenerator.ImportResolutionMode;
15 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
18 abstract class GeneratorTaskFactory extends ParserConfigAware {
19 private final YangParserConfiguration parserConfig;
21 GeneratorTaskFactory(final ImportResolutionMode importMode) {
22 parserConfig = switch (importMode) {
23 case REVISION_EXACT_OR_LATEST -> YangParserConfiguration.DEFAULT;
28 final YangParserConfiguration parserConfig() {
32 final String generatorName() {
33 return generator().getClass().getName();
37 * Create a new {@link GeneratorTask} which will work in scope of specified {@link MavenProject} with the effective
38 * model held in specified {@link ContextHolder}.
40 * @param project current Maven Project
41 * @param context model generation context
43 abstract GeneratorTask<?> createTask(MavenProject project, ContextHolder context);
45 abstract Object generator();
47 ToStringHelper addToStringProperties(final ToStringHelper helper) {
48 return helper.add("generator", generatorName());
52 public final String toString() {
53 return addToStringProperties(MoreObjects.toStringHelper(this).omitNullValues()).toString();