Skip to content

Commit

Permalink
[MINDEXER-214] ArtifactContext should not log warnings if artifacts a…
Browse files Browse the repository at this point in the history
…re no zip files. (#347)

DefaultScanner is processing all files which are in the local repo,
which means that ArtifactContext has to deal with files which are
no zip archives too.

This updates ArtifactContext to not log zip exceptions as warning
if it can't open the zip but should still log all other exceptions
which might occur after successful initial read.

Co-authored-by: Tamas Cservenak <[email protected]>

---

https://issues.apache.org/jira/browse/MINDEXER-214
  • Loading branch information
mbien authored Dec 29, 2023
1 parent 0a485dc commit fb85a7c
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;

import org.apache.lucene.document.Document;
Expand Down Expand Up @@ -92,7 +93,9 @@ public Model getPomModel() {
}
// Otherwise, check for pom contained in maven generated artifact
else if (getArtifact() != null && getArtifact().isFile()) {
boolean isZip = false;
try (ZipFile zipFile = new ZipFile(artifact)) {
isZip = true;
final String embeddedPomPath =
"META-INF/maven/" + getGav().getGroupId() + "/" + getGav().getArtifactId() + "/pom.xml";

Expand All @@ -104,7 +107,11 @@ else if (getArtifact() != null && getArtifact().isFile()) {
}
}
} catch (IOException | XmlPullParserException e) {
LOGGER.warn("skip error reading pom withing artifact:" + artifact, e);
if (e instanceof ZipException && !isZip) {
// ZipFile constructor threw ZipException which means this is no zip file -> ignore
} else {
LOGGER.warn("skip error reading pom within artifact:" + artifact, e);
}
}
}

Expand Down

0 comments on commit fb85a7c

Please sign in to comment.