Skip to content

Commit f3855c5

Browse files
Merge pull request #21 from xenit-eu/issue-11
Handle non-string objects being added to properties files
2 parents 09a8ad0 + 962a690 commit f3855c5

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

src/integrationTest/java/eu/xenit/gradle/alfrescosdk/Examples.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22

33
import static junit.framework.TestCase.assertTrue;
44
import static org.junit.Assert.assertArrayEquals;
5+
import static org.junit.Assert.assertEquals;
56

67
import java.io.IOException;
8+
import java.io.InputStream;
79
import java.nio.file.FileSystem;
810
import java.nio.file.FileSystems;
911
import java.nio.file.Files;
12+
import java.nio.file.OpenOption;
1013
import java.nio.file.Path;
1114
import java.nio.file.Paths;
15+
import java.nio.file.StandardOpenOption;
16+
import java.util.Properties;
1217
import java.util.function.Predicate;
18+
import org.gradle.util.GUtil;
1319
import org.junit.Test;
1420

1521
public class Examples extends AbstractIntegrationTest {
@@ -116,6 +122,13 @@ public void testConfiguredAlfrescoProject() throws IOException {
116122
Path packagedJarFile = ampFs.getPath("lib/configured-alfresco-project-0.0.1.jar");
117123
assertPath(Files::isRegularFile, packagedJarFile);
118124
assertArrayEquals("Jar inside amp is not identical to jar outside amp", Files.readAllBytes(jarFile), Files.readAllBytes(packagedJarFile));
125+
126+
Properties moduleProperties = GUtil.loadProperties(Files.newInputStream(ampFs.getPath("module.properties")));
127+
assertEquals("configured-alfresco-project", moduleProperties.get("module.id"));
128+
assertEquals("configured-alfresco-project", moduleProperties.get("module.title"));
129+
assertEquals("0.0.1", moduleProperties.get("module.version"));
130+
assertEquals("Content type detection Webscript, very useful", moduleProperties.get("module.description"));
131+
119132
ampFs.close();
120133

121134
FileSystem jarFs = FileSystems.newFileSystem(jarFile, null);
@@ -128,5 +141,28 @@ public void testConfiguredAlfrescoProject() throws IOException {
128141
@Test
129142
public void multiSourceAlfrescoProject() throws IOException {
130143
testProjectFolder(EXAMPLES.resolve("multi-source-alfresco-project"), ":assemble");
144+
145+
Path buildFolder = projectFolder.toPath().resolve("build");
146+
Path shareAmpFile = buildFolder.resolve("dist/multi-source-alfresco-project-0.0.1-share.amp");
147+
148+
assertPath(Files::isRegularFile, shareAmpFile);
149+
FileSystem shareAmpFs = FileSystems.newFileSystem(shareAmpFile, null);
150+
assertPath(Files::isRegularFile, shareAmpFs.getPath("module.properties"));
151+
InputStream shareAmpPropertiesInputStream = Files.newInputStream(shareAmpFs.getPath("module.properties"));
152+
Properties shareAmpProperties = GUtil.loadProperties(shareAmpPropertiesInputStream);
153+
assertEquals("multi-source-alfresco-project-share", shareAmpProperties.getProperty("module.id"));
154+
assertEquals("0.0.1", shareAmpProperties.getProperty("module.version"));
155+
shareAmpFs.close();
156+
157+
Path ampFile = buildFolder.resolve("dist/multi-source-alfresco-project-0.0.1.amp");
158+
assertPath(Files::isRegularFile, ampFile);
159+
FileSystem ampFs = FileSystems.newFileSystem(ampFile, null);
160+
assertPath(Files::isRegularFile, ampFs.getPath("module.properties"));
161+
InputStream ampPropertiesInputStream = Files.newInputStream(ampFs.getPath("module.properties"));
162+
Properties ampProperties = GUtil.loadProperties(ampPropertiesInputStream);
163+
assertEquals("multi-source-alfresco-project-repo", ampProperties.getProperty("module.id"));
164+
assertEquals("0.0.1", ampProperties.getProperty("module.version"));
165+
ampFs.close();
166+
131167
}
132168
}

src/integrationTest/resources/examples/multi-source-alfresco-project/build.gradle

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,27 @@ plugins {
33
id 'eu.xenit.amp'
44
}
55

6+
version = "0.0.1"
7+
68
sourceSets {
79
main {
8-
10+
amp {
11+
module([
12+
"module.id": "${project.name}-repo",
13+
"module.version": project.version
14+
])
15+
}
916
}
1017
share {
1118
amp {
1219
module {
13-
it.setProperty("module.id", project.name + "-share")
20+
it.setProperty("module.id", "${project.name}-share")
1421
it.setProperty("module.version", project.version)
1522
}
1623
}
1724
}
1825
}
1926

20-
description = "HelloWorld Webscript, very useful"
21-
version = "0.0.1"
2227

2328
repositories {
2429
mavenCentral()

src/main/java/eu/xenit/gradle/alfrescosdk/AmpBasePlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public void apply(Project target) {
5656
}
5757

5858
private static Map<String, Object> propertiesToMap(Properties properties) {
59-
return properties.stringPropertyNames()
59+
return properties.keySet()
6060
.stream()
61-
.collect(Collectors.toMap(Function.identity(), properties::getProperty));
61+
.collect(Collectors.toMap(Object::toString, k -> properties.get(k).toString()));
6262
}
6363

6464

0 commit comments

Comments
 (0)