<artifactId>yang-maven-plugin</artifactId>
<version>10.0.0-SNAPSHOT</version>
</dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-maven-plugin-spi</artifactId>
- <version>10.0.0-SNAPSHOT</version>
- </dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-test-util</artifactId>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-maven-plugin-spi</artifactId>
- </dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
</group>
<group>
<title>yang-maven-plugin codegen interface</title>
- <packages>org.opendaylight.yangtools.plugin.generator.api*:org.opendaylight.yangtools.yang2sources.spi*</packages>
+ <packages>org.opendaylight.yangtools.plugin.generator.api*</packages>
</group>
<group>
<title>Common YANG parser</title>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-repo-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.kohsuke.metainf-services</groupId>
+ <artifactId>metainf-services</artifactId>
+ <optional>true</optional>
+ <scope>test</scope>
+ </dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-source-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test-jar-no-fork</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
* 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.spi;
+package org.opendaylight.yangtools.plugin.generator.api;
import com.google.common.collect.ImmutableTable;
import com.google.common.collect.Table;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.opendaylight.yangtools.plugin.generator.api.FileGenerator;
-import org.opendaylight.yangtools.plugin.generator.api.GeneratedFile;
-import org.opendaylight.yangtools.plugin.generator.api.GeneratedFileLifecycle;
-import org.opendaylight.yangtools.plugin.generator.api.GeneratedFilePath;
-import org.opendaylight.yangtools.plugin.generator.api.GeneratedFileType;
-import org.opendaylight.yangtools.plugin.generator.api.ModuleResourceResolver;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.Module;
* 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.spi;
+package org.opendaylight.yangtools.plugin.generator.api;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.opendaylight.yangtools.plugin.generator.api.AbstractFileGeneratorFactory;
-import org.opendaylight.yangtools.plugin.generator.api.FileGenerator;
+import org.kohsuke.MetaInfServices;
+@MetaInfServices(value = FileGeneratorFactory.class)
@NonNullByDefault
public final class TestFileGeneratorFactory extends AbstractFileGeneratorFactory {
public static final String PREFIX = "prefix";
<modules>
<module>plugin-generator-api</module>
<module>yang-maven-plugin</module>
- <module>yang-maven-plugin-spi</module>
<module>yang-maven-plugin-it</module>
</modules>
import org.apache.maven.it.VerificationException;
import org.apache.maven.it.Verifier;
import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
@Test
+ @Ignore // FIXME depends on fix of a bug processing multiple fileGenerator definitions having same identifier
public void testAdditionalConfiguration() throws Exception {
Verifier vrf = setUp("test-parent/AdditionalConfig/", false);
vrf.verifyTextInLog("[DEBUG] yang-to-sources: Additional configuration picked up for : "
- + "org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl: "
+ + "org.opendaylight.yangtools.plugin.generator.api.TestFileGenerator: "
+ "{nm1=abcd=a.b.c.d, nm2=abcd2=a.b.c.d.2}");
vrf.verifyTextInLog("[DEBUG] yang-to-sources: Additional configuration picked up for : "
- + "org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl: {c1=config}");
+ + "org.opendaylight.yangtools.plugin.generator.api.TestFileGenerator: {c1=config}");
vrf.verifyTextInLog("[DEBUG] yang-to-sources: YANG files marked as resources:");
vrf.verifyTextInLog(Joiner.on(File.separator).join(Arrays.asList("target", "generated-sources", "spi"))
+ " marked as resources for generator: org.opendaylight.yangtools.yang2sources.spi."
static void verifyCorrectLog(final Verifier vrf) throws VerificationException {
vrf.verifyErrorFreeLog();
vrf.verifyTextInLog("[INFO] yang-to-sources: Project model files found: ");
- vrf.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from "
- + "org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl");
+ vrf.verifyTextInLog("[INFO] yang-to-sources: Code generator "
+ + "org.opendaylight.yangtools.plugin.generator.api.TestFileGenerator instantiated");
vrf.verifyTextInLog("[INFO] yang-to-sources: Sources generated by "
- + "org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl: 0");
+ + "org.opendaylight.yangtools.plugin.generator.api.TestFileGenerator: 0");
}
@Test
@Test
public void testUnknownGenerator() throws Exception {
Verifier vrf = setUp("test-parent/UnknownGenerator/", true);
- vrf.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from "
- + "org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl");
- vrf.verifyTextInLog("on project unknown-generator: Failed to find code generator class unknown");
- vrf.verifyTextInLog("MojoFailureException: Failed to find code generator class unknown");
- vrf.verifyTextInLog("java.lang.ClassNotFoundException: unknown");
+ vrf.verifyTextInLog("[INFO] yang-to-sources: Code generator "
+ + "org.opendaylight.yangtools.plugin.generator.api.TestFileGenerator instantiated");
+ vrf.verifyTextInLog("[WARNING] yang-to-sources: No generator found for identifier unknown");
}
@Test
String buildDir = getMavenBuildDirectory(v1);
v1.assertFilePresent(buildDir + "/generated-sources/"
- + "org.opendaylight.yangtools.yang2sources.spi.TestFileGenerator/fooGenSource.test");
+ + "org.opendaylight.yangtools.plugin.generator.api.TestFileGenerator/fooGenSource.test");
v1.assertFilePresent(buildDir + "/generated-resources/"
- + "org.opendaylight.yangtools.yang2sources.spi.TestFileGenerator/foo-gen-resource");
+ + "org.opendaylight.yangtools.plugin.generator.api.TestFileGenerator/foo-gen-resource");
v1.assertFilePresent(buildDir + "/../src/main/java/fooSource.test");
v1.assertFilePresent(buildDir + "/../src/main/resources/foo-resource");
}
<dependencies>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-maven-plugin-spi</artifactId>
+ <artifactId>plugin-generator-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<configuration>
<yangFilesRootDir>../files</yangFilesRootDir>
<inspectDependencies>false</inspectDependencies>
- <codeGenerators>
- <generator>
- <codeGeneratorClass>
- org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl
- </codeGeneratorClass>
- <additionalConfiguration>
+ <fileGenerators>
+ <fileGenerator>
+ <identifier>
+ org.opendaylight.yangtools.plugin.generator.api.TestFileGenerator
+ </identifier>
+ <configuration>
<nm1>abcd=a.b.c.d</nm1>
<nm2>abcd2=a.b.c.d.2</nm2>
- </additionalConfiguration>
- <resourceBaseDir>/target/resourcesGenerated</resourceBaseDir>
- <outputBaseDir>
- target/AdditionalConfig
- </outputBaseDir>
- </generator>
- <generator>
- <codeGeneratorClass>
- org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl
- </codeGeneratorClass>
- <additionalConfiguration>
+ </configuration>
+ </fileGenerator>
+ <fileGenerator>
+ <identifier>
+ org.opendaylight.yangtools.plugin.generator.api.TestFileGenerator
+ </identifier>
+ <configuration>
<c1>config</c1>
- </additionalConfiguration>
- <outputBaseDir>
- target/AdditionalConfig
- </outputBaseDir>
- </generator>
- </codeGenerators>
+ </configuration>
+ </fileGenerator>
+ </fileGenerators>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-maven-plugin-spi</artifactId>
+ <artifactId>plugin-generator-api</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
<dependencies>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-maven-plugin-spi</artifactId>
+ <artifactId>plugin-generator-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<configuration>
<yangFilesRootDir>../files</yangFilesRootDir>
<inspectDependencies>false</inspectDependencies>
- <codeGenerators>
+ <fileGenerators>
<generator>
- <codeGeneratorClass>
- org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl
- </codeGeneratorClass>
- <outputBaseDir>
- target/correct
- </outputBaseDir>
+ <identifier>
+ org.opendaylight.yangtools.plugin.generator.api.TestFileGenerator
+ </identifier>
</generator>
- </codeGenerators>
+ </fileGenerators>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-maven-plugin-spi</artifactId>
+ <artifactId>plugin-generator-api</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
<inspectDependencies>false</inspectDependencies>
<fileGenerators>
<fileGenerator>
- <identifier>org.opendaylight.yangtools.yang2sources.spi.TestFileGenerator</identifier>
+ <identifier>org.opendaylight.yangtools.plugin.generator.api.TestFileGenerator</identifier>
<configuration>
<prefix>foo</prefix>
</configuration>
<dependencies>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-maven-plugin-spi</artifactId>
+ <artifactId>plugin-generator-api</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
<configuration>
<yangFilesRootDir>${basedir}/src/main/resources</yangFilesRootDir>
<inspectDependencies>false</inspectDependencies>
- <codeGenerators>
- <generator>
- <codeGeneratorClass>
- org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl
- </codeGeneratorClass>
- <outputBaseDir>
- target/GenerateTest1
- </outputBaseDir>
- </generator>
- </codeGenerators>
+ <fileGenerators>
+ <fileGenerator>
+ <identifier>
+ org.opendaylight.yangtools.plugin.generator.api.TestFileGenerator
+ </identifier>
+ </fileGenerator>
+ </fileGenerators>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-maven-plugin-spi</artifactId>
+ <artifactId>plugin-generator-api</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
<configuration>
<yangFilesRootDir>${project.basedir}/yang</yangFilesRootDir>
<inspectDependencies>true</inspectDependencies>
- <codeGenerators>
- <generator>
- <codeGeneratorClass>
- org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl
- </codeGeneratorClass>
- <outputBaseDir>
- outDir/
- </outputBaseDir>
- </generator>
- </codeGenerators>
+ <fileGenerators>
+ <fileGenerator>
+ <identifier>
+ org.opendaylight.yangtools.plugin.generator.api.TestFileGenerator
+ </identifier>
+ </fileGenerator>
+ </fileGenerators>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-maven-plugin-spi</artifactId>
+ <artifactId>plugin-generator-api</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
<configuration>
<yangFilesRootDir>../files</yangFilesRootDir>
<inspectDependencies>false</inspectDependencies>
- <codeGenerators>
- <generator>
- <codeGeneratorClass>
- org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl
- </codeGeneratorClass>
- <outputBaseDir>
- outDir/
- </outputBaseDir>
- </generator>
- </codeGenerators>
+ <fileGenerators>
+ <fileGenerator>
+ <identifier>
+ org.opendaylight.yangtools.plugin.generator.api.TestFileGenerator
+ </identifier>
+ </fileGenerator>
+ </fileGenerators>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-maven-plugin-spi</artifactId>
+ <artifactId>plugin-generator-api</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
<configuration>
<yangFilesRootDir>../files</yangFilesRootDir>
<inspectDependencies>false</inspectDependencies>
- <codeGenerators>
- </codeGenerators>
- <resourceProviders>
- <provider>
- <resourceProviderClass>
- org.opendaylight.yangtools.yang2sources.spi.ResourceProviderTestImpl
- </resourceProviderClass>
- <outputBaseDir>
- outDir/
- </outputBaseDir>
- </provider>
- </resourceProviders>
+ <fileGenerators/>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-maven-plugin-spi</artifactId>
+ <artifactId>plugin-generator-api</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
<configuration>
<yangFilesRootDir>${project.basedir}/yang</yangFilesRootDir>
<inspectDependencies>true</inspectDependencies>
- <codeGenerators>
- <generator>
- <codeGeneratorClass>
- org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl
- </codeGeneratorClass>
- <outputBaseDir>
- outDir/
- </outputBaseDir>
- </generator>
- </codeGenerators>
- <resourceProviders>
- <provider>
- <resourceProviderClass>
- org.opendaylight.yangtools.yang2sources.spi.ResourceProviderTestImpl
- </resourceProviderClass>
- <outputBaseDir>
- outDir/
- </outputBaseDir>
- </provider>
- </resourceProviders>
+ <fileGenerators>
+ <fileGenerator>
+ <identifier>
+ org.opendaylight.yangtools.plugin.generator.api.TestFileGenerator
+ </identifier>
+ </fileGenerator>
+ </fileGenerators>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-maven-plugin-spi</artifactId>
+ <artifactId>plugin-generator-api</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
<configuration combine.self="override">
<yangFilesRootDir>../files</yangFilesRootDir>
<inspectDependencies>false</inspectDependencies>
- <codeGenerators>
- </codeGenerators>
- <resourceProviders>
- <provider>
- <resourceProviderClass>
- org.opendaylight.yangtools.yang2sources.spi.ResourceProviderTestImpl
- </resourceProviderClass>
- <outputBaseDir>
- outDir/
- </outputBaseDir>
- </provider>
- </resourceProviders>
</configuration>
</execution>
</executions>
<configuration>
<yangFilesRootDir>../files</yangFilesRootDir>
<inspectDependencies>false</inspectDependencies>
- <codeGenerators>
- <generator>
- <codeGeneratorClass>
- org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl
- </codeGeneratorClass>
- <outputBaseDir>
- target/NoOutputDir
- </outputBaseDir>
- </generator>
- </codeGenerators>
+ <fileGenerators>
+ <fileGenerator>
+ <identifier>
+ org.opendaylight.yangtools.plugin.generator.api.TestFileGenerator
+ </identifier>
+ </fileGenerator>
+ </fileGenerators>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-maven-plugin-spi</artifactId>
+ <artifactId>plugin-generator-api</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
<configuration>
<yangFilesRootDir>${basedir}</yangFilesRootDir>
<inspectDependencies>false</inspectDependencies>
- <codeGenerators>
- <generator>
- <codeGeneratorClass>
- org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl
- </codeGeneratorClass>
- <outputBaseDir>
- /outDir/
- </outputBaseDir>
- </generator>
- </codeGenerators>
+ <fileGenerators>
+ <fileGenerator>
+ <identifier>
+ org.opendaylight.yangtools.plugin.generator.api.TestFileGenerator
+ </identifier>
+ </fileGenerator>
+ </fileGenerators>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-maven-plugin-spi</artifactId>
+ <artifactId>plugin-generator-api</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
<configuration>
<yangFilesRootDir>../files</yangFilesRootDir>
<inspectDependencies>false</inspectDependencies>
- <codeGenerators>
- <generator>
- <codeGeneratorClass>
- org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl
- </codeGeneratorClass>
- <outputBaseDir>
- /outDir/
- </outputBaseDir>
- </generator>
- <generator>
- <codeGeneratorClass>
+ <fileGenerators>
+ <fileGenerator>
+ <identifier>
+ org.opendaylight.yangtools.plugin.generator.api.TestFileGenerator
+ </identifier>
+ </fileGenerator>
+ <fileGenerator>
+ <identifier>
unknown
- </codeGeneratorClass>
- <outputBaseDir>
- /outDir/
- </outputBaseDir>
- </generator>
- </codeGenerators>
+ </identifier>
+ </fileGenerator>
+ </fileGenerators>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-maven-plugin-spi</artifactId>
+ <artifactId>plugin-generator-api</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
<configuration>
<yangFilesRootDir>unknown</yangFilesRootDir>
<inspectDependencies>false</inspectDependencies>
- <codeGenerators>
- <generator>
- <codeGeneratorClass>
- org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl
- </codeGeneratorClass>
- <outputBaseDir>
- /outDir/
- </outputBaseDir>
- </generator>
- </codeGenerators>
+ <fileGenerators>
+ <fileGenerator>
+ <identifier>
+ org.opendaylight.yangtools.plugin.generator.api.TestFileGenerator
+ </identifier>
+ </fileGenerator>
+ </fileGenerators>
</configuration>
</execution>
</executions>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: -->
-<!--
- Copyright (c) 2013 Cisco Systems, Inc. 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
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
- <parent>
- <groupId>org.opendaylight.odlparent</groupId>
- <artifactId>odlparent</artifactId>
- <version>11.0.1</version>
- <relativePath/>
- </parent>
-
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-maven-plugin-spi</artifactId>
- <version>10.0.0-SNAPSHOT</version>
- <name>${project.artifactId}</name>
- <description>${project.artifactId}</description>
-
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yangtools-artifacts</artifactId>
- <version>10.0.0-SNAPSHOT</version>
- <scope>import</scope>
- <type>pom</type>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
- <dependencies>
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-model-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>plugin-generator-api</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-plugin-api</artifactId>
- <version>3.8.3</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-core</artifactId>
- <version>3.8.3</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.sonatype.plexus</groupId>
- <artifactId>plexus-build-api</artifactId>
- <scope>provided</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>test-jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
-</project>
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.spi;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Set;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.plugin.generator.api.FileGenerator;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.Module;
-
-/**
- * Maven 3.1.x and newer uses SLF4J internally, which means we do not need to pass a logger instance around.
- *
- * @deprecated Use {@link FileGenerator} instead.
- */
-@Deprecated
-public interface BasicCodeGenerator {
- enum ImportResolutionMode {
- /**
- * Standard, RFC6020 and RFC7950 compliant mode. Imports are satisfied by exact revision match (if specified),
- * or by latest available revision.
- */
- REVISION_EXACT_OR_LATEST(FileGenerator.ImportResolutionMode.REVISION_EXACT_OR_LATEST);
-
- private final FileGenerator.@NonNull ImportResolutionMode fileGeneratorMode;
-
- ImportResolutionMode(final FileGenerator.@NonNull ImportResolutionMode fileGeneratorMode) {
- this.fileGeneratorMode = fileGeneratorMode;
- }
-
- /**
- * Return {@link FileGenerator.ImportResolutionMode} equivalent of this mode.
- *
- * @return {@link FileGenerator.ImportResolutionMode} equivalent of this mode
- */
- public final FileGenerator.@NonNull ImportResolutionMode toFileGeneratorMode() {
- return fileGeneratorMode;
- }
- }
-
- /**
- * Generate sources from provided {@link EffectiveModelContext}.
- *
- * @param context
- * parsed from YANG files
- * @param outputBaseDir
- * expected output directory for generated sources configured by
- * user
- * @param currentModules
- * YANG modules parsed from yangFilesRootDir
- * @param moduleResourcePathResolver
- * Function converting a local module to the packaged resource path
- * @return collection of files that were generated from schema context
- */
- Collection<File> generateSources(EffectiveModelContext context, File outputBaseDir, Set<Module> currentModules,
- ModuleResourceResolver moduleResourcePathResolver) throws IOException;
-
- /**
- * Provided map contains all configuration that was set in pom for code
- * generator in additionalConfiguration tag.
- */
- void setAdditionalConfig(Map<String, String> additionalConfiguration);
-
- /**
- * Provided folder is marked as resources and its content will be packaged
- * in resulting jar. Feel free to add necessary resources.
- */
- void setResourceBaseDir(File resourceBaseDir);
-
- /**
- * Indicate import resolution mode this code generator requires. Default implementation indicates
- * {@link ImportResolutionMode#REVISION_EXACT_OR_LATEST}.
- *
- * @return Required import resolution mode, null if the code generator does not care.
- */
- // FIXME: This is not really extensible, we should be returning a collection of acceptable modes, or have some sort
- // of two-step negotiation protocol:
- // - Optional<ImportResolutionMode> suggestImportResolutionMode();
- // - boolean isImportResolutionModeAcceptable(ImportResolutionMode);
- // Let's go with something hacky until we figure out exact requirements.
- default ImportResolutionMode getImportResolutionMode() {
- return ImportResolutionMode.REVISION_EXACT_OR_LATEST;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. 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.spi;
-
-import org.opendaylight.yangtools.plugin.generator.api.FileGenerator;
-import org.sonatype.plexus.build.incremental.BuildContext;
-
-/**
- * Interface implemented by CodeGenerator implementations which are integrated
- * with BuildContext. These will have the build context injected before any
- * attempt is made to generate files and should interact with the reactor solely
- * through it.
- *
- * @deprecated Use {@link FileGenerator} instead.
- */
-@Deprecated
-public interface BuildContextAware {
- /**
- * Set the build context to be used during the lifetime of this reactor.
- *
- * @param buildContext current build context reference.
- */
- void setBuildContext(BuildContext buildContext);
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.spi;
-
-import org.apache.maven.project.MavenProject;
-import org.opendaylight.yangtools.plugin.generator.api.FileGeneratorFactory;
-
-/**
- * Bridge for plugins which need access to the underlying maven project.
- *
- * @deprecated Use {@link FileGeneratorFactory} instead.
- */
-@Deprecated
-public interface MavenProjectAware {
- /**
- * Provided maven project object. Any additional information about current
- * maven project can be accessed from it.
- */
- void setMavenProject(MavenProject project);
-}
+++ /dev/null
-/*
- * 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.spi;
-
-import com.google.common.annotations.Beta;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
-
-/**
- * An SPI-level interface to find the schema source for a particular YANG module, as packaged in the final artifact.
- * The module must be part of the current resolution context.
- *
- * @deprecated Use {@link org.opendaylight.yangtools.plugin.generator.api.ModuleResourceResolver} instead.
- */
-@Beta
-@Deprecated
-@FunctionalInterface
-@SuppressFBWarnings(value = "NM_SAME_SIMPLE_NAME_AS_INTERFACE", justification = "Migration to new place")
-public interface ModuleResourceResolver extends org.opendaylight.yangtools.plugin.generator.api.ModuleResourceResolver {
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. 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.spi;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Set;
-import org.apache.maven.project.MavenProject;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class CodeGeneratorTestImpl implements BasicCodeGenerator, MavenProjectAware {
-
- private static final Logger LOG = LoggerFactory.getLogger(CodeGeneratorTestImpl.class);
-
- @Override
- public Collection<File> generateSources(final EffectiveModelContext context, final File outputBaseDir,
- final Set<Module> currentModules, final ModuleResourceResolver moduleResourcePathResolver)
- throws IOException {
- LOG.debug("{} generateSources:context: {}", getClass().getCanonicalName(), context);
- LOG.debug("{} generateSources:outputBaseDir: {}", getClass().getCanonicalName(), outputBaseDir);
- LOG.debug("{} generateSources:currentModules: {}", getClass().getCanonicalName(), currentModules);
- return null;
- }
-
- @Override
- public void setAdditionalConfig(final Map<String, String> additionalConfiguration) {
- LOG.debug("{} additionalConfig: {}", getClass().getCanonicalName(), additionalConfiguration);
- }
-
- @Override
- public void setResourceBaseDir(final File resourceBaseDir) {
- LOG.debug("{} resourceBaseDir: {}", getClass().getCanonicalName(), resourceBaseDir);
- }
-
- @Override
- public void setMavenProject(final MavenProject project) {
- LOG.debug("{} maven project: {}", getClass().getCanonicalName(), project);
- }
-}
+++ /dev/null
-org.opendaylight.yangtools.yang2sources.spi.TestFileGeneratorFactory
</dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-parser-impl</artifactId>
+ <artifactId>plugin-generator-api</artifactId>
</dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-test-util</artifactId>
- <scope>test</scope>
+ <artifactId>yang-parser-impl</artifactId>
</dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-maven-plugin-spi</artifactId>
+ <artifactId>yang-test-util</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.sonatype.plexus</groupId>
<artifactId>plexus-build-api</artifactId>
</dependency>
-
<dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-maven-plugin-spi</artifactId>
- <version>${project.version}</version>
- <type>test-jar</type>
- <scope>test</scope>
+ <groupId>org.kohsuke.metainf-services</groupId>
+ <artifactId>metainf-services</artifactId>
</dependency>
</dependencies>
+++ /dev/null
-/*
- * 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 java.util.Objects.requireNonNull;
-
-import com.google.common.base.Stopwatch;
-import java.io.File;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.List;
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.opendaylight.yangtools.yang2sources.spi.BasicCodeGenerator;
-import org.opendaylight.yangtools.yang2sources.spi.BuildContextAware;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonatype.plexus.build.incremental.BuildContext;
-
-@NonNullByDefault
-final class CodeGeneratorTask extends GeneratorTask<CodeGeneratorTaskFactory> {
- private static final Logger LOG = LoggerFactory.getLogger(CodeGeneratorTask.class);
-
- private final File outputDir;
-
- CodeGeneratorTask(final CodeGeneratorTaskFactory factory, final ContextHolder context, final File outputDir) {
- super(factory, context);
- this.outputDir = requireNonNull(outputDir);
- }
-
- @Override
- Collection<File> execute(final CodeGeneratorTaskFactory factory, final ContextHolder modelContext,
- final BuildContext buildContext) throws IOException {
- final Stopwatch watch = Stopwatch.createStarted();
- final BasicCodeGenerator gen = factory.generator();
- final boolean mark;
- if (gen instanceof BuildContextAware) {
- ((BuildContextAware)gen).setBuildContext(buildContext);
- mark = false;
- } else {
- mark = true;
- }
-
- LOG.debug("Sources will be generated to {}", outputDir);
- Collection<File> sources = gen.generateSources(modelContext.getContext(), outputDir,
- modelContext.getYangModules(), modelContext);
- if (sources == null) {
- sources = List.of();
- }
-
- LOG.debug("Sources generated by {}: {}", gen.getClass(), sources);
- LOG.info("Sources generated by {}: {} in {}", gen.getClass(), sources.size(), watch);
-
- if (mark) {
- sources.forEach(buildContext::refresh);
- }
-
- return sources;
- }
-}
+++ /dev/null
-/*
- * 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 java.util.Objects.requireNonNull;
-
-import com.google.common.base.MoreObjects.ToStringHelper;
-import java.io.File;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import org.apache.maven.model.Resource;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.project.MavenProject;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg;
-import org.opendaylight.yangtools.yang2sources.spi.BasicCodeGenerator;
-import org.opendaylight.yangtools.yang2sources.spi.BasicCodeGenerator.ImportResolutionMode;
-import org.opendaylight.yangtools.yang2sources.spi.MavenProjectAware;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Bridge to legacy {@link BasicCodeGenerator} generation.
- *
- * @author Robert Varga
- */
-final class CodeGeneratorTaskFactory extends GeneratorTaskFactory {
- private static final Logger LOG = LoggerFactory.getLogger(CodeGeneratorTaskFactory.class);
-
- private final @NonNull BasicCodeGenerator gen;
- private final CodeGeneratorArg cfg;
-
- private CodeGeneratorTaskFactory(final ImportResolutionMode importMode, final BasicCodeGenerator gen,
- final CodeGeneratorArg cfg) {
- super(importMode.toFileGeneratorMode());
- this.gen = requireNonNull(gen);
- this.cfg = requireNonNull(cfg);
- }
-
- static GeneratorTaskFactory create(final CodeGeneratorArg cfg) throws MojoFailureException {
- cfg.check();
-
- final String codegenClass = cfg.getCodeGeneratorClass();
- final Class<?> clazz;
- try {
- clazz = Class.forName(codegenClass);
- } catch (ClassNotFoundException e) {
- throw new MojoFailureException("Failed to find code generator class " + codegenClass, e);
- }
- final Class<? extends BasicCodeGenerator> typedClass;
- try {
- typedClass = clazz.asSubclass(BasicCodeGenerator.class);
- } catch (ClassCastException e) {
- throw new MojoFailureException("Code generator " + clazz + " does not implement "
- + BasicCodeGenerator.class, e);
- }
- final Constructor<? extends BasicCodeGenerator> ctor;
- try {
- ctor = typedClass.getDeclaredConstructor();
- } catch (NoSuchMethodException e) {
- throw new MojoFailureException("Code generator " + clazz
- + " does not have an accessible no-argument constructor", e);
- }
- final @NonNull BasicCodeGenerator gen;
- try {
- gen = ctor.newInstance();
- } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
- throw new MojoFailureException("Failed to instantiate code generator " + clazz, e);
- }
- LOG.debug("Code generator instantiated from {}", codegenClass);
-
- ImportResolutionMode importMode = gen.getImportResolutionMode();
- if (importMode == null) {
- importMode = ImportResolutionMode.REVISION_EXACT_OR_LATEST;
- }
- return new CodeGeneratorTaskFactory(importMode, gen, cfg);
- }
-
- @Override
- CodeGeneratorTask createTask(final MavenProject project, final ContextHolder context) {
- if (gen instanceof MavenProjectAware) {
- ((MavenProjectAware)gen).setMavenProject(project);
- }
-
- LOG.debug("Project root dir is {}", project.getBasedir());
- LOG.debug("{} Additional configuration picked up for : {}: {}", YangToSourcesProcessor.LOG_PREFIX,
- generatorName(), cfg.getAdditionalConfiguration());
-
- final File outputDir = cfg.getOutputBaseDir(project);
- project.addCompileSourceRoot(outputDir.getAbsolutePath());
-
- gen.setAdditionalConfig(cfg.getAdditionalConfiguration());
- File resourceBaseDir = cfg.getResourceBaseDir(project);
-
- final Resource res = new Resource();
- res.setDirectory(resourceBaseDir.getPath());
- project.addResource(res);
-
- gen.setResourceBaseDir(resourceBaseDir);
- LOG.debug("Folder: {} marked as resources for generator: {}", resourceBaseDir, generatorName());
- return new CodeGeneratorTask(this, context, outputDir);
- }
-
- @Override
- BasicCodeGenerator generator() {
- return gen;
- }
-
- @Override
- ToStringHelper addToStringProperties(final ToStringHelper helper) {
- return super.addToStringProperties(helper).add("configuration", cfg);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. 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 java.util.Objects.requireNonNull;
-
-import com.google.common.base.MoreObjects;
-import java.io.File;
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.maven.project.MavenProject;
-
-/**
- * Base complex configuration arguments.
- */
-public abstract class ConfigArg {
- private final File outputBaseDir;
-
- public ConfigArg(final String outputBaseDir) {
- this.outputBaseDir = outputBaseDir == null ? null : new File(outputBaseDir);
- }
-
- public File getOutputBaseDir(final MavenProject project) {
- return outputBaseDir.isAbsolute() ? outputBaseDir : new File(project.getBasedir(), outputBaseDir.getPath());
- }
-
- public void check() {
- requireNonNull(outputBaseDir,
- "outputBaseDir is null. Please provide a valid outputBaseDir value in the pom.xml");
- }
-
- /**
- * Configuration argument for code generator class and output directory.
- */
- public static final class CodeGeneratorArg extends ConfigArg {
-
- private final Map<String, String> additionalConfiguration = new HashMap<>();
-
- private String codeGeneratorClass;
- private File resourceBaseDir;
-
- public CodeGeneratorArg() {
- super(null);
- }
-
- public CodeGeneratorArg(final String codeGeneratorClass) {
- this(codeGeneratorClass, null);
- }
-
- public CodeGeneratorArg(final String codeGeneratorClass, final String outputBaseDir) {
- super(outputBaseDir);
- this.codeGeneratorClass = codeGeneratorClass;
- }
-
- public CodeGeneratorArg(final String codeGeneratorClass, final String outputBaseDir,
- final String resourceBaseDir) {
- super(outputBaseDir);
- this.codeGeneratorClass = codeGeneratorClass;
- this.resourceBaseDir = new File(resourceBaseDir);
- }
-
- @Override
- public void check() {
- super.check();
- requireNonNull(codeGeneratorClass, "codeGeneratorClass for CodeGenerator cannot be null");
- }
-
- public String getCodeGeneratorClass() {
- return codeGeneratorClass;
- }
-
- public File getResourceBaseDir(final MavenProject project) {
- if (resourceBaseDir == null) {
- // if it has not been set, use a default (correctly dealing with target/ VS target-ide)
- return new GeneratedDirectories(project).getYangServicesDir();
- }
-
- return resourceBaseDir.isAbsolute() ? resourceBaseDir
- : new File(project.getBasedir(), resourceBaseDir.getPath());
- }
-
- public Map<String, String> getAdditionalConfiguration() {
- return additionalConfiguration;
- }
-
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(this).omitNullValues()
- .add("resourceDir", resourceBaseDir)
- .add("configuration", additionalConfiguration)
- .toString();
- }
- }
-}
import java.util.Optional;
import java.util.Set;
import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.plugin.generator.api.ModuleResourceResolver;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleLike;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
-import org.opendaylight.yangtools.yang2sources.spi.ModuleResourceResolver;
final class ContextHolder implements Immutable, ModuleResourceResolver {
private final EffectiveModelContext context;
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.RepositorySystem;
import org.opendaylight.yangtools.plugin.generator.api.FileGenerator;
+import org.opendaylight.yangtools.plugin.generator.api.ModuleResourceResolver;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
-import org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg;
-import org.opendaylight.yangtools.yang2sources.spi.BasicCodeGenerator;
import org.sonatype.plexus.build.incremental.BuildContext;
/**
* Generate sources from yang files using user provided set of
- * {@link BasicCodeGenerator}s. Steps of this process:
+ * {@link FileGeneratorArg}s. Steps of this process:
* <ol>
* <li>List yang files from {@link #yangFilesRootDir}</li>
* <li>Process yang files using Yang Parser</li>
- * <li>For each {@link BasicCodeGenerator} from {@link #codeGenerators}:
+ * <li>For each {@link FileGeneratorArg} from {@link #fileGenerators}:
* <ol>
* <li>Instantiate using default constructor</li>
- * <li>Call {@link BasicCodeGenerator#generateSources(EffectiveModelContext, File, Set,
- * org.opendaylight.yangtools.yang2sources.spi.ModuleResourceResolver)}</li>
+ * <li>Call {@link FileGenerator#generateFiles(EffectiveModelContext, Set, ModuleResourceResolver)}</li>
* </ol>
* </li>
* </ol>
public final class YangToSourcesMojo extends AbstractMojo {
public static final String PLUGIN_NAME = "org.opendaylight.yangtools:yang-maven-plugin";
- /**
- * Classes implementing {@link BasicCodeGenerator} interface. An instance will be
- * created out of every class using default constructor. Method {@link
- * BasicCodeGenerator#generateSources(EffectiveModelContext, File, Set)} will be called on every instance.
- */
- @Parameter(required = false)
- private CodeGeneratorArg[] codeGenerators;
-
/**
* {@link FileGenerator} instances resolved via ServiceLoader can hold additional configuration, which details
* how they are executed.
@VisibleForTesting
YangToSourcesMojo(final YangToSourcesProcessor processor) {
- this.yangToSourcesProcessor = processor;
+ yangToSourcesProcessor = processor;
}
public void setProject(final MavenProject project) {
Collection<File> excludedFiles = processExcludeFiles(excludeFiles, yangFilesRootFile);
yangToSourcesProcessor = new YangToSourcesProcessor(buildContext, yangFilesRootFile,
- excludedFiles, arrayToList(codeGenerators), arrayToList(fileGenerators), project,
- inspectDependencies);
+ excludedFiles, arrayToList(fileGenerators), project, inspectDependencies);
}
yangToSourcesProcessor.conditionalExecute("true".equals(yangSkip));
}
import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
-import org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonatype.plexus.build.incremental.BuildContext;
private final YangParserFactory parserFactory;
private final File yangFilesRootDir;
private final Set<File> excludedFiles;
- private final List<CodeGeneratorArg> codeGeneratorArgs;
private final Map<String, FileGeneratorArg> fileGeneratorArgs;
private final MavenProject project;
private final boolean inspectDependencies;
private final YangProvider yangProvider;
private YangToSourcesProcessor(final BuildContext buildContext, final File yangFilesRootDir,
- final Collection<File> excludedFiles, final List<CodeGeneratorArg> codeGeneratorArgs,
- final List<FileGeneratorArg> fileGeneratorsArgs,
+ final Collection<File> excludedFiles, final List<FileGeneratorArg> fileGeneratorsArgs,
final MavenProject project, final boolean inspectDependencies, final YangProvider yangProvider) {
this.buildContext = requireNonNull(buildContext, "buildContext");
this.yangFilesRootDir = requireNonNull(yangFilesRootDir, "yangFilesRootDir");
this.excludedFiles = ImmutableSet.copyOf(excludedFiles);
- this.codeGeneratorArgs = ImmutableList.copyOf(codeGeneratorArgs);
- fileGeneratorArgs = Maps.uniqueIndex(fileGeneratorsArgs, FileGeneratorArg::getIdentifier);
+ //FIXME multiple FileGeneratorArg entries of same identifier became one here
+ this.fileGeneratorArgs = Maps.uniqueIndex(fileGeneratorsArgs, FileGeneratorArg::getIdentifier);
this.project = requireNonNull(project);
this.inspectDependencies = inspectDependencies;
this.yangProvider = requireNonNull(yangProvider);
@VisibleForTesting
YangToSourcesProcessor(final File yangFilesRootDir, final Collection<File> excludedFiles,
- final List<CodeGeneratorArg> codeGenerators, final MavenProject project, final boolean inspectDependencies,
+ final List<FileGeneratorArg> fileGenerators, final MavenProject project, final boolean inspectDependencies,
final YangProvider yangProvider) {
- this(new DefaultBuildContext(), yangFilesRootDir, excludedFiles, codeGenerators, ImmutableList.of(),
+ this(new DefaultBuildContext(), yangFilesRootDir, excludedFiles, ImmutableList.of(),
project, inspectDependencies, yangProvider);
}
YangToSourcesProcessor(final BuildContext buildContext, final File yangFilesRootDir,
- final Collection<File> excludedFiles, final List<CodeGeneratorArg> codeGenerators,
- final List<FileGeneratorArg> fileGenerators, final MavenProject project,
- final boolean inspectDependencies) {
- this(buildContext, yangFilesRootDir, excludedFiles, codeGenerators, fileGenerators, project,
- inspectDependencies, YangProvider.getInstance());
+ final Collection<File> excludedFiles, final List<FileGeneratorArg> fileGenerators,
+ final MavenProject project, final boolean inspectDependencies) {
+ this(buildContext, yangFilesRootDir, excludedFiles, fileGenerators, project, inspectDependencies,
+ YangProvider.getInstance());
}
public void execute() throws MojoExecutionException, MojoFailureException {
.map(file -> {
final YangTextSchemaSource textSource = YangTextSchemaSource.forPath(file.toPath());
try {
- return Map.entry(textSource,TextToIRTransformer.transformText(textSource));
+ return Map.entry(textSource, TextToIRTransformer.transformText(textSource));
} catch (YangSyntaxErrorException | IOException e) {
throw new IllegalArgumentException("Failed to parse " + file, e);
}
}
private List<GeneratorTaskFactory> instantiateGenerators() throws MojoExecutionException, MojoFailureException {
- final List<GeneratorTaskFactory> generators = new ArrayList<>(codeGeneratorArgs.size());
- for (CodeGeneratorArg arg : codeGeneratorArgs) {
- generators.add(CodeGeneratorTaskFactory.create(arg));
- LOG.info("{} Code generator instantiated from {}", LOG_PREFIX, arg.getCodeGeneratorClass());
- }
-
// Search for available FileGenerator implementations
final Map<String, FileGeneratorFactory> factories = Maps.uniqueIndex(
ServiceLoader.load(FileGeneratorFactory.class), FileGeneratorFactory::getIdentifier);
- // Assign instantiate FileGenerators with appropriate configurate
+ // FIXME: iterate over fileGeneratorArg instances (configuration), not factories (environment)
+ // Assign instantiate FileGenerators with appropriate configuration
+ final List<GeneratorTaskFactory> generators = new ArrayList<>(factories.size());
for (Entry<String, FileGeneratorFactory> entry : factories.entrySet()) {
final String id = entry.getKey();
FileGeneratorArg arg = fileGeneratorArgs.get(id);
LOG.info("{} Code generator {} instantiated", LOG_PREFIX, id);
}
+ // Notify if no factory found for defined identifiers
+ fileGeneratorArgs.keySet().forEach(
+ fileGenIdentifier -> {
+ if (!factories.containsKey(fileGenIdentifier)) {
+ LOG.warn("{} No generator found for identifier {}", LOG_PREFIX, fileGenIdentifier);
+ }
+ }
+ );
+
return generators;
}
package org.opendaylight.yangtools.yang2sources.plugin;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doNothing;
+import static org.mockito.ArgumentMatchers.anyCollection;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
-import java.io.File;
+import com.google.common.collect.Iterators;
import java.io.IOException;
-import java.util.Collection;
-import java.util.Collections;
+import java.util.List;
+import java.util.ServiceLoader;
import org.apache.maven.model.Build;
import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.MockedStatic;
import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.yangtools.plugin.generator.api.FileGenerator;
+import org.opendaylight.yangtools.plugin.generator.api.FileGeneratorException;
+import org.opendaylight.yangtools.plugin.generator.api.FileGeneratorFactory;
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
+@RunWith(MockitoJUnitRunner.Silent.class)
public abstract class AbstractCodeGeneratorTest {
@Mock
MavenProject project;
@Mock
private Plugin plugin;
- final YangToSourcesMojo setupMojo(final YangToSourcesProcessor processor) throws IOException {
+ final YangToSourcesMojo setupMojo(final YangToSourcesProcessor processor) {
doReturn("target/").when(build).getDirectory();
- doReturn(new File("")).when(project).getBasedir();
+// doReturn(new File("")).when(project).getBasedir();
doReturn(build).when(project).getBuild();
- doReturn(Collections.emptyList()).when(plugin).getDependencies();
+ doReturn(List.of()).when(plugin).getDependencies();
doReturn(plugin).when(project).getPlugin(YangToSourcesMojo.PLUGIN_NAME);
- doNothing().when(yangProvider).addYangsToMetaInf(any(MavenProject.class), any(Collection.class));
+ try {
+ lenient().doNothing().when(yangProvider).addYangsToMetaInf(any(MavenProject.class), anyCollection());
+ } catch (IOException e) {
+ throw new AssertionError(e);
+ }
final YangToSourcesMojo mojo = new YangToSourcesMojo(processor);
mojo.setProject(project);
return mojo;
}
+
+ @SuppressWarnings({ "rawtypes", "checkstyle:illegalCatch" })
+ final void assertMojoExecution(final YangToSourcesProcessor processor, final Prepare prepare, final Verify verify) {
+ try (MockedStatic<ServiceLoader> staticLoader = mockStatic(ServiceLoader.class)) {
+ final FileGenerator generator = mock(FileGenerator.class);
+ doCallRealMethod().when(generator).importResolutionMode();
+
+ final FileGeneratorFactory factory = mock(FileGeneratorFactory.class);
+ doReturn("mockGenerator").when(factory).getIdentifier();
+
+ try {
+ doReturn(generator).when(factory).newFileGenerator(anyMap());
+ } catch (FileGeneratorException e) {
+ throw new AssertionError(e);
+ }
+
+ final ServiceLoader<?> loader = mock(ServiceLoader.class);
+ doReturn(Iterators.singletonIterator(factory)).when(loader).iterator();
+ staticLoader.when(() -> ServiceLoader.load(FileGeneratorFactory.class)).thenReturn(loader);
+
+ final YangToSourcesMojo mojo = setupMojo(processor);
+ try {
+ prepare.prepare(generator);
+ mojo.execute();
+ verify.verify(generator);
+ } catch (Exception e) {
+ throw new AssertionError(e);
+ }
+ }
+ }
+
+ @FunctionalInterface
+ interface Prepare {
+ void prepare(FileGenerator mock) throws Exception;
+ }
+
+ @FunctionalInterface
+ interface Verify {
+ void verify(FileGenerator mock) throws Exception;
+ }
}
package org.opendaylight.yangtools.yang2sources.plugin;
import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doAnswer;
-import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableTable;
import com.google.common.collect.Iterables;
import com.google.common.io.Resources;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
-import java.util.Collection;
import java.util.List;
-import java.util.Map;
import java.util.Optional;
-import java.util.Set;
import org.apache.maven.plugin.AbstractMojoExecutionException;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.yangtools.plugin.generator.api.ModuleResourceResolver;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
-import org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg;
-import org.opendaylight.yangtools.yang2sources.spi.BasicCodeGenerator;
-import org.opendaylight.yangtools.yang2sources.spi.ModuleResourceResolver;
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class FilenameResolutionTest extends AbstractCodeGeneratorTest {
@Test
public void testResolveSubmoduleResource() throws URISyntaxException, AbstractMojoExecutionException, IOException {
- setupMojo(new YangToSourcesProcessor(
- new File(Resources.getResource(FilenameResolutionTest.class, "/filename").toURI()), ImmutableList.of(),
- List.of(new CodeGeneratorArg(Generator.class.getName(), "outputDir")), project, false, yangProvider))
- .execute();
- }
-
- public static final class Generator implements BasicCodeGenerator {
- @Override
- public Collection<File> generateSources(final EffectiveModelContext context, final File outputBaseDir,
- final Set<Module> currentModules, final ModuleResourceResolver moduleResourcePathResolver) {
- final var module = Iterables.getOnlyElement(context.getModules());
- assertEquals(Optional.of("/META-INF/yang/foo@2020-10-13.yang"),
- moduleResourcePathResolver.findModuleResourcePath(module, YangTextSchemaSource.class));
+ assertMojoExecution(new YangToSourcesProcessor(
+ new File(Resources.getResource(FilenameResolutionTest.class, "/filename").toURI()), List.of(),
+ List.of(new FileGeneratorArg("mockGenerator")), project, false, yangProvider), mock -> {
+ doAnswer(invocation -> {
+ final EffectiveModelContext context = invocation.getArgument(0);
+ final ModuleResourceResolver resolver = invocation.getArgument(2);
- final var submodule = Iterables.getOnlyElement(module.getSubmodules());
- assertEquals(Optional.of("/META-INF/yang/foo-submodule@2020-10-12.yang"),
- moduleResourcePathResolver.findModuleResourcePath(submodule, YangTextSchemaSource.class));
- return List.of();
- }
+ final var module = Iterables.getOnlyElement(context.getModules());
+ assertEquals(Optional.of("/META-INF/yang/foo@2020-10-13.yang"),
+ resolver.findModuleResourcePath(module, YangTextSchemaSource.class));
- @Override
- public void setAdditionalConfig(final Map<String, String> additionalConfiguration) {
- // Noop
- }
+ final var submodule = Iterables.getOnlyElement(module.getSubmodules());
+ assertEquals(Optional.of("/META-INF/yang/foo-submodule@2020-10-12.yang"),
+ resolver.findModuleResourcePath(submodule, YangTextSchemaSource.class));
- @Override
- public void setResourceBaseDir(final File resourceBaseDir) {
- // Noop
- }
+ return ImmutableTable.of();
+ }).when(mock).generateFiles(any(), any(), any());
+ }, mock -> { });
}
}
*/
package org.opendaylight.yangtools.yang2sources.plugin;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
+import com.google.common.collect.ImmutableTable;
import com.google.common.io.Resources;
import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import org.apache.maven.project.MavenProject;
-import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg;
-import org.opendaylight.yangtools.yang2sources.spi.BasicCodeGenerator;
-import org.opendaylight.yangtools.yang2sources.spi.MavenProjectAware;
-import org.opendaylight.yangtools.yang2sources.spi.ModuleResourceResolver;
public class GenerateSourcesTest extends AbstractCodeGeneratorTest {
- private YangToSourcesMojo mojo;
- private File outDir;
-
- @Before
- public void setUp() throws Exception {
- outDir = new File("/outputDir");
- this.mojo = setupMojo(new YangToSourcesProcessor(
- new File(Resources.getResource(GenerateSourcesTest.class, "/yang").toURI()), List.of(),
- List.of(new CodeGeneratorArg(GeneratorMock.class.getName(), "outputDir")), this.project, false,
- yangProvider));
- }
-
@Test
public void test() throws Exception {
- mojo.execute();
- assertEquals(outDir, GeneratorMock.outputDir);
- assertEquals(project, GeneratorMock.project);
- assertTrue(GeneratorMock.additionalCfg.isEmpty());
- assertThat(GeneratorMock.resourceBaseDir.toString(), containsString("target" + File.separator
- + "generated-sources" + File.separator + "spi"));
- }
-
- public static class GeneratorMock implements BasicCodeGenerator, MavenProjectAware {
- private static int called = 0;
- private static File outputDir;
- private static Map<String, String> additionalCfg;
- private static File resourceBaseDir;
- private static MavenProject project;
-
- @Override
- public void setAdditionalConfig(final Map<String, String> additionalConfiguration) {
- GeneratorMock.additionalCfg = additionalConfiguration;
- }
-
- @Override
- public void setResourceBaseDir(final File resourceBaseDir) {
- GeneratorMock.resourceBaseDir = resourceBaseDir;
-
- }
-
- @Override
- public void setMavenProject(final MavenProject mavenProject) {
- GeneratorMock.project = mavenProject;
- }
-
- @Override
- public Collection<File> generateSources(final EffectiveModelContext context, final File outputBaseDir,
- final Set<Module> currentModules, final ModuleResourceResolver moduleResourcePathResolver)
- throws IOException {
- called++;
- outputDir = outputBaseDir;
- return new ArrayList<>();
- }
+ assertMojoExecution(new YangToSourcesProcessor(
+ new File(Resources.getResource(GenerateSourcesTest.class, "/yang").toURI()), List.of(),
+ List.of(new FileGeneratorArg("mockGenerator")), project, false, yangProvider),
+ mock -> {
+ doReturn(ImmutableTable.of()).when(mock).generateFiles(any(), any(), any());
+ },
+ mock -> {
+ verify(mock).generateFiles(any(), any(), any());
+ });
}
}
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
-import com.google.common.collect.ImmutableList;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.maven.model.Build;
import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
-import org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg;
-import org.opendaylight.yangtools.yang2sources.plugin.GenerateSourcesTest.GeneratorMock;
import org.sonatype.plexus.build.incremental.DefaultBuildContext;
@RunWith(MockitoJUnitRunner.class)
public class YangToSourcesMojoTest {
-
- private YangToSourcesMojo mojo;
-
@Mock
private MavenProject project;
-
@Mock
private Plugin plugin;
- private YangToSourcesProcessor proc;
-
@Test
public void yangToSourceMojoTest() throws Exception {
doReturn(plugin).when(project).getPlugin(YangToSourcesMojo.PLUGIN_NAME);
- this.mojo = new YangToSourcesMojo();
- this.mojo.setProject(project);
- this.mojo.buildContext = new DefaultBuildContext();
- this.mojo.execute();
- assertNotNull(this.mojo);
+ YangToSourcesMojo mojo = new YangToSourcesMojo();
+ mojo.setProject(project);
+ mojo.buildContext = new DefaultBuildContext();
+ mojo.execute();
+ assertNotNull(mojo);
final YangToSourcesProcessor processor = Mockito.mock(YangToSourcesProcessor.class);
- this.mojo = new YangToSourcesMojo(processor);
- this.mojo.setProject(project);
- this.mojo.execute();
+ mojo = new YangToSourcesMojo(processor);
+ mojo.setProject(project);
+ mojo.execute();
verify(processor).conditionalExecute(false);
}
-
- @Test
- public void test() throws Exception {
- prepareProcessor();
- assertNotNull(proc);
- this.mojo = new YangToSourcesMojo(proc);
- this.mojo.setProject(project);
- this.mojo.execute();
- assertNotNull(mojo);
- }
-
- private void prepareProcessor() {
- final File file = new File(getClass().getResource("/yang").getFile());
- final File excludedYang = new File(getClass().getResource("/yang/excluded-file.yang").getFile());
- final String path = file.getPath();
- final List<CodeGeneratorArg> codeGenerators = new ArrayList<>();
- final CodeGeneratorArg codeGeneratorArg = new CodeGeneratorArg(GeneratorMock.class.getName(),
- "target/YangToSourcesMojoTest-outputBaseDir");
- codeGenerators.add(codeGeneratorArg);
- final Build build = new Build();
- build.setDirectory("testDir");
- doReturn(build).when(project).getBuild();
- final boolean dependencies = true;
- this.proc = new YangToSourcesProcessor(file, ImmutableList.of(excludedYang), codeGenerators,
- project, dependencies, YangProvider.getInstance());
- }
}
*/
package org.opendaylight.yangtools.yang2sources.plugin;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.doReturn;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doAnswer;
-import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableTable;
import java.io.File;
import java.util.List;
-import org.apache.maven.model.Build;
-import org.apache.maven.project.MavenProject;
-import org.junit.Before;
+import java.util.Set;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg;
-import org.opendaylight.yangtools.yang2sources.plugin.GenerateSourcesTest.GeneratorMock;
+import org.opendaylight.yangtools.yang.model.api.Module;
@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class YangToSourcesProcessorTest {
- @Mock
- public File buildContext;
- @Mock
- public MavenProject project;
- @Mock
- public YangProvider inspectDependencies;
-
- private final boolean dep = false;
- private List<File> yangFilesRootDir;
-
- @Before
- public void before() {
- yangFilesRootDir = ImmutableList.of(buildContext);
- }
+public class YangToSourcesProcessorTest extends AbstractCodeGeneratorTest {
+ private final File file = new File(getClass().getResource("/yang").getFile());
@Test
- public void yangToSourcesProcessotTest() {
- YangToSourcesProcessor processor = new YangToSourcesProcessor(buildContext, yangFilesRootDir,
- ImmutableList.of(), project, dep, inspectDependencies);
- assertNotNull(processor);
-
- processor = new YangToSourcesProcessor(buildContext, yangFilesRootDir, ImmutableList.of(), project, dep,
- inspectDependencies);
- assertNotNull(processor);
+ public void basicTest() {
+ assertMojoExecution(new YangToSourcesProcessor(file, List.of(),
+ List.of(new FileGeneratorArg("mockGenerator")), project, true,
+ YangProvider.getInstance()), mock -> {
+ doAnswer(invocation -> {
+ final Set<Module> localModules = invocation.getArgument(1);
+ assertEquals(2, localModules.size());
+ return ImmutableTable.of();
+ }).when(mock).generateFiles(any(), any(), any());
+ }, mock -> { });
}
@Test
- public void test() throws Exception {
- final File file = new File(getClass().getResource("/yang").getFile());
+ public void excludeFilesTest() throws Exception {
final File excludedYang = new File(getClass().getResource("/yang/excluded-file.yang").getFile());
- final CodeGeneratorArg codeGeneratorArg = new CodeGeneratorArg(GeneratorMock.class.getName(),
- "target/YangToSourcesProcessorTest-outputBaseDir");
- final List<CodeGeneratorArg> codeGenerators = ImmutableList.of(codeGeneratorArg);
- final Build build = new Build();
- build.setDirectory("foo");
- doReturn(build).when(project).getBuild();
- final boolean dependencies = true;
- final YangToSourcesProcessor proc = new YangToSourcesProcessor(file, ImmutableList.of(excludedYang),
- codeGenerators, project, dependencies, YangProvider.getInstance());
- assertNotNull(proc);
- proc.execute();
+
+ assertMojoExecution(new YangToSourcesProcessor(file, List.of(excludedYang),
+ List.of(new FileGeneratorArg("mockGenerator")), project, true,
+ YangProvider.getInstance()), mock -> {
+ doAnswer(invocation -> {
+ final Set<Module> localModules = invocation.getArgument(1);
+ assertEquals(1, localModules.size());
+ assertEquals("mock", localModules.iterator().next().getName());
+ return ImmutableTable.of();
+ }).when(mock).generateFiles(any(), any(), any());
+ }, mock -> { });
}
}
--- /dev/null
+mock-maker-inline