com.outbrain.ci.friendly.flatten.maven.plugin.VersionProviderImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ci-friendly-flatten-maven-plugin Show documentation
Show all versions of ci-friendly-flatten-maven-plugin Show documentation
Plugin helps to use CI friendly versions in maven projects by simplifying the flatten-maven-plugin
The newest version!
package com.outbrain.ci.friendly.flatten.maven.plugin;
import org.apache.maven.plugin.MojoExecutionException;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@Named
@Singleton
public class VersionProviderImpl implements VersionProvider {
public String getVersion(String command) throws MojoExecutionException {
try {
StringBuilder builder = new StringBuilder();
Process process = Runtime.getRuntime().exec(command);
try (BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String line;
while ((line = input.readLine()) != null) {
builder.append(line);
}
}
process.waitFor();
// return the output
return builder.toString();
} catch (IOException | InterruptedException e) {
throw new MojoExecutionException("Execution of command '" + command
+ "' failed", e);
}
}
}