diff --git a/README.md b/README.md index 3ef46b1..e05a278 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,19 @@ Then, add this dependency to the `build.gradle` file in app directory. ```gradle dependencies { - implementation "com.github.ivanisidrowu:KtRssReader:v2.0.0" + implementation "com.github.ivanisidrowu.KtRssReader:ktRssReader:v2.0.0" +} +``` + +If you want to customize data format, you have to add these dependencies. + +```gradle +apply plugin: 'kotlin-kapt' + +dependencies { + implementation "com.github.ivanisidrowu.KtRssReader:ktRssReader:v2.0.0" + implementation "com.github.ivanisidrowu.KtRssReader:annotation:v2.0.0" + kapt "com.github.ivanisidrowu.KtRssReader:processor:v2.0.0" } ``` diff --git a/build.gradle b/build.gradle index f98f28d..ea06b85 100644 --- a/build.gradle +++ b/build.gradle @@ -32,6 +32,7 @@ buildscript { dependencies { classpath "com.android.tools.build:gradle:4.0.1" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -45,6 +46,25 @@ allprojects { } } +subprojects { project -> + if (project.name == 'annotation' || project.name == 'processor') { + apply plugin: 'java' + apply plugin: 'maven' + + sourceCompatibility = 1.8 // java 8 + targetCompatibility = 1.8 + + task sourcesJar(type: Jar, dependsOn: classes) { + classifier = 'sources' + from sourceSets.main.allSource + } + + artifacts { + archives sourcesJar + } + } +} + task clean(type: Delete) { delete rootProject.buildDir } \ No newline at end of file diff --git a/ktRssReader/build.gradle b/ktRssReader/build.gradle index 943bef3..9f8fcff 100644 --- a/ktRssReader/build.gradle +++ b/ktRssReader/build.gradle @@ -2,6 +2,9 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' +apply plugin: 'com.github.dcendents.android-maven' + +group='com.github.ivanisidrowu' android { compileSdkVersion 30 diff --git a/processor/src/main/java/tw/ktrssreader/processor/generator/ParserGenerator.kt b/processor/src/main/java/tw/ktrssreader/processor/generator/ParserGenerator.kt index c406118..31c5242 100644 --- a/processor/src/main/java/tw/ktrssreader/processor/generator/ParserGenerator.kt +++ b/processor/src/main/java/tw/ktrssreader/processor/generator/ParserGenerator.kt @@ -136,7 +136,11 @@ class ParserGenerator( funSpec.addStatement("\nreturn $outputClassName(") // Generate constructor statements - propertyToParseData.forEach { generateConstructor(it, funSpec) } + var index = 0 + propertyToParseData.forEach { + generateConstructor(it, funSpec, index == propertyToParseData.size - 1) + index ++ + } funSpec.addStatement("$TAB)") return funSpec.build() @@ -343,7 +347,8 @@ class ParserGenerator( private fun generateConstructor( parseData: Map.Entry, - funSpec: FunSpec.Builder + funSpec: FunSpec.Builder, + isLastLine: Boolean ) { val stringBuilder = StringBuilder() val dataType = parseData.value.dataType @@ -377,7 +382,12 @@ class ParserGenerator( } } } - funSpec.addStatement("$TAB$TAB${parseData.key} = $stringBuilder,") + + if (isLastLine) { + funSpec.addStatement("$TAB$TAB${parseData.key} = $stringBuilder") + } else { + funSpec.addStatement("$TAB$TAB${parseData.key} = $stringBuilder,") + } } private fun getTagCandidates( diff --git a/processor/src/main/java/tw/ktrssreader/processor/generator/ReaderGenerator.kt b/processor/src/main/java/tw/ktrssreader/processor/generator/ReaderGenerator.kt index ecbb35a..61ed9e9 100644 --- a/processor/src/main/java/tw/ktrssreader/processor/generator/ReaderGenerator.kt +++ b/processor/src/main/java/tw/ktrssreader/processor/generator/ReaderGenerator.kt @@ -65,7 +65,7 @@ class ReaderGenerator( .addParameter(configParameter.build()) .addModifiers(KModifier.INLINE) .addCode( - "return %T.read<%T>(url = $URL, customParser = { xml -> %T.parse(xml) }, $CONFIG)", + "return %T.read<%T>(url = $URL, customParser = { xml -> %T.parse(xml) }, config = $CONFIG)", readerClassName, outputClassName, parserClassName @@ -85,7 +85,7 @@ class ReaderGenerator( ) .addModifiers(KModifier.INLINE) .addStatement( - "return %T.flowRead<%T>(url = $URL, customParser = { xml -> %T.parse(xml) }, $CONFIG)", + "return %T.flowRead<%T>(url = $URL, customParser = { xml -> %T.parse(xml) }, config = $CONFIG)", readerClassName, outputClassName, parserClassName @@ -104,7 +104,7 @@ class ReaderGenerator( ) .addModifiers(KModifier.INLINE, KModifier.SUSPEND) .addStatement( - "return %T.coRead<%T>(url = $URL, customParser = { xml -> %T.parse(xml) }, $CONFIG)", + "return %T.coRead<%T>(url = $URL, customParser = { xml -> %T.parse(xml) }, config = $CONFIG)", readerClassName, outputClassName, parserClassName