Skip to content

Commit 94e7427

Browse files
committed
initial commit after repository move
1 parent 29f9155 commit 94e7427

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1340
-2
lines changed

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "maven" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "daily"

.github/workflows/maven.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3+
4+
name: Java CI with Maven
5+
6+
on: [ push, pull_request ]
7+
8+
jobs:
9+
build:
10+
name: Build for JDK ${{ matrix.java }}
11+
if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'codejanovic/java-filesearch' }}
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
java: [ 8 ]
16+
steps:
17+
- uses: actions/checkout@v2
18+
- uses: actions/cache@v1
19+
with:
20+
path: ~/.m2/repository
21+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
22+
restore-keys: |
23+
${{ runner.os }}-maven-
24+
- name: Set up JDK ${{ matrix.java }}
25+
uses: actions/setup-java@v2
26+
with:
27+
java-version: ${{ matrix.java }}
28+
distribution: 'zulu'
29+
cache: maven
30+
- name: Build with Maven
31+
run: mvn -B -U compile test --file pom.xml
32+
env:
33+
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea/**
2+
target/**

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
MIT License
1+
The MIT License (MIT)
22

3-
Copyright (c) 2024 Zero-dependency Java
3+
Copyright (c) 2016 Aleksandar Damjanovic
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
[![Build Status](https://travis-ci.org/codejanovic/java-filesearch.svg?branch=develop)](https://travis-ci.org/codejanovic/java-filesearch)
2+
[![Coverage Status](https://coveralls.io/repos/github/codejanovic/java-filesearch/badge.svg?branch=develop)](https://coveralls.io/github/codejanovic/java-filesearch?branch=develop)
3+
[![License](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)]()
4+
5+
# java-filesearch
6+
7+
Java filesearch reimagined.
8+
9+
## Maven
10+
11+
Add the Jitpack repository to your build file
12+
13+
```xml
14+
15+
<repositories>
16+
<repository>
17+
<id>jitpack.io</id>
18+
<url>https://jitpack.io</url>
19+
</repository>
20+
</repositories>
21+
```
22+
23+
Release artifact
24+
25+
```xml
26+
27+
<dependency>
28+
<groupId>com.github.zrdj</groupId>
29+
<artifactId>java-filesearch</artifactId>
30+
<version>0.2.0</version>
31+
</dependency>
32+
```
33+
34+
## Motivation
35+
36+
This is just a fun project to reimplement the horrible file walking implementation from the JDK, trying to combine the
37+
two Java APIs of `File.listFiles()` and `Files.walkFileTree()` into a new API using Java's new `Stream<T>` feature of
38+
version 8.
39+
40+
To search for files simply start with the static method `Search.search()` and search for executable (.exe) files ...
41+
42+
... not **recursively** using the **Path API**
43+
44+
```java
45+
import static com.github.zrdj.java.filesearch.Search.search;
46+
47+
public void doSomeFileSearchStuff() {
48+
final List<Path> executables = search().directory("S:\Earch\Path").notRecursively().byPath()
49+
.stream()
50+
.filter(p -> p.getFileName().toString().endsWith(".exe"))
51+
.collect(Collectors.toList());
52+
// do something with found files
53+
}
54+
```
55+
56+
... or **recursively** using the **Path API**
57+
58+
```java
59+
import static com.github.zrdj.java.filesearch.Search.search;
60+
61+
public void doSomeFileSearchStuff() {
62+
final List<Path> executables = search().directory("S:\Earch\Path").recursively().byPath()
63+
.stream()
64+
.filter(p -> p.getFileName().toString().endsWith(".exe"))
65+
.collect(Collectors.toList());
66+
// do something with found files
67+
}
68+
```
69+
70+
... or **not recursively** using the **File API**
71+
72+
```java
73+
import static com.github.zrdj.java.filesearch.Search.search;
74+
75+
public void doSomeFileSearchStuff() {
76+
final List<File> executables = search().directory("S:\Earch\Path").notRecursively().byFile()
77+
.stream()
78+
.filter(f -> f.getName().endsWith(".exe"))
79+
.collect(Collectors.toList());
80+
// do something with found files
81+
}
82+
```
83+
84+
... or **recursively** using the **File API**
85+
86+
```java
87+
import static com.github.zrdj.java.filesearch.Search.search;
88+
89+
public void doSomeFileSearchStuff() {
90+
final List<File> executables = search().directory("S:\Earch\Path").recursively().byFile()
91+
.stream()
92+
.filter(f -> f.getName().endsWith(".exe"))
93+
.collect(Collectors.toList());
94+
// do something with found files
95+
}
96+
```

pom.xml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.github.zrdj</groupId>
7+
<artifactId>java-filesearch</artifactId>
8+
<version>0.2.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>java-filesearch</name>
12+
<description>java filesearch reimagined</description>
13+
<url>https://github.com/codejanovic/java-filesearch</url>
14+
<developers>
15+
<developer>
16+
<id>codejanovic</id>
17+
<name>Aleksandar Damjanovic</name>
18+
<email>codejanovic@gmail.com</email>
19+
<roles>
20+
<role>Project-Administrator</role>
21+
<role>Developer</role>
22+
</roles>
23+
</developer>
24+
</developers>
25+
26+
<licenses>
27+
<license>
28+
<name>MIT License</name>
29+
<url>https://opensource.org/licenses/MIT</url>
30+
<distribution>repo</distribution>
31+
</license>
32+
</licenses>
33+
34+
<scm>
35+
<connection>scm:git:git://github.com/codejanovic/java-filesearch.git</connection>
36+
<developerConnection>scm:git:git@github.com:codejanovic/java-filesearch.git</developerConnection>
37+
<url>https://github.com/codejanovic/java-filesearch.git</url>
38+
<tag>HEAD</tag>
39+
</scm>
40+
41+
<properties>
42+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
43+
<maven.compiler.source>1.8</maven.compiler.source>
44+
<maven.compiler.target>1.8</maven.compiler.target>
45+
</properties>
46+
47+
<dependencies>
48+
<dependency>
49+
<groupId>junit</groupId>
50+
<artifactId>junit</artifactId>
51+
<version>4.13.2</version>
52+
<scope>test</scope>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.assertj</groupId>
56+
<artifactId>assertj-core</artifactId>
57+
<version>3.24.2</version>
58+
<scope>test</scope>
59+
</dependency>
60+
</dependencies>
61+
<build>
62+
<plugins>
63+
<!-- Sources -->
64+
<plugin>
65+
<groupId>org.apache.maven.plugins</groupId>
66+
<artifactId>maven-source-plugin</artifactId>
67+
<version>3.2.1</version>
68+
<executions>
69+
<execution>
70+
<id>attach-sources</id>
71+
<goals>
72+
<goal>jar-no-fork</goal>
73+
</goals>
74+
</execution>
75+
</executions>
76+
</plugin>
77+
78+
<!-- Javadoc -->
79+
<plugin>
80+
<groupId>org.apache.maven.plugins</groupId>
81+
<artifactId>maven-javadoc-plugin</artifactId>
82+
<version>3.5.0</version>
83+
<executions>
84+
<execution>
85+
<id>attach-javadocs</id>
86+
<goals>
87+
<goal>jar</goal>
88+
</goals>
89+
</execution>
90+
</executions>
91+
</plugin>
92+
93+
<!-- Code coverage -->
94+
<plugin>
95+
<groupId>org.eluder.coveralls</groupId>
96+
<artifactId>coveralls-maven-plugin</artifactId>
97+
<version>4.3.0</version>
98+
</plugin>
99+
<plugin>
100+
<groupId>org.jacoco</groupId>
101+
<artifactId>jacoco-maven-plugin</artifactId>
102+
<version>0.8.11</version>
103+
<executions>
104+
<execution>
105+
<id>prepare-agent</id>
106+
<goals>
107+
<goal>prepare-agent</goal>
108+
</goals>
109+
</execution>
110+
</executions>
111+
</plugin>
112+
<plugin>
113+
<groupId>org.apache.maven.plugins</groupId>
114+
<artifactId>maven-compiler-plugin</artifactId>
115+
<version>3.12.1</version>
116+
<configuration>
117+
<source>${maven.compiler.source}</source>
118+
<target>${maven.compiler.target}</target>
119+
<compilerArgs>
120+
<arg>-XDignore.symbol.file</arg>
121+
</compilerArgs>
122+
<fork>true</fork>
123+
</configuration>
124+
</plugin>
125+
</plugins>
126+
</build>
127+
</project>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package com.github.zrdj.java.filesearch;
2+
3+
import com.github.zrdj.java.filesearch.filesystem.Directory;
4+
import com.github.zrdj.java.filesearch.filesystem.FileEntry;
5+
import com.github.zrdj.java.filesearch.iterator.file.RecursiveDirectoryIterator;
6+
import com.github.zrdj.java.filesearch.iterator.path.DirectoryIterator;
7+
import com.github.zrdj.java.filesearch.iterator.path.RecursiveSilentDirectoryIterator;
8+
9+
import java.io.File;
10+
import java.nio.file.Path;
11+
import java.util.Iterator;
12+
import java.util.Spliterator;
13+
import java.util.Spliterators;
14+
import java.util.stream.Stream;
15+
import java.util.stream.StreamSupport;
16+
17+
public interface FileSearch<T> {
18+
default Stream<T> stream() {
19+
final int characteristics = Spliterator.DISTINCT | Spliterator.SORTED | Spliterator.ORDERED;
20+
final Spliterator<T> splitIterator = Spliterators.spliteratorUnknownSize(iterator(), characteristics);
21+
return StreamSupport.stream(splitIterator, false);
22+
}
23+
24+
Iterator<T> iterator();
25+
26+
final class ByPath implements FileSearch<Path> {
27+
private final Path directory;
28+
29+
public ByPath(Path directory) {
30+
this.directory = directory;
31+
}
32+
33+
public ByPath(File directory) {
34+
this.directory = directory.toPath();
35+
}
36+
37+
@Override
38+
public Iterator<Path> iterator() {
39+
return new DirectoryIterator(new Directory.Smart(new FileEntry.Smart(directory)));
40+
}
41+
}
42+
43+
final class ByPathRecursive implements FileSearch<Path> {
44+
private final Path directory;
45+
46+
public ByPathRecursive(Path directory) {
47+
this.directory = directory;
48+
}
49+
50+
public ByPathRecursive(File directory) {
51+
this.directory = directory.toPath();
52+
}
53+
54+
@Override
55+
public Iterator<Path> iterator() {
56+
return new RecursiveSilentDirectoryIterator(new Directory.Smart(new FileEntry.Smart(directory)));
57+
}
58+
}
59+
60+
final class ByFile implements FileSearch<File> {
61+
private final File directory;
62+
63+
public ByFile(File directory) {
64+
this.directory = directory;
65+
}
66+
67+
public ByFile(Path directory) {
68+
this.directory = directory.toFile();
69+
}
70+
71+
@Override
72+
public Iterator<File> iterator() {
73+
return new com.github.zrdj.java.filesearch.iterator.file.DirectoryIterator(directory);
74+
}
75+
}
76+
77+
final class ByFileRecursive implements FileSearch<File> {
78+
private final File directory;
79+
80+
public ByFileRecursive(File directory) {
81+
this.directory = directory;
82+
}
83+
84+
public ByFileRecursive(Path directory) {
85+
this.directory = directory.toFile();
86+
}
87+
88+
@Override
89+
public Iterator<File> iterator() {
90+
return new RecursiveDirectoryIterator(directory);
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)