<commit_before>package org.codehaus.plexus.archiver.util;

import java.io.File;
import java.lang.reflect.Method;

import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.Os;
import org.codehaus.plexus.util.cli.CommandLineException;
import org.codehaus.plexus.util.cli.CommandLineUtils;
import org.codehaus.plexus.util.cli.Commandline;

public final class ArchiveEntryUtils
{

    private ArchiveEntryUtils()
    {
        // no op
    }

    public static void chmod( File file, int mode, Logger logger )
        throws ArchiverException
    {
        if ( !Os.isFamily( Os.FAMILY_UNIX ) )
        {
            return;
        }

        String m = Integer.toOctalString( mode & 0xfff );

        
        if ( isJvmFilePermAvailable() )
        {
            applyPermissionsWithJvm( file, m, logger );
            return;
        }
        
        try
        {
            Commandline commandline = new Commandline();

            commandline.setWorkingDirectory( file.getParentFile().getAbsolutePath() );

            logger.info( "mode " + mode + ", chmod " + m );
            
            commandline.setExecutable( "chmod" );

            commandline.createArg().setValue( m );

            String path = file.getAbsolutePath();

            commandline.createArg().setValue( path );

            // commenting this debug statement, since it can produce VERY verbose output...
            // this method is called often during archive creation.
//            logger.debug( "Executing:\n\n" + commandline.toString() + "\n\n" );

            CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();

            CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();

            int exitCode = CommandLineUtils.executeCommandLine( commandline, stderr, stdout );

            if ( exitCode != 0 )
            {
                logger.warn( "-------------------------------" );
                logger.warn( "Standard error:" );
                logger.warn( "-------------------------------" );
                logger.warn( stderr.getOutput() );
                logger.warn( "-------------------------------" );
                logger.warn( "Standard output:" );
                logger.warn( "-------------------------------" );
                logger.warn( stdout.getOutput() );
                logger.warn( "-------------------------------" );

                throw new ArchiverException( "chmod exit code was: " + exitCode );
            }
        }
        catch ( CommandLineException e )
        {
            throw new ArchiverException( "Error while executing chmod.", e );
        }
    }
    
    /**
     * 
     * @return true if file permissions for JVM are available ie is 1.6
     */
    private static boolean isJvmFilePermAvailable()
    {
        try
        {
            return File.class.getMethod( "setReadable", new Class[] { Boolean.class } ) != null;
        }
        catch ( Exception e )
        {
            return false;
        }
    }
    
    private static void applyPermissionsWithJvm( File file, String mode, Logger logger )
    {
        FilePermission filePermission = FilePermissionUtils.getFilePermissionFromMode( mode, logger );

        Method method;
        try
        {
            method = File.class.getMethod( "setReadable", new Class[] { Boolean.class, Boolean.class } );
<commit_msg>add debug information<commit_after>package org.codehaus.plexus.archiver.util;

import java.io.File;
import java.lang.reflect.Method;

import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.Os;
import org.codehaus.plexus.util.cli.CommandLineException;
import org.codehaus.plexus.util.cli.CommandLineUtils;
import org.codehaus.plexus.util.cli.Commandline;

public final class ArchiveEntryUtils
{

    private ArchiveEntryUtils()
    {
        // no op
    }

    public static void chmod( File file, int mode, Logger logger )
        throws ArchiverException
    {
        if ( !Os.isFamily( Os.FAMILY_UNIX ) )
        {
            return;
        }

        String m = Integer.toOctalString( mode & 0xfff );

        
        if ( isJvmFilePermAvailable( logger ) )
        {
            applyPermissionsWithJvm( file, m, logger );
            return;
        }
        
        try
        {
            Commandline commandline = new Commandline();

            commandline.setWorkingDirectory( file.getParentFile().getAbsolutePath() );

            logger.info( "mode " + mode + ", chmod " + m );
            
            commandline.setExecutable( "chmod" );

            commandline.createArg().setValue( m );

            String path = file.getAbsolutePath();

            commandline.createArg().setValue( path );

            // commenting this debug statement, since it can produce VERY verbose output...
            // this method is called often during archive creation.
//            logger.debug( "Executing:\n\n" + commandline.toString() + "\n\n" );

            CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();

            CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();

            int exitCode = CommandLineUtils.executeCommandLine( commandline, stderr, stdout );

            if ( exitCode != 0 )
            {
                logger.warn( "-------------------------------" );
                logger.warn( "Standard error:" );
                logger.warn( "-------------------------------" );
                logger.warn( stderr.getOutput() );
                logger.warn( "-------------------------------" );
                logger.warn( "Standard output:" );
                logger.warn( "-------------------------------" );
                logger.warn( stdout.getOutput() );
                logger.warn( "-------------------------------" );

                throw new ArchiverException( "chmod exit code was: " + exitCode );
            }
        }
        catch ( CommandLineException e )
        {
            throw new ArchiverException( "Error while executing chmod.", e );
        }
    }
    
    /**
     * 
     * @return true if file permissions for JVM are available ie is 1.6
     */
    private static boolean isJvmFilePermAvailable( Logger logger )
    {
        try
        {
            return File.class.getMethod( "setReadable", new Class[] { Boolean.class } ) != null;
        }
        catch ( Exception e )
        {
            logger.debug( "exception during isJvmFilePermAvailable " + e.getMessage(), e );
            return false;
        }
    }
    
    private static void applyPermissionsWithJvm( File file, String mode, Logger logger )
    {
        FilePermission filePermission = FilePermissionUtils.getFilePermissionFromMode( mode, logger );

        Method method;
        try
        {
            method = File.class.getMethod( "setReadable", new Class[] { Boolean.class, Boolean.class } );

{'fraction_non_alphanumeric': 0.1399182753276032, 'fraction_numerical': 0.0011272368606453432, 'mean_word_length': 1.6795016987542468, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1695442', 'n_tokens_mistral': 1837, 'n_tokens_neox': 1769, 'n_words': 417}