use of com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException in project jib-extensions by GoogleContainerTools.
the class JibLayerFilterExtension method getParentDependencies.
private List<Dependency> getParentDependencies(MavenData mavenData) throws JibPluginExtensionException {
if (mavenData.getMavenProject().getParent() == null) {
throw new JibPluginExtensionException(getClass(), "Try to get parent dependencies, but project has no parent.");
}
if (dependencyResolver == null) {
throw new JibPluginExtensionException(getClass(), "Try to get parent dependencies, but ProjectDependenciesResolver is null. Please use a " + "more recent Jib plugin version to fix this.");
}
try {
DefaultDependencyResolutionRequest request = new DefaultDependencyResolutionRequest(mavenData.getMavenProject().getParent(), mavenData.getMavenSession().getRepositorySession());
request.setResolutionFilter(new ScopeDependencyFilter("test"));
DependencyResolutionResult resolutionResult = dependencyResolver.resolve(request);
return resolutionResult.getDependencies();
} catch (DependencyResolutionException ex) {
throw new JibPluginExtensionException(getClass(), "Error when getting parent dependencies", ex);
}
}
use of com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException in project jib-extensions by GoogleContainerTools.
the class JibQuarkusExtension method extendContainerBuildPlan.
@Override
public ContainerBuildPlan extendContainerBuildPlan(ContainerBuildPlan buildPlan, Map<String, String> properties, Optional<Void> config, MavenData mavenData, ExtensionLogger logger) throws JibPluginExtensionException {
try {
logger.log(LogLevel.LIFECYCLE, "Running Quarkus Jib extension");
readJibConfigurations(mavenData.getMavenProject());
Build build = mavenData.getMavenProject().getBuild();
Path outputDirectory = Paths.get(build.getDirectory());
Path jar = outputDirectory.resolve(build.getFinalName() + "-runner.jar");
if (!Files.isRegularFile(jar)) {
throw new JibPluginExtensionException(getClass(), jar + " doesn't exist; did you run the Qaurkus Maven plugin " + "('compile' and 'quarkus:build' Maven goals)?");
}
ContainerBuildPlan.Builder planBuilder = buildPlan.toBuilder();
planBuilder.setLayers(Collections.emptyList());
// dependency layers
addDependencyLayers(mavenData.getMavenSession(), planBuilder, outputDirectory.resolve("lib"));
// Quarkus runner JAR layer
AbsoluteUnixPath appRootJar = appRoot.resolve("app.jar");
FileEntriesLayer jarLayer = FileEntriesLayer.builder().setName("quarkus jar").addEntry(jar, appRootJar).build();
planBuilder.addLayer(jarLayer);
// Preserve extra directories layers.
String extraFilesLayerName = JavaContainerBuilder.LayerType.EXTRA_FILES.getName();
buildPlan.getLayers().stream().filter(layer -> layer.getName().startsWith(extraFilesLayerName)).forEach(planBuilder::addLayer);
// set entrypoint
List<String> entrypoint = new ArrayList<>();
entrypoint.add("java");
entrypoint.addAll(jvmFlags);
entrypoint.add("-jar");
entrypoint.add(appRootJar.toString());
planBuilder.setEntrypoint(entrypoint);
return planBuilder.build();
} catch (IOException ex) {
throw new JibPluginExtensionException(getClass(), Verify.verifyNotNull(ex.getMessage()), ex);
}
}
use of com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException in project jib-extensions by GoogleContainerTools.
the class JibQuarkusExtensionTest method testExtendContainerBuildPlan_noQuarkusRunnerJar.
@Test
public void testExtendContainerBuildPlan_noQuarkusRunnerJar() throws IOException {
Files.delete(tempFolder.getRoot().toPath().resolve("target").resolve("my-app-runner.jar"));
ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().build();
try {
new JibQuarkusExtension().extendContainerBuildPlan(buildPlan, null, Optional.empty(), mavenData, logger);
fail();
} catch (JibPluginExtensionException ex) {
assertEquals(JibQuarkusExtension.class, ex.getExtensionClass());
assertThat(ex.getMessage(), endsWith(File.separator + "my-app-runner.jar doesn't exist; did you run the Qaurkus Maven plugin " + "('compile' and 'quarkus:build' Maven goals)?"));
}
}
use of com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException in project jib-extensions by GoogleContainerTools.
the class JibNativeImageExtensionTest method testExecutableNotFound.
@Test
public void testExecutableNotFound() {
Map<String, String> properties = Collections.singletonMap("imageName", "theExecutable");
ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().build();
try {
new JibNativeImageExtension().extendContainerBuildPlan(buildPlan, properties, Optional.empty(), mavenData, logger);
fail();
} catch (JibPluginExtensionException ex) {
assertEquals("Native-image executable does not exist or not a file: " + tempFolder.getRoot().toPath().resolve("theExecutable") + "\nDid you run the 'native-image:native-image' goal?", ex.getMessage());
}
}
use of com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException in project jib-extensions by GoogleContainerTools.
the class JibQuarkusExtensionTest method testExtendContainerBuildPlan_noQuarkusRunnerJar.
@Test
public void testExtendContainerBuildPlan_noQuarkusRunnerJar() throws IOException {
Files.delete(tempFolder.getRoot().toPath().resolve("build").resolve("my-app-runner.jar"));
ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().build();
try {
new JibQuarkusExtension().extendContainerBuildPlan(buildPlan, null, Optional.empty(), gradleData, logger);
fail();
} catch (JibPluginExtensionException ex) {
assertEquals(JibQuarkusExtension.class, ex.getExtensionClass());
assertThat(ex.getMessage(), endsWith(File.separator + "my-app-runner.jar doesn't exist; did you run the Qaurkus Gradle plugin " + "('quarkusBuild' task)?"));
}
}
Aggregations