in plugin/src/main/java/io/fabric8/maven/plugin/mojo/infra/SetupMojo.java [100:188]
private boolean createOrUpdateFabric8MavenPlugin(Document doc) throws MojoExecutionException {
boolean updated = false;
String latestVersion;
try {
latestVersion = MavenUtil.getVersion(PLUGIN_GROUPID, PLUGIN_ARTIFACTID);
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
// lets check that there's a property defined
String currentVersion = project.getProperties().getProperty(FABRIC8_MAVEN_PLUGIN_VERSION_PROPERTY);
String versionExpression = "${" + FABRIC8_MAVEN_PLUGIN_VERSION_PROPERTY + "}";
Element fmpPlugin = findPlugin(doc, PLUGIN_GROUPID, PLUGIN_ARTIFACTID);
boolean pluginMissing = fmpPlugin == null;
if (updateVersion || pluginMissing) {
if (useVersionProperty) {
Element documentElement = doc.getDocumentElement();
Element properties = firstChild(documentElement, "properties");
if (properties == null) {
properties = addChildAfter(appendAfterLastElement(properties, doc.createTextNode("\n ")), "properties");
}
if (Strings.isNullOrBlank(currentVersion)) {
addChildAfter(appendAfterLastElement(properties, doc.createTextNode("\n ")), FABRIC8_MAVEN_PLUGIN_VERSION_PROPERTY, latestVersion);
updated = true;
} else if (!Objects.equals(currentVersion, latestVersion)) {
Element propertyElement = DomHelper.firstChild(properties, FABRIC8_MAVEN_PLUGIN_VERSION_PROPERTY);
if (propertyElement != null) {
propertyElement.setTextContent(latestVersion);
updated = true;
}
}
} else {
versionExpression = latestVersion;
}
}
if (pluginMissing) {
fmpPlugin = findOrAddPlugin(doc, PLUGIN_GROUPID, PLUGIN_ARTIFACTID, versionExpression);
updated = true;
}
if (updateVersion || pluginMissing) {
String version = DomHelper.firstChildTextContent(fmpPlugin, "version");
if (version == null || !version.equals(versionExpression)) {
Element versionElement = DomHelper.firstChild(fmpPlugin, "version");
if (versionElement == null) {
Element artifactId = DomHelper.firstChild(fmpPlugin, "artifactId");
Text textNode = doc.createTextNode("\n ");
if (artifactId != null) {
addChildAfter(artifactId, textNode);
} else {
appendAfterLastElement(fmpPlugin, textNode);
}
addChildAfter(textNode, "version", versionExpression);
} else {
versionElement.setTextContent(versionExpression);
}
updated = true;
}
}
if (pluginMissing) {
Element executions = firstChild(fmpPlugin, "executions");
if (executions == null) {
executions = addChildAfter(appendAfterLastElement(fmpPlugin, doc.createTextNode("\n ")), "executions");
} else {
// lets remove all the children to be sure
DomHelper.removeChildren(executions);
}
executions.appendChild(doc.createTextNode("\n "));
Element execution = DomHelper.addChildElement(executions, "execution");
execution.appendChild(doc.createTextNode("\n "));
DomHelper.addChildElement(execution, "id", "fmp");
execution.appendChild(doc.createTextNode("\n "));
Element goals = DomHelper.addChildElement(execution, "goals");
execution.appendChild(doc.createTextNode("\n "));
String[] goalNames = {"resource", "helm", "build"};
for (String goalName : goalNames) {
goals.appendChild(doc.createTextNode("\n "));
DomHelper.addChildElement(goals, "goal", goalName);
}
goals.appendChild(doc.createTextNode("\n "));
executions.appendChild(doc.createTextNode("\n "));
updated = true;
}
return updated;
}