org.apache.maven.plugin.BuildPluginManager#org.apache.maven.model.Plugin源码实例Demo

下面列出了org.apache.maven.plugin.BuildPluginManager#org.apache.maven.model.Plugin 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jax-maven-plugin   文件: Util.java
static Stream<String> getPluginRuntimeDependencyEntries(AbstractMojo mojo, MavenProject project, Log log,
        RepositorySystem repositorySystem, ArtifactRepository localRepository,
        List<ArtifactRepository> remoteRepositories) {
    PluginDescriptor pluginDescriptor = (PluginDescriptor) mojo.getPluginContext().get(PLUGIN_DESCRIPTOR);
    Plugin plugin = project.getBuild().getPluginsAsMap().get(pluginDescriptor.getPluginLookupKey());

    List<ArtifactResolutionResult> artifactResolutionResults = plugin //
            .getDependencies() //
            .stream() //
            .map(repositorySystem::createDependencyArtifact) //
            .map(a -> Util.resolve(log, a, repositorySystem, localRepository, remoteRepositories)) //
            .collect(Collectors.toList());

    Stream<Artifact> originalArtifacts = artifactResolutionResults.stream()
            .map(ArtifactResolutionResult::getOriginatingArtifact);

    Stream<Artifact> childArtifacts = artifactResolutionResults.stream()
            .flatMap(resolutionResult -> resolutionResult.getArtifactResolutionNodes().stream())
            .map(ResolutionNode::getArtifact);

    return Stream.concat(originalArtifacts, childArtifacts).map(Artifact::getFile).map(File::getAbsolutePath);
}
 
源代码2 项目: jkube   文件: MavenConfigurationExtractorTest.java
@Test
public void should_parse_inner_objects() {

    // Given
    final Plugin fakePlugin = createFakePlugin("<a>"
        + "<b>b</b>"
        + "</a>");

    // When
    final Map<String, Object> config = MavenConfigurationExtractor.extract((Xpp3Dom) fakePlugin.getConfiguration());

    // Then
    final Map<String, Object> expected = new HashMap<>();
    expected.put("b", "b");
    assertEquals(expected, config.get("a"));
}
 
源代码3 项目: jkube   文件: MavenConfigurationExtractorTest.java
@Test
public void should_parse_list_of_elements() {

    // Given
    final Plugin fakePlugin = createFakePlugin("<a>"
        + "<b>"
        + "<c>c1</c><c>c2</c>"
        + "</b>"
        + "</a>");

    // When
    final Map<String, Object> config = MavenConfigurationExtractor.extract((Xpp3Dom) fakePlugin.getConfiguration());

    // Then
    final Map<String, Object> expectedC = new HashMap<>();
    expectedC.put("c", Arrays.asList("c1", "c2"));
    final Map<String, Object> expected = new HashMap<>();
    expected.put("b", expectedC);

    assertEquals(expected, config.get("a"));

}
 
@Test
public void projectDeploySkipTurnedOffWhenModeIsOff()
    throws Exception
{
    final Plugin plugin = new Plugin();
    plugin.setGroupId( MAVEN_PLUGIN_GROUPID );
    plugin.setArtifactId( MAVEN_DEPLOY_ARTIFACTID );
    plugin.setConfiguration( simpleSkipConfig( true ) );

    final Build build = new Build();
    build.addPlugin( plugin );

    final Model model = new Model();
    model.setModelVersion( "4.0.0" );
    model.setGroupId( "org.foo" );
    model.setArtifactId( "bar" );
    model.setVersion( "1" );

    model.setBuild( build );

    applyTest( off, model, model );
    assertSkip( model, null );
}
 
@Test
public void projectUnchangedWhenModeIsNone()
    throws Exception
{
    final Plugin plugin = new Plugin();
    plugin.setGroupId( MAVEN_PLUGIN_GROUPID );
    plugin.setArtifactId( MAVEN_DEPLOY_ARTIFACTID );
    plugin.setConfiguration( simpleSkipConfig( true ) );

    final Build build = new Build();
    build.addPlugin( plugin );

    final Model model = new Model();
    model.setModelVersion( "4.0.0" );
    model.setGroupId( "org.foo" );
    model.setArtifactId( "bar" );
    model.setVersion( "1" );

    model.setBuild( build );

    applyTest( none, model, null );
}
 
