Skip to content
This repository has been archived by the owner on May 18, 2021. It is now read-only.

Update asconfig command #60

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package io.airlift.airship.configbundler;

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

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

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

@Command(name = "add", description = "Add config for a component")
public class AddComponentCommand
implements Callable<Void>
Expand All @@ -19,13 +21,13 @@ public class AddComponentCommand
public Void call()
throws Exception
{
Preconditions.checkNotNull(component, "component is null");
checkNotNull(component, "component is null");

Git git = Git.open(new File("."));

Model model = new Model(git);

Preconditions.checkArgument(model.getBundle(component) == null, "Component already exists: %s", component);
checkArgument(model.getBundle(component) == null, "Component already exists: %s", component);

Bundle bundle = model.createBundle(component);
model.activateBundle(bundle);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.airlift.airship.configbundler;

import com.google.common.base.Preconditions;
import static com.google.common.base.Preconditions.checkNotNull;

class Bundle
{
Expand All @@ -10,9 +10,7 @@ class Bundle

public Bundle(String name, int version, boolean snapshot)
{
Preconditions.checkNotNull(name, "name is null");

this.name = name;
this.name = checkNotNull(name, "name is null");
this.version = version;
this.snapshot = snapshot;
}
Expand All @@ -29,19 +27,14 @@ public int getVersion()

public String getVersionString()
{
if (snapshot) {
return version + "-SNAPSHOT";
}

return Integer.toString(version);
return Integer.toString(version) + (snapshot ? "-SNAPSHOT" : "");
}

public boolean isSnapshot()
{
return snapshot;
}


@Override
public boolean equals(Object o)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ public static void main(String[] args)
{
initializeLogging(false);

Cli<Callable<Void>> cli = Cli.<Callable<Void>>builder("configgy")
Cli<Callable<Void>> cli = Cli.<Callable<Void>>builder("asconfig")
.withDefaultCommand(Help.class)
.withCommand(ReleaseCommand.class)
.withCommand(InitCommand.class)
.withCommand(AddComponentCommand.class)
.withCommand(SnapshotCommand.class)
.withCommand(InfoCommand.class)
.withCommand(Help.class)
.build();

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.io.InputSupplier;
import com.google.common.io.ByteSource;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
Expand All @@ -30,7 +30,6 @@ public static Ref getBranch(Repository repository, String name)
return repository.getRefDatabase().getRefs(Constants.R_HEADS).get(name);
}


public static RevCommit getCommit(Repository repository, Ref ref)
{
RevWalk revWalk = new RevWalk(repository);
Expand All @@ -45,22 +44,21 @@ public static RevCommit getCommit(Repository repository, Ref ref)
}
}

public static InputSupplier<InputStream> getBlob(final Repository repository, final ObjectId objectId)
public static ByteSource getBlob(final Repository repository, final ObjectId objectId)
{
Preconditions.checkArgument(repository.hasObject(objectId), "object id '%s' not found in git repository", objectId.getName());

return new InputSupplier<InputStream>()
return new ByteSource()
{
@Override
public InputStream getInput()
public InputStream openStream()
throws IOException
{
return repository.open(objectId).openStream();
}
};
}


public static Map<String, ObjectId> getEntries(Repository repository, RevTree tree)
throws IOException
{
Expand Down Expand Up @@ -94,11 +92,11 @@ public static ObjectId findFileObject(Repository repository, RevCommit commit, S
return null;
}

public static Function<? super ObjectId, InputSupplier<InputStream>> inputStreamSupplierFunction(final Repository repository)
public static Function<? super ObjectId, ByteSource> byteSourceFunction(final Repository repository)
{
return new Function<ObjectId, InputSupplier<InputStream>>()
return new Function<ObjectId, ByteSource>()
{
public InputSupplier<InputStream> apply(ObjectId input)
public ByteSource apply(ObjectId input)
{
return getBlob(repository, input);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.io.IOException;

class IgnoreHiddenFilter
extends TreeFilter
extends TreeFilter
{
@Override
public boolean include(TreeWalk walker)
Expand All @@ -26,5 +26,4 @@ public TreeFilter clone()
{
return this;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package io.airlift.airship.configbundler;

import io.airlift.airline.Arguments;
import io.airlift.airline.Command;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.RepositoryBuilder;
import org.eclipse.jgit.util.FS;

import java.util.concurrent.Callable;

import static com.google.common.base.Preconditions.checkNotNull;

@Command(name = "info", description = "Show metadata ")
public class InfoCommand
implements Callable<Void>
{
@Arguments
public String component;

@Override
public Void call()
throws Exception
{
Model model = new Model(Git.wrap(new RepositoryBuilder().findGitDir().setFS(FS.DETECTED).build()));
Metadata metadata = model.readMetadata();

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

System.out.printf("Metadata Group Id: %s%n", metadata.getGroupId());

if (metadata.getReleasesRepository() == null) {
System.out.println("No releases repository configured, only local install possible.");
}
else {
System.out.printf("Release Repository Id: %s%n", metadata.getReleasesRepository().getId());
System.out.printf("Release Repository URL: %s%n", metadata.getReleasesRepository().getUri());
}

if (metadata.getSnapshotsRepository() == null) {
System.out.println("No snapshots repository configured, only local install possible.");
}
else {
System.out.printf("Snapshot Repository Id: %s%n", metadata.getSnapshotsRepository().getId());
System.out.printf("Snapshot Repository URL: %s%n", metadata.getSnapshotsRepository().getUri());
}

if (model.isDirty()) {
System.out.println("Local repository is modified.");
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.airlift.airship.configbundler;

import com.google.common.base.Preconditions;
import io.airlift.airline.Command;
import io.airlift.airline.Option;
import org.eclipse.jgit.api.Git;
Expand All @@ -9,6 +8,8 @@
import java.io.File;
import java.util.concurrent.Callable;

import static com.google.common.base.Preconditions.checkState;

@Command(name = "init", description = "Initialize a git config repository")
public class InitCommand
implements Callable<Void>
Expand Down Expand Up @@ -46,13 +47,33 @@ public Void call()
exists = false;
}

Preconditions.checkState(!exists, "A git repository already exists in the current directory");
checkState(!exists, "A git repository already exists in the current directory");

Model model = new Model(Git.init().call());

if (releasesRepositoryId != null) {
checkState(releasesRepositoryUri != null, "releaseRepositoryId requires releaseRepositoryUri!");

// If the same id is given for release repository and snapshot repository, then the snapshot uri can
// be empty (in that case, the release repository uri is used).
if (releasesRepositoryId.equals(snapshotsRepositoryId) && snapshotsRepositoryUri == null) {
snapshotsRepositoryUri = releasesRepositoryUri;
}
}
else {
System.out.println("No release repository id given! Releases can only be used locally!");
}

if (snapshotsRepositoryId != null) {
checkState(snapshotsRepositoryId != null, "snapshotsRepositoryId requires snapshotsRepositoryUri!");
}
else {
System.out.println("No snapshot repository id given! Snapshots can only be used locally!");
}

Metadata metadata = new Metadata(groupId,
new Metadata.Repository(snapshotsRepositoryId, snapshotsRepositoryUri),
new Metadata.Repository(releasesRepositoryId, releasesRepositoryUri));
Metadata.Repository.getRepository(snapshotsRepositoryId, snapshotsRepositoryUri),
Metadata.Repository.getRepository(releasesRepositoryId, releasesRepositoryUri));

model.initialize(metadata);
model.checkoutTemplateBranch();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package io.airlift.airship.configbundler;

import com.google.common.base.Preconditions;
import static com.google.common.base.Preconditions.checkState;

import com.google.common.collect.ImmutableList;
import com.google.common.io.ByteSource;

import org.apache.maven.repository.internal.DefaultArtifactDescriptorReader;
import org.apache.maven.repository.internal.DefaultVersionRangeResolver;
import org.apache.maven.repository.internal.DefaultVersionResolver;
Expand Down Expand Up @@ -39,6 +42,8 @@
import java.io.File;
import java.io.FileOutputStream;

import static com.google.common.base.Preconditions.checkNotNull;

class Maven
{
private static final String USER_DIR = System.getProperty("user.dir", "");
Expand All @@ -60,7 +65,7 @@ public Maven(@Nullable Metadata.Repository snapshotsRepositoryInfo,
{
validateRepositoryMetadata(snapshotsRepositoryInfo, "snapshots");
validateRepositoryMetadata(releasesRepositoryInfo, "releases");

final SettingsBuildingRequest request = new DefaultSettingsBuildingRequest()
.setGlobalSettingsFile(DEFAULT_GLOBAL_SETTINGS_FILE)
.setUserSettingsFile(DEFAULT_USER_SETTINGS_FILE)
Expand Down Expand Up @@ -88,32 +93,42 @@ public Maven(@Nullable Metadata.Repository snapshotsRepositoryInfo,
session = new MavenRepositorySystemSession()
.setLocalRepositoryManager(repositorySystem.newLocalRepositoryManager(new LocalRepository(localRepository)));

releasesRepository = makeRemoteRepository(releasesRepositoryInfo, settings.getServer(releasesRepositoryInfo.getId()), false);
snapshotsRepository = makeRemoteRepository(snapshotsRepositoryInfo, settings.getServer(snapshotsRepositoryInfo.getId()), true);
releasesRepository = makeRemoteRepository(releasesRepositoryInfo, settings, false);
snapshotsRepository = makeRemoteRepository(snapshotsRepositoryInfo, settings, true);
}

private static void validateRepositoryMetadata(Metadata.Repository info, String name)
private static void validateRepositoryMetadata(@Nullable Metadata.Repository info, String name)
{
Preconditions.checkNotNull(info.getId(), "%s repository id is null", name);
Preconditions.checkNotNull(info.getUri(), "%s repository uri is null", name);
if (info != null) {
checkNotNull(info.getId(), "%s repository id is null", name);
checkNotNull(info.getUri(), "%s repository uri is null", name);
}
}
private static RemoteRepository makeRemoteRepository(Metadata.Repository info, Server server, boolean snapshot)

private static RemoteRepository makeRemoteRepository(@Nullable Metadata.Repository info, Settings settings, boolean snapshot)
{
if (info == null) {
return null;
}

Server server = settings.getServer(info.getId());

checkState(server != null, "Could not locate Server for repository %s! (missing maven settings.xml file?)", info.getId());

return new RemoteRepository(info.getId(), "default", info.getUri())
.setPolicy(true, new RepositoryPolicy(snapshot, RepositoryPolicy.UPDATE_POLICY_ALWAYS, RepositoryPolicy.CHECKSUM_POLICY_FAIL))
.setPolicy(false, new RepositoryPolicy(!snapshot, RepositoryPolicy.UPDATE_POLICY_ALWAYS, RepositoryPolicy.CHECKSUM_POLICY_FAIL))
.setAuthentication(new Authentication(server.getUsername(), server.getPassword()));
}

public void upload(String groupId, String artifactId, String version, String extension, Generator writer)
public boolean upload(String groupId, String artifactId, String version, String extension, ByteSource source)
throws Exception
{
File file = File.createTempFile(String.format("%s-%s-%s", groupId, artifactId, version), "." + extension);
try {
FileOutputStream out = new FileOutputStream(file);
try {
writer.write(out);
source.copyTo(out);
}
finally {
out.close();
Expand All @@ -124,19 +139,21 @@ public void upload(String groupId, String artifactId, String version, String ext
// Install the artifact locally
repositorySystem.install(session, new InstallRequest().addArtifact(artifact));

// Deploy the artifact remotely
DeployRequest deployRequest = new DeployRequest()
.addArtifact(artifact);
// Deploy the artifact remotely if a repository is configured.

if (artifact.isSnapshot()) {
Preconditions.checkNotNull(snapshotsRepository, "snapshots repository uri is null");
deployRequest.setRepository(snapshotsRepository);
RemoteRepository repository = artifact.isSnapshot() ? snapshotsRepository : releasesRepository;

if (repository != null) {
DeployRequest deployRequest = new DeployRequest()
.addArtifact(artifact)
.setRepository(repository);

repositorySystem.deploy(session, deployRequest);
return true; // Uploaded successfully.
}
else {
Preconditions.checkNotNull(releasesRepository, "releases repository uri is null");
deployRequest.setRepository(releasesRepository);
return false; // Only installed, not uploaded.
}
repositorySystem.deploy(session, deployRequest);
}
finally {
file.delete();
Expand All @@ -156,5 +173,4 @@ public boolean contains(String groupId, String artifactId, String version, Strin

return true;
}

}
Loading