From fa6aea1abe254810e5e8b09dda23dfb584e71f6e Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Thu, 11 Jul 2019 19:49:04 +0100 Subject: [PATCH] attempt to produce an I2P plugin --- gradle.properties | 10 +++ plug/build.gradle | 122 ++++++++++++++++++++++++++ plug/templates/plugin.config.template | 14 +++ settings.gradle | 1 + webui/build.gradle | 5 ++ 5 files changed, 152 insertions(+) create mode 100644 plug/build.gradle create mode 100644 plug/templates/plugin.config.template diff --git a/gradle.properties b/gradle.properties index e5a804ca..ab24bb6b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,3 +8,13 @@ gorm.version=7.0.2.RELEASE sourceCompatibility=1.8 targetCompatibility=1.8 + +# plugin properties +author = zab@mail.i2p +signer = zab@mail.i2p +i2pVersion=0.9.41 +keystorePassword=changeit +websiteURL=http://muwire.i2p +updateURLsu3=http://muwire.i2p/MuWire.su3 + +pack200=true diff --git a/plug/build.gradle b/plug/build.gradle new file mode 100644 index 00000000..73c75ec9 --- /dev/null +++ b/plug/build.gradle @@ -0,0 +1,122 @@ +buildscript { + repositories { mavenCentral() } + dependencies { + classpath fileTree("../i2pjars") { include '*.jar' } + classpath 'gnu.getopt:java-getopt:1.0.13' + } +} + +apply plugin : 'java' + +dependencies { + compile project(":webui") +} + +def buildDir = new File("$buildDir") +def zipDir = new File(buildDir, "zip") +def libDir = new File(zipDir, "lib") +def consoleDir = new File(zipDir, "console") +def webAppDir = new File(consoleDir, "webapps") +def keystore = new File(System.getProperty("user.home")+"/.i2p-plugin-keys/plugin-su3-keystore.ks") + + +String libDirPath() { + def libDir = new File("$buildDir/zip/lib") + libDir.listFiles().stream().map({ + "\$PLUGIN/lib/" + it.getName() + }).collect(java.util.stream.Collectors.joining(',')) +} + +task pluginConfig { + doLast { + def binding = [ "version" : project.version + "-b" + project.buildNumber, + "author" : project.author, + "signer" : project.signer, + "websiteURL" : project.websiteURL, + "updateURLsu3" : project.updateURLsu3, + "i2pVersion" : project.i2pVersion ] + + def templateFile = new File("$projectDir/templates/plugin.config.template") + def engine = new groovy.text.SimpleTemplateEngine() + def output = engine.createTemplate(templateFile).make(binding) + + zipDir.mkdirs() + + def outputFile = new File(zipDir,"plugin.config") + outputFile.text = output + } +} + +task pluginDir { + dependsOn ':webui:assemble' + doLast { task -> + libDir.mkdirs() + def webapp = project(":webui") + def i2pjars = task.project.fileTree("../i2pjars").getFiles() + webapp.configurations.runtime.each { + if (!i2pjars.contains(it)) { + def dest = new File(libDir, it.getName()) + java.nio.file.Files.copy(it.toPath(), dest.toPath()) + } + } + + webAppDir.mkdirs() + def warFile = webapp.configurations.warArtifact.getAllArtifacts().file[0] + def dest = new File(webAppDir, "MuWire.war") + java.nio.file.Files.copy(warFile.toPath(), dest.toPath()) + "zip -d ${dest.toString()} *.jar".execute() + } +} + +task webappConfig { + doLast { + def cPath = "webapps.MuWire.classpath=" + libDirPath() + def webappConfig = new File(consoleDir, "webapps.config") + webappConfig.text = cPath + } +} + +task pack { + doLast { + if (project.pack200 == "true") { + libDir.listFiles().stream().filter( { it.getName().endsWith(".jar") } ).forEach { + println "packing $it" + def name = it.toString() + println "pack200 --no-gzip ${name}.pack $name".execute().text + it.delete() + } + } else { + println "pack200 disabled" + } + } +} + +task pluginZip(type: Zip) { + archiveFileName = "MuWire.zip" + destinationDirectory = buildDir + from zipDir +} + +task sign { + doLast { + def password = project.keystorePassword + if (password == "") { + println "enter your keystore password:" + def reader = new BufferedReader(new InputStreamReader(System.in)) + password = reader.readLine() + } + def su3args = [] + def version = project.version + "-b" + project.buildNumber + su3args << 'sign' << '-t' << '6' << '-c' << 'PLUGIN' << '-f' << '0' << '-p' << password << \ + "$buildDir/MuWire.zip".toString() << "$buildDir/MuWire.su3".toString() << \ + keystore.getAbsoluteFile().toString() << version << project.signer + println "now enter private key password for signer $project.signer" + net.i2p.crypto.SU3File.main(su3args.toArray(new String[0])) + } +} + +webappConfig.dependsOn pluginDir +pack.dependsOn webappConfig +pluginZip.dependsOn(webappConfig,pluginConfig,pack) +sign.dependsOn pluginZip +assemble.dependsOn sign diff --git a/plug/templates/plugin.config.template b/plug/templates/plugin.config.template new file mode 100644 index 00000000..b8f427bc --- /dev/null +++ b/plug/templates/plugin.config.template @@ -0,0 +1,14 @@ +name=MuWire +description=Easy Anonymous File-Sharing +license=GPLv3 +version=${version} +author=${author} +signer=${signer} +websiteURL=${websiteURL} +updateURL.su3=${updateURLsu3} +min-i2p-version=${i2pVersion} +min-java-version=1.8 +consoleLinkName=MuWire +consoleLinkTooltip=Anonymous File Sharing +consoleLinkURL=/MuWire +<% println "date="+System.currentTimeMillis() %> diff --git a/settings.gradle b/settings.gradle index 3884af17..5469cef6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -5,3 +5,4 @@ include 'core' include 'gui' include 'cli' include 'webui' +include 'plug' diff --git a/webui/build.gradle b/webui/build.gradle index cacfc045..08319899 100644 --- a/webui/build.gradle +++ b/webui/build.gradle @@ -30,6 +30,7 @@ configurations { runtimeClasspath { extendsFrom developmentOnly } + warArtifact } dependencies { @@ -102,3 +103,7 @@ assets { minifyJs = true minifyCss = true } + +artifacts { + warArtifact war +}