/**
 * Download a plugin, all of its transitive dependencies and dependencies declared on the plugin declaration.
 * <p>
 * Dependencies and plugin artifacts that refer to an artifact in the current reactor build are ignored.
 * Transitive dependencies that are marked as optional are ignored
 * Transitive dependencies with the scopes "test", "system" and "provided" are ignored.
 *
 * @param plugin the plugin to download
 */
public Set<ArtifactWithRepoType> resolvePlugin(Plugin plugin) {
    Artifact pluginArtifact = toArtifact(plugin);
    Dependency pluginDependency = new Dependency(pluginArtifact, null);
    CollectRequest collectRequest = new CollectRequest(pluginDependency, pluginRepositories);
    collectRequest.setRequestContext(RepositoryType.PLUGIN.getRequestContext());

    List<Dependency> pluginDependencies = new ArrayList<>();
    for (org.apache.maven.model.Dependency d : plugin.getDependencies()) {
        Dependency dependency = RepositoryUtils.toDependency(d, typeRegistry);
        pluginDependencies.add(dependency);
    }
    collectRequest.setDependencies(pluginDependencies);

    try {
        CollectResult collectResult = repositorySystem.collectDependencies(pluginSession, collectRequest);
        return getArtifactsFromCollectResult(collectResult, RepositoryType.PLUGIN);
    } catch (DependencyCollectionException | RuntimeException e) {
        log.error("Error resolving plugin " + plugin.getGroupId() + ":" + plugin.getArtifactId());
        handleRepositoryException(e);
    }
    return Collections.emptySet();
}
 
@Test
public void findReturnsValueWhenSecondEnforcerExecutionIsValidAndFirstEnforcerExecutionHasNoRulesTag() {
    String mavenVersionRange = "1.0";
    ArrayList<Plugin> buildPlugins = new ArrayList<>();
    buildPlugins.add(enforcerPlugin);
    when(mavenProject.getBuildPlugins()).thenReturn(buildPlugins);
    ArrayList<PluginExecution> pluginExecutions = new ArrayList<>();
    pluginExecutions.add(otherPluginExecution);
    pluginExecutions.add(pluginExecution);
    ArrayList<String> goals = new ArrayList<>();
    ArrayList<String> otherGoals = new ArrayList<>();
    goals.add("enforce");
    otherGoals.add("enforce");
    when(pluginExecution.getGoals()).thenReturn(goals);
    when(otherPluginExecution.getGoals()).thenReturn(otherGoals);
    when(enforcerPlugin.getExecutions()).thenReturn(pluginExecutions);
    when(pluginExecution.getConfiguration()).thenReturn(configurationTag);
    when(otherPluginExecution.getConfiguration()).thenReturn(otherConfigurationTag);
    when(configurationTag.getChild("rules")).thenReturn(rulesTag);
    when(otherConfigurationTag.getChild("rules")).thenReturn(null);
    when(rulesTag.getChild("requireMavenVersion")).thenReturn(requireMavenVersionTag);
    when(requireMavenVersionTag.getChild("version")).thenReturn(versionTag);
    when(versionTag.getValue()).thenReturn(mavenVersionRange);
    DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion(mavenVersionRange);
    assertEquals(artifactVersion, new RequiredMavenVersionFinder(mavenProject).find());
}
 
源代码8 项目: developer-studio   文件: MavenUtils.java
public static void addMavenBpelPlugin(MavenProject mavenProject){
		Plugin plugin;
		
		PluginExecution pluginExecution;
		plugin = MavenUtils.createPluginEntry(mavenProject, GROUP_ID_ORG_WSO2_MAVEN, ARTIFACT_ID_MAVEN_BPEL_PLUGIN,
				WSO2MavenPluginVersions.getPluginVersion(ARTIFACT_ID_MAVEN_BPEL_PLUGIN), true);
		// FIXME : remove hard-coded version value (cannot use
		// org.wso2.developerstudio.eclipse.capp.maven.utils.MavenConstants
		// due to cyclic reference)
//		pluginExecution=new PluginExecution();
//		pluginExecution.addGoal("bpel");
//		pluginExecution.setPhase("package");
//		pluginExecution.setId("bpel");
//		plugin.addExecution(pluginExecution)
		
		mavenProject.getModel().addProperty(PROPERTY_CAPP_TYPE, "bpel/workflow");
	}
 
