use of org.gradle.api.GradleException in project atlas by alibaba.
the class ExecutorServicesHelper method execute.
public void execute(List<Runnable> runnables) throws InterruptedException {
if (runnables.isEmpty()) {
return;
}
final CountDownLatch countDownLatch = new CountDownLatch(runnables.size());
final int size = runnables.size();
for (final Runnable runnable : runnables) {
this.executorService.execute(new Runnable() {
@Override
public void run() {
try {
if (!hasException) {
info("excute " + name + " task at " + index.incrementAndGet() + "/" + size);
runnable.run();
}
} catch (GradleException gradleException) {
hasException = true;
exception = gradleException;
} finally {
countDownLatch.countDown();
}
}
});
}
countDownLatch.await();
if (hasException) {
throw new GradleException(exception.getMessage(), exception);
}
}
use of org.gradle.api.GradleException in project atlas by alibaba.
the class ExecutorServicesHelper method execute.
public <T> void execute(BlockingQueue<T> blockingQueue, Handler<T> handler) throws InterruptedException {
if (blockingQueue.isEmpty()) {
return;
}
final CountDownLatch countDownLatch = new CountDownLatch(this.threadCount);
for (int i = 0; i < this.threadCount; i++) {
this.executorService.execute(new Runnable() {
@Override
public void run() {
try {
while (true) {
T t = blockingQueue.poll();
if (null == t) {
break;
}
handler.handle(t);
}
} catch (GradleException gradleException) {
hasException = true;
exception = gradleException;
} finally {
countDownLatch.countDown();
}
}
});
}
countDownLatch.await();
if (hasException) {
throw new GradleException(exception.getMessage(), exception);
}
}
use of org.gradle.api.GradleException in project hibernate-orm by hibernate.
the class HibernatePlugin method doEnhancement.
private byte[] doEnhancement(File root, File javaClassFile, Enhancer enhancer) {
try {
String className = javaClassFile.getAbsolutePath().substring(root.getAbsolutePath().length() + 1, javaClassFile.getAbsolutePath().length() - ".class".length()).replace(File.separatorChar, '.');
ByteArrayOutputStream originalBytes = new ByteArrayOutputStream();
FileInputStream fileInputStream = new FileInputStream(javaClassFile);
try {
byte[] buffer = new byte[1024];
int length;
while ((length = fileInputStream.read(buffer)) != -1) {
originalBytes.write(buffer, 0, length);
}
} finally {
fileInputStream.close();
}
return enhancer.enhance(className, originalBytes.toByteArray());
} catch (Exception e) {
throw new GradleException("Unable to enhance class : " + javaClassFile, e);
}
}
use of org.gradle.api.GradleException in project hibernate-orm by hibernate.
the class HibernatePlugin method toClassLoader.
private ClassLoader toClassLoader(FileCollection runtimeClasspath) {
List<URL> urls = new ArrayList<URL>();
for (File file : runtimeClasspath) {
try {
urls.add(file.toURI().toURL());
logger.debug("Adding classpath entry for " + file.getAbsolutePath());
} catch (MalformedURLException e) {
throw new GradleException("Unable to resolve classpath entry to URL : " + file.getAbsolutePath(), e);
}
}
return new URLClassLoader(urls.toArray(new URL[urls.size()]), Enhancer.class.getClassLoader());
}
use of org.gradle.api.GradleException in project byte-buddy by raphw.
the class TransformationAction method processOutputDirectory.
/**
* Processes all class files within the given directory.
*
* @param root The root directory to process.
* @param classPath A list of class path elements expected by the processed classes.
* @throws IOException If an I/O exception occurs.
*/
private void processOutputDirectory(File root, Iterable<? extends File> classPath) throws IOException {
if (!root.isDirectory()) {
throw new GradleException("Target location does not exist or is no directory: " + root);
}
ClassLoaderResolver classLoaderResolver = new ClassLoaderResolver();
try {
List<Plugin> plugins = new ArrayList<Plugin>(byteBuddyExtension.getTransformations().size());
for (Transformation transformation : byteBuddyExtension.getTransformations()) {
String plugin = transformation.getPlugin();
try {
plugins.add((Plugin) Class.forName(plugin, false, classLoaderResolver.resolve(transformation.getClassPath(root, classPath))).getDeclaredConstructor().newInstance());
project.getLogger().info("Created plugin: {}", plugin);
} catch (Exception exception) {
if (exception instanceof GradleException) {
throw (GradleException) exception;
}
throw new GradleException("Cannot create plugin: " + transformation.getRawPlugin(), exception);
}
}
EntryPoint entryPoint = byteBuddyExtension.getInitialization().getEntryPoint(classLoaderResolver, root, classPath);
project.getLogger().info("Resolved entry point: {}", entryPoint);
transform(root, classPath, entryPoint, plugins);
} finally {
classLoaderResolver.close();
}
}
Aggregations