use of org.apache.avro.compiler.idl.ParseException in project spf4j by zolyfarkas.
the class SchemaCompileMojo method addMvnIdToIdlsAndMoveToDestination.
public void addMvnIdToIdlsAndMoveToDestination(final Path destPath) throws MojoExecutionException {
Thread currentThread = Thread.currentThread();
ClassLoader contextClassLoader = currentThread.getContextClassLoader();
try {
List<URL> runtimeUrls = createPathUrls(this.sourceDirectory);
getLog().info("Compile classpath: " + runtimeUrls);
URLClassLoader projPathLoader = AccessController.doPrivileged((PrivilegedAction<URLClassLoader>) () -> new URLClassLoader(runtimeUrls.toArray(new URL[runtimeUrls.size()]), contextClassLoader));
currentThread.setContextClassLoader(projPathLoader);
for (String file : getSourceFiles("**/*.avdl")) {
Path destination = destPath.resolve(file);
Path parent = destination.getParent();
if (parent != null) {
Files.createDirectories(parent);
}
File idlFile = new File(sourceDirectory, file);
try {
idlFile = addMvnIdsToIdl(idlFile, projPathLoader);
} catch (ParseException | IOException | RuntimeException ex) {
throw new MojoExecutionException("cannot add mvnId to IDL " + idlFile + ", " + ex.getMessage(), ex);
}
Files.copy(idlFile.toPath(), destination, StandardCopyOption.REPLACE_EXISTING);
}
} catch (IOException | DependencyResolutionRequiredException ex) {
throw new MojoExecutionException("cannot add mvnId to IDL " + this, ex);
} finally {
currentThread.setContextClassLoader(contextClassLoader);
}
}
use of org.apache.avro.compiler.idl.ParseException in project spf4j by zolyfarkas.
the class SchemaCompileMojo method doCompileIDL.
protected void doCompileIDL(final File sourceDir, final String filename) throws IOException {
Thread currentThread = Thread.currentThread();
ClassLoader contextClassLoader = currentThread.getContextClassLoader();
try {
List<URL> runtimeUrls = createPathUrls(sourceDir);
getLog().info("IDL Compile classpath: " + runtimeUrls);
URLClassLoader projPathLoader = AccessController.doPrivileged((PrivilegedAction<URLClassLoader>) () -> new URLClassLoader(runtimeUrls.toArray(new URL[runtimeUrls.size()]), contextClassLoader));
currentThread.setContextClassLoader(projPathLoader);
File file = new File(sourceDir, filename);
String sourceAbsolutePath = sourceDir.getAbsolutePath();
// set the current dir do that sourceIdl will be computed relative to it.
// This makes this plugin not thread safe.
Idl parser;
String origCurrentDir = org.spf4j.base.Runtime.getCurrentDir();
org.spf4j.base.Runtime.setCurrentDir(sourceAbsolutePath);
try {
parser = new Idl(file, projPathLoader);
} finally {
org.spf4j.base.Runtime.setCurrentDir(origCurrentDir);
}
Protocol protocol = parser.CompilationUnit();
publishSchemasAndAttachMvnIdToProtocol(protocol, false, useSchemaReferencesForAvsc);
SpecificCompiler compiler = new SpecificCompiler(protocol);
compiler.setOutputCharacterEncoding(mavenProject.getProperties().getProperty("project.build.sourceEncoding"));
compiler.setStringType(GenericData.StringType.valueOf(stringType));
compiler.setTemplateDir(templateDirectory);
compiler.setFieldVisibility(SpecificCompiler.FieldVisibility.valueOf(fieldVisibility));
compiler.setCreateSetters(createSetters);
compiler.compileToDestination(null, generatedJavaTarget);
} catch (ParseException e) {
throw new IOException(e);
} catch (DependencyResolutionRequiredException drre) {
throw new IOException(drre);
} finally {
currentThread.setContextClassLoader(contextClassLoader);
}
}
Aggregations