use of org.apache.maven.project.MavenProject in project jersey by jersey.
the class GenerateJerseyModuleListMojo method categorizeModules.
private Map<String, List<MavenProject>> categorizeModules(List<MavenProject> projects) {
Map<String, List<MavenProject>> categorizedProjects = new HashMap<>();
for (MavenProject project : projects) {
String groupId = project.getGroupId();
if (categorizedProjects.containsKey(groupId)) {
categorizedProjects.get(groupId).add(project);
} else {
List<MavenProject> actualList = new LinkedList<>();
actualList.add(project);
categorizedProjects.put(groupId, actualList);
}
}
return categorizedProjects;
}
use of org.apache.maven.project.MavenProject in project intellij-community by JetBrains.
the class MavenEmbedder method readProject.
@NotNull
private MavenExecutionResult readProject(@NotNull final MavenExecutionRequest request) {
ProfileManager globalProfileManager = request.getGlobalProfileManager();
globalProfileManager.loadSettingsProfiles(request.getSettings());
MavenProject rootProject = null;
final List<Exception> exceptions = new ArrayList<Exception>();
Object result = null;
try {
final File pomFile = new File(request.getPomFile());
if (!pomFile.exists()) {
throw new FileNotFoundException("File doesn't exist: " + pomFile.getPath());
}
final Method getProjectsMethod = DefaultMaven.class.getDeclaredMethod("getProjects", MavenExecutionRequest.class);
getProjectsMethod.setAccessible(true);
Maven maven = getComponent(Maven.class);
result = getProjectsMethod.invoke(maven, request);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
return handleException(e.getTargetException());
} catch (Exception e) {
return handleException(e);
}
if (result != null) {
MavenProjectBuilder builder = getComponent(MavenProjectBuilder.class);
for (Object p : (List) result) {
MavenProject project = (MavenProject) p;
try {
builder.calculateConcreteState(project, request.getProjectBuilderConfiguration(), false);
} catch (ModelInterpolationException e) {
exceptions.add(e);
}
if (project.isExecutionRoot()) {
rootProject = project;
}
}
if (rootProject == null && exceptions.isEmpty()) {
throw new RuntimeException("Could't build project for unknown reason");
}
}
return new MavenExecutionResult(rootProject, exceptions);
}
use of org.apache.maven.project.MavenProject in project asterixdb by apache.
the class LicenseMojo method addDependencyToLicenseMap.
private void addDependencyToLicenseMap(MavenProject depProject, List<Pair<String, String>> depLicenses, String depLocation) {
final String depGav = toGav(depProject);
getLog().debug("adding " + depGav + ", location: " + depLocation);
final MutableBoolean usedMetric = new MutableBoolean(false);
if (depLicenses.size() > 1) {
Collections.sort(depLicenses, (o1, o2) -> {
final int metric1 = getLicenseMetric(o1.getLeft());
final int metric2 = getLicenseMetric(o2.getLeft());
usedMetric.setValue(usedMetric.booleanValue() || metric1 != LicenseSpec.UNDEFINED_LICENSE_METRIC || metric2 != LicenseSpec.UNDEFINED_LICENSE_METRIC);
return Integer.compare(metric1, metric2);
});
if (usedMetric.booleanValue()) {
getLog().info("Multiple licenses for " + depGav + ": " + depLicenses + "; taking lowest metric: " + depLicenses.get(0));
} else {
getLog().warn("Multiple licenses for " + depGav + ": " + depLicenses + "; taking first listed: " + depLicenses.get(0));
}
} else if (depLicenses.isEmpty()) {
getLog().info("no license defined in model for " + depGav);
depLicenses.add(new ImmutablePair<>("MISSING_LICENSE", null));
}
Pair<String, String> key = depLicenses.get(0);
String licenseUrl = key.getLeft();
final String displayName = key.getRight();
if (!urlToLicenseMap.containsKey(licenseUrl)) {
// assuming we've not already mapped it, annotate the URL with artifact info, if not an actual URL
try {
getLog().debug("- URL: " + new URL(licenseUrl));
// life is good
} catch (MalformedURLException e) {
// we encounter this a lot. Log a warning, and use an annotated key
final String fakeLicenseUrl = depGav.replaceAll(":", "--") + "_" + licenseUrl;
getLog().info("- URL for " + depGav + " is malformed: " + licenseUrl + "; using: " + fakeLicenseUrl);
licenseUrl = fakeLicenseUrl;
}
}
addProject(new Project(depProject, depLocation, depProject.getArtifact().getFile()), new LicenseSpec(licenseUrl, displayName), true);
}
use of org.apache.maven.project.MavenProject in project asterixdb by apache.
the class LicenseMojo method resolveDependency.
protected MavenProject resolveDependency(Artifact depObj) throws ProjectBuildingException {
String key = depObj.getGroupId() + ":" + depObj.getArtifactId() + ":" + depObj.getVersion();
MavenProject depProj = projectCache.get(key);
if (depProj == null) {
try {
depProj = projectBuilder.buildFromRepository(depObj, remoteRepositories, localRepository, false);
} catch (ProjectBuildingException e) {
throw new ProjectBuildingException(key, "Error creating dependent artifacts", e);
}
Model supplement = supplementModels.get(SupplementalModelHelper.generateSupplementMapKey(depObj.getGroupId(), depObj.getArtifactId()));
if (supplement != null) {
Model merged = SupplementalModelHelper.mergeModels(assembler, depProj.getModel(), supplement);
Set<String> origLicenses = depProj.getModel().getLicenses().stream().map(License::getUrl).collect(Collectors.toSet());
Set<String> newLicenses = merged.getLicenses().stream().map(License::getUrl).collect(Collectors.toSet());
if (!origLicenses.equals(newLicenses)) {
getLog().warn("license list for " + toGav(depProj) + " changed with supplemental model; was: " + origLicenses + ", now: " + newLicenses);
}
depProj = new MavenProject(merged);
depProj.setArtifact(depObj);
depProj.setVersion(depObj.getVersion());
}
depProj.getArtifact().setScope(depObj.getScope());
projectCache.put(key, depProj);
}
return depProj;
}
use of org.apache.maven.project.MavenProject in project asterixdb by apache.
the class LicenseMojo method gatherProjectDependencies.
private void gatherProjectDependencies(MavenProject project, Map<MavenProject, List<Pair<String, String>>> dependencyLicenseMap, Map<String, MavenProject> dependencyGavMap) throws ProjectBuildingException {
final Set dependencyArtifacts = project.getArtifacts();
if (dependencyArtifacts != null) {
for (Object depArtifactObj : dependencyArtifacts) {
final Artifact depArtifact = (Artifact) depArtifactObj;
if (!excludedScopes.contains(depArtifact.getScope())) {
MavenProject dep = resolveDependency(depArtifact);
dep.setArtifact(depArtifact);
dependencyGavMap.put(toGav(dep), dep);
List<Pair<String, String>> licenseUrls = new ArrayList<>();
for (Object license : dep.getLicenses()) {
final License license1 = (License) license;
String url = license1.getUrl() != null ? license1.getUrl() : (license1.getName() != null ? license1.getName() : "LICENSE_EMPTY_NAME_URL");
licenseUrls.add(new ImmutablePair<>(url, license1.getName()));
}
dependencyLicenseMap.put(dep, licenseUrls);
}
}
}
}
Aggregations