예제 #1
0
 @Override
 public String getProjectDescription() {
   if (model != null) {
     return model.getDescription();
   }
   return null;
 }
  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;
  }