Example usage for java.util Properties store

List of usage examples for java.util Properties store

Introduction

In this page you can find the example usage for java.util Properties store.

Prototype

public void store(OutputStream out, String comments) throws IOException 

Source Link

Document

Writes this property list (key and element pairs) in this Properties table to the output stream in a format suitable for loading into a Properties table using the #load(InputStream) load(InputStream) method.

Usage

From source file:com.hp.application.automation.tools.run.RunFromAlmBuilder.java

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
        throws InterruptedException, IOException {

    // get the alm server settings
    AlmServerSettingsModel almServerSettingsModel = getAlmServerSettingsModel();

    if (almServerSettingsModel == null) {
        listener.fatalError(//from   w  w  w. j  a  v a2s . c  o  m
                "An ALM server is not defined. Go to Manage Jenkins->Configure System and define your ALM server under Application Lifecycle Management");
        return false;
    }

    EnvVars env = null;
    try {
        env = build.getEnvironment(listener);
    } catch (IOException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }
    VariableResolver<String> varResolver = build.getBuildVariableResolver();

    // now merge them into one list
    Properties mergedProperties = new Properties();

    mergedProperties.putAll(almServerSettingsModel.getProperties());
    mergedProperties.putAll(runFromAlmModel.getProperties(env, varResolver));

    String encAlmPass = "";
    try {

        encAlmPass = EncryptionUtils.Encrypt(runFromAlmModel.getAlmPassword(), EncryptionUtils.getSecretKey());

        mergedProperties.remove(RunFromAlmModel.ALM_PASSWORD_KEY);
        mergedProperties.put(RunFromAlmModel.ALM_PASSWORD_KEY, encAlmPass);

    } catch (Exception e) {
        build.setResult(Result.FAILURE);
        listener.fatalError("problem in qcPassword encription");
    }

    Date now = new Date();
    Format formatter = new SimpleDateFormat("ddMMyyyyHHmmssSSS");
    String time = formatter.format(now);

    // get a unique filename for the params file
    ParamFileName = "props" + time + ".txt";
    ResultFilename = "Results" + time + ".xml";
    //KillFileName = "stop" + time + ".txt";

    mergedProperties.put("runType", RunType.Alm.toString());
    mergedProperties.put("resultsFilename", ResultFilename);

    // get properties serialized into a stream
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    try {
        mergedProperties.store(stream, "");
    } catch (IOException e) {
        build.setResult(Result.FAILURE);
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    String propsSerialization = stream.toString();
    InputStream propsStream = IOUtils.toInputStream(propsSerialization);

    // get the remote workspace filesys
    FilePath projectWS = build.getWorkspace();

    // Get the URL to the Script used to run the test, which is bundled
    // in the plugin
    URL cmdExeUrl = Hudson.getInstance().pluginManager.uberClassLoader.getResource(HpToolsLauncher_SCRIPT_NAME);
    if (cmdExeUrl == null) {
        listener.fatalError(HpToolsLauncher_SCRIPT_NAME + " not found in resources");
        return false;
    }

    FilePath propsFileName = projectWS.child(ParamFileName);
    FilePath CmdLineExe = projectWS.child(HpToolsLauncher_SCRIPT_NAME);

    try {
        // create a file for the properties file, and save the properties
        propsFileName.copyFrom(propsStream);

        // Copy the script to the project workspace
        CmdLineExe.copyFrom(cmdExeUrl);
    } catch (IOException e1) {
        build.setResult(Result.FAILURE);
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    try {
        // Run the HpToolsLauncher.exe
        AlmToolsUtils.runOnBuildEnv(build, launcher, listener, CmdLineExe, ParamFileName);
    } catch (IOException ioe) {
        Util.displayIOException(ioe, listener);
        build.setResult(Result.FAILURE);
        return false;
    } catch (InterruptedException e) {
        build.setResult(Result.ABORTED);
        PrintStream out = listener.getLogger();
        // kill processes
        //FilePath killFile = projectWS.child(KillFileName);
        /* try {
        out.println("Sending abort command");
        killFile.write("\n", "UTF-8");
        while (!killFile.exists())
            Thread.sleep(1000);
        Thread.sleep(1500);
                
        } catch (IOException e1) {
        //build.setResult(Result.FAILURE);
        // TODO Auto-generated catch block
        e1.printStackTrace();
        } catch (InterruptedException e1) {
        //build.setResult(Result.FAILURE);
        // TODO Auto-generated catch block
        e1.printStackTrace();
        }*/

        try {
            AlmToolsUtils.runHpToolsAborterOnBuildEnv(build, launcher, listener, ParamFileName);
        } catch (IOException e1) {
            Util.displayIOException(e1, listener);
            build.setResult(Result.FAILURE);
            return false;
        } catch (InterruptedException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        out.println("Operation was aborted by user.");
        //build.setResult(Result.FAILURE);
    }
    return true;

}

From source file:org.cloudifysource.azure.AbstractCliAzureDeploymentTest.java

public void before(String relativeApplicationExamplePath, String azureHostedService, AzureSlot azureSlot)
        throws Exception {

    isDebugMode = Boolean//w w w  .  jav  a  2  s  .c  o m
            .parseBoolean(System.getProperty(IS_DEBUG_MODE_SYSTEM_PROPERTY, Boolean.toString(false)));

    String localWorkingDirPath = System.getProperty(LOCAL_WORKING_DIR_SYSTEM_PROPERTY_KEY);
    Assert.assertNotNull(LOCAL_WORKING_DIR_SYSTEM_PROPERTY_KEY + " system property has to exists",
            localWorkingDirPath);

    File localWorkingDir = new File(localWorkingDirPath);
    Assert.assertTrue(localWorkingDir.getPath() + " does not exist", localWorkingDir.isDirectory());

    File gigaSpacesCloudifyDir = new File(localWorkingDir, GIGASPACES_LATEST_HOME);
    Assert.assertTrue(gigaSpacesCloudifyDir.getPath() + " does not exist", gigaSpacesCloudifyDir.isDirectory());

    applicationFile = new File(gigaSpacesCloudifyDir, relativeApplicationExamplePath);
    Assert.assertTrue(applicationFile.getPath() + " does not exist", applicationFile.isDirectory());

    // these should exist assuming the cloudify folder is valid
    cliExecutablePath = new File(gigaSpacesCloudifyDir, RELATIVE_CLI_PATH);
    File azureConfigExec = new File(gigaSpacesCloudifyDir, RELATIVE_AZURE_CONFIG_EXEC_PATH);
    File azurePropertiesFile = new File(gigaSpacesCloudifyDir, RELATIVE_AZURE_PROPERTIES_PATH);
    File cscfgFile = new File(cliExecutablePath.getParent(),
            RELATIVE_WORKER_ROLE_DIR + "\\ServiceConfiguration.Cloud.cscfg");

    // update worker roles configuration to upload logs
    AzureDeploymentConfigurationFile cscfg = new AzureDeploymentConfigurationFile(cscfgFile);
    cscfg.setUploadAgentLogs(true);
    cscfg.setUploadAllLogs(true);
    cscfg.flush();

    Properties newAzureProps = new Properties();
    newAzureProps.setProperty(AZURE_PROPERTIES_ACCOUNT_NAME_KEY, credentials.getBlobStorageAccountName());
    newAzureProps.setProperty(AZURE_PROPERTIES_ACCOUNT_KEY_KEY, credentials.getBlobStorageAccountKey());
    newAzureProps.setProperty(AZURE_PROPERTIES_CONTAINER_NAME_KEY, AZURE_CONTAINER_NAME);
    newAzureProps.setProperty(AZURE_PROPERTIES_WORKER_ROLE_FOLDER_KEY, RELATIVE_WORKER_ROLE_DIR);
    newAzureProps.setProperty(AZURE_PROPERTIES_CS_PACK_FOLDER_KEY, CS_PACK_FOLDER);
    newAzureProps.setProperty(AZURE_PROPERTIES_RDP_CERT_FILE_KEY, RDP_CERT_FILE);
    newAzureProps.setProperty(AZURE_PROPERTIES_RDP_PFX_FILE_KEY, RDP_PFX_FILE);
    newAzureProps.setProperty(AZURE_PROPERITES_CERTIFICATE_THUMBPRINT_KEY,
            credentials.getHostedServicesCertificateThumbrint());
    newAzureProps.setProperty(AZURE_PROPERITES_SUBSCRIPTION_ID_KEY,
            credentials.getHostedServicesSubscriptionId());
    newAzureProps.setProperty(AZURE_PROPERTIES_RDP_LOGIN_USERNAME_KEY, AZURE_RDP_LOGIN_USERNAME);
    newAzureProps.setProperty(AZURE_PROPERTIES_RDP_LOGIN_ENCRYPTED_PASSWORD,
            AZURE_RDP_LOGIN_ENCRYPTED_PASSWORD);

    log("Overriding azure.properties file");
    FileOutputStream fos = new FileOutputStream(azurePropertiesFile);
    newAzureProps.store(fos, null);
    fos.close();

    deployment = new AzureDeploymentWrapper(azureConfigExec, credentials.getHostedServicesSubscriptionId(),
            credentials.getHostedServicesCertificateThumbrint(), azureHostedService, azureSlot, null, null,
            null, null);

}

From source file:fr.fastconnect.factory.tibco.bw.maven.run.LaunchDesignerMojo.java

private void updateAliasesFile() throws IOException {
    File aliasesFile = getAliasesFile();
    File designer5Prefs = getDesigner5Prefs();

    Properties prefs = new SortedProperties();
    FileInputStream fisPrefs = new FileInputStream(designer5Prefs);
    prefs.load(fisPrefs);/* w w w .j av  a2s .  c  o  m*/
    fisPrefs.close();

    Integer maxFileAliasPref = 0;
    for (Object k : prefs.keySet()) {
        String key = (String) k;

        if (key.startsWith(FILE_ALIAS_PREFIX)) {
            maxFileAliasPref++;
        }
    }

    Properties aliases = new Properties();
    FileInputStream fis = new FileInputStream(aliasesFile);
    aliases.load(fis);
    fis.close();

    String projectVersion = getProject().getVersion();
    Properties duplicates = new Properties();

    for (Object k : aliases.keySet()) {
        String key = (String) k;
        String value = aliases.getProperty(key);
        if (key.contains(projectVersion) && key.endsWith(":jar")) {
            getLog().debug(key);
            key = key.replace(projectVersion, "${project.version}");
            duplicates.put(key, value);
        }
    }

    if (!duplicates.isEmpty()) {
        for (Object k : duplicates.keySet()) {
            String key = (String) k;
            String value = duplicates.getProperty(key);
            key = key.replace(TIBCO_ALIAS_PREFIX, "");

            prefs.put(FILE_ALIAS_PREFIX + maxFileAliasPref.toString(), key + "=" + value);
            maxFileAliasPref++;
        }

        FileOutputStream fosPrefs = new FileOutputStream(designer5Prefs);
        prefs.store(fosPrefs, "");
        fis.close();

        aliases.putAll(duplicates);

        FileOutputStream fos = new FileOutputStream(aliasesFile);
        aliases.store(fos, "");
        fis.close();
    }
}

From source file:gtu._work.ui.PropertyEditUI.java

private void initGUI() {
    try {/*  w w  w .j a va2s.  co  m*/
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        BorderLayout thisLayout = new BorderLayout();
        this.setTitle("PropertyEditUI");
        getContentPane().setLayout(thisLayout);
        {
            jMenuBar1 = new JMenuBar();
            setJMenuBar(jMenuBar1);
            {
                jMenu1 = new JMenu();
                jMenuBar1.add(jMenu1);
                jMenu1.setText("File");
                {
                    jMenuItem1 = new JMenuItem();
                    jMenu1.add(jMenuItem1);
                    jMenuItem1.setText("open directory");
                    jMenuItem1.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File file = JCommonUtil._jFileChooser_selectDirectoryOnly();
                            loadCurrentFile(file);
                        }
                    });
                }
                {
                    openDirectoryAndChildren = new JMenuItem();
                    jMenu1.add(openDirectoryAndChildren);
                    openDirectoryAndChildren.setText("open directory and children");
                    openDirectoryAndChildren.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            System.out.println("openDirectoryAndChildren.actionPerformed, event=" + evt);
                            File file = JCommonUtil._jFileChooser_selectDirectoryOnly();
                            if (file == null) {
                                // file =
                                // PropertiesUtil.getJarCurrentPath(getClass());//XXX
                                file = new File("D:\\my_tool\\english");
                                JCommonUtil._jOptionPane_showMessageDialog_info("load C:\\L-CONFIG !");
                            }
                            DefaultListModel model = new DefaultListModel();
                            List<File> list = new ArrayList<File>();
                            FileUtil.searchFileMatchs(file, ".*\\.properties", list);
                            for (File f : list) {
                                File_ ff = new File_();
                                ff.file = f;
                                model.addElement(ff);
                            }
                            backupFileList = list;
                            fileList.setModel(model);
                        }
                    });
                }
                {
                    jMenuItem2 = new JMenuItem();
                    jMenu1.add(jMenuItem2);
                    jMenuItem2.setText("save");
                    jMenuItem2.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            System.out.println("jMenu3.actionPerformed, event=" + evt);
                            if (currentFile == null) {
                                return;
                            }
                            if (JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption(
                                    "save to " + currentFile.getName(), "SAVE")) {
                                try {
                                    Properties prop = new Properties();
                                    // try {
                                    // prop.load(new
                                    // FileInputStream(currentFile));
                                    // } catch (Exception e) {
                                    // e.printStackTrace();
                                    // JCommonUtil.handleException(e);
                                    // return;
                                    // }
                                    loadModelToProperties(prop);
                                    prop.store(new FileOutputStream(currentFile), getTitle());
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    JCommonUtil.handleException(e);
                                }
                            }
                        }
                    });
                }
                {
                    jMenuItem3 = new JMenuItem();
                    jMenu1.add(jMenuItem3);
                    jMenuItem3.setText("save to target");
                    jMenuItem3.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File file = JFileChooserUtil.newInstance().selectFileOnly().showSaveDialog()
                                    .getApproveSelectedFile();
                            if (file == null) {
                                JCommonUtil._jOptionPane_showMessageDialog_error("file name is not correct!");
                                return;
                            }
                            if (!file.getName().contains(".properties")) {
                                file = new File(file.getParent(), file.getName() + ".properties");
                            }
                            try {
                                Properties prop = new Properties();
                                // try {
                                // prop.load(new
                                // FileInputStream(currentFile));
                                // } catch (Exception e) {
                                // e.printStackTrace();
                                // JCommonUtil.handleException(e);
                                // return;
                                // }
                                loadModelToProperties(prop);
                                prop.store(new FileOutputStream(file), getTitle());
                            } catch (Exception e) {
                                e.printStackTrace();
                                JCommonUtil.handleException(e);
                            }
                        }
                    });
                }
                {
                    jMenuItem4 = new JMenuItem();
                    jMenu1.add(jMenuItem4);
                    jMenuItem4.setText("save file(sorted)");
                    jMenuItem4.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            if (currentFile == null) {
                                return;
                            }
                            try {
                                BufferedReader reader = new BufferedReader(
                                        new InputStreamReader(new FileInputStream(currentFile)));
                                List<String> sortList = new ArrayList<String>();
                                for (String line = null; (line = reader.readLine()) != null;) {
                                    sortList.add(line);
                                }
                                reader.close();
                                Collections.sort(sortList);
                                StringBuilder sb = new StringBuilder();
                                for (String line : sortList) {
                                    sb.append(line + "\n");
                                }
                                FileUtil.saveToFile(currentFile, sb.toString(), "UTF8");
                            } catch (FileNotFoundException e) {
                                e.printStackTrace();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    });
                }
                {
                    jMenuItem5 = new JMenuItem();
                    jMenu1.add(jMenuItem5);
                    jMenuItem5.setText("");
                    jMenuItem5.addActionListener(new ActionListener() {
                        private void setMeaning(String meaning, int rowPos) {
                            propTable.getRowSorter().getModel().setValueAt(meaning, rowPos, 2);
                        }

                        private void setMeaningEn1(String english, int rowPos, List<String> errSb) {
                            EnglishTester_Diectory eng = new EnglishTester_Diectory();
                            try {
                                WordInfo wordInfo = eng.parseToWordInfo(english);
                                String meaning = getChs2Big5(wordInfo.getMeaning());
                                if (hasChinese(meaning)) {
                                    setMeaning(meaning, rowPos);
                                } else {
                                    setMeaningEn2(english, rowPos, errSb);
                                }
                            } catch (Exception e) {
                                errSb.add(english);
                                e.printStackTrace();
                            }
                        }

                        private void setMeaningEn2(String english, int rowPos, List<String> errSb) {
                            EnglishTester_Diectory2 eng2 = new EnglishTester_Diectory2();
                            try {
                                WordInfo2 wordInfo = eng2.parseToWordInfo(english);
                                String meaning = getChs2Big5(StringUtils.join(wordInfo.getMeaningList(), ";"));
                                setMeaning(meaning, rowPos);
                            } catch (Exception e) {
                                errSb.add(english);
                                e.printStackTrace();
                            }
                        }

                        private boolean hasChinese(String val) {
                            return new StringUtil_().getChineseWord(val, true).length() > 0;
                        }

                        private Properties loadFromMemoryBank() {
                            try {
                                Properties prop = new Properties();
                                File f1 = new File(
                                        "D:/gtu001_dropbox/Dropbox/Apps/gtu001_test/etc_config/EnglishSearchUI_MemoryBank.properties");
                                File f2 = new File(
                                        "e:/gtu001_dropbox/Dropbox/Apps/gtu001_test/etc_config/EnglishSearchUI_MemoryBank.properties");
                                for (File f : new File[] { f1, f2 }) {
                                    if (f.exists()) {
                                        HermannEbbinghaus_Memory memory = new HermannEbbinghaus_Memory();
                                        memory.init(f);
                                        List<MemData> memLst = memory.getAllMemData(true);
                                        for (MemData d : memLst) {
                                            prop.setProperty(d.getKey(), getChs2Big5(d.getRemark()));
                                        }
                                        break;
                                    }
                                }
                                return prop;
                            } catch (Exception ex) {
                                throw new RuntimeException(ex);
                            }
                        }

                        public void actionPerformed(ActionEvent evt) {
                            if (currentFile == null) {
                                return;
                            }

                            // Properties memoryProp = loadFromMemoryBank();
                            Properties memoryProp = new Properties();

                            List<String> errSb = new ArrayList<String>();
                            for (int row = 0; row < propTable.getModel().getRowCount(); row++) {
                                int rowPos = propTable.getRowSorter().convertRowIndexToModel(row);
                                String english = StringUtils.trimToEmpty(
                                        (String) propTable.getRowSorter().getModel().getValueAt(rowPos, 1))
                                        .toLowerCase();
                                String desc = (String) propTable.getRowSorter().getModel().getValueAt(rowPos,
                                        2);

                                if (memoryProp.containsKey(english)
                                        && StringUtils.isNotBlank(memoryProp.getProperty(english))) {
                                    setMeaning(memoryProp.getProperty(english), rowPos);
                                } else {
                                    if (StringUtils.isBlank(desc) || !hasChinese(desc)) {
                                        if (!english.contains(" ")) {
                                            setMeaningEn1(english, rowPos, errSb);
                                        } else {
                                            setMeaningEn2(english, rowPos, errSb);
                                        }
                                    }
                                }

                                if (StringUtils.trimToEmpty(desc).contains("?")) {
                                    setMeaning("", rowPos);
                                }
                            }
                            if (!errSb.isEmpty()) {
                                JCommonUtil._jOptionPane_showMessageDialog_error(":\n" + errSb);
                            }
                        }
                    });
                }

                {
                    JMenuItem jMenuItem6 = new JMenuItem();
                    jMenu1.add(jMenuItem6);
                    jMenuItem6.setText("");
                    jMenuItem6.addActionListener(new ActionListener() {
                        private void setMeaning(String meaning, int rowPos) {
                            propTable.getRowSorter().getModel().setValueAt(meaning, rowPos, 2);
                        }

                        public void actionPerformed(ActionEvent evt) {
                            for (int row = 0; row < propTable.getModel().getRowCount(); row++) {
                                int rowPos = propTable.getRowSorter().convertRowIndexToModel(row);
                                String english = StringUtils.trimToEmpty(
                                        (String) propTable.getRowSorter().getModel().getValueAt(rowPos, 1))
                                        .toLowerCase();
                                String desc = (String) propTable.getRowSorter().getModel().getValueAt(rowPos,
                                        2);

                                if (StringUtils.trimToEmpty(desc).contains("?")) {
                                    setMeaning("", rowPos);
                                }
                            }
                        }
                    });
                }
            }
        }
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("editor", null, jPanel2, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel2.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(550, 314));
                    {
                        TableModel propTableModel = new DefaultTableModel(
                                new String[][] { { "", "", "" }, { "", "", "" } },
                                new String[] { "index", "Key", "value" });
                        propTable = new JTable();
                        JTableUtil.defaultSetting_AutoResize(propTable);
                        jScrollPane1.setViewportView(propTable);
                        propTable.setModel(propTableModel);
                        propTable.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                JTableUtil xxxxxx = JTableUtil.newInstance(propTable);
                                int[] rows = xxxxxx.getSelectedRows();
                                for (int ii : rows) {
                                    System.out.println(xxxxxx.getModel().getValueAt(ii, 1));
                                }
                                JPopupMenuUtil.newInstance(propTable).applyEvent(evt)
                                        .addJMenuItem(JTableUtil.newInstance(propTable).getDefaultJMenuItems())
                                        .show();
                            }
                        });
                    }
                }
                {
                    queryText = new JTextField();
                    jPanel2.add(queryText, BorderLayout.NORTH);
                    queryText.getDocument()
                            .addDocumentListener(JCommonUtil.getDocumentListener(new HandleDocumentEvent() {

                                @Override
                                public void process(DocumentEvent event) {
                                    if (currentFile == null) {
                                        return;
                                    }
                                    Properties prop = new Properties();
                                    try {
                                        prop.load(new FileInputStream(currentFile));
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        JCommonUtil.handleException(e);
                                        return;
                                    }
                                    loadPropertiesToModel(prop);
                                    String text = JCommonUtil.getDocumentText(event);
                                    Pattern pattern = null;
                                    try {
                                        pattern = Pattern.compile(text);
                                    } catch (Exception ex) {
                                    }

                                    DefaultTableModel model = JTableUtil.newInstance(propTable).getModel();
                                    for (int ii = 0; ii < model.getRowCount(); ii++) {
                                        String key = (String) model.getValueAt(ii, 1);
                                        String value = (String) model.getValueAt(ii, 2);
                                        if (key.contains(text)) {
                                            continue;
                                        }
                                        if (value.contains(text)) {
                                            continue;
                                        }
                                        if (pattern != null) {
                                            if (pattern.matcher(key).find()) {
                                                continue;
                                            }
                                            if (pattern.matcher(value).find()) {
                                                continue;
                                            }
                                        }
                                        model.removeRow(propTable.convertRowIndexToModel(ii));
                                        ii--;
                                    }
                                }
                            }));
                }
            }
            {
                jPanel3 = new JPanel();
                BorderLayout jPanel3Layout = new BorderLayout();
                jPanel3.setLayout(jPanel3Layout);
                jTabbedPane1.addTab("folder", null, jPanel3, null);
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel3.add(jScrollPane2, BorderLayout.CENTER);
                    jScrollPane2.setPreferredSize(new java.awt.Dimension(550, 314));
                    {
                        fileList = new JList();
                        jScrollPane2.setViewportView(fileList);
                        fileList.addKeyListener(new KeyAdapter() {
                            public void keyPressed(KeyEvent evt) {
                                JListUtil.newInstance(fileList).defaultJListKeyPressed(evt);
                            }
                        });
                        fileList.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                final File_ file = JListUtil.getLeadSelectionObject(fileList);

                                if (evt.getButton() == MouseEvent.BUTTON1) {
                                    Properties prop = new Properties();
                                    currentFile = file.file;
                                    setTitle(currentFile.getName());
                                    try {
                                        prop.load(new FileInputStream(file.file));
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                    loadPropertiesToModel(prop);
                                }

                                if (evt.getButton() == MouseEvent.BUTTON1 && evt.getClickCount() == 2) {
                                    try {
                                        Runtime.getRuntime().exec(String.format("cmd /c \"%s\"", file.file));
                                    } catch (IOException e1) {
                                        e1.printStackTrace();
                                    }
                                }

                                final File parent = file.file.getParentFile();
                                JMenuItem openTargetDir = new JMenuItem();
                                openTargetDir.setText("open : " + parent);
                                openTargetDir.addActionListener(new ActionListener() {
                                    @Override
                                    public void actionPerformed(ActionEvent e) {
                                        try {
                                            Desktop.getDesktop().open(parent);
                                        } catch (IOException e1) {
                                            JCommonUtil.handleException(e1);
                                        }
                                    }
                                });

                                JPopupMenuUtil.newInstance(fileList).addJMenuItem(openTargetDir).applyEvent(evt)
                                        .show();
                            }
                        });
                    }
                }
                {
                    fileQueryText = new JTextField();
                    jPanel3.add(fileQueryText, BorderLayout.NORTH);
                    fileQueryText.getDocument()
                            .addDocumentListener(JCommonUtil.getDocumentListener(new HandleDocumentEvent() {
                                @Override
                                public void process(DocumentEvent event) {
                                    String text = JCommonUtil.getDocumentText(event);
                                    DefaultListModel model = new DefaultListModel();
                                    for (File f : backupFileList) {
                                        if (f.getName().contains(text)) {
                                            File_ ff = new File_();
                                            ff.file = f;
                                            model.addElement(ff);
                                        }
                                    }
                                    fileList.setModel(model);
                                }
                            }));
                }
                {
                    contentQueryText = new JTextField();
                    jPanel3.add(contentQueryText, BorderLayout.SOUTH);
                    contentQueryText.addActionListener(new ActionListener() {

                        void addModel(File f, DefaultListModel model) {
                            File_ ff = new File_();
                            ff.file = f;
                            model.addElement(ff);
                        }

                        public void actionPerformed(ActionEvent evt) {
                            DefaultListModel model = new DefaultListModel();
                            String text = contentQueryText.getText();
                            if (StringUtils.isEmpty(contentQueryText.getText())) {
                                return;
                            }
                            Pattern pattern = Pattern.compile(text);
                            Properties pp = null;
                            for (File f : backupFileList) {
                                pp = new Properties();
                                try {
                                    pp.load(new FileInputStream(f));
                                    for (String key : pp.stringPropertyNames()) {
                                        if (key.isEmpty()) {
                                            continue;
                                        }
                                        if (pp.getProperty(key) == null || pp.getProperty(key).isEmpty()) {
                                            continue;
                                        }
                                        if (key.contains(text)) {
                                            addModel(f, model);
                                            break;
                                        }
                                        if (pp.getProperty(key).contains(text)) {
                                            addModel(f, model);
                                            break;
                                        }
                                        if (pattern.matcher(key).find()) {
                                            addModel(f, model);
                                            break;
                                        }
                                        if (pattern.matcher(pp.getProperty(key)).find()) {
                                            addModel(f, model);
                                            break;
                                        }
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                            fileList.setModel(model);
                        }
                    });
                }
            }
        }
        JCommonUtil.setJFrameIcon(this, "resource/images/ico/english.ico");
        JCommonUtil.setJFrameCenter(this);
        pack();
        this.setSize(571, 408);

        loadCurrentFile(null);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.apache.solr.SolrTestCaseJ4.java

public static void writeCoreProperties(Path coreDirectory, Properties properties, String testname)
        throws IOException {
    log.info("Writing core.properties file to {}", coreDirectory);
    Files.createDirectories(coreDirectory);
    try (Writer writer = new OutputStreamWriter(
            Files.newOutputStream(coreDirectory.resolve(CORE_PROPERTIES_FILENAME)), Charset.forName("UTF-8"))) {
        properties.store(writer, testname);
    }//  w w w .  j  a  va2s . co  m
}

From source file:net.sf.taverna.t2.workbench.ui.impl.UserRegistrationForm.java

private void saveUserRegistrationData(UserRegistrationData regData, File propertiesFile) {
    Properties props = new Properties();
    props.setProperty(TAVERNA_VERSION_PROPERTY_NAME, regData.getTavernaVersion());
    props.setProperty(FIRST_NAME_PROPERTY_NAME, regData.getFirstName());
    props.setProperty(LAST_NAME_PROPERTY_NAME, regData.getLastName());
    props.setProperty(EMAIL_ADDRESS_PROPERTY_NAME, regData.getEmailAddress());
    props.setProperty(KEEP_ME_INFORMED_PROPERTY_NAME, regData.getKeepMeInformed() ? TRUE : FALSE);
    props.setProperty(INSTITUTION_OR_COMPANY_PROPERTY_NAME, regData.getInstitutionOrCompanyName());
    props.setProperty(INDUSTRY_PROPERTY_NAME, regData.getIndustry());
    props.setProperty(FIELD_PROPERTY_NAME, regData.getPurposeOfUsingTaverna());
    props.setProperty(PURPOSE_PROPERTY_NAME, regData.getPurposeOfUsingTaverna());

    // Write the properties file.
    try {/*from w  ww  . j  av  a  2s  . c o m*/
        props.store(new FileOutputStream(propertiesFile), null);
    } catch (Exception e) {
        logger.error("Failed to save user registration data locally on disk.");
    }
}

From source file:com.hpe.application.automation.tools.run.RunFromAlmBuilder.java

@Override
public void perform(Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener)
        throws InterruptedException, IOException {

    // get the alm server settings
    AlmServerSettingsModel almServerSettingsModel = getAlmServerSettingsModel();

    if (almServerSettingsModel == null) {
        listener.fatalError(//from w w w.  java2  s. c o  m
                "An ALM server is not defined. Go to Manage Jenkins->Configure System and define your ALM server under Application Lifecycle Management");

        // set pipeline stage as failure in case if ALM server was not configured
        build.setResult(Result.FAILURE);

        return;
    }

    EnvVars env = null;
    try {
        env = build.getEnvironment(listener);
    } catch (IOException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }
    VariableResolver<String> varResolver = new VariableResolver.ByMap<String>(build.getEnvironment(listener));

    // now merge them into one list
    Properties mergedProperties = new Properties();

    mergedProperties.putAll(almServerSettingsModel.getProperties());
    mergedProperties.putAll(runFromAlmModel.getProperties(env, varResolver));

    String encAlmPass = "";
    try {

        encAlmPass = EncryptionUtils.Encrypt(runFromAlmModel.getAlmPassword(), EncryptionUtils.getSecretKey());

        mergedProperties.remove(RunFromAlmModel.ALM_PASSWORD_KEY);
        mergedProperties.put(RunFromAlmModel.ALM_PASSWORD_KEY, encAlmPass);

    } catch (Exception e) {
        build.setResult(Result.FAILURE);
        listener.fatalError("problem in qcPassword encription");
    }

    Date now = new Date();
    Format formatter = new SimpleDateFormat("ddMMyyyyHHmmssSSS");
    String time = formatter.format(now);

    // get a unique filename for the params file
    ParamFileName = "props" + time + ".txt";
    ResultFilename = "Results" + time + ".xml";
    //KillFileName = "stop" + time + ".txt";

    mergedProperties.put("runType", RunType.Alm.toString());
    mergedProperties.put("resultsFilename", ResultFilename);

    // get properties serialized into a stream
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    try {
        mergedProperties.store(stream, "");
    } catch (IOException e) {
        build.setResult(Result.FAILURE);
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    String propsSerialization = stream.toString();
    InputStream propsStream = IOUtils.toInputStream(propsSerialization);

    // get the remote workspace filesys
    FilePath projectWS = workspace;

    // Get the URL to the Script used to run the test, which is bundled
    // in the plugin
    URL cmdExeUrl = Hudson.getInstance().pluginManager.uberClassLoader.getResource(HpToolsLauncher_SCRIPT_NAME);
    if (cmdExeUrl == null) {
        listener.fatalError(HpToolsLauncher_SCRIPT_NAME + " not found in resources");
        return;
    }

    FilePath propsFileName = projectWS.child(ParamFileName);
    FilePath CmdLineExe = projectWS.child(HpToolsLauncher_SCRIPT_NAME);

    try {
        // create a file for the properties file, and save the properties
        propsFileName.copyFrom(propsStream);

        // Copy the script to the project workspace
        CmdLineExe.copyFrom(cmdExeUrl);
    } catch (IOException e1) {
        build.setResult(Result.FAILURE);
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    try {
        // Run the HpToolsLauncher.exe
        AlmToolsUtils.runOnBuildEnv(build, launcher, listener, CmdLineExe, ParamFileName);
    } catch (IOException ioe) {
        Util.displayIOException(ioe, listener);
        build.setResult(Result.FAILURE);
        return;
    } catch (InterruptedException e) {
        build.setResult(Result.ABORTED);
        PrintStream out = listener.getLogger();
        // kill processes
        //FilePath killFile = projectWS.child(KillFileName);
        /* try {
        out.println("Sending abort command");
        killFile.write("\n", "UTF-8");
        while (!killFile.exists())
            Thread.sleep(1000);
        Thread.sleep(1500);
                
        } catch (IOException e1) {
        //build.setResult(Result.FAILURE);
        // TODO Auto-generated catch block
        e1.printStackTrace();
        } catch (InterruptedException e1) {
        //build.setResult(Result.FAILURE);
        // TODO Auto-generated catch block
        e1.printStackTrace();
        }*/

        try {
            AlmToolsUtils.runHpToolsAborterOnBuildEnv(build, launcher, listener, ParamFileName, workspace);
        } catch (IOException e1) {
            Util.displayIOException(e1, listener);
            build.setResult(Result.FAILURE);
            return;
        } catch (InterruptedException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        out.println("Operation was aborted by user.");
        //build.setResult(Result.FAILURE);
    }
    return;

}

From source file:com.bt.aloha.batchtest.ultramonkey.Servlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    LOG.debug(request.getPathInfo() + ":" + request.getQueryString());
    Properties resultProperties = new Properties();
    resultProperties.put("local.host.name", request.getLocalName());
    resultProperties.put("local.host.port", Integer.toString(request.getLocalPort()));
    resultProperties.put("remote.host.name", request.getRemoteHost());
    resultProperties.put("remote.host.port", Integer.toString(request.getRemotePort()));
    resultProperties.put("makeCall.count", Integer.toString(makeCallCount));
    resultProperties.put("terminateCall.count", Integer.toString(terminateCallCount));
    resultProperties.put("incomingCall.count", Integer.toString(((ServiceImpl) service).getIncomingCount()));
    String result = "something or rather";
    String resultKey = "callid";
    if (request.getPathInfo().equalsIgnoreCase("/makecall")) {
        makeCallCount++;//  w w w.  j  a  va2s. c om
        String caller = request.getParameter("caller");
        String callee = request.getParameter("callee");
        result = this.service.makeCall(caller, callee);
    } else if (request.getPathInfo().equalsIgnoreCase("/terminatecall")) {
        terminateCallCount++;
        String callid = request.getParameter("callid");
        service.terminateCall(callid);
        result = callid;
    } else if (request.getPathInfo().equalsIgnoreCase("/reset")) {
        makeCallCount = 0;
        terminateCallCount = 0;
        ((ServiceImpl) service).setIncomingCount(0);
    } else if (request.getPathInfo().equalsIgnoreCase("/status")) {
        result = "Sample SpringRing web application";
        resultKey = "status";
    } else {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }
    resultProperties.put(resultKey, result);
    resultProperties.store(response.getOutputStream(), "Response generated on:");
}

From source file:org.kemri.wellcome.controller.Dhis2ServerController.java

@RequestMapping(value = Views.DB_CONFIGURE, method = RequestMethod.POST)
public @ResponseBody Map<String, ? extends Object> configServer(HttpServletRequest request,
        @RequestBody DatabaseProperties dbProperties) throws Exception {

    Set<ConstraintViolation<DatabaseProperties>> failures = validator.validate(dbProperties);
    if (!failures.isEmpty()) {
        return Collections.singletonMap("u", validationDBMessages(failures).toString());
    } else {//from www. j av  a  2s.co m
        try {
            Properties properties = new Properties();
            properties.setProperty("jdbc.url", "jdbc:mysql://" + dbProperties.getDatabaseUrl() + ":3306/"
                    + dbProperties.getDatabaseName());
            properties.setProperty("jdbc.username", dbProperties.getUsername());
            properties.setProperty("jdbc.password", dbProperties.getPassword());
            properties.setProperty("hibernate.hbm2ddl.auto", "update");
            properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5InnoDBDialect");
            properties.setProperty("hibernate.query.substitutions", "true 'T', false 'F'");
            properties.setProperty("hibernate.show_sql", "false");
            properties.setProperty("hibernate.c3p0.minPoolSize", "50");
            properties.setProperty("hibernate.c3p0.maxPoolSize", "1000");
            properties.setProperty("hibernate.c3p0.timeout", "300");
            properties.setProperty("hibernate.c3p0.max_statement", "700");
            properties.setProperty("hibernate.c3p0.testConnectionOnCheckout", "false");
            properties.setProperty("jdbc.driverClassName", "com.mysql.jdbc.Driver");

            //save properties to project root folder
            ServletContext servletContext = request.getSession().getServletContext();
            Resource resource = new ServletContextResource(servletContext, databaseProperties);
            properties.store(new FileOutputStream(resource.getFile()), null);
        } catch (IOException e) {
            log.error("\n " + e.getMessage() + "\n");
            return Collections.singletonMap("u", e.getMessage());
        }
        return Collections.singletonMap("u", "Saved");
    }
}

From source file:org.cloudifysource.azure.CliAzureDeploymentTest.java

public void before() throws Exception {

    isDebugMode = Boolean/*from ww  w. j  a  v a  2  s.c  o m*/
            .parseBoolean(System.getProperty(IS_DEBUG_MODE_SYSTEM_PROPERTY, Boolean.toString(false)));

    String localWorkingDirPath = System.getProperty(LOCAL_WORKING_DIR_SYSTEM_PROPERTY_KEY);
    Assert.assertNotNull(LOCAL_WORKING_DIR_SYSTEM_PROPERTY_KEY + " system property has to exists",
            localWorkingDirPath);

    File localWorkingDir = new File(localWorkingDirPath);
    Assert.assertTrue(localWorkingDir.getPath() + " does not exist", localWorkingDir.isDirectory());

    File gigaSpacesCloudifyDir = new File(localWorkingDir, GIGASPACES_LATEST_HOME);
    Assert.assertTrue(gigaSpacesCloudifyDir.getPath() + " does not exist", gigaSpacesCloudifyDir.isDirectory());

    applicationFile = new File(gigaSpacesCloudifyDir, RELATIVE_APPLICATION_EXAMPLE_PATH);
    Assert.assertTrue(applicationFile.getPath() + " does not exist", applicationFile.isDirectory());

    // these should exist assuming the cloudify folder is valid
    cliExecutablePath = new File(gigaSpacesCloudifyDir, RELATIVE_CLI_PATH);
    File azureConfigExec = new File(gigaSpacesCloudifyDir, RELATIVE_AZURE_CONFIG_EXEC_PATH);
    File azurePropertiesFile = new File(gigaSpacesCloudifyDir, RELATIVE_AZURE_PROPERTIES_PATH);
    File cscfgFile = new File(cliExecutablePath.getParent(),
            RELATIVE_WORKER_ROLE_DIR + "\\ServiceConfiguration.Cloud.cscfg");

    // update worker roles configuration to upload logs
    AzureDeploymentConfigurationFile cscfg = new AzureDeploymentConfigurationFile(cscfgFile);
    cscfg.setUploadAgentLogs(true);
    cscfg.setUploadAllLogs(true);
    cscfg.flush();

    Properties newAzureProps = new Properties();
    newAzureProps.setProperty(AZURE_PROPERTIES_ACCOUNT_NAME_KEY, credentials.getBlobStorageAccountName());
    newAzureProps.setProperty(AZURE_PROPERTIES_ACCOUNT_KEY_KEY, credentials.getBlobStorageAccountKey());
    newAzureProps.setProperty(AZURE_PROPERTIES_CONTAINER_NAME_KEY, AZURE_CONTAINER_NAME);
    newAzureProps.setProperty(AZURE_PROPERTIES_WORKER_ROLE_FOLDER_KEY, RELATIVE_WORKER_ROLE_DIR);
    newAzureProps.setProperty(AZURE_PROPERTIES_CS_PACK_FOLDER_KEY, CS_PACK_FOLDER);
    newAzureProps.setProperty(AZURE_PROPERTIES_RDP_CERT_FILE_KEY, RDP_CERT_FILE);
    newAzureProps.setProperty(AZURE_PROPERTIES_RDP_PFX_FILE_KEY, RDP_PFX_FILE);
    newAzureProps.setProperty(AZURE_PROPERITES_CERTIFICATE_THUMBPRINT_KEY,
            credentials.getHostedServicesCertificateThumbrint());
    newAzureProps.setProperty(AZURE_PROPERITES_SUBSCRIPTION_ID_KEY,
            credentials.getHostedServicesSubscriptionId());
    newAzureProps.setProperty(AZURE_PROPERTIES_RDP_LOGIN_USERNAME_KEY, AZURE_RDP_LOGIN_USERNAME);
    newAzureProps.setProperty(AZURE_PROPERTIES_RDP_LOGIN_ENCRYPTED_PASSWORD,
            AZURE_RDP_LOGIN_ENCRYPTED_PASSWORD);

    log("Overriding azure.properties file");
    FileOutputStream fos = new FileOutputStream(azurePropertiesFile);
    newAzureProps.store(fos, null);
    fos.close();

    deployment = new AzureDeploymentWrapper(azureConfigExec, credentials.getHostedServicesSubscriptionId(),
            credentials.getHostedServicesCertificateThumbrint(), AZURE_HOSTED_SERVICE, AZURE_SLOT, null, null,
            null, null);

}