Search in sources :

Example 11 with PublishArtifact

use of org.gradle.api.artifacts.PublishArtifact in project gradle by gradle.

the class JvmLocalLibraryMetaDataAdapter method createResolvedMetaData.

private DefaultLibraryLocalComponentMetadata createResolvedMetaData(BinarySpecInternal selectedBinary, String projectPath, EnumMap<UsageKind, Iterable<DependencySpec>> dependenciesPerUsage, EnumMap<UsageKind, List<PublishArtifact>> artifacts) {
    final DefaultLibraryLocalComponentMetadata metadata = newResolvedLibraryMetadata(selectedBinary.getId(), toStringMap(dependenciesPerUsage), projectPath);
    for (Map.Entry<UsageKind, List<PublishArtifact>> entry : artifacts.entrySet()) {
        UsageKind usage = entry.getKey();
        final List<PublishArtifact> publishArtifacts = entry.getValue();
        metadata.addArtifacts(usage.getConfigurationName(), publishArtifacts);
        metadata.addVariant(usage.getConfigurationName(), new OutgoingVariant() {

            @Override
            public DisplayName asDescribable() {
                return Describables.of(metadata.getId());
            }

            @Override
            public AttributeContainerInternal getAttributes() {
                return ImmutableAttributes.EMPTY;
            }

            @Override
            public Set<? extends PublishArtifact> getArtifacts() {
                return new LinkedHashSet<PublishArtifact>(publishArtifacts);
            }

            @Override
            public Set<? extends OutgoingVariant> getChildren() {
                return ImmutableSet.of();
            }
        });
    }
    return metadata;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) DefaultLibraryLocalComponentMetadata(org.gradle.language.base.internal.model.DefaultLibraryLocalComponentMetadata) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal) OutgoingVariant(org.gradle.api.internal.artifacts.configurations.OutgoingVariant) DisplayName(org.gradle.internal.DisplayName) LinkedList(java.util.LinkedList) List(java.util.List) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) DefaultPublishArtifact(org.gradle.api.internal.artifacts.publish.DefaultPublishArtifact) HashMap(java.util.HashMap) Map(java.util.Map) EnumMap(java.util.EnumMap)

Example 12 with PublishArtifact

use of org.gradle.api.artifacts.PublishArtifact in project gradle by gradle.

the class ModuleMetadataFileGenerator method writeArtifacts.

private void writeArtifacts(PublicationInternal publication, UsageContext variant, JsonWriter jsonWriter) throws IOException {
    if (variant.getArtifacts().isEmpty()) {
        return;
    }
    jsonWriter.name("files");
    jsonWriter.beginArray();
    for (PublishArtifact artifact : variant.getArtifacts()) {
        writeArtifact(publication, artifact, jsonWriter);
    }
    jsonWriter.endArray();
}
Also used : PublishArtifact(org.gradle.api.artifacts.PublishArtifact)

Example 13 with PublishArtifact

use of org.gradle.api.artifacts.PublishArtifact in project gradle by gradle.

the class JvmLocalLibraryMetaDataAdapter method addArtifact.

private static void addArtifact(UsageKind usage, Set<File> directories, EnumMap<UsageKind, List<PublishArtifact>> artifacts, JvmAssembly assembly) {
    List<PublishArtifact> publishArtifacts = artifacts.get(usage);
    for (File dir : directories) {
        DefaultPublishArtifact publishArtifact = new DefaultPublishArtifact("assembly", "", "", "", new Date(dir.lastModified()), dir);
        publishArtifact.builtBy(assembly);
        publishArtifacts.add(publishArtifact);
    }
}
Also used : DefaultPublishArtifact(org.gradle.api.internal.artifacts.publish.DefaultPublishArtifact) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) DefaultPublishArtifact(org.gradle.api.internal.artifacts.publish.DefaultPublishArtifact) JarFile(org.gradle.jvm.internal.JarFile) File(java.io.File) Date(java.util.Date)

Example 14 with PublishArtifact

use of org.gradle.api.artifacts.PublishArtifact in project gradle by gradle.

the class DefaultIvyModulePublishMetadata method addArtifacts.

@Override
public void addArtifacts(String configuration, Iterable<? extends PublishArtifact> artifacts) {
    for (PublishArtifact artifact : artifacts) {
        DefaultIvyArtifactName ivyName = DefaultIvyArtifactName.forPublishArtifact(artifact);
        DefaultIvyModuleArtifactPublishMetadata ivyArtifact = getOrCreate(ivyName);
        ivyArtifact.setFile(artifact.getFile());
        ivyArtifact.addConfiguration(configuration);
    }
}
Also used : DefaultIvyArtifactName(org.gradle.internal.component.model.DefaultIvyArtifactName) PublishArtifact(org.gradle.api.artifacts.PublishArtifact)

Example 15 with PublishArtifact

use of org.gradle.api.artifacts.PublishArtifact in project gradle by gradle.

the class DefaultArtifactPomTest method pomWithMainArtifactAndMetadataArtifacts.

@Test
public void pomWithMainArtifactAndMetadataArtifacts() {
    Artifact mainArtifact = createTestArtifact("someName", null, "mainPackaging");
    File mainFile = new File("someFile");
    File metadataFile = new File("someMetadataFile");
    Artifact metadataArtifact = createTestArtifact("otherName", null, "sometype");
    artifactPom.addArtifact(mainArtifact, mainFile);
    artifactPom.addArtifact(metadataArtifact, metadataFile);
    assertThat(artifactPom.getArtifact().getName(), equalTo("someName"));
    assertThat(artifactPom.getArtifact().getExtension(), equalTo("mainPackaging"));
    assertThat(artifactPom.getArtifact().getType(), equalTo("mainPackaging"));
    assertThat(artifactPom.getArtifact().getClassifier(), nullValue());
    assertThat(artifactPom.getArtifact().getFile(), equalTo(mainFile));
    PublishArtifact artifact = singleItem(artifactPom.getAttachedArtifacts());
    assertThat(artifact.getName(), equalTo("someName"));
    assertThat(artifact.getExtension(), equalTo("sometype"));
    assertThat(artifact.getType(), equalTo("sometype"));
    assertThat(artifact.getClassifier(), nullValue());
    assertThat(artifact.getFile(), equalTo(metadataFile));
    assertThat(artifactPom.getPom().getGroupId(), equalTo("org"));
    assertThat(artifactPom.getPom().getArtifactId(), equalTo("someName"));
    assertThat(artifactPom.getPom().getVersion(), equalTo("1.0"));
    assertThat(artifactPom.getPom().getPackaging(), equalTo("mainPackaging"));
}
Also used : PublishArtifact(org.gradle.api.artifacts.PublishArtifact) File(java.io.File) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Aggregations

PublishArtifact (org.gradle.api.artifacts.PublishArtifact)22 File (java.io.File)8 DefaultPublishArtifact (org.gradle.api.internal.artifacts.publish.DefaultPublishArtifact)5 Test (org.junit.Test)4 Artifact (org.apache.ivy.core.module.descriptor.Artifact)3 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)3 InvalidUserDataException (org.gradle.api.InvalidUserDataException)3 Configuration (org.gradle.api.artifacts.Configuration)3 EnumMap (java.util.EnumMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Task (org.gradle.api.Task)2 ModuleDependency (org.gradle.api.artifacts.ModuleDependency)2 ProjectDependency (org.gradle.api.artifacts.ProjectDependency)2 OutgoingVariant (org.gradle.api.internal.artifacts.configurations.OutgoingVariant)2 UsageContext (org.gradle.api.internal.component.UsageContext)2 PublishArtifactLocalArtifactMetadata (org.gradle.internal.component.local.model.PublishArtifactLocalArtifactMetadata)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 FileOutputStream (java.io.FileOutputStream)1