@Override @SuppressWarnings("unchecked") public DefaultLibraryLocalComponentMetadata createLocalComponentMetaData(Binary selectedBinary, String projectPath, boolean toAssembly) { EnumMap<UsageKind, Iterable<DependencySpec>> dependenciesPerUsage = new EnumMap<UsageKind, Iterable<DependencySpec>>(UsageKind.class); EnumMap<UsageKind, List<PublishArtifact>> artifacts = new EnumMap<UsageKind, List<PublishArtifact>>(UsageKind.class); initializeUsages(dependenciesPerUsage, artifacts); if (selectedBinary instanceof JarBinarySpecInternal) { JarBinarySpecInternal jarBinarySpec = (JarBinarySpecInternal) selectedBinary; createJarBinarySpecLocalComponentMetaData(artifacts, jarBinarySpec, dependenciesPerUsage, toAssembly); } if (selectedBinary instanceof WithJvmAssembly) { // a local component that provides a JVM assembly JvmAssembly assembly = ((WithJvmAssembly) selectedBinary).getAssembly(); createJvmAssemblyLocalComponentMetaData(artifacts, assembly, dependenciesPerUsage, toAssembly); } return createResolvedMetaData((BinarySpecInternal) selectedBinary, projectPath, dependenciesPerUsage, artifacts); }
@SuppressWarnings("unchecked") private void createJarBinarySpecLocalComponentMetaData(EnumMap<UsageKind, List<PublishArtifact>> artifacts, JarBinarySpecInternal jarBinarySpec, EnumMap<UsageKind, Iterable<DependencySpec>> dependenciesPerUsage, boolean toAssembly) { JarFile apiJar = jarBinarySpec.getApiJar(); configureUsageMetadata(UsageKind.API, jarBinarySpec.getApiDependencies(), dependenciesPerUsage); JarFile runtimeJar = jarBinarySpec.getRuntimeJar(); JvmLibrarySpec library = jarBinarySpec.getLibrary(); configureUsageMetadata(UsageKind.RUNTIME, library != null ? collectDependencies(jarBinarySpec, library, library.getDependencies().getDependencies(), jarBinarySpec.getApiDependencies()) : Collections.<DependencySpec>emptyList(), dependenciesPerUsage); if (!toAssembly) { addArtifact(UsageKind.API, apiJar, artifacts); addArtifact(UsageKind.RUNTIME, runtimeJar, artifacts); } }
private void createJvmAssemblyLocalComponentMetaData(EnumMap<UsageKind, List<PublishArtifact>> artifacts, JvmAssembly assembly, EnumMap<UsageKind, Iterable<DependencySpec>> dependenciesPerUsage, boolean toAssembly) { configureUsageMetadata(UsageKind.API, Collections.<DependencySpec>emptyList(), dependenciesPerUsage); configureUsageMetadata(UsageKind.RUNTIME, Collections.<DependencySpec>emptyList(), dependenciesPerUsage); if (toAssembly) { // TODO:Cedric This is an approximation: when a component wants to compile against the assembly of // a library (not the jar), then we should give it the *stubbed classes* instead of the raw classes. However: // - there's no such thing as a "stubbed classes assembly" // - for performance reasons only the classes that belong to the API are stubbed, so we would miss the classes that do not belong to the API // So this makes the UsageKind.API misleading (should this be COMPILE?). addArtifact(UsageKind.API, assembly.getClassDirectories(), artifacts, assembly); addArtifact(UsageKind.RUNTIME, Sets.union(assembly.getClassDirectories(), assembly.getResourceDirectories()), artifacts, assembly); } }
public NotationParser<Object, MavenArtifact> create() { FileNotationConverter fileNotationConverter = new FileNotationConverter(fileResolver); ArchiveTaskNotationConverter archiveTaskNotationConverter = new ArchiveTaskNotationConverter(); PublishArtifactNotationConverter publishArtifactNotationConverter = new PublishArtifactNotationConverter(); NotationParser<Object, MavenArtifact> sourceNotationParser = NotationParserBuilder .toType(MavenArtifact.class) .fromType(AbstractArchiveTask.class, archiveTaskNotationConverter) .fromType(PublishArtifact.class, publishArtifactNotationConverter) .converter(fileNotationConverter) .toComposite(); MavenArtifactMapNotationConverter mavenArtifactMapNotationConverter = new MavenArtifactMapNotationConverter(sourceNotationParser); NotationParserBuilder<MavenArtifact> parserBuilder = NotationParserBuilder .toType(MavenArtifact.class) .fromType(AbstractArchiveTask.class, archiveTaskNotationConverter) .fromType(PublishArtifact.class, publishArtifactNotationConverter) .converter(mavenArtifactMapNotationConverter) .converter(fileNotationConverter); return parserBuilder.toComposite(); }
public OutgoingVariant convertToOutgoingVariant() { return new OutgoingVariant() { @Override public AttributeContainerInternal getAttributes() { return parentAttributes; } @Override public Set<? extends PublishArtifact> getArtifacts() { return artifacts; } @Override public Set<? extends OutgoingVariant> getChildren() { if (variants == null || variants.isEmpty()) { return ImmutableSet.of(); } Set<OutgoingVariant> result = new LinkedHashSet<OutgoingVariant>(variants.size()); for (DefaultVariant variant : variants.withType(DefaultVariant.class)) { result.add(variant.convertToOutgoingVariant()); } return result; } }; }
public OutgoingVariant convertToOutgoingVariant() { return new OutgoingVariant() { @Override public AttributeContainerInternal getAttributes() { return attributes; } @Override public Set<? extends PublishArtifact> getArtifacts() { return artifacts; } @Override public Set<? extends OutgoingVariant> getChildren() { return ImmutableSet.of(); } }; }
public void addCandidate(PublishArtifact artifact) { if (defaultArtifact == null) { artifacts.add(artifact); defaultArtifact = artifact; return; } String thisType = artifact.getType(); String currentType = defaultArtifact.getType(); if (thisType.equals("ear")) { replaceCurrent(artifact); } else if (thisType.equals("war")) { if (currentType.equals("jar")) { replaceCurrent(artifact); } } else if (!thisType.equals("jar")) { artifacts.add(artifact); } }
/** * @see me.seeber.gradle.plugin.AbstractProjectConfigPlugin#initialize() */ @Override protected void initialize() { getProject().getPluginManager().apply(GroovyPlugin.class); getProject().getPluginManager().apply(JavaConfigPlugin.class); DependencyHandler dependencies = getProject().getDependencies(); ExternalDependency spock = (ExternalDependency) dependencies.add("testCompile", ImmutableMap.of("group", "org.spockframework", "name", "spock-core", "version", "1.0-groovy-2.4")); spock.exclude(ImmutableMap.of("group", "org.codehaus.groovy", "module", "groovy-all")); String name = Validate.notNull(getProject().getName()); Configuration archives = getProject().getConfigurations().getByName("archives"); Jar groovydocJar = getProject().getTasks().create("groovydocJar", Jar.class); PublishArtifact groovydocArtifact = Projects.createJarPublishArtifact(getProject(), name, "groovydoc", "jar", "jar", groovydocJar); archives.getArtifacts().add(groovydocArtifact); }
/** * Search a collection of projects for a publish artifact * * @param projects Projects to search * @param configurationPredicate Predicate to test configurations * @param artifactPredicate Predicate to test artifacts * @return Found element or empty value */ public static Optional<ProjectElement<PublishArtifact>> findPublishArtifact(Collection<@NonNull Project> projects, Predicate<@NonNull Configuration> configurationPredicate, Predicate<@NonNull PublishArtifact> artifactPredicate) { Optional<ProjectElement<PublishArtifact>> info = Optional.empty(); for (Project project : projects) { info = findPublishArtifact(project, configurationPredicate, artifactPredicate); if (info.isPresent()) { break; } } return info; }
/** * Search a project for a publish artifact * * @param project Project to search * @param configurationPredicate Predicate to test configurations * @param artifactPredicate Predicate to test artifacts * @return Found element or empty value */ public static Optional<ProjectElement<PublishArtifact>> findPublishArtifact(Project project, Predicate<@NonNull Configuration> configurationPredicate, Predicate<@NonNull PublishArtifact> artifactPredicate) { Optional<ProjectElement<PublishArtifact>> info = Optional.empty(); for (@NonNull Configuration configuration : project.getConfigurations()) { if (configurationPredicate.test(configuration)) { info = findPublishArtifact(project, configuration, artifactPredicate); if (info.isPresent()) { break; } } } return info; }
@TaskAction protected void deployProject() { Set<PublishArtifact> seenArtifacts = new HashSet<>(); for ( SoftwareComponent component : getProject().getComponents() ) { SoftwareComponentInternal internalComponent = (SoftwareComponentInternal) component; for ( UsageContext usage : internalComponent.getUsages() ) { Set<? extends ModuleDependency> dependencies = usage.getDependencies(); for ( PublishArtifact artifact : usage.getArtifacts() ) { if ( seenArtifacts.add( artifact ) ) { deploy( artifact, dependencies ); } } } } }
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); } } } }
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(); }
public Artifact createIvyArtifact(PublishArtifact publishArtifact, ModuleRevisionId moduleRevisionId) { Map<String, String> extraAttributes = new HashMap<String, String>(); if (GUtil.isTrue(publishArtifact.getClassifier())) { extraAttributes.put(Dependency.CLASSIFIER, publishArtifact.getClassifier()); } String name = publishArtifact.getName(); if (!GUtil.isTrue(name)) { name = moduleRevisionId.getName(); } return new DefaultArtifact( moduleRevisionId, publishArtifact.getDate(), name, publishArtifact.getType(), publishArtifact.getExtension(), extraAttributes); }
private DefaultLibraryLocalComponentMetadata createResolvedMetaData(BinarySpecInternal selectedBinary, String projectPath, EnumMap<UsageKind, Iterable<DependencySpec>> dependenciesPerUsage, EnumMap<UsageKind, List<PublishArtifact>> artifacts) { DefaultLibraryLocalComponentMetadata metadata = newResolvedLibraryMetadata(selectedBinary.getId(), toStringMap(dependenciesPerUsage), projectPath); for (Map.Entry<UsageKind, List<PublishArtifact>> entry : artifacts.entrySet()) { UsageKind usage = entry.getKey(); List<PublishArtifact> publishArtifacts = entry.getValue(); metadata.addArtifacts(usage.getConfigurationName(), publishArtifacts); } return metadata; }
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); } }
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); }
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; }
private void addArtifacts(MavenPublishAction publishAction, MavenDeployment mavenDeployment) { if (mavenDeployment.getMainArtifact() != null) { publishAction.setMainArtifact(mavenDeployment.getMainArtifact().getFile()); } for (PublishArtifact classifierArtifact : mavenDeployment.getAttachedArtifacts()) { publishAction.addAdditionalArtifact(classifierArtifact.getFile(), classifierArtifact.getType(), classifierArtifact.getClassifier()); } }
public Set<PublishArtifact> getArtifacts() { Set<PublishArtifact> artifacts = new HashSet<PublishArtifact>(); artifacts.addAll(attachedArtifacts); if (mainArtifact != null) { artifacts.add(mainArtifact); } artifacts.add(pomArtifact); return artifacts; }
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); }
@Override public void addArtifacts(String configuration, Iterable<? extends PublishArtifact> artifacts) { for (PublishArtifact artifact : artifacts) { LocalComponentArtifactMetadata artifactMetadata = new PublishArtifactLocalArtifactMetadata(componentIdentifier, artifact); addArtifact(configuration, artifactMetadata); } }
@Override public void addVariant(String configuration, OutgoingVariant variant) { Set<LocalComponentArtifactMetadata> artifacts; if (variant.getArtifacts().isEmpty()) { artifacts = ImmutableSet.of(); } else { ImmutableSet.Builder<LocalComponentArtifactMetadata> builder = ImmutableSet.builder(); for (PublishArtifact artifact : variant.getArtifacts()) { builder.add(new PublishArtifactLocalArtifactMetadata(componentIdentifier, artifact)); } artifacts = builder.build(); } allVariants.put(configuration, new DefaultVariantMetadata(variant.getAttributes().asImmutable(), artifacts)); }
public static DefaultIvyArtifactName forPublishArtifact(PublishArtifact publishArtifact) { String name = publishArtifact.getName(); if (name == null) { name = publishArtifact.getFile().getName(); } String classifier = GUtil.elvis(publishArtifact.getClassifier(), null); return new DefaultIvyArtifactName(name, publishArtifact.getType(), publishArtifact.getExtension(), classifier); }
@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); } }
private void addArtifacts(Project project, List<GradleFileBuildOutcome> outcomes) { Configuration configuration = project.getConfigurations().findByName(Dependency.ARCHIVES_CONFIGURATION); if (configuration != null) { for (PublishArtifact artifact : configuration.getArtifacts()) { GradleFileBuildOutcome outcome = artifactTransformer.transform(artifact, project); outcomes.add(outcome); } } }
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); }
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(); }
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(); } }
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; } }
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.getTargetConfiguration() == null ? Dependency.DEFAULT_CONFIGURATION : dependency.getTargetConfiguration()); if (dependency instanceof ProjectDependency) { addProjectDependency((ProjectDependency) dependency, confMapping); } else { addModuleDependency(dependency, confMapping); } } } }
@Override protected IvyArtifact parseType(PublishArtifact publishArtifact) { DefaultIvyArtifact ivyArtifact = createDefaultIvyArtifact( publishArtifact.getFile(), publishArtifact.getExtension(), publishArtifact.getType(), publishArtifact.getClassifier()); ivyArtifact.builtBy(publishArtifact.getBuildDependencies()); return ivyArtifact; }
private static LocalComponentArtifactMetadata createArtifact(String extension, ProjectComponentIdentifier projectId, String projectName, Project project) { File projectFile = new File(project.getProjectDir(), "." + extension); Task byName = project.getTasks().getByName("eclipseProject"); String type = "eclipse." + extension; PublishArtifact publishArtifact = new DefaultPublishArtifact(projectName, extension, type, null, null, projectFile, byName); return new PublishArtifactLocalArtifactMetadata(projectId, publishArtifact); }
private static LocalComponentArtifactMetadata createImlArtifact(ProjectComponentIdentifier projectId, Project project) { String moduleName = project.getExtensions().getByType(IdeaModel.class).getModule().getName(); File imlFile = new File(project.getProjectDir(), moduleName + ".iml"); Task byName = project.getTasks().getByName("ideaModule"); PublishArtifact publishArtifact = new DefaultPublishArtifact(moduleName, "iml", "iml", null, null, imlFile, byName); return new PublishArtifactLocalArtifactMetadata(projectId, publishArtifact); }
@Override public Set<File> getFiles() { Set<File> files = new LinkedHashSet<File>(); for (PublishArtifact artifact : DefaultPublishArtifactSet.this) { files.add(artifact.getFile()); } return files; }
/** * Registers signatures for the given artifacts. * * @return this * @see Signature#Signature(File, SignatureSpec, Object...) */ public SignOperation sign(PublishArtifact... artifacts) { for (PublishArtifact artifact : artifacts) { signatures.add(new Signature(artifact, this)); } return this; }
/** * Creates a signature artifact for the given public artifact. * * <p>The file to sign will be the file of the given artifact and the classifier of this signature artifact will default to the classifier of the given artifact to sign.</p> <p> The artifact to * sign may change after being used as the source for this signature.</p> * * @param toSign The artifact that is to be signed * @param signatureSpec The specification of how the artifact is to be signed * @param tasks The task(s) that will invoke {@link #generate()} on this signature (optional) */ public Signature(final PublishArtifact toSign, SignatureSpec signatureSpec, Object... tasks) { super(tasks); init(new Callable<File>() { public File call() { return toSign.getFile(); } }, new Callable<String>() { public String call() { return toSign.getClassifier(); } }, signatureSpec); this.toSignArtifact = toSign; }