Skip to content

Commit

Permalink
Change property file based reader filtering from reader filter to pos…
Browse files Browse the repository at this point in the history
…t-read filtering

Fixes an issue we were seeing where property file values were not being read when passed through both filters
  • Loading branch information
OdysseusLives committed Feb 16, 2024
1 parent e0eb5dd commit 978cf04
Showing 1 changed file with 6 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import org.gradle.api.Project;

import java.io.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Collection;
import java.util.Properties;

Expand All @@ -21,7 +24,7 @@ protected String propertyValue(String name) {
if (property == null) {
return null;
}
return property.trim();
return property.split(" ")[0].split("#")[0];
}
};

Expand All @@ -34,9 +37,7 @@ public String getVersion(String org, String name) throws Exception {
if(recommendations == null) {
recommendations = new Properties();
try (InputStream inputStream = inputProvider.getInputStream()) {
recommendations.load(
new EolCommentFilteringReader(
new ColonFilteringReader(new InputStreamReader(inputStream))));
recommendations.load(new ColonFilteringReader(new InputStreamReader(inputStream)));
}
}
return fuzzyResolver.versionOf(org + "/" + name);
Expand Down Expand Up @@ -67,42 +68,4 @@ public void close() throws IOException {
reader.close();
}
}

private class EolCommentFilteringReader extends Reader {
Reader reader;
boolean inComment;

public EolCommentFilteringReader(Reader reader) {
this.reader = reader;
inComment = false;
}

@Override
public int read(char[] cbuf, int off, int len) throws IOException {
int val;
int read = 0;
while (read < len && (val = reader.read()) != -1) {
if (val == '#') {
inComment = true;
continue;
}
if (val == '\n') {
inComment = false;
}

if (inComment) {
continue;
}

cbuf[off + read] = (char) val;
read++;
}
return read;
}

@Override
public void close() throws IOException {
reader.close();
}
}
}

0 comments on commit 978cf04

Please sign in to comment.