All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.openshift.internal.restclient.model.build.BuildRequest Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 * Copyright (c) 2015 Red Hat, Inc.
 * Distributed under license by Red Hat, Inc. All rights reserved.
 * This program is made available under the terms of the
 * Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Red Hat, Inc. - initial API and implementation
 ******************************************************************************/

package com.openshift.internal.restclient.model.build;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.jboss.dmr.ModelNode;

import com.openshift.internal.restclient.model.KubernetesResource;
import com.openshift.restclient.IClient;
import com.openshift.restclient.model.build.IBuildRequest;

public class BuildRequest extends KubernetesResource implements IBuildRequest {

    private static final String COMMIT = "commit";
    private static final String GIT = "git";
    private static final String BIGGIT = "Git";
    private static final String TYPE = "type";
    private static final String REVISION = "revision";
    private static final String REVISION_GIT_COMMIT = REVISION + "." + GIT + "." + COMMIT;
    private static final String REVISION_TYPE = REVISION + "." + TYPE;
    private static final String TRIGGERED_BY = "triggeredBy";
    private static final String MESSAGE = "message";
    private static final String ENV = "env";

    public BuildRequest(ModelNode node, IClient client, Map propertyKeys) {
        super(node, client, propertyKeys);
    }

    @Override
    public void setCommitId(String commitId) {
        set(REVISION_TYPE, BIGGIT);
        set(REVISION_GIT_COMMIT, commitId);
    }

    @Override
    public void addBuildCause(String cause) {
        ModelNode triggeredBys = get(TRIGGERED_BY);
        triggeredBys.add(MESSAGE, cause);
    }

    @Override
    public String getCommitId() {
        return get(REVISION_GIT_COMMIT).asString();
    }

    @Override
    public List getBuildCauses() {
        List causes = get(TRIGGERED_BY).asList();
        ArrayList ret = new ArrayList<>();
        for (ModelNode cause : causes) {
            ret.add(cause.asString());
        }
        return ret;
    }

    @Override
    public void setEnvironmentVariable(String name, String value) {
        ModelNode envs = get(ENV);
        ModelNode entry = envs.add();
        entry.get(NAME).set(name);
        entry.get(VALUE).set(value);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy