Skip to content

Commit 25ca3ba

Browse files
committed
Merge tag 'v1.1.0'
[maven-release-plugin] copy for tag v1.1.0
2 parents 8d4a09f + ce9de8b commit 25ca3ba

File tree

16 files changed

+207
-47
lines changed

16 files changed

+207
-47
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ build/
2121
nbbuild/
2222
dist/
2323
nbdist/
24-
.nb-gradle/
24+
.nb-gradle/
25+
26+
application.properties
27+
test_repository/

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: java
2+
jdk:
3+
- oraclejdk8
4+
sudo: false
5+
script: ./mvnw clean verify

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@ Configuration can be provided by `application.properties` file on classpath
7979
box.home=/tmp/test_repository
8080
box.prefix=sftp://my_box_server:
8181
```
82-
, or as command line arguments `java -jar -Dbox.home=/tmp/test_repository target/boxsitory-${version}.jar`
82+
or as command line arguments `java -jar -Dbox.home=/tmp/test_repository target/boxsitory-${version}.jar`

pom.xml

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
43
<modelVersion>4.0.0</modelVersion>
54

65
<groupId>cz.sparko.boxitory</groupId>
76
<artifactId>boxitory</artifactId>
8-
<version>1.0.0</version>
7+
<version>1.1.0</version>
98
<packaging>jar</packaging>
109

1110
<name>boxitory</name>
@@ -15,9 +14,29 @@
1514
<groupId>org.springframework.boot</groupId>
1615
<artifactId>spring-boot-starter-parent</artifactId>
1716
<version>1.5.3.RELEASE</version>
18-
<relativePath/> <!-- lookup parent from repository -->
17+
<relativePath /> <!-- lookup parent from repository -->
1918
</parent>
2019

20+
<issueManagement>
21+
<url>https://github.com/sparkoo/boxitory/issues</url>
22+
<system>GitHub Issues</system>
23+
</issueManagement>
24+
25+
<licenses>
26+
<license>
27+
<name>MIT License</name>
28+
<url>http://www.opensource.org/licenses/mit-license.php</url>
29+
<distribution>repo</distribution>
30+
</license>
31+
</licenses>
32+
33+
<scm>
34+
<url>https://github.com/sparkoo/boxitory</url>
35+
<connection>scm:git:git://github.com/sparkoo/boxitory.git</connection>
36+
<developerConnection>scm:git:[email protected]:sparkoo/boxitory.git</developerConnection>
37+
<tag>v1.1.0</tag>
38+
</scm>
39+
2140
<properties>
2241
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2342
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
@@ -50,7 +69,15 @@
5069
<groupId>org.testng</groupId>
5170
<artifactId>testng</artifactId>
5271
<version>6.11</version>
72+
<scope>test</scope>
73+
</dependency>
74+
<dependency>
75+
<groupId>commons-io</groupId>
76+
<artifactId>commons-io</artifactId>
77+
<version>2.5</version>
78+
<scope>test</scope>
5379
</dependency>
80+
5481
</dependencies>
5582

5683
<build>
@@ -59,6 +86,10 @@
5986
<groupId>org.springframework.boot</groupId>
6087
<artifactId>spring-boot-maven-plugin</artifactId>
6188
</plugin>
89+
<plugin>
90+
<artifactId>maven-release-plugin</artifactId>
91+
<version>2.5.3</version>
92+
</plugin>
6293
</plugins>
6394
</build>
6495

src/main/java/cz/sparko/boxitory/conf/AppProperties.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
public class AppProperties {
99
private String home = ".";
1010
private String host_prefix = "";
11+
private boolean sort_desc = false;
1112

1213
public String getHome() {
1314
return home;
@@ -17,6 +18,14 @@ public String getHost_prefix() {
1718
return host_prefix;
1819
}
1920

21+
public boolean isSort_desc() {
22+
return sort_desc;
23+
}
24+
25+
public void setSort_desc(boolean sort_desc) {
26+
this.sort_desc = sort_desc;
27+
}
28+
2029
public void setHome(String home) {
2130
this.home = home;
2231
}

src/main/java/cz/sparko/boxitory/domain/BoxVersion.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public String toString() {
2424
public boolean equals(Object o) {
2525
if (this == o) { return true; }
2626
if (o == null || getClass() != o.getClass()) { return false; }
27-
BoxVersion that = (BoxVersion) o;
28-
return Objects.equals(version, that.version) &&
29-
Objects.equals(providers, that.providers);
27+
BoxVersion thatVersion = (BoxVersion) o;
28+
return Objects.equals(this.version, thatVersion.version) &&
29+
providers.containsAll(thatVersion.getProviders()) && thatVersion.getProviders().containsAll(providers);
3030
}
3131

3232
@Override

src/main/java/cz/sparko/boxitory/service/FilesystemBoxRepository.java

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,37 @@
66
import cz.sparko.boxitory.domain.BoxVersion;
77
import org.slf4j.Logger;
88
import org.slf4j.LoggerFactory;
9-
import org.springframework.beans.factory.annotation.Autowired;
109

1110
import java.io.File;
12-
import java.util.ArrayList;
13-
import java.util.Arrays;
14-
import java.util.List;
15-
import java.util.Optional;
11+
import java.util.*;
1612
import java.util.stream.Collectors;
13+
import java.util.stream.Stream;
1714

18-
import static java.util.Collections.singletonList;
15+
import static java.lang.Integer.compare;
16+
import static java.lang.Integer.parseInt;
17+
import static java.util.Comparator.comparingInt;
1918

2019
public class FilesystemBoxRepository implements BoxRepository {
2120
private static final Logger LOG = LoggerFactory.getLogger(FilesystemBoxRepository.class);
2221

2322
private final String hostPrefix;
2423
private final File boxHome;
24+
private final boolean sortDesc;
2525

26-
@Autowired
2726
public FilesystemBoxRepository(AppProperties appProperties) {
2827
this.boxHome = new File(appProperties.getHome());
2928
this.hostPrefix = appProperties.getHost_prefix();
29+
this.sortDesc = appProperties.isSort_desc();
3030
LOG.info("setting BOX_HOME as [{}] and HOST_PREFIX as [{}]", boxHome.getAbsolutePath(), hostPrefix);
3131
}
3232

3333
@Override
3434
public Optional<Box> getBox(String boxName) {
35-
List<BoxVersion> boxVersions = new ArrayList<>();
35+
Map<String, List<File>> groupedBoxFiles = new HashMap<>();
3636
getBoxDir(boxName)
37-
.ifPresent(d -> boxVersions.addAll(getBoxVersionsFromBoxDir(d)));
37+
.ifPresent(d -> groupedBoxFiles.putAll(groupBoxFilesByVersion(d)));
38+
39+
List<BoxVersion> boxVersions = createBoxVersionsFromGroupedFiles(groupedBoxFiles);
3840
if (boxVersions.isEmpty()) {
3941
LOG.debug("no box versions found for [{}]", boxName);
4042
return Optional.empty();
@@ -55,15 +57,16 @@ private Optional<File> getBoxDir(String boxName) {
5557
.findFirst();
5658
}
5759

58-
private List<BoxVersion> getBoxVersionsFromBoxDir(File boxDir) {
60+
private Map<String, List<File>> groupBoxFilesByVersion(File boxDir) {
5961
File[] boxFiles = Optional.ofNullable(boxDir.listFiles())
6062
.orElse(new File[0]);
6163
return Arrays.stream(boxFiles)
6264
.filter(File::isFile)
6365
.filter(f -> f.getName().endsWith(".box"))
6466
.filter(this::validateFilename)
65-
.map(this::parseBoxFile)
66-
.collect(Collectors.toList());
67+
.collect(Collectors.groupingBy(
68+
this::getBoxVersionFromFileName
69+
));
6770
}
6871

6972
private boolean validateFilename(File boxFile) {
@@ -76,16 +79,40 @@ private boolean validateFilename(File boxFile) {
7679
return true;
7780
}
7881

79-
private BoxVersion parseBoxFile(File file) {
82+
private String getBoxVersionFromFileName(File file) {
8083
String filename = file.getName();
8184
List<String> parsedFilename = Arrays.asList(filename.split("_"));
85+
return parsedFilename.get(1);
86+
}
87+
88+
private List<BoxVersion> createBoxVersionsFromGroupedFiles(Map<String, List<File>> groupedFiles) {
89+
List<BoxVersion> boxVersions = new ArrayList<>();
90+
groupedFiles.forEach(
91+
(key, value) -> boxVersions.add(createBoxVersion(key, value))
92+
);
93+
Comparator<BoxVersion> versionComparator = Comparator.comparingInt(o -> Integer.parseInt(o.getVersion()));
94+
if (sortDesc) {
95+
boxVersions.sort(versionComparator.reversed());
96+
} else {
97+
boxVersions.sort(versionComparator);
98+
}
99+
return boxVersions;
100+
}
101+
102+
private BoxVersion createBoxVersion(String version, List<File> fileList) {
103+
return new BoxVersion(
104+
version,
105+
fileList.stream().map(this::createBoxProviderFromFile).collect(Collectors.toList())
106+
);
107+
}
82108

83-
String name = parsedFilename.get(0);
84-
String version = parsedFilename.get(1);
109+
private BoxProvider createBoxProviderFromFile(File file) {
110+
String filename = file.getName();
111+
List<String> parsedFilename = Arrays.asList(filename.split("_"));
85112
String provider = parsedFilename.get(2);
86113
if (provider.endsWith(".box")) {
87114
provider = provider.substring(0, provider.length() - 4);
88115
}
89-
return new BoxVersion(version, singletonList(new BoxProvider(hostPrefix + file.getAbsolutePath(), provider)));
116+
return new BoxProvider(hostPrefix + file.getAbsolutePath(), provider);
90117
}
91118
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
box.home=.
22
box.host_prefix=
3-
server.port=8083
3+
server.port=8083
4+
box.sort_desc=false

0 commit comments

Comments
 (0)