Skip to content

Commit

Permalink
naming tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Hartmeier committed Nov 24, 2023
1 parent 59ad5f2 commit 8957b17
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void addOption(String option) {
}

@Override
public List<Descriptor> doScan() throws IOException {
public List<Descriptor> list() throws IOException {
List<Descriptor> result = new ArrayList<>();
Node<?> listing = world.validNode(artifactory() + "api/storage/" + repositoryAndPath() + "?list&deep=1&mdTimestamps=0");
try {
Expand All @@ -86,7 +86,7 @@ public List<Descriptor> doScan() throws IOException {
}

@Override
public Descriptor scanOpt(Descriptor descriptor) {
public Descriptor load(Descriptor descriptor) {
// TODO: currently all processing done by parser
return descriptor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public BitbucketRepository(Environment environment, String name, HttpNode bitbuc
}

@Override
public List<Descriptor> doScan() throws IOException {
public List<Descriptor> list() throws IOException {
List<Descriptor> result = new ArrayList<>();
Bitbucket bb;
String bbProject;
Expand Down Expand Up @@ -90,7 +90,7 @@ public List<Descriptor> doScan() throws IOException {
}

@Override
public Descriptor scanOpt(Descriptor descriptor) throws IOException {
public Descriptor load(Descriptor descriptor) throws IOException {
// TODO
return descriptor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public GiteaRepository(Environment environment, String repository, String hostna
}

@Override
public List<GiteaProject> doScan() throws IOException {
public List<GiteaProject> list() throws IOException {
List<String> orgs;
orgs = listCurrentUserOrgs();
orgs.addAll(listOrganizations());
Expand All @@ -124,7 +124,7 @@ public List<GiteaProject> doScan() throws IOException {
}

@Override
public Descriptor scanOpt(GiteaProject project) throws IOException {
public Descriptor load(GiteaProject project) throws IOException {
try {
return project.scanOpt(environment, hostname, repositoryApi);
} catch (ApiException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public List<String> files(GithubRepo repo) throws IOException {
}

@Override
public List<GithubRepo> doScan() throws IOException {
public List<GithubRepo> list() throws IOException {
if (groupsOrUsers.isEmpty()) {
throw new IOException("cannot collect all repos ...");
}
Expand All @@ -160,7 +160,7 @@ public HttpNode fileNode(GithubRepo repo, String path) {
}

@Override
public Descriptor scanOpt(GithubRepo repo) throws IOException {
public Descriptor load(GithubRepo repo) throws IOException {
Descriptor.Creator m;
Node<?> node;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void setToken(String token) {
}

@Override
public List<GitlabProject> doScan() throws IOException {
public List<GitlabProject> list() throws IOException {
List<GitlabProject> result;

if (groupsOrUsers.isEmpty()) {
Expand All @@ -174,7 +174,7 @@ private GitUrl repoUrl(GitlabProject project) throws ScmUrlException {
}

@Override
public Descriptor scanOpt(GitlabProject project) throws IOException {
public Descriptor load(GitlabProject project) throws IOException {
Descriptor.Creator m;
Node<?> node;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public JsonRepository(String name, Node node) {
}

@Override
public List<Descriptor> doScan() throws IOException {
public List<Descriptor> list() throws IOException {
List<Descriptor> result = new ArrayList<>();
JsonArray array;
Descriptor descriptor;
Expand All @@ -75,7 +75,7 @@ public List<Descriptor> doScan() throws IOException {
}

@Override
public Descriptor scanOpt(Descriptor descriptor) throws IOException {
public Descriptor load(Descriptor descriptor) throws IOException {
return descriptor; // TODO
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ public void addExclude(String str) {
}

@Override
public List<NodeProject> doScan() throws IOException {
public List<NodeProject> list() throws IOException {
List<NodeProject> result = new ArrayList<>();
scan(root, true, result);
return result;
}

@Override
public Descriptor scanOpt(NodeProject project) throws IOException {
public Descriptor load(NodeProject project) throws IOException {
return project.descriptor();
}

Expand Down
22 changes: 13 additions & 9 deletions src/main/java/net/oneandone/pommes/repository/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.concurrent.BlockingQueue;

/** A place to search for descriptors. */
public abstract class Repository<T> {
public abstract class Repository<E> {
private static Map<String, Constructor> types;
static {
types = new HashMap<>();
Expand Down Expand Up @@ -88,22 +88,26 @@ public void addExclude(String exclude) {
throw new ArgumentException(name + ": excludes not supported: " + exclude);
}
public final void scan(BlockingQueue<Descriptor> dest, Console console) throws IOException, InterruptedException {
console.info.println("collecting projects ...");
List<T> projects = doScan();
console.info.println("collected " + projects.size());
for (T project : projects) {
console.info.print("collecting entries ...");
console.info.flush();
List<E> entries = list();
console.info.println(" done: " + entries.size());
for (E entry : entries) {
try {
var descriptor = scanOpt(project);
var descriptor = load(entry);
if (descriptor != null) {
dest.put(descriptor);
}
} catch (IOException e) {
console.error.println("cannot load " + project + ": " + e.getMessage());
console.error.println("cannot load " + entry + ": " + e.getMessage());
e.printStackTrace(console.verbose);
}
}
}

public abstract List<T> doScan() throws IOException;
public abstract Descriptor scanOpt(T project) throws IOException;
/** List entries in the repository */
public abstract List<E> list() throws IOException;

/** Load an entry, i.e. return the respective descriptor */
public abstract Descriptor load(E entry) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@

import net.oneandone.inline.Console;
import net.oneandone.pommes.cli.Environment;
import net.oneandone.pommes.descriptor.Descriptor;
import net.oneandone.sushi.fs.World;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.Charset;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -51,7 +49,7 @@ public void repo() throws IOException {
var pom = hub.fileNode(repo, "pom.xml").readString();
assertTrue(hub.files(repo).contains("pom.xml"));
assertTrue(pom.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"), pom);
var descriptor = hub.scanOpt(repo);
var descriptor = hub.load(repo);
var project = descriptor.load(new Environment(Console.create(), World.create()));
System.out.println("" + project.revision);
assertEquals("net.oneandone:pommes", project.artifact.toGaString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void scanOpt() throws IOException {
System.out.println("" + gitlab.files(project));
System.out.println("default branch: " + project.default_branch());
System.out.println("branch revision: " + gitlab.branchRevision(project, project.default_branch()));
descriptor = gitlab.scanOpt(project);
descriptor = gitlab.load(project);
var pommes = descriptor.load(environment);
System.out.println("project: " + project);
assertEquals("ru.t1.sochilenkov.tm", pommes.artifact.groupId);
Expand Down

0 comments on commit 8957b17

Please sign in to comment.