forked from eclipse-jkube/jkube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MicroprofileHealthUtil.java
63 lines (54 loc) · 2.78 KB
/
MicroprofileHealthUtil.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* Copyright (c) 2019 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at:
*
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.jkube.microprofile;
import org.eclipse.jkube.kit.common.Dependency;
import org.eclipse.jkube.kit.common.JavaProject;
import org.eclipse.jkube.kit.common.util.JKubeProjectUtil;
import static org.eclipse.jkube.kit.common.util.SemanticVersionUtil.isVersionAtLeast;
public class MicroprofileHealthUtil {
private static final String MICROPROFILE_HEALTH_DEPENDENCY = "microprofile-health-api";
private static final String MICROPROFILE_HEALTH_GROUP = "org.eclipse.microprofile.health";
private static final String MICROPROFILE_DEPENDENCY = "microprofile";
private static final String MICROPROFILE_GROUP = "org.eclipse.microprofile";
private static final int MICROPROFILE_HEALTH_SUPPORTED_VERSION_MAJOR = 3;
private static final int MICROPROFILE_HEALTH_SUPPORTED_VERSION_MINOR = 1;
public static final String DEFAULT_READINESS_PATH = "/health/ready";
public static final String DEFAULT_LIVENESS_PATH = "/health/live";
public static final String DEFAULT_STARTUP_PATH = "/health/started";
private MicroprofileHealthUtil() { }
public static boolean hasMicroProfileHealthDependency(JavaProject javaProject) {
return JKubeProjectUtil.hasTransitiveDependency(javaProject, MICROPROFILE_HEALTH_GROUP , MICROPROFILE_HEALTH_DEPENDENCY);
}
public static boolean hasMicroProfileDependency(JavaProject javaProject) {
return JKubeProjectUtil.hasTransitiveDependency(javaProject, MICROPROFILE_GROUP , MICROPROFILE_DEPENDENCY);
}
public static boolean isStartupEndpointSupported(JavaProject javaProject) {
String microProfileHealthVersion;
if (hasMicroProfileDependency(javaProject)) {
microProfileHealthVersion = getMicroProfileVersionFromArtifactId(javaProject, MICROPROFILE_GROUP, MICROPROFILE_DEPENDENCY);
} else if (hasMicroProfileHealthDependency(javaProject)) {
microProfileHealthVersion = getMicroProfileVersionFromArtifactId(javaProject, MICROPROFILE_HEALTH_GROUP, MICROPROFILE_HEALTH_DEPENDENCY);
} else {
return false;
}
return isVersionAtLeast(MICROPROFILE_HEALTH_SUPPORTED_VERSION_MAJOR, MICROPROFILE_HEALTH_SUPPORTED_VERSION_MINOR, microProfileHealthVersion);
}
private static String getMicroProfileVersionFromArtifactId(JavaProject javaProject, String groupId, String artifactId) {
Dependency microProfileDep = JKubeProjectUtil.getTransitiveDependency(javaProject, groupId, artifactId);
if (microProfileDep != null) {
return microProfileDep.getVersion();
}
return null;
}
}