<commit_before>/*
 * Copyright 2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gradle.buildsetup.plugins.internal

import groovy.text.SimpleTemplateEngine
import org.gradle.api.Project
import org.gradle.api.internal.DocumentationRegistry
import org.gradle.api.internal.file.FileResolver
import org.gradle.util.GradleVersion

class JavaLibraryProjectSetupDescriptor extends TemplateBasedProjectSetupDescriptor {

    private final FileResolver fileResolver

    public JavaLibraryProjectSetupDescriptor(FileResolver fileResolver, DocumentationRegistry documentationRegistry) {
        super(fileResolver, documentationRegistry);
        this.fileResolver = fileResolver;
    }

    String getId() {
        return "java-library";
    }

    URL getBuildFileTemplate() {
        return JavaLibraryProjectSetupDescriptor.class.getResource("/org/gradle/buildsetup/tasks/templates/java-library-build.gradle.template");
    }

    URL getSettingsTemplate() {
        return JavaLibraryProjectSetupDescriptor.class.getResource("/org/gradle/buildsetup/tasks/templates/settings.gradle.template")
    }

    void generateProjectSources() {
        if (fileResolver.resolveFilesAsTree("src/main/java").files.empty ||
                fileResolver.resolveFilesAsTree("src/test/java").files.empty) {
            generateClass("src/main/java", "Library.java")
            generateClass("src/test/java", "LibraryTest.java")
        }
    }

    def generateClass(String sourceRoot, String clazzFileName) {
        File sourceRootFolder = fileResolver.resolve(sourceRoot)
        sourceRootFolder.mkdirs()
        File clazzFile = new File(sourceRootFolder, clazzFileName)
        URL productionClazzFileTemplate = JavaLibraryProjectSetupDescriptor.class.getResource("/org/gradle/buildsetup/tasks/templates/${clazzFileName}.template");
        SimpleTemplateEngine templateEngine = new SimpleTemplateEngine()
        def bindings = [genDate: new Date(), genUser: System.getProperty("user.name"), genGradleVersion: GradleVersion.current().toString()]
        clazzFile.text = templateEngine.createTemplate(productionClazzFileTemplate.text).make(bindings).toString();
    }
}<commit_msg>Use FileCollection.isEmpty() rather than getFiles().isEmpty(), as it's more efficient.<commit_after>/*
 * Copyright 2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gradle.buildsetup.plugins.internal

import groovy.text.SimpleTemplateEngine
import org.gradle.api.Project
import org.gradle.api.internal.DocumentationRegistry
import org.gradle.api.internal.file.FileResolver
import org.gradle.util.GradleVersion

class JavaLibraryProjectSetupDescriptor extends TemplateBasedProjectSetupDescriptor {

    private final FileResolver fileResolver

    public JavaLibraryProjectSetupDescriptor(FileResolver fileResolver, DocumentationRegistry documentationRegistry) {
        super(fileResolver, documentationRegistry);
        this.fileResolver = fileResolver;
    }

    String getId() {
        return "java-library";
    }

    URL getBuildFileTemplate() {
        return JavaLibraryProjectSetupDescriptor.class.getResource("/org/gradle/buildsetup/tasks/templates/java-library-build.gradle.template");
    }

    URL getSettingsTemplate() {
        return JavaLibraryProjectSetupDescriptor.class.getResource("/org/gradle/buildsetup/tasks/templates/settings.gradle.template")
    }

    void generateProjectSources() {
        if (fileResolver.resolveFilesAsTree("src/main/java").empty || fileResolver.resolveFilesAsTree("src/test/java").empty) {
            generateClass("src/main/java", "Library.java")
            generateClass("src/test/java", "LibraryTest.java")
        }
    }

    def generateClass(String sourceRoot, String clazzFileName) {
        File sourceRootFolder = fileResolver.resolve(sourceRoot)
        sourceRootFolder.mkdirs()
        File clazzFile = new File(sourceRootFolder, clazzFileName)
        URL productionClazzFileTemplate = JavaLibraryProjectSetupDescriptor.class.getResource("/org/gradle/buildsetup/tasks/templates/${clazzFileName}.template");
        SimpleTemplateEngine templateEngine = new SimpleTemplateEngine()
        def bindings = [genDate: new Date(), genUser: System.getProperty("user.name"), genGradleVersion: GradleVersion.current().toString()]
        clazzFile.text = templateEngine.createTemplate(productionClazzFileTemplate.text).make(bindings).toString();
    }
}
{'fraction_non_alphanumeric': 0.09127200145164217, 'fraction_numerical': 0.002903284340410089, 'mean_word_length': 4.190207156308851, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4050893', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1346, 'n_words': 344}