Search in sources :

Example 1 with GroupLocation

use of org.commonjava.indy.model.galley.GroupLocation 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;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) TransferException(org.commonjava.maven.galley.TransferException) GroupLocation(org.commonjava.indy.model.galley.GroupLocation) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) CacheOnlyLocation(org.commonjava.indy.model.galley.CacheOnlyLocation) ArrayList(java.util.ArrayList) StoreKey(org.commonjava.indy.model.core.StoreKey) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) CacheOnlyLocation(org.commonjava.indy.model.galley.CacheOnlyLocation) RepositoryLocation(org.commonjava.indy.model.galley.RepositoryLocation) GroupLocation(org.commonjava.indy.model.galley.GroupLocation) Location(org.commonjava.maven.galley.model.Location)

Example 2 with GroupLocation

use of org.commonjava.indy.model.galley.GroupLocation in project indy by Commonjava.

the class LocationUtils method toLocation.

public static KeyedLocation toLocation(final ArtifactStore store) {
    if (store == null) {
        return null;
    }
    final StoreType type = store.getKey().getType();
    KeyedLocation location = null;
    switch(type) {
        case group:
            {
                location = new GroupLocation(store.getName());
                break;
            }
        case hosted:
            {
                location = new CacheOnlyLocation((HostedRepository) store);
                break;
            }
        case remote:
        default:
            {
                final RemoteRepository repository = (RemoteRepository) store;
                location = new RepositoryLocation(repository);
                AttributePasswordManager.bind(location, PasswordEntry.KEY_PASSWORD, repository.getKeyPassword());
                AttributePasswordManager.bind(location, PasswordEntry.PROXY_PASSWORD, repository.getProxyPassword());
                AttributePasswordManager.bind(location, PasswordEntry.USER_PASSWORD, repository.getPassword());
                // FIXME: Make this configurable on the RemoteRepository!
                location.setAttribute(Location.MAX_CONNECTIONS, 30);
            }
    }
    if (location != null) {
        location.setAttribute(PATH_STYLE, store.getPathStyle());
        Map<String, String> metadata = store.getMetadata();
        if (metadata != null) {
            Location loc = location;
            metadata.forEach((k, v) -> {
                if (!loc.getAttributes().containsKey(k)) {
                    loc.setAttribute(k, v);
                }
            });
        }
    }
    return location;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) GroupLocation(org.commonjava.indy.model.galley.GroupLocation) CacheOnlyLocation(org.commonjava.indy.model.galley.CacheOnlyLocation) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) RepositoryLocation(org.commonjava.indy.model.galley.RepositoryLocation) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) CacheOnlyLocation(org.commonjava.indy.model.galley.CacheOnlyLocation) RepositoryLocation(org.commonjava.indy.model.galley.RepositoryLocation) GroupLocation(org.commonjava.indy.model.galley.GroupLocation) Location(org.commonjava.maven.galley.model.Location)

Aggregations

CacheOnlyLocation (org.commonjava.indy.model.galley.CacheOnlyLocation)2 GroupLocation (org.commonjava.indy.model.galley.GroupLocation)2 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)2 RepositoryLocation (org.commonjava.indy.model.galley.RepositoryLocation)2 Location (org.commonjava.maven.galley.model.Location)2 ArrayList (java.util.ArrayList)1 IndyDataException (org.commonjava.indy.data.IndyDataException)1 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)1 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)1 StoreKey (org.commonjava.indy.model.core.StoreKey)1 StoreType (org.commonjava.indy.model.core.StoreType)1 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)1 TransferException (org.commonjava.maven.galley.TransferException)1