Skip to content

Commit 8898a16

Browse files
authored
Merge pull request #7 from CSC207-2022F-UofT/feat-checkstyle
[+] Add checkstyle
2 parents 8131de4 + e10fd48 commit 8898a16

File tree

14 files changed

+407
-27
lines changed

14 files changed

+407
-27
lines changed

.github/checkstyle.xml

Lines changed: 335 additions & 0 deletions
Large diffs are not rendered by default.

.github/workflows/gradle-check.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Gradle Checkstyle CI
2+
3+
on: [push]
4+
5+
permissions:
6+
checks: write
7+
actions: read
8+
contents: read
9+
10+
jobs:
11+
build:
12+
name: Gradle Test
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
- name: Set up Java JDK
18+
uses: actions/setup-java@v3
19+
with:
20+
java-version: '19'
21+
distribution: 'adopt'
22+
23+
- name: Gradle Wrapper Validation
24+
uses: gradle/wrapper-validation-action@v1
25+
26+
- name: Setup Gradle with Dependency Cache
27+
uses: gradle/[email protected]
28+
29+
- name: Gradle Checkstyle
30+
run: ./gradlew check

backups/kotlin/CreateTeam.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@ import java.util.*
99
import kotlin.text.Charsets.UTF_8
1010
import io.ktor.client.*
1111
import io.ktor.client.engine.cio.*
12+
import io.ktor.client.plugins.*
1213
import io.ktor.client.request.*
1314

1415

1516
val GSON = Gson()
1617
val HTTP = OkHttpClient()
17-
val KTOR = HttpClient(CIO)
18+
val KTOR = HttpClient(CIO) {
19+
install(HttpTimeout) {
20+
requestTimeoutMillis = 5000
21+
}
22+
install(HttpRequestRetry) {
23+
retryOnServerErrors(maxRetries = 5)
24+
}
25+
}
1826

