Skip to content

Commit 7cedb6c

Browse files
authored
Merge pull request #519 from jonesbusy/feature/native-path
Avoid using String for a Path
2 parents 0dc74b9 + 4e20ecf commit 7cedb6c

5 files changed

Lines changed: 14 additions & 29 deletions

File tree

plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/extractor/ArchetypeCommonFile.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public enum ArchetypeCommonFile {
110110
*/
111111
public static ArchetypeCommonFile fromFile(String file) {
112112
for (ArchetypeCommonFile f : ArchetypeCommonFile.values()) {
113-
if (Path.of(f.getPath()).equals(Path.of(file))) {
113+
if (f.getPath().equals(Path.of(file))) {
114114
return f;
115115
}
116116
}
@@ -121,7 +121,7 @@ public static ArchetypeCommonFile fromFile(String file) {
121121
* Get the path
122122
* @return the path
123123
*/
124-
public String getPath() {
125-
return path;
124+
public Path getPath() {
125+
return Path.of(path);
126126
}
127127
}

plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/extractor/PluginMetadata.java

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@
55
import io.jenkins.tools.pluginmodernizer.core.model.JDK;
66
import io.jenkins.tools.pluginmodernizer.core.model.Plugin;
77
import io.jenkins.tools.pluginmodernizer.core.model.PreconditionError;
8+
import java.io.Serial;
89
import java.io.Serializable;
910
import java.nio.file.Path;
1011
import java.util.*;
11-
import org.openrewrite.marker.Marker;
1212

1313
/**
1414
* Metadata of a plugin extracted from its POM file or code
1515
*/
16-
public class PluginMetadata extends CacheEntry<PluginMetadata> implements Serializable, Marker {
16+
public class PluginMetadata extends CacheEntry<PluginMetadata> implements Serializable {
1717

18+
@Serial
1819
private static final long serialVersionUID = 1L;
1920

20-
private transient UUID id;
21-
2221
/**
2322
* Name of the plugin
2423
*/
@@ -189,7 +188,7 @@ public void setJdks(Set<JDK> jdkVersions) {
189188
* @param path The path
190189
* @return The file or null
191190
*/
192-
public ArchetypeCommonFile getFile(String path) {
191+
public ArchetypeCommonFile getFile(Path path) {
193192
return commonFiles.stream()
194193
.filter(f -> f.getPath().equals(path))
195194
.findFirst()
@@ -201,7 +200,7 @@ public ArchetypeCommonFile getFile(String path) {
201200
* @param path The path
202201
* @return True if the file is present
203202
*/
204-
public boolean hasFile(String path) {
203+
public boolean hasFile(Path path) {
205204
return commonFiles.stream().anyMatch(f -> f.getPath().equals(path));
206205
}
207206

@@ -260,15 +259,4 @@ public void addProperty(String key, String value) {
260259
}
261260
properties.put(key, value);
262261
}
263-
264-
@Override
265-
public UUID getId() {
266-
return id;
267-
}
268-
269-
@Override
270-
public PluginMetadata withId(UUID id) {
271-
this.id = id;
272-
return this;
273-
}
274262
}

plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/recipes/IsUsingArchetypeCommonFile.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import io.jenkins.tools.pluginmodernizer.core.extractor.ArchetypeCommonFile;
44
import io.jenkins.tools.pluginmodernizer.core.extractor.ArchetypeCommonFileVisitor;
55
import io.jenkins.tools.pluginmodernizer.core.extractor.PluginMetadata;
6-
import java.nio.file.Path;
76
import org.openrewrite.*;
87
import org.openrewrite.marker.SearchResult;
98

@@ -44,7 +43,7 @@ public Tree visit(Tree tree, ExecutionContext ctx) {
4443
PluginMetadata pluginMetadata = new ArchetypeCommonFileVisitor().reduce(tree, new PluginMetadata());
4544
if (pluginMetadata.hasCommonFile(archetypeCommonFile)) {
4645
SourceFile sourceFile = (SourceFile) tree;
47-
if (sourceFile.getSourcePath().equals(Path.of(archetypeCommonFile.getPath()))) {
46+
if (sourceFile.getSourcePath().equals(archetypeCommonFile.getPath())) {
4847
return SearchResult.found(tree, "Project is using " + archetypeCommonFile.getPath());
4948
}
5049
}

plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/recipes/SetupDependabot.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
44
import io.jenkins.tools.pluginmodernizer.core.extractor.ArchetypeCommonFile;
5-
import java.nio.file.Path;
6-
import java.nio.file.Paths;
75
import java.util.Collection;
86
import java.util.Collections;
97
import java.util.concurrent.atomic.AtomicBoolean;
@@ -65,11 +63,11 @@ public TreeVisitor<?, ExecutionContext> getScanner(AtomicBoolean shouldCreate) {
6563
@Override
6664
public Tree visit(Tree tree, ExecutionContext ctx) {
6765
SourceFile sourceFile = (SourceFile) tree;
68-
if (sourceFile.getSourcePath().equals(Path.of(ArchetypeCommonFile.RENOVATE.getPath()))) {
66+
if (sourceFile.getSourcePath().equals(ArchetypeCommonFile.RENOVATE.getPath())) {
6967
LOG.info("Project is using Renovate. Doing nothing.");
7068
shouldCreate.set(false);
7169
}
72-
if (sourceFile.getSourcePath().equals(Path.of(ArchetypeCommonFile.DEPENDABOT.getPath()))) {
70+
if (sourceFile.getSourcePath().equals(ArchetypeCommonFile.DEPENDABOT.getPath())) {
7371
LOG.info("Project is using Dependabot already. Doing nothing.");
7472
shouldCreate.set(false);
7573
}
@@ -84,8 +82,8 @@ public Collection<SourceFile> generate(AtomicBoolean shouldCreate, ExecutionCont
8482
return YamlParser.builder()
8583
.build()
8684
.parse(DEPENDABOT_FILE)
87-
.map(brandNewFile -> (SourceFile)
88-
brandNewFile.withSourcePath(Paths.get(ArchetypeCommonFile.DEPENDABOT.getPath())))
85+
.map(brandNewFile ->
86+
(SourceFile) brandNewFile.withSourcePath(ArchetypeCommonFile.DEPENDABOT.getPath()))
8987
.collect(Collectors.toList());
9088
}
9189
return Collections.emptyList();

plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/recipes/DeclarativeRecipesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void shouldAddCodeOwnerIfNeeded() {
128128
* @my-custom-team
129129
""",
130130
sourceSpecs -> {
131-
sourceSpecs.path(Path.of(ArchetypeCommonFile.CODEOWNERS.getPath()));
131+
sourceSpecs.path(ArchetypeCommonFile.CODEOWNERS.getPath());
132132
}));
133133
}
134134

0 commit comments

Comments
 (0)