Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Andrej Betík
2016-autumn-hw03-find
Commits
4aedfb79
Commit
4aedfb79
authored
Dec 23, 2016
by
Andrej Betík
Browse files
project 3
parent
a2a0ad38
Changes
16
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
4aedfb79
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns=
"http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
cz.muni.fi.pb162
</groupId>
<artifactId>
find
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<packaging>
jar
</packaging>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<maven.compiler.source>
1.8
</maven.compiler.source>
<maven.compiler.target>
1.8
</maven.compiler.target>
<version.junit>
4.12
</version.junit>
<version.cli>
1.3.1
</version.cli>
<hamcrest.version>
1.3
</hamcrest.version>
<checkstyle.fail>
true
</checkstyle.fail>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/commons-cli/commons-cli -->
<dependency>
<groupId>
commons-cli
</groupId>
<artifactId>
commons-cli
</artifactId>
<version>
${version.cli}
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.ant/ant -->
<dependency>
<groupId>
org.apache.ant
</groupId>
<artifactId>
ant
</artifactId>
<version>
1.8.2
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<version>
${version.junit}
</version>
</dependency>
<dependency>
<groupId>
org.hamcrest
</groupId>
<artifactId>
hamcrest-all
</artifactId>
<version>
${hamcrest.version}
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>
maven-dependency-plugin
</artifactId>
<executions>
<execution>
<phase>
install
</phase>
<goals>
<goal>
copy-dependencies
</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- Include sources into JAR -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-source-plugin
</artifactId>
<executions>
<execution>
<id>
attach-sources
</id>
<goals>
<goal>
jar
</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Check code style -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-checkstyle-plugin
</artifactId>
<version>
2.16
</version>
<executions>
<execution>
<id>
validate
</id>
<phase>
validate
</phase>
<configuration>
<configLocation>
pb162_codestyle.xml
</configLocation>
<encoding>
UTF-8
</encoding>
<consoleOutput>
true
</consoleOutput>
<failOnViolation>
${checkstyle.fail}
</failOnViolation>
<violationSeverity>
warning
</violationSeverity>
<includeTestSourceDirectory>
false
</includeTestSourceDirectory>
</configuration>
<goals>
<goal>
check
</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Jar -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-jar-plugin
</artifactId>
<configuration>
<archive>
<manifest>
<!-- tell maven, which class contains our main method-->
<mainClass>
cz.muni.fi.pb162.find.Application
</mainClass>
<addClasspath>
true
</addClasspath>
<classpathPrefix>
lib/
</classpathPrefix>
</manifest>
</archive>
</configuration>
<!-- this plugin can be executed with command mvn jar:jar -->
<!-- following executions block is telling maven to execute this plugin automatically during build -->
<executions>
<execution>
<id>
make-executable
</id>
<phase>
package
</phase>
<goals>
<goal>
jar
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns=
"http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
cz.muni.fi.pb162
</groupId>
<artifactId>
find
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<packaging>
jar
</packaging>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<maven.compiler.source>
1.8
</maven.compiler.source>
<maven.compiler.target>
1.8
</maven.compiler.target>
<version.junit>
4.12
</version.junit>
<version.cli>
1.3.1
</version.cli>
<hamcrest.version>
1.3
</hamcrest.version>
<checkstyle.fail>
true
</checkstyle.fail>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/commons-cli/commons-cli -->
<dependency>
<groupId>
commons-cli
</groupId>
<artifactId>
commons-cli
</artifactId>
<version>
${version.cli}
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.ant/ant -->
<dependency>
<groupId>
org.apache.ant
</groupId>
<artifactId>
ant
</artifactId>
<version>
1.8.2
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<version>
${version.junit}
</version>
</dependency>
<dependency>
<groupId>
org.hamcrest
</groupId>
<artifactId>
hamcrest-all
</artifactId>
<version>
${hamcrest.version}
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>
maven-dependency-plugin
</artifactId>
<executions>
<execution>
<phase>
install
</phase>
<goals>
<goal>
copy-dependencies
</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- Include sources into JAR -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-source-plugin
</artifactId>
<version>
3.0.1
</version>
<executions>
<execution>
<id>
attach-sources
</id>
<goals>
<goal>
jar
</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Check code style -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-checkstyle-plugin
</artifactId>
<version>
2.16
</version>
<executions>
<execution>
<id>
validate
</id>
<phase>
validate
</phase>
<configuration>
<configLocation>
pb162_codestyle.xml
</configLocation>
<encoding>
UTF-8
</encoding>
<consoleOutput>
true
</consoleOutput>
<failOnViolation>
${checkstyle.fail}
</failOnViolation>
<violationSeverity>
warning
</violationSeverity>
<includeTestSourceDirectory>
false
</includeTestSourceDirectory>
</configuration>
<goals>
<goal>
check
</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Jar -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-jar-plugin
</artifactId>
<version>
2.4
</version>
<configuration>
<archive>
<manifest>
<!-- tell maven, which class contains our main method-->
<mainClass>
cz.muni.fi.pb162.find.Application
</mainClass>
<addClasspath>
true
</addClasspath>
<classpathPrefix>
lib/
</classpathPrefix>
</manifest>
</archive>
</configuration>
<!-- this plugin can be executed with command mvn jar:jar -->
<!-- following executions block is telling maven to execute this plugin automatically during build -->
<executions>
<execution>
<id>
make-executable
</id>
<phase>
package
</phase>
<goals>
<goal>
jar
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
src/main/java/cz/muni/fi/pb162/find/filters/BasicFilter.java
View file @
4aedfb79
package
cz.muni.fi.pb162.find.filters
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
cz.muni.fi.pb162.find.filesystem.SearchEntry
;
/**
* Created by pstanko.
*
* @author pstanko
*/
public
abstract
class
BasicFilter
{
protected
List
<
SearchEntry
>
paths
;
/**
* Basic filter
* @param paths list of filtered entries
*/
public
BasicFilter
(
List
<
SearchEntry
>
paths
)
{
this
.
paths
=
paths
;
}
/**
* Determine whether file or directory passes this filter
*
* @param path filtered entry
* @return true if given entry passes the filter, false otherwise
*/
public
abstract
boolean
filter
(
SearchEntry
path
);
/**
* Filters provided list of entries
* @return filtered list of entries
*/
public
List
<
SearchEntry
>
filtered
()
{
return
paths
.
stream
().
filter
(
this
::
filter
).
collect
(
Collectors
.
toList
());
}
}
package
cz.muni.fi.pb162.find.filters
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
cz.muni.fi.pb162.find.filesystem.SearchEntry
;
/**
* Created by pstanko.
*
* @author pstanko
*/
public
abstract
class
BasicFilter
{
protected
List
<
SearchEntry
>
paths
;
/**
* Basic filter
* @param paths list of filtered entries
*/
public
BasicFilter
(
List
<
SearchEntry
>
paths
)
{
this
.
paths
=
paths
;
}
/**
* Determine whether file or directory passes this filter
*
* @param path filtered entry
* @return true if given entry passes the filter, false otherwise
*/
public
abstract
boolean
filter
(
SearchEntry
path
);
/**
* Filters provided list of entries
* @return filtered list of entries
*/
public
List
<
SearchEntry
>
filtered
()
{
return
paths
.
stream
().
filter
(
this
::
filter
).
collect
(
Collectors
.
toList
());
}
}
src/main/java/cz/muni/fi/pb162/find/impl/FSWalkResultImpl.java
0 → 100644
View file @
4aedfb79
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
cz.muni.fi.pb162.find.impl
;
import
cz.muni.fi.pb162.find.ApplicationOptions
;
import
cz.muni.fi.pb162.find.filesystem.FSWalkResult
;
import
cz.muni.fi.pb162.find.filesystem.SearchEntry
;
import
cz.muni.fi.pb162.find.filesystem.SearchEntry.Types
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
*
* @author Andrej Betik
*/
public
class
FSWalkResultImpl
extends
FSWalkResult
{
/**
* FSWalkResultImpl constructor
* @param options options
*/
public
FSWalkResultImpl
(
ApplicationOptions
options
)
{
super
(
options
);
}
/**
* getDirectiories
* @return list
*/
@Override
public
List
<
SearchEntry
>
getDirectories
()
{
List
<
SearchEntry
>
dirlist
=
new
ArrayList
<>();
String
pathSep
=
"/"
;
String
dirct
=
this
.
getOpts
().
getDirectory
();
File
file
=
new
File
(
dirct
);
if
(
file
.
isDirectory
())
{
SearchEntry
se
=
new
SearchEntryImpl
(
file
.
toPath
(),
Types
.
DIR
);
dirlist
.
add
(
se
);
}
String
[]
names
=
file
.
list
();
for
(
String
name
:
names
){
File
foundDir
=
new
File
(
dirct
+
pathSep
+
name
);
if
(
foundDir
.
isDirectory
()){
SearchEntry
se
=
new
SearchEntryImpl
(
foundDir
.
toPath
(),
Types
.
DIR
);
se
.
setSize
(
0
);
dirlist
.
add
(
se
);
}
}
return
dirlist
;
}
/**
* getFiles
* @return list
*/
@Override
public
List
<
SearchEntry
>
getFiles
()
{
String
pathSep
=
"/"
;
String
dirct
=
this
.
getOpts
().
getDirectory
();
File
file
=
new
File
(
dirct
);
String
[]
names
=
file
.
list
();
List
<
SearchEntry
>
dirlist
=
new
ArrayList
<>();
for
(
String
name
:
names
){
File
foundDir
=
new
File
(
dirct
+
pathSep
+
name
);
if
(
foundDir
.
isFile
()){
SearchEntry
se
=
new
SearchEntryImpl
(
foundDir
.
toPath
(),
Types
.
FILE
);
se
.
setSize
(
foundDir
.
length
());
dirlist
.
add
(
se
);
}
}
return
dirlist
;
}
}
src/main/java/cz/muni/fi/pb162/find/impl/SearchEntryImpl.java
0 → 100644
View file @
4aedfb79
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
cz.muni.fi.pb162.find.impl
;
import
cz.muni.fi.pb162.find.filesystem.SearchEntry
;
import
java.nio.file.Path
;
/**
*
* @author Andrej Betik
*/
public
class
SearchEntryImpl
extends
SearchEntry
{
private
final
Types
type
;
/**
* SearchEntryImpl constructor
* @param path path
* @param type type
*/
public
SearchEntryImpl
(
Path
path
,
Types
type
)
{
super
(
path
);
this
.
type
=
type
;
}
@Override
public
Types
getType
()
{
return
type
;
}
}
src/main/java/cz/muni/fi/pb162/find/impl/actions/FilterActionImpl.java
0 → 100644
View file @
4aedfb79
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
cz.muni.fi.pb162.find.impl.actions
;
import
cz.muni.fi.pb162.find.ApplicationOptions
;
import
cz.muni.fi.pb162.find.actions.FilterAction
;
import
cz.muni.fi.pb162.find.filesystem.SearchEntry
;
import
cz.muni.fi.pb162.find.filters.BasicFilter
;
import
cz.muni.fi.pb162.find.impl.filters.FileContentFilter
;
import
cz.muni.fi.pb162.find.impl.filters.FileNameFilter
;
import
cz.muni.fi.pb162.find.impl.filters.MaxSizeFilter
;
import
cz.muni.fi.pb162.find.impl.filters.MinSizeFilter
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
*
* @author Andrej Betik
*/
public
class
FilterActionImpl
implements
FilterAction
{
private
ApplicationOptions
options
;
private
BasicFilter
filter
=
null
;
/**
* FilterActionImpl constructor
* @param options options
*/
public
FilterActionImpl
(
ApplicationOptions
options
)
{
this
.
options
=
options
;
if
(
this
.
options
.
getSizeMax
()
!=
null
)
{
filter
=
new
MaxSizeFilter
(
new
ArrayList
<>(),
this
.
options
.
getSizeMax
());
}
else
if
(
this
.
options
.
getSizeMin
()
!=
null
)
{
filter
=
new
MinSizeFilter
(
new
ArrayList
<>(),
this
.
options
.
getSizeMin
());
}
else
if
(
this
.
options
.
getNameRegex
()!=
null
)
{
filter
=
new
FileNameFilter
(
new
ArrayList
<>(),
this
.
options
.
getNameRegex
());
}
else
if
(
this
.
options
.
getTextRegex
()
!=
null
)
{
filter
=
new
FileContentFilter
(
new
ArrayList
<>(),
this
.
options
.
getTextRegex
());
}
}
/**
* filter
* @param entries entries
* @return filtered list of files
*/
@Override
public
List
<
SearchEntry
>
filter
(
List
<
SearchEntry
>
entries
)
{
if
(
this
.
filter
==
null
){
return
entries
;
}
List
<
SearchEntry
>
result
=
new
ArrayList
<>();
for
(
SearchEntry
entry
:
entries
)
{
if
(
filter
.
filter
(
entry
))
{
result
.
add
(
entry
);
}
}
return
result
;
}
}
src/main/java/cz/muni/fi/pb162/find/impl/actions/SortActionImpl.java
0 → 100644
View file @
4aedfb79
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
cz.muni.fi.pb162.find.impl.actions
;
import
cz.muni.fi.pb162.find.ApplicationOptions
;
import
cz.muni.fi.pb162.find.actions.SortAction
;
import
cz.muni.fi.pb162.find.comparators.BasicComparator
;
import
cz.muni.fi.pb162.find.filesystem.SearchEntry
;
import
cz.muni.fi.pb162.find.tools.SortFactory
;
import
java.util.List
;
/**
*
* @author Andrej Betik
*/
public
class
SortActionImpl
implements
SortAction
{
private
BasicComparator
comp
=
null
;
private
final
ApplicationOptions
options
;
/**
* SortActionImpl constructor
* @param applicationOptions applicationOptions
*/
public
SortActionImpl
(
ApplicationOptions
applicationOptions
)
{
this
.
options
=
applicationOptions
;
this
.
comp
=
SortFactory
.
create
(
applicationOptions
.
getSort
());
}
/**
* sorted
* @param entries entries
* @return sorted list
*/
@Override
public
List
<
SearchEntry
>
sorted
(
List
<
SearchEntry
>
entries
)
{
if
(
this
.
comp
!=
null
){
entries
.
sort
(
comp
);
}
return
entries
;
}
}
src/main/java/cz/muni/fi/pb162/find/impl/comparators/FileExtensionComparator.java
0 → 100644
View file @
4aedfb79
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
cz.muni.fi.pb162.find.impl.comparators
;
import
cz.muni.fi.pb162.find.comparators.BasicComparator
;
import
cz.muni.fi.pb162.find.filesystem.SearchEntry
;
/**
*
* @author Andrej Betik
*/
public
class
FileExtensionComparator
implements
BasicComparator
{
private
final
BasicComparator
next
;
/**
* FileExtensionComparator constructor
* @param next next
*/
public
FileExtensionComparator
(
BasicComparator
next
)
{
this
.
next
=
next
;
}
@Override