List of usage examples for java.lang System getProperties
public static Properties getProperties()
From source file:com.jbrisbin.groovy.mqdsl.RabbitMQDsl.java
public static void main(String[] argv) { // Parse command line arguments CommandLine args = null;// w ww . j a v a2 s . c o m try { Parser p = new BasicParser(); args = p.parse(cliOpts, argv); } catch (ParseException e) { log.error(e.getMessage(), e); } // Check for help if (args.hasOption('?')) { printUsage(); return; } // Runtime properties Properties props = System.getProperties(); // Check for ~/.rabbitmqrc File userSettings = new File(System.getProperty("user.home"), ".rabbitmqrc"); if (userSettings.exists()) { try { props.load(new FileInputStream(userSettings)); } catch (IOException e) { log.error(e.getMessage(), e); } } // Load Groovy builder file StringBuffer script = new StringBuffer(); BufferedInputStream in = null; String filename = "<STDIN>"; if (args.hasOption("f")) { filename = args.getOptionValue("f"); try { in = new BufferedInputStream(new FileInputStream(filename)); } catch (FileNotFoundException e) { log.error(e.getMessage(), e); } } else { in = new BufferedInputStream(System.in); } // Read script if (null != in) { byte[] buff = new byte[4096]; try { for (int read = in.read(buff); read > -1;) { script.append(new String(buff, 0, read)); read = in.read(buff); } } catch (IOException e) { log.error(e.getMessage(), e); } } else { System.err.println("No script file to evaluate..."); } PrintStream stdout = System.out; PrintStream out = null; if (args.hasOption("o")) { try { out = new PrintStream(new FileOutputStream(args.getOptionValue("o")), true); System.setOut(out); } catch (FileNotFoundException e) { log.error(e.getMessage(), e); } } String[] includes = (System.getenv().containsKey("MQDSL_INCLUDE") ? System.getenv("MQDSL_INCLUDE").split(String.valueOf(File.pathSeparatorChar)) : new String[] { System.getenv("HOME") + File.separator + ".mqdsl.d" }); try { // Setup RabbitMQ String username = (args.hasOption("U") ? args.getOptionValue("U") : props.getProperty("mq.user", "guest")); String password = (args.hasOption("P") ? args.getOptionValue("P") : props.getProperty("mq.password", "guest")); String virtualHost = (args.hasOption("v") ? args.getOptionValue("v") : props.getProperty("mq.virtualhost", "/")); String host = (args.hasOption("h") ? args.getOptionValue("h") : props.getProperty("mq.host", "localhost")); int port = Integer.parseInt( args.hasOption("p") ? args.getOptionValue("p") : props.getProperty("mq.port", "5672")); CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host); connectionFactory.setPort(port); connectionFactory.setUsername(username); connectionFactory.setPassword(password); if (null != virtualHost) { connectionFactory.setVirtualHost(virtualHost); } // The DSL builder RabbitMQBuilder builder = new RabbitMQBuilder(); builder.setConnectionFactory(connectionFactory); // Our execution environment Binding binding = new Binding(args.getArgs()); binding.setVariable("mq", builder); String fileBaseName = filename.replaceAll("\\.groovy$", ""); binding.setVariable("log", LoggerFactory.getLogger(fileBaseName.substring(fileBaseName.lastIndexOf("/") + 1))); if (null != out) { binding.setVariable("out", out); } // Include helper files GroovyShell shell = new GroovyShell(binding); for (String inc : includes) { File f = new File(inc); if (f.isDirectory()) { File[] files = f.listFiles(new FilenameFilter() { @Override public boolean accept(File file, String s) { return s.endsWith(".groovy"); } }); for (File incFile : files) { run(incFile, shell, binding); } } else { run(f, shell, binding); } } run(script.toString(), shell, binding); while (builder.isActive()) { try { Thread.sleep(500); } catch (InterruptedException e) { log.error(e.getMessage(), e); } } if (null != out) { out.close(); System.setOut(stdout); } } finally { System.exit(0); } }
From source file:edu.kit.checkstyle.Main.java
/** * Loops over the files specified checking them for errors. The exit code * is the number of errors found in all the files. * @param aArgs the command line arguments **///from www.j a va2s . c om public static void main(String[] aArgs) { // parse the parameters final CommandLineParser clp = new PosixParser(); CommandLine line = null; try { line = clp.parse(OPTS, aArgs); } catch (final ParseException e) { e.printStackTrace(); usage(); } assert line != null; // setup the properties final Properties properties = System.getProperties(); final Configuration config = loadConfig(properties); AuditListener listener = new QualifiedListener(); final List<File> files = getFilesToProcess(line); final Checker checker = createChecker(config); checker.addListener(listener); checker.process(files); checker.destroy(); System.exit(0); }
From source file:MainClass.java
public static void main(String argv[]) { boolean debug = false;// change to get more errors if (argv.length != 5) { System.out.println("usage: copier <urlname> <src folder>" + "<dest folder> <start msg #> <end msg #>"); return;// w w w. j ava2 s. co m } try { URLName url = new URLName(argv[0]); String src = argv[1]; // source folder String dest = argv[2]; // dest folder int start = Integer.parseInt(argv[3]); // copy from message # int end = Integer.parseInt(argv[4]); // to message # // Get the default Session object Session session = Session.getInstance(System.getProperties(), null); // session.setDebug(debug); // Get a Store object that implements // the protocol. Store store = session.getStore(url); store.connect(); System.out.println("Connected..."); // Open Source Folder Folder folder = store.getFolder(src); folder.open(Folder.READ_WRITE); System.out.println("Opened source..."); if (folder.getMessageCount() == 0) { System.out.println("Source folder has no messages .."); folder.close(false); store.close(); } // Open destination folder, create if needed Folder dfolder = store.getFolder(dest); if (!dfolder.exists()) // create dfolder.create(Folder.HOLDS_MESSAGES); Message[] msgs = folder.getMessages(start, end); System.out.println("Got messages..."); // Copy messages into destination, folder.copyMessages(msgs, dfolder); System.out.println("Copied messages..."); // Close the folder and store folder.close(false); store.close(); System.out.println("Closed folder and store..."); } catch (Exception e) { e.printStackTrace(); } System.exit(0); }
From source file:org.atomspace.pi2c.runtime.Server.java
public static void main(String[] args) throws Exception { System.err.println("::: ----------------------------------------------------------------------- :::"); System.err.println("::: ------------------------------ STARTING ------------------------------:::"); System.err.println("::: ----------------------------------------------------------------------- :::"); System.err.println("\n::: SYSTEM-Properties: :::"); Set<?> properties = System.getProperties().keySet(); for (Object object : properties) { System.err.println("::: " + object.toString() + " = " + System.getProperty(object.toString())); }/*from ww w . j a v a 2s . co m*/ System.err.println("\n::: ENV-Properties: :::"); properties = System.getenv().keySet(); for (Object object : properties) { System.err.println("::: " + object.toString() + " = " + System.getenv(object.toString())); } windows = System.getProperty("os.name").toLowerCase().startsWith("windows"); linux = System.getProperty("os.name").toLowerCase().startsWith("linux"); sunos = System.getProperty("os.name").toLowerCase().startsWith("sun"); freebsd = System.getProperty("os.name").toLowerCase().startsWith("freebsd"); if (linux || sunos) { //USR2-Signal-Handel lookup internal Server STATUS for Linux or SunOS System.err.println("::: " + new Date() + "::: run unter Linux or SunOS :::"); addUnixSignalStatusHandle(); } else if (freebsd) { System.err.println("::: " + new Date() + "::: run unter FreeBSD :::"); } else if (windows) { //Gracefull Shutdown JFrame for Windows, because can not kill -15 <pid> on Window or in Eclipse Console System.err.println("::: " + new Date() + " ::: run unter windows :::"); addWindowsShutdownHandle(); } else { System.err.println("UNKNOWN OS:" + System.getProperty("os.name")); } status = STATUS_STARTING; Server server = new Server(); Thread serverThread = new Thread(server); serverThread.start(); //Thread can stop by Shutdown-Hook while (true) { try { Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); break; } } }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel gui = new JPanel(new BorderLayout(5, 5)); JPanel plafComponents = new JPanel(new FlowLayout(FlowLayout.RIGHT, 3, 3)); plafComponents.setBorder(new TitledBorder("FlowLayout(FlowLayout.RIGHT, 3,3)")); UIManager.LookAndFeelInfo[] plafInfos = UIManager.getInstalledLookAndFeels(); String[] plafNames = new String[plafInfos.length]; for (int ii = 0; ii < plafInfos.length; ii++) { plafNames[ii] = plafInfos[ii].getName(); }/*from w w w . ja va2 s . c o m*/ JComboBox plafChooser = new JComboBox(plafNames); plafComponents.add(plafChooser); JCheckBox pack = new JCheckBox("Pack on PLAF change", true); plafComponents.add(pack); plafChooser.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { int index = plafChooser.getSelectedIndex(); try { UIManager.setLookAndFeel(plafInfos[index].getClassName()); SwingUtilities.updateComponentTreeUI(frame); if (pack.isSelected()) { frame.pack(); frame.setMinimumSize(frame.getSize()); } } catch (Exception e) { e.printStackTrace(); } } }); gui.add(plafComponents, BorderLayout.NORTH); JPanel dynamicLabels = new JPanel(new BorderLayout(4, 4)); dynamicLabels.setBorder(new TitledBorder("BorderLayout(4,4)")); gui.add(dynamicLabels, BorderLayout.WEST); final JPanel labels = new JPanel(new GridLayout(0, 2, 3, 3)); labels.setBorder(new TitledBorder("GridLayout(0,2,3,3)")); JButton addNew = new JButton("Add Another Label"); dynamicLabels.add(addNew, BorderLayout.NORTH); addNew.addActionListener(new ActionListener() { private int labelCount = 0; public void actionPerformed(ActionEvent ae) { labels.add(new JLabel("Label " + ++labelCount)); frame.validate(); } }); dynamicLabels.add(new JScrollPane(labels), BorderLayout.CENTER); String[] header = { "Name", "Value" }; String[] a = new String[0]; String[] names = System.getProperties().stringPropertyNames().toArray(a); String[][] data = new String[names.length][2]; for (int ii = 0; ii < names.length; ii++) { data[ii][0] = names[ii]; data[ii][1] = System.getProperty(names[ii]); } DefaultTableModel model = new DefaultTableModel(data, header); JTable table = new JTable(model); JScrollPane tableScroll = new JScrollPane(table); Dimension tablePreferred = tableScroll.getPreferredSize(); tableScroll.setPreferredSize(new Dimension(tablePreferred.width, tablePreferred.height / 3)); JPanel imagePanel = new JPanel(new GridBagLayout()); JLabel imageLabel = new JLabel("test"); imagePanel.add(imageLabel, null); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tableScroll, new JScrollPane(imagePanel)); gui.add(splitPane, BorderLayout.CENTER); frame.setContentPane(gui); frame.pack(); frame.setVisible(true); }
From source file:sendfile.java
public static void main(String[] args) { if (args.length != 5) { System.out.println("usage: java sendfile <to> <from> <smtp> <file> true|false"); System.exit(1);// ww w. ja va 2 s .c o m } String to = args[0]; String from = args[1]; String host = args[2]; String filename = args[3]; boolean debug = Boolean.valueOf(args[4]).booleanValue(); String msgText1 = "Sending a file.\n"; String subject = "Sending a file"; // create some properties and get the default Session Properties props = System.getProperties(); props.put("mail.smtp.host", host); Session session = Session.getInstance(props, null); session.setDebug(debug); try { // create a message MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress(from)); InternetAddress[] address = { new InternetAddress(to) }; msg.setRecipients(Message.RecipientType.TO, address); msg.setSubject(subject); // create and fill the first message part MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setText(msgText1); // create the second message part MimeBodyPart mbp2 = new MimeBodyPart(); // attach the file to the message FileDataSource fds = new FileDataSource(filename); mbp2.setDataHandler(new DataHandler(fds)); mbp2.setFileName(fds.getName()); // create the Multipart and add its parts to it Multipart mp = new MimeMultipart(); mp.addBodyPart(mbp1); mp.addBodyPart(mbp2); // add the Multipart to the message msg.setContent(mp); // set the Date: header msg.setSentDate(new Date()); // send the message Transport.send(msg); } catch (MessagingException mex) { mex.printStackTrace(); Exception ex = null; if ((ex = mex.getNextException()) != null) { ex.printStackTrace(); } } }
From source file:de.onyxbits.raccoon.cli.Router.java
public static void main(String[] args) { Options options = new Options(); Option property = Option.builder("D").argName("property=value").numberOfArgs(2).valueSeparator() .desc(Messages.getString(DESC + "D")).build(); options.addOption(property);// w w w .ja v a 2s . c o m Option help = new Option("h", "help", false, Messages.getString(DESC + "h")); options.addOption(help); Option version = new Option("v", "version", false, Messages.getString(DESC + "v")); options.addOption(version); // GPA: Google Play Apps (we might add different markets later) Option playAppDetails = new Option(null, "gpa-details", true, Messages.getString(DESC + "gpa-details")); playAppDetails.setArgName("package"); options.addOption(playAppDetails); Option playAppBulkDetails = new Option(null, "gpa-bulkdetails", true, Messages.getString(DESC + "gpa-bulkdetails")); playAppBulkDetails.setArgName("file"); options.addOption(playAppBulkDetails); Option playAppBatchDetails = new Option(null, "gpa-batchdetails", true, Messages.getString(DESC + "gpa-batchdetails")); playAppBatchDetails.setArgName("file"); options.addOption(playAppBatchDetails); Option playAppSearch = new Option(null, "gpa-search", true, Messages.getString(DESC + "gpa-search")); playAppSearch.setArgName("query"); options.addOption(playAppSearch); CommandLine commandLine = null; try { commandLine = new DefaultParser().parse(options, args); } catch (ParseException e) { System.err.println(e.getMessage()); System.exit(1); } if (commandLine.hasOption(property.getOpt())) { System.getProperties().putAll(commandLine.getOptionProperties(property.getOpt())); } if (commandLine.hasOption(help.getOpt())) { new HelpFormatter().printHelp("raccoon", Messages.getString("header"), options, Messages.getString("footer"), true); System.exit(0); } if (commandLine.hasOption(version.getOpt())) { System.out.println(GlobalsProvider.getGlobals().get(Version.class)); System.exit(0); } if (commandLine.hasOption(playAppDetails.getLongOpt())) { Play.details(commandLine.getOptionValue(playAppDetails.getLongOpt())); System.exit(0); } if (commandLine.hasOption(playAppBulkDetails.getLongOpt())) { Play.bulkDetails(new File(commandLine.getOptionValue(playAppBulkDetails.getLongOpt()))); System.exit(0); } if (commandLine.hasOption(playAppBatchDetails.getLongOpt())) { Play.details(new File(commandLine.getOptionValue(playAppBatchDetails.getLongOpt()))); System.exit(0); } if (commandLine.hasOption(playAppSearch.getLongOpt())) { Play.search(commandLine.getOptionValue(playAppSearch.getLongOpt())); System.exit(0); } }
From source file:namespace.java
public static void main(String argv[]) { int msgnum = -1; int optind;//from w ww. j ava2 s . co m for (optind = 0; optind < argv.length; optind++) { if (argv[optind].equals("-T")) { protocol = argv[++optind]; } else if (argv[optind].equals("-H")) { host = argv[++optind]; } else if (argv[optind].equals("-U")) { user = argv[++optind]; } else if (argv[optind].equals("-P")) { password = argv[++optind]; } else if (argv[optind].equals("-D")) { debug = true; } else if (argv[optind].equals("-L")) { url = argv[++optind]; } else if (argv[optind].equals("-p")) { port = Integer.parseInt(argv[++optind]); } else if (argv[optind].equals("-u")) { suser = argv[++optind]; } else if (argv[optind].equals("--")) { optind++; break; } else if (argv[optind].startsWith("-")) { System.out.println("Usage: namespace [-L url] [-T protocol] [-H host] [-p port] [-U user]"); System.out.println("\t[-P password] [-u other-user] [-D]"); System.exit(1); } else { break; } } try { // Get a Properties object Properties props = System.getProperties(); // Get a Session object Session session = Session.getInstance(props, null); session.setDebug(debug); // Get a Store object Store store = null; if (url != null) { URLName urln = new URLName(url); store = session.getStore(urln); store.connect(); } else { if (protocol != null) store = session.getStore(protocol); else store = session.getStore(); // Connect if (host != null || user != null || password != null) store.connect(host, port, user, password); else store.connect(); } printFolders("Personal", store.getPersonalNamespaces()); printFolders("User \"" + suser + "\"", store.getUserNamespaces(suser)); printFolders("Shared", store.getSharedNamespaces()); store.close(); } catch (Exception ex) { System.out.println("Oops, got exception! " + ex.getMessage()); ex.printStackTrace(); } System.exit(0); }
From source file:populate.java
public static void main(String argv[]) { String srcURL = null;/* w ww .j a v a 2s.com*/ String dstURL = null; boolean debug = false; int optind; for (optind = 0; optind < argv.length; optind++) { if (argv[optind].equals("-s")) { srcURL = argv[++optind]; } else if (argv[optind].equals("-d")) { dstURL = argv[++optind]; } else if (argv[optind].equals("-D")) { debug = true; } else if (argv[optind].equals("-f")) { force = true; } else if (argv[optind].equals("-S")) { skipSpecial = true; } else if (argv[optind].equals("-c")) { clear = true; } else if (argv[optind].equals("-P")) { dontPreserveFlags = true; } else if (argv[optind].equals("-W")) { warn = true; } else if (argv[optind].equals("--")) { optind++; break; } else if (argv[optind].startsWith("-")) { printUsage(); System.exit(1); } else { break; } } try { if (srcURL == null || dstURL == null) { printUsage(); System.exit(1); } Session session = Session.getInstance(System.getProperties(), null); session.setDebug(debug); // Get source folder URLName srcURLName = new URLName(srcURL); Folder srcFolder; // Check if the source URL has a folder specified. If // not, we use the default folder if (srcURLName.getFile() == null) { Store s = session.getStore(srcURLName); s.connect(); srcFolder = s.getDefaultFolder(); } else { srcFolder = session.getFolder(new URLName(srcURL)); if (!srcFolder.exists()) { System.out.println("source folder does not exist"); srcFolder.getStore().close(); System.exit(1); } } // Set up destination folder URLName dstURLName = new URLName(dstURL); Folder dstFolder; // Check if the destination URL has a folder specified. If // not, we use the source folder name if (dstURLName.getFile() == null) { Store s = session.getStore(dstURLName); s.connect(); dstFolder = s.getFolder(srcFolder.getName()); } else dstFolder = session.getFolder(dstURLName); if (clear && dstFolder.exists()) { if (!dstFolder.delete(true)) { System.out.println("couldn't delete " + dstFolder.getFullName()); return; } } copy(srcFolder, dstFolder); // Close the respective stores. srcFolder.getStore().close(); dstFolder.getStore().close(); } catch (MessagingException mex) { System.out.println(mex.getMessage()); mex.printStackTrace(); } }
From source file:SimpleClient.java
public static void main(String argv[]) { boolean usage = false; for (int optind = 0; optind < argv.length; optind++) { if (argv[optind].equals("-L")) { url.addElement(argv[++optind]); } else if (argv[optind].startsWith("-")) { usage = true;//w w w . j av a 2s . co m break; } else { usage = true; break; } } if (usage || url.size() == 0) { System.out.println("Usage: SimpleClient -L url"); System.out.println(" where url is protocol://username:password@hostname/"); System.exit(1); } try { // Set up our Mailcap entries. This will allow the JAF // to locate our viewers. File capfile = new File("simple.mailcap"); if (!capfile.isFile()) { System.out.println("Cannot locate the \"simple.mailcap\" file."); System.exit(1); } CommandMap.setDefaultCommandMap(new MailcapCommandMap(new FileInputStream(capfile))); JFrame frame = new JFrame("Simple JavaMail Client"); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); //frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // Get a Store object SimpleAuthenticator auth = new SimpleAuthenticator(frame); Session session = Session.getDefaultInstance(System.getProperties(), auth); //session.setDebug(true); DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root"); // create a node for each store we have for (Enumeration e = url.elements(); e.hasMoreElements();) { String urlstring = (String) e.nextElement(); URLName urln = new URLName(urlstring); Store store = session.getStore(urln); StoreTreeNode storenode = new StoreTreeNode(store); root.add(storenode); } DefaultTreeModel treeModel = new DefaultTreeModel(root); JTree tree = new JTree(treeModel); tree.addTreeSelectionListener(new TreePress()); /* Put the Tree in a scroller. */ JScrollPane sp = new JScrollPane(); sp.setPreferredSize(new Dimension(250, 300)); sp.getViewport().add(tree); /* Create a double buffered JPanel */ JPanel sv = new JPanel(new BorderLayout()); sv.add("Center", sp); fv = new FolderViewer(null); JSplitPane jsp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sv, fv); jsp.setOneTouchExpandable(true); mv = new MessageViewer(); JSplitPane jsp2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, jsp, mv); jsp2.setOneTouchExpandable(true); frame.getContentPane().add(jsp2); frame.pack(); frame.show(); } catch (Exception ex) { System.out.println("SimpletClient caught exception"); ex.printStackTrace(); System.exit(1); } }