Search in sources :

Example 1 with Factory

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;
        }
    };
}
Also used : JavaExecHandleBuilder(org.gradle.process.internal.JavaExecHandleBuilder) ModuleRegistry(org.gradle.api.internal.classpath.ModuleRegistry) Factory(org.gradle.internal.Factory) File(java.io.File) TestFile(org.gradle.test.fixtures.file.TestFile) Main(org.gradle.launcher.Main)

Example 2 with Factory

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);
                }
            });
        }
    });
}
Also used : DefaultRhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.DefaultRhinoWorkerHandleFactory) Configuration(org.gradle.api.artifacts.Configuration) RhinoExtension(org.gradle.plugins.javascript.rhino.RhinoExtension) BrowserEvaluate(org.gradle.plugins.javascript.envjs.browser.BrowserEvaluate) DefaultRhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.DefaultRhinoWorkerHandleFactory) RhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.RhinoWorkerHandleFactory) JavaScriptExtension(org.gradle.plugins.javascript.base.JavaScriptExtension) WorkerProcessFactory(org.gradle.process.internal.worker.WorkerProcessFactory) DefaultRhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.DefaultRhinoWorkerHandleFactory) RhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.RhinoWorkerHandleFactory) Factory(org.gradle.internal.Factory) ConventionMapping(org.gradle.api.internal.ConventionMapping) Callable(java.util.concurrent.Callable) EnvJsBrowserEvaluator(org.gradle.plugins.javascript.envjs.internal.EnvJsBrowserEvaluator) IConventionAware(org.gradle.api.internal.IConventionAware) File(java.io.File)

Example 3 with Factory

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;
}
Also used : AnalyzingCompiler(sbt.compiler.AnalyzingCompiler) Compiler(com.typesafe.zinc.Compiler) JavaCompiler(xsbti.compile.JavaCompiler) PersistentCache(org.gradle.cache.PersistentCache) Factory(org.gradle.internal.Factory) CacheRepository(org.gradle.cache.CacheRepository) Setup(com.typesafe.zinc.Setup) File(java.io.File)

Example 4 with Factory

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();
}
Also used : WorkerTestClassProcessorFactory(org.gradle.api.internal.tasks.testing.WorkerTestClassProcessorFactory) BuildOperationWorkerRegistry(org.gradle.internal.operations.BuildOperationWorkerRegistry) WorkerProcessFactory(org.gradle.process.internal.worker.WorkerProcessFactory) Factory(org.gradle.internal.Factory) WorkerTestClassProcessorFactory(org.gradle.api.internal.tasks.testing.WorkerTestClassProcessorFactory) ActorFactory(org.gradle.internal.actor.ActorFactory) TestMainAction(org.gradle.api.internal.tasks.testing.processors.TestMainAction) TestClassProcessor(org.gradle.api.internal.tasks.testing.TestClassProcessor) RestartEveryNTestClassProcessor(org.gradle.api.internal.tasks.testing.processors.RestartEveryNTestClassProcessor) ForkingTestClassProcessor(org.gradle.api.internal.tasks.testing.worker.ForkingTestClassProcessor) MaxNParallelTestClassProcessor(org.gradle.api.internal.tasks.testing.processors.MaxNParallelTestClassProcessor) RestartEveryNTestClassProcessor(org.gradle.api.internal.tasks.testing.processors.RestartEveryNTestClassProcessor) TestFramework(org.gradle.api.internal.tasks.testing.TestFramework) MaxNParallelTestClassProcessor(org.gradle.api.internal.tasks.testing.processors.MaxNParallelTestClassProcessor) TrueTimeProvider(org.gradle.internal.time.TrueTimeProvider) ForkingTestClassProcessor(org.gradle.api.internal.tasks.testing.worker.ForkingTestClassProcessor) FileTree(org.gradle.api.file.FileTree) File(java.io.File)

Example 5 with Factory

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();
}
Also used : BTreePersistentIndexedCache(org.gradle.cache.internal.btree.BTreePersistentIndexedCache) ExecutorFactory(org.gradle.internal.concurrent.ExecutorFactory) Factory(org.gradle.internal.Factory) File(java.io.File)

Aggregations

Factory (org.gradle.internal.Factory)7 File (java.io.File)6 WorkerProcessFactory (org.gradle.process.internal.worker.WorkerProcessFactory)2 Compiler (com.typesafe.zinc.Compiler)1 Setup (com.typesafe.zinc.Setup)1 IOException (java.io.IOException)1 Callable (java.util.concurrent.Callable)1 Configuration (org.gradle.api.artifacts.Configuration)1 ResolvedDependency (org.gradle.api.artifacts.ResolvedDependency)1 ResolvedModuleVersion (org.gradle.api.artifacts.ResolvedModuleVersion)1 ComponentArtifactIdentifier (org.gradle.api.artifacts.component.ComponentArtifactIdentifier)1 FileTree (org.gradle.api.file.FileTree)1 ConventionMapping (org.gradle.api.internal.ConventionMapping)1 IConventionAware (org.gradle.api.internal.IConventionAware)1 ImmutableAttributesFactory (org.gradle.api.internal.attributes.ImmutableAttributesFactory)1 ModuleRegistry (org.gradle.api.internal.classpath.ModuleRegistry)1 TestClassProcessor (org.gradle.api.internal.tasks.testing.TestClassProcessor)1 TestFramework (org.gradle.api.internal.tasks.testing.TestFramework)1 WorkerTestClassProcessorFactory (org.gradle.api.internal.tasks.testing.WorkerTestClassProcessorFactory)1 MaxNParallelTestClassProcessor (org.gradle.api.internal.tasks.testing.processors.MaxNParallelTestClassProcessor)1