import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
public static YangStatementStreamSource sourceForResource(final String resourceName) {
try {
- return YangStatementStreamSource.create(YangTextSchemaSource.forFile(new File(
+ return YangStatementStreamSource.create(YangTextSchemaSource.forPath(Path.of(
StmtTestUtils.class.getResource(resourceName).toURI())));
} catch (IOException | YangSyntaxErrorException | URISyntaxException e) {
throw new IllegalArgumentException("Failed to create source", e);
final Collection<YangStatementStreamSource> sources = new ArrayList<>(files.length);
for (File file : files) {
- sources.add(YangStatementStreamSource.create(YangTextSchemaSource.forFile(file)));
+ sources.add(YangStatementStreamSource.create(YangTextSchemaSource.forPath(file.toPath())));
}
return parseYangSources(config, supportedFeatures, sources);
public static EffectiveModelContext parseYangSources(final Collection<File> files,
final YangParserConfiguration config) throws ReactorException, IOException, YangSyntaxErrorException {
- return parseYangSources(config, null, files.toArray(new File[files.size()]));
+ return parseYangSources(config, null, files.toArray(new File[0]));
}
public static EffectiveModelContext parseYangSources(final String yangSourcesDirectoryPath)
.listFiles(StmtTestUtils.YANG_FILE_FILTER);
final var sources = new ArrayList<StatementStreamSource>(files.length);
for (var file : files) {
- sources.add(YangStatementStreamSource.create(YangTextSchemaSource.forFile(file)));
+ sources.add(YangStatementStreamSource.create(YangTextSchemaSource.forPath(file.toPath())));
}
return sources;
}
for (File file : files) {
if (file.getName().endsWith(YangConstants.RFC6020_YANG_FILE_EXTENSION)) {
- reactor.addSource(YangStatementStreamSource.create(YangTextSchemaSource.forFile(file)));
+ reactor.addSource(YangStatementStreamSource.create(YangTextSchemaSource.forPath(file.toPath())));
} else {
LOG.info("Ignoring non-yang file {}", file);
}
for (File file : new File(resourceDirectory).listFiles()) {
reactor.addSource(YinStatementStreamSource.create(YinTextToDomTransformer.transformSource(
- YinTextSchemaSource.forFile(file))));
+ YinTextSchemaSource.forPath(file.toPath()))));
}
return reactor.buildEffective();
StatementStreamSource[] sources = new StatementStreamSource[files.length];
for (int i = 0; i < files.length; i++) {
- sources[i] = YangStatementStreamSource.create(YangTextSchemaSource.forFile(files[i]));
+ sources[i] = YangStatementStreamSource.create(YangTextSchemaSource.forPath(files[i].toPath()));
}
return parseYangSources(sources);
* @param files YANG files to be parsed
* @return effective schema context
*/
+ // FIXME: use Java.nio.file.Path
public static EffectiveModelContext parseYangFiles(final Set<QName> supportedFeatures,
final YangParserConfiguration config, final Collection<File> files) {
return parseSources(config, supportedFeatures,
- files.stream().map(YangTextSchemaSource::forFile).collect(Collectors.toList()));
+ files.stream().map(file -> YangTextSchemaSource.forPath(file.toPath())).collect(Collectors.toList()));
}
/**
@Override
Collection<YangTextSchemaSource> sources() {
- return ImmutableList.of(YangTextSchemaSource.forFile(file()));
+ return ImmutableList.of(YangTextSchemaSource.forPath(file().toPath()));
}
}
return entryNames.isEmpty() ? ImmutableList.of() : ImmutableList.of(new Zip(zipFile, entryNames));
}
+ // FIXME: java.nio.file.Path
final File file() {
return file;
}
this.yangFilesRootDir = requireNonNull(yangFilesRootDir, "yangFilesRootDir");
this.excludedFiles = ImmutableSet.copyOf(excludedFiles);
this.codeGeneratorArgs = ImmutableList.copyOf(codeGeneratorArgs);
- this.fileGeneratorArgs = Maps.uniqueIndex(fileGeneratorsArgs, FileGeneratorArg::getIdentifier);
+ fileGeneratorArgs = Maps.uniqueIndex(fileGeneratorsArgs, FileGeneratorArg::getIdentifier);
this.project = requireNonNull(project);
this.inspectDependencies = inspectDependencies;
this.yangProvider = requireNonNull(yangProvider);
- this.parserFactory = DEFAULT_PARSER_FACTORY;
+ parserFactory = DEFAULT_PARSER_FACTORY;
}
@VisibleForTesting
final Stopwatch watch = Stopwatch.createStarted();
final List<Entry<YangTextSchemaSource, IRSchemaSource>> parsed = yangFilesInProject.parallelStream()
.map(file -> {
- final YangTextSchemaSource textSource = YangTextSchemaSource.forFile(file);
+ final YangTextSchemaSource textSource = YangTextSchemaSource.forPath(file.toPath());
try {
return Map.entry(textSource,TextToIRTransformer.transformText(textSource));
} catch (YangSyntaxErrorException | IOException e) {
}
for (File file : testFiles) {
- parser.addSource(YangTextSchemaSource.forFile(file));
+ parser.addSource(YangTextSchemaSource.forPath(file.toPath()));
}
for (File file : libFiles) {
- parser.addLibSource(YangTextSchemaSource.forFile(file));
+ parser.addLibSource(YangTextSchemaSource.forPath(file.toPath()));
}
return parser.buildEffectiveModel();
import static java.util.Objects.requireNonNull;
import com.google.common.base.MoreObjects.ToStringHelper;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Delegator;
*
* @author Robert Varga
*/
-final class YangTextFileSchemaSource extends YangTextSchemaSource implements Delegator<File> {
- private final @NonNull File file;
+final class YangTextFileSchemaSource extends YangTextSchemaSource implements Delegator<Path> {
+ private final @NonNull Path path;
- YangTextFileSchemaSource(final SourceIdentifier identifier, final File file) {
+ YangTextFileSchemaSource(final SourceIdentifier identifier, final Path path) {
super(identifier);
- this.file = requireNonNull(file);
+ this.path = requireNonNull(path);
}
@Override
- public File getDelegate() {
- return file;
+ public Path getDelegate() {
+ return path;
}
@Override
public InputStream openStream() throws IOException {
- return Files.newInputStream(file.toPath());
+ return Files.newInputStream(path);
}
@Override
protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
- return toStringHelper.add("file", file);
+ return toStringHelper.add("path", path);
}
@Override
public Optional<String> getSymbolicName() {
- return Optional.of(file.toString());
+ // 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 Optional.of(path.toString());
}
}
import java.io.File;
import java.io.InputStream;
import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.Map.Entry;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.Revision;
* Create a new YangTextSchemaSource backed by a {@link File} with {@link SourceIdentifier} derived from the file
* name.
*
- * @param file Backing File
+ * @param path Backing path
* @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 {@code null}
*/
- public static @NonNull YangTextSchemaSource forFile(final File file) {
- return forFile(file, identifierFromFilename(file.getName()));
+ public static @NonNull YangTextSchemaSource forPath(final Path path) {
+ return forPath(path, identifierFromFilename(path.toFile().getName()));
}
/**
* Create a new YangTextSchemaSource backed by a {@link File} and specified {@link SourceIdentifier}.
*
- * @param file Backing File
+ * @param path Backing path
* @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}
+ * @throws IllegalArgumentException if the supplied path is not a regular file
*/
- 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(identifier, file);
+ public static @NonNull YangTextSchemaSource forPath(final Path path, final SourceIdentifier identifier) {
+ checkArgument(Files.isRegularFile(path), "Supplied path %s is not a regular file", path);
+ return new YangTextFileSchemaSource(identifier, path);
}
/**
import static java.util.Objects.requireNonNull;
import com.google.common.base.MoreObjects.ToStringHelper;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Delegator;
*
* @author Robert Varga
*/
-final class YinTextFileSchemaSource extends YinTextSchemaSource implements Delegator<File> {
- private final @NonNull File file;
+final class YinTextFileSchemaSource extends YinTextSchemaSource implements Delegator<Path> {
+ private final @NonNull Path path;
- YinTextFileSchemaSource(final @NonNull SourceIdentifier identifier, final @NonNull File file) {
+ YinTextFileSchemaSource(final @NonNull SourceIdentifier identifier, final @NonNull Path path) {
super(identifier);
- this.file = requireNonNull(file);
+ this.path = requireNonNull(path);
}
@Override
- public File getDelegate() {
- return file;
+ public Path getDelegate() {
+ return path;
}
@Override
public InputStream openStream() throws IOException {
- return Files.newInputStream(file.toPath());
+ return Files.newInputStream(path);
}
@Override
protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
- return toStringHelper.add("file", file);
+ return toStringHelper.add("path", path);
}
@Override
public Optional<String> getSymbolicName() {
- return Optional.of(file.toString());
+ return Optional.of(path.toString());
}
}
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.io.ByteSource;
import com.google.common.io.Resources;
-import java.io.File;
import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.Map.Entry;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.Revision;
return new DelegatedYinTextSchemaSource(identifier, delegate);
}
- public static @NonNull YinTextSchemaSource forFile(final File file) {
- checkArgument(file.isFile(), "Supplied file %s is not a file", file);
- return new YinTextFileSchemaSource(identifierFromFilename(file.getName()), file);
+ public static @NonNull YinTextSchemaSource forPath(final Path path) {
+ checkArgument(Files.isRegularFile(path), "Supplied path %s is not a regular file", path);
+ return new YinTextFileSchemaSource(identifierFromFilename(path.toFile().getName()), path);
}
public static @NonNull YinTextSchemaSource forResource(final Class<?> clazz, final String resourceName) {
storeAsType(file, supportedType.cast(schemaSourceRepresentation));
}
+ // FIXME: use java.nio.filePath
protected abstract void storeAsType(File file, T cast);
- public T restore(final SourceIdentifier sourceIdentifier, final File cachedSource) {
+ T restore(final SourceIdentifier sourceIdentifier, final File cachedSource) {
checkArgument(cachedSource.isFile());
checkArgument(cachedSource.exists());
checkArgument(cachedSource.canRead());
return restoreAsType(sourceIdentifier, cachedSource);
}
- protected abstract T restoreAsType(SourceIdentifier sourceIdentifier, File cachedSource);
+ abstract T restoreAsType(SourceIdentifier sourceIdentifier, File cachedSource);
}
private static final class YangTextSchemaStorageAdapter extends StorageAdapter<YangTextSchemaSource> {
}
@Override
- public YangTextSchemaSource restoreAsType(final SourceIdentifier sourceIdentifier, final File cachedSource) {
- return YangTextSchemaSource.forFile(cachedSource, sourceIdentifier);
+ YangTextSchemaSource restoreAsType(final SourceIdentifier sourceIdentifier, final File cachedSource) {
+ return YangTextSchemaSource.forPath(cachedSource.toPath(), sourceIdentifier);
}
}