Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * Copyright (C) 2010 JFrog Ltd.
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
package org.jfrog.hudson.util;
When upgrading from an older version, a user might have deployer credentials as local variables of a builder configuration. This converter Will check for existing old deployer credentials and "move" them to a credentials object instead, thus overriding the deployer credentials of the global config.

Noam Y. Tenne
        extends XStream2.PassthruConverter<T> {
    protected void callback(T deployerOverriderUnmarshallingContext context) {
        Class<? extends DeployerOverrideroverriderClass = deployerOverrider.getClass();
        try {
            Field oldUsernameField = overriderClass.getDeclaredField("username");
            Object oldUsernameValue = oldUsernameField.get(deployerOverrider);
            if (oldUsernameValue != null && StringUtils.isNotBlank((StringoldUsernameValue) &&
                    !deployerOverrider.isOverridingDefaultDeployer()) {
                String oldUsername = (StringoldUsernameValue;
                String oldPassword = null;
                Field oldPasswordField;
                try {
                    oldPasswordField = overriderClass.getDeclaredField("password");
                } catch (NoSuchFieldException e) {
                    oldPasswordField = overriderClass.getDeclaredField("scrambledPassword");
                Object oldPasswordValue = oldPasswordField.get(deployerOverrider);
                if ((oldPasswordValue != null) && StringUtils.isNotBlank(((StringoldPasswordValue))) {
                    oldPassword = Scrambler.descramble((StringoldPasswordValue);
                Field overridingCredentialsField = overriderClass.getDeclaredField("overridingDeployerCredentials");
                overridingCredentialsField.set(deployerOverridernew Credentials(oldUsernameoldPassword));
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(getConversionErrorMessage(deployerOverrider), e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(getConversionErrorMessage(deployerOverrider), e);
    private String getConversionErrorMessage(T deployerOverrider) {
        return String.format("Could not convert the class '%s' to use the new overriding deployer credential storage " +
New to GrepCode? Check out our FAQ X