Search in sources :

Example 11 with GradleException

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);
    }
}
Also used : GradleException(org.gradle.api.GradleException) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 12 with GradleException

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);
    }
}
Also used : GradleException(org.gradle.api.GradleException) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 13 with GradleException

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);
    }
}
Also used : GradleException(org.gradle.api.GradleException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileInputStream(java.io.FileInputStream) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) GradleException(org.gradle.api.GradleException)

Example 14 with GradleException

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());
}
Also used : MalformedURLException(java.net.MalformedURLException) Enhancer(org.hibernate.bytecode.enhance.spi.Enhancer) GradleException(org.gradle.api.GradleException) URLClassLoader(java.net.URLClassLoader) ArrayList(java.util.ArrayList) File(java.io.File) URL(java.net.URL)

Example 15 with GradleException

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();
    }
}
Also used : GradleException(org.gradle.api.GradleException) ArrayList(java.util.ArrayList) EntryPoint(net.bytebuddy.build.EntryPoint) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException) Plugin(net.bytebuddy.build.Plugin)

Aggregations

GradleException (org.gradle.api.GradleException)99 File (java.io.File)33 IOException (java.io.IOException)25 TaskAction (org.gradle.api.tasks.TaskAction)12 ArrayList (java.util.ArrayList)10 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)9 AndroidDependencyTree (com.taobao.android.builder.dependency.AndroidDependencyTree)8 UncheckedIOException (org.gradle.api.UncheckedIOException)7 HashSet (java.util.HashSet)6 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)5 FileOutputStream (java.io.FileOutputStream)5 Method (java.lang.reflect.Method)5 ProcessOutputHandler (com.android.ide.common.process.ProcessOutputHandler)4 URL (java.net.URL)4 List (java.util.List)4 Map (java.util.Map)4 ConsoleRenderer (org.gradle.internal.logging.ConsoleRenderer)4 ClassReader (org.objectweb.asm.ClassReader)4 ExecutorServicesHelper (com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper)3 MalformedURLException (java.net.MalformedURLException)3