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

-DnoDeps property to exclude the local project dependencies from dev-mode #2587

Merged
merged 1 commit into from May 24, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
98 changes: 56 additions & 42 deletions devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
Expand Up @@ -58,7 +58,6 @@
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;

import io.quarkus.bootstrap.model.AppArtifact;
import io.quarkus.bootstrap.model.AppDependency;
import io.quarkus.bootstrap.model.AppModel;
import io.quarkus.bootstrap.resolver.BootstrapAppModelResolver;
Expand Down Expand Up @@ -151,6 +150,13 @@ public class DevMojo extends AbstractMojo {
@Parameter(defaultValue = "${preventnoverify}")
private boolean preventnoverify = false;

/**
* Whether changes in the projects that appear to be dependencies of the project containing the application to be launched
* should trigger hot-reload. By default they do.
*/
@Parameter(defaultValue = "${noDeps}")
private boolean noDeps = false;

@Component
private ToolchainManager toolchainManager;

Expand All @@ -175,7 +181,7 @@ public void execute() throws MojoFailureException, MojoExecutionException {
}

if (!sourceDir.isDirectory()) {
getLog().warn("The `src/main/java` directory does not exist");
getLog().warn("The project's sources directory does not exist " + sourceDir);
}

if (!buildDir.isDirectory() || !new File(buildDir, "classes").isDirectory()) {
Expand Down Expand Up @@ -235,48 +241,16 @@ public void execute() throws MojoFailureException, MojoExecutionException {
}

final AppModel appModel;
Map<String, MavenProject> projectMap = session.getProjectMap();
try {
final LocalProject localProject = LocalProject.loadWorkspace(outputDirectory.toPath());
for (LocalProject project : localProject.getSelfWithLocalDeps()) {
AppArtifact appArtifact = project.getAppArtifact();
MavenProject mavenProject = projectMap.get(String.format("%s:%s:%s",
appArtifact.getGroupId(), appArtifact.getArtifactId(), appArtifact.getVersion()));
// no information about this project from Maven. Skip.

String projectDirectory = null;
List<String> sourcePaths = null;
String classesPath = null;
String resourcePath = null;

if (mavenProject == null) {
projectDirectory = localProject.getDir().toAbsolutePath().toString();
sourcePaths = Collections.singletonList(
localProject.getSourcesSourcesDir().toAbsolutePath().toString());
} else {
projectDirectory = mavenProject.getBasedir().getPath();
sourcePaths = mavenProject.getCompileSourceRoots().stream()
.map(Paths::get)
.filter(Files::isDirectory)
.map(src -> src.toAbsolutePath().toString())
.collect(Collectors.toList());
}

Path classesDir = project.getClassesDir();
if (Files.isDirectory(classesDir)) {
classesPath = classesDir.toAbsolutePath().toString();
}
Path resourcesSourcesDir = project.getResourcesSourcesDir();
if (Files.isDirectory(resourcesSourcesDir)) {
resourcePath = resourcesSourcesDir.toAbsolutePath().toString();
final LocalProject localProject;
if (noDeps) {
localProject = LocalProject.load(outputDirectory.toPath());
addProject(devModeContext, localProject);
} else {
localProject = LocalProject.loadWorkspace(outputDirectory.toPath());
for (LocalProject project : localProject.getSelfWithLocalDeps()) {
addProject(devModeContext, project);
}
DevModeContext.ModuleInfo moduleInfo = new DevModeContext.ModuleInfo(
project.getArtifactId(),
projectDirectory,
sourcePaths,
classesPath,
resourcePath);
devModeContext.getModules().add(moduleInfo);
}

/*
Expand Down Expand Up @@ -395,6 +369,46 @@ public void run() {
}
}

private void addProject(DevModeContext devModeContext, LocalProject localProject) {

String projectDirectory = null;
List<String> sourcePaths = null;
String classesPath = null;
String resourcePath = null;

final MavenProject mavenProject = session.getProjectMap().get(
String.format("%s:%s:%s", localProject.getGroupId(), localProject.getArtifactId(), localProject.getVersion()));

if (mavenProject == null) {
projectDirectory = localProject.getDir().toAbsolutePath().toString();
sourcePaths = Collections.singletonList(
localProject.getSourcesSourcesDir().toAbsolutePath().toString());
} else {
projectDirectory = mavenProject.getBasedir().getPath();
sourcePaths = mavenProject.getCompileSourceRoots().stream()
.map(Paths::get)
.filter(Files::isDirectory)
.map(src -> src.toAbsolutePath().toString())
.collect(Collectors.toList());
}

Path classesDir = localProject.getClassesDir();
if (Files.isDirectory(classesDir)) {
classesPath = classesDir.toAbsolutePath().toString();
}
Path resourcesSourcesDir = localProject.getResourcesSourcesDir();
if (Files.isDirectory(resourcesSourcesDir)) {
resourcePath = resourcesSourcesDir.toAbsolutePath().toString();
}
DevModeContext.ModuleInfo moduleInfo = new DevModeContext.ModuleInfo(
localProject.getArtifactId(),
projectDirectory,
sourcePaths,
classesPath,
resourcePath);
devModeContext.getModules().add(moduleInfo);
}

private void addToClassPaths(StringBuilder classPathManifest, DevModeContext classPath, File file) {
URI uri = file.toPath().toAbsolutePath().toUri();
try {
Expand Down
42 changes: 39 additions & 3 deletions devtools/maven/src/test/java/io/quarkus/maven/it/DevMojoIT.java
Expand Up @@ -7,8 +7,10 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -83,7 +85,7 @@ public void testThatTheApplicationIsReloadedOnJavaChange() throws MavenInvocatio

@Test
public void testThatTheApplicationIsReloadedMultiModule() throws MavenInvocationException, IOException {
testDir = initProject("projects/multimodule", "projects/multimodule");
testDir = initProject("projects/multimodule", "projects/multimodule-with-deps");
runAndCheck();

// Edit the "Hello" message.
Expand Down Expand Up @@ -133,6 +135,32 @@ public void testThatTheApplicationIsReloadedMultiModule() throws MavenInvocation
.until(() -> getHttpResponse("/lorem.txt", 404));
}

@Test
public void testMultiModuleDevModeWithLocalDepsDisabled() throws MavenInvocationException, IOException {
testDir = initProject("projects/multimodule", "projects/multimodule-nodeps");
runAndCheck("-DnoDeps");

String greeting = getHttpResponse("/app/hello/greeting");
assertThat(greeting).containsIgnoringCase("bonjour");

// Edit the "Hello" message.
File source = new File(testDir, "rest/src/main/java/org/acme/HelloResource.java");
filter(source, ImmutableMap.of("return \"hello\";", "return \"" + UUID.randomUUID().toString() + "\";"));

// Edit the greeting property.
source = new File(testDir, "runner/src/main/resources/application.properties");
final String uuid = UUID.randomUUID().toString();
filter(source, ImmutableMap.of("greeting=bonjour", "greeting=" + uuid + ""));

// Wait until we get "uuid"
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(1, TimeUnit.MINUTES).until(() -> getHttpResponse("/app/hello/greeting").contains(uuid));

greeting = getHttpResponse("/app/hello");
assertThat(greeting).containsIgnoringCase("hello");
}

@Test
public void testThatTheApplicationIsReloadedOnKotlinChange() throws MavenInvocationException, IOException {
testDir = initProject("projects/classic-kotlin", "projects/project-classic-run-kotlin-change");
Expand Down Expand Up @@ -191,10 +219,18 @@ public void testThatTheApplicationIsReloadedOnNewResource() throws MavenInvocati
.atMost(1, TimeUnit.MINUTES).until(() -> getHttpResponse("/app/foo").contains("bar"));
}

private void runAndCheck() throws FileNotFoundException, MavenInvocationException {
private void runAndCheck(String... options) throws FileNotFoundException, MavenInvocationException {
assertThat(testDir).isDirectory();
running = new RunningInvoker(testDir, false);
running.execute(Arrays.asList("compile", "quarkus:dev"), Collections.emptyMap());
final List<String> args = new ArrayList<>(2 + options.length);
args.add("compile");
args.add("quarkus:dev");
if (options.length > 0) {
for (String s : options) {
args.add(s);
}
}
running.execute(args, Collections.emptyMap());

String resp = getHttpResponse();

Expand Down