Skip to content

Commit 4ab81db

Browse files
authored
Fix test client ruining main detection (#559)
1 parent c1a9e5e commit 4ab81db

File tree

2 files changed

+47
-25
lines changed

2 files changed

+47
-25
lines changed

http-generator-client/src/main/java/io/avaje/http/generator/client/ComponentReader.java

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
import static java.util.stream.Collectors.toList;
88

99
import java.io.FileNotFoundException;
10-
import java.io.LineNumberReader;
11-
import java.io.Reader;
10+
import java.io.IOException;
11+
import java.net.URI;
12+
import java.nio.file.Files;
1213
import java.nio.file.NoSuchFileException;
13-
import java.util.ArrayList;
14-
import java.util.Collections;
15-
import java.util.List;
14+
import java.nio.file.Path;
15+
import java.util.HashSet;
1616
import java.util.Map;
17+
import java.util.Set;
1718

1819
import javax.annotation.processing.FilerException;
1920
import javax.lang.model.element.Modifier;
2021
import javax.lang.model.element.TypeElement;
21-
import javax.tools.FileObject;
2222
import javax.tools.StandardLocation;
2323

2424
import io.avaje.http.generator.core.APContext;
@@ -64,32 +64,40 @@ void read() {
6464
}
6565
}
6666

67-
private List<String> loadMetaInf() {
67+
private Set<String> loadMetaInf() {
68+
var set = new HashSet<String>();
6869
try {
69-
final FileObject fileObject = filer().getResource(StandardLocation.CLASS_OUTPUT, "", Constants.META_INF_COMPONENT);
70-
if (fileObject != null) {
71-
final List<String> lines = new ArrayList<>();
72-
final Reader reader = fileObject.openReader(true);
73-
final LineNumberReader lineReader = new LineNumberReader(reader);
74-
String line;
75-
while ((line = lineReader.readLine()) != null) {
76-
line = line.trim();
77-
if (!line.isEmpty()) {
78-
lines.add(line);
79-
}
80-
}
81-
return lines;
82-
}
70+
addLines(mainMetaInfURI(), set);
71+
addLines(metaInfURI(), set);
72+
} catch (final IOException e) {
73+
logWarn("Error reading services file: " + e.getMessage());
74+
}
75+
return set;
76+
}
8377

78+
private static void addLines(URI uri, HashSet<String> set) {
79+
try (var lines = Files.lines(Path.of(uri))) {
80+
lines.forEach(set::add);
8481
} catch (FileNotFoundException | NoSuchFileException e) {
8582
// logDebug("no services file yet");
86-
8783
} catch (final FilerException e) {
8884
logDebug("FilerException reading services file");
89-
90-
} catch (final Exception e) {
85+
} catch (Exception e) {
9186
logWarn("Error reading services file: " + e.getMessage());
9287
}
93-
return Collections.emptyList();
88+
}
89+
90+
private static URI mainMetaInfURI() throws IOException {
91+
return URI.create(
92+
metaInfURI()
93+
.toString()
94+
.replaceFirst("java/test", "java/main")
95+
.replaceFirst("test-classes", "classes"));
96+
}
97+
98+
private static URI metaInfURI() throws IOException {
99+
return filer()
100+
.getResource(StandardLocation.CLASS_OUTPUT, "", Constants.META_INF_COMPONENT)
101+
.toUri();
94102
}
95103
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package example.github;
2+
3+
import java.util.List;
4+
5+
import io.avaje.http.api.Client;
6+
import io.avaje.http.api.Get;
7+
import io.avaje.http.client.HttpException;
8+
9+
@Client
10+
public interface Dummy {
11+
12+
@Get("users/{user}/repos")
13+
List<Repo> listRepos(String user, String other) throws HttpException;
14+
}

0 commit comments

Comments
 (0)