use of org.gradle.api.Buildable in project gradle by gradle.
the class ScalaRuntime method inferScalaClasspath.
/**
* Searches the specified class path for a 'scala-library' Jar, and returns a class path
* containing a corresponding (same version) 'scala-compiler' Jar and its dependencies.
*
* <p>The returned class path may be empty, or may fail to resolve when asked for its contents.
*
* @param classpath a class path containing a 'scala-library' Jar
* @return a class path containing a corresponding 'scala-compiler' Jar and its dependencies
*/
public FileCollection inferScalaClasspath(final Iterable<File> classpath) {
// would differ in the following ways: 1. live (not sure if we want live here) 2. no autowiring (probably want autowiring here)
return new LazilyInitializedFileCollection() {
@Override
public String getDisplayName() {
return "Scala runtime classpath";
}
@Override
public FileCollection createDelegate() {
try {
return inferScalaClasspath();
} catch (RuntimeException e) {
return new FailingFileCollection(getDisplayName(), e);
}
}
private Configuration inferScalaClasspath() {
File scalaLibraryJar = findScalaJar(classpath, "library");
File scala3LibraryJar = findScalaJar(classpath, "library_3");
boolean isScala3 = scala3LibraryJar != null;
if (scalaLibraryJar == null && scala3LibraryJar == null) {
throw new GradleException(String.format("Cannot infer Scala class path because no Scala library Jar was found. " + "Does %s declare dependency to scala-library? Searched classpath: %s.", project, classpath));
}
String scalaVersion;
if (isScala3) {
scalaVersion = getScalaVersion(scala3LibraryJar);
} else {
scalaVersion = getScalaVersion(scalaLibraryJar);
}
if (scalaVersion == null) {
throw new AssertionError(String.format("Unexpectedly failed to parse version of Scala Jar file: %s in %s", scalaLibraryJar, project));
}
String zincVersion = project.getExtensions().getByType(ScalaPluginExtension.class).getZincVersion().get();
DefaultExternalModuleDependency compilerBridgeJar = getScalaBridgeDependency(scalaVersion, zincVersion);
compilerBridgeJar.setTransitive(false);
compilerBridgeJar.artifact(artifact -> {
if (!isScala3) {
artifact.setClassifier("sources");
}
artifact.setType("jar");
artifact.setExtension("jar");
artifact.setName(compilerBridgeJar.getName());
});
DefaultExternalModuleDependency compilerInterfaceJar = getScalaCompilerInterfaceDependency(scalaVersion, zincVersion);
Configuration scalaRuntimeClasspath = isScala3 ? project.getConfigurations().detachedConfiguration(getScalaCompilerDependency(scalaVersion), compilerBridgeJar, compilerInterfaceJar, getScaladocDependency(scalaVersion)) : project.getConfigurations().detachedConfiguration(getScalaCompilerDependency(scalaVersion), compilerBridgeJar, compilerInterfaceJar);
jvmEcosystemUtilities.configureAsRuntimeClasspath(scalaRuntimeClasspath);
return scalaRuntimeClasspath;
}
// let's override this so that delegate isn't created at autowiring time (which would mean on every build)
@Override
public void visitDependencies(TaskDependencyResolveContext context) {
if (classpath instanceof Buildable) {
context.add(classpath);
}
}
};
}
use of org.gradle.api.Buildable in project gradle by gradle.
the class TaskDependencyMatchers method builtBy.
@Factory
public static <T extends Buildable> Matcher<T> builtBy(final Matcher<? extends Iterable<String>> matcher) {
return new BaseMatcher<T>() {
@Override
public boolean matches(Object o) {
Buildable task = (Buildable) o;
Set<String> names = new HashSet<String>();
Set<? extends Task> depTasks = task.getBuildDependencies().getDependencies(null);
for (Task depTask : depTasks) {
names.add(depTask.getName());
}
boolean matches = matcher.matches(names);
if (!matches) {
StringDescription description = new StringDescription();
matcher.describeTo(description);
System.out.println(String.format("expected %s, got %s.", description.toString(), names));
}
return matches;
}
@Override
public void describeTo(Description description) {
description.appendText("a Buildable that is built by ").appendDescriptionOf(matcher);
}
};
}
Aggregations