Search in sources :

Example 1 with MDWException

use of com.centurylink.mdw.common.exception.MDWException in project mdw-designer by CenturyLinkCloud.

the class ProjectUpdater method postFilterProperties.

private void postFilterProperties(IFile mdwPropsFile, IProgressMonitor monitor) {
    if (mdwPropsFile.exists()) {
        String mdwProps = new String(PluginUtil.readFile(mdwPropsFile));
        mdwProps = mdwProps.replaceFirst("MDWFramework\\.ApplicationDetails-@GROUP_SEP@MdwVersion.*", "");
        mdwProps = mdwProps.replaceFirst("MDWFramework\\.ApplicationDetails@GROUP_SEP@EnvironmentName.*", "");
        mdwProps = mdwProps.replaceAll("@GROUP_SEP@", workflowProject.isOsgi() ? "-" : "/");
        mdwProps = mdwProps.replaceFirst("MDWFramework.TaskManagerWeb/dev.tm.gui.user=.*", "MDWFramework.TaskManagerWeb/dev.tm.gui.user=" + System.getProperty("user.name"));
        mdwProps = mdwProps.replaceFirst("mdw.hub.user=.*", "mdw.hub.user=" + System.getProperty("user.name"));
        // db settings
        JdbcDataSource dataSource = workflowProject.getMdwDataSource();
        if (dataSource.getJdbcUrl() != null) {
            mdwProps = mdwProps.replaceFirst("mdw.database.driver=.*", "mdw.database.driver=" + dataSource.getDriver());
            mdwProps = mdwProps.replaceFirst("mdw.database.url=.*", "mdw.database.url=" + dataSource.getJdbcUrl());
            mdwProps = mdwProps.replaceFirst("mdw.database.username=.*", "mdw.database.username=" + dataSource.getDbUser());
            mdwProps = mdwProps.replaceFirst("mdw.database.password=.*", "mdw.database.password=" + dataSource.getDbPassword());
        }
        if (workflowProject.isFilePersist()) {
            // also handle case where properties are commented out
            mdwProps = mdwProps.replaceFirst("#?mdw.asset.location=.*", "mdw.asset.location=" + workflowProject.getAssetDir().toString().replace('\\', '/'));
            if (workflowProject.getMdwVcsRepository().hasRemoteRepository()) {
                mdwProps = mdwProps.replaceFirst("#?mdw.git.local.path=.*", "mdw.git.local.path=" + workflowProject.getProjectDir().toString().replace('\\', '/'));
                if (workflowProject.getMdwVcsRepository().getRepositoryUrl() != null)
                    mdwProps = mdwProps.replaceFirst("#?mdw.git.remote.url=.*", "mdw.git.remote.url=" + workflowProject.getMdwVcsRepository().getRepositoryUrl());
            } else {
                mdwProps = mdwProps.replaceFirst("mdw.git.local.path=", "# mdw.git.local.path=");
                mdwProps = mdwProps.replaceFirst("mdw.git.remote.url=", "# mdw.git.remote.url=");
                mdwProps = mdwProps.replaceFirst("mdw.git.branch=", "# mdw.git.branch=");
            }
        } else {
            mdwProps = mdwProps.replaceFirst("mdw.asset.location=", "# mdw.asset.location=");
            mdwProps = mdwProps.replaceFirst("mdw.git.local.path=", "# mdw.git.local.path=");
            mdwProps = mdwProps.replaceFirst("mdw.git.remote.url=", "# mdw.git.remote.url=");
        }
        if (workflowProject.isOsgi()) {
            mdwProps = mdwProps.replaceAll("@@", "~at~@");
            StringBuffer substituted = new StringBuffer(mdwProps.length());
            Pattern tokenPattern = Pattern.compile("(@.*?@)");
            Matcher matcher = tokenPattern.matcher(mdwProps);
            int index = 0;
            while (matcher.find()) {
                String match = matcher.group();
                substituted.append(mdwProps.substring(index, matcher.start()));
                String value = match.substring(1, match.length() - 1);
                substituted.append("${").append(value).append("}");
                index = matcher.end();
            }
            substituted.append(mdwProps.substring(index));
            mdwProps = substituted.toString();
            mdwProps = mdwProps.replaceAll("~at~", "@");
            if (workflowProject.checkRequiredVersion(5, 5)) {
                Map<String, String> values = getPropertiesMap();
                try {
                    mdwProps = ExpressionUtil.substitute(mdwProps, values, true);
                } catch (MDWException ex) {
                    PluginMessages.log(ex);
                }
            }
        }
        PluginUtil.writeFile(mdwPropsFile, mdwProps, monitor);
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) JdbcDataSource(com.centurylink.mdw.plugin.project.model.JdbcDataSource) MDWException(com.centurylink.mdw.common.exception.MDWException)

Aggregations

MDWException (com.centurylink.mdw.common.exception.MDWException)1 JdbcDataSource (com.centurylink.mdw.plugin.project.model.JdbcDataSource)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1