Example usage for org.springframework.boot.cli.command.init InitializrServiceMetadata getDefaultType

List of usage examples for org.springframework.boot.cli.command.init InitializrServiceMetadata getDefaultType

Introduction

In this page you can find the example usage for org.springframework.boot.cli.command.init InitializrServiceMetadata getDefaultType.

Prototype

ProjectType getDefaultType() 

Source Link

Document

Return the default type to use or null if the metadata does not define any default.

Usage

From source file:org.springframework.boot.cli.command.init.ProjectGenerationRequest.java

protected ProjectType determineProjectType(InitializrServiceMetadata metadata) {
    if (this.type != null) {
        ProjectType result = metadata.getProjectTypes().get(this.type);
        if (result == null) {
            throw new ReportableException(
                    ("No project type with id '" + this.type + "' - check the service capabilities (--list)"));
        }//  w w w. ja v  a 2 s  .  c o  m
        return result;
    } else if (isDetectType()) {
        Map<String, ProjectType> types = new HashMap<>(metadata.getProjectTypes());
        if (this.build != null) {
            filter(types, "build", this.build);
        }
        if (this.format != null) {
            filter(types, "format", this.format);
        }
        if (types.size() == 1) {
            return types.values().iterator().next();
        } else if (types.isEmpty()) {
            throw new ReportableException("No type found with build '" + this.build + "' and format '"
                    + this.format + "' check the service capabilities (--list)");
        } else {
            throw new ReportableException("Multiple types found with build '" + this.build + "' and format '"
                    + this.format + "' use --type with a more specific value " + types.keySet());
        }
    } else {
        ProjectType defaultType = metadata.getDefaultType();
        if (defaultType == null) {
            throw new ReportableException(("No project type is set and no default is defined. "
                    + "Check the service capabilities (--list)"));
        }
        return defaultType;
    }
}