/**
 * Get the GWT Maven plugin 2 <moduleName/>.
 *
 * @param mavenProject
 * @return the moduleName from configuration
 */
private String getGwtModuleName(MavenProject mavenProject) {
  if (!isGwtMavenPlugin2(mavenProject)) {
    return null;
  }

  Plugin gwtPlugin2 = getGwtMavenPlugin2(mavenProject);
  if (gwtPlugin2 == null) {
    return null;
  }

  Xpp3Dom gwtPluginConfig = (Xpp3Dom) gwtPlugin2.getConfiguration();
  if (gwtPluginConfig == null) {
    return null;
  }

  String moduleName = null;
  for (Xpp3Dom child : gwtPluginConfig.getChildren()) {
    if (child != null && GWT_MAVEN_MODULENAME.equals(child.getName())) {
      moduleName = child.getValue().trim();
    }
  }
  return moduleName;
}
 
/**
 * Returns the list of <tt>requirePropertyDiverges</tt> configurations from the map of plugins.
 *
 * @param plugins
 * @return list of requirePropertyDiverges configurations.
 */
List<Xpp3Dom> getRuleConfigurations( final Map<String, Plugin> plugins )
{
    if ( plugins.containsKey( MAVEN_ENFORCER_PLUGIN ) )
    {
        final List<Xpp3Dom> ruleConfigurations = new ArrayList<Xpp3Dom>();

        final Plugin enforcer = plugins.get( MAVEN_ENFORCER_PLUGIN );
        final Xpp3Dom configuration = ( Xpp3Dom ) enforcer.getConfiguration();

        // add rules from plugin configuration
        addRules( configuration, ruleConfigurations );

        // add rules from all plugin execution configurations
        for ( Object execution : enforcer.getExecutions() )
        {
            addRules( ( Xpp3Dom ) ( ( PluginExecution ) execution ).getConfiguration(), ruleConfigurations );
        }

        return ruleConfigurations;
    }
    else
    {
        return new ArrayList();
    }
}
 
源代码11 项目: repairnator   文件: ComputePlugins.java
@Override
protected StepStatus businessExecute() {
    this.getLogger().debug("Computing project plugins...");

    String mainPomPath = this.getPom();
    List<Plugin> plugins = this.findPlugins(mainPomPath);

    if (plugins == null) {
        this.getLogger().info("No plugins was found.");
        return StepStatus.buildError(this, PipelineState.PLUGINSNOTCOMPUTED);
    } else if (plugins.size() == 0) {
        this.getLogger().info("No plugins was found.");
    }
    this.getInspector().getJobStatus().setPlugins(plugins);
    this.getInspector().getJobStatus().getProperties().getProjectMetrics().setNumberPlugins(plugins.size());
    return StepStatus.buildSuccess(this);
}
 
/**
 * Searches the Maven pom.xml for the given project nature.
 *
 * @param mavenProject a description of the Maven project
 * @param natureId the nature to check
 * @return {@code true} if the project
 */
protected boolean hasProjectNature(MavenProject mavenProject, String natureId) {
  if (natureId == GWTNature.NATURE_ID || getGwtMavenPlugin(mavenProject) != null) {
    return true;
  }
  // The use of the maven-eclipse-plugin is deprecated. The following code is
  // only for backward compatibility.
  Plugin plugin = getEclipsePlugin(mavenProject);
  if (plugin != null) {
    Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
    if (configuration != null) {
      Xpp3Dom additionalBuildCommands = configuration.getChild("additionalProjectnatures");
      if (additionalBuildCommands != null) {
        for (Xpp3Dom projectNature : additionalBuildCommands.getChildren("projectnature")) {
          if (projectNature != null && natureId.equals(projectNature.getValue())) {
            return true;
          }
        }
      }
    }
  }
  return false;
}
 
源代码13 项目: netbeans   文件: PluginPropertyUtils.java
/** @see org.apache.maven.lifecycle.internal.DefaultLifecycleExecutionPlanCalculator */
private static @NonNull List<PluginExecution> getPluginExecutions(@NonNull Plugin plug, @NullAllowed String goal) {
    if (goal == null) {
        return Collections.emptyList();
    }
    List<PluginExecution> exes = new ArrayList<PluginExecution>();
    for (PluginExecution exe : plug.getExecutions()) {
        if (exe.getGoals().contains(goal) || /* #179328: Maven 2.2.0+ */ ("default-" + goal).equals(exe.getId())) {
            exes.add(exe);
        }
    }
    Collections.sort(exes, new Comparator<PluginExecution>() {
        @Override public int compare(PluginExecution e1, PluginExecution e2) {
            return e2.getPriority() - e1.getPriority();
        }
    });
    return exes;
}
 
源代码14 项目: netbeans   文件: NbPluginDependenciesResolver.java
@Override
public Artifact resolve(Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session) throws PluginResolutionException {
    WorkspaceReader wr = session.getWorkspaceReader();
    NbWorkspaceReader nbwr = null;
    if (wr instanceof NbWorkspaceReader) {
        nbwr = (NbWorkspaceReader)wr;
        //this only works reliably because the NbWorkspaceReader is part of the session, not a component
        nbwr.silence();
    }
    try {
        return super.resolve(plugin, repositories, session);
    } finally {
        if (nbwr != null) {
            nbwr.normal();
        }
    }
}
 
源代码15 项目: netbeans   文件: NbPluginDependenciesResolver.java
@Override
public DependencyNode resolve(Plugin plugin, Artifact pluginArtifact, DependencyFilter dependencyFilter, List<RemoteRepository> repositories, RepositorySystemSession session) throws PluginResolutionException {
    
    WorkspaceReader wr = session.getWorkspaceReader();
    NbWorkspaceReader nbwr = null;
    if (wr instanceof NbWorkspaceReader) {
        nbwr = (NbWorkspaceReader)wr;
        //this only works reliably because the NbWorkspaceReader is part of the session, not a component
        nbwr.silence();
    }
    try {
        return super.resolve(plugin, pluginArtifact, dependencyFilter, repositories, session);
    } finally {
        if (nbwr != null) {
            nbwr.normal();
        }
    }
}
 
/**
 * Test of execute method, of class RequirePropertyDiverges.
 */
@Test
public void testExecuteInParentWithConfigurationInPluginManagement() throws EnforcerRuleException
{
    RequirePropertyDiverges mockInstance = createMockRule();
    final MavenProject project = createMavenProject( "company", "company-parent-pom" );
    final Build build = new Build();
    // create pluginManagement
    final Plugin pluginInManagement = newPlugin( "org.apache.maven.plugins", "maven-enforcer-plugin", "1.0");
    final Xpp3Dom configuration = createPluginConfiguration();
    pluginInManagement.setConfiguration( configuration );
    final PluginManagement pluginManagement = new PluginManagement();
    pluginManagement.addPlugin( pluginInManagement );
    build.setPluginManagement( pluginManagement );
    // create plugins
    final Plugin pluginInPlugins = newPlugin( "org.apache.maven.plugins", "maven-enforcer-plugin", "1.0");
    build.addPlugin( pluginInPlugins );
    // add build
    project.getOriginalModel().setBuild( build );
    //project.getOriginalModel().setBuild( build );
    setUpHelper( project, "parentValue" );
    mockInstance.execute( helper );
}
 
源代码17 项目: smart-testing   文件: CustomProvidersTest.java
@Test
public void should_remove_custom_provider_dependency_and_create_info_file_when_set_in_config() {
    // given
    Configuration config = ConfigurationLoader.load(tmpFolder);
    config.setCustomProviders(new String[] {"org.foo.provider:my-custom-provider=org.foo.impl.SurefireProvider"});
    DependencyResolver dependencyResolver = new DependencyResolver(config);
    Dependency customDep = createDependency("org.foo.provider", "my-custom-provider", "1.2.3");
    Model model = Mockito.mock(Model.class);
    Plugin plugin = prepareModelWithPluginDep(model, customDep);

    // when
    dependencyResolver.removeAndRegisterFirstCustomProvider(model, plugin);

    // then
    verifyDependencyIsRemovedAndFileCreated(plugin, customDep, "org.foo.impl.SurefireProvider");
}
 
/**
 * Returns the rule configurations from the <tt>pluginManagement</tt> as well
 * as the <tt>plugins</tt> section.
 *
 * @param build the build to inspect.
 * @return configuration of the rules, may be an empty list.
 */
