final MavenPluginFacet pluginFacet = getProject().getFacet(MavenPluginFacet.class);
final DependencyFacet depFacet = getProject().getFacet(DependencyFacet.class);
final VersionOracle oracle = new VersionOracle(depFacet);
final Dependency pluginDep = DependencyBuilder.create(getPluginArtifact().toString()).setVersion(
oracle.resolveVersion(getPluginArtifact()));
final MavenPluginBuilder plugin;
if (pluginFacet.hasPlugin(pluginDep.getCoordinate())) {
plugin = MavenPluginBuilder.create(pluginFacet.getPlugin(pluginDep.getCoordinate()));
// So that it is not duplicated when added later on
pluginFacet.removePlugin(pluginDep.getCoordinate());
}
else {
plugin = MavenPluginBuilder.create();
plugin.setCoordinate(pluginDep.getCoordinate());
}
Configuration config = plugin.getConfig();
for (final ConfigurationElement configElem : getConfigurations()) {
mergeConfigurationElement(config, configElem);
}
for (final DependencyBuilder dep : getDependencies()) {
if (dep.getCoordinate().getVersion() == null || dep.getCoordinate().getVersion().equals("")) {
if (dep.getGroupId().equals(ArtifactVault.ERRAI_GROUP_ID))
dep.setVersion(Property.ErraiVersion.invoke());
else
dep.setVersion(oracle.resolveVersion(dep.getGroupId(), dep.getCoordinate().getArtifactId()));
}
plugin.addPluginDependency(dep);
}
for (final Execution exec : getExecutions()) {
plugin.addExecution(exec);
}
pluginFacet.addPlugin(plugin);
return true;
}