Search in sources :

Example 1 with ManifestBuilder

use of org.jetbrains.idea.maven.utils.ManifestBuilder in project intellij-community by JetBrains.

the class MavenResourceCompilerConfigurationGenerator method generateManifest.

private static void generateManifest(@NotNull MavenProject mavenProject, @NotNull Module module, @NotNull MavenModuleResourceConfiguration resourceConfig) {
    if (mavenProject.isAggregator())
        return;
    if (Boolean.valueOf(IDEA_MAVEN_DISABLE_MANIFEST)) {
        resourceConfig.manifest = null;
        return;
    }
    try {
        String jdkVersion = null;
        Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
        if (sdk != null && (jdkVersion = sdk.getVersionString()) != null) {
            final int quoteIndex = jdkVersion.indexOf('"');
            if (quoteIndex != -1) {
                jdkVersion = jdkVersion.substring(quoteIndex + 1, jdkVersion.length() - 1);
            }
        }
        Manifest manifest = new ManifestBuilder(mavenProject).withJdkVersion(jdkVersion).build();
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        try {
            manifest.write(outputStream);
            MavenDomProjectModel domModel = MavenDomUtil.getMavenDomProjectModel(module.getProject(), mavenProject.getFile());
            if (domModel != null) {
                final String resolvedText = MavenPropertyResolver.resolve(outputStream.toString(CharsetToolkit.UTF8), domModel);
                resourceConfig.manifest = Base64.getEncoder().encodeToString(resolvedText.getBytes(StandardCharsets.UTF_8));
            }
        } finally {
            StreamUtil.closeStream(outputStream);
        }
        resourceConfig.classpath = ManifestBuilder.getClasspath(mavenProject);
    } catch (ManifestBuilder.ManifestBuilderException e) {
        LOG.warn("Unable to generate artifact manifest", e);
    } catch (Exception e) {
        LOG.warn("Unable to save generated artifact manifest", e);
    }
}
Also used : ManifestBuilder(org.jetbrains.idea.maven.utils.ManifestBuilder) MavenDomProjectModel(org.jetbrains.idea.maven.dom.model.MavenDomProjectModel) Sdk(com.intellij.openapi.projectRoots.Sdk) Manifest(java.util.jar.Manifest)

Aggregations

Sdk (com.intellij.openapi.projectRoots.Sdk)1 Manifest (java.util.jar.Manifest)1 MavenDomProjectModel (org.jetbrains.idea.maven.dom.model.MavenDomProjectModel)1 ManifestBuilder (org.jetbrains.idea.maven.utils.ManifestBuilder)1