Use plugin-generator-api in yang-maven-plugin
[yangtools.git] / plugin / yang-maven-plugin / src / main / java / org / opendaylight / yangtools / yang2sources / plugin / GeneratorTask.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 static java.util.Objects.requireNonNull;
11
12 import java.io.File;
13 import java.io.IOException;
14 import java.util.Collection;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.opendaylight.yangtools.plugin.generator.api.FileGeneratorException;
17 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
18 import org.sonatype.plexus.build.incremental.BuildContext;
19
20 @NonNullByDefault
21 abstract class GeneratorTask<T extends GeneratorTaskFactory> extends ParserModeAware {
22     private final ContextHolder context;
23     private final T factory;
24
25     GeneratorTask(final T factory, final ContextHolder context) {
26         this.factory = requireNonNull(factory);
27         this.context = requireNonNull(context);
28     }
29
30     @Override
31     final StatementParserMode parserMode() {
32         return factory.parserMode();
33     }
34
35     final Collection<File> execute(final BuildContext buildContext) throws FileGeneratorException, IOException {
36         return execute(factory, context, buildContext);
37     }
38
39     abstract Collection<File> execute(T factory, ContextHolder modelContext, BuildContext buildContext)
40         throws FileGeneratorException, IOException;
41 }