本文整理汇总了Java中org.apache.maven.execution.MavenExecutionRequest.getProjectBuildingRequest方法的典型用法代码示例。如果您正苦于以下问题:Java MavenExecutionRequest.getProjectBuildingRequest方法的具体用法?Java MavenExecutionRequest.getProjectBuildingRequest怎么用?Java MavenExecutionRequest.getProjectBuildingRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.maven.execution.MavenExecutionRequest
的用法示例。
在下文中一共展示了MavenExecutionRequest.getProjectBuildingRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readProjectWithDependencies
import org.apache.maven.execution.MavenExecutionRequest; //导入方法依赖的package包/类
public MavenExecutionResult readProjectWithDependencies(MavenExecutionRequest req, boolean useWorkspaceResolution) {
if (useWorkspaceResolution) {
req.setWorkspaceReader(new NbWorkspaceReader());
}
File pomFile = req.getPom();
MavenExecutionResult result = new DefaultMavenExecutionResult();
try {
ProjectBuildingRequest configuration = req.getProjectBuildingRequest();
configuration.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
configuration.setResolveDependencies(true);
configuration.setRepositorySession(maven.newRepositorySession(req));
ProjectBuildingResult projectBuildingResult = projectBuilder.build(pomFile, configuration);
result.setProject(projectBuildingResult.getProject());
result.setDependencyResolutionResult(projectBuildingResult.getDependencyResolutionResult());
} catch (ProjectBuildingException ex) {
//don't add the exception here. this should come out as a build marker, not fill
//the error logs with msgs
return result.addException(ex);
}
normalizePaths(result.getProject());
return result;
}
示例2: lookupConfiguredMojo
import org.apache.maven.execution.MavenExecutionRequest; //导入方法依赖的package包/类
/**
* Workaround for parent class lookupMojo and lookupConfiguredMojo.
* @param name the name of the Mojo to lookup
* @param pomPath where to find the POM file
* @return a configured MSBuild Mojo for testing
* @throws Exception if we can't find the Mojo or the POM is malformed
*/
protected final Mojo lookupConfiguredMojo( String name, String pomPath ) throws Exception
{
File pom = new File( getClass().getResource( pomPath ).getPath() );
assertTrue( pom.exists() );
// The following 4 lines are simply to get a MavenProject object
MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
ProjectBuilder projectBuilder = this.lookup( ProjectBuilder.class );
MavenProject mavenProject = projectBuilder.build( pom, buildingRequest ).getProject();
assertNotNull( mavenProject );
// Used lookupMojo as it sets up most of what we need and reads configuration
// variables from the poms.
// It doesn't set a MavenProject so we have to do that manually
// lookupConfiguredMojo doesn't work properly, configuration variables are no expanded
// as we expect and it fails to setup a Log.
Mojo mojo = lookupMojo( name, pom );
//Mojo mojo = super.lookupConfiguredMojo( mavenProject, name );
assertNotNull( mojo );
setVariableValueToObject( mojo, "mavenProject", mavenProject );
return mojo;
}
示例3: testSomething
import org.apache.maven.execution.MavenExecutionRequest; //导入方法依赖的package包/类
/**
* @throws Exception if any
*/
@Test
public void testSomething()
throws Exception {
File projectBase = getTestFile("src/test/resources/com/vityuk/ginger/maven/");
File pom = new File(projectBase, "pom.xml");
assertNotNull(pom);
assertTrue(pom.exists());
MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
ProjectBuilder projectBuilder = lookup(ProjectBuilder.class);
MavenProject project = projectBuilder.build(pom, buildingRequest).getProject();
MavenGeneratorMojo myMojo = (MavenGeneratorMojo) lookupConfiguredMojo(project, "ginger-generator");
assertNotNull(myMojo);
myMojo.execute();
File outputDirectory = new File(myMojo.outputDirectory);
File resultFile = new File(outputDirectory, "com/vityuk/ginger/test1/GeneralConstants.java");
assertTrue("GeneralConstants.java is NOT generated", resultFile.exists());
}
示例4: loadParentOf
import org.apache.maven.execution.MavenExecutionRequest; //导入方法依赖的package包/类
/**
* replacement for MavenProject.getParent() which has bad long term memory behaviour. We offset it by recalculating/reparsing everything
* therefore should not be used lightly!
* pass a MavenProject instance and current configuration and other settings will be applied when loading the parent.
* @param project
* @return null or the parent mavenproject
*/
public MavenProject loadParentOf(MavenEmbedder embedder, MavenProject project) throws ProjectBuildingException {
MavenProject parent = null;
ProjectBuilder builder = embedder.lookupComponent(ProjectBuilder.class);
MavenExecutionRequest req = embedder.createMavenExecutionRequest();
M2Configuration active = configProvider.getActiveConfiguration();
req.addActiveProfiles(active.getActivatedProfiles());
req.setNoSnapshotUpdates(true);
req.setUpdateSnapshots(false);
req.setInteractiveMode(false);
req.setRecursive(false);
req.setOffline(true);
//#238800 important to merge, not replace
Properties uprops = req.getUserProperties();
uprops.putAll(MavenProjectCache.createUserPropsForProjectLoading(active.getProperties()));
req.setUserProperties(uprops);
ProjectBuildingRequest request = req.getProjectBuildingRequest();
request.setRemoteRepositories(project.getRemoteArtifactRepositories());
DefaultMaven maven = (DefaultMaven) embedder.lookupComponent(Maven.class);
request.setRepositorySession(maven.newRepositorySession(req));
if (project.getParentFile() != null) {
parent = builder.build(project.getParentFile(), request).getProject();
} else if (project.getModel().getParent() != null) {
parent = builder.build(project.getParentArtifact(), request).getProject();
}
//clear the project building request, it references multiple Maven Models via the RepositorySession cache
//is not used in maven itself, most likely used by m2e only..
if (parent != null) {
parent.setProjectBuildingRequest(null);
}
MavenEmbedder.normalizePaths(parent);
return parent;
}
示例5: runMavenValidationImpl
import org.apache.maven.execution.MavenExecutionRequest; //导入方法依赖的package包/类
static List<ModelProblem> runMavenValidationImpl(final File pom) {
//TODO profiles based on current configuration??
MavenEmbedder embedder = EmbedderFactory.getProjectEmbedder();
MavenExecutionRequest meReq = embedder.createMavenExecutionRequest();
ProjectBuildingRequest req = meReq.getProjectBuildingRequest();
req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1); // currently enables just <reporting> warning
req.setLocalRepository(embedder.getLocalRepository());
List<ArtifactRepository> remoteRepos = RepositoryPreferences.getInstance().remoteRepositories(embedder);
req.setRemoteRepositories(remoteRepos);
req.setRepositorySession(((DefaultMaven) embedder.lookupComponent(Maven.class)).newRepositorySession(meReq));
List<ModelProblem> problems;
try {
problems = embedder.lookupComponent(ProjectBuilder.class).build(pom, req).getProblems();
} catch (ProjectBuildingException x) {
problems = new ArrayList<ModelProblem>();
List<ProjectBuildingResult> results = x.getResults();
if (results != null) { //one code point throwing ProjectBuildingException contains results,
for (ProjectBuildingResult result : results) {
problems.addAll(result.getProblems());
}
} else {
// another code point throwing ProjectBuildingException doesn't contain results..
Throwable cause = x.getCause();
if (cause instanceof ModelBuildingException) {
problems.addAll(((ModelBuildingException) cause).getProblems());
}
}
}
return problems;
}
示例6: runMavenValidationImpl
import org.apache.maven.execution.MavenExecutionRequest; //导入方法依赖的package包/类
static List<ModelProblem> runMavenValidationImpl(final File pom) {
MavenEmbedder embedder = EmbedderFactory.getProjectEmbedder();
MavenExecutionRequest meReq = embedder.createMavenExecutionRequest();
ProjectBuildingRequest req = meReq.getProjectBuildingRequest();
req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0); // 3.1 currently enables just <reporting> warning, see issue 223562 for details on why it's bad to show.
req.setLocalRepository(embedder.getLocalRepository());
List<ArtifactRepository> remoteRepos = RepositoryPreferences.getInstance().remoteRepositories(embedder);
req.setRemoteRepositories(remoteRepos);
req.setRepositorySession(((DefaultMaven) embedder.lookupComponent(Maven.class)).newRepositorySession(meReq));
List<ModelProblem> problems;
try {
problems = embedder.lookupComponent(ProjectBuilder.class).build(pom, req).getProblems();
} catch (ProjectBuildingException x) {
problems = new ArrayList<ModelProblem>();
List<ProjectBuildingResult> results = x.getResults();
if (results != null) { //one code point throwing ProjectBuildingException contains results,
for (ProjectBuildingResult result : results) {
problems.addAll(result.getProblems());
}
} else {
// another code point throwing ProjectBuildingException doesn't contain results..
Throwable cause = x.getCause();
if (cause instanceof ModelBuildingException) {
problems.addAll(((ModelBuildingException) cause).getProblems());
}
}
}
List<ModelProblem> toRet = new LinkedList<ModelProblem>();
for (ModelProblem problem : problems) {
if(ModelUtils.checkByCLIMavenValidationLevel(problem)) {
toRet.add(problem);
}
}
return toRet;
}
示例7: findMojo
import org.apache.maven.execution.MavenExecutionRequest; //导入方法依赖的package包/类
private <T extends AbstractGolangMojo> T findMojo(final Class<T> klazz, final String pomName, final String goal) throws Exception {
final File pomFile = new File(GolangMojoCfgTest.class.getResource(pomName).toURI());
final MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
final ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
final ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class);
final MavenProject project = projectBuilder.build(pomFile, buildingRequest).getProject();
return klazz.cast(this.lookupConfiguredMojo(project, goal));
}
示例8: lookupMojo
import org.apache.maven.execution.MavenExecutionRequest; //导入方法依赖的package包/类
protected Mojo lookupMojo(Path pomPath, String goal) throws Exception {
File pom = getTestFile(pomPath.toString());
assertTrue(pom.exists());
MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
buildingRequest.setRepositorySession(new DefaultRepositorySystemSession());
ProjectBuilder projectBuilder = lookup(ProjectBuilder.class);
MavenProject project = projectBuilder.build(pom, buildingRequest).getProject();
return lookupConfiguredMojo(project, goal);
}
示例9: lookupConfiguredMojo
import org.apache.maven.execution.MavenExecutionRequest; //导入方法依赖的package包/类
private Mojo lookupConfiguredMojo(String goal, File pom) throws Exception
{
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setBaseDirectory(pom.getParentFile());
ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
// Fix for bug: https://git-wip-us.apache.org/repos/asf?p=maven-plugin-testing.git;a=commit;h=3cd5f47c586499e438a3f9393304ac9d1f9a7f53
configuration.setRepositorySession(new DefaultRepositorySystemSession());
MavenProject project = lookup(ProjectBuilder.class).build(pom, configuration).getProject();
return super.lookupConfiguredMojo(project, goal);
}
示例10: newMojo
import org.apache.maven.execution.MavenExecutionRequest; //导入方法依赖的package包/类
protected AbstractXmlMojo newMojo( String pDir )
throws Exception
{
File testPom = new File( new File( getBasedir(), pDir ), "pom.xml" );
MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class);
MavenProject project = projectBuilder.build(testPom, buildingRequest).getProject();
// final Build build = new Build();
// build.setDirectory( "target" );
// project.setBuild(build);
project.getBuild().setDirectory("target");
AbstractXmlMojo vm = (AbstractXmlMojo) lookupConfiguredMojo(project, getGoal());
setVariableValueToObject( vm, "basedir", new File( getBasedir(), pDir ) );
final Log log = new SilentLog();
DefaultResourceManager rm = new DefaultResourceManager();
setVariableValueToObject( rm, "logger", log );
setVariableValueToObject( vm, "locator", rm );
final Map<String, ResourceLoader> resourceLoaders = new HashMap<String, ResourceLoader>();
resourceLoaders.put( "file", new FileResourceLoader() );
resourceLoaders.put( "jar", new JarResourceLoader() );
resourceLoaders.put( "classloader", new ThreadContextClasspathResourceLoader() );
URLResourceLoader url = new URLResourceLoader();
setVariableValueToObject( url, "logger", log );
resourceLoaders.put( "url", url );
setVariableValueToObject( rm, "resourceLoaders", resourceLoaders );
// MavenProjectStub project = new MavenProjectStub()
// {
// public Build getBuild()
// {
// return build;
// }
// };
// setVariableValueToObject( vm, "project", project );
return vm;
}
示例11: findMojo
import org.apache.maven.execution.MavenExecutionRequest; //导入方法依赖的package包/类
private JBBPGenerateMojo findMojo(final String pomName, final String goal) throws Exception {
final File pomFile = new File(this.getClass().getResource(pomName).toURI());
final MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
final ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
final ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class);
final MavenProject project = projectBuilder.build(pomFile, buildingRequest).getProject();
return (JBBPGenerateMojo) this.lookupConfiguredMojo(project, goal);
}
示例12: init
import org.apache.maven.execution.MavenExecutionRequest; //导入方法依赖的package包/类
private UPomMojo init(final File config) throws Exception {
final MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
final ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
final ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class);
final MavenProject project = projectBuilder.build(config, buildingRequest).getProject();
final UPomMojo mojo = (UPomMojo) this.lookupConfiguredMojo(project, "upom");
return mojo;
}
示例13: getMavenProject
import org.apache.maven.execution.MavenExecutionRequest; //导入方法依赖的package包/类
private MavenProject getMavenProject(String pomPath) throws Exception {
File pom = new File(pomPath);
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setPom(pom);
ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
return lookup( ProjectBuilder.class ).build( pom, configuration ).getProject();
}
示例14: readMavenProject
import org.apache.maven.execution.MavenExecutionRequest; //导入方法依赖的package包/类
private MavenProject readMavenProject(File basedir, Properties properties) throws Exception {
File pom = new File(basedir, "pom.xml");
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setUserProperties(properties);
request.setBaseDirectory(basedir);
ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
configuration.setRepositorySession(new DefaultRepositorySystemSession());
MavenProject project = mojos.lookup(ProjectBuilder.class).build(pom, configuration).getProject();
Assert.assertNotNull(project);
return project;
}
示例15: collectProjects
import org.apache.maven.execution.MavenExecutionRequest; //导入方法依赖的package包/类
private void collectProjects( List<MavenProject> projects, List<File> files, MavenExecutionRequest request )
throws ProjectBuildingException
{
ProjectBuildingRequest projectBuildingRequest = request.getProjectBuildingRequest();
List<ProjectBuildingResult> results = projectBuilder.build( files, request.isRecursive(), projectBuildingRequest );
boolean problems = false;
for ( ProjectBuildingResult result : results )
{
projects.add( result.getProject() );
if ( !result.getProblems().isEmpty() && logger.isWarnEnabled() )
{
logger.warn( "" );
logger.warn( "Some problems were encountered while building the effective model for "
+ result.getProject().getId() );
for ( ModelProblem problem : result.getProblems() )
{
String location = ModelProblemUtils.formatLocation( problem, result.getProjectId() );
logger.warn( problem.getMessage() + ( StringUtils.isNotEmpty( location ) ? " @ " + location : "" ) );
}
problems = true;
}
}
if ( problems )
{
logger.warn( "" );
logger.warn( "It is highly recommended to fix these problems"
+ " because they threaten the stability of your build." );
logger.warn( "" );
logger.warn( "For this reason, future Maven versions might no"
+ " longer support building such malformed projects." );
logger.warn( "" );
}
}