use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.
the class KojiContentManagerDecorator method retrieve.
@Override
@IndyMetrics(measure = @Measure(timers = @MetricNamed(name = IndyMetricsKojiNames.METHOD_CONTENTMANAGER_RETRIEVE + IndyMetricsNames.TIMER), meters = @MetricNamed(name = IndyMetricsKojiNames.METHOD_CONTENTMANAGER_RETRIEVE + IndyMetricsNames.METER)))
public Transfer retrieve(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
logger.info("KOJI: Delegating initial retrieval attempt for: {}/{}", store.getKey(), path);
Transfer result = delegate.retrieve(store, path, eventMetadata);
if (result == null && StoreType.group == store.getKey().getType()) {
logger.info("KOJI: Checking for Koji build matching: {}", path);
Group group = (Group) store;
RemoteRepository kojiProxy = findKojiBuildAnd(store, path, eventMetadata, null, this::createRemoteRepository);
if (kojiProxy != null) {
adjustTargetGroup(kojiProxy, group);
result = delegate.retrieve(kojiProxy, path, eventMetadata);
}
if (result != null) {
nfc.clearMissing(new ConcreteResource(LocationUtils.toLocation(store), path));
}
}
// Finally, pass the Transfer back.
return result;
}
use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.
the class ImpliedRepositoryDetector method initJob.
private boolean initJob(final ImplicationsJob job) {
switch(job.event.getType()) {
case DOWNLOAD:
case UPLOAD:
break;
default:
// we're not interested in these.
return false;
}
final Transfer transfer = job.transfer;
if (!transfer.getPath().endsWith(".pom")) {
return false;
}
final Location location = transfer.getLocation();
if (!(location instanceof KeyedLocation)) {
return false;
}
final StoreKey key = ((KeyedLocation) location).getKey();
try {
job.store = storeManager.getArtifactStore(key);
} catch (final IndyDataException e) {
logger.error(String.format("Cannot retrieve artifact store for: %s. Failed to process implied repositories.", key), e);
}
if (job.store == null) {
return false;
}
job.pathInfo = ArtifactPathInfo.parse(transfer.getPath());
if (job.pathInfo == null) {
return false;
}
try {
logger.debug("Parsing: {}", transfer);
job.pomView = pomReader.readLocalPom(job.pathInfo.getProjectId(), transfer, MavenPomView.ALL_PROFILES);
} catch (final GalleyMavenException e) {
logger.error(String.format("Cannot parse: %s from: %s. Failed to process implied repositories.", job.pathInfo.getProjectId(), transfer), e);
}
return job.pomView != null;
}
use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.
the class MergedFileUploadListener method reMerge.
private void reMerge(final Group group, final String path) throws IOException {
logger.debug("Updating merged metadata file: {} in group: {}", path, group.getKey());
final Transfer[] toDelete = { fileManager.getStorageReference(group, path), fileManager.getStorageReference(group, path + GroupMergeHelper.MERGEINFO_SUFFIX), fileManager.getStorageReference(group, path + GroupMergeHelper.SHA_SUFFIX), fileManager.getStorageReference(group, path + GroupMergeHelper.MD5_SUFFIX) };
for (final Transfer item : toDelete) {
logger.debug("Attempting to delete: {}", item);
if (item.exists()) {
final boolean result = item.delete();
logger.debug("Deleted: {} (success? {})", item, result);
if (fileEvent != null) {
logger.debug("Firing deletion event for: {}", item);
fileEvent.fire(new FileDeletionEvent(item, new EventMetadata()));
}
}
}
}
use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.
the class MavenMetadataGenerator method generateGroupFileContent.
@Override
public Transfer generateGroupFileContent(final Group group, final List<ArtifactStore> members, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
if (!canProcess(path)) {
return null;
}
final Transfer target = fileManager.getTransfer(group, path);
logger.debug("Working on metadata file: {} (already exists? {})", target, target != null && target.exists());
if (!target.exists()) {
String toMergePath = path;
if (!path.endsWith(MavenMetadataMerger.METADATA_NAME)) {
toMergePath = normalize(normalize(parentPath(toMergePath)), MavenMetadataMerger.METADATA_NAME);
}
final List<Transfer> sources = fileManager.retrieveAllRaw(members, toMergePath, new EventMetadata());
final byte[] merged = merger.merge(sources, group, toMergePath);
if (merged != null) {
OutputStream fos = null;
try {
fos = target.openOutputStream(TransferOperation.GENERATE, true, eventMetadata);
fos.write(merged);
} catch (final IOException e) {
throw new IndyWorkflowException("Failed to write merged metadata to: {}.\nError: {}", e, target, e.getMessage());
} finally {
closeQuietly(fos);
}
helper.writeMergeInfo(merged, sources, group, toMergePath);
}
}
if (target.exists()) {
return target;
}
return null;
}
use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.
the class ArchetypeCatalogMerger method merge.
@Override
public byte[] merge(final Collection<Transfer> sources, final Group group, final String path) {
final ArchetypeCatalog master = new ArchetypeCatalog();
final ArchetypeCatalogXpp3Reader reader = new ArchetypeCatalogXpp3Reader();
final FileReader fr = null;
InputStream stream = null;
boolean merged = false;
final Set<String> seen = new HashSet<String>();
for (final Transfer src : sources) {
try {
stream = src.openInputStream();
final ArchetypeCatalog catalog = reader.read(stream, false);
for (final Archetype arch : catalog.getArchetypes()) {
final String key = arch.getGroupId() + ":" + arch.getArtifactId() + ":" + arch.getVersion();
if (seen.add(key)) {
master.addArchetype(arch);
}
}
merged = true;
} catch (final IOException e) {
final StoreKey key = getKey(src);
logger.error(String.format("Cannot read archetype catalog: %s from artifact-store: %s. Reason: %s", src.getPath(), key, e.getMessage()), e);
} catch (final XmlPullParserException e) {
final StoreKey key = getKey(src);
logger.error(String.format("Cannot parse archetype catalog: %s from artifact-store: %s. Reason: %s", src.getPath(), key, e.getMessage()), e);
} finally {
closeQuietly(fr);
}
}
if (merged) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
new ArchetypeCatalogXpp3Writer().write(baos, master);
return baos.toByteArray();
} catch (final IOException e) {
logger.error(String.format("Cannot write consolidated archetype catalog: %s to: %s. Reason: %s", path, group.getKey(), e.getMessage()), e);
}
}
return null;
}
Aggregations