org.apache.maven.model.building.ModelBuilder Java Examples

The following examples show how to use org.apache.maven.model.building.ModelBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BootstrapMavenContext.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private RepositorySystem newRepositorySystem() throws BootstrapMavenException {
    final DefaultServiceLocator locator = getServiceLocator();
    if (!isOffline()) {
        locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
        locator.addService(TransporterFactory.class, WagonTransporterFactory.class);
        locator.setServices(WagonConfigurator.class, new BootstrapWagonConfigurator());
        locator.setServices(WagonProvider.class, new BootstrapWagonProvider());
    }
    locator.setServices(ModelBuilder.class, new MavenModelBuilder(workspace, getCliOptions(),
            workspace == null ? Collections.emptyList() : getActiveSettingsProfiles()));
    locator.setErrorHandler(new DefaultServiceLocator.ErrorHandler() {
        @Override
        public void serviceCreationFailed(Class<?> type, Class<?> impl, Throwable exception) {
            log.error("Failed to initialize " + impl.getName() + " as a service implementing " + type.getName(), exception);
        }
    });
    return locator.getService(RepositorySystem.class);
}
 
Example #2
Source File: ExtensionModule.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
    public void configure(Binder binder) {
        binder.bind(PluginDependenciesResolver.class).to(NbPluginDependenciesResolver.class);
        binder.bind(Roles.componentKey(RepositoryConnectorFactory.class, "offline")).to(OfflineConnector.class);
        //#212214 the EnhancedLocalRepositoryManager will claim artifact is not locally present even if file is there but some metadata is missing
        //we just replace it with the simple variant that relies on file's presence only. 
        //I'm a bit afraid to remove the binding altogether, that's why we map simple to enhanced.
        binder.bind(Roles.componentKey(LocalRepositoryManagerFactory.class, "enhanced")).to(SimpleLocalRepositoryManagerFactory.class);
        
        //exxperimental only.
//        binder.bind(InheritanceAssembler.class).to(NbInheritanceAssembler.class);
        binder.bind(ModelBuilder.class).to(NBModelBuilder.class);
    }
 
Example #3
Source File: MavenContainer.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
public RepositorySystem getRepositorySystem()
{

   final DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
   locator.setServices(ModelBuilder.class, new DefaultModelBuilderFactory().newInstance());
   // Installing Wagon to fetch from HTTP repositories
   locator.setServices(WagonProvider.class, new ManualWagonProvider());
   locator.addService(TransporterFactory.class, WagonTransporterFactory.class);
   locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
   final RepositorySystem repositorySystem = locator.getService(RepositorySystem.class);
   return repositorySystem;
}
 
Example #4
Source File: ProjectHelper.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
public Model loadPomFromFile(File pomFile, String... profiles)
{
   RepositorySystem system = mavenContainer.getRepositorySystem();
   Settings settings = mavenContainer.getSettings();
   DefaultRepositorySystemSession session = mavenContainer.setupRepoSession(system, settings);
   final DefaultModelBuildingRequest request = new DefaultModelBuildingRequest()
            .setSystemProperties(System.getProperties())
            .setPomFile(pomFile)
            .setActiveProfileIds(settings.getActiveProfiles());
   ModelBuilder builder = new DefaultModelBuilderFactory().newInstance();
   ModelBuildingResult result;
   try
   {
      request.setModelResolver(new MavenModelResolver(system, session,
               MavenRepositories.getRemoteRepositories(mavenContainer, settings)));
      result = builder.build(request);
   }
   // wrap exception message
   catch (ModelBuildingException e)
   {
      String pomPath = request.getPomFile().getAbsolutePath();
      StringBuilder sb = new StringBuilder("Found ").append(e.getProblems().size())
               .append(" problems while building POM model from ").append(pomPath).append("\n");

      int counter = 1;
      for (ModelProblem problem : e.getProblems())
      {
         sb.append(counter++).append("/ ").append(problem).append("\n");
      }

      throw new RuntimeException(sb.toString());
   }
   return result.getEffectiveModel();
}
 
Example #5
Source File: Pom.java    From buck with Apache License 2.0 5 votes vote down vote up
private Model constructModel(File file, Model model) {
  ModelBuilder modelBuilder = MODEL_BUILDER_FACTORY.newInstance();

  try {
    ModelBuildingRequest req = new DefaultModelBuildingRequest().setPomFile(file);
    ModelBuildingResult modelBuildingResult = modelBuilder.build(req);

    Model constructed = Objects.requireNonNull(modelBuildingResult.getRawModel());

    return merge(model, constructed);
  } catch (ModelBuildingException e) {
    throw new RuntimeException(e);
  }
}