final List<Xpp3Dom> getRuleConfigurations( final Build build )
{
    @SuppressWarnings( "unchecked" )
    final Map<String, Plugin> plugins = build.getPluginsAsMap();
    final List<Xpp3Dom> ruleConfigurationsForPlugins = getRuleConfigurations( plugins );
    final PluginManagement pluginManagement = build.getPluginManagement();
    if ( pluginManagement != null )
    {
        @SuppressWarnings( "unchecked" )
        final Map<String, Plugin> pluginsFromManagementAsMap = pluginManagement.getPluginsAsMap();
        List<Xpp3Dom> ruleConfigurationsFromManagement = getRuleConfigurations( pluginsFromManagementAsMap );
        ruleConfigurationsForPlugins.addAll( ruleConfigurationsFromManagement );
    }
    return ruleConfigurationsForPlugins;
}
 
/**
 * Get the GWT Maven plugin 2 <moduleShort=Name/>.
 *
 * @param mavenProject
 * @return the moduleName from configuration
 */
private String getGwtModuleShortName(MavenProject mavenProject) {
  if (!isGwtMavenPlugin2(mavenProject)) {
    return null;
  }

  Plugin gwtPlugin2 = getGwtMavenPlugin2(mavenProject);
  if (gwtPlugin2 == null) {
    return null;
  }

  Xpp3Dom gwtPluginConfig = (Xpp3Dom) gwtPlugin2.getConfiguration();
  if (gwtPluginConfig == null) {
    return null;
  }

  String moduleName = null;
  for (Xpp3Dom child : gwtPluginConfig.getChildren()) {
    if (child != null && GWT_MAVEN_MODULESHORTNAME.equals(child.getName())) {
      moduleName = child.getValue().trim();
    }
  }
  return moduleName;
}
 
源代码20 项目: jkube   文件: MavenConfigurationExtractorTest.java
@Test
public void should_parse_simple_types() {

    // Given
    final Plugin fakePlugin = createFakePlugin("<a>a</a><b>b</b>");

    // When
    final Map<String, Object> config = MavenConfigurationExtractor.extract((Xpp3Dom) fakePlugin.getConfiguration());

    // Then
    assertEquals("a", config.get("a"));
    assertEquals("b", config.get("b"));
}
 
private Map<String, Plugin> getManagedPluginMap( final ModelBase base )
{
    if ( base instanceof Model )
    {
        final Build build = ( (Model) base ).getBuild();
        if ( build == null )
        {
            return Collections.emptyMap();
        }

        final PluginManagement pm = build.getPluginManagement();
        if ( pm == null )
        {
            return Collections.emptyMap();
        }

        final Map<String, Plugin> result = pm.getPluginsAsMap();
        if ( result == null )
        {
            return Collections.emptyMap();
        }

        return result;
    }

    return Collections.emptyMap();
}
 
源代码22 项目: ci.maven   文件: DevMojo.java
/**
 * Executes Maven goal passed but sets failOnError to false
 * All errors are logged as warning messages
 * 
 * @param goal Maven compile goal
 * @throws MojoExecutionException
 */
private void runCompileMojo(String goal) throws MojoExecutionException {
    Plugin plugin = getPlugin("org.apache.maven.plugins", "maven-compiler-plugin");
    Xpp3Dom config = ExecuteMojoUtil.getPluginGoalConfig(plugin, goal, log);
    config = Xpp3Dom.mergeXpp3Dom(configuration(element(name("failOnError"), "false")), config);
    log.info("Running maven-compiler-plugin:" + goal);
    log.debug("configuration:\n" + config);
    executeMojo(plugin, goal(goal), config,
            executionEnvironment(project, session, pluginManager));
}
 
源代码23 项目: pgpverify-maven-plugin   文件: ArtifactResolver.java
private boolean matchSurefireVersion(Plugin plugin) {

        return Try.of(() -> repositorySystem.createPluginArtifact(plugin).getSelectedVersion())
                .map(SUREFIRE_PLUGIN_VERSION_RANGE::containsVersion)
                .onFailure(e -> LOG.debug("Found build plug-in with overly constrained version specification.", e))
                .getOrElse(false);
    }
 
