diff options
author | Dierk König <dierk.koenig@canoo.com> | 2015-11-21 10:09:31 +0100 |
---|---|---|
committer | Dierk König <dierk.koenig@canoo.com> | 2015-11-21 10:09:31 +0100 |
commit | f0807811f48c50b6a5fe7816ef48c148be9f9903 (patch) | |
tree | c61df925b637d26c95086510ee471ac861a36731 /src/main/groovy/frege/gradle/plugins/FregeRuntime.java | |
parent | fa6dce676590c83bc84d130e1241cf585f88a469 (diff) | |
parent | 73dd702743a5b4d8816e495e55c19f391669fc25 (diff) | |
download | frege-gradle-plugin-f0807811f48c50b6a5fe7816ef48c148be9f9903.tar.gz frege-gradle-plugin-f0807811f48c50b6a5fe7816ef48c148be9f9903.tar.bz2 frege-gradle-plugin-f0807811f48c50b6a5fe7816ef48c148be9f9903.zip |
Merge pull request #28 from breskeby/base-plugin
Base plugin
Diffstat (limited to 'src/main/groovy/frege/gradle/plugins/FregeRuntime.java')
-rw-r--r-- | src/main/groovy/frege/gradle/plugins/FregeRuntime.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/main/groovy/frege/gradle/plugins/FregeRuntime.java b/src/main/groovy/frege/gradle/plugins/FregeRuntime.java new file mode 100644 index 0000000..4265d0b --- /dev/null +++ b/src/main/groovy/frege/gradle/plugins/FregeRuntime.java @@ -0,0 +1,63 @@ +package frege.gradle.plugins; + +import com.google.common.collect.Lists; +import org.gradle.api.Buildable; +import org.gradle.api.GradleException; +import org.gradle.api.Project; +import org.gradle.api.artifacts.Dependency; +import org.gradle.api.file.FileCollection; +import org.gradle.api.internal.file.collections.LazilyInitializedFileCollection; +import org.gradle.api.internal.tasks.TaskDependencyResolveContext; + +import java.io.File; +import java.util.List; + +public class FregeRuntime { + + private final Project project; + + public FregeRuntime(Project project) { + this.project = project; + } + + + public FileCollection inferFregeClasspath(final Iterable<File> classpath) { + return new LazilyInitializedFileCollection() { + public String getDisplayName() { + return "Frege runtime classpath"; + } + + public FileCollection createDelegate() { + final FregeJarFile fregeJar = FregeRuntime.this.findFregeJarFile(classpath); + if (fregeJar == null) { + throw new GradleException(String.format("Cannot infer Frege class path because no Frege Jar was found on class path: %s", classpath)); + } + String notation = fregeJar.getDependencyNotation(); + List<Dependency> dependencies = Lists.newArrayList(); + dependencies.add(project.getDependencies().create(notation)); + return project.getConfigurations().detachedConfiguration(dependencies.toArray(new Dependency[dependencies.size()])); + } + + public void visitDependencies(TaskDependencyResolveContext context) { + if (classpath instanceof Buildable) { + context.add(classpath); + } + } + + }; + } + + private FregeJarFile findFregeJarFile(Iterable<File> classpath) { + if (classpath == null) { + return null; + } + for (File file : classpath) { + FregeJarFile fregeJar = FregeJarFile.parse(file); + if (fregeJar != null) { + return fregeJar; + } + } + return null; + } + +} |