Compare commits
1 commit
main
...
wip/sbt-te
| Author | SHA1 | Date | |
|---|---|---|---|
| c672c19517 |
88 changed files with 1052 additions and 121 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -4,6 +4,10 @@
|
|||
# Ignore Gradle build output directory
|
||||
build
|
||||
|
||||
# Ignore SBT output directories
|
||||
**/target
|
||||
**/.bsp
|
||||
|
||||
# Eclipse
|
||||
bin
|
||||
.classpath
|
||||
|
|
|
|||
78
.gitlab-ci.yml
Normal file
78
.gitlab-ci.yml
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
stages:
|
||||
- build
|
||||
- test
|
||||
- publish
|
||||
- deploy
|
||||
|
||||
.any-job:
|
||||
rules:
|
||||
- if: $CI_SERVER_HOST == "gitlab.mnl.de"
|
||||
|
||||
.gradle-job:
|
||||
extends: .any-job
|
||||
image: registry.mnl.de/org/jgrapes/jdk21-builder:v2
|
||||
cache:
|
||||
- key: dependencies-${CI_COMMIT_BRANCH}
|
||||
policy: pull-push
|
||||
paths:
|
||||
- .gradle
|
||||
- node_modules
|
||||
- key: "$CI_COMMIT_SHA"
|
||||
policy: pull-push
|
||||
paths:
|
||||
- build
|
||||
- "*/build"
|
||||
before_script:
|
||||
- echo -n $CI_REGISTRY_PASSWORD | podman login -u "$CI_REGISTRY_USER" --password-stdin $CI_REGISTRY
|
||||
- git switch $(git branch -r --sort="authordate" --contains $CI_COMMIT_SHA | head -1 | sed -e 's#[^/]*/##')
|
||||
- git pull
|
||||
- git reset --hard $CI_COMMIT_SHA
|
||||
|
||||
build-jars:
|
||||
stage: build
|
||||
extends: .gradle-job
|
||||
script:
|
||||
- ./gradlew -Pdocker.registry=$CI_REGISTRY_IMAGE build apidocs
|
||||
|
||||
publish-images:
|
||||
stage: publish
|
||||
extends: .gradle-job
|
||||
dependencies:
|
||||
- build-jars
|
||||
script:
|
||||
- ./gradlew -Pdocker.registry=$CI_REGISTRY_IMAGE publishImage
|
||||
|
||||
.pages-job:
|
||||
extends: .any-job
|
||||
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/ruby:3.2
|
||||
variables:
|
||||
JEKYLL_ENV: production
|
||||
LC_ALL: C.UTF-8
|
||||
before_script:
|
||||
- git fetch origin gh-pages
|
||||
- git checkout gh-pages
|
||||
- gem install bundler
|
||||
- bundle install
|
||||
|
||||
test-pages:
|
||||
stage: test
|
||||
extends: .pages-job
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == "gh-pages"
|
||||
script:
|
||||
- bundle exec jekyll build -d test
|
||||
artifacts:
|
||||
paths:
|
||||
- test
|
||||
|
||||
#publish-pages:
|
||||
# stage: publish
|
||||
# extends: .pages-job
|
||||
# rules:
|
||||
# - if: $CI_COMMIT_BRANCH == "gh-pages"
|
||||
# script:
|
||||
# - bundle exec jekyll build -d public
|
||||
# artifacts:
|
||||
# paths:
|
||||
# - public
|
||||
# environment: production
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
when:
|
||||
- event: push
|
||||
evaluate: 'CI_SYSTEM_HOST == "woodpecker.mnl.de"'
|
||||
|
||||
clone:
|
||||
- name: git
|
||||
image: woodpeckerci/plugin-git
|
||||
settings:
|
||||
partial: false
|
||||
tags: true
|
||||
depth: 0
|
||||
|
||||
steps:
|
||||
- name: prepare
|
||||
image: alpine
|
||||
commands:
|
||||
# Because we run the next step as user 1000 to make podman work:
|
||||
- mkdir /woodpecker/workflow
|
||||
- chown 1000:1000 /woodpecker/workflow
|
||||
- chown -R 1000:1000 $CI_WORKSPACE
|
||||
|
||||
- name: build-jars
|
||||
image: registry.mnl.de/mnl/jdk21-builder:v4
|
||||
environment:
|
||||
HOME: /woodpecker/workflow
|
||||
REGISTRY: registry.mnl.de
|
||||
REGISTRY_USER: mnl
|
||||
REGISTRY_TOKEN:
|
||||
from_secret: REGISTRY_TOKEN
|
||||
commands:
|
||||
- echo $REGISTRY_TOKEN | podman login -u $REGISTRY_USER --password-stdin $REGISTRY
|
||||
- ./gradlew -Pdocker.registry=$REGISTRY/$REGISTRY_USER build apidocs publishImage
|
||||
backend_options:
|
||||
kubernetes:
|
||||
securityContext:
|
||||
privileged: true
|
||||
runAsUser: 1000
|
||||
runAsGroup: 1000
|
||||
25
build.sbt
Normal file
25
build.sbt
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
lazy val commonSettings = Seq(
|
||||
// Sensible layout
|
||||
Compile / javaSource := baseDirectory.value / "src",
|
||||
Compile / resourceDirectory := baseDirectory.value / "resources",
|
||||
Test / javaSource := baseDirectory.value / "test",
|
||||
Test / resourceDirectory := baseDirectory.value / "test-resources",
|
||||
|
||||
// Do not append Scala versions to the generated artifacts
|
||||
crossPaths := false,
|
||||
// This forbids including Scala related libraries into the dependency
|
||||
autoScalaLibrary := false,
|
||||
|
||||
Compile / packageDoc / publishArtifact := false
|
||||
)
|
||||
|
||||
lazy val util = (project in file("org.jdrupes.vmoperator.util"))
|
||||
.settings(commonSettings: _*)
|
||||
|
||||
lazy val common = (project in file("org.jdrupes.vmoperator.common"))
|
||||
.settings(commonSettings: _*)
|
||||
.dependsOn(util)
|
||||
|
||||
lazy val runnerQemu = (project in file("org.jdrupes.vmoperator.runner.qemu"))
|
||||
.settings(commonSettings: _*)
|
||||
.dependsOn(common)
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
sed -i '/AutomaticLogin/d' /etc/gdm/custom.conf
|
||||
|
|
@ -72,8 +72,8 @@ doLogin() {
|
|||
return
|
||||
fi
|
||||
|
||||
# Check if this user is already logged in on tty2
|
||||
curUser=$(loginctl -j | jq -r '.[] | select(.tty=="tty2") | .user')
|
||||
# Check if this user is already logged in on tty1
|
||||
curUser=$(loginctl -j | jq -r '.[] | select(.tty=="tty1") | .user')
|
||||
if [ "$curUser" = "$user" ]; then
|
||||
echo >&${con} "201 User already logged in"
|
||||
return
|
||||
|
|
@ -96,14 +96,17 @@ doLogin() {
|
|||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
# Configure user as auto login user
|
||||
sed -i '/AutomaticLogin/d' /etc/gdm/custom.conf
|
||||
sed -i '/\[daemon\]/a AutomaticLoginEnable=true\nAutomaticLogin='$user \
|
||||
/etc/gdm/custom.conf
|
||||
|
||||
# Activate user
|
||||
systemctl restart gdm
|
||||
|
||||
# Start the desktop for the user
|
||||
systemd-run 2>$temperr \
|
||||
--unit vmop-user-desktop --uid=$uid --gid=$uid \
|
||||
--working-directory="/home/$user" -p TTYPath=/dev/tty1 \
|
||||
-p PAMName=login -p StandardInput=tty -p StandardOutput=journal \
|
||||
-p Conflicts="gdm.service getty@tty1.service" \
|
||||
-E XDG_RUNTIME_DIR="/run/user/$uid" \
|
||||
-E XDG_CURRENT_DESKTOP=GNOME \
|
||||
-p ExecStartPre="/usr/bin/chvt 1" \
|
||||
dbus-run-session -- gnome-shell --display-server --wayland
|
||||
if [ $? -eq 0 ]; then
|
||||
echo >&${con} "201 User logged in successfully"
|
||||
else
|
||||
|
|
@ -114,8 +117,14 @@ doLogin() {
|
|||
# Attempt to log out a user currently using tty1. This is an intermediate
|
||||
# operation that can be invoked from other operations
|
||||
attemptLogout() {
|
||||
sed -i '/AutomaticLogin/d' /etc/gdm/custom.conf
|
||||
systemctl stop gdm
|
||||
systemctl status vmop-user-desktop > /dev/null 2>&1
|
||||
if [ $? = 0 ]; then
|
||||
systemctl stop vmop-user-desktop
|
||||
fi
|
||||
loginctl -j | jq -r '.[] | select(.tty=="tty1") | .session' \
|
||||
| while read sid; do
|
||||
loginctl kill-session $sid
|
||||
done
|
||||
echo >&${con} "102 Desktop stopped"
|
||||
}
|
||||
|
||||
|
|
@ -124,7 +133,15 @@ attemptLogout() {
|
|||
# Also try to restart gdm, if it is not running.
|
||||
doLogout() {
|
||||
attemptLogout
|
||||
systemctl restart gdm
|
||||
systemctl status gdm >/dev/null 2>&1
|
||||
if [ $? != 0 ]; then
|
||||
systemctl restart gdm 2>$temperr
|
||||
if [ $? -eq 0 ]; then
|
||||
echo >&${con} "102 gdm restarted"
|
||||
else
|
||||
echo >&${con} "102 Restarting gdm failed: $(tr '\n' ' ' <${temperr})"
|
||||
fi
|
||||
fi
|
||||
echo >&${con} "202 User logged out"
|
||||
}
|
||||
|
||||
|
|
@ -136,7 +153,7 @@ while read line <&${con}; do
|
|||
done
|
||||
|
||||
onExit() {
|
||||
doLogout
|
||||
attemptLogout
|
||||
if [ -n "$temperr" ]; then
|
||||
rm -f $temperr
|
||||
fi
|
||||
|
|
|
|||
7
org.jdrupes.vmoperator.common/build.sbt
Normal file
7
org.jdrupes.vmoperator.common/build.sbt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
libraryDependencies ++= Seq(
|
||||
"org.jgrapes" % "org.jgrapes.core" % "[1.22.1,2)",
|
||||
"io.kubernetes" % "client-java" % "[19.0.0,20.0.0)",
|
||||
"org.yaml" % "snakeyaml" % "[2.4,2.5)",
|
||||
"com.fasterxml.jackson.datatype" % "jackson-datatype-jsr310" % "[2.16.1,3]"
|
||||
)
|
||||
|
|
@ -32,11 +32,13 @@ import java.util.regex.Pattern;
|
|||
public class Convertions {
|
||||
|
||||
@SuppressWarnings({ "PMD.UseConcurrentHashMap",
|
||||
"PMD.FieldNamingConventions" })
|
||||
"PMD.FieldNamingConventions", "PMD.VariableNamingConventions" })
|
||||
private static final Map<String, BigInteger> unitMap = new HashMap<>();
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions" })
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions",
|
||||
"PMD.VariableNamingConventions" })
|
||||
private static final List<Map.Entry<String, BigInteger>> unitMappings;
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions" })
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions",
|
||||
"PMD.VariableNamingConventions" })
|
||||
private static final Pattern memorySize
|
||||
= Pattern.compile("^\\s*(\\d+(\\.\\d+)?)\\s*([A-Za-z]*)\\s*");
|
||||
|
||||
|
|
@ -67,6 +69,7 @@ public class Convertions {
|
|||
* @param amount the amount
|
||||
* @return the big integer
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
public static BigInteger parseMemory(Object amount) {
|
||||
if (amount == null) {
|
||||
return (BigInteger) amount;
|
||||
|
|
|
|||
|
|
@ -47,7 +47,8 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
|
|||
/**
|
||||
* Helpers for K8s API.
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.ShortClassName", "PMD.UseUtilityClass" })
|
||||
@SuppressWarnings({ "PMD.ShortClassName", "PMD.UseUtilityClass",
|
||||
"PMD.DataflowAnomalyAnalysis" })
|
||||
public class K8s {
|
||||
|
||||
/**
|
||||
|
|
@ -112,6 +113,7 @@ public class K8s {
|
|||
public static JsonObject yamlToJson(ApiClient client, Reader yaml) {
|
||||
// Avoid Yaml.load due to
|
||||
// https://github.com/kubernetes-client/java/issues/2741
|
||||
@SuppressWarnings("PMD.UseConcurrentHashMap")
|
||||
Map<String, Object> yamlData
|
||||
= new Yaml(new SafeConstructor(new LoaderOptions())).load(yaml);
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@ import okhttp3.Response;
|
|||
* A client with some additional properties.
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.ExcessivePublicCount", "PMD.TooManyMethods",
|
||||
"checkstyle:LineLength", "PMD.CouplingBetweenObjects", "PMD.GodClass" })
|
||||
"PMD.LinguisticNaming", "checkstyle:LineLength",
|
||||
"PMD.CouplingBetweenObjects", "PMD.GodClass" })
|
||||
public class K8sClient extends ApiClient {
|
||||
|
||||
private ApiClient apiClient;
|
||||
|
|
@ -230,6 +231,7 @@ public class K8sClient extends ApiClient {
|
|||
* @return the api client
|
||||
* @see ApiClient#setKeyManagers(javax.net.ssl.KeyManager[])
|
||||
*/
|
||||
@SuppressWarnings("PMD.UseVarargs")
|
||||
@Override
|
||||
public ApiClient setKeyManagers(KeyManager[] managers) {
|
||||
return apiClient().setKeyManagers(managers);
|
||||
|
|
@ -636,6 +638,7 @@ public class K8sClient extends ApiClient {
|
|||
* @return the string
|
||||
* @see ApiClient#selectHeaderAccept(java.lang.String[])
|
||||
*/
|
||||
@SuppressWarnings("PMD.UseVarargs")
|
||||
@Override
|
||||
public String selectHeaderAccept(String[] accepts) {
|
||||
return apiClient().selectHeaderAccept(accepts);
|
||||
|
|
@ -648,6 +651,7 @@ public class K8sClient extends ApiClient {
|
|||
* @return the string
|
||||
* @see ApiClient#selectHeaderContentType(java.lang.String[])
|
||||
*/
|
||||
@SuppressWarnings("PMD.UseVarargs")
|
||||
@Override
|
||||
public String selectHeaderContentType(String[] contentTypes) {
|
||||
return apiClient().selectHeaderContentType(contentTypes);
|
||||
|
|
@ -814,7 +818,7 @@ public class K8sClient extends ApiClient {
|
|||
* @throws ApiException the api exception
|
||||
* @see ApiClient#buildCall(java.lang.String, java.lang.String, java.util.List, java.util.List, java.lang.Object, java.util.Map, java.util.Map, java.util.Map, java.lang.String[], io.kubernetes.client.openapi.ApiCallback)
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
@SuppressWarnings({ "rawtypes", "PMD.ExcessiveParameterList" })
|
||||
@Override
|
||||
public Call buildCall(String path, String method, List<Pair> queryParams,
|
||||
List<Pair> collectionQueryParams, Object body,
|
||||
|
|
@ -843,7 +847,7 @@ public class K8sClient extends ApiClient {
|
|||
* @throws ApiException the api exception
|
||||
* @see ApiClient#buildRequest(java.lang.String, java.lang.String, java.util.List, java.util.List, java.lang.Object, java.util.Map, java.util.Map, java.util.Map, java.lang.String[], io.kubernetes.client.openapi.ApiCallback)
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
@SuppressWarnings({ "rawtypes", "PMD.ExcessiveParameterList" })
|
||||
@Override
|
||||
public Request buildRequest(String path, String method,
|
||||
List<Pair> queryParams, List<Pair> collectionQueryParams,
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@ import java.util.function.Function;
|
|||
* @param <O> the generic type
|
||||
* @param <L> the generic type
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.CouplingBetweenObjects" })
|
||||
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis",
|
||||
"PMD.CouplingBetweenObjects" })
|
||||
public class K8sClusterGenericStub<O extends KubernetesObject,
|
||||
L extends KubernetesListObject> {
|
||||
protected final K8sClient client;
|
||||
|
|
@ -254,6 +255,7 @@ public class K8sClusterGenericStub<O extends KubernetesObject,
|
|||
* @param name the name
|
||||
* @return the result
|
||||
*/
|
||||
@SuppressWarnings("PMD.UseObjectForClearerAPI")
|
||||
R get(Class<O> objectClass, Class<L> objectListClass, K8sClient client,
|
||||
APIResource context, String name);
|
||||
}
|
||||
|
|
@ -282,6 +284,7 @@ public class K8sClusterGenericStub<O extends KubernetesObject,
|
|||
* @return the stub if the object exists
|
||||
* @throws ApiException the api exception
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.AvoidBranchingStatementAsLastInLoop" })
|
||||
public static <O extends KubernetesObject, L extends KubernetesListObject,
|
||||
R extends K8sClusterGenericStub<O, L>>
|
||||
R get(Class<O> objectClass, Class<L> objectListClass,
|
||||
|
|
@ -312,6 +315,8 @@ public class K8sClusterGenericStub<O extends KubernetesObject,
|
|||
* @return the stub if the object exists
|
||||
* @throws ApiException the api exception
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.AvoidBranchingStatementAsLastInLoop",
|
||||
"PMD.UseObjectForClearerAPI" })
|
||||
public static <O extends KubernetesObject, L extends KubernetesListObject,
|
||||
R extends K8sClusterGenericStub<O, L>>
|
||||
R get(Class<O> objectClass, Class<L> objectListClass,
|
||||
|
|
@ -336,6 +341,8 @@ public class K8sClusterGenericStub<O extends KubernetesObject,
|
|||
* @return the stub if the object exists
|
||||
* @throws ApiException the api exception
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.AvoidBranchingStatementAsLastInLoop",
|
||||
"PMD.AvoidInstantiatingObjectsInLoops", "PMD.UseObjectForClearerAPI" })
|
||||
public static <O extends KubernetesObject, L extends KubernetesListObject,
|
||||
R extends K8sClusterGenericStub<O, L>>
|
||||
R create(Class<O> objectClass, Class<L> objectListClass,
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import io.kubernetes.client.openapi.models.V1ObjectMeta;
|
|||
* notably the metadata, is made available through the methods
|
||||
* defined by {@link KubernetesObject}.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataClass")
|
||||
public class K8sDynamicModel implements KubernetesObject {
|
||||
|
||||
private final V1ObjectMeta metadata;
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public class K8sDynamicModelsBase<T extends K8sDynamicModel>
|
|||
} catch (InstantiationException | IllegalAccessException
|
||||
| IllegalArgumentException | InvocationTargetException
|
||||
| NoSuchMethodException | SecurityException exc) {
|
||||
throw new IllegalArgumentException(exc);
|
||||
throw new IllegalArgumentException(exc); // NOPMD
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import java.util.Collection;
|
|||
* state and can therefore be used for any kind of object, especially
|
||||
* custom objects.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
public class K8sDynamicStub
|
||||
extends K8sDynamicStubBase<K8sDynamicModel, K8sDynamicModels> {
|
||||
|
||||
|
|
@ -63,6 +64,8 @@ public class K8sDynamicStub
|
|||
* @return the stub if the object exists
|
||||
* @throws ApiException the api exception
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.AvoidBranchingStatementAsLastInLoop",
|
||||
"PMD.AvoidInstantiatingObjectsInLoops", "PMD.UseObjectForClearerAPI" })
|
||||
public static K8sDynamicStub get(K8sClient client,
|
||||
GroupVersionKind gvk, String namespace, String name)
|
||||
throws ApiException {
|
||||
|
|
@ -80,6 +83,8 @@ public class K8sDynamicStub
|
|||
* @return the stub if the object exists
|
||||
* @throws ApiException the api exception
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.AvoidBranchingStatementAsLastInLoop",
|
||||
"PMD.AvoidInstantiatingObjectsInLoops", "PMD.UseObjectForClearerAPI" })
|
||||
public static K8sDynamicStub get(K8sClient client,
|
||||
APIResource context, String namespace, String name) {
|
||||
return new K8sDynamicStub(client, context, namespace, name);
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import io.kubernetes.client.Discovery.APIResource;
|
|||
* state and can therefore be used for any kind of object, especially
|
||||
* custom objects.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
public abstract class K8sDynamicStubBase<O extends K8sDynamicModel,
|
||||
L extends K8sDynamicModelsBase<O>> extends K8sGenericStub<O, L> {
|
||||
|
||||
|
|
@ -39,6 +40,7 @@ public abstract class K8sDynamicStubBase<O extends K8sDynamicModel,
|
|||
* @param namespace the namespace
|
||||
* @param name the name
|
||||
*/
|
||||
@SuppressWarnings("PMD.ConstructorCallsOverridableMethod")
|
||||
public K8sDynamicStubBase(Class<O> objectClass,
|
||||
Class<L> objectListClass, DynamicTypeAdapterFactory<O, L> taf,
|
||||
K8sClient client, APIResource context, String namespace,
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ import java.util.function.Function;
|
|||
* @param <O> the generic type
|
||||
* @param <L> the generic type
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.TooManyMethods" })
|
||||
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis", "PMD.TooManyMethods" })
|
||||
public class K8sGenericStub<O extends KubernetesObject,
|
||||
L extends KubernetesListObject> {
|
||||
protected final K8sClient client;
|
||||
|
|
@ -200,6 +200,7 @@ public class K8sGenericStub<O extends KubernetesObject,
|
|||
* @return the updated model or empty if the object was not found
|
||||
* @throws ApiException the api exception
|
||||
*/
|
||||
@SuppressWarnings("PMD.AssignmentInOperand")
|
||||
public Optional<O> updateStatus(O object, Function<O, Object> updater)
|
||||
throws ApiException {
|
||||
return K8s.optional(api.updateStatus(object, updater));
|
||||
|
|
@ -217,7 +218,7 @@ public class K8sGenericStub<O extends KubernetesObject,
|
|||
* @return the updated model or empty if the object was not found
|
||||
* @throws ApiException the api exception
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.AssignmentInOperand" })
|
||||
@SuppressWarnings({ "PMD.AssignmentInOperand", "PMD.UnusedAssignment" })
|
||||
public Optional<O> updateStatus(Function<O, Object> updater, O current,
|
||||
int retries) throws ApiException {
|
||||
while (true) {
|
||||
|
|
@ -247,6 +248,7 @@ public class K8sGenericStub<O extends KubernetesObject,
|
|||
* @return the updated model or empty if the object was not found
|
||||
* @throws ApiException the api exception
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.AssignmentInOperand", "PMD.UnusedAssignment" })
|
||||
public Optional<O> updateStatus(Function<O, Object> updater, int retries)
|
||||
throws ApiException {
|
||||
return updateStatus(updater, null, retries);
|
||||
|
|
@ -369,6 +371,7 @@ public class K8sGenericStub<O extends KubernetesObject,
|
|||
* @param name the name
|
||||
* @return the result
|
||||
*/
|
||||
@SuppressWarnings("PMD.UseObjectForClearerAPI")
|
||||
R get(K8sClient client, String namespace, String name);
|
||||
}
|
||||
|
||||
|
|
@ -394,6 +397,8 @@ public class K8sGenericStub<O extends KubernetesObject,
|
|||
* @return the stub if the object exists
|
||||
* @throws ApiException the api exception
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.AvoidBranchingStatementAsLastInLoop",
|
||||
"PMD.AvoidInstantiatingObjectsInLoops", "PMD.UseObjectForClearerAPI" })
|
||||
public static <O extends KubernetesObject, L extends KubernetesListObject,
|
||||
R extends K8sGenericStub<O, L>>
|
||||
R create(Class<O> objectClass, Class<L> objectListClass,
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ public class K8sObserver<O extends KubernetesObject,
|
|||
ADDED, MODIFIED, DELETED
|
||||
}
|
||||
|
||||
@SuppressWarnings("PMD.FieldNamingConventions")
|
||||
protected final Logger logger = Logger.getLogger(getClass().getName());
|
||||
|
||||
protected final K8sClient client;
|
||||
|
|
@ -72,7 +73,8 @@ public class K8sObserver<O extends KubernetesObject,
|
|||
* @param namespace the namespace
|
||||
* @param options the options
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.AvoidCatchingThrowable",
|
||||
@SuppressWarnings({ "PMD.AvoidBranchingStatementAsLastInLoop",
|
||||
"PMD.UseObjectForClearerAPI", "PMD.AvoidCatchingThrowable",
|
||||
"PMD.CognitiveComplexity", "PMD.AvoidCatchingGenericException" })
|
||||
public K8sObserver(Class<O> objectClass, Class<L> objectListClass,
|
||||
K8sClient client, APIResource context, String namespace,
|
||||
|
|
@ -98,6 +100,7 @@ public class K8sObserver<O extends KubernetesObject,
|
|||
while (!Thread.currentThread().isInterrupted()) {
|
||||
Instant startedAt = Instant.now();
|
||||
try {
|
||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
||||
var changed
|
||||
= api.watch(namespace, options).iterator();
|
||||
while (changed.hasNext()) {
|
||||
|
|
@ -230,6 +233,7 @@ public class K8sObserver<O extends KubernetesObject,
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("PMD.UseLocaleWithCaseConversions")
|
||||
public String toString() {
|
||||
return "Observer for " + K8s.toString(context) + " " + namespace;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import java.util.List;
|
|||
/**
|
||||
* A stub for config maps (v1).
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
public class K8sV1ConfigMapStub
|
||||
extends K8sGenericStub<V1ConfigMap, V1ConfigMapList> {
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import java.util.Optional;
|
|||
/**
|
||||
* A stub for pods (v1).
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
public class K8sV1DeploymentStub
|
||||
extends K8sGenericStub<V1Deployment, V1DeploymentList> {
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import java.util.List;
|
|||
/**
|
||||
* A stub for nodes (v1).
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
public class K8sV1NodeStub extends K8sClusterGenericStub<V1Node, V1NodeList> {
|
||||
|
||||
public static final APIResource CONTEXT = new APIResource("", List.of("v1"),
|
||||
|
|
@ -73,7 +74,8 @@ public class K8sV1NodeStub extends K8sClusterGenericStub<V1Node, V1NodeList> {
|
|||
/**
|
||||
* Provide {@link GenericSupplier}.
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.UnusedFormalParameter" })
|
||||
@SuppressWarnings({ "PMD.UnusedFormalParameter",
|
||||
"PMD.UnusedPrivateMethod" })
|
||||
private static K8sV1NodeStub getGeneric(Class<V1Node> objectClass,
|
||||
Class<V1NodeList> objectListClass, K8sClient client,
|
||||
APIResource context, String name) {
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import java.util.List;
|
|||
/**
|
||||
* A stub for pods (v1).
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
public class K8sV1PodStub extends K8sGenericStub<V1Pod, V1PodList> {
|
||||
|
||||
/** The pods' context. */
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import java.util.List;
|
|||
/**
|
||||
* A stub for pods (v1).
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
public class K8sV1PvcStub extends
|
||||
K8sGenericStub<V1PersistentVolumeClaim, V1PersistentVolumeClaimList> {
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import java.util.List;
|
|||
/**
|
||||
* A stub for secrets (v1).
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
public class K8sV1SecretStub extends K8sGenericStub<V1Secret, V1SecretList> {
|
||||
|
||||
public static final APIResource CONTEXT = new APIResource("", List.of("v1"),
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import java.util.List;
|
|||
/**
|
||||
* A stub for secrets (v1).
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
public class K8sV1ServiceStub extends K8sGenericStub<V1Service, V1ServiceList> {
|
||||
|
||||
public static final APIResource CONTEXT = new APIResource("", List.of("v1"),
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import java.util.List;
|
|||
/**
|
||||
* A stub for stateful sets (v1).
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
public class K8sV1StatefulSetStub
|
||||
extends K8sGenericStub<V1StatefulSet, V1StatefulSetList> {
|
||||
|
||||
|
|
|
|||
|
|
@ -46,10 +46,11 @@ import org.jdrupes.vmoperator.util.DataPath;
|
|||
/**
|
||||
* Represents a VM definition.
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.DataClass", "PMD.TooManyMethods" })
|
||||
@SuppressWarnings({ "PMD.DataClass", "PMD.TooManyMethods",
|
||||
"PMD.CouplingBetweenObjects" })
|
||||
public class VmDefinition extends K8sDynamicModel {
|
||||
|
||||
@SuppressWarnings({ "unused" })
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions", "unused" })
|
||||
private static final Logger logger
|
||||
= Logger.getLogger(VmDefinition.class.getName());
|
||||
@SuppressWarnings("PMD.FieldNamingConventions")
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import java.util.Collection;
|
|||
* state and can therefore be used for any kind of object, especially
|
||||
* custom objects.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
public class VmDefinitionStub
|
||||
extends K8sDynamicStubBase<VmDefinition, VmDefinitions> {
|
||||
|
||||
|
|
@ -63,6 +64,8 @@ public class VmDefinitionStub
|
|||
* @return the stub if the object exists
|
||||
* @throws ApiException the api exception
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.AvoidBranchingStatementAsLastInLoop",
|
||||
"PMD.AvoidInstantiatingObjectsInLoops", "PMD.UseObjectForClearerAPI" })
|
||||
public static VmDefinitionStub get(K8sClient client,
|
||||
GroupVersionKind gvk, String namespace, String name)
|
||||
throws ApiException {
|
||||
|
|
@ -80,6 +83,8 @@ public class VmDefinitionStub
|
|||
* @return the stub if the object exists
|
||||
* @throws ApiException the api exception
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.AvoidBranchingStatementAsLastInLoop",
|
||||
"PMD.AvoidInstantiatingObjectsInLoops", "PMD.UseObjectForClearerAPI" })
|
||||
public static VmDefinitionStub get(K8sClient client,
|
||||
APIResource context, String namespace, String name) {
|
||||
return new VmDefinitionStub(client, context, namespace, name);
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import java.util.logging.Logger;
|
|||
*/
|
||||
public class VmExtraData {
|
||||
|
||||
@SuppressWarnings("PMD.FieldNamingConventions")
|
||||
private static final Logger logger
|
||||
= Logger.getLogger(VmExtraData.class.getName());
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import org.jdrupes.vmoperator.util.DataPath;
|
|||
/**
|
||||
* Represents a VM pool.
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.DataClass" })
|
||||
public class VmPool {
|
||||
|
||||
private final String name;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import org.jgrapes.core.Event;
|
|||
/**
|
||||
* Assign a VM from a pool to a user.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataClass")
|
||||
public class AssignVm extends Event<VmData> {
|
||||
|
||||
private final String fromPool;
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ public interface ChannelDictionary<K, C extends Channel, A> {
|
|||
* @param channel the channel
|
||||
* @param associated the associated
|
||||
*/
|
||||
@SuppressWarnings("PMD.ShortClassName")
|
||||
public record Value<C extends Channel, A>(C channel, A associated) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -149,6 +149,8 @@ public class ChannelManager<K, C extends Channel, A>
|
|||
* @param supplier the supplier
|
||||
* @return the channel
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.AssignmentInOperand",
|
||||
"PMD.DataflowAnomalyAnalysis" })
|
||||
public C computeIfAbsent(K key, Function<K, C> supplier) {
|
||||
return entries.computeIfAbsent(key,
|
||||
k -> new Value<>(supplier.apply(k), null)).channel();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import org.jgrapes.core.Event;
|
|||
/**
|
||||
* Gets the current display secret and optionally updates it.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataClass")
|
||||
public class GetDisplaySecret extends Event<String> {
|
||||
|
||||
private final VmDefinition vmDef;
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import org.jgrapes.core.Event;
|
|||
/**
|
||||
* Gets the known pools' definitions.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataClass")
|
||||
public class GetPools extends Event<List<VmPool>> {
|
||||
|
||||
private String name;
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import org.jgrapes.core.Event;
|
|||
/**
|
||||
* Gets the known VMs' definitions and channels.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataClass")
|
||||
public class GetVms extends Event<List<GetVms.VmData>> {
|
||||
|
||||
private String name;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import org.jgrapes.core.Event;
|
|||
/**
|
||||
* Modifies a VM.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataClass")
|
||||
public class ModifyVm extends Event<Void> {
|
||||
|
||||
private final String name;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import org.jgrapes.core.Event;
|
|||
/**
|
||||
* Triggers a reset of the VM.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataClass")
|
||||
public class ResetVm extends Event<String> {
|
||||
|
||||
private final String vmName;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import org.jgrapes.core.Event;
|
|||
/**
|
||||
* Note the assignment to a user in the VM status.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataClass")
|
||||
public class UpdateAssignment extends Event<Boolean> {
|
||||
|
||||
private final VmPool fromPool;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import org.jgrapes.core.Subchannel.DefaultSubchannel;
|
|||
/**
|
||||
* A subchannel used to send the events related to a specific VM.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataClass")
|
||||
public class VmChannel extends DefaultSubchannel {
|
||||
|
||||
private final EventPipeline pipeline;
|
||||
|
|
@ -55,6 +56,7 @@ public class VmChannel extends DefaultSubchannel {
|
|||
* @param definition the definition
|
||||
* @return the watch channel
|
||||
*/
|
||||
@SuppressWarnings("PMD.LinguisticNaming")
|
||||
public VmChannel setVmDefinition(VmDefinition definition) {
|
||||
this.definition = definition;
|
||||
return this;
|
||||
|
|
@ -85,6 +87,7 @@ public class VmChannel extends DefaultSubchannel {
|
|||
* @param generation the generation to set
|
||||
* @return true if value has changed
|
||||
*/
|
||||
@SuppressWarnings("PMD.LinguisticNaming")
|
||||
public boolean setGeneration(long generation) {
|
||||
if (this.generation == generation) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import org.jgrapes.core.Event;
|
|||
/**
|
||||
* Indicates a change in a pool configuration.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataClass")
|
||||
public class VmPoolChanged extends Event<Void> {
|
||||
|
||||
private final VmPool vmPool;
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ data:
|
|||
# The template to use. Resolved relative to /usr/share/vmrunner/templates.
|
||||
# template: "Standard-VM-latest.ftl.yaml"
|
||||
<#if spec.runnerTemplate?? && spec.runnerTemplate.source?? >
|
||||
template: ${ spec.runnerTemplate.source }
|
||||
template: ${ cm.spec().runnerTemplate.source }
|
||||
</#if>
|
||||
|
||||
# The template is copied to the data diretory when the VM starts for
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ import org.jgrapes.util.events.ConfigurationUpdate;
|
|||
* @param <O> the object type for the context
|
||||
* @param <L> the object list type for the context
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis" })
|
||||
public abstract class AbstractMonitor<O extends KubernetesObject,
|
||||
L extends KubernetesListObject, C extends Channel> extends Component {
|
||||
|
||||
|
|
@ -180,6 +181,7 @@ public abstract class AbstractMonitor<O extends KubernetesObject,
|
|||
* @param event the event
|
||||
*/
|
||||
@Handler(priority = 10)
|
||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
||||
public void onStart(Start event) {
|
||||
try {
|
||||
// Get namespace
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
|
|||
/**
|
||||
* Delegee for reconciling the config map
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
/* default */ class ConfigMapReconciler {
|
||||
|
||||
protected final Logger logger = Logger.getLogger(getClass().getName());
|
||||
|
|
@ -80,6 +81,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
|
|||
* @throws TemplateException the template exception
|
||||
* @throws ApiException the API exception
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
|
||||
public void reconcile(Map<String, Object> model, VmChannel channel,
|
||||
boolean modelChanged)
|
||||
throws IOException, TemplateException, ApiException {
|
||||
|
|
@ -187,6 +189,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
|
|||
private final TemplateMethodModelEx adjustCloudInitMetaModel
|
||||
= new TemplateMethodModelEx() {
|
||||
@Override
|
||||
@SuppressWarnings("PMD.PreserveStackTrace")
|
||||
public Object exec(@SuppressWarnings("rawtypes") List arguments)
|
||||
throws TemplateModelException {
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.jdrupes.vmoperator.manager;
|
|||
/**
|
||||
* Some constants.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataClass")
|
||||
public class Constants extends org.jdrupes.vmoperator.common.Constants {
|
||||
|
||||
/** The Constant STATE_RUNNING. */
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ import org.jgrapes.core.Channel;
|
|||
* of the pod running the VM in response to force an update of the files
|
||||
* in the pod that reflect the information from the secret.
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis", "PMD.TooManyStaticImports" })
|
||||
public class DisplaySecretMonitor
|
||||
extends AbstractMonitor<V1Secret, V1SecretList, VmChannel> {
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ import org.jose4j.base64url.Base64;
|
|||
* * `passwordValidity`: the validity of the random password in seconds.
|
||||
* Used to calculate the password expiry time in the generated secret.
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis", "PMD.TooManyStaticImports" })
|
||||
public class DisplaySecretReconciler extends Component {
|
||||
|
||||
protected final Logger logger = Logger.getLogger(getClass().getName());
|
||||
|
|
@ -103,15 +104,12 @@ public class DisplaySecretReconciler extends Component {
|
|||
return oldConfig;
|
||||
}).ifPresent(c -> {
|
||||
try {
|
||||
Optional.ofNullable(c.get("passwordValidity"))
|
||||
.map(p -> p instanceof Integer ? (Integer) p
|
||||
: Integer.valueOf((String) p))
|
||||
.ifPresent(p -> {
|
||||
passwordValidity = p;
|
||||
});
|
||||
} catch (NumberFormatException e) {
|
||||
logger.warning(
|
||||
() -> "Malformed configuration: " + e.getMessage());
|
||||
if (c.containsKey("passwordValidity")) {
|
||||
passwordValidity = Integer
|
||||
.parseInt((String) c.get("passwordValidity"));
|
||||
}
|
||||
} catch (ClassCastException e) {
|
||||
logger.config("Malformed configuration: " + e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -192,6 +190,7 @@ public class DisplaySecretReconciler extends Component {
|
|||
* @throws ApiException the api exception
|
||||
*/
|
||||
@Handler
|
||||
@SuppressWarnings("PMD.StringInstantiation")
|
||||
public void onGetDisplaySecret(GetDisplaySecret event, VmChannel channel)
|
||||
throws ApiException {
|
||||
// Get VM definition and check if running
|
||||
|
|
@ -320,6 +319,7 @@ public class DisplaySecretReconciler extends Component {
|
|||
/**
|
||||
* The Class PendingGet.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataClass")
|
||||
private static class PendingRequest {
|
||||
public final GetDisplaySecret event;
|
||||
public final long expectedSerial;
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
|
|||
/**
|
||||
* Delegee for reconciling the service
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
/* default */ class LoadBalancerReconciler {
|
||||
|
||||
private static final String LOAD_BALANCER_SERVICE = "loadBalancerService";
|
||||
|
|
@ -85,7 +86,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
|
|||
}
|
||||
|
||||
// Check if to be generated
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
@SuppressWarnings({ "PMD.AvoidDuplicateLiterals", "unchecked" })
|
||||
var lbsDef = Optional.of(model)
|
||||
.map(m -> (Map<String, Object>) m.get("reconciler"))
|
||||
.map(c -> c.get(LOAD_BALANCER_SERVICE)).orElse(Boolean.FALSE);
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ import org.jgrapes.webconsole.vuejs.VueJsConsoleWeblet;
|
|||
/**
|
||||
* The application class.
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.ExcessiveImports" })
|
||||
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis", "PMD.ExcessiveImports" })
|
||||
public class Manager extends Component {
|
||||
|
||||
private static String version;
|
||||
|
|
@ -97,8 +97,8 @@ public class Manager extends Component {
|
|||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.NcssCount",
|
||||
"PMD.ConstructorCallsOverridableMethod" })
|
||||
@SuppressWarnings({ "PMD.TooFewBranchesForASwitchStatement",
|
||||
"PMD.NcssCount", "PMD.ConstructorCallsOverridableMethod" })
|
||||
public Manager(CommandLine cmdLine) throws IOException, URISyntaxException {
|
||||
super(new NamedChannel("manager"));
|
||||
// Prepare component tree
|
||||
|
|
@ -217,6 +217,7 @@ public class Manager extends Component {
|
|||
* @param event the event
|
||||
*/
|
||||
@Handler
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
public void onConfigurationUpdate(ConfigurationUpdate event) {
|
||||
event.structured(componentPath()).ifPresent(c -> {
|
||||
if (c.containsKey("clusterName")) {
|
||||
|
|
@ -290,6 +291,7 @@ public class Manager extends Component {
|
|||
* @param args the arguments
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
// Instance logger is not available yet.
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
|
|||
/**
|
||||
* Delegee for reconciling the pod.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
/* default */ class PodReconciler {
|
||||
|
||||
protected final Logger logger = Logger.getLogger(getClass().getName());
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ import org.jgrapes.core.events.Attached;
|
|||
* {@link VmPoolChanged} events fired on a special pipeline to
|
||||
* avoid concurrent change informations.
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis", "PMD.ExcessiveImports" })
|
||||
public class PoolMonitor extends
|
||||
AbstractMonitor<K8sDynamicModel, K8sDynamicModels, Channel> {
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
|
|||
/**
|
||||
* Delegee for reconciling the stateful set (effectively the pod).
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
/* default */ class PvcReconciler {
|
||||
|
||||
protected final Logger logger = Logger.getLogger(getClass().getName());
|
||||
|
|
@ -74,7 +75,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
|
|||
* @throws TemplateException the template exception
|
||||
* @throws ApiException the api exception
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
@SuppressWarnings({ "PMD.AvoidDuplicateLiterals", "unchecked" })
|
||||
public void reconcile(VmDefinition vmDef, Map<String, Object> model,
|
||||
VmChannel channel, boolean specChanged)
|
||||
throws IOException, TemplateException, ApiException {
|
||||
|
|
|
|||
|
|
@ -137,13 +137,15 @@ import org.jgrapes.util.events.ConfigurationUpdate;
|
|||
*
|
||||
* @see org.jdrupes.vmoperator.manager.DisplaySecretReconciler
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.AvoidDuplicateLiterals" })
|
||||
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis",
|
||||
"PMD.AvoidDuplicateLiterals" })
|
||||
public class Reconciler extends Component {
|
||||
|
||||
/** The Constant mapper. */
|
||||
@SuppressWarnings("PMD.FieldNamingConventions")
|
||||
protected static final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@SuppressWarnings("PMD.SingularField")
|
||||
private final Configuration fmConfig;
|
||||
private final ConfigMapReconciler cmReconciler;
|
||||
private final DisplaySecretReconciler dsReconciler;
|
||||
|
|
@ -201,6 +203,7 @@ public class Reconciler extends Component {
|
|||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
@Handler
|
||||
@SuppressWarnings("PMD.ConfusingTernary")
|
||||
public void onVmResourceChanged(VmResourceChanged event, VmChannel channel)
|
||||
throws ApiException, TemplateException, IOException {
|
||||
// Ownership relationships takes care of deletions
|
||||
|
|
@ -335,6 +338,7 @@ public class Reconciler extends Component {
|
|||
private final TemplateMethodModelEx formatMemoryModel
|
||||
= new TemplateMethodModelEx() {
|
||||
@Override
|
||||
@SuppressWarnings("PMD.PreserveStackTrace")
|
||||
public Object exec(@SuppressWarnings("rawtypes") List arguments)
|
||||
throws TemplateModelException {
|
||||
var arg = arguments.get(0);
|
||||
|
|
@ -364,7 +368,8 @@ public class Reconciler extends Component {
|
|||
private final TemplateMethodModelEx imgageLocationModel
|
||||
= new TemplateMethodModelEx() {
|
||||
@Override
|
||||
@SuppressWarnings({ "PMD.AvoidLiteralsInIfCondition" })
|
||||
@SuppressWarnings({ "PMD.PreserveStackTrace",
|
||||
"PMD.AvoidLiteralsInIfCondition" })
|
||||
public Object exec(@SuppressWarnings("rawtypes") List arguments)
|
||||
throws TemplateModelException {
|
||||
var image = ((SimpleScalar) arguments.get(0)).getAsString();
|
||||
|
|
@ -389,6 +394,7 @@ public class Reconciler extends Component {
|
|||
private final TemplateMethodModelEx toJsonModel
|
||||
= new TemplateMethodModelEx() {
|
||||
@Override
|
||||
@SuppressWarnings("PMD.PreserveStackTrace")
|
||||
public Object exec(@SuppressWarnings("rawtypes") List arguments)
|
||||
throws TemplateModelException {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ import org.jgrapes.core.annotation.Handler;
|
|||
* event pipeline should be used for all events related to changes of
|
||||
* a particular VM.
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis", "PMD.ExcessiveImports" })
|
||||
public class VmMonitor extends
|
||||
AbstractMonitor<VmDefinition, VmDefinitions, VmChannel> {
|
||||
|
||||
|
|
@ -106,6 +107,7 @@ public class VmMonitor extends
|
|||
purge();
|
||||
}
|
||||
|
||||
@SuppressWarnings("PMD.CognitiveComplexity")
|
||||
private void purge() throws ApiException {
|
||||
// Get existing CRs (VMs)
|
||||
var known = K8sDynamicStub.list(client(), context(), namespace())
|
||||
|
|
@ -190,6 +192,7 @@ public class VmMonitor extends
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
|
||||
private void addExtraData(VmDefinition vmDef, VmDefinition prevState) {
|
||||
var extra = new VmExtraData(vmDef);
|
||||
var prevExtra = Optional.ofNullable(prevState).map(VmDefinition::extra);
|
||||
|
|
@ -238,6 +241,7 @@ public class VmMonitor extends
|
|||
.ofNullable(pod.getSpec().getNodeName()).orElse("");
|
||||
logger.finer(() -> "Adding node name " + nodeName
|
||||
+ " to VM info for " + vmDef.name());
|
||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
||||
var addrs = new ArrayList<String>();
|
||||
Optional.ofNullable(pod.getStatus().getPodIPs())
|
||||
.orElse(Collections.emptyList()).stream()
|
||||
|
|
|
|||
11
org.jdrupes.vmoperator.runner.qemu/build.sbt
Normal file
11
org.jdrupes.vmoperator.runner.qemu/build.sbt
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
enablePlugins(JavaAppPackaging)
|
||||
|
||||
libraryDependencies ++= Seq(
|
||||
"org.jgrapes" % "org.jgrapes.core" % "[1.22.1,2)",
|
||||
"org.jgrapes" % "org.jgrapes.util" % "[1.38.1,2)",
|
||||
"org.jgrapes" % "org.jgrapes.io" % "[2.12.1,3)",
|
||||
"org.jgrapes" % "org.jgrapes.http" % "[3.5.0,4)",
|
||||
"commons-cli" % "commons-cli" % "1.5.0",
|
||||
"com.fasterxml.jackson.dataformat" % "jackson-dataformat-yaml" % "[2.16.1]",
|
||||
"org.slf4j" % "slf4j-jdk14" % "[2.0.7,3)" % Runtime
|
||||
)
|
||||
|
|
@ -36,6 +36,7 @@ import org.jgrapes.core.annotation.Handler;
|
|||
/**
|
||||
* The Class CdMediaController.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
public class CdMediaController extends Component {
|
||||
|
||||
/**
|
||||
|
|
@ -54,6 +55,7 @@ public class CdMediaController extends Component {
|
|||
*
|
||||
* @param componentChannel the component channel
|
||||
*/
|
||||
@SuppressWarnings("PMD.AssignmentToNonFinalStatic")
|
||||
public CdMediaController(Channel componentChannel) {
|
||||
super(componentChannel);
|
||||
}
|
||||
|
|
@ -64,7 +66,8 @@ public class CdMediaController extends Component {
|
|||
* @param event the event
|
||||
*/
|
||||
@Handler
|
||||
@SuppressWarnings({ "PMD.AvoidInstantiatingObjectsInLoops" })
|
||||
@SuppressWarnings({ "PMD.AvoidLiteralsInIfCondition",
|
||||
"PMD.AvoidInstantiatingObjectsInLoops" })
|
||||
public void onConfigureQemu(ConfigureQemu event) {
|
||||
if (event.runState() == RunState.TERMINATING) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -39,9 +39,11 @@ import org.jdrupes.vmoperator.util.FsdUtils;
|
|||
/**
|
||||
* The configuration information from the configuration file.
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.ExcessivePublicCount", "PMD.TooManyFields" })
|
||||
public class Configuration implements Dto {
|
||||
private static final String CI_INSTANCE_ID = "instance-id";
|
||||
|
||||
@SuppressWarnings("PMD.FieldNamingConventions")
|
||||
protected final Logger logger = Logger.getLogger(getClass().getName());
|
||||
|
||||
/** Configuration timestamp. */
|
||||
|
|
@ -93,12 +95,15 @@ public class Configuration implements Dto {
|
|||
public static class CloudInit implements Dto {
|
||||
|
||||
/** The meta data. */
|
||||
@SuppressWarnings("PMD.UseConcurrentHashMap")
|
||||
public Map<String, Object> metaData;
|
||||
|
||||
/** The user data. */
|
||||
@SuppressWarnings("PMD.UseConcurrentHashMap")
|
||||
public Map<String, Object> userData;
|
||||
|
||||
/** The network config. */
|
||||
@SuppressWarnings("PMD.UseConcurrentHashMap")
|
||||
public Map<String, Object> networkConfig;
|
||||
}
|
||||
|
||||
|
|
@ -294,6 +299,7 @@ public class Configuration implements Dto {
|
|||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("PMD.AvoidLiteralsInIfCondition")
|
||||
private void checkDrives() {
|
||||
for (Drive drive : vm.drives) {
|
||||
if (drive.file != null || drive.device != null
|
||||
|
|
@ -313,6 +319,7 @@ public class Configuration implements Dto {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("PMD.AvoidDeeplyNestedIfStmts")
|
||||
private boolean checkRuntimeDir() {
|
||||
// Runtime directory (sockets etc.)
|
||||
if (runtimeDir == null) {
|
||||
|
|
@ -348,6 +355,7 @@ public class Configuration implements Dto {
|
|||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("PMD.AvoidDeeplyNestedIfStmts")
|
||||
private boolean checkDataDir() {
|
||||
// Data directory
|
||||
if (dataDir == null) {
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ import org.jgrapes.core.events.Start;
|
|||
* A (sub)component that updates the console status in the CR status.
|
||||
* Created as child of {@link StatusUpdater}.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
public class ConsoleTracker extends VmDefUpdater {
|
||||
|
||||
private VmDefinitionStub vmStub;
|
||||
|
|
@ -52,6 +53,7 @@ public class ConsoleTracker extends VmDefUpdater {
|
|||
*
|
||||
* @param componentChannel the component channel
|
||||
*/
|
||||
@SuppressWarnings("PMD.ConstructorCallsOverridableMethod")
|
||||
public ConsoleTracker(Channel componentChannel) {
|
||||
super(componentChannel);
|
||||
apiClient = (K8sClient) io.kubernetes.client.openapi.Configuration
|
||||
|
|
@ -89,7 +91,8 @@ public class ConsoleTracker extends VmDefUpdater {
|
|||
* @throws ApiException the api exception
|
||||
*/
|
||||
@Handler
|
||||
@SuppressWarnings({ "PMD.AvoidLiteralsInIfCondition" })
|
||||
@SuppressWarnings({ "PMD.AvoidLiteralsInIfCondition",
|
||||
"PMD.AvoidDuplicateLiterals" })
|
||||
public void onSpiceInitialized(SpiceInitializedEvent event)
|
||||
throws ApiException {
|
||||
if (vmStub == null) {
|
||||
|
|
@ -124,6 +127,7 @@ public class ConsoleTracker extends VmDefUpdater {
|
|||
* @throws ApiException the api exception
|
||||
*/
|
||||
@Handler
|
||||
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
|
||||
public void onSpiceDisconnected(SpiceDisconnectedEvent event)
|
||||
throws ApiException {
|
||||
if (vmStub == null) {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.jdrupes.vmoperator.runner.qemu;
|
|||
/**
|
||||
* Some constants.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataClass")
|
||||
public class Constants extends org.jdrupes.vmoperator.common.Constants {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ import org.jgrapes.core.annotation.Handler;
|
|||
/**
|
||||
* The Class CpuController.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
public class CpuController extends Component {
|
||||
|
||||
private Integer currentCpus;
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ import org.jgrapes.util.events.WatchFile;
|
|||
/**
|
||||
* The Class DisplayController.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
public class DisplayController extends Component {
|
||||
|
||||
private String currentPassword;
|
||||
|
|
@ -58,7 +59,8 @@ public class DisplayController extends Component {
|
|||
* @param componentChannel the component channel
|
||||
* @param configDir
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.ConstructorCallsOverridableMethod" })
|
||||
@SuppressWarnings({ "PMD.AssignmentToNonFinalStatic",
|
||||
"PMD.ConstructorCallsOverridableMethod" })
|
||||
public DisplayController(Channel componentChannel, Path configDir) {
|
||||
super(componentChannel);
|
||||
this.configDir = configDir;
|
||||
|
|
@ -112,6 +114,7 @@ public class DisplayController extends Component {
|
|||
* @param event the event
|
||||
*/
|
||||
@Handler
|
||||
@SuppressWarnings("PMD.EmptyCatchBlock")
|
||||
public void onFileChanged(FileChanged event) {
|
||||
if (event.path().equals(configDir.resolve(DisplaySecret.PASSWORD))) {
|
||||
logger.fine(() -> "Display password updated");
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ import org.jgrapes.util.events.ConfigurationUpdate;
|
|||
* If the log level for this class is set to fine, the messages
|
||||
* exchanged on the monitor socket are logged.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
public class QemuMonitor extends QemuConnector {
|
||||
|
||||
private int powerdownTimeout;
|
||||
|
|
@ -71,6 +72,8 @@ public class QemuMonitor extends QemuConnector {
|
|||
* @param configDir the config dir
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.AssignmentToNonFinalStatic",
|
||||
"PMD.ConstructorCallsOverridableMethod" })
|
||||
public QemuMonitor(Channel componentChannel, Path configDir)
|
||||
throws IOException {
|
||||
super(componentChannel);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ public class RamController extends Component {
|
|||
*
|
||||
* @param componentChannel the component channel
|
||||
*/
|
||||
@SuppressWarnings("PMD.AssignmentToNonFinalStatic")
|
||||
public RamController(Channel componentChannel) {
|
||||
super(componentChannel);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -201,7 +201,8 @@ import org.jgrapes.util.events.WatchFile;
|
|||
*
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.ExcessiveImports", "PMD.AvoidPrintStackTrace",
|
||||
"PMD.TooManyMethods", "PMD.CouplingBetweenObjects" })
|
||||
"PMD.DataflowAnomalyAnalysis", "PMD.TooManyMethods",
|
||||
"PMD.CouplingBetweenObjects", "PMD.TooManyFields" })
|
||||
public class Runner extends Component {
|
||||
|
||||
private static final String TEMPLATE_DIR
|
||||
|
|
@ -217,6 +218,7 @@ public class Runner extends Component {
|
|||
.builder().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)
|
||||
.build());
|
||||
private final JsonNode defaults;
|
||||
@SuppressWarnings("PMD.UseConcurrentHashMap")
|
||||
private final File configFile;
|
||||
private final Path configDir;
|
||||
private Configuration initialConfig;
|
||||
|
|
@ -248,7 +250,8 @@ public class Runner extends Component {
|
|||
* @param cmdLine the cmd line
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.ConstructorCallsOverridableMethod" })
|
||||
@SuppressWarnings({ "PMD.SystemPrintln",
|
||||
"PMD.ConstructorCallsOverridableMethod" })
|
||||
public Runner(CommandLine cmdLine) throws IOException {
|
||||
yamlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
|
||||
false);
|
||||
|
|
@ -384,6 +387,8 @@ public class Runner extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "PMD.CognitiveComplexity",
|
||||
"PMD.DataflowAnomalyAnalysis" })
|
||||
private void setFirmwarePaths(Configuration config) throws IOException {
|
||||
JsonNode firmware = defaults.path("firmware").path(config.vm.firmware);
|
||||
// Get file for firmware ROM
|
||||
|
|
@ -615,6 +620,8 @@ public class Runner extends Component {
|
|||
* @throws InterruptedException the interrupted exception
|
||||
*/
|
||||
@Handler
|
||||
@SuppressWarnings({ "PMD.SwitchStmtsShouldHaveDefault",
|
||||
"PMD.TooFewBranchesForASwitchStatement" })
|
||||
public void onProcessStarted(ProcessStarted event, ProcessChannel channel)
|
||||
throws InterruptedException {
|
||||
event.startEvent().associated(CommandDefinition.class)
|
||||
|
|
@ -771,6 +778,7 @@ public class Runner extends Component {
|
|||
"The VM has been shut down"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("PMD.ConfusingArgumentToVarargsMethod")
|
||||
private void shutdown() {
|
||||
if (!Set.of(RunState.TERMINATING, RunState.STOPPED).contains(state)) {
|
||||
fire(new Stop());
|
||||
|
|
|
|||
|
|
@ -66,7 +66,8 @@ import org.jgrapes.core.events.Start;
|
|||
/**
|
||||
* Updates the CR status.
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.CouplingBetweenObjects" })
|
||||
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis",
|
||||
"PMD.CouplingBetweenObjects" })
|
||||
public class StatusUpdater extends VmDefUpdater {
|
||||
|
||||
@SuppressWarnings("PMD.FieldNamingConventions")
|
||||
|
|
@ -89,6 +90,7 @@ public class StatusUpdater extends VmDefUpdater {
|
|||
*
|
||||
* @param componentChannel the component channel
|
||||
*/
|
||||
@SuppressWarnings("PMD.ConstructorCallsOverridableMethod")
|
||||
public StatusUpdater(Channel componentChannel) {
|
||||
super(componentChannel);
|
||||
attach(new ConsoleTracker(componentChannel));
|
||||
|
|
@ -151,6 +153,7 @@ public class StatusUpdater extends VmDefUpdater {
|
|||
* @throws ApiException
|
||||
*/
|
||||
@Handler
|
||||
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
|
||||
public void onConfigureQemu(ConfigureQemu event)
|
||||
throws ApiException {
|
||||
guestShutdownStops = event.configuration().guestShutdownStops;
|
||||
|
|
@ -184,7 +187,8 @@ public class StatusUpdater extends VmDefUpdater {
|
|||
* @throws ApiException
|
||||
*/
|
||||
@Handler
|
||||
@SuppressWarnings({ "PMD.AssignmentInOperand" })
|
||||
@SuppressWarnings({ "PMD.AvoidLiteralsInIfCondition",
|
||||
"PMD.AssignmentInOperand", "PMD.AvoidDuplicateLiterals" })
|
||||
public void onRunnerStateChanged(RunnerStateChange event)
|
||||
throws ApiException {
|
||||
VmDefinition vmDef;
|
||||
|
|
@ -421,6 +425,7 @@ public class StatusUpdater extends VmDefUpdater {
|
|||
* @throws ApiException
|
||||
*/
|
||||
@Handler
|
||||
@SuppressWarnings("PMD.AssignmentInOperand")
|
||||
public void onVmopAgentLoggedIn(VmopAgentLoggedIn event)
|
||||
throws ApiException {
|
||||
vmStub.updateStatus(from -> {
|
||||
|
|
@ -437,6 +442,7 @@ public class StatusUpdater extends VmDefUpdater {
|
|||
* @throws ApiException
|
||||
*/
|
||||
@Handler
|
||||
@SuppressWarnings("PMD.AssignmentInOperand")
|
||||
public void onVmopAgentLoggedOut(VmopAgentLoggedOut event)
|
||||
throws ApiException {
|
||||
vmStub.updateStatus(from -> {
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ import org.jgrapes.util.events.InitialConfiguration;
|
|||
/**
|
||||
* Updates the CR status.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
public class VmDefUpdater extends Component {
|
||||
|
||||
protected String namespace;
|
||||
|
|
|
|||
|
|
@ -87,7 +87,8 @@ public class VmopAgentClient extends AgentConnector {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "PMD.AvoidLiteralsInIfCondition" })
|
||||
@SuppressWarnings({ "PMD.UnnecessaryReturn",
|
||||
"PMD.AvoidLiteralsInIfCondition" })
|
||||
protected void processInput(String line) throws IOException {
|
||||
logger.finer(() -> "vmop agent(in): " + line);
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|||
*/
|
||||
public class QmpCapabilities extends QmpCommand {
|
||||
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions" })
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions",
|
||||
"PMD.VariableNamingConventions" })
|
||||
private static final JsonNode jsonTemplate
|
||||
= parseJson("{ \"execute\": \"qmp_capabilities\" }");
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
|||
*/
|
||||
public class QmpChangeMedium extends QmpCommand {
|
||||
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions" })
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions",
|
||||
"PMD.VariableNamingConventions" })
|
||||
private static final JsonNode jsonTemplate
|
||||
= parseJson("{ \"execute\": \"blockdev-change-medium\",\"arguments\": {"
|
||||
+ "\"id\": \"\",\"filename\": \"\",\"format\": \"raw\","
|
||||
|
|
|
|||
|
|
@ -30,7 +30,8 @@ import java.util.logging.Logger;
|
|||
*/
|
||||
public abstract class QmpCommand {
|
||||
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions" })
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions",
|
||||
"PMD.VariableNamingConventions" })
|
||||
protected static final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|||
*/
|
||||
public class QmpCont extends QmpCommand {
|
||||
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions" })
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions",
|
||||
"PMD.VariableNamingConventions" })
|
||||
private static final JsonNode jsonTemplate
|
||||
= parseJson("{ \"execute\": \"cont\" }");
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
|||
*/
|
||||
public class QmpDelCpu extends QmpCommand {
|
||||
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions" })
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions",
|
||||
"PMD.VariableNamingConventions" })
|
||||
private static final JsonNode jsonTemplate
|
||||
= parseJson("{ \"execute\": \"device_del\", "
|
||||
+ "\"arguments\": " + "{ \"id\": 0 } }");
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
|||
*/
|
||||
public class QmpOpenTray extends QmpCommand {
|
||||
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions" })
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions",
|
||||
"PMD.VariableNamingConventions" })
|
||||
private static final JsonNode jsonTemplate
|
||||
= parseJson("{ \"execute\": \"blockdev-open-tray\",\"arguments\": {"
|
||||
+ "\"id\": \"\" } }");
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|||
*/
|
||||
public class QmpPowerdown extends QmpCommand {
|
||||
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions" })
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions",
|
||||
"PMD.VariableNamingConventions" })
|
||||
private static final JsonNode jsonTemplate
|
||||
= parseJson("{ \"execute\": \"system_powerdown\" }");
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|||
*/
|
||||
public class QmpQueryHotpluggableCpus extends QmpCommand {
|
||||
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions" })
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions",
|
||||
"PMD.VariableNamingConventions" })
|
||||
private static final JsonNode jsonTemplate = parseJson(
|
||||
"{\"execute\":\"query-hotpluggable-cpus\",\"arguments\":{}}");
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
|||
*/
|
||||
public class QmpRemoveMedium extends QmpCommand {
|
||||
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions" })
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions",
|
||||
"PMD.VariableNamingConventions" })
|
||||
private static final JsonNode jsonTemplate
|
||||
= parseJson("{ \"execute\": \"blockdev-remove-medium\",\"arguments\": {"
|
||||
+ "\"id\": \"\" } }");
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|||
*/
|
||||
public class QmpReset extends QmpCommand {
|
||||
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions" })
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions",
|
||||
"PMD.VariableNamingConventions" })
|
||||
private static final JsonNode jsonTemplate
|
||||
= parseJson("{ \"execute\": \"system_reset\" }");
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,8 @@ import java.math.BigInteger;
|
|||
*/
|
||||
public class QmpSetBalloon extends QmpCommand {
|
||||
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions" })
|
||||
@SuppressWarnings({ "PMD.FieldNamingConventions",
|
||||
"PMD.VariableNamingConventions" })
|
||||
private static final JsonNode jsonTemplate
|
||||
= parseJson("{ \"execute\": \"balloon\", "
|
||||
+ "\"arguments\": " + "{ \"value\": 0 } }");
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ public class MonitorEvent extends Event<Void> {
|
|||
* @param response the response
|
||||
* @return the optional
|
||||
*/
|
||||
@SuppressWarnings("PMD.TooFewBranchesForASwitchStatement")
|
||||
public static Optional<MonitorEvent> from(JsonNode response) {
|
||||
try {
|
||||
var kind = Kind.valueOf(response.get("event").asText());
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import org.jgrapes.core.Event;
|
|||
/**
|
||||
* The Class RunnerStateChange.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataClass")
|
||||
public class RunnerStateChange extends Event<Void> {
|
||||
|
||||
/**
|
||||
|
|
|
|||
5
org.jdrupes.vmoperator.util/build.sbt
Normal file
5
org.jdrupes.vmoperator.util/build.sbt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
|
||||
libraryDependencies ++= Seq(
|
||||
"org.freemarker" % "freemarker" % "[2.3.32,2.4)",
|
||||
"com.google.code.gson" % "gson" % "[2.10.1,2.11)"
|
||||
)
|
||||
|
|
@ -32,6 +32,7 @@ import java.util.logging.Logger;
|
|||
*/
|
||||
public final class DataPath {
|
||||
|
||||
@SuppressWarnings("PMD.FieldNamingConventions")
|
||||
private static final Logger logger
|
||||
= Logger.getLogger(DataPath.class.getName());
|
||||
|
||||
|
|
@ -55,6 +56,7 @@ public final class DataPath {
|
|||
* @param selectors the selectors
|
||||
* @return the result
|
||||
*/
|
||||
@SuppressWarnings("PMD.UseLocaleWithCaseConversions")
|
||||
public static <T> Optional<T> get(Object from, Object... selectors) {
|
||||
Object cur = from;
|
||||
for (var selector : selectors) {
|
||||
|
|
@ -130,6 +132,7 @@ public final class DataPath {
|
|||
@SuppressWarnings({ "PMD.CognitiveComplexity", "unchecked" })
|
||||
public static <T> T deepCopy(T object) {
|
||||
if (object instanceof Map map) {
|
||||
@SuppressWarnings("PMD.UseConcurrentHashMap")
|
||||
Map<Object, Object> copy;
|
||||
try {
|
||||
copy = (Map<Object, Object>) object.getClass().getConstructor()
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ import java.util.function.Supplier;
|
|||
/**
|
||||
* Utility class for pointing to elements on a Gson (Json) tree.
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.ClassWithOnlyPrivateConstructorsShouldBeFinal" })
|
||||
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis",
|
||||
"PMD.ClassWithOnlyPrivateConstructorsShouldBeFinal", "PMD.GodClass" })
|
||||
public class GsonPtr {
|
||||
|
||||
private final JsonElement position;
|
||||
|
|
@ -101,7 +102,7 @@ public class GsonPtr {
|
|||
* @param selectors the selectors
|
||||
* @return the Gson pointer
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.PreserveStackTrace" })
|
||||
@SuppressWarnings({ "PMD.ShortMethodName", "PMD.PreserveStackTrace" })
|
||||
public Optional<GsonPtr> get(Object... selectors) {
|
||||
JsonElement element = position;
|
||||
for (Object sel : selectors) {
|
||||
|
|
@ -145,6 +146,7 @@ public class GsonPtr {
|
|||
* @param cls the cls
|
||||
* @return the result
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.AvoidBranchingStatementAsLastInLoop" })
|
||||
public <T extends JsonElement> T getAs(Class<T> cls) {
|
||||
if (cls.isAssignableFrom(position.getClass())) {
|
||||
return cls.cast(position);
|
||||
|
|
|
|||
|
|
@ -111,8 +111,9 @@ import org.jgrapes.webconsole.base.freemarker.FreeMarkerConlet;
|
|||
* users and roles.
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.ExcessiveImports", "PMD.CouplingBetweenObjects",
|
||||
"PMD.GodClass", "PMD.TooManyMethods", "PMD.CyclomaticComplexity" })
|
||||
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis", "PMD.ExcessiveImports",
|
||||
"PMD.CouplingBetweenObjects", "PMD.GodClass", "PMD.TooManyMethods",
|
||||
"PMD.CyclomaticComplexity" })
|
||||
public class VmAccess extends FreeMarkerConlet<VmAccess.ResourceModel> {
|
||||
|
||||
private static final String VM_NAME_PROPERTY = "vmName";
|
||||
|
|
@ -166,7 +167,7 @@ public class VmAccess extends FreeMarkerConlet<VmAccess.ResourceModel> {
|
|||
*
|
||||
* @param event the event
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
@SuppressWarnings({ "unchecked", "PMD.AvoidDuplicateLiterals" })
|
||||
@Handler
|
||||
public void onConfigurationUpdate(ConfigurationUpdate event) {
|
||||
event.structured(componentPath())
|
||||
|
|
@ -266,7 +267,7 @@ public class VmAccess extends FreeMarkerConlet<VmAccess.ResourceModel> {
|
|||
public void onConsoleConfigured(ConsoleConfigured event,
|
||||
ConsoleConnection connection) throws InterruptedException,
|
||||
IOException {
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
@SuppressWarnings({ "unchecked", "PMD.PrematureDeclaration" })
|
||||
final var rendered
|
||||
= (Set<ResourceModel>) connection.session().get(RENDERED);
|
||||
connection.session().remove(RENDERED);
|
||||
|
|
@ -276,7 +277,8 @@ public class VmAccess extends FreeMarkerConlet<VmAccess.ResourceModel> {
|
|||
addMissingConlets(event, connection, rendered);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "PMD.AvoidInstantiatingObjectsInLoops" })
|
||||
@SuppressWarnings({ "PMD.AvoidInstantiatingObjectsInLoops",
|
||||
"PMD.AvoidDuplicateLiterals" })
|
||||
private void addMissingConlets(ConsoleConfigured event,
|
||||
ConsoleConnection connection, final Set<ResourceModel> rendered)
|
||||
throws InterruptedException {
|
||||
|
|
@ -404,6 +406,7 @@ public class VmAccess extends FreeMarkerConlet<VmAccess.ResourceModel> {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "PMD.AvoidInstantiatingObjectsInLoops" })
|
||||
protected Set<RenderMode> doRenderConlet(RenderConletRequestBase<?> event,
|
||||
ConsoleConnection channel, String conletId, ResourceModel model)
|
||||
throws Exception {
|
||||
|
|
@ -652,8 +655,9 @@ public class VmAccess extends FreeMarkerConlet<VmAccess.ResourceModel> {
|
|||
* @throws InterruptedException
|
||||
*/
|
||||
@Handler(namedChannels = "manager")
|
||||
@SuppressWarnings({ "PMD.CognitiveComplexity",
|
||||
"PMD.AvoidInstantiatingObjectsInLoops" })
|
||||
@SuppressWarnings({ "PMD.ConfusingTernary", "PMD.CognitiveComplexity",
|
||||
"PMD.AvoidInstantiatingObjectsInLoops", "PMD.AvoidDuplicateLiterals",
|
||||
"PMD.ConfusingArgumentToVarargsMethod" })
|
||||
public void onVmResourceChanged(VmResourceChanged event, VmChannel channel)
|
||||
throws IOException, InterruptedException {
|
||||
var vmDef = event.vmDefinition();
|
||||
|
|
@ -849,7 +853,8 @@ public class VmAccess extends FreeMarkerConlet<VmAccess.ResourceModel> {
|
|||
model.getConletId(), "openConsole", cf)));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "PMD.UseLocaleWithCaseConversions" })
|
||||
@SuppressWarnings({ "PMD.AvoidLiteralsInIfCondition",
|
||||
"PMD.UseLocaleWithCaseConversions" })
|
||||
private void selectResource(NotifyConletModel event,
|
||||
ConsoleConnection channel, ResourceModel model)
|
||||
throws JsonProcessingException, InterruptedException {
|
||||
|
|
@ -876,6 +881,7 @@ public class VmAccess extends FreeMarkerConlet<VmAccess.ResourceModel> {
|
|||
/**
|
||||
* The Class AccessModel.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataClass")
|
||||
public static class ResourceModel extends ConletBaseModel {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import java.util.List;
|
|||
/**
|
||||
* The Class TimeSeries.
|
||||
*/
|
||||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
|
||||
public class TimeSeries {
|
||||
|
||||
@SuppressWarnings("PMD.LooseCoupling")
|
||||
|
|
|
|||
|
|
@ -75,7 +75,8 @@ import org.jgrapes.webconsole.base.freemarker.FreeMarkerConlet;
|
|||
/**
|
||||
* The Class {@link VmMgmt}.
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.CouplingBetweenObjects", "PMD.ExcessiveImports" })
|
||||
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis", "PMD.CouplingBetweenObjects",
|
||||
"PMD.ExcessiveImports" })
|
||||
public class VmMgmt extends FreeMarkerConlet<VmMgmt.VmsModel> {
|
||||
|
||||
private Class<?> preferredIpVersion = Inet4Address.class;
|
||||
|
|
@ -111,7 +112,7 @@ public class VmMgmt extends FreeMarkerConlet<VmMgmt.VmsModel> {
|
|||
*
|
||||
* @param event the event
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
@SuppressWarnings({ "unchecked", "PMD.AvoidDuplicateLiterals" })
|
||||
@Handler
|
||||
public void onConfigurationUpdate(ConfigurationUpdate event) {
|
||||
event.structured("/Manager/GuiHttpServer"
|
||||
|
|
@ -176,6 +177,7 @@ public class VmMgmt extends FreeMarkerConlet<VmMgmt.VmsModel> {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
||||
protected Set<RenderMode> doRenderConlet(RenderConletRequestBase<?> event,
|
||||
ConsoleConnection channel, String conletId, VmsModel conletState)
|
||||
throws Exception {
|
||||
|
|
@ -228,6 +230,7 @@ public class VmMgmt extends FreeMarkerConlet<VmMgmt.VmsModel> {
|
|||
simplifiedVmDefinition(vmDef, user, roles)));
|
||||
}
|
||||
|
||||
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
|
||||
private Map<String, Object> simplifiedVmDefinition(VmDefinition vmDef,
|
||||
String user, List<String> roles) {
|
||||
// Convert RAM sizes to unitless numbers
|
||||
|
|
@ -267,8 +270,9 @@ public class VmMgmt extends FreeMarkerConlet<VmMgmt.VmsModel> {
|
|||
* @throws IOException
|
||||
*/
|
||||
@Handler(namedChannels = "manager")
|
||||
@SuppressWarnings({ "PMD.CognitiveComplexity",
|
||||
"PMD.AvoidInstantiatingObjectsInLoops" })
|
||||
@SuppressWarnings({ "PMD.ConfusingTernary", "PMD.CognitiveComplexity",
|
||||
"PMD.AvoidInstantiatingObjectsInLoops", "PMD.AvoidDuplicateLiterals",
|
||||
"PMD.ConfusingArgumentToVarargsMethod" })
|
||||
public void onVmResourceChanged(VmResourceChanged event, VmChannel channel)
|
||||
throws IOException {
|
||||
var vmName = event.vmDefinition().name();
|
||||
|
|
@ -374,6 +378,8 @@ public class VmMgmt extends FreeMarkerConlet<VmMgmt.VmsModel> {
|
|||
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "PMD.AvoidLiteralsInIfCondition",
|
||||
"PMD.LambdaCanBeMethodReference" })
|
||||
private Summary evaluateSummary(boolean force) {
|
||||
if (!force && cachedSummary != null) {
|
||||
return cachedSummary;
|
||||
|
|
@ -396,7 +402,8 @@ public class VmMgmt extends FreeMarkerConlet<VmMgmt.VmsModel> {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "PMD.NcssCount" })
|
||||
@SuppressWarnings({ "PMD.AvoidDecimalLiteralsInBigDecimalConstructor",
|
||||
"PMD.NcssCount" })
|
||||
protected void doUpdateConletState(NotifyConletModel event,
|
||||
ConsoleConnection channel, VmsModel model) throws Exception {
|
||||
event.stop();
|
||||
|
|
|
|||
1
project/build.properties
Normal file
1
project/build.properties
Normal file
|
|
@ -0,0 +1 @@
|
|||
sbt.version=1.10.11
|
||||
1
project/plugins.sbt
Normal file
1
project/plugins.sbt
Normal file
|
|
@ -0,0 +1 @@
|
|||
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "[1.11.1,1.12)")
|
||||
664
sbt
Executable file
664
sbt
Executable file
|
|
@ -0,0 +1,664 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# A more capable sbt runner, coincidentally also called sbt.
|
||||
# Author: Paul Phillips <paulp@improving.org>
|
||||
# https://github.com/paulp/sbt-extras
|
||||
#
|
||||
# Generated from http://www.opensource.org/licenses/bsd-license.php
|
||||
# Copyright (c) 2011, Paul Phillips. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# * Neither the name of the author nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
set -o pipefail
|
||||
|
||||
declare -r sbt_release_version="1.10.11"
|
||||
declare -r sbt_unreleased_version="1.10.11"
|
||||
|
||||
declare -r latest_213="2.13.16"
|
||||
declare -r latest_212="2.12.20"
|
||||
declare -r latest_211="2.11.12"
|
||||
declare -r latest_210="2.10.7"
|
||||
declare -r latest_29="2.9.3"
|
||||
declare -r latest_28="2.8.2"
|
||||
|
||||
declare -r buildProps="project/build.properties"
|
||||
|
||||
declare -r sbt_launch_ivy_release_repo="https://repo.typesafe.com/typesafe/ivy-releases"
|
||||
declare -r sbt_launch_ivy_snapshot_repo="https://repo.scala-sbt.org/scalasbt/ivy-snapshots"
|
||||
declare -r sbt_launch_mvn_release_repo="https://repo1.maven.org/maven2"
|
||||
declare -r sbt_launch_mvn_snapshot_repo="https://repo.scala-sbt.org/scalasbt/maven-snapshots"
|
||||
|
||||
declare -r default_jvm_opts_common="-Xms512m -Xss2m -XX:MaxInlineLevel=18"
|
||||
declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy -Dsbt.coursier.home=project/.coursier"
|
||||
|
||||
declare sbt_jar sbt_dir sbt_create sbt_version sbt_script sbt_new
|
||||
declare sbt_explicit_version
|
||||
declare verbose noshare batch trace_level
|
||||
|
||||
declare java_cmd="java"
|
||||
declare sbt_launch_dir="$HOME/.sbt/launchers"
|
||||
declare sbt_launch_repo
|
||||
|
||||
# pull -J and -D options to give to java.
|
||||
declare -a java_args scalac_args sbt_commands residual_args
|
||||
|
||||
# args to jvm/sbt via files or environment variables
|
||||
declare -a extra_jvm_opts extra_sbt_opts
|
||||
|
||||
echoerr() { echo >&2 "$@"; }
|
||||
vlog() { [[ -n "$verbose" ]] && echoerr "$@"; }
|
||||
die() {
|
||||
echo "Aborting: $*"
|
||||
exit 1
|
||||
}
|
||||
|
||||
setTrapExit() {
|
||||
# save stty and trap exit, to ensure echo is re-enabled if we are interrupted.
|
||||
SBT_STTY="$(stty -g 2>/dev/null)"
|
||||
export SBT_STTY
|
||||
|
||||
# restore stty settings (echo in particular)
|
||||
onSbtRunnerExit() {
|
||||
[ -t 0 ] || return
|
||||
vlog ""
|
||||
vlog "restoring stty: $SBT_STTY"
|
||||
stty "$SBT_STTY"
|
||||
}
|
||||
|
||||
vlog "saving stty: $SBT_STTY"
|
||||
trap onSbtRunnerExit EXIT
|
||||
}
|
||||
|
||||
# this seems to cover the bases on OSX, and someone will
|
||||
# have to tell me about the others.
|
||||
get_script_path() {
|
||||
local path="$1"
|
||||
[[ -L "$path" ]] || {
|
||||
echo "$path"
|
||||
return
|
||||
}
|
||||
|
||||
local -r target="$(readlink "$path")"
|
||||
if [[ "${target:0:1}" == "/" ]]; then
|
||||
echo "$target"
|
||||
else
|
||||
echo "${path%/*}/$target"
|
||||
fi
|
||||
}
|
||||
|
||||
script_path="$(get_script_path "${BASH_SOURCE[0]}")"
|
||||
declare -r script_path
|
||||
script_name="${script_path##*/}"
|
||||
declare -r script_name
|
||||
|
||||
init_default_option_file() {
|
||||
local overriding_var="${!1}"
|
||||
local default_file="$2"
|
||||
if [[ ! -r "$default_file" && "$overriding_var" =~ ^@(.*)$ ]]; then
|
||||
local envvar_file="${BASH_REMATCH[1]}"
|
||||
if [[ -r "$envvar_file" ]]; then
|
||||
default_file="$envvar_file"
|
||||
fi
|
||||
fi
|
||||
echo "$default_file"
|
||||
}
|
||||
|
||||
sbt_opts_file="$(init_default_option_file SBT_OPTS .sbtopts)"
|
||||
sbtx_opts_file="$(init_default_option_file SBTX_OPTS .sbtxopts)"
|
||||
jvm_opts_file="$(init_default_option_file JVM_OPTS .jvmopts)"
|
||||
|
||||
build_props_sbt() {
|
||||
[[ -r "$buildProps" ]] &&
|
||||
grep '^sbt\.version' "$buildProps" | tr '=\r' ' ' | awk '{ print $2; }'
|
||||
}
|
||||
|
||||
set_sbt_version() {
|
||||
sbt_version="${sbt_explicit_version:-$(build_props_sbt)}"
|
||||
[[ -n "$sbt_version" ]] || sbt_version=$sbt_release_version
|
||||
export sbt_version
|
||||
}
|
||||
|
||||
url_base() {
|
||||
local version="$1"
|
||||
|
||||
case "$version" in
|
||||
0.7.*) echo "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/simple-build-tool" ;;
|
||||
0.10.*) echo "$sbt_launch_ivy_release_repo" ;;
|
||||
0.11.[12]) echo "$sbt_launch_ivy_release_repo" ;;
|
||||
0.*-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]) # ie "*-yyyymmdd-hhMMss"
|
||||
echo "$sbt_launch_ivy_snapshot_repo" ;;
|
||||
0.*) echo "$sbt_launch_ivy_release_repo" ;;
|
||||
*-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T[0-9][0-9][0-9][0-9][0-9][0-9]) # ie "*-yyyymmddThhMMss"
|
||||
echo "$sbt_launch_mvn_snapshot_repo" ;;
|
||||
*) echo "$sbt_launch_mvn_release_repo" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
make_url() {
|
||||
local version="$1"
|
||||
|
||||
local base="${sbt_launch_repo:-$(url_base "$version")}"
|
||||
|
||||
case "$version" in
|
||||
0.7.*) echo "$base/sbt-launch-0.7.7.jar" ;;
|
||||
0.10.*) echo "$base/org.scala-tools.sbt/sbt-launch/$version/sbt-launch.jar" ;;
|
||||
0.11.[12]) echo "$base/org.scala-tools.sbt/sbt-launch/$version/sbt-launch.jar" ;;
|
||||
0.*) echo "$base/org.scala-sbt/sbt-launch/$version/sbt-launch.jar" ;;
|
||||
*) echo "$base/org/scala-sbt/sbt-launch/$version/sbt-launch-${version}.jar" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
addJava() {
|
||||
vlog "[addJava] arg = '$1'"
|
||||
java_args+=("$1")
|
||||
}
|
||||
addSbt() {
|
||||
vlog "[addSbt] arg = '$1'"
|
||||
sbt_commands+=("$1")
|
||||
}
|
||||
addScalac() {
|
||||
vlog "[addScalac] arg = '$1'"
|
||||
scalac_args+=("$1")
|
||||
}
|
||||
addResidual() {
|
||||
vlog "[residual] arg = '$1'"
|
||||
residual_args+=("$1")
|
||||
}
|
||||
|
||||
addResolver() { addSbt "set resolvers += $1"; }
|
||||
|
||||
addDebugger() { addJava "-Xdebug" && addJava "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$1"; }
|
||||
|
||||
setThisBuild() {
|
||||
vlog "[addBuild] args = '$*'"
|
||||
local key="$1" && shift
|
||||
addSbt "set $key in ThisBuild := $*"
|
||||
}
|
||||
setScalaVersion() {
|
||||
[[ "$1" == *"-SNAPSHOT" ]] && addResolver 'Resolver.sonatypeRepo("snapshots")'
|
||||
addSbt "++ $1"
|
||||
}
|
||||
setJavaHome() {
|
||||
java_cmd="$1/bin/java"
|
||||
setThisBuild javaHome "_root_.scala.Some(file(\"$1\"))"
|
||||
export JAVA_HOME="$1"
|
||||
export JDK_HOME="$1"
|
||||
export PATH="$JAVA_HOME/bin:$PATH"
|
||||
}
|
||||
|
||||
getJavaVersion() {
|
||||
local -r str=$("$1" -version 2>&1 | grep -E -e '(java|openjdk) version' | awk '{ print $3 }' | tr -d '"')
|
||||
|
||||
# java -version on java8 says 1.8.x
|
||||
# but on 9 and 10 it's 9.x.y and 10.x.y.
|
||||
if [[ "$str" =~ ^1\.([0-9]+)(\..*)?$ ]]; then
|
||||
echo "${BASH_REMATCH[1]}"
|
||||
# Fixes https://github.com/dwijnand/sbt-extras/issues/326
|
||||
elif [[ "$str" =~ ^([0-9]+)(\..*)?(-ea)?$ ]]; then
|
||||
echo "${BASH_REMATCH[1]}"
|
||||
elif [[ -n "$str" ]]; then
|
||||
echoerr "Can't parse java version from: $str"
|
||||
fi
|
||||
}
|
||||
|
||||
checkJava() {
|
||||
# Warn if there is a Java version mismatch between PATH and JAVA_HOME/JDK_HOME
|
||||
|
||||
[[ -n "$JAVA_HOME" && -e "$JAVA_HOME/bin/java" ]] && java="$JAVA_HOME/bin/java"
|
||||
[[ -n "$JDK_HOME" && -e "$JDK_HOME/lib/tools.jar" ]] && java="$JDK_HOME/bin/java"
|
||||
|
||||
if [[ -n "$java" ]]; then
|
||||
pathJavaVersion=$(getJavaVersion java)
|
||||
homeJavaVersion=$(getJavaVersion "$java")
|
||||
if [[ "$pathJavaVersion" != "$homeJavaVersion" ]]; then
|
||||
echoerr "Warning: Java version mismatch between PATH and JAVA_HOME/JDK_HOME, sbt will use the one in PATH"
|
||||
echoerr " Either: fix your PATH, remove JAVA_HOME/JDK_HOME or use -java-home"
|
||||
echoerr " java version from PATH: $pathJavaVersion"
|
||||
echoerr " java version from JAVA_HOME/JDK_HOME: $homeJavaVersion"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
java_version() {
|
||||
local -r version=$(getJavaVersion "$java_cmd")
|
||||
vlog "Detected Java version: $version"
|
||||
echo "$version"
|
||||
}
|
||||
|
||||
is_apple_silicon() { [[ "$(uname -s)" == "Darwin" && "$(uname -m)" == "arm64" ]]; }
|
||||
|
||||
# MaxPermSize critical on pre-8 JVMs but incurs noisy warning on 8+
|
||||
default_jvm_opts() {
|
||||
local -r v="$(java_version)"
|
||||
if [[ $v -ge 17 ]]; then
|
||||
echo "$default_jvm_opts_common"
|
||||
elif [[ $v -ge 10 ]]; then
|
||||
if is_apple_silicon; then
|
||||
# As of Dec 2020, JVM for Apple Silicon (M1) doesn't support JVMCI
|
||||
echo "$default_jvm_opts_common"
|
||||
else
|
||||
echo "$default_jvm_opts_common -XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler"
|
||||
fi
|
||||
elif [[ $v -ge 8 ]]; then
|
||||
echo "$default_jvm_opts_common"
|
||||
else
|
||||
echo "-XX:MaxPermSize=384m $default_jvm_opts_common"
|
||||
fi
|
||||
}
|
||||
|
||||
execRunner() {
|
||||
# print the arguments one to a line, quoting any containing spaces
|
||||
vlog "# Executing command line:" && {
|
||||
for arg; do
|
||||
if [[ -n "$arg" ]]; then
|
||||
if printf "%s\n" "$arg" | grep -q ' '; then
|
||||
printf >&2 "\"%s\"\n" "$arg"
|
||||
else
|
||||
printf >&2 "%s\n" "$arg"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
vlog ""
|
||||
}
|
||||
|
||||
setTrapExit
|
||||
|
||||
if [[ -n "$batch" ]]; then
|
||||
"$@" </dev/null
|
||||
else
|
||||
"$@"
|
||||
fi
|
||||
}
|
||||
|
||||
jar_url() { make_url "$1"; }
|
||||
|
||||
is_cygwin() { [[ "$(uname -a)" == "CYGWIN"* ]]; }
|
||||
|
||||
jar_file() {
|
||||
is_cygwin &&
|
||||
cygpath -w "$sbt_launch_dir/$1/sbt-launch.jar" ||
|
||||
echo "$sbt_launch_dir/$1/sbt-launch.jar"
|
||||
}
|
||||
|
||||
download_url() {
|
||||
local url="$1"
|
||||
local jar="$2"
|
||||
|
||||
mkdir -p "${jar%/*}" && {
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
curl --fail --silent --location "$url" --output "$jar"
|
||||
elif command -v wget >/dev/null 2>&1; then
|
||||
wget -q -O "$jar" "$url"
|
||||
fi
|
||||
} && [[ -r "$jar" ]]
|
||||
}
|
||||
|
||||
acquire_sbt_jar() {
|
||||
{
|
||||
sbt_jar="$(jar_file "$sbt_version")"
|
||||
[[ -r "$sbt_jar" ]]
|
||||
} || {
|
||||
sbt_jar="$HOME/.ivy2/local/org.scala-sbt/sbt-launch/$sbt_version/jars/sbt-launch.jar"
|
||||
[[ -r "$sbt_jar" ]]
|
||||
} || {
|
||||
sbt_jar="$(jar_file "$sbt_version")"
|
||||
jar_url="$(make_url "$sbt_version")"
|
||||
|
||||
echoerr "Downloading sbt launcher for ${sbt_version}:"
|
||||
echoerr " From ${jar_url}"
|
||||
echoerr " To ${sbt_jar}"
|
||||
|
||||
download_url "${jar_url}" "${sbt_jar}"
|
||||
|
||||
case "${sbt_version}" in
|
||||
0.*)
|
||||
vlog "SBT versions < 1.0 do not have published MD5 checksums, skipping check"
|
||||
echo ""
|
||||
;;
|
||||
*) verify_sbt_jar "${sbt_jar}" ;;
|
||||
esac
|
||||
}
|
||||
}
|
||||
|
||||
verify_sbt_jar() {
|
||||
local jar="${1}"
|
||||
local md5="${jar}.md5"
|
||||
md5url="$(make_url "${sbt_version}").md5"
|
||||
|
||||
echoerr "Downloading sbt launcher ${sbt_version} md5 hash:"
|
||||
echoerr " From ${md5url}"
|
||||
echoerr " To ${md5}"
|
||||
|
||||
download_url "${md5url}" "${md5}" >/dev/null 2>&1
|
||||
|
||||
if command -v md5sum >/dev/null 2>&1; then
|
||||
if echo "$(cat "${md5}") ${jar}" | md5sum -c -; then
|
||||
rm -rf "${md5}"
|
||||
return 0
|
||||
else
|
||||
echoerr "Checksum does not match"
|
||||
return 1
|
||||
fi
|
||||
elif command -v md5 >/dev/null 2>&1; then
|
||||
if [ "$(md5 -q "${jar}")" == "$(cat "${md5}")" ]; then
|
||||
rm -rf "${md5}"
|
||||
return 0
|
||||
else
|
||||
echoerr "Checksum does not match"
|
||||
return 1
|
||||
fi
|
||||
elif command -v openssl >/dev/null 2>&1; then
|
||||
if [ "$(openssl md5 -r "${jar}" | awk '{print $1}')" == "$(cat "${md5}")" ]; then
|
||||
rm -rf "${md5}"
|
||||
return 0
|
||||
else
|
||||
echoerr "Checksum does not match"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
echoerr "Could not find an MD5 command"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
usage() {
|
||||
set_sbt_version
|
||||
cat <<EOM
|
||||
Usage: $script_name [options]
|
||||
|
||||
Note that options which are passed along to sbt begin with -- whereas
|
||||
options to this runner use a single dash. Any sbt command can be scheduled
|
||||
to run first by prefixing the command with --, so --warn, --error and so on
|
||||
are not special.
|
||||
|
||||
-h | -help print this message
|
||||
-v verbose operation (this runner is chattier)
|
||||
-d, -w, -q aliases for --debug, --warn, --error (q means quiet)
|
||||
-x debug this script
|
||||
-trace <level> display stack traces with a max of <level> frames (default: -1, traces suppressed)
|
||||
-debug-inc enable debugging log for the incremental compiler
|
||||
-no-colors disable ANSI color codes
|
||||
-sbt-create start sbt even if current directory contains no sbt project
|
||||
-sbt-dir <path> path to global settings/plugins directory (default: ~/.sbt/<version>)
|
||||
-sbt-boot <path> path to shared boot directory (default: ~/.sbt/boot in 0.11+)
|
||||
-ivy <path> path to local Ivy repository (default: ~/.ivy2)
|
||||
-no-share use all local caches; no sharing
|
||||
-offline put sbt in offline mode
|
||||
-jvm-debug <port> Turn on JVM debugging, open at the given port.
|
||||
-batch Disable interactive mode
|
||||
-prompt <expr> Set the sbt prompt; in expr, 's' is the State and 'e' is Extracted
|
||||
-script <file> Run the specified file as a scala script
|
||||
|
||||
# sbt version (default: sbt.version from $buildProps if present, otherwise $sbt_release_version)
|
||||
-sbt-version <version> use the specified version of sbt (default: $sbt_release_version)
|
||||
-sbt-force-latest force the use of the latest release of sbt: $sbt_release_version
|
||||
-sbt-dev use the latest pre-release version of sbt: $sbt_unreleased_version
|
||||
-sbt-jar <path> use the specified jar as the sbt launcher
|
||||
-sbt-launch-dir <path> directory to hold sbt launchers (default: $sbt_launch_dir)
|
||||
-sbt-launch-repo <url> repo url for downloading sbt launcher jar (default: $(url_base "$sbt_version"))
|
||||
|
||||
# scala version (default: as chosen by sbt)
|
||||
-28 use $latest_28
|
||||
-29 use $latest_29
|
||||
-210 use $latest_210
|
||||
-211 use $latest_211
|
||||
-212 use $latest_212
|
||||
-213 use $latest_213
|
||||
-scala-home <path> use the scala build at the specified directory
|
||||
-scala-version <version> use the specified version of scala
|
||||
-binary-version <version> use the specified scala version when searching for dependencies
|
||||
|
||||
# java version (default: java from PATH, currently $(java -version 2>&1 | grep version))
|
||||
-java-home <path> alternate JAVA_HOME
|
||||
|
||||
# passing options to the jvm - note it does NOT use JAVA_OPTS due to pollution
|
||||
# The default set is used if JVM_OPTS is unset and no -jvm-opts file is found
|
||||
<default> $(default_jvm_opts)
|
||||
JVM_OPTS environment variable holding either the jvm args directly, or
|
||||
the reference to a file containing jvm args if given path is prepended by '@' (e.g. '@/etc/jvmopts')
|
||||
Note: "@"-file is overridden by local '.jvmopts' or '-jvm-opts' argument.
|
||||
-jvm-opts <path> file containing jvm args (if not given, .jvmopts in project root is used if present)
|
||||
-Dkey=val pass -Dkey=val directly to the jvm
|
||||
-J-X pass option -X directly to the jvm (-J is stripped)
|
||||
|
||||
# passing options to sbt, OR to this runner
|
||||
SBT_OPTS environment variable holding either the sbt args directly, or
|
||||
the reference to a file containing sbt args if given path is prepended by '@' (e.g. '@/etc/sbtopts')
|
||||
Note: "@"-file is overridden by local '.sbtopts' or '-sbt-opts' argument.
|
||||
-sbt-opts <path> file containing sbt args (if not given, .sbtopts in project root is used if present)
|
||||
-S-X add -X to sbt's scalacOptions (-S is stripped)
|
||||
|
||||
# passing options exclusively to this runner
|
||||
SBTX_OPTS environment variable holding either the sbt-extras args directly, or
|
||||
the reference to a file containing sbt-extras args if given path is prepended by '@' (e.g. '@/etc/sbtxopts')
|
||||
Note: "@"-file is overridden by local '.sbtxopts' or '-sbtx-opts' argument.
|
||||
-sbtx-opts <path> file containing sbt-extras args (if not given, .sbtxopts in project root is used if present)
|
||||
EOM
|
||||
exit 0
|
||||
}
|
||||
|
||||
process_args() {
|
||||
require_arg() {
|
||||
local type="$1"
|
||||
local opt="$2"
|
||||
local arg="$3"
|
||||
|
||||
if [[ -z "$arg" ]] || [[ "${arg:0:1}" == "-" ]]; then
|
||||
die "$opt requires <$type> argument"
|
||||
fi
|
||||
}
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-h | -help) usage ;;
|
||||
-v) verbose=true && shift ;;
|
||||
-d) addSbt "--debug" && shift ;;
|
||||
-w) addSbt "--warn" && shift ;;
|
||||
-q) addSbt "--error" && shift ;;
|
||||
-x) shift ;; # currently unused
|
||||
-trace) require_arg integer "$1" "$2" && trace_level="$2" && shift 2 ;;
|
||||
-debug-inc) addJava "-Dxsbt.inc.debug=true" && shift ;;
|
||||
|
||||
-no-colors) addJava "-Dsbt.log.noformat=true" && addJava "-Dsbt.color=false" && shift ;;
|
||||
-sbt-create) sbt_create=true && shift ;;
|
||||
-sbt-dir) require_arg path "$1" "$2" && sbt_dir="$2" && shift 2 ;;
|
||||
-sbt-boot) require_arg path "$1" "$2" && addJava "-Dsbt.boot.directory=$2" && shift 2 ;;
|
||||
-ivy) require_arg path "$1" "$2" && addJava "-Dsbt.ivy.home=$2" && shift 2 ;;
|
||||
-no-share) noshare=true && shift ;;
|
||||
-offline) addSbt "set offline in Global := true" && shift ;;
|
||||
-jvm-debug) require_arg port "$1" "$2" && addDebugger "$2" && shift 2 ;;
|
||||
-batch) batch=true && shift ;;
|
||||
-prompt) require_arg "expr" "$1" "$2" && setThisBuild shellPrompt "(s => { val e = Project.extract(s) ; $2 })" && shift 2 ;;
|
||||
-script) require_arg file "$1" "$2" && sbt_script="$2" && addJava "-Dsbt.main.class=sbt.ScriptMain" && shift 2 ;;
|
||||
|
||||
-sbt-version) require_arg version "$1" "$2" && sbt_explicit_version="$2" && shift 2 ;;
|
||||
-sbt-force-latest) sbt_explicit_version="$sbt_release_version" && shift ;;
|
||||
-sbt-dev) sbt_explicit_version="$sbt_unreleased_version" && shift ;;
|
||||
-sbt-jar) require_arg path "$1" "$2" && sbt_jar="$2" && shift 2 ;;
|
||||
-sbt-launch-dir) require_arg path "$1" "$2" && sbt_launch_dir="$2" && shift 2 ;;
|
||||
-sbt-launch-repo) require_arg path "$1" "$2" && sbt_launch_repo="$2" && shift 2 ;;
|
||||
|
||||
-28) setScalaVersion "$latest_28" && shift ;;
|
||||
-29) setScalaVersion "$latest_29" && shift ;;
|
||||
-210) setScalaVersion "$latest_210" && shift ;;
|
||||
-211) setScalaVersion "$latest_211" && shift ;;
|
||||
-212) setScalaVersion "$latest_212" && shift ;;
|
||||
-213) setScalaVersion "$latest_213" && shift ;;
|
||||
|
||||
-scala-version) require_arg version "$1" "$2" && setScalaVersion "$2" && shift 2 ;;
|
||||
-binary-version) require_arg version "$1" "$2" && setThisBuild scalaBinaryVersion "\"$2\"" && shift 2 ;;
|
||||
-scala-home) require_arg path "$1" "$2" && setThisBuild scalaHome "_root_.scala.Some(file(\"$2\"))" && shift 2 ;;
|
||||
-java-home) require_arg path "$1" "$2" && setJavaHome "$2" && shift 2 ;;
|
||||
-sbt-opts) require_arg path "$1" "$2" && sbt_opts_file="$2" && shift 2 ;;
|
||||
-sbtx-opts) require_arg path "$1" "$2" && sbtx_opts_file="$2" && shift 2 ;;
|
||||
-jvm-opts) require_arg path "$1" "$2" && jvm_opts_file="$2" && shift 2 ;;
|
||||
|
||||
-D*) addJava "$1" && shift ;;
|
||||
-J*) addJava "${1:2}" && shift ;;
|
||||
-S*) addScalac "${1:2}" && shift ;;
|
||||
|
||||
new) sbt_new=true && : "${sbt_explicit_version:=$sbt_release_version}" && addResidual "$1" && shift ;;
|
||||
|
||||
*) addResidual "$1" && shift ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# process the direct command line arguments
|
||||
process_args "$@"
|
||||
|
||||
# skip #-styled comments and blank lines
|
||||
readConfigFile() {
|
||||
local end=false
|
||||
until $end; do
|
||||
read -r || end=true
|
||||
[[ $REPLY =~ ^# ]] || [[ -z $REPLY ]] || echo "$REPLY"
|
||||
done <"$1"
|
||||
}
|
||||
|
||||
# if there are file/environment sbt_opts, process again so we
|
||||
# can supply args to this runner
|
||||
if [[ -r "$sbt_opts_file" ]]; then
|
||||
vlog "Using sbt options defined in file $sbt_opts_file"
|
||||
while read -r opt; do extra_sbt_opts+=("$opt"); done < <(readConfigFile "$sbt_opts_file")
|
||||
elif [[ -n "$SBT_OPTS" && ! ("$SBT_OPTS" =~ ^@.*) ]]; then
|
||||
vlog "Using sbt options defined in variable \$SBT_OPTS"
|
||||
IFS=" " read -r -a extra_sbt_opts <<<"$SBT_OPTS"
|
||||
else
|
||||
vlog "No extra sbt options have been defined"
|
||||
fi
|
||||
|
||||
# if there are file/environment sbtx_opts, process again so we
|
||||
# can supply args to this runner
|
||||
if [[ -r "$sbtx_opts_file" ]]; then
|
||||
vlog "Using sbt options defined in file $sbtx_opts_file"
|
||||
while read -r opt; do extra_sbt_opts+=("$opt"); done < <(readConfigFile "$sbtx_opts_file")
|
||||
elif [[ -n "$SBTX_OPTS" && ! ("$SBTX_OPTS" =~ ^@.*) ]]; then
|
||||
vlog "Using sbt options defined in variable \$SBTX_OPTS"
|
||||
IFS=" " read -r -a extra_sbt_opts <<<"$SBTX_OPTS"
|
||||
else
|
||||
vlog "No extra sbt options have been defined"
|
||||
fi
|
||||
|
||||
[[ -n "${extra_sbt_opts[*]}" ]] && process_args "${extra_sbt_opts[@]}"
|
||||
|
||||
# reset "$@" to the residual args
|
||||
set -- "${residual_args[@]}"
|
||||
argumentCount=$#
|
||||
|
||||
# set sbt version
|
||||
set_sbt_version
|
||||
|
||||
checkJava
|
||||
|
||||
# only exists in 0.12+
|
||||
setTraceLevel() {
|
||||
case "$sbt_version" in
|
||||
"0.7."* | "0.10."* | "0.11."*) echoerr "Cannot set trace level in sbt version $sbt_version" ;;
|
||||
*) setThisBuild traceLevel "$trace_level" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# set scalacOptions if we were given any -S opts
|
||||
[[ ${#scalac_args[@]} -eq 0 ]] || addSbt "set scalacOptions in ThisBuild += \"${scalac_args[*]}\""
|
||||
|
||||
[[ -n "$sbt_explicit_version" && -z "$sbt_new" ]] && addJava "-Dsbt.version=$sbt_explicit_version"
|
||||
vlog "Detected sbt version $sbt_version"
|
||||
|
||||
if [[ -n "$sbt_script" ]]; then
|
||||
residual_args=("$sbt_script" "${residual_args[@]}")
|
||||
else
|
||||
# no args - alert them there's stuff in here
|
||||
((argumentCount > 0)) || {
|
||||
vlog "Starting $script_name: invoke with -help for other options"
|
||||
residual_args=(shell)
|
||||
}
|
||||
fi
|
||||
|
||||
# verify this is an sbt dir, -create was given or user attempts to run a scala script
|
||||
[[ -r ./build.sbt || -d ./project || -n "$sbt_create" || -n "$sbt_script" || -n "$sbt_new" ]] || {
|
||||
cat <<EOM
|
||||
$(pwd) doesn't appear to be an sbt project.
|
||||
If you want to start sbt anyway, run:
|
||||
$0 -sbt-create
|
||||
|
||||
EOM
|
||||
exit 1
|
||||
}
|
||||
|
||||
# pick up completion if present; todo
|
||||
# shellcheck disable=SC1091
|
||||
[[ -r .sbt_completion.sh ]] && source .sbt_completion.sh
|
||||
|
||||
# directory to store sbt launchers
|
||||
[[ -d "$sbt_launch_dir" ]] || mkdir -p "$sbt_launch_dir"
|
||||
[[ -w "$sbt_launch_dir" ]] || sbt_launch_dir="$(mktemp -d -t sbt_extras_launchers.XXXXXX)"
|
||||
|
||||
# no jar? download it.
|
||||
[[ -r "$sbt_jar" ]] || acquire_sbt_jar || {
|
||||
# still no jar? uh-oh.
|
||||
echo "Could not download and verify the launcher. Obtain the jar manually and place it at $sbt_jar"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [[ -n "$noshare" ]]; then
|
||||
for opt in ${noshare_opts}; do
|
||||
addJava "$opt"
|
||||
done
|
||||
else
|
||||
case "$sbt_version" in
|
||||
"0.7."* | "0.10."* | "0.11."* | "0.12."*)
|
||||
[[ -n "$sbt_dir" ]] || {
|
||||
sbt_dir="$HOME/.sbt/$sbt_version"
|
||||
vlog "Using $sbt_dir as sbt dir, -sbt-dir to override."
|
||||
}
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ -n "$sbt_dir" ]]; then
|
||||
addJava "-Dsbt.global.base=$sbt_dir"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -r "$jvm_opts_file" ]]; then
|
||||
vlog "Using jvm options defined in file $jvm_opts_file"
|
||||
while read -r opt; do extra_jvm_opts+=("$opt"); done < <(readConfigFile "$jvm_opts_file")
|
||||
elif [[ -n "$JVM_OPTS" && ! ("$JVM_OPTS" =~ ^@.*) ]]; then
|
||||
vlog "Using jvm options defined in \$JVM_OPTS variable"
|
||||
IFS=" " read -r -a extra_jvm_opts <<<"$JVM_OPTS"
|
||||
else
|
||||
vlog "Using default jvm options"
|
||||
IFS=" " read -r -a extra_jvm_opts <<<"$( default_jvm_opts)"
|
||||
fi
|
||||
|
||||
# traceLevel is 0.12+
|
||||
[[ -n "$trace_level" ]] && setTraceLevel
|
||||
|
||||
execRunner "$java_cmd" \
|
||||
"${extra_jvm_opts[@]}" \
|
||||
"${java_args[@]}" \
|
||||
-jar "$sbt_jar" \
|
||||
"${sbt_commands[@]}" \
|
||||
"${residual_args[@]}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue