Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the Gradle artifacts #56

Merged
merged 6 commits into from Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Expand Up @@ -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"
}
```

Expand Down
20 changes: 20 additions & 0 deletions build.gradle
Expand Up @@ -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
Expand All @@ -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
}
3 changes: 3 additions & 0 deletions ktRssReader/build.gradle
Expand Up @@ -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
Expand Down
Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用 propertyToParseData.lastIndex 取代 size - 1 如何?

index ++
}

funSpec.addStatement("$TAB)")
return funSpec.build()
Expand Down Expand Up @@ -343,7 +347,8 @@ class ParserGenerator(

private fun generateConstructor(
parseData: Map.Entry<String, ParseData>,
funSpec: FunSpec.Builder
funSpec: FunSpec.Builder,
isLastLine: Boolean
) {
val stringBuilder = StringBuilder()
val dataType = parseData.value.dataType
Expand Down Expand Up @@ -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(
Expand Down
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down