Skip to content

Commit 08e2cde

Browse files
authored
Cleanup code according to CodeQL reports (#925)
1 parent 4fbd6dd commit 08e2cde

17 files changed

Lines changed: 37 additions & 68 deletions

File tree

client/src/main/java/com/defold/extender/client/ExtenderClient.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.io.OutputStream;
3232
import java.io.UnsupportedEncodingException;
3333
import java.math.BigInteger;
34-
import java.nio.file.Files;
3534
import java.nio.file.Path;
3635
import java.security.MessageDigest;
3736
import java.security.NoSuchAlgorithmException;
@@ -79,7 +78,7 @@ public ExtenderClient(String extenderBaseUrl, File cacheDir) throws IOException
7978
public ExtenderClient(CookieStore cookieStore,
8079
String extenderBaseUrl,
8180
File cacheDir) throws IOException {
82-
this(new ExtenderClientCache(cacheDir), cookieStore,
81+
this(new ExtenderClientCache(cacheDir),
8382
HttpClientBuilder.create()
8483
.setDefaultRequestConfig(
8584
RequestConfig.custom()
@@ -92,7 +91,6 @@ public ExtenderClient(CookieStore cookieStore,
9291
}
9392

9493
public ExtenderClient(ExtenderClientCache cache,
95-
CookieStore cookieStore,
9694
HttpClient httpClient,
9795
String extenderBaseUrl) {
9896
this.extenderBaseUrl = extenderBaseUrl;
@@ -401,7 +399,7 @@ public boolean health() throws IOException {
401399
}
402400

403401
public HttpGet createGetRequest(String url) throws UnsupportedEncodingException {
404-
HttpGet request = new HttpGet(extenderBaseUrl);
402+
HttpGet request = new HttpGet(url);
405403
addAuthorizationHeader(request);
406404
addHeaders(request);
407405
return request;

client/src/test/java/com/defold/extender/client/ExtenderClientTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void testClientHeaders() throws Exception {
6464
final String HDR_VALUE_2 = "my custom header2";
6565
DefaultHttpClient httpClient = Mockito.mock(DefaultHttpClient.class);
6666

67-
ExtenderClient extenderClient = new ExtenderClient(null, null, httpClient, "http://localhost");
67+
ExtenderClient extenderClient = new ExtenderClient(null, httpClient, "http://localhost");
6868
extenderClient.setHeader(HDR_NAME_1, HDR_VALUE_1);
6969
extenderClient.setHeader(HDR_NAME_2, HDR_VALUE_2);
7070

server/manifestmergetool/src/main/java/com/defold/manifestmergetool/HtmlMerger.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ public HtmlMerger(Logger logger) {
2020
HtmlMerger.logger = logger;
2121
}
2222

23-
class HtmlMergeException extends RuntimeException {
24-
};
25-
2623
private MergePolicy getMergePolicy(Element e) {
2724
String attr = e.attr("merge");
2825
return MergePolicy.fromString(attr);
@@ -108,17 +105,9 @@ private Document loadDocument(File file) throws IOException {
108105
public void merge(File main, File[] libraries, File out) throws RuntimeException, IOException {
109106
Document baseDocument = loadDocument(main);
110107

111-
// For error reporting/troubleshooting
112-
String paths = "\n" + main.getAbsolutePath();
113-
114108
for (File library : libraries) {
115-
paths += "\n" + library.getAbsolutePath();
116109
Document libraryDocument = loadDocument(library);
117-
try {
118-
mergeDocuments(baseDocument, libraryDocument);
119-
} catch (HtmlMergeException e) {
120-
throw new RuntimeException(String.format("Errors merging html files: %s + %s:\n%s", paths, library.getAbsolutePath(), e.toString()));
121-
}
110+
mergeDocuments(baseDocument, libraryDocument);
122111
}
123112

124113
writeDocument(baseDocument, out);

server/src/main/java/com/defold/extender/Extender.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class Extender {
113113
// * libraryJars - Array of .jar files should be passed to ProGuard as '-libraryjar' entries.
114114
// Everything from a libraryjar will be kept by ProGuard, i.e no optimization or
115115
// obfuscation will be performed.
116-
private class ProGuardContext {
116+
private static class ProGuardContext {
117117
public List<String> proGuardFiles = new ArrayList<>();
118118
public List<String> libraryJars = new ArrayList<>();
119119
}
@@ -1377,8 +1377,6 @@ private List<File> buildPipelineExtension(File manifest, Map<String, Object> man
13771377
// ***************************************************************************
13781378
// Python
13791379
{
1380-
List<File> srcFiles = ExtenderUtil.listFiles(srcDirs, platformConfig.sourceRe);
1381-
13821380
if (!protoFiles.isEmpty()) {
13831381
List<File> generatedFiles = generateProtoSrcForPlugin(extDir, manifestContext, protoFiles, "python");
13841382
outputFiles.addAll(generatedFiles);
@@ -2204,7 +2202,7 @@ private File buildWin32Resources(Map<String, Object> mergedAppContext) throws Ex
22042202
context.put("tgt", ExtenderUtil.getRelativePath(buildState.jobDir, resourceFile));
22052203

22062204
String command = templateExecutor.execute(platformConfig.windresCmd, context);
2207-
if (command.equals("")) {
2205+
if (command.isEmpty()) {
22082206
return null;
22092207
}
22102208
try {
@@ -2343,7 +2341,7 @@ private boolean shouldBuildArtifact(String artifact) {
23432341
}
23442342

23452343
private boolean shouldBuildEngine() {
2346-
return buildState.getBuildArtifacts().equals("") || shouldBuildArtifact("engine");
2344+
return buildState.getBuildArtifacts().isEmpty() || shouldBuildArtifact("engine");
23472345
}
23482346
private boolean shouldBuildPlugins() {
23492347
return shouldBuildArtifact("plugins");
@@ -2711,7 +2709,7 @@ private List<File> buildApple(String platform) throws ExtenderException {
27112709
}
27122710

27132711
private String getBasePlatform(String platform) {
2714-
String[] platformParts = buildState.fullPlatform.split("-");
2712+
String[] platformParts = platform.split("-");
27152713
return platformParts[1];
27162714
}
27172715

server/src/main/java/com/defold/extender/ExtenderController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public void buildEngineAsync(HttpServletRequest _request,
235235
if (remoteBuilderEnabled && buildEnvDescription != null && isRemotePlatform(buildEnvDescription[0], buildEnvDescription[1])) {
236236
LOGGER.info("Building engine on remote builder");
237237
RemoteInstanceConfig remoteInstanceConfig = getRemoteBuilderConfig(buildEnvDescription[0], buildEnvDescription[1]);
238-
this.remoteEngineBuilder.buildAsync(remoteInstanceConfig, uploadDirectory, platform, sdkVersion, jobDirectory, buildDirectory, metricsWriter);
238+
this.remoteEngineBuilder.buildAsync(remoteInstanceConfig, uploadDirectory, platform, sdkVersion, jobDirectory, metricsWriter);
239239
} else if (instanceType.equals(InstanceType.MIXED)) {
240240
asyncBuilder.asyncBuildEngine(metricsWriter, platform, sdkVersion, jobDirectory, uploadDirectory, buildDirectory);
241241
} else {

server/src/main/java/com/defold/extender/ExtenderUtil.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
public class ExtenderUtil
4040
{
4141
static String convertStringToLiteral(String expression) {
42-
String expressionOriginal = expression;
4342
int begin = expression.indexOf("{{");
4443
if (begin >= 0)
4544
{

server/src/main/java/com/defold/extender/cache/DataCacheException.java

Lines changed: 0 additions & 11 deletions
This file was deleted.

server/src/main/java/com/defold/extender/remote/RemoteEngineBuilder.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.apache.http.client.methods.HttpPost;
2626
import org.apache.http.entity.ContentType;
2727
import org.apache.http.entity.mime.MultipartEntityBuilder;
28-
import org.apache.http.entity.mime.content.ByteArrayBody;
2928
import org.apache.http.entity.mime.content.FileBody;
3029
import org.apache.http.impl.client.HttpClientBuilder;
3130
import org.apache.http.util.EntityUtils;
@@ -38,7 +37,6 @@
3837

3938
import java.io.OutputStream;
4039
import java.io.PrintWriter;
41-
import java.io.ByteArrayOutputStream;
4240
import java.io.File;
4341
import java.io.FileNotFoundException;
4442
import java.io.FileOutputStream;
@@ -86,7 +84,7 @@ public void buildAsync(final RemoteInstanceConfig remoteInstanceConfig,
8684
final File projectDirectory,
8785
final String platform,
8886
final String sdkVersion,
89-
File jobDirectory, File buildDirectory, MetricsWriter metricsWriter) throws FileNotFoundException, IOException {
87+
File jobDirectory, MetricsWriter metricsWriter) throws FileNotFoundException, IOException {
9088

9189
LOGGER.info("Building engine remotely at {}", remoteInstanceConfig.getUrl());
9290
String jobName = jobDirectory.getName();

server/src/main/java/com/defold/extender/services/DataCacheService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class DataCacheService {
4242

4343
private DataCache dataCache;
4444

45-
public class DataCacheServiceInfo {
45+
public static class DataCacheServiceInfo {
4646
public AtomicInteger cachedFileCount = new AtomicInteger();
4747
public AtomicLong cachedFileSize = new AtomicLong();
4848
}

server/src/main/java/com/defold/extender/services/DefoldSdkService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ public void destroy() {
326326
}
327327
}
328328

329-
private JSONObject getLocalPlatformSdkMappings(String hash) throws IOException, ParseException {
329+
private JSONObject getLocalPlatformSdkMappings() throws IOException, ParseException {
330330
JSONParser parser = new JSONParser();
331331
return (JSONObject)parser.parse(new FileReader(Path.of(getLocalSdk().toFile().getAbsolutePath(), "platform.sdks.json").toFile()));
332332
}
@@ -391,7 +391,7 @@ private JSONObject getRemotePlatformSdkMappings(String hash) throws IOException,
391391
}
392392

393393
public JSONObject getPlatformSdkMappings(String hash) throws IOException, ExtenderException, ParseException {
394-
return isLocalSdk(hash) ? getLocalPlatformSdkMappings(hash) : getRemotePlatformSdkMappings(hash);
394+
return isLocalSdk(hash) ? getLocalPlatformSdkMappings() : getRemotePlatformSdkMappings(hash);
395395
}
396396

397397
public void acquireSdk(String hash) {

0 commit comments

Comments
 (0)