org.apache.ivy.core.module.descriptor.MDArtifact Java Examples
The following examples show how to use
org.apache.ivy.core.module.descriptor.MDArtifact.
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: BuildableIvyModuleResolveMetaData.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public void addArtifact(IvyArtifactName newArtifact, Set<String> configurations) { if (configurations.isEmpty()) { throw new IllegalArgumentException("Artifact should be attached to at least one configuration."); } MDArtifact unattached = new MDArtifact(module, newArtifact.getName(), newArtifact.getType(), newArtifact.getExtension(), null, newArtifact.getAttributes()); //Adding the artifact will replace any existing artifact //This potentially leads to loss of information - the configurations of the replaced artifact are lost (see GRADLE-123) //Hence we attempt to find an existing artifact and merge the information Artifact[] allArtifacts = module.getAllArtifacts(); for (Artifact existing : allArtifacts) { // Can't just compare the raw IvyArtifactName, since creating MDArtifact creates a bunch of attributes if (artifactsEqual(unattached, existing)) { if (!(existing instanceof MDArtifact)) { throw new IllegalArgumentException("Cannot update an existing artifact (" + existing + ") in provided module descriptor (" + module + ")" + " because the artifact is not an instance of MDArtifact." + module); } attachArtifact((MDArtifact) existing, configurations, module); return; //there is only one matching artifact } } attachArtifact(unattached, configurations, module); }
Example #2
Source File: IvyNode.java From ant-ivy with Apache License 2.0 | 6 votes |
private void addArtifactsFromMergedUsage(String rootModuleConf, Set<Artifact> artifacts) { for (IvyNodeUsage usage : mergedUsages.values()) { Set<DependencyArtifactDescriptor> mergedDependencyArtifacts = usage .getDependencyArtifactsSet(rootModuleConf); if (mergedDependencyArtifacts != null) { for (DependencyArtifactDescriptor dad : mergedDependencyArtifacts) { Map<String, String> extraAttributes = new HashMap<>( dad.getQualifiedExtraAttributes()); MDArtifact artifact = new MDArtifact(md, dad.getName(), dad.getType(), dad.getExt(), dad.getUrl(), extraAttributes); if (!artifacts.contains(artifact)) { // this is later used to know that this is a merged artifact extraAttributes.put("ivy:merged", dad.getDependencyDescriptor() .getParentRevisionId() + " -> " + usage.getNode().getId()); artifacts.add(artifact); } } } } }
Example #3
Source File: BuildableIvyModuleResolveMetaData.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
public void addArtifact(IvyArtifactName newArtifact, Set<String> configurations) { if (configurations.isEmpty()) { throw new IllegalArgumentException("Artifact should be attached to at least one configuration."); } MDArtifact unattached = new MDArtifact(module, newArtifact.getName(), newArtifact.getType(), newArtifact.getExtension(), null, newArtifact.getAttributes()); //Adding the artifact will replace any existing artifact //This potentially leads to loss of information - the configurations of the replaced artifact are lost (see GRADLE-123) //Hence we attempt to find an existing artifact and merge the information Artifact[] allArtifacts = module.getAllArtifacts(); for (Artifact existing : allArtifacts) { // Can't just compare the raw IvyArtifactName, since creating MDArtifact creates a bunch of attributes if (artifactsEqual(unattached, existing)) { if (!(existing instanceof MDArtifact)) { throw new IllegalArgumentException("Cannot update an existing artifact (" + existing + ") in provided module descriptor (" + module + ")" + " because the artifact is not an instance of MDArtifact." + module); } attachArtifact((MDArtifact) existing, configurations, module); return; //there is only one matching artifact } } attachArtifact(unattached, configurations, module); }
Example #4
Source File: IvyNode.java From ant-ivy with Apache License 2.0 | 5 votes |
private void addArtifactsFromOwnUsage(Set<Artifact> artifacts, Set<DependencyArtifactDescriptor> dependencyArtifacts) { for (DependencyArtifactDescriptor dad : dependencyArtifacts) { artifacts.add(new MDArtifact(md, dad.getName(), dad.getType(), dad.getExt(), dad .getUrl(), dad.getQualifiedExtraAttributes())); } }
Example #5
Source File: XmlModuleDescriptorParser.java From ant-ivy with Apache License 2.0 | 5 votes |
protected void artifactStarted(String qName, Attributes attributes) throws MalformedURLException { if (state == State.PUB) { // this is a published artifact String artName = settings.substitute(attributes.getValue("name")); if (artName == null) { artName = getMd().getModuleRevisionId().getName(); } String type = settings.substitute(attributes.getValue("type")); if (type == null) { type = "jar"; } String ext = settings.substitute(attributes.getValue("ext")); if (ext == null) { ext = type; } String url = settings.substitute(attributes.getValue("url")); artifact = new MDArtifact(getMd(), artName, type, ext, url == null ? null : new URL(url), ExtendableItemHelper.getExtraAttributes(settings, attributes, Arrays.asList("ext", "type", "name", "conf"))); String confs = settings.substitute(attributes.getValue("conf")); // only add confs if they are specified. if they aren't, endElement will // handle this // only if there are no conf defined in sub elements if (confs != null && confs.length() > 0) { String[] configs = "*".equals(confs) ? getMd().getConfigurationsNames() : splitToArray(confs); for (String config : configs) { artifact.addConfiguration(config); getMd().addArtifact(config, artifact); } } } else if (state == State.DEP) { // this is an artifact asked for a particular dependency addDependencyArtifacts(qName, attributes); } else if (validate) { addError("artifact tag found in invalid tag: " + state); } }
Example #6
Source File: IvyBackedArtifactPublisher.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public void publish(final Iterable<? extends PublicationAwareRepository> repositories, final ModuleInternal module, final Configuration configuration, final File descriptor) throws PublishException { ivyContextManager.withIvy(new Action<Ivy>() { public void execute(Ivy ivy) { Set<Configuration> allConfigurations = configuration.getAll(); Set<Configuration> configurationsToPublish = configuration.getHierarchy(); MutableLocalComponentMetaData componentMetaData = publishLocalComponentFactory.convert(allConfigurations, module); if (descriptor != null) { ModuleDescriptor moduleDescriptor = componentMetaData.getModuleDescriptor(); ivyModuleDescriptorWriter.write(moduleDescriptor, descriptor); } // Need to convert a second time, to determine which artifacts to publish (and yes, this isn't a great way to do things...) componentMetaData = publishLocalComponentFactory.convert(configurationsToPublish, module); BuildableIvyModulePublishMetaData publishMetaData = componentMetaData.toPublishMetaData(); if (descriptor != null) { Artifact artifact = MDArtifact.newIvyArtifact(componentMetaData.getModuleDescriptor()); publishMetaData.addArtifact(artifact, descriptor); } List<ModuleVersionPublisher> publishResolvers = new ArrayList<ModuleVersionPublisher>(); for (PublicationAwareRepository repository : repositories) { ModuleVersionPublisher publisher = repository.createPublisher(); publishResolvers.add(publisher); } dependencyPublisher.publish(publishResolvers, publishMetaData); } }); }
Example #7
Source File: IvyBackedArtifactPublisher.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public void publish(final Iterable<? extends PublicationAwareRepository> repositories, final ModuleInternal module, final Configuration configuration, final File descriptor) throws PublishException { ivyContextManager.withIvy(new Action<Ivy>() { public void execute(Ivy ivy) { Set<Configuration> allConfigurations = configuration.getAll(); Set<Configuration> configurationsToPublish = configuration.getHierarchy(); MutableLocalComponentMetaData componentMetaData = publishLocalComponentFactory.convert(allConfigurations, module); if (descriptor != null) { ModuleDescriptor moduleDescriptor = componentMetaData.getModuleDescriptor(); ivyModuleDescriptorWriter.write(moduleDescriptor, descriptor); } // Need to convert a second time, to determine which artifacts to publish (and yes, this isn't a great way to do things...) componentMetaData = publishLocalComponentFactory.convert(configurationsToPublish, module); BuildableModuleVersionPublishMetaData publishMetaData = componentMetaData.toPublishMetaData(); if (descriptor != null) { Artifact artifact = MDArtifact.newIvyArtifact(componentMetaData.getModuleDescriptor()); publishMetaData.addArtifact(artifact, descriptor); } List<ModuleVersionPublisher> publishResolvers = new ArrayList<ModuleVersionPublisher>(); for (PublicationAwareRepository repository : repositories) { ModuleVersionPublisher publisher = repository.createPublisher(); publisher.setSettings(ivy.getSettings()); publishResolvers.add(publisher); } dependencyPublisher.publish(publishResolvers, publishMetaData); } }); }
Example #8
Source File: BuildableIvyModuleResolveMetaData.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
private static void attachArtifact(MDArtifact artifact, Set<String> configurations, DefaultModuleDescriptor target) { //The existing artifact configurations will be first Set<String> existingConfigurations = newLinkedHashSet(asList(artifact.getConfigurations())); for (String c : configurations) { if (!existingConfigurations.contains(c)) { artifact.addConfiguration(c); target.addArtifact(c, artifact); } } }
Example #9
Source File: IvyBackedArtifactPublisher.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public void publish(final Iterable<? extends PublicationAwareRepository> repositories, final ModuleInternal module, final Configuration configuration, final File descriptor) throws PublishException { ivyContextManager.withIvy(new Action<Ivy>() { public void execute(Ivy ivy) { Set<Configuration> allConfigurations = configuration.getAll(); Set<Configuration> configurationsToPublish = configuration.getHierarchy(); MutableLocalComponentMetaData componentMetaData = publishLocalComponentFactory.convert(allConfigurations, module); if (descriptor != null) { ModuleDescriptor moduleDescriptor = componentMetaData.getModuleDescriptor(); ivyModuleDescriptorWriter.write(moduleDescriptor, descriptor); } // Need to convert a second time, to determine which artifacts to publish (and yes, this isn't a great way to do things...) componentMetaData = publishLocalComponentFactory.convert(configurationsToPublish, module); BuildableIvyModulePublishMetaData publishMetaData = componentMetaData.toPublishMetaData(); if (descriptor != null) { Artifact artifact = MDArtifact.newIvyArtifact(componentMetaData.getModuleDescriptor()); publishMetaData.addArtifact(artifact, descriptor); } List<ModuleVersionPublisher> publishResolvers = new ArrayList<ModuleVersionPublisher>(); for (PublicationAwareRepository repository : repositories) { ModuleVersionPublisher publisher = repository.createPublisher(); publishResolvers.add(publisher); } dependencyPublisher.publish(publishResolvers, publishMetaData); } }); }
Example #10
Source File: IvyBackedArtifactPublisher.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public void publish(final Iterable<? extends PublicationAwareRepository> repositories, final ModuleInternal module, final Configuration configuration, final File descriptor) throws PublishException { ivyContextManager.withIvy(new Action<Ivy>() { public void execute(Ivy ivy) { Set<Configuration> allConfigurations = configuration.getAll(); Set<Configuration> configurationsToPublish = configuration.getHierarchy(); MutableLocalComponentMetaData componentMetaData = publishLocalComponentFactory.convert(allConfigurations, module); if (descriptor != null) { ModuleDescriptor moduleDescriptor = componentMetaData.getModuleDescriptor(); ivyModuleDescriptorWriter.write(moduleDescriptor, descriptor); } // Need to convert a second time, to determine which artifacts to publish (and yes, this isn't a great way to do things...) componentMetaData = publishLocalComponentFactory.convert(configurationsToPublish, module); BuildableModuleVersionPublishMetaData publishMetaData = componentMetaData.toPublishMetaData(); if (descriptor != null) { Artifact artifact = MDArtifact.newIvyArtifact(componentMetaData.getModuleDescriptor()); publishMetaData.addArtifact(artifact, descriptor); } List<ModuleVersionPublisher> publishResolvers = new ArrayList<ModuleVersionPublisher>(); for (PublicationAwareRepository repository : repositories) { ModuleVersionPublisher publisher = repository.createPublisher(); publisher.setSettings(ivy.getSettings()); publishResolvers.add(publisher); } dependencyPublisher.publish(publishResolvers, publishMetaData); } }); }
Example #11
Source File: BuildableIvyModuleResolveMetaData.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
private static void attachArtifact(MDArtifact artifact, Set<String> configurations, DefaultModuleDescriptor target) { //The existing artifact configurations will be first Set<String> existingConfigurations = newLinkedHashSet(asList(artifact.getConfigurations())); for (String c : configurations) { if (!existingConfigurations.contains(c)) { artifact.addConfiguration(c); target.addArtifact(c, artifact); } } }
Example #12
Source File: PomModuleDescriptorBuilder.java From ant-ivy with Apache License 2.0 | 4 votes |
public Artifact getSourceArtifact() { return new MDArtifact(ivyModuleDescriptor, mrid.getName(), "source", "jar", null, Collections.singletonMap("m:classifier", "sources")); }
Example #13
Source File: PomModuleDescriptorBuilder.java From ant-ivy with Apache License 2.0 | 4 votes |
public Artifact getSrcArtifact() { return new MDArtifact(ivyModuleDescriptor, mrid.getName(), "source", "jar", null, Collections.singletonMap("m:classifier", "src")); }
Example #14
Source File: PomModuleDescriptorBuilder.java From ant-ivy with Apache License 2.0 | 4 votes |
public Artifact getJavadocArtifact() { return new MDArtifact(ivyModuleDescriptor, mrid.getName(), "javadoc", "jar", null, Collections.singletonMap("m:classifier", "javadoc")); }
Example #15
Source File: XmlModuleDescriptorParser.java From ant-ivy with Apache License 2.0 | 4 votes |
protected MDArtifact getArtifact() { return artifact; }
Example #16
Source File: XmlModuleDescriptorParser.java From ant-ivy with Apache License 2.0 | 4 votes |
protected void setArtifact(MDArtifact artifact) { this.artifact = artifact; }
Example #17
Source File: PublishEventsTest.java From ant-ivy with Apache License 2.0 | 4 votes |
@Before public void setUp() throws Exception { // reset test case state. resetCounters(); // this ivy settings should configure an InstrumentedResolver, PrePublishTrigger, and // PostPublishTrigger // (see inner classes below). ivy = Ivy.newInstance(); ivy.configure(PublishEventsTest.class.getResource("ivysettings-publisheventstest.xml")); ivy.pushContext(); publishEngine = ivy.getPublishEngine(); // setup dummy ivy and data files to test publishing. since we're testing the engine and not // the resolver, // we don't really care whether the file actually gets published. we just want to make sure // that the engine calls the correct methods in the correct order, and fires required // events. ivyFile = new File("test/java/org/apache/ivy/core/publish/ivy-1.0-dev.xml"); assertTrue("path to ivy file not found in test environment", ivyFile.exists()); // the contents of the data file don't matter. dataFile = File.createTempFile("ivydata", ".jar"); dataFile.deleteOnExit(); publishModule = XmlModuleDescriptorParser.getInstance().parseDescriptor(ivy.getSettings(), ivyFile.toURI().toURL(), false); // always use the same source data file, no pattern substitution is required. publishSources = Collections.singleton(dataFile.getAbsolutePath()); // always use the same ivy file, no pattern substitution is required. publishOptions = new PublishOptions(); publishOptions.setSrcIvyPattern(ivyFile.getAbsolutePath()); // set up our expectations for the test. these variables will // be checked by the resolver and triggers during publication. dataArtifact = publishModule.getAllArtifacts()[0]; assertEquals("sanity check", "foo", dataArtifact.getName()); ivyArtifact = MDArtifact.newIvyArtifact(publishModule); expectedPublications = new HashMap<>(); expectedPublications.put(dataArtifact.getId(), new PublishTestCase(dataArtifact, dataFile, true)); expectedPublications.put(ivyArtifact.getId(), new PublishTestCase(ivyArtifact, ivyFile, true)); assertEquals("hashCode sanity check: two artifacts expected during publish", 2, expectedPublications.size()); // push the TestCase instance onto the context stack, so that our // triggers and resolver instances can interact with it it. IvyContext.getContext().push(PublishEventsTest.class.getName(), this); }