Skip to content

Commit

Permalink
Use DefaultsPlugin to set up gradle build. Use travis-ci. Correct sty…
Browse files Browse the repository at this point in the history
…le issues which cause spotless check to fail.
  • Loading branch information
LunNova committed Sep 21, 2017
1 parent e9b7193 commit 7ce6f14
Show file tree
Hide file tree
Showing 18 changed files with 94 additions and 183 deletions.
32 changes: 32 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# More details on how to configure the Travis build
# https://docs.travis-ci.com/user/customizing-the-build/

# Speed up build with travis caches
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/

language: java

jdk:
- oraclejdk8

#Skipping install step to avoid having Travis run arbitrary './gradlew assemble' task
# https://docs.travis-ci.com/user/customizing-the-build/#Skipping-the-Installation-Step
install:
- true

#Don't build tags
branches:
except:
- /^v\d/

#Build and perform release (if needed)
script:
- ./gradlew build -s && ./gradlew ciPerformRelease

after_success:
#Generates coverage report:
- ./gradlew --stacktrace jacocoTestReport && cp build/reports/jacoco/test/jacocoTestReport.xml jacoco.xml || echo "Code coverage failed"
- bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"
120 changes: 14 additions & 106 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,126 +1,34 @@
buildscript {
repositories {
jcenter()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
maven {
name = "nallar"
url = "https://repo.nallar.me/"
}
}
if (System.getenv("GRADLE_NO_CACHE_CHANGING") != null) {
configurations.all {
resolutionStrategy.cacheChangingModulesFor 1, 'seconds'
resolutionStrategy.cacheDynamicVersionsFor 1, 'seconds'
}
maven { url "https://repo.nallar.me/" }
maven { url "https://plugins.gradle.org/m2/" }
maven { url "http://files.minecraftforge.net/maven" }
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
classpath 'org.minimallycorrect.libloader:LibLoaderGradle:0.1-SNAPSHOT'
classpath 'org.minimallycorrect.gradle:DefaultsPlugin:0.0.7'
}
}
plugins {
id "com.matthewprenger.cursegradle" version "1.0.9"
}
apply plugin: 'org.minimallycorrect.gradle.DefaultsPlugin'
apply plugin: 'org.minimallycorrect.libloader.LibLoaderGradle'
apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'idea'

ext.mcVersion = "1.12"
ext.runMcVersion = "1.12"
ext.forgeVersion = "14.21.0.2340"
ext.forgeMappings = "snapshot_20170617"
group = "org.minimallycorrect.tickprofiler" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "TickProfiler"

def calculateVersion() {
def ver = project.runMcVersion
if (System.env.BUILD_NUMBER != null)
return ver + "-jenkins." + System.env.BUILD_NUMBER
if (project.hasProperty("release"))
return ver + '-' + project.release
return ver + "-dev"
}

version = calculateVersion()
group = "org.minimallycorrect.tickprofiler"

repositories {
jcenter()
maven { url = 'https://repo.nallar.me/' }
}

if (System.getenv("GRADLE_NO_CACHE_CHANGING") != null) {
configurations.all {
resolutionStrategy.cacheChangingModulesFor 1, 'seconds'
resolutionStrategy.cacheDynamicVersionsFor 1, 'seconds'
}
}
minimallyCorrectDefaults {
minecraft = 1.12
fmlCorePlugin = "org.minimallycorrect.tickprofiler.minecraft.CoreMod"
fmlCorePluginContainsFmlMod = true
curseforgeProject = 270330
labels = ['minecraft-mod', 'profiler', 'minecraft', 'java', 'performance']
} ()

dependencies {
libLoader "com.eclipsesource.minimal-json:minimal-json:0.9.4"
libLoader "org.minimallycorrect.modpatcher:ModPatcher:$mcVersion-SNAPSHOT"
compileOnly 'org.projectlombok:lombok:1.16.16'
testCompileOnly 'org.projectlombok:lombok:1.16.16'
libLoader "org.minimallycorrect.modpatcher:ModPatcher:${project.minecraft.version}-SNAPSHOT"
testCompile 'junit:junit:4.12'
}

tasks.withType(JavaCompile) {
sourceCompatibility = 8
targetCompatibility = 8
options.with {
encoding = 'UTF-8'
compilerArgs << "-Xlint:all" << '-Xlint:-path' << '-Xlint:-processing' << '-Xlint:-rawtypes' << '-Xlint:-serial'
}
}

minecraft {
version = "${project.mcVersion}-${project.forgeVersion}"
runDir = "run"
mappings = project.forgeMappings

replace "@MOD_VERSION@", project.version
replace "@MC_VERSION@", runMcVersion
}

processResources {
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version

filesMatching("mcmod.info") {
expand 'version': project.version, 'mcversion': runMcVersion
}
filesMatching("modpatcher.version") {
expand 'version': project.version
}
}

jar {
manifest.mainAttributes("FMLCorePlugin": "org.minimallycorrect.tickprofiler.minecraft.CoreMod", "FMLCorePluginContainsFMLMod": "YasPlease")
}

wrapper {
gradleVersion = "3.5"
def jvmOpts = "-Xmx2G"
inputs.property("jvmOpts", jvmOpts)
doLast {
def optsEnvVar = "DEFAULT_JVM_OPTS"
scriptFile.write scriptFile.text.replace("$optsEnvVar=\"\"", "$optsEnvVar=\"$jvmOpts\"")
batchScript.write batchScript.text.replace("set $optsEnvVar=", "set $optsEnvVar=$jvmOpts")
}
}

