Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
linisme committed Dec 5, 2017
1 parent 3133d23 commit 4dc1e4b
Show file tree
Hide file tree
Showing 50 changed files with 1,089 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ captures/
.idea/gradle.xml
.idea/dictionaries
.idea/libraries
.idea/modules.xml

# Keystore files
*.jks
Expand Down
6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'


// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
1 change: 1 addition & 0 deletions buildSrc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
9 changes: 9 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apply plugin: 'groovy'

dependencies {
implementation gradleApi()
implementation localGroovy()
}

sourceCompatibility = "1.8"
targetCompatibility = "1.8"
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.idik.lib.cipher.so.extension

import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project

class CipherSoExt {

NamedDomainObjectContainer<KeyExt> keys


CipherSoExt(Project project) {
keys = project.container(KeyExt)
}

def keys(Closure closure) {
keys.configure closure
}


@Override
public String toString() {
return "CipherSoExt{" +
"keys=" + keys +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.idik.lib.cipher.so.extension

class KeyExt {
String name
String value

public KeyExt(String name) {
this.name = name
}

@Override
public String toString() {
return "KeyExt{" +
"name='" + name + '\'' +
", value='" + value + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.idik.lib.cipher.so.plugin

import net.idik.lib.cipher.so.extension.CipherSoExt
import net.idik.lib.cipher.so.task.GenerateCipherSoHeaderTask
import org.gradle.api.Plugin
import org.gradle.api.Project

class CipherSoPlugin implements Plugin<Project> {

@Override
void apply(Project project) {

project.extensions.add("cipher", new CipherSoExt(project))
project.tasks.create("printKey", GenerateCipherSoHeaderTask)

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package net.idik.lib.cipher.so.task

import net.idik.lib.cipher.so.extension.CipherSoExt
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction

class GenerateCipherSoHeaderTask extends DefaultTask {

public static final String TARGET_FILE_NAME = "extension_keys.h"
private File targetFile

GenerateCipherSoHeaderTask() {
group = 'cipher.so'
targetFile = findTargetNativeFile(project.buildDir)
}

@TaskAction
void generate() {
def keyContainer = project.cipher as CipherSoExt
def writer = new FileWriter(targetFile)
new SoHeaderBuilder(TARGET_FILE_NAME, keyContainer.keys.asList()).build().each {
writer.append(it)
}
writer.flush()
writer.close()
}

private File findTargetNativeFile(File rootFile) {
File dir = new File(rootFile, "cipher.so/include/main/cpp")
if (!dir.exists()) {
dir.mkdirs()
}
return new File(dir, TARGET_FILE_NAME)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.idik.lib.cipher.so.task

import net.idik.lib.cipher.so.extension.KeyExt

class SoHeaderBuilder {

List<KeyExt> keys

String fileName

SoHeaderBuilder(String fileName, List<KeyExt> keys) {
this.fileName = fileName
this.keys = keys
}

List<String> build() {
List<String> lines = new ArrayList<>()
lines.add("// Auto-Generated By Cipher.so - 林帅斌 [email protected]\n\n")
lines.add("#ifndef CIPHER_EXTENSION_KEY_${fileName.replaceAll("\\.","_").toUpperCase(Locale.US)}\n")
lines.add("#defind CIPHER_EXTENSION_KEY_${fileName.replaceAll("\\.","_").toUpperCase(Locale.US)}\n")
keys.each {
lines.add("const char* KEY_${it.name} = \"${it.value}\";\n")
}
lines.add("\n")
lines.add("#endif //CIPHER_EXTENSION_KEY_${fileName.replaceAll("\\.","_").toUpperCase(Locale.US)}\n")
lines
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
implementation-class=net.idik.lib.cipher.so.plugin.CipherSoPlugin
17 changes: 17 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Tue Dec 05 19:48:22 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
Loading

0 comments on commit 4dc1e4b

Please sign in to comment.