Search in sources :

Example 1 with StandardPackagedProcessor

use of com.google.cloud.tools.jib.cli.jar.StandardPackagedProcessor in project jib by google.

the class ArtifactProcessors method fromJar.

/**
 * Creates a {@link ArtifactProcessor} instance based on jar type and processing mode.
 *
 * @param jarPath path to the jar
 * @param cacheDirectories the location of the relevant caches
 * @param jarOptions jar cli options
 * @param commonContainerConfigCliOptions common cli options shared between jar and war command
 * @return ArtifactProcessor
 * @throws IOException if I/O error occurs when opening the jar file
 */
public static ArtifactProcessor fromJar(Path jarPath, CacheDirectories cacheDirectories, Jar jarOptions, CommonContainerConfigCliOptions commonContainerConfigCliOptions) throws IOException {
    Integer jarJavaVersion = determineJavaMajorVersion(jarPath);
    if (jarJavaVersion > 17 && !commonContainerConfigCliOptions.getFrom().isPresent()) {
        throw new IllegalStateException(String.format("The input JAR (%s) is compiled with Java %d, but the default base image only " + "supports versions up to Java 17. Specify a custom base image with --from.", jarPath, jarJavaVersion));
    }
    String jarType = determineJarType(jarPath);
    ProcessingMode mode = jarOptions.getMode();
    if (jarType.equals(SPRING_BOOT) && mode.equals(ProcessingMode.packaged)) {
        return new SpringBootPackagedProcessor(jarPath, jarJavaVersion);
    } else if (jarType.equals(SPRING_BOOT) && mode.equals(ProcessingMode.exploded)) {
        return new SpringBootExplodedProcessor(jarPath, cacheDirectories.getExplodedArtifactDirectory(), jarJavaVersion);
    } else if (jarType.equals(STANDARD) && mode.equals(ProcessingMode.packaged)) {
        return new StandardPackagedProcessor(jarPath, jarJavaVersion);
    } else {
        return new StandardExplodedProcessor(jarPath, cacheDirectories.getExplodedArtifactDirectory(), jarJavaVersion);
    }
}
Also used : ProcessingMode(com.google.cloud.tools.jib.cli.jar.ProcessingMode) StandardExplodedProcessor(com.google.cloud.tools.jib.cli.jar.StandardExplodedProcessor) StandardPackagedProcessor(com.google.cloud.tools.jib.cli.jar.StandardPackagedProcessor) SpringBootPackagedProcessor(com.google.cloud.tools.jib.cli.jar.SpringBootPackagedProcessor) SpringBootExplodedProcessor(com.google.cloud.tools.jib.cli.jar.SpringBootExplodedProcessor)

Example 2 with StandardPackagedProcessor

use of com.google.cloud.tools.jib.cli.jar.StandardPackagedProcessor in project jib by GoogleContainerTools.

the class ArtifactProcessors method fromJar.

/**
 * Creates a {@link ArtifactProcessor} instance based on jar type and processing mode.
 *
 * @param jarPath path to the jar
 * @param cacheDirectories the location of the relevant caches
 * @param jarOptions jar cli options
 * @param commonContainerConfigCliOptions common cli options shared between jar and war command
 * @return ArtifactProcessor
 * @throws IOException if I/O error occurs when opening the jar file
 */
public static ArtifactProcessor fromJar(Path jarPath, CacheDirectories cacheDirectories, Jar jarOptions, CommonContainerConfigCliOptions commonContainerConfigCliOptions) throws IOException {
    Integer jarJavaVersion = determineJavaMajorVersion(jarPath);
    if (jarJavaVersion > 17 && !commonContainerConfigCliOptions.getFrom().isPresent()) {
        throw new IllegalStateException(String.format("The input JAR (%s) is compiled with Java %d, but the default base image only " + "supports versions up to Java 17. Specify a custom base image with --from.", jarPath, jarJavaVersion));
    }
    String jarType = determineJarType(jarPath);
    ProcessingMode mode = jarOptions.getMode();
    if (jarType.equals(SPRING_BOOT) && mode.equals(ProcessingMode.packaged)) {
        return new SpringBootPackagedProcessor(jarPath, jarJavaVersion);
    } else if (jarType.equals(SPRING_BOOT) && mode.equals(ProcessingMode.exploded)) {
        return new SpringBootExplodedProcessor(jarPath, cacheDirectories.getExplodedArtifactDirectory(), jarJavaVersion);
    } else if (jarType.equals(STANDARD) && mode.equals(ProcessingMode.packaged)) {
        return new StandardPackagedProcessor(jarPath, jarJavaVersion);
    } else {
        return new StandardExplodedProcessor(jarPath, cacheDirectories.getExplodedArtifactDirectory(), jarJavaVersion);
    }
}
Also used : ProcessingMode(com.google.cloud.tools.jib.cli.jar.ProcessingMode) StandardExplodedProcessor(com.google.cloud.tools.jib.cli.jar.StandardExplodedProcessor) StandardPackagedProcessor(com.google.cloud.tools.jib.cli.jar.StandardPackagedProcessor) SpringBootPackagedProcessor(com.google.cloud.tools.jib.cli.jar.SpringBootPackagedProcessor) SpringBootExplodedProcessor(com.google.cloud.tools.jib.cli.jar.SpringBootExplodedProcessor)

Aggregations

ProcessingMode (com.google.cloud.tools.jib.cli.jar.ProcessingMode)2 SpringBootExplodedProcessor (com.google.cloud.tools.jib.cli.jar.SpringBootExplodedProcessor)2 SpringBootPackagedProcessor (com.google.cloud.tools.jib.cli.jar.SpringBootPackagedProcessor)2 StandardExplodedProcessor (com.google.cloud.tools.jib.cli.jar.StandardExplodedProcessor)2 StandardPackagedProcessor (com.google.cloud.tools.jib.cli.jar.StandardPackagedProcessor)2