Java Code Examples for org.springframework.boot.ApplicationArguments#containsOption()

The following examples show how to use org.springframework.boot.ApplicationArguments#containsOption() . 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 File: CacheProcessor.java    From coolretailer with Apache License 2.0 6 votes vote down vote up
@NewSpan
public void run(ApplicationArguments args) throws Exception {
	if (args.containsOption("clear-cache")) {
		clearCache();
	}

	if (args.containsOption("process-cache")) {
		List<String> cacheOptions = args.getOptionValues("process-cache");
		if (cacheOptions.size() == 1) {
			processCache(cacheOptions.get(0));
		} else {
			processCache(null);
		}
		if (args.containsOption("exit")) {
			Runtime.getRuntime().halt(0);
		}
	}
}
 
Example 2
Source File: WebApplication.java    From TrackRay with GNU General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) {

		ApplicationArguments applicationArguments = new DefaultApplicationArguments(
				args);


		String releaseDir = PropertyUtil.getProperty("trackray.release.dir");
		String root = System.getProperty("user.dir");

		if (!root.contains(releaseDir)){
			System.err.println("请检查工作目录是否在配置文件指定的 "+releaseDir+" 发布目录");
			System.exit(0);
		}

		if (applicationArguments.containsOption("help")){
			help(applicationArguments);
		}else{
			run(args,applicationArguments);
		}

	}
 
Example 3
Source File: TestConsumer.java    From spring-cloud-consul with Apache License 2.0 6 votes vote down vote up
@Override
public void run(ApplicationArguments args) throws Exception {
	logger.info("Consumer running with binder {}", this.binder);
	SubscribableChannel consumerChannel = new ExecutorSubscribableChannel();
	consumerChannel.subscribe(new MessageHandler() {
		@Override
		public void handleMessage(Message<?> message) throws MessagingException {
			TestConsumer.this.messagePayload = (String) message.getPayload();
			logger.info("Received message: {}", TestConsumer.this.messagePayload);
		}
	});
	String group = null;

	if (args.containsOption("group")) {
		group = args.getOptionValues("group").get(0);
	}

	this.binder.bindConsumer(ConsulBinderTests.BINDING_NAME, group, consumerChannel,
			new ConsumerProperties());
	this.isBound = true;
}
 
Example 4
Source File: JsonProcessor.java    From coolretailer with 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 5
Source File: WebApplication.java    From TrackRay with GNU General Public License v3.0 5 votes vote down vote up
private static void run(String[] args, ApplicationArguments applicationArguments) {

		if (!applicationArguments.getNonOptionArgs().isEmpty()){
			List<String> funcArgs = applicationArguments.getNonOptionArgs();
			for (String f : TrackrayConfiguration.Function.names()) {
				if (funcArgs.contains(f)){
					//TrackrayConfiguration.sysVariable.put(f,true);
					TrackrayConfiguration.Function.valueOf(f).setEnable(true);
				}else{
					//TrackrayConfiguration.sysVariable.put(f,false);
					TrackrayConfiguration.Function.valueOf(f).setEnable(false);
				}
			}
		}


		if (!applicationArguments.getOptionNames().isEmpty()){

			if (applicationArguments.containsOption("burp.local")){
				BurpSuiteConfiguration.mode = BurpSuiteConfiguration.Mode.LOCAL;
			}else if (applicationArguments.containsOption("burp.remote")){
				BurpSuiteConfiguration.mode = BurpSuiteConfiguration.Mode.REMOTE;
			}
		}

		loadPlugins(applicationArguments);

		SpringApplication.run(WebApplication.class, args);

	}
 
Example 6
Source File: MyBean.java    From blog with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Autowired
public MyBean(ApplicationArguments args) {
	boolean debug = args.containsOption("debug");
	System.err.println("myBean<debug>:" + debug);
	List<String> files = args.getNonOptionArgs();
	System.err.println("myBean<files>:" + files);
}
 
Example 7
Source File: FunctionDeployerConfiguration.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
private ApplicationArguments updateArguments(ApplicationArguments arguments) {
	List<String> originalArguments =  new ArrayList<String>(Arrays.asList(arguments.getSourceArgs()));

	if (arguments.containsOption("function.name")) {
		originalArguments.add(FunctionProperties.PREFIX + ".definition=" + arguments.getOptionValues("function.name").get(0));
	}
	if (arguments.containsOption("function.location")) {
		originalArguments.add(FunctionProperties.PREFIX + ".location=" + arguments.getOptionValues("function.location").get(0));
	}
	ApplicationArguments updatedArguments = new DefaultApplicationArguments(originalArguments.toArray(new String[] {}));
	return updatedArguments;
}
 
