Search in sources :

Example 1 with DefaultManifest

use of org.gradle.api.java.archives.internal.DefaultManifest 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 2 with DefaultManifest

use of org.gradle.api.java.archives.internal.DefaultManifest 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 3 with DefaultManifest

use of org.gradle.api.java.archives.internal.DefaultManifest in project gradle by gradle.

the class DefaultOsgiManifest method getEffectiveManifest.

@Override
public DefaultManifest getEffectiveManifest() {
    ContainedVersionAnalyzer analyzer = analyzerFactory.create();
    DefaultManifest effectiveManifest = new DefaultManifest(null);
    try {
        setAnalyzerProperties(analyzer);
        Manifest osgiManifest = analyzer.calcManifest();
        java.util.jar.Attributes attributes = osgiManifest.getMainAttributes();
        for (Map.Entry<Object, Object> entry : attributes.entrySet()) {
            effectiveManifest.attributes(WrapUtil.toMap(entry.getKey().toString(), (String) entry.getValue()));
        }
        effectiveManifest.attributes(this.getAttributes());
        for (Map.Entry<String, Attributes> ent : getSections().entrySet()) {
            effectiveManifest.attributes(ent.getValue(), ent.getKey());
        }
        if (classesDir != null) {
            long mod = classesDir.lastModified();
            if (mod > 0) {
                effectiveManifest.getAttributes().put(Analyzer.BND_LASTMODIFIED, mod);
            }
        }
    } catch (Exception e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
    return getEffectiveManifestInternal(effectiveManifest);
}
Also used : DefaultManifest(org.gradle.api.java.archives.internal.DefaultManifest) Attributes(org.gradle.api.java.archives.Attributes) Manifest(java.util.jar.Manifest) DefaultManifest(org.gradle.api.java.archives.internal.DefaultManifest) OsgiManifest(org.gradle.api.plugins.osgi.OsgiManifest) IOException(java.io.IOException) UncheckedException(org.gradle.internal.UncheckedException)

Aggregations

DefaultManifest (org.gradle.api.java.archives.internal.DefaultManifest)3 Manifest (org.gradle.api.java.archives.Manifest)2 IOException (java.io.IOException)1 Manifest (java.util.jar.Manifest)1 Project (org.gradle.api.Project)1 FileResolver (org.gradle.api.internal.file.FileResolver)1 Attributes (org.gradle.api.java.archives.Attributes)1 CustomManifestInternalWrapper (org.gradle.api.java.archives.internal.CustomManifestInternalWrapper)1 ManifestInternal (org.gradle.api.java.archives.internal.ManifestInternal)1 Logger (org.gradle.api.logging.Logger)1 OsgiManifest (org.gradle.api.plugins.osgi.OsgiManifest)1 UncheckedException (org.gradle.internal.UncheckedException)1 Jar (org.gradle.jvm.tasks.Jar)1 Test (org.junit.Test)1