PT 173730396 - Initial implementation of generations validation
Includes parsing of spring boot projects from spring.io/api, as well as spring boot project generations from sample code, and relevant junits.
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.validation.generations;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.Generations;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.Link;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.Links;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.SpringProject;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.SpringProjects;
|
||||
|
||||
public class SpringProjectIndex {
|
||||
|
||||
private final SpringProjectsClient client;
|
||||
|
||||
public SpringProjectIndex(SpringProjectsClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public SpringProjects getProjects() throws Exception {
|
||||
return client.getSpringProjects();
|
||||
}
|
||||
|
||||
public Generations getGenerations(SpringProject project) throws Exception {
|
||||
if (project != null) {
|
||||
Links _links = project.get_links();
|
||||
if (_links != null) {
|
||||
Link genLink = _links.getGenerations();
|
||||
if (genLink != null) {
|
||||
return client.getGenerations(genLink.getHref());
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param projectSlug slug used by Spring projects metadata, for example
|
||||
* "spring-boot" for Spring Boot projects
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public SpringProject getProject(String projectSlug) throws Exception {
|
||||
SpringProjects springProjects = getProjects();
|
||||
List<SpringProject> projects = springProjects.getProjects();
|
||||
SpringProject prj = null;
|
||||
for (SpringProject project : projects) {
|
||||
if (project.getSlug().equals(projectSlug)) {
|
||||
prj = project;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return prj;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.validation.generations;
|
||||
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.Generations;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.GenerationsEmbedded;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.JsonHalEmbedded;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.SpringProjects;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.SpringProjectsEmbedded;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
public class SpringProjectsClient {
|
||||
|
||||
private final String url;
|
||||
|
||||
public SpringProjectsClient(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public SpringProjects getSpringProjects() throws Exception {
|
||||
return getEmbedded(url, SpringProjectsEmbedded.class);
|
||||
}
|
||||
|
||||
public Generations getGenerations(String generationsUrl) throws Exception {
|
||||
return getEmbedded(generationsUrl, GenerationsEmbedded.class);
|
||||
}
|
||||
|
||||
private <T> T getEmbedded(String url, Class<? extends JsonHalEmbedded<T>> clazz) throws Exception {
|
||||
if (url != null) {
|
||||
JsonHalEmbedded<T> embedded = get(url, clazz);
|
||||
if (embedded != null) {
|
||||
return embedded.get_embedded();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private <T> T get(String url, Class<T> clazz) throws Exception {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
headers.setAccept(MediaType.parseMediaTypes("application/hal+json"));
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
HttpEntity<?> entity = new HttpEntity(headers);
|
||||
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
ResponseEntity<T> response = restTemplate.exchange(url, HttpMethod.GET, entity, clazz);
|
||||
|
||||
return response.getBody();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.validation.generations.json;
|
||||
|
||||
public class Generation extends JsonHalLinks {
|
||||
|
||||
private String name;
|
||||
private String ossSupportEndDate;
|
||||
private String commercialSupportEndDate;
|
||||
private String initialReleaseDate;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getOssSupportEndDate() {
|
||||
return ossSupportEndDate;
|
||||
}
|
||||
|
||||
public void setOssSupportEndDate(String ossSupportEndDate) {
|
||||
this.ossSupportEndDate = ossSupportEndDate;
|
||||
}
|
||||
|
||||
public String getCommercialSupportEndDate() {
|
||||
return commercialSupportEndDate;
|
||||
}
|
||||
|
||||
public void setCommercialSupportEndDate(String commercialSupportEndDate) {
|
||||
this.commercialSupportEndDate = commercialSupportEndDate;
|
||||
}
|
||||
|
||||
public String getInitialReleaseDate() {
|
||||
return initialReleaseDate;
|
||||
}
|
||||
|
||||
public void setInitialReleaseDate(String initialReleaseDate) {
|
||||
this.initialReleaseDate = initialReleaseDate;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.validation.generations.json;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Generations {
|
||||
|
||||
private List<Generation> generations;
|
||||
|
||||
public List<Generation> getGenerations() {
|
||||
return generations;
|
||||
}
|
||||
|
||||
public void setGenerations(List<Generation> generations) {
|
||||
this.generations = generations;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.validation.generations.json;
|
||||
|
||||
public class GenerationsEmbedded extends JsonHalLinks implements JsonHalEmbedded<Generations> {
|
||||
|
||||
|
||||
private Generations _embedded;
|
||||
|
||||
public Generations get_embedded() {
|
||||
return _embedded;
|
||||
}
|
||||
|
||||
public void set_embedded(Generations _embedded) {
|
||||
this._embedded = _embedded;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.validation.generations.json;
|
||||
|
||||
public interface JsonHalEmbedded<T> {
|
||||
|
||||
T get_embedded();
|
||||
|
||||
void set_embedded(T _embedded);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.validation.generations.json;
|
||||
|
||||
public class JsonHalLinks {
|
||||
|
||||
private Links _links;
|
||||
|
||||
public Links get_links() {
|
||||
return _links;
|
||||
}
|
||||
|
||||
public void set_links(Links _links) {
|
||||
this._links = _links;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.validation.generations.json;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class JsonHalParser {
|
||||
|
||||
public <T> T getEmbedded(String json, Class<? extends JsonHalEmbedded<T>> clazz) throws Exception {
|
||||
if (json != null) {
|
||||
Gson gson = new Gson();
|
||||
JsonHalEmbedded<T> embedded = gson.fromJson(json, clazz);
|
||||
return embedded.get_embedded();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.validation.generations.json;
|
||||
|
||||
public class Link {
|
||||
|
||||
private String href;
|
||||
|
||||
public void setHref(String href) {
|
||||
this.href = href;
|
||||
}
|
||||
|
||||
public String getHref() {
|
||||
return this.href;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.validation.generations.json;
|
||||
|
||||
public class Links {
|
||||
|
||||
private Link self;
|
||||
private Link releases;
|
||||
private Link generations;
|
||||
private Link parent;
|
||||
private Link project;
|
||||
|
||||
public Link getSelf() {
|
||||
return self;
|
||||
}
|
||||
|
||||
public void setSelf(Link self) {
|
||||
this.self = self;
|
||||
}
|
||||
|
||||
public Link getReleases() {
|
||||
return releases;
|
||||
}
|
||||
|
||||
public void setReleases(Link releases) {
|
||||
this.releases = releases;
|
||||
}
|
||||
|
||||
public Link getGenerations() {
|
||||
return generations;
|
||||
}
|
||||
|
||||
public void setGenerations(Link generations) {
|
||||
this.generations = generations;
|
||||
}
|
||||
|
||||
public Link getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(Link parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public Link getProject() {
|
||||
return project;
|
||||
}
|
||||
|
||||
public void setProject(Link project) {
|
||||
this.project = project;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.validation.generations.json;
|
||||
|
||||
public class SpringProject extends JsonHalLinks {
|
||||
|
||||
private String name;
|
||||
private String slug;
|
||||
private String status;
|
||||
private String repositoryUrl;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSlug() {
|
||||
return slug;
|
||||
}
|
||||
|
||||
public void setSlug(String slug) {
|
||||
this.slug = slug;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getRepositoryUrl() {
|
||||
return repositoryUrl;
|
||||
}
|
||||
|
||||
public void setRepositoryUrl(String repositoryUrl) {
|
||||
this.repositoryUrl = repositoryUrl;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.validation.generations.json;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SpringProjects {
|
||||
private List<SpringProject> projects;
|
||||
|
||||
public List<SpringProject> getProjects() {
|
||||
return projects;
|
||||
}
|
||||
|
||||
public void setProjects(List<SpringProject> projects) {
|
||||
this.projects = projects;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.validation.generations.json;
|
||||
|
||||
public class SpringProjectsEmbedded extends JsonHalLinks implements JsonHalEmbedded<SpringProjects> {
|
||||
|
||||
private SpringProjects _embedded;
|
||||
|
||||
public SpringProjects get_embedded() {
|
||||
return _embedded;
|
||||
}
|
||||
|
||||
public void set_embedded(SpringProjects _embedded) {
|
||||
this._embedded = _embedded;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user