Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn the PathsCollection back into a class to not break binary backward compatibility #17403

Merged
merged 1 commit into from
May 21, 2021
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
@@ -1,6 +1,7 @@
package io.quarkus.deployment.dev;

import java.io.Closeable;
import java.io.File;
import java.nio.file.Path;
import java.util.Collections;
import java.util.LinkedHashSet;
Expand All @@ -20,6 +21,7 @@
import io.quarkus.bootstrap.resolver.AppModelResolverException;
import io.quarkus.bootstrap.resolver.maven.workspace.LocalProject;
import io.quarkus.bootstrap.resolver.maven.workspace.LocalWorkspace;
import io.quarkus.bootstrap.util.PathsUtils;
import io.quarkus.bootstrap.util.QuarkusModelHelper;
import io.quarkus.bootstrap.utils.BuildToolHelper;

Expand Down Expand Up @@ -97,8 +99,8 @@ private DevModeContext.ModuleInfo toModule(WorkspaceModule module) throws Bootst
module.getArtifactCoords().getArtifactId(), module.getArtifactCoords().getClassifier());

final Set<Path> sourceParents = new LinkedHashSet<>();
for (Path srcDir : module.getSourceSourceSet().getSourceDirectories()) {
sourceParents.add(srcDir.getParent());
for (File srcDir : module.getSourceSourceSet().getSourceDirectories()) {
sourceParents.add(srcDir.getParentFile().toPath());
}
String resourceDirectory = null;
if (!module.getSourceSet().getResourceDirectories().isEmpty()) {
Expand All @@ -109,9 +111,9 @@ private DevModeContext.ModuleInfo toModule(WorkspaceModule module) throws Bootst
.setAppArtifactKey(key)
.setName(module.getArtifactCoords().getArtifactId())
.setProjectDirectory(module.getProjectRoot().getPath())
.setSourcePaths(module.getSourceSourceSet().getSourceDirectories())
.setSourcePaths(PathsUtils.toPathsCollection(module.getSourceSourceSet().getSourceDirectories()))
.setClassesPath(QuarkusModelHelper.getClassPath(module).toAbsolutePath().toString())
.setResourcePaths(module.getSourceSourceSet().getResourceDirectories())
.setResourcePaths(PathsUtils.toPathsCollection(module.getSourceSourceSet().getResourceDirectories()))
.setResourcesOutputPath(resourceDirectory)
.setSourceParents(PathsCollection.from(sourceParents))
.setPreBuildOutputDir(module.getBuildDir().toPath().resolve("generated-sources").toAbsolutePath().toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,87 +12,20 @@
import java.util.Iterator;
import java.util.List;

/**
* A specific collection meant to be used to manipulate {@code Path}s.
*/
public interface PathsCollection extends Iterable<Path> {

/**
* @return {@code true} if the collection is empty, {@code false} otherwise.
*/
boolean isEmpty();

/**
* @return the size of the collection id paths.
*/
int size();

/**
* @return {@code true} if the collection contains one path. {@code false} otherwise.
*/
boolean isSinglePath();

/**
* @return the only path that could be found into the collection.
* @throws IllegalStateException if there is no path or there are more than one paths into the collection.
*/
Path getSinglePath();

/**
* @param path the path to check.
* @return {@code true} if the collection contains the given path, {@code false} otherwise.
*/
boolean contains(Path path);

/**
* Appends the given paths to the collection.
*
* @param paths the paths to append.
* @return a new collection with the appended paths.
*/
PathsCollection add(Path... paths);

/**
* Adds the given paths at the beginning of the collection
*
* @param paths the paths to add.
* @return a new collection with the added paths.
*/
PathsCollection addFirst(Path... paths);

/**
* Adds the given paths at the beginning of the collection
*
* @param paths the paths to add.
* @return a new collection with the added paths.
*/
PathsCollection addAllFirst(Iterable<Path> paths);

/**
* Gives a path of the collection for which a file could found at the given relative location.
*
* @param path the relative location for which we want to find a matching root path.
* @return the root path of the collection that could match with the given location, {@code null} otherwise.
*/
Path resolveExistingOrNull(String path);

/**
* @return the content of the collection as a {@link List}.
*/
Collection<Path> toList();

static PathsCollection from(Iterable<Path> paths) {
public class PathsCollection implements Iterable<Path>, Serializable {

public static PathsCollection from(Iterable<Path> paths) {
final List<Path> list = new ArrayList<>();
paths.forEach(list::add);
return new Default(list);
return new PathsCollection(list);
}

static PathsCollection of(Path... paths) {
return new Default(Arrays.asList(paths));
public static PathsCollection of(Path... paths) {
return new PathsCollection(Arrays.asList(paths));
}

class Builder {
private final List<Path> paths = new ArrayList<>();
public static class Builder {
private List<Path> paths = new ArrayList<>();

private Builder() {
}
Expand All @@ -107,117 +40,108 @@ public boolean contains(Path p) {
}

public PathsCollection build() {
return new Default(paths);
return new PathsCollection(paths);
}
}

static Builder builder() {
public static Builder builder() {
return new Builder();
}

class Default implements PathsCollection, Serializable {
private List<Path> paths;
private List<Path> paths;

private Default(List<Path> paths) {
this.paths = Collections.unmodifiableList(paths);
}
private PathsCollection(List<Path> paths) {
this.paths = Collections.unmodifiableList(paths);
}

@Override
public boolean isEmpty() {
return paths.isEmpty();
}
public boolean isEmpty() {
return paths.isEmpty();
}

@Override
public int size() {
return paths.size();
}
public int size() {
return paths.size();
}

@Override
public boolean isSinglePath() {
return paths.size() == 1;
}
public boolean isSinglePath() {
return paths.size() == 1;
}

@Override
public Path getSinglePath() {
if (paths.size() != 1) {
throw new IllegalStateException(
"Paths collection expected to contain a single path but contains " + paths.size());
}
return paths.get(0);
public Path getSinglePath() {
if (paths.size() != 1) {
throw new IllegalStateException("Paths collection expected to contain a single path but contains " + paths.size());
}
return paths.get(0);
}

@Override
public Iterator<Path> iterator() {
return paths.iterator();
}
@Override
public Iterator<Path> iterator() {
return paths.iterator();
}

@Override
public boolean contains(Path path) {
return paths.contains(path);
}
public boolean contains(Path path) {
return paths.contains(path);
}

@Override
public PathsCollection add(Path... paths) {
final List<Path> list = new ArrayList<>(this.paths.size() + paths.length);
list.addAll(this.paths);
list.addAll(Arrays.asList(paths));
return new Default(list);
public PathsCollection add(Path... paths) {
final List<Path> list = new ArrayList<>(this.paths.size() + paths.length);
list.addAll(this.paths);
for (int i = 0; i < paths.length; ++i) {
list.add(paths[i]);
}
return new PathsCollection(list);
}

@Override
public PathsCollection addFirst(Path... paths) {
final List<Path> list = new ArrayList<>(this.paths.size() + paths.length);
list.addAll(Arrays.asList(paths));
list.addAll(this.paths);
return new Default(list);
public PathsCollection addFirst(Path... paths) {
final List<Path> list = new ArrayList<>(this.paths.size() + paths.length);
for (int i = 0; i < paths.length; ++i) {
list.add(paths[i]);
}
list.addAll(this.paths);
return new PathsCollection(list);
}

@Override
public PathsCollection addAllFirst(Iterable<Path> i) {
final List<Path> list = new ArrayList<>();
i.forEach(list::add);
list.addAll(paths);
return new Default(list);
}
public PathsCollection addAllFirst(Iterable<Path> i) {
final List<Path> list = new ArrayList<>();
i.forEach(list::add);
paths.forEach(list::add);
return new PathsCollection(list);
}

@Override
public Path resolveExistingOrNull(String path) {
for (Path p : paths) {
final Path resolved = p.resolve(path);
if (Files.exists(resolved)) {
return resolved;
}
public Path resolveExistingOrNull(String path) {
for (Path p : paths) {
final Path resolved = p.resolve(path);
if (Files.exists(resolved)) {
return resolved;
}
return null;
}
return null;
}

@Override
public Collection<Path> toList() {
return new ArrayList<>(paths);
}
@Override
public String toString() {
final StringBuilder buf = new StringBuilder();
buf.append("[paths: ");
forEach(p -> buf.append(p).append(';'));
return buf.append(']').toString();
}

@Override
public String toString() {
final StringBuilder buf = new StringBuilder();
buf.append("[paths: ");
forEach(p -> buf.append(p).append(';'));
return buf.append(']').toString();
private void writeObject(java.io.ObjectOutputStream out) throws IOException {
out.writeInt(paths.size());
for (Path p : paths) {
out.writeUTF(p.toAbsolutePath().toString());
}
}

private void writeObject(java.io.ObjectOutputStream out) throws IOException {
out.writeInt(paths.size());
for (Path p : paths) {
out.writeUTF(p.toAbsolutePath().toString());
}
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
final int pathsTotal = in.readInt();
List<Path> paths = new ArrayList<>(pathsTotal);
for (int i = 0; i < pathsTotal; ++i) {
paths.add(Paths.get(in.readUTF()));
}
this.paths = Collections.unmodifiableList(paths);
}

private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
final int pathsTotal = in.readInt();
List<Path> paths = new ArrayList<>(pathsTotal);
for (int i = 0; i < pathsTotal; ++i) {
paths.add(Paths.get(in.readUTF()));
}
this.paths = Collections.unmodifiableList(paths);
}
public Collection<Path> toList() {
return new ArrayList<>(paths);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package io.quarkus.bootstrap.model.gradle;

import io.quarkus.bootstrap.model.PathsCollection;
import java.io.File;
import java.util.Set;

public interface SourceSet {

PathsCollection getSourceDirectories();
Set<File> getSourceDirectories();

PathsCollection getResourceDirectories();
Set<File> getResourceDirectories();
}
Loading