Skip to content

Commit

Permalink
Add method to deploy InputStream to target
Browse files Browse the repository at this point in the history
  • Loading branch information
ThadHouse committed Dec 11, 2023
1 parent c78ee74 commit 52e3a50
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.wpi.first.deployutils.deploy.context;

import java.io.File;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -119,4 +120,9 @@ public String friendlyString() {
public DeployContext subContext(String workingDir) {
return new DefaultDeployContext(session, logger.push(), deployLocation, PathUtils.combine(this.workingDir, workingDir));
}

@Override
public void put(InputStream source, String dest) {
session.put(source, dest);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.wpi.first.deployutils.deploy.context;

import java.io.File;
import java.io.InputStream;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -30,6 +31,9 @@ public interface DeployContext {
// Send multiple files, and trigger cache checking only once
void put(Set<File> files, CacheMethod cache);

// Put an input stream, with no caching
void put(InputStream source, String dest);

String friendlyString();

DeployContext subContext(String workingDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

import javax.inject.Inject;
Expand Down Expand Up @@ -47,4 +48,8 @@ public String getHost() {
public int getPort() {
return 22;
}

@Override
public void put(InputStream source, String dest) {
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.wpi.first.deployutils.deploy.sessions;

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

import edu.wpi.first.deployutils.deploy.CommandDeployResult;
Expand All @@ -12,5 +13,7 @@ public interface SessionController extends AutoCloseable {

void put(Map<String, File> files);

void put(InputStream source, String dest);

String friendlyString();
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,23 @@ public String getHost() {
public int getPort() {
return this.port;
}

@Override
public void put(InputStream source, String dest) {
int sem = acquire();

ChannelSftp sftp;
try {
sftp = (ChannelSftp) session.openChannel("sftp");
sftp.connect();
try {
sftp.put(source, dest);
} finally {
sftp.disconnect();
release(sem);
}
} catch (JSchException | SftpException e2) {
throw new RuntimeException(e2);
}
}
}

0 comments on commit 52e3a50

Please sign in to comment.