<commit_before>package org.jboss.windup.windride.ui;


import javax.inject.Inject;
import org.jboss.forge.addon.resource.DirectoryResource;
import org.jboss.forge.addon.ui.command.UICommand;
import org.jboss.forge.addon.ui.context.UIBuilder;
import org.jboss.forge.addon.ui.context.UIContext;
import org.jboss.forge.addon.ui.context.UIExecutionContext;
import org.jboss.forge.addon.ui.context.UIValidationContext;
import org.jboss.forge.addon.ui.input.UIInput;
import org.jboss.forge.addon.ui.metadata.UICommandMetadata;
import org.jboss.forge.addon.ui.metadata.WithAttributes;
import org.jboss.forge.addon.ui.result.Result;
import org.jboss.forge.addon.ui.result.Results;
import org.jboss.forge.addon.ui.util.Categories;
import org.jboss.forge.addon.ui.util.Metadata;
import org.jboss.loom.conf.Configuration;
import org.jboss.loom.conf.ConfigurationValidator;
import org.jboss.windup.windride.impl.WindRideService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 *  @author <NAME>, ozizka at redhat.com
 */
public class WindRideUI implements UICommand {
    private static final Logger log = LoggerFactory.getLogger( WindRideUI.class );


    @Inject private WindRideService windride;

    // Source server - e.g. directory of EAP 5.
    @Inject  @WithAttributes(label = "Source server directory", required = true)
    private UIInput<DirectoryResource> srcServer;

    // Target server, e.g. AS 7. Used to start the server through Arquillian.
    @Inject  @WithAttributes(label = "Target server directory", required = true)
    private UIInput<DirectoryResource> destServer;
    private Configuration conf;


    // Give Forge the command metadata.
    @Override public UICommandMetadata getMetadata( UIContext uic ) {
        return Metadata.forCommand(getClass()).name("Run Windup 1.x")
              .description("Run Windup 1.x Migration Analyzer")
              .category(Categories.create("Platform", "Migration"));
    }


    public boolean isEnabled( UIContext uic ) {
        return true;
    }


    @Override public void initializeUI(final UIBuilder builder) throws Exception {
         builder.add(srcServer).add(destServer);
    }


    public void validate( UIValidationContext uivc ) {
        Configuration conf = new Configuration();
        
        conf.getGlobal().getSourceServerConf().setDir( srcServer.getValue().getContents() );
        conf.getGlobal().getSourceServerConf().setProfileName("all");
        
        conf.getGlobal().getTargetServerConf().setDir( srcServer.getValue().getContents() ); // target/as7copy
        conf.getGlobal().getTargetServerConf().setConfigPath("standalone/configuration/standalone.xml");
        
        ConfigurationValidator.validate( conf );
        this.conf = conf;
    }


    public Result execute( UIExecutionContext uiec ) {
        try {
            windride.doMigration( conf );
            return Results.success();
        } catch( Exception e ) {
            log.error( "Error executing WindRide", e );
            return Results.fail( "Error executing WindRide", e );
        }
    }
    

}// class<commit_msg>Fix the forge metadata; Add reportDir input and a message for the user where to find the report.<commit_after>package org.jboss.windup.windride.ui;


import java.io.File;
import javax.inject.Inject;
import org.jboss.forge.addon.resource.DirectoryResource;
import org.jboss.forge.addon.ui.command.UICommand;
import org.jboss.forge.addon.ui.context.UIBuilder;
import org.jboss.forge.addon.ui.context.UIContext;
import org.jboss.forge.addon.ui.context.UIExecutionContext;
import org.jboss.forge.addon.ui.context.UIValidationContext;
import org.jboss.forge.addon.ui.input.UIInput;
import org.jboss.forge.addon.ui.metadata.UICommandMetadata;
import org.jboss.forge.addon.ui.metadata.WithAttributes;
import org.jboss.forge.addon.ui.result.Result;
import org.jboss.forge.addon.ui.result.Results;
import org.jboss.forge.addon.ui.util.Categories;
import org.jboss.forge.addon.ui.util.Metadata;
import org.jboss.loom.conf.Configuration;
import org.jboss.loom.conf.ConfigurationValidator;
import org.jboss.windup.windride.impl.WindRideService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *  UI for WindRide Forge addon.
 * 
 *  @author <NAME>, ozizka at redhat.com
 */
public class WindRideUI implements UICommand {
    private static final Logger log = LoggerFactory.getLogger( WindRideUI.class );


    @Inject private WindRideService windride;

    private Configuration conf;
    
    
    // --- UI elements ---

    /** Source server - e.g. directory of EAP 5. */
    @Inject  @WithAttributes(label = "Source server directory", required = true)
    private UIInput<DirectoryResource> srcServerUI;

    /** Target server, e.g. AS 7. Used to start the server through Arquillian. */
    @Inject  @WithAttributes(label = "Target server directory", required = true)
    private UIInput<DirectoryResource> destServerUI;

    /** Directory to store the reports to. */
    @Inject  @WithAttributes(label = "Directory to store the reports to", required = false)
    private UIInput<DirectoryResource> reportDirUI;



    // Give Forge the command metadata.
    @Override public UICommandMetadata getMetadata( UIContext uic ) {
        return Metadata.forCommand(getClass()).name("Run WindRide 1.x")
              .description("Run WindRide 1.x server configuration migrator")
              .category(Categories.create("Platform", "Migration", "Configuration"));
    }


    public boolean isEnabled( UIContext uic ) {
        return true;
    }


    @Override public void initializeUI(final UIBuilder builder) throws Exception {
        builder.add(srcServerUI).add(destServerUI).add( reportDirUI );
    }


    /**
     *  Validate user input, and along the way, create the config object which will be used in execute().
     */
    public void validate( UIValidationContext uivc ) {
        Configuration conf = new Configuration();
        
        conf.getGlobal().getSourceServerConf().setDir( srcServerUI.getValue().getContents() );
        conf.getGlobal().getSourceServerConf().setProfileName("all");
        
        conf.getGlobal().getTargetServerConf().setDir( srcServerUI.getValue().getContents() ); // target/as7copy
        conf.getGlobal().getTargetServerConf().setConfigPath("standalone/configuration/standalone.xml");
        
        // If the user didn't choose reports dir, generate them into <CWD>/WindRide-report-<timestamp> .
        String reportDir = null;
        if( this.reportDirUI.hasValue() )
            reportDir = this.reportDirUI.getValue().getContents();
        else
            reportDir = System.getProperty("user.dir") + File.separator + "WindRide-report-" + System.currentTimeMillis();
            
        conf.getGlobal().setReportDir( reportDir );
        
        ConfigurationValidator.validate( conf );
        this.conf = conf;
    }


    /**
     *  Performs a migration as per configuration provided by the user.
     */
    public Result execute( UIExecutionContext uiec ) {
        try {
            windride.doMigration( this.conf );
            String msg = "Server config migration report stored in: " + this.conf.getGlobal().getReportDir();
            return Results.success( msg );
        }
        catch( Exception e ) {
            String msg = "Error executing WindRide: " + e.getMessage();
            log.error( msg, e );
            return Results.fail( msg, e );
        }
    }
    

}// class
{'fraction_non_alphanumeric': 0.11140831884445633, 'fraction_numerical': 0.0018724087200748963, 'mean_word_length': 3.1917040358744395, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '7662235', 'n_tokens_mistral': 2231, 'n_tokens_neox': 2152, 'n_words': 484}