Skip to content

Commit

Permalink
merge and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
eupedroosouza committed May 28, 2023
1 parent e9e281a commit 2c41485
Showing 9 changed files with 404 additions and 42 deletions.
55 changes: 34 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,52 @@
![banner](logo/banner.png)
![Build badge](https://img.shields.io/github/workflow/status/Iltotore/EntityMetadataAPI/Java%20CI/master)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/9af1fd09f7514581a0c2d900c176d50c)](https://www.codacy.com/manual/Iltotore/ManaDrop?utm_source=github.com&utm_medium=referral&utm_content=Iltotore/ManaDrop&utm_campaign=Badge_Grade)
[![Known Vulnerabilities](https://snyk.io/test/github/Iltotore/ManaDrop/badge.svg?targetFile=build.gradle)](https://snyk.io/test/github/Iltotore/ManaDrop?targetFile=build.gradle)
![License Badge](https://img.shields.io/github/license/Iltotore/ManaDrop)
![Release badge](https://img.shields.io/github/v/release/Iltotore/ManaDrop?include_prereleases)
![Build badge](https://img.shields.io/github/actions/workflow/status/eupedroosouza/ManaDrop/gradle.yml?branch=master)

A Gradle plugin for Minecraft development.
[//]: # ([![Codacy Badge](https://api.codacy.com/project/badge/Grade/9af1fd09f7514581a0c2d900c176d50c)](https://www.codacy.com/manual/Iltotore/ManaDrop?utm_source=github.com&utm_medium=referral&utm_content=Iltotore/ManaDrop&utm_campaign=Badge_Grade))

[//]: # ([![Known Vulnerabilities](https://snyk.io/test/github/Iltotore/ManaDrop/badge.svg?targetFile=build.gradle)](https://snyk.io/test/github/Iltotore/ManaDrop?targetFile=build.gradle))
![License Badge](https://img.shields.io/github/license/eupedroosouza/ManaDrop)
![Release badge](https://img.shields.io/github/v/release/eupedroosouza/ManaDrop?include_prereleases)

# Description
ManaDrop is a Gradle plugin designed to help Minecraft developers.
It helps to automatise some tasks and makes projects more portables.

# Features
Here are main features of this plugin. For more details about them, check the [wiki](https://github.com/Iltotore/ManaDrop/wiki/)
### Features
Here are main features of this plugin. For more details about them, check the [wiki](https://github.com/eupedroosouza/ManaDrop/wiki/)

### General
- [Dependency and Repository shortcuts](https://github.com/eupedroosouza/ManaDrop/wiki/General-features#dependency-and-repository-shortcuts)
- [YAML validation](https://github.com/eupedroosouza/ManaDrop/wiki/General-features#yaml-validation)

### Spigot and Paper
- [Plugin.yml generation](https://github.com/eupedroosouza/ManaDrop/wiki/Spigot#pluginyml-generation)
- [NMS dependencies management](https://github.com/eupedroosouza/ManaDrop/wiki/Spigot#nms-support)

## General
- [Dependency and Repository shortcuts](https://github.com/Iltotore/ManaDrop/wiki/General-features#dependency-and-repository-shortcuts)
- [YAML validation](https://github.com/Iltotore/ManaDrop/wiki/General-features#yaml-validation)
### BungeeCord and Waterfall
- [Bungee.yml generation](https://github.com/eupedroosouza/ManaDrop/wiki/BungeeCord#bungeeyml-generation)

## Spigot and Paper
- [Plugin.yml generation](https://github.com/Iltotore/ManaDrop/wiki/Spigot#pluginyml-generation)
- [NMS dependencies management](https://github.com/Iltotore/ManaDrop/wiki/Spigot#nms-support)
### NMS Remap
- [Wiki](https://github.com/eupedroosouza/ManaDrop/wiki/Remap)

## BungeeCord and Waterfall
- [Bungee.yml generation](https://github.com/Iltotore/ManaDrop/wiki/BungeeCord#bungeeyml-generation)

# Use in your project
### Merge
As of version 0.4.4, ManaDrop has been merged with mojang-spigot-remapper by @patrick-choe (https://github.com/patrick-choe/mojang-spigot-remapper) and now has a NMS remapping system.
- [More info and Wiki](https://github.com/eupedroosouza/ManaDrop/wiki/Remap)

### Use in your project
You can use this plugin in your Gradle Build by applying it.
- Using `apply plugin: fr.il_totore.manadrop:version`
- Using `apply plugin: io.github.eupedroosouza.fr.il_totore.manadrop:version`

- Using the new `plugins` statement
```gradle
plugins {
id 'fr.il_totore.manadrop' version 'version'
id 'io.github.eupedroosouza.fr.il_totore.manadrop' version 'version'
}
```

Check the latest available version [here](https://plugins.gradle.org/plugin/fr.il_totore.manadrop)
Check the latest available version [here](https://plugins.gradle.org/plugin/io.github.eupedroosouza.fr.il_totore.manadrop)

### Changelog

#### 0.4.4
- BuildTools now accepts arguments.
- ManaDrop has been merged with mojang-spigot-remapper and now has a NMS remapping system.
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -3,13 +3,12 @@ plugins {
}



allprojects {

apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'

group 'fr.il_totore'
group 'io.github.eupedroosouza.fr.il_totore.'

sourceCompatibility = 1.8

17 changes: 9 additions & 8 deletions mainPlugin/build.gradle
Original file line number Diff line number Diff line change
@@ -4,33 +4,34 @@ plugins {
id 'java-gradle-plugin'
}

version = '0.4.2'
version = '0.4.4'

dependencies {
implementation gradleApi()
shadow 'com.github.carleslc:simple-yaml:1.4.1'
shadow 'net.md-5:SpecialSource:1.11.0'
shadow project(':util')
}

gradlePlugin {

plugins {
manadrop {
id = 'fr.il_totore.manadrop'
id = 'io.github.eupedroosouza.fr.il_totore.manadrop'
implementationClass = 'fr.il_totore.manadrop.ManaDrop'
}
}
}

pluginBundle {
ext['gradle.publish.key'] = System.getenv('gradle.publish.key')
ext['gradle.publish.secret'] = System.getenv('gradle.publish.secret')
website = 'https://github.com/Iltotore/ManaDrop'
vcsUrl = 'https://github.com/Iltotore/ManaDrop'
description = 'A Gradle plugin for Minecraft Development'
tags = ['minecraft', 'spigot', 'bungeecord']
website = 'https://github.com/eupedroosouza/ManaDrop'
vcsUrl = 'https://github.com/eupedroosouza/ManaDrop'
plugins {
manadrop {
displayName = 'ManaDrop'
description = 'Gradle plugin that helps Minecraft developers automate tasks and make plugins more portable.'
version = project.version
tags = Arrays.asList('minecraft', 'spigot', 'remap', 'specialsource', 'bungeecord')
}
}
}
3 changes: 3 additions & 0 deletions mainPlugin/src/main/java/fr/il_totore/manadrop/ManaDrop.java
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import fr.il_totore.manadrop.spigot.task.BuildSpigot;
import fr.il_totore.manadrop.spigot.task.BuildTools;
import fr.il_totore.manadrop.task.CheckYaml;
import io.github.patrick.gradle.remapper.tasks.RemapTask;
import org.gradle.api.Plugin;
import org.gradle.api.Project;

@@ -21,6 +22,8 @@ public void apply(Project project) {
buildTools.setGroup("spigot");
BuildSpigot buildSpigot = project.getTasks().create("spigotPlugin", BuildSpigot.class);
buildSpigot.setGroup("spigot");
RemapTask remapTask = project.getTasks().create("remapJar", RemapTask.class);
remapTask.setGroup("remap");

project.getExtensions().create("spigot", SpigotExtension.class, project);

Original file line number Diff line number Diff line change
@@ -22,6 +22,10 @@ public static String bungeecordApi(String version) {
return "net.md-5:bungeecord-api:" + version + "-SNAPSHOT";
}

public static String remappedSpigot(String version){
return "org.spigotmc:spigot:" + version + "-R0.1-SNAPSHOT:remapped-mojang";
}

private static String getPaperGroup(String version) {
int majorVersion = Integer.parseInt(version.split("\\.")[1]);
return majorVersion >= 16 ? "io.papermc.paper" : "com.destroystokyo.paper";
Original file line number Diff line number Diff line change
@@ -2,32 +2,43 @@

import fr.il_totore.manadrop.util.LoggerProcessBuilder;
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.plugins.ExtensionContainer;
import org.gradle.api.tasks.TaskAction;
import org.gradle.internal.os.OperatingSystem;

import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class BuildTools extends DefaultTask {

private List<String> allVersions = new ArrayList<>();
private final List<String> allVersions = new ArrayList<>();
public File workDir;
public boolean refreshBuildTools = true;
public boolean refreshVersions = false;
public String buildToolsURL = "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar";
public boolean stopOnError = true;
public boolean showMavenInstallCheckLogs = false;
public boolean showBuildToolsLogs = true;
public boolean checkIfExistsInMavenRepository = true;
public int maxRamAllowed = 1024;
public String mavenPath = System.getenv("MAVEN_HOME") + "/bin/mvn" + (System.getenv("OS") != null && System.getenv("OS").toLowerCase().contains("win") ? ".cmd" : "");

public List<String> arguments = new ArrayList<>();
public String mavenLocal;

@TaskAction
public void run() throws IOException, InterruptedException {
Objects.requireNonNull(workDir, "workDir cannot be null !");
Objects.requireNonNull(mavenPath, "Can't find mavenPath !");
if(!workDir.exists()) workDir.mkdirs();
File buildTools = new File(workDir, "BuildTools.jar");
if(refreshBuildTools) buildTools.delete();
@@ -37,20 +48,67 @@ public void run() throws IOException, InterruptedException {
connection.setDoInput(true);
Files.copy(connection.getInputStream(), buildTools.toPath());
}
if(checkIfExistsInMavenRepository && mavenLocal == null){
System.out.println("Checking maven...");

/* Provided by gradle-maven-exec-plugin (https://github.com/dkorotych/gradle-maven-exec-plugin/tree/master)
* Copyright 2022 Dmitry Korotych
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Project project = getProject();
mavenLocal = (String) Optional.of(project)
.map(Project::getExtensions)
.map(ExtensionContainer::getExtraProperties)
.filter(properties -> properties.has("maven"))
.map(properties -> properties.get("maven"))
.orElse(null);
if(mavenLocal == null)
mavenLocal = Optional.ofNullable(System.getenv("MAVEN_HOME"))
.filter(((Predicate<String>) s -> s.trim().isEmpty()).negate())
.map(Paths::get)
.map(path -> path.resolve("bin"))
.map(path -> path.resolve("mvn" + (OperatingSystem.current().isWindows() ? ".cmd" : "")))
.map(Path::toAbsolutePath)
.map(Path::toString)
.orElseThrow(() -> new GradleException("Maven installation not found by MAVEN_HOME environment variable"));

}
if(mavenLocal != null)
System.out.println("Maven: " + mavenLocal);

for(String version : allVersions) {
System.out.println("Checking for " + version + "...");
LoggerProcessBuilder mavenProcessBuilder = new LoggerProcessBuilder(new ProcessBuilder(mavenPath, "dependency:get", "-Dartifact=\"org.spigotmc:spigot:" + version + "-R0.1-SNAPSHOT\""),
showMavenInstallCheckLogs ? System.out : null,
showMavenInstallCheckLogs ? System.err : null);
mavenProcessBuilder.environment().putAll(System.getenv());
if(mavenProcessBuilder.startAndWait().exitValue() == 0 && !refreshVersions) {
System.out.println(version + " is already installed! Skipping...");
continue;
if(checkIfExistsInMavenRepository){
LoggerProcessBuilder mavenProcessBuilder = new LoggerProcessBuilder(new ProcessBuilder(mavenLocal, "dependency:get",
"-Dartifact=\"org.spigotmc:spigot:" + version + "-R0.1-SNAPSHOT\""),
showMavenInstallCheckLogs ? System.out : null,
showMavenInstallCheckLogs ? System.err : null);
mavenProcessBuilder.environment().putAll(System.getenv());
if(mavenProcessBuilder.startAndWait().exitValue() == 0 && !refreshVersions) {
System.out.println(version + " is already installed! Skipping...");
continue;
}
}

System.out.println("Building " + version + "...");

LoggerProcessBuilder buildProcessBuilder = new LoggerProcessBuilder(new ProcessBuilder("java", "-Xmx" + maxRamAllowed + "M", "-jar", "BuildTools.jar", "--rev", version),
List<String> buildArguments = Stream.concat(Stream.of("java", "-Xmx" + maxRamAllowed + "M",
"-jar", "BuildTools.jar", "--rev", version), arguments.stream()).collect(Collectors.toList());

LoggerProcessBuilder buildProcessBuilder = new LoggerProcessBuilder(new ProcessBuilder(buildArguments),
showBuildToolsLogs ? System.out : null,
showBuildToolsLogs ? System.err : null);
buildProcessBuilder.directory(workDir);
@@ -69,4 +127,8 @@ public void versions(String... versions) {
public Collection<String> allVersions() {
return allVersions;
}

public void arguments(String... arguments){
this.arguments.addAll(Arrays.asList(arguments));
}
}
Loading

0 comments on commit 2c41485

Please sign in to comment.