org.apache.maven.model.Plugin Java Examples

The following examples show how to use org.apache.maven.model.Plugin. 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: MavenUtils.java    From developer-studio with Apache License 2.0 6 votes vote down vote up
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");
	}
 
Example #2
Source File: DistributionEnforcingManipulatorTest.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
@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 );
}
 
Example #3
Source File: PluginPropertyUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** @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;
}
 
Example #4
Source File: NbPluginDependenciesResolver.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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();
        }
    }
}
 
Example #5
Source File: NbPluginDependenciesResolver.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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();
        }
    }
}
 
Example #6
Source File: MavenConfigurationExtractorTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@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"));

}
 
Example #7
Source File: MavenConfigurationExtractorTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@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"));
}
 
Example #8
Source File: RequirePropertyDivergesTest.java    From extra-enforcer-rules with Apache License 2.0 6 votes vote down vote up
/**
 * 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 );
}
 
Example #9
Source File: DistributionEnforcingManipulatorTest.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
@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 );
}
 
Example #10
Source File: AbstracMavenProjectConfigurator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #11
Source File: DependencyDownloader.java    From go-offline-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #12
Source File: ComputePlugins.java    From repairnator with MIT License 6 votes vote down vote up
@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);
}
 
Example #13
Source File: RequiredMavenVersionFinderTest.java    From versions-maven-plugin with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #14
Source File: MavenProjectConfigurator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #15
Source File: RequirePropertyDiverges.java    From extra-enforcer-rules with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
    }
}
 
Example #16
Source File: Util.java    From jax-maven-plugin with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #17
Source File: CustomProvidersTest.java    From smart-testing with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #18
Source File: RequirePropertyDiverges.java    From extra-enforcer-rules with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #19
Source File: MavenProjectConfigurator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #20
Source File: MavenCompilerUtilsTest.java    From pgpverify-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testExtractAnnotationProcessorsNoConfiguration() {
    final RepositorySystem repository = mock(RepositorySystem.class);
    final Plugin plugin = mock(Plugin.class);
    when(plugin.getGroupId()).thenReturn("org.apache.maven.plugins");
    when(plugin.getArtifactId()).thenReturn("maven-compiler-plugin");
    when(plugin.getVersion()).thenReturn("3.8.1");
    assertEquals(extractAnnotationProcessors(repository, plugin), emptySet());
}
 
Example #21
Source File: MojoUtils.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 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)
        );
    }

}
 
Example #22
Source File: MojoExecutionServiceTest.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test(expected = MojoExecutionException.class)
public void noDescriptor() throws Exception {
    new Expectations() {{
        project.getPlugin(PLUGIN_NAME);
        result = new Plugin();
        pluginDescriptor.getMojo(GOAL_NAME);
        result = null;
        executionService.getPluginDescriptor((MavenProject) any, (Plugin) any);
    }};
    executionService.callPluginGoal(PLUGIN_NAME + ":" + GOAL_NAME);

    new Verifications() {{}};
}
 
Example #23
Source File: MavenProjectConfigurator.java    From smart-testing with Apache License 2.0 5 votes vote down vote up
private List<Plugin> getEffectivePlugins(Model model) {
    final List<Plugin> testRunnerPluginConfigurations = model.getBuild().getPlugins()
        .stream()
        .filter(
            plugin -> ApplicablePlugins.contains(plugin.getArtifactId()) && hasMinimumVersionRequired(plugin, model))
        .filter(this::hasPluginSelectionConfigured)
        .collect(Collectors.toList());

    if (areNotApplicableTestingPlugins(testRunnerPluginConfigurations) && isNotPomProject(model)) {
        failBecauseOfMissingApplicablePlugin(model);
    }

    return removePluginsThatAreSkipped(testRunnerPluginConfigurations, model);
}
 
Example #24
Source File: PomUpdater.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
private Boolean skipFromConfiguration(Plugin plugin) {
	if (!(plugin.getConfiguration() instanceof Xpp3Dom)) {
		return false;
	}
	Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
	Xpp3Dom skip = configuration.getChild("skip");
	return skip != null && Boolean.parseBoolean(skip.getValue());
}
 
Example #25
Source File: MavenCompilerUtilsTest.java    From pgpverify-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testExtractAnnotationProcessorsIllegalInputs() {
    assertThrows(NullPointerException.class, () -> extractAnnotationProcessors(null, null));
    final Plugin badPlugin = mock(Plugin.class);
    when(badPlugin.getGroupId()).thenReturn("org.my-bad-plugin");
    when(badPlugin.getArtifactId()).thenReturn("bad-plugin");
    when(badPlugin.getVersion()).thenReturn("1.1.1");
    assertThrows(NullPointerException.class, () -> extractAnnotationProcessors(null, badPlugin));
    final RepositorySystem repository = mock(RepositorySystem.class);
    assertThrows(NullPointerException.class, () -> extractAnnotationProcessors(repository, null));
    assertThrows(IllegalArgumentException.class, () -> extractAnnotationProcessors(repository, badPlugin));
}
 
Example #26
Source File: MojoExecutionServiceTest.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
private void standardSetup() throws Exception {
    new Expectations() {{
        project.getPlugin(PLUGIN_NAME);
        result = new Plugin();
        pluginDescriptor.getMojo(GOAL_NAME);
        result = createPluginDescriptor();

        pluginManager.executeMojo(session, (MojoExecution) any);
        executionService.getPluginDescriptor((MavenProject) any, (Plugin) any);
    }};
}
 
Example #27
Source File: MavenHelper.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Load the given plugin.
 *
 * @param plugin the plugin to load.
 * @return the descriptor of the plugin.
 * @throws MojoExecutionException if something bad append.
 */
