Example usage for java.lang System getProperties

List of usage examples for java.lang System getProperties

Introduction

In this page you can find the example usage for java.lang System getProperties.

Prototype

public static Properties getProperties() 

Source Link

Document

Determines the current system properties.

Usage

From source file:com.tacitknowledge.util.migration.jdbc.StandaloneMigrationLauncher.java

void run(String[] arguments) throws Exception {

    String migrationSystemName = ConfigurationUtil.getRequiredParam("migration.systemname",
            System.getProperties(), arguments, 0);
    String migrationSettings = ConfigurationUtil.getOptionalParam("migration.settings", System.getProperties(),
            arguments, 1);/* w w w . j ava  2  s  . c o  m*/

    boolean isRollback = false;
    int[] rollbackLevels = new int[] {};
    boolean forceRollback = false;

    for (int i = 0; i < arguments.length; i++) {
        String argument1 = arguments[i];

        if (ROLLBACK.equals(argument1)) {
            isRollback = true;

            if (i + 2 <= arguments.length) {
                String argument2 = arguments[i + 1];

                if (argument2 != null) {
                    try {
                        rollbackLevels = getRollbackLevels(argument2);
                    } catch (NumberFormatException nfe) {
                        throw new MigrationException(
                                "The rollbacklevels should be integers separated by a comma");
                    }
                }
            }

            if (rollbackLevels.length == 0) {
                // this indicates that the rollback level has not been set
                throw new MigrationException(
                        "The rollback flag requires a following integer parameter or a list of integer parameters separated by comma to indicate the rollback level(s).");
            }
        }

        if (FORCE_ROLLBACK.equals(argument1)) {
            forceRollback = true;
        }

    }

    // The MigrationLauncher is responsible for handling the interaction
    // between the PatchTable and the underlying MigrationTasks; as each
    // task is executed, the patch level is incremented, etc.
    try {

        if (isRollback) {
            String infoMessage = "Found rollback flag. AutoPatch will attempt to rollback the system to patch level(s) "
                    + ArrayUtils.toString(rollbackLevels) + ".";
            log.info(infoMessage);

            migrationUtil.doRollbacks(migrationSystemName, migrationSettings, rollbackLevels, forceRollback);
        } else {
            migrationUtil.doMigrations(migrationSystemName, migrationSettings);
        }
    } catch (Exception e) {
        log.error(e);
        throw e;
    }
}

From source file:com._17od.upm.util.Preferences.java

public static void load() throws FileNotFoundException, IOException {

    //Check for the system property PREF_FILE_SYS_PROP. If supplied it will give the name
    //of the properties file to use. If it's not given then use the properties file in the
    //user's home directory (which may or may not exist)

    // Mac and Linux have different places to store configuration files -
    // set PREF_FILE_SYS_PROP appropriately.
    if (!System.getProperties().containsKey(PREF_FILE_SYS_PROP)) {
        if (PlatformSpecificCode.isLinux()) {
            String configBase = System.getenv("XDG_CONFIG_HOME");
            if (null == configBase || configBase.trim().equals("")) {
                configBase = System.getProperty("user.home") + System.getProperty("file.separator") + ".config";
            }/*from   w  w w  . j a  v  a  2  s.  c o  m*/
            System.setProperty(PREF_FILE_SYS_PROP,
                    configBase + System.getProperty("file.separator") + "upm.properties");
        } else if (PlatformSpecificCode.isMAC()) {
            System.setProperty(PREF_FILE_SYS_PROP,
                    System.getProperty("user.home") + System.getProperty("file.separator") + "Library"
                            + System.getProperty("file.separator") + "Preferences"
                            + System.getProperty("file.separator") + "upm.properties");
        }
    }

    propertiesFile = System.getProperty(PREF_FILE_SYS_PROP);
    if (propertiesFile == null || propertiesFile.trim().equals("")) {
        propertiesFile = PREF_FILE;
    }

    // Create propertiesFile directories if it doesn't exist
    File prefs = new File(propertiesFile);
    prefs.getParentFile().mkdirs();

    //Attempt to load the properties
    try {
        if (log.isInfoEnabled()) {
            log.info("Loading the properties file [" + propertiesFile + "]");
        }
        preferences = new Properties();
        preferences.load(new FileInputStream(propertiesFile));
    } catch (FileNotFoundException e) {
        if (log.isDebugEnabled()) {
            log.debug("Property file not found. Will be created the next time the properties are saved.");
        }
    }
}

