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();
}
}
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);
}
}
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);
}
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);
}
}
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();
}
}
Aggregations