Search in sources :

Example 6 with FileTree

use of org.gradle.api.file.FileTree 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 7 with FileTree

use of org.gradle.api.file.FileTree in project rest.li by linkedin.

the class GenerateAvroSchemaTask method generate.

@TaskAction
public void generate() {
    FileTree inputDataSchemaFiles = getSuffixedFiles(getProject(), _inputDir, PegasusPlugin.DATA_TEMPLATE_FILE_SUFFIXES);
    List<String> inputDataSchemaFilenames = StreamSupport.stream(inputDataSchemaFiles.spliterator(), false).map(File::getPath).collect(Collectors.toList());
    if (inputDataSchemaFilenames.isEmpty()) {
        throw new StopExecutionException("There are no data schema input files. Skip generating avro schema.");
    }
    getProject().getLogger().info("Generating Avro schemas ...");
    getProject().getLogger().lifecycle("There are {} data schema input files. Using input root folder: {}", inputDataSchemaFilenames.size(), _inputDir);
    _destinationDir.mkdirs();
    String resolverPathStr = _resolverPath.plus(getProject().files(_inputDir)).getAsPath();
    FileCollection _pathedCodegenClasspath;
    try {
        _pathedCodegenClasspath = PathingJarUtil.generatePathingJar(getProject(), getName(), _codegenClasspath, false);
    } catch (IOException e) {
        throw new GradleException("Error occurred generating pathing JAR.", e);
    }
    getProject().javaexec(javaExecSpec -> {
        String resolverPathArg = resolverPathStr;
        if (isEnableArgFile()) {
            resolverPathArg = ArgumentFileGenerator.getArgFileSyntax(ArgumentFileGenerator.createArgFile("generateAvro_resolverPath", Collections.singletonList(resolverPathArg), getTemporaryDir()));
        }
        javaExecSpec.setMain("com.linkedin.data.avro.generator.AvroSchemaGenerator");
        javaExecSpec.setClasspath(_pathedCodegenClasspath);
        javaExecSpec.jvmArgs("-Dgenerator.resolver.path=" + resolverPathArg);
        String translateOptionalDefault = getTranslateOptionalDefault();
        if (translateOptionalDefault != null) {
            javaExecSpec.jvmArgs("-Dgenerator.avro.optional.default=" + translateOptionalDefault);
        }
        String overrideNamespace = getOverrideNamespace();
        if (overrideNamespace != null) {
            javaExecSpec.jvmArgs("-Dgenerator.avro.namespace.override=" + overrideNamespace);
        }
        String typeRefPropertiesExcludeList = getTypeRefPropertiesExcludeList();
        if (typeRefPropertiesExcludeList == null) {
            // unless overridden,
            // by default gradle plugin tasks will set this to have "validate" "java" so it is backward compatible
            typeRefPropertiesExcludeList = "validate,data";
        }
        javaExecSpec.jvmArgs(String.format("-D%s=%s", TYPERF_PROPERTIES_EXCLUDE, typeRefPropertiesExcludeList));
        javaExecSpec.args(_destinationDir.getPath());
        javaExecSpec.args(inputDataSchemaFilenames);
    });
}
Also used : StopExecutionException(org.gradle.api.tasks.StopExecutionException) GradleException(org.gradle.api.GradleException) FileTree(org.gradle.api.file.FileTree) IOException(java.io.IOException) FileCollection(org.gradle.api.file.FileCollection) TaskAction(org.gradle.api.tasks.TaskAction)

Example 8 with FileTree

use of org.gradle.api.file.FileTree in project rest.li by linkedin.

the class GenerateDataTemplateTask method generate.

