private void append( MessageBuilder buffer, MojoExecution me ) { buffer.mojo( me.getArtifactId() + ':' + me.getVersion() + ':' + me.getGoal() ); if ( me.getExecutionId() != null ) { buffer.a( ' ' ).strong( '(' + me.getExecutionId() + ')' ); } }
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); value = session.getLocalRepository(); value = session.getProjects(); value = project.getExecutionProject(); value = session.getRepositorySession(); value = mojoDescriptor.getPluginDescriptor(); PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor(); if ( ( value == null ) && ( ( project != null ) && ( project.getProperties() != null ) ) ) value = project.getProperties().getProperty( expression );
for ( Plugin plugin : project.getBuild().getPlugins() ) MojoExecution mojoExecution = new MojoExecution( plugin, goal, execution.getId() ); mojoExecution.setLifecyclePhase( execution.getPhase() ); addMojoExecution( phaseBindings, mojoExecution, execution.getPriority() ); pluginManager.getMojoDescriptor( plugin, goal, project.getRemotePluginRepositories(), session.getRepositorySession() ); Map<Integer, List<MojoExecution>> phaseBindings = mappings.get( mojoDescriptor.getPhase() ); if ( phaseBindings != null ) MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, execution.getId() ); mojoExecution.setLifecyclePhase( mojoDescriptor.getPhase() ); addMojoExecution( phaseBindings, mojoExecution, execution.getPriority() );
private static String constructMessage( MojoExecution mojoExecution, Throwable cause ) { String message; if ( mojoExecution != null ) { message = "Execution " + mojoExecution.getExecutionId() + " of goal " + mojoExecution.getMojoDescriptor().getId() + " failed"; } else { message = "Mojo execution failed"; } if ( cause != null && StringUtils.isNotEmpty( cause.getMessage() ) ) { message += ": " + cause.getMessage(); } else { message += "."; } return message; }
/** * Get set of plugins having a goal/mojo used but not marked @threadSafe * * @return the set of plugins (without info on which goal is concerned) */ public Set<Plugin> getNonThreadSafePlugins() { Set<Plugin> plugins = new HashSet<>(); for ( ExecutionPlanItem executionPlanItem : planItem ) { final MojoExecution mojoExecution = executionPlanItem.getMojoExecution(); if ( !mojoExecution.getMojoDescriptor().isThreadSafe() ) { plugins.add( mojoExecution.getPlugin() ); } } return plugins; }
private void unpackFileBasedResources() throws MojoExecutionException { if ( mojoExecution == null || mavenProject == null ) { unconstructedParts.add( "Unpacked Ant build scripts (in Maven build directory)." ); return; } // What we need to write out any resources in the plugin to the target directory of the // mavenProject using the Ant-based plugin: // // 1. Need a reference to the plugin JAR itself // 2. Need a reference to the ${basedir} of the mavenProject PluginDescriptor pluginDescriptor = mojoExecution.getMojoDescriptor().getPluginDescriptor(); File pluginJar = pluginDescriptor.getPluginArtifact().getFile(); String resourcesPath = pluginDescriptor.getArtifactId(); File outputDirectory = new File( mavenProject.getBuild().getDirectory() ); try { UnArchiver ua = new ZipUnArchiver( pluginJar ); ua.extract( resourcesPath, outputDirectory ); } catch ( ArchiverException e ) { throw new MojoExecutionException( "Error extracting resources from your Ant-based plugin.", e ); } }
/** * We use a specific status directory for each Mojo execution to store state * which is needed during the next build invocation run. * @return the directory for storing status information of the current Mojo execution. */ public File getMojoStatusDirectory() throws MojoExecutionException { if ( mojoExecution == null ) { throw new MojoExecutionException( "MojoExecution could not get resolved" ); } File buildOutputDirectory = new File( mavenProject.getBuild().getDirectory() ); //X TODO the executionId contains -cli and -mojoname //X we should remove those postfixes as it should not make //X any difference whether being run on the cli or via build String mojoStatusPath = MAVEN_STATUS_ROOT + File.separator + mojoExecution.getMojoDescriptor().getPluginDescriptor().getArtifactId() + File.separator + mojoExecution.getMojoDescriptor().getGoal() + File.separator + mojoExecution.getExecutionId(); File mojoStatusDir = new File( buildOutputDirectory, mojoStatusPath ); if ( !mojoStatusDir.exists() ) { mojoStatusDir.mkdirs(); } return mojoStatusDir; }
String computeSourceOutputDir(@Nullable File target) { String output; if (target != null) { output = target.getAbsolutePath(); } else { String phase = execution.getLifecyclePhase(); String buildDirectory = project.getBuild().getDirectory(); if (GENERATE_TEST_SOURCES.id().equals(phase)) { output = buildDirectory + GENERATED_TEST_SOURCES; } else { output = buildDirectory + GENERATED_SOURCES; } } LOGGER.debug("output = {}", output); return output; }
if (GENERATE_TEST_SOURCES_PHASE.equals(execution.getLifecyclePhase())) project.addTestCompileSourceRoot(m.getOutputDir().getAbsolutePath()); project.addCompileSourceRoot(m.getOutputDir().getAbsolutePath()); if (GENERATE_TEST_SOURCES_PHASE.equals(execution.getLifecyclePhase())) project.addTestCompileSourceRoot(m.getOutputDir().getAbsolutePath());
Path getSourcePath() { if (source != null) { return source.toPath(); } String phase = execution.getLifecyclePhase(); String basedir; basedir = getCanonicalPath(project.getBasedir()); String sourcePath; if (GENERATE_TEST_SOURCES.id().equals(phase)) { sourcePath = basedir + "/src/test/proto/"; } else { sourcePath = basedir + "/src/main/proto/"; } return Paths.get(sourcePath); }
plugin.setVersion(DATANUCLEUS_VERSION); plugin.addDependency(enhancer_api.equals("JDO") ? JDO_DEPENDENCY : JPA_DEPENDENCY); for (Dependency transitiveDep : project.getDependencies()) { plugin.addDependency(transitiveDep); project.getRemotePluginRepositories(), session.getRepositorySession()); } catch (PluginNotFoundException | PluginResolutionException | PluginDescriptorParsingException | InvalidPluginDescriptorException e) { MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo("enhance"); convertPlexusConfiguration(mojoDescriptor.getMojoConfiguration())); MojoExecution exec = new MojoExecution(mojoDescriptor, configuration);
throws Exception, ComponentConfigurationException MavenProject project = session.getCurrentProject(); MojoDescriptor mojoDescriptor = execution.getMojoDescriptor(); Mojo mojo = (Mojo) lookup( mojoDescriptor.getRole(), mojoDescriptor.getRoleHint() ); Plugin plugin = project.getPlugin( mojoDescriptor.getPluginDescriptor().getPluginLookupKey() ); if ( plugin != null ) configuration = Xpp3Dom.mergeXpp3Dom( configuration, execution.getConfiguration() );
throws LifecycleExecutionException MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); mavenPluginManager.checkRequiredMavenVersion( mojoDescriptor.getPluginDescriptor() ); throw new LifecycleExecutionException( mojoExecution, session.getCurrentProject(), e ); if ( mojoDescriptor.isProjectRequired() && !session.getRequest().isProjectPresent() ) + session.getExecutionRootDirectory() + ")." + " Please verify you invoked Maven from the correct directory." ); throw new LifecycleExecutionException( mojoExecution, null, cause ); if ( mojoDescriptor.isOnlineRequired() && session.isOffline() ) if ( MojoExecution.Source.CLI.equals( mojoExecution.getSource() ) ) forkedProject.setExecutionProject( null );
public <T> T getConfiguredMojo( Class<T> mojoInterface, MavenSession session, MojoExecution mojoExecution ) throws PluginConfigurationException, PluginContainerException MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor(); ClassRealm pluginRealm = pluginDescriptor.getClassRealm(); logger.debug( "Configuring mojo " + mojoDescriptor.getId() + " from plugin realm " + pluginRealm ); mojo = container.lookup( mojoInterface, mojoDescriptor.getRoleHint() ); PrintStream ps = new PrintStream( os ); ps.println( "Unable to load the mojo '" + mojoDescriptor.getGoal() + "' in the plugin '" + pluginDescriptor.getId() + "'. A required class is missing: " + cause.getMessage() ); pluginRealm.display( ps ); MavenProject project = session.getCurrentProject(); Map<String, Object> pluginContext = session.getPluginContext( pluginDescriptor, project ); Xpp3Dom dom = mojoExecution.getConfiguration();
InvalidPluginDescriptorException, PluginVersionResolutionException MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor(); String forkedLifecycle = mojoDescriptor.getExecuteLifecycle(); lifecycleOverlay = pluginDescriptor.getLifecycleMapping( forkedLifecycle ); throw new PluginDescriptorParsingException( pluginDescriptor.getPlugin(), pluginDescriptor.getSource(), e ); new MojoExecution( forkedMojoDescriptor, mojoExecution.getExecutionId() ); forkedExecution.setConfiguration( forkedConfiguration ); Xpp3Dom forkedConfiguration = forkedExecution.getConfiguration(); forkedExecution.setConfiguration( forkedConfiguration );
private void debugMojoExecution( MojoExecution mojoExecution ) { String mojoExecId = mojoExecution.getGroupId() + ':' + mojoExecution.getArtifactId() + ':' + mojoExecution.getVersion() + ':' + mojoExecution.getGoal() + " (" + mojoExecution.getExecutionId() + ')'; Map<String, List<MojoExecution>> forkedExecutions = mojoExecution.getForkedExecutions(); if ( !forkedExecutions.isEmpty() ) { for ( Map.Entry<String, List<MojoExecution>> fork : forkedExecutions.entrySet() ) { logger.debug( "--- init fork of " + fork.getKey() + " for " + mojoExecId + " ---" ); debugDependencyRequirements( fork.getValue() ); for ( MojoExecution forkedExecution : fork.getValue() ) { debugMojoExecution( forkedExecution ); } logger.debug( "--- exit fork of " + fork.getKey() + " for " + mojoExecId + " ---" ); } } logger.debug( "-----------------------------------------------------------------------" ); logger.debug( "Goal: " + mojoExecId ); logger.debug( "Style: " + ( mojoExecution.getMojoDescriptor().isAggregator() ? "Aggregating" : "Regular" ) ); logger.debug( "Configuration: " + mojoExecution.getConfiguration() ); }
@Override public void configure( MavenProject project, MojoExecution mojoExecution, boolean allowPluginLevelConfig ) { String g = mojoExecution.getGroupId(); String a = mojoExecution.getArtifactId(); Plugin plugin = findPlugin( g, a, project.getBuildPlugins() ); if ( plugin == null && project.getPluginManagement() != null ) { plugin = findPlugin( g, a, project.getPluginManagement().getPlugins() ); } if ( plugin != null ) { PluginExecution pluginExecution = findPluginExecution( mojoExecution.getExecutionId(), plugin.getExecutions() ); Xpp3Dom pomConfiguration = null; if ( pluginExecution != null ) { pomConfiguration = (Xpp3Dom) pluginExecution.getConfiguration(); } else if ( allowPluginLevelConfig ) { pomConfiguration = (Xpp3Dom) plugin.getConfiguration(); } Xpp3Dom mojoConfiguration = ( pomConfiguration != null ) ? new Xpp3Dom( pomConfiguration ) : null; mojoConfiguration = Xpp3Dom.mergeXpp3Dom( mojoExecution.getConfiguration(), mojoConfiguration ); mojoExecution.setConfiguration( mojoConfiguration ); } }
private String mojoExec(ExecutionEvent event) { MojoExecution me = event.getMojoExecution(); return String.format("%s:%s:%s(%s)", me.getGroupId(), me.getArtifactId(), me.getVersion(), me.getExecutionId()); } }
/** * Returns conventional MojoExecution identifier used by incremental build tools. */ public String getExecutionId(MojoExecution execution) { PluginDescriptor pluginDescriptor = execution.getMojoDescriptor().getPluginDescriptor(); StringBuilder builderId = new StringBuilder(); builderId.append(pluginDescriptor.getGroupId()).append('_') .append(pluginDescriptor.getArtifactId()); builderId.append('_').append(execution.getGoal()).append('_') .append(execution.getExecutionId()); return builderId.toString(); }
LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); String forkedPhase = mojoDescriptor.getExecutePhase(); if ( forkedExecution.getMojoDescriptor() == null ) pluginManager.getMojoDescriptor( forkedExecution.getPlugin(), forkedExecution.getGoal(), project.getRemotePluginRepositories(), session.getRepositorySession() ); forkedExecution.setMojoDescriptor( forkedMojoDescriptor ); if ( !alreadyForkedExecutions.contains( forkedExecution.getMojoDescriptor() ) )