Search in sources :

Example 16 with PublishArtifact

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

the class DefaultArtifactPomTest method writePom.

@Test
public void writePom() {
    final MavenPom mavenPomMock = context.mock(MavenPom.class);
    DefaultArtifactPom artifactPom = new DefaultArtifactPom(mavenPomMock);
    final File somePomFile = new File(tmpDir.getTestDirectory(), "someDir/somePath");
    context.checking(new Expectations() {

        {
            allowing(mavenPomMock).getArtifactId();
            will(returnValue("artifactId"));
            oneOf(mavenPomMock).writeTo(with(any(FileOutputStream.class)));
        }
    });
    PublishArtifact artifact = artifactPom.writePom(somePomFile);
    assertThat(artifact.getName(), equalTo("artifactId"));
    assertThat(artifact.getType(), equalTo("pom"));
    assertThat(artifact.getExtension(), equalTo("pom"));
    assertThat(artifact.getClassifier(), nullValue());
    assertThat(artifact.getFile(), equalTo(somePomFile));
}
Also used : Expectations(org.jmock.Expectations) DefaultMavenPom(org.gradle.api.publication.maven.internal.pom.DefaultMavenPom) MavenPom(org.gradle.api.artifacts.maven.MavenPom) FileOutputStream(java.io.FileOutputStream) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) File(java.io.File) Test(org.junit.Test)

Example 17 with PublishArtifact

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

the class DefaultArtifactPomTest method pomWithClassifierArtifactsOnly.

@Test
public void pomWithClassifierArtifactsOnly() {
    File classifierFile = new File("someClassifierFile");
    Artifact classifierArtifact = createTestArtifact("someName", "javadoc", "zip");
    artifactPom.addArtifact(classifierArtifact, classifierFile);
    assertThat(artifactPom.getArtifact(), nullValue());
    PublishArtifact artifact = singleItem(artifactPom.getAttachedArtifacts());
    assertThat(artifact.getName(), equalTo("someName"));
    assertThat(artifact.getExtension(), equalTo("zip"));
    assertThat(artifact.getType(), equalTo("zip"));
    assertThat(artifact.getClassifier(), equalTo("javadoc"));
    assertThat(artifact.getFile(), equalTo(classifierFile));
    assertThat(artifactPom.getPom().getGroupId(), equalTo("org"));
    assertThat(artifactPom.getPom().getArtifactId(), equalTo("someName"));
    assertThat(artifactPom.getPom().getVersion(), equalTo("1.0"));
    assertThat(artifactPom.getPom().getPackaging(), equalTo("jar"));
}
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)

Example 18 with PublishArtifact

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

the class DefaultArtifactPublisher method addConfigurations.

private void addConfigurations(DefaultIvyModulePublishMetadata metaData, Collection<? extends ConfigurationInternal> configurations, boolean validateArtifacts) {
    for (ConfigurationInternal configuration : configurations) {
        BuildableLocalConfigurationMetadata configurationMetadata = addConfiguration(metaData, configuration);
        dependenciesConverter.addDependenciesAndExcludes(configurationMetadata, configuration);
        OutgoingVariant outgoingVariant = configuration.convertToOutgoingVariant();
        for (PublishArtifact publishArtifact : outgoingVariant.getArtifacts()) {
            if (!validateArtifacts || isValidToPublish(publishArtifact)) {
                metaData.addArtifact(configuration.getName(), publishArtifact);
            }
        }
    }
}
Also used : OutgoingVariant(org.gradle.api.internal.artifacts.configurations.OutgoingVariant) BuildableLocalConfigurationMetadata(org.gradle.internal.component.local.model.BuildableLocalConfigurationMetadata) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) ConfigurationInternal(org.gradle.api.internal.artifacts.configurations.ConfigurationInternal)

Example 19 with PublishArtifact

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

the class DefaultLocalComponentMetadata method addArtifacts.

@Override
public void addArtifacts(String configuration, Iterable<? extends PublishArtifact> artifacts) {
    for (PublishArtifact artifact : artifacts) {
        LocalComponentArtifactMetadata artifactMetadata = new PublishArtifactLocalArtifactMetadata(componentId, artifact);
        allArtifacts.put(configuration, artifactMetadata);
    }
}
Also used : PublishArtifact(org.gradle.api.artifacts.PublishArtifact)

Example 20 with PublishArtifact

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

the class DefaultLocalComponentMetadata method addVariant.

@Override
public void addVariant(String configuration, OutgoingVariant variant) {
    List<LocalComponentArtifactMetadata> artifacts;
    if (variant.getArtifacts().isEmpty()) {
        artifacts = ImmutableList.of();
    } else {
        ImmutableList.Builder<LocalComponentArtifactMetadata> builder = ImmutableList.builder();
        for (PublishArtifact artifact : variant.getArtifacts()) {
            builder.add(new PublishArtifactLocalArtifactMetadata(componentId, artifact));
        }
        artifacts = builder.build();
    }
    allVariants.put(configuration, new DefaultVariantMetadata(variant.asDescribable(), variant.getAttributes().asImmutable(), artifacts, null));
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) DefaultVariantMetadata(org.gradle.internal.component.model.DefaultVariantMetadata)

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