Example 8
Source File: BurpService.java    From burp-rest-api with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Autowired
public BurpService(ApplicationArguments args,
                   @Value("${headless.mode}") boolean headlessMode,
                   @Value("${burp.jar:#{null}}") String burpJar,
                   @Value("${burp.ext:#{null}}") String burpExtension)
        throws IOException, ClassNotFoundException, NoSuchMethodException,
        InvocationTargetException, IllegalAccessException, URISyntaxException {
    if (!headlessMode) {
        log.info("Setting java.awt.headless to false...");
        System.setProperty("java.awt.headless", Boolean.toString(false));
    }
    log.info("# of command line arguments received to Burp suite: {}", args.getSourceArgs().length);
    log.info("Launching Burp suite in {} mode...", headlessMode ? "headless" : "UI");

    String[] projectData;
    String[] projectOptions;
    String[] userOptions;

    UserConfigUtils ucu = new UserConfigUtils();

    //Include the REST API Plugin User Options config
    restApiPath = extractPlugin();
    ucu.registerBurpExtension(restApiPath);

    if (burpExtension != null) {
        log.info("Loading extensions {}", burpExtension);
        for (String extension : burpExtension.split(",")) {
            ucu.registerBurpExtension(Paths.get(extension).toAbsolutePath().normalize().toString());
        }
    }

    //Project Data File
    if (!args.containsOption(PROJECT_FILE)) {
        projectData = new String[]{generateProjectDataTempFile()};
    } else {
        projectData = args.getOptionValues(PROJECT_FILE).stream().toArray(String[]::new);
        for(int i = 0; i < projectData.length; i++) {
            projectData[i] = PROJECT_FILE_ARGUMENT + projectData[i];
        }
    }

    //Project Options File
    if (!args.containsOption(CONFIG_FILE)) {
        projectOptions = new String[]{generateProjectOptionsTempFile()};
    } else {
        projectOptions = args.getOptionValues(CONFIG_FILE).stream().toArray(String[]::new);
        for(int i = 0; i < projectOptions.length; i++) {
            projectOptions[i] = CONFIG_FILE_ARGUMENT + projectOptions[i];
        }
    }

    //User Options File
    if (!args.containsOption(USER_CONFIG_FILE)) {
        userOptions = new String[]{USER_CONFIG_FILE_ARGUMENT + ucu.injectExtensions(generateUserOptionsTempFile())};
    } else {
        userOptions = args.getOptionValues(USER_CONFIG_FILE).stream().toArray(String[]::new);
        for(int i = 0; i < userOptions.length; i++) {
            userOptions[i] = USER_CONFIG_FILE_ARGUMENT + ucu.injectExtensions(userOptions[i]);
        }
    }
    String[] burpOptions = Stream.concat(Arrays.stream(projectData), Arrays.stream(projectOptions)).toArray(String[]::new);
    burpOptions = Stream.of(
            Arrays.stream(args.getSourceArgs()),
            Arrays.stream(burpOptions),
            Arrays.stream(userOptions))
            .reduce(Stream::concat).orElseGet(Stream::empty).toArray(String[]::new);

    log.info("Launching the Burp with options: {}", Arrays.toString(burpOptions));
    if (burpJar != null) {
        log.info("Injecting ClassLoader with Jar: {}", burpJar);
        URL url = new File(burpJar).toURI().toURL();
        injectClassLoader(url);
    }
    BurpService.class.getClassLoader().loadClass("burp.StartBurp")
            .getMethod("main", String[].class)
            .invoke(null, (Object)burpOptions);

    scans = new ScanQueueMap();
    spiders = new SpiderQueueMap(3000);
}
 
Example 9
Source File: GenerateWiki.java    From ogham with Apache License 2.0 4 votes vote down vote up
@Override
public void run(ApplicationArguments args) throws Exception {
	if(args.containsOption("wiki")) {
		generate();
	}
}
 
Example 10
Source File: GenerateReadme.java    From ogham with Apache License 2.0 4 votes vote down vote up
@Override
public void run(ApplicationArguments args) throws Exception {
	if(args.containsOption("readme")) {
		generate();
	}
}