Skip to content

Commit 9384cd1

Browse files
authored
removed dependency on guava (#803)
replaced any methods used with apache-commons
1 parent 55637e1 commit 9384cd1

File tree

7 files changed

+20
-28
lines changed

7 files changed

+20
-28
lines changed

Diff for: ApplicationInsightsInternalLogger/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ dependencies {
77
testCompile group: 'org.mockito', name: 'mockito-core', version: '1.10.19'
88
testCompile group:'org.hamcrest', name:'hamcrest-library', version:'1.3'
99
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'
10-
compile group: 'com.google.guava', name: 'guava', version: '20.0'
1110
compile group: 'commons-io', name: 'commons-io', version: '2.6'
1211
}
1312

Diff for: ApplicationInsightsInternalLogger/src/main/java/com/microsoft/applicationinsights/internal/logger/FileLoggerOutput.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121

2222
package com.microsoft.applicationinsights.internal.logger;
2323

24-
import com.google.common.base.Strings;
25-
import com.google.common.collect.Lists;
2624
import java.nio.file.Files;
2725
import java.nio.file.Path;
2826
import java.nio.file.Paths;
2927
import org.apache.commons.io.FileUtils;
3028
import org.apache.commons.io.FilenameUtils;
29+
import org.apache.commons.lang3.StringUtils;
3130

3231
import java.io.File;
3332
import java.io.IOException;
@@ -88,7 +87,7 @@ private FileAndDate(File file, Date date) {
8887

8988
public FileLoggerOutput(Map<String, String> loggerData) {
9089
uniquePrefix = loggerData.get(UNIQUE_LOG_FILE_PREFIX_ATTRIBUTE);
91-
if (Strings.isNullOrEmpty(uniquePrefix)) {
90+
if (StringUtils.isEmpty(uniquePrefix)) {
9291
throw new IllegalArgumentException(String.format("Unique log file prefix is not defined"));
9392
}
9493

@@ -107,7 +106,7 @@ public FileLoggerOutput(Map<String, String> loggerData) {
107106
private int getRequest(Map<String, String> loggerData, String requestName, int defaultValue) {
108107
int requestValue = defaultValue;
109108
String requestValueAsString = loggerData.get(requestName);
110-
if (!Strings.isNullOrEmpty(requestValueAsString)) {
109+
if (StringUtils.isNotEmpty(requestValueAsString)) {
111110
try {
112111
requestValue = Integer.valueOf(loggerData.get(requestName));
113112
} catch (Exception e) {
@@ -122,7 +121,7 @@ private void initialize(String baseFolderPath, int numberOfFiles, int numberOfTo
122121
currentLogFileIndex = 0;
123122
Path logFilePath;
124123

125-
if (Strings.isNullOrEmpty(baseFolderPath)) {
124+
if (StringUtils.isEmpty(baseFolderPath)) {
126125
baseFolderPath = SDK_LOGS_BASE_FOLDER_PATH;
127126

128127
// If no path is specified by user create log file directory in temp with default folder
@@ -284,7 +283,7 @@ private List<FileAndDate> getExistingLogsFromNewToOld() {
284283
Collection<File> oldLogs = FileUtils.listFiles(baseFolder, new String[]{LOG_FILE_SUFFIX_FOR_LISTING}, false);
285284
List<File> asList;
286285
if (!(oldLogs instanceof List)) {
287-
asList = Lists.newArrayList(oldLogs);
286+
asList = new ArrayList<>(oldLogs);
288287
} else {
289288
asList = (List<File>)oldLogs;
290289
}

Diff for: ApplicationInsightsInternalLogger/src/main/java/com/microsoft/applicationinsights/internal/logger/InternalLogger.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
package com.microsoft.applicationinsights.internal.logger;
2323

24-
import com.google.common.base.Strings;
24+
import org.apache.commons.lang3.StringUtils;
2525

2626
import java.text.SimpleDateFormat;
2727
import java.util.Date;
@@ -88,7 +88,7 @@ public synchronized void initialize(String loggerOutputType, Map<String, String>
8888
if (!initialized) {
8989
try {
9090
String loggerLevel = loggerData.get(LOGGER_LEVEL);
91-
if (Strings.isNullOrEmpty(loggerLevel)) {
91+
if (StringUtils.isEmpty(loggerLevel)) {
9292
// The user didn't specify the logging level, therefore by default we set that to 'TRACE'
9393
loggingLevel = LoggingLevel.TRACE;
9494
setLoggerOutput(loggerOutputType, loggerData);
@@ -251,7 +251,7 @@ private void setLoggerOutput(String loggerOutputType, Map<String, String> logger
251251
}
252252

253253
LoggerOutputType type = LoggerOutputType.CONSOLE;
254-
if (!Strings.isNullOrEmpty(loggerOutputType)) {
254+
if (StringUtils.isNotEmpty(loggerOutputType)) {
255255
try {
256256
// If the user asked for a logger type
257257
type = LoggerOutputType.valueOf(loggerOutputType.toUpperCase());

Diff for: agent/src/main/java/com/microsoft/applicationinsights/agent/internal/config/XmlAgentConfigurationBuilder.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
package com.microsoft.applicationinsights.agent.internal.config;
2323

24-
import com.google.common.annotations.VisibleForTesting;
2524
import com.microsoft.applicationinsights.agent.internal.agent.ClassInstrumentationData;
2625
import com.microsoft.applicationinsights.agent.internal.common.StringUtils;
2726
import com.microsoft.applicationinsights.agent.internal.coresync.InstrumentedClassType;
@@ -60,13 +59,14 @@ final class XmlAgentConfigurationBuilder implements AgentConfigurationBuilder {
6059
private final static String JMX_TAG = "AgentJmx";
6160
private final static String MAX_STATEMENT_QUERY_LIMIT_TAG = "MaxStatementQueryLimitInMS";
6261

63-
@VisibleForTesting final static String AGENT_LOGGER_TAG = "AgentLogger";
64-
@VisibleForTesting final static String SDK_LOGGER_TYPE_TAG = "type";
65-
@VisibleForTesting final static String SDK_LOG_LEVEL_TAG = "Level";
66-
@VisibleForTesting final static String SDK_LOGGER_UNIQUE_PREFIX_TAG = "UniquePrefix";
67-
@VisibleForTesting final static String SDK_LOGGER_BASE_FOLDER_PATH_TAG = "BaseFolderPath";
68-
@VisibleForTesting final static String SDK_LOGGER_MAX_NUMBER_OF_LOG_FILES = "NumberOfFiles";
69-
@VisibleForTesting final static String SDK_LOGGER_NUMBER_OF_TOTAL_SIZE_IN_MB = "NumberOfTotalSizeInMB";
62+
// visible for testing
63+
final static String AGENT_LOGGER_TAG = "AgentLogger";
64+
final static String SDK_LOGGER_TYPE_TAG = "type";
65+
final static String SDK_LOG_LEVEL_TAG = "Level";
66+
final static String SDK_LOGGER_UNIQUE_PREFIX_TAG = "UniquePrefix";
67+
final static String SDK_LOGGER_BASE_FOLDER_PATH_TAG = "BaseFolderPath";
68+
final static String SDK_LOGGER_MAX_NUMBER_OF_LOG_FILES = "NumberOfFiles";
69+
final static String SDK_LOGGER_NUMBER_OF_TOTAL_SIZE_IN_MB = "NumberOfTotalSizeInMB";
7070

7171
private final static long JEDIS_ARGS_THRESHOLD_IN_MS = 10000L;
7272
private final static String W3C_ENABLED = "W3C";

Diff for: core/build.gradle

+1-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ dependencies {
121121
compile ([group: 'commons-io', name: 'commons-io', version: '2.6' ])
122122
compile ([group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'])
123123
compile ([group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.3'])
124-
compile ([group: 'com.google.guava', name: 'guava', version: '20.0'])
125124
compile ([group: 'com.google.code.gson', name: 'gson', version: '2.8.2'])
126125
compile ([group: 'com.google.protobuf', name:'protobuf-java', version:'3.6.1'])
127126
compile ([group: 'io.grpc', name: 'grpc-stub', version: '1.16.1'])
@@ -174,7 +173,7 @@ whenPomConfigured = { p ->
174173
p.dependencies = p.dependencies.findAll { dep ->
175174
dep.scope == "test" || dep.artifactId != agentArtifactId && dep.artifactId != loggerArtifactId &&
176175
!(dep.groupId in ['org.apache.http', 'eu.infomas', 'org.apache.commons', 'commons-io',
177-
'com.google.guava', 'com.google.code.gson', 'org.apache.httpcomponents',
176+
'com.google.code.gson', 'org.apache.httpcomponents',
178177
'io.grpc', 'com.google.protobuf'])
179178
}
180179
}

Diff for: web/src/main/java/com/microsoft/applicationinsights/web/internal/correlation/TraceContextCorrelation.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.microsoft.applicationinsights.web.internal.correlation;
22

3-
import com.google.common.base.Joiner;
43
import com.microsoft.applicationinsights.TelemetryConfiguration;
54
import com.microsoft.applicationinsights.internal.logger.InternalLogger;
65
import com.microsoft.applicationinsights.telemetry.RequestTelemetry;
@@ -13,6 +12,8 @@
1312
import java.util.List;
1413
import javax.servlet.http.HttpServletRequest;
1514
import javax.servlet.http.HttpServletResponse;
15+
16+
import org.apache.commons.lang3.StringUtils;
1617
import org.apache.commons.lang3.exception.ExceptionUtils;
1718

1819
/**
@@ -206,7 +207,7 @@ private static Tracestate getTracestate(HttpServletRequest request, Traceparent
206207
List<String> tracestateList = getEnumerationAsCollection(tracestates);
207208
try {
208209
//create tracestate from incoming header
209-
tracestate = Tracestate.fromString(Joiner.on(",").join(tracestateList));
210+
tracestate = Tracestate.fromString(StringUtils.join(tracestateList, ","));
210211
// add appId to it if it's resolved
211212
if (appId != null && !appId.isEmpty()) {
212213
tracestate = new Tracestate(tracestate, AZURE_TRACEPARENT_COMPONENT_INITIAL,

Diff for: web/src/main/java/com/microsoft/applicationinsights/web/internal/correlation/tracecontext/Traceparent.java

-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.util.concurrent.ThreadLocalRandom;
44

5-
import com.google.common.annotations.VisibleForTesting;
65
import org.apache.http.annotation.Experimental;
76

87
/**
@@ -18,25 +17,21 @@ public class Traceparent {
1817
/**
1918
* Version number between range [0,255] inclusive
2019
*/
21-
@VisibleForTesting
2220
final int version;
2321

2422
/**
2523
* 16 byte trace-id that is used to uniquely identify a distributed trace
2624
*/
27-
@VisibleForTesting
2825
final String traceId;
2926

3027
/**
3128
* It is a 8 byte ID that represents the caller span
3229
*/
33-
@VisibleForTesting
3430
final String spanId;
3531

3632
/**
3733
* An 8-bit field that controls tracing flags such as sampling, trace level etc.
3834
*/
39-
@VisibleForTesting
4035
final int traceFlags;
4136

4237
private Traceparent(int version, String traceId, String spanId, int traceFlags, boolean check) {
@@ -119,7 +114,6 @@ public String toString() {
119114
*
120115
* @return n byte hexadecimal string
121116
*/
122-
@VisibleForTesting
123117
static String randomHex(int n) {
124118
byte[] bytes = new byte[n];
125119
ThreadLocalRandom.current().nextBytes(bytes);

0 commit comments

Comments
 (0)