/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.codehaus.mojo.flatten.model.resolution;

import java.io.File;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Repository;
import org.apache.maven.model.building.FileModelSource;
import org.apache.maven.model.building.ModelSource;
import org.apache.maven.model.resolution.InvalidRepositoryException;
import org.apache.maven.model.resolution.ModelResolver;
import org.apache.maven.model.resolution.UnresolvableModelException;

/**
 * This is a custom implementation of {@link ModelResolver} to emulate the maven POM resolution in order to build the
 * flattened POM.
 * 
 * @see org.codehaus.mojo.flatten.FlattenMojo
 * @author Robert Scholte
 */
@SuppressWarnings( "deprecation" )
public class FlattenModelResolver
    implements ModelResolver
{

    /** The local repository for artifact resolution. */
    private ArtifactRepository localRepository;

    /** The factory used to create project artifact instances. */
    private ArtifactFactory artifactFactory;

    /**
     * The constructor.
     * 
     * @param localRepository is the local repository.
     * @param artifactFactory is the factory used to create project artifact instances.
     */
    public FlattenModelResolver( ArtifactRepository localRepository, ArtifactFactory artifactFactory )
    {

        this.localRepository = localRepository;
        this.artifactFactory = artifactFactory;
    }

    /**
     * {@inheritDoc}
     */
    public ModelSource resolveModel( String groupId, String artifactId, String version )
        throws UnresolvableModelException
    {

        Artifact pomArtifact = this.artifactFactory.createProjectArtifact( groupId, artifactId, version );
        pomArtifact = this.localRepository.find( pomArtifact );

        File pomFile = pomArtifact.getFile();

        return new FileModelSource( pomFile );
    }

    /**
     * {@inheritDoc}
     */
    public void addRepository( Repository repository )
        throws InvalidRepositoryException
    {

        // ignoring... artifact resolution via repository should already have happened before by maven core.
    }

    /**
     * {@inheritDoc}
     */
    public ModelResolver newCopy()
    {
        return new FlattenModelResolver( this.localRepository, this.artifactFactory );
    }

}

@@ -1060,32 +1060,71 @@
 actRepository;%0D%0A
+import org.apache.maven.model.Parent;%0D%0A
 import org.apach
@@ -1305,161 +1305,21 @@
 ion.
-InvalidRepositoryException;%0D%0Aimport org.apache.maven.model.resolution.ModelResolver;%0D%0Aimport org.apache.maven.model.resolution.UnresolvableModelException
+ModelResolver
 ;%0D%0A%0D
@@ -2427,51 +2427,8 @@
  )%0D%0A
-        throws UnresolvableModelException%0D%0A
     
@@ -2725,37 +2725,24 @@
 /**%0D%0A     * 
-%7B@inheritDoc%7D
 %0D%0A     */%0D%0A 
@@ -2800,51 +2800,8 @@
  )%0D%0A
-        throws InvalidRepositoryException%0D%0A
     
@@ -3104,11 +3104,971 @@
    %7D%0D%0A%0D%0A
+    /**%0D%0A     * Resolves the POM for the specified parent.%0D%0A     * %0D%0A     * @param The parent coordinates to resolve, must not be %7B@code null%7D%0D%0A     * @return The source of the requested POM, never %7B@code null%7D%0D%0A     * %0D%0A     * @since Apache-Maven-3.2.2 (MNG-5639)%0D%0A     */%0D%0A    public ModelSource resolveModel( Parent parent )%0D%0A    %7B%0D%0A        Artifact pomArtifact =%0D%0A            this.artifactFactory.createProjectArtifact( parent.getGroupId(), parent.getArtifactId(),%0D%0A                                                        parent.getVersion() );%0D%0A        pomArtifact = this.localRepository.find( pomArtifact );%0D%0A%0D%0A        File pomFile = pomArtifact.getFile();%0D%0A%0D%0A        return new FileModelSource( pomFile );%0D%0A    %7D%0D%0A    %0D%0A    /**%0D%0A     * @since Apache-Maven-3.2.2 (MNG-5639)%0D%0A     */%0D%0A    public void resetRepositories()%0D%0A    %7B%0D%0A     // ignoring... artifact resolution via repository should already have happened before by maven core.%0D%0A    %7D%0D%0A    %0D%0A    %0D%0A
 %7D%0D%0A

Fix MOJO-2039: Maven 3.2.2 build error with flatten plugin Add new methods of interface ModelResolver