@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);
 }
예제 #3
0
  public void flushPluginMaps(final ModelBase base) {
    final BuildBase build = getBuild(base);
    if (build != null) {
      build.flushPluginMap();

      final PluginManagement pm = build.getPluginManagement();
      if (pm != null) {
        pm.flushPluginMap();
      }
    }

    final Reporting reporting = model.getReporting();
    if (reporting != null) {
      reporting.flushReportPluginMap();
    }
  }
 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;
 }
예제 #5
0
  public Map<String, Plugin> getManagedPluginMap(final ModelBase base) {
    if (base instanceof Model) {
      final Build build = ((Model) base).getBuild();
      if (build == null) {
        return Collections.<String, Plugin>emptyMap();
      }

      final PluginManagement pm = build.getPluginManagement();
      if (pm == null) {
        return Collections.<String, Plugin>emptyMap();
      }

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

      return result;
    }

    return Collections.<String, Plugin>emptyMap();
  }
예제 #6
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;
  }
예제 #7
0
  public Model toMavenModel() {
    Model model = new Model();
    model.setBuild(new Build());
    model.setDescription(description);
    model.setUrl(url);
    model.setName(projectId.getArtifact());
    model.setGroupId(projectId.getGroup());
    model.setVersion(projectId.getVersion());
    model.setArtifactId(projectId.getArtifact());
    model.setModelVersion("4.0.0");

    // parent
    if (parent != null) {
      model.setParent(parent);
    }

    model.setPackaging(packaging);

    if (properties != null) {
      Properties modelProperties = new Properties();
      for (Property p : properties) {
        modelProperties.setProperty(p.getKey(), p.getValue());
      }
      model.setProperties(modelProperties);
    }

    // Add jar repository urls.
    if (null != repositories) {
      for (String repoUrl : repositories.getRepositories()) {
        Repository repository = new Repository();
        repository.setId(Integer.toString(repoUrl.hashCode()));
        repository.setUrl(repoUrl);
        model.addRepository(repository);
      }
    }

    // Add dependency management
    if (overrides != null) {
      DependencyManagement depMan = new DependencyManagement();
      for (Id dep : overrides) {
        Dependency dependency = new Dependency();
        dependency.setGroupId(dep.getGroup());
        dependency.setArtifactId(dep.getArtifact());
        dependency.setVersion(dep.getVersion());
        // JVZ: We need to parse these
        dependency.setType("jar");

        if (null != dep.getClassifier()) {
          dependency.setClassifier(dep.getClassifier());
        }
        depMan.addDependency(dependency);
      }
      model.setDependencyManagement(depMan);
    }

    // Add project dependencies.
    if (deps != null) {
      for (Id dep : deps) {
        Dependency dependency = new Dependency();
        dependency.setGroupId(dep.getGroup());
        dependency.setArtifactId(dep.getArtifact());
        dependency.setVersion(dep.getVersion());
        // JVZ: We need to parse these
        dependency.setType("jar");

        if (null != dep.getClassifier()) {
          dependency.setClassifier(dep.getClassifier());
        }
        model.addDependency(dependency);
      }
    }

    if (modules != null) {
      model.setModules(modules);
    }

    if (pluginOverrides != null) {
      PluginManagement management = new PluginManagement();
      management.setPlugins(pluginOverrides);
      model.getBuild().setPluginManagement(management);
    }

    if (plugins != null) {
      model.getBuild().setPlugins(plugins);
    }

    // Optional source dirs customization.
    if (dirs != null) {
      Build build = new Build();
      String srcDir = dirs.get("src");
      String testDir = dirs.get("test");

      if (null != srcDir) build.setSourceDirectory(srcDir);

      if (null != testDir) build.setTestSourceDirectory(testDir);

      model.setBuild(build);
    }

    if (null != scm) {
      Scm scm = new Scm();
      scm.setConnection(this.scm.getConnection());
      scm.setDeveloperConnection(this.scm.getDeveloperConnection());
      scm.setUrl(this.scm.getUrl());

      model.setScm(scm);
    }

    return model;
  }