/*-
 * Copyright (c) 2012-2013 Red Hat, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.fedoraproject.maven.resolver;

import java.io.File;

import org.fedoraproject.maven.config.ResolverSettings;
import org.fedoraproject.maven.model.Artifact;
import org.fedoraproject.maven.repository.Layout;
import org.fedoraproject.maven.repository.Repository;
import org.fedoraproject.maven.repository.SingletonRepository;

class LocalResolver
    extends AbstractResolver
{
    private final Repository repo;

    public LocalResolver( ResolverSettings settings )
    {
        // FIXME: only the first local repository is used for now
        if ( settings.getLocalRepositories().size() > 0 )
        {
            String localRepoDir = settings.getLocalRepositories().iterator().next();
            repo = new SingletonRepository( new File( localRepoDir ), Layout.MAVEN );
        }
        else
        {
            repo = null;
        }
    }

    @Override
    public File resolve( Artifact artifact )
    {
        if ( repo != null )
        {
            return repo.findArtifact( artifact, true );
        }
        else
        {
            return null;
        }
    }
}

/*-
 * Copyright (c) 2012-2013 Red Hat, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.fedoraproject.maven.resolver;

import java.io.File;
import java.util.LinkedList;
import java.util.List;

import org.fedoraproject.maven.config.ResolverSettings;
import org.fedoraproject.maven.model.Artifact;
import org.fedoraproject.maven.repository.Layout;
import org.fedoraproject.maven.repository.Repository;
import org.fedoraproject.maven.repository.SingletonRepository;

class LocalResolver
    extends AbstractResolver
{
    private final List<Repository> repositories = new LinkedList<>();

    public LocalResolver( ResolverSettings settings )
    {
        for ( String localRepoDir : settings.getLocalRepositories() )
        {
            Repository repo = new SingletonRepository( new File( localRepoDir ), Layout.MAVEN );
            repositories.add( repo );
        }
    }

    @Override
    public File resolve( Artifact artifact )
    {
        for ( Repository repo : repositories )
        {
            File artifactFile = repo.findArtifact( artifact, true );
            if ( artifactFile != null )
                return artifactFile;
        }

        return null;
    }
}

Use all local repositories to resolve artifacts, not just only one