/** * 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); } }
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; }