Skip to content

Commit 10b87a8

Browse files
committed
e
1 parent 44f2912 commit 10b87a8

5 files changed

Lines changed: 29 additions & 40 deletions

File tree

modules/packed/src/main/java/app/packed/application/BootstrapApp.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import app.packed.container.Wirelet;
2525
import app.packed.lifecycle.LifecycleKind;
2626
import app.packed.lifecycle.RunState;
27-
import internal.app.packed.application.PackedApplicationTemplate;
2827
import internal.app.packed.application.PackedBootstrapImage;
2928
import internal.app.packed.application.PackedBootstrapImage.ImageMapped;
3029

@@ -191,14 +190,7 @@ default BootstrapApp<I> withWirelets(boolean before, Wirelet... wirelets) {
191190
}
192191

193192
static <A> BootstrapApp<A> of(LifecycleKind lifecycleKind, Bean<A> bean) {
194-
requireNonNull(bean, "bean is null");
195-
requireNonNull(lifecycleKind, "lifecycleKind is null");
196-
PackedApplicationTemplate.Builder<A> builder = new PackedApplicationTemplate.Builder<>(bean);
197-
return switch (lifecycleKind) {
198-
case NONE -> throw new IllegalArgumentException("LifecycleKind.NONE is not supported for BootstrapApp");
199-
case UNMANAGED -> PackedBootstrapApp.of(builder.unmanaged().build());
200-
case MANAGED -> PackedBootstrapApp.of(builder.build());
201-
};
193+
return PackedBootstrapApp.of(lifecycleKind, bean);
202194
}
203195

204196
/**

modules/packed/src/main/java/app/packed/application/PackedBootstrapApp.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import app.packed.build.BuildGoal;
2525
import app.packed.container.Wirelet;
2626
import app.packed.extension.BaseExtension;
27+
import app.packed.lifecycle.LifecycleKind;
2728
import app.packed.lifecycle.RunState;
2829
import internal.app.packed.ValueBased;
2930
import internal.app.packed.application.PackedApplicationTemplate;
@@ -42,7 +43,7 @@ final class PackedBootstrapApp<A, H extends ApplicationHandle<A, ?>> implements
4243
// TODO we need to restrict the extensions that can be used to BaseExtension
4344
// So beans do not uses hooks from various extensions
4445
private static final PackedApplicationTemplate<?> BOOTSTRAP_APP_TEMPLATE =
45-
new PackedApplicationTemplate.Builder<>(Bean.of(PackedBootstrapApp.class)).build();
46+
PackedApplicationTemplate.of(LifecycleKind.UNMANAGED, Bean.of(PackedBootstrapApp.class));
4647

4748
/** The application launcher. */
4849
private final ApplicationBaseLauncher launcher;
@@ -120,16 +121,13 @@ public PackedBootstrapApp<A, H> withExpectsResult(Class<?> resultType) {
120121
throw new UnsupportedOperationException();
121122
}
122123

123-
/**
124-
* Builds a new bootstrap app for applications represented by the specified template.
125-
*
126-
* @param <A>
127-
* @param template
128-
* the template for the type applications that should be bootstrapped
129-
* @return a new bootstrap app
130-
*/
131-
public static <A, H extends ApplicationHandle<A, ?>> BootstrapApp<A> of(PackedApplicationTemplate<H> template) {
132-
// We need a an assembly to build the (bootstrap) application
124+
public static <A> BootstrapApp<A> of(LifecycleKind lifecycleKind, Bean<A> bean) {
125+
if (lifecycleKind == LifecycleKind.NONE) {
126+
throw new IllegalArgumentException("LifecycleKind.NONE is not supported for BootstrapApp");
127+
}
128+
PackedApplicationTemplate<ApplicationHandle<A, ApplicationConfiguration>> template = PackedApplicationTemplate.of(lifecycleKind, bean);
129+
130+
// We need an assembly to build the (bootstrap) application
133131
BootstrapAppAssembly assembly = new BootstrapAppAssembly(template);
134132

135133
// Creates a new application installer and installs the specified assembly and build the final bootstrap application
@@ -139,8 +137,8 @@ public PackedBootstrapApp<A, H> withExpectsResult(Class<?> resultType) {
139137
if (assembly.sidehandle != null) {
140138
launcher = ServiceSupport.newApplicationBaseLauncher(assembly.sidehandle);
141139
}
142-
// Returned the bootstrap implementation (represented by a construcing method handle) wrapped in this class.
143-
return new PackedBootstrapApp<A, H>(template, launcher);
140+
// Returned the bootstrap implementation wrapped in this class.
141+
return new PackedBootstrapApp<>(template, launcher);
144142
}
145143

146144
/** The assembly responsible for building the bootstrap app. */

modules/packed/src/main/java/app/packed/application/registry/ApplicationTemplate.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ static <T> Builder<T> builder(Bean<T> bean) {
4848

4949
interface Builder<I> {
5050

51-
Builder<I> unmanaged();
52-
5351
ApplicationTemplate<ApplicationHandle<I, ApplicationConfiguration>> build();
5452

5553
<H extends ApplicationHandle<I, ?>> ApplicationTemplate<H> build(Class<? super H> handleClass,

modules/packed/src/main/java/internal/app/packed/application/PackedApplicationTemplate.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package internal.app.packed.application;
1717

18+
import static java.util.Objects.requireNonNull;
19+
1820
import java.util.function.Function;
1921

2022
import app.packed.application.ApplicationConfiguration;
@@ -24,17 +26,24 @@
2426
import app.packed.bean.Bean;
2527
import app.packed.build.BuildGoal;
2628
import app.packed.container.Wirelet;
29+
import app.packed.lifecycle.LifecycleKind;
2730
import app.packed.util.Nullable;
2831
import internal.app.packed.invoke.MethodHandleInvoker.ApplicationBaseLauncher;
2932

3033
/** Implementation of {@link ApplicationTemplate}. */
31-
public record PackedApplicationTemplate<H extends ApplicationHandle<?, ?>>(Bean<?> bean, Class<? super H> handleClass,
32-
Function<? super ApplicationInstaller<H>, ? extends ApplicationHandle<?, ?>> handleFactory, boolean isManaged
33-
) implements ApplicationTemplate<H> {
34+
public record PackedApplicationTemplate<H extends ApplicationHandle<?, ?>>(LifecycleKind lifecycleKind, Bean<?> bean, Class<? super H> handleClass,
35+
Function<? super ApplicationInstaller<H>, ? extends ApplicationHandle<?, ?>> handleFactory) implements ApplicationTemplate<H> {
3436

3537
public Class<?> guestClass() {
3638
return bean.beanClass();
3739
}
40+
41+
public static <I> PackedApplicationTemplate<ApplicationHandle<I, ApplicationConfiguration>> of(LifecycleKind kind, Bean<I> bean) {
42+
requireNonNull(kind, "lifecycleKind is null");
43+
requireNonNull(bean, "bean is null");
44+
return new PackedApplicationTemplate<>(kind, bean, ApplicationHandle.class, ApplicationHandle::new);
45+
}
46+
3847
/**
3948
* Creates a new {@link ApplicationInstaller} from this template.
4049
*
@@ -56,15 +65,15 @@ public interface ApplicationInstallingSource {}
5665
/** {@inheritDoc} */
5766
@Override
5867
public boolean isManaged() {
59-
return isManaged;
68+
return lifecycleKind == LifecycleKind.MANAGED;
6069
}
6170

6271
/** Implementation of {@link ApplicationTemplate.Builder}. */
6372
public static final class Builder<I> implements ApplicationTemplate.Builder<I> {
6473

6574
private final Bean<I> bean;
6675

67-
private boolean managed = true;
76+
private LifecycleKind lifecycleKind = LifecycleKind.MANAGED;
6877

6978
public Builder(Bean<I> bean) {
7079
this.bean = bean;
@@ -80,15 +89,7 @@ public PackedApplicationTemplate<ApplicationHandle<I, ApplicationConfiguration>>
8089
@Override
8190
public <H extends ApplicationHandle<I, ?>> PackedApplicationTemplate<H> build(Class<? super H> handleClass,
8291
Function<? super ApplicationInstaller<H>, ? extends H> handleFactory) {
83-
return new PackedApplicationTemplate<>(bean, handleClass,
84-
handleFactory, managed);
85-
}
86-
87-
/** {@inheritDoc} */
88-
@Override
89-
public Builder<I> unmanaged() {
90-
this.managed = false;
91-
return this;
92+
return new PackedApplicationTemplate<>(lifecycleKind, bean, handleClass, handleFactory);
9293
}
9394
}
9495
}

modules/packed/src/test/java/tck/AbstractAppTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import app.packed.build.BuildGoal;
3939
import app.packed.container.ContainerConfiguration;
4040
import app.packed.container.Wirelet;
41+
import app.packed.lifecycle.LifecycleKind;
4142
import app.packed.operation.OperationHandle;
4243
import internal.app.packed.application.ApplicationSetup;
4344
import internal.app.packed.application.ApplicationSetup.ApplicationBuildPhase;
@@ -213,8 +214,7 @@ public State1Setup wirelets(Wirelet... wirelets) {
213214

214215
final class State2Building implements InternalTestState, ApplicationInstallingSource {
215216
public static final MethodHandle EMPTY_MH = MethodHandles.empty(MethodType.methodType(Object.class, ApplicationLaunchContext.class));
216-
static final PackedApplicationTemplate<?> PAT = new PackedApplicationTemplate<>(Bean.of(), ApplicationHandle.class, ApplicationHandle::new,
217-
true);
217+
static final PackedApplicationTemplate<?> PAT = new PackedApplicationTemplate<>(LifecycleKind.MANAGED, Bean.of(), ApplicationHandle.class, ApplicationHandle::new);
218218
final AssemblySetup assembly;
219219

220220
final PackedApplicationInstaller<?> b;

0 commit comments

Comments
 (0)