001package org.eclipse.aether.internal.impl.synccontext.legacy;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.util.Objects;
023
024import javax.inject.Inject;
025import javax.inject.Named;
026import javax.inject.Singleton;
027
028import org.eclipse.aether.RepositorySystemSession;
029import org.eclipse.aether.SyncContext;
030import org.eclipse.aether.spi.locator.Service;
031import org.eclipse.aether.spi.locator.ServiceLocator;
032import org.eclipse.aether.spi.synccontext.SyncContextFactory;
033
034/**
035 * Deprecated {@link org.eclipse.aether.impl.SyncContextFactory} implementation that delegates to proper
036 * {@link SyncContextFactory} implementation. Used in Guice/SISU where we cannot bind same instance to two keys,
037 * this component "bridges" from deprecated to current.
038 *
039 * @deprecated Use the proper class from SPI module.
040 */
041@Singleton
042@Named
043@Deprecated
044public final class DefaultSyncContextFactory
045        implements org.eclipse.aether.impl.SyncContextFactory, Service
046{
047    private SyncContextFactory delegate;
048
049    public DefaultSyncContextFactory()
050    {
051        // default ctor for ServiceLocator
052    }
053
054    @Inject
055    public DefaultSyncContextFactory( final SyncContextFactory delegate )
056    {
057        this.delegate = Objects.requireNonNull( delegate );
058    }
059
060    @Override
061    public void initService( final ServiceLocator locator )
062    {
063        this.delegate = Objects.requireNonNull( locator.getService( SyncContextFactory.class ) );
064    }
065
066    @Override
067    public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
068    {
069        return delegate.newInstance( session, shared );
070    }
071}