use of org.gradle.internal.Factory in project gradle by gradle.
the class InProcessGradleExecuter method getJavaExecBuilder.
private Factory<JavaExecHandleBuilder> getJavaExecBuilder() {
return new Factory<JavaExecHandleBuilder>() {
public JavaExecHandleBuilder create() {
GradleInvocation invocation = buildInvocation();
JavaExecHandleBuilder builder = new JavaExecHandleBuilder(TestFiles.resolver());
builder.workingDir(getWorkingDir());
builder.setExecutable(new File(getJavaHome(), "bin/java"));
Collection<File> classpath = cleanup(GLOBAL_SERVICES.get(ModuleRegistry.class).getAdditionalClassPath().getAsFiles());
builder.classpath(classpath);
builder.jvmArgs(invocation.launcherJvmArgs);
builder.setMain(Main.class.getName());
builder.args(invocation.args);
builder.setStandardInput(connectStdIn());
return builder;
}
};
}
use of org.gradle.internal.Factory in project gradle by gradle.
the class EnvJsPlugin method apply.
public void apply(final Project project) {
project.getPluginManager().apply(RhinoPlugin.class);
project.getPluginManager().apply(ReportingBasePlugin.class);
JavaScriptExtension jsExtension = project.getExtensions().getByType(JavaScriptExtension.class);
final EnvJsExtension envJsExtension = ((ExtensionAware) jsExtension).getExtensions().create(EnvJsExtension.NAME, EnvJsExtension.class);
final Configuration configuration = addConfiguration(project.getConfigurations(), project.getDependencies(), envJsExtension);
final ConventionMapping conventionMapping = ((IConventionAware) envJsExtension).getConventionMapping();
conventionMapping.map("js", new Callable<Configuration>() {
public Configuration call() {
return configuration;
}
});
conventionMapping.map("version", new Callable<String>() {
public String call() {
return EnvJsExtension.DEFAULT_DEPENDENCY_VERSION;
}
});
final RhinoExtension rhinoExtension = ((ExtensionAware) jsExtension).getExtensions().getByType(RhinoExtension.class);
project.getTasks().withType(BrowserEvaluate.class, new Action<BrowserEvaluate>() {
public void execute(BrowserEvaluate task) {
((IConventionAware) task).getConventionMapping().map("evaluator", new Callable<EnvJsBrowserEvaluator>() {
public EnvJsBrowserEvaluator call() {
RhinoWorkerHandleFactory handleFactory = new DefaultRhinoWorkerHandleFactory(workerProcessBuilderFactory);
File workDir = project.getProjectDir();
Factory<File> envJsFactory = new Factory<File>() {
public File create() {
return envJsExtension.getJs().getSingleFile();
}
};
return new EnvJsBrowserEvaluator(handleFactory, rhinoExtension.getClasspath(), envJsFactory, project.getGradle().getStartParameter().getLogLevel(), workDir);
}
});
}
});
}
use of org.gradle.internal.Factory in project gradle by gradle.
the class ZincScalaCompilerFactory method createParallelSafeCompiler.
static Compiler createParallelSafeCompiler(final Iterable<File> scalaClasspath, final Iterable<File> zincClasspath, final xsbti.Logger logger, File gradleUserHome) {
File zincCacheHomeDir = new File(System.getProperty(ZincScalaCompilerUtil.ZINC_CACHE_HOME_DIR_SYSTEM_PROPERTY, gradleUserHome.getAbsolutePath()));
CacheRepository cacheRepository = ZincCompilerServices.getInstance(zincCacheHomeDir).get(CacheRepository.class);
String zincVersion = Setup.zincVersion().published();
String zincCacheKey = String.format("zinc-%s", zincVersion);
String zincCacheName = String.format("Zinc %s compiler cache", zincVersion);
final PersistentCache zincCache = cacheRepository.cache(zincCacheKey).withDisplayName(zincCacheName).withLockOptions(mode(FileLockManager.LockMode.Exclusive)).open();
Compiler compiler;
try {
final File cacheDir = zincCache.getBaseDir();
final String userSuppliedZincDir = System.getProperty("zinc.dir");
if (userSuppliedZincDir != null && !userSuppliedZincDir.equals(cacheDir.getAbsolutePath())) {
LOGGER.warn(ZincScalaCompilerUtil.ZINC_DIR_IGNORED_MESSAGE);
}
compiler = SystemProperties.getInstance().withSystemProperty(ZincScalaCompilerUtil.ZINC_DIR_SYSTEM_PROPERTY, cacheDir.getAbsolutePath(), new Factory<Compiler>() {
@Override
public Compiler create() {
Setup zincSetup = createZincSetup(scalaClasspath, zincClasspath, logger);
return createCompiler(zincSetup, zincCache, logger);
}
});
} finally {
zincCache.close();
}
return compiler;
}
use of org.gradle.internal.Factory in project gradle by gradle.
the class DefaultTestExecuter method execute.
@Override
public void execute(final Test testTask, TestResultProcessor testResultProcessor) {
final TestFramework testFramework = testTask.getTestFramework();
final WorkerTestClassProcessorFactory testInstanceFactory = testFramework.getProcessorFactory();
final BuildOperationWorkerRegistry.Operation currentOperation = buildOperationWorkerRegistry.getCurrent();
final Set<File> classpath = ImmutableSet.copyOf(testTask.getClasspath());
final Factory<TestClassProcessor> forkingProcessorFactory = new Factory<TestClassProcessor>() {
public TestClassProcessor create() {
return new ForkingTestClassProcessor(workerFactory, testInstanceFactory, testTask, classpath, testFramework.getWorkerConfigurationAction(), moduleRegistry, currentOperation);
}
};
Factory<TestClassProcessor> reforkingProcessorFactory = new Factory<TestClassProcessor>() {
public TestClassProcessor create() {
return new RestartEveryNTestClassProcessor(forkingProcessorFactory, testTask.getForkEvery());
}
};
TestClassProcessor processor = new MaxNParallelTestClassProcessor(getMaxParallelForks(testTask), reforkingProcessorFactory, actorFactory);
final FileTree testClassFiles = testTask.getCandidateClassFiles();
Runnable detector;
if (testTask.isScanForTestClasses()) {
TestFrameworkDetector testFrameworkDetector = testTask.getTestFramework().getDetector();
testFrameworkDetector.setTestClassesDirectory(testTask.getTestClassesDir());
testFrameworkDetector.setTestClasspath(classpath);
detector = new DefaultTestClassScanner(testClassFiles, testFrameworkDetector, processor);
} else {
detector = new DefaultTestClassScanner(testClassFiles, null, processor);
}
final Object testTaskOperationId = buildOperationExecutor.getCurrentOperation().getParentId();
new TestMainAction(detector, processor, testResultProcessor, new TrueTimeProvider(), testTaskOperationId, testTask.getPath(), "Gradle Test Run " + testTask.getIdentityPath()).run();
}
use of org.gradle.internal.Factory in project gradle by gradle.
the class DefaultCacheAccess method newCache.
@Override
public <K, V> MultiProcessSafePersistentIndexedCache<K, V> newCache(final PersistentIndexedCacheParameters<K, V> parameters) {
lock.lock();
IndexedCacheEntry entry = caches.get(parameters.getCacheName());
try {
if (entry == null) {
final File cacheFile = new File(baseDir, parameters.getCacheName() + ".bin");
LOG.info("Creating new cache for {}, path {}, access {}", parameters.getCacheName(), cacheFile, this);
Factory<BTreePersistentIndexedCache<K, V>> indexedCacheFactory = new Factory<BTreePersistentIndexedCache<K, V>>() {
public BTreePersistentIndexedCache<K, V> create() {
return doCreateCache(cacheFile, parameters.getKeySerializer(), parameters.getValueSerializer());
}
};
MultiProcessSafePersistentIndexedCache<K, V> indexedCache = new DefaultMultiProcessSafePersistentIndexedCache<K, V>(indexedCacheFactory, fileAccess);
CacheDecorator decorator = parameters.getCacheDecorator();
if (decorator != null) {
indexedCache = decorator.decorate(cacheFile.getAbsolutePath(), parameters.getCacheName(), indexedCache, crossProcessCacheAccess, getCacheAccessWorker());
if (fileLock == null) {
useCache(new Runnable() {
@Override
public void run() {
// Empty initial operation to trigger onStartWork calls
}
});
}
}
entry = new IndexedCacheEntry(parameters, indexedCache);
caches.put(parameters.getCacheName(), entry);
if (fileLock != null) {
indexedCache.afterLockAcquire(stateAtOpen);
}
} else {
entry.assertCompatibleCacheParameters(parameters);
}
} finally {
lock.unlock();
}
return entry.getCache();
}
Aggregations