use of org.apache.maven.model.Dependency in project maven-plugins by apache.
the class SubProject2Stub method getDependencies.
@Override
public List<Dependency> getDependencies() {
Dependency d = new Dependency();
d.setGroupId("junit");
d.setArtifactId("junit");
d.setVersion("3.8.1");
d.setScope(Artifact.SCOPE_COMPILE);
return Collections.singletonList(d);
}
use of org.apache.maven.model.Dependency in project maven-plugins by apache.
the class WebappStructure method analyseDependencies.
/**
* Analyze the dependencies of the project using the specified callback.
*
* @param callback the callback to use to report the result of the analysis
*/
public void analyseDependencies(DependenciesAnalysisCallback callback) {
if (callback == null) {
throw new NullPointerException("Callback could not be null.");
}
if (cache == null) {
// Could not analyze dependencies without a cache
return;
}
final List<Dependency> currentDependencies = new ArrayList<Dependency>(getDependencies());
final List<Dependency> previousDependencies = new ArrayList<Dependency>(cache.getDependencies());
final Iterator<Dependency> it = currentDependencies.listIterator();
while (it.hasNext()) {
Dependency dependency = it.next();
// Check if the dependency is there "as is"
final Dependency matchingDependency = matchDependency(previousDependencies, dependency);
if (matchingDependency != null) {
callback.unchangedDependency(dependency);
// Handled so let's remove
it.remove();
previousDependencies.remove(matchingDependency);
} else {
// Try to get the dependency
final Dependency previousDep = findDependency(dependency, previousDependencies);
if (previousDep == null) {
callback.newDependency(dependency);
it.remove();
} else if (!dependency.getVersion().equals(previousDep.getVersion())) {
callback.updatedVersion(dependency, previousDep.getVersion());
it.remove();
previousDependencies.remove(previousDep);
} else if (!dependency.getScope().equals(previousDep.getScope())) {
callback.updatedScope(dependency, previousDep.getScope());
it.remove();
previousDependencies.remove(previousDep);
} else if (dependency.isOptional() != previousDep.isOptional()) {
callback.updatedOptionalFlag(dependency, previousDep.isOptional());
it.remove();
previousDependencies.remove(previousDep);
} else {
callback.updatedUnknown(dependency, previousDep);
it.remove();
previousDependencies.remove(previousDep);
}
}
}
for (Dependency dependency : previousDependencies) {
callback.removedDependency(dependency);
}
}
use of org.apache.maven.model.Dependency in project maven-plugins by apache.
the class AbstractCheckstyleReport method getCheckstylePluginDependenciesAsArtifacts.
private List<Artifact> getCheckstylePluginDependenciesAsArtifacts(Map<String, Plugin> plugins, String hint) {
List<Artifact> artifacts = new ArrayList<>();
Plugin checkstylePlugin = plugins.get(plugin.getGroupId() + ":" + plugin.getArtifactId());
if (checkstylePlugin != null) {
for (Dependency dep : checkstylePlugin.getDependencies()) {
// @todo if we can filter on hints, it should be done here...
String depKey = dep.getGroupId() + ":" + dep.getArtifactId();
artifacts.add((Artifact) plugin.getArtifactMap().get(depKey));
}
}
return artifacts;
}
use of org.apache.maven.model.Dependency in project maven-plugins by apache.
the class ShadeMojo method createDependency.
private Dependency createDependency(Artifact artifact) {
Dependency dep = new Dependency();
dep.setArtifactId(artifact.getArtifactId());
if (artifact.hasClassifier()) {
dep.setClassifier(artifact.getClassifier());
}
dep.setGroupId(artifact.getGroupId());
dep.setOptional(artifact.isOptional());
dep.setScope(artifact.getScope());
dep.setType(artifact.getType());
if (useBaseVersion) {
dep.setVersion(artifact.getBaseVersion());
} else {
dep.setVersion(artifact.getVersion());
}
return dep;
}
use of org.apache.maven.model.Dependency in project maven-plugins by apache.
the class ShadeMojo method createDependencyReducedPom.
// We need to find the direct dependencies that have been included in the uber JAR so that we can modify the
// POM accordingly.
private void createDependencyReducedPom(Set<String> artifactsToRemove) throws IOException, DependencyGraphBuilderException, ProjectBuildingException {
List<Dependency> dependencies = new ArrayList<Dependency>();
boolean modified = false;
List<Dependency> transitiveDeps = new ArrayList<Dependency>();
// including the system scoped artifacts with expanded values of properties used.
for (Artifact artifact : project.getArtifacts()) {
if ("pom".equals(artifact.getType())) {
// don't include pom type dependencies in dependency reduced pom
continue;
}
// promote
Dependency dep = createDependency(artifact);
// we'll figure out the exclusions in a bit.
transitiveDeps.add(dep);
}
List<Dependency> origDeps = project.getDependencies();
if (promoteTransitiveDependencies) {
origDeps = transitiveDeps;
}
Model model = project.getOriginalModel();
// MSHADE-185: We will remove all system scoped dependencies which usually
// have some kind of property usage. At this time the properties within
// such things are already evaluated.
List<Dependency> originalDependencies = model.getDependencies();
removeSystemScopedDependencies(artifactsToRemove, originalDependencies);
for (Dependency d : origDeps) {
dependencies.add(d);
String id = getId(d);
if (artifactsToRemove.contains(id)) {
modified = true;
if (keepDependenciesWithProvidedScope) {
d.setScope("provided");
} else {
dependencies.remove(d);
}
}
}
// MSHADE-155
model.setArtifactId(shadedArtifactId);
// MSHADE-185: We will add those system scoped dependencies
// from the non interpolated original pom file. So we keep
// things like this: <systemPath>${tools.jar}</systemPath> intact.
addSystemScopedDependencyFromNonInterpolatedPom(dependencies, originalDependencies);
// Check to see if we have a reduction and if so rewrite the POM.
rewriteDependencyReducedPomIfWeHaveReduction(dependencies, modified, transitiveDeps, model);
}
Aggregations