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

io.airlift.airship.configbundler.SnapshotCommand Maven / Gradle / Ivy

There is a newer version: 0.13
Show newest version
package io.airlift.airship.configbundler;

import com.google.common.base.Preconditions;
import com.google.common.io.InputSupplier;
import io.airlift.command.Arguments;
import io.airlift.command.Command;
import org.eclipse.jgit.api.Git;

import java.io.File;
import java.io.InputStream;
import java.util.Map;
import java.util.concurrent.Callable;

import static java.lang.String.format;

@Command(name = "snapshot", description = "Deploy a snapshot config bundle")
public class SnapshotCommand
        implements Callable
{
    @Arguments
    public String component;

    @Override
    public Void call()
            throws Exception
    {
        Git git = Git.open(new File("."));

        Model model = new Model(git);
        Metadata metadata = model.readMetadata();

        String groupId = metadata.getGroupId();
        Preconditions.checkNotNull(groupId, "GroupId missing from metadata file");

        Preconditions.checkState(!model.isDirty(), "Cannot deploy with a dirty working tree");

        Bundle bundle;

        if (component == null) {
            bundle = model.getActiveBundle();
        }
        else {
            bundle = model.getBundle(component);
        }

        Preconditions.checkState(bundle.isSnapshot(), "There are not pending changes for bundle %s. Use released version %s:%s instead",
                bundle.getName(), bundle.getName(), bundle.getVersionString());

        final Map> entries = model.getEntries(bundle);

        if (entries.isEmpty()) {
            throw new RuntimeException("Cannot build an empty config package");
        }

        Maven maven = new Maven(metadata.getSnapshotsRepository(), metadata.getReleasesRepository());
        maven.upload(groupId, bundle.getName(), bundle.getVersionString(), ReleaseCommand.ARTIFACT_TYPE, new ZipGenerator(entries));

        System.out.println(format("Uploaded %s-%s", bundle.getName(), bundle.getVersionString()));

        return null;

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy