Skip to content

Commit 2d2bcb3

Browse files
Copilotslachiewicz
andcommitted
Initial plan for fixing negative modification time issue
Co-authored-by: slachiewicz <6705942+slachiewicz@users.noreply.github.com>
1 parent f714783 commit 2d2bcb3

File tree

61 files changed

+4699
-0
lines changed

Some content is hidden

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

61 files changed

+4699
-0
lines changed

META-INF/MANIFEST.MF

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Created-By: Maven Source Plugin 3.3.1
3+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
artifactId=plexus-io
2+
groupId=org.codehaus.plexus
3+
version=3.5.1
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<?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" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>org.codehaus.plexus</groupId>
7+
<artifactId>plexus</artifactId>
8+
<version>18</version>
9+
</parent>
10+
11+
<artifactId>plexus-io</artifactId>
12+
<version>3.5.1</version>
13+
14+
<name>Plexus IO Components</name>
15+
16+
<scm>
17+
<connection>scm:git:git@github.com:codehaus-plexus/plexus-io.git</connection>
18+
<developerConnection>scm:git:git@github.com:codehaus-plexus/plexus-io.git</developerConnection>
19+
<tag>plexus-io-3.5.1</tag>
20+
<url>http://github.com/codehaus-plexus/plexus-io</url>
21+
</scm>
22+
<issueManagement>
23+
<system>jira</system>
24+
<url>https://github.com/codehaus-plexus/plexus-io/issues</url>
25+
</issueManagement>
26+
<distributionManagement>
27+
<site>
28+
<id>github:gh-pages</id>
29+
<url>${project.scm.developerConnection}</url>
30+
</site>
31+
</distributionManagement>
32+
33+
<properties>
34+
<eclipseSisuVersion>0.9.0.M3</eclipseSisuVersion>
35+
<slf4jVersion>1.7.36</slf4jVersion>
36+
<project.build.outputTimestamp>2024-09-09T12:59:16Z</project.build.outputTimestamp>
37+
</properties>
38+
39+
<dependencyManagement>
40+
<dependencies>
41+
<dependency>
42+
<groupId>org.eclipse.sisu</groupId>
43+
<artifactId>org.eclipse.sisu.inject</artifactId>
44+
<version>${eclipseSisuVersion}</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.eclipse.sisu</groupId>
48+
<artifactId>org.eclipse.sisu.plexus</artifactId>
49+
<version>${eclipseSisuVersion}</version>
50+
</dependency>
51+
</dependencies>
52+
</dependencyManagement>
53+
<dependencies>
54+
<!-- JSR330 -->
55+
<dependency>
56+
<groupId>javax.inject</groupId>
57+
<artifactId>javax.inject</artifactId>
58+
<version>1</version>
59+
</dependency>
60+
61+
<dependency>
62+
<groupId>org.codehaus.plexus</groupId>
63+
<artifactId>plexus-utils</artifactId>
64+
<version>4.0.1</version>
65+
</dependency>
66+
<dependency>
67+
<groupId>org.codehaus.plexus</groupId>
68+
<artifactId>plexus-xml</artifactId>
69+
<version>3.0.1</version>
70+
<scope>test</scope>
71+
</dependency>
72+
<dependency>
73+
<groupId>com.google.code.findbugs</groupId>
74+
<artifactId>jsr305</artifactId>
75+
<version>3.0.2</version>
76+
<scope>provided</scope>
77+
</dependency>
78+
<dependency>
79+
<groupId>commons-io</groupId>
80+
<artifactId>commons-io</artifactId>
81+
<version>2.16.1</version>
82+
</dependency>
83+
84+
<!-- Tests -->
85+
<dependency>
86+
<groupId>org.junit.jupiter</groupId>
87+
<artifactId>junit-jupiter-api</artifactId>
88+
<scope>test</scope>
89+
</dependency>
90+
<dependency>
91+
<groupId>org.slf4j</groupId>
92+
<artifactId>slf4j-simple</artifactId>
93+
<version>${slf4jVersion}</version>
94+
<scope>test</scope>
95+
</dependency>
96+
<dependency>
97+
<groupId>org.codehaus.plexus</groupId>
98+
<artifactId>plexus-testing</artifactId>
99+
<version>1.4.0</version>
100+
<scope>test</scope>
101+
</dependency>
102+
<!-- Sisu and dependencies -->
103+
<dependency>
104+
<groupId>org.eclipse.sisu</groupId>
105+
<artifactId>org.eclipse.sisu.inject</artifactId>
106+
<scope>test</scope>
107+
</dependency>
108+
<dependency>
109+
<groupId>com.google.inject</groupId>
110+
<artifactId>guice</artifactId>
111+
<version>6.0.0</version>
112+
<scope>test</scope>
113+
</dependency>
114+
</dependencies>
115+
116+
<build>
117+
<plugins>
118+
<plugin>
119+
<groupId>org.eclipse.sisu</groupId>
120+
<artifactId>sisu-maven-plugin</artifactId>
121+
</plugin>
122+
<plugin>
123+
<groupId>org.apache.maven.plugins</groupId>
124+
<artifactId>maven-scm-publish-plugin</artifactId>
125+
<configuration>
126+
<content>${project.reporting.outputDirectory}</content>
127+
<!-- mono-module doesn't require site:stage -->
128+
</configuration>
129+
<executions>
130+
<execution>
131+
<id>scm-publish</id>
132+
<!-- deploy site with maven-scm-publish-plugin -->
133+
<goals>
134+
<goal>publish-scm</goal>
135+
</goals>
136+
<phase>site-deploy</phase>
137+
</execution>
138+
</executions>
139+
</plugin>
140+
</plugins>
141+
</build>
142+
</project>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.codehaus.plexus.components.io.attributes;
2+
3+
/*
4+
* Copyright 2007 The Codehaus Foundation.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* 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, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
@SuppressWarnings("OctalInteger")
20+
public final class AttributeConstants {
21+
22+
public static final int OCTAL_OWNER_READ = 0400;
23+
24+
public static final int OCTAL_OWNER_WRITE = 0200;
25+
26+
public static final int OCTAL_OWNER_EXECUTE = 0100;
27+
28+
public static final int OCTAL_GROUP_READ = 040;
29+
30+
public static final int OCTAL_GROUP_WRITE = 020;
31+
32+
public static final int OCTAL_GROUP_EXECUTE = 010;
33+
34+
public static final int OCTAL_WORLD_READ = 04;
35+
36+
public static final int OCTAL_WORLD_WRITE = 02;
37+
38+
public static final int OCTAL_WORLD_EXECUTE = 01;
39+
40+
private AttributeConstants() {}
41+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Copyright 2014 The Codehaus Foundation.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.codehaus.plexus.components.io.attributes;
17+
18+
import javax.annotation.Nonnull;
19+
import javax.annotation.Nullable;
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.BasicFileAttributes;
27+
import java.nio.file.attribute.FileOwnerAttributeView;
28+
import java.nio.file.attribute.PosixFileAttributes;
29+
import java.nio.file.attribute.PosixFilePermission;
30+
import java.util.HashSet;
31+
import java.util.Set;
32+
33+
/**
34+
* @author Kristian Rosenvold
35+
*/
36+
@SuppressWarnings("OctalInteger")
37+
public class AttributeUtils {
38+
/*
39+
Reads last-modified with proper failure handling if something goes wrong.
40+
*/
41+
public static long getLastModified(@Nonnull File file) {
42+
try {
43+
BasicFileAttributes basicFileAttributes = Files.readAttributes(file.toPath(), BasicFileAttributes.class);
44+
return basicFileAttributes.lastModifiedTime().toMillis();
45+
} catch (IOException e) {
46+
throw new RuntimeException(e);
47+
}
48+
}
49+
50+
public static void chmod(@Nonnull File file, int mode) throws IOException {
51+
final Path path = file.toPath();
52+
if (!Files.isSymbolicLink(path)) {
53+
Files.setPosixFilePermissions(path, getPermissions(mode));
54+
}
55+
}
56+
57+
@Nonnull
58+
public static Set<PosixFilePermission> getPermissions(int mode) {
59+
Set<PosixFilePermission> perms = new HashSet<>();
60+
// add owners permission
61+
if ((mode & 0400) > 0) {
62+
perms.add(PosixFilePermission.OWNER_READ);
63+
}
64+
if ((mode & 0200) > 0) {
65+
perms.add(PosixFilePermission.OWNER_WRITE);
66+
}
67+
if ((mode & 0100) > 0) {
68+
perms.add(PosixFilePermission.OWNER_EXECUTE);
69+
}
70+
// add group permissions
71+
if ((mode & 0040) > 0) {
72+
perms.add(PosixFilePermission.GROUP_READ);
73+
}
74+
if ((mode & 0020) > 0) {
75+
perms.add(PosixFilePermission.GROUP_WRITE);
76+
}
77+
if ((mode & 0010) > 0) {
78+
perms.add(PosixFilePermission.GROUP_EXECUTE);
79+
}
80+
// add others permissions
81+
if ((mode & 0004) > 0) {
82+
perms.add(PosixFilePermission.OTHERS_READ);
83+
}
84+
if ((mode & 0002) > 0) {
85+
perms.add(PosixFilePermission.OTHERS_WRITE);
86+
}
87+
if ((mode & 0001) > 0) {
88+
perms.add(PosixFilePermission.OTHERS_EXECUTE);
89+
}
90+
return perms;
91+
}
92+
93+
@Nonnull
94+
public static PosixFileAttributes getPosixFileAttributes(@Nonnull File file) throws IOException {
95+
return Files.readAttributes(file.toPath(), PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
96+
}
97+
98+
@Nonnull
99+
public static BasicFileAttributes getFileAttributes(@Nonnull File file) throws IOException {
100+
return getFileAttributes(file.toPath());
101+
}
102+
103+
public static BasicFileAttributes getFileAttributes(Path path) throws IOException {
104+
if (isUnix(path)) {
105+
try {
106+
return Files.readAttributes(path, PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
107+
} catch (UnsupportedOperationException ignore) {
108+
// Maybe ignoring is dramatic. Maybe not. But we do get the basic attrs anyway
109+
}
110+
}
111+
return Files.readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
112+
}
113+
114+
public static boolean isUnix(Path path) {
115+
return path.getFileSystem().supportedFileAttributeViews().contains("unix");
116+
}
117+
118+
@Nullable
119+
public static FileOwnerAttributeView getFileOwnershipInfo(@Nonnull File file) throws IOException {
120+
try {
121+
return Files.getFileAttributeView(file.toPath(), FileOwnerAttributeView.class, LinkOption.NOFOLLOW_LINKS);
122+
} catch (UnsupportedOperationException e) {
123+
return null;
124+
}
125+
}
126+
}

0 commit comments

Comments
 (0)