Java Code Examples for org.apache.ivy.core.module.id.ModuleId#newInstance()

The following examples show how to use org.apache.ivy.core.module.id.ModuleId#newInstance() . 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: SearchEngine.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * List module ids of the module accessible through the current resolvers matching the given mid
 * criteria according to the given matcher.
 * <p>
 * ModuleId are returned in the system namespace.
 * </p>
 *
 * @param moduleCrit ModuleId
 * @param matcher PatternMatcher
 * @return ModuleId[]
 */
public ModuleId[] listModules(ModuleId moduleCrit, PatternMatcher matcher) {
    List<ModuleId> ret = new ArrayList<>();

    Map<String, Object> criteria = new HashMap<>();
    addMatcher(matcher, moduleCrit.getOrganisation(), criteria,
        IvyPatternHelper.ORGANISATION_KEY);
    addMatcher(matcher, moduleCrit.getName(), criteria, IvyPatternHelper.MODULE_KEY);

    String[] tokensToList = new String[] {IvyPatternHelper.ORGANISATION_KEY,
            IvyPatternHelper.MODULE_KEY};

    for (DependencyResolver resolver : settings.getResolvers()) {
        Map<String, String>[] moduleIdAsMap = resolver.listTokenValues(tokensToList, criteria);
        for (Map<String, String> moduleId : moduleIdAsMap) {
            String org = moduleId.get(IvyPatternHelper.ORGANISATION_KEY);
            String name = moduleId.get(IvyPatternHelper.MODULE_KEY);
            ModuleId modId = ModuleId.newInstance(org, name);
            ret.add(NameSpaceHelper.transform(modId, resolver.getNamespace()
                    .getToSystemTransformer()));
        }
    }

    return ret.toArray(new ModuleId[ret.size()]);
}
 
Example 2
Source File: PomModuleDescriptorBuilder.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private String getDefaultVersion(PomDependencyData dep) {
    ModuleId moduleId = ModuleId.newInstance(dep.getGroupId(), dep.getArtifactId());
    if (ivyModuleDescriptor.getDependencyManagementMap().containsKey(moduleId)) {
        return ivyModuleDescriptor.getDependencyManagementMap().get(moduleId).getVersion();
    }
    String key = getDependencyMgtExtraInfoKeyForVersion(dep.getGroupId(), dep.getArtifactId());
    return ivyModuleDescriptor.getExtraInfoContentByTagName(key);
}
 
Example 3
Source File: PomModuleDescriptorBuilder.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private String getDefaultScope(PomDependencyData dep) {
    String result;
    ModuleId moduleId = ModuleId.newInstance(dep.getGroupId(), dep.getArtifactId());
    if (ivyModuleDescriptor.getDependencyManagementMap().containsKey(moduleId)) {
        result = ivyModuleDescriptor.getDependencyManagementMap().get(moduleId).getScope();
    } else {
        String key = getDependencyMgtExtraInfoKeyForScope(dep.getGroupId(), dep.getArtifactId());
        result = ivyModuleDescriptor.getExtraInfoContentByTagName(key);
    }
    if (result == null || !MAVEN2_CONF_MAPPING.containsKey(result)) {
        result = "compile";
    }
    return result;
}
 
Example 4
Source File: IvyUtil.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static ModuleId createModuleId(String org, String name) {
    synchronized (MODULE_ID_LOCK) {
        return ModuleId.newInstance(org, name);
    }
}
 
Example 5
Source File: IvyUtil.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static ModuleId createModuleId(String org, String name) {
    synchronized (MODULE_ID_LOCK) {
        return ModuleId.newInstance(org, name);
    }
}
 
Example 6
Source File: IvyUtil.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static ModuleId createModuleId(String org, String name) {
    synchronized (MODULE_ID_LOCK) {
        return ModuleId.newInstance(org, name);
    }
}
 
Example 7
Source File: IvyUtil.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static ModuleId createModuleId(String org, String name) {
    synchronized (MODULE_ID_LOCK) {
        return ModuleId.newInstance(org, name);
    }
}
 
