Example usage for org.springframework.core.env SimpleCommandLinePropertySource SimpleCommandLinePropertySource

List of usage examples for org.springframework.core.env SimpleCommandLinePropertySource SimpleCommandLinePropertySource

Introduction

In this page you can find the example usage for org.springframework.core.env SimpleCommandLinePropertySource SimpleCommandLinePropertySource.

Prototype

public SimpleCommandLinePropertySource(String... args) 

Source Link

Document

Create a new SimpleCommandLinePropertySource having the default name and backed by the given String[] of command line arguments.

Usage

From source file:com.todo.backend.BackendApplication.java

public static void main(String[] args) {
    final SpringApplication app = new SpringApplication(BackendApplication.class);
    final SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
    if (!source.containsProperty("spring.profiles.active")
            && !System.getenv().containsKey("SPRING_PROFILES_ACTIVE")) {
        app.setAdditionalProfiles("dev");
    }/*from w  w w. jav  a  2s .c om*/
    app.run(args).getEnvironment();
}

From source file:org.dawnsci.marketplace.MarketplaceApplication.java

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    // convert the command line argument to properties
    CommandLinePropertySource<?> ps = new SimpleCommandLinePropertySource(args);
    ctx.getEnvironment().getPropertySources().addFirst(ps);
    ctx.register(ApplicationConfiguration.class);
    ctx.refresh();/* w  w  w  .ja va  2 s. co m*/
    try {
        SpringApplication.run(MarketplaceApplication.class, args);
    } finally {
        ctx.close();
    }
}

From source file:org.obiba.mica.Application.java

/**
 * Main method, used to run the application.
 * <p/>/*w w  w.ja v a  2s  .co  m*/
 * To run the application with hot reload enabled, add the following arguments to your JVM:
 * "-javaagent:spring_loaded/springloaded-jhipster.jar -noverify -Dspringloaded=plugins=io.github.jhipster.loaded.instrument.JHipsterLoadtimeInstrumentationPlugin"
 */
public static void main(String... args) {

    checkSystemProperty("MICA_HOME");

    SpringApplicationBuilder app = new SpringApplicationBuilder(Application.class).bannerMode(Banner.Mode.OFF);

    SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);

    // Check if the selected profile has been set as argument.
    // if not the development profile will be added
    addDefaultProfile(app, source);

    app.run(args);
}

From source file:fi.helsinki.opintoni.Application.java

/**
 * Main method, used to run the application.
 *//*from  w ww  . j a  v a 2 s.  com*/
public static void main(String[] args) throws UnknownHostException {
    SpringApplication app = new SpringApplication(Application.class);
    app.setBannerMode(Banner.Mode.OFF);

    SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);

    // Check if the selected profile has been set as argument.
    // if not the development profile will be added
    addDefaultProfile(app, source);
    addLiquibaseScanPackages();
    Environment env = app.run(args).getEnvironment();
    log.info(
            "Access URLs:\n----------------------------------------------------------\n\t"
                    + "Local: \t\thttp://127.0.0.1:{}\n\t"
                    + "External: \thttp://{}:{}\n----------------------------------------------------------",
            env.getProperty("server.port"), InetAddress.getLocalHost().getHostAddress(),
            env.getProperty("server.port"));

}

From source file:com.acapulcoapp.alloggiatiweb.AddRegion.java

public static void main(String[] args) throws UnknownHostException, IOException {
    // TODO code application logic here

    SpringApplication app = new SpringApplication(AcapulcoappApp.class);
    SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
    addDefaultProfile(app, source);//ww  w .ja v a2s .c  om

    ConfigurableApplicationContext context = app.run(args);

    initBeans(context);

    runTask();

    context.registerShutdownHook();

    System.exit(0);
}

From source file:com.mejmo.appletraus.server.AppletRausServerApplication.java

public static void main(String[] args) {

    SpringApplication app = new SpringApplication(AppletRausServerApplication.class);
    app.setShowBanner(false);/*from   w  ww.ja  v  a 2s  .co m*/
    SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);

    addDefaultProfile(app, source);

    propertySource = source;
    app.run(args).getEnvironment();
}

From source file:com.acapulcoapp.alloggiatiweb.FileReader.java

