mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
maven artifacts resolution: archive entries check should be called earlier from jps
GitOrigin-RevId: 50c2b5502ec0a29b3a892fd0b9bd0eeac3698d22
This commit is contained in:
committed by
intellij-monorepo-bot
parent
119e51bfac
commit
d6cf712cf3
@@ -35,6 +35,7 @@ import org.eclipse.aether.util.graph.visitor.TreeDependencyVisitor;
|
||||
import org.eclipse.aether.util.repository.AuthenticationBuilder;
|
||||
import org.eclipse.aether.util.version.GenericVersionScheme;
|
||||
import org.eclipse.aether.version.*;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
@@ -114,6 +115,12 @@ public final class ArtifactRepositoryManager {
|
||||
myRetry = retry;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public boolean isValidArchive(File archive) {
|
||||
var localRepositoryManager = mySessionFactory.sessionTemplate.getLocalRepositoryManager();
|
||||
return ((StrictLocalRepositoryManager) localRepositoryManager).isValidArchive(archive);
|
||||
}
|
||||
|
||||
private static final class RepositorySystemSessionFactory {
|
||||
private final RepositorySystemSession sessionTemplate;
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.eclipse.aether.repository.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.zip.ZipFile;
|
||||
@@ -24,37 +25,37 @@ class StrictLocalRepositoryManager implements LocalRepositoryManager {
|
||||
@Override
|
||||
public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRequest request) {
|
||||
var result = delegate.find(session, request);
|
||||
// TODO: to be revised after IDEA-269182 is implemented
|
||||
if (STRICT_VALIDATION &&
|
||||
result.isAvailable() &&
|
||||
(result.getFile().getName().endsWith(".jar") ||
|
||||
result.getFile().getName().endsWith(".zip"))) {
|
||||
validateArchive(result);
|
||||
if (result.isAvailable() && !isValidArchive(result.getFile())) {
|
||||
result.setFile(null);
|
||||
result.setAvailable(false);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void validateArchive(LocalArtifactResult artifact) {
|
||||
long entriesCount;
|
||||
var file = artifact.getFile();
|
||||
try (var zip = new ZipFile(file)) {
|
||||
entriesCount = zip.size();
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.warn("Unable to read a number of entries in " + file, e);
|
||||
entriesCount = 0;
|
||||
}
|
||||
if (entriesCount <= 0) {
|
||||
LOG.warn(file + " is probably corrupted, deleting");
|
||||
try {
|
||||
Files.deleteIfExists(file.toPath());
|
||||
boolean isValidArchive(File archive) {
|
||||
if (!archive.exists()) return false;
|
||||
// TODO: to be revised after IDEA-269182 is implemented
|
||||
if (STRICT_VALIDATION && (archive.getName().endsWith(".jar") || archive.getName().endsWith(".zip"))) {
|
||||
long entriesCount;
|
||||
try (var zip = new ZipFile(archive)) {
|
||||
entriesCount = zip.size();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException("Unable to delete " + file, e);
|
||||
LOG.warn("Unable to read a number of entries in " + archive, e);
|
||||
entriesCount = 0;
|
||||
}
|
||||
if (entriesCount <= 0) {
|
||||
LOG.warn(archive + " is probably corrupted, deleting");
|
||||
try {
|
||||
Files.deleteIfExists(archive.toPath());
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException("Unable to delete " + archive, e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
artifact.setFile(null);
|
||||
artifact.setAvailable(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user