Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public enum ArchetypeCommonFile {
*/
public static ArchetypeCommonFile fromFile(String file) {
for (ArchetypeCommonFile f : ArchetypeCommonFile.values()) {
if (Path.of(f.getPath()).equals(Path.of(file))) {
if (f.getPath().equals(Path.of(file))) {
return f;
}
}
Expand All @@ -121,7 +121,7 @@ public static ArchetypeCommonFile fromFile(String file) {
* Get the path
* @return the path
*/
public String getPath() {
return path;
public Path getPath() {
return Path.of(path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
import io.jenkins.tools.pluginmodernizer.core.model.JDK;
import io.jenkins.tools.pluginmodernizer.core.model.Plugin;
import io.jenkins.tools.pluginmodernizer.core.model.PreconditionError;
import java.io.Serial;
import java.io.Serializable;
import java.nio.file.Path;
import java.util.*;
import org.openrewrite.marker.Marker;

/**
* Metadata of a plugin extracted from its POM file or code
*/
public class PluginMetadata extends CacheEntry<PluginMetadata> implements Serializable, Marker {
public class PluginMetadata extends CacheEntry<PluginMetadata> implements Serializable {

@Serial
private static final long serialVersionUID = 1L;

private transient UUID id;

/**
* Name of the plugin
*/
Expand Down Expand Up @@ -189,7 +188,7 @@ public void setJdks(Set<JDK> jdkVersions) {
* @param path The path
* @return The file or null
*/
public ArchetypeCommonFile getFile(String path) {
public ArchetypeCommonFile getFile(Path path) {
return commonFiles.stream()
.filter(f -> f.getPath().equals(path))
.findFirst()
Expand All @@ -201,7 +200,7 @@ public ArchetypeCommonFile getFile(String path) {
* @param path The path
* @return True if the file is present
*/
public boolean hasFile(String path) {
public boolean hasFile(Path path) {
return commonFiles.stream().anyMatch(f -> f.getPath().equals(path));
}

Expand Down Expand Up @@ -260,15 +259,4 @@ public void addProperty(String key, String value) {
}
properties.put(key, value);
}

@Override
public UUID getId() {
return id;
}

@Override
public PluginMetadata withId(UUID id) {
this.id = id;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.jenkins.tools.pluginmodernizer.core.extractor.ArchetypeCommonFile;
import io.jenkins.tools.pluginmodernizer.core.extractor.ArchetypeCommonFileVisitor;
import io.jenkins.tools.pluginmodernizer.core.extractor.PluginMetadata;
import java.nio.file.Path;
import org.openrewrite.*;
import org.openrewrite.marker.SearchResult;

Expand Down Expand Up @@ -44,7 +43,7 @@ public Tree visit(Tree tree, ExecutionContext ctx) {
PluginMetadata pluginMetadata = new ArchetypeCommonFileVisitor().reduce(tree, new PluginMetadata());
if (pluginMetadata.hasCommonFile(archetypeCommonFile)) {
SourceFile sourceFile = (SourceFile) tree;
if (sourceFile.getSourcePath().equals(Path.of(archetypeCommonFile.getPath()))) {
if (sourceFile.getSourcePath().equals(archetypeCommonFile.getPath())) {
return SearchResult.found(tree, "Project is using " + archetypeCommonFile.getPath());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.jenkins.tools.pluginmodernizer.core.extractor.ArchetypeCommonFile;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -65,11 +63,11 @@ public TreeVisitor<?, ExecutionContext> getScanner(AtomicBoolean shouldCreate) {
@Override
public Tree visit(Tree tree, ExecutionContext ctx) {
SourceFile sourceFile = (SourceFile) tree;
if (sourceFile.getSourcePath().equals(Path.of(ArchetypeCommonFile.RENOVATE.getPath()))) {
if (sourceFile.getSourcePath().equals(ArchetypeCommonFile.RENOVATE.getPath())) {
LOG.info("Project is using Renovate. Doing nothing.");
shouldCreate.set(false);
}
if (sourceFile.getSourcePath().equals(Path.of(ArchetypeCommonFile.DEPENDABOT.getPath()))) {
if (sourceFile.getSourcePath().equals(ArchetypeCommonFile.DEPENDABOT.getPath())) {
LOG.info("Project is using Dependabot already. Doing nothing.");
shouldCreate.set(false);
}
Expand All @@ -84,8 +82,8 @@ public Collection<SourceFile> generate(AtomicBoolean shouldCreate, ExecutionCont
return YamlParser.builder()
.build()
.parse(DEPENDABOT_FILE)
.map(brandNewFile -> (SourceFile)
brandNewFile.withSourcePath(Paths.get(ArchetypeCommonFile.DEPENDABOT.getPath())))
.map(brandNewFile ->
(SourceFile) brandNewFile.withSourcePath(ArchetypeCommonFile.DEPENDABOT.getPath()))
.collect(Collectors.toList());
}
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void shouldAddCodeOwnerIfNeeded() {
* @my-custom-team
""",
sourceSpecs -> {
sourceSpecs.path(Path.of(ArchetypeCommonFile.CODEOWNERS.getPath()));
sourceSpecs.path(ArchetypeCommonFile.CODEOWNERS.getPath());
}));
}

Expand Down