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

fix: index optional dependencies (#172) (CP: 2.0) #173

Merged
merged 2 commits into from
Sep 12, 2024
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
Expand Up @@ -20,6 +20,9 @@
import java.util.Collection;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -29,18 +32,23 @@
import io.quarkus.arc.deployment.ContextRegistrationPhaseBuildItem;
import io.quarkus.arc.deployment.ContextRegistrationPhaseBuildItem.ContextConfiguratorBuildItem;
import io.quarkus.arc.deployment.CustomScopeBuildItem;
import io.quarkus.arc.deployment.IgnoreSplitPackageBuildItem;
import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.IndexDependencyBuildItem;
import io.quarkus.deployment.builditem.RemovedResourceBuildItem;
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
import io.quarkus.maven.dependency.ArtifactKey;
import io.quarkus.undertow.deployment.ServletBuildItem;
import io.quarkus.undertow.deployment.ServletDeploymentManagerBuildItem;
import io.quarkus.vertx.http.deployment.FilterBuildItem;
import io.quarkus.websockets.client.deployment.ServerWebSocketContainerBuildItem;
import io.quarkus.websockets.client.deployment.WebSocketDeploymentInfoBuildItem;
import org.atmosphere.cpr.ApplicationConfig;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
Expand Down Expand Up @@ -83,6 +91,66 @@ FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@BuildStep
void indexOptionalVaadinDependencies(
BuildProducer<IndexDependencyBuildItem> producer) {
// Optional dependencies
producer.produce(
new IndexDependencyBuildItem("com.vaadin", "flow-react"));
producer.produce(new IndexDependencyBuildItem("com.vaadin",
"flow-polymer-template"));

// Development dependencies
producer.produce(new IndexDependencyBuildItem("com.vaadin",
"vaadin-dev-server"));
producer.produce(new IndexDependencyBuildItem("com.vaadin", "copilot"));
producer.produce(
new IndexDependencyBuildItem("com.vaadin", "ui-tests"));
}

/*
* Removes vaadin-core-jandex artifact, if vaadin-jandex is also present
*/
@BuildStep
void removeUnusedJandexIndex(CurateOutcomeBuildItem curateOutcome,
BuildProducer<RemovedResourceBuildItem> removedResourceProducer,
BuildProducer<IgnoreSplitPackageBuildItem> ignoreSplitPackage) {
Predicate<String> isVaadinJandex = Pattern
.compile("vaadin(-core)?-jandex").asMatchPredicate();
ApplicationModel applicationModel = curateOutcome.getApplicationModel();
Set<String> vaadinIndexes = applicationModel.getDependencies().stream()
.filter(archive -> "com.vaadin"
.equals(archive.getKey().getGroupId())
&& isVaadinJandex
.test(archive.getKey().getArtifactId()))
.map(archive -> archive.getKey().toGacString())
.collect(Collectors.toSet());
if (vaadinIndexes.size() > 1) {
ArtifactKey artifactKey = ArtifactKey.of("com.vaadin",
"vaadin-core-jandex", null, "jar");
// To prevent the vaadin-core-index to be indexed, it should add to
// the removed resources, but producing a RemovedResourceBuildItem
// does not prevent the split package processor to log all classes
// present in both vaadin-jandex and vaadin-core-jandex The
// removedResources map in ApplicationModel is computed before the
// SplitPackageProcessor and it is mutable, but the javadocs don't
// specify if updating it is allowed or not. To prevent issues in
// the future, try to put the artifact in the collection, but
// fallback to producing a RemovedResourceBuildItem and a
// IgnoreSplitPackageBuildItem to prevent the verbose and useless
// log.
try {
applicationModel.getRemovedResources().put(artifactKey,
Set.of());
} catch (Exception ex) {
removedResourceProducer.produce(
new RemovedResourceBuildItem(artifactKey, Set.of()));
ignoreSplitPackage.produce(new IgnoreSplitPackageBuildItem(
Set.of("com.vaadin.*")));
}
}
}

@BuildStep
public void build(
final BuildProducer<AdditionalBeanBuildItem> additionalBeanProducer,
Expand Down Expand Up @@ -145,8 +213,7 @@ void mapVaadinServletPaths(final BeanArchiveIndexBuildItem beanArchiveIndex,
.builder(QuarkusVaadinServlet.class.getName(),
QuarkusVaadinServlet.class.getName())
.addMapping("/*").setAsyncSupported(true)
.setLoadOnStartup(1)
.build());
.setLoadOnStartup(1).build());
}
}

Expand Down
8 changes: 8 additions & 0 deletions integration-tests/development/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
<groupId>com.vaadin</groupId>
<artifactId>flow-html-components</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-dnd</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-react</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-dev-server</artifactId>
Expand Down
14 changes: 14 additions & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@
<version>31.0.1-jre</version>
<scope>test</scope>
</dependency>

<!-- Pin JNA version to prevent clashes between Vaadin License Checker and Quarkus BOM -->
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.14.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>5.14.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
8 changes: 8 additions & 0 deletions integration-tests/production/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
<groupId>com.vaadin</groupId>
<artifactId>flow-html-components</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-dnd</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-react</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>reusable-theme</artifactId>
Expand Down
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<maven.compiler.parameters>true</maven.compiler.parameters>

<vaadin.flow.version>24.4-SNAPSHOT</vaadin.flow.version>
<quarkus.version>3.0.1.Final</quarkus.version>
<quarkus.version>3.2.12.Final</quarkus.version>
<open.telemetry.alpha.version>1.16.0-alpha</open.telemetry.alpha.version>
<open.telemetry.version>1.16.0</open.telemetry.version>

Expand Down Expand Up @@ -102,16 +102,16 @@
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>${quarkus.version}</version>
<groupId>com.vaadin</groupId>
<artifactId>flow-bom</artifactId>
<version>${vaadin.flow.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-bom</artifactId>
<version>${vaadin.flow.version}</version>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>${quarkus.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down