Skip to content

Commit 3d9ad6b

Browse files
committed
Fix docFxZip archive naming to use original source file name
- Store original source file name before updating to docfx.json - Use original source file name for zip archive base name - Allows override via archiveBaseName property on docFxZip task - Results in: {originalSourceFileName}-docfx.zip format
1 parent b336100 commit 3d9ad6b

File tree

5 files changed

+61
-12
lines changed

5 files changed

+61
-12
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# gradle-docfx-plugin changelog
22

3+
## 0.1.0
4+
5+
### Fixed
6+
* **Fixed docFxZip archive naming**: Zip archive now uses the original source file name (e.g., `inetsoftware.Reporting.dll`) instead of the generated `docfx.json` filename
7+
* Archive name format: `{originalSourceFileName}-docfx.zip` (e.g., `inetsoftware.Reporting.dll-docfx.zip`)
8+
* Users can override by setting `archiveBaseName` on the `docFxZip` task in `build.gradle`
9+
* This ensures consistent artifact naming that matches the source assembly
10+
311
## 0.0.9
412

513
### Added

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = 0.1.0-SNAPSHOT
1+
version = 0.1.0

src/main/groovy/de/inetsoftware/docfx/DocFxPlugin.groovy

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,30 +82,62 @@ class DocFxPlugin implements Plugin<Project> {
8282
into "/"
8383
}
8484

85-
// Set archive base name from source file name
86-
def baseName = sourceFile.name
87-
if (baseName.endsWith('.json')) {
88-
baseName = baseName.substring(0, baseName.length() - 5)
89-
}
85+
// Set archive base name from original source file name (if available)
86+
// This allows the zip to be named after the original source (e.g., inetsoftware.Reporting.dll)
87+
// instead of the generated docfx.json file
88+
// User can override this by setting archiveBaseName on docFxZip task in build.gradle
89+
def baseName = null
9090

91-
// Set archiveBaseName (works for both Gradle 8 and 9)
91+
// Check if user has already set archiveBaseName
92+
def currentBaseName = null
9293
try {
9394
if (zipTask.hasProperty('archiveBaseName')) {
9495
def prop = zipTask.archiveBaseName
9596
if (prop instanceof org.gradle.api.provider.Property) {
9697
// Gradle 9+ - Property API
97-
if (!prop.isPresent() || prop.get() == project.name) {
98-
prop.set(baseName)
98+
if (prop.isPresent()) {
99+
currentBaseName = prop.get()
99100
}
100101
} else {
101102
// Gradle 8 - direct property
102-
if (prop == null || prop == project.name) {
103+
currentBaseName = prop
104+
}
105+
}
106+
} catch (Exception e) {
107+
// Ignore
108+
}
109+
110+
// Only set archiveBaseName if user hasn't set it and it's still the default (project.name)
111+
if (currentBaseName == null || currentBaseName == project.name) {
112+
// Use original source file name if available (stored before docFx updated extension.source)
113+
if (extension.originalSourceFileName != null && !extension.originalSourceFileName.trim().isEmpty()) {
114+
baseName = extension.originalSourceFileName
115+
project.logger.debug("docFxZip: Using original source file name for archive: ${baseName}")
116+
} else {
117+
// Fallback to current source file name (docfx.json)
118+
baseName = sourceFile.name
119+
if (baseName.endsWith('.json')) {
120+
baseName = baseName.substring(0, baseName.length() - 5)
121+
}
122+
}
123+
124+
// Set archiveBaseName (works for both Gradle 8 and 9)
125+
try {
126+
if (zipTask.hasProperty('archiveBaseName')) {
127+
def prop = zipTask.archiveBaseName
128+
if (prop instanceof org.gradle.api.provider.Property) {
129+
// Gradle 9+ - Property API
130+
prop.set(baseName)
131+
} else {
132+
// Gradle 8 - direct property
103133
zipTask.archiveBaseName = baseName
104134
}
105135
}
136+
} catch (Exception e) {
137+
project.logger.debug("Could not set archiveBaseName: ${e.message}")
106138
}
107-
} catch (Exception e) {
108-
project.logger.debug("Could not set archiveBaseName: ${e.message}")
139+
} else {
140+
project.logger.debug("docFxZip: Using user-configured archiveBaseName: ${currentBaseName}")
109141
}
110142

111143
// Configure inputs/outputs for up-to-date checking

src/main/groovy/de/inetsoftware/docfx/DocfxExtension.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ class DocfxExtension {
1515
Map<String, String> environment = [:]
1616
Closure additionalResources = null
1717

18+
// Internal: stores original source file name before it's updated to docfx.json
19+
// Used by zip task to name the archive based on original source (e.g., inetsoftware.Reporting.dll)
20+
String originalSourceFileName = null
21+
1822
// DocFX configuration options for auto-generated docfx.json
1923
String template = "statictoc"
2024
String markdownEngine = "markdig"

src/main/groovy/de/inetsoftware/docfx/Docs.groovy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ class Docs extends DocfxDefaultTask {
3535
return
3636
}
3737

38+
// Store original source file name for zip task naming (before we update extension.source)
39+
// This allows the zip task to use the original file name (e.g., inetsoftware.Reporting.dll)
40+
// instead of the generated docfx.json name
41+
extension.originalSourceFileName = sourceFile.name
42+
3843
// Auto-generate docfx.json if source is not a JSON file
3944
File docfxJsonFile
4045
if (!extension.isSourceJsonFile()) {

0 commit comments

Comments
 (0)