@Override
  public boolean updateModel(Model model) throws MavenExecutionException {
    Map<String, String> versionOverrides = getVersionOverrides();
    if (versionOverrides.size() == 0) {
      return false;
    }

    // If the model doesn't have any plugin management set by default, create one for it
    PluginManagement pluginManagement = model.getBuild().getPluginManagement();
    if (pluginManagement == null) {
      pluginManagement = new PluginManagement();
      model.getBuild().setPluginManagement(pluginManagement);
      Log.getLog().debug("Created new Plugin Management for model");
    }

    // Override plugin management versions
    applyOverrides(pluginManagement.getPlugins(), versionOverrides);

    // Override plugin versions
    List<Plugin> projectPlugins = model.getBuild().getPlugins();
    applyOverrides(projectPlugins, versionOverrides);

    // Include the overrides in the built files for repeatability
    writeOverrideMap(model, getName(), versionOverrides);

    // Assuming the Model changed since overrides were given
    return true;
  }
 /**
  * Adds information about managed plugins.
  *
  * @param pomDescriptor The descriptor for the current POM.
  * @param build Information required to build the project.
  * @param scannerContext The scanner context.
  */
 private void addManagedPlugins(
     BaseProfileDescriptor pomDescriptor, BuildBase build, ScannerContext scannerContext) {
   if (null == build) {
     return;
   }
   PluginManagement pluginManagement = build.getPluginManagement();
   if (null == pluginManagement) {
     return;
   }
   List<MavenPluginDescriptor> pluginDescriptors =
       createMavenPluginDescriptors(pluginManagement.getPlugins(), scannerContext);
   pomDescriptor.getManagedPlugins().addAll(pluginDescriptors);
 }
 static InputLocation findLocationForManagedArtifact(
     final ManagedArtifactRegion region, MavenProject mavprj) {
   Model mdl = mavprj.getModel();
   InputLocation openLocation = null;
   if (region.isDependency) {
     DependencyManagement dm = mdl.getDependencyManagement();
     if (dm != null) {
       List<Dependency> list = dm.getDependencies();
       String id = region.groupId + ":" + region.artifactId + ":"; // $NON-NLS-1$ //$NON-NLS-2$
       if (list != null) {
         for (Dependency dep : list) {
           if (dep.getManagementKey().startsWith(id)) {
             InputLocation location = dep.getLocation(ARTIFACT_ID); // $NON-NLS-1$
             // when would this be null?
             if (location != null) {
               openLocation = location;
               break;
             }
           }
         }
       }
     }
   }
   if (region.isPlugin) {
     Build build = mdl.getBuild();
     if (build != null) {
       PluginManagement pm = build.getPluginManagement();
       if (pm != null) {
         List<Plugin> list = pm.getPlugins();
         String id = Plugin.constructKey(region.groupId, region.artifactId);
         if (list != null) {
           for (Plugin plg : list) {
             if (id.equals(plg.getKey())) {
               InputLocation location = plg.getLocation(ARTIFACT_ID); // $NON-NLS-1$
               // when would this be null?
               if (location != null) {
                 openLocation = location;
                 break;
               }
             }
           }
         }
       }
     }
   }
   return openLocation;
 }
예제 #4
0
  public List<Plugin> getManagedPlugins(final ModelBase base) {
    BuildBase build;
    if (base instanceof Model) {
      build = ((Model) base).getBuild();
    } else {
      build = ((Profile) base).getBuild();
    }

    if (build == null) {
      return Collections.emptyList();
    }

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

    final List<Plugin> result = pm.getPlugins();
    if (result == null) {
      return Collections.emptyList();
    }

    return result;
  }