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