Skip to content

Commit 4a6167b

Browse files
author
mtctx
committed
release(2.0.0): Not a Publishing wrapper anymore, only for "securely" saving and loading credentials
1 parent 9360b8b commit 4a6167b

File tree

10 files changed

+170
-753
lines changed

10 files changed

+170
-753
lines changed

build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@ plugins {
2525
}
2626

2727
group = "dev.mtctx.unipub"
28-
version = "1.0.16"
28+
version = "2.0.0"
2929

3030
repositories {
3131
mavenCentral()
3232
gradlePluginPortal()
3333
}
3434

3535
dependencies {
36+
implementation("com.squareup.okio:okio:3.16.0")
3637
implementation("com.charleskorn.kaml:kaml:0.95.0")
37-
testImplementation(kotlin("test"))
3838
}
3939

4040
gradlePlugin {
4141
website = "https://github.com/mtctx/UniPub"
4242
vcsUrl = "https://github.com/mtctx/UniPub.git"
4343

4444
plugins {
45-
create("unipub") {
45+
register("unipub") {
4646
id = "dev.mtctx.unipub"
4747
displayName = "UniPub"
4848
description = "A Gradle plugin for publishing to Maven Repositories."
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* UniPub: GenerateSettingsTemplateTasks.kt
3+
* Copyright (C) 2025 mtctx
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package dev.mtctx.unipub
20+
21+
import com.charleskorn.kaml.Yaml
22+
import okio.Path
23+
import okio.Path.Companion.toPath
24+
import okio.buffer
25+
import org.gradle.api.DefaultTask
26+
import org.gradle.api.tasks.Input
27+
import org.gradle.api.tasks.TaskAction
28+
29+
open class UniPubGenerateTemplateUniPubInProjectDirTask : UniPubGenerateTemplateUniPubTask() {
30+
override fun file(): Path = projectPath(project.projectDir.absolutePath)
31+
32+
@TaskAction
33+
override fun run() {
34+
super.run()
35+
val gitignore = fs
36+
.canonicalize(project.projectDir.absolutePath.toPath())
37+
.resolve(".gitignore")
38+
39+
val entry = file().name
40+
41+
if (!fs.exists(gitignore)) {
42+
fs.write(gitignore) {
43+
writeUtf8(entry)
44+
writeUtf8("\n")
45+
}
46+
return
47+
}
48+
49+
val content = fs.read(gitignore) { readUtf8() }
50+
if (!content.contains(entry)) {
51+
fs.appendingSink(gitignore).buffer().use {
52+
it.writeUtf8("\n")
53+
it.writeUtf8(entry)
54+
}
55+
}
56+
}
57+
58+
}
59+
60+
open class UniPubGenerateTemplateUniPubInHomeDirTask : UniPubGenerateTemplateUniPubTask() {
61+
override fun file(): Path = globalPath
62+
}
63+
64+
abstract class UniPubGenerateTemplateUniPubTask : DefaultTask() {
65+
@Input
66+
var profileName: String = "main"
67+
68+
@Input
69+
var overwrite: Boolean = false
70+
71+
abstract fun file(): Path
72+
73+
@TaskAction
74+
open fun run() {
75+
var settingsYaml = Yaml.default.encodeToString(
76+
UniPubSettings.serializer(), UniPubSettings(
77+
profiles = listOf(
78+
UniPubSettings.Profile(
79+
"primary # Can be anything you want",
80+
"YOUR_USERNAME",
81+
"YOUR_PASSWORD"
82+
),
83+
UniPubSettings.Profile(
84+
"secondary",
85+
"YOUR_USERNAME",
86+
"YOUR_PASSWORD"
87+
)
88+
)
89+
)
90+
)
91+
92+
settingsYaml = """
93+
# You can customize the settings file for UniPub here.
94+
# You can use ENV(VARIABLE_NAME) to refer to environment variables.
95+
96+
$settingsYaml
97+
""".trimIndent()
98+
99+
val file = file()
100+
if (fs.exists(file) && !overwrite) {
101+
logger.lifecycle("Settings file already exists at $file. Use '-Poverwrite=true' to overwrite it.")
102+
return
103+
}
104+
105+
fs.write(file) {
106+
writeUtf8(settingsYaml)
107+
}
108+
logger.lifecycle("Settings file generated at $file")
109+
}
110+
}

src/main/kotlin/dev/mtctx/unipub/Info.kt

Lines changed: 0 additions & 75 deletions
This file was deleted.

src/main/kotlin/dev/mtctx/unipub/License.kt

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)