-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that native-sources package results in the configuration as n…
…ative Furthermore, fail the build when native-sources is requested but the extension creates its own output Related to: quarkusio/quarkus#15233 (comment)
- Loading branch information
Luca Di Grazia
committed
Sep 4, 2022
1 parent
d34ebc9
commit b3423a9
Showing
10 changed files
with
199 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
.../deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeOrNativeSourcesBuild.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.quarkus.deployment.pkg.steps; | ||
|
||
import java.util.function.BooleanSupplier; | ||
|
||
import io.quarkus.deployment.pkg.PackageConfig; | ||
|
||
/** | ||
* Supplier that can be used to only run build steps in the | ||
* native or native sources builds. | ||
*/ | ||
public class NativeOrNativeSourcesBuild implements BooleanSupplier { | ||
|
||
private final PackageConfig packageConfig; | ||
|
||
NativeOrNativeSourcesBuild(PackageConfig packageConfig) { | ||
this.packageConfig = packageConfig; | ||
} | ||
|
||
@Override | ||
public boolean getAsBoolean() { | ||
return packageConfig.type.equalsIgnoreCase(PackageConfig.NATIVE) | ||
|| packageConfig.type.equalsIgnoreCase(PackageConfig.NATIVE_SOURCES); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...t/src/main/java/io/quarkus/gcp/functions/deployment/CloudFunctionDeploymentBuildStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.quarkus.gcp.functions.deployment; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Collections; | ||
|
||
import io.quarkus.builder.BuildException; | ||
import io.quarkus.deployment.IsNormal; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem; | ||
import io.quarkus.deployment.pkg.builditem.JarBuildItem; | ||
import io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem; | ||
import io.quarkus.deployment.pkg.builditem.UberJarRequiredBuildItem; | ||
import io.quarkus.deployment.pkg.steps.NativeBuild; | ||
import io.quarkus.deployment.pkg.steps.NativeSourcesBuild; | ||
|
||
public class CloudFunctionDeploymentBuildStep { | ||
@BuildStep | ||
public UberJarRequiredBuildItem forceUberJar() { | ||
// Google Cloud Function needs a single JAR inside a dedicated directory | ||
return new UberJarRequiredBuildItem(); | ||
} | ||
|
||
@BuildStep(onlyIf = NativeSourcesBuild.class) | ||
void failForNativeSources(BuildProducer<ArtifactResultBuildItem> artifactResultProducer) { | ||
throw new IllegalArgumentException( | ||
"The Google Cloud extensions are incompatible with the 'native-sources' package type."); | ||
} | ||
|
||
/** | ||
* Creates a target/deployment dir and copy the uber jar in it. | ||
* This facilitates the usage of the 'glcoud' command. | ||
*/ | ||
@BuildStep(onlyIf = IsNormal.class, onlyIfNot = NativeBuild.class) | ||
public ArtifactResultBuildItem functionDeployment(OutputTargetBuildItem target, JarBuildItem jar) | ||
throws BuildException, IOException { | ||
if (!jar.isUberJar()) { | ||
throw new BuildException("Google Cloud Function deployment need to use a uberjar, " + | ||
"please set 'quarkus.package.type=uber-jar' inside your application.properties", | ||
Collections.EMPTY_LIST); | ||
} | ||
|
||
Path deployment = target.getOutputDirectory().resolve("deployment"); | ||
if (Files.notExists(deployment)) { | ||
Files.createDirectory(deployment); | ||
} | ||
|
||
Path jarPath = jar.getPath(); | ||
Path targetJarPath = deployment.resolve(jarPath.getFileName()); | ||
Files.deleteIfExists(targetJarPath); | ||
Files.copy(jarPath, targetJarPath); | ||
|
||
return new ArtifactResultBuildItem(targetJarPath, "function", Collections.EMPTY_MAP); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.