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

feat - Extract classes.jar from *.aar #1594

Merged
merged 7 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,8 @@ private List<IClasspathEntry> getDependencyJars(DependencyModulesResult dependen
}
String classifier = artifactData.getClassifier();
try {
File jarFile = new File(new URI(uri));
File artifactFile = new File(new URI(uri));
File jarFile = Utils.getJarFile(artifactFile);
if (classifier == null) {
artifact = jarFile;
} else if ("sources".equals(classifier)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

import static org.eclipse.jdt.ls.core.internal.handlers.MapFlattener.getString;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -214,4 +221,44 @@ public static void sendTelemetry(JavaLanguageClient client, Object message) {
client.sendNotification(new ExecuteCommandParams("_java.gradle.buildServer.sendTelemetry",
Arrays.asList(message)));
}

/**
* Extracts the jar file from the given artifact.
jdneo marked this conversation as resolved.
Show resolved Hide resolved
*/
public static File getJarFile(File file) {
jdneo marked this conversation as resolved.
Show resolved Hide resolved

String filepath = file.getAbsolutePath();

if (filepath.endsWith(".aar")) {

// Extracting classes.jar from AAR files
try(ZipInputStream is = new ZipInputStream(new FileInputStream(file))) {

ZipEntry entry;
while ((entry = is.getNextEntry()) != null) {
if (entry.getName().equals("classes.jar")) {
String fileName = file.getName();
fileName = fileName.substring(0, fileName.length() - 4);
fileName = fileName + ".jar";
File outputFile = Path.of(file.getParentFile().getAbsolutePath(), fileName).toFile();
try (FileOutputStream outputStream = new FileOutputStream(outputFile)) {
byte[] buffer = new byte[1024];
int len;
while((len = is.read(buffer)) > 0) {
outputStream.write(buffer, 0, len);
}
return outputFile;
}
}
}

} catch(IOException e) {
}
jdneo marked this conversation as resolved.
Show resolved Hide resolved

}

return file;

}

}