@Test public void updateURL () throws ManipulationException, IOException { String modifyPath = "$.repository.url"; File target = tf.newFile(); FileUtils.copyFile( pluginFile, target ); Project project = new Project( target, TestUtils.getDummyModel() ); jsonManipulator.internalApplyChanges( project, new JSONState.JSONOperation( target.getName(), modifyPath, "https: assertTrue( FileUtils.readFileToString( target, StandardCharsets.UTF_8 ).contains( "https: assertFalse( FileUtils.contentEquals( pluginFile, target ) ); }
void internalApplyChanges( Project project, JSONState.JSONOperation operation ) throws ManipulationException { File target = new File( project.getPom().getParentFile(), operation.getFile() ); logger.info( "Attempting to start JSON update to file {} with xpath {} and replacement '{}' ", target, operation.getXPath(), operation.getUpdate() ); DocumentContext dc = null; try { if ( !target.exists() ) { logger.error( "Unable to locate JSON file {} ", target ); throw new ManipulationException( "Unable to locate JSON file {}", target ); } dc = jsonIO.parseJSON( target ); List<?> o = dc.read( operation.getXPath() ); if ( o.size() == 0 ) { if ( project.isIncrementalPME() ) { logger.warn ("Did not locate JSON using XPath " + operation.getXPath() ); return; } else { logger.error( "XPath {} did not find any expressions within {} ", operation.getXPath(), operation.getFile() ); throw new ManipulationException( "XPath did not resolve to a valid value" ); } } if ( isEmpty( operation.getUpdate() ) ) { logger.info( "Deleting {} on {}", operation.getXPath(), dc ); dc.delete( operation.getXPath() ); } else { logger.info( "Updating {} on {}", operation.getXPath(), dc ); dc.set( operation.getXPath(), operation.getUpdate() ); } jsonIO.writeJSON( target, dc ); } catch ( JsonPathException e ) { logger.error( "Caught JSON exception processing file {}, document context {} ", target, dc, e ); throw new ManipulationException( "Caught JsonPath", e ); } }
JSONManipulator implements Manipulator { void internalApplyChanges( Project project, JSONState.JSONOperation operation ) throws ManipulationException { File target = new File( project.getPom().getParentFile(), operation.getFile() ); logger.info( "Attempting to start JSON update to file {} with xpath {} and replacement '{}' ", target, operation.getXPath(), operation.getUpdate() ); DocumentContext dc = null; try { if ( !target.exists() ) { logger.error( "Unable to locate JSON file {} ", target ); throw new ManipulationException( "Unable to locate JSON file {}", target ); } dc = jsonIO.parseJSON( target ); List<?> o = dc.read( operation.getXPath() ); if ( o.size() == 0 ) { if ( project.isIncrementalPME() ) { logger.warn ("Did not locate JSON using XPath " + operation.getXPath() ); return; } else { logger.error( "XPath {} did not find any expressions within {} ", operation.getXPath(), operation.getFile() ); throw new ManipulationException( "XPath did not resolve to a valid value" ); } } if ( isEmpty( operation.getUpdate() ) ) { logger.info( "Deleting {} on {}", operation.getXPath(), dc ); dc.delete( operation.getXPath() ); } else { logger.info( "Updating {} on {}", operation.getXPath(), dc ); dc.set( operation.getXPath(), operation.getUpdate() ); } jsonIO.writeJSON( target, dc ); } catch ( JsonPathException e ) { logger.error( "Caught JSON exception processing file {}, document context {} ", target, dc, e ); throw new ManipulationException( "Caught JsonPath", e ); } } }
JSONManipulator implements Manipulator { void internalApplyChanges( Project project, JSONState.JSONOperation operation ) throws ManipulationException { File target = new File( project.getPom().getParentFile(), operation.getFile() ); logger.info( "Attempting to start JSON update to file {} with xpath {} and replacement '{}' ", target, operation.getXPath(), operation.getUpdate() ); DocumentContext dc = null; try { if ( !target.exists() ) { logger.error( "Unable to locate JSON file {} ", target ); throw new ManipulationException( "Unable to locate JSON file {}", target ); } dc = jsonIO.parseJSON( target ); List<?> o = dc.read( operation.getXPath() ); if ( o.size() == 0 ) { if ( project.isIncrementalPME() ) { logger.warn ("Did not locate JSON using XPath " + operation.getXPath() ); return; } else { logger.error( "XPath {} did not find any expressions within {} ", operation.getXPath(), operation.getFile() ); throw new ManipulationException( "XPath did not resolve to a valid value" ); } } if ( isEmpty( operation.getUpdate() ) ) { logger.info( "Deleting {} on {}", operation.getXPath(), dc ); dc.delete( operation.getXPath() ); } else { logger.info( "Updating {} on {}", operation.getXPath(), dc ); dc.set( operation.getXPath(), operation.getUpdate() ); } jsonIO.writeJSON( target, dc ); } catch ( JsonPathException e ) { logger.error( "Caught JSON exception processing file {}, document context {} ", target, dc, e ); throw new ManipulationException( "Caught JsonPath", e ); } } @Inject  JSONManipulator(JSONIO jsonIO); }
JSONManipulator implements Manipulator { void internalApplyChanges( Project project, JSONState.JSONOperation operation ) throws ManipulationException { File target = new File( project.getPom().getParentFile(), operation.getFile() ); logger.info( "Attempting to start JSON update to file {} with xpath {} and replacement '{}' ", target, operation.getXPath(), operation.getUpdate() ); DocumentContext dc = null; try { if ( !target.exists() ) { logger.error( "Unable to locate JSON file {} ", target ); throw new ManipulationException( "Unable to locate JSON file {}", target ); } dc = jsonIO.parseJSON( target ); List<?> o = dc.read( operation.getXPath() ); if ( o.size() == 0 ) { if ( project.isIncrementalPME() ) { logger.warn ("Did not locate JSON using XPath " + operation.getXPath() ); return; } else { logger.error( "XPath {} did not find any expressions within {} ", operation.getXPath(), operation.getFile() ); throw new ManipulationException( "XPath did not resolve to a valid value" ); } } if ( isEmpty( operation.getUpdate() ) ) { logger.info( "Deleting {} on {}", operation.getXPath(), dc ); dc.delete( operation.getXPath() ); } else { logger.info( "Updating {} on {}", operation.getXPath(), dc ); dc.set( operation.getXPath(), operation.getUpdate() ); } jsonIO.writeJSON( target, dc ); } catch ( JsonPathException e ) { logger.error( "Caught JSON exception processing file {}, document context {} ", target, dc, e ); throw new ManipulationException( "Caught JsonPath", e ); } } @Inject  JSONManipulator(JSONIO jsonIO); @Override void init( final ManipulationSession session ); @Override Set<Project> applyChanges( final List<Project> projects ); @Override int getExecutionIndex(); }
JSONManipulator implements Manipulator { void internalApplyChanges( Project project, JSONState.JSONOperation operation ) throws ManipulationException { File target = new File( project.getPom().getParentFile(), operation.getFile() ); logger.info( "Attempting to start JSON update to file {} with xpath {} and replacement '{}' ", target, operation.getXPath(), operation.getUpdate() ); DocumentContext dc = null; try { if ( !target.exists() ) { logger.error( "Unable to locate JSON file {} ", target ); throw new ManipulationException( "Unable to locate JSON file {}", target ); } dc = jsonIO.parseJSON( target ); List<?> o = dc.read( operation.getXPath() ); if ( o.size() == 0 ) { if ( project.isIncrementalPME() ) { logger.warn ("Did not locate JSON using XPath " + operation.getXPath() ); return; } else { logger.error( "XPath {} did not find any expressions within {} ", operation.getXPath(), operation.getFile() ); throw new ManipulationException( "XPath did not resolve to a valid value" ); } } if ( isEmpty( operation.getUpdate() ) ) { logger.info( "Deleting {} on {}", operation.getXPath(), dc ); dc.delete( operation.getXPath() ); } else { logger.info( "Updating {} on {}", operation.getXPath(), dc ); dc.set( operation.getXPath(), operation.getUpdate() ); } jsonIO.writeJSON( target, dc ); } catch ( JsonPathException e ) { logger.error( "Caught JSON exception processing file {}, document context {} ", target, dc, e ); throw new ManipulationException( "Caught JsonPath", e ); } } @Inject  JSONManipulator(JSONIO jsonIO); @Override void init( final ManipulationSession session ); @Override Set<Project> applyChanges( final List<Project> projects ); @Override int getExecutionIndex();  }