Skip to content

Commit

Permalink
SDK-295: Multiple invocations of watch for the same project and serve…
Browse files Browse the repository at this point in the history
…r add multiple records (#250)

This prevents users from adding the same module twice if they are located in different directories.
  • Loading branch information
wikumChamith authored Sep 5, 2023
1 parent 9b0f0c9 commit 2bd50eb
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;

Expand Down Expand Up @@ -313,15 +314,17 @@ private void replaceDbNameInDbUri() {
setParam(Server.PROPERTY_DB_URI, dbUri);
}
}
public void addWatchedProject(Project project) {
linkProject(project);

public void addWatchedProject(Project project) throws MojoExecutionException {
Set<Project> watchedProjects = getWatchedProjects();
Optional<Project> existingSameModule = watchedProjects.stream().filter(existingProject -> existingProject.getArtifactId().equals(project.getArtifactId())).findFirst();
if (existingSameModule.isPresent()) {
throw new MojoExecutionException("Module " + project.getArtifactId() + " already being watched in a different location: " + existingSameModule.get().getPath());
}
linkProject(project);
if (watchedProjects.add(project)) {
setWatchedProjects(watchedProjects);
}
}

private boolean linkProject(Project project) {
File link = getWatchedProjectLink(project);
Path linkPath = Paths.get(link.getAbsolutePath());
Expand Down

0 comments on commit 2bd50eb

Please sign in to comment.