@TaskAction
public void generate() {
    FileTree inputDataSchemaFiles = getSuffixedFiles(getProject(), _inputDir, PegasusPlugin.DATA_TEMPLATE_FILE_SUFFIXES);
    List<String> inputDataSchemaFilenames = StreamSupport.stream(inputDataSchemaFiles.spliterator(), false).map(File::getPath).collect(Collectors.toList());
    if (inputDataSchemaFilenames.isEmpty()) {
        getLogger().lifecycle("There are no data schema input files. Skip generating data template.");
        return;
    }
    getLogger().lifecycle("There are {} data schema input files. Using input root folder: {}", inputDataSchemaFilenames.size(), _inputDir);
    _destinationDir.mkdirs();
    String resolverPathStr = _resolverPath.plus(getProject().files(_inputDir)).getAsPath();
    FileCollection _pathedCodegenClasspath;
    try {
        _pathedCodegenClasspath = PathingJarUtil.generatePathingJar(getProject(), "generateDataTemplate", _codegenClasspath, true);
    } catch (IOException e) {
        throw new GradleException("Error occurred generating pathing JAR.", e);
    }
    getProject().javaexec(javaExecSpec -> {
        String resolverPathArg = resolverPathStr;
        if (isEnableArgFile()) {
            resolverPathArg = ArgumentFileGenerator.getArgFileSyntax(ArgumentFileGenerator.createArgFile("generateDataTemplate_resolverPath", Collections.singletonList(resolverPathArg), getTemporaryDir()));
        }
        javaExecSpec.setMain("com.linkedin.pegasus.generator.DataTemplateGeneratorCmdLineApp");
        javaExecSpec.setClasspath(_pathedCodegenClasspath);
        javaExecSpec.args("--resolverPath", resolverPathArg);
        if (_generateLowercasePath != null && _generateLowercasePath == false) {
            javaExecSpec.args("--generateCaseSensitivePath");
        }
        if (_generateImported != null && _generateImported == false) {
            javaExecSpec.args("--skipImportedSchemas");
        }
        if (_generateFieldMask != null && _generateFieldMask == false) {
            javaExecSpec.args("--skipFieldMask");
        }
        if (_resolverDirectories != null) {
            javaExecSpec.args("--resolverSchemaDirectories", String.join(",", _resolverDirectories));
        }
        javaExecSpec.args("--rootPath", getProject().getRootDir().getPath());
        javaExecSpec.args("--targetDir", _destinationDir.getPath());
        javaExecSpec.args(_inputDir);
    });
}
Also used : GradleException(org.gradle.api.GradleException) FileTree(org.gradle.api.file.FileTree) IOException(java.io.IOException) FileCollection(org.gradle.api.file.FileCollection) TaskAction(org.gradle.api.tasks.TaskAction)

Example 9 with FileTree

use of org.gradle.api.file.FileTree in project rest.li by linkedin.

the class ValidateExtensionSchemaTask method validateExtensionSchema.

@TaskAction
public void validateExtensionSchema() throws IOException {
    FileTree inputDataSchemaFiles = getSuffixedFiles(getProject(), _inputDir, PegasusPlugin.DATA_TEMPLATE_FILE_SUFFIXES);
    List<String> inputDataSchemaFilenames = StreamSupport.stream(inputDataSchemaFiles.spliterator(), false).map(File::getPath).collect(Collectors.toList());
    if (inputDataSchemaFilenames.isEmpty()) {
        getLogger().lifecycle("There are no extension schema input files. Skip validating extension schema");
        return;
    }
    getProject().getLogger().info("Verifying extension schemas ...");
    String resolverPathStr = _resolverPath.plus(getProject().files(_inputDir)).getAsPath();
    FileCollection _pathedClasspath;
    try {
        _pathedClasspath = PathingJarUtil.generatePathingJar(getProject(), getName(), _classPath, false);
    } catch (IOException e) {
        throw new GradleException("Error occurred generating pathing JAR.", e);
    }
    getProject().javaexec(javaExecSpec -> {
        String resolverPathArg = resolverPathStr;
        if (isEnableArgFile()) {
            resolverPathArg = ArgumentFileGenerator.getArgFileSyntax(ArgumentFileGenerator.createArgFile("validateExtensionSchema_resolverPath", Collections.singletonList(resolverPathArg), getTemporaryDir()));
        }
        javaExecSpec.setMain("com.linkedin.restli.tools.data.ExtensionSchemaValidationCmdLineApp");
        javaExecSpec.setClasspath(_pathedClasspath);
        javaExecSpec.args(resolverPathArg);
        javaExecSpec.args(_inputDir.getAbsolutePath());
    });
}
Also used : GradleException(org.gradle.api.GradleException) FileTree(org.gradle.api.file.FileTree) IOException(java.io.IOException) FileCollection(org.gradle.api.file.FileCollection) TaskAction(org.gradle.api.tasks.TaskAction)

