use of com.google.cloud.asset.v1.Asset in project tapestry-5 by apache.
the class ExternalUrlAssetFactory method createAsset.
@Override
public Asset createAsset(Resource resource) {
final URL url = resource.toURL();
Asset asset = cache.get(url);
if (asset == null) {
asset = new UrlAsset(url.toExternalForm(), resource);
cache.put(url, asset);
}
return asset;
}
use of com.google.cloud.asset.v1.Asset in project tapestry-5 by apache.
the class JavaScriptStackPathConstructorImpl method constructPathsForJavaScriptStack.
public List<String> constructPathsForJavaScriptStack(String stackName) {
JavaScriptStack stack = javascriptStackSource.getStack(stackName);
List<Asset> assets = stack.getJavaScriptLibraries();
// if there is more than one library asset, or any modules.
if (combineScripts && stack.getJavaScriptAggregationStrategy().enablesCombine()) {
boolean needsVirtual = (assets.size() > 1) || (!stack.getModules().isEmpty());
if (needsVirtual) {
return combinedStackURL(stackName, stack);
}
}
return toPaths(assets);
}
use of com.google.cloud.asset.v1.Asset in project tapestry-5 by apache.
the class CSSURLRewriter method replaceURLs.
/**
* Replaces any relative URLs in the content for the resource and returns the content with
* the URLs expanded.
*
* @param input
* content of the resource
* @param baseResource
* resource used to resolve relative URLs
* @return replacement content, or null if no relative URLs in the content
*/
private String replaceURLs(String input, Resource baseResource) {
boolean didReplace = false;
StringBuffer output = new StringBuffer(input.length());
Matcher matcher = urlPattern.matcher(input);
while (matcher.find()) {
// the string inside the quotes
String url = matcher.group(2);
// When the URL starts with a slash or a scheme (e.g. http: or data:) , there's no need
// to rewrite it (this is actually rare in Tapestry as you want to use relative URLs to
// leverage the asset pipeline.
Matcher completeURLMatcher = completeURLPattern.matcher(url);
boolean matchFound = completeURLMatcher.find();
boolean isAssetUrl = matchFound && "asset:".equals(completeURLMatcher.group(1));
if (matchFound && !isAssetUrl) {
String queryParameters = matcher.group(3);
if (queryParameters != null) {
url = url + queryParameters;
}
// This may normalize single quotes, or missing quotes, to double quotes, but is not
// considered a real change, since all such variations are valid.
appendReplacement(matcher, output, url);
continue;
}
if (isAssetUrl) {
// strip away the "asset:" prefix
url = url.substring(6);
}
Asset asset;
// TAP5-2656
try {
asset = assetSource.getAsset(baseResource, url, null);
} catch (AssetNotFoundException e) {
asset = null;
}
if (asset != null) {
String assetURL = asset.toClientURL();
String queryParameters = matcher.group(3);
if (queryParameters != null) {
assetURL += queryParameters;
}
appendReplacement(matcher, output, assetURL);
didReplace = true;
} else {
final String message = String.format("URL %s, referenced in file %s, doesn't exist.", url, baseResource.toURL(), baseResource);
if (strictCssUrlRewriting) {
throw new RuntimeException(message);
} else if (logger.isWarnEnabled()) {
logger.warn(message);
}
}
}
if (!didReplace) {
return null;
}
matcher.appendTail(output);
return output.toString();
}
use of com.google.cloud.asset.v1.Asset in project gapic-generator-java by googleapis.
the class AsyncListAssets method asyncListAssets.
public static void asyncListAssets() throws Exception {
// It may require modifications to work in your environment.
try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
ListAssetsRequest request = ListAssetsRequest.newBuilder().setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()).setReadTime(Timestamp.newBuilder().build()).addAllAssetTypes(new ArrayList<String>()).setContentType(ContentType.forNumber(0)).setPageSize(883849137).setPageToken("pageToken873572522").addAllRelationshipTypes(new ArrayList<String>()).build();
ApiFuture<Asset> future = assetServiceClient.listAssetsPagedCallable().futureCall(request);
// Do something.
for (Asset element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
}
use of com.google.cloud.asset.v1.Asset in project gapic-generator-java by googleapis.
the class AssetServiceClientTest method listAssetsTest.
@Test
public void listAssetsTest() throws Exception {
Asset responsesElement = Asset.newBuilder().build();
ListAssetsResponse expectedResponse = ListAssetsResponse.newBuilder().setNextPageToken("").addAllAssets(Arrays.asList(responsesElement)).build();
mockAssetService.addResponse(expectedResponse);
ResourceName parent = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]");
ListAssetsPagedResponse pagedListResponse = client.listAssets(parent);
List<Asset> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getAssetsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockAssetService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListAssetsRequest actualRequest = ((ListAssetsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations