/*-
 * Copyright (c) 2012 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 static org.fedoraproject.maven.utils.Logger.debug;

import java.io.File;
import java.util.Set;
import java.util.TreeSet;

import org.fedoraproject.maven.model.Artifact;
import org.fedoraproject.maven.repository.JppRepository;
import org.fedoraproject.maven.repository.Repository;
import org.fedoraproject.rpmquery.RpmDb;

public class SystemResolver
    extends AbstractResolver
{
    private final Repository systemRepo;

    private static final DependencyMap depmap = new DependencyMap();

    private static final RpmDb rpmdb = new RpmDb();

    private static final Set<String> usedRpmPackages = new TreeSet<>();

    public SystemResolver( File root )
    {
        systemRepo = new JppRepository( root );
        DepmapReader depmapReader = new DepmapReader();
        depmapReader.readArtifactMap( root, depmap );
    }

    @Override
    public File resolve( Artifact artifact )
    {

        debug( "Resolving ", artifact );
        Artifact jppArtifact = depmap.translate( artifact );
        File file = systemRepo.findArtifact( jppArtifact );
        if ( file == null )
        {
            debug( "Failed to resolve artifact ", artifact );
            debug( "JPP artifact for ", artifact, " is ", jppArtifact );
            return null;
        }

        debug( "Artifact ", artifact, " was resolved to ", file );
        String rpmPackage = rpmdb.lookupFile( file );
        if ( rpmPackage != null )
        {
            usedRpmPackages.add( rpmPackage );
            debug( "Artifact ", artifact, " is provided by ", rpmPackage );
        }
        else
        {
            debug( "Artifact ", artifact, " is not provided by any package" );
        }

        return file;
    }

    public static void printInvolvedPackages()
    {
        if ( !usedRpmPackages.isEmpty() )
        {
            debug( "Packages involved in artifact resolution:" );
            for ( String pkg : usedRpmPackages )
                debug( "  * ", pkg );
        }
    }
}

@@ -767,16 +767,62 @@
 eeSet;%0A%0A
+import org.fedoraproject.maven.Configuration;%0A
 import o
@@ -2016,32 +2016,93 @@
 d to %22, file );%0A
+%0A        if ( Configuration.isDebugEnabled() )%0A        %7B%0A    
         String r
@@ -2143,24 +2143,28 @@
  );%0A        
+    
 if ( rpmPack
@@ -2177,34 +2177,42 @@
  null )%0A        
+   
+ 
 %7B%0A
+    
             used
@@ -2234,32 +2234,36 @@
 ( rpmPackage );%0A
+    
             debu
@@ -2314,32 +2314,36 @@
 , rpmPackage );%0A
+    
         %7D%0A      
@@ -2344,16 +2344,20 @@
         
+    
 else%0A   
@@ -2353,34 +2353,42 @@
    else%0A        
+  
-%7B%0A
+  %7B%0A    
             debu
@@ -2446,24 +2446,38 @@
 package%22 );%0A
+            %7D%0A
         %7D%0A%0A 

Resolve files to RPM packages only when debugging is enabled