Remove ImportResolutionMode.SEMVER_LATEST
[yangtools.git] / plugin / yang-maven-plugin / src / main / java / org / opendaylight / yangtools / yang2sources / plugin / GeneratorTaskFactory.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;
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;
16
17 @NonNullByDefault
18 abstract class GeneratorTaskFactory extends ParserConfigAware {
19     private final YangParserConfiguration parserConfig;
20
21     GeneratorTaskFactory(final ImportResolutionMode importMode) {
22         parserConfig = switch (importMode) {
23             case REVISION_EXACT_OR_LATEST -> YangParserConfiguration.DEFAULT;
24         };
25     }
26
27     @Override
28     final YangParserConfiguration parserConfig() {
29         return parserConfig;
30     }
31
32     final String generatorName() {
33         return generator().getClass().getName();
34     }
35
36     /**
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}.
39      *
40      * @param project current Maven Project
41      * @param context model generation context
42      */
43     abstract GeneratorTask<?> createTask(MavenProject project, ContextHolder context);
44
45     abstract Object generator();
46
47     ToStringHelper addToStringProperties(final ToStringHelper helper) {
48         return helper.add("generator", generatorName());
49     }
50
51     @Override
52     public final String toString() {
53         return addToStringProperties(MoreObjects.toStringHelper(this).omitNullValues()).toString();
54     }
55 }