<commit_before>package org.apache.maven.extension;

import org.apache.maven.ArtifactFilterManager;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.execution.MavenProjectSession;
import org.apache.maven.lifecycle.mapping.LifecycleMapping;
import org.apache.maven.model.Build;
import org.apache.maven.model.Extension;
import org.apache.maven.model.Model;
import org.codehaus.plexus.MutablePlexusContainer;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class DefaultExtensionManagerTest
    extends PlexusTestCase
{

    private Set toDelete = new HashSet();

    private MutablePlexusContainer container;

    private ArtifactFilterManager filterManager;

    private ArtifactRepositoryFactory repoFactory;

    private ArtifactFactory factory;

    private ArtifactResolver resolver;

    private ArtifactMetadataSource metadataSource;

    private WagonManager wagonManager;

    public void setUp()
        throws Exception
    {
        super.setUp();

        container = (MutablePlexusContainer) getContainer();

//        container.getLoggerManager().setThreshold( Logger.LEVEL_DEBUG );

        filterManager = (ArtifactFilterManager) lookup( ArtifactFilterManager.class.getName() );

        repoFactory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );

        factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
        resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );

        metadataSource = (ArtifactMetadataSource) lookup( ArtifactMetadataSource.ROLE );

        wagonManager = (WagonManager) lookup( WagonManager.ROLE );
    }

    public void tearDown()
        throws Exception
    {
        super.tearDown();

        for ( Iterator it = toDelete.iterator(); it.hasNext(); )
        {
            File f = (File) it.next();

            if ( f.exists() )
            {
                try
                {
                    FileUtils.forceDelete( f );
                }
                catch ( IOException e )
                {
                    // TODO carlos: delete fails on windows, needs investigation
                    // the test-extension-1.jar is locked for deletion
                    // I traced it and seems to get locked at getRealm().findRealmResources(
                    // name ) in org.codehaus.plexus.classworlds.strategy.DefaultStrategy:146
                }
            }
        }
    }

    public void test_addExtension_usingModel_ShouldLoadExtensionComponent()
        throws Exception
    {
        File remoteRepoDir = findRemoteRepositoryDirectory();
        File localRepo = createTempDir();

        Model model = createModel( "org.test", "artifact-name", "1" );
        Extension ext = addExtension( model, "org.apache.maven.core.test", "test-extension", "1" );

        List remoteRepositories = new ArrayList();
        remoteRepositories.add( repoFactory.createArtifactRepository( "central",
                                                                      remoteRepoDir.toURI()
                                                                                   .toURL()
                                                                                   .toExternalForm(),<commit_msg>Rolling back last workaround, files must not be locked, test is right and code needs to be fixed<commit_after>package org.apache.maven.extension;

import org.apache.maven.ArtifactFilterManager;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.execution.MavenProjectSession;
import org.apache.maven.lifecycle.mapping.LifecycleMapping;
import org.apache.maven.model.Build;
import org.apache.maven.model.Extension;
import org.apache.maven.model.Model;
import org.codehaus.plexus.MutablePlexusContainer;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class DefaultExtensionManagerTest
    extends PlexusTestCase
{

    private Set toDelete = new HashSet();

    private MutablePlexusContainer container;

    private ArtifactFilterManager filterManager;

    private ArtifactRepositoryFactory repoFactory;

    private ArtifactFactory factory;

    private ArtifactResolver resolver;

    private ArtifactMetadataSource metadataSource;

    private WagonManager wagonManager;

    public void setUp()
        throws Exception
    {
        super.setUp();

        container = (MutablePlexusContainer) getContainer();

//        container.getLoggerManager().setThreshold( Logger.LEVEL_DEBUG );

        filterManager = (ArtifactFilterManager) lookup( ArtifactFilterManager.class.getName() );

        repoFactory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );

        factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
        resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );

        metadataSource = (ArtifactMetadataSource) lookup( ArtifactMetadataSource.ROLE );

        wagonManager = (WagonManager) lookup( WagonManager.ROLE );
    }

    public void tearDown()
        throws Exception
    {
        super.tearDown();

        for ( Iterator it = toDelete.iterator(); it.hasNext(); )
        {
            File f = (File) it.next();

            if ( f.exists() )
            {
                FileUtils.forceDelete( f );
            }
        }
    }

    public void test_addExtension_usingModel_ShouldLoadExtensionComponent()
        throws Exception
    {
        File remoteRepoDir = findRemoteRepositoryDirectory();
        File localRepo = createTempDir();

        Model model = createModel( "org.test", "artifact-name", "1" );
        Extension ext = addExtension( model, "org.apache.maven.core.test", "test-extension", "1" );

        List remoteRepositories = new ArrayList();
        remoteRepositories.add( repoFactory.createArtifactRepository( "central",
                                                                      remoteRepoDir.toURI()
                                                                                   .toURL()
                                                                                   .toExternalForm(),
{'fraction_non_alphanumeric': 0.08756116404841617, 'fraction_numerical': 0.0010301313417460727, 'mean_word_length': 2.6897862232779097, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3320159', 'n_tokens_mistral': 2043, 'n_tokens_neox': 1937, 'n_words': 405}