Skip to content

Commit

Permalink
Implement original image deletion and set to version 1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
andresmanz committed Dec 6, 2014
1 parent 07d0a31 commit 93233a6
Show file tree
Hide file tree
Showing 18 changed files with 91 additions and 35 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ apply plugin: "sonar-runner"
mainClassName = 'org.cethos.tools.ninebatch.NineBatchMain'

allprojects {
version = '1.1.2-SNAPSHOT'
version = '1.1.2'
group = 'org.cethos.tools'

ext {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/cethos/tools/ninebatch/NineBatchMain.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.cethos.tools.ninebatch;

import org.cethos.tools.ninebatch.conversion.ConversionFailureException;
import org.cethos.tools.ninebatch.conversion.processor.ConversionProcessor;
import org.cethos.tools.ninebatch.conversion.processor.ConversionProcessorFactory;
import org.cethos.tools.ninebatch.conversion.ConversionProcessor;
import org.cethos.tools.ninebatch.conversion.ConversionProcessorFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.cethos.tools.ninebatch.conversion.batch.BatchConfig;

public class BatchArgumentParser
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cethos.tools.ninebatch.conversion.batch;
package org.cethos.tools.ninebatch.conversion;

public class BatchConfig
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
package org.cethos.tools.ninebatch.conversion.processor;
package org.cethos.tools.ninebatch.conversion;

import org.apache.commons.io.IOUtils;
import org.cethos.tools.ninebatch.conversion.ConversionFailureException;
import org.cethos.tools.ninebatch.conversion.ConversionParsing;
import org.cethos.tools.ninebatch.conversion.batch.ConversionBatch;
import org.cethos.tools.ninebatch.conversion.streamprovider.StreamProvider;
import org.cethos.tools.ninebatch.conversion.batch.ConversionParsing;
import org.cethos.tools.ninebatch.conversion.io.StreamProvider;
import org.cethos.tools.ninebatch.creation.NinePatchConfig;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Set;

public class BatchConversionProcessor implements ConversionProcessor
{
private static final String CONVERSION_CONFIG_FILE_NAME = "ninepatches.json";

private final StreamProvider streamProvider;
private boolean isDeletingImageSourcesEnabled;

public BatchConversionProcessor(final StreamProvider streamProvider)
{
this.streamProvider = streamProvider;
}

public void setDeletingImageSourcesEnabled(final boolean isEnabled)
{
this.isDeletingImageSourcesEnabled = isEnabled;
}

public void loadAndProcessConversions()
{
final Map<String, NinePatchConfig> conversions = loadConversions();
final ConversionBatch conversionBatch = new ConversionBatch(streamProvider);
conversionBatch.process(conversions);

if(isDeletingImageSourcesEnabled)
{
deleteOriginalImageSources(conversions.keySet());
}
}

private Map<String, NinePatchConfig> loadConversions()
Expand All @@ -49,4 +60,12 @@ private String loadConversionJson()
throw new ConversionFailureException(exception);
}
}

private void deleteOriginalImageSources(final Set<String> fileNames)
{
for(final String fileName : fileNames)
{
streamProvider.deleteImageSource(fileName);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cethos.tools.ninebatch.conversion.processor;
package org.cethos.tools.ninebatch.conversion;

public interface ConversionProcessor
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.cethos.tools.ninebatch.conversion.processor;
package org.cethos.tools.ninebatch.conversion;

import org.cethos.tools.ninebatch.conversion.BatchArgumentParser;
import org.cethos.tools.ninebatch.conversion.batch.BatchConfig;
import org.cethos.tools.ninebatch.conversion.streamprovider.RelativeFileStreamProvider;
import org.cethos.tools.ninebatch.conversion.streamprovider.StreamProvider;
import org.cethos.tools.ninebatch.conversion.io.RelativeFileStreamProvider;
import org.cethos.tools.ninebatch.conversion.io.StreamProvider;

public class ConversionProcessorFactory
{
Expand All @@ -17,7 +15,10 @@ private static BatchConversionProcessor createBatchConversionProcessorFrom(final
final BatchArgumentParser argumentParser = new BatchArgumentParser();
final BatchConfig batchConfig = argumentParser.createConfigFrom(args);
final StreamProvider streamProvider = createStreamProviderFrom(batchConfig);
return new BatchConversionProcessor(streamProvider);

final BatchConversionProcessor processor = new BatchConversionProcessor(streamProvider);
processor.setDeletingImageSourcesEnabled(batchConfig.isDeletingOriginalsEnabled());
return processor;
}

private static StreamProvider createStreamProviderFrom(final BatchConfig batchConfig)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.cethos.tools.ninebatch.conversion.batch;

import org.cethos.tools.ninebatch.conversion.StreamConversionIO;
import org.cethos.tools.ninebatch.conversion.streamprovider.StreamProvider;
import org.cethos.tools.ninebatch.conversion.io.StreamConversionIO;
import org.cethos.tools.ninebatch.conversion.io.StreamProvider;
import org.cethos.tools.ninebatch.creation.NinePatchConfig;
import org.cethos.tools.ninebatch.creation.NinePatchCreation;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cethos.tools.ninebatch.conversion;
package org.cethos.tools.ninebatch.conversion.batch;

import com.esotericsoftware.jsonbeans.JsonReader;
import com.esotericsoftware.jsonbeans.JsonValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cethos.tools.ninebatch.conversion.streamprovider;
package org.cethos.tools.ninebatch.conversion.io;

import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -31,4 +31,14 @@ public InputStream getInputStreamFor(final String fileName) throws FileNotFoundE
final File file = new File(baseInputPath, fileName);
return new FileInputStream(file);
}

@Override
public void deleteImageSource(final String fileName)
{
final File file = new File(baseInputPath, fileName);
if(file.exists())
{
file.delete();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.cethos.tools.ninebatch.conversion;
package org.cethos.tools.ninebatch.conversion.io;

import org.cethos.tools.ninebatch.conversion.streamprovider.StreamProvider;
import org.cethos.tools.ninebatch.conversion.io.StreamProvider;
import org.cethos.tools.ninebatch.util.NinePatchUtil;

import java.awt.image.BufferedImage;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cethos.tools.ninebatch.conversion.streamprovider;
package org.cethos.tools.ninebatch.conversion.io;

import java.io.FileNotFoundException;
import java.io.InputStream;
Expand All @@ -8,4 +8,5 @@ public interface StreamProvider
{
public OutputStream getOutputStreamFor(final String fileName) throws FileNotFoundException;
public InputStream getInputStreamFor(final String fileName) throws FileNotFoundException;
public void deleteImageSource(final String fileName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.cethos.tools.ninebatch.conversion.BatchArgumentParser;
import org.cethos.tools.ninebatch.conversion.ConversionFailureException;
import org.cethos.tools.ninebatch.conversion.batch.BatchConfig;
import org.cethos.tools.ninebatch.conversion.BatchConfig;
import org.cethos.tools.ninebatch.tests.testutil.CommandLineUtil;
import org.junit.Before;
import org.junit.Rule;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.cethos.tools.ninebatch.tests.conversion.processor;
package org.cethos.tools.ninebatch.tests.conversion;

import org.cethos.tools.ninebatch.conversion.ConversionFailureException;
import org.cethos.tools.ninebatch.conversion.processor.BatchConversionProcessor;
import org.cethos.tools.ninebatch.tests.conversion.batch.ResourceStreamProvider;
import org.cethos.tools.ninebatch.conversion.BatchConversionProcessor;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
Expand Down Expand Up @@ -40,5 +39,19 @@ public void testLoadAndProcess_withOneImage()
processor.loadAndProcessConversions();
assertEquals(2, streamProvider.getTotalInputStreamAccessCount());
assertEquals(1, streamProvider.getTotalOutputStreamAccessCount());
assertEquals(0, streamProvider.getTotalSourceDeletionCount());
}

@Test
public void testLoadAndProcess_withOneImageAndOriginalsDeletionEnabled()
{
final ResourceStreamProvider streamProvider = new ResourceStreamProvider("/envs/oneimage");
final BatchConversionProcessor processor = new BatchConversionProcessor(streamProvider);
processor.setDeletingImageSourcesEnabled(true);
processor.loadAndProcessConversions();

assertEquals(2, streamProvider.getTotalInputStreamAccessCount());
assertEquals(1, streamProvider.getTotalOutputStreamAccessCount());
assertEquals(1, streamProvider.getTotalSourceDeletionCount());
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.cethos.tools.ninebatch.tests.conversion.processor;
package org.cethos.tools.ninebatch.tests.conversion;

import org.cethos.tools.ninebatch.conversion.ConversionFailureException;
import org.cethos.tools.ninebatch.conversion.processor.BatchConversionProcessor;
import org.cethos.tools.ninebatch.conversion.processor.ConversionProcessor;
import org.cethos.tools.ninebatch.conversion.processor.ConversionProcessorFactory;
import org.cethos.tools.ninebatch.conversion.BatchConversionProcessor;
import org.cethos.tools.ninebatch.conversion.ConversionProcessor;
import org.cethos.tools.ninebatch.conversion.ConversionProcessorFactory;
import org.cethos.tools.ninebatch.tests.testutil.CommandLineUtil;
import org.junit.Before;
import org.junit.Rule;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.cethos.tools.ninebatch.tests.conversion.batch;
package org.cethos.tools.ninebatch.tests.conversion;

import org.cethos.tools.ninebatch.conversion.streamprovider.StreamProvider;
import org.cethos.tools.ninebatch.conversion.io.StreamProvider;

import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
Expand All @@ -12,6 +12,7 @@ public class ResourceStreamProvider implements StreamProvider
private final String basePath;
private int totalOutputStreamAccessCount;
private int totalInputStreamAccessCount;
private int totalSourceDeletionCount;

public ResourceStreamProvider(final String basePath)
{
Expand Down Expand Up @@ -41,6 +42,12 @@ public InputStream getInputStreamFor(final String fileName) throws FileNotFoundE
}
}

@Override
public void deleteImageSource(String fileName)
{
++totalSourceDeletionCount;
}

public int getTotalOutputStreamAccessCount()
{
return totalOutputStreamAccessCount;
Expand All @@ -50,4 +57,9 @@ public int getTotalInputStreamAccessCount()
{
return totalInputStreamAccessCount;
}

public int getTotalSourceDeletionCount()
{
return totalSourceDeletionCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.cethos.tools.ninebatch.conversion.batch.ConversionBatch;
import org.cethos.tools.ninebatch.creation.NinePatchConfig;
import org.cethos.tools.ninebatch.tests.conversion.ResourceStreamProvider;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.cethos.tools.ninebatch.tests.conversion;
package org.cethos.tools.ninebatch.tests.conversion.batch;

import org.apache.commons.io.IOUtils;
import org.cethos.tools.ninebatch.conversion.ConversionParsing;
import org.cethos.tools.ninebatch.conversion.batch.ConversionParsing;
import org.cethos.tools.ninebatch.creation.NinePatchConfig;
import org.cethos.tools.ninebatch.creation.PixelRange;
import org.cethos.tools.ninebatch.tests.testutil.Assert;
Expand Down

0 comments on commit 93233a6

Please sign in to comment.