Skip to content

Commit

Permalink
more info messages and create property file creates protected values
Browse files Browse the repository at this point in the history
  • Loading branch information
cecom committed Oct 28, 2015
1 parent 8755b2a commit 3ddbb5d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
*parentProtectedField=dontShowThisInDebug
*parentProtectedFieldReference2=dontShowThisInDebug/foobar
*parentProtectedFieldReference=dontShowThisInDebug/foo
*password=aReallySecretPasswordThatWeShouldNotSeeOnDebugOutput
SomeBaseProperty=SomeBasePropertyValue
SomeChild1Property=SomeChild1PropertyValue
SomeChild2Property=SomeChild2PropertyValue
Expand All @@ -14,7 +18,3 @@ foobar4=62999/http://0815/someProperty
foobar5=someProperty
foobar6=someProperty
foobar7=someProperty
parentProtectedField=dontShowThisInDebug
parentProtectedFieldReference2=dontShowThisInDebug/foobar
parentProtectedFieldReference=dontShowThisInDebug/foo
password=aReallySecretPasswordThatWeShouldNotSeeOnDebugOutput
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ private void setPermission() {
private Set<String> getPropertyLines() {
Set<String> result = new TreeSet<String>();
for (String propertyKey : propertyResolveManager.getPropertyKeys()) {
String line = propertyKey + "=" + propertyResolveManager.getPropertyValue(propertyKey);
String protectedPrefix = "";
if (propertyResolveManager.isProtectedProperty(propertyKey)) {
protectedPrefix = "*";
}
String line = protectedPrefix + propertyKey + "=" + propertyResolveManager.getPropertyValue(propertyKey);
result.add(line);
}
return result;
Expand Down
19 changes: 9 additions & 10 deletions impl/src/main/java/com/geewhiz/pacify/managers/FilterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@

public class FilterManager {

private Logger logger = LogManager.getLogger(FilterManager.class.getName());
private Logger logger = LogManager.getLogger(FilterManager.class.getName());

private PropertyResolveManager propertyResolveManager;
private PMarker pMarker;
private int fileChangeCount = 0;

public FilterManager(PropertyResolveManager propertyResolveManager, PMarker pMarker) {
this.propertyResolveManager = propertyResolveManager;
Expand All @@ -76,13 +75,12 @@ public LinkedHashSet<Defect> doFilter() {
pMarker.getFile().delete();
}

logger.info(" Adjusted Files: {}", fileChangeCount);

return defects;
}

private LinkedHashSet<Defect> filterPFile(PFile pFile) {
logger.debug(" Filtering [{}] using encoding [{}] and filter [{}]", pMarker.getAbsoluteFileFor(pFile).getAbsolutePath(), pFile.getEncoding(),
logger.info(" Customize File [{}]", pFile.getRelativePath());
logger.debug(" Filtering [{}] using encoding [{}] and filter [{}]", pMarker.getAbsoluteFileFor(pFile).getAbsolutePath(), pFile.getEncoding(),
pFile.getFilterClass());

File fileToFilter = pMarker.getAbsoluteFileFor(pFile);
Expand All @@ -96,19 +94,21 @@ private LinkedHashSet<Defect> filterPFile(PFile pFile) {
String encoding = pFile.getEncoding();

defects.addAll(pacifyFilter.filter(propertyValues, beginToken, endToken, fileToFilter, encoding));

fileChangeCount++;
logger.info(" [{}] placeholders replaced.", pFile.getPProperties().size());

return defects;
}

private LinkedHashSet<Defect> filterPArchive(PArchive pArchive) {
logger.info(" Customize Archive [{}]", pArchive.getRelativePath());

LinkedHashSet<Defect> defects = new LinkedHashSet<Defect>();

Map<PFile, File> replaceFiles = new HashMap<PFile, File>();

for (PFile pFile : pArchive.getPFiles()) {
logger.debug(" Filtering [{}] in archive [{}] using encoding [{}] and filter [{}]", pFile.getRelativePath(),
logger.info(" Customize File [{}]", pFile.getRelativePath());
logger.debug(" Filtering [{}] in archive [{}] using encoding [{}] and filter [{}]", pFile.getRelativePath(),
pMarker.getAbsoluteFileFor(pArchive).getAbsolutePath(), pFile.getEncoding(),
pFile.getFilterClass());

Expand All @@ -128,8 +128,7 @@ private LinkedHashSet<Defect> filterPArchive(PArchive pArchive) {
defects.addAll(pacifyFilter.filter(propertyValues, beginToken, endToken, fileToFilter, encoding));

replaceFiles.put(pFile, fileToFilter);

fileChangeCount++;
logger.info(" [{}] placeholders replaced.", pFile.getPProperties().size());
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,19 @@ public String getPropertyValue(String propertyKey, boolean convertBackslashToSla
boolean isProtected = isProtectedProperty(propertyKey);

if (!convertBackslashToSlash) {
logger.debug(" Resolved property [{}] to value [{}]", propertyKey, isProtected ? "**********" : value);
logger.debug(" Resolved property [{}] to value [{}]", propertyKey, isProtected ? "**********" : value);
return value;
}

String convertedString = value.replace('\\', '/');
logger.debug(" Resolved property [{}] with original value [{}] to [{}] (backslash convertion)", propertyKey, isProtected ? "**********" : value,
logger.debug(" Resolved property [{}] with original value [{}] to [{}] (backslash convertion)", propertyKey, isProtected ? "**********"
: value,
isProtected ? "**********" : convertedString);

return convertedString;
}

private boolean isProtectedProperty(String property) {
public boolean isProtectedProperty(String property) {
for (PropertyResolver propertyResolver : propertyResolverList) {
if (!propertyResolver.containsProperty(property)) {
continue;
Expand Down
10 changes: 10 additions & 0 deletions impl/src/test/java/com/geewhiz/pacify/TestArchive.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.compress.archivers.ArchiveInputStream;
import org.apache.commons.compress.archivers.ArchiveStreamFactory;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -37,6 +40,7 @@
import com.geewhiz.pacify.property.resolver.HashMapPropertyResolver;
import com.geewhiz.pacify.resolver.PropertyResolver;
import com.geewhiz.pacify.test.TestUtil;
import com.geewhiz.pacify.utils.LoggingUtils;

/*
* Licensed to the Apache Software Foundation (ASF) under one
Expand All @@ -61,6 +65,9 @@ public class TestArchive {

@Test
public void checkJar() throws ArchiveException, IOException {
Logger logger = LogManager.getLogger(TestArchive.class.getName());
LoggingUtils.setLogLevel(logger, Level.INFO);

File testResourceFolder = new File("src/test/resources/testArchive/correct/jar");
File targetResourceFolder = new File("target/test-resources/testArchive/correct/jar");

Expand All @@ -87,6 +94,9 @@ public void checkJar() throws ArchiveException, IOException {

@Test
public void checkJarWhereTheSourceIsntAJarPerDefinition() throws ArchiveException, IOException {
Logger logger = LogManager.getLogger(TestArchive.class.getName());
LoggingUtils.setLogLevel(logger, Level.ERROR);

File testResourceFolder = new File("src/test/resources/testArchive/correct/jarWhereSourceIsntAJarPerDefinition");
File targetResourceFolder = new File("target/test-resources/testArchive/correct/jarWhereSourceIsntAJarPerDefinition");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class FilePropertyResolver extends BasePropertyResolver {
public static final String SEPARATOR_STRING = "=";
public static final String COMMENT_STRING = "#";

public static final String PROTECTED_MARKER = "*";

public static final String SEARCH_PATTERN = "([^" + Pattern.quote(SEPARATOR_STRING) + "]*)" + Pattern.quote(SEPARATOR_STRING) + "?(.*)";
public static final Pattern PROPERTY_PATTERN = Pattern.compile(SEARCH_PATTERN);

Expand Down Expand Up @@ -204,7 +206,7 @@ private void initialize() {
String key = matcher.group(1);
String value = matcher.group(2);

if (key.startsWith("*")) {
if (key.startsWith(PROTECTED_MARKER)) {
key = key.substring(1);
protectedProperties.add(key);
}
Expand Down

0 comments on commit 3ddbb5d

Please sign in to comment.