Example usage for org.apache.commons.lang StringUtils endsWith

List of usage examples for org.apache.commons.lang StringUtils endsWith

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils endsWith.

Prototype

public static boolean endsWith(String str, String suffix) 

Source Link

Document

Check if a String ends with a specified suffix.

Usage

From source file:org.jvnet.hudson.plugins.mavendepsupdate.MavenUpdateChecker.java

public MavenUpdateCheckerResult call() throws IOException {
    ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();

    try {//from www  .  ja  v  a 2  s  .c  o m

        PluginFirstClassLoader pluginFirstClassLoader = getPluginFirstClassLoader();
        Thread.currentThread().setContextClassLoader(pluginFirstClassLoader);
        String classLoaderName = getClass().getClassLoader().toString();

        mavenUpdateCheckerResult.addDebugLine(classLoaderName);
        PlexusContainer plexusContainer = getPlexusContainer(pluginFirstClassLoader);

        Thread.currentThread().setContextClassLoader(plexusContainer.getContainerRealm());
        mavenUpdateCheckerResult.addDebugLine("ok for new DefaultPlexusContainer( conf ) ");
        mavenUpdateCheckerResult.addDebugLine("Thread.currentThread().getContextClassLoader() "
                + Thread.currentThread().getContextClassLoader());
        mavenUpdateCheckerResult.addDebugLine("Thread.currentThread().getContextClassLoader().parent "
                + (Thread.currentThread().getContextClassLoader().getParent() == null ? "null"
                        : Thread.currentThread().getContextClassLoader().getParent().toString()));
        mavenUpdateCheckerResult.addDebugLine(
                "classLoader  urls " + Arrays.asList(plexusContainer.getContainerRealm().getURLs()));
        ProjectBuilder projectBuilder = plexusContainer.lookup(ProjectBuilder.class);

        // FIXME load userProperties from the job
        Properties userProperties = this.userProperties == null ? new Properties() : this.userProperties;

        userProperties.put("java.home", jdkHome);

        ProjectBuildingRequest projectBuildingRequest = getProjectBuildingRequest(userProperties,
                plexusContainer);

        // check plugins too
        projectBuildingRequest.setProcessPlugins(true);
        // force snapshots update

        projectBuildingRequest.setResolveDependencies(true);

        List<ProjectBuildingResult> projectBuildingResults = projectBuilder
                .build(Arrays.asList(new File(rootPomPath)), true, projectBuildingRequest);

        ProjectDependenciesResolver projectDependenciesResolver = plexusContainer
                .lookup(ProjectDependenciesResolver.class);

        List<MavenProject> mavenProjects = new ArrayList<MavenProject>(projectBuildingResults.size());

        for (ProjectBuildingResult projectBuildingResult : projectBuildingResults) {
            mavenProjects.add(projectBuildingResult.getProject());
        }

        ProjectSorter projectSorter = new ProjectSorter(mavenProjects);

        // use the projects reactor model as a workspaceReader
        // if reactors are not available remotely dependencies resolve will failed
        // due to artifact not found

        final Map<String, MavenProject> projectMap = getProjectMap(mavenProjects);
        WorkspaceReader reactorRepository = new ReactorReader(projectMap);

        MavenRepositorySystemSession mavenRepositorySystemSession = (MavenRepositorySystemSession) projectBuildingRequest
                .getRepositorySession();

        mavenRepositorySystemSession.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS);

        mavenRepositorySystemSession.setWorkspaceReader(reactorRepository);

        MavenPluginManager mavenPluginManager = plexusContainer.lookup(MavenPluginManager.class);

        for (MavenProject mavenProject : projectSorter.getSortedProjects()) {
            LOGGER.info("resolve dependencies for project " + mavenProject.getId());

            DefaultDependencyResolutionRequest dependencyResolutionRequest = new DefaultDependencyResolutionRequest(
                    mavenProject, mavenRepositorySystemSession);

            try {
                DependencyResolutionResult dependencyResolutionResult = projectDependenciesResolver
                        .resolve(dependencyResolutionRequest);
            } catch (DependencyResolutionException e) {
                mavenUpdateCheckerResult.addDebugLine(e.getMessage());
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                e.printStackTrace(pw);
                mavenUpdateCheckerResult.addDebugLine("skip:" + sw.toString());
            }
            if (checkPlugins) {
                for (Plugin plugin : mavenProject.getBuildPlugins()) {
                    // only for SNAPSHOT
                    if (StringUtils.endsWith(plugin.getVersion(), "SNAPSHOT")) {
                        mavenPluginManager.getPluginDescriptor(plugin,
                                mavenProject.getRemotePluginRepositories(), mavenRepositorySystemSession);
                    }
                }
            }

        }
        SnapshotTransfertListener snapshotTransfertListener = (SnapshotTransfertListener) projectBuildingRequest
                .getRepositorySession().getTransferListener();

        if (snapshotTransfertListener.isSnapshotDownloaded()) {
            mavenUpdateCheckerResult.addFilesUpdatedNames(snapshotTransfertListener.getSnapshots());
        }

    } catch (Exception e) {
        mavenUpdateCheckerResult.addDebugLine(e.getMessage());
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        mavenUpdateCheckerResult.addDebugLine("skip:" + sw.toString());
    } finally {
        Thread.currentThread().setContextClassLoader(originalClassLoader);
    }
    return mavenUpdateCheckerResult;
}

