Skip to content

Commit

Permalink
Merge pull request #17 from metaschema-framework/hotfix/windows-support
Browse files Browse the repository at this point in the history
handle windows paths better
  • Loading branch information
wandmagic authored Oct 15, 2024
2 parents e89e461 + cd1942f commit 22c03f3
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 49 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/windows-support.yml

This file was deleted.

8 changes: 8 additions & 0 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@
<artifactId>appassembler-maven-plugin</artifactId>
<version>2.1.0</version>
<executions>
<execution>
<id>generate-scripts</id>
<phase>package</phase>
<goals>
<goal>assemble</goal>
</goals>
</execution>
<execution>
<id>exec-oscal-server-windows</id>
<phase>package</phase>
Expand Down Expand Up @@ -169,6 +176,7 @@
<repositoryLayout>flat</repositoryLayout>
<repositoryName>lib</repositoryName>
<outputFileNameMapping>@{groupId}@.@{artifactId}@-@{version}@.@{extension}@</outputFileNameMapping>
<useWildcardClassPath>true</useWildcardClassPath>
<extraJvmArguments>-Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8</extraJvmArguments>
<projectArtifactFirstInClassPath>true</projectArtifactFirstInClassPath>
<includeConfigurationDirectoryInClasspath>false</includeConfigurationDirectoryInClasspath>
Expand Down
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,19 @@
<outputFileNameMapping>
@{groupId}@.@{artifactId}@-@{version}@.@{extension}@
</outputFileNameMapping>
<useWildcardClassPath>true</useWildcardClassPath>
<extraJvmArguments>-Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8</extraJvmArguments>
<projectArtifactFirstInClassPath>true</projectArtifactFirstInClassPath>
<includeConfigurationDirectoryInClasspath>false</includeConfigurationDirectoryInClasspath>
</configuration>
<executions>
<execution>
<id>generate-scripts</id>
<phase>package</phase>
<goals>
<goal>assemble</goal>
</goals>
</execution>
<execution>
<id>exec-oscal-server-windows</id>
<phase>package</phase>
Expand Down
7 changes: 7 additions & 0 deletions src/main/assembly/bin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
<exclude>org.eclipse.jdt:org.eclipse.jdt.annotation</exclude>
</excludes>
</dependencySet>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>false</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
Expand All @@ -45,6 +51,7 @@
<include>**/*</include>
</includes>
</fileSet>

</fileSets>
<containerDescriptorHandlers>
<containerDescriptorHandler>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,33 +92,45 @@ class OscalVerticle : CoroutineVerticle() {
.putHeader("Content-Type", "application/json")
.end(response.encode())
}

private fun processUrl(url: String): String {
return if (url.startsWith("file://")) {
try {
val uri = URI(url)
val path = when {
uri.authority != null -> {
// Remove the authority component
Paths.get(uri.authority + uri.path)
}
uri.path.startsWith("/") -> {
// Absolute path
Paths.get(uri.path)
}
else -> {
// Relative path
Paths.get(uri.path).toAbsolutePath()
logger.info("processUrl input: $url")

if (!url.startsWith("file://")) {
logger.info("processUrl output (unchanged): $url")
return url
}

try {
// Remove the "file://" prefix and decode the URL
val decodedPath = URLDecoder.decode(url.substring(7), StandardCharsets.UTF_8.name())

val result = when {
System.getProperty("os.name").toLowerCase().contains("win") -> {
// Windows-specific handling
if (decodedPath.startsWith("/")) {
// Absolute path with drive letter
decodedPath.substring(1).replace('/', '\\')
} else {
// UNC path or relative path
decodedPath.replace('/', '\\')
}
}
path.toString()
} catch (e: Exception) {
logger.error("Error processing file URL: $url", e)
url // Return original URL if processing fails
else -> {
// Unix-like systems
decodedPath
}
}
} else {
url

logger.info("processUrl output: $result")
return result
} catch (e: Exception) {
logger.error("Error processing file URL: $url", e)
logger.info("processUrl output (error case): $url")
return url
}
}

private fun handleValidateFileUpload(ctx: RoutingContext) {
logger.info("Handling file upload request!")
launch {
Expand Down

0 comments on commit 22c03f3

Please sign in to comment.