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

Fix the returned location of packages. #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.thoughtworks.go</groupId>
<artifactId>deb-repo-poller</artifactId>
<version>1.2</version>
<version>1.4</version>
<packaging>jar</packaging>

<properties>
Expand All @@ -25,7 +25,7 @@
<dependency>
<groupId>com.thoughtworks.go</groupId>
<artifactId>deb-repo-query</artifactId>
<version>1.1</version>
<version>1.2</version>
</dependency>

<!-- apache commons -->
Expand Down Expand Up @@ -160,4 +160,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,15 @@ public String forDisplay() {
}

public String getPackageLocation(String filePath) {
String packageLocation = null;
if (url.endsWith("/"))
packageLocation = url.substring(0, url.length() - 1);
else
packageLocation = url;
String[] parts = filePath.split("/");
for (int i = 0; i < parts.length; i++) {
if (!packageLocation.contains(parts[i])) {
packageLocation = merge(packageLocation, parts, i);
break;
}
}
return packageLocation;
}
String packageLocation = url;
// For repo http://in.archive.ubuntu.com/ubuntu/dists/trusty/main/binary-amd64/
// packages will be located under http://in.archive.ubuntu.com/ubuntu/pool/...,
// so truncate the package_location to http://in.archive.ubuntu.com/ubuntu and
// append the filename.

private String merge(String packageLocation, String[] parts, int index) {
for (int i = index; i < parts.length; i++) {
packageLocation += "/" + parts[i];
}
int truncateIndex = url.indexOf("dists");
packageLocation = packageLocation.substring(0, truncateIndex);
packageLocation += filePath;
return packageLocation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ public void shouldFailCheckConnectionToTheRepoWhenRepoFileSystemPathIsNotReachab

@Test
public void shouldNotThrowExceptionIfCheckConnectionToTheRepoPasses() {
new RepoUrl("http://in.archive.ubuntu.com/ubuntu/dists/saucy/main/binary-amd64/", null, null).checkConnection();
new RepoUrl("http://in.archive.ubuntu.com/ubuntu/dists/saucy/main/binary-amd64", null, null).checkConnection();
new RepoUrl("http://in.archive.ubuntu.com/ubuntu/dists/trusty/main/binary-amd64/", null, null).checkConnection();
new RepoUrl("http://in.archive.ubuntu.com/ubuntu/dists/trusty/main/binary-amd64", null, null).checkConnection();
}

@Test
Expand All @@ -117,6 +117,14 @@ public void shouldGetRepoMetadataUrl() throws Exception {
assertThat(new RepoUrl("file:///foo/bar//", null, null).getRepoMetadataUrl(), is("file:///foo/bar/Packages.gz"));
}

@Test
public void shouldGetCorrectPathGetPackageLocation() throws Exception {
assertThat(
new RepoUrl("http://in.archive.ubuntu.com/ubuntu/dists/trusty/main/binary-amd64/", null, null).getPackageLocation("pool/main/e/empathy/account-plugin-aim_3.8.6-0ubuntu9_amd64.deb"),
is("http://in.archive.ubuntu.com/ubuntu/pool/main/e/empathy/account-plugin-aim_3.8.6-0ubuntu9_amd64.deb")
);
}

private void assertRepositoryUrlValidation(String url, String username, String password, List<ValidationError> expectedErrors, boolean isSuccessful) {
ValidationResult errors = new ValidationResult();
new RepoUrl(url, username, password).validate(errors);
Expand Down