org.apache.maven.execution.MavenExecutionResult Java Examples
The following examples show how to use
org.apache.maven.execution.MavenExecutionResult.
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: InstallDeployTest.java From takari-lifecycle with Eclipse Public License 1.0 | 6 votes |
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; }
Example #2
Source File: MavenEmbedder.java From netbeans with Apache License 2.0 | 6 votes |
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; }
Example #3
Source File: MavenExecutionResultHandler.java From pipeline-maven-plugin with MIT License | 6 votes |
@Override protected boolean _handle(MavenExecutionResult result) { Xpp3Dom root = new Xpp3Dom("MavenExecutionResult"); root.setAttribute("class", result.getClass().getName()); for (MavenProject project : result.getTopologicallySortedProjects()) { BuildSummary summary = result.getBuildSummary(project); if (summary == null) { Xpp3Dom comment = new Xpp3Dom("comment"); comment.setValue("No build summary found for maven project: " + project); root.addChild(comment); } else { Xpp3Dom buildSummary = newElement("buildSummary", project); root.addChild(buildSummary); buildSummary.setAttribute("class", summary.getClass().getName()); buildSummary.setAttribute("time", Long.toString(summary.getTime())); } } reporter.print(root); return true; }
Example #4
Source File: MavenProjectConfigCollector.java From helidon-build-tools with Apache License 2.0 | 6 votes |
@Override public void afterSessionEnd(MavenSession session) { if (ENABLED && supportedProjectDir != null) { final MavenExecutionResult result = session.getResult(); if (result == null) { debug("Build failed: no result"); invalidateConfig(); } else if (result.hasExceptions()) { debug("Build failed: %s", result.getExceptions()); invalidateConfig(); } else if (projectConfig != null) { debug("Build succeeded, with compilation. Updating config."); storeConfig(); } else { debug("Build succeeded, without compilation"); invalidateConfig(); } } }
Example #5
Source File: EmbedderFactoryTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testArtifactFixer() throws Exception { // #197669 File main = TestFileUtils.writeFile(new File(getWorkDir(), "main/pom.xml"), "<project xmlns='http://maven.apache.org/POM/4.0.0'><modelVersion>4.0.0</modelVersion>" + "<parent><groupId>g</groupId><artifactId>p</artifactId><version>0</version></parent>" + "<artifactId>m</artifactId>" + "<dependencies><dependency><groupId>g</groupId><artifactId>s</artifactId><version>0</version></dependency></dependencies>" + "</project>"); final File parent = TestFileUtils.writeFile(new File(getWorkDir(), "parent/pom.xml"), "<project xmlns='http://maven.apache.org/POM/4.0.0'><modelVersion>4.0.0</modelVersion>" + "<groupId>g</groupId><artifactId>p</artifactId><version>0</version>" + "<packaging>pom</packaging>" + "<properties><k>v</k></properties>" + "</project>"); final File sibling = TestFileUtils.writeFile(new File(getWorkDir(), "sib/pom.xml"), "<project xmlns='http://maven.apache.org/POM/4.0.0'><modelVersion>4.0.0</modelVersion>" + "<groupId>g</groupId><artifactId>s</artifactId><version>0</version>" + "<dependencies><dependency><groupId>g</groupId><artifactId>b</artifactId><version>0</version></dependency></dependencies>" + "</project>"); final File binary = TestFileUtils.writeZipFile(new File(getWorkDir(), "b.jar"), "g/r:stuff"); MockLookup.setInstances(new ArtifactFixer() { @Override public File resolve(org.eclipse.aether.artifact.Artifact artifact) { String id = artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getExtension() + ':' + artifact.getVersion(); if (id.equals("g:p:pom:0")) { return parent; } else if (id.equals("g:s:pom:0")) { return sibling; } else if (id.equals("g:b:jar:0")) { return binary; } else { return null; } } }); MavenEmbedder e = EmbedderFactory.getProjectEmbedder(); MavenExecutionRequest req = e.createMavenExecutionRequest(); req.setPom(main); req.setOffline(true); MavenExecutionResult res = e.readProjectWithDependencies(req, true); assertEquals(Collections.emptyList(), res.getExceptions()); MavenProject prj = res.getProject(); assertEquals("v", prj.getProperties().getProperty("k")); assertEquals("[g:b:jar:0:compile, g:s:jar:0:compile]", new TreeSet<Artifact>(prj.getArtifacts()).toString()); }
Example #6
Source File: ReactorContextFactory.java From sundrio with Apache License 2.0 | 5 votes |
private static ReactorContext create_3_3_x(MavenExecutionResult result, ProjectIndex index, ClassLoader classLoader, ReactorBuildStatus status, LifecycleModuleBuilder builder) { try { Constructor<ReactorContext> constructor = (Constructor<ReactorContext>) ReactorContext.class.getDeclaredConstructors()[0]; return constructor.newInstance(result, index, classLoader, status, Reflections.getMemento(builder)); } catch (Throwable t) { throw new RuntimeException("Could not create ReactorContext.", t); } }
Example #7
Source File: ReactorContextFactory.java From sundrio with Apache License 2.0 | 5 votes |
private static ReactorContext create_3_2_x(MavenExecutionResult result, ProjectIndex index, ClassLoader classLoader, ReactorBuildStatus status) { try { Constructor<ReactorContext> constructor = ReactorContext.class.getDeclaredConstructor(MavenExecutionResult.class, ProjectIndex.class, ClassLoader.class, ReactorBuildStatus.class); return constructor.newInstance(result, index, classLoader, status); } catch (NoSuchMethodException e) { return null; } catch (Throwable t) { throw new RuntimeException("Could not create ReactorContext.", t); } }
Example #8
Source File: ReactorContextFactory.java From sundrio with Apache License 2.0 | 5 votes |
public ReactorContext create(MavenExecutionResult result, ProjectIndex index, ClassLoader classLoader, ReactorBuildStatus status, LifecycleModuleBuilder builder) { ReactorContext context; if (VERSION_3_0_0.compareTo(version) < 0) { throw new UnsupportedOperationException("ReactorContext is not supported in maven version:" + version); } else if (VERSION_3_3_0.compareTo(version) < 0) { context = create_3_2_x(result, index, classLoader, status); } else { context = create_3_3_x(result, index, classLoader, status, builder); } if (context == null) { throw new IllegalStateException("Unable to create ReactorContext"); } return context; }
Example #9
Source File: BetterAbstractMojoTestCase.java From repairnator with MIT License | 5 votes |
protected MavenSession newMavenSession() { try { MavenExecutionRequest request = new DefaultMavenExecutionRequest(); MavenExecutionResult result = new DefaultMavenExecutionResult(); // populate sensible defaults, including repository basedir and remote repos MavenExecutionRequestPopulator populator; populator = getContainer().lookup( MavenExecutionRequestPopulator.class ); populator.populateDefaults( request ); // this is needed to allow java profiles to get resolved; i.e. avoid during project builds: // [ERROR] Failed to determine Java version for profile java-1.5-detected @ org.apache.commons:commons-parent:22, /Users/alex/.m2/repository/org/apache/commons/commons-parent/22/commons-parent-22.pom, line 909, column 14 request.setSystemProperties( System.getProperties() ); // and this is needed so that the repo session in the maven session // has a repo manager, and it points at the local repo // (cf MavenRepositorySystemUtils.newSession() which is what is otherwise done) DefaultMaven maven = (DefaultMaven) getContainer().lookup( Maven.class ); DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) maven.newRepositorySession( request ); repoSession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance(repoSession, new LocalRepository( request.getLocalRepository().getBasedir() ) )); @SuppressWarnings("deprecation") MavenSession session = new MavenSession( getContainer(), repoSession, request, result ); return session; } catch (Exception e) { throw new RuntimeException(e); } }
Example #10
Source File: BetterMojoRule.java From swaggerhub-maven-plugin with Apache License 2.0 | 5 votes |
protected MavenSession newMavenSession() { try { MavenExecutionRequest request = new DefaultMavenExecutionRequest(); MavenExecutionResult result = new DefaultMavenExecutionResult(); // populate sensible defaults, including repository basedir and remote repos MavenExecutionRequestPopulator populator; populator = getContainer().lookup(MavenExecutionRequestPopulator.class); populator.populateDefaults(request); // this is needed to allow java profiles to get resolved; i.e. avoid during project builds: // [ERROR] Failed to determine Java version for profile java-1.5-detected @ org.apache.commons:commons-parent:22, /Users/alex/.m2/repository/org/apache/commons/commons-parent/22/commons-parent-22.pom, line 909, column 14 request.setSystemProperties(System.getProperties()); // and this is needed so that the repo session in the maven session // has a repo manager, and it points at the local repo // (cf MavenRepositorySystemUtils.newSession() which is what is otherwise done) DefaultMaven maven = (DefaultMaven) getContainer().lookup(Maven.class); DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) maven.newRepositorySession(request); repoSession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance(repoSession, new LocalRepository(request.getLocalRepository().getBasedir()))); @SuppressWarnings("deprecation") MavenSession session = new MavenSession(getContainer(), repoSession, request, result); return session; } catch (Exception e) { throw new RuntimeException(e); } }
Example #11
Source File: MavenEmbedder.java From netbeans with Apache License 2.0 | 5 votes |
private void setResult(ProjectBuildingResult pbr, Map<File, MavenExecutionResult> results) { DefaultMavenExecutionResult r = new DefaultMavenExecutionResult(); normalizePaths(pbr.getProject()); r.setProject(pbr.getProject()); r.setDependencyResolutionResult(pbr.getDependencyResolutionResult()); results.put(pbr.getPomFile(), r); }
Example #12
Source File: LifecycleStarter.java From dew with Apache License 2.0 | 4 votes |
public void execute( MavenSession session ) { eventCatapult.fire( ExecutionEvent.Type.SessionStarted, session, null ); MavenExecutionResult result = session.getResult(); try { if ( !session.isUsingPOMsFromFilesystem() && lifecycleTaskSegmentCalculator.requiresProject( session ) ) { throw new MissingProjectException( "The goal you specified requires a project to execute" + " but there is no POM in this directory (" + session.getExecutionRootDirectory() + ")." + " Please verify you invoked Maven from the correct directory." ); } final MavenExecutionRequest executionRequest = session.getRequest(); boolean isThreaded = executionRequest.isThreadConfigurationPresent(); session.setParallel( isThreaded ); List<TaskSegment> taskSegments = lifecycleTaskSegmentCalculator.calculateTaskSegments( session ); ProjectBuildList projectBuilds = buildListCalculator.calculateProjectBuilds( session, taskSegments ); if ( projectBuilds.isEmpty() ) { throw new NoGoalSpecifiedException( "No goals have been specified for this build." + " You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or" + " <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>." + " Available lifecycle phases are: " + defaultLifeCycles.getLifecyclePhaseList() + "." ); } ProjectIndex projectIndex = new ProjectIndex( session.getProjects() ); if ( logger.isDebugEnabled() ) { lifecycleDebugLogger.debugReactorPlan( projectBuilds ); } ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader(); ReactorBuildStatus reactorBuildStatus = new ReactorBuildStatus( session.getProjectDependencyGraph() ); ReactorContext callableContext = new ReactorContext( result, projectIndex, oldContextClassLoader, reactorBuildStatus ); if ( isThreaded ) { ExecutorService executor = threadConfigService.getExecutorService( executionRequest.getThreadCount(), executionRequest.isPerCoreThreadCount(), session.getProjects().size() ); try { final boolean isWeaveMode = LifecycleWeaveBuilder.isWeaveMode( executionRequest ); if ( isWeaveMode ) { lifecycleDebugLogger.logWeavePlan( session ); lifeCycleWeaveBuilder.build( projectBuilds, callableContext, taskSegments, session, executor, reactorBuildStatus ); } else { ConcurrencyDependencyGraph analyzer = new ConcurrencyDependencyGraph( projectBuilds, session.getProjectDependencyGraph() ); CompletionService<ProjectSegment> service = new ExecutorCompletionService<ProjectSegment>( executor ); lifecycleThreadedBuilder.build( session, callableContext, projectBuilds, taskSegments, analyzer, service ); } } finally { executor.shutdown(); // If the builder has terminated with an exception we want to catch any stray threads before going // to System.exit in the mavencli. executor.awaitTermination( 5, TimeUnit.SECONDS ) ; } } else { singleThreadedBuild( session, callableContext, projectBuilds, taskSegments, reactorBuildStatus ); } } catch ( Exception e ) { result.addException( e ); } eventCatapult.fire( ExecutionEvent.Type.SessionEnded, session, null ); }
Example #13
Source File: MavenEmbedder.java From netbeans with Apache License 2.0 | 4 votes |
public MavenExecutionResult execute(MavenExecutionRequest req) { return maven.execute(req); }
Example #14
Source File: MavenEmbedder.java From netbeans with Apache License 2.0 | 4 votes |
@Deprecated public MavenExecutionResult readProjectWithDependencies(MavenExecutionRequest req) { return readProjectWithDependencies(req, true); }
Example #15
Source File: NbMavenProject.java From netbeans with Apache License 2.0 | 4 votes |
@Messages({ "Progress_Download=Downloading Maven dependencies", "# {0} - error message", "MSG_Failed=Failed to download - {0}", "MSG_Done=Finished retrieving dependencies from remote repositories."}) private RequestProcessor.Task createBinaryDownloadTask(RequestProcessor rp) { return rp.create(new Runnable() { @Override public void run() { //#146171 try the hardest to avoid NPE for files/directories that // seemed to have been deleted while the task was scheduled. FileObject fo = project.getProjectDirectory(); if (fo == null || !fo.isValid()) { return; } fo = fo.getFileObject("pom.xml"); //NOI18N if (fo == null) { return; } File pomFile = FileUtil.toFile(fo); if (pomFile == null) { return; } MavenEmbedder online = EmbedderFactory.getOnlineEmbedder(); AggregateProgressHandle hndl = AggregateProgressFactory.createHandle(Progress_Download(), new ProgressContributor[] { AggregateProgressFactory.createProgressContributor("zaloha") }, //NOI18N ProgressTransferListener.cancellable(), null); boolean ok = true; try { ProgressTransferListener.setAggregateHandle(hndl); hndl.start(); MavenExecutionRequest req = online.createMavenExecutionRequest(); req.setPom(pomFile); req.setTransferListener(ProgressTransferListener.activeListener()); MavenExecutionResult res = online.readProjectWithDependencies(req, false); //NOI18N if (res.hasExceptions()) { ok = false; Exception ex = (Exception)res.getExceptions().get(0); StatusDisplayer.getDefault().setStatusText(MSG_Failed(ex.getLocalizedMessage())); } } catch (ThreadDeath d) { // download interrupted } catch (IllegalStateException x) { if (x.getCause() instanceof ThreadDeath) { // #197261: download interrupted } else { throw x; } } catch (RuntimeException exc) { //guard against exceptions that are not processed by the embedder //#136184 NumberFormatException, #214152 InvalidArtifactRTException StatusDisplayer.getDefault().setStatusText(MSG_Failed(exc.getLocalizedMessage())); } finally { hndl.finish(); ProgressTransferListener.clearAggregateHandle(); } if (ok) { StatusDisplayer.getDefault().setStatusText(MSG_Done()); } if (support.hasListeners(NbMavenProject.PROP_PROJECT)) { NbMavenProject.fireMavenProjectReload(project); } } }); }
Example #16
Source File: MavenModelProblemsProvider.java From netbeans with Apache License 2.0 | 4 votes |
@NbBundle.Messages({ "TXT_Artifact_Resolution_problem=Artifact Resolution problem", "TXT_Artifact_Not_Found=Artifact Not Found", "TXT_Cannot_Load_Project=Unable to properly load project", "TXT_Cannot_read_model=Error reading project model", "TXT_NoMsg=Exception thrown while loading maven project at {0}. See messages.log for more information." }) private Collection<ProjectProblem> reportExceptions(MavenExecutionResult res) { List<ProjectProblem> toRet = new ArrayList<ProjectProblem>(); for (Throwable e : res.getExceptions()) { LOG.log(Level.FINE, "Error on loading project " + project.getProjectDirectory(), e); if (e instanceof ArtifactResolutionException) { // XXX when does this occur? toRet.add(ProjectProblem.createError(TXT_Artifact_Resolution_problem(), getDescriptionText(e))); problemReporter.addMissingArtifact(((ArtifactResolutionException) e).getArtifact()); } else if (e instanceof ArtifactNotFoundException) { // XXX when does this occur? toRet.add(ProjectProblem.createError(TXT_Artifact_Not_Found(), getDescriptionText(e))); problemReporter.addMissingArtifact(((ArtifactNotFoundException) e).getArtifact()); } else if (e instanceof ProjectBuildingException) { toRet.add(ProjectProblem.createError(TXT_Cannot_Load_Project(), getDescriptionText(e), new SanityBuildAction(project))); if (e.getCause() instanceof ModelBuildingException) { ModelBuildingException mbe = (ModelBuildingException) e.getCause(); for (ModelProblem mp : mbe.getProblems()) { LOG.log(Level.FINE, mp.toString(), mp.getException()); if (mp.getException() instanceof UnresolvableModelException) { // Probably obsoleted by ProblemReporterImpl.checkParent, but just in case: UnresolvableModelException ume = (UnresolvableModelException) mp.getException(); problemReporter.addMissingArtifact(EmbedderFactory.getProjectEmbedder().createProjectArtifact(ume.getGroupId(), ume.getArtifactId(), ume.getVersion())); } else if (mp.getException() instanceof PluginResolutionException) { Plugin plugin = ((PluginResolutionException) mp.getException()).getPlugin(); // XXX this is not actually accurate; should rather pick out the ArtifactResolutionException & ArtifactNotFoundException inside problemReporter.addMissingArtifact(EmbedderFactory.getProjectEmbedder().createArtifact(plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion(), "jar")); } else if (mp.getException() instanceof PluginManagerException) { PluginManagerException ex = (PluginManagerException) mp.getException(); problemReporter.addMissingArtifact(EmbedderFactory.getProjectEmbedder().createArtifact(ex.getPluginGroupId(), ex.getPluginArtifactId(), ex.getPluginVersion(), "jar")); } } } } else { String msg = e.getMessage(); if(msg != null) { LOG.log(Level.INFO, "Exception thrown while loading maven project at " + project.getProjectDirectory(), e); //NOI18N toRet.add(ProjectProblem.createError(TXT_Cannot_read_model(), msg)); } else { String path = project.getProjectDirectory().getPath(); toRet.add(ProjectProblem.createError(TXT_Cannot_read_model(), TXT_NoMsg(path))); LOG.log(Level.WARNING, "Exception thrown while loading maven project at " + path, e); //NOI18N } } } return toRet; }
Example #17
Source File: MavenProjectCache.java From netbeans with Apache License 2.0 | 4 votes |
public static MavenExecutionResult getExecutionResult(MavenProject project) { return (MavenExecutionResult) project.getContextValue(CONTEXT_EXECUTION_RESULT); }