Skip to content

Commit

Permalink
Merge pull request #21 from xenit-eu/issue-11
Browse files Browse the repository at this point in the history
Handle non-string objects being added to properties files
  • Loading branch information
vierbergenlars authored Jul 8, 2019
2 parents 09a8ad0 + 962a690 commit f3855c5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
36 changes: 36 additions & 0 deletions src/integrationTest/java/eu/xenit/gradle/alfrescosdk/Examples.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Properties;
import java.util.function.Predicate;
import org.gradle.util.GUtil;
import org.junit.Test;

public class Examples extends AbstractIntegrationTest {
Expand Down Expand Up @@ -116,6 +122,13 @@ public void testConfiguredAlfrescoProject() throws IOException {
Path packagedJarFile = ampFs.getPath("lib/configured-alfresco-project-0.0.1.jar");
assertPath(Files::isRegularFile, packagedJarFile);
assertArrayEquals("Jar inside amp is not identical to jar outside amp", Files.readAllBytes(jarFile), Files.readAllBytes(packagedJarFile));

Properties moduleProperties = GUtil.loadProperties(Files.newInputStream(ampFs.getPath("module.properties")));
assertEquals("configured-alfresco-project", moduleProperties.get("module.id"));
assertEquals("configured-alfresco-project", moduleProperties.get("module.title"));
assertEquals("0.0.1", moduleProperties.get("module.version"));
assertEquals("Content type detection Webscript, very useful", moduleProperties.get("module.description"));

ampFs.close();

FileSystem jarFs = FileSystems.newFileSystem(jarFile, null);
Expand All @@ -128,5 +141,28 @@ public void testConfiguredAlfrescoProject() throws IOException {
@Test
public void multiSourceAlfrescoProject() throws IOException {
testProjectFolder(EXAMPLES.resolve("multi-source-alfresco-project"), ":assemble");

Path buildFolder = projectFolder.toPath().resolve("build");
Path shareAmpFile = buildFolder.resolve("dist/multi-source-alfresco-project-0.0.1-share.amp");

assertPath(Files::isRegularFile, shareAmpFile);
FileSystem shareAmpFs = FileSystems.newFileSystem(shareAmpFile, null);
assertPath(Files::isRegularFile, shareAmpFs.getPath("module.properties"));
InputStream shareAmpPropertiesInputStream = Files.newInputStream(shareAmpFs.getPath("module.properties"));
Properties shareAmpProperties = GUtil.loadProperties(shareAmpPropertiesInputStream);
assertEquals("multi-source-alfresco-project-share", shareAmpProperties.getProperty("module.id"));
assertEquals("0.0.1", shareAmpProperties.getProperty("module.version"));
shareAmpFs.close();

Path ampFile = buildFolder.resolve("dist/multi-source-alfresco-project-0.0.1.amp");
assertPath(Files::isRegularFile, ampFile);
FileSystem ampFs = FileSystems.newFileSystem(ampFile, null);
assertPath(Files::isRegularFile, ampFs.getPath("module.properties"));
InputStream ampPropertiesInputStream = Files.newInputStream(ampFs.getPath("module.properties"));
Properties ampProperties = GUtil.loadProperties(ampPropertiesInputStream);
assertEquals("multi-source-alfresco-project-repo", ampProperties.getProperty("module.id"));
assertEquals("0.0.1", ampProperties.getProperty("module.version"));
ampFs.close();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@ plugins {
id 'eu.xenit.amp'
}

version = "0.0.1"

sourceSets {
main {

amp {
module([
"module.id": "${project.name}-repo",
"module.version": project.version
])
}
}
share {
amp {
module {
it.setProperty("module.id", project.name + "-share")
it.setProperty("module.id", "${project.name}-share")
it.setProperty("module.version", project.version)
}
}
}
}

description = "HelloWorld Webscript, very useful"
version = "0.0.1"

repositories {
mavenCentral()
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/eu/xenit/gradle/alfrescosdk/AmpBasePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public void apply(Project target) {
}

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


Expand Down

0 comments on commit f3855c5

Please sign in to comment.