-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce shared utilities for ProjectRequestPostProcessor
- Loading branch information
Showing
9 changed files
with
128 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...main/java/io/spring/initializr/service/extension/AbstractProjectRequestPostProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright 2012-2018 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.spring.initializr.service.extension; | ||
|
||
import io.spring.initializr.generator.ProjectRequest; | ||
import io.spring.initializr.generator.ProjectRequestPostProcessor; | ||
import io.spring.initializr.metadata.Dependency; | ||
import io.spring.initializr.util.Version; | ||
|
||
/** | ||
* Base {@link ProjectRequestPostProcessor} with reusable utilities. | ||
* | ||
* @author Stephane Nicoll | ||
*/ | ||
public class AbstractProjectRequestPostProcessor implements ProjectRequestPostProcessor { | ||
|
||
/** | ||
* Determine if the {@link ProjectRequest request} defines the dependency with the | ||
* specified {@code dependencyId}. | ||
* @param request the request to handle | ||
* @param dependencyId the id of a dependency | ||
* @return {@code true} if the project defines that dependency | ||
*/ | ||
protected boolean hasDependency(ProjectRequest request, String dependencyId) { | ||
return hasDependencies(request, dependencyId); | ||
} | ||
|
||
/** | ||
* Determine if the {@link ProjectRequest request} defines the dependencies with the | ||
* specified {@code dependenciesId}. | ||
* @param request the request to handle | ||
* @param dependenciesId the dependency ids | ||
* @return {@code true} if the project defines all dependencies | ||
*/ | ||
protected boolean hasDependencies(ProjectRequest request, String... dependenciesId) { | ||
for (String id : dependenciesId) { | ||
if (getDependency(request, id) == null) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* Return the {@link Dependency} with the specified {@code id} or {@code null} if the | ||
* project does not define it. | ||
* @param request the request to handle | ||
* @param id the id of a dependency | ||
* @return the {@link Dependency} with that id or {@code null} if the project does not | ||
* define such dependency | ||
*/ | ||
protected Dependency getDependency(ProjectRequest request, String id) { | ||
return request.getResolvedDependencies().stream() | ||
.filter(d -> id.equals(d.getId())).findFirst().orElse(null); | ||
} | ||
|
||
/** | ||
* Specify if the Spring Boot version of the {@link ProjectRequest request} is higher | ||
* or equal to the specified {@link Version}. | ||
* @param request the request to handle | ||
* @param version the minimum version | ||
* @return {@code true} if the requested version is equal or higher than the specified | ||
* {@code version} | ||
*/ | ||
protected boolean isSpringBootVersionAtLeastAfter(ProjectRequest request, | ||
Version version) { | ||
Version requestVersion = Version.safeParse(request.getBootVersion()); | ||
return version.compareTo(requestVersion) <= 0; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters