Search in sources :

Example 1 with Manifest

use of org.gradle.api.java.archives.Manifest in project gradle by gradle.

the class JavaPluginConvention method manifest.

/**
 * Creates and configures a new instance of a {@link Manifest}.
 *
 * @param action The action to use to configure the manifest.
 * @since 3.5
 */
public Manifest manifest(Action<? super Manifest> action) {
    Manifest manifest = createManifest();
    action.execute(manifest);
    return manifest;
}
Also used : DefaultManifest(org.gradle.api.java.archives.internal.DefaultManifest) Manifest(org.gradle.api.java.archives.Manifest)

Example 2 with Manifest

use of org.gradle.api.java.archives.Manifest in project jib by google.

the class ProjectPropertiesTest method testGetMainClassFromJarTask.

@Test
public void testGetMainClassFromJarTask() {
    Manifest fakeManifest = new DefaultManifest(Mockito.mock(FileResolver.class));
    fakeManifest.attributes(ImmutableMap.of("Main-Class", "some.main.class"));
    Jar mockJar = Mockito.mock(Jar.class);
    Mockito.when(mockJar.getManifest()).thenReturn(fakeManifest);
    Project mockProject = Mockito.mock(Project.class);
    Mockito.when(mockProject.getTasksByName("jar", false)).thenReturn(ImmutableSet.of(mockJar));
    ProjectProperties testProjectProperties = new ProjectProperties(mockProject, Mockito.mock(Logger.class));
    Assert.assertEquals("some.main.class", testProjectProperties.getMainClassFromJarTask());
}
Also used : Project(org.gradle.api.Project) DefaultManifest(org.gradle.api.java.archives.internal.DefaultManifest) Jar(org.gradle.jvm.tasks.Jar) DefaultManifest(org.gradle.api.java.archives.internal.DefaultManifest) Manifest(org.gradle.api.java.archives.Manifest) FileResolver(org.gradle.api.internal.file.FileResolver) Logger(org.gradle.api.logging.Logger) Test(org.junit.Test)

Example 3 with Manifest

use of org.gradle.api.java.archives.Manifest in project gradle by gradle.

the class Jar method computeManifest.

private ManifestInternal computeManifest() {
    Manifest manifest = getManifest();
    if (manifest == null) {
        manifest = new DefaultManifest(null);
    }
    ManifestInternal manifestInternal;
    if (manifest instanceof ManifestInternal) {
        manifestInternal = (ManifestInternal) manifest;
    } else {
        manifestInternal = new CustomManifestInternalWrapper(manifest);
    }
    manifestInternal.setContentCharset(manifestContentCharset);
    return manifestInternal;
}
Also used : DefaultManifest(org.gradle.api.java.archives.internal.DefaultManifest) CustomManifestInternalWrapper(org.gradle.api.java.archives.internal.CustomManifestInternalWrapper) ManifestInternal(org.gradle.api.java.archives.internal.ManifestInternal) DefaultManifest(org.gradle.api.java.archives.internal.DefaultManifest) Manifest(org.gradle.api.java.archives.Manifest)

Example 4 with Manifest

use of org.gradle.api.java.archives.Manifest in project spring-boot by spring-projects.

the class BootArchiveSupport method createCopyAction.

CopyAction createCopyAction(Jar jar, LayerResolver layerResolver, String layerToolsLocation) {
    File output = jar.getArchiveFile().get().getAsFile();
    Manifest manifest = jar.getManifest();
    boolean preserveFileTimestamps = jar.isPreserveFileTimestamps();
    boolean includeDefaultLoader = isUsingDefaultLoader(jar);
    Spec<FileTreeElement> requiresUnpack = this.requiresUnpack.getAsSpec();
    Spec<FileTreeElement> exclusions = this.exclusions.getAsExcludeSpec();
    LaunchScriptConfiguration launchScript = this.launchScript;
    Spec<FileCopyDetails> librarySpec = this.librarySpec;
    Function<FileCopyDetails, ZipCompression> compressionResolver = this.compressionResolver;
    String encoding = jar.getMetadataCharset();
    CopyAction action = new BootZipCopyAction(output, manifest, preserveFileTimestamps, includeDefaultLoader, layerToolsLocation, requiresUnpack, exclusions, launchScript, librarySpec, compressionResolver, encoding, layerResolver);
    return jar.isReproducibleFileOrder() ? new ReproducibleOrderingCopyAction(action) : action;
}
Also used : CopyAction(org.gradle.api.internal.file.copy.CopyAction) FileTreeElement(org.gradle.api.file.FileTreeElement) FileCopyDetails(org.gradle.api.file.FileCopyDetails) Manifest(org.gradle.api.java.archives.Manifest) File(java.io.File)

Example 5 with Manifest

use of org.gradle.api.java.archives.Manifest in project gradle by gradle.

the class Jar method manifestFileTree.

private FileTreeInternal manifestFileTree() {
    final Cached<ManifestInternal> manifest = Cached.of(this::computeManifest);
    final OutputChangeListener outputChangeListener = outputChangeListener();
    return fileCollectionFactory().generated(getTemporaryDirFactory(), "MANIFEST.MF", action(file -> outputChangeListener.beforeOutputChange(ImmutableList.of(file.getAbsolutePath()))), action(outputStream -> manifest.get().writeTo(outputStream)));
}
Also used : Action(org.gradle.api.Action) DefaultManifest(org.gradle.api.java.archives.internal.DefaultManifest) Closure(groovy.lang.Closure) Cached(org.gradle.internal.serialization.Cached) OutputChangeListener(org.gradle.internal.execution.OutputChangeListener) SerializableLambdas.action(org.gradle.api.internal.lambdas.SerializableLambdas.action) CopySpec(org.gradle.api.file.CopySpec) DisableCachingByDefault(org.gradle.work.DisableCachingByDefault) CustomManifestInternalWrapper(org.gradle.api.java.archives.internal.CustomManifestInternalWrapper) ConfigureUtil(org.gradle.util.internal.ConfigureUtil) ImmutableList(com.google.common.collect.ImmutableList) Charset(java.nio.charset.Charset) FileCollectionFactory(org.gradle.api.internal.file.FileCollectionFactory) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) FileTreeInternal(org.gradle.api.internal.file.FileTreeInternal) FileCopyDetails(org.gradle.api.file.FileCopyDetails) Manifest(org.gradle.api.java.archives.Manifest) ManifestInternal(org.gradle.api.java.archives.internal.ManifestInternal) Input(org.gradle.api.tasks.Input) InvalidUserDataException(org.gradle.api.InvalidUserDataException) Zip(org.gradle.api.tasks.bundling.Zip) Internal(org.gradle.api.tasks.Internal) CopySpecInternal(org.gradle.api.internal.file.copy.CopySpecInternal) ManifestInternal(org.gradle.api.java.archives.internal.ManifestInternal) OutputChangeListener(org.gradle.internal.execution.OutputChangeListener)

Aggregations

Manifest (org.gradle.api.java.archives.Manifest)6 DefaultManifest (org.gradle.api.java.archives.internal.DefaultManifest)5 FileCopyDetails (org.gradle.api.file.FileCopyDetails)2 CustomManifestInternalWrapper (org.gradle.api.java.archives.internal.CustomManifestInternalWrapper)2 ManifestInternal (org.gradle.api.java.archives.internal.ManifestInternal)2 ImmutableList (com.google.common.collect.ImmutableList)1 Closure (groovy.lang.Closure)1 File (java.io.File)1 Charset (java.nio.charset.Charset)1 Action (org.gradle.api.Action)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 Project (org.gradle.api.Project)1 CopySpec (org.gradle.api.file.CopySpec)1 FileTreeElement (org.gradle.api.file.FileTreeElement)1 FileCollectionFactory (org.gradle.api.internal.file.FileCollectionFactory)1 FileResolver (org.gradle.api.internal.file.FileResolver)1 FileTreeInternal (org.gradle.api.internal.file.FileTreeInternal)1 CopyAction (org.gradle.api.internal.file.copy.CopyAction)1 CopySpecInternal (org.gradle.api.internal.file.copy.CopySpecInternal)1 SerializableLambdas.action (org.gradle.api.internal.lambdas.SerializableLambdas.action)1