From source file:ch.cyberduck.core.b2.B2ReadFeatureTest.java

@Test
public void testReadChunkedTransfer() throws Exception {
    final B2Session session = new B2Session(new Host(new B2Protocol(), new B2Protocol().getDefaultHostname(),
            new Credentials(System.getProperties().getProperty("b2.user"),
                    System.getProperties().getProperty("b2.key"))));
    final LoginConnectionService service = new LoginConnectionService(new DisabledLoginCallback(),
            new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener());
    service.connect(session, PathCache.empty(), new DisabledCancelCallback());
    final Path bucket = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path file = new Path(bucket, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final byte[] content = RandomUtils.nextBytes(923);
    final TransferStatus status = new TransferStatus();
    status.setLength(content.length);/*from   ww w.ja  v  a 2 s.  com*/
    status.setChecksum(new SHA1ChecksumCompute().compute(new ByteArrayInputStream(content), status));
    final HttpResponseOutputStream<BaseB2Response> out = new B2WriteFeature(session).write(file, status,
            new DisabledConnectionCallback());
    IOUtils.write(content, out);
    out.close();
    final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    assertEquals(-1L, local.attributes().getSize());
    new DefaultDownloadFeature(new B2ReadFeature(session)).download(file, local,
            new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(),
            new TransferStatus() {
                @Override
                public void setLength(long length) {
                    assertEquals(923L, length);
                    // Ignore update. As with unknown length for chunked transfer
                }
            }, new DisabledLoginCallback(), new DisabledPasswordCallback());
    assertEquals(923L, local.attributes().getSize());
    new B2DeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();
}

From source file:com.weaverplatform.nifi.CreateIndividualTest.java

@Before
public void init() throws URISyntaxException {

    // Wipe weaver database first
    weaver = new Weaver();
    weaver.connect(new WeaverSocket(new URI(WEAVER_URL)));
    weaver.wipe();//from  ww w.ja v  a  2  s. com

    System.out
            .println(new File(getClass().getClassLoader().getResource("nifi.properties").getFile()).toString());
    Properties props = System.getProperties();
    props.setProperty("nifi.properties.file.path",
            new File(getClass().getClassLoader().getResource("nifi.properties").getFile()).toString());
    testRunner = TestRunners.newTestRunner(CreateIndividual.class);
}

From source file:gwtupload.sendmailsample.server.SendMailSampleServlet.java

@Override
public String executeAction(HttpServletRequest request, List<FileItem> sessionFiles)
        throws UploadActionException {
    try {// w ww.  ja v  a2s.c o  m
        String from = null, to = null, subject = "", body = "";
        // create a new multipart content
        MimeMultipart multiPart = new MimeMultipart();
        for (FileItem item : sessionFiles) {
            if (item.isFormField()) {
                if ("from".equals(item.getFieldName()))
                    from = item.getString();
                if ("to".equals(item.getFieldName()))
                    to = item.getString();
                if ("subject".equals(item.getFieldName()))
                    subject = item.getString();
                if ("body".equals(item.getFieldName()))
                    body = item.getString();
            } else {
                // add the file part to multipart content
                MimeBodyPart part = new MimeBodyPart();
                part.setFileName(item.getName());
                part.setDataHandler(
                        new DataHandler(new ByteArrayDataSource(item.get(), item.getContentType())));
                multiPart.addBodyPart(part);
            }
        }

        // add the text part to multipart content
        MimeBodyPart txtPart = new MimeBodyPart();
        txtPart.setContent(body, "text/plain");
        multiPart.addBodyPart(txtPart);

        // configure smtp server
        Properties props = System.getProperties();
        props.put("mail.smtp.host", SMTP_SERVER);
        // create a new mail session and the mime message
        MimeMessage mime = new MimeMessage(Session.getInstance(props));
        mime.setText(body);
        mime.setContent(multiPart);
        mime.setSubject(subject);
        mime.setFrom(new InternetAddress(from));
        for (String rcpt : to.split("[\\s;,]+"))
            mime.addRecipient(Message.RecipientType.TO, new InternetAddress(rcpt));
        // send the message
        Transport.send(mime);
    } catch (MessagingException e) {
        throw new UploadActionException(e.getMessage());
    }
    return "Your mail has been sent successfuly.";
}

From source file:ch.cyberduck.core.ftp.FTPDefaultListServiceTest.java

@Test
public void testListDefaultFlag() throws Exception {
    final Host host = new Host(new FTPTLSProtocol(), "test.cyberduck.ch",
            new Credentials(System.getProperties().getProperty("ftp.user"),
                    System.getProperties().getProperty("ftp.password")));
    final FTPSession session = new FTPSession(host);
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final ListService list = new FTPDefaultListService(session, new DisabledPasswordStore(),
            new DisabledLoginCallback(), new CompositeFileEntryParser(Arrays.asList(new UnixFTPEntryParser())),
            FTPListService.Command.lista);
    final Path directory = new FTPWorkdirService(session).find();
    final Path file = new Path(directory, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.file));
    new DefaultTouchFeature<Integer>(new DefaultUploadFeature<Integer>(new FTPWriteFeature(session)))
            .touch(file, new TransferStatus());
    assertTrue(list.list(directory, new DisabledListProgressListener()).contains(file));
    new FTPDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();//  w  ww .  j a  v  a  2  s  .co m
}