源代码24 项目: boost   文件: RuntimeParams.java
public RuntimeParams(List<AbstractBoosterConfig> boosterConfigs, Properties boostProperties, ExecutionEnvironment env, MavenProject project,
        Log log, RepositorySystem repoSystem, RepositorySystemSession repoSession,
        List<RemoteRepository> remoteRepos, Plugin mavenDepPlugin) {
    this.log = log;
    this.boosterConfigs = boosterConfigs;
    this.boostProperties = boostProperties;
    this.env = env;
    this.project = project;
    this.projectBuildDir = project.getBuild().getDirectory();
    this.repoSystem = repoSystem;
    this.repoSession = repoSession;
    this.remoteRepos = remoteRepos;
    this.mavenDepPlugin = mavenDepPlugin;
}
 
源代码25 项目: pom-manipulation-ext   文件: PluginState.java
public void setRemoteRESTOverrides( Map<ArtifactRef, String> overrides )
{
    for ( ArtifactRef a : overrides.keySet() )
    {
        Plugin p = new Plugin();
        p.setGroupId( a.getGroupId() );
        p.setArtifactId( a.getArtifactId() );
        p.setVersion( overrides.get( a ) );
        remoteRESTplugins.add( p );
    }
}
 
@Test
public void findReturnsValueWhenSecondEnforcerExecutionIsValidAndFirstEnforcerExecutionHasNoRequireMavenVersionTag() {
    String mavenVersionRange = "1.0";
    ArrayList<Plugin> buildPlugins = new ArrayList<>();
    buildPlugins.add(enforcerPlugin);
    when(mavenProject.getBuildPlugins()).thenReturn(buildPlugins);
    ArrayList<PluginExecution> pluginExecutions = new ArrayList<>();
    pluginExecutions.add(otherPluginExecution);
    pluginExecutions.add(pluginExecution);
    ArrayList<String> goals = new ArrayList<>();
    ArrayList<String> otherGoals = new ArrayList<>();
    goals.add("enforce");
    otherGoals.add("enforce");
    when(pluginExecution.getGoals()).thenReturn(goals);
    when(otherPluginExecution.getGoals()).thenReturn(otherGoals);
    when(enforcerPlugin.getExecutions()).thenReturn(pluginExecutions);
    when(pluginExecution.getConfiguration()).thenReturn(configurationTag);
    when(otherPluginExecution.getConfiguration()).thenReturn(otherConfigurationTag);
    when(configurationTag.getChild("rules")).thenReturn(rulesTag);
    when(otherConfigurationTag.getChild("rules")).thenReturn(otherRulesTag);
    when(rulesTag.getChild("requireMavenVersion")).thenReturn(requireMavenVersionTag);
    when(otherRulesTag.getChild("requireMavenVersion")).thenReturn(null);
    when(requireMavenVersionTag.getChild("version")).thenReturn(versionTag);
    when(versionTag.getValue()).thenReturn(mavenVersionRange);
    DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion(mavenVersionRange);
    assertEquals(artifactVersion, new RequiredMavenVersionFinder(mavenProject).find());
}
 
源代码27 项目: vertx-maven-plugin   文件: MojoUtils.java
/**
 * Execute the Maven Compiler Plugin to compile java sources.
 *
 * @param project            the project
 * @param mavenSession       the session
 * @param buildPluginManager the build plugin manager
 * @throws Exception if the compilation fails for any reason
 */
public static void compile(MavenProject project, MavenSession mavenSession,
                           BuildPluginManager buildPluginManager) throws Exception {

    Optional<Plugin> mvnCompilerPlugin = project.getBuildPlugins().stream()
        .filter(plugin -> A_MAVEN_COMPILER_PLUGIN.equals(plugin.getArtifactId()))
        .findFirst();

    String pluginVersion = properties.getProperty(V_MAVEN_COMPILER_PLUGIN);

    if (mvnCompilerPlugin.isPresent()) {
        pluginVersion = mvnCompilerPlugin.get().getVersion();
    }

    Optional<Xpp3Dom> optConfiguration = buildConfiguration(project, A_MAVEN_COMPILER_PLUGIN, GOAL_COMPILE);

    if (optConfiguration.isPresent()) {

        Xpp3Dom configuration = optConfiguration.get();

        executeMojo(
            plugin(G_MAVEN_COMPILER_PLUGIN, A_MAVEN_COMPILER_PLUGIN, pluginVersion),
            goal(GOAL_COMPILE),
            configuration,
            executionEnvironment(project, mavenSession, buildPluginManager)
        );
    }
}
 
