Skip to content

Commit 0359fb0

Browse files
Upgrade parent POM to version 44 and fix the checkstyle violations (#213)
* Upgrade parent POM to version 44
1 parent 376714e commit 0359fb0

File tree

10 files changed

+318
-370
lines changed

10 files changed

+318
-370
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ under the License.
2323
<parent>
2424
<groupId>org.apache.maven.extensions</groupId>
2525
<artifactId>maven-extensions</artifactId>
26-
<version>41</version>
26+
<version>44</version>
2727
<relativePath />
2828
</parent>
2929

src/test/java/org/apache/maven/buildcache/checksum/InputExclusionTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -400,20 +400,20 @@ private ExclusionResolver createExclusionResolver(
400400
* - other-file.json
401401
*/
402402
private class FsTree {
403-
public Path txtFileRootFolder;
404-
public Path javaFileRootFolder;
405-
public Path jsonFileRootFolder;
406-
public Path folder1;
407-
public Path txtFileFolder1;
408-
public Path javaFileFolder1;
409-
public Path jsonFileFolder1;
410-
public Path subFolder1;
411-
public Path txtFileSubFolder1;
412-
public Path javaFileSubFolder1;
413-
public Path jsonFileSubFolder1;
414-
public Path folder2;
415-
public Path txtFileFolder2;
416-
public Path javaFileFolder2;
417-
public Path jsonFileFolder2;
403+
private Path txtFileRootFolder;
404+
private Path javaFileRootFolder;
405+
private Path jsonFileRootFolder;
406+
private Path folder1;
407+
private Path txtFileFolder1;
408+
private Path javaFileFolder1;
409+
private Path jsonFileFolder1;
410+
private Path subFolder1;
411+
private Path txtFileSubFolder1;
412+
private Path javaFileSubFolder1;
413+
private Path jsonFileSubFolder1;
414+
private Path folder2;
415+
private Path txtFileFolder2;
416+
private Path javaFileFolder2;
417+
private Path jsonFileFolder2;
418418
}
419419
}

src/test/java/org/apache/maven/buildcache/hash/PerfTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,32 +73,32 @@ String doTest(HashFactory hashFactory, HashState state) throws IOException {
7373
}
7474

7575
@Benchmark
76-
public String SHA1(HashState state) throws IOException {
76+
public String sha1(HashState state) throws IOException {
7777
return doTest(HashFactory.SHA1, state);
7878
}
7979

8080
@Benchmark
81-
public String SHA256(HashState state) throws IOException {
81+
public String sha256(HashState state) throws IOException {
8282
return doTest(HashFactory.SHA256, state);
8383
}
8484

8585
@Benchmark
86-
public String XX(HashState state) throws IOException {
86+
public String xx(HashState state) throws IOException {
8787
return doTest(HashFactory.XX, state);
8888
}
8989

9090
@Benchmark
91-
public String XXMM(HashState state) throws IOException {
91+
public String xxmm(HashState state) throws IOException {
9292
return doTest(HashFactory.XXMM, state);
9393
}
9494

9595
@Benchmark
96-
public String METRO(HashState state) throws IOException {
96+
public String metro(HashState state) throws IOException {
9797
return doTest(HashFactory.METRO, state);
9898
}
9999

100100
@Benchmark
101-
public String METRO_MM(HashState state) throws IOException {
101+
public String metroMm(HashState state) throws IOException {
102102
return doTest(HashFactory.METRO_MM, state);
103103
}
104104

src/test/java/org/apache/maven/buildcache/its/CoreExtensionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void simple(Verifier verifier) throws VerificationException {
4343
}
4444

4545
@Test
46-
void simple_build_change_version_reuse_build_cache(Verifier verifier) throws VerificationException {
46+
void simpleBuildChangeVersionReuseBuildCache(Verifier verifier) throws VerificationException {
4747
verifier.setAutoclean(false);
4848

4949
verifier.setLogFileName("../log-1.txt");

src/test/java/org/apache/maven/buildcache/its/IncrementalRestoreTest.java

Lines changed: 86 additions & 117 deletions
Large diffs are not rendered by default.

src/test/java/org/apache/maven/buildcache/its/Issue74Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
@IntegrationTest("src/test/projects/mbuildcache-74-clean-cache-any-artifact")
4242
public class Issue74Test {
4343

44-
private static final Logger logger = LoggerFactory.getLogger(Issue74Test.class);
44+
private static final Logger LOGGER = LoggerFactory.getLogger(Issue74Test.class);
4545

4646
@Test
4747
void simple(Verifier verifier) throws VerificationException, IOException {
@@ -79,7 +79,7 @@ private static void verifyBuildCacheEntries(final Verifier verifier, long expect
7979
// buildinfo.xml -> local -> hash -> project
8080
Path projectPathInCache = buildInfoXmlPath.getParent().getParent().getParent();
8181

82-
logger.info("Checking '{}' for cached builds ...", projectPathInCache);
82+
LOGGER.info("Checking '{}' for cached builds ...", projectPathInCache);
8383

8484
if (!Files.exists(projectPathInCache)) {
8585
throw new VerificationException(

src/test/java/org/apache/maven/buildcache/its/Issue76Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class Issue76Test {
2929
private static final String PROJECT_NAME = "org.apache.maven.caching.test:mbuildcache-76";
3030

3131
@Test
32-
void simple_build_change_version_build_install_again(Verifier verifier) throws VerificationException {
32+
void simpleBuildChangeVersionBuildInstallAgain(Verifier verifier) throws VerificationException {
3333
verifier.setAutoclean(false);
3434

3535
verifier.setLogFileName("../log-1.txt");
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.buildcache.its;
20+
21+
import java.io.File;
22+
import java.io.IOException;
23+
import java.nio.file.Files;
24+
import java.nio.file.LinkOption;
25+
import java.nio.file.Path;
26+
import java.nio.file.attribute.FileTime;
27+
import java.nio.file.attribute.PosixFilePermission;
28+
import java.nio.file.attribute.PosixFilePermissions;
29+
import java.time.Instant;
30+
import java.time.ZoneId;
31+
import java.time.ZonedDateTime;
32+
import java.time.format.DateTimeFormatter;
33+
import java.util.EnumSet;
34+
import java.util.Map;
35+
import java.util.Objects;
36+
import java.util.Set;
37+
import java.util.TreeMap;
38+
39+
public class PathEntry implements Comparable<PathEntry> {
40+
41+
private final Path abs;
42+
private final Path path;
43+
private final Map<String, Object> attributes;
44+
45+
public PathEntry(Path abs, Path root) {
46+
this.abs = abs;
47+
this.path = abs.startsWith(root) ? root.relativize(abs) : abs;
48+
this.attributes = readAttributes(abs);
49+
}
50+
51+
@Override
52+
public int compareTo(PathEntry o) {
53+
return path.toString().compareTo(o.path.toString());
54+
}
55+
56+
boolean isNotDirectory() {
57+
return is("isRegularFile") || is("isSymbolicLink") || is("isOther");
58+
}
59+
60+
boolean isDirectory() {
61+
return is("isDirectory");
62+
}
63+
64+
private boolean is(String attr) {
65+
Object d = attributes.get(attr);
66+
return d instanceof Boolean && (Boolean) d;
67+
}
68+
69+
String display() {
70+
String suffix;
71+
String link = "";
72+
if (is("isSymbolicLink")) {
73+
suffix = "@";
74+
try {
75+
Path l = Files.readSymbolicLink(abs);
76+
link = " -> " + l.toString();
77+
} catch (IOException e) {
78+
// ignore
79+
}
80+
} else if (is("isDirectory")) {
81+
suffix = "/";
82+
} else if (is("isExecutable")) {
83+
suffix = "*";
84+
} else if (is("isOther")) {
85+
suffix = "";
86+
} else {
87+
suffix = "";
88+
}
89+
return path.toString() + suffix + link;
90+
}
91+
92+
String longDisplay() {
93+
String username = getUsername();
94+
String group = getGroup();
95+
Number length = (Number) attributes.get("size");
96+
if (length == null) {
97+
length = 0L;
98+
}
99+
String lengthString = formatLength(length);
100+
@SuppressWarnings("unchecked")
101+
Set<PosixFilePermission> perms = (Set<PosixFilePermission>) attributes.get("permissions");
102+
if (perms == null) {
103+
perms = EnumSet.noneOf(PosixFilePermission.class);
104+
}
105+
return (is("isDirectory") ? "d" : (is("isSymbolicLink") ? "l" : (is("isOther") ? "o" : "-")))
106+
+ PosixFilePermissions.toString(perms) + " "
107+
+ String.format(
108+
"%3s",
109+
(attributes.containsKey("nlink")
110+
? attributes.get("nlink").toString()
111+
: "1"))
112+
+ " " + username + " " + group + " " + lengthString + " "
113+
+ toString((FileTime) attributes.get("lastModifiedTime"))
114+
+ " " + display();
115+
}
116+
117+
private String getUsername() {
118+
String username = attributes.containsKey("owner") ? Objects.toString(attributes.get("owner"), null) : "owner";
119+
if (username.length() > 8) {
120+
username = username.substring(0, 8);
121+
} else {
122+
username = String.format("%-8s", username);
123+
}
124+
return username;
125+
}
126+
127+
private String getGroup() {
128+
String group = attributes.containsKey("group") ? Objects.toString(attributes.get("group"), null) : "group";
129+
if (group.length() > 8) {
130+
group = group.substring(0, 8);
131+
} else {
132+
group = String.format("%-8s", group);
133+
}
134+
return group;
135+
}
136+
137+
private String formatLength(Number length) {
138+
double l = length.longValue();
139+
String unit = "B";
140+
if (l >= 1000) {
141+
l /= 1024;
142+
unit = "K";
143+
if (l >= 1000) {
144+
l /= 1024;
145+
unit = "M";
146+
if (l >= 1000) {
147+
l /= 1024;
148+
unit = "T";
149+
}
150+
}
151+
}
152+
if (l < 10 && length.longValue() > 1000) {
153+
return String.format("%.1f%s", l, unit);
154+
} else {
155+
return String.format("%3.0f%s", l, unit);
156+
}
157+
}
158+
159+
protected String toString(FileTime time) {
160+
long millis = (time != null) ? time.toMillis() : -1L;
161+
if (millis < 0L) {
162+
return "------------";
163+
}
164+
ZonedDateTime dt = Instant.ofEpochMilli(millis).atZone(ZoneId.systemDefault());
165+
if (System.currentTimeMillis() - millis < 183L * 24L * 60L * 60L * 1000L) {
166+
return DateTimeFormatter.ofPattern("MMM ppd HH:mm").format(dt);
167+
} else {
168+
return DateTimeFormatter.ofPattern("MMM ppd yyyy").format(dt);
169+
}
170+
}
171+
172+
protected Map<String, Object> readAttributes(Path path) {
173+
Map<String, Object> attrs = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
174+
for (String view : path.getFileSystem().supportedFileAttributeViews()) {
175+
try {
176+
Map<String, Object> ta = Files.readAttributes(path, view + ":*", LinkOption.NOFOLLOW_LINKS);
177+
ta.forEach(attrs::putIfAbsent);
178+
} catch (IOException e) {
179+
// Ignore
180+
}
181+
}
182+
attrs.computeIfAbsent("isExecutable", s -> Files.isExecutable(path));
183+
attrs.computeIfAbsent("permissions", s -> getPermissionsFromFile(path.toFile()));
184+
return attrs;
185+
}
186+
187+
static Set<PosixFilePermission> getPermissionsFromFile(File f) {
188+
Set<PosixFilePermission> perms = EnumSet.noneOf(PosixFilePermission.class);
189+
if (f.canRead()) {
190+
perms.add(PosixFilePermission.OWNER_READ);
191+
perms.add(PosixFilePermission.GROUP_READ);
192+
perms.add(PosixFilePermission.OTHERS_READ);
193+
}
194+
if (f.canWrite()) {
195+
perms.add(PosixFilePermission.OWNER_WRITE);
196+
perms.add(PosixFilePermission.GROUP_WRITE);
197+
perms.add(PosixFilePermission.OTHERS_WRITE);
198+
}
199+
if (f.canExecute()) {
200+
perms.add(PosixFilePermission.OWNER_EXECUTE);
201+
perms.add(PosixFilePermission.GROUP_EXECUTE);
202+
perms.add(PosixFilePermission.OTHERS_EXECUTE);
203+
}
204+
return perms;
205+
}
206+
}

0 commit comments

Comments
 (0)