Archived
0

BuildFile and FS modules implementation [commit 2]

This commit is contained in:
terminator48
2016-04-08 23:32:54 +06:00
parent cccf8c2bc0
commit 94105d790e
22 changed files with 784 additions and 10 deletions

View File

@@ -10,7 +10,26 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>filesystem</artifactId>
<packaging>jar</packaging>
<packaging>bundle</packaging>
<build>
<finalName>${groupId}.${artifactId}-${version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.5</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-Name>Arcadex System: ${name} ${version}</Bundle-Name>
<Bundle-SymbolicName>${groupId}.${artifactId}</Bundle-SymbolicName>
<Bundle-Activator>eu.arcadex.system.file_system.Activator</Bundle-Activator>
<Export-Package>eu.arcadex.system.file_system.api</Export-Package>
<Import-Package>*</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,24 @@
package eu.arcadex.system.file_system;
import eu.arcadex.system.file_system.api.IFileSystem;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
/**
* @author Daniil on 08.04.16.
*/
public class Activator implements BundleActivator {
private ServiceRegistration<?> service;
@Override
public void start(BundleContext bundleContext) throws Exception {
FileSystemLib lib = new FileSystemLib();
service = bundleContext.registerService(IFileSystem.class.getName(), lib, null);
}
@Override
public void stop(BundleContext bundleContext) throws Exception {
service.unregister();
}
}

View File

@@ -1,3 +1,7 @@
package eu.arcadex.system.file_system;
import eu.arcadex.system.file_system.api.IFileSystem;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -8,7 +12,7 @@ import java.nio.file.StandardCopyOption;
* <p>
* Created by daniil on 02.04.16.
*/
public class FileSystemLib {
public class FileSystemLib implements IFileSystem {
/**
* Copy data from InputStream to OutputStream
*
@@ -42,6 +46,7 @@ public class FileSystemLib {
* @param replace replace the destination file if present?
* @throws IOException
*/
@Override
public void copy(Path from, Path to, boolean replace) throws IOException {
assert from != null;
assert to != null;
@@ -58,6 +63,7 @@ public class FileSystemLib {
* @param file file to delete
* @throws IOException, FileNotFoundException
*/
@Override
public void delete(File file) throws IOException {
assert file != null;
@@ -74,6 +80,7 @@ public class FileSystemLib {
* @param actualFile Where should it point to
* @throws IOException
*/
@Override
public void createSymlink(Path linkFile, Path actualFile) throws IOException {
assert linkFile != null;
assert actualFile != null;
@@ -84,6 +91,7 @@ public class FileSystemLib {
Files.createSymbolicLink(linkFile, actualFile);
}
@Override
public void restoreFromResources(String resourceName, File destination, boolean replace) throws IOException {
assert resourceName != null;
assert destination != null;
@@ -112,6 +120,7 @@ public class FileSystemLib {
* @return FileReader
* @throws FileNotFoundException
*/
@Override
public Reader getReader(File file) throws FileNotFoundException {
assert file != null;
@@ -127,6 +136,7 @@ public class FileSystemLib {
* @return FileWriter
* @throws IOException
*/
@Override
public Writer getWriter(File file) throws IOException {
return new FileWriter(file);
}
@@ -138,8 +148,13 @@ public class FileSystemLib {
* @param directory destination
* @throws IOException
*/
@Override
public void unzip(String archive, String directory) throws IOException {
UnzipUtility zip = new UnzipUtility();
zip.unzip(archive, directory);
}
public boolean mkdirs(File file) {
return file.mkdirs();
}
}

View File

@@ -1,3 +1,5 @@
package eu.arcadex.system.file_system;
import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

View File

@@ -0,0 +1,71 @@
package eu.arcadex.system.file_system.api;
import java.io.*;
import java.nio.file.Path;
/**
* @author Daniil on 08.04.16.
*/
public interface IFileSystem {
/**
* Copy file or directory from one direction to another
*
* @param from File to copy
* @param to Destination
* @param replace replace the destination file if present?
* @throws IOException
*/
void copy(Path from, Path to, boolean replace) throws IOException;
/**
* Delete file
*
* @param file file to delete
* @throws IOException, FileNotFoundException
*/
void delete(File file) throws IOException;
/**
* Create a symlink
*
* @param linkFile Where symlink should be created
* @param actualFile Where should it point to
* @throws IOException
*/
void createSymlink(Path linkFile, Path actualFile) throws IOException;
void restoreFromResources(String resourceName, File destination, boolean replace) throws IOException;
/**
* Get FileReader for the file
* <p>
* We need this to make the code testable
*
* @param file file to read
* @return FileReader
* @throws FileNotFoundException
*/
Reader getReader(File file) throws FileNotFoundException;
/**
* Get FileWriter for the file
* <p>
* We need this to make the code testable
*
* @param file file to write to
* @return FileWriter
* @throws IOException
*/
Writer getWriter(File file) throws IOException;
/**
* Unzip archive to directory
*
* @param archive archive to extract
* @param directory destination
* @throws IOException
*/
void unzip(String archive, String directory) throws IOException;
boolean mkdirs(File file);
}