Skip to content

Commit

Permalink
modJar signing
Browse files Browse the repository at this point in the history
  • Loading branch information
ROMVoid95 committed Jan 29, 2022
1 parent 3dfc1c4 commit a28a706
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 149 deletions.
62 changes: 55 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,7 @@ ext {
}
}

FileCollection collection = layout.files { file('gradle').listFiles() }
FileCollection scripts = collection.filter { File f ->
f.name.endsWith('.gradle') || !f.directory
}
scripts.collect { relativePath(it) }.each { String s ->
apply from: "$s".replace("\\", "/")
}
apply from: 'gradle/minecraft.gradle'

task generateChangelog(type: se.bjurr.gitchangelog.plugin.gradle.GitChangelogTask) {
group = 'script-tasks'
Expand All @@ -83,3 +77,57 @@ task generateChangelog(type: se.bjurr.gitchangelog.plugin.gradle.GitChangelogTas
templateContent = file('changelog.mustache').getText('UTF-8');
}

import net.minecraftforge.gradle.common.tasks.SignJar

task signJar(type: SignJar) {

onlyIf {
project.hasProperty('keyStore')
}

keyStore = project.findProperty('keyStore')
alias = project.findProperty('keyStoreAlias')
storePass = project.findProperty('keyStorePass')
keyPass = project.findProperty('keyStoreKeyPass')
inputFile = jar.archivePath
outputFile = jar.archivePath
}

jar {
manifest.from(MANIFEST)

afterEvaluate { project.getTasks().getByName('reobfJar').finalizedBy(signJar) }
}

jar.finalizedBy('reobfJar')

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
manifest.from(MANIFEST)
}

task apiJar(type: Jar) {
classifier "api"
include 'micdoodle8/mods/galacticraft/api/**'
from sourceSets.main.allJava
from sourceSets.main.output
manifest.from(MANIFEST)
}

task deobfJar(type: Jar) {
classifier = 'deobf'
from sourceSets.main.output
manifest.from(MANIFEST)
}

artifacts {
archives deobfJar
archives sourcesJar
archives apiJar
}

apply from: 'gradle/maven.gradle'
apply from: 'gradle/resources.gradle'

build.dependsOn signJar
31 changes: 0 additions & 31 deletions gradle/artifacts.gradle

This file was deleted.

154 changes: 58 additions & 96 deletions gradle/maven.gradle
Original file line number Diff line number Diff line change
@@ -1,110 +1,53 @@
apply plugin: "maven-publish"
apply plugin: 'signing'

task buildAllJars(type: GradleBuild) {
group = 'script-tasks'
description = 'Builds all Jars for Galacticraft'
tasks = [
'build',
'coreJar',
'miccoreJar',
'planetsJar',
'fullBuild',
'apiJar',
'coreDevJar',
'planetsDevJar',
'miccoreDevJar'
]
}

task buildMainJars(type: GradleBuild) {
group = 'script-tasks'
description = 'Builds the main Jars for Galacticraft'
tasks = [
'build',
'coreJar',
'miccoreJar',
'planetsJar',
'fullBuild'
]
}

task buildDevJars(type: GradleBuild) {
group = 'script-tasks'
description = 'Builds the dev Jars for Galacticraft'
tasks = [
'build',
'apiJar',
'coreDevJar',
'planetsDevJar',
'miccoreDevJar',
'fullBuild'
]
}

clean {
File buildDir = file('build')
FileCollection collection = layout.files { buildDir.listFiles() }
FileCollection cache = collection.filter { File f ->
!f.name.equals('fg_cache')
}
cache.collect { relativePath(it) }
delete = []
delete cache
}

tasks.named('wrapper') {
distributionType = Wrapper.DistributionType.ALL
}

