Skip to content

Commit

Permalink
Merge pull request #125 from nebula-plugins/adjust-property-file-reco…
Browse files Browse the repository at this point in the history
…mmendation-filtering

Change property file based reader filtering from reader filter to post-read filtering
  • Loading branch information
OdysseusLives authored Feb 17, 2024
2 parents e0eb5dd + 978cf04 commit 259dbaa
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 259dbaa

Please sign in to comment.