Search in sources :

Example 31 with ManipulationException

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());
    }
}
Also used : ManipulationException(org.commonjava.maven.ext.common.ManipulationException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter) SettingsXpp3Writer(org.apache.maven.settings.io.xpp3.SettingsXpp3Writer)

Example 32 with ManipulationException

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);
    }
}
Also used : JsonPathException(com.jayway.jsonpath.JsonPathException) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) DocumentContext(com.jayway.jsonpath.DocumentContext) Test(org.junit.Test)

Example 33 with ManipulationException

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");
}
Also used : DefaultExecutionParser(org.commonjava.maven.ext.integrationtest.invoker.DefaultExecutionParser) Execution(org.commonjava.maven.ext.integrationtest.invoker.Execution) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) DefaultExecutionParser(org.commonjava.maven.ext.integrationtest.invoker.DefaultExecutionParser) ExecutionParser(org.commonjava.maven.ext.integrationtest.invoker.ExecutionParser)

Example 34 with ManipulationException

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;
}
Also used : ManipulationException(org.commonjava.maven.ext.common.ManipulationException) JsonPathException(com.jayway.jsonpath.JsonPathException) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) YamlFile(org.commonjava.maven.ext.common.model.YamlFile) Map(java.util.Map)

Example 35 with ManipulationException

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;
}
Also used : Representer(org.yaml.snakeyaml.representer.Representer) FileNotFoundException(java.io.FileNotFoundException) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) YamlFile(org.commonjava.maven.ext.common.model.YamlFile) Properties(java.util.Properties) Yaml(org.yaml.snakeyaml.Yaml) FileInputStream(java.io.FileInputStream)

Aggregations

ManipulationException (org.commonjava.maven.ext.common.ManipulationException)42 IOException (java.io.IOException)13 File (java.io.File)11 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 LinkedHashMap (java.util.LinkedHashMap)7 Project (org.commonjava.maven.ext.common.model.Project)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 ArtifactRef (org.commonjava.maven.atlas.ident.ref.ArtifactRef)6 Properties (java.util.Properties)5 SimpleArtifactRef (org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef)5 JsonPathException (com.jayway.jsonpath.JsonPathException)4 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)4 SimpleProjectRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectRef)4 CommonState (org.commonjava.maven.ext.core.state.CommonState)4 Test (org.junit.Test)4 DocumentContext (com.jayway.jsonpath.DocumentContext)3 FileInputStream (java.io.FileInputStream)3 Dependency (org.apache.maven.model.Dependency)3