From d23aa17bf81deed1dc7208d00bd15400954edf9c Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 21 Apr 2021 07:36:22 +0200 Subject: [PATCH] Do not subclass YangTextSchemaSource in yang-repo-fs We have a readily-available File-based implementation, reuse it instead of rolling our own. JIRA: YANGTOOLS-1275 Change-Id: I0a6604b83cb1aa216e61f5f5be97f93d2d1dd0e4 Signed-off-by: Robert Varga --- .../model/repo/api/YangTextSchemaSource.java | 17 +++++++++++++++-- .../repo/fs/FilesystemSchemaSourceCache.java | 14 +------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextSchemaSource.java b/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextSchemaSource.java index 0e521561aa..d21fdcb021 100644 --- a/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextSchemaSource.java +++ b/yang/yang-repo-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextSchemaSource.java @@ -78,11 +78,24 @@ public abstract class YangTextSchemaSource extends ByteSource implements YangSch * @param file Backing File * @return A new YangTextSchemaSource * @throws IllegalArgumentException if the file name has invalid format or if the supplied File is not a file - * @throws NullPointerException if file is null + * @throws NullPointerException if file is {@code null} */ public static @NonNull YangTextSchemaSource forFile(final File file) { + return forFile(file, identifierFromFilename(file.getName())); + } + + /** + * Create a new YangTextSchemaSource backed by a {@link File} and specified {@link SourceIdentifier}. + * + * @param file Backing File + * @param identifier source identifier + * @return A new YangTextSchemaSource + * @throws IllegalArgumentException if the file name has invalid format or if the supplied File is not a file + * @throws NullPointerException if any argument is {@code null} + */ + public static @NonNull YangTextSchemaSource forFile(final File file, final SourceIdentifier identifier) { checkArgument(file.isFile(), "Supplied file %s is not a file", file); - return new YangTextFileSchemaSource(identifierFromFilename(file.getName()), file); + return new YangTextFileSchemaSource(identifier, file); } /** diff --git a/yang/yang-repo-fs/src/main/java/org/opendaylight/yangtools/yang/model/repo/fs/FilesystemSchemaSourceCache.java b/yang/yang-repo-fs/src/main/java/org/opendaylight/yangtools/yang/model/repo/fs/FilesystemSchemaSourceCache.java index 3c24b0dade..1b069ef80f 100644 --- a/yang/yang-repo-fs/src/main/java/org/opendaylight/yangtools/yang/model/repo/fs/FilesystemSchemaSourceCache.java +++ b/yang/yang-repo-fs/src/main/java/org/opendaylight/yangtools/yang/model/repo/fs/FilesystemSchemaSourceCache.java @@ -12,7 +12,6 @@ import static java.util.Objects.requireNonNull; import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFailedFluentFuture; import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFluentFuture; -import com.google.common.base.MoreObjects.ToStringHelper; import com.google.common.util.concurrent.FluentFuture; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.File; @@ -251,18 +250,7 @@ public final class FilesystemSchemaSourceCache