use of org.gradle.internal.Factory in project gradle by gradle.
the class DefaultResolvedDependencyTest method createResolvedArtifact.
public static DefaultResolvedArtifact createResolvedArtifact(final Mockery context, final String name, final String type, final String extension, final File file) {
final IvyArtifactName artifactStub = context.mock(IvyArtifactName.class, "artifact" + name);
final ImmutableAttributesFactory factory = context.mock(ImmutableAttributesFactory.class);
final BuildOperationExecutor buildOperationExecutor = context.mock(BuildOperationExecutor.class);
context.checking(new Expectations() {
{
allowing(factory).builder(ImmutableAttributes.EMPTY);
allowing(artifactStub).getName();
will(returnValue(name));
allowing(artifactStub).getType();
will(returnValue(type));
allowing(artifactStub).getExtension();
will(returnValue(extension));
allowing(artifactStub).getClassifier();
will(returnValue(null));
}
});
final Factory artifactSource = context.mock(Factory.class);
context.checking(new Expectations() {
{
allowing(artifactSource).create();
will(returnValue(file));
}
});
final ResolvedDependency resolvedDependency = context.mock(ResolvedDependency.class);
final ResolvedModuleVersion version = context.mock(ResolvedModuleVersion.class);
context.checking(new Expectations() {
{
allowing(resolvedDependency).getModule();
will(returnValue(version));
allowing(version).getId();
will(returnValue(new DefaultModuleVersionIdentifier("group", name, "1.2")));
}
});
return new DefaultResolvedArtifact(resolvedDependency.getModule().getId(), artifactStub, context.mock(ComponentArtifactIdentifier.class), context.mock(TaskDependency.class), artifactSource);
}
use of org.gradle.internal.Factory in project gradle by gradle.
the class ZincScalaCompilerFactory method getCompilerInterface.
// parallel safe version of Compiler.compilerInterface()
private static File getCompilerInterface(final Setup setup, final ScalaInstance instance, PersistentCache zincCache, final xsbti.Logger logger) {
final String sbtInterfaceFileName = Compiler.interfaceId(instance.actualVersion()) + ".jar";
final File compilerInterface = new File(setup.cacheDir(), sbtInterfaceFileName);
if (compilerInterface.exists()) {
return zincCache.useCache(new Factory<File>() {
@Override
public File create() {
return compilerInterface;
}
});
}
try {
// Compile the interface to a temp file and then copy it to the cache folder.
// This avoids sporadic cache lock timeouts when the compiler interface JAR takes
// a long time to generate while avoiding starving multiple compiler daemons.
final File tmpDir = new File(zincCache.getBaseDir(), "tmp");
tmpDir.mkdirs();
final File tempFile = File.createTempFile("zinc", ".jar", tmpDir);
final Clock timer = new Clock();
sbt.compiler.IC.compileInterfaceJar(sbtInterfaceFileName, setup.compilerInterfaceSrc(), tempFile, setup.sbtInterface(), instance, logger);
final String interfaceCompletedMessage = String.format("Zinc interface compilation took %s", timer.getElapsed());
if (timer.getElapsedMillis() > 30000) {
LOGGER.warn(interfaceCompletedMessage);
} else {
LOGGER.debug(interfaceCompletedMessage);
}
return zincCache.useCache(new Factory<File>() {
public File create() {
// Avoid copying over same existing file to avoid locking problems
if (!compilerInterface.exists()) {
GFileUtils.moveFile(tempFile, compilerInterface);
} else {
GFileUtils.deleteQuietly(tempFile);
}
return compilerInterface;
}
});
} catch (IOException e) {
// fall back to the default logic
return zincCache.useCache(new Factory<File>() {
public File create() {
return Compiler.compilerInterface(setup, instance, logger);
}
});
}
}
Aggregations