Exemplo n.º 1
0
 private String createDefaultLicenseHeader() {
   String organization = "";
   Organization org = project.getOrganization();
   if (org != null) {
     organization = org.getName();
   }
   if (organization == null) {
     List devs = project.getDevelopers();
     if (devs.size() > 0) {
       Iterator dvs = devs.iterator();
       String devsString = "";
       while (dvs.hasNext()) {
         Developer d = (Developer) dvs.next();
         devsString = devsString + "," + d.getName() != null ? d.getName() : d.getId();
       }
       organization = devsString.substring(1);
     }
   }
   if (organization == null) {
     organization = ""; // what's a good default value?
   }
   String date = "";
   if (project.getInceptionYear() != null) {
     date = project.getInceptionYear();
   }
   String year = Integer.toString(Calendar.getInstance().get(Calendar.YEAR));
   if (!year.equals(date)) {
     date = date.length() == 0 ? year : date + "-" + year;
   }
   return "Copyright " + organization + " " + date;
 }
  public GemSpecification createSpecification(final MavenArtifact artifact) {
    final GemSpecification result = new GemSpecification();

    // this is fix
    result.setPlatform(this.PLATFORM_JAVA);

    // the must ones
    result.setName(
        createGemName(
            artifact.getCoordinates().getGroupId(),
            artifact.getCoordinates().getArtifactId(),
            artifact.getCoordinates().getVersion()));
    result.setVersion(new GemVersion(createGemVersion(artifact.getCoordinates().getVersion())));

    // dependencies
    if (artifact.getPom().getDependencies().size() > 0) {
      for (final Dependency dependency : artifact.getPom().getDependencies()) {
        if (!dependency.isOptional()) {
          result.getDependencies().add(convertDependency(artifact, dependency));
        }
      }
    }

    // and other stuff "nice to have"
    result.setDate(new Date()); // now
    result.setDescription(
        sanitizeStringValue(
            artifact.getPom().getDescription() != null
                ? artifact.getPom().getDescription()
                : artifact.getPom().getName()));
    result.setSummary(sanitizeStringValue(artifact.getPom().getName()));
    result.setHomepage(sanitizeStringValue(artifact.getPom().getUrl()));

    if (artifact.getPom().getLicenses().size() > 0) {
      for (final License license : artifact.getPom().getLicenses()) {
        result
            .getLicenses()
            .add(sanitizeStringValue(license.getName() + " (" + license.getUrl() + ")"));
      }
    }
    if (artifact.getPom().getDevelopers().size() > 0) {
      for (final Developer developer : artifact.getPom().getDevelopers()) {
        result
            .getAuthors()
            .add(sanitizeStringValue(developer.getName() + " (" + developer.getEmail() + ")"));
      }
    }

    // by default, we pack into lib/ inside gem (where is the jar and the
    // stub ruby)
    result.getRequire_paths().add("lib");
    return result;
  }
  /**
   * Returns the identify of the mail sender according to the plugin's configuration:
   *
   * <ul>
   *   <li>if the <tt>mailSender</tt> parameter is set, it is returned
   *   <li>if no <tt>fromDeveloperId</tt> is set, the first developer in the list is returned
   *   <li>if a <tt>fromDeveloperId</tt> is set, the developer with that id is returned
   *   <li>if the developers list is empty or if the specified id does not exist, an exception is
   *       thrown
   * </ul>
   *
   * @return the mail sender to use
   * @throws MojoExecutionException if the mail sender could not be retrieved
   */
  protected MailSender getActualMailSender() throws MojoExecutionException {
    if (senderString != null) {
      try {
        InternetAddress ia = new InternetAddress(senderString, true);
        return new MailSender(ia.getPersonal(), ia.getAddress());
      } catch (AddressException e) {
        throw new MojoExecutionException("Invalid value for change.sender: ", e);
      }
    }
    if (mailSender != null && mailSender.getEmail() != null) {
      return mailSender;
    } else if (from == null || from.isEmpty()) {
      throw new MojoExecutionException(
          "The <developers> section in your pom should not be empty. Add a <developer> entry or set the "
              + "mailSender parameter.");
    } else if (fromDeveloperId == null) {
      final Developer dev = (Developer) from.get(0);
      return new MailSender(dev.getName(), dev.getEmail());
    } else {
      final Iterator it = from.iterator();
      while (it.hasNext()) {
        Developer developer = (Developer) it.next();

        if (fromDeveloperId.equals(developer.getId())) {
          return new MailSender(developer.getName(), developer.getEmail());
        }
      }
      throw new MojoExecutionException(
          "Missing developer with id '"
              + fromDeveloperId
              + "' in the <developers> section in your pom.");
    }
  }
  /** Finds and lists developers specified in POM. */
  private String getDevelopersForManifest() throws IOException {
    StringBuilder buf = new StringBuilder();

    for (Object o : project.getDevelopers()) {
      Developer d = (Developer) o;
      if (buf.length() > 0) {
        buf.append(',');
      }
      buf.append(d.getName() != null ? d.getName() : "");
      buf.append(':');
      buf.append(d.getId() != null ? d.getId() : "");
      buf.append(':');
      buf.append(d.getEmail() != null ? d.getEmail() : "");
    }

    return buf.toString();
  }
  private DefaultCoreExtension parseMavenPom(
      URL descriptorUrl, DefaultCoreExtensionRepository repository)
      throws IOException, XmlPullParserException {
    DefaultCoreExtension coreExtension = null;

    InputStream descriptorStream = descriptorUrl.openStream();
    try {
      MavenXpp3Reader reader = new MavenXpp3Reader();
      Model mavenModel = reader.read(descriptorStream);

      String version = resolveVersion(mavenModel.getVersion(), mavenModel, false);
      String groupId = resolveGroupId(mavenModel.getGroupId(), mavenModel, false);

      URL extensionURL = getExtensionURL(descriptorUrl);

      coreExtension =
          new MavenCoreExtension(
              repository,
              extensionURL,
              new ExtensionId(groupId + ':' + mavenModel.getArtifactId(), version),
              packagingToType(mavenModel.getPackaging()),
              mavenModel);

      coreExtension.setName(mavenModel.getName());
      coreExtension.setSummary(mavenModel.getDescription());
      for (Developer developer : mavenModel.getDevelopers()) {
        URL authorURL = null;
        if (developer.getUrl() != null) {
          try {
            authorURL = new URL(developer.getUrl());
          } catch (MalformedURLException e) {
            // TODO: log ?
          }
        }

        coreExtension.addAuthor(new DefaultExtensionAuthor(developer.getId(), authorURL));
      }
      coreExtension.setWebsite(mavenModel.getUrl());

      // licenses
      for (License license : mavenModel.getLicenses()) {
        coreExtension.addLicense(getExtensionLicense(license));
      }

      // features
      String featuresString = mavenModel.getProperties().getProperty("xwiki.extension.features");
      if (StringUtils.isNotBlank(featuresString)) {
        coreExtension.setFeatures(
            this.converter.<Collection<String>>convert(List.class, featuresString));
      }

      // custom properties
      coreExtension.putProperty("maven.groupId", groupId);
      coreExtension.putProperty("maven.artifactId", mavenModel.getArtifactId());

      // dependencies
      for (Dependency mavenDependency : mavenModel.getDependencies()) {
        if (!mavenDependency.isOptional()
            && (mavenDependency.getScope() == null
                || mavenDependency.getScope().equals("compile")
                || mavenDependency.getScope().equals("runtime"))) {

          String dependencyGroupId = resolveGroupId(mavenDependency.getGroupId(), mavenModel, true);
          String dependencyArtifactId = mavenDependency.getArtifactId();
          String dependencyClassifier = mavenDependency.getClassifier();
          String dependencyVersion = resolveVersion(mavenDependency.getVersion(), mavenModel, true);

          DefaultExtensionDependency extensionDependency =
              new MavenCoreExtensionDependency(
                  toExtensionId(dependencyGroupId, dependencyArtifactId, dependencyClassifier),
                  new DefaultVersionConstraint(dependencyVersion),
                  mavenDependency);

          coreExtension.addDependency(extensionDependency);
        }
      }
    } finally {
      IOUtils.closeQuietly(descriptorStream);
    }

    return coreExtension;
  }