From source file:org.jvnet.hudson.plugins.mavendepsupdate.util.SnapshotTransfertListener.java

private boolean isMetaData(File file) {
    return StringUtils.contains(file.getName(), "maven-metadata")
            && StringUtils.endsWith(file.getName(), ".xml");
}

From source file:org.kaaproject.kaa.server.common.thrift.cli.client.BaseCliThriftClient.java

/**
 * Process command line./*from   w w w .  j a v  a2s .co m*/
 *
 * @param line the command line
 * @return the int execution result code
 */
public int processLine(String line) {
    int lastRet = 0;
    int ret = 0;

    String command = "";
    for (String oneCmd : line.split(";")) {
        if (StringUtils.endsWith(oneCmd, "\\")) {
            command += StringUtils.chop(oneCmd) + ";";
            continue;
        } else {
            command += oneCmd;
        }
        if (StringUtils.isBlank(command)) {
            continue;
        }

        ret = processCmd(command);
        command = "";
        lastRet = ret;
        if (ret != 0) {
            return ret;
        }

    }
    return lastRet;
}

From source file:org.kaaproject.kaa.server.control.cli.ControlApiCliThriftClient.java

/**
 * Process command line.//w  w  w.  j ava 2s  .  c om
 *
 * @param line
 *            the command line
 * @return the int execution result code
 */
public int processLine(String line) {
    int lastRet = 0, ret = 0;

    String command = "";
    for (String oneCmd : line.split(";")) {
        if (StringUtils.endsWith(oneCmd, "\\")) {
            command += StringUtils.chop(oneCmd) + ";";
            continue;
        } else {
            command += oneCmd;
        }
        if (StringUtils.isBlank(command)) {
            continue;
        }

        ret = processCmd(command);
        command = "";
        lastRet = ret;
        if (ret != 0) {
            return ret;
        }

    }
    return lastRet;
}

From source file:org.kuali.kfs.module.ar.businessobject.lookup.ContractsGrantsInvoiceDocumentErrorLogLookupableHelperServiceImpl.java

/**
 * Manipulate fields for search criteria in order to get the results the user really wants.
 *
 * @param fieldValues/* w w  w . j ava 2  s  .  c  om*/
 * @return updated search criteria fieldValues
 */