public static void main(String[] args) throws UnknownHostException, IOException {
    // TODO code application logic here

    SpringApplication app = new SpringApplication(AcapulcoappApp.class);
    SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
    addDefaultProfile(app, source);//from  w  ww  .  j  av  a2  s  . c o  m

    ConfigurableApplicationContext context = app.run(args);

    initBeans(context);

    Map<LocalDate, List<List<String>>> map = new TreeMap<>();

    List<File> files = new ArrayList<>(FileUtils.listFiles(new File("/Users/chiccomask/Downloads/ALLOGGIATI"),
            new String[] { "txt" }, true));

    Collections.reverse(files);

    int count = 0;

    for (File file : files) {

        //            List<String> allLines = FileUtils.readLines(file, "windows-1252");
        List<String> allLines = FileUtils.readLines(file, "UTF-8");

        for (int i = 0; i < allLines.size();) {

            count++;

            List<String> record = new ArrayList<>();

            String line = allLines.get(i);
            String type = TIPO_ALLOGGIO.parse(line);

            switch (type) {
            case "16":
                record.add(line);
                i++;
                break;
            case "17": {
                record.add(line);
                boolean out = false;
                while (!out) {
                    i++;
                    if (i < allLines.size()) {
                        String subline = allLines.get(i);
                        String subtype = TIPO_ALLOGGIO.parse(subline);
                        if (!subtype.equals("19")) {
                            out = true;
                        } else {
                            record.add(subline);
                        }
                    } else {
                        out = true;
                    }
                }
                break;
            }
            case "18": {
                record.add(line);
                boolean out = false;
                while (!out) {
                    i++;
                    if (i < allLines.size()) {
                        String subline = allLines.get(i);
                        String subtype = TIPO_ALLOGGIO.parse(subline);
                        if (!subtype.equals("20")) {
                            out = true;
                        } else {
                            record.add(subline);
                        }
                    } else {
                        out = true;
                    }
                }
                break;
            }
            default:
                break;
            }

            LocalDate arrived = LocalDate.parse(DATA_ARRIVO.parse(line),
                    DateTimeFormatter.ofPattern(DATE_PATTERN));
            if (!map.containsKey(arrived)) {
                map.put(arrived, new ArrayList<>());
            }
            map.get(arrived).add(record);
        }
    }

    for (LocalDate date : map.keySet()) {

        System.out.println();
        System.out.println("process day " + date);

        for (List<String> record : map.get(date)) {

            System.out.println();
            System.out.println("process record ");
            for (String line : record) {
                System.out.println(line);
            }

            CheckinRecord checkinRecord = new CheckinRecord();

            //non lo setto per adesso
            String firstLine = record.get(0);

            String typeStr = TIPO_ALLOGGIO.parse(firstLine);
            CheckinType cht = checkinTypeRepository.find(typeStr);
            checkinRecord.setCheckinType(cht);

            int days = Integer.parseInt(PERMANENZA.parse(firstLine));
            checkinRecord.setDays(days);
            checkinRecord.setArrived(date);

            boolean isMain = true;

            List<Person> others = new ArrayList<>();

            for (String line : record) {
                Person p = extractPerson(line);

                if (p.getDistrictOfBirth() == null) {
                    System.out.println("district of birth not found " + p);
                }

                List<Person> duplicates = personRepository.findDuplicates(p.getSurname(), p.getName(),
                        p.getDateOfBirth());

                if (duplicates.isEmpty()) {
                    System.out.println("add new person " + p.getId() + " " + p);
                    personRepository.saveAndFlush(p);
                } else if (duplicates.size() == 1) {

                    Person found = duplicates.get(0);

                    if (p.getIdentityDocument() != null) {
                        //we sorted by date so we suppose 
                        //the file version is newer so we update the entity
                        p.setId(found.getId());
                        System.out.println("update person " + p.getId() + " " + p);
                        personRepository.saveAndFlush(p);

                    } else if (found.getIdentityDocument() != null) {
                        //on db there are more data so I use them.
                        p = found;
                        System.out.println("use already saved person " + p.getId() + " " + p);
                    } else {
                        p.setId(found.getId());
                        System.out.println("update person " + p.getId() + " " + p);
                        personRepository.saveAndFlush(p);
                    }

                } else {
                    throw new RuntimeException("More duplicated for " + p.getName());
                }

                if (isMain) {
                    checkinRecord.setMainPerson(p);
                    isMain = false;
                } else {
                    others.add(p);
                }
            }

            checkinRecord.setOtherPeople(new HashSet<>(others));

            if (checkinRecordRepository.alreadyExists(checkinRecord.getMainPerson(), date) != null) {
                System.out.println("already exists " + date + " p " + checkinRecord.getMainPerson());
            } else {
                System.out.println("save record ");
                checkinRecordRepository.saveAndFlush(checkinRecord);
            }
        }
    }

    //
    //            if (type.equals("16")) {
    //                List<String> record = new ArrayList<>();
    //                record.add(line);
    //                keepOpen = false;
    //            }
    //
    //            map.get(arrived).add(record);
    //        map.values().forEach((list) -> {
    //
    //            for (String line : list) {
    //
    //                Person p = null;
    //
    //                try {
    //
    //                    p = extractPerson(line);
    //
    //                    List<Person> duplicates = personRepository.findDuplicates(p.getSurname(), p.getName(), p.getDateOfBirth());
    //
    //                    if (duplicates.isEmpty()) {
    //                        personRepository.saveAndFlush(p);
    //
    //                    } else if (duplicates.size() > 1) {
    //                        System.out.println();
    //                        System.out.println("MULIPLE DUPLICATED");
    //
    //                        for (Person dd : duplicates) {
    //                            System.out.println(dd);
    //                        }
    //                        System.out.println("* " + p);
    //                        throw new RuntimeException();
    //                    } else {
    //
    ////                        if (!duplicates.get(0).getDistrictOfBirth().equals(p.getDistrictOfBirth())) {
    ////                        int index = 0;
    ////
    ////                        System.out.println();
    ////                        System.out.println("DUPLICATED");
    ////
    ////                        for (Person dd : duplicates) {
    ////                            System.out.println(dd);
    ////                            index++;
    ////                        }
    ////                        System.out.println("* " + p);
    ////                        System.out.println(file.getAbsolutePath() + " " + p);
    ////
    ////                        System.out.println();
    ////                        System.out.println();
    ////                        }
    ////                        duplicates.remove(0);
    ////                        personRepository.deleteInBatch(duplicates);
    ////                System.out.println();
    ////                System.out.println("Seleziona scelta");
    ////                Scanner s = new Scanner(System.in);
    ////                int selected;
    ////                try {
    ////                    selected = s.nextInt();
    ////                } catch (InputMismatchException e) {
    ////                    selected = 0;
    ////                }
    ////
    ////                if (duplicates.size() <= selected) {
    ////                    personRepository.deleteInBatch(duplicates);
    ////                    personRepository.saveAndFlush(p);
    ////                } else {
    ////                    duplicates.remove(selected);
    ////                    personRepository.deleteInBatch(duplicates);
    ////                }
    //                    }
    //
    //                } catch (Exception e) {
    //
    //                    System.out.println();
    ////                    System.out.println("ERROR READING lineCount=" + allLines.indexOf(line) + " line=" + line);
    ////                    System.out.println(file.getAbsolutePath());
    //                    System.out.println(p);
    //                    e.printStackTrace();
    //                    System.out.println();
    //                }
    //            }
    //        });
    context.registerShutdownHook();

    System.exit(0);
}

