Skip to content

Commit

Permalink
Fix: @Value does not work in Docker environment
Browse files Browse the repository at this point in the history
Constructor autowiring seems like the safest bet at this point
  • Loading branch information
dabico committed Jan 8, 2024
1 parent ed8795e commit 522154e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
11 changes: 7 additions & 4 deletions src/main/java/ch/usi/si/seart/cloc/CLOCConnector.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package ch.usi.si.seart.cloc;

import ch.usi.si.seart.config.properties.CLOCProperties;
import ch.usi.si.seart.exception.StaticCodeAnalysisException;
import ch.usi.si.seart.exception.TerminalExecutionException;
import ch.usi.si.seart.io.ExternalProcess;
import ch.usi.si.seart.stereotype.Connector;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.experimental.FieldDefaults;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.convert.ConversionService;

import java.nio.file.Path;
Expand All @@ -21,15 +20,19 @@
* Component responsible for performing static code analysis through CLOC.
*/
@Connector(command = "cloc")
@AllArgsConstructor(onConstructor_ = @Autowired)
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
public class CLOCConnector {

@Value("${ghs.cloc.analysis-timeout-duration}")
Duration analysisTimeout;

ConversionService conversionService;

@Autowired
public CLOCConnector(CLOCProperties properties, ConversionService conversionService) {
this.analysisTimeout = properties.getAnalysisTimeoutDuration();
this.conversionService = conversionService;
}

/**
* Performs static code analysis using CLOC.
*
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/ch/usi/si/seart/git/GitConnector.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package ch.usi.si.seart.git;

import ch.usi.si.seart.config.properties.GitProperties;
import ch.usi.si.seart.exception.TerminalExecutionException;
import ch.usi.si.seart.exception.git.GitException;
import ch.usi.si.seart.exception.git.RemoteReferenceDisplayException;
import ch.usi.si.seart.io.ExternalProcess;
import ch.usi.si.seart.stereotype.Connector;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.experimental.FieldDefaults;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.SystemUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.convert.ConversionService;

import java.io.IOException;
Expand All @@ -27,18 +26,22 @@
*/
@Slf4j
@Connector(command = "git")
@AllArgsConstructor(onConstructor_ = @Autowired)
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
public class GitConnector implements InitializingBean {

@Value("${ghs.git.folder-prefix}")
String folderPrefix;

@Value("${ghs.git.clone-timeout-duration}")
Duration cloneTimeout;

ConversionService conversionService;

@Autowired
public GitConnector(GitProperties properties, ConversionService conversionService) {
this.folderPrefix = properties.getFolderPrefix();
this.cloneTimeout = properties.getCloneTimeoutDuration();
this.conversionService = conversionService;
}

/**
* Clones a git repository into a temporary folder
* and returns a handle for the cloned repository.
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/ch/usi/si/seart/http/ClientURLConnector.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package ch.usi.si.seart.http;

import ch.usi.si.seart.config.properties.ClientURLProperties;
import ch.usi.si.seart.exception.ClientURLException;
import ch.usi.si.seart.exception.TerminalExecutionException;
import ch.usi.si.seart.io.ExternalProcess;
import ch.usi.si.seart.stereotype.Connector;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.experimental.FieldDefaults;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import java.net.ConnectException;
import java.net.URL;
Expand All @@ -19,13 +18,16 @@

@Slf4j
@Connector(command = "curl")
@AllArgsConstructor(onConstructor_ = @Autowired)
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
public class ClientURLConnector {

@Value("${ghs.curl.connect-timeout-duration}")
Duration connectTimeout;

@Autowired
public ClientURLConnector(ClientURLProperties properties) {
this.connectTimeout = properties.getConnectTimeoutDuration();
}

public boolean ping(URL url) throws ClientURLException {
try {
String[] command = {
Expand Down

0 comments on commit 522154e

Please sign in to comment.