use of org.commonjava.maven.ext.common.ManipulationException in project pom-manipulation-ext by release-engineering.
the class SettingsIO method write.
public void write(Settings settings, File settingsFile) throws ManipulationException {
try {
PrintWriter printWriter = new PrintWriter(settingsFile, "UTF-8");
new SettingsXpp3Writer().write(printWriter, settings);
} catch (IOException e) {
throw new ManipulationException("Failed to create repo removal backup settings.xml file.", e, settingsFile, e.getMessage());
}
}
use of org.commonjava.maven.ext.common.ManipulationException in project pom-manipulation-ext by release-engineering.
the class JSONIOTest method updateWithInvalidPath.
@Test(expected = ManipulationException.class)
public void updateWithInvalidPath() throws ManipulationException, IOException {
String modifyPath = "$.I.really.do.not.exist.repository.url";
try {
DocumentContext doc = jsonIO.parseJSON(pluginFile);
doc.set(modifyPath, "https://maven.repository.redhat.com/ga/");
} catch (JsonPathException e) {
throw new ManipulationException("Caught JsonPath", e);
}
}
use of org.commonjava.maven.ext.common.ManipulationException in project pom-manipulation-ext by release-engineering.
the class TestUtils method runLikeInvoker.
/**
* Run the same/similar execution to what invoker plugin would run.
*
* @param workingDir - Working directory where the invoker properties are.
* @param url The URL to either the REST server that manages versions, or HTTP server for static Groovy scripts or null
* @throws Exception if an error occurs
*/
public static void runLikeInvoker(String workingDir, String url) throws Exception {
ExecutionParser executionParser = new DefaultExecutionParser(DefaultExecutionParser.DEFAULT_HANDLERS);
Collection<Execution> executions = executionParser.parse(workingDir);
// Execute
for (Execution e : executions) {
// Setup
runScript(workingDir, "setup");
if (url != null) {
logger.info("Resetting URL to: {}", url);
if (url.matches(".*[0-9]+$")) {
e.getJavaParams().put("restURL", url);
} else {
e.getJavaParams().put("groovyScripts", url);
}
}
List<String> args = new ArrayList<>();
args.add("-s");
args.add(getDefaultTestLocation("settings.xml"));
args.add("-d");
args.add(toFlagsParams(e.getFlags()));
// Run PME-Cli
Integer cliExitValue = runCli(args, e.getJavaParams(), e.getLocation());
logger.info("Returned {} from running {} ", cliExitValue, args);
// Run Maven
Map<String, String> mavenParams = new HashMap<>();
mavenParams.putAll(DEFAULT_MVN_PARAMS);
mavenParams.putAll(e.getJavaParams());
Integer mavenExitValue = runMaven(e.getMvnCommand(), mavenParams, e.getLocation());
// Test return codes
if (e.isSuccess()) {
if (cliExitValue != 0) {
throw new ManipulationException("PME-Cli (running in: " + workingDir + ") exited with a non zero value : " + cliExitValue);
}
if (mavenExitValue != 0) {
throw new ManipulationException("Maven (running in: " + workingDir + ") exited with a non zero value." + mavenExitValue);
}
} else {
if (cliExitValue == 0 && mavenExitValue == 0) {
throw new ManipulationException("Exit value of either PME-Cli (" + cliExitValue + ") or Maven (" + mavenExitValue + ") (running in: " + workingDir + ") must be non-zero.");
}
}
}
// Verify
runScript(workingDir, "verify");
}
use of org.commonjava.maven.ext.common.ManipulationException in project pom-manipulation-ext by release-engineering.
the class ConfigIO method parse.
public Properties parse(final File workingDir) throws ManipulationException {
Properties result = new Properties();
File propertyFile = new File(workingDir, propertyFileString);
File yamlPMEFile = new File(workingDir, yamlPMEFileString);
File yamlPNCFile = new File(workingDir, yamlPNCFileString);
File jsonPNCFile = new File(workingDir, jsonPNCFileString);
if (propertyFile.exists() && (yamlPMEFile.exists() || yamlPNCFile.exists() || jsonPNCFile.exists())) {
throw new ManipulationException("Cannot have both yaml, json and property configuration files.");
} else if (yamlPMEFile.exists() && yamlPNCFile.exists()) {
throw new ManipulationException("Cannot have both yaml configuration file formats.");
} else if ((yamlPMEFile.exists() || yamlPNCFile.exists()) && jsonPNCFile.exists()) {
throw new ManipulationException("Cannot have yaml and json configuration file formats.");
}
if (yamlPMEFile.exists()) {
result = loadYamlFile(yamlPMEFile);
logger.debug("Read yaml file containing {}.", result);
} else if (yamlPNCFile.exists()) {
result = loadYamlFile(yamlPNCFile);
logger.debug("Read yaml file containing {}.", result);
} else if (jsonPNCFile.exists()) {
try {
result.putAll(JsonPath.parse(jsonPNCFile).read("$.pme", Map.class));
} catch (IOException | JsonPathException e) {
throw new ManipulationException("Caught exception processing JSON file.", e);
}
logger.debug("Read json file containing {}.", result);
} else if (propertyFile.exists()) {
result = loadPropertiesFile(propertyFile);
logger.debug("Read properties file containing {}.", result);
}
return result;
}
use of org.commonjava.maven.ext.common.ManipulationException in project pom-manipulation-ext by release-engineering.
the class ConfigIO method loadYamlFile.
private Properties loadYamlFile(final File configFile) throws ManipulationException {
Properties result = new Properties();
Representer representer = new Representer();
representer.getPropertyUtils().setSkipMissingProperties(true);
Yaml yaml = new Yaml(representer);
try {
YamlFile yf = yaml.loadAs(new FileInputStream(configFile), YamlFile.class);
result.putAll(yf.getPme());
} catch (FileNotFoundException e) {
throw new ManipulationException("Unable to load yaml file.", e);
}
return result;
}
Aggregations