use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class ValidationRequest method getSourcePaths.
public synchronized Set<String> getSourcePaths(boolean includeMetadata, boolean includeChecksums) throws PromotionValidationException {
if (requestPaths == null) {
Set<String> paths = null;
if (promoteRequest instanceof PathsPromoteRequest) {
paths = ((PathsPromoteRequest) promoteRequest).getPaths();
}
if (paths == null) {
ArtifactStore store = null;
try {
store = tools.getArtifactStore(promoteRequest.getSource());
} catch (IndyDataException e) {
throw new PromotionValidationException("Failed to retrieve source ArtifactStore: {}. Reason: {}", e, promoteRequest.getSource(), e.getMessage());
}
if (store != null) {
try {
paths = new HashSet<>();
listRecursively(store, "/", paths);
} catch (IndyWorkflowException e) {
throw new PromotionValidationException("Failed to list paths in source: {}. Reason: {}", e, promoteRequest.getSource(), e.getMessage());
}
}
}
requestPaths = paths;
}
if (!includeMetadata || !includeChecksums) {
Predicate<String> filter = (path) -> (includeMetadata || !path.matches(".+/maven-metadata\\.xml(\\.(md5|sha[0-9]+))?")) && (includeChecksums || !path.matches(".+\\.(md5|sha[0-9]+)"));
return requestPaths.stream().filter(filter).collect(Collectors.toSet());
}
return requestPaths;
}
use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class SetBackSettingsManager method updateSettingsForGroup.
private DataFile updateSettingsForGroup(final Group group) throws SetBackDataException {
if (!config.isEnabled()) {
throw new SetBackDataException("SetBack is disabled!");
}
logger.info("Updating set-back settings.xml for group: {}", group.getName());
List<ArtifactStore> concreteStores;
try {
concreteStores = storeManager.query().packageType(group.getPackageType()).getOrderedConcreteStoresInGroup(group.getName());
} catch (final IndyDataException e) {
logger.error(String.format("Failed to retrieve concrete membership for group: {}. Reason: {}", group.getName(), e.getMessage()), e);
return null;
}
final List<RemoteRepository> remotes = new ArrayList<RemoteRepository>();
for (final ArtifactStore cs : concreteStores) {
if (StoreType.remote == cs.getKey().getType()) {
remotes.add((RemoteRepository) cs);
}
}
return updateSettings(group, concreteStores, remotes);
}
use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class IndyLocationExpander method expand.
/**
* For group references, expand into a list of concrete repository locations (hosted or remote). For remote repository references that are
* specified as cache-only locations (see: {@link CacheOnlyLocation}), lookup the corresponding {@link RemoteRepository} and use it to create a
* {@link RepositoryLocation} that contains any relevant SSL, authentication, proxy, etc. attbributes.
*/
@Override
public <T extends Location> List<Location> expand(final Collection<T> locations) throws TransferException {
final List<Location> result = new ArrayList<Location>();
for (final Location location : locations) {
if (location instanceof GroupLocation) {
final GroupLocation gl = (GroupLocation) location;
try {
logger.debug("Expanding group: {}", gl.getKey());
final List<ArtifactStore> members = data.query().packageType(gl.getKey().getPackageType()).getOrderedConcreteStoresInGroup(gl.getKey().getName());
if (members != null) {
for (final ArtifactStore member : members) {
if (!result.contains(member)) {
logger.debug("expansion += {}", member.getKey());
result.add(LocationUtils.toLocation(member));
}
}
logger.debug("Expanded group: {} to:\n {}", gl.getKey(), new JoinString("\n ", result));
}
} catch (final IndyDataException e) {
throw new TransferException("Failed to lookup ordered concrete artifact stores contained in group: {}. Reason: {}", e, gl, e.getMessage());
}
} else if (location instanceof CacheOnlyLocation && !((CacheOnlyLocation) location).isHostedRepository()) {
final StoreKey key = ((KeyedLocation) location).getKey();
try {
final ArtifactStore store = data.getArtifactStore(key);
if (store == null) {
throw new TransferException("Cannot find ArtifactStore to match key: %s.", key);
}
logger.debug("Adding single store: {} for location: {}", store, location);
result.add(LocationUtils.toLocation(store));
} catch (final IndyDataException e) {
throw new TransferException("Failed to lookup store for key: {}. Reason: {}", e, key, e.getMessage());
}
} else {
logger.debug("No expansion available for location: {}", location);
result.add(location);
}
}
return result;
}
use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class RelateGenerationManager method generateRelationshipFile.
/**
* Generate relationship file for pom transfer.
* @param transfer
* @param op
* @return transfer pointing to the generated rel file.
*/
public Transfer generateRelationshipFile(Transfer transfer, TransferOperation op) {
final Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Relate generation for {}", transfer);
if (transfer == null) {
logger.debug("No transfer. No .rel generation performed.");
return null;
}
String txfrPath = transfer.getPath();
if (!txfrPath.endsWith(".pom")) {
logger.debug("This is not a pom transfer.");
return null;
}
ArtifactPathInfo artPathInfo = ArtifactPathInfo.parse(txfrPath);
if (artPathInfo == null) {
logger.debug("Not an artifact download ({}). No .rel generation performed.", txfrPath);
return null;
}
ConcreteResource pomResource = transfer.getResource();
StoreKey storeKey = StoreKey.fromString(transfer.getLocation().getName());
ArtifactStore store;
try {
store = storeManager.getArtifactStore(storeKey);
} catch (final IndyDataException ex) {
logger.error("Error retrieving artifactStore with key " + storeKey, ex);
return null;
}
logger.debug("Generate .rel corresponding to associated POM download: {}/{}", storeKey, pomResource.getPath());
try {
URI source = new URI(pomResource.getLocation().getUri() + REL_SUFFIX);
ProjectVersionRef ref = artPathInfo.getProjectId();
// get all groups that this store is a member of
Set<ArtifactStore> stores = new HashSet<>();
stores.add(store);
stores.addAll(storeManager.query().getGroupsContaining(store.getKey()));
List<? extends Location> supplementalLocations = LocationUtils.toLocations(stores.toArray(new ArtifactStore[0]));
MavenPomView pomView = mavenPomReader.read(ref, transfer, supplementalLocations, ALL_PROFILES);
EProjectDirectRelationships rel = mavenModelProcessor.readRelationships(pomView, source, new ModelProcessorConfig());
Transfer transferRel = transfer.getSiblingMeta(REL_SUFFIX);
writeRelationships(rel, transferRel, op);
return transferRel;
} catch (Exception e) {
logger.error("Error generating .rel file for " + txfrPath + " from store " + store, e);
return null;
}
}
use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class HttProxOriginMigrationAction method migrate.
@Override
public boolean migrate() throws IndyLifecycleException {
List<RemoteRepository> repos;
try {
repos = storeDataManager.query().noPackageType().getAllRemoteRepositories();
} catch (IndyDataException e) {
throw new IndyLifecycleException("Cannot retrieve all remote repositories. Reason: %s", e, e.getMessage());
}
List<RemoteRepository> toStore = new ArrayList<>();
repos.forEach((repo) -> {
if (repo.getDescription() != null && repo.getDescription().contains("HTTProx proxy")) {
repo.setMetadata(ArtifactStore.METADATA_ORIGIN, ProxyAcceptHandler.HTTPROX_ORIGIN);
RemoteRepository store = repo.copyOf(GENERIC_PKG_KEY, repo.getName());
toStore.add(store);
}
});
final ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Adding HttProx origin metadata");
for (RemoteRepository repo : toStore) {
try {
storeDataManager.storeArtifactStore(repo, changeSummary, false, true, new EventMetadata());
} catch (IndyDataException e) {
throw new IndyLifecycleException("Failed to store %s with HttProx origin metadata. Reason: %s", e, repo == null ? "NULL REPO" : repo.getKey(), e.getMessage());
}
}
return !toStore.isEmpty();
}
Aggregations