Skip to content

Commit

Permalink
Get rid of lombok val.
Browse files Browse the repository at this point in the history
  • Loading branch information
vogti committed Oct 30, 2023
1 parent 662cc63 commit 9c06290
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 86 deletions.
2 changes: 2 additions & 0 deletions lombok.config
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# This file is generated by the 'io.freefair.lombok' Gradle plugin
config.stopBubbling = true
lombok.val.flagUsage = error
lombok.var.flagUsage = error
25 changes: 13 additions & 12 deletions src/main/java/org/polypheny/control/control/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigRenderOptions;
import com.typesafe.config.ConfigValue;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.List;
import java.util.Map.Entry;
import java.util.Properties;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.commons.lang3.StringUtils;


Expand All @@ -50,9 +51,9 @@ public static Config getConfig() {

private static void loadConfigFile() {
if ( applicationConfFile == null ) {
val defaultConfig = ConfigFactory.load();
val workingDir = defaultConfig.getString( "pcrtl.workingdir" );
val configDir = new File( new File( workingDir ), "config" );
Config defaultConfig = ConfigFactory.load();
String workingDir = defaultConfig.getString( "pcrtl.workingdir" );
File configDir = new File( new File( workingDir ), "config" );
createConfigFolders( workingDir, configDir );
applicationConfFile = new File( configDir, "application.conf" );
}
Expand Down Expand Up @@ -82,9 +83,9 @@ public static void writeConfiguration( final Config configuration ) {
configRenderOptions = configRenderOptions.setJson( false );
configRenderOptions = configRenderOptions.setOriginComments( false );

val defaultConfig = ConfigFactory.load();
val workingDir = defaultConfig.getString( "pcrtl.workingdir" );
val configDir = new File( new File( workingDir ), "config" );
Config defaultConfig = ConfigFactory.load();
String workingDir = defaultConfig.getString( "pcrtl.workingdir" );
File configDir = new File( new File( workingDir ), "config" );
createConfigFolders( workingDir, configDir );
try (
FileOutputStream fos = new FileOutputStream( applicationConfFile, false );
Expand All @@ -104,7 +105,7 @@ public static void setApplicationConfFile( File applicationConfFile ) {


public static String getCurrentConfigAsJson() {
val config = getConfig();
Config config = getConfig();
ConfigRenderOptions configRenderOptions = ConfigRenderOptions.defaults();
configRenderOptions = configRenderOptions.setComments( false );
configRenderOptions = configRenderOptions.setFormatted( true );
Expand All @@ -115,10 +116,10 @@ public static String getCurrentConfigAsJson() {


public static Properties convertToProperties( Config config ) {
val properties = new Properties();
for ( val entry : config.entrySet() ) {
val key = entry.getKey();
val value = entry.getValue();
Properties properties = new Properties();
for ( Entry<String, ConfigValue> entry : config.entrySet() ) {
String key = entry.getKey();
ConfigValue value = entry.getValue();

final String stringValue;
switch ( value.valueType() ) {
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/org/polypheny/control/control/Control.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import lombok.NonNull;
import lombok.val;
import org.polypheny.control.httpinterface.ClientCommunicationStream;


Expand All @@ -54,7 +53,7 @@ public synchronized void setConfig( Context ctx ) {
}
getClientCommunicationStream( ctx, "currentConfig" );

val json = ctx.formParam( "config" );
String json = ctx.formParam( "config" );

JsonObject object = JsonParser.parseString( json ).getAsJsonObject();

Expand Down Expand Up @@ -166,8 +165,8 @@ public void getControlVersion( Context ctx ) {


public void getAvailablePdbBranches( Context ctx ) {
val configuration = ConfigManager.getConfig();
val pdbbuilddir = new File( configuration.getString( "pcrtl.pdbbuilddir" ) );
Config configuration = ConfigManager.getConfig();
File pdbbuilddir = new File( configuration.getString( "pcrtl.pdbbuilddir" ) );
if ( !pdbbuilddir.exists() ) {
ServiceManager.clonePdbRepository( null, configuration );
}
Expand All @@ -177,8 +176,8 @@ public void getAvailablePdbBranches( Context ctx ) {


public void getAvailablePuiBranches( Context ctx ) {
val configuration = ConfigManager.getConfig();
val puiBuildDir = new File( configuration.getString( "pcrtl.puibuilddir" ) );
Config configuration = ConfigManager.getConfig();
File puiBuildDir = new File( configuration.getString( "pcrtl.puibuilddir" ) );
if ( !puiBuildDir.exists() ) {
ServiceManager.clonePuiRepository( null, configuration );
}
Expand All @@ -190,7 +189,7 @@ public void getAvailablePuiBranches( Context ctx ) {
private ClientCommunicationStream getClientCommunicationStream( @NonNull final Context context, @NonNull final String topic ) {
String str = context.formParam( "clientId" );
if ( str != null ) {
val cid = Integer.parseInt( str );
int cid = Integer.parseInt( str );
return new ClientCommunicationStream( cid, topic );
}
throw new NoSuchElementException( "The request does not contain a client identifier (clientId)" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.commons.lang3.SystemUtils;
import org.jvnet.winp.WinProcess;
import org.jvnet.winp.WinpException;
Expand Down Expand Up @@ -148,7 +148,7 @@ public boolean isAlive() {
public void kill() {
// "PID Mode"
try {
val kill = Runtime.getRuntime().exec( "TASKKILL /PID " + getPid() ); // SIGTERM -- CTRL + C
Process kill = Runtime.getRuntime().exec( "TASKKILL /PID " + getPid() ); // SIGTERM -- CTRL + C
if ( kill.waitFor( 1, TimeUnit.MINUTES ) ) {
if ( isAlive() ) {
killForcibly();
Expand Down Expand Up @@ -194,7 +194,7 @@ protected UnixPolyphenyDbProcess( final Process process ) {
long pid = -1;

try {
val pidField = process.getClass().getDeclaredField( "pid" );
Field pidField = process.getClass().getDeclaredField( "pid" );

AccessController.doPrivileged( (PrivilegedAction<Void>) () -> {
pidField.setAccessible( true );
Expand Down Expand Up @@ -228,8 +228,8 @@ public boolean isAlive() {
if ( super.process == null ) {
// "PID Mode"
try {
val process = Runtime.getRuntime().exec( "ps -p " + pid );
try ( val input = new BufferedReader( new InputStreamReader( process.getInputStream() ) ) ) {
Process process = Runtime.getRuntime().exec( "ps -p " + pid );
try ( BufferedReader input = new BufferedReader( new InputStreamReader( process.getInputStream() ) ) ) {
String line;
while ( (line = input.readLine()) != null ) {
if ( line.contains( " " + pid + " " ) ) {
Expand All @@ -252,7 +252,7 @@ public boolean isAlive() {
public void kill() {
// "PID Mode"
try {
val kill = Runtime.getRuntime().exec( "kill -15 " + pid ); // SIGTERM -- CTRL + C
Process kill = Runtime.getRuntime().exec( "kill -15 " + pid ); // SIGTERM -- CTRL + C
if ( kill.waitFor( 1, TimeUnit.MINUTES ) ) {
// terminated within the time
if ( kill.exitValue() == 0 ) {
Expand All @@ -273,7 +273,7 @@ public void killForcibly() {
if ( super.process == null ) {
// "PID Mode"
try {
val kill = Runtime.getRuntime().exec( "kill -9 " + pid ); // SIGKILL
Process kill = Runtime.getRuntime().exec( "kill -9 " + pid ); // SIGKILL
if ( kill.waitFor( 1, TimeUnit.SECONDS ) ) {
// terminated within the time
if ( kill.exitValue() == 0 ) {
Expand Down
Loading

0 comments on commit 9c06290

Please sign in to comment.