mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
maven artifacts resolution: mark bad jars corrupted but don't delete them
Bad JARs are moved to file-name.jar.corruptedXXXX instead of deletion which allows to inspect bad ZIP contents if needed. Should be revised when IDEA-269182 is enabled. GitOrigin-RevId: c31746e6f09a670ebcfac5ff7f329f2df233ae19
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e98c32838a
commit
02dac8c264
@@ -11,8 +11,11 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
|
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
|
||||||
|
|
||||||
class StrictLocalRepositoryManager implements LocalRepositoryManager {
|
class StrictLocalRepositoryManager implements LocalRepositoryManager {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(StrictLocalRepositoryManager.class);
|
private static final Logger LOG = LoggerFactory.getLogger(StrictLocalRepositoryManager.class);
|
||||||
private static final boolean STRICT_VALIDATION = "true".equals(System.getProperty("org.jetbrains.idea.maven.aether.strictValidation"));
|
private static final boolean STRICT_VALIDATION = "true".equals(System.getProperty("org.jetbrains.idea.maven.aether.strictValidation"));
|
||||||
@@ -32,6 +35,12 @@ class StrictLocalRepositoryManager implements LocalRepositoryManager {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether {@code archive} file is valid ZIP. If ZIP is invalid, renames the file adding {@code .corruptedXXXXX} suffix.
|
||||||
|
*
|
||||||
|
* @param archive ZIP archive file
|
||||||
|
* @return true if valid, false if not
|
||||||
|
*/
|
||||||
boolean isValidArchive(File archive) {
|
boolean isValidArchive(File archive) {
|
||||||
if (!archive.exists()) return false;
|
if (!archive.exists()) return false;
|
||||||
// TODO: to be revised after IDEA-269182 is implemented
|
// TODO: to be revised after IDEA-269182 is implemented
|
||||||
@@ -41,16 +50,25 @@ class StrictLocalRepositoryManager implements LocalRepositoryManager {
|
|||||||
entriesCount = zip.size();
|
entriesCount = zip.size();
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
LOG.warn("Unable to read a number of entries in " + archive, e);
|
/* Short exception message is enough */
|
||||||
|
LOG.warn("Unable to read a number of entries in " + archive + ": " + e.getMessage());
|
||||||
entriesCount = 0;
|
entriesCount = 0;
|
||||||
}
|
}
|
||||||
if (entriesCount <= 0) {
|
if (entriesCount <= 0) {
|
||||||
LOG.warn(archive + " is probably corrupted, deleting");
|
LOG.warn(archive + " is probably corrupted, marking as corrupted");
|
||||||
try {
|
try {
|
||||||
Files.deleteIfExists(archive.toPath());
|
Path archiveAsPath = archive.toPath();
|
||||||
|
if (Files.exists(archiveAsPath)) {
|
||||||
|
String prefix = archiveAsPath.getFileName() + ".corrupted";
|
||||||
|
String suffix = "";
|
||||||
|
Path corruptedArchivePath = Files.createTempFile(archiveAsPath.getParent(), prefix, suffix);
|
||||||
|
Files.move(archiveAsPath, corruptedArchivePath, REPLACE_EXISTING);
|
||||||
|
|
||||||
|
LOG.warn(archive + " is moved to " + corruptedArchivePath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
throw new RuntimeException("Unable to delete " + archive, e);
|
throw new RuntimeException("Unable to move " + archive, e);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user