-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom XInclude attributes and resolution mechanisms (#1097)
* Support `includeIf` and `includeUnless` in XInclude * Resolve XIncludes in META-INF and resource roots * Require a system property enabled to allow conditional XInclude
- Loading branch information
Showing
28 changed files
with
512 additions
and
7 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...c/main/java/com/jetbrains/plugin/structure/intellij/xinclude/XIncludeResourceResolvers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.jetbrains.plugin.structure.intellij.xinclude | ||
|
||
import com.jetbrains.plugin.structure.intellij.resources.ResourceResolver | ||
import com.jetbrains.plugin.structure.jar.META_INF | ||
import java.nio.file.FileSystems | ||
import java.nio.file.Path | ||
|
||
/** | ||
* Resolves a resource not only in the relative path, but also in the `META-INF` subdirectory. | ||
* | ||
* This is used to resolve plugin descriptors that are scattered across resource roots and `META-INF` | ||
* directories, while XIncluding each other. | ||
*/ | ||
class MetaInfResourceResolver(private val delegateResolver: ResourceResolver) : ResourceResolver { | ||
override fun resolveResource(relativePath: String, basePath: Path): ResourceResolver.Result { | ||
val parentPath = getParent(basePath) ?: return ResourceResolver.Result.NotFound | ||
return delegateResolver.resolveResource(relativePath, parentPath.resolve(META_INF).resolve(relativePath)) | ||
} | ||
|
||
private fun getParent(path: Path): Path? { | ||
val parent: Path? = path.parent | ||
return if (parent == null && path.fileSystem != FileSystems.getDefault()) { | ||
path.fileSystem.rootDirectories.first() | ||
} else { | ||
parent | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Resolves a resource not only in the base path, but also in the parent directory. | ||
* | ||
* This is used to resolve a XIncluded resource placed in the root directory being referenced | ||
* from the `META-INF` directory. | ||
* | ||
*/ | ||
class InParentPathResourceResolver(private val delegateResolver: ResourceResolver) : ResourceResolver { | ||
override fun resolveResource(relativePath: String, basePath: Path): ResourceResolver.Result { | ||
val parentPath: Path = basePath.parent ?: return ResourceResolver.Result.NotFound | ||
return delegateResolver.resolveResource(relativePath, parentPath) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.