org.apache.ivy.core.module.descriptor.Artifact Java Examples

The following examples show how to use org.apache.ivy.core.module.descriptor.Artifact. 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: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #2
Source File: XmlModuleUpdaterTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@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"));
    }
}
 
Example #3
Source File: FileSystemResolverTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #4
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #5
Source File: ResolveReport.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
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);
            }
        }
    }
}
 
Example #6
Source File: DependencyResolverIvyPublisher.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
    }
}
 
Example #7
Source File: DefaultConfigurationsToArtifactsConverter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
}
 
Example #8
Source File: DownloadingRepositoryCacheManager.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
}
 
Example #9
Source File: DefaultArtifactPom.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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());
    }
}
 
Example #10
Source File: P2DescriptorTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@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());
        }
    }
}
 
Example #11
Source File: XmlModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #12
Source File: DefaultArtifactPom.java    From Pushjet-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 #13
Source File: Ivy14.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
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)));
}
 
Example #14
Source File: DefaultArtifactPom.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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.");
    }
}
 
Example #15
Source File: Ivy14.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #16
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #17
Source File: PomModuleDescriptorWriter.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #18
Source File: AntWorkspaceResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #19
Source File: DefaultArtifactPom.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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.");
    }
}
 
Example #20
Source File: PomModuleDescriptorWriter.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #21
Source File: PublishEventsTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
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;
        }
 
Example #22
Source File: XmlModuleDescriptorWriter.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #23
Source File: IBiblioResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #24
Source File: IvyBackedArtifactPublisher.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 #25
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #26
Source File: Ivy14.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example #27
Source File: FileSystemResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #28
Source File: Ivy14.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example #29
Source File: PomModuleDescriptorBuilder.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public Artifact getSrcArtifact() {
    return new MDArtifact(ivyModuleDescriptor, mrid.getName(), "source", "jar", null,
            Collections.singletonMap("m:classifier", "src"));
}
 
Example #30
Source File: LoopbackDependencyResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
    throw new UnsupportedOperationException();
}