Skip to content

Conversation

@suztomo
Copy link
Contributor

@suztomo suztomo commented Jan 31, 2020

Fixes #1170 . The problem was gax-java's Gradle build directory contains multiple pom.xml files that have the same artifactId.

This change worked fine for a manually-created bad entry in gax-bom: https://gist.github.com/suztomo/85ba6c8f27b40db1809dbdbad8991c85

@@ -0,0 +1,14 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
Copy link
Contributor Author

@suztomo suztomo Jan 31, 2020

Choose a reason for hiding this comment

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

LinkageMonitorTest.testFindLocalArtifacts ensures this file is not picked up.

@suztomo suztomo requested a review from elharo January 31, 2020 20:27
String name = pathElement.toString();
if (name.equals("build") || name.equals("target")) {
// Exclude Gradle's build directory and Maven's target directory.
continue PATHS_LOOP;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this truly necessary? Usually there's a cleaner approach that does not use continue. Here I think you can reverse the if and avoid continue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the label. Does this look good now?

}

ImmutableSet<Path> elements = ImmutableSet.copyOf(path);
if (elements.contains(Paths.get("build")) || elements.contains(Paths.get("target"))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it matter where in the path this directory occurs? Can it be only at the end? What if a something several levels up has the name build or target?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would say it does not matter.

From my experience, it's a common practice to avoid using "build" or "target" directory to place something to be published.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another logic I have in mind: flags to indicate the existence of "build.gradle" and "pom.xml" files. (It gets complicated as it seeks for accuracy)

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we can talk about this offline, but I don't think this one is answered. As written, this seems buggy to me.

@suztomo
Copy link
Contributor Author

suztomo commented Feb 3, 2020

@elharo As discussed, the exception is on org.jacoco:org.jacoco.agent's pom.xml, stored in build directory. Regarding pom.xml generation, fortunately gax does not rely on Gradle to generate pom.xml and it has pom.xml in its repository.

The solution in this PR is just to ignore "build" directory.

}

ImmutableSet<Path> elements = ImmutableSet.copyOf(path);
if (elements.contains(Paths.get("build")) || elements.contains(Paths.get("target"))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we can talk about this offline, but I don't think this one is answered. As written, this seems buggy to me.


```
set -e # fail if any of command fails
# Install artifacts to local Maven repository. The command depends on build system of the project.
Copy link
Contributor

Choose a reason for hiding this comment

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

to --> in the

continue;
}

Verify.verify(
Copy link
Contributor

Choose a reason for hiding this comment

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

This will throw an exception the calling code isn't prepared to handle. This method should handle both cases here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to use path.relativize in case it is an absolute path.

@suztomo suztomo changed the title Linkage Monitor to work with Gradle Linkage Monitor to ignore Gradle's build directory Feb 4, 2020
@suztomo suztomo merged commit cf5ce6d into master Feb 4, 2020
@suztomo suztomo deleted the linkage-monitor-gradle branch February 4, 2020 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linkage Monitor to ignore Gradle's build directory

3 participants