use of org.apache.maven.model.Dependency in project maven-plugins by apache.
the class WebappStructureTest method testDependencyAnalysisWithNewDependency.
public void testDependencyAnalysisWithNewDependency() {
final List<Dependency> dependencies = new ArrayList<Dependency>();
dependencies.add(createDependency("groupTest", "artifactTest", "1.0"));
final WebappStructure cache = new WebappStructure(dependencies);
final List<Dependency> newDependencies = new ArrayList<Dependency>(dependencies);
final Dependency newDependency = createDependency("groupTest", "nexArtifact", "2.0");
newDependencies.add(newDependency);
final WebappStructure webappStructure = new WebappStructure(newDependencies, cache);
webappStructure.analyseDependencies(new WebappStructure.DependenciesAnalysisCallback() {
int count = 0;
public void unchangedDependency(Dependency dependency) {
if (count == 0) {
count++;
} else {
fail("Should have called unchanged dependency only once");
}
}
public void newDependency(Dependency dependency) {
if (!newDependency.equals(dependency)) {
fail("Called new dependency with an unexpected dependency " + dependency);
}
}
public void removedDependency(Dependency dependency) {
fail("Should have failed to trigger this callback");
}
public void updatedVersion(Dependency dependency, String previousVersion) {
fail("Should have failed to trigger this callback");
}
public void updatedScope(Dependency dependency, String previousScope) {
fail("Should have failed to trigger this callback");
}
public void updatedOptionalFlag(Dependency dependency, boolean previousOptional) {
fail("Should have failed to trigger this callback");
}
public void updatedUnknown(Dependency dependency, Dependency previousDep) {
fail("Should have failed to trigger this callback");
}
});
}
use of org.apache.maven.model.Dependency in project sling by apache.
the class ModelPreprocessor method searchSlingstartDependencies.
/**
* Search for dependent slingstart/slingfeature artifacts and remove them from the effective model.
* @throws MavenExecutionException
*/
private List<Model> searchSlingstartDependencies(final Environment env, final ProjectInfo info, final Model rawModel, final Model effectiveModel) throws MavenExecutionException {
// slingstart or slingfeature
final List<Model> dependencies = new ArrayList<>();
for (final Feature feature : effectiveModel.getFeatures()) {
for (final RunMode runMode : feature.getRunModes()) {
for (final ArtifactGroup group : runMode.getArtifactGroups()) {
final List<org.apache.sling.provisioning.model.Artifact> removeList = new ArrayList<>();
for (final org.apache.sling.provisioning.model.Artifact a : group) {
if (a.getType().equals(BuildConstants.PACKAGING_SLINGSTART) || a.getType().equals(BuildConstants.PACKAGING_PARTIAL_SYSTEM)) {
final Dependency dep = new Dependency();
dep.setGroupId(a.getGroupId());
dep.setArtifactId(a.getArtifactId());
dep.setVersion(a.getVersion());
dep.setType(BuildConstants.PACKAGING_PARTIAL_SYSTEM);
if (a.getType().equals(BuildConstants.PACKAGING_SLINGSTART)) {
dep.setClassifier(BuildConstants.PACKAGING_PARTIAL_SYSTEM);
} else {
dep.setClassifier(a.getClassifier());
}
dep.setScope(Artifact.SCOPE_PROVIDED);
env.logger.debug("- adding dependency " + ModelUtils.toString(dep));
info.project.getDependencies().add(dep);
// if it's a project from the current reactor build, we can't resolve it right now
final String key = a.getGroupId() + ":" + a.getArtifactId();
final ProjectInfo depInfo = env.modelProjects.get(key);
if (depInfo != null) {
env.logger.debug("Found reactor " + a.getType() + " dependency : " + a);
final Model model = addDependencies(env, depInfo);
if (model == null) {
throw new MavenExecutionException("Recursive model dependency list including project " + info.project, (File) null);
}
dependencies.add(model);
info.includedModels.put(a, depInfo.localModel);
} else {
env.logger.debug("Found external " + a.getType() + " dependency: " + a);
// "external" dependency, we can already resolve it
final File modelFile = resolveSlingstartArtifact(env, info.project, dep);
FileReader r = null;
try {
r = new FileReader(modelFile);
final Model model = ModelReader.read(r, modelFile.getAbsolutePath());
info.includedModels.put(a, model);
final Map<Traceable, String> errors = ModelUtility.validate(model);
if (errors != null) {
throw new MavenExecutionException("Unable to read model file from " + modelFile + " : " + errors, modelFile);
}
final Model fullModel = processSlingstartDependencies(env, info, dep, model);
dependencies.add(fullModel);
} catch (final IOException ioe) {
throw new MavenExecutionException("Unable to read model file from " + modelFile, ioe);
} finally {
try {
if (r != null) {
r.close();
}
} catch (final IOException io) {
// ignore
}
}
}
removeList.add(a);
}
}
for (final org.apache.sling.provisioning.model.Artifact r : removeList) {
group.remove(r);
final Feature localModelFeature = rawModel.getFeature(feature.getName());
if (localModelFeature != null) {
final RunMode localRunMode = localModelFeature.getRunMode(runMode.getNames());
if (localRunMode != null) {
final ArtifactGroup localAG = localRunMode.getArtifactGroup(group.getStartLevel());
if (localAG != null) {
localAG.remove(r);
}
}
}
}
}
}
}
return dependencies;
}
use of org.apache.maven.model.Dependency in project sling by apache.
the class ModelPreprocessor method addDependenciesFromModel.
/**
* Add all dependencies from the model
* @param env The environment
* @param info The project info
* @param scope The scope which the new dependencies should have
* @throws MavenExecutionException
*/
private void addDependenciesFromModel(final Environment env, final ProjectInfo info, final String scope) throws MavenExecutionException {
if (info.project.getPackaging().equals(BuildConstants.PACKAGING_SLINGSTART)) {
// add base artifact if defined in current model
final org.apache.sling.provisioning.model.Artifact baseArtifact = ModelUtils.findBaseArtifact(info.model);
final String[] classifiers = new String[] { null, BuildConstants.CLASSIFIER_APP, BuildConstants.CLASSIFIER_WEBAPP };
for (final String c : classifiers) {
final Dependency dep = new Dependency();
dep.setGroupId(baseArtifact.getGroupId());
dep.setArtifactId(baseArtifact.getArtifactId());
dep.setVersion(baseArtifact.getVersion());
dep.setType(baseArtifact.getType());
dep.setClassifier(c);
if (BuildConstants.CLASSIFIER_WEBAPP.equals(c)) {
dep.setType(BuildConstants.TYPE_WAR);
}
dep.setScope(scope);
info.project.getDependencies().add(dep);
env.logger.debug("- adding base dependency " + ModelUtils.toString(dep));
}
}
for (final Feature feature : info.model.getFeatures()) {
// skip launchpad feature
if (feature.getName().equals(ModelConstants.FEATURE_LAUNCHPAD)) {
continue;
}
for (final RunMode runMode : feature.getRunModes()) {
for (final ArtifactGroup group : runMode.getArtifactGroups()) {
for (final org.apache.sling.provisioning.model.Artifact a : group) {
if (a.getGroupId().equals(info.project.getGroupId()) && a.getArtifactId().equals(info.project.getArtifactId()) && a.getVersion().equals(info.project.getVersion())) {
// skip artifact from the same project
env.logger.debug("- skipping dependency " + a.toMvnUrl());
continue;
}
final Dependency dep = new Dependency();
dep.setGroupId(a.getGroupId());
dep.setArtifactId(a.getArtifactId());
dep.setVersion(a.getVersion());
dep.setType(a.getType());
dep.setClassifier(a.getClassifier());
dep.setScope(scope);
env.logger.debug("- adding dependency " + ModelUtils.toString(dep));
info.project.getDependencies().add(dep);
}
}
}
}
}
Aggregations