org.gradle.api.artifacts.PublishArtifact Java Examples

The following examples show how to use org.gradle.api.artifacts.PublishArtifact. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultMavenPublication.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void from(SoftwareComponent component) {
    if (this.component != null) {
        throw new InvalidUserDataException(String.format("Maven publication '%s' cannot include multiple components", name));
    }
    this.component = (SoftwareComponentInternal) component;

    for (Usage usage : this.component.getUsages()) {
        // TODO Need a smarter way to map usage to artifact classifier
        for (PublishArtifact publishArtifact : usage.getArtifacts()) {
            artifact(publishArtifact);
        }

        // TODO Need a smarter way to map usage to scope
        for (ModuleDependency dependency : usage.getDependencies()) {
            if (dependency instanceof ProjectDependency) {
                addProjectDependency((ProjectDependency) dependency);
            } else {
                addModuleDependency(dependency);
            }
        }
    }
}
 
Example #2
Source File: DefaultMavenPublication.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void from(SoftwareComponent component) {
    if (this.component != null) {
        throw new InvalidUserDataException(String.format("Maven publication '%s' cannot include multiple components", name));
    }
    this.component = (SoftwareComponentInternal) component;

    for (Usage usage : this.component.getUsages()) {
        // TODO Need a smarter way to map usage to artifact classifier
        for (PublishArtifact publishArtifact : usage.getArtifacts()) {
            artifact(publishArtifact);
        }

        // TODO Need a smarter way to map usage to scope
        for (ModuleDependency dependency : usage.getDependencies()) {
            if (dependency instanceof ProjectDependency) {
                addProjectDependency((ProjectDependency) dependency);
            } else {
                addModuleDependency(dependency);
            }
        }
    }
}
 
Example #3
Source File: MavenArtifactNotationParserFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public NotationParser<Object, MavenArtifact> create() {
    FileNotationParser fileNotationParser = new FileNotationParser(fileResolver);
    ArchiveTaskNotationParser archiveTaskNotationParser = new ArchiveTaskNotationParser();
    PublishArtifactNotationParser publishArtifactNotationParser = new PublishArtifactNotationParser();

    NotationParser<Object, MavenArtifact> sourceNotationParser = NotationParserBuilder
            .toType(MavenArtifact.class)
            .fromType(AbstractArchiveTask.class, archiveTaskNotationParser)
            .fromType(PublishArtifact.class, publishArtifactNotationParser)
            .converter(fileNotationParser)
            .toComposite();

    MavenArtifactMapNotationParser mavenArtifactMapNotationParser = new MavenArtifactMapNotationParser(sourceNotationParser);

    NotationParserBuilder<MavenArtifact> parserBuilder = NotationParserBuilder
            .toType(MavenArtifact.class)
            .fromType(AbstractArchiveTask.class, archiveTaskNotationParser)
            .fromType(PublishArtifact.class, publishArtifactNotationParser)
            .parser(mavenArtifactMapNotationParser)
            .converter(fileNotationParser);

    return parserBuilder.toComposite();
}
 
Example #4
Source File: AbstractMavenResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void addPomAndArtifact(InstallDeployTaskSupport installOrDeployTask, MavenDeployment mavenDeployment) {
    Pom pom = new Pom();
    pom.setProject(installOrDeployTask.getProject());
    pom.setFile(mavenDeployment.getPomArtifact().getFile());
    installOrDeployTask.addPom(pom);
    if (mavenDeployment.getMainArtifact() != null) {
        installOrDeployTask.setFile(mavenDeployment.getMainArtifact().getFile());
    }
    for (PublishArtifact classifierArtifact : mavenDeployment.getAttachedArtifacts()) {
        AttachedArtifact attachedArtifact = installOrDeployTask.createAttach();
        attachedArtifact.setClassifier(classifierArtifact.getClassifier());
        attachedArtifact.setFile(classifierArtifact.getFile());
        attachedArtifact.setType(classifierArtifact.getType());
    }
}
 
Example #5
Source File: MavenArtifactNotationParserFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected MavenArtifact parseType(PublishArtifact publishArtifact) {
    DefaultMavenArtifact artifact = instantiator.newInstance(
            DefaultMavenArtifact.class,
            publishArtifact.getFile(), publishArtifact.getExtension(), publishArtifact.getClassifier());
    artifact.builtBy(publishArtifact.getBuildDependencies());
    return artifact;
}
 
