Search in sources :

Example 16 with GradleException

use of org.gradle.api.GradleException in project byte-buddy by raphw.

the class TransformationAction method transform.

/**
     * Applies all registered transformations.
     *
     * @param root       The root directory to process.
     * @param entryPoint The transformation's entry point.
     * @param classPath  A list of class path elements expected by the processed classes.
     * @param plugins    The plugins to apply.
     * @throws IOException If an I/O exception occurs.
     */
private void transform(File root, Iterable<? extends File> classPath, EntryPoint entryPoint, List<Plugin> plugins) throws IOException {
    List<ClassFileLocator> classFileLocators = new ArrayList<ClassFileLocator>();
    classFileLocators.add(new ClassFileLocator.ForFolder(root));
    for (File artifact : classPath) {
        classFileLocators.add(artifact.isFile() ? ClassFileLocator.ForJarFile.of(artifact) : new ClassFileLocator.ForFolder(artifact));
    }
    ClassFileLocator classFileLocator = new ClassFileLocator.Compound(classFileLocators);
    try {
        TypePool typePool = new TypePool.Default.WithLazyResolution(new TypePool.CacheProvider.Simple(), classFileLocator, TypePool.Default.ReaderMode.FAST, TypePool.ClassLoading.ofBootPath());
        project.getLogger().info("Processing class files located in in: {}", root);
        ByteBuddy byteBuddy;
        try {
            byteBuddy = entryPoint.getByteBuddy();
        } catch (Throwable throwable) {
            throw new GradleException("Cannot create Byte Buddy instance", throwable);
        }
        processDirectory(root, root, byteBuddy, entryPoint, byteBuddyExtension.getMethodNameTransformer(), classFileLocator, typePool, plugins);
    } finally {
        classFileLocator.close();
    }
}
Also used : ArrayList(java.util.ArrayList) ByteBuddy(net.bytebuddy.ByteBuddy) ClassFileLocator(net.bytebuddy.dynamic.ClassFileLocator) GradleException(org.gradle.api.GradleException) File(java.io.File) TypePool(net.bytebuddy.pool.TypePool)

Example 17 with GradleException

use of org.gradle.api.GradleException in project gradle by gradle.

the class ClasspathUtil method getClasspathForClass.

public static File getClasspathForClass(Class<?> targetClass) {
    URI location;
    try {
        CodeSource codeSource = targetClass.getProtectionDomain().getCodeSource();
        if (codeSource != null && codeSource.getLocation() != null) {
            location = toURI(codeSource.getLocation());
            if (location.getScheme().equals("file")) {
                return new File(location);
            }
        }
        if (targetClass.getClassLoader() != null) {
            String resourceName = targetClass.getName().replace('.', '/') + ".class";
            URL resource = targetClass.getClassLoader().getResource(resourceName);
            if (resource != null) {
                return getClasspathForResource(resource, resourceName);
            }
        }
        throw new GradleException(String.format("Cannot determine classpath for class %s.", targetClass.getName()));
    } catch (URISyntaxException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
Also used : GradleException(org.gradle.api.GradleException) URISyntaxException(java.net.URISyntaxException) CodeSource(java.security.CodeSource) URI(java.net.URI) File(java.io.File) URL(java.net.URL)

Example 18 with GradleException

use of org.gradle.api.GradleException in project gradle by gradle.

the class TransformingClassLoader method findClass.

@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
    if (!shouldTransform(name)) {
        return super.findClass(name);
    }
    String resourceName = name.replace('.', '/') + ".class";
    URL resource = findResource(resourceName);
    byte[] bytes;
    CodeSource codeSource;
    try {
        if (resource != null) {
            bytes = loadBytecode(resource);
            bytes = transform(name, bytes);
            URL codeBase = ClasspathUtil.getClasspathForResource(resource, resourceName).toURI().toURL();
            codeSource = new CodeSource(codeBase, (Certificate[]) null);
        } else {
            bytes = generateMissingClass(name);
            codeSource = null;
        }
    } catch (Exception e) {
        throw new GradleException(String.format("Could not load class '%s' from %s.", name, resource), e);
    }
    if (bytes == null) {
        throw new ClassNotFoundException(name);
    }
    String packageName = StringUtils.substringBeforeLast(name, ".");
    Package p = getPackage(packageName);
    if (p == null) {
        definePackage(packageName, null, null, null, null, null, null, null);
    }
    return defineClass(name, bytes, 0, bytes.length, codeSource);
}
Also used : GradleException(org.gradle.api.GradleException) CodeSource(java.security.CodeSource) URL(java.net.URL) GradleException(org.gradle.api.GradleException) IOException(java.io.IOException)

Example 19 with GradleException

use of org.gradle.api.GradleException in project gradle by gradle.

the class DefaultBuildOperationProcessor method doRun.

private <T extends BuildOperation> void doRun(BuildOperationWorker<T> worker, Action<BuildOperationQueue<T>> generator) {
    BuildOperationQueue<T> queue = buildOperationQueueFactory.create(buildOperationWorkerRegistry.getCurrent(), fixedSizePool, worker);
    List<GradleException> failures = Lists.newArrayList();
    try {
        generator.execute(queue);
    } catch (Exception e) {
        failures.add(new BuildOperationQueueFailure("There was a failure while populating the build operation queue: " + e.getMessage(), e));
        queue.cancel();
    }
    try {
        queue.waitForCompletion();
    } catch (MultipleBuildOperationFailures e) {
        failures.add(e);
    }
    if (failures.size() == 1) {
        throw failures.get(0);
    } else if (failures.size() > 1) {
        throw new DefaultMultiCauseException(formatMultipleFailureMessage(failures), failures);
    }
}
Also used : GradleException(org.gradle.api.GradleException) DefaultMultiCauseException(org.gradle.internal.exceptions.DefaultMultiCauseException) GradleException(org.gradle.api.GradleException) DefaultMultiCauseException(org.gradle.internal.exceptions.DefaultMultiCauseException)

Example 20 with GradleException

use of org.gradle.api.GradleException in project gradle by gradle.

the class JavadocConverter method parse.

public DocComment parse(final PropertyMetaData propertyMetaData, final GenerationListener listener) {
    listener.start(String.format("property %s", propertyMetaData));
    try {
        ClassMetaData ownerClass = propertyMetaData.getOwnerClass();
        String rawCommentText = propertyMetaData.getRawCommentText();
        try {
            CommentSource commentSource = new InheritedPropertyCommentSource(propertyMetaData, listener);
            DocCommentImpl docComment = parse(rawCommentText, ownerClass, commentSource, listener);
            adjustGetterComment(docComment);
            return docComment;
        } catch (Exception e) {
            throw new GradleException(String.format("Could not convert javadoc comment to docbook.%nClass: %s%nProperty: %s%nComment: %s", ownerClass.getClassName(), propertyMetaData.getName(), rawCommentText), e);
        }
    } finally {
        listener.finish();
    }
}
Also used : GradleException(org.gradle.api.GradleException) ClassMetaData(org.gradle.build.docs.dsl.source.model.ClassMetaData) GradleException(org.gradle.api.GradleException)

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