Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
LCLPYT committed Jun 5, 2021
1 parent 5da0e4f commit fe86b11
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 68 deletions.
30 changes: 18 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
# Ignore Gradle project-specific cache directory
.gradle
gradle.properties

# Ignore Gradle build output directory
build
buildRT

# eclipse
bin
*.launch
.settings
.project
.metadata
.classpath
.project

.iws
workspace.xml
tasks.xml
# idea
out
*.ipr
*.iws
*.iml
.idea

# gradle
build
.gradle
libs
private.properties
repo

# other
eclipse
96 changes: 91 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,107 @@
import org.ajoberstar.grgit.Tag

plugins {
id 'java'
id 'maven-publish'
id 'org.ajoberstar.grgit' version '4.1.0'
}

def privateProps = new Properties()
def privatePropsFile = file("private.properties")
if(privatePropsFile.exists())
privatePropsFile.withInputStream { privateProps.load(it) }

ext {
getHeadId = {
return grgit.head().abbreviatedId
}
getHeadTag = {
def headId = grgit.head().id
def headTag = null

grgit.tag.list().forEach {
def tag = it as Tag
if(tag.commit.id == headId) headTag = tag
}

return headTag
}
PRIVATE = privateProps
}

def getVersion(boolean strict = false) {
def headTag = rootProject.ext.getHeadTag()
def tagName = null
if (headTag != null && (tagName = headTag.name).matches('^v[0-9]+\\.[0-9]+\\.[0-9]+$')) {
return (tagName as String).substring(1)
} else {
if(strict) {
if (headTag == null) throw new IllegalStateException("Commit HEAD is not tagged.")
else throw new IllegalStateException("Commit HEAD tag '${tagName}' does not meet the required versioning scheme.")
} else return "dev-${rootProject.ext.getHeadId()}" as String
}
}

group 'work.lclpnet'
archivesBaseName = 'launcher-logic-forge-installer'
version getVersion()

sourceCompatibility = targetCompatibility = '16'

repositories {
mavenCentral()
maven {
url "http://files.minecraftforge.net/maven"
url "https://maven.minecraftforge.net"
}
}

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compileOnly "net.minecraftforge:forge:1.15.2-31.2.36:installer"
implementation 'net.minecraftforge:forge:1.16.5-36.1.4:installer'

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
}

test {
useJUnitPlatform()
}

jar {
manifest {
attributes 'Main-Class': 'work.lclpnet.forgeinstaller.ForgeInstaller'
manifest.attributes(
'Main-Class': 'work.lclpnet.forgeinstaller.ForgeInstaller'
)
}

tasks.publish.dependsOn({
def versionTest = getVersion(true)
println("Publishing version '${versionTest}'...")
})

publishing {
publications {
mavenJava(MavenPublication) {
artifactId = archivesBaseName
from components.java

pom {
name = 'LauncherLogic Forge Installer'
description = 'Installer for MinecraftForge for LauncherLogic'
}
}
}
repositories {
maven {
if (privateProps.containsKey('mavenPassword')
&& privateProps.containsKey('mavenHost')
&& privateProps.containsKey('mavenUser')) {
credentials {
username privateProps.getProperty('mavenUser')
password privateProps.getProperty('mavenPassword')
}
url privateProps.getProperty('mavenHost')
} else {
url "file:///${project.projectDir}/repo"
}
}
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
5 changes: 0 additions & 5 deletions latest.json

This file was deleted.

33 changes: 4 additions & 29 deletions src/main/java/work/lclpnet/forgeinstaller/ForgeInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,13 @@
import net.minecraftforge.installer.actions.ActionCanceledException;
import net.minecraftforge.installer.actions.ClientInstall;
import net.minecraftforge.installer.actions.ProgressCallback;
import net.minecraftforge.installer.json.OptionalLibrary;
import net.minecraftforge.installer.json.Util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.io.*;
import java.util.Locale;
import java.util.Optional;
import java.util.function.Predicate;

public class ForgeInstaller {

private static List<OptionalListEntry> optionals = new ArrayList<>();

public static void main(String[] args) {
if (args.length != 2) {
System.err.println("You need to pass exactly 2 arguments: <host> <port>");
Expand All @@ -33,7 +22,7 @@ public static void main(String[] args) {
pgClient.setClientName("forgeInstaller");

File tempDir = new File(System.getProperty("java.io.tmpdir"), "launcherlogic_forge");
tempDir.mkdirs();
if(!tempDir.exists() && !tempDir.mkdirs()) throw new IllegalStateException("Could not create temp directory.");
File logFile = new File(tempDir, String.format("llforgei_%s_stdout.txt", System.currentTimeMillis() / 1000L));
File errFile = new File(tempDir, String.format("llforgei_%s_stderr.txt", System.currentTimeMillis() / 1000L));

Expand All @@ -57,13 +46,9 @@ public static void main(String[] args) {
System.setErr(new LoggingPrintStream(origErr, outErr, pgClient));

ClientInstall install = new ClientInstall(Util.loadInstallProfile(), ProgressCallback.withOutputs(interceptor));
Predicate<String> optPred = input -> {
Optional<OptionalListEntry> ent = optionals.stream().filter(e -> e.lib.getArtifact().equals(input)).findFirst();
return !ent.isPresent() || ent.get().isEnabled();
};

try {
install.run(getMCDir(), optPred);
install.run(getMCDir(), input -> true);
} catch (ActionCanceledException e) {
e.printStackTrace();
System.exit(1);
Expand All @@ -73,7 +58,7 @@ public static void main(String[] args) {

if (ProgressCallbackClient.hasOpenSockets()) {
try {
Thread.sleep(1000L); //Delay to send potential pending tcp stuff (is this necessary?)
Thread.sleep(1000L); // Delay to send potential pending tcp stuff (is this necessary?)
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -103,14 +88,4 @@ else if (osType.contains("mac"))
return new File(userHomeDir, mcDir);
}

private static class OptionalListEntry {
OptionalLibrary lib;

private boolean enabled;

public boolean isEnabled() {
return this.enabled;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

public class ProgressCallbackClient {

private static List<Socket> openSockets = new ArrayList<>();
private static final List<Socket> openSockets = new ArrayList<>();

private String host;
private int port;
private final String host;
private final int port;
private transient Socket socket;

public ProgressCallbackClient(String host, int port) {
Expand Down Expand Up @@ -48,28 +48,17 @@ private void send(byte[] bytes) {
public void setClientName(String name) {
JsonObject obj = new JsonObject();
obj.addProperty("setname", name);
String s = obj.toString() + "\n";
String s = obj + "\n";
send(s.getBytes(StandardCharsets.UTF_8));
}

public void send(String msg) {
JsonObject obj = new JsonObject();
obj.addProperty("forgeInstaller", msg);
msg = obj.toString() + "\n";
msg = obj + "\n";
send(msg.getBytes(StandardCharsets.UTF_8));
}

public void stop() {
if (socket == null) return;
try {
socket.close();
openSockets.remove(socket);
socket = null;
} catch (IOException e) {
e.printStackTrace();
}
}

public static void closeAllSockets() {
openSockets.forEach(s -> {
try {
Expand Down

0 comments on commit fe86b11

Please sign in to comment.