源代码28 项目: vertx-maven-plugin   文件: MojoUtils.java
/**
 * Executes the Maven Resource Plugin to copy resources to `target/classes`
 *
 * @param project            the project
 * @param mavenSession       the maven session
 * @param buildPluginManager the build plugin manager
 * @throws MojoExecutionException if the copy cannot be completed successfully
 */
public static void copyResources(MavenProject project, MavenSession mavenSession,
                                 BuildPluginManager buildPluginManager) throws MojoExecutionException {

    Optional<Plugin> resourcesPlugin = hasPlugin(project, RESOURCES_PLUGIN_KEY);

    Xpp3Dom pluginConfig = configuration(element("outputDirectory", "${project.build.outputDirectory}"));

    if (resourcesPlugin.isPresent()) {

        Optional<Xpp3Dom> optConfiguration = buildConfiguration(project, A_MAVEN_RESOURCES_PLUGIN, GOAL_RESOURCES);

        if (optConfiguration.isPresent()) {
            pluginConfig = optConfiguration.get();
        }

        executeMojo(
            resourcesPlugin.get(),
            goal(GOAL_RESOURCES),
            pluginConfig,
            executionEnvironment(project, mavenSession, buildPluginManager)
        );

    } else {
        executeMojo(
            plugin(G_MAVEN_RESOURCES_PLUGIN, A_MAVEN_RESOURCES_PLUGIN,
                properties.getProperty(V_MAVEN_RESOURCES_PLUGIN)),
            goal(GOAL_RESOURCES),
            pluginConfig,
            executionEnvironment(project, mavenSession, buildPluginManager)
        );
    }

}
 
源代码29 项目: docker-maven-plugin   文件: MojoExecutionService.java
public void callPluginGoal(String fullGoal) throws MojoFailureException, MojoExecutionException {
    String[] parts = splitGoalSpec(fullGoal);
    Plugin plugin = project.getPlugin(parts[0]);
    String goal = parts[1];

    if (plugin == null) {
        throw new MojoFailureException("No goal " + fullGoal + " found in pom.xml");
    }

    try {
        String executionId = null;
        if (goal != null && goal.length() > 0 && goal.indexOf('#') > -1) {
            int pos = goal.indexOf('#');
            executionId = goal.substring(pos + 1);
            goal = goal.substring(0, pos);
        }

        PluginDescriptor pluginDescriptor = getPluginDescriptor(project, plugin);
        MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo(goal);
        if (mojoDescriptor == null) {
            throw new MojoExecutionException("Could not find goal '" + goal + "' in plugin "
                                             + plugin.getGroupId() + ":"
                                             + plugin.getArtifactId() + ":"
                                             + plugin.getVersion());
        }
        MojoExecution exec = getMojoExecution(executionId, mojoDescriptor);
        pluginManager.executeMojo(session, exec);
    } catch (Exception e) {
        throw new MojoExecutionException("Unable to execute mojo", e);
    }
}
 
源代码30 项目: vertx-maven-plugin   文件: MojoUtils.java
/**
 * Execute the Maven Compiler Plugin to compile java sources.
 *
 * @param project            the project
 * @param mavenSession       the session
 * @param buildPluginManager the build plugin manager
 * @throws Exception if the compilation fails for any reason
 */
public static void compile(MavenProject project, MavenSession mavenSession,
                           BuildPluginManager buildPluginManager) throws Exception {

    Optional<Plugin> mvnCompilerPlugin = project.getBuildPlugins().stream()
        .filter(plugin -> A_MAVEN_COMPILER_PLUGIN.equals(plugin.getArtifactId()))
        .findFirst();

    String pluginVersion = properties.getProperty(V_MAVEN_COMPILER_PLUGIN);

    if (mvnCompilerPlugin.isPresent()) {
        pluginVersion = mvnCompilerPlugin.get().getVersion();
    }

    Optional<Xpp3Dom> optConfiguration = buildConfiguration(project, A_MAVEN_COMPILER_PLUGIN, GOAL_COMPILE);

    if (optConfiguration.isPresent()) {

        Xpp3Dom configuration = optConfiguration.get();

        executeMojo(
            plugin(G_MAVEN_COMPILER_PLUGIN, A_MAVEN_COMPILER_PLUGIN, pluginVersion),
            goal(GOAL_COMPILE),
            configuration,
            executionEnvironment(project, mavenSession, buildPluginManager)
        );
    }
}