Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ charset=utf-8
indent_style=space

[*.java]
indent_size = 4
indent_size = 2
5 changes: 4 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ http_archive(
)

load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")

rules_jvm_external_deps()

load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")

rules_jvm_external_setup()

load("@rules_jvm_external//:defs.bzl", "maven_install")
Expand All @@ -25,6 +27,7 @@ maven_install(
"com.fasterxml.jackson.core:jackson-core:2.18.2",
"com.fasterxml.jackson.core:jackson-databind:2.18.2",
"com.google.guava:guava:33.3.1-jre",
"org.apache.commons:commons-compress:1.27.1",
"org.apache.httpcomponents:httpclient:4.5.14",
# This is the last release that produce Java 8 class files.
"org.eclipse.jgit:org.eclipse.jgit:5.13.3.202401111512-r",
Expand All @@ -45,10 +48,10 @@ maven_install(
version = "1.4.4",
),
],
fetch_sources = True,
maven_install_json = "//src:maven_install.json",
repositories = ["https://repo1.maven.org/maven2"],
version_conflict_policy = "pinned",
fetch_sources = True,
)

load("@maven//:defs.bzl", "pinned_maven_install")
Expand Down
8 changes: 6 additions & 2 deletions launchable/commands/record/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ def commit(ctx, source: str, executable: bool, max_days: int, scrub_pii: bool, i

# Commit messages are not collected in the default.
is_collect_message = False
is_collect_files = False
try:
res = client.request("get", "commits/collect/options")
res.raise_for_status()
is_collect_message = res.json().get("commitMessage", False)
is_collect_files = res.json().get("files", False)
except Exception as e:
tracking_client.send_error_event(
event_name=Tracking.ErrorEvent.INTERNAL_CLI_ERROR,
Expand All @@ -79,7 +81,7 @@ def commit(ctx, source: str, executable: bool, max_days: int, scrub_pii: bool, i

cwd = os.path.abspath(source)
try:
exec_jar(cwd, max_days, ctx.obj, is_collect_message)
exec_jar(cwd, max_days, ctx.obj, is_collect_message, is_collect_files)
except Exception as e:
if os.getenv(REPORT_ERROR_KEY):
raise e
Expand All @@ -89,7 +91,7 @@ def commit(ctx, source: str, executable: bool, max_days: int, scrub_pii: bool, i
"If not, please set a directory use by --source option.\nerror: {}".format(cwd, e))


def exec_jar(source: str, max_days: int, app: Application, is_collect_message: bool):
def exec_jar(source: str, max_days: int, app: Application, is_collect_message: bool, is_collect_files: bool):
java = get_java_command()

if not java:
Expand Down Expand Up @@ -120,6 +122,8 @@ def exec_jar(source: str, max_days: int, app: Application, is_collect_message: b
command.append("-skip-cert-verification")
if is_collect_message:
command.append("-commit-message")
if is_collect_files:
command.append("-files")
if os.getenv(COMMIT_TIMEOUT):
command.append("-enable-timeout")
command.append(cygpath(source))
Expand Down
Binary file modified launchable/jar/exe_deploy.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion src/main/java/com/launchableinc/ingest/commits/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package(
default_visibility = ["//visibility:public"]
default_visibility = ["//visibility:public"],
)

java_library(
Expand All @@ -11,6 +11,7 @@ java_library(
"@maven//:com_fasterxml_jackson_core_jackson_core",
"@maven//:com_fasterxml_jackson_core_jackson_databind",
"@maven//:com_google_guava_guava",
"@maven//:org_apache_commons_commons_compress",
"@maven//:org_apache_httpcomponents_httpclient",
"@maven//:org_apache_httpcomponents_httpcore",
"@maven//:org_eclipse_jgit_org_eclipse_jgit",
Expand Down
59 changes: 59 additions & 0 deletions src/main/java/com/launchableinc/ingest/commits/ChunkStreamer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.launchableinc.ingest.commits;

import org.apache.http.entity.ContentProducer;

import java.io.Closeable;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

/**
* Accepts T, buffers them, and writes them out as a batch.
*/
abstract class ChunkStreamer<T> implements Consumer<T>, Closeable {
/**
* Encapsulation of how batches are sent.
*/
private final IOConsumer<ContentProducer> sender;
private final int chunkSize;
private final List<T> spool = new ArrayList<>();

ChunkStreamer(IOConsumer<ContentProducer> sender, int chunkSize) {
this.sender = sender;
this.chunkSize = chunkSize;
}

@Override
public void accept(T f) {
spool.add(f);
if (spool.size() >= chunkSize) {
try {
flush();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}

@Override
public void close() throws IOException {
flush();
}

private void flush() throws IOException {
if (spool.isEmpty()) {
return;
}

try {
sender.accept(os -> writeTo(spool,os));
} finally {
spool.clear();
}
}

protected abstract void writeTo(List<T> spool, OutputStream os) throws IOException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.launchableinc.ingest.commits;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import org.apache.http.entity.ContentProducer;
import org.eclipse.jgit.revwalk.RevCommit;

import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.function.Consumer;

/**
* {@link Consumer} that groups commits into chunks and write them as JSON, using streams supplied
* by the factory.
*/
final class CommitChunkStreamer extends ChunkStreamer<JSCommit> {
CommitChunkStreamer(IOConsumer<ContentProducer> sender, int chunkSize) {
super(sender, chunkSize);
}

@Override
protected void writeTo(List<JSCommit> spool, OutputStream os) throws IOException {
JsonGenerator w = new JsonFactory().createGenerator(os).useDefaultPrettyPrinter();
w.setCodec(CommitGraphCollector.objectMapper);
w.writeStartObject();
w.writeArrayFieldStart("commits");

for (JSCommit commit : spool) {
w.writeObject(commit);
}

w.writeEndArray();
w.writeEndObject();
w.close();
}
}
Loading
Loading