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

Only include bootstrap dependencies in quarkus:dev ClassPath #12156

Merged
merged 1 commit into from
Oct 22, 2020
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
31 changes: 29 additions & 2 deletions devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.jar.Manifest;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;

import org.apache.maven.artifact.Artifact;
Expand Down Expand Up @@ -75,6 +76,7 @@
import org.eclipse.aether.util.artifact.JavaScopes;

import io.quarkus.bootstrap.model.AppArtifactKey;
import io.quarkus.bootstrap.model.AppModel;
import io.quarkus.bootstrap.resolver.maven.options.BootstrapMavenOptions;
import io.quarkus.bootstrap.resolver.maven.workspace.LocalProject;
import io.quarkus.bootstrap.resolver.maven.workspace.LocalWorkspace;
Expand All @@ -93,6 +95,7 @@
*/
@Mojo(name = "dev", defaultPhase = LifecyclePhase.PREPARE_PACKAGE, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
public class DevMojo extends AbstractMojo {
private static final String EXT_PROPERTIES_PATH = "META-INF/quarkus-extension.properties";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's io.quarkus.bootstrap.BootstrapConstants.DESCRIPTOR_PATH, btw.


/**
* running any one of these phases means the compile phase will have been run, if these have
Expand Down Expand Up @@ -717,11 +720,35 @@ void prepare(final boolean triggerCompile) throws Exception {

//in most cases these are not used, however they need to be present for some
//parent-first cases such as logging
//first we go through and get all the parent first artifacts
Set<AppArtifactKey> parentFirstArtifacts = new HashSet<>();
for (Artifact appDep : project.getArtifacts()) {
if (appDep.getArtifactHandler().getExtension().equals("jar") && appDep.getFile().isFile()) {
try (ZipFile file = new ZipFile(appDep.getFile())) {
ZipEntry entry = file.getEntry(EXT_PROPERTIES_PATH);
if (entry != null) {
Properties p = new Properties();
try (InputStream inputStream = file.getInputStream(entry)) {
p.load(inputStream);
String parentFirst = p.getProperty(AppModel.PARENT_FIRST_ARTIFACTS);
if (parentFirst != null) {
String[] artifacts = parentFirst.split(",");
for (String artifact : artifacts) {
parentFirstArtifacts.add(new AppArtifactKey(artifact.split(":")));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is AppArtifactKey.fromString(str) actually.

}
}
}

}
}
}
}
for (Artifact appDep : project.getArtifacts()) {
// only add the artifact if it's present in the dev mode context
// we need this to avoid having jars on the classpath multiple times
if (!devModeContext.getLocalArtifacts().contains(new AppArtifactKey(appDep.getGroupId(), appDep.getArtifactId(),
appDep.getClassifier(), appDep.getArtifactHandler().getExtension()))) {
AppArtifactKey key = new AppArtifactKey(appDep.getGroupId(), appDep.getArtifactId(),
appDep.getClassifier(), appDep.getArtifactHandler().getExtension());
if (!devModeContext.getLocalArtifacts().contains(key) && parentFirstArtifacts.contains(key)) {
addToClassPaths(classPathManifest, appDep.getFile());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected static String[] split(String str, String[] parts, int fromIndex) {
protected final String classifier;
protected final String type;

protected AppArtifactKey(String[] parts) {
public AppArtifactKey(String[] parts) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like this change is necessary. There is already public AppArtifactKey(String groupId, String artifactId, String classifier, String type)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes the code a lot simpler. This is the ctor that is used by the existing code that reads from quarkus-extensions.properties, I would need to copy the logic.

this.groupId = parts[0];
this.artifactId = parts[1];
if (parts.length == 2 || parts[2] == null) {
Expand Down