public PluginDescriptor loadPlugin(Plugin plugin)
		throws MojoExecutionException {
	try {
		final Object repositorySessionObject = this.getRepositorySessionMethod.invoke(this.session);
		return (PluginDescriptor) this.loadPluginMethod.invoke(
				this.buildPluginManager,
				plugin,
				getSession().getCurrentProject().getRemotePluginRepositories(),
				repositorySessionObject);
	} catch (IllegalAccessException | IllegalArgumentException
			| InvocationTargetException e) {
		throw new MojoExecutionException(e.getLocalizedMessage(), e);
	}
}
 
Example #28
Source File: Project.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
/**
 * This method will scan the plugins in this project including those without a version and return a fully resolved
 * list. Note that while updating the {@link Plugin} reference returned will be reflected in the Model as it is the
 * same object, if you wish to remove or add items to the Model then you must use {@link #getModel()}
 *
 * @param session MavenSessionHandler, used by {@link PropertyResolver}
 * @return a list of fully resolved {@link ProjectVersionRef} to the original {@link Plugin}
 * @throws ManipulationException if an error occurs
 */
public Map<ProjectVersionRef, Plugin> getAllResolvedPlugins ( MavenSessionHandler session) throws ManipulationException
{
    Map<ProjectVersionRef, Plugin> resolvedPlugins = new HashMap<>();

    if ( getModel().getBuild() != null )
    {
        resolvePlugins( session, getModel().getBuild().getPlugins(), PluginResolver.ALL, resolvedPlugins );
    }

    return resolvedPlugins;
}
 
Example #29
Source File: RequiredMavenVersionFinderTest.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void findReturnsNullWhenEnforceGoalConfigurationIsNull() {
    ArrayList<Plugin> buildPlugins = new ArrayList<>();
    buildPlugins.add(enforcerPlugin);
    when(mavenProject.getBuildPlugins()).thenReturn(buildPlugins);
    ArrayList<PluginExecution> pluginExecutions = new ArrayList<>();
    pluginExecutions.add(pluginExecution);
    ArrayList<String> goals = new ArrayList<>();
    goals.add("enforce");
    when(pluginExecution.getGoals()).thenReturn(goals);
    when(enforcerPlugin.getExecutions()).thenReturn(pluginExecutions);
    when(pluginExecution.getConfiguration()).thenReturn(null);
    assertNull(new RequiredMavenVersionFinder(mavenProject).find());
}
 
Example #30
Source File: AbstractArtifactPomOperation.java    From butterfly with MIT License 5 votes vote down vote up
private Plugin getPluginInList(List<Plugin> pluginList, String groupId, String artifactId) {
    if (pluginList == null || pluginList.size() == 0) {
        return null;
    }

    Plugin plugin = null;
    for (Plugin d : pluginList) {
        if(d.getArtifactId().equals(artifactId) && d.getGroupId().equals(groupId)) {
            plugin = d;
            break;
        }
    }

    return plugin;
}