Skip to content

Commit

Permalink
Add default sources unless default-jar has a custom classifier
Browse files Browse the repository at this point in the history
(cherry picked from commit 1ee532b)
  • Loading branch information
aloubyansky authored and gsmet committed May 3, 2022
1 parent 3714f30 commit 9e386e1
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 41 deletions.
54 changes: 34 additions & 20 deletions devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -721,12 +721,16 @@ private String getSourceEncoding() {

private void addProject(MavenDevModeLauncher.Builder builder, ResolvedDependency module, boolean root) throws Exception {

if (!ArtifactCoords.TYPE_JAR.equals(module.getType())) {
return;
}

String projectDirectory;
Set<Path> sourcePaths;
String classesPath = null;
Set<Path> resourcePaths;
Set<Path> testSourcePaths;
String testClassesPath;
String testClassesPath = null;
Set<Path> testResourcePaths;
List<Profile> activeProfiles = Collections.emptyList();

Expand All @@ -736,6 +740,10 @@ private void addProject(MavenDevModeLauncher.Builder builder, ResolvedDependency
: null;
final ArtifactSources sources = module.getSources();
if (mavenProject == null) {
if (sources == null) {
getLog().debug("Local dependency " + module.toCompactCoords() + " does not appear to have any sources");
return;
}
projectDirectory = module.getWorkspaceModule().getModuleDir().getAbsolutePath();
sourcePaths = new LinkedHashSet<>();
for (SourceDir src : sources.getSourceDirs()) {
Expand Down Expand Up @@ -766,28 +774,33 @@ private void addProject(MavenDevModeLauncher.Builder builder, ResolvedDependency
}

final Path sourceParent;
if (sources.getSourceDirs() == null) {
if (sources.getResourceDirs() == null) {
throw new MojoExecutionException("The project does not appear to contain any sources or resources");
if (sourcePaths.isEmpty()) {
if (sources == null || sources.getResourceDirs() == null) {
throw new MojoExecutionException(
"Local dependency " + module.toCompactCoords() + " does not appear to have any sources");
}
sourceParent = sources.getResourceDirs().iterator().next().getDir().toAbsolutePath().getParent();
} else {
sourceParent = sources.getSourceDirs().iterator().next().getDir().toAbsolutePath().getParent();
sourceParent = sourcePaths.iterator().next().toAbsolutePath().getParent();
}

Path classesDir = sources.getSourceDirs().iterator().next().getOutputDir().toAbsolutePath();
if (Files.isDirectory(classesDir)) {
classesPath = classesDir.toString();
}
Path testClassesDir = module.getWorkspaceModule().getTestSources().getSourceDirs().iterator().next().getOutputDir()
.toAbsolutePath();
testClassesPath = testClassesDir.toString();

Path classesDir = null;
resourcePaths = new LinkedHashSet<>();
for (SourceDir src : sources.getResourceDirs()) {
for (Path p : src.getSourceTree().getRoots()) {
resourcePaths.add(p.toAbsolutePath());
if (sources != null) {
classesDir = sources.getSourceDirs().iterator().next().getOutputDir().toAbsolutePath();
if (Files.isDirectory(classesDir)) {
classesPath = classesDir.toString();
}
for (SourceDir src : sources.getResourceDirs()) {
for (Path p : src.getSourceTree().getRoots()) {
resourcePaths.add(p.toAbsolutePath());
}
}
}
if (module.getWorkspaceModule().hasTestSources()) {
Path testClassesDir = module.getWorkspaceModule().getTestSources().getSourceDirs().iterator().next().getOutputDir()
.toAbsolutePath();
testClassesPath = testClassesDir.toString();
}

testResourcePaths = new LinkedHashSet<>();
Expand All @@ -807,24 +820,25 @@ private void addProject(MavenDevModeLauncher.Builder builder, ResolvedDependency
resourcePaths.addAll(
build.getResources().stream()
.map(Resource::getDirectory)
.map(Paths::get)
.map(Path::of)
.map(Path::toAbsolutePath)
.collect(Collectors.toList()));
testResourcePaths.addAll(
build.getTestResources().stream()
.map(Resource::getDirectory)
.map(Paths::get)
.map(Path::of)
.map(Path::toAbsolutePath)
.collect(Collectors.toList()));
}
}

if (classesPath == null && (!sourcePaths.isEmpty() || !resourcePaths.isEmpty())) {
throw new MojoExecutionException("Hot reloadable dependency " + module.getWorkspaceModule().getId()
+ " has not been compiled yet (the classes directory " + classesDir + " does not exist)");
+ " has not been compiled yet (the classes directory " + (classesDir == null ? "" : classesDir)
+ " does not exist)");
}

Path targetDir = Paths.get(project.getBuild().getDirectory());
Path targetDir = Path.of(project.getBuild().getDirectory());

DevModeContext.ModuleInfo moduleInfo = new DevModeContext.ModuleInfo.Builder()
.setArtifactKey(module.getKey())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public WorkspaceModule toWorkspaceModule() {
.setBuildDir(getOutputDir());

final Build build = (modelBuildingResult == null ? getRawModel() : modelBuildingResult.getEffectiveModel()).getBuild();
boolean addedNonTestSourceSets = false;
boolean addDefaultSourceSet = true;
if (build != null && !build.getPlugins().isEmpty()) {
for (Plugin plugin : build.getPlugins()) {
if (!plugin.getArtifactId().equals("maven-jar-plugin")) {
Expand All @@ -348,15 +348,15 @@ public WorkspaceModule toWorkspaceModule() {
if (plugin.getExecutions().isEmpty()) {
final DefaultArtifactSources src = processJarPluginExecutionConfig(plugin.getConfiguration(), false);
if (src != null) {
addedNonTestSourceSets = true;
addDefaultSourceSet = false;
moduleBuilder.addArtifactSources(src);
}
} else {
for (PluginExecution e : plugin.getExecutions()) {
DefaultArtifactSources src = null;
if (e.getGoals().contains(ArtifactCoords.TYPE_JAR)) {
src = processJarPluginExecutionConfig(e.getConfiguration(), false);
addedNonTestSourceSets |= src != null;
addDefaultSourceSet &= !e.getId().equals("default-jar");
} else if (e.getGoals().contains("test-jar")) {
src = processJarPluginExecutionConfig(e.getConfiguration(), true);
}
Expand All @@ -365,10 +365,11 @@ public WorkspaceModule toWorkspaceModule() {
}
}
}
break;
}
}

if (!addedNonTestSourceSets) {
if (addDefaultSourceSet) {
moduleBuilder.addArtifactSources(new DefaultArtifactSources(ArtifactSources.MAIN,
Collections.singletonList(new DefaultSourceDir(getSourcesSourcesDir(), getClassesDir())),
collectMainResources(null)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,9 @@
<artifactId>acme-hello</artifactId>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>org.acme</groupId>
<artifactId>acme-beans</artifactId>
</dependency>
<dependency>
<groupId>org.acme</groupId>
<artifactId>acme-beans</artifactId>
<classifier>other</classifier>
<artifactId>acme-intermediary</artifactId>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.acme</groupId>
<artifactId>acme-parent</artifactId>
<version>${revision}.${changelist}${sha1}</version>
</parent>
<artifactId>acme-intermediary</artifactId>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>org.acme</groupId>
<artifactId>acme-beans</artifactId>
</dependency>
<dependency>
<groupId>org.acme</groupId>
<artifactId>acme-beans</artifactId>
<classifier>other</classifier>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>jar-jdk11</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>\${project.build.outputDirectory}/jdk11</classesDirectory>
<classifier>jdk11</classifier>
</configuration>
</execution>
</executions>
<configuration>
<excludes>
<exclude>jdk11/**</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public class Dummy {}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
</properties>
<modules>
<module>beans</module>
<module>intermediary</module>
<module>hello</module>
<module>runner</module>
</modules>
Expand Down Expand Up @@ -88,6 +89,11 @@
<artifactId>acme-runner</artifactId>
<version>\${project.version}</version>
</dependency>
<dependency>
<groupId>org.acme</groupId>
<artifactId>acme-intermediary</artifactId>
<version>\${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
<maven.home>\${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>${quarkus.platform.group-id}</groupId>
<groupId>\${quarkus.platform.group-id}</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.platform.version}</version>
<version>\${quarkus.platform.version}</version>
<executions>
<execution>
<goals>
Expand Down Expand Up @@ -102,12 +102,12 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${skipTests}</skipTests>
<skipTests>\${skipTests}</skipTests>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<version>\${surefire-plugin.version}</version>
<executions>
<execution>
<goals>
Expand All @@ -116,9 +116,9 @@
</goals>
<configuration>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
<native.image.path>\${project.build.directory}/\${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
<maven.home>\${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</execution>
Expand Down

0 comments on commit 9e386e1

Please sign in to comment.