Example 8
Source File: BundleInfoAdapter.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
/**
 * @param parser ModuleDescriptorParser
 * @param baseUri
 *            uri to help build the absolute url if the bundle info has a relative uri.
 * @param bundle BundleInfo
 * @param manifest Manifest
 * @param profileProvider ExecutionEnvironmentProfileProvider
 * @return DefaultModuleDescriptor ditto
 * @throws ProfileNotFoundException if descriptor is not found
 */
public static DefaultModuleDescriptor toModuleDescriptor(ModuleDescriptorParser parser,
        URI baseUri, BundleInfo bundle, Manifest manifest,
        ExecutionEnvironmentProfileProvider profileProvider) throws ProfileNotFoundException {
    DefaultModuleDescriptor md = new DefaultModuleDescriptor(parser, null);
    md.addExtraAttributeNamespace("o", Ivy.getIvyHomeURL() + "osgi");
    ModuleRevisionId mrid = asMrid(BundleInfo.BUNDLE_TYPE, bundle.getSymbolicName(),
        bundle.getVersion());
    md.setResolvedPublicationDate(new Date());
    md.setModuleRevisionId(mrid);

    md.addConfiguration(CONF_DEFAULT);
    md.addConfiguration(CONF_OPTIONAL);
    md.addConfiguration(CONF_TRANSITIVE_OPTIONAL);

    Set<String> exportedPkgNames = new HashSet<>(bundle.getExports().size());
    for (ExportPackage exportPackage : bundle.getExports()) {
        md.getExtraInfos().add(
            new ExtraInfoHolder(EXTRA_INFO_EXPORT_PREFIX + exportPackage.getName(),
                    exportPackage.getVersion().toString()));
        exportedPkgNames.add(exportPackage.getName());
        String[] confDependencies = new String[exportPackage.getUses().size() + 1];
        int i = 0;
        for (String use : exportPackage.getUses()) {
            confDependencies[i++] = CONF_USE_PREFIX + use;
        }
        confDependencies[i] = CONF_NAME_DEFAULT;
        md.addConfiguration(new Configuration(CONF_USE_PREFIX + exportPackage.getName(),
                PUBLIC, "Exported package " + exportPackage.getName(),
                confDependencies, true, null));
    }

    requirementAsDependency(md, bundle, exportedPkgNames);

    if (baseUri != null) {
        for (BundleArtifact bundleArtifact : bundle.getArtifacts()) {
            String type = "jar";
            String ext = "jar";
            String packaging = null;
            if (bundle.hasInnerClasspath() && !bundleArtifact.isSource()) {
                packaging = "bundle";
            }
            if ("packed".equals(bundleArtifact.getFormat())) {
                ext = "jar.pack.gz";
                if (packaging != null) {
                    packaging += ",pack200";
                } else {
                    packaging = "pack200";
                }
            }
            if (bundleArtifact.isSource()) {
                type = "source";
            }
            URI uri = bundleArtifact.getUri();
            if (uri != null) {
                DefaultArtifact artifact = buildArtifact(mrid, baseUri, uri, type, ext,
                    packaging);
                md.addArtifact(CONF_NAME_DEFAULT, artifact);
            }
        }
    }

    if (profileProvider != null) {
        for (String env : bundle.getExecutionEnvironments()) {
            ExecutionEnvironmentProfile profile = profileProvider.getProfile(env);
            if (profile == null) {
                throw new ProfileNotFoundException("Execution environment profile " + env
                        + " not found");
            }
            for (String pkg : profile.getPkgNames()) {
                ArtifactId id = new ArtifactId(ModuleId.newInstance(BundleInfo.PACKAGE_TYPE,
                    pkg), PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION,
                        PatternMatcher.ANY_EXPRESSION);
                DefaultExcludeRule rule = new DefaultExcludeRule(id,
                        ExactOrRegexpPatternMatcher.INSTANCE, null);
                for (String conf : md.getConfigurationsNames()) {
                    rule.addConfiguration(conf);
                }
                md.addExcludeRule(rule);
            }
        }
    }

    if (manifest != null) {
        for (Map.Entry<Object, Object> entries : manifest.getMainAttributes().entrySet()) {
            md.addExtraInfo(new ExtraInfoHolder(entries.getKey().toString(), entries.getValue()
                    .toString()));
        }
    }

    return md;
}