use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.
the class ContentControllerTest method detectHtml_SingleHtmlElementLineWithPrecedingWhitespace.
@Test
public void detectHtml_SingleHtmlElementLineWithPrecedingWhitespace() throws Exception {
final ConcreteResource res = new ConcreteResource(new SimpleLocation("test:uri"), "file.html");
final Transfer tx = fixture.getCache().getTransfer(res);
PrintWriter writer = null;
try {
writer = new PrintWriter(new OutputStreamWriter(tx.openOutputStream(TransferOperation.GENERATE)));
writer.print(" <html>");
writer.flush();
} finally {
IOUtils.closeQuietly(writer);
}
assertThat(content.isHtmlContent(tx), equalTo(true));
}
use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.
the class ContentController method renderListing.
public String renderListing(final String acceptHeader, final StoreKey key, final String requestPath, final String serviceUrl, final UriFormatter uriFormatter) throws IndyWorkflowException {
String path = requestPath;
if (path.endsWith(LISTING_HTML_FILE)) {
path = normalize(parentPath(path));
}
final List<StoreResource> listed = getListing(key, path);
if (ApplicationContent.application_json.equals(acceptHeader)) {
final DirectoryListingDTO dto = new DirectoryListingDTO(StoreResource.convertToEntries(listed));
try {
return mapper.writeValueAsString(dto);
} catch (final JsonProcessingException e) {
throw new IndyWorkflowException("Failed to render listing to JSON: %s. Reason: %s", e, dto, e.getMessage());
}
}
final Map<String, Set<String>> listingUrls = new TreeMap<>();
final String storeUrl = uriFormatter.formatAbsolutePathTo(serviceUrl, key.getType().singularEndpointName(), key.getName());
if (listed != null) {
// second pass, process the remainder.
for (int pass = 0; pass < 2; pass++) {
for (final ConcreteResource res : listed) {
String p = res.getPath();
if (pass == 0 && !p.endsWith("/")) {
continue;
} else if (pass == 1) {
if (!p.endsWith("/")) {
final String dirpath = p + "/";
if (listingUrls.containsKey(normalize(storeUrl, dirpath))) {
p = dirpath;
}
} else {
continue;
}
}
final String localUrl = normalize(storeUrl, p);
Set<String> sources = listingUrls.get(localUrl);
if (sources == null) {
sources = new HashSet<>();
listingUrls.put(localUrl, sources);
}
sources.add(normalize(res.getLocationUri(), res.getPath()));
}
}
}
final List<String> sources = new ArrayList<>();
if (listed != null) {
for (final ConcreteResource res : listed) {
// KeyedLocation is all we use in Indy.
logger.debug("Formatting sources URL for: {}", res);
final KeyedLocation kl = (KeyedLocation) res.getLocation();
final String uri = uriFormatter.formatAbsolutePathTo(serviceUrl, kl.getKey().getType().singularEndpointName(), kl.getKey().getName());
if (!sources.contains(uri)) {
logger.debug("adding source URI: '{}'", uri);
sources.add(uri);
}
}
}
Collections.sort(sources);
String parentPath = normalize(parentPath(path));
if (!parentPath.endsWith("/")) {
parentPath += "/";
}
final String parentUrl;
if (parentPath.equals(path)) {
parentPath = null;
parentUrl = null;
} else {
parentUrl = uriFormatter.formatAbsolutePathTo(serviceUrl, key.getType().singularEndpointName(), key.getName(), parentPath);
}
final Map<String, Object> params = new HashMap<>();
params.put("items", listingUrls);
params.put("parentUrl", parentUrl);
params.put("parentPath", parentPath);
params.put("path", path);
params.put("storeKey", key);
params.put("storeUrl", storeUrl);
params.put("baseUrl", serviceUrl);
params.put("sources", sources);
// render...
try {
return templates.render(acceptHeader, "directory-listing", params);
} catch (final IndyGroovyException e) {
throw new IndyWorkflowException(e.getMessage(), e);
}
}
use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.
the class DefaultDownloadManager method getStorageReference.
@Override
public Transfer getStorageReference(final ArtifactStore store, final String... path) {
Logger logger = LoggerFactory.getLogger(getClass());
logger.trace("Retrieving cache reference (Transfer) to: {} in: {}", Arrays.asList(path), store.getKey());
return transfers.getCacheReference(new ConcreteResource(LocationUtils.toLocation(store), path));
}
use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.
the class DefaultDownloadManager method store.
/*
* (non-Javadoc)
* @see org.commonjava.indy.core.rest.util.FileManager#upload(org.commonjava.indy.core.model.DeployPoint,
* java.lang.String, java.io.InputStream)
*/
@Override
public Transfer store(final ArtifactStore store, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
if (store.getKey().getType() == StoreType.group) {
//FIXME: Why is this null? Investigate.
return null;
}
if (store.getKey().getType() != StoreType.hosted) {
throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Cannot deploy to non-deploy point artifact store: {}.", store.getKey());
}
if (storeManager.isReadonly(store)) {
throw new IndyWorkflowException(ApplicationStatus.METHOD_NOT_ALLOWED.code(), "The store {} is readonly. If you want to store any content to this store, please modify it to non-readonly", store.getKey());
}
if (store instanceof HostedRepository) {
final HostedRepository deploy = (HostedRepository) store;
// final ArtifactPathInfo pathInfo = ArtifactPathInfo.parse( path );
final ContentQuality quality = getQuality(path);
if (quality != null && quality == ContentQuality.SNAPSHOT) {
if (!deploy.isAllowSnapshots()) {
logger.error("Cannot store snapshot in non-snapshot deploy point: {}", deploy.getName());
throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Cannot store snapshot in non-snapshot deploy point: {}", deploy.getName());
}
} else if (!deploy.isAllowReleases()) {
logger.error("Cannot store release in snapshot-only deploy point: {}", deploy.getName());
throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Cannot store release in snapshot-only deploy point: {}", deploy.getName());
}
}
try {
return transfers.store(new ConcreteResource(LocationUtils.toLocation(store), path), stream, eventMetadata);
} catch (final BadGatewayException e) {
Location location = e.getLocation();
KeyedLocation kl = (KeyedLocation) location;
fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
logger.warn("Bad gateway: " + e.getMessage(), e);
throw new IndyWorkflowException("Failed to store path: {} in: {}. Reason: {}", e, path, store, e.getMessage());
} catch (final TransferTimeoutException e) {
Location location = e.getLocation();
KeyedLocation kl = (KeyedLocation) location;
fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
logger.warn("Timeout: " + e.getMessage(), e);
throw new IndyWorkflowException("Failed to store path: {} in: {}. Reason: {}", e, path, store, e.getMessage());
} catch (final TransferLocationException e) {
Location location = e.getLocation();
KeyedLocation kl = (KeyedLocation) location;
fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
logger.warn("Location Error: " + e.getMessage(), e);
throw new IndyWorkflowException("Failed to store path: {} in: {}. Reason: {}", e, path, store, e.getMessage());
} catch (TransferException e) {
logger.error(String.format("Failed to store: %s in: %s. Reason: %s", path, store.getKey(), e.getMessage()), e);
throw new IndyWorkflowException("Failed to store: %s in: %s. Reason: %s", e, path, store.getKey(), e.getMessage());
}
}
use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.
the class AbstractMergedContentGenerator method clearMergedFile.
protected void clearMergedFile(final Group group, final String path) {
try {
// delete so it'll be recomputed.
final Transfer target = fileManager.getTransfer(group, path);
if (target.exists()) {
logger.debug("Deleting merged file: {}", target);
target.delete(false);
if (target.exists()) {
logger.error("\n\n\n\nDID NOT DELETE merged metadata file at: {} in group: {}\n\n\n\n", path, group.getName());
}
helper.deleteChecksumsAndMergeInfo(group, path);
} else {
ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(group), path);
nfc.clearMissing(resource);
}
} catch (final IndyWorkflowException | IOException e) {
logger.error("Failed to delete generated file (to allow re-generation on demand: {}/{}. Error: {}", e, group.getKey(), path, e.getMessage());
}
}
Aggregations