-
Notifications
You must be signed in to change notification settings - Fork 48
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
Conversation
<dependency> | ||
<groupId>com.google.cloud</groupId> | ||
<artifactId>google-cloud</artifactId> | ||
<version>${googleCloudJavaVersion}</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
googleCloudJavaBomVersion
?
scopePresent = true; | ||
} | ||
} | ||
Assert.assertTrue(scopePresent); |
There was a problem hiding this comment.
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
?
@@ -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$ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codecov Report
@@ Coverage Diff @@
## master #2956 +/- ##
============================================
- Coverage 69.2% 69.18% -0.02%
- Complexity 2648 2657 +9
============================================
Files 356 358 +2
Lines 12428 12482 +54
Branches 1474 1483 +9
============================================
+ Hits 8601 8636 +35
- Misses 3220 3233 +13
- Partials 607 613 +6
Continue to review full report at Codecov.
|
* Maps all prefixes to http://maven.apache.org/POM/4.0.0 and | ||
* all namespace URIs to "m". Not suitable for general use. | ||
*/ | ||
class Maven4NamespaceContext implements NamespaceContext { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can reuse com.google.cloud.tools.eclipse.appengine.validation.MavenContext
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd forgotten about that class. Looking at it now, it has the same issues this class does. That is, it works only for very limited code and is actively broken for all other uses. Given that, I don't feels safe exposing it as part of the public API. We could look for or build a more correct namespace context that fully satisfies the interface's contract.
Trying to understand the direction of this BOM stuff. So, with a BOM, I believe eventually we will get rid of the |
With the BOM we can remove explicit versions from the google-cloud-java dependencies. However this may require splitting our library addition code into two: one for google-cloud-java dependencies and one for everything else. |
There's a bug where our code is expecting there to be only one
I'm surprised tests didn't catch this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, this PR now fixes bugs that occur when adding libraries to any existing pom.xml files that have a dependencyManagement
element.
It's not only about adding bom support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping. This is now ready for review.
@@ -0,0 +1,89 @@ | |||
/* | |||
* Copyright 2018 Google LLC. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No period after "LLC".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -1,5 +1,5 @@ | |||
/* | |||
* Copyright 2017 Google Inc. | |||
* Copyright 2017 Google LLC. All Rights Reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should end with "LLC" with no period.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
Node rootElement = doc.getDocumentElement(); | ||
|
||
dependencyManager = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this dependencyManager
or dependencyManagement
? (I'm confused.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
management, done
@@ -13,6 +13,18 @@ | |||
<artifactId>com.google.cloud.tools.eclipse.appengine.libraries.test</artifactId> | |||
<version>0.1.0-SNAPSHOT</version> | |||
<packaging>eclipse-test-plugin</packaging> | |||
|
|||
<dependencyManagement> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this dependencyManager
or dependencyManagement
? (I'm confused.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dependencyManagement
|
||
/** | ||
* | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
private final static XPathFactory factory = XPathFactory.newInstance(); | ||
|
||
private static Set<String> artifacts; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about artifactIds
?
"http://maven.apache.org/POM/4.0.0", "dependencies"); | ||
} | ||
} catch (XPathExpressionException ex) { | ||
IStatus status = StatusUtil.error(Pom.class, ex.getMessage(), ex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem it will happen. RuntimeException
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we can return a status here, that's safer. But your'e right, it shouldn't happen.
String bomArtifactId = (String) xpath.evaluate( | ||
"string(./m:dependencies/m:dependency/m:artifactId)", | ||
dependencyManager, | ||
XPathConstants.STRING); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's say users include another 3rd-party BOM in addition to ours. I guess this code may not work, since it could return the group ID and artifact ID of the other 3rd-party POM?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Let me think about that.
FYI, right now in prod the code is broken with any dependencyManagement section including ours.
static { | ||
try { | ||
List<CloudLibrary> cloudLibraries = | ||
com.google.cloud.tools.libraries.CloudLibraries.getCloudLibraries(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To confirm: so we simply assume here our Cloud BOM includes all the libraries that appengine-plugins-core returns, and a future work is to read the actual content of the BOM?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
@@ -1,5 +1,5 @@ | |||
/* | |||
* Copyright 2017 Google Inc. | |||
* Copyright 2017 Google LLC. All Rights Reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No All Rights Reserved, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right
NodeList dependencies = actual.getElementsByTagName("dependencies"); | ||
NodeList children = ((Element) dependencies.item(0)).getElementsByTagName("dependency"); | ||
|
||
Assert.assertEquals(2, children.getLength()); |
There was a problem hiding this comment.
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 keeping asserting length == 2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -286,7 +297,7 @@ public void testResolveLibraries() throws CoreException { | |||
Library library2 = newLibrary("id2", file1, file2); | |||
|
|||
pom.updateDependencies(Arrays.asList(library1), Arrays.asList(library1, library2)); | |||
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the introduced space
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Google style is officially not to worry about trailing whitespace
Element dependencies = (Element) dependenciesList.item(0); | ||
Assert.assertEquals(2, dependenciesList.getLength()); | ||
|
||
Element dependencies = (Element) dependenciesList.item(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it's worth a comment here saying item 0 is from the <dependencyManagement>
section? (Or would it be clearer to rewrite this section using XPath too to ensure the depMgmt section is never seen?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added comment
import org.w3c.dom.Element; | ||
|
||
/** | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class comment? This class might be better named to indicate that it's specific to the Google Cloud BOM. (Need to remember that users may use other BOMs, like the Spring BOM, and the bom project defines BOMs for all sorts of projects.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expect it's going to become more generic. For now it's package private.
static { | ||
try { | ||
List<CloudLibrary> cloudLibraries = | ||
com.google.cloud.tools.libraries.CloudLibraries.getCloudLibraries(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for the FQCN?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a same-name class, so I think it's good to signify that this is from appengine-plugins-core.
|
||
try { | ||
String bomGroupId = (String) xpath.evaluate( | ||
"string(./m:dependencies/m:dependency/m:groupId)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't you want to get with type=pom
and scope=import
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not necessary
XPathConstants.NODESET); | ||
Assert.assertEquals(1, dependencyManagementNodes.getLength()); | ||
|
||
String bomGroupId = (String) xpath.evaluate( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth checking that there is a single <dependencies>
element?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we're not. We're getting the first top-level dependencies element.
The ultimate fix to the JUnit warning is to expand the dependency checking code to actually query the BOM. For now, though, it's just a low priority warning with no actual effect on the user's code. |
I don't see junit in the
https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/google-cloud-bom/pom.xml
(and wouldn't expect it there)
…On Fri, Mar 23, 2018 at 6:53 PM Elliotte Rusty Harold < ***@***.***> wrote:
Merged #2956
<#2956>.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2956 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHf5HfYDXItT0d7qn2Wm87IraCiSVoR0ks5thXzvgaJpZM4SypUT>
.
|
The BOM pulls in transitive dependencies, not just the immediate declarations. It's a lot broader and deeper than it looks. |
Yeah, it pulls in |
Did you guys trace which dep is pulling in junit? We should file a bug.
…On Mon, Mar 26, 2018 at 10:41 AM Chanseok Oh ***@***.***> wrote:
Yeah, it pulls in guava too. The <version> element is not needed when
importing the BOM.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2956 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHf5Hdb6856jS5uLgNLmRQHelrgocZE4ks5tiP4mgaJpZM4SypUT>
.
|
Element springDependency = | ||
configureBom(doc, "org.springframework.boot", "spring-boot-dependencies", "2.0.0.RELEASE"); | ||
dependencies.appendChild(springDependency); | ||
Element cloudDependency = configureBom(doc, "com.google.cloud", "google-cloud", "0.40.0-alpha"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha. This should be google-cloud-bom
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you guys trace which dep is pulling in junit? We should file a bug.
@patflynn turns out we were not pulling in a BOM.
@chanseokoh fix #2923 for Maven projects