use of org.gradle.buildinit.plugins.internal.modifiers.ComponentType in project gradle by gradle.
the class InitBuild method setupProjectLayout.
@TaskAction
public void setupProjectLayout() {
UserInputHandler inputHandler = getServices().get(UserInputHandler.class);
ProjectLayoutSetupRegistry projectLayoutRegistry = getProjectLayoutRegistry();
BuildInitializer initDescriptor = null;
if (isNullOrEmpty(type)) {
BuildConverter converter = projectLayoutRegistry.getBuildConverter();
if (converter.canApplyToCurrentDirectory(projectDir)) {
if (inputHandler.askYesNoQuestion("Found a " + converter.getSourceBuildDescription() + " build. Generate a Gradle build from this?", true)) {
initDescriptor = converter;
}
}
if (initDescriptor == null) {
ComponentType componentType = inputHandler.selectOption("Select type of project to generate", projectLayoutRegistry.getComponentTypes(), projectLayoutRegistry.getDefault().getComponentType());
List<Language> languages = projectLayoutRegistry.getLanguagesFor(componentType);
if (languages.size() == 1) {
initDescriptor = projectLayoutRegistry.get(componentType, languages.get(0));
} else {
if (!languages.contains(Language.JAVA)) {
// Not yet implemented
throw new UnsupportedOperationException();
}
Language language = inputHandler.selectOption("Select implementation language", languages, Language.JAVA);
initDescriptor = projectLayoutRegistry.get(componentType, language);
}
}
} else {
initDescriptor = projectLayoutRegistry.get(type);
}
ModularizationOption modularizationOption;
if (splitProject.isPresent()) {
modularizationOption = splitProject.get() ? ModularizationOption.WITH_LIBRARY_PROJECTS : ModularizationOption.SINGLE_PROJECT;
} else if (initDescriptor.getModularizationOptions().size() == 1) {
modularizationOption = initDescriptor.getModularizationOptions().iterator().next();
} else if (!isNullOrEmpty(type)) {
modularizationOption = ModularizationOption.SINGLE_PROJECT;
} else {
modularizationOption = inputHandler.selectOption("Split functionality across multiple subprojects?", initDescriptor.getModularizationOptions(), ModularizationOption.SINGLE_PROJECT);
}
BuildInitDsl dsl;
if (isNullOrEmpty(this.dsl)) {
dsl = initDescriptor.getDefaultDsl();
if (initDescriptor.getDsls().size() > 1) {
dsl = inputHandler.selectOption("Select build script DSL", initDescriptor.getDsls(), dsl);
}
} else {
dsl = BuildInitDsl.fromName(getDsl());
if (!initDescriptor.getDsls().contains(dsl)) {
throw new GradleException("The requested DSL '" + getDsl() + "' is not supported for '" + initDescriptor.getId() + "' build type");
}
}
boolean useIncubatingAPIs;
if (this.useIncubatingAPIs.isPresent()) {
useIncubatingAPIs = this.useIncubatingAPIs.get();
} else {
useIncubatingAPIs = inputHandler.askYesNoQuestion("Generate build using new APIs and behavior (some features may change in the next minor release)?", false);
}
BuildInitTestFramework testFramework = null;
if (modularizationOption == ModularizationOption.WITH_LIBRARY_PROJECTS) {
// currently we only support JUnit5 tests for this combination
testFramework = BuildInitTestFramework.JUNIT_JUPITER;
} else if (isNullOrEmpty(this.testFramework)) {
testFramework = initDescriptor.getDefaultTestFramework();
if (initDescriptor.getTestFrameworks().size() > 1) {
testFramework = inputHandler.selectOption("Select test framework", initDescriptor.getTestFrameworks(), testFramework);
}
} else {
for (BuildInitTestFramework candidate : initDescriptor.getTestFrameworks()) {
if (this.testFramework.equals(candidate.getId())) {
testFramework = candidate;
break;
}
}
if (testFramework == null) {
TreeFormatter formatter = new TreeFormatter();
formatter.node("The requested test framework '" + getTestFramework() + "' is not supported for '" + initDescriptor.getId() + "' build type. Supported frameworks");
formatter.startChildren();
for (BuildInitTestFramework framework : initDescriptor.getTestFrameworks()) {
formatter.node("'" + framework.getId() + "'");
}
formatter.endChildren();
throw new GradleException(formatter.toString());
}
}
String projectName = this.projectName;
if (initDescriptor.supportsProjectName()) {
if (isNullOrEmpty(projectName)) {
projectName = inputHandler.askQuestion("Project name", getProjectName());
}
} else if (!isNullOrEmpty(projectName)) {
throw new GradleException("Project name is not supported for '" + initDescriptor.getId() + "' build type.");
}
String packageName = this.packageName;
if (initDescriptor.supportsPackage()) {
if (isNullOrEmpty(packageName)) {
packageName = inputHandler.askQuestion("Source package", toPackageName(projectName));
}
} else if (!isNullOrEmpty(packageName)) {
throw new GradleException("Package name is not supported for '" + initDescriptor.getId() + "' build type.");
}
if (!isNullOrEmpty(packageName)) {
if (!SourceVersion.isName(packageName)) {
throw new GradleException("Package name: '" + packageName + "' is not valid - it may contain invalid characters or reserved words.");
}
}
List<String> subprojectNames = initDescriptor.getComponentType().getDefaultProjectNames();
InitSettings settings = new InitSettings(projectName, useIncubatingAPIs, subprojectNames, modularizationOption, dsl, packageName, testFramework, insecureProtocol.get(), projectDir);
initDescriptor.generate(settings);
initDescriptor.getFurtherReading(settings).ifPresent(link -> getLogger().lifecycle("Get more help with your project: {}", link));
}
Aggregations