-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1318 from BladeRunnerJS/out-of-scope-exception-12…
…32+565 OutOfScopeExceptions that list the scope and stricter enforcement so Blades cant depend on Blades in the Aspect scope
- Loading branch information
Showing
24 changed files
with
373 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
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
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
39 changes: 39 additions & 0 deletions
39
...main/java/org/bladerunnerjs/api/model/exception/OutOfBundleScopeRequirePathException.java
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,39 @@ | ||
package org.bladerunnerjs.api.model.exception; | ||
|
||
import org.bladerunnerjs.api.Asset; | ||
import org.bladerunnerjs.api.BundlableNode; | ||
import org.bladerunnerjs.api.LinkedAsset; | ||
|
||
public class OutOfBundleScopeRequirePathException extends RequirePathException { | ||
|
||
private static final long serialVersionUID = 1L; | ||
private String requirePath; | ||
private String scopedLocations; | ||
private Asset asset; | ||
private BundlableNode bundlableNode; | ||
private Asset assetWithException = null; | ||
|
||
public OutOfBundleScopeRequirePathException(BundlableNode bundlableNode, String requirePath, Asset asset) { | ||
this.bundlableNode = bundlableNode; | ||
this.requirePath = requirePath; | ||
this.asset = asset; | ||
scopedLocations = RequirePathExceptionUtils.getScopeLocationText(bundlableNode); | ||
} | ||
|
||
public void setAssetWithException(LinkedAsset asset) { | ||
assetWithException = asset; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
if (assetWithException != null) { | ||
return String.format("There was an exception calculating dependencies for the asset at '%s'. It's dependency with the require path '%s' was found at '%s', but it was not in one of the valid bundler scopes."+ | ||
" The bundlable node was '%s' and the valid locations for assets in this scope are '%s'", | ||
assetWithException.getAssetPath(), requirePath, asset.getAssetPath(), bundlableNode.getClass().getSimpleName(), scopedLocations); | ||
} | ||
return String.format("The asset with the require path '%s' was found at '%s', but it was not in one of the valid bundler scopes."+ | ||
" The bundlable node was '%s' and the valid locations for assets in this scope are '%s'", | ||
requirePath, asset.getAssetPath(), bundlableNode.getClass().getSimpleName(), scopedLocations); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...e/src/main/java/org/bladerunnerjs/api/model/exception/OutOfScopeRequirePathException.java
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,31 @@ | ||
package org.bladerunnerjs.api.model.exception; | ||
|
||
import org.bladerunnerjs.api.Asset; | ||
import org.bladerunnerjs.api.LinkedAsset; | ||
|
||
|
||
public class OutOfScopeRequirePathException extends RequirePathException | ||
{ | ||
private static final long serialVersionUID = 4008632015949516509L; | ||
private LinkedAsset sourceAsset; | ||
private Asset dependantAsset; | ||
private String scopedLocations; | ||
|
||
public OutOfScopeRequirePathException(LinkedAsset sourceAsset, Asset dependantAsset) { | ||
this.sourceAsset = sourceAsset; | ||
this.dependantAsset = dependantAsset; | ||
scopedLocations = RequirePathExceptionUtils.getScopeLocationText(sourceAsset.assetContainer()); | ||
} | ||
|
||
@Override | ||
public String getMessage() | ||
{ | ||
return String.format( | ||
"The asset with the primary require path '%s' has a dependency on the asset with the primary require path '%s',"+ | ||
" which is located at '%s' and is outside of the assets' scope."+ | ||
" The source asset is contained within the '%s' scope and can only depend on the assets in the following locations: '%s'.", | ||
sourceAsset.getPrimaryRequirePath(), dependantAsset.getPrimaryRequirePath(), dependantAsset.getAssetPath(), | ||
sourceAsset.assetContainer().getClass().getSimpleName(), scopedLocations); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
brjs-core/src/main/java/org/bladerunnerjs/api/model/exception/RequirePathExceptionUtils.java
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,22 @@ | ||
package org.bladerunnerjs.api.model.exception; | ||
|
||
import org.bladerunnerjs.api.BRJS; | ||
import org.bladerunnerjs.model.AssetContainer; | ||
|
||
|
||
public class RequirePathExceptionUtils | ||
{ | ||
|
||
public static String getScopeLocationText(AssetContainer assetContainer) { | ||
BRJS brjs = assetContainer.root(); | ||
StringBuilder scopedLocationsBuilder = new StringBuilder(); | ||
for (AssetContainer scopeAssetContainer : assetContainer.scopeAssetContainers()) { | ||
if (scopedLocationsBuilder.length() > 0) { | ||
scopedLocationsBuilder.append(", "); | ||
} | ||
scopedLocationsBuilder.append( brjs.dir().getRelativePath(scopeAssetContainer.dir()) ); | ||
} | ||
return scopedLocationsBuilder.toString(); | ||
} | ||
|
||
} |
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
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
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.