Java Code Examples for org.apache.ivy.core.IvyPatternHelper#substitute()

The following examples show how to use org.apache.ivy.core.IvyPatternHelper#substitute() . 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: IvyArtifactProperty.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public void doExecute() throws BuildException {
    prepareAndCheck();

    try {
        ResolutionCacheManager cacheMgr = getIvyInstance().getResolutionCacheManager();
        String resolveId = getResolveId();
        if (resolveId == null) {
            resolveId = ResolveOptions.getDefaultResolveId(getResolvedModuleId());
        }
        XmlReportParser parser = new XmlReportParser();
        for (String conf : splitToArray(getConf())) {
            File report = cacheMgr.getConfigurationResolveReportInCache(resolveId, conf);
            parser.parse(report);

            for (Artifact artifact : parser.getArtifacts()) {
                String name = IvyPatternHelper.substitute(getSettings().substitute(getName()),
                        artifact, conf);
                String value = IvyPatternHelper.substitute(
                        getSettings().substitute(getValue()), artifact, conf);
                setProperty(name, value);
            }
        }
    } catch (Exception ex) {
        throw new BuildException("impossible to add artifact properties: " + ex, ex);
    }
}
 
Example 2
Source File: RetrieveTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that retrieve, when invoked with "symlink" enabled, creates the necessary symlink
 * when the artifact being retrieved is a directory instead of a regular file
 *
 * @throws Exception
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1594">IVY-1594</a>
 */
@Test
public void testRetrieveZipArtifactWithSymlinks() throws Exception {
    // resolve (inline) with org1:mod1.1:3.0 as a dependency
    final ResolveReport report = ivy.resolve(new ModuleRevisionId(new ModuleId("org1", "mod1.7"), "3.0"),
            getResolveOptions(new String[]{"*"}), false);
    assertNotNull("Resolution report is null", report);
    final ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull("Module descriptor is null", md);

    final String retrievePattern = "build/test/retrieve/[module]/[conf]/[artifact]-[revision]";
    ivy.retrieve(md.getModuleRevisionId(),
            getRetrieveOptions().setMakeSymlinks(true).setDestArtifactPattern(retrievePattern));

    final String expectedRetrieveLocation = IvyPatternHelper.substitute(retrievePattern, "org1", "mod1.7",
            "3.0", "zipped-artifact", null, null, "default");
    // make sure it's retrieved as a symlink (on systems that support symlink)
    assertLinkOrExists(expectedRetrieveLocation);
}
 
Example 3
Source File: JarModuleFinder.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public JarModule[] findJarModules() {
    List<JarModule> ret = new ArrayList<>();
    URLLister lister = new FileURLLister();
    try {
        for (String org : ResolverHelper.listTokenValues(lister, pattern, "organisation")) {
            String orgPattern = IvyPatternHelper.substituteToken(pattern,
                    IvyPatternHelper.ORGANISATION_KEY, org);
            for (String module : ResolverHelper.listTokenValues(lister, orgPattern, "module")) {
                String modPattern = IvyPatternHelper.substituteToken(orgPattern,
                        IvyPatternHelper.MODULE_KEY, module);
                for (String rev : ResolverHelper.listTokenValues(lister, modPattern, "revision")) {
                    File jar = new File(IvyPatternHelper.substitute(filePattern, org,
                            module, rev, module, "jar", "jar"));
                    if (jar.exists()) {
                        ret.add(new JarModule(ModuleRevisionId.newInstance(org, module, rev), jar));
                    }
                }
            }
        }

    } catch (Exception e) {
        Message.debug(e);
        // TODO: handle exception
    }
    return ret.toArray(new JarModule[ret.size()]);
}
 