From source file:br.prof.salesfilho.oci.view.console.Main.java

@PostConstruct
public void init() throws FileNotFoundException, IOException {
    propertySource = new SimpleCommandLinePropertySource(applicationArguments.getSourceArgs());

    if (this.propertySource.containsProperty("classify")) {
        this.classify();
    }/*from   www  .j a  va  2  s.co m*/
    if (this.propertySource.containsProperty("normalyze")) {
        this.startNormalyze();
    }
    if (this.propertySource.containsProperty("extractFeatures")) {
        this.extractFeatures();
    }
    if (!(this.propertySource.containsProperty("classify") || this.propertySource.containsProperty("normalyze")
            || this.propertySource.containsProperty("extractFeatures"))) {
        this.usage();
    }
}

From source file:org.wso2.msf4j.spring.MSF4JSpringApplication.java

protected ConfigurableApplicationContext run(boolean doRefresh, String... args) {
    ConfigurableApplicationContext context = createApplicationContext();
    if (configurationClass != null) {
        registerIfAnnotationConfigApplicationContext(context);
    } else {//from w w w. ja  va  2  s .  c  om
        scanIfAnnotationConfigApplicationContext(context);
    }

    context.getEnvironment().getPropertySources().addFirst(new SimpleCommandLinePropertySource(args));

    if (doRefresh) {
        context.refresh();
    }
    return context;
}