Move YangTextSource 55/109655/10
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 7 Jan 2024 17:28:58 +0000 (18:28 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 7 Jan 2024 18:02:03 +0000 (19:02 +0100)
YangTextSource is something defined in RFC6020, really, expose this
construct at yang-model-api level.

JIRA: YANGTOOLS-1561
Change-Id: Ic1f0d5c37fe66d216749cfbafe0efa798bcd83f9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
28 files changed:
model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/source/YangTextSource.java [moved from model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/source/YangTextSource.java with 62% similarity]
model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/source/AbstractYangTextSource.java [new file with mode: 0644]
model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/source/DelegatedYangTextSource.java
model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/source/DelegatedYinTextSource.java
model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/source/FileYangTextSource.java
model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/source/StringYangTextSource.java
model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/source/URLYangTextSource.java
parser/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/DefaultYangParser.java
parser/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/YangTextSchemaContextResolver.java
parser/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/SharedEffectiveModelContextFactoryTest.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/repo/TextToIRTransformer.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/repo/YangIRSourceInfoExtractor.java
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/repo/YangStatementStreamSource.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/TestUtils.java
parser/yang-test-util/src/main/java/org/opendaylight/yangtools/yang/test/util/LiteralYangTextSource.java [deleted file]
parser/yang-test-util/src/main/java/org/opendaylight/yangtools/yang/test/util/YangParserTestUtils.java
plugin/plugin-generator-api/src/main/java/org/opendaylight/yangtools/plugin/generator/api/ModuleResourceResolver.java
plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/ContextHolder.java
plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/ProcessorModuleReactor.java
plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/ScannedDependency.java
plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangProvider.java
plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java
plugin/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/FilenameResolutionTest.java
yang/yang-repo-fs/src/main/java/org/opendaylight/yangtools/yang/model/repo/fs/FilesystemSchemaSourceCache.java
yang/yang-repo-fs/src/test/java/org/opendaylight/yangtools/yang/model/repo/fs/FilesystemSchemaSourceCacheIntegrationTest.java
yang/yang-repo-fs/src/test/java/org/opendaylight/yangtools/yang/model/repo/fs/FilesystemSchemaSourceCacheTest.java
yang/yang-repo-spi/src/test/java/org/opendaylight/yangtools/yang/model/repo/spi/GuavaSchemaSourceCacheTest.java
yang/yang-repo-spi/src/test/java/org/opendaylight/yangtools/yang/model/repo/spi/SoftSchemaSourceCacheTest.java

similarity index 62%
rename from model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/source/YangTextSource.java
rename to model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/source/YangTextSource.java
index 785a611aa8ae7e03ccac31a30c6dd628767e5755..739bca2d33ff208244b7f54eb73b4f6c021a8439 100644 (file)
@@ -5,38 +5,24 @@
  * 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.yang.model.spi.source;
-
-import static java.util.Objects.requireNonNull;
+package org.opendaylight.yangtools.yang.model.api.source;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.io.CharSource;
-import java.io.InputStream;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.api.source.YangSourceRepresentation;
+import java.io.Reader;
+import org.eclipse.jdt.annotation.NonNullByDefault;
 
 /**
- * YANG text schema source representation. Exposes an RFC6020 or RFC7950 text representation as an {@link InputStream}.
+ * YANG text schema source representation. Exposes an RFC6020 or RFC7950 text representation as a {@link Reader}.
  */
+@NonNullByDefault
 public abstract class YangTextSource extends CharSource implements YangSourceRepresentation {
-    private final @NonNull SourceIdentifier sourceId;
-
-    protected YangTextSource(final SourceIdentifier sourceId) {
-        this.sourceId = requireNonNull(sourceId);
-    }
-
     @Override
     public final Class<YangTextSource> getType() {
         return YangTextSource.class;
     }
 
-    @Override
-    public final SourceIdentifier sourceId() {
-        return sourceId;
-    }
-
     @Override
     public final String toString() {
         return addToStringAttributes(MoreObjects.toStringHelper(this).omitNullValues()).toString();
@@ -51,7 +37,7 @@ public abstract class YangTextSource extends CharSource implements YangSourceRep
      * @param toStringHelper ToStringHelper onto the attributes can be added
      * @return ToStringHelper supplied as input argument.
      */
-    protected ToStringHelper addToStringAttributes(final @NonNull ToStringHelper toStringHelper) {
-        return toStringHelper.add("identifier", sourceId);
+    protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+        return toStringHelper.add("identifier", sourceId());
     }
 }
diff --git a/model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/source/AbstractYangTextSource.java b/model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/source/AbstractYangTextSource.java
new file mode 100644 (file)
index 0000000..d8706f7
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2014 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.yang.model.spi.source;
+
+import static java.util.Objects.requireNonNull;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.yangtools.concepts.Delegator;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
+
+/**
+ * Abstract base class for implementing {@link YangTextSource}s with {@link Delegator}.
+ */
+@NonNullByDefault
+abstract class AbstractYangTextSource<T> extends YangTextSource implements Delegator<T> {
+    private final SourceIdentifier sourceId;
+    private final T delegate;
+
+    AbstractYangTextSource(final SourceIdentifier sourceId, final T delegate) {
+        this.sourceId = requireNonNull(sourceId);
+        this.delegate = requireNonNull(delegate);
+    }
+
+    @Override
+    public final SourceIdentifier sourceId() {
+        return sourceId;
+    }
+
+    @Override
+    public final T getDelegate() {
+        return delegate;
+    }
+}
index d965c8243afa3c31a7d02df9a1b8e4b8bc770525..d503262704e687b5859be1e05573e6926b5038e0 100644 (file)
@@ -7,24 +7,20 @@
  */
 package org.opendaylight.yangtools.yang.model.spi.source;
 
-import static java.util.Objects.requireNonNull;
-
 import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.io.CharSource;
 import java.io.IOException;
 import java.io.Reader;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.opendaylight.yangtools.concepts.Delegator;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
 
 /**
  * A {@link YangTextSource} delegating to a {@link CharSource}.
  */
 @NonNullByDefault
-public class DelegatedYangTextSource extends YangTextSource implements Delegator<CharSource> {
-    private final CharSource delegate;
-
+public class DelegatedYangTextSource extends AbstractYangTextSource<CharSource> {
     /**
      * Default constructor.
      *
@@ -32,27 +28,21 @@ public class DelegatedYangTextSource extends YangTextSource implements Delegator
      * @param delegate Backing {@link CharSource} instance
      */
     public DelegatedYangTextSource(final SourceIdentifier sourceId, final CharSource delegate) {
-        super(sourceId);
-        this.delegate = requireNonNull(delegate);
-    }
-
-    @Override
-    public final CharSource getDelegate() {
-        return delegate;
+        super(sourceId, delegate);
     }
 
     @Override
     public final Reader openStream() throws IOException {
-        return delegate.openStream();
+        return getDelegate().openStream();
     }
 
     @Override
     public final @NonNull String symbolicName() {
-        return "[" + delegate.toString() + "]";
+        return "[" + getDelegate().toString() + "]";
     }
 
     @Override
     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
-        return super.addToStringAttributes(toStringHelper).add("delegate", delegate);
+        return super.addToStringAttributes(toStringHelper).add("delegate", getDelegate());
     }
 }
index 9b973f534a3a43a126b7100f88065545c4bc3782..fefa414e6334cd387861eb7bb78a914f15452656 100644 (file)
@@ -14,9 +14,10 @@ import java.io.InputStream;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YinTextSource;
 
 /**
- * A {@link YangTextSource} delegating to a {@link ByteSource}.
+ * A {@link YinTextSource} delegating to a {@link ByteSource}.
  */
 @NonNullByDefault
 public class DelegatedYinTextSource extends AbstractYinTextSource<ByteSource> {
index 2b7ca4b058bd46629e313dc0fdefadcee3ccbe8c..57e4caac93ef2864f3a64996541672785d4ff201 100644 (file)
@@ -19,15 +19,14 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.opendaylight.yangtools.concepts.Delegator;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
 
 /**
  * A {@link YangTextSource} backed by a file.
  */
 @NonNullByDefault
-public class FileYangTextSource extends YangTextSource implements Delegator<Path> {
-    private final Path path;
+public class FileYangTextSource extends AbstractYangTextSource<Path> {
     private final Charset charset;
 
     /**
@@ -40,11 +39,10 @@ public class FileYangTextSource extends YangTextSource implements Delegator<Path
      * @throws IllegalArgumentException if the supplied path is not a regular file
      */
     public FileYangTextSource(final SourceIdentifier sourceId, final Path path, final Charset charset) {
-        super(sourceId);
+        super(sourceId, path);
         if (!Files.isRegularFile(path)) {
             throw new IllegalArgumentException("Supplied path " + path + " is not a regular file");
         }
-        this.path = requireNonNull(path);
         this.charset = requireNonNull(charset);
     }
 
@@ -59,25 +57,20 @@ public class FileYangTextSource extends YangTextSource implements Delegator<Path
         this(SourceIdentifier.ofYangFileName(path.toFile().getName()), path, StandardCharsets.UTF_8);
     }
 
-    @Override
-    public final Path getDelegate() {
-        return path;
-    }
-
     @Override
     public final Reader openStream() throws IOException {
-        return new InputStreamReader(Files.newInputStream(path), charset);
+        return new InputStreamReader(Files.newInputStream(getDelegate()), charset);
     }
 
     @Override
     public final @NonNull String symbolicName() {
         // FIXME: NEXT: this is forcing internal normalization. I think this boils down to providing Path back, which
         //        is essentially getDelegate() anyway. Perhaps expose it as PathAware?
-        return path.toString();
+        return getDelegate().toString();
     }
 
     @Override
     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
-        return super.addToStringAttributes(toStringHelper).add("path", path);
+        return super.addToStringAttributes(toStringHelper).add("path", getDelegate());
     }
 }
index a5fb641072106c579dd9432a98bcafaf7672a7cd..689733ad8fb7d279c9ff05b1abe89cd6073fc647 100644 (file)
@@ -7,20 +7,17 @@
  */
 package org.opendaylight.yangtools.yang.model.spi.source;
 
-import static java.util.Objects.requireNonNull;
-
 import java.io.Reader;
 import java.io.StringReader;
-import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
 
 /**
  * A {@link YangTextSource} with content readily available.
  */
-public class StringYangTextSource extends YangTextSource {
+public class StringYangTextSource extends AbstractYangTextSource<String> {
     private final @Nullable String symbolicName;
-    private final @NonNull String content;
 
     public StringYangTextSource(final SourceIdentifier sourceId, final String content) {
         this(sourceId, content, null);
@@ -28,8 +25,7 @@ public class StringYangTextSource extends YangTextSource {
 
     public StringYangTextSource(final SourceIdentifier sourceId, final String content,
             final @Nullable String symbolicName) {
-        super(sourceId);
-        this.content = requireNonNull(content);
+        super(sourceId, content);
         this.symbolicName = symbolicName;
     }
 
@@ -40,6 +36,6 @@ public class StringYangTextSource extends YangTextSource {
 
     @Override
     public final Reader openStream() {
-        return new StringReader(content);
+        return new StringReader(getDelegate());
     }
 }
index e4cdb1ef7023dd9f7c97cf63adb5a58760ced65a..ca5dfbc715b413fd09893b2f0b168a2a5406dfbb 100644 (file)
@@ -18,20 +18,18 @@ import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.opendaylight.yangtools.concepts.Delegator;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
 
 /**
  * A {@link YangTextSource} backed by a {@link URL}.
  */
 @NonNullByDefault
-public class URLYangTextSource extends YangTextSource implements Delegator<URL> {
-    private final URL url;
+public class URLYangTextSource extends AbstractYangTextSource<URL> {
     private final Charset charset;
 
     public URLYangTextSource(final SourceIdentifier sourceId, final URL url, final Charset charset) {
-        super(sourceId);
-        this.url = requireNonNull(url);
+        super(sourceId, url);
         this.charset = requireNonNull(charset);
     }
 
@@ -47,22 +45,17 @@ public class URLYangTextSource extends YangTextSource implements Delegator<URL>
 
     @Override
     public final Reader openStream() throws IOException {
-        return new InputStreamReader(url.openStream(), charset);
+        return new InputStreamReader(getDelegate().openStream(), charset);
     }
 
     @Override
     public final @NonNull String symbolicName() {
-        return url.toString();
-    }
-
-    @Override
-    public final URL getDelegate() {
-        return url;
+        return getDelegate().toString();
     }
 
     @Override
     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
-        return super.addToStringAttributes(toStringHelper).add("url", url);
+        return super.addToStringAttributes(toStringHelper).add("url", getDelegate());
     }
 
     private static String extractFileName(final String path) {
index b2c60ccd41131d8257d5fd118e7e37479098ed19..b90eab781d628847b24f88d8b1355a40e65f5bfc 100644 (file)
@@ -19,10 +19,10 @@ import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
 import org.opendaylight.yangtools.yang.model.api.source.YinTextSource;
 import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
 import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
 import org.opendaylight.yangtools.yang.model.spi.source.YinDomSource;
 import org.opendaylight.yangtools.yang.model.spi.source.YinXmlSource;
 import org.opendaylight.yangtools.yang.parser.api.YangParser;
index 850928fff156607dd523ad090fd5cfdd407bd3c8..d8e50bd385b0a9c5ce757d5274596a856b88cf17 100644 (file)
@@ -38,6 +38,7 @@ import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
 import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
 import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
@@ -53,7 +54,6 @@ import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
 import org.opendaylight.yangtools.yang.model.spi.source.DelegatedYangTextSource;
 import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
 import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
 import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
 import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
index 26a6953ffc3991facd8a55940baea786583dc8c5..d5b1fcbe2f527959525f24d0e18f093075b57886 100644 (file)
@@ -19,13 +19,13 @@ import java.util.concurrent.ExecutionException;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
 import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
 import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
 import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
 import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
 
 class SharedEffectiveModelContextFactoryTest {
index 01c65c38ca854d3720d6c414cde0f3abf27bf3a5..02049b03e8dad954dea2d3f68dc2abf8b5371177 100644 (file)
@@ -11,11 +11,11 @@ import com.google.common.annotations.Beta;
 import com.google.common.util.concurrent.Futures;
 import java.io.IOException;
 import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceTransformer;
 import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
 import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.parser.rfc7950.antlr.IRSupport;
 
index 26787499b6f735c31b2e7c81cf8e8be26d931d31..815f40e21c4f1f9b4d8117affcb93306202e6527 100644 (file)
@@ -22,10 +22,10 @@ import org.opendaylight.yangtools.yang.model.api.source.SourceDependency.Belongs
 import org.opendaylight.yangtools.yang.model.api.source.SourceDependency.Import;
 import org.opendaylight.yangtools.yang.model.api.source.SourceDependency.Include;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
 import org.opendaylight.yangtools.yang.model.spi.meta.StatementDeclarations;
 import org.opendaylight.yangtools.yang.model.spi.source.SourceInfo;
 import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
 import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
 
 /**
index 89c6e819d2127634645466570514c83f7985ea5f..a33af5692a0000c06760e90ecfd2fd3e19946d33 100644 (file)
@@ -24,8 +24,8 @@ import org.opendaylight.yangtools.yang.ir.IRStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementSourceReference;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
 import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
 import org.opendaylight.yangtools.yang.parser.antlr.YangStatementLexer;
 import org.opendaylight.yangtools.yang.parser.antlr.YangStatementParser;
 import org.opendaylight.yangtools.yang.parser.antlr.YangStatementParser.FileContext;
index 52ae77c0200d30d16a72157c8e07334b2da9664e..89b3c8fe5985b799df1edbcc0973cf5f88ccdafd 100644 (file)
@@ -21,12 +21,12 @@ import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
 import org.opendaylight.yangtools.yang.model.api.source.YinTextSource;
 import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
 import org.opendaylight.yangtools.yang.model.spi.source.FileYangTextSource;
 import org.opendaylight.yangtools.yang.model.spi.source.FileYinTextSource;
 import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YinStatementStreamSource;
diff --git a/parser/yang-test-util/src/main/java/org/opendaylight/yangtools/yang/test/util/LiteralYangTextSource.java b/parser/yang-test-util/src/main/java/org/opendaylight/yangtools/yang/test/util/LiteralYangTextSource.java
deleted file mode 100644 (file)
index 1e0f303..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2023 PANTHEON.tech s.r.o. 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.yang.test.util;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static java.util.Objects.requireNonNull;
-
-import java.io.StringReader;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.UnresolvedQName;
-import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
-
-/**
- * A {@link YangTextSource} backed by a string literal.
- */
-final class LiteralYangTextSource extends YangTextSource {
-    private final @NonNull String sourceString;
-
-    private LiteralYangTextSource(final SourceIdentifier identifier, final String sourceString,
-            final String symbolicName) {
-        super(identifier);
-        this.sourceString = requireNonNull(sourceString);
-    }
-
-    /**
-     * Create a new {@link YangTextSource} backed by a String input.
-     *
-     * @param sourceString YANG file as a String
-     * @return A new instance.
-     * @throws NullPointerException if {@code sourceString} is {@code null}
-     * @throws IllegalArgumentException if {@code sourceString} does not a valid YANG body, given a rather restrictive
-     *         view of what is valid.
-     */
-    static @NonNull LiteralYangTextSource ofLiteral(final String sourceString) {
-        // First line of a YANG file looks as follows:
-        //   `module module-name {`
-        // therefore in order to extract the name of the module from a plain string, we are interested in the second
-        // word of the first line
-        final String[] firstLine = sourceString.substring(0, sourceString.indexOf("{")).strip().split(" ");
-        final String moduleOrSubmoduleString = firstLine[0].strip();
-        checkArgument(moduleOrSubmoduleString.equals("module") || moduleOrSubmoduleString.equals("submodule"));
-
-        final String arg = firstLine[1].strip();
-        final var localName = UnresolvedQName.tryLocalName(arg);
-        checkArgument(localName != null);
-        return new LiteralYangTextSource(new SourceIdentifier(localName), sourceString, arg);
-    }
-
-    @Override
-    public StringReader openStream() {
-        return new StringReader(sourceString);
-    }
-
-    @Override
-    public String symbolicName() {
-        return sourceId().name().getLocalName();
-    }
-}
index 48e0035d55b521e641ba5c688cf77b32e6f087fa..690446456025e71217e68716d92750178e804bec 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.yangtools.yang.test.util;
 
+import static com.google.common.base.Preconditions.checkArgument;
+
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.io.File;
 import java.io.FileFilter;
@@ -23,13 +25,16 @@ import java.util.ServiceLoader;
 import java.util.Set;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.UnresolvedQName;
 import org.opendaylight.yangtools.yang.common.YangConstants;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
 import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
 import org.opendaylight.yangtools.yang.model.spi.source.FileYangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.StringYangTextSource;
 import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
 import org.opendaylight.yangtools.yang.parser.api.YangParser;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
 import org.opendaylight.yangtools.yang.parser.api.YangParserException;
@@ -373,7 +378,7 @@ public final class YangParserTestUtils {
      */
     public static EffectiveModelContext parseYang(final String... sources) {
         return parseSources(YangParserConfiguration.DEFAULT, null,
-            Arrays.stream(sources).map(LiteralYangTextSource::ofLiteral).toList());
+            Arrays.stream(sources).map(YangParserTestUtils::createYangTextSource).toList());
     }
 
     @SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification = "Wrong inferent on listFiles")
@@ -386,4 +391,29 @@ public final class YangParserTestUtils {
         }
         return Arrays.asList(new File(directoryPath).listFiles(YANG_FILE_FILTER));
     }
+
+
+    /**
+     * Create a new {@link YangTextSource} backed by a String input.
+     *
+     * @param sourceString YANG file as a String
+     * @return A new instance.
+     * @throws NullPointerException if {@code sourceString} is {@code null}
+     * @throws IllegalArgumentException if {@code sourceString} does not a valid YANG body, given a rather restrictive
+     *         view of what is valid.
+     */
+    private static @NonNull StringYangTextSource createYangTextSource(final String sourceString) {
+        // First line of a YANG file looks as follows:
+        //   `module module-name {`
+        // therefore in order to extract the name of the module from a plain string, we are interested in the second
+        // word of the first line
+        final var firstLine = sourceString.substring(0, sourceString.indexOf("{")).strip().split(" ");
+        final var moduleOrSubmoduleString = firstLine[0].strip();
+        checkArgument(moduleOrSubmoduleString.equals("module") || moduleOrSubmoduleString.equals("submodule"));
+
+        final String arg = firstLine[1].strip();
+        final var localName = UnresolvedQName.tryLocalName(arg);
+        checkArgument(localName != null);
+        return new StringYangTextSource(new SourceIdentifier(localName), sourceString, arg);
+    }
 }
index c3b966dd2b285f5b7c9ee6ea28e50a9ba9058b1e..6f0814906d947041542c1fd8dc64a8a24d53cd7b 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.yangtools.plugin.generator.api;
 import java.util.Optional;
 import org.opendaylight.yangtools.yang.model.api.ModuleLike;
 import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
 
 /**
  * An SPI-level interface to find the schema source for a particular YANG module, as packaged in the final artifact.
index 3c58e1aa0b15721d3e53f94e2922be5c0a7fabe4..d248a074dc285937033f63718446f18f58bd52a3 100644 (file)
@@ -21,7 +21,7 @@ import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.ModuleLike;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
 
 final class ContextHolder implements Immutable, ModuleResourceResolver {
     private final @NonNull EffectiveModelContext context;
index e607ffef8b258c0443194fb86b442512239ec428..819a60e39f3d48752a57a20740fa054891f5c4df 100644 (file)
@@ -26,7 +26,7 @@ import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.Submodule;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
 import org.opendaylight.yangtools.yang.parser.api.YangParser;
 import org.opendaylight.yangtools.yang.parser.api.YangParserException;
 import org.slf4j.Logger;
index 6a841f2a9a3857a341affbc558fc0bf2fcdf419c..e380cc1f0ea4f21b1061155c9c50261912330d91 100644 (file)
@@ -28,9 +28,9 @@ import org.apache.maven.artifact.Artifact;
 import org.apache.maven.project.MavenProject;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
 import org.opendaylight.yangtools.yang.model.spi.source.DelegatedYangTextSource;
 import org.opendaylight.yangtools.yang.model.spi.source.FileYangTextSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
index ee880da8a06a1450199284aa7a3ea553b5337f37..1e29c867c375e4c7a03fe35c7257590d90ceaf0b 100644 (file)
@@ -12,7 +12,7 @@ import java.io.IOException;
 import java.util.Collection;
 import java.util.List;
 import org.apache.maven.project.MavenProject;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
 
 @FunctionalInterface
 @VisibleForTesting
index f9769f9ba8b4b4efe07160dea548606bf1b4b3dc..d6086b972ca6410fe1a5359711e01d65135ed8ec 100644 (file)
@@ -39,10 +39,10 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.plugin.generator.api.FileGeneratorException;
 import org.opendaylight.yangtools.plugin.generator.api.FileGeneratorFactory;
 import org.opendaylight.yangtools.yang.common.YangConstants;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
 import org.opendaylight.yangtools.yang.model.spi.source.DelegatedYangTextSource;
 import org.opendaylight.yangtools.yang.model.spi.source.FileYangTextSource;
 import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
 import org.opendaylight.yangtools.yang.parser.api.YangParserException;
 import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
index dbbc43bd0a497c1c590e08f933012420c531cee5..4fbb72c82a75e6653c65a0760860274f5d9c059d 100644 (file)
@@ -22,7 +22,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.opendaylight.yangtools.plugin.generator.api.ModuleResourceResolver;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
 
 @ExtendWith(MockitoExtension.class)
 class FilenameResolutionTest extends AbstractCodeGeneratorTest {
index 570a957393832bb4229821055ab7f034fbf7051c..63c4e79ca87b3d189612ea300703663c6f30685b 100644 (file)
@@ -35,12 +35,12 @@ import java.util.regex.Pattern;
 import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
 import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
 import org.opendaylight.yangtools.yang.model.repo.spi.AbstractSchemaSourceCache;
 import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource.Costs;
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
 import org.opendaylight.yangtools.yang.model.spi.source.FileYangTextSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
index 94fc3448f6d87d04983c3ef5f4d68363adfdff20..210b607b807bd7aca441180bb517828a6bfd3570 100644 (file)
@@ -14,15 +14,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
-import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.collect.Lists;
 import com.google.common.io.Files;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.io.File;
 import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -33,10 +30,11 @@ import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
 import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
 import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceListener;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.StringYangTextSource;
 import org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
 
@@ -108,22 +106,8 @@ public class FilesystemSchemaSourceCacheIntegrationTest {
         final SourceIdentifier runningId = new SourceIdentifier("running", "2012-12-12");
 
         sharedSchemaRepository.registerSchemaSource(sourceIdentifier -> FluentFutures.immediateFluentFuture(
-            new YangTextSource(runningId) {
-                @Override
-                protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
-                    return toStringHelper;
-                }
-
-                @Override
-                public Reader openStream() throws IOException {
-                    return new StringReader("running");
-                }
-
-                @Override
-                public String symbolicName() {
-                    return null;
-                }
-            }), PotentialSchemaSource.create(runningId, YangTextSource.class,
+            new StringYangTextSource(runningId, "running", null)),
+            PotentialSchemaSource.create(runningId, YangTextSource.class,
                 PotentialSchemaSource.Costs.REMOTE_IO.getValue()));
 
         final TextToIRTransformer transformer = TextToIRTransformer.create(sharedSchemaRepository,
index 5c99d47965fb2b7468fa3f6c852ee847820b15ff..7a7c2a54cba7f1ae27f6c17109398ddf0bb650d4 100644 (file)
@@ -13,21 +13,17 @@ import static org.hamcrest.CoreMatchers.either;
 import static org.hamcrest.CoreMatchers.hasItem;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
-import com.google.common.base.MoreObjects;
 import com.google.common.collect.Collections2;
-import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.Futures;
 import java.io.File;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
 import java.nio.file.Files;
 import java.util.Arrays;
 import java.util.Collection;
@@ -42,44 +38,45 @@ import org.mockito.junit.jupiter.MockitoSettings;
 import org.mockito.quality.Strictness;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
 import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.StringYangTextSource;
 
 @ExtendWith(MockitoExtension.class)
 @MockitoSettings(strictness = Strictness.LENIENT)
-public class FilesystemSchemaSourceCacheTest {
+class FilesystemSchemaSourceCacheTest {
     @Mock
-    public SchemaSourceRegistry registry;
+    private SchemaSourceRegistry registry;
     @Mock
-    public Registration registration;
+    private Registration registration;
 
-    public File storageDir;
+    private File storageDir;
 
     @BeforeEach
-    public void setUp() throws Exception {
+    void setUp() throws Exception {
         storageDir = Files.createTempDirectory(null).toFile();
         doReturn(registration).when(registry).registerSchemaSource(any(SchemaSourceProvider.class),
             any(PotentialSchemaSource.class));
     }
 
     @Test
-    public void testCacheAndRestore() throws Exception {
-        final FilesystemSchemaSourceCache<YangTextSource> cache = new FilesystemSchemaSourceCache<>(registry,
-            YangTextSource.class, storageDir);
+    void testCacheAndRestore() throws Exception {
+        final var cache = new FilesystemSchemaSourceCache<>(registry, YangTextSource.class, storageDir);
 
-        final String content = "content1";
-        final YangTextSource source = new TestingYangSource("test", "2012-12-12", content);
+        final var content = "content1";
+        final var source = new StringYangTextSource(new SourceIdentifier("test", "2012-12-12"), content);
         cache.offer(source);
 
-        final String content2 = "content2";
-        final YangTextSource source2 = new TestingYangSource("test2", null, content);
+        final var content2 = "content2";
+        final var source2 = new StringYangTextSource(new SourceIdentifier("test2"), content);
         cache.offer(source2);
 
-        final List<File> storedFiles = getFilesFromCache();
+        final var storedFiles = getFilesFromCache();
         assertEquals(2, storedFiles.size());
-        final Collection<String> fileNames = filesToFilenamesWithoutRevision(storedFiles);
+        final var fileNames = filesToFilenamesWithoutRevision(storedFiles);
 
         assertThat(fileNames, both(hasItem("test2")).and(hasItem("test@2012-12-12")));
 
@@ -97,7 +94,7 @@ public class FilesystemSchemaSourceCacheTest {
         verify(registry, times(4)).registerSchemaSource(any(SchemaSourceProvider.class),
             any(PotentialSchemaSource.class));
 
-        final List<File> storedFilesAfterNewCache = getFilesFromCache();
+        final var storedFilesAfterNewCache = getFilesFromCache();
         assertEquals(2, storedFilesAfterNewCache.size());
     }
 
@@ -110,36 +107,33 @@ public class FilesystemSchemaSourceCacheTest {
     }
 
     @Test
-    public void testCacheDuplicate() throws Exception {
-        final FilesystemSchemaSourceCache<YangTextSource> cache = new FilesystemSchemaSourceCache<>(registry,
-            YangTextSource.class, storageDir);
+    void testCacheDuplicate() throws Exception {
+        final var cache = new FilesystemSchemaSourceCache<>(registry, YangTextSource.class, storageDir);
 
-        final String content = "content1";
-        final YangTextSource source = new TestingYangSource("test", null, content);
+        final var content = "content1";
+        final var source = new StringYangTextSource(new SourceIdentifier("test"), content);
         // Double offer
         cache.offer(source);
         cache.offer(source);
 
-        final List<File> storedFiles = getFilesFromCache();
+        final var storedFiles = getFilesFromCache();
         assertEquals(1, storedFiles.size());
         verify(registry).registerSchemaSource(any(SchemaSourceProvider.class), any(PotentialSchemaSource.class));
     }
 
     @Test
-    public void testCacheMultipleRevisions() throws Exception {
-        final FilesystemSchemaSourceCache<YangTextSource> cache = new FilesystemSchemaSourceCache<>(registry,
-            YangTextSource.class, storageDir);
-
-        final String content = "content1";
-        final YangTextSource source = new TestingYangSource("test", null, content);
-        final YangTextSource source2 = new TestingYangSource("test", "2012-12-12", content);
-        final YangTextSource source3 = new TestingYangSource("test", "2013-12-12", content);
+    void testCacheMultipleRevisions() throws Exception {
+        final var cache = new FilesystemSchemaSourceCache<>(registry, YangTextSource.class, storageDir);
+
+        final var source = new StringYangTextSource(new SourceIdentifier("test"), "content1");
+        final var source2 = new StringYangTextSource(new SourceIdentifier("test", "2012-12-12"), "content2");
+        final var source3 = new StringYangTextSource(new SourceIdentifier("test", "2013-12-12"), "content3");
         // Double offer
         cache.offer(source);
         cache.offer(source2);
         cache.offer(source3);
 
-        final List<File> storedFiles = getFilesFromCache();
+        final var storedFiles = getFilesFromCache();
         assertEquals(3, storedFiles.size());
 
         assertThat(filesToFilenamesWithoutRevision(storedFiles), both(hasItem("test"))
@@ -150,102 +144,66 @@ public class FilesystemSchemaSourceCacheTest {
     }
 
     @Test
-    public void sourceIdToFileEmptyRevWithEmptyDir() {
-        final SourceIdentifier sourceIdentifier = new SourceIdentifier("test");
-        final File sourceIdToFile = FilesystemSchemaSourceCache.sourceIdToFile(sourceIdentifier, storageDir);
-        final FilesystemSchemaSourceCache<YangTextSource> cache = new FilesystemSchemaSourceCache<>(registry,
-                YangTextSource.class, sourceIdToFile);
+    void sourceIdToFileEmptyRevWithEmptyDir() {
+        final var sourceId = new SourceIdentifier("test");
+        final var sourceIdToFile = FilesystemSchemaSourceCache.sourceIdToFile(sourceId, storageDir);
+        final var cache = new FilesystemSchemaSourceCache<>(registry, YangTextSource.class, sourceIdToFile);
         assertNotNull(cache);
-        final List<File> storedFiles = Arrays.asList(sourceIdToFile.listFiles());
+        final var storedFiles = Arrays.asList(sourceIdToFile.listFiles());
         assertEquals(0, storedFiles.size());
     }
 
     @Test
-    public void sourceIdToFileEmptyRevWithOneItemInDir() {
-        final FilesystemSchemaSourceCache<YangTextSource> cache = new FilesystemSchemaSourceCache<>(registry,
-                YangTextSource.class, storageDir);
-        final String content = "content1";
-        final YangTextSource source = new TestingYangSource("test", "2013-12-12", content);
+    void sourceIdToFileEmptyRevWithOneItemInDir() {
+        final var cache = new FilesystemSchemaSourceCache<>(registry, YangTextSource.class, storageDir);
+        final var source = new StringYangTextSource(new SourceIdentifier("test", "2013-12-12"), "content1");
         cache.offer(source);
 
-        final SourceIdentifier sourceIdentifier = new SourceIdentifier("test");
-        final File sourceIdToFile = FilesystemSchemaSourceCache.sourceIdToFile(sourceIdentifier,
-                storageDir);
+        final var sourceId = new SourceIdentifier("test");
+        final var sourceIdToFile = FilesystemSchemaSourceCache.sourceIdToFile(sourceId, storageDir);
         assertNotNull(sourceIdToFile);
-        final List<File> storedFiles = Arrays.asList(storageDir.listFiles());
+        final var storedFiles = Arrays.asList(storageDir.listFiles());
         assertEquals(1, storedFiles.size());
     }
 
     @Test
-    public void sourceIdToFileEmptyRevWithMoreItemsInDir() {
-        final FilesystemSchemaSourceCache<YangTextSource> cache = new FilesystemSchemaSourceCache<>(registry,
-                YangTextSource.class, storageDir);
-        final String content = "content1";
-        final YangTextSource source = new TestingYangSource("test", "2012-12-12", content);
-        final YangTextSource source2 = new TestingYangSource("test", "2013-12-12", content);
+    void sourceIdToFileEmptyRevWithMoreItemsInDir() {
+        final var cache = new FilesystemSchemaSourceCache<>(registry, YangTextSource.class, storageDir);
+        final var source = new StringYangTextSource(new SourceIdentifier("test", "2012-12-12"), "content1");
+        final var source2 = new StringYangTextSource(new SourceIdentifier("test", "2013-12-12"), "content1");
         cache.offer(source);
         cache.offer(source2);
 
-        final SourceIdentifier sourceIdentifier = new SourceIdentifier("test");
-        final File sourceIdToFile = FilesystemSchemaSourceCache.sourceIdToFile(sourceIdentifier, storageDir);
+        final var sourceId = new SourceIdentifier("test");
+        final var sourceIdToFile = FilesystemSchemaSourceCache.sourceIdToFile(sourceId, storageDir);
         assertNotNull(sourceIdToFile);
-        final List<File> storedFiles = Arrays.asList(storageDir.listFiles());
+        final var storedFiles = Arrays.asList(storageDir.listFiles());
         assertEquals(2, storedFiles.size());
     }
 
     @Test
-    public void test() throws Exception {
-        final FilesystemSchemaSourceCache<YangTextSource> cache = new FilesystemSchemaSourceCache<>(registry,
-                YangTextSource.class, storageDir);
-        final String content = "content1";
-        final YangTextSource source = new TestingYangSource("test", "2013-12-12", content);
+    void test() throws Exception {
+        final var cache = new FilesystemSchemaSourceCache<>(registry, YangTextSource.class, storageDir);
+        final var sourceId = new SourceIdentifier("test", "2013-12-12");
+        final var source = new StringYangTextSource(sourceId, "content1", null);
         cache.offer(source);
-        final SourceIdentifier sourceIdentifier = new SourceIdentifier("test", "2013-12-12");
-        final ListenableFuture<? extends YangTextSource> checked = cache.getSource(sourceIdentifier);
-        assertNotNull(checked);
-        assertTrue(checked.isDone());
-        final YangTextSource checkedGet = checked.get();
-        assertEquals(sourceIdentifier, checkedGet.sourceId());
+        assertEquals(sourceId, Futures.getDone(cache.getSource(sourceId)).sourceId());
     }
 
     @Test
-    public void test1() throws Exception {
-        final FilesystemSchemaSourceCache<YangTextSource> cache = new FilesystemSchemaSourceCache<>(registry,
-                YangTextSource.class, storageDir);
-        final String content = "content1";
-        final YangTextSource source = new TestingYangSource("test", "2013-12-12", content);
+    void test1() throws Exception {
+        final var cache = new FilesystemSchemaSourceCache<>(registry, YangTextSource.class, storageDir);
+        final var source = new StringYangTextSource(new SourceIdentifier("test1", "2013-12-12"), "content1");
         cache.offer(source);
-        final SourceIdentifier sourceIdentifier = new SourceIdentifier("test1", "2012-12-12");
-        final ListenableFuture<? extends YangTextSource> checked = cache.getSource(sourceIdentifier);
-        assertNotNull(checked);
-        assertThrows(ExecutionException.class, () -> checked.get());
+        final var sourceId = new SourceIdentifier("test1", "2012-12-12");
+        final var future = cache.getSource(sourceId);
+        final var ex = assertThrows(ExecutionException.class, () -> Futures.getDone(future));
+        final var cause = assertInstanceOf(MissingSchemaSourceException.class, ex.getCause());
+        assertEquals(sourceId, cause.sourceId());
+        assertEquals("Source not found", cause.getMessage());
     }
 
     private List<File> getFilesFromCache() {
         return Arrays.asList(storageDir.listFiles());
     }
-
-    private static class TestingYangSource extends YangTextSource {
-        private final String content;
-
-        TestingYangSource(final String name, final String revision, final String content) {
-            super(new SourceIdentifier(name, revision));
-            this.content = content;
-        }
-
-        @Override
-        protected MoreObjects.ToStringHelper addToStringAttributes(final MoreObjects.ToStringHelper toStringHelper) {
-            return toStringHelper;
-        }
-
-        @Override
-        public Reader openStream() throws IOException {
-            return new StringReader(content);
-        }
-
-        @Override
-        public String symbolicName() {
-            return null;
-        }
-    }
 }
index 6c53af93bfd525b352a070c1abb5bb825b3794fb..3746eeac367bf4b2b58a1820ca13d249ced56896 100644 (file)
@@ -14,8 +14,6 @@ import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 
-import com.google.common.base.MoreObjects.ToStringHelper;
-import java.io.StringReader;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import org.junit.jupiter.api.Test;
@@ -25,7 +23,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.source.YangSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.StringYangTextSource;
 
 @Deprecated
 @ExtendWith(MockitoExtension.class)
@@ -59,11 +57,10 @@ class GuavaSchemaSourceCacheTest {
         doReturn(registration).when(registry).registerSchemaSource(any(), any());
 
         try (var cache = GuavaSchemaSourceCache.createSoftCache(registry, REPRESENTATION)) {
-            final var content = "content";
-            final var source = new TestingYangSource("test", "2012-12-12", content);
-            cache.offer(source);
             final var sourceIdentifier = new SourceIdentifier("test", "2012-12-12");
-            final var checkedSource = cache .getSource(sourceIdentifier);
+            final var source = new StringYangTextSource(sourceIdentifier, "content");
+            cache.offer(source);
+            final var checkedSource = cache.getSource(sourceIdentifier);
             assertNotNull(checkedSource);
             final var yangSchemaSourceRepresentation = checkedSource.get();
             assertNotNull(yangSchemaSourceRepresentation);
@@ -89,11 +86,11 @@ class GuavaSchemaSourceCacheTest {
         try (var cache1 = GuavaSchemaSourceCache.createSoftCache(registry, REPRESENTATION)) {
             try (var cache2 = GuavaSchemaSourceCache.createSoftCache(registry, REPRESENTATION, LIFETIME, UNITS)) {
                 final var content = "content";
-                final var source = new TestingYangSource("test", "2012-12-12", content);
+                final var sourceIdentifier = new SourceIdentifier("test", "2012-12-12");
+                final var source = new StringYangTextSource(sourceIdentifier, content);
                 cache1.offer(source);
                 cache2.offer(source);
 
-                final var sourceIdentifier = new SourceIdentifier("test", "2012-12-12");
                 final var checkedSource = cache1.getSource(sourceIdentifier);
                 final var checkedSource2 = cache2.getSource(sourceIdentifier);
                 assertNotNull(checkedSource);
@@ -103,28 +100,4 @@ class GuavaSchemaSourceCacheTest {
             }
         }
     }
-
-    private static class TestingYangSource extends YangTextSource {
-        private final String content;
-
-        TestingYangSource(final String name, final String revision, final String content) {
-            super(new SourceIdentifier(name, revision));
-            this.content = content;
-        }
-
-        @Override
-        public StringReader openStream() {
-            return new StringReader(content);
-        }
-
-        @Override
-        public String symbolicName() {
-            return null;
-        }
-
-        @Override
-        protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
-            return toStringHelper;
-        }
-    }
 }
index a3759c540a552a06372a9e2ce21b285acc5844ec..fc72542a0f717b944c8485ca4f283e1973872048 100644 (file)
@@ -14,8 +14,6 @@ import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 
-import com.google.common.base.MoreObjects.ToStringHelper;
-import java.io.StringReader;
 import java.util.concurrent.ExecutionException;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
@@ -24,7 +22,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.source.YangSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.StringYangTextSource;
 
 @ExtendWith(MockitoExtension.class)
 class SoftSchemaSourceCacheTest {
@@ -48,11 +46,10 @@ class SoftSchemaSourceCacheTest {
         doReturn(registration).when(registry).registerSchemaSource(any(), any());
 
         try (var cache = new SoftSchemaSourceCache<>(registry, REPRESENTATION)) {
-            final var content = "content";
-            final var source = new TestingYangSource("test", "2012-12-12", content);
-            cache.offer(source);
             final var sourceIdentifier = new SourceIdentifier("test", "2012-12-12");
-            final var checkedSource = cache .getSource(sourceIdentifier);
+            final var source = new StringYangTextSource(sourceIdentifier, "content");
+            cache.offer(source);
+            final var checkedSource = cache.getSource(sourceIdentifier);
             assertNotNull(checkedSource);
             final var yangSchemaSourceRepresentation = checkedSource.get();
             assertNotNull(yangSchemaSourceRepresentation);
@@ -77,12 +74,11 @@ class SoftSchemaSourceCacheTest {
 
         try (var cache1 = new SoftSchemaSourceCache<>(registry, REPRESENTATION)) {
             try (var cache2 = new SoftSchemaSourceCache<>(registry, REPRESENTATION)) {
-                final var content = "content";
-                final var source = new TestingYangSource("test", "2012-12-12", content);
+                final var sourceIdentifier = new SourceIdentifier("test", "2012-12-12");
+                final var source = new StringYangTextSource(sourceIdentifier, "content");
                 cache1.offer(source);
                 cache2.offer(source);
 
-                final var sourceIdentifier = new SourceIdentifier("test", "2012-12-12");
                 final var checkedSource = cache1.getSource(sourceIdentifier);
                 final var checkedSource2 = cache2.getSource(sourceIdentifier);
                 assertNotNull(checkedSource);
@@ -92,28 +88,4 @@ class SoftSchemaSourceCacheTest {
             }
         }
     }
-
-    private static class TestingYangSource extends YangTextSource {
-        private final String content;
-
-        TestingYangSource(final String name, final String revision, final String content) {
-            super(new SourceIdentifier(name, revision));
-            this.content = content;
-        }
-
-        @Override
-        public StringReader openStream() {
-            return new StringReader(content);
-        }
-
-        @Override
-        public String symbolicName() {
-            return null;
-        }
-
-        @Override
-        protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
-            return toStringHelper;
-        }
-    }
 }