Example #6
Source File: PublishArtifactToFileBuildOutcomeTransformer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private String getTypeIdentifier(PublishArtifact artifact) {
    if (artifact instanceof ArchivePublishArtifact) {
        ArchivePublishArtifact publishArtifact = (ArchivePublishArtifact) artifact;
        AbstractArchiveTask task = publishArtifact.getArchiveTask();

        // There is an inheritance hierarchy in play here, so the order
        // of the clauses is very important.

        if (task instanceof War) {
            return WAR_ARTIFACT.getTypeIdentifier();
        } else if (task instanceof Ear) {
            return EAR_ARTIFACT.getTypeIdentifier();
        } else if (task instanceof Jar) {
            return JAR_ARTIFACT.getTypeIdentifier();
        } else if (task instanceof Zip) {
            return ZIP_ARTIFACT.getTypeIdentifier();
        } else if (task instanceof Tar) {
            return TAR_ARTIFACT.getTypeIdentifier();
        } else {
            // we don't know about this kind of archive task
            return ARCHIVE_ARTIFACT.getTypeIdentifier();
        }
    } else {
        // This could very well be a zip (or something else we understand), but we can't know for sure.
        // The client may try to infer from the file extension.
        return UNKNOWN_ARTIFACT.getTypeIdentifier();
    }
}
 
Example #7
Source File: PublishArtifactToFileBuildOutcomeTransformer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public GradleFileBuildOutcome transform(PublishArtifact artifact, Project project) {
    String id = getId(artifact, project);
    String taskPath = getTaskPath(artifact);
    String description = getDescription(artifact);
    String typeIdentifier = getTypeIdentifier(artifact);

    return new DefaultGradleFileBuildOutcome(id, description, taskPath, artifact.getFile(), typeIdentifier);
}
 
Example #8
Source File: DefaultArtifactPom.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void addArtifact(Artifact artifact, File src) {
    throwExceptionIfArtifactOrSrcIsNull(artifact, src);
    PublishArtifact publishArtifact = new MavenArtifact(artifact, src);
    ArtifactKey artifactKey = new ArtifactKey(publishArtifact);
    if (this.artifacts.containsKey(artifactKey)) {
        throw new InvalidUserDataException(String.format("A POM cannot have multiple artifacts with the same type and classifier. Already have %s, trying to add %s.", this.artifacts.get(
                artifactKey), publishArtifact));
    }

    if (publishArtifact.getClassifier() != null) {
        addArtifact(publishArtifact);
        assignArtifactValuesToPom(artifact, pom, false);
        return;
    }

    if (this.artifact != null) {
        // Choose the 'main' artifact based on its type.
        if (!PACKAGING_TYPES.contains(artifact.getType())) {
            addArtifact(publishArtifact);
            return;
        }
        if (PACKAGING_TYPES.contains(this.artifact.getType())) {
            throw new InvalidUserDataException("A POM can not have multiple main artifacts. " + "Already have " + this.artifact + ", trying to add " + publishArtifact);
        }
        addArtifact(this.artifact);
    }

    this.artifact = publishArtifact;
    this.artifacts.put(artifactKey, publishArtifact);
    assignArtifactValuesToPom(artifact, pom, true);
}
 
Example #9
Source File: PublishArtifactToFileBuildOutcomeTransformer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private String getId(PublishArtifact artifact, Project project) {
    // Assume that each artifact points to a unique file, and use the relative path from the project as the id
    URI artifactUri = artifact.getFile().toURI();
    URI projectDirUri = project.getProjectDir().toURI();
    URI relativeUri = projectDirUri.relativize(artifactUri);
    return relativeUri.getPath();
}
 
Example #10
Source File: PublishArtifactToFileBuildOutcomeTransformer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public GradleFileBuildOutcome transform(PublishArtifact artifact, Project project) {
    String id = getId(artifact, project);
    String taskPath = getTaskPath(artifact);
    String description = getDescription(artifact);
    String typeIdentifier = getTypeIdentifier(artifact);

    return new DefaultGradleFileBuildOutcome(id, description, taskPath, artifact.getFile(), typeIdentifier);
}
 
Example #11
Source File: DefaultIvyPublication.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void from(SoftwareComponent component) {
    if (this.component != null) {
        throw new InvalidUserDataException(String.format("Ivy publication '%s' cannot include multiple components", name));
    }
    this.component = (SoftwareComponentInternal) component;

    configurations.maybeCreate("default");

    for (Usage usage : this.component.getUsages()) {
        String conf = usage.getName();
        configurations.maybeCreate(conf);
        configurations.getByName("default").extend(conf);

        for (PublishArtifact publishArtifact : usage.getArtifacts()) {
            artifact(publishArtifact).setConf(conf);
        }

        for (ModuleDependency dependency : usage.getDependencies()) {
            // TODO: When we support multiple components or configurable dependencies, we'll need to merge the confs of multiple dependencies with same id.
            String confMapping = String.format("%s->%s", conf, dependency.getConfiguration());
            if (dependency instanceof ProjectDependency) {
                addProjectDependency((ProjectDependency) dependency, confMapping);
            } else {
                addModuleDependency(dependency, confMapping);
            }
        }
    }
}
 
Example #12
Source File: DefaultPublishArtifactSet.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Set<File> getFiles() {
    Set<File> files = new LinkedHashSet<File>();
    for (PublishArtifact artifact : DefaultPublishArtifactSet.this) {
        files.add(artifact.getFile());
    }
    return files;
}
 
Example #13
Source File: DefaultMavenDeployment.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Set<PublishArtifact> getArtifacts() {
    Set<PublishArtifact> artifacts = new HashSet<PublishArtifact>();
    artifacts.addAll(attachedArtifacts);
    if (mainArtifact != null) {
        artifacts.add(mainArtifact);
    }
    artifacts.add(pomArtifact);
    return artifacts;
}
 
Example #14
Source File: MavenArtifactNotationParserFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void convert(PublishArtifact publishArtifact, NotationConvertResult<? super MavenArtifact> result) throws TypeConversionException {
    DefaultMavenArtifact artifact = instantiator.newInstance(
            DefaultMavenArtifact.class,
            publishArtifact.getFile(), publishArtifact.getExtension(), publishArtifact.getClassifier());
    artifact.builtBy(publishArtifact.getBuildDependencies());
    result.converted(artifact);
}
 
Example #15
Source File: PublishArtifactToFileBuildOutcomeTransformer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private String getId(PublishArtifact artifact, Project project) {
    // Assume that each artifact points to a unique file, and use the relative path from the project as the id
    URI artifactUri = artifact.getFile().toURI();
    URI projectDirUri = project.getProjectDir().toURI();
    URI relativeUri = projectDirUri.relativize(artifactUri);
    return relativeUri.getPath();
}
 
Example #16
Source File: DefaultArtifactPomContainer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Set<MavenDeployment> createDeployableFilesInfos() {
    Set<MavenDeployment> mavenDeployments = new HashSet<MavenDeployment>();
    for (String activeArtifactPomName : artifactPoms.keySet()) {
        ArtifactPom activeArtifactPom = artifactPoms.get(activeArtifactPomName);
        File pomFile = createPomFile(activeArtifactPomName);
        PublishArtifact pomArtifact = activeArtifactPom.writePom(pomFile);
        mavenDeployments.add(new DefaultMavenDeployment(pomArtifact, activeArtifactPom.getArtifact(), activeArtifactPom.getAttachedArtifacts()));
    }
    return mavenDeployments;
}
 
Example #17
Source File: PublishArtifactToFileBuildOutcomeTransformer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public GradleFileBuildOutcome transform(PublishArtifact artifact, Project project) {
    String id = getId(artifact, project);
    String taskPath = getTaskPath(artifact);
    String description = getDescription(artifact);
    String typeIdentifier = getTypeIdentifier(artifact);

    return new DefaultGradleFileBuildOutcome(id, description, taskPath, artifact.getFile(), typeIdentifier);
}
 
Example #18
Source File: MavenArtifactNotationParserFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void convert(PublishArtifact publishArtifact, NotationConvertResult<? super MavenArtifact> result) throws TypeConversionException {
    DefaultMavenArtifact artifact = instantiator.newInstance(
            DefaultMavenArtifact.class,
            publishArtifact.getFile(), publishArtifact.getExtension(), publishArtifact.getClassifier());
    artifact.builtBy(publishArtifact.getBuildDependencies());
    result.converted(artifact);
}
 
Example #19
Source File: AbstractMavenResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void addPomAndArtifact(InstallDeployTaskSupport installOrDeployTask, MavenDeployment mavenDeployment) {
    Pom pom = new Pom();
    pom.setProject(installOrDeployTask.getProject());
    pom.setFile(mavenDeployment.getPomArtifact().getFile());
    installOrDeployTask.addPom(pom);
    if (mavenDeployment.getMainArtifact() != null) {
        installOrDeployTask.setFile(mavenDeployment.getMainArtifact().getFile());
    }
    for (PublishArtifact classifierArtifact : mavenDeployment.getAttachedArtifacts()) {
        AttachedArtifact attachedArtifact = installOrDeployTask.createAttach();
        attachedArtifact.setClassifier(classifierArtifact.getClassifier());
        attachedArtifact.setFile(classifierArtifact.getFile());
        attachedArtifact.setType(classifierArtifact.getType());
    }
}
 
Example #20
Source File: PlayApplicationPlugin.java    From playframework with Apache License 2.0 5 votes vote down vote up
private void registerOutgoingArtifact(Project project, TaskProvider<Jar> assetsJarTask) {
    Configuration runtimeElementsConfiguration = project.getConfigurations().getByName(RUNTIME_ELEMENTS_CONFIGURATION_NAME);
    PublishArtifact jarArtifact = new LazyPublishArtifact(assetsJarTask);
    ConfigurationPublications publications = runtimeElementsConfiguration.getOutgoing();
    publications.getArtifacts().add(jarArtifact);
    publications.getAttributes().attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.JAR_TYPE);
}
 
Example #21
Source File: PublishArtifactNotationParserFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public NotationParser<Object, PublishArtifact> create() {
    FileNotationParser fileParser = new FileNotationParser();
    return NotationParserBuilder
            .toType(PublishArtifact.class)
            .parser(new ArchiveTaskNotationParser())
            .parser(new FileMapNotationParser(fileParser))
            .parser(fileParser)
            .toComposite();
}
 
Example #22
Source File: PublishArtifactToFileBuildOutcomeTransformer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private String getTaskPath(PublishArtifact artifact) {
    if (artifact instanceof ArchivePublishArtifact) {
        return ((ArchivePublishArtifact) artifact).getArchiveTask().getPath();
    } else {
        String taskPath = null;
        Set<? extends Task> tasks = artifact.getBuildDependencies().getDependencies(null);
        if (!tasks.isEmpty()) {
            taskPath = tasks.iterator().next().getPath();
        }
        return taskPath;
    }
}
 
Example #23
Source File: PublishArtifactNotationParserFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected PublishArtifact parseType(File file) {
    Module module = metaDataProvider.getModule();
    ArtifactFile artifactFile = new ArtifactFile(file, module.getVersion());
    return instantiator.newInstance(DefaultPublishArtifact.class, artifactFile.getName(), artifactFile.getExtension(),
                                    artifactFile.getExtension() == null? "":artifactFile.getExtension(),
                                    artifactFile.getClassifier(), null, file, new Task[0]);
}
 
Example #24
Source File: DefaultConfigurationsToArtifactsConverter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void addArtifacts(MutableLocalComponentMetaData metaData, Iterable<? extends Configuration> configurations) {
    ModuleVersionIdentifier id = metaData.getId();
    for (Configuration configuration : configurations) {
        for (PublishArtifact publishArtifact : configuration.getArtifacts()) {
            IvyArtifactName ivyArtifact = createIvyArtifact(publishArtifact, id);
            metaData.addArtifact(configuration.getName(), ivyArtifact, publishArtifact.getFile());
        }
    }
}
 
Example #25
Source File: MavenArtifactNotationParserFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected MavenArtifact parseType(PublishArtifact publishArtifact) {
    DefaultMavenArtifact artifact = instantiator.newInstance(
            DefaultMavenArtifact.class,
            publishArtifact.getFile(), publishArtifact.getExtension(), publishArtifact.getClassifier());
    artifact.builtBy(publishArtifact.getBuildDependencies());
    return artifact;
}
 
Example #26
Source File: PublishArtifactToFileBuildOutcomeTransformer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private String getTaskPath(PublishArtifact artifact) {
    if (artifact instanceof ArchivePublishArtifact) {
        return ((ArchivePublishArtifact) artifact).getArchiveTask().getPath();
    } else {
        String taskPath = null;
        Set<? extends Task> tasks = artifact.getBuildDependencies().getDependencies(null);
        if (!tasks.isEmpty()) {
            taskPath = tasks.iterator().next().getPath();
        }
        return taskPath;
    }
}
 
Example #27
Source File: PublishArtifactNotationParserFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public NotationParser<Object, PublishArtifact> create() {
    FileNotationParser fileParser = new FileNotationParser();
    return NotationParserBuilder
            .toType(PublishArtifact.class)
            .parser(new ArchiveTaskNotationParser())
            .parser(new FileMapNotationParser(fileParser))
            .parser(fileParser)
            .toComposite();
}
 
Example #28
Source File: DefaultPublishArtifactSet.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultPublishArtifactSet(String displayName, DomainObjectSet<PublishArtifact> backingSet) {
    super(backingSet);
    this.displayName = displayName;
}
 
Example #29
Source File: PublishArtifactNotationParserFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected PublishArtifact parseMap(@MapKey("file") File file) {
    return fileParser.parseType(file);
}
 
Example #30
Source File: DefaultMavenDeployment.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void addArtifact(PublishArtifact artifact) {
    attachedArtifacts.add(artifact);
}