MavenSchemaResolver implements SchemaResolver { @Override @SuppressFBWarnings("PCAIL_POSSIBLE_CONSTANT_ALLOCATION_IN_LOOP") public Schema resolveSchema(final String id) { SchemaRef ref = new SchemaRef(id); try { File artifact = MavenRepositoryUtils.resolveArtifact(ref.getGroupId(), ref.getArtifactId(), classifier, extension, ref.getVersion(), remotes, repoSystem, repoSystemSession); URI zipUri = URI.create("jar:" + artifact.toURI().toURL()); FileSystem zipFs; synchronized (zipUri.toString().intern()) { try { zipFs = FileSystems.newFileSystem(zipUri, Collections.emptyMap()); } catch (FileSystemAlreadyExistsException ex) { zipFs = FileSystems.getFileSystem(zipUri); } catch (ZipError ze) { throw new AvroRuntimeException("Cannot resolve " + id, ze); } } for (Path root : zipFs.getRootDirectories()) { Path index = root.resolve("schema_index.properties"); if (Files.exists(index)) { Properties prop = new Properties(); try (BufferedReader indexReader = Files.newBufferedReader(index)) { prop.load(indexReader); } String schemaName = prop.getProperty(ref.getRef()); if (schemaName == null) { throw new AvroRuntimeException("unable to resolve schema: " + id + " missing from index " + index); } Path schemaPath = root.resolve(schemaName.replace('.', '/') + ".avsc"); try (BufferedInputStream bis = new BufferedInputStream(Files.newInputStream(schemaPath))) { return new Schema.Parser().parse(bis); } } } throw new IOException("unable to resolve schema: " + id); } catch (ArtifactResolutionException | IOException ex) { throw new AvroRuntimeException("Cannot resolve " + id, ex); } } MavenSchemaResolver(final RepositorySystem repoSystem, final RepositorySystemSession repoSystemSession,
          final List<RemoteRepository> remotes, final String classifier, final String extension);  MavenSchemaResolver(final List<RemoteRepository> repos,
          final File localRepo, final String classifier, final String extension); @Override @SuppressFBWarnings("PCAIL_POSSIBLE_CONSTANT_ALLOCATION_IN_LOOP") Schema resolveSchema(final String id); @Override String getId(final Schema schema); @Override void registerAsDefault(); @Override String toString();  }
@Test public void testSchemaResolution() { File localRepo = new File(System.getProperty("user.home"), ".m2/repository"); RemoteRepository bintray = new RemoteRepository.Builder("central", "default", "https: .build(); MavenSchemaResolver resolver = new MavenSchemaResolver(Collections.singletonList(bintray), localRepo, null, "jar"); String mvnId = "org.spf4j.avro:core-schema:0.2:6"; Schema resolveSchema = resolver.resolveSchema(mvnId); Assert.assertEquals("ServiceError", resolveSchema.getName()); }