Example usage for org.springframework.boot ApplicationArguments getSourceArgs

List of usage examples for org.springframework.boot ApplicationArguments getSourceArgs

Introduction

In this page you can find the example usage for org.springframework.boot ApplicationArguments getSourceArgs.

Prototype

String[] getSourceArgs();

Source Link

Document

Return the raw unprocessed arguments that were passed to the application.

Usage

From source file:org.cloudfoundry.dependency.out.OutConfiguration.java

@Bean
Path source(ApplicationArguments applicationArguments) {
    Path source = Paths.get(applicationArguments.getSourceArgs()[0]);
    this.logger.debug("Source: {}", source);
    return source;
}

From source file:org.cloudfoundry.dependency.in.InConfiguration.java

@Bean
Path destination(ApplicationArguments applicationArguments) {
    Path destination = Paths.get(applicationArguments.getSourceArgs()[0]);
    this.logger.debug("Destination: {}", destination);
    return destination;
}

From source file:com.intuit.karate.demo.config.ServerStartedInitializingBean.java

@Override
public void run(ApplicationArguments aa) throws Exception {
    logger.info("server started with args: {}", Arrays.toString(aa.getSourceArgs()));
}

From source file:com.blackducksoftware.integration.hub.detect.Application.java

@Override
public void run(final ApplicationArguments applicationArguments) throws Exception {
    final long startTime = System.currentTimeMillis();

    //Events, Status and Exit Codes are required even if boot fails.
    EventSystem eventSystem = new EventSystem();
    DetectStatusManager statusManager = new DetectStatusManager(eventSystem);

    ExitCodeUtility exitCodeUtility = new ExitCodeUtility();
    ExitCodeManager exitCodeManager = new ExitCodeManager(eventSystem, exitCodeUtility);

    ReportManager reportManager = ReportManager.createDefault(eventSystem);

    //Before boot even begins, we create a new Spring context for Detect to work within.
    logger.info("Preparing detect.");
    DetectRun detectRun = DetectRun.createDefault();
    DetectContext detectContext = new DetectContext(detectRun);

    BootResult bootResult = null;/*from  w ww.j a  v a  2  s .  com*/
    Optional<RunResult> runResult = Optional.empty();
    try {
        logger.info("Detect boot begin.");
        BootManager bootManager = new BootManager(new BootFactory());
        bootResult = bootManager.boot(detectRun, applicationArguments.getSourceArgs(), environment, eventSystem,
                detectContext);
        logger.info("Detect boot completed.");
    } catch (final Exception e) {
        logger.error("Detect boot failed.");
        exitCodeManager.requestExitCode(e);
    }
    if (bootResult != null && bootResult.bootType == BootResult.BootType.CONTINUE) {
        logger.info("Detect will attempt to run.");
        RunManager runManager = new RunManager(detectContext);
        try {
            logger.info("Detect run begin: " + detectRun.getRunId());
            runResult = Optional.ofNullable(runManager.run());
            logger.info("Detect run completed.");
        } catch (final Exception e) {
            if (e.getMessage() != null) {
                logger.error("Detect run failed: " + e.getMessage());
            } else {
                logger.error("Detect run failed: " + e.getClass().getSimpleName());
            }
            logger.debug("An exception was thrown during the detect run.", e);
            exitCodeManager.requestExitCode(e);
        }
        try {
            logger.info("Detect will attempt to shutdown.");
            DiagnosticManager diagnosticManager = detectContext.getBean(DiagnosticManager.class);
            DirectoryManager directoryManager = detectContext.getBean(DirectoryManager.class);
            DetectConfiguration detectConfiguration = detectContext.getBean(DetectConfiguration.class);
            ConnectivityManager connectivityManager = detectContext.getBean(ConnectivityManager.class);
            ShutdownManager shutdownManager = new ShutdownManager(connectivityManager, statusManager,
                    exitCodeManager, directoryManager, detectConfiguration, reportManager, diagnosticManager);
            logger.info("Detect shutdown begin.");
            shutdownManager.shutdown(runResult);
            logger.info("Detect shutdown completed.");
        } catch (final Exception e) {
            logger.error("Detect shutdown failed.");
            exitCodeManager.requestExitCode(e);
        }
    } else {
        logger.debug("Detect will NOT attempt to run.");
    }

    logger.info("All detect actions completed.");

    //Determine how detect should actually exit
    boolean printOutput = true;
    boolean shouldForceSuccess = false;
    if (bootResult != null && bootResult.detectConfiguration != null) {
        printOutput = !bootResult.detectConfiguration
                .getBooleanProperty(DetectProperty.DETECT_SUPPRESS_RESULTS_OUTPUT, PropertyAuthority.None);
        shouldForceSuccess = bootResult.detectConfiguration
                .getBooleanProperty(DetectProperty.DETECT_FORCE_SUCCESS, PropertyAuthority.None);
    }

    //Generally, when requesting a failure status, an exit code is also requested, but if it is not, we default to an unknown error.
    if (statusManager.hasAnyFailure()) {
        eventSystem.publishEvent(Event.ExitCode, new ExitCodeRequest(ExitCodeType.FAILURE_UNKNOWN_ERROR,
                "A failure status was requested by one or more of Detect's tools."));
    }

    //Find the final (as requested) exit code
    ExitCodeType finalExitCode = exitCodeManager.getWinningExitCode();

    //Print detect's status
    if (printOutput) {
        reportManager.printDetectorIssues();
        statusManager.logDetectResults(new Slf4jIntLogger(logger), finalExitCode);
    }

    //Print duration of run
    final long endTime = System.currentTimeMillis();
    logger.info(String.format("Detect duration: %s",
            DurationFormatUtils.formatPeriod(startTime, endTime, "HH'h' mm'm' ss's' SSS'ms'")));

    //Exit with formal exit code
    if (finalExitCode != ExitCodeType.SUCCESS && shouldForceSuccess) {
        logger.warn(String.format("Forcing success: Exiting with exit code 0. Ignored exit code was %s.",
                finalExitCode.getExitCode()));
        System.exit(0);
    } else if (finalExitCode != ExitCodeType.SUCCESS) {
        logger.error(String.format("Exiting with code %s - %s", finalExitCode.getExitCode(),
                finalExitCode.toString()));
    }

    System.exit(finalExitCode.getExitCode());
}

From source file:com.synopsys.detect.doctor.DoctorApplication.java

@Override
public void run(final ApplicationArguments applicationArguments) throws Exception {
    PropertyMap<DoctorProperty> doctorPropertyPropertyMap = new PropertyMap<>();
    SpringPropertySource springPropertySource = new SpringPropertySource(configurableEnvironment);
    DoctorConfiguration doctorConfiguration = new DoctorConfiguration(springPropertySource,
            doctorPropertyPropertyMap);//from   ww  w . j a v  a 2  s . c  o  m

    DoctorArgumentStateParser argumentStateParser = new DoctorArgumentStateParser();
    DoctorArgumentState state = argumentStateParser.parseArgs(applicationArguments.getSourceArgs());

    doctorConfiguration.init();

    DoctorRun doctorRun = DoctorRun.createDefault();

    logger.info("Doctor begin: " + doctorRun.getRunId());

    DoctorDirectoryManager doctorDirectoryManager = new DoctorDirectoryManager(doctorRun);

    logger.info("Doctor ready.");

    Optional<DetectRunInfo> detectRunInfo = Optional.empty();

    File diagnosticZip = new File(doctorConfiguration.getProperty(DoctorProperty.DETECT_DIAGNOSTIC_FILE));
    if (diagnosticZip.exists()) {
        logger.info("A diagnostic zip was found: " + diagnosticZip.getAbsolutePath());
        DiagnosticParser diagnosticParser = new DiagnosticParser();
        detectRunInfo = Optional
                .of(diagnosticParser.processDiagnosticZip(doctorDirectoryManager, diagnosticZip));
    } else {
        logger.info("No diagnostic zip provided, looking for the pieces.");
        File log = new File(doctorConfiguration.getProperty(DoctorProperty.DETECT_LOG_FILE));

        logger.info("Looking for log file at: " + log.getAbsolutePath());
        if (log.exists()) {
            logger.info("Found log file.");
            // detectRunInfo = Optional.of(new DetectRunInfo(log));
        } else {
            logger.info("No log file found.");
        }
    }

    if (detectRunInfo.isPresent()) {

        DetectLogParser logParser = new DetectLogParser();

        logger.info("Doctor can proceed, necessary pieces located.");

        File log = detectRunInfo.get().getLogFile();

        DetectLogParseResult result = logParser.parse(log);

        logger.info("Detect log parsed.");

        String extractionId = doctorConfiguration.getProperty(DoctorProperty.DETECT_EXTRACTION_ID);

        Set<String> extractions = new HashSet<>();

        LoggedDetectExtraction extraction = null;
        for (LoggedDetectExtraction possibleExtraction : result.loggedConfiguration.extractions) {
            extractions.add(possibleExtraction.extractionIdentifier);
            if (possibleExtraction.extractionIdentifier.equals(extractionId)) {
                extraction = possibleExtraction;
            }
        }

        if (StringUtils.isBlank(extractionId)) {
            quit("Doctor needs an extraction to work with, options are: "
                    + extractions.stream().collect(Collectors.joining(",")));
        }

        if (extraction == null) {
            quit("No extraction found for given id: " + extractionId);
        }

        logger.info("Found extraction with id: " + extractionId);
        logger.info("Doctor will attempt to diagnose!");

        logger.info("We begin by rebuilding the configuration.");
        Map<String, String> propertyMap = new HashMap<>();
        result.loggedConfiguration.loggedPropertyList.stream().forEach(it -> propertyMap.put(it.key, it.value));
        RehydratedPropertySource rehydratedPropertySource = new RehydratedPropertySource(propertyMap);
        DetectConfiguration detectConfiguration = new DetectConfiguration(
                new DetectPropertySource(rehydratedPropertySource), new DetectPropertyMap());

        ExtractionHandler extractionHandler = new ExtractionHandler();
        extractionHandler.processExtraction(extraction, detectRunInfo.get(), detectConfiguration);

    } else {
        quit("Neccessary pieces not found for doctor to proceed.");
    }

}

From source file:org.springframework.boot.SpringApplication.java

/**
 * Called after the context has been refreshed.
 * @param context the application context
 * @param args the application argumments
 *///from  w w w . j ava 2 s  .c  om
protected void afterRefresh(ConfigurableApplicationContext context, ApplicationArguments args) {
    afterRefresh(context, args.getSourceArgs());
    callRunners(context, args);
}

From source file:org.springframework.boot.SpringApplication.java

private void callRunner(CommandLineRunner runner, ApplicationArguments args) {
    try {/*w ww.  j av a 2 s  . com*/
        (runner).run(args.getSourceArgs());
    } catch (Exception ex) {
        throw new IllegalStateException("Failed to execute CommandLineRunner", ex);
    }
}