Java源码示例:org.apache.ivy.core.module.descriptor.Artifact
示例1
public void setDependencies(List<IvyNode> dependencies, Filter<Artifact> artifactFilter) {
this.dependencies = dependencies;
// collect list of artifacts
artifacts = new ArrayList<>();
for (IvyNode dependency : dependencies) {
if (!dependency.isCompletelyEvicted() && !dependency.hasProblem()) {
artifacts.addAll(Arrays.asList(dependency.getSelectedArtifacts(artifactFilter)));
}
// update the configurations reports with the dependencies
// these reports will be completed later with download information, if any
for (String dconf : dependency.getRootModuleConfigurations()) {
ConfigurationResolveReport configurationReport = getConfigurationReport(dconf);
if (configurationReport != null) {
configurationReport.addDependency(dependency);
}
}
}
}
示例2
public void publish(IvyNormalizedPublication publication, PublicationAwareRepository repository) {
ModuleVersionPublisher publisher = repository.createPublisher();
IvyPublicationIdentity projectIdentity = publication.getProjectIdentity();
ModuleRevisionId moduleRevisionId = IvyUtil.createModuleRevisionId(projectIdentity.getOrganisation(), projectIdentity.getModule(), projectIdentity.getRevision());
ModuleVersionIdentifier moduleVersionIdentifier = DefaultModuleVersionIdentifier.newId(moduleRevisionId);
DefaultIvyModulePublishMetaData publishMetaData = new DefaultIvyModulePublishMetaData(moduleVersionIdentifier);
try {
for (IvyArtifact publishArtifact : publication.getArtifacts()) {
Artifact ivyArtifact = createIvyArtifact(publishArtifact, moduleRevisionId);
publishMetaData.addArtifact(ivyArtifact, publishArtifact.getFile());
}
Artifact artifact = DefaultArtifact.newIvyArtifact(moduleRevisionId, null);
publishMetaData.addArtifact(artifact, publication.getDescriptorFile());
publisher.publish(publishMetaData);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例3
/**
* Publishing with transaction=true and overwrite mode must fail.
*
* @throws Exception if something goes wrong
*/
@Test
public void testUnsupportedTransaction3() throws Exception {
expExc.expect(IllegalStateException.class);
expExc.expectMessage("transactional");
FileSystemResolver resolver = new FileSystemResolver();
resolver.setName("test");
resolver.setSettings(settings);
resolver.setTransactional("true");
resolver.addArtifactPattern(settings.getBaseDir()
+ "/test/repositories/1/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");
ModuleRevisionId mrid = ModuleRevisionId.newInstance("myorg", "mymodule", "myrevision");
Artifact artifact = new DefaultArtifact(mrid, new Date(), "myartifact", "mytype",
"myext");
File src = new File("test/repositories/ivysettings.xml");
// overwrite transaction not supported
resolver.beginPublishTransaction(mrid, true);
resolver.publish(artifact, src, true);
}
示例4
@Test
public void testModel() throws Exception {
ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
getClass().getResource("test-model.pom"), false);
assertNotNull(md);
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test", "1.0");
assertEquals(mrid, md.getModuleRevisionId());
assertNotNull(md.getConfigurations());
assertEquals(Arrays.asList(PomModuleDescriptorBuilder.MAVEN2_CONFIGURATIONS),
Arrays.asList(md.getConfigurations()));
Artifact[] artifact = md.getArtifacts("master");
assertEquals(1, artifact.length);
assertEquals(mrid, artifact[0].getModuleRevisionId());
assertEquals("test", artifact[0].getName());
assertEquals("jar", artifact[0].getExt());
assertEquals("jar", artifact[0].getType());
}
示例5
@Test
public void testUpdateWithExcludeConfigurations4() throws Exception {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
URL settingsUrl = new File("test/java/org/apache/ivy/plugins/parser/xml/"
+ "test-update-excludedconfs4.xml").toURI().toURL();
XmlModuleDescriptorUpdater.update(settingsUrl, buffer,
getUpdateOptions("release", "mynewrev").setConfsToExclude(new String[] {"myconf2"}));
XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(),
new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0,
false), true);
// test the number of configurations
Artifact[] artifacts = updatedMd.getAllArtifacts();
assertNotNull("Published artifacts shouldn't be null", artifacts);
assertEquals("Number of published artifacts incorrect", 4, artifacts.length);
// test that the correct configuration has been removed
for (Artifact current : artifacts) {
List<String> currentConfs = Arrays.asList(current.getConfigurations());
assertTrue("myconf2 hasn't been removed for artifact " + current.getName(),
!currentConfs.contains("myconf2"));
}
}
示例6
@Test
public void testSimple() throws Exception {
ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
getClass().getResource("test-simple.pom"), false);
assertNotNull(md);
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test", "1.0");
assertEquals(mrid, md.getModuleRevisionId());
assertNotNull(md.getConfigurations());
assertEquals(Arrays.asList(PomModuleDescriptorBuilder.MAVEN2_CONFIGURATIONS),
Arrays.asList(md.getConfigurations()));
Artifact[] artifact = md.getArtifacts("master");
assertEquals(1, artifact.length);
assertEquals(mrid, artifact[0].getModuleRevisionId());
assertEquals("test", artifact[0].getName());
assertEquals("jar", artifact[0].getExt());
assertEquals("jar", artifact[0].getType());
}
示例7
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);
}
示例8
private static void setModuleVariables(ModuleDescriptor md, IvyVariableContainer variables,
PomWriterOptions options) {
ModuleRevisionId mrid = md.getModuleRevisionId();
variables.setVariable("ivy.pom.groupId", mrid.getOrganisation(), true);
String artifactId = options.getArtifactName();
if (artifactId == null) {
artifactId = mrid.getName();
}
String packaging = options.getArtifactPackaging();
if (packaging == null) {
// find artifact to determine the packaging
Artifact artifact = findArtifact(md, artifactId);
if (artifact == null) {
// no suitable artifact found, default to 'pom'
packaging = "pom";
} else {
packaging = artifact.getType();
}
}
variables.setVariable("ivy.pom.artifactId", artifactId, true);
variables.setVariable("ivy.pom.packaging", packaging, true);
if (mrid.getRevision() != null) {
variables.setVariable("ivy.pom.version", mrid.getRevision(), true);
}
if (options.getDescription() != null) {
variables.setVariable("ivy.pom.description", options.getDescription(), true);
} else if (!isNullOrEmpty(md.getDescription())) {
variables.setVariable("ivy.pom.description", md.getDescription(), true);
}
if (md.getHomePage() != null) {
variables.setVariable("ivy.pom.url", md.getHomePage(), true);
}
}
示例9
public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFilePattern,
String destIvyPattern, Filter<Artifact> artifactFilter) {
try {
return ivy.retrieve(new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()),
new RetrieveOptions().setConfs(confs).setDestArtifactPattern(destFilePattern)
.setDestIvyPattern(destIvyPattern)
.setArtifactFilter(artifactFilter)).getNbrArtifactsCopied();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例10
private void throwExceptionIfArtifactOrSrcIsNull(Artifact artifact, File src) {
if (artifact == null) {
throw new InvalidUserDataException("Artifact must not be null.");
}
if (src == null) {
throw new InvalidUserDataException("Src file must not be null.");
}
}
示例11
private void assignArtifactValuesToPom(Artifact artifact, MavenPom pom, boolean setType) {
if (pom.getGroupId().equals(MavenProject.EMPTY_PROJECT_GROUP_ID)) {
pom.setGroupId(artifact.getModuleRevisionId().getOrganisation());
}
if (pom.getArtifactId().equals(MavenProject.EMPTY_PROJECT_ARTIFACT_ID)) {
pom.setArtifactId(artifact.getName());
}
if (pom.getVersion().equals(MavenProject.EMPTY_PROJECT_VERSION)) {
pom.setVersion(artifact.getModuleRevisionId().getRevision());
}
if (setType) {
pom.setPackaging(artifact.getType());
}
}
示例12
public ResolvedModuleRevision cacheModuleDescriptor(DependencyResolver resolver, final ResolvedResource resolvedResource, DependencyDescriptor dd, Artifact moduleArtifact, ResourceDownloader downloader, CacheMetadataOptions options) throws ParseException {
if (!moduleArtifact.isMetadata()) {
return null;
}
ArtifactResourceResolver artifactResourceResolver = new ArtifactResourceResolver() {
public ResolvedResource resolve(Artifact artifact) {
return resolvedResource;
}
};
ArtifactDownloadReport report = download(moduleArtifact, artifactResourceResolver, downloader, new CacheDownloadOptions().setListener(options.getListener()).setForce(true));
if (report.getDownloadStatus() == DownloadStatus.FAILED) {
LOGGER.warn("problem while downloading module descriptor: {}: {} ({} ms)", resolvedResource.getResource(), report.getDownloadDetails(), report.getDownloadTimeMillis());
return null;
}
ModuleDescriptor md = parseModuleDescriptor(resolver, moduleArtifact, options, report.getLocalFile(), resolvedResource.getResource());
LOGGER.debug("\t{}: parsed downloaded md file for {}; parsed={}" + getName(), moduleArtifact.getModuleRevisionId(), md.getModuleRevisionId());
MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(md.getMetadataArtifact());
madr.setSearched(true);
madr.setDownloadStatus(report.getDownloadStatus());
madr.setDownloadDetails(report.getDownloadDetails());
madr.setArtifactOrigin(report.getArtifactOrigin());
madr.setDownloadTimeMillis(report.getDownloadTimeMillis());
madr.setOriginalLocalFile(report.getLocalFile());
madr.setSize(report.getSize());
return new ResolvedModuleRevision(resolver, resolver, md, madr);
}
示例13
@Override
protected List<Artifact> createWorkspaceArtifacts(ModuleDescriptor md) {
List<Artifact> res = new ArrayList<>();
for (WorkspaceArtifact wa : artifacts) {
String name = wa.name;
String type = wa.type;
String ext = wa.ext;
String path = wa.path;
if (name == null) {
name = md.getModuleRevisionId().getName();
}
if (type == null) {
type = "jar";
}
if (ext == null) {
ext = "jar";
}
if (path == null) {
path = "target" + File.separator + "dist" + File.separator + type + "s"
+ File.separator + name + "." + ext;
}
URL url;
File ivyFile = md2IvyFile.get(md);
File artifactFile = new File(ivyFile.getParentFile(), path);
try {
url = artifactFile.toURI().toURL();
} catch (MalformedURLException e) {
throw new RuntimeException("Unsupported file path : " + artifactFile, e);
}
res.add(new DefaultArtifact(md.getModuleRevisionId(), new Date(), name, type, ext,
url, null));
}
return res;
}
示例14
public Collection<Artifact> publish(ModuleRevisionId mrid, String pubrevision, File cache,
String srcArtifactPattern, String resolverName, String srcIvyPattern, boolean validate)
throws IOException {
return ivy.publish(mrid, Collections.singleton(srcArtifactPattern), resolverName,
new PublishOptions().setPubrevision(pubrevision).setSrcIvyPattern(srcIvyPattern)
.setValidate(validate));
}
示例15
public ResolveReport install(ModuleRevisionId mrid, String from, String to, boolean transitive,
boolean validate, boolean overwrite, Filter<Artifact> artifactFilter, File cache,
String matcherName) throws IOException {
return ivy.install(mrid, from, to,
new InstallOptions().setTransitive(transitive).setValidate(validate)
.setOverwrite(overwrite).setArtifactFilter(artifactFilter)
.setMatcherName(matcherName));
}
示例16
@Test
public void testDisableTransaction() throws Exception {
FileSystemResolver resolver = new FileSystemResolver();
resolver.setName("test");
resolver.setSettings(settings);
resolver.setTransactional("false");
resolver.addIvyPattern(settings.getBaseDir()
+ "/test/repositories/1/[organisation]/[module]/[revision]/[artifact].[ext]");
resolver.addArtifactPattern(settings.getBaseDir()
+ "/test/repositories/1/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");
ModuleRevisionId mrid = ModuleRevisionId.newInstance("myorg", "mymodule", "myrevision");
Artifact ivyArtifact = new DefaultArtifact(mrid, new Date(), "ivy", "ivy", "xml");
Artifact artifact = new DefaultArtifact(mrid, new Date(), "myartifact", "mytype",
"myext");
File src = new File("test/repositories/ivysettings.xml");
resolver.beginPublishTransaction(mrid, false);
// with transactions disabled the file should be available as soon as they are published
resolver.publish(ivyArtifact, src, false);
assertTrue(new File("test/repositories/1/myorg/mymodule/myrevision/ivy.xml").exists());
resolver.publish(artifact, src, false);
assertTrue(new File(
"test/repositories/1/myorg/mymodule/myrevision/myartifact-myrevision.myext")
.exists());
resolver.commitPublishTransaction();
assertTrue(new File("test/repositories/1/myorg/mymodule/myrevision/ivy.xml").exists());
assertTrue(new File(
"test/repositories/1/myorg/mymodule/myrevision/myartifact-myrevision.myext")
.exists());
}
示例17
public void publish(Artifact artifact, File src, boolean overwrite) throws IOException {
// verify that the data from the current test case has been handed down to us
PublishEventsTest test = (PublishEventsTest) IvyContext.getContext().peek(
PublishEventsTest.class.getName());
// test sequence of events.
assertNotNull(test.currentTestCase);
assertTrue("preTrigger has already fired", test.currentTestCase.preTriggerFired);
assertFalse("postTrigger has not yet fired", test.currentTestCase.postTriggerFired);
assertFalse("publish has not been called", test.currentTestCase.published);
// test event data
assertSameArtifact("publisher has received correct artifact",
test.currentTestCase.expectedArtifact, artifact);
assertEquals("publisher has received correct datafile",
test.currentTestCase.expectedData.getCanonicalPath(), src.getCanonicalPath());
assertEquals("publisher has received correct overwrite setting",
test.expectedOverwrite, overwrite);
assertTrue("publisher only invoked when source file exists",
test.currentTestCase.expectedData.exists());
// simulate a publisher error if the current test case demands it.
if (test.publishError != null) {
throw test.publishError;
}
// all assertions pass. increment the publication count
test.currentTestCase.published = true;
++test.publications;
}
示例18
private void throwExceptionIfArtifactOrSrcIsNull(Artifact artifact, File src) {
if (artifact == null) {
throw new InvalidUserDataException("Artifact must not be null.");
}
if (src == null) {
throw new InvalidUserDataException("Src file must not be null.");
}
}
示例19
@Test
public void testResolveZipped() throws Exception {
settings.setDefaultResolver("p2-zipped");
ModuleRevisionId mrid = ModuleRevisionId.newInstance(BundleInfo.BUNDLE_TYPE,
"org.apache.ant", "1.8.3.v20120321-1730");
ResolvedModuleRevision rmr = p2ZippedResolver.getDependency(
new DefaultDependencyDescriptor(mrid, false), data);
assertNotNull(rmr);
assertEquals(mrid, rmr.getId());
assertEquals(2, rmr.getDescriptor().getAllArtifacts().length);
DownloadOptions options = new DownloadOptions();
DownloadReport report = p2ZippedResolver.download(rmr.getDescriptor().getAllArtifacts(),
options);
assertNotNull(report);
assertEquals(2, report.getArtifactsReports().length);
for (int i = 0; i < 2; i++) {
Artifact artifact = rmr.getDescriptor().getAllArtifacts()[i];
ArtifactDownloadReport ar = report.getArtifactReport(artifact);
assertNotNull(ar);
assertEquals(artifact, ar.getArtifact());
assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
// only the binary get unpacked
if (ar.getArtifact().getType().equals("source")) {
assertNull(ar.getUnpackedLocalFile());
} else {
assertNotNull(ar.getUnpackedLocalFile());
}
}
}
示例20
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);
}
示例21
private static String getConfs(ModuleDescriptor md, Artifact artifact) {
StringBuilder ret = new StringBuilder();
for (String conf : md.getConfigurationsNames()) {
if (Arrays.asList(md.getArtifacts(conf)).contains(artifact)) {
ret.append(conf).append(",");
}
}
if (ret.length() > 0) {
ret.setLength(ret.length() - 1);
}
return ret.toString();
}
示例22
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);
}
});
}
示例23
/**
* Returns the first artifact with the correct name and without a classifier.
*/
private static Artifact findArtifact(ModuleDescriptor md, String artifactName) {
for (Artifact artifact : md.getAllArtifacts()) {
if (artifact.getName().equals(artifactName)
&& artifact.getAttribute("classifier") == null) {
return artifact;
}
}
return null;
}
示例24
@Test
public void testParent() throws Exception {
ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
getClass().getResource("test-parent.pom"), false);
assertNotNull(md);
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test", "1.0");
assertEquals(mrid, md.getModuleRevisionId());
Artifact[] artifact = md.getArtifacts("master");
assertEquals(1, artifact.length);
assertEquals(mrid, artifact[0].getModuleRevisionId());
assertEquals("test", artifact[0].getName());
}
示例25
private ResolvedResource findSnapshotArtifact(final Artifact artifact, final Date date,
final ModuleRevisionId mrid, final MavenTimedSnapshotVersionMatcher.MavenSnapshotRevision snapshotRevision) {
if (!isM2compatible()) {
return null;
}
final String snapshotArtifactPattern;
if (snapshotRevision.isTimestampedSnapshot()) {
Message.debug(mrid + " has been identified as a (Maven) timestamped snapshot revision");
// this is a Maven timestamped snapshot revision. Something like 1.0.0-<timestampedRev>
// We now get the base revision from it, which is "1.0.0" and append the "-SNAPSHOT" to it.
final String inferredSnapshotRevision = snapshotRevision.getBaseRevision() + "-SNAPSHOT";
// we replace the "/[revision]" in the descriptor pattern with the "inferred" snapshot
// revision which is like "1.0.0-SNAPSHOT". Ultimately, this will translate to
// something like
// org/module/1.0.0-SNAPSHOT/artifact-1.0.0-<timestampedRev>(-[classifier]).ext
snapshotArtifactPattern = getWholePattern().replaceFirst("/\\[revision\\]", "/" + inferredSnapshotRevision);
} else {
// it's not a timestamped revision, but a regular snapshot. Try and find any potential
// timestamped revisions of this regular snapshot, by looking into the Maven metadata
final String timestampedRev = findTimestampedSnapshotVersion(mrid);
if (timestampedRev == null) {
// no timestamped snapshots found and instead this is just a regular snapshot
// version. So let's just fallback to our logic of finding resources using
// configured artifact pattern(s)
return null;
}
Message.verbose(mrid + " has been identified as a snapshot revision which has a timestamped snapshot revision " + timestampedRev);
// we have found a timestamped revision for a snapshot. So we replace the "-[revision]"
// in the artifact file name to use the timestamped revision.
// Ultimately, this will translate to something like
// org/module/1.0.0-SNAPSHOT/artifact-1.0.0-<timestampedRev>(-[classifier]).ext
snapshotArtifactPattern = getWholePattern().replaceFirst("\\-\\[revision\\]", "-" + timestampedRev);
}
return findResourceUsingPattern(mrid, snapshotArtifactPattern, artifact, getDefaultRMDParser(artifact
.getModuleRevisionId().getModuleId()), date);
}
示例26
@Test
public void testExtendsDescriptionWithOverride() throws Exception {
// descriptor specifies that only parent description should be included
ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings,
getClass().getResource("test-extends-description-override.xml"), true);
assertNotNull(md);
assertEquals("myorg", md.getModuleRevisionId().getOrganisation());
assertEquals("mymodule", md.getModuleRevisionId().getName());
assertEquals(Ivy.getWorkingRevision(), md.getModuleRevisionId().getRevision());
assertEquals("integration", md.getStatus());
// child description should always be preferred, even if extendType="description"
assertEquals("Child description overrides parent.", md.getDescription());
// verify that the parent configurations were ignored.
final Configuration[] expectedConfs = {new Configuration("default")};
assertNotNull(md.getConfigurations());
assertEquals(Arrays.asList(expectedConfs), Arrays.asList(md.getConfigurations()));
// verify parent dependencies were ignored.
DependencyDescriptor[] deps = md.getDependencies();
assertNotNull(deps);
assertEquals(1, deps.length);
assertEquals(Collections.singletonList("default"),
Arrays.asList(deps[0].getModuleConfigurations()));
ModuleRevisionId dep = deps[0].getDependencyRevisionId();
assertEquals("myorg", dep.getModuleId().getOrganisation());
assertEquals("mymodule2", dep.getModuleId().getName());
assertEquals("2.0", dep.getRevision());
// verify only child publications are present
Artifact[] artifacts = md.getAllArtifacts();
assertNotNull(artifacts);
assertEquals(1, artifacts.length);
assertEquals("mymodule", artifacts[0].getName());
assertEquals("jar", artifacts[0].getType());
}
示例27
@Test
public void testParent2() throws Exception {
ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings,
getClass().getResource("test-parent2.pom"), false);
assertNotNull(md);
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test", "1.0");
assertEquals(mrid, md.getModuleRevisionId());
Artifact[] artifact = md.getArtifacts("master");
assertEquals(1, artifact.length);
assertEquals(mrid, artifact[0].getModuleRevisionId());
assertEquals("test", artifact[0].getName());
}
示例28
public Collection<Artifact> publish(ModuleRevisionId mrid, String pubrevision, File cache,
Collection<String> srcArtifactPattern, String resolverName, String srcIvyPattern,
String status, Date pubdate, Artifact[] extraArtifacts, boolean validate,
boolean overwrite, boolean update, String conf) throws IOException {
return ivy.publish(mrid, srcArtifactPattern, resolverName,
new PublishOptions().setStatus(status).setPubdate(pubdate).setPubrevision(pubrevision)
.setSrcIvyPattern(srcIvyPattern).setExtraArtifacts(extraArtifacts)
.setUpdate(update).setValidate(validate).setOverwrite(overwrite)
.setConfs(splitToArray(conf)));
}
示例29
private void collectArtifact(Artifact artifact, File src) {
if (isIgnorable(artifact)) {
return;
}
getArtifactPomContainer().addArtifact(artifact, src);
}
示例30
@Test
public void testIvyRepWithLocalURL() throws Exception {
IvyRepResolver resolver = new IvyRepResolver();
String rootpath = new File("test/repositories/1").getAbsolutePath();
resolver.setName("testLocal");
resolver.setIvyroot("file:" + rootpath);
resolver.setIvypattern("[organisation]/[module]/ivys/ivy-[revision].xml");
resolver.setArtroot("file:" + rootpath);
resolver.setArtpattern("[organisation]/[module]/jars/[artifact]-[revision].[ext]");
resolver.setSettings(settings);
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid,
false), data);
assertNotNull(rmr);
DefaultArtifact artifact = new DefaultArtifact(mrid, rmr.getPublicationDate(), "mod1.1",
"jar", "jar");
DownloadReport report = resolver.download(new Artifact[] {artifact}, downloadOptions());
assertNotNull(report);
assertEquals(1, report.getArtifactsReports().length);
ArtifactDownloadReport ar = report.getArtifactReport(artifact);
assertNotNull(ar);
assertEquals(artifact, ar.getArtifact());
assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
// test to ask to download again, should use cache
report = resolver.download(new Artifact[] {artifact}, downloadOptions());
assertNotNull(report);
assertEquals(1, report.getArtifactsReports().length);
ar = report.getArtifactReport(artifact);
assertNotNull(ar);
assertEquals(artifact, ar.getArtifact());
assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
}