1927
/**
2028
* fromJson patch for Kotlin

build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
id 'java'
33
id 'maven-publish'
4+
id 'checkstyle'
45
}
56

67
group 'org.hydev.csc207'
@@ -16,6 +17,15 @@ java {
1617
}
1718
}
1819

20+
checkstyle {
21+
// assign the latest checkstyle version explicitly, since the default version is very old
22+
toolVersion = '10.3.4'
23+
configFile = rootProject.file('.github/checkstyle.xml')
24+
25+
ignoreFailures = false
26+
maxWarnings = 5
27+
}
28+
1929

2030
dependencies {
2131
// Apache HTTP Client

src/main/java/org/hydev/mcpm/client/Downloader.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.hydev.mcpm.client;
22

33
import java.io.File;
4-
import java.util.List;
54
import java.util.Map;
65

76
/**

src/main/java/org/hydev/mcpm/client/database/DatabaseLoader.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import org.hydev.mcpm.client.models.Plugin;
44

5-
import javax.xml.crypto.Data;
6-
import java.io.File;
75
import java.util.HashMap;
86
import java.util.List;
97
import java.util.Map;

src/main/java/org/hydev/mcpm/client/database/LocalPluginTracker.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.hydev.mcpm.client.database;
22

3-
import org.hydev.mcpm.client.models.Plugin;
43
import org.hydev.mcpm.client.models.PluginVersion;
54

65
import java.io.File;

src/main/java/org/hydev/mcpm/client/models/PluginYml.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import org.yaml.snakeyaml.constructor.Constructor;
77
import org.yaml.snakeyaml.representer.Representer;
88

9-
import java.util.*;
9+
import java.util.ArrayList;
10+
import java.util.Map;
11+
import java.util.Objects;
1012

1113
/**
1214
* POJO model for plugin.yml inside each Minecraft Bukkit/Spigot plugin.
@@ -247,7 +249,8 @@ public boolean equals(Object o)
247249
@Override
248250
public int hashCode()
249251
{
250-
return Objects.hash(main, name, version, description, apiVersion, load, author, authors, website, depend, prefix, softdepend, loadbefore, libraries, commands, permissions);
252+
return Objects.hash(main, name, version, description, apiVersion, load, author, authors,
253+
website, depend, prefix, softdepend, loadbefore, libraries, commands, permissions);
251254
}
252255

253256
@Override

src/main/java/org/hydev/mcpm/server/crawlers/SpigetCrawler.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.stream.StreamSupport;
2222

2323
import static java.lang.String.format;
24+
import static java.nio.file.Files.createSymbolicLink;
2425
import static org.hydev.mcpm.Constants.JACKSON;
2526
import static org.hydev.mcpm.utils.GeneralUtils.makeUrl;
2627

@@ -33,7 +34,8 @@
3334
public class SpigetCrawler
3435
{
3536
private final String spiget = "https://api.spiget.org/v2";
36-
private final String userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36";
37+
private final String userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) " +
38+
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36";
3739
private final long mtDelay = 1000;
3840
private final File dataDir;
3941
private final StoredHashMap<Long, String> blacklist;
@@ -56,15 +58,17 @@ private List<JsonNode> crawlResourcesPage(long i)
5658
{
5759
// Send request
5860
var resp = Request.get(makeUrl(spiget + "/resources", "size", 500, "sort", "+id", "page", i,
59-
"fields", "id,name,tag,external,likes,testedVersions,links,contributors,premium,price,currency,version,releaseDate,updateDate,downloads,existenceStatus"))
61+
"fields", "id,name,tag,external,likes,testedVersions,links,contributors,premium," +
62+
"price,currency,version,releaseDate,updateDate,downloads,existenceStatus"))
6063
.addHeader("User-Agent", userAgent).execute().returnContent().asString();
6164

6265
// Parse JSON
6366
ArrayNode page = (ArrayNode) JACKSON.readTree(resp);
6467

6568
// Print debug info
6669
if (!page.isEmpty())
67-
System.out.printf("Page %s done, page len: %s, last id: %s\n", i, page.size(), page.get(page.size() - 1).get("id").asLong());
70+
System.out.printf("Page %s done, page len: %s, last id: %s\n",
71+
i, page.size(), page.get(page.size() - 1).get("id").asLong());
6872
else
6973
System.out.printf("Page %s is empty\n", i);
7074

@@ -268,7 +272,7 @@ public void links()
268272

269273
// Create new link
270274
linkPath.getParentFile().mkdirs();
271-
Files.createSymbolicLink(linkPath.toPath(), linkPath.getParentFile().toPath().relativize(ver.toPath()));
275+
createSymbolicLink(linkPath.toPath(), linkPath.getParentFile().toPath().relativize(ver.toPath()));
272276
}
273277
catch (IOException e)
274278
{
@@ -280,6 +284,11 @@ public void links()
280284
});
281285
}
282286

287+
/**
288+
* Execute server crawler
289+
*
290+
* @param args Arguments (Unused)
291+
*/
283292
public static void main(String[] args)
284293
{
285294
var crawler = new SpigetCrawler(new File(".mcpm"));

src/main/java/org/hydev/mcpm/utils/PluginJarFile.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@
22

33
import org.hydev.mcpm.client.models.PluginYml;
44
import org.jetbrains.annotations.NotNull;
5-
import org.yaml.snakeyaml.Yaml;
6-
import org.yaml.snakeyaml.constructor.Constructor;
75

86
import java.io.File;
97
import java.io.IOException;
108
import java.nio.charset.Charset;
119
import java.nio.charset.StandardCharsets;
12-
import java.util.Map;
1310
import java.util.zip.ZipFile;
1411

1512
/**
16-
* Static utility functions for reading Java archives (jar)
13+
* Static utility functions for reading Java archives (jar).
1714
*
1815
* @author Azalea (https://github.com/hykilpikonna)
1916
* @since 2022-10-02
@@ -31,7 +28,7 @@ public PluginJarFile(@NotNull File file, int mode, @NotNull Charset charset) thr
3128
}
3229

3330
/**
34-
* Read the content of a file inside a jar/zip file
31+
* Read the content of a file inside a jar/zip file.
3532
*
3633
* @param innerPath Local path inside the jar/zip file (e.g. "./plugins.yml")
3734
* @return File content as byte array
@@ -43,7 +40,7 @@ public byte[] readBytes(String innerPath) throws IOException
4340
}
4441

4542
/**
46-
* Read the content of a file inside a jar/zip file
43+
* Read the content of a file inside a jar/zip file.
4744
*
4845
* @param innerPath Local path inside the jar/zip file (e.g. "./plugins.yml")
4946
* @return File content as string using UTF-8 encoding

0 commit comments

Comments
 (0)