Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolLoong committed Oct 16, 2023
1 parent 59cbdee commit 949479f
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 175 deletions.
75 changes: 2 additions & 73 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ subprojects {
val mainClass = "io.papermc.paperclip.Main"

tasks.jar {
val java6Jar = project(":java6").tasks.named("jar")
val java17Jar = project(":java17").tasks.named("shadowJar")
dependsOn(java6Jar, java17Jar)
dependsOn(java17Jar)

from(zipTree(java6Jar.map { it.outputs.files.singleFile }))
from(zipTree(java17Jar.map { it.outputs.files.singleFile }))

manifest {
Expand All @@ -42,83 +40,14 @@ tasks.jar {
}

val sourcesJar by tasks.registering(Jar::class) {
val java6Sources = project(":java6").tasks.named("sourcesJar")
val java17Sources = project(":java17").tasks.named("sourcesJar")
dependsOn(java6Sources, java17Sources)

from(zipTree(java6Sources.map { it.outputs.files.singleFile }))
dependsOn(java17Sources)
from(zipTree(java17Sources.map { it.outputs.files.singleFile }))

archiveClassifier.set("sources")
}

val isSnapshot = project.version.toString().endsWith("-SNAPSHOT")

publishing {
publications {
register<MavenPublication>("maven") {
groupId = project.group.toString()
artifactId = project.name
version = project.version.toString()

from(components["java"])
artifact(sourcesJar)
withoutBuildIdentifier()

pom {
val repoPath = "PaperMC/Paperclip"
val repoUrl = "https://github.com/$repoPath"

name.set("Paperclip")
description.set(project.description)
url.set(repoUrl)
packaging = "jar"

licenses {
license {
name.set("MIT")
url.set("$repoUrl/blob/main/license.txt")
distribution.set("repo")
}
}

issueManagement {
system.set("GitHub")
url.set("$repoUrl/issues")
}

developers {
developer {
id.set("DemonWav")
name.set("Kyle Wood")
email.set("demonwav@gmail.com")
url.set("https://github.com/DemonWav")
}
}

scm {
url.set(repoUrl)
connection.set("scm:git:$repoUrl.git")
developerConnection.set("scm:git:git@github.com:$repoPath.git")
}
}
}

repositories {
val url = if (isSnapshot) {
"https://repo.papermc.io/repository/maven-snapshots/"
} else {
"https://repo.papermc.io/repository/maven-releases/"
}

maven(url) {
credentials(PasswordCredentials::class)
name = "paper"
}
}
}
}

tasks.register("printVersion") {
doFirst {
println(version)
Expand Down
1 change: 1 addition & 0 deletions java17/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ repositories {

dependencies {
implementation("io.sigpipe:jbsdiff:1.0")
compileOnly(files("D:\\idea\\project\\Allay\\Allay-API\\build\\libs\\Allay-API-0.0.1-all.jar"))
}

tasks.shadowJar {
Expand Down
71 changes: 36 additions & 35 deletions java17/src/main/java/io/papermc/paperclip/Paperclip.java
Original file line number Diff line number Diff line change
@@ -1,55 +1,54 @@
package io.papermc.paperclip;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import cn.allay.api.datastruct.DynamicURLClassLoader;

import java.io.*;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public final class Paperclip {
private static String workPath;

public static void setup(DynamicURLClassLoader loader, final String[] args) {
workPath = args[0];
File file = Path.of(workPath).toFile();
if (!file.exists() || !file.isDirectory()) {
System.err.println("The working directory of je generator must be first param!");
System.exit(1);
}

public static void main(final String[] args) {
if (Path.of("").toAbsolutePath().toString().contains("!")) {
if (Path.of(workPath).toAbsolutePath().toString().contains("!")) {
System.err.println("Paperclip may not run in a directory containing '!'. Please rename the affected folder.");
System.exit(1);
}

final URL[] classpathUrls = setupClasspath();

final ClassLoader parentClassLoader = Paperclip.class.getClassLoader().getParent();
final URLClassLoader classLoader = new URLClassLoader(classpathUrls, parentClassLoader);

for (var url : classpathUrls) {
loader.addURL(url);
}
final String mainClassName = findMainClass();
System.out.println("Starting " + mainClassName);

final Thread runThread = new Thread(() -> {
try {
final Class<?> mainClass = Class.forName(mainClassName, true, classLoader);
final MethodHandle mainHandle = MethodHandles.lookup()
try {
final Class<?> mainClass = Class.forName(mainClassName, true, loader);
final MethodHandle mainHandle = MethodHandles.lookup()
.findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class))
.asFixedArity();
mainHandle.invoke((Object) args);
} catch (final Throwable t) {
throw Util.sneakyThrow(t);
}
}, "ServerMain");
runThread.setContextClassLoader(classLoader);
runThread.start();
mainHandle.invoke((Object) args);
} catch (final Throwable t) {
throw Util.sneakyThrow(t);
}
}

private static URL[] setupClasspath() {
final var repoDir = Path.of(System.getProperty("bundlerRepoDir", ""));
final var repoDir = Path.of(System.getProperty("bundlerRepoDir", workPath));

final PatchEntry[] patches = findPatches();
final DownloadContext downloadContext = findDownloadContext();
Expand Down Expand Up @@ -115,9 +114,11 @@ private static DownloadContext findDownloadContext() {
private static FileEntry[] findVersionEntries() {
return findFileEntries("versions.list");
}

private static FileEntry[] findLibraryEntries() {
return findFileEntries("libraries.list");
}

private static FileEntry[] findFileEntries(final String fileName) {
final InputStream libListStream = Paperclip.class.getResourceAsStream("/META-INF/" + fileName);
if (libListStream == null) {
Expand Down Expand Up @@ -199,12 +200,12 @@ private static Map<String, Map<String, URL>> extractFiles(final PatchEntry[] pat
}

private static void extractEntries(
final Map<String, URL> urls,
final PatchEntry[] patches,
final Path originalRootDir,
final Path repoDir,
final FileEntry[] entries,
final String targetName
final Map<String, URL> urls,
final PatchEntry[] patches,
final Path originalRootDir,
final Path repoDir,
final FileEntry[] entries,
final String targetName
) throws IOException {
if (entries == null) {
return;
Expand All @@ -219,10 +220,10 @@ private static void extractEntries(
}

private static void applyPatches(
final Map<String, Map<String, URL>> urls,
final PatchEntry[] patches,
final Path originalJar,
final Path repoDir
final Map<String, Map<String, URL>> urls,
final PatchEntry[] patches,
final Path originalJar,
final Path repoDir
) {
if (patches.length == 0) {
return;
Expand Down
16 changes: 0 additions & 16 deletions java6/build.gradle.kts

This file was deleted.

50 changes: 0 additions & 50 deletions java6/src/main/java/io/papermc/paperclip/Main.java

This file was deleted.

2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ plugins {
}

rootProject.name = "paperclip"
include("java6", "java17")
include("java17")

0 comments on commit 949479f

Please sign in to comment.