use of org.apache.maven.model.DependencyManagement in project camel by apache.
the class BomGeneratorMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
try {
DependencyManagement mng = project.getDependencyManagement();
List<Dependency> filteredDependencies = enhance(filter(mng.getDependencies()));
Set<String> externallyManagedDependencies = getExternallyManagedDependencies();
checkConflictsWithExternalBoms(filteredDependencies, externallyManagedDependencies);
Document pom = loadBasePom();
// transform
overwriteDependencyManagement(pom, filteredDependencies);
writePom(pom);
} catch (MojoFailureException ex) {
throw ex;
} catch (MojoExecutionException ex) {
throw ex;
} catch (Exception ex) {
throw new MojoExecutionException("Cannot generate the output BOM file", ex);
}
}
use of org.apache.maven.model.DependencyManagement in project buck by facebook.
the class Pom method merge.
private Model merge(Model first, @Nullable Model second) {
if (second == null) {
return first;
}
Model model = first.clone();
//---- Values from ModelBase
List<String> modules = second.getModules();
if (modules != null) {
for (String module : modules) {
model.addModule(module);
}
}
DistributionManagement distributionManagement = second.getDistributionManagement();
if (distributionManagement != null) {
model.setDistributionManagement(distributionManagement);
}
Properties properties = second.getProperties();
if (properties != null) {
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
model.addProperty((String) entry.getKey(), (String) entry.getValue());
}
}
DependencyManagement dependencyManagement = second.getDependencyManagement();
if (dependencyManagement != null) {
model.setDependencyManagement(dependencyManagement);
}
List<Dependency> dependencies = second.getDependencies();
if (dependencies != null) {
for (Dependency dependency : dependencies) {
model.addDependency(dependency);
}
}
List<Repository> repositories = second.getRepositories();
if (repositories != null) {
for (Repository repository : repositories) {
model.addRepository(repository);
}
}
List<Repository> pluginRepositories = second.getPluginRepositories();
if (pluginRepositories != null) {
for (Repository pluginRepository : pluginRepositories) {
model.addPluginRepository(pluginRepository);
}
}
// Ignore reports, reporting, and locations
//----- From Model
Parent parent = second.getParent();
if (parent != null) {
model.setParent(parent);
}
Organization organization = second.getOrganization();
if (organization != null) {
model.setOrganization(organization);
}
List<License> licenses = second.getLicenses();
Set<String> currentLicenseUrls = new HashSet<>();
if (model.getLicenses() != null) {
for (License license : model.getLicenses()) {
currentLicenseUrls.add(license.getUrl());
}
}
if (licenses != null) {
for (License license : licenses) {
if (!currentLicenseUrls.contains(license.getUrl())) {
model.addLicense(license);
currentLicenseUrls.add(license.getUrl());
}
}
}
List<Developer> developers = second.getDevelopers();
Set<String> currentDevelopers = new HashSet<>();
if (model.getDevelopers() != null) {
for (Developer developer : model.getDevelopers()) {
currentDevelopers.add(developer.getName());
}
}
if (developers != null) {
for (Developer developer : developers) {
if (!currentDevelopers.contains(developer.getName())) {
model.addDeveloper(developer);
currentDevelopers.add(developer.getName());
}
}
}
List<Contributor> contributors = second.getContributors();
Set<String> currentContributors = new HashSet<>();
if (model.getContributors() != null) {
for (Contributor contributor : model.getContributors()) {
currentDevelopers.add(contributor.getName());
}
}
if (contributors != null) {
for (Contributor contributor : contributors) {
if (!currentContributors.contains(contributor.getName())) {
model.addContributor(contributor);
currentContributors.add(contributor.getName());
}
}
}
List<MailingList> mailingLists = second.getMailingLists();
if (mailingLists != null) {
for (MailingList mailingList : mailingLists) {
model.addMailingList(mailingList);
}
}
Prerequisites prerequisites = second.getPrerequisites();
if (prerequisites != null) {
model.setPrerequisites(prerequisites);
}
Scm scm = second.getScm();
if (scm != null) {
model.setScm(scm);
}
String url = second.getUrl();
if (url != null) {
model.setUrl(url);
}
String description = second.getDescription();
if (description != null) {
model.setDescription(description);
}
IssueManagement issueManagement = second.getIssueManagement();
if (issueManagement != null) {
model.setIssueManagement(issueManagement);
}
CiManagement ciManagement = second.getCiManagement();
if (ciManagement != null) {
model.setCiManagement(ciManagement);
}
Build build = second.getBuild();
if (build != null) {
model.setBuild(build);
}
List<Profile> profiles = second.getProfiles();
Set<String> currentProfileIds = new HashSet<>();
if (model.getProfiles() != null) {
for (Profile profile : model.getProfiles()) {
currentProfileIds.add(profile.getId());
}
}
if (profiles != null) {
for (Profile profile : profiles) {
if (!currentProfileIds.contains(profile.getId())) {
model.addProfile(profile);
currentProfileIds.add(profile.getId());
}
}
}
return model;
}
use of org.apache.maven.model.DependencyManagement in project maven-plugins by apache.
the class AnalyzeDepMgt method checkDependencyManagement.
/**
* Does the work of checking the DependencyManagement Section.
*
* @return true if errors are found.
* @throws MojoExecutionException
*/
private boolean checkDependencyManagement() throws MojoExecutionException {
boolean foundError = false;
getLog().info("Found Resolved Dependency/DependencyManagement mismatches:");
List<Dependency> depMgtDependencies = null;
DependencyManagement depMgt = project.getDependencyManagement();
if (depMgt != null) {
depMgtDependencies = depMgt.getDependencies();
}
if (depMgtDependencies != null && !depMgtDependencies.isEmpty()) {
// put all the dependencies from depMgt into a map for quick lookup
Map<String, Dependency> depMgtMap = new HashMap<String, Dependency>();
Map<String, Exclusion> exclusions = new HashMap<String, Exclusion>();
for (Dependency depMgtDependency : depMgtDependencies) {
depMgtMap.put(depMgtDependency.getManagementKey(), depMgtDependency);
// now put all the exclusions into a map for quick lookup
exclusions.putAll(addExclusions(depMgtDependency.getExclusions()));
}
// get dependencies for the project (including transitive)
Set<Artifact> allDependencyArtifacts = new LinkedHashSet<Artifact>(project.getArtifacts());
// depMgt. That's ok.
if (this.ignoreDirect) {
getLog().info("\tIgnoring Direct Dependencies.");
Set<Artifact> directDependencies = project.getDependencyArtifacts();
allDependencyArtifacts.removeAll(directDependencies);
}
// log exclusion errors
List<Artifact> exclusionErrors = getExclusionErrors(exclusions, allDependencyArtifacts);
for (Artifact exclusion : exclusionErrors) {
getLog().info(StringUtils.stripEnd(getArtifactManagementKey(exclusion), ":") + " was excluded in DepMgt, but version " + exclusion.getVersion() + " has been found in the dependency tree.");
foundError = true;
}
// find and log version mismatches
Map<Artifact, Dependency> mismatch = getMismatch(depMgtMap, allDependencyArtifacts);
for (Map.Entry<Artifact, Dependency> entry : mismatch.entrySet()) {
logMismatch(entry.getKey(), entry.getValue());
foundError = true;
}
if (!foundError) {
getLog().info("\tNone");
}
} else {
getLog().info("\tNothing in DepMgt.");
}
return foundError;
}
use of org.apache.maven.model.DependencyManagement in project maven-plugins by apache.
the class TestAnalyzeDepMgt method setUp.
protected void setUp() throws Exception {
mojo = new AnalyzeDepMgt();
MavenProject project = new DependencyProjectStub();
stubFactory = new DependencyArtifactStubFactory(new File(""), false);
Set<Artifact> allArtifacts = stubFactory.getMixedArtifacts();
Set<Artifact> directArtifacts = stubFactory.getClassifiedArtifacts();
exclusionArtifact = stubFactory.getReleaseArtifact();
directArtifacts.add(exclusionArtifact);
ex = new Exclusion();
ex.setArtifactId(exclusionArtifact.getArtifactId());
ex.setGroupId(exclusionArtifact.getGroupId());
exclusion = new Dependency();
exclusion.setArtifactId(exclusionArtifact.getArtifactId());
exclusion.setGroupId(exclusionArtifact.getGroupId());
exclusion.setType(exclusionArtifact.getType());
exclusion.setClassifier("");
exclusion.setVersion("3.0");
exclusion.addExclusion(ex);
List<Dependency> list = new ArrayList<Dependency>();
list.add(exclusion);
depMgt = new DependencyManagement();
depMgt.setDependencies(list);
project.setArtifacts(allArtifacts);
project.setDependencyArtifacts(directArtifacts);
mojo.setProject(project);
}
Aggregations