Search in sources :

Example 1 with BuildInitDsl

use of org.gradle.buildinit.plugins.internal.modifiers.BuildInitDsl in project gradle by gradle.

the class InitBuild method setupProjectLayout.

@TaskAction
public void setupProjectLayout() {
    final String type = getType();
    BuildInitDsl dsl = BuildInitDsl.fromName(getDsl());
    BuildInitTestFramework testFramework = BuildInitTestFramework.fromName(getTestFramework());
    final ProjectLayoutSetupRegistry projectLayoutRegistry = getProjectLayoutRegistry();
    if (!projectLayoutRegistry.supports(type)) {
        String supportedTypes = Joiner.on(", ").join(Iterables.transform(projectLayoutRegistry.getSupportedTypes(), new Function<String, String>() {

            @Override
            public String apply(String input) {
                return "'" + input + "'";
            }
        }));
        throw new GradleException("The requested build setup type '" + type + "' is not supported. Supported types: " + supportedTypes + ".");
    }
    ProjectInitDescriptor initDescriptor = projectLayoutRegistry.get(type);
    if (!testFramework.equals(BuildInitTestFramework.NONE) && !initDescriptor.supports(testFramework)) {
        throw new GradleException("The requested test framework '" + testFramework.getId() + "' is not supported in '" + type + "' setup type");
    }
    initDescriptor.generate(dsl, testFramework);
}
Also used : BuildInitDsl(org.gradle.buildinit.plugins.internal.modifiers.BuildInitDsl) ProjectLayoutSetupRegistry(org.gradle.buildinit.plugins.internal.ProjectLayoutSetupRegistry) Function(com.google.common.base.Function) GradleException(org.gradle.api.GradleException) ProjectInitDescriptor(org.gradle.buildinit.plugins.internal.ProjectInitDescriptor) BuildInitTestFramework(org.gradle.buildinit.plugins.internal.modifiers.BuildInitTestFramework) TaskAction(org.gradle.api.tasks.TaskAction)

Example 2 with BuildInitDsl

use of org.gradle.buildinit.plugins.internal.modifiers.BuildInitDsl in project gradle by gradle.

the class TaskConfiguration method reasonToSkip.

private static String reasonToSkip(Project project) {
    for (BuildInitDsl dsl : BuildInitDsl.values()) {
        String buildFileName = dsl.fileNameFor("build");
        if (project.file(buildFileName).exists()) {
            return "The build file '" + buildFileName + "' already exists. Skipping build initialization.";
        }
        String settingsFileName = dsl.fileNameFor("settings");
        if (project.file(settingsFileName).exists()) {
            return "The settings file '" + settingsFileName + "' already exists. Skipping build initialization.";
        }
    }
    File buildFile = project.getBuildFile();
    if (buildFile != null && buildFile.exists()) {
        return "The build file \'" + buildFile.getName() + "\' already exists. Skipping build initialization.";
    }
    if (project.getSubprojects().size() > 0) {
        return "This Gradle project appears to be part of an existing multi-project Gradle build. Skipping build initialization.";
    }
    return null;
}
Also used : BuildInitDsl(org.gradle.buildinit.plugins.internal.modifiers.BuildInitDsl) File(java.io.File)

Aggregations

BuildInitDsl (org.gradle.buildinit.plugins.internal.modifiers.BuildInitDsl)2 Function (com.google.common.base.Function)1 File (java.io.File)1 GradleException (org.gradle.api.GradleException)1 TaskAction (org.gradle.api.tasks.TaskAction)1 ProjectInitDescriptor (org.gradle.buildinit.plugins.internal.ProjectInitDescriptor)1 ProjectLayoutSetupRegistry (org.gradle.buildinit.plugins.internal.ProjectLayoutSetupRegistry)1 BuildInitTestFramework (org.gradle.buildinit.plugins.internal.modifiers.BuildInitTestFramework)1