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
034import static java.util.Objects.requireNonNull;
035
036/**
037 * Deprecated {@link org.eclipse.aether.impl.SyncContextFactory} implementation that delegates to proper
038 * {@link SyncContextFactory} implementation. Used in Guice/SISU where we cannot bind same instance to two keys,
039 * this component "bridges" from deprecated to current.
040 *
041 * @deprecated Use the proper class from SPI module.
042 */
043@Singleton
044@Named
045@Deprecated
046public final class DefaultSyncContextFactory
047        implements org.eclipse.aether.impl.SyncContextFactory, Service
048{
049    private SyncContextFactory delegate;
050
051    public DefaultSyncContextFactory()
052    {
053        // default ctor for ServiceLocator
054    }
055
056    @Inject
057    public DefaultSyncContextFactory( final SyncContextFactory delegate )
058    {
059        this.delegate = Objects.requireNonNull( delegate );
060    }
061
062    @Override
063    public void initService( final ServiceLocator locator )
064    {
065        this.delegate = Objects.requireNonNull( locator.getService( SyncContextFactory.class ) );
066    }
067
068    @Override
069    public SyncContext newInstance( final RepositorySystemSession session, final boolean shared )
070    {
071        requireNonNull( session, "session cannot be null" );
072        return delegate.newInstance( session, shared );
073    }
074}