use of org.spf4j.maven.MavenSchemaResolver in project spf4j by zolyfarkas.
the class SchemaMojoBase method execute.
/**
* Children must call this.
* @throws MojoExecutionException
* @throws MojoFailureException
*/
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (useSchemaReferencesForAvsc && SchemaRefWriter.isSchemaRefsSupported()) {
Map<String, String> currentMappings;
try {
currentMappings = idx2Name();
} catch (IOException ex) {
throw new MojoExecutionException("Exception loading schema index: " + generatedAvscTarget.toPath().resolve(SCHEMA_INDEX_FILENAME), ex);
}
MavenSchemaResolver res = new MavenSchemaResolver(repoSystem, getMavenSession().getRepositorySession(), mavenProject.getRemoteProjectRepositories(), schemaArtifactClassifier, schemaArtifactExtension);
SchemaResolvers.registerDefault(new SchemaResolver() {
@Override
public Schema resolveSchema(final String id) {
SchemaRef ref = new SchemaRef(id);
if (mavenProject.getGroupId().equals(ref.getGroupId()) && mavenProject.getArtifactId().equals(ref.getArtifactId()) && mavenProject.getVersion().equals(ref.getVersion())) {
String name = currentMappings.get(ref.getRef());
Path schemaPath = generatedAvscTarget.toPath().resolve(name.replace('.', '/') + ".avsc");
try (BufferedInputStream bis = new BufferedInputStream(Files.newInputStream(schemaPath))) {
return new Schema.Parser().parse(bis);
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
} else {
return res.resolveSchema(id);
}
}
@Override
public String getId(final Schema schema) {
return res.getId(schema);
}
});
}
}
Aggregations