publishing {
publications {
coreDev(MavenPublication) {
Galacticraft(MavenPublication) {
groupId 'micdoodle8.mods'
artifactId 'galacticraft-core'
version project.version
artifactId 'galacticraft'
version project.version.split("-")[1]

artifact coreJar

artifact coreDevJar {
classifier 'deobf'
}
}
planetsDev(MavenPublication) {
groupId 'micdoodle8.mods'
artifactId 'galacticraft-planets'
version project.version

artifact planetsJar

artifact planetsDevJar {
classifier 'deobf'
}
}
miccoreDev(MavenPublication) {
groupId 'micdoodle8.mods'
artifactId 'micdoodlecore'
version project.version
artifact jar
artifact deobfJar
artifact sourcesJar
artifact apiJar

pom {
name = 'Galacticraft'
description = 'An advanced space exploration mod for Minecraft'
url = 'https://github.com/TeamGalacticraft/Galacticraft-Legacy'
scm {
url = 'https://github.com/TeamGalacticraft/Galacticraft-Legacy'
connection = 'scm:git:git://github.com/TeamGalacticraft/Galacticraft-Legacy.git'
developerConnection = 'scm:git:git@github.com:TeamGalacticraft/Galacticraft-Legacy.git'
}
issueManagement {
system = 'github'
url = 'https://github.com/TeamGalacticraft/Galacticraft-Legacy/issues'
}

artifact miccoreJar

artifact miccoreDevJar {
classifier 'deobf'
}
}
apiDev(MavenPublication) {
groupId 'micdoodle8.mods'
artifactId 'galacticraft-api'
version project.version

artifact apiJar
licenses {
license {
name = 'custom'
url = 'https://github.com/TeamGalacticraft/Galacticraft-Legacy/blob/master/LICENSE.txt'
}
}
}
}
}
repositories {
mavenLocal()
maven {
url "file:///${project.buildDir}/repo"
}
maven {
name = 'external'
url = 'https://maven.galacticraft.dev/releases'
authentication {
basic(BasicAuthentication)
}
credentials {
username = System.getenv('MAVEN_USER')
password = System.getenv('MAVEN_PASSWORD')
}
}
}

signing {
Expand All @@ -113,3 +56,22 @@ publishing {
}
}
}

tasks.register('PublishToGalacticraftMaven') {
group = 'script-tasks'
description = 'Publishes the Galacticraft publication to the Galacticraft Maven repository.'
dependsOn tasks.withType(PublishToMavenRepository).matching {
it.repository == publishing.repositories.external

def ver = it.publication.version
def group = it.publication.groupId
def artifact = it.publication.artifactId

println('************************************************************************')
println('')
println(" compile " + group + ":" + group + ":" + ver)
println(" imlementation " + group + ":" + group + ":" + ver)
println('')
println('************************************************************************')
}
}
4 changes: 2 additions & 2 deletions gradle/resources.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def resourceTargets = [ 'mcmod.info' ]
def intoTargets = [ "$rootDir/out/production/resources/", "$rootDir/out/production/${project.name}.main/", "$rootDir/bin/main/" ]
def replaceProperties = [ mod_version: version.toString().split("-")[1], minecraft_version: mc_version ]
def replaceProperties = [ mod_version: version.toString().split("-")[1], minecraft_version: MC_VERSION ]

processResources {
inputs.properties replaceProperties
Expand All @@ -23,7 +23,7 @@ processResources {
}
}

def modFileTokens = [ gcVersion: version.toString().split("-")[1] ]
def modFileTokens = [ gcVersion: version.toString().split("-")[1], sha1: project.findProperty('signSHA1') ]
def included = [ "micdoodle8/mods/galacticraft/core/Constants.java" ]
def includedPaths = included.collect { java.nio.file.Paths.get(it) }
def expandedSrc = new File(project.buildDir, 'expandedSrc')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class Constants
public static final String MOD_ID_PLANETS = "galacticraftplanets";
public static final String MOD_NAME_SIMPLE = "Galacticraft";

public static final String FINGERPRINT = "${sha1}";

// public static final int LOCALMAJVERSION = 4;
// public static final int LOCALMINVERSION = 0;
// public static final int LOCALPATCHVERSION = 2;
Expand All @@ -19,10 +21,10 @@ public class Constants

@Deprecated
@ForRemoval(deadline = "4.1.0")
public static final String DEPENDENCIES_FORGE = "required-after:forge@[14.23.5.2860,); "; // Keep the space at the end!
public static final String DEPENDENCIES_FORGE = "required-after:forge@[14.23.5.2847,); "; // Keep the space at the end!
@Deprecated
@ForRemoval(deadline = "4.1.0")
public static final String DEPENDENCIES_MICCORE = "required-after:micdoodlecore; "; //Keep the space at the end!
public static final String DEPENDENCIES_MICCORE = "required-after:micdoodlecore; "; //Keep the space at the end!
@Deprecated
@ForRemoval(deadline = "4.1.0")
public static final String DEPENDENCIES_MODS = "after:ic2; after:tconstruct; after:mantle;";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLFingerprintViolationEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLInterModComms;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
Expand All @@ -194,15 +195,14 @@
import net.minecraftforge.server.permission.DefaultPermissionLevel;
import net.minecraftforge.server.permission.PermissionAPI;

//@formatter:off
@Mod(modid = Constants.MOD_ID_CORE,
name = GalacticraftCore.NAME,
version = Constants.VERSION,
dependencies = "required-after:forge@[14.23.5.2860,);",
useMetadata = true,
acceptedMinecraftVersions = "[1.12, 1.13)",
guiFactory = "micdoodle8.mods.galacticraft.core.client.gui.screen.ConfigGuiFactoryCore")
//@formatter:on
guiFactory = "micdoodle8.mods.galacticraft.core.client.gui.screen.ConfigGuiFactoryCore",
certificateFingerprint = Constants.FINGERPRINT)
public class GalacticraftCore
{

Expand Down Expand Up @@ -259,6 +259,13 @@ public GalacticraftCore()
FluidRegistry.enableUniversalBucket();
}

@EventHandler
public void onFingerprintViolation(FMLFingerprintViolationEvent event)
{
if (!GCCoreUtil.isDeobfuscated())
logger.warn("Invalid fingerprint detected! The file " + event.getSource().getName() + " may have been tampered with. This version will NOT be supported by the author!");
}

@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
Expand Down
Loading

0 comments on commit a28a706

Please sign in to comment.