Skip to content

Commit

Permalink
Merge branch 'main' into issues/19616-maven-plugin-classloading-attem…
Browse files Browse the repository at this point in the history
…pt-3
  • Loading branch information
mcollovati authored Nov 18, 2024
2 parents 2fc8455 + 2977de2 commit 684a080
Show file tree
Hide file tree
Showing 31 changed files with 268 additions and 122 deletions.
6 changes: 3 additions & 3 deletions eclipse/VaadinJavaConventions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/>
<setting id="org.eclipse.jdt.core.compiler.source" value="1.5"/>
<setting id="org.eclipse.jdt.core.compiler.source" value="17"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/>
Expand Down Expand Up @@ -167,7 +167,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.5"/>
<setting id="org.eclipse.jdt.core.compiler.compliance" value="17"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/>
Expand Down Expand Up @@ -242,7 +242,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.5"/>
<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="17"/>
<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public void send(final JsonObject payload) {
pushPendingMessage = payload;
push.push(payload);
} else {
Console.log("send XHR");
Console.debug("send XHR");
registry.getXhrConnection().send(payload);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,31 @@ default Validator<V> getDefaultValidator() {
* public class DatePickerDemo implements HasValidator&lt;LocalDate&gt; {
*
* // Each web component has a way to communicate its validation status
* // to its server-side component instance. The following clientSideValid
* // state is introduced here just for the sake of simplicity of this code
* // snippet:
* // to its server-side component instance. The following
* // clientSideValid state is introduced here just for the sake of
* // simplicity of this code snippet:
* boolean clientSideValid = true;
*
* /**
* * Note how <code>clientSideValid</code> engaged in the definition
* * of this method. It is important to reflect this status either
* * in the returning validation result of this method or any other
* * validation that is associated with this component.
* *&#47;
* * Note how <code>clientSideValid</code> engaged in the definition of
* * this method. It is important to reflect this status either in the
* * returning validation result of this method or any other validation
* * that is associated with this component.
* *&#47;
* &#64;Override
* public Validator getDefaultValidator() {
* return (value, valueContext) -&gt; clientSideValid ? ValidationResult.ok()
* return (value, valueContext) -&gt; clientSideValid
* ? ValidationResult.ok()
* : ValidationResult.error("Invalid date format");
* }
*
* private final Collection&lt;ValidationStatusChangeListener&lt;LocalDate&gt;&gt;
* validationStatusListeners = new ArrayList&lt;&gt;();
* private final Collection&lt;ValidationStatusChangeListener&lt;LocalDate&gt;&gt; validationStatusListeners = new ArrayList&lt;&gt;();
*
* /**
* * This enables the binding to subscribe for the validation status
* * change events that are fired by this component and revalidate
* * itself respectively.
* *&#47;
* *&#47;
* &#64;Override
* public Registration addValidationStatusChangeListener(
* ValidationStatusChangeListener&lt;LocalDate&gt; listener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1314,14 +1314,18 @@ public void fetchFromProvider_disablePaging_singleQueryWithLimit() {

@Test
public void fetchFromProvider_maxLimitValue_pagesCalculatedProperly() {
AbstractDataProvider<Item,Object>dataProvider=createDataProvider(42);dataProvider=Mockito.spy(dataProvider);
AbstractDataProvider<Item, Object> dataProvider = createDataProvider(
42);
dataProvider = Mockito.spy(dataProvider);

dataCommunicator.setDataProvider(dataProvider,null);dataCommunicator.setPageSize(2_000_000_000);
dataCommunicator.setDataProvider(dataProvider, null);
dataCommunicator.setPageSize(2_000_000_000);
// We check the page number calculation does not lead to integer
// overflow, and not throw thus
dataCommunicator.fetchFromProvider(0,Integer.MAX_VALUE);
dataCommunicator.fetchFromProvider(0, Integer.MAX_VALUE);

Mockito.verify(dataProvider,Mockito.times(1)).fetch(Mockito.any(Query.class));
Mockito.verify(dataProvider, Mockito.times(1))
.fetch(Mockito.any(Query.class));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public void testInvalidDecimalsFailsInFrench() {

@Test
public void testAddressNestedPropertyInvalidPostalCodeFails() {
assertFails(100_000,"must be less than or equal to 99999",validator("address.postalCode"));
assertFails(100_000, "must be less than or equal to 99999",
validator("address.postalCode"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,12 @@ public void testNullLessThanEverything() {

@Test
public void testDateRange() {
RangeValidator<LocalDate>v=RangeValidator.of("Date must be in 2016",LocalDate.of(2016,1,1),LocalDate.of(2016,12,31));
RangeValidator<LocalDate> v = RangeValidator.of("Date must be in 2016",
LocalDate.of(2016, 1, 1), LocalDate.of(2016, 12, 31));

assertFails(LocalDate.ofEpochDay(0),v);assertPasses(LocalDate.of(2016,7,31),v);assertFails(LocalDate.ofEpochDay(1_000_000_000),v);
assertFails(LocalDate.ofEpochDay(0), v);
assertPasses(LocalDate.of(2016, 7, 31), v);
assertFails(LocalDate.ofEpochDay(1_000_000_000), v);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ public class FeatureFlags implements Serializable {
"collaborationEngineBackend",
"https://github.com/vaadin/platform/issues/1988", true, null);

public static final Feature WEB_PUSH = new Feature(
"Server side WebPush API", "webPush",
"https://vaadin.com/docs/latest/configuration/setting-up-webpush",
true, "com.vaadin.flow.server.webpush.WebPush");

public static final Feature FORM_FILLER_ADDON = new Feature(
"Form Filler Add-on", "formFillerAddon",
"https://github.com/vaadin/form-filler-addon", true,
Expand Down Expand Up @@ -112,7 +107,6 @@ public FeatureFlags(Lookup lookup) {
this.lookup = lookup;
features.add(new Feature(EXAMPLE));
features.add(new Feature(COLLABORATION_ENGINE_BACKEND));
features.add(new Feature(WEB_PUSH));
features.add(new Feature(FORM_FILLER_ADDON));
features.add(new Feature(HILLA_I18N));
features.add(new Feature(HILLA_FULLSTACK_SIGNALS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.File;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -47,6 +48,10 @@ public class ComponentTracker {
.synchronizedMap(new WeakHashMap<>());
private static Map<Component, Location> attachLocation = Collections
.synchronizedMap(new WeakHashMap<>());
private static Map<Component, Location[]> createLocations = Collections
.synchronizedMap(new WeakHashMap<>());
private static Map<Component, Location[]> attachLocations = Collections
.synchronizedMap(new WeakHashMap<>());

private static Boolean disabled = null;
private static String[] prefixesToSkip = new String[] {
Expand Down Expand Up @@ -190,6 +195,18 @@ public static Location findCreate(Component component) {
return createLocation.get(component);
}

/**
* Finds the locations related to where the given component instance was
* created.
*
* @param component
* the component to find
* @return the locations involved in creating the component
*/
public static Location[] findCreateLocations(Component component) {
return createLocations.get(component);
}

/**
* Tracks the location where the component was created. This should be
* called from the Component constructor so that the creation location can
Expand All @@ -203,12 +220,14 @@ public static void trackCreate(Component component) {
return;
}
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
Location location = findRelevantLocation(component.getClass(), stack,
null);
Location[] relevantLocations = findRelevantLocations(stack);
Location location = findRelevantLocation(component.getClass(),
relevantLocations, null);
if (isNavigatorCreate(location)) {
location = findRelevantLocation(null, stack, null);
location = findRelevantLocation(null, relevantLocations, null);
}
createLocation.put(component, location);
createLocations.put(component, relevantLocations);
}

/**
Expand All @@ -223,6 +242,18 @@ public static Location findAttach(Component component) {
return attachLocation.get(component);
}

/**
* Finds the locations related to where the given component instance was
* attached to a parent.
*
* @param component
* the component to find
* @return the locations involved in creating the component
*/
public static Location[] findAttachLocations(Component component) {
return attachLocations.get(component);
}

/**
* Tracks the location where the component was attached. This should be
* called from the Component attach logic so that the creation location can
Expand All @@ -239,14 +270,16 @@ public static void trackAttach(Component component) {

// In most cases the interesting attach call is found in the same class
// where the component was created and not in a generic layout class
Location location = findRelevantLocation(component.getClass(), stack,
findCreate(component));
Location[] relevantLocations = findRelevantLocations(stack);
Location location = findRelevantLocation(component.getClass(),
relevantLocations, findCreate(component));
if (isNavigatorCreate(location)) {
// For routes, we can just show the init location as we have nothing
// better
location = createLocation.get(component);
}
attachLocation.put(component, location);
attachLocations.put(component, relevantLocations);
}

/**
Expand Down Expand Up @@ -283,30 +316,41 @@ private static boolean isNavigatorCreate(Location location) {
.equals(AbstractNavigationStateRenderer.class.getName());
}

private static Location[] findRelevantLocations(StackTraceElement[] stack) {
return Stream.of(stack).filter(e -> {
for (String prefixToSkip : prefixesToSkip) {
if (e.getClassName().startsWith(prefixToSkip)) {
return false;
}
}
return true;
}).map(ComponentTracker::toLocation).toArray(Location[]::new);
}

private static Location findRelevantLocation(
Class<? extends Component> excludeClass, StackTraceElement[] stack,
Class<? extends Component> excludeClass, Location[] locations,
Location preferredClass) {
List<StackTraceElement> candidates = Stream.of(stack)
.filter(e -> excludeClass == null
|| !e.getClassName().equals(excludeClass.getName()))
.filter(e -> {
List<Location> candidates = Arrays.stream(locations)
.filter(location -> excludeClass == null
|| !location.className().equals(excludeClass.getName()))
.filter(location -> {
for (String prefixToSkip : prefixesToSkip) {
if (e.getClassName().startsWith(prefixToSkip)) {
if (location.className().startsWith(prefixToSkip)) {
return false;
}
}
return true;
}).collect(Collectors.toList());
if (preferredClass != null) {
Optional<StackTraceElement> preferredCandidate = candidates.stream()
.filter(e -> e.getClassName()
Optional<Location> preferredCandidate = candidates.stream()
.filter(location -> location.className()
.equals(preferredClass.className()))
.findFirst();
if (preferredCandidate.isPresent()) {
return toLocation(preferredCandidate.get());
return preferredCandidate.get();
}
}
return toLocation(candidates.stream().findFirst().orElse(null));
return candidates.isEmpty() ? null : candidates.get(0);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
* <p>
* Only for read as data is immutable.
*/
public record MenuData(String title, Double order, boolean exclude, String icon, Class<? extends Component> menuClass) implements Serializable {
public record MenuData(String title, Double order, boolean exclude, String icon,
Class<? extends Component> menuClass) implements Serializable {

/**
* MenuData constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private static VaadinRequest createVaadinRequest(
* the enforcement messages or null if enforcement should not be
* applied
* @param origin
* the exception that caused the enforcement
* the exception that caused the enforcement
* @param endRequestAction
* the action to be run at the end of the request
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,32 @@
/**
* Represents a view configuration for use with a menu.
*
* @param title title of view
* @param rolesAllowed logged in roles allowed for view
* @param loginRequired requires login
* @param route path string
* @param lazy lazy loaded
* @param register register view
* @param menu menu item information
* @param children view children
* @param routeParameters view parameters
* @param flowLayout if server layout should be used
* @param title
* title of view
* @param rolesAllowed
* logged in roles allowed for view
* @param loginRequired
* requires login
* @param route
* path string
* @param lazy
* lazy loaded
* @param register
* register view
* @param menu
* menu item information
* @param children
* view children
* @param routeParameters
* view parameters
* @param flowLayout
* if server layout should be used
*/
public record AvailableViewInfo(String title, String[] rolesAllowed,
boolean loginRequired, String route, boolean lazy,
boolean register, MenuData menu,
List<AvailableViewInfo> children, @JsonProperty(
"params") Map<String, RouteParamType> routeParameters, boolean flowLayout) implements Serializable {
boolean loginRequired, String route, boolean lazy, boolean register,
MenuData menu, List<AvailableViewInfo> children,
@JsonProperty("params") Map<String, RouteParamType> routeParameters,
boolean flowLayout) implements Serializable {

@Override
public boolean equals(final Object o) {
Expand All @@ -67,22 +77,20 @@ public boolean equals(final Object o) {

@Override
public int hashCode() {
int result = Objects.hash(title, loginRequired, route, lazy, register, menu, routeParameters);
int result = Objects.hash(title, loginRequired, route, lazy, register,
menu, routeParameters);
result = 31 * result + Arrays.hashCode(rolesAllowed);
return result;
}

@Override
public String toString() {
return "AvailableViewInfo{" + "title='" + title
+ '\'' + ", rolesAllowed=" + Arrays.toString(rolesAllowed)
+ ", loginRequired=" + loginRequired
+ ", route='" + route + '\''
+ ", lazy=" + lazy
+ ", register=" + register
+ ", menu=" + menu
+ ", flowLayout=" + flowLayout
+ ", routeParameters=" + routeParameters + '}';
return "AvailableViewInfo{" + "title='" + title + '\''
+ ", rolesAllowed=" + Arrays.toString(rolesAllowed)
+ ", loginRequired=" + loginRequired + ", route='" + route
+ '\'' + ", lazy=" + lazy + ", register=" + register + ", menu="
+ menu + ", flowLayout=" + flowLayout + ", routeParameters="
+ routeParameters + '}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
* annotation or null if not available. Always null for
* Hilla/TypeScript client views.
*/
public record MenuEntry(String path, String title, Double order,
String icon, Class<? extends Component> menuClass) implements Serializable {
public record MenuEntry(String path, String title, Double order, String icon,
Class<? extends Component> menuClass) implements Serializable {
}
Loading

0 comments on commit 684a080

Please sign in to comment.