protected Map<String, String> updateFieldValuesForSearchCriteria(Map<String, String> fieldValues) {
    Map<String, String> newFieldValues = new HashMap<>();
    newFieldValues.putAll(fieldValues);

    // Add wildcard character to start and end of accounts field so users can search for single account
    // within the delimited list of accounts without having to add the wildcards explicitly themselves.
    String accounts = newFieldValues
            .get(ArPropertyConstants.ContractsGrantsInvoiceDocumentErrorLogLookupFields.ACCOUNTS);
    if (StringUtils.isNotBlank(accounts)) {
        // only add wildcards if they haven't already been added (for some reason this method gets called twice when generating the pdf report)
        if (!StringUtils.startsWith(accounts, KFSConstants.WILDCARD_CHARACTER)) {
            accounts = KFSConstants.WILDCARD_CHARACTER + accounts;
        }
        if (!StringUtils.endsWith(accounts, KFSConstants.WILDCARD_CHARACTER)) {
            accounts += KFSConstants.WILDCARD_CHARACTER;
        }
    }
    newFieldValues.put(ArPropertyConstants.ContractsGrantsInvoiceDocumentErrorLogLookupFields.ACCOUNTS,
            accounts);

    // Increment to error date by one day so that the correct results are retrieved.
    // Since the error date is stored as both a date and time in the database records with an error date
    // the same as the error date the user enters on the search criteria aren't retrieved without this modification.
    String errorDate = newFieldValues
            .get(ArPropertyConstants.ContractsGrantsInvoiceDocumentErrorLogLookupFields.ERROR_DATE_TO);

    int index = StringUtils.indexOf(errorDate, SearchOperator.LESS_THAN_EQUAL.toString());
    if (index == StringUtils.INDEX_NOT_FOUND) {
        index = StringUtils.indexOf(errorDate, SearchOperator.BETWEEN.toString());
        if (index != StringUtils.INDEX_NOT_FOUND) {
            incrementErrorDate(newFieldValues, errorDate, index);
        }
    } else {
        incrementErrorDate(newFieldValues, errorDate, index);
    }

    return newFieldValues;
}

From source file:org.kuali.rice.core.impl.config.property.JAXBConfigImpl.java

protected boolean isPropertiesFile(String filename) {
    String lower = StringUtils.lowerCase(filename);
    return StringUtils.endsWith(lower, ".properties");
}

From source file:org.kuali.rice.krad.lookup.LookupUtils.java

/**
 * Retrieves the value for the given parameter name to send as a lookup parameter.
 *
 * @param form form instance to retrieve values from
 * @param request request object to retrieve parameters from
 * @param lookupObjectClass data object class associated with the lookup, used to check whether the
 * value needs to be encyrpted// w  ww .  j  a va 2s .  c  o  m
 * @param propertyName name of the property associated with the parameter, used to check whether the
 * value needs to be encrypted
 * @param parameterName name of the parameter to retrieve the value for
 * @return String parameter value or empty string if no value was found
 */
public static String retrieveLookupParameterValue(UifFormBase form, HttpServletRequest request,
        Class<?> lookupObjectClass, String propertyName, String parameterName) {
    String parameterValue = "";

    // get literal parameter values first
    if (StringUtils.startsWith(parameterName, "'") && StringUtils.endsWith(parameterName, "'")) {
        parameterValue = StringUtils.substringBetween(parameterName, "'");
    } else if (parameterValue.startsWith(
            KRADConstants.LOOKUP_PARAMETER_LITERAL_PREFIX + KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER)) {
        parameterValue = StringUtils.removeStart(parameterValue, KRADConstants.LOOKUP_PARAMETER_LITERAL_PREFIX
                + KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER);
    }
    // check if parameter is in request
    else if (request.getParameterMap().containsKey(parameterName)) {
        parameterValue = request.getParameter(parameterName);
    }
    // get parameter value from form object
    else {
        parameterValue = ObjectPropertyUtils.getPropertyValueAsText(form, parameterName);
    }

    if (parameterValue != null && lookupObjectClass != null
            && KRADServiceLocatorWeb.getDataObjectAuthorizationService()
                    .attributeValueNeedsToBeEncryptedOnFormsAndLinks(lookupObjectClass, propertyName)) {
        try {
            if (CoreApiServiceLocator.getEncryptionService().isEnabled()) {
                parameterValue = CoreApiServiceLocator.getEncryptionService().encrypt(parameterValue)
                        + EncryptionService.ENCRYPTION_POST_PREFIX;
            }
        } catch (GeneralSecurityException e) {
            LOG.error("Unable to encrypt value for property name: " + propertyName);
            throw new RuntimeException(e);
        }
    }

    return parameterValue;
}

From source file:org.kuali.rice.krad.uif.element.Action.java

