Skip to content

Commit

Permalink
resolving jdk 14 test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcin committed Sep 3, 2020
1 parent 798d994 commit e459a32
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 79 deletions.
48 changes: 32 additions & 16 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@
<include>biz.aQute.bnd:bndlib</include>
<include>org.apache.sling:org.apache.sling.jcr.repoinit</include>
<include>org.apache.sling:org.apache.sling.installer.core</include>
<include>org.osgi:org.apache.felix.converter</include>
<include>org.apache.felix:org.apache.felix.cm.json</include>
<include>org.osgi:org.osgi.util.function</include>
<include>org.osgi:org.osgi.util.converter</include>
</includes>
</artifactSet>
<filters>
Expand All @@ -164,19 +166,21 @@
<filter>
<artifact>org.apache.sling:org.apache.sling.installer.core</artifact>
<includes>
<include>org/apache/felix/cm/file/ConfigurationHandler*</include>
<include>org/apache/felix/configurator/impl/json/**</include>
<include>org/apache/felix/configurator/impl/model/**</include>
<include>org/apache/sling/installer/api/InstallableResource*</include>
</includes>
</filter>
<filter>
<artifact>org.apache.felix:org.apache.felix.converter</artifact>
<artifact>org.osgi:org.osgi.util.function</artifact>
<includes>
<include>org/osgi/util/converter/**</include>
<include>org/osgi/util/function/**</include>
</includes>
</filter>
<filter>
<artifact>org.osgi:org.osgi.util.converter</artifact>
<includes>
<include>org/osgi/util/converter/**</include>
</includes>
</filter>
</filters>
<relocations>
<relocation>
Expand All @@ -188,8 +192,8 @@
<shadedPattern>net.adamcin.oakpal.shaded.sling.jcr.repoinit</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.felix</pattern>
<shadedPattern>net.adamcin.oakpal.shaded.felix</shadedPattern>
<pattern>org.apache.felix.cm</pattern>
<shadedPattern>net.adamcin.oakpal.shaded.felix.cm</shadedPattern>
</relocation>
<relocation>
<pattern>org.osgi.util.function</pattern>
Expand Down Expand Up @@ -285,24 +289,36 @@
<artifactId>bndlib</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.installer.core</artifactId>
<version>3.9.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.configadmin</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.converter</artifactId>
<artifactId>org.apache.felix.cm.json</artifactId>
<version>1.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.util.function</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.util.function</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.util.converter</artifactId>
<version>1.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.adamcin.oakpal.api.SlingSimulator;
import net.adamcin.oakpal.core.ErrorListener;
import org.apache.felix.cm.file.ConfigurationHandler;
import org.apache.felix.cm.json.Configurations;
import org.apache.felix.configurator.impl.json.JSONUtil;
import org.apache.felix.configurator.impl.json.TypeConverter;
import org.apache.felix.configurator.impl.model.ConfigurationFile;
Expand All @@ -35,6 +36,7 @@
import org.apache.sling.installer.api.InstallableResource;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.osgi.util.converter.ConversionException;

import javax.jcr.Node;
import javax.jcr.Property;
Expand All @@ -48,8 +50,10 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.reflect.Array;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Dictionary;
import java.util.Enumeration;
Expand Down Expand Up @@ -218,7 +222,7 @@ public Map<String, Object> getProps() {
if (isConfigExtension(path)) {
try (InputStream is = node.getProperty(JCR_CONTENT_DATA).getBinary().getStream()) {
nodeRes.getProps().putAll(readDictionary(is, nodeRes.getPath()));
} catch (IOException e) {
} catch (Exception e) {
nodeRes.setParseError(e);
}

Expand Down Expand Up @@ -286,15 +290,6 @@ static boolean isConfigExtension(String url) {
return false;
}

static <K, V> Map<K, V> dictionaryToMap(final @NotNull Dictionary<K, V> dictionary) {
final Map<K, V> map = new LinkedHashMap<>(dictionary.size());
for (Enumeration<K> keys = dictionary.keys(); keys.hasMoreElements(); ) {
final K key = keys.nextElement();
map.put(key, dictionary.get(key));
}
return map;
}

/**
* Read dictionary from an input stream.
* We use the same logic as Apache Felix FileInstall here, but only for .config files:
Expand All @@ -307,6 +302,7 @@ static <K, V> Map<K, V> dictionaryToMap(final @NotNull Dictionary<K, V> dictiona
*/
static Map<String, Object> readDictionary(
final InputStream is, final String id) throws IOException {
final Map<String, Object> ht = new LinkedHashMap<>();
if (id.endsWith(".cfg.json")) {
final String name = "jcrinstall:".concat(id);
String configId;
Expand All @@ -322,52 +318,20 @@ static Map<String, Object> readDictionary(
}
configId = removeConfigExtension(configId);

final TypeConverter typeConverter = new TypeConverter(null);
final JSONUtil.Report report = new JSONUtil.Report();

// read from input stream
final String contents;
try (final BufferedReader buf = new BufferedReader(
new InputStreamReader(is, "UTF-8"))) {

final StringBuilder sb = new StringBuilder();

sb.append("{ \"");
sb.append(configId);
sb.append("\" : ");
String line;

while ((line = buf.readLine()) != null) {
sb.append(line);
sb.append('\n');
}
sb.append("}");

contents = sb.toString();
}

final URL url = new URL("file://" + configId);

final ConfigurationFile config = JSONUtil.readJSON(typeConverter, name, url, 0, contents, report);

if (!report.errors.isEmpty() || !report.warnings.isEmpty()) {
final StringBuilder builder = new StringBuilder();
builder.append("Errors in configuration:");
for (final String w : report.warnings) {
builder.append("\n");
builder.append(w);
}
for (final String e : report.errors) {
builder.append("\n");
builder.append(e);
try (final Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) {
final Dictionary<String, Object> config = Configurations.buildReader()
.withIdentifier(configId).build(reader).readConfiguration();

final Enumeration<String> i = config.keys();
while (i.hasMoreElements()) {
final String key = i.nextElement();
ht.put(key, config.get(key));
}
throw new IOException(builder.toString());
} catch (ConversionException e) {
throw new IOException(e.getMessage(), e);
}

return dictionaryToMap(config.getConfigurations().get(0).getProperties());
} else {
final Map<String, Object> ht = new LinkedHashMap<>();

try (final BufferedInputStream in = new BufferedInputStream(is)) {

if (id.endsWith(".config")) {
Expand Down Expand Up @@ -407,8 +371,8 @@ static Map<String, Object> readDictionary(
}
}
}
return ht;
}
return ht;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import org.mockito.ArgumentMatcher;
import org.osgi.util.converter.ConversionException;

import javax.jcr.Node;
import javax.jcr.PropertyType;
Expand Down Expand Up @@ -196,15 +197,6 @@ public void testReadDictionary_onlyCommentLineThrows() throws Exception {
new ByteArrayInputStream(simpleConfigWithComment.getBytes(StandardCharsets.UTF_8)), "simple.config");
}

@Test(expected = IOException.class)
public void testReadDictionary_dotCfgJson_throwsWarning() throws Exception {
final String dotCfgJson = obj()
.key(":configurator:ranking", "A200")
.get().toString();
DefaultSlingSimulator.readDictionary(
new ByteArrayInputStream(dotCfgJson.getBytes(StandardCharsets.UTF_8)), "simple.cfg.json");
}

@Test(expected = IOException.class)
public void testReadDictionary_dotCfgJson_throwsError() throws Exception {
final String dotCfgJson = obj()
Expand Down Expand Up @@ -530,6 +522,7 @@ public void testReadInstallableResourceFromNode_fileConfig() throws Exception {
assertTrue("expect instance of OsgiConfigInstallableParams",
badResource instanceof OsgiConfigInstallableParams);
OsgiConfigInstallableParams badParams = (OsgiConfigInstallableParams) badResource;
assertNotNull("expect parseError not null", badParams.getParseError());
assertTrue("expect parseError instanceof IOException", badParams.getParseError() instanceof IOException);

});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
":configurator:ranking": "badRanking"
"foo:Integer": "badRanking"
}

0 comments on commit e459a32

Please sign in to comment.