Skip to content

Commit

Permalink
Fix test client ruining main detection
Browse files Browse the repository at this point in the history
  • Loading branch information
SentryMan committed Jan 27, 2025
1 parent 29270a2 commit 54c6754
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
import static java.util.stream.Collectors.toList;

import java.io.FileNotFoundException;
import java.io.LineNumberReader;
import java.io.Reader;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.annotation.processing.FilerException;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import javax.tools.FileObject;
import javax.tools.StandardLocation;

import io.avaje.http.generator.core.APContext;
Expand All @@ -38,6 +37,7 @@ final class ComponentReader {

void read() {
for (String fqn : loadMetaInf()) {
System.err.println(fqn );
final TypeElement moduleType = typeElement(fqn);
if (moduleType != null) {
var adapters =
Expand All @@ -64,22 +64,26 @@ void read() {
}
}

private List<String> loadMetaInf() {
private Set<String> loadMetaInf() {
var set = new HashSet<String>();
try {
final FileObject fileObject = filer().getResource(StandardLocation.CLASS_OUTPUT, "", Constants.META_INF_COMPONENT);
if (fileObject != null) {
final List<String> lines = new ArrayList<>();
final Reader reader = fileObject.openReader(true);
final LineNumberReader lineReader = new LineNumberReader(reader);
String line;
while ((line = lineReader.readLine()) != null) {
line = line.trim();
if (!line.isEmpty()) {
lines.add(line);
}
}
return lines;
}
var main =
Path.of(
URI.create(
filer()
.getResource(StandardLocation.CLASS_OUTPUT, "", Constants.META_INF_COMPONENT)
.toUri()
.toString()
.replaceFirst("java/test", "java/main")
.replaceFirst("test-classes", "classes")));

final var fileObject =
Path.of(
filer()
.getResource(StandardLocation.CLASS_OUTPUT, "", Constants.META_INF_COMPONENT)
.toUri());
Files.lines(main).forEach(set::add);
Files.lines(fileObject).forEach(set::add);

} catch (FileNotFoundException | NoSuchFileException e) {
// logDebug("no services file yet");
Expand All @@ -90,6 +94,6 @@ private List<String> loadMetaInf() {
} catch (final Exception e) {
logWarn("Error reading services file: " + e.getMessage());
}
return Collections.emptyList();
return set;
}
}
14 changes: 14 additions & 0 deletions tests/test-client/src/test/java/example/github/Dummy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package example.github;

import java.util.List;

import io.avaje.http.api.Client;
import io.avaje.http.api.Get;
import io.avaje.http.client.HttpException;

@Client
public interface Dummy {

@Get("users/{user}/repos")
List<Repo> listRepos(String user, String other) throws HttpException;
}

0 comments on commit 54c6754

Please sign in to comment.