Skip to content

Commit

Permalink
Address PR requests
Browse files Browse the repository at this point in the history
  • Loading branch information
a1flecke committed Jun 23, 2020
1 parent d9bd96c commit a2779cf
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 8 deletions.
17 changes: 10 additions & 7 deletions maven/lib/dependabot/maven/metadata_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ def look_up_source
tmp_source = look_up_source_in_pom(parent)
return unless tmp_source

artifact = dependency.name.split(":").last
return tmp_source if tmp_source.repo.end_with?(artifact)
return tmp_source if tmp_source.repo.end_with?(dependency_artifact_id)
return tmp_source if repo_has_subdir_for_dep?(tmp_source)
end

Expand All @@ -34,14 +33,13 @@ def repo_has_subdir_for_dep?(tmp_source)
return @repo_has_subdir_for_dep[tmp_source]
end

artifact = dependency.name.split(":").last
fetcher =
FileFetchers::Base.new(source: tmp_source, credentials: credentials)

@repo_has_subdir_for_dep[tmp_source] =
fetcher.send(:repo_contents, raise_errors: false).
select { |f| f.type == "dir" }.
any? { |f| artifact.end_with?(f.name) }
any? { |f| dependency_artifact_id.end_with?(f.name) }
rescue Dependabot::BranchNotFound
tmp_source.branch = nil
retry
Expand Down Expand Up @@ -96,18 +94,17 @@ def source_from_anywhere_in_pom(pom)

github_urls.find do |url|
repo = Source.from_url(url).repo
repo.end_with?(dependency.name.split(":").last)
repo.end_with?(dependency_artifact_id)
end
end

def dependency_pom_file
return @dependency_pom_file unless @dependency_pom_file.nil?

artifact_id = dependency.name.split(":").last
response = Excon.get(
"#{maven_repo_dependency_url}/"\
"#{dependency.version}/"\
"#{artifact_id}-#{dependency.version}.pom",
"#{dependency_artifact_id}-#{dependency.version}.pom",
headers: auth_details,
idempotent: true,
**SharedHelpers.excon_defaults
Expand All @@ -118,6 +115,12 @@ def dependency_pom_file
@dependency_pom_file = Nokogiri::XML("")
end

def dependency_artifact_id
_group_id, artifact_id, = dependency.name.split(":")

artifact_id
end

def parent_pom_file(pom)
doc = pom.dup
doc.remove_namespaces!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def pom
end

def dependency_metadata_url(repository_url)
group_id, artifact_id = dependency.name.split(":")
group_id, artifact_id, = dependency.name.split(":")

"#{repository_url}/"\
"#{group_id.tr('.', '/')}/"\
Expand Down
26 changes: 26 additions & 0 deletions maven/spec/dependabot/maven/file_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,27 @@
package_manager: "maven"
)
end
let(:mockk_dependency) do
Dependabot::Dependency.new(
name: "io.mockk:mockk:sources",
version: "1.10.0",
requirements: [{
file: "pom.xml",
requirement: "1.10.0",
groups: [],
source: nil,
metadata: { packaging_type: "jar" }
}],
previous_requirements: [{
file: "pom.xml",
requirement: "1.0.0",
groups: [],
source: nil,
metadata: { packaging_type: "jar" }
}],
package_manager: "maven"
)
end
let(:dependency_groups) { ["test"] }

describe "#updated_dependency_files" do
Expand All @@ -72,6 +93,11 @@
to include(%(<project xmlns="http://maven.apache.org/POM/4.0.0"\n))
end

context "handles dependencies with classifiers" do
let(:dependencies) { [dependency, mockk_dependency] }
its(:content) { is_expected.to include("<version>1.10.0</version>") }
end

context "with rogue whitespace" do
let(:pom_body) { fixture("poms", "whitespace.xml") }
let(:dependency_groups) { [] }
Expand Down
13 changes: 13 additions & 0 deletions maven/spec/dependabot/maven/metadata_finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,22 @@
"guava/23.3-jre/guava-23.3-jre.pom"
end
let(:maven_response) { fixture("poms", "guava-23.3-jre.xml") }
let(:mockk_url) do
"https://repo.maven.apache.org/maven2/io/mockk/"\
"mockk/1.10.0/mockk-1.10.0.pom"
end
let(:mockk_response) { fixture("poms", "mockk-1.10.0.pom.xml") }

before do
stub_request(:get, maven_url).to_return(status: 200, body: maven_response)
stub_request(:get, mockk_url).to_return(status: 200, body: mockk_response)
end

context "when the dependency name has a classifier" do
let(:dependency_name) { "io.mockk:mockk:sources" }
let(:dependency_version) { "1.10.0" }

it { is_expected.to eq("https://github.com/mockk/mockk") }
end

context "when the github link is buried in the pom" do
Expand Down
59 changes: 59 additions & 0 deletions maven/spec/fixtures/poms/mockk-1.10.0.pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- This module was also published with a richer model, Gradle metadata, -->
<!-- which should be used instead. Do not delete the following line which -->
<!-- is to indicate to Gradle or any Gradle module metadata file consumer -->
<!-- that they should prefer consuming it instead. -->
<!-- do_not_remove: published-with-gradle-metadata -->
<modelVersion>4.0.0</modelVersion>
<groupId>io.mockk</groupId>
<artifactId>mockk</artifactId>
<version>1.10.0</version>
<name>MockK</name>
<description>mocking library for Kotlin</description>
<url>http://mockk.io</url>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
</license>
</licenses>
<developers>
<developer>
<id>oleksiyp</id>
<name>Oleksii Pylypenko</name>
<email>oleksiy.pylypenko@gmail.com</email>
</developer>
</developers>
<scm>
<connection>scm:git:git@github.com:mockk/mockk.git</connection>
<developerConnection>scm:git:git@github.com:mockk/mockk.git</developerConnection>
<url>https://github.com/mockk/mockk/</url>
</scm>
<dependencies>
<dependency>
<groupId>io.mockk</groupId>
<artifactId>mockk-common</artifactId>
<version>1.10.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.mockk</groupId>
<artifactId>mockk-dsl-jvm</artifactId>
<version>1.10.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.mockk</groupId>
<artifactId>mockk-agent-jvm</artifactId>
<version>1.10.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
<version>1.3.61</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>

0 comments on commit a2779cf

Please sign in to comment.