org.apache.maven.model.building.DefaultModelBuilderFactory Java Examples
The following examples show how to use
org.apache.maven.model.building.DefaultModelBuilderFactory.
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: MavenHelper.java From repairnator with MIT License | 6 votes |
public static Model readPomXml(File pomXml, String localMavenRepository) { ModelBuildingRequest req = new DefaultModelBuildingRequest(); req.setProcessPlugins(true); req.setPomFile(pomXml); req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); req.setModelResolver(new RepositoryModelResolver(localMavenRepository)); DefaultModelBuilder defaultModelBuilder = new DefaultModelBuilderFactory().newInstance(); // we try to build the model, and if we fail, we try to get the raw model try { ModelBuildingResult modelBuildingResult = defaultModelBuilder.build(req); return modelBuildingResult.getEffectiveModel(); } catch (ModelBuildingException e) { LOGGER.error("Error while building complete model. The raw model will be used. Error message: " + e.getMessage()); return defaultModelBuilder.buildRawModel(pomXml, ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL, true).get(); } }
Example #2
Source File: ModelBuilderThreadSafetyWorkaround.java From flatten-maven-plugin with Apache License 2.0 | 6 votes |
public ModelBuildingResult build( ModelBuildingRequest buildingRequest, ProfileInjector customInjector, ProfileSelector customSelector ) throws ModelBuildingException { // note: there is neither DefaultModelBuilder.get*(), nor DefaultModelBuilder.clone() return new DefaultModelBuilderFactory().newInstance() .setProfileInjector( customInjector ) .setProfileSelector( customSelector ) // apply currently active ModelProcessor etc. to support extensions like jgitver .setDependencyManagementImporter( dependencyManagementImporter ) .setDependencyManagementInjector( dependencyManagementInjector ) .setInheritanceAssembler( inheritanceAssembler ) .setLifecycleBindingsInjector( lifecycleBindingsInjector ) .setModelInterpolator( modelInterpolator ) .setModelNormalizer( modelNormalizer ) .setModelPathTranslator( modelPathTranslator ) .setModelProcessor( modelProcessor ) .setModelUrlNormalizer( modelUrlNormalizer ) .setModelValidator( modelValidator ) .setPluginConfigurationExpander( pluginConfigurationExpander ) .setPluginManagementInjector( pluginManagementInjector ) .setReportConfigurationExpander( reportConfigurationExpander ) .setReportingConverter( reportingConverter ) .setSuperPomProvider( superPomProvider ) .build( buildingRequest ); }
Example #3
Source File: Resolver.java From buck with Apache License 2.0 | 6 votes |
public Resolver(ArtifactConfig config) { this.modelBuilder = new DefaultModelBuilderFactory() .newInstance() .setProfileSelector(new DefaultProfileSelector()) .setPluginConfigurationExpander(new DefaultPluginConfigurationExpander()) .setPluginManagementInjector(new DefaultPluginManagementInjector()) .setDependencyManagementImporter(new DefaultDependencyManagementImporter()) .setDependencyManagementInjector(new DefaultDependencyManagementInjector()); ServiceLocator locator = AetherUtil.initServiceLocator(); this.repoSys = locator.getService(RepositorySystem.class); this.localRepo = new LocalRepository(Paths.get(config.mavenLocalRepo).toFile()); this.session = newSession(repoSys, localRepo); this.buckRepoRoot = Paths.get(Objects.requireNonNull(config.buckRepoRoot)); this.buckThirdPartyRelativePath = Paths.get(Objects.requireNonNull(config.thirdParty)); this.visibility = config.visibility; this.repos = config.repositories.stream() .map(AetherUtil::toRemoteRepository) .collect(ImmutableList.toImmutableList()); }
Example #4
Source File: CreateEffectivePomTest.java From flatten-maven-plugin with Apache License 2.0 | 5 votes |
/** * @return ModelBuilderThreadSafetyWorkaround with a reduced scope for this simple test */ private ModelBuilderThreadSafetyWorkaround buildModelBuilderThreadSafetyWorkaroundForTest() { return new ModelBuilderThreadSafetyWorkaround() { @Override public ModelBuildingResult build(ModelBuildingRequest buildingRequest, ProfileInjector customInjector, ProfileSelector customSelector) throws ModelBuildingException { return new DefaultModelBuilderFactory().newInstance() .setProfileInjector( customInjector ) .setProfileSelector( customSelector ) .build( buildingRequest ); } }; }
Example #5
Source File: MavenContainer.java From furnace with Eclipse Public License 1.0 | 5 votes |
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 #6
Source File: ProjectHelper.java From furnace with Eclipse Public License 1.0 | 5 votes |
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 #7
Source File: Maven2RepositoryStorage.java From archiva with Apache License 2.0 | 4 votes |
@PostConstruct public void initialize() { builder = new DefaultModelBuilderFactory().newInstance(); }