Skip to content

Commit 969cef6

Browse files
committed
Fixed relative path of non class files
1 parent fa672e6 commit 969cef6

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/main/java/com/github/sgtsilvio/gradle/android/retrofix/RetroFixTransform.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,17 @@ public void transform(final @NotNull TransformInvocation transformInvocation) {
115115
final Path inputPath = Paths.get(directoryInput.getFile().getAbsolutePath());
116116
Files.walk(inputPath)
117117
.filter(Files::isRegularFile)
118-
.map(inputPath::relativize)
119118
.filter(Lambdas.predicate(path -> {
120119
if (path.getFileName().toFile().getName().endsWith(".class")) {
121120
return true;
122121
}
123-
final File file = new File(outputDir, path.toString());
122+
final File file = new File(outputDir, inputPath.relativize(path).toString());
124123
//noinspection ResultOfMethodCallIgnored
125124
file.getParentFile().mkdirs();
126125
Files.copy(path, file.toPath());
127126
return false;
128127
}))
128+
.map(inputPath::relativize)
129129
.map(Path::toString)
130130
.map(s -> s.replaceAll("/", ".").replaceAll("\\\\", "."))
131131
.map(s -> s.substring(0, s.length() - ".class".length()))
@@ -187,34 +187,34 @@ private static boolean hasBackport(
187187
}
188188

189189
private static void transformClass(
190-
final @NotNull ClassPool classPool, final @NotNull String className, final @NotNull TypeMap classMap,
191-
final @NotNull MethodMap redirectMap, final @NotNull File outputDir) throws Exception {
190+
final @NotNull ClassPool classPool, final @NotNull String className, final @NotNull TypeMap typeMap,
191+
final @NotNull MethodMap methodMap, final @NotNull File outputDir) throws Exception {
192192

193193
final CtClass ctClass = classPool.get(className);
194194

195195
final HashMap<Integer, String> replaceMap = new HashMap<>();
196196

197197
ctClass.instrument(Lambdas.methodEditor((m, c) -> {
198198
final String key = m.getMethodName() + " " + m.getSignature();
199-
MethodMap.Entry redirectEntry = redirectMap.get(key);
200-
while (redirectEntry != null) {
199+
MethodMap.Entry methodMapEntry = methodMap.get(key);
200+
while (methodMapEntry != null) {
201201
final CtMethod method = m.getMethod();
202202
final CtClass declaringClass = method.getDeclaringClass();
203203
final boolean matches;
204204
if (Modifier.isStatic(method.getModifiers())) {
205-
matches = declaringClass.getName().equals(redirectEntry.type);
205+
matches = declaringClass.getName().equals(methodMapEntry.type);
206206
} else {
207-
matches = declaringClass.subtypeOf(declaringClass.getClassPool().get(redirectEntry.type));
207+
matches = declaringClass.subtypeOf(declaringClass.getClassPool().get(methodMapEntry.type));
208208
}
209209
if (matches) {
210-
replaceMap.put(c, redirectEntry.replacement);
210+
replaceMap.put(c, methodMapEntry.replacement);
211211
break;
212212
}
213-
redirectEntry = redirectEntry.next;
213+
methodMapEntry = methodMapEntry.next;
214214
}
215215
}));
216216

217-
ctClass.getClassFile().renameClass(classMap);
217+
ctClass.getClassFile().renameClass(typeMap);
218218

219219
ctClass.instrument(Lambdas.methodEditor((m, c) -> {
220220
final String replacement = replaceMap.get(c);

0 commit comments

Comments
 (0)