From bae3f965c0b741d9383dc1cecaa3aa742b946eb1 Mon Sep 17 00:00:00 2001 From: Holly Cummins Date: Thu, 30 May 2024 10:49:30 +0100 Subject: [PATCH] Update elementary and remove filesystem support classes no longer needed by tests --- core/processor/pom.xml | 2 +- .../ExtensionAnnotationProcessorTest.java | 11 +- .../processor/fs/CustomMemoryFileSystem.java | 158 ------------------ .../fs/CustomMemoryFileSystemProvider.java | 152 ----------------- .../java.nio.file.spi.FileSystemProvider | 1 - 5 files changed, 2 insertions(+), 322 deletions(-) delete mode 100644 core/processor/src/test/java/io/quarkus/annotation/processor/fs/CustomMemoryFileSystem.java delete mode 100644 core/processor/src/test/java/io/quarkus/annotation/processor/fs/CustomMemoryFileSystemProvider.java delete mode 100644 core/processor/src/test/resources/META-INF/services/java.nio.file.spi.FileSystemProvider diff --git a/core/processor/pom.xml b/core/processor/pom.xml index aee2ce4090171..680bc888257b2 100644 --- a/core/processor/pom.xml +++ b/core/processor/pom.xml @@ -62,7 +62,7 @@ com.karuslabs elementary - 2.0.1 + 3.0.0 test diff --git a/core/processor/src/test/java/io/quarkus/annotation/processor/ExtensionAnnotationProcessorTest.java b/core/processor/src/test/java/io/quarkus/annotation/processor/ExtensionAnnotationProcessorTest.java index d9d85a19ab53a..6181456df994e 100644 --- a/core/processor/src/test/java/io/quarkus/annotation/processor/ExtensionAnnotationProcessorTest.java +++ b/core/processor/src/test/java/io/quarkus/annotation/processor/ExtensionAnnotationProcessorTest.java @@ -9,7 +9,6 @@ import javax.tools.JavaFileObject; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -18,18 +17,10 @@ import com.karuslabs.elementary.junit.annotations.Classpath; import com.karuslabs.elementary.junit.annotations.Processors; -import io.quarkus.annotation.processor.fs.CustomMemoryFileSystemProvider; - @ExtendWith(JavacExtension.class) @Processors({ ExtensionAnnotationProcessor.class }) class ExtensionAnnotationProcessorTest { - @BeforeEach - void beforeEach() { - // This is of limited use, since the filesystem doesn't seem to directly generate files, in the current usage - CustomMemoryFileSystemProvider.reset(); - } - @Test @Classpath("org.acme.examples.ClassWithBuildStep") void shouldProcessClassWithBuildStepWithoutErrors(Results results) throws IOException { @@ -40,7 +31,7 @@ void shouldProcessClassWithBuildStepWithoutErrors(Results results) throws IOExce @Classpath("org.acme.examples.ClassWithBuildStep") void shouldGenerateABscFile(Results results) throws IOException { assertNoErrrors(results); - List sources = results.sources; + List sources = results.generatedSources; JavaFileObject bscFile = sources.stream() .filter(source -> source.getName() .endsWith(".bsc")) diff --git a/core/processor/src/test/java/io/quarkus/annotation/processor/fs/CustomMemoryFileSystem.java b/core/processor/src/test/java/io/quarkus/annotation/processor/fs/CustomMemoryFileSystem.java deleted file mode 100644 index 432bd86b334e9..0000000000000 --- a/core/processor/src/test/java/io/quarkus/annotation/processor/fs/CustomMemoryFileSystem.java +++ /dev/null @@ -1,158 +0,0 @@ -package io.quarkus.annotation.processor.fs; - -import java.io.IOException; -import java.net.URI; -import java.nio.ByteBuffer; -import java.nio.channels.SeekableByteChannel; -import java.nio.file.FileStore; -import java.nio.file.FileSystem; -import java.nio.file.Path; -import java.nio.file.PathMatcher; -import java.nio.file.Paths; -import java.nio.file.WatchService; -import java.nio.file.attribute.UserPrincipalLookupService; -import java.nio.file.spi.FileSystemProvider; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -public class CustomMemoryFileSystem extends FileSystem { - - private final Map fileContents = new HashMap<>(); - private final CustomMemoryFileSystemProvider provider; - - public CustomMemoryFileSystem(CustomMemoryFileSystemProvider provider) { - this.provider = provider; - } - - @Override - public FileSystemProvider provider() { - return provider; - } - - @Override - public void close() throws IOException { - // No resources to close - } - - @Override - public boolean isOpen() { - return true; // Always open - } - - @Override - public boolean isReadOnly() { - return false; // This filesystem is writable - } - - @Override - public String getSeparator() { - return "/"; // Unix-style separator - } - - @Override - public Iterable getRootDirectories() { - return Collections.singleton(Paths.get("/")); // Single root directory - } - - @Override - public Iterable getFileStores() { - return Collections.emptyList(); // No file stores - } - - @Override - public Set supportedFileAttributeViews() { - return Collections.emptySet(); // No supported file attribute views - } - - @Override - public Path getPath(String first, String... more) { - String path = first; - for (String segment : more) { - path += "/" + segment; - } - return Paths.get(path); - } - - @Override - public PathMatcher getPathMatcher(String syntaxAndPattern) { - return null; - } - - @Override - public UserPrincipalLookupService getUserPrincipalLookupService() { - return null; - } - - @Override - public WatchService newWatchService() throws IOException { - return null; - } - - public void addFile(URI uri, byte[] content) { - fileContents.put(uri, ByteBuffer.wrap(content)); - } - - static class CustomMemorySeekableByteChannel implements SeekableByteChannel { - - private final ByteBuffer buffer; - - CustomMemorySeekableByteChannel(ByteBuffer buffer) { - this.buffer = buffer; - } - - @Override - public int read(ByteBuffer dst) throws IOException { - int remaining = buffer.remaining(); - int count = Math.min(remaining, dst.remaining()); - if (count > 0) { - ByteBuffer slice = buffer.slice(); - slice.limit(count); - dst.put(slice); - buffer.position(buffer.position() + count); - } - return count; - } - - @Override - public int write(ByteBuffer src) throws IOException { - int count = src.remaining(); - buffer.put(src); - return count; - } - - @Override - public long position() throws IOException { - return buffer.position(); - } - - @Override - public SeekableByteChannel position(long newPosition) throws IOException { - buffer.position((int) newPosition); - return this; - } - - @Override - public long size() throws IOException { - return buffer.limit(); - } - - @Override - public SeekableByteChannel truncate(long size) throws IOException { - buffer.limit((int) size); - return this; - } - - @Override - public boolean isOpen() { - return true; // Always open - } - - @Override - public void close() throws IOException { - // No resources to close - } - } - -} diff --git a/core/processor/src/test/java/io/quarkus/annotation/processor/fs/CustomMemoryFileSystemProvider.java b/core/processor/src/test/java/io/quarkus/annotation/processor/fs/CustomMemoryFileSystemProvider.java deleted file mode 100644 index 8d28a7ae672a6..0000000000000 --- a/core/processor/src/test/java/io/quarkus/annotation/processor/fs/CustomMemoryFileSystemProvider.java +++ /dev/null @@ -1,152 +0,0 @@ -package io.quarkus.annotation.processor.fs; - -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.nio.ByteBuffer; -import java.nio.channels.SeekableByteChannel; -import java.nio.file.AccessMode; -import java.nio.file.CopyOption; -import java.nio.file.DirectoryStream; -import java.nio.file.FileStore; -import java.nio.file.FileSystem; -import java.nio.file.LinkOption; -import java.nio.file.NoSuchFileException; -import java.nio.file.OpenOption; -import java.nio.file.Path; -import java.nio.file.attribute.BasicFileAttributes; -import java.nio.file.attribute.FileAttribute; -import java.nio.file.spi.FileSystemProvider; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -public class CustomMemoryFileSystemProvider extends FileSystemProvider { - - private static final String MEM = "mem"; - - private static Map fileContents = new HashMap(); - - public static void reset() { - fileContents = new HashMap(); - } - - public static Set getCreatedFiles() { - return fileContents.keySet(); - } - - @Override - public String getScheme() { - return MEM; - } - - @Override - public FileSystem newFileSystem(URI uri, Map env) throws IOException { - // There's a bit of a disconnect here between the Elementary JavaFileManager and the memory filesystem, - // even though both are in-memory filesystems - return new CustomMemoryFileSystem(this); - } - - @Override - public FileSystem getFileSystem(URI uri) { - throw new UnsupportedOperationException(); - } - - @Override - public Path getPath(URI uri) { - - if (uri.getScheme() == null || !uri.getScheme() - .equalsIgnoreCase(MEM)) { - throw new IllegalArgumentException("For URI " + uri + ", URI scheme is not '" + MEM + "'"); - - } - - // TODO what should we do here? Can we use the java file manager used by Elementary? - try { - return Path.of(File.createTempFile("mem-fs", "adhoc") - .toURI()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public SeekableByteChannel newByteChannel(Path path, Set options, FileAttribute... attrs) - throws IOException { - if (fileContents.containsKey(path.toUri())) { - ByteBuffer buffer = fileContents.get(path.toUri()); - return new CustomMemoryFileSystem.CustomMemorySeekableByteChannel(buffer); - } else { - throw new NoSuchFileException(path.toString()); - } - } - - @Override - public DirectoryStream newDirectoryStream(Path dir, DirectoryStream.Filter filter) throws IOException { - throw new UnsupportedOperationException(); - } - - @Override - public void createDirectory(Path dir, FileAttribute... attrs) throws IOException { - throw new UnsupportedOperationException(); - } - - @Override - public void delete(Path path) throws IOException { - throw new UnsupportedOperationException(); - } - - @Override - public void copy(Path source, Path target, CopyOption... options) throws IOException { - throw new UnsupportedOperationException(); - } - - @Override - public void move(Path source, Path target, CopyOption... options) throws IOException { - throw new UnsupportedOperationException(); - } - - @Override - public boolean isSameFile(Path path1, Path path2) throws IOException { - return path1.equals(path2); - } - - @Override - public boolean isHidden(Path path) throws IOException { - return false; - } - - @Override - public FileStore getFileStore(Path path) throws IOException { - throw new UnsupportedOperationException(); - } - - @Override - public void checkAccess(Path path, AccessMode... modes) throws IOException { - if (!fileContents.containsKey(path.toUri())) { - throw new NoSuchFileException(path.toString()); - } - } - - @Override - public V getFileAttributeView(Path path, Class type, - LinkOption... options) { - throw new UnsupportedOperationException(); - } - - @Override - public A readAttributes(Path path, Class type, LinkOption... options) - throws IOException { - throw new UnsupportedOperationException(); - } - - @Override - public Map readAttributes(Path path, String attributes, LinkOption... options) throws IOException { - throw new UnsupportedOperationException(); - } - - @Override - public void setAttribute(Path path, String attribute, Object value, LinkOption... options) throws IOException { - throw new UnsupportedOperationException(); - } -} diff --git a/core/processor/src/test/resources/META-INF/services/java.nio.file.spi.FileSystemProvider b/core/processor/src/test/resources/META-INF/services/java.nio.file.spi.FileSystemProvider deleted file mode 100644 index 9582882517a77..0000000000000 --- a/core/processor/src/test/resources/META-INF/services/java.nio.file.spi.FileSystemProvider +++ /dev/null @@ -1 +0,0 @@ -io.quarkus.annotation.processor.fs.CustomMemoryFileSystemProvider \ No newline at end of file