List of usage examples for org.springframework.boot.cli.command.init ReportableException ReportableException
public ReportableException(String message)
From source file:org.springframework.boot.cli.command.init.InitializrService.java
private void validateResponse(CloseableHttpResponse httpResponse, String serviceUrl) { if (httpResponse.getEntity() == null) { throw new ReportableException("No content received from server '" + serviceUrl + "'"); }//from www . j a v a 2 s .c o m if (httpResponse.getStatusLine().getStatusCode() != 200) { throw createException(serviceUrl, httpResponse); } }
From source file:org.springframework.boot.cli.command.init.InitializrService.java
private CloseableHttpResponse execute(HttpUriRequest request, Object url, String description) { try {/*w w w . j a v a2s. c om*/ request.addHeader("User-Agent", "SpringBootCli/" + getClass().getPackage().getImplementationVersion()); return getHttp().execute(request); } catch (IOException ex) { throw new ReportableException( "Failed to " + description + " from service at '" + url + "' (" + ex.getMessage() + ")"); } }
From source file:org.springframework.boot.cli.command.init.InitializrService.java
private ReportableException createException(String url, CloseableHttpResponse httpResponse) { String message = "Initializr service call failed using '" + url + "' - service returned " + httpResponse.getStatusLine().getReasonPhrase(); String error = extractMessage(httpResponse.getEntity()); if (StringUtils.hasText(error)) { message += ": '" + error + "'"; } else {// w ww . j a va2s.co m int statusCode = httpResponse.getStatusLine().getStatusCode(); message += " (unexpected " + statusCode + " error)"; } throw new ReportableException(message); }
From source file:org.springframework.boot.cli.command.init.ProjectGenerationRequest.java
/** * Generates the URI to use to generate a project represented by this request. * @param metadata the metadata that describes the service * @return the project generation URI/* w w w. j av a 2 s .co m*/ */ URI generateUrl(InitializrServiceMetadata metadata) { try { URIBuilder builder = new URIBuilder(this.serviceUrl); StringBuilder sb = new StringBuilder(); if (builder.getPath() != null) { sb.append(builder.getPath()); } ProjectType projectType = determineProjectType(metadata); this.type = projectType.getId(); sb.append(projectType.getAction()); builder.setPath(sb.toString()); if (!this.dependencies.isEmpty()) { builder.setParameter("dependencies", StringUtils.collectionToCommaDelimitedString(this.dependencies)); } if (this.groupId != null) { builder.setParameter("groupId", this.groupId); } String resolvedArtifactId = resolveArtifactId(); if (resolvedArtifactId != null) { builder.setParameter("artifactId", resolvedArtifactId); } if (this.version != null) { builder.setParameter("version", this.version); } if (this.name != null) { builder.setParameter("name", this.name); } if (this.description != null) { builder.setParameter("description", this.description); } if (this.packageName != null) { builder.setParameter("packageName", this.packageName); } if (this.type != null) { builder.setParameter("type", projectType.getId()); } if (this.packaging != null) { builder.setParameter("packaging", this.packaging); } if (this.javaVersion != null) { builder.setParameter("javaVersion", this.javaVersion); } if (this.language != null) { builder.setParameter("language", this.language); } if (this.bootVersion != null) { builder.setParameter("bootVersion", this.bootVersion); } return builder.build(); } catch (URISyntaxException e) { throw new ReportableException("Invalid service URL (" + e.getMessage() + ")"); } }
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)")); }//from www .j av 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; } }