Skip to content

Commit e737a02

Browse files
committed
Initial commit for OS Utils (#14)
1 parent d75de43 commit e737a02

File tree

11 files changed

+555
-119
lines changed

11 files changed

+555
-119
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Build Download Utils
2+
on:
3+
push:
4+
branches: [master]
5+
paths:
6+
- os-utils/**
7+
- '!.github/workflows/**'
8+
- '!settings.gradle'
9+
permissions:
10+
contents: read
11+
jobs:
12+
build:
13+
uses: MinecraftForge/SharedActions/.github/workflows/gradle.yml@v0
14+
with:
15+
java: 21
16+
gradle_tasks: :os-utils:check :os-utils:publish
17+
project_path: os-utils
18+
secrets:
19+
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
20+
PROMOTE_ARTIFACT_WEBHOOK: ${{ secrets.PROMOTE_ARTIFACT_WEBHOOK }}
21+
PROMOTE_ARTIFACT_USERNAME: ${{ secrets.PROMOTE_ARTIFACT_USERNAME }}
22+
PROMOTE_ARTIFACT_PASSWORD: ${{ secrets.PROMOTE_ARTIFACT_PASSWORD }}
23+
MAVEN_USER: ${{ secrets.MAVEN_USER }}
24+
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
25+
GRADLE_CACHE_KEY: ${{ secrets.GRADLE_CACHE_KEY }}

.gitversion.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ tag = "log"
1414
path = "json-data-utils"
1515
tag = "json-data"
1616

17+
[os]
18+
path = "os-utils"
19+
tag = "os"
20+
1721
[download]
1822
path = "download-utils"
1923
tag = "download"

json-data-utils/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ dependencies {
2525
compileOnly libs.nulls
2626

2727
api libs.gson
28+
api projects.osUtils
2829
}
2930

3031
tasks.named('jar', Jar) {

json-data-utils/src/main/java/net/minecraftforge/util/data/MCJsonUtils.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,28 @@
44
*/
55
package net.minecraftforge.util.data;
66

7+
import net.minecraftforge.util.os.OS;
8+
79
import java.io.File;
810

911
public class MCJsonUtils {
12+
@Deprecated
13+
public static File getMCDir() {
14+
return getMCDir(OS.current());
15+
}
16+
1017
/**
1118
* Gets the Minecraft directory used by Minecraft Launcher. This is the directory where the launcher stores
1219
* libraries, which we can use instead of downloading them again.
1320
*
1421
* @return The Minecraft directory
1522
*/
16-
public static File getMCDir() {
23+
public static File getMCDir(OS os) {
1724
String userHomeDir = System.getProperty("user.home", ".");
1825
String mcDir = ".minecraft";
19-
if (OS.CURRENT == OS.WINDOWS && System.getenv("APPDATA") != null)
26+
if (os == OS.WINDOWS && System.getenv("APPDATA") != null)
2027
return new File(System.getenv("APPDATA"), mcDir);
21-
else if (OS.CURRENT == OS.MACOS)
28+
else if (os == OS.MACOS)
2229
return new File(userHomeDir, "Library/Application Support/minecraft");
2330
return new File(userHomeDir, mcDir);
2431
}

json-data-utils/src/main/java/net/minecraftforge/util/data/OS.java

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

json-data-utils/src/main/java/net/minecraftforge/util/data/json/MinecraftVersion.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@
44
*/
55
package net.minecraftforge.util.data.json;
66

7-
import net.minecraftforge.util.data.OS;
7+
import net.minecraftforge.util.os.OS;
88
import org.jetbrains.annotations.Nullable;
99

1010
import java.net.URL;
1111
import java.util.ArrayList;
1212
import java.util.Arrays;
13-
import java.util.Collection;
14-
import java.util.Collections;
1513
import java.util.EnumSet;
1614
import java.util.List;
1715
import java.util.Map;
18-
import java.util.Objects;
1916

2017
// TODO: [MCMaven][Documentation][MinecraftVersion] What in here is nullable?
2118
/** Represents a Minecraft version and its artifacts. */
@@ -136,20 +133,20 @@ public static class Rule {
136133
public static class OS {
137134
public String name;
138135

139-
public static net.minecraftforge.util.data.OS toOS(String name) {
136+
public static net.minecraftforge.util.os.OS toOS(String name) {
140137
switch (name) {
141138
case "windows":
142-
return net.minecraftforge.util.data.OS.WINDOWS;
139+
return net.minecraftforge.util.os.OS.WINDOWS;
143140
case "linux":
144-
return net.minecraftforge.util.data.OS.LINUX;
141+
return net.minecraftforge.util.os.OS.LINUX;
145142
case "osx":
146-
return net.minecraftforge.util.data.OS.MACOS;
143+
return net.minecraftforge.util.os.OS.MACOS;
147144
default:
148-
return net.minecraftforge.util.data.OS.UNKNOWN;
145+
return net.minecraftforge.util.os.OS.UNKNOWN;
149146
}
150147
}
151148

152-
public net.minecraftforge.util.data.OS toOS() {
149+
public net.minecraftforge.util.os.OS toOS() {
153150
return toOS(this.name);
154151
}
155152
}

os-utils/build.gradle

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
plugins {
2+
id 'java-library'
3+
id 'idea'
4+
id 'eclipse'
5+
id 'maven-publish'
6+
alias libs.plugins.licenser
7+
alias libs.plugins.gradleutils
8+
alias libs.plugins.gitversion
9+
alias libs.plugins.changelog
10+
}
11+
12+
gradleutils.displayName = 'OS Utils'
13+
description = 'Utilities for identifying operating systems, architectures, and their defaults.'
14+
group = 'net.minecraftforge'
15+
version = gitversion.tagOffset
16+
17+
println "Version: $version"
18+
19+
java {
20+
toolchain.languageVersion = JavaLanguageVersion.of(8)
21+
withSourcesJar()
22+
//withJavadocJar()
23+
}
24+
25+
dependencies {
26+
compileOnly libs.nulls
27+
}
28+
29+
tasks.named('jar', Jar) {
30+
manifest {
31+
attributes('Automatic-Module-Name': 'net.minecraftforge.utils.os')
32+
33+
gradleutils.manifestDefaults(it, 'net/minecraftforge/util/os/')
34+
}
35+
}
36+
37+
license {
38+
header = rootProject.file('LICENSE-header.txt')
39+
newLine = false
40+
exclude '**/*.properties'
41+
}
42+
43+
changelog {
44+
fromBase()
45+
}
46+
47+
publishing {
48+
repositories {
49+
maven gradleutils.publishingForgeMaven
50+
}
51+
52+
publications.register('mavenJava', MavenPublication) {
53+
from components.java
54+
55+
changelog.publish(it)
56+
gradleutils.promote(it)
57+
58+
pom { pom ->
59+
name = gradleutils.displayName
60+
description = project.description
61+
62+
gradleutils.pom.addRemoteDetails(pom)
63+
64+
licenses {
65+
license gradleutils.pom.licenses.LGPLv2_1
66+
}
67+
68+
developers {
69+
developer gradleutils.pom.developers.LexManos
70+
developer gradleutils.pom.developers.Jonathing
71+
}
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)