Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a BOM to our generated pom.xml files #2956

Merged
merged 18 commits into from
Mar 23, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Import-Package: com.google.cloud.tools.eclipse.test.util,
com.google.cloud.tools.eclipse.test.util.project,
com.google.cloud.tools.eclipse.test.util.ui,
com.google.common.cache;version="[21.0.0,22.0.0)",
org.apache.maven.artifact.versioning,
org.eclipse.core.resources,
org.eclipse.core.runtime;version="3.5.0",
org.eclipse.jdt.core,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

Expand Down Expand Up @@ -237,6 +238,45 @@ private Element validatePom()
new DefaultArtifactVersion(pluginVersion.getTextContent());
DefaultArtifactVersion expected = new DefaultArtifactVersion("1.3.2");
Assert.assertTrue(artifactVersion.compareTo(expected) >= 0);

NodeList dependencyManagement = root.getElementsByTagName("dependencyManagement");
Assert.assertEquals(1, dependencyManagement.getLength());

for (int i = 0; i < dependencyManagement.getLength(); i++) {
Node item = dependencyManagement.item(i);
for (int j = 0; j < item.getChildNodes().getLength(); j++) {
Node dependencies = item.getChildNodes().item(j);
if (dependencies.getNodeType() == Node.ELEMENT_NODE) {
Assert.assertEquals("dependencies", dependencies.getNodeName());
NodeList coordinates = dependencies.getChildNodes();
for (int k = 0; k < coordinates.getLength(); k++) {
Node dependency = coordinates.item(k);
if (dependency.getNodeType() == Node.ELEMENT_NODE) {
Assert.assertEquals("dependency", dependency.getNodeName());
boolean scopePresent = false;
boolean typePresent = false;
for (int c = 0; c < dependency.getChildNodes().getLength(); c++) {
Node coord = dependency.getChildNodes().item(c);
if (coord.getNodeName().equals("version")) {
DefaultArtifactVersion bomVersion = new DefaultArtifactVersion(
coord.getTextContent().trim());
Assert.assertTrue(
bomVersion.compareTo(new DefaultArtifactVersion("0.40.0-alpha")) >= 0);
} else if (coord.getNodeName().equals("type")) {
typePresent = true;
} else if (coord.getNodeName().equals("scope")) {
scopePresent = true;
}
}
Assert.assertTrue(scopePresent);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be simplified using XPath as in PomXmlValidator?

Assert.assertTrue(typePresent);
}

}
}
}
}

return root;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ private static void createPomXml(IProject project, AppEngineProjectConfig config
properties.put("projectArtifactId", config.getMavenArtifactId()); //$NON-NLS-1$
properties.put("projectVersion", config.getMavenVersion()); //$NON-NLS-1$

String bomVersion = getCurrentVersion(
"com.google.cloud", //$NON-NLS-1$
"google-cloud", //$NON-NLS-1$
"0.40.0-alpha"); //$NON-NLS-1$
properties.put("googleCloudJavaVersion", bomVersion); //$NON-NLS-1$

String mavenPluginVersion = getCurrentVersion(
"com.google.cloud.tools", //$NON-NLS-1$
"appengine-maven-plugin", //$NON-NLS-1$
Expand All @@ -208,7 +214,7 @@ private static void createPomXml(IProject project, AppEngineProjectConfig config
String sdkVersion = getCurrentVersion(
"com.google.appengine", //$NON-NLS-1$
"appengine-api-1.0-sdk", //$NON-NLS-1$
"1.9.62"); //$NON-NLS-1$
"1.9.63"); //$NON-NLS-1$
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth pulling these artifact constants (including the BOM artifact too) out into explicit constants rather than have them scattered in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Can you file an issue for that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

properties.put("appEngineApiSdkVersion", sdkVersion); //$NON-NLS-1$

if (isStandardProject) {
Expand All @@ -229,6 +235,9 @@ private static void createPomXml(IProject project, AppEngineProjectConfig config

private static String getCurrentVersion(String group, String artifact, String defaultVersion) {
ArtifactVersion version = ArtifactRetriever.DEFAULT.getLatestReleaseVersion(group, artifact);
if (version == null) { // there is no release version
version = ArtifactRetriever.DEFAULT.getLatestVersion(group, artifact);
}
if (version == null) {
return defaultVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ public static String getEclipseVersion() {
return "_(failed to get bundle \"org.eclipse.platform\")_";
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
<prerequisites>
<maven>3.3.9</maven>
</prerequisites>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud</artifactId>
<version>${googleCloudJavaVersion}</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

googleCloudJavaBomVersion?

<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- Compile/runtime dependencies -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
<prerequisites>
<maven>3.3.9</maven>
</prerequisites>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud</artifactId>
<version>${googleCloudJavaVersion}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- Compile/runtime dependencies -->
Expand Down