Search in sources :

Example 1 with JSONState

use of org.commonjava.maven.ext.core.state.JSONState in project pom-manipulation-ext by release-engineering.

the class JSONManipulator method applyChanges.

/**
 * Apply the json changes to the specified file(s).
 */
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
    final JSONState state = session.getState(JSONState.class);
    if (!session.isEnabled() || !state.isEnabled()) {
        logger.debug(getClass().getSimpleName() + ": Nothing to do!");
        return Collections.emptySet();
    }
    final Set<Project> changed = new HashSet<>();
    final List<JSONState.JSONOperation> scripts = state.getJSONOperations();
    for (final Project project : projects) {
        if (project.isExecutionRoot()) {
            for (JSONState.JSONOperation operation : scripts) {
                internalApplyChanges(project, operation);
                changed.add(project);
            }
            break;
        }
    }
    return changed;
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) JSONState(org.commonjava.maven.ext.core.state.JSONState) HashSet(java.util.HashSet)

Example 2 with JSONState

use of org.commonjava.maven.ext.core.state.JSONState in project pom-manipulation-ext by release-engineering.

the class JSONManipulator method init.

/**
 * Initialize the {@link JSONState} state holder in the {@link ManipulationSession}. This state holder detects
 * configuration from the Maven user properties (-D properties from the CLI) and makes it available for
 * later.
 */
@Override
public void init(final ManipulationSession session) throws ManipulationException {
    this.session = session;
    session.setState(new JSONState(session.getUserProperties()));
}
Also used : JSONState(org.commonjava.maven.ext.core.state.JSONState)

Example 3 with JSONState

use of org.commonjava.maven.ext.core.state.JSONState in project pom-manipulation-ext by release-engineering.

the class JSONManipulatorTest method testStateConstructionNoEscape.

@Test(expected = ManipulationException.class)
public void testStateConstructionNoEscape() throws ManipulationException {
    Properties p = new Properties();
    p.put("jsonUpdate", "amg-plugin-registry.json:$..plugins[0].description:CORS,and:controlling");
    new JSONState(p);
}
Also used : Properties(java.util.Properties) JSONState(org.commonjava.maven.ext.core.state.JSONState) Test(org.junit.Test) JSONIOTest(org.commonjava.maven.ext.io.JSONIOTest)

Example 4 with JSONState

use of org.commonjava.maven.ext.core.state.JSONState in project pom-manipulation-ext by release-engineering.

the class JSONManipulatorTest method testStateConstructionEscaping.

@Test
public void testStateConstructionEscaping() throws ManipulationException {
    Properties p = new Properties();
    p.put("jsonUpdate", "amg-plugin-registry.json:$xpath-with\\:and\\,:replace with space and \\,\\:controlling\\:access_to_resources_outside_of_an_originating_domain\\,and_to_this_domain.");
    JSONState js = new JSONState(p);
}
Also used : Properties(java.util.Properties) JSONState(org.commonjava.maven.ext.core.state.JSONState) Test(org.junit.Test) JSONIOTest(org.commonjava.maven.ext.io.JSONIOTest)

Aggregations

JSONState (org.commonjava.maven.ext.core.state.JSONState)4 Properties (java.util.Properties)2 JSONIOTest (org.commonjava.maven.ext.io.JSONIOTest)2 Test (org.junit.Test)2 HashSet (java.util.HashSet)1 Project (org.commonjava.maven.ext.common.model.Project)1