if(assetPlugin.canHandleAsset(assetFile, assetLocation)) {
String assetFilePath = assetFile.getAbsolutePath();
if(!cachedAssets.containsKey(assetFilePath)) {
try {
Asset createdAsset = assetPlugin.createAsset(assetFile, assetLocation);
assetLocation.root().logger(this.getClass()).debug("creating new asset for the path '%s'",
createdAsset.getAssetPath());
String assetPrimaryRequirePath = createdAsset.getPrimaryRequirePath();
if (createdAsset instanceof SourceModule && createdAsset.assetLocation().assetContainer().isNamespaceEnforced()) {
String relativePathFromAssetContainer = RelativePathUtility.get(assetLocation.root().getFileInfoAccessor(), createdAsset.assetLocation().assetContainer().dir(), createdAsset.dir());
String relativeRequirePathPathFromAssetContainer = StringUtils.substringAfter(relativePathFromAssetContainer, "/"); // strip of 'src/' at the start of the relative path
String appRequirePrefix = assetLocation.assetContainer().app().getRequirePrefix();
String createdAssetContainerRequirePrefix = createdAsset.assetLocation().assetContainer().requirePrefix();
if (relativeRequirePathPathFromAssetContainer.startsWith(appRequirePrefix) && !relativeRequirePathPathFromAssetContainer.startsWith(createdAssetContainerRequirePrefix)) {
InvalidRequirePathException wrappedRequirePathException = new InvalidRequirePathException(
"The source module at '"+createdAsset.getAssetPath()+"' is in an invalid location. "+
"It's require path starts with the apps require prefix ('"+appRequirePrefix+"') which suggests it's require path is intended to be '"+createdAssetContainerRequirePrefix+"'. "+
"The require path defined by the source modules location is '"+relativeRequirePathPathFromAssetContainer+"'. Either it's package structure should be '"+createdAssetContainerRequirePrefix+"/*' or "+
"remove the folders '"+relativeRequirePathPathFromAssetContainer+"' to allow the require prefix to be calculated automatically.");
throw new RuntimeException(wrappedRequirePathException);
}
}
if (assetPrimaryRequirePath != null) {
assetLocation.root().logger(this.getClass()).debug("asset at '%s' is a '%s' and it's primary require path is '%s'",
createdAsset.getAssetPath(), createdAsset.getClass().getSimpleName(), assetPrimaryRequirePath);
} else {
assetLocation.root().logger(this.getClass()).debug("asset at '%s' is a '%s'",
createdAsset.getAssetPath(), createdAsset.getClass().getSimpleName());
}
cachedAssets.put(assetFilePath, createdAsset);
}
catch (AssetFileInstantationException e) {
throw new RuntimeException(e);
}
}
Asset asset = cachedAssets.get(assetFilePath);
if(asset instanceof SourceModule) {
assets.sourceModules.add((SourceModule) asset);
}
else if(asset instanceof LinkedAsset) {
assets.linkedAssets.add((LinkedAsset) asset);