public MavenProject build(File pom, ProjectBuilderConfiguration configuration) throws ProjectBuildingException { ProjectBuildingRequest request = injectSession(toRequest(configuration)); try { return projectBuilder.build(pom, request).getProject(); } catch (ProjectBuildingException e) { throw transformError(e); } }
/** * This is used for pom-less execution like running archetype:generate. I am taking out the * profile handling and the interpolation of the base directory until we spec this out properly. */ public MavenProject buildStandaloneSuperProject(ProjectBuilderConfiguration configuration) throws ProjectBuildingException { ProjectBuildingRequest request = injectSession(toRequest(configuration)); request.setProcessPlugins(false); request.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); ModelSource modelSource = new UrlModelSource(getClass().getResource("standalone.xml")); MavenProject project = projectBuilder.build(modelSource, request).getProject(); project.setExecutionRoot(true); return project; }
@NotNull protected List<ProjectBuildingResult> getProjectBuildingResults( @NotNull MavenExecutionRequest request, @NotNull Collection<File> files) { final ProjectBuilder builder = getComponent(ProjectBuilder.class); CustomMaven3ModelInterpolator2 modelInterpolator = (CustomMaven3ModelInterpolator2) getComponent(ModelInterpolator.class); String savedLocalRepository = modelInterpolator.getLocalRepository(); modelInterpolator.setLocalRepository(request.getLocalRepositoryPath().getAbsolutePath()); List<ProjectBuildingResult> buildingResults = new SmartList<ProjectBuildingResult>(); final ProjectBuildingRequest projectBuildingRequest = request.getProjectBuildingRequest(); projectBuildingRequest.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); projectBuildingRequest.setResolveDependencies(false); try { buildingResults = builder.build(new ArrayList<File>(files), false, projectBuildingRequest); } catch (ProjectBuildingException e) { for (ProjectBuildingResult result : e.getResults()) { if (result.getProject() != null) { buildingResults.add(result); } else { try { ProjectBuildingResult build = builder.build(result.getPomFile(), projectBuildingRequest); buildingResults.add(build); } catch (ProjectBuildingException e2) { buildingResults.addAll(e2.getResults()); } } } } finally { modelInterpolator.setLocalRepository(savedLocalRepository); } return buildingResults; }
public MavenProject buildFromRepository( Artifact artifact, List<ArtifactRepository> remoteRepositories, ProjectBuilderConfiguration configuration, boolean allowStubModel) throws ProjectBuildingException { ProjectBuildingRequest request = injectSession(toRequest(configuration)); request.setRemoteRepositories(normalizeToArtifactRepositories(remoteRepositories, request)); request.setProcessPlugins(false); request.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); try { return projectBuilder.build(artifact, allowStubModel, request).getProject(); } catch (ProjectBuildingException e) { throw transformError(e); } }
public MavenProject buildWithDependencies( File pom, ArtifactRepository localRepository, ProfileManager profileManager, TransferListener transferListener) throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException { ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration(); configuration.setLocalRepository(localRepository); configuration.setGlobalProfileManager(profileManager); ProjectBuildingRequest request = injectSession(toRequest(configuration)); request.setResolveDependencies(true); try { return projectBuilder.build(pom, request).getProject(); } catch (ProjectBuildingException e) { throw transformError(e); } }