if (System.getenv("CURSEFORGE_API_KEY") != null) {
curseforge {
apiKey = System.getenv("CURSEFORGE_API_KEY") // This should really be in a gradle.properties file
project {
id = "270330"
changelog = "git rev-parse --short HEAD".execute().text.trim() + ":" + "git log -1 --pretty=%B".execute().text.trim()
releaseType = "beta"
addArtifact sourceJar
}
}
project.tasks.getByName("curseforge").dependsOn.add(sourceJar)
}
3 changes: 3 additions & 0 deletions gradle/shipkit.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Auto-generated by https://github.com/MinimallyCorrect/DefaultsPlugin

minimallyCorrectDefaultsShipkit {} ()
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Fri May 12 22:30:15 BST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2-bin.zip
6 changes: 3 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS="-Xmx2G"
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
warn () {
echo "$*"
}

die ( ) {
die () {
echo
echo "$*"
echo
Expand Down Expand Up @@ -155,7 +155,7 @@ if $cygwin ; then
fi

# Escape application args
save ( ) {
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@SuppressWarnings("WeakerAccess")
@Mod(modid = "tickprofiler", name = "TickProfiler", acceptableRemoteVersions = "*", version = "@MOD_VERSION@", acceptedMinecraftVersions = "[@MC_VERSION@]")
public class TickProfiler {
private static final Set<World> profilingWorlds = Collections.newSetFromMap(new MapMaker().weakKeys().<World, Boolean>makeMap());
private static final Set<World> profilingWorlds = Collections.newSetFromMap(new MapMaker().weakKeys().makeMap());
@Mod.Instance("tickprofiler")
public static TickProfiler instance;
public static long tickTime = 20; // Initialise with non-zero value to avoid divide-by-zero errors calculating TPS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private void addPreParameters(Parameters p) {

private void addPostParameters(Parameters p) {
p.orderWithDefault(Arrays.asList("output", "commandsender"));
}
}

private void process(final ICommandSender commandSender, List<String> arguments) {
val p = new Parameters(arguments);
Expand All @@ -58,16 +58,16 @@ private void process(final ICommandSender commandSender, List<String> arguments)
break;
default:
throw new UsageException("Unknown output: " + output);
}
}
}

val profile = type.create();
try {
profile.start(targets, p);
} finally {
profile.closeIfNeeded();
}
}
}

@Override
public String getUsage(ICommandSender icommandsender) {
Expand All @@ -79,7 +79,7 @@ public String getUsage(ICommandSender icommandsender) {
sb.append(type.name()).append(": ").append("/profile ").append(type.shortName);
p.writeExpectedParameters(sb);
sb.append('\n');
}
}
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.gen.ChunkProviderServer;
import org.minimallycorrect.tickprofiler.Log;
import org.minimallycorrect.tickprofiler.minecraft.TickProfiler;
Expand Down Expand Up @@ -82,13 +83,11 @@ public void processCommand(ICommandSender commandSender, List<String> arguments)
.heading("TE")
.heading("C")
.heading("");
for (World world : server.worlds) {
for (WorldServer world : server.worlds) {
int worldEntities = world.loadedEntityList.size();
int worldTileEntities = world.loadedTileEntityList.size();
int worldChunks = 0;
val provider = world.getChunkProvider();
if (provider instanceof ChunkProviderServer)
worldChunks = ((ChunkProviderServer) provider).getLoadedChunkCount();
int worldChunks = provider.getLoadedChunkCount();
entities += worldEntities;
tileEntities += worldTileEntities;
chunks += worldChunks;
Expand All @@ -97,8 +96,7 @@ public void processCommand(ICommandSender commandSender, List<String> arguments)
.row(worldEntities)
.row(worldTileEntities)
.row(worldChunks)
.row("")
;
.row("");
}
tf
.row(server.getPlayerList().getCurrentPlayerCount() + " Players")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.minimallycorrect.tickprofiler.minecraft.profiling;

import com.google.common.primitives.Longs;
import lombok.EqualsAndHashCode;
import lombok.val;
import org.minimallycorrect.tickprofiler.util.CollectionsUtil;
import org.minimallycorrect.tickprofiler.util.TableFormatter;
Expand Down Expand Up @@ -116,8 +117,7 @@ private void tick() {
}

private static class IntHashMap<K> extends HashMap<K, IntegerHolder> {
IntHashMap() {
}
IntHashMap() {}

@SuppressWarnings("unchecked")
@Override
Expand All @@ -131,17 +131,15 @@ public IntegerHolder get(Object k) {
}
}

@EqualsAndHashCode
private static class IntegerHolder implements Comparable<IntegerHolder> {
int value;

IntegerHolder() {
}
IntegerHolder() {}

@Override
public int compareTo(final IntegerHolder o) {
int x = value;
int y = o.value;
return (x < y) ? -1 : ((x == y) ? 0 : 1);
return Integer.compare(value, o.value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public void start() {
val elements = parameters.getInt("elements");
if (elements <= 0)
throw new IllegalArgumentException("elements must be > 0");
val entityCounts = new HashMap<Class, Integer>();
val tileEntityCounts = new HashMap<Class, Integer>();
val entityCounts = new HashMap<Class<?>, Integer>();
val tileEntityCounts = new HashMap<Class<?>, Integer>();
val worlds = parameters.getString("worlds").toLowerCase();
val worldList = new ArrayList<WorldServer>();
if (worlds.equals("all")) {
Collections.addAll(worldList, DimensionManager.getWorlds());
} else {
//TODO: handle multiple entries, split by ','
// TODO: handle multiple entries, split by ','
worldList.add(DimensionManager.getWorld(Integer.parseInt(worlds)));
}
for (val world : worldList)
Expand Down

0 comments on commit 7ce6f14

Please sign in to comment.