*/
package org.opendaylight.yangtools.yang2sources.plugin;
-import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.VisibleForTesting;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.NoSuchElementException;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.function.Function;
private static final YangParserFactory DEFAULT_PARSER_FACTORY;
static {
- final Iterator<YangParserFactory> it = ServiceLoader.load(YangParserFactory.class).iterator();
- checkState(it.hasNext(), "Failed to find a YangParserFactory implementation");
- DEFAULT_PARSER_FACTORY = it.next();
+ try {
+ DEFAULT_PARSER_FACTORY = ServiceLoader.load(YangParserFactory.class).iterator().next();
+ } catch (NoSuchElementException e) {
+ throw new IllegalStateException("Failed to find a YangParserFactory implementation", e);
+ }
}
private static final String META_INF_STR = "META-INF";
}
@VisibleForTesting
- YangToSourcesProcessor(final File yangFilesRootDir, final Collection<File> excludedFiles,
- final List<FileGeneratorArg> fileGenerators, final MavenProject project, final boolean inspectDependencies,
- final YangProvider yangProvider) {
- this(new DefaultBuildContext(), yangFilesRootDir, excludedFiles, ImmutableList.of(),
- project, inspectDependencies, yangProvider);
+ YangToSourcesProcessor(final File yangFilesRootDir, final List<FileGeneratorArg> fileGenerators,
+ final MavenProject project, final YangProvider yangProvider) {
+ this(new DefaultBuildContext(), yangFilesRootDir, List.of(), List.of(), project, false, yangProvider);
}
YangToSourcesProcessor(final BuildContext buildContext, final File yangFilesRootDir,
}
LOG.info("{} Found {} dependencies in {}", LOG_PREFIX, dependencies.size(), watch);
} else {
- dependencies = ImmutableList.of();
+ dependencies = List.of();
}
/*
import java.util.Set;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.sonatype.plexus.build.incremental.DefaultBuildContext;
+import org.sonatype.plexus.build.incremental.BuildContext;
@ExtendWith(MockitoExtension.class)
class YangToSourcesProcessorTest extends AbstractCodeGeneratorTest {
+ @Mock
+ private BuildContext buildContext;
+
private final File file = new File(getClass().getResource("/yang").getFile());
@Test
void basicTest() {
assertMojoExecution(
- new YangToSourcesProcessor(new DefaultBuildContext(), file, List.of(),
+ new YangToSourcesProcessor(buildContext, file, List.of(),
List.of(new FileGeneratorArg("mockGenerator")), project, true),
mock -> {
doAnswer(invocation -> {
final var excludedYang = new File(getClass().getResource("/yang/excluded-file.yang").getFile());
assertMojoExecution(
- new YangToSourcesProcessor(new DefaultBuildContext(), file, List.of(excludedYang),
+ new YangToSourcesProcessor(buildContext, file, List.of(excludedYang),
List.of(new FileGeneratorArg("mockGenerator")), project, true),
mock -> {
doAnswer(invocation -> {