zed.deployer.handlers.FatJarMavenDeployableHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zed-deployer Show documentation
Show all versions of zed-deployer Show documentation
A application used as an example on how to set up pushing
its components to the Central Repository.
The newest version!
package zed.deployer.handlers;
import org.apache.commons.io.IOUtils;
import zed.deployer.manager.DeployableDescriptor;
import zed.deployer.util.FatJarUriUtil;
import zed.mavenrepo.JcabiMavenArtifactResolver;
import zed.mavenrepo.MavenArtifactResolver;
import zed.ssh.client.SshClient;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class FatJarMavenDeployableHandler implements DeployableHandler {
private final static String URI_PREFIX = "fatjar:mvn:";
private final File workspace;
private final MavenArtifactResolver mavenArtifactResolver;
public FatJarMavenDeployableHandler(File workspace, MavenArtifactResolver mavenArtifactResolver) {
this.workspace = workspace;
this.mavenArtifactResolver = mavenArtifactResolver;
}
public FatJarMavenDeployableHandler(File workspace) {
this(workspace, new JcabiMavenArtifactResolver());
}
@Override
public boolean supports(String uri) {
return uri.startsWith(URI_PREFIX);
}
@Override
public DeployableDescriptor deploy(DeployableDescriptor deployableDescriptor) {
try {
String mavenCoordinatesUri = deployableDescriptor.uri().substring(URI_PREFIX.length());
String[] mavenCoordinates = mavenCoordinatesUri.split("\\?")[0].split("/");
if (mavenCoordinates.length < 3) {
throw new IllegalArgumentException(mavenCoordinatesUri + " is not a valid Maven artifact URI. Proper URI format is fatjar:mvn:groupId/artifactId/version/[type] .");
}
String artifactType = mavenCoordinates.length == 4 ? mavenCoordinates[3] : "jar";
InputStream artifactData = mavenArtifactResolver.artifactStream(mavenCoordinates[0].replaceAll("\\.", "/"), mavenCoordinates[1].replaceAll("\\.", "/"), mavenCoordinates[2], artifactType);
File deployDirectory = new File(workspace, mavenCoordinates[1] + "-" + mavenCoordinates[2] + "." + artifactType);
if (FatJarUriUtil.isSshUri(mavenCoordinatesUri)) {
SshClient sshClient;
Integer port = FatJarUriUtil.sshPort(mavenCoordinatesUri);
if (port != null) {
sshClient = new SshClient(FatJarUriUtil.sshHost(mavenCoordinatesUri),
port,
FatJarUriUtil.sshUser(mavenCoordinatesUri),
FatJarUriUtil.sshPassword(mavenCoordinatesUri));
} else {
sshClient = new SshClient(FatJarUriUtil.sshHost(mavenCoordinatesUri),
FatJarUriUtil.sshUser(mavenCoordinatesUri),
FatJarUriUtil.sshPassword(mavenCoordinatesUri));
}
sshClient.scp(artifactData, deployDirectory);
} else {
IOUtils.copy(artifactData, new FileOutputStream(deployDirectory));
}
return deployableDescriptor;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy