/*-
 * 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.connector;

import static org.fedoraproject.maven.utils.Logger.info;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import org.apache.maven.cli.MavenCli;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.ClassWorld;
import org.fedoraproject.maven.resolver.SystemResolver;

public class Main
    extends MavenCli
{
    public static int main( String[] args, ClassWorld world )
    {
        info( "Maven RPM extension" );
        info( "Written by Mikolaj Izdebski <mizdebsk@redhat.com>" );

        List<String> options = new LinkedList<>();
        options.add( "--offline" );
        options.add( "--batch-mode" );
        options.add( "-Dmaven.repo.local=.xm2" );
        options.addAll( Arrays.asList( args ) );

        Main cli = new Main();
        args = options.toArray( new String[0] );
        return cli.exec( args );
    }

    private int exec( String[] args )
    {
        int ret = doMain( args, null, null, null );
        SystemResolver.printInvolvedPackages();
        return ret;
    }

    @Override
    protected void customizeContainer( PlexusContainer container )
    {
        LoggerProvider.initialize( container );
    }
}

@@ -813,16 +813,67 @@
 venCli;%0A
+import org.codehaus.plexus.DefaultPlexusContainer;%0A
 import o
@@ -959,16 +959,181 @@
 sWorld;%0A
+import org.codehaus.plexus.component.annotations.Component;%0Aimport org.codehaus.plexus.component.annotations.Requirement;%0Aimport org.codehaus.plexus.logging.Logger;%0A
 import o
@@ -1181,16 +1181,48 @@
 olver;%0A%0A
+@Component( role = Main.class )%0A
 public c
@@ -1254,16 +1254,61 @@
 enCli%0A%7B%0A
+    @Requirement%0A    private Logger logger;%0A%0A
     publ
@@ -1359,32 +1359,414 @@
 d world )%0A    %7B%0A
+        try%0A        %7B%0A            PlexusContainer container = new DefaultPlexusContainer();%0A            int ret = container.lookup( Main.class ).exec( args );%0A            container.dispose();%0A            return ret;%0A        %7D%0A        catch ( Exception e )%0A        %7B%0A            e.printStackTrace();%0A            return 1;%0A        %7D%0A    %7D%0A%0A    private int exec( String%5B%5D args )%0A    %7B%0A
         info( %22M
@@ -2088,39 +2088,8 @@
 );%0A%0A
-        Main cli = new Main();%0A
     
@@ -2137,91 +2137,8 @@
  );%0A
-        return cli.exec( args );%0A    %7D%0A%0A    private int exec( String%5B%5D args )%0A    %7B
 %0A   

Convert main CLI class to Plexus Component