/** * Given a local path to a Maven project, this attempts to find the transitive dependencies of the * project. * * @param projectPath The path to search for Maven projects. * @param scopes The scopes to look up dependencies in. */ public String resolvePomDependencies(String projectPath, Set<String> scopes) { DefaultModelProcessor processor = new DefaultModelProcessor(); processor.setModelLocator(new DefaultModelLocator()); processor.setModelReader(new DefaultModelReader()); File pom = processor.locatePom(new File(projectPath)); FileModelSource pomSource = new FileModelSource(pom); // First resolve the model source locations. resolveSourceLocations(pomSource); // Next, fully resolve the models. Model model = modelResolver.getEffectiveModel(pomSource); if (model != null) { traverseDeps(model, scopes, Sets.newHashSet(), null); } return pom.getAbsolutePath(); }
@Override protected void configure() { bind(ModelLocator.class).to(DefaultModelLocator.class).in(Singleton.class); bind(ModelReader.class).to(DefaultModelReader.class).in(Singleton.class); bind(ModelValidator.class).to(DefaultModelValidator.class).in(Singleton.class); bind(RepositoryConnectorFactory.class).to(BasicRepositoryConnectorFactory.class) .in(Singleton.class); bind(ArtifactDescriptorReader.class) // .to(DefaultArtifactDescriptorReader.class).in(Singleton.class); bind(VersionResolver.class) // .to(DefaultVersionResolver.class).in(Singleton.class); bind(VersionRangeResolver.class) // .to(DefaultVersionRangeResolver.class).in(Singleton.class); bind(MetadataGeneratorFactory.class).annotatedWith(Names.named("snapshot")) // .to(SnapshotMetadataGeneratorFactory.class).in(Singleton.class); bind(MetadataGeneratorFactory.class).annotatedWith(Names.named("versions")) // .to(VersionsMetadataGeneratorFactory.class).in(Singleton.class); bind(TransporterFactory.class).annotatedWith(Names.named("http")) .to(HttpTransporterFactory.class).in(Singleton.class); bind(TransporterFactory.class).annotatedWith(Names.named("file")) .to(FileTransporterFactory.class).in(Singleton.class); }
private static Model readModel() { DefaultModelProcessor modelProcessor = new DefaultModelProcessor(); modelProcessor.setModelLocator(new DefaultModelLocator()); modelProcessor.setModelReader(new DefaultModelReader()); try { return modelProcessor.read(SpringBootDependenciesDependencyManagement.class .getResourceAsStream("effective-pom.xml"), null); } catch (IOException ex) { throw new IllegalStateException("Failed to build model from effective pom", ex); } }
@Before public void setup() throws Exception { try (final InputStream in = getClass().getResourceAsStream("/version-transfer/" + getFileName())) { copyInputStreamToFile(in, originalPom); } originalPom.deleteOnExit(); originalLines = readLines(originalPom); final DefaultModelReader reader = new DefaultModelReader(); updatedModel = reader.read(originalPom, Collections.<String, Object> emptyMap()); updatedModel.getParent().setVersion(EXPECTED_VERSIONS[0]); updatedModel.setVersion(EXPECTED_VERSIONS[1]); updatedModel.getDependencyManagement().getDependencies().get(0).setVersion(EXPECTED_VERSIONS[2]); updatedModel.getDependencyManagement().getDependencies().get(1).setVersion(EXPECTED_VERSIONS[3]); updatedModel.getDependencies().get(0).setVersion(EXPECTED_VERSIONS[4]); updatedModel.getDependencies().get(1).setVersion(EXPECTED_VERSIONS[5]); updatedModel.getDependencies().get(2).setVersion(EXPECTED_VERSIONS[6]); writer = new VersionTransferWriter(originalPom, getOwnVersionOrNull()); try { mavenXpp3Writer.write(writer, updatedModel); } finally { writer.close(); } updatedLines = readLines(originalPom); }
private static Model getModel() { ModelReader modelReader = new DefaultModelReader(); try { return modelReader.read(new File("pom.xml"), null); } catch (IOException cause) { throw new RuntimeException(cause); } }
public ChangeManager ( final Log log ) { this.log = log; this.writer = new DefaultModelWriter (); this.reader = new DefaultModelReader (); }
protected ModelReader newModelReader() { return new DefaultModelReader(); }