From source file:ch.cyberduck.core.sftp.auth.SFTPPublicKeyAuthenticationTest.java

@Test(expected = LoginFailureException.class)
public void testAuthenticatePuTTYKeyWithWrongPassword() throws Exception {
    final Credentials credentials = new Credentials(System.getProperties().getProperty("sftp.user"), "");
    final Local key = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    try {//from  w w w .ja  v  a2s .  com
        credentials.setIdentity(key);
        new DefaultLocalTouchFeature().touch(key);
        IOUtils.copy(new StringReader(System.getProperties().getProperty("sftp.key.putty")),
                key.getOutputStream(false), Charset.forName("UTF-8"));
        final Host host = new Host(new SFTPProtocol(), "test.cyberduck.ch", credentials);
        final SFTPSession session = new SFTPSession(host);
        session.open(new DisabledHostKeyCallback());
        final AtomicBoolean p = new AtomicBoolean();
        assertFalse(new SFTPPublicKeyAuthentication(session).authenticate(host, new DisabledPasswordStore(),
                new DisabledLoginCallback() {
                    @Override
                    public Credentials prompt(final Host bookmark, String username, String title, String reason,
                            LoginOptions options) throws LoginCanceledException {
                        p.set(true);
                        throw new LoginCanceledException();
                    }
                }, new DisabledCancelCallback()));
        assertTrue(p.get());
        session.close();
    } finally {
        key.delete();
    }
}

From source file:com.joyent.manta.config.TestConfigContext.java

/**
 * Populate configuration from defaults, environment variables, system
 * properties and an addition context passed in.
 *
 * @param context additional context to layer on top
 *//*from   w  w  w  .java 2 s  .  c  om*/
public TestConfigContext(ConfigContext context) {
    this(context, System.getProperties());
}

From source file:mitm.application.djigzo.DjigzoConfigurator.java

private static void printSystemProperties() {
    System.out.println();//from   w  w  w .  ja  v  a  2s  .c o  m
    System.out.println("**** Begin system properties ****");
    System.getProperties().list(System.out);
    System.out.println("**** End system properties ****");
    System.out.println();
}