/**
  * Create the fully qualified name of the model (using packaging type "pom").
  *
  * @param model The model.
  * @return The fully qualified name.
  */
 private String getFullyQualifiedName(Model model) {
   StringBuilder id = new StringBuilder();
   id.append((model.getGroupId() == null) ? "[inherited]" : model.getGroupId());
   id.append(":");
   id.append(model.getArtifactId());
   id.append(":pom:");
   id.append((model.getVersion() == null) ? "[inherited]" : model.getVersion());
   return id.toString();
 }
 /**
  * Adds information about parent POM.
  *
  * @param pomDescriptor The descriptor for the current POM.
  * @param model The Maven Model.
  * @param context The scanner context.
  */
 private void addParent(MavenPomDescriptor pomDescriptor, Model model, ScannerContext context) {
   Parent parent = model.getParent();
   if (null != parent) {
     MavenArtifactDescriptor parentDescriptor =
         getArtifactResolver(context).resolve(new ParentCoordinates(parent), context);
     pomDescriptor.setParent(parentDescriptor);
   }
 }
  /**
   * Adds information about references licenses.
   *
   * @param pomDescriptor The descriptor for the current POM.
   * @param model The Maven Model.
   * @param store The database.
   */
  private void addLicenses(MavenPomDescriptor pomDescriptor, Model model, Store store) {
    List<License> licenses = model.getLicenses();
    for (License license : licenses) {
      MavenLicenseDescriptor licenseDescriptor = store.create(MavenLicenseDescriptor.class);
      licenseDescriptor.setUrl(license.getUrl());
      licenseDescriptor.setComments(license.getComments());
      licenseDescriptor.setName(license.getName());
      licenseDescriptor.setDistribution(license.getDistribution());

      pomDescriptor.getLicenses().add(licenseDescriptor);
    }
  }
 /**
  * Create the descriptor and set base information.
  *
  * @param model The model.
  * @param scanner The scanner.
  * @return The descriptor.
  */
 protected MavenPomDescriptor createMavenPomDescriptor(Model model, Scanner scanner) {
   ScannerContext context = scanner.getContext();
   MavenPomDescriptor pomDescriptor = context.peek(MavenPomDescriptor.class);
   pomDescriptor.setName(model.getName());
   pomDescriptor.setGroupId(model.getGroupId());
   pomDescriptor.setArtifactId(model.getArtifactId());
   pomDescriptor.setPackaging(model.getPackaging());
   pomDescriptor.setVersion(model.getVersion());
   String pomFqn = getFullyQualifiedName(model);
   pomDescriptor.setFullQualifiedName(pomFqn);
   Coordinates artifactCoordinates = new ModelCoordinates(model);
   MavenArtifactDescriptor artifact =
       getArtifactResolver(context).resolve(artifactCoordinates, context);
   // if the pom describes itself as artifact then the returned artifact
   // descriptor must be used as pom descriptor (the old instance is
   // invalidated due to adding labels)
   if (MavenPomDescriptor.class.isAssignableFrom(artifact.getClass())) {
     pomDescriptor = MavenPomDescriptor.class.cast(artifact);
   }
   pomDescriptor.getDescribes().add(artifact);
   return pomDescriptor;
 }
 /**
  * Adds information about defined profile.
  *
  * @param pomDescriptor The descriptor for the current POM.
  * @param model The Maven Model.
  * @param scannerContext The scanner context.
  */
 private void addProfiles(
     MavenPomDescriptor pomDescriptor, Model model, ScannerContext scannerContext) {
   List<Profile> profiles = model.getProfiles();
   Store store = scannerContext.getStore();
   for (Profile profile : profiles) {
     MavenProfileDescriptor mavenProfileDescriptor = store.create(MavenProfileDescriptor.class);
     pomDescriptor.getProfiles().add(mavenProfileDescriptor);
     mavenProfileDescriptor.setId(profile.getId());
     addProperties(mavenProfileDescriptor, profile.getProperties(), store);
     addModules(mavenProfileDescriptor, profile.getModules(), store);
     addPlugins(mavenProfileDescriptor, profile.getBuild(), scannerContext);
     addManagedPlugins(mavenProfileDescriptor, profile.getBuild(), scannerContext);
     addManagedDependencies(
         mavenProfileDescriptor,
         profile.getDependencyManagement(),
         scannerContext,
         ProfileManagesDependencyDescriptor.class);
     addProfileDependencies(mavenProfileDescriptor, profile.getDependencies(), scannerContext);
     addActivation(mavenProfileDescriptor, profile.getActivation(), store);
   }
 }
 /** {@inheritDoc} */
 @Override
 public MavenPomDescriptor scan(Model model, String path, Scope scope, Scanner scanner)
     throws IOException {
   MavenPomDescriptor pomDescriptor = createMavenPomDescriptor(model, scanner);
   ScannerContext scannerContext = scanner.getContext();
   Store store = scannerContext.getStore();
   addParent(pomDescriptor, model, scannerContext);
   addProfiles(pomDescriptor, model, scannerContext);
   addProperties(pomDescriptor, model.getProperties(), store);
   addModules(pomDescriptor, model.getModules(), store);
   addManagedDependencies(
       pomDescriptor,
       model.getDependencyManagement(),
       scannerContext,
       PomManagesDependencyDescriptor.class);
   addDependencies(
       pomDescriptor, model.getDependencies(), PomDependsOnDescriptor.class, scannerContext);
   addManagedPlugins(pomDescriptor, model.getBuild(), scannerContext);
   addPlugins(pomDescriptor, model.getBuild(), scannerContext);
   addLicenses(pomDescriptor, model, store);
   return pomDescriptor;
 }