Example 10 with FileTree

use of org.gradle.api.file.FileTree in project rest.li by linkedin.

the class GeneratePegasusSnapshotTask method generatePegasusSnapshot.

@TaskAction
public void generatePegasusSnapshot() {
    FileTree inputDataSchemaFiles = _extensionSchema ? getSuffixedFiles(getProject(), _inputDir, PegasusPlugin.PDL_FILE_SUFFIX) : getSuffixedFiles(getProject(), _inputDir, PegasusPlugin.DATA_TEMPLATE_FILE_SUFFIXES);
    List<String> inputDataSchemaFilenames = StreamSupport.stream(inputDataSchemaFiles.spliterator(), false).map(File::getPath).collect(Collectors.toList());
    if (inputDataSchemaFilenames.isEmpty()) {
        getLogger().lifecycle("There are no Pegasus schema input files. Skip generating Pegasus schema snapshots.");
        return;
    }
    getLogger().info("Generating Pegasus schema snapshot...");
    String resolverPathStr = _resolverPath.plus(getProject().files(_inputDir)).getAsPath();
    FileCollection _pathedClasspath;
    try {
        _pathedClasspath = PathingJarUtil.generatePathingJar(getProject(), getName(), _classPath, false);
    } catch (IOException e) {
        throw new GradleException("Error occurred generating pathing JAR.", e);
    }
    getProject().javaexec(javaExecSpec -> {
        String resolverPathArg = resolverPathStr;
        if (isEnableArgFile()) {
            resolverPathArg = ArgumentFileGenerator.getArgFileSyntax(ArgumentFileGenerator.createArgFile("generatePegasusSchemaSnapshot_resolverPath", Collections.singletonList(resolverPathArg), getTemporaryDir()));
        }
        javaExecSpec.setMain("com.linkedin.restli.tools.snapshot.gen.PegasusSchemaSnapshotGenerationCmdLineApp");
        javaExecSpec.setClasspath(_pathedClasspath);
        javaExecSpec.args(resolverPathArg);
        javaExecSpec.args(_inputDir.getAbsolutePath());
        javaExecSpec.args(_pegasusSchemaSnapshotDestinationDir);
    });
}
Also used : GradleException(org.gradle.api.GradleException) FileTree(org.gradle.api.file.FileTree) IOException(java.io.IOException) FileCollection(org.gradle.api.file.FileCollection) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

FileTree (org.gradle.api.file.FileTree)24 File (java.io.File)8 Test (org.junit.Test)6 GradleException (org.gradle.api.GradleException)5 Expectations (org.jmock.Expectations)5 IOException (java.io.IOException)4 FileCollection (org.gradle.api.file.FileCollection)4 TaskAction (org.gradle.api.tasks.TaskAction)4 PatternSet (org.gradle.api.tasks.util.PatternSet)4 Project (org.gradle.api.Project)2 DirectoryFileTree (org.gradle.api.internal.file.collections.DirectoryFileTree)2 MinimalFileSet (org.gradle.api.internal.file.collections.MinimalFileSet)2 TestClassProcessor (org.gradle.api.internal.tasks.testing.TestClassProcessor)2 TestFramework (org.gradle.api.internal.tasks.testing.TestFramework)2 WorkerTestClassProcessorFactory (org.gradle.api.internal.tasks.testing.WorkerTestClassProcessorFactory)2 MaxNParallelTestClassProcessor (org.gradle.api.internal.tasks.testing.processors.MaxNParallelTestClassProcessor)2 RestartEveryNTestClassProcessor (org.gradle.api.internal.tasks.testing.processors.RestartEveryNTestClassProcessor)2 TestMainAction (org.gradle.api.internal.tasks.testing.processors.TestMainAction)2 ForkingTestClassProcessor (org.gradle.api.internal.tasks.testing.worker.ForkingTestClassProcessor)2 SourceSet (org.gradle.api.tasks.SourceSet)2