@Override
public boolean install() {
final MavenFacet coreFacet = getProject().getFacet(MavenFacet.class);
Model pom = coreFacet.getModel();
Profile profile = MavenModelUtil.getProfileById(profileId, pom.getProfiles());
final VersionOracle oracle = new VersionOracle(getProject().getFacet(DependencyFacet.class));
if (profile == null) {
addDependenciesToProfile(profileId, Collections.<DependencyBuilder> emptyList(), oracle);
pom = coreFacet.getModel();
profile = MavenModelUtil.getProfileById(profileId, pom.getProfiles());
}
if (profile.getBuild() == null) {
profile.setBuild(new BuildBase());
}
Plugin plugin = getPlugin(getPluginArtifact(), profile.getBuild().getPlugins());
if (plugin == null) {
plugin = new Plugin();
plugin.setArtifactId(getPluginArtifact().getArtifactId());
plugin.setGroupId(getPluginArtifact().getGroupId());
if (ArtifactVault.ERRAI_GROUP_ID.equals(plugin.getGroupId()))
plugin.setVersion(Property.ErraiVersion.invoke());
else
plugin.setVersion(oracle.resolveVersion(plugin.getGroupId(), plugin.getArtifactId()));
profile.getBuild().addPlugin(plugin);
}
final MavenPluginAdapter adapter = new MavenPluginAdapter(plugin);
final Configuration config = adapter.getConfig();
for (final ConfigurationElement elem : getConfigurations()) {
mergeConfigurationElement(config, elem);
}
adapter.setConfig(config);
for (final DependencyBuilder depBuilder : getDependencies()) {
if (depBuilder.getCoordinate().getVersion() == null || depBuilder.getCoordinate().getVersion().equals("")) {
if (ArtifactVault.ERRAI_GROUP_ID.equals(depBuilder.getGroupId())) {
depBuilder.setVersion(Property.ErraiVersion.invoke());
}
else {
depBuilder.setVersion(new VersionOracle(getProject().getFacet(DependencyFacet.class)).resolveVersion(
depBuilder.getGroupId(), depBuilder.getCoordinate().getArtifactId()));
}
}
adapter.addDependency(MavenConverter.convert(depBuilder));
}