/**
 * Setter for {@link #getActionScript()}.
 *
 * @param actionScript the actionScript to set
 *//*from w w  w. jav a2  s.  c o m*/
public void setActionScript(String actionScript) {
    if (StringUtils.isNotBlank(actionScript) && !StringUtils.endsWith(actionScript, ";")) {
        actionScript = actionScript + ";";
    }

    this.actionScript = actionScript;
}

From source file:org.kuali.rice.krad.uif.service.impl.ExpressionEvaluatorServiceImpl.java

/**
 * @see org.kuali.rice.krad.uif.service.ExpressionEvaluatorService#evaluateExpression(java.lang.Object,
 *      java.util.Map, java.lang.String)
 *///  w ww  . j  a  v a  2 s.  c  o  m
public Object evaluateExpression(Object contextObject, Map<String, Object> evaluationParameters,
        String expressionStr) {
    StandardEvaluationContext context = new StandardEvaluationContext(contextObject);
    context.setVariables(evaluationParameters);
    addCustomFunctions(context);

    // if expression contains placeholders remove before evaluating
    if (StringUtils.startsWith(expressionStr, UifConstants.EL_PLACEHOLDER_PREFIX)
            && StringUtils.endsWith(expressionStr, UifConstants.EL_PLACEHOLDER_SUFFIX)) {
        expressionStr = StringUtils.removeStart(expressionStr, UifConstants.EL_PLACEHOLDER_PREFIX);
        expressionStr = StringUtils.removeEnd(expressionStr, UifConstants.EL_PLACEHOLDER_SUFFIX);
    }

    ExpressionParser parser = new SpelExpressionParser();
    Object result = null;
    try {
        Expression expression = parser.parseExpression(expressionStr);

        result = expression.getValue(context);
    } catch (Exception e) {
        LOG.error("Exception evaluating expression: " + expressionStr);
        throw new RuntimeException("Exception evaluating expression: " + expressionStr, e);
    }

    return result;
}

From source file:org.kuali.rice.krad.uif.service.impl.ExpressionEvaluatorServiceImpl.java

/**
 * Retrieves the Map from the given object that containing the property expressions that should
 * be evaluated. Each expression is then evaluated and the result is used to set the property value
 *
 * <p>//from  w w  w . j  a  v a2 s.  c  om
 * If the expression is an el template (part static text and part expression), only the expression
 * part will be replaced with the result. More than one expressions may be contained within the template
 * </p>
 *
 * @param object - object instance to evaluate expressions for
 * @param contextObject - object providing the default context for expressions
 * @param evaluationParameters - map of additional parameters that may be used within the expressions
 */
protected void evaluatePropertyExpressions(Object object, Object contextObject,
        Map<String, Object> evaluationParameters) {
    Map<String, String> propertyExpressions = new HashMap<String, String>();
    if (Configurable.class.isAssignableFrom(object.getClass())) {
        propertyExpressions = ((Configurable) object).getPropertyExpressions();
    }

    for (Entry<String, String> propertyExpression : propertyExpressions.entrySet()) {
        String propertyName = propertyExpression.getKey();
        String expression = propertyExpression.getValue();

        // check whether expression should be evaluated or property should retain the expression
        if (CloneUtils.fieldHasAnnotation(object.getClass(), propertyName, KeepExpression.class)) {
            // set expression as property value to be handled by the component
            ObjectPropertyUtils.setPropertyValue(object, propertyName, expression);
            continue;
        }

        Object propertyValue = null;

        // determine whether the expression is a string template, or evaluates to another object type
        if (StringUtils.startsWith(expression, UifConstants.EL_PLACEHOLDER_PREFIX)
                && StringUtils.endsWith(expression, UifConstants.EL_PLACEHOLDER_SUFFIX)
                && (StringUtils.countMatches(expression, UifConstants.EL_PLACEHOLDER_PREFIX) == 1)) {
            propertyValue = evaluateExpression(contextObject, evaluationParameters, expression);
        } else {
            // treat as string template
            propertyValue = evaluateExpressionTemplate(contextObject, evaluationParameters, expression);
        }

        ObjectPropertyUtils.setPropertyValue(object, propertyName, propertyValue);
    }
}