Example 4
Source File: RepositoryAnalyser.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public void analyse(String pattern, DependencyAnalyser depAnalyser) {
    JarModuleFinder finder = new JarModuleFinder(pattern);
    ModuleDescriptor[] mds = depAnalyser.analyze(finder.findJarModules());
    Message.info("found " + mds.length + " modules");
    for (ModuleDescriptor md : mds) {
        File ivyFile = new File(IvyPatternHelper.substitute(
                pattern,
                DefaultArtifact.newIvyArtifact(md.getModuleRevisionId(),
                        md.getPublicationDate())));
        try {
            Message.info("generating " + ivyFile);
            XmlModuleDescriptorWriter.write(md, ivyFile);
        } catch (IOException e) {
            Message.debug(e);
        }
    }
}
 
Example 5
Source File: IvyReport.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private String getOutputPattern(String conf, String ext) {
    if (mRevId == null) {
        ResolutionCacheManager cacheMgr = getIvyInstance().getResolutionCacheManager();

        XmlReportParser parser = new XmlReportParser();
        File reportFile = cacheMgr.getConfigurationResolveReportInCache(resolveId, conf);

        try {
            parser.parse(reportFile);
        } catch (ParseException e) {
            throw new BuildException("Error occurred while parsing reportfile '"
                    + reportFile.getAbsolutePath() + "'", e);
        }

        // get the resolve module
        mRevId = parser.getResolvedModule();
    }

    return IvyPatternHelper.substitute(outputpattern, mRevId.getOrganisation(),
        mRevId.getName(), mRevId.getRevision(), "", "", ext, conf,
        mRevId.getQualifiedExtraAttributes(), null);
}
 
Example 6
Source File: DefaultRepositoryCacheManager.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * A resolver-specific ivydata file, only used for caching dynamic revisions, e.g.
 * integration-repo.
 */
private PropertiesFile getCachedDataFile(String resolverName, ModuleRevisionId mRevId) {
    // we append ".${resolverName} onto the end of the regular ivydata location
    return new PropertiesFile(new File(getRepositoryCacheRoot(),
            IvyPatternHelper.substitute(getDataFilePattern(), mRevId) + "." + resolverName),
            "ivy cached data file for " + mRevId);
}
 
Example 7
Source File: FileSystemResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Override
protected String getDestination(String pattern, Artifact artifact, ModuleRevisionId mrid) {
    if (supportTransaction() && isTransactionStarted()) {

        String destPattern = fullTransactionPatterns.get(pattern);
        if (destPattern == null) {
            throw new IllegalArgumentException(
                    "unsupported pattern for publish destination pattern: " + pattern
                            + ". supported patterns: " + fullTransactionPatterns.keySet());
        }
        return IvyPatternHelper.substitute(destPattern, mrid, artifact);
    } else {
        return super.getDestination(pattern, artifact, mrid);
    }
}
 
Example 8
Source File: PackagerCacheEntry.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private String getResourceURL() {
    String baseURL = IvyPatternHelper.substitute(resourceURL, mr.getOrganisation(),
        mr.getName(), mr.getRevision(), null, null, null, null,
        mr.getQualifiedExtraAttributes(), null);
    int slash = baseURL.lastIndexOf('/');
    if (slash != -1) {
        baseURL = baseURL.substring(0, slash + 1);
    }
    return baseURL;
}
 
Example 9
Source File: DefaultResolutionCacheManager.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public File getResolvedIvyFileInCache(ModuleRevisionId mrid) {
    String file = IvyPatternHelper.substitute(getResolvedIvyPattern(), mrid.getOrganisation(),
        mrid.getName(), mrid.getRevision(), "ivy", "ivy", "xml");
    return new File(getResolutionCacheRoot(), file);
}
 
Example 10
Source File: DefaultResolutionCacheManager.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public File getResolvedIvyPropertiesInCache(ModuleRevisionId mrid) {
    String file = IvyPatternHelper.substitute(getResolvedIvyPropertiesPattern(),
        mrid.getOrganisation(), mrid.getName(), mrid.getRevision(), "ivy", "ivy", "xml");
    return new File(getResolutionCacheRoot(), file);
}
 
Example 11
Source File: DefaultRepositoryCacheManager.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public File getIvyFileInCache(ModuleRevisionId mrid) {
    String file = IvyPatternHelper.substitute(getIvyPattern(),
        DefaultArtifact.newIvyArtifact(mrid, null));
    return new File(getRepositoryCacheRoot(), file);
}
 
Example 12
Source File: DefaultRepositoryCacheManager.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public String getArchivePathInCache(Artifact artifact) {
    return IvyPatternHelper.substitute(getArtifactPattern(), artifact);
}
 
Example 13
Source File: DefaultRepositoryCacheManager.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public String getArchivePathInCache(Artifact artifact, ArtifactOrigin origin) {
    if (isOriginalMetadataArtifact(artifact)) {
        return IvyPatternHelper.substitute(getIvyPattern() + ".original", artifact, origin);
    }
    return IvyPatternHelper.substitute(getArtifactPattern(), artifact, origin);
}
 
Example 14
Source File: DefaultRepositoryCacheManager.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
private PropertiesFile getCachedDataFile(ModuleRevisionId mRevId) {
    return new PropertiesFile(new File(getRepositoryCacheRoot(), IvyPatternHelper.substitute(
        getDataFilePattern(), mRevId)), "ivy cached data file for " + mRevId);
}
 
Example 15
Source File: IBiblioResolver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
private String findTimestampedSnapshotVersion(final ModuleRevisionId mrid) {
    if (!isM2compatible()) {
        return null;
    }
    if (!shouldUseMavenMetadata(getWholePattern())) {
        return null;
    }
    try {
        final String metadataLocation = IvyPatternHelper.substitute(root
                + "[organisation]/[module]/[revision]/maven-metadata.xml", mrid);
        final Resource metadata = getRepository().getResource(metadataLocation);
        if (!metadata.exists()) {
            Message.verbose("\tmaven-metadata not available for: " + mrid);
            return null;
        }
        try (final InputStream metadataStream = metadata.openStream()) {
            final StringBuilder timestamp = new StringBuilder();
            final StringBuilder buildNumber = new StringBuilder();
            XMLHelper.parse(metadataStream, null, new ContextualSAXHandler() {
                @Override
                public void endElement(String uri, String localName, String qName)
                        throws SAXException {
                    if ("metadata/versioning/snapshot/timestamp".equals(getContext())) {
                        timestamp.append(getText());
                    }
                    if ("metadata/versioning/snapshot/buildNumber".equals(getContext())) {
                        buildNumber.append(getText());
                    }
                    super.endElement(uri, localName, qName);
                }
            }, null);
            if (timestamp.length() > 0) {
                // we have found a timestamp, so this is a snapshot unique version
                String rev = mrid.getRevision();
                rev = rev.substring(0, rev.length() - "SNAPSHOT".length());
                rev += timestamp.toString() + "-" + buildNumber.toString();

                return rev;
            }
        }
    } catch (IOException | SAXException | ParserConfigurationException e) {
        Message.debug("impossible to access maven metadata file, ignored", e);
    }
    return null;
}
 
Example 16
Source File: IBiblioResolver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@Override
protected ResolvedResource[] listResources(Repository repository, ModuleRevisionId mrid,
                                           String pattern, Artifact artifact) {
    if (shouldUseMavenMetadata(pattern)) {
        List<String> revs = listRevisionsWithMavenMetadata(repository, mrid.getModuleId()
                .getAttributes());
        if (revs != null) {
            Message.debug("\tfound revs: " + revs);
            List<ResolvedResource> rres = new ArrayList<>();
            for (String rev : revs) {
                ModuleRevisionId historicalMrid = ModuleRevisionId.newInstance(mrid, rev);

                String patternForRev = pattern;
                if (rev.endsWith("SNAPSHOT")) {
                    String snapshotVersion = findTimestampedSnapshotVersion(historicalMrid);
                    if (snapshotVersion != null) {
                        patternForRev = pattern.replaceFirst("\\-\\[revision\\]", "-"
                                + snapshotVersion);
                    }
                }
                String resolvedPattern = IvyPatternHelper.substitute(patternForRev,
                        historicalMrid, artifact);
                try {
                    Resource res = repository.getResource(resolvedPattern);
                    if (res != null) {
                        // we do not test if the resource actually exist here, it would cause
                        // a lot of checks which are not always necessary depending on the usage
                        // which is done of the returned ResolvedResource array
                        rres.add(new ResolvedResource(res, rev));
                    }
                } catch (IOException e) {
                    Message.warn(
                            "impossible to get resource from name listed by maven-metadata.xml:"
                                    + rres, e);
                }
            }
            return rres.toArray(new ResolvedResource[rres.size()]);
        } else {
            // maven metadata not available or something went wrong,
            // use default listing capability
            return super.listResources(repository, mrid, pattern, artifact);
        }
    } else {
        return super.listResources(repository, mrid, pattern, artifact);
    }
}
 
Example 17
Source File: BuiltFileResource.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public BuiltFileResource(File dir, Artifact artifact) {
    this(new File(dir, IvyPatternHelper.substitute(BUILT_ARTIFACT_PATTERN, artifact)));
}
 
Example 18
Source File: RepositoryResolver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@Override
protected ResolvedResource findResourceUsingPattern(ModuleRevisionId mrid, String pattern,
        Artifact artifact, ResourceMDParser rmdparser, Date date) {
    String name = getName();
    VersionMatcher versionMatcher = getSettings().getVersionMatcher();
    try {
        if (!versionMatcher.isDynamic(mrid) || isAlwaysCheckExactRevision()) {
            String resourceName = IvyPatternHelper.substitute(pattern, mrid, artifact);
            Message.debug("\t trying " + resourceName);
            logAttempt(resourceName);
            Resource res = repository.getResource(resourceName);
            boolean reachable = res.exists();
            if (reachable) {
                String revision;
                if (pattern.contains(IvyPatternHelper.REVISION_KEY)) {
                    revision = mrid.getRevision();
                } else {
                    if ("ivy".equals(artifact.getType()) || "pom".equals(artifact.getType())) {
                        // we can't determine the revision from the pattern, get it
                        // from the module descriptor itself
                        File temp = File.createTempFile("ivy", artifact.getExt());
                        temp.deleteOnExit();
                        repository.get(res.getName(), temp);
                        ModuleDescriptorParser parser = ModuleDescriptorParserRegistry
                                .getInstance().getParser(res);
                        ModuleDescriptor md = parser.parseDescriptor(getParserSettings(), temp
                                .toURI().toURL(), res, false);
                        revision = md.getRevision();
                        if (isNullOrEmpty(revision)) {
                            revision = "working@" + name;
                        }
                    } else {
                        revision = "working@" + name;
                    }
                }
                return new ResolvedResource(res, revision);
            } else if (versionMatcher.isDynamic(mrid)) {
                return findDynamicResourceUsingPattern(rmdparser, mrid, pattern, artifact, date);
            } else {
                Message.debug("\t" + name + ": resource not reachable for " + mrid + ": res="
                        + res);
                return null;
            }
        } else {
            return findDynamicResourceUsingPattern(rmdparser, mrid, pattern, artifact, date);
        }
    } catch (IOException | ParseException ex) {
        throw new RuntimeException(name + ": unable to get resource for " + mrid + ": res="
                + IvyPatternHelper.substitute(pattern, mrid, artifact) + ": " + ex, ex);
    }
}
 
Example 19
Source File: RepositoryResolver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
protected String getDestination(String pattern, Artifact artifact, ModuleRevisionId mrid) {
    return IvyPatternHelper.substitute(pattern, mrid, artifact);
}