org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry Java Examples

The following examples show how to use org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry. 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: AntWorkspaceResolver.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private synchronized Map<ModuleDescriptor, File> getModuleDescriptors() {
    if (md2IvyFile == null) {
        md2IvyFile = new HashMap<>();
        for (ResourceCollection resources : allResources) {
            for (Resource resource : resources) {
                File ivyFile = ((FileResource) resource).getFile();
                try {
                    ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance()
                            .parseDescriptor(getParserSettings(), ivyFile.toURI().toURL(),
                                isValidate());
                    md2IvyFile.put(md, ivyFile);
                    Message.debug("Add " + md.getModuleRevisionId().getModuleId());
                } catch (Exception ex) {
                    if (haltOnError) {
                        throw new BuildException("impossible to parse ivy file " + ivyFile
                                + " exception=" + ex, ex);
                    } else {
                        Message.warn("impossible to parse ivy file " + ivyFile
                                + " exception=" + ex.getMessage());
                    }
                }
            }
        }
    }
    return md2IvyFile;
}
 
Example #2
Source File: ResolveEngine.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * Resolve dependencies of a module described by an ivy file.
 *
 * @param ivySource URL
 * @param options ResolveOptions
 * @return ResolveReport
 * @throws ParseException if something goes wrong
 * @throws IOException if something goes wrong
 */
public ResolveReport resolve(URL ivySource, ResolveOptions options) throws ParseException,
        IOException {
    URLResource res = new URLResource(ivySource);
    ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser(res);
    Message.verbose("using " + parser + " to parse " + ivySource);
    ModuleDescriptor md = parser.parseDescriptor(settings, ivySource, options.isValidate());
    String revision = options.getRevision();
    if (revision == null && md.getResolvedModuleRevisionId().getRevision() == null) {
        revision = Ivy.getWorkingRevision();
    }
    if (revision != null) {
        md.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(md.getModuleRevisionId(),
            revision));
    }

    return resolve(md, options);
}
 
Example #3
Source File: AbstractRepositoryCacheManager.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected ModuleDescriptor parseModuleDescriptor(DependencyResolver resolver, Artifact moduleArtifact, CacheMetadataOptions options, File artifactFile, Resource resource) throws ParseException {
    ModuleRevisionId moduleRevisionId = moduleArtifact.getId().getModuleRevisionId();
    try {
        IvySettings ivySettings = IvyContextualiser.getIvyContext().getSettings();
        ParserSettings parserSettings = new LegacyResolverParserSettings(ivySettings, resolver, moduleRevisionId);
        ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser(resource);
        return parser.parseDescriptor(parserSettings, new URL(artifactFile.toURI().toASCIIString()), resource, options.isValidate());
    } catch (IOException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
 
Example #4
Source File: AbstractRepositoryCacheManager.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected ModuleDescriptor parseModuleDescriptor(DependencyResolver resolver, Artifact moduleArtifact, CacheMetadataOptions options, File artifactFile, Resource resource) throws ParseException {
    ModuleRevisionId moduleRevisionId = moduleArtifact.getId().getModuleRevisionId();
    try {
        IvySettings ivySettings = IvyContextualiser.getIvyContext().getSettings();
        ParserSettings parserSettings = new LegacyResolverParserSettings(ivySettings, resolver, moduleRevisionId);
        ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser(resource);
        return parser.parseDescriptor(parserSettings, new URL(artifactFile.toURI().toASCIIString()), resource, options.isValidate());
    } catch (IOException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
 
Example #5
Source File: XmlSettingsParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testParser() throws Exception {
    IvySettings settings = new IvySettings();
    XmlSettingsParser parser = new XmlSettingsParser(settings);
    parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-parser.xml"));
    assertEquals(ModuleDescriptorParserRegistryTest.MyParser.class.getName(),
            ModuleDescriptorParserRegistry.getInstance().getParsers()[0].getClass().getName());
}
 
Example #6
Source File: PomModuleDescriptorWriterTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testTransitive() throws Exception {
    ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance().parseDescriptor(
        new IvySettings(), getClass().getResource("test-transitive.xml"), false);
    PomModuleDescriptorWriter.write(md, dest, getWriterOptions());
    assertTrue(dest.exists());

    String wrote = FileUtil.readEntirely(new BufferedReader(new FileReader(dest)))
            .replaceAll("\r\n", "\n").replace('\r', '\n');
    System.out.println(wrote);
    String expected = readEntirely("test-transitive.pom").replaceAll("\r\n", "\n").replace(
        '\r', '\n');
    assertEquals(expected, wrote);
}
 
Example #7
Source File: IvySettings.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public synchronized void addConfigured(ModuleDescriptorParser parser) {
    ModuleDescriptorParserRegistry.getInstance().addParser(parser);
}
 
Example #8
Source File: BasicResolver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public ResolvedModuleRevision parse(final ResolvedResource mdRef, DependencyDescriptor dd,
        ResolveData data) throws ParseException {

    DependencyDescriptor nsDd = dd;
    dd = toSystem(nsDd);

    ModuleRevisionId mrid = dd.getDependencyRevisionId();
    ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser(
        mdRef.getResource());
    if (parser == null) {
        Message.warn("no module descriptor parser available for " + mdRef.getResource());
        return null;
    }
    Message.verbose("\t" + getName() + ": found md file for " + mrid);
    Message.verbose("\t\t=> " + mdRef);
    Message.debug("\tparser = " + parser);

    ModuleRevisionId resolvedMrid = mrid;

    // first check if this dependency has not yet been resolved
    if (getSettings().getVersionMatcher().isDynamic(mrid)) {
        resolvedMrid = ModuleRevisionId.newInstance(mrid, mdRef.getRevision());
        IvyNode node = data.getNode(resolvedMrid);
        if (node != null && node.getModuleRevision() != null) {
            // this revision has already be resolved : return it
            if (node.getDescriptor() == null || !node.getDescriptor().isDefault()) {
                Message.verbose("\t" + getName() + ": revision already resolved: "
                        + resolvedMrid);
                node.getModuleRevision().getReport().setSearched(true);
                return node.getModuleRevision();
            }
            Message.verbose("\t" + getName() + ": found already resolved revision: "
                    + resolvedMrid
                    + ": but it's a default one, maybe we can find a better one");
        }
    }

    Artifact moduleArtifact = parser.getMetadataArtifact(resolvedMrid, mdRef.getResource());
    return getRepositoryCacheManager().cacheModuleDescriptor(this, mdRef, dd, moduleArtifact,
        downloader, getCacheOptions(data));
}
 
Example #9
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 #10
Source File: DependenciesManager.java    From restcommander with Apache License 2.0 4 votes vote down vote up
public ResolveReport resolve() throws Exception {

        // Module
        ModuleDescriptorParserRegistry.getInstance().addParser(new YamlParser());
        File ivyModule = new File(application, "conf/dependencies.yml");
        if(!ivyModule.exists()) {
            System.out.println("~ !! " + ivyModule.getAbsolutePath() + " does not exist");
            return null;
        }


        // Variables
        System.setProperty("play.path", framework.getAbsolutePath());
        
        // Ivy
        Ivy ivy = configure();

        // Clear the cache
        boolean clearcache = System.getProperty("clearcache") != null;
        if(clearcache){
           System.out.println("~ Clearing cache : " + ivy.getResolutionCacheManager().getResolutionCacheRoot() + ",");
           System.out.println("~");
           try{
      		   FileUtils.deleteDirectory(ivy.getResolutionCacheManager().getResolutionCacheRoot());
      		   System.out.println("~       Clear");
           }catch(IOException e){
        	   System.out.println("~       Could not clear");
        	   System.out.println("~ ");
        	   e.printStackTrace();
             }

           System.out.println("~");
         }
        

        System.out.println("~ Resolving dependencies using " + ivyModule.getAbsolutePath() + ",");
        System.out.println("~");
        
        // Resolve
        ResolveEngine resolveEngine = ivy.getResolveEngine();
        ResolveOptions resolveOptions = new ResolveOptions();
        resolveOptions.setConfs(new String[]{"default"});
        resolveOptions.setArtifactFilter(FilterHelper.getArtifactTypeFilter(new String[]{"jar", "bundle"}));

        return resolveEngine.resolve(ivyModule.toURI().toURL(), resolveOptions);
    }
 
Example #11
Source File: ResolveEngine.java    From ant-ivy with Apache License 2.0 3 votes vote down vote up
/**
 * Resolve the dependencies of a module without downloading corresponding artifacts. The module
 * to resolve is given by its ivy file URL. This method requires appropriate configuration of
 * the ivy instance, especially resolvers.
 *
 * @param ivySource
 *            url of the ivy file to use for dependency resolving
 * @param options
 *            ditto
 * @return an array of the resolved dependencies
 * @throws ParseException
 *             if a parsing problem occurred in the ivy file
 * @throws IOException
 *             if an IO problem was raised during ivy file parsing
 */
public IvyNode[] getDependencies(URL ivySource, ResolveOptions options) throws ParseException,
        IOException {
    return getDependencies(
        ModuleDescriptorParserRegistry.getInstance().parseDescriptor(settings, ivySource,
            options.isValidate()), options, null);
}