/** * 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); }
@Override public File locatePom(File projectDirectory) { try { File pomFile = new DefaultModelLocator().locatePom(projectDirectory); if (stamper.isEnabled()) { logger.info("[FreezeModelLocator]: Freeze pom in folder " + projectDirectory.getAbsolutePath()); artifactFreezeMapping.put(pomFile); logger.debug("[FreezeModelLocator]: Freezing pom " + pomFile.getAbsolutePath()); return pomFreezer.freeze(pomFile); } else { return pomFile; } } catch (RuntimeException e) { throw new FreezeException("Unable to locate " + (stamper.isEnabled() ? " frozen " : "") + "pom in directory [" + projectDirectory + "] ...", e); } }
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); } }
protected ModelLocator newModelLocator() { return new DefaultModelLocator(); }