\r
import org.apache.commons.lang3.builder.EqualsBuilder;\r
import org.apache.commons.lang3.builder.HashCodeBuilder;\r
+import org.tizen.common.file.FileHandler;\r
import org.tizen.common.file.FileHandler.Attribute;\r
+import org.tizen.common.file.IResource;\r
\r
public class\r
-Resource\r
+Resource implements IResource\r
{\r
protected String path;\r
\r
{\r
return "Resource[" + getPath() + "](" + getLayer() + ")";\r
}\r
+ \r
+ @Override\r
+ public FileHandler getFileHandler() {\r
+ if (layer!= null) {\r
+ return layer.getFileHandler();\r
+ } else {\r
+ return null;\r
+ }\r
+ }\r
}\r
package org.tizen.common.builder;\r
\r
import org.junit.Test;\r
-import org.tizen.common.builder.ResourceLayer;\r
import org.tizen.common.file.VirtualFileHandler;\r
\r
public class ResourceLayerTest\r
import org.tizen.common.file.FileHandler;
import org.tizen.common.file.FileHandler.Attribute;
import org.tizen.common.file.FileHandler.Type;
+import org.tizen.common.file.IResource;
import org.tizen.common.util.Assert;
import org.tizen.common.util.FilenameUtil;
import org.tizen.common.util.IOUtil;
* Directory to zip
*/
protected final String baseDir;
+ private IResource[] resources = null;
/**
* Constructor with base dir and target file name
final String target
)
{
+ this(baseDir, null, target);
+ }
+
+ /**
+ * Constructor with base dir and resources and target file name
+ * @param baseDir base directory path
+ * @param resources resource file list what add to target file. If it is null, add file located in base directory to target file.
+ * @param target target file name
+ */
+ public
+ ZipCommand(
+ final String baseDir,
+ final IResource[] resources,
+ final String target
+ )
+ {
this.baseDir = baseDir;
+ this.resources = resources;
setPath( target );
}
final ExecutionContext context
)
throws IOException
- {
+ {
final FileHandler handler = context.getFileHandler();
Assert.notNull( handler );
try
{
- addEntry( zipOut, handler, baseDir );
+ if (resources != null) {
+ for (IResource resource : resources) {
+ addEntry(zipOut, resource.getFileHandler(), resource.getPath());
+ }
+ } else {
+ addEntry( zipOut, handler, baseDir );
+ }
}
finally
{
throw new IllegalStateException( e );
// TODO Handle
}
-
- }
+ }
/**
* Add file entry with <code>filePath</code> into <code>zipOut</code>
zipOut.closeEntry();
}
-
for ( final String child : children )
{
addEntry( zipOut, handler, child );
--- /dev/null
+package org.tizen.common.file;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public interface IResource {
+ public String getName() throws IOException;
+ public String getPath();
+ public FileHandler getFileHandler();
+ public InputStream getContents() throws IOException;
+ public void setContents(InputStream in) throws IOException;
+ public void setContents(byte[] contents) throws IOException;
+}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.tizen.common.util.FilenameUtil;
import org.tizen.common.util.IOUtil;
import org.tizen.common.util.StringUtil;
/* (non-Javadoc)
* @see org.tizen.common.file.FileHandler#makeDirectory(java.lang.String)
*/
+ public void makeDirectory(final String path, boolean recursive) throws IOException {
+ if (recursive) {
+ String parentDir = FilenameUtil.removeTailingPath(path, 1);
+ if (!is(parentDir, Attribute.EXISTS)) {
+ makeDirectory(parentDir, recursive);
+ }
+ }
+ final Directory parent = getParent(path);
+ final String dirName = getFilename(path);
+
+ if (parent.name2file.containsKey(dirName)) {
+ if (!recursive) {
+ throw new IOException();
+ } else {
+ return;
+ }
+ }
+ parent.add(dirName);
+ }
+
+ /* (non-Javadoc)
+ * @see org.tizen.common.file.FileHandler#makeDirectory(java.lang.String)
+ */
@Override
public
void
)
throws IOException
{
- final Directory parent = getParent( path );
- final String dirName = getFilename( path );
- if ( parent.name2file.containsKey( dirName ) )
- {
- throw new IOException();
- }
- parent.add( dirName );
+ makeDirectory(path, false);
}
/* (non-Javadoc)
this.cwd = cwd;
logger.info( "CWD changed :{}", this.cwd );
}
-
}