Java Code Examples for org.springframework.boot.ApplicationArguments

The following examples show how to use org.springframework.boot.ApplicationArguments. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: KOMORAN   Source File: SetupDefaultData.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void run(ApplicationArguments args) throws IOException {
    logger.debug("DicWord : " + dicWordRepository.count());
    logger.debug("GrammarIn : " + grammarInRepository.count());

    // Initialize DicWord
    if (dicWordRepository.count() <= 0 && getDefaultFilePath("dicword") != null) {
        logger.debug("Importing DicWord from file named " + filenameDicWord);
        dicWordService.importFromFile(getDefaultFilePath("dicword"));
    }

    // Initialize GrammarIn
    if (grammarInRepository.count() <= 0 && getDefaultFilePath("grammarin") != null) {
        logger.debug("Importing GrammarIn from file named " + filenameGrammarIn);
        grammarInService.importFromFile(getDefaultFilePath("grammarin"));
    }
}
 
Example 2
@Override
public void run(ApplicationArguments args) throws Exception {
	// if we have args, assume one time run
	ArrayList<String> argsToShellCommand = new ArrayList<>();
	for (String arg : args.getSourceArgs()) {
		// consider client connection options as non command args
		if (!arg.contains("spring.cloud.skipper.client")) {
			argsToShellCommand.add(arg);
		}
	}
	if (argsToShellCommand.size() > 0) {
		if (ShellUtils.hasHelpOption(args)) {
			// going into 'help' mode. HelpAwareShellApplicationRunner already
			// printed usage, we just force running just help.
			argsToShellCommand.clear();
			argsToShellCommand.add("help");
		}
	}

	if (!argsToShellCommand.isEmpty()) {
		InteractiveShellApplicationRunner.disable(environment);
		shell.run(new StringInputProvider(argsToShellCommand));
	}
}
 
Example 3
Source Project: circus-train   Source File: HousekeepingRunner.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void run(ApplicationArguments args) {
  Instant deletionCutoff = new Instant().minus(housekeeping.getExpiredPathDuration());
  LOG.info("Housekeeping at instant {} has started", deletionCutoff);
  CompletionCode completionCode = CompletionCode.SUCCESS;
  try {
    housekeepingService.cleanUp(deletionCutoff);
    LOG.info("Housekeeping at instant {} has finished", deletionCutoff);
  } catch (Exception e) {
    completionCode = CompletionCode.FAILURE;
    LOG.error("Housekeeping at instant {} has failed", deletionCutoff, e);
    throw e;
  } finally {
    Map<String, Long> metricsMap = ImmutableMap
        .<String, Long>builder()
        .put("housekeeping", completionCode.getCode())
        .build();
    metricSender.send(metricsMap);
  }
}
 
Example 4
@Override
public void run(ApplicationArguments args) throws Exception {
	// user just wants to print help, do not try
	// to init connection. HelpAwareShellApplicationRunner simply output
	// usage and InteractiveModeApplicationRunner forces to run help.
	if (ShellUtils.hasHelpOption(args)) {
		return;
	}

	Target target = new Target(skipperClientProperties.getServerUri(), skipperClientProperties.getUsername(),
			skipperClientProperties.getPassword(), skipperClientProperties.isSkipSslValidation());

	// Attempt connection (including against default values) but do not crash the shell on
	// error
	try {
		targetHolder.changeTarget(target, null);
	}
	catch (Exception e) {
		resultHandler.handleResult(e);
	}

}
 
Example 5
@Override
public void run(ApplicationArguments args) throws Exception {
	if (ShellUtils.hasHelpOption(args)) {
		String usageInstructions;

		final Reader reader = new InputStreamReader(getInputStream(HelpAwareShellApplicationRunner.class, "/usage.txt"));

		try {
			usageInstructions = FileCopyUtils.copyToString(new BufferedReader(reader));
			usageInstructions.replaceAll("(\\r|\\n)+", System.getProperty("line.separator"));
		}
		catch (Exception ex) {
			throw new IllegalStateException("Cannot read stream", ex);
		}
		System.out.println(usageInstructions);
	}
}
 
Example 6
Source Project: Aooms   Source File: AoomsApplicationRunner.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void run(ApplicationArguments applicationArguments) {
    LogUtils.info("Aooms("+ Aooms.VERSION +") Start Sucess, At " + DateUtil.now());

    ApplicationContext context = SpringUtils.getApplicationContext();
    ServiceConfigurations serviceConfigurations = context.getBean(ServiceConfigurations.class);
    AoomsWebMvcConfigurer webMvcConfigurer = (AoomsWebMvcConfigurer) context.getBean("webMvcConfigurer");

    String[] beanNames = context.getBeanNamesForType(AoomsSetting.class);
    LogUtils.info("SettingBeanNames = " + JSON.toJSONString(beanNames));
    for(String name : beanNames){
        AoomsSetting settingBean = (AoomsSetting)context.getBean(name);
        //settingBean.configInterceptor(webMvcConfigurer.getInterceptorRegistryProxy());
        settingBean.configProps(Aooms.self().getPropertyObject());
        settingBean.configService(serviceConfigurations);
        settingBean.onFinish(Aooms.self());
    }
    //Set<Class<?>> classes = ClassScaner.scanPackageByAnnotation("net",AoomsSettingBean.class);
    //System.err.println(classes.size());
}
 
Example 7
Source Project: fabric-net-server   Source File: FabricEdgeRunner.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void run(ApplicationArguments args) {
    if (!hadSuperAdmin()) {
        initRola();
    }
    addUser();
    System.out.println();
    System.out.println(" _____   _   _   ____    ");
    System.out.println("| ____| | \\ | | |  _ \\   ");
    System.out.println("|  _|   |  \\| | | | | |  ");
    System.out.println("| |___  | |\\  | | |_| |  ");
    System.out.println("|_____| |_| \\_| |____/   ");
    System.out.println();
    System.out.println("===================== please make your fabric net work ===================== ");
    System.out.println();
    System.out.println("================================= read logs ================================ ");
}
 
Example 8
@Override
public void run(ApplicationArguments args) throws Exception {

	Flux<String> stringFlux = Flux
		.just("Josh", "Rada", "Jason", "Ming",
			"Kieran", "Rudrakshi", "Sean", "Sumi");

	Flux<Reservation> flux = stringFlux
		.map(name -> new Reservation(null, name))
		.flatMap(this.reservationRepository::save);

	this.reservationRepository
		.deleteAll()
		.thenMany(flux)
		.thenMany(this.reservationRepository.findAll())
		.subscribe(System.out::println);


}
 
Example 9
@Override
		public void run(ApplicationArguments args) throws Exception {

				Author viktor = new Author("viktorklang");
				Author jboner = new Author("jboner");
				Author josh = new Author("starbuxman");

				Flux<Tweet> tweets = Flux.just(
					new Tweet(viktor, "woot, @Konrad will be talking #enterprise #integration done right!"),
					new Tweet(viktor, "#scala implicits can easily be used to model capabilities, but can they encode obligations easily?"),
					new Tweet(viktor, "this is so cool! #akka"),
					new Tweet(jboner, "cross data center replication of event sourced #akka actors is soon available (using #crdts and more!)"),
					new Tweet(josh, "a reminder: @SpringBoot lets you pair program with the #Spring team. #bootiful"),
					new Tweet(josh, "whatever your next platform is, don't build it yourself.\n\n" +
						"Even companies with the $$ and the motivation to do it fail. A LOT. #bootiful")
				);
				this
					.tweetRepository
					.deleteAll()
					.thenMany(tweets.flatMap(tweetRepository::save))
					.thenMany(tweetRepository.findAll())
//					.subscribeOn(Schedulers.fromExecutor(Executors.newSingleThreadExecutor()))
					.subscribe(System.out::println);
		}
 
Example 10
@Override
public void run(ApplicationArguments args) throws Exception {
    ImageBanner imageBanner = new ImageBanner(
            this.resolveInputImage());

    int maxWidth = this.properties.getMaxWidth();
    double aspectRatio = this.properties.getAspectRatio();
    boolean invert = this.properties.isInvert();
    Resource output = this.properties.getOutput();

    String banner = imageBanner.printBanner(maxWidth, aspectRatio, invert);
    if (output != null) {
        try (PrintWriter pw = new PrintWriter(output.getFile(), "UTF-8")) {
            pw.println(banner);
        }
    } else {
        System.out.println(banner);
    }
}
 
Example 11
Source Project: sk-admin   Source File: JobRunner.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 项目启动时重新激活启用的定时任务
 * @param applicationArguments /
 */
@Override
public void run(ApplicationArguments applicationArguments){
    System.out.println("-------------------- 开始注入定时任务 ---------------------");
    List<QuartzJob> quartzJobs = quartzJobDao.findByIsPauseIsFalse();
    quartzJobs.forEach(quartzManage::addJob);
    System.out.println("-------------------- 定时任务注入完成 ---------------------");
}
 
Example 12
Source Project: lightning   Source File: CliParamsTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testGetParsedCommand_report() {
    ApplicationArguments args = Mockito.mock(ApplicationArguments.class);
    List<String> values = Collections.singletonList("report");

    Mockito.when(args.getNonOptionArgs()).thenReturn(values);

    Optional<String> command = new CliParams(args).getParsedCommand();
    assertThat(command).isEqualTo(Optional.of("report"));
}
 
Example 13
Source Project: lightning   Source File: CliParamsTest.java    License: MIT License 5 votes vote down vote up
@Test(expectedExceptions = RuntimeException.class)
public void testGetFileFromOptionValue_nonexistent() {
    ApplicationArguments args = Mockito.mock(ApplicationArguments.class);
    List<String> values = Collections.singletonList("nonexistent");

    Mockito.when(args.containsOption("xml")).thenReturn(false);
    Mockito.when(args.getOptionValues("xml")).thenReturn(values);

    new CliParams(args).getFileFromOptionValue("xml");
}
 
Example 14
Source Project: das   Source File: UserInitCommandLineRunner.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void run(ApplicationArguments args) {
    DasEnv.setDefaultConfiguration(defaultConfiguration);
    DasEnv.setAdditionalConfiguration(additionalConfiguration);
    DasEnv.setEncdecConfiguration(encdecConfiguration);
    //log.info("---==--- 服务启动后,当前环境 ---==---> " + consts.springActive);
    log.info("---==--- 服务启动后,当前路径 ---==---> " + ResourceUtil.getSingleInstance().getDbXmlPath());
    log.info("---==--- 服务启动后,文件路径 ---==---> " + consts.codeConsoleilePath);
    //log.info("---==--- 服务启动后,加解密组件 ---==---> 加密前:" + pwd + " 加密后: " + DasEnv.encdecConfiguration.encrypt(pwd));
}
 
Example 15
Source Project: ogham   Source File: CleanerRunner.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void run(ApplicationArguments args) throws Exception {
	boolean override = args.getOptionValues("override")!=null;
	if(!override) {
		return;
	}
	Path parentFolder = Paths.get(args.getNonOptionArgs().get(0));
	log.info("Cleaning {}", parentFolder);
	Files.createDirectories(parentFolder);
	FileUtils.cleanDirectory(parentFolder.toFile());
}
 
Example 16
Source Project: coolretailer   Source File: JsonProcessor.java    License: Apache License 2.0 5 votes vote down vote up
public void run(ApplicationArguments args) throws Exception {
	if (args.containsOption("input.json")) {
		toNdJson(args.getOptionValues("input.json").get(0));
		if (args.containsOption("exit")) {
			System.exit(0);
		}
	}
}
 
Example 17
Source Project: cf-butler   Source File: DatabaseCreator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void run(ApplicationArguments args) {
	String line; String provider = ""; String ddl = ""; String location = "";
	try {
		provider = settings.getProvider().toLowerCase().replaceAll("\\s","");
		location = String.join("/", "classpath:db", provider, "schema.ddl");
		Resource schema = resourceLoader.getResource(location);
		InputStream is = schema.getInputStream();
		BufferedReader br = new BufferedReader(new InputStreamReader(is));
		while ((line = br.readLine()) != null) {
			if (!line.isBlank()) {
				ddl = line.strip().replace(";","");
				client.execute(ddl)
					.then()
					.doOnError(e -> {
						log.error(e.getMessage());
						System.exit(1);
					}).subscribe();
			}
		}
		br.close();
		publisher.publishEvent(new DatabaseCreatedEvent(this));
	} catch (IOException ioe) {
		log.error(String.format("Failed trying to read %s\n", location), ioe);
		System.exit(1);
	}
}
 
Example 18
Source Project: syndesis   Source File: Application.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@SuppressFBWarnings("DM_EXIT")
public void run(ApplicationArguments args) {
    try {
        System.out.println("To: "+to); //NOPMD
        generateIntegrationProject(new File(to));
    } catch (IOException e) {
        e.printStackTrace(); //NOPMD
        System.exit(1); //NOPMD
    }
}
 
Example 19
Source Project: circus-train   Source File: FilterToolApplication.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void run(ApplicationArguments args) {
  LOG.info("{} tables to replicate.", tableReplications.size());
  for (TableReplication tableReplication : tableReplications) {
    try {
      FilterGenerator filterGenerator = filterGeneratorFactory.newInstance(tableReplication);
      filterGenerator.run();
    } catch (Throwable t) {
      LOG.error("Failed.", t);
    }
  }

}
 
Example 20
Source Project: star-zone   Source File: MyApplicationRunner.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void run(ApplicationArguments args) throws Exception {
    shardMysqlService.buildShardMapForAll();
    log.info("MyApplicationRunner--run.");

    String str0 = JSON.toJSONString(CustomSingleton.getInstance().getMomentLikeShardMap());
    String str1 = JSON.toJSONString(CustomSingleton.getInstance().getOrderShardMap());
    log.info("getMomentLikeShardMap={}" , str0);
    log.info("-----------------------");
    log.info("getOrderShardMap={}", str1);
}
 
Example 21
Source Project: WeBASE-Collect-Bee   Source File: CrawlApplicationRunner.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void run(ApplicationArguments var1) throws InterruptedException {
    if (systemEnvironmentConfig.getCrawlBatchUnit() < 1) {
        log.error("The batch unit threshold can't be less than 1!!");
        System.exit(1);
    }
    handle();
}
 
Example 22
Source Project: web-flash   Source File: StartJob.java    License: MIT License 5 votes vote down vote up
@Override
public void run(ApplicationArguments applicationArguments) throws Exception {
    log.info("start Job >>>>>>>>>>>>>>>>>>>>>>>");
    List<QuartzJob> list = jobService.getTaskList();
    for (QuartzJob quartzJob : list) {
        jobService.addJob(quartzJob);
    }
}
 
Example 23
Source Project: springboot-learn   Source File: ApplicationRunnerImpl.java    License: MIT License 5 votes vote down vote up
@Override
public void run(ApplicationArguments args) throws Exception {
    System.out.println("通过实现ApplicationRunner接口,在spring boot项目启动后打印参数");
    String[] sourceArgs = args.getSourceArgs();
    for (String arg : sourceArgs) {
        System.out.print(arg + " ");
    }
    System.out.println();
}
 
Example 24
Source Project: lightning   Source File: CliParamsTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testIsHelpRequested_false() {
    ApplicationArguments args = Mockito.mock(ApplicationArguments.class);

    Mockito.when(args.containsOption("h")).thenReturn(false);
    Mockito.when(args.containsOption("help")).thenReturn(false);

    boolean is = new CliParams(args).isHelpRequested();
    assertThat(is).isEqualTo(false);
}
 
Example 25
@Bean
public ApplicationRunner runner(final UrlRestClient client) {
	return new ApplicationRunner() {

		@Override
		public void run(ApplicationArguments args) throws Exception {
			System.err.println(client.hello());
		}
	};
}
 
Example 26
Source Project: flash-waimai   Source File: StartJob.java    License: MIT License 5 votes vote down vote up
@Override
public void run(ApplicationArguments applicationArguments) throws Exception {
    log.info("start Job >>>>>>>>>>>>>>>>>>>>>>>");
    List<QuartzJob> list = jobService.getTaskList();
    for (QuartzJob quartzJob : list) {
        jobService.addJob(quartzJob);
    }
}
 
Example 27
@Override
public void run(ApplicationArguments var1) throws Exception {

    log.info("Begin to generate code.");
    codeGenerateService.generateBee();
    log.info("Code generation Finished!");       
    Runtime.getRuntime().exit(0);
}
 
Example 28
public void run(ApplicationArguments applicationArguments) throws Exception {

    	System.out.println(">>> Iniciando carga de dados...");
    	Cliente fernando = new Cliente(ID_CLIENTE_FERNANDO,"Fernando Boaglio","Sampa");
    	Cliente zePequeno = new Cliente(ID_CLIENTE_ZE_PEQUENO,"Zé Pequeno","Cidade de Deus");    	
    	
    	Item dog1 = new Item(ID_ITEM1,"Green Dog tradicional",25d);
    	Item dog2 = new Item(ID_ITEM2,"Green Dog tradicional picante",27d);
		Item dog3 = new Item(ID_ITEM3,"Green Dog max salada",30d);
    	
    	List<Item> listaPedidoFernando1 = new ArrayList<Item>();
    	listaPedidoFernando1.add(dog1);

    	List<Item> listaPedidoZePequeno1 = new ArrayList<Item>();
    	listaPedidoZePequeno1.add(dog2);
    	listaPedidoZePequeno1.add(dog3);
    	
    	Pedido pedidoDoFernando = new Pedido(ID_PEDIDO1,fernando,listaPedidoFernando1,dog1.getPreco());
    	fernando.novoPedido(pedidoDoFernando);
    	
    	Pedido pedidoDoZepequeno = new Pedido(ID_PEDIDO2,zePequeno,listaPedidoZePequeno1, dog2.getPreco()+dog3.getPreco());
    	zePequeno.novoPedido(pedidoDoZepequeno);
    	
    	System.out.println(">>> Pedido 1 - Fernando : "+ pedidoDoFernando);
    	System.out.println(">>> Pedido 2 - Ze Pequeno: "+ pedidoDoZepequeno);
    	
       
		clienteRepository.saveAndFlush(zePequeno);
		System.out.println(">>> Gravado cliente 2: "+zePequeno);

		List<Item> listaPedidoFernando2 = new ArrayList<Item>();
		listaPedidoFernando2.add(dog2);
    	Pedido pedido2DoFernando  = new Pedido(ID_PEDIDO3,fernando,listaPedidoFernando2,dog2.getPreco());
    	fernando.novoPedido(pedido2DoFernando);
    	clienteRepository.saveAndFlush(fernando);
    	System.out.println(">>> Pedido 2 - Fernando : "+ pedido2DoFernando);
    	System.out.println(">>> Gravado cliente 1: "+fernando);
		
    }
 
Example 29
Source Project: AuTe-Framework   Source File: TestRunner.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void run(ApplicationArguments args) {
    if (args.getNonOptionArgs().contains("execute")) {
        prepareLoggers();
        try {
            launcher.launch(new ExternalVariables(args).get());
        } catch (Exception e) {
            log.error("Error while running tests", e);
        }
    }
}
 
Example 30
Source Project: lightning   Source File: CliParamsTest.java    License: MIT License 5 votes vote down vote up
@Test(expectedExceptions = RuntimeException.class)
public void testGetFileFromOptionValue_notProvided() {
    ApplicationArguments args = Mockito.mock(ApplicationArguments.class);

    Mockito.when(args.containsOption("xml")).thenReturn(false);

    new CliParams(args).getFileFromOptionValue("xml");
}