本文整理汇总了Java中org.apache.maven.execution.MavenExecutionRequest类的典型用法代码示例。如果您正苦于以下问题:Java MavenExecutionRequest类的具体用法?Java MavenExecutionRequest怎么用?Java MavenExecutionRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MavenExecutionRequest类属于org.apache.maven.execution包,在下文中一共展示了MavenExecutionRequest类的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: afterSessionStart
import org.apache.maven.execution.MavenExecutionRequest; //导入依赖的package包/类
@Override
public void afterSessionStart( MavenSession session )
throws MavenExecutionException
{
MavenExecutionRequest request = session.getRequest();
DependencyVersionReportGenerator reportGenerator = new DependencyVersionReportGenerator( logger );
if ( workspaceReader != null )
{
workspaceReader.addResolutionListener( mojoExecutionListener );
workspaceReader.addResolutionListener( reportGenerator );
}
ChainedExecutionListener chainedListener = new ChainedExecutionListener();
chainedListener.addExecutionListener( request.getExecutionListener() );
chainedListener.addExecutionListener( reportGenerator );
request.setExecutionListener( chainedListener );
}
示例3: runMavenRequest
import org.apache.maven.execution.MavenExecutionRequest; //导入依赖的package包/类
public void runMavenRequest(MavenExecutionRequest request, Runnable runnable) {
DefaultMaven maven = (DefaultMaven) getMavenComponent(Maven.class);
RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);
request.getProjectBuildingRequest().setRepositorySession(repositorySystemSession);
MavenSession mavenSession =
new MavenSession(
container, repositorySystemSession, request, new DefaultMavenExecutionResult());
LegacySupport legacySupport = getMavenComponent(LegacySupport.class);
MavenSession previousSession = legacySupport.getSession();
legacySupport.setSession(mavenSession);
try {
for (AbstractMavenLifecycleParticipant participant :
getLifecycleParticipants(Collections.emptyList())) {
participant.afterSessionStart(mavenSession);
}
runnable.run();
} catch (MavenExecutionException e) {
throw new RuntimeException(e);
} finally {
legacySupport.setSession(previousSession);
}
}
示例4: newMavenRequest
import org.apache.maven.execution.MavenExecutionRequest; //导入依赖的package包/类
public MavenExecutionRequest newMavenRequest(
File pom, List<String> activeProfiles, List<String> inactiveProfiles, List<String> goals) {
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
try {
getMavenComponent(MavenExecutionRequestPopulator.class)
.populateFromSettings(request, settings);
request.setGoals(goals);
request.setPom(pom);
getMavenComponent(MavenExecutionRequestPopulator.class).populateDefaults(request);
request.setSystemProperties(properties);
request.setActiveProfiles(activeProfiles);
request.setInactiveProfiles(inactiveProfiles);
request.setStartTime(buildDate);
return request;
} catch (MavenExecutionRequestPopulationException e) {
throw new RuntimeException(e);
}
}
示例5: backGroundBuild
import org.apache.maven.execution.MavenExecutionRequest; //导入依赖的package包/类
void backGroundBuild(MavenProject project) throws MojoExecutionException {
MavenExecutionRequest executionRequest = session.getRequest();
InvocationRequest request = new DefaultInvocationRequest();
request.setBaseDirectory(project.getBasedir());
request.setPomFile(project.getFile());
request.setGoals(executionRequest.getGoals());
request.setRecursive(false);
request.setInteractive(false);
request.setProfiles(executionRequest.getActiveProfiles());
request.setProperties(executionRequest.getUserProperties());
Invoker invoker = new DefaultInvoker();
try {
InvocationResult result = invoker.execute(request);
if (result.getExitCode() != 0) {
throw new IllegalStateException("Error invoking Maven goals:[" + StringUtils.join(executionRequest.getGoals(), ", ") + "]", result.getExecutionException());
}
} catch (MavenInvocationException e) {
throw new IllegalStateException("Error invoking Maven goals:[" + StringUtils.join(executionRequest.getGoals(), ", ") + "]", e);
}
}
示例6: onEvent
import org.apache.maven.execution.MavenExecutionRequest; //导入依赖的package包/类
@Override
public void onEvent(Object event) throws Exception {
if (event instanceof MavenExecutionRequest) {
if (stamper.isEnabled()) {
logger.info("[FreezePomSpy]: Received a " + MavenExecutionRequest.class.getSimpleName());
MavenExecutionRequest mavenExecutionRequest = (MavenExecutionRequest)event;
File pomFile = mavenExecutionRequest.getPom();
if (!MavenConventions.FROZEN_POM_FILE.equals(pomFile.getName())) {
logger.info("[FreezeModelLocator]: Freeze pom " + pomFile.getAbsolutePath());
artifactFreezeMapping.put(pomFile);
logger.debug("[FreezeModelLocator]: Freezing pom " + pomFile.getAbsolutePath());
mavenExecutionRequest.setPom(pomFreezer.freeze(pomFile));
}
}
}
}
示例7: getProjectsForMavenReactor
import org.apache.maven.execution.MavenExecutionRequest; //导入依赖的package包/类
private List<MavenProject> getProjectsForMavenReactor( MavenSession session )
throws ProjectBuildingException
{
MavenExecutionRequest request = session.getRequest();
request.getProjectBuildingRequest().setRepositorySession( session.getRepositorySession() );
List<MavenProject> projects = new ArrayList<MavenProject>();
// We have no POM file.
//
if ( request.getPom() == null )
{
ModelSource modelSource = new UrlModelSource( DefaultMaven.class.getResource( "project/standalone.xml" ) );
MavenProject project =
projectBuilder.build( modelSource, request.getProjectBuildingRequest() ).getProject();
project.setExecutionRoot( true );
projects.add( project );
request.setProjectPresent( false );
return projects;
}
List<File> files = Arrays.asList( request.getPom().getAbsoluteFile() );
collectProjects( projects, files, request );
return projects;
}
示例8: createUpdateSession
import org.apache.maven.execution.MavenExecutionRequest; //导入依赖的package包/类
private ManipulationSession createUpdateSession() throws Exception
{
ManipulationSession session = new ManipulationSession();
session.setState( new DependencyState( p ) );
session.setState( new VersioningState( p ) );
session.setState( new CommonState( p ) );
final MavenExecutionRequest req =
new DefaultMavenExecutionRequest().setUserProperties( p ).setRemoteRepositories( Collections.<ArtifactRepository>emptyList() );
final PlexusContainer container = new DefaultPlexusContainer();
final MavenSession mavenSession = new MavenSession( container, null, req, new DefaultMavenExecutionResult() );
session.setMavenSession( mavenSession );
return session;
}
示例9: 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;
}
示例10: newSession
import org.apache.maven.execution.MavenExecutionRequest; //导入依赖的package包/类
private MavenSession newSession(MavenProject project, File localrepo, Properties properties) throws Exception {
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
MavenExecutionResult result = new DefaultMavenExecutionResult();
DefaultRepositorySystemSession repoSession = MavenRepositorySystemUtils.newSession();
LocalRepository localRepo = new LocalRepository(localrepo);
repoSession.setLocalRepositoryManager(mojos.getContainer().lookup(LocalRepositoryManagerFactory.class, "simple").newInstance(repoSession, localRepo));
MavenSession session = new MavenSession(mojos.getContainer(), repoSession, request, result);
List<MavenProject> projects = new ArrayList<>();
projects.add(project);
for (String module : project.getModules()) {
MavenProject moduleProject = readMavenProject(new File(project.getBasedir(), module), properties);
moduleProject.setParent(project);
projects.add(moduleProject);
}
session.setProjects(projects);
return session;
}
示例11: commands
import org.apache.maven.execution.MavenExecutionRequest; //导入依赖的package包/类
private void commands( CliRequest cliRequest )
{
if ( cliRequest.showErrors )
{
slf4jLogger.info( "Error stacktraces are turned on." );
}
if ( MavenExecutionRequest.CHECKSUM_POLICY_WARN.equals( cliRequest.request.getGlobalChecksumPolicy() ) )
{
slf4jLogger.info( "Disabling strict checksum verification on all artifact downloads." );
}
else if ( MavenExecutionRequest.CHECKSUM_POLICY_FAIL.equals( cliRequest.request.getGlobalChecksumPolicy() ) )
{
slf4jLogger.info( "Enabling strict checksum verification on all artifact downloads." );
}
}
示例12: getProjectsForMavenReactor
import org.apache.maven.execution.MavenExecutionRequest; //导入依赖的package包/类
private List<MavenProject> getProjectsForMavenReactor( MavenExecutionRequest request )
throws ProjectBuildingException
{
List<MavenProject> projects = new ArrayList<MavenProject>();
// We have no POM file.
//
if ( request.getPom() == null )
{
ModelSource modelSource = new UrlModelSource( DefaultMaven.class.getResource( "project/standalone.xml" ) );
MavenProject project =
projectBuilder.build( modelSource, request.getProjectBuildingRequest() ).getProject();
project.setExecutionRoot( true );
projects.add( project );
request.setProjectPresent( false );
return projects;
}
List<File> files = Arrays.asList( request.getPom().getAbsoluteFile() );
collectProjects( projects, files, request );
return projects;
}
示例13: createDependencyGraph
import org.apache.maven.execution.MavenExecutionRequest; //导入依赖的package包/类
private ProjectDependencyGraph createDependencyGraph( ProjectSorter sorter, MavenExecutionRequest request )
throws MavenExecutionException
{
ProjectDependencyGraph graph = new DefaultProjectDependencyGraph( sorter );
List<MavenProject> activeProjects = sorter.getSortedProjects();
activeProjects = trimSelectedProjects( activeProjects, graph, request );
activeProjects = trimResumedProjects( activeProjects, request );
if ( activeProjects.size() != sorter.getSortedProjects().size() )
{
graph = new FilteredProjectDependencyGraph( graph, activeProjects );
}
return graph;
}
示例14: 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());
}
示例15: 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;
}