Search in sources :

Example 21 with DefaultModuleDescriptor

use of org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor in project ant-ivy by apache.

the class PublishEngineTest method testAtomicity.

@Test
public void testAtomicity() throws Exception {
    IvySettings settings = new IvySettings();
    final PublishEngine engine = new PublishEngine(settings, new EventManager());
    final int[] counter = new int[] { 0 };
    final DefaultModuleDescriptor md = DefaultModuleDescriptor.newDefaultInstance(ModuleRevisionId.parse("#A;1.0"));
    final FileSystemResolver resolver = new FileSystemResolver() {

        public void publish(Artifact artifact, File src, boolean overwrite) throws IOException {
            super.publish(artifact, src, overwrite);
            synchronized (PublishEngineTest.this) {
                counter[0]++;
            }
            sleepSilently(50);
            synchronized (PublishEngineTest.this) {
                counter[0]++;
            }
        }
    };
    resolver.setName("test");
    resolver.setSettings(settings);
    String publishRepoDir = new File("build/test/publish/repo").getAbsolutePath();
    resolver.addIvyPattern(publishRepoDir + "/[module]/[revision]/[artifact].[ext]");
    resolver.addArtifactPattern(publishRepoDir + "/[module]/[revision]/[artifact].[ext]");
    FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), new File("build/test/publish/module/A.jar"), null);
    XmlModuleDescriptorWriter.write(md, new File("build/test/publish/module/ivy.xml"));
    resolveAndAssertNotFound(settings, resolver, "#A;latest.integration", "before publishing");
    // run publish asynchronously
    new Thread() {

        public void run() {
            try {
                engine.publish(md, Collections.singletonList("build/test/publish/module/[artifact].[ext]"), resolver, new PublishOptions().setSrcIvyPattern("build/test/publish/module/[artifact].[ext]"));
                synchronized (PublishEngineTest.this) {
                    counter[0]++;
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }.start();
    while (true) {
        sleepSilently(5);
        synchronized (this) {
            if (counter[0] == 5) {
                break;
            } else if (counter[0] < 4) {
                resolveAndAssertNotFound(settings, resolver, "#A;latest.integration", "after " + (counter[0] / 2) + " artifacts published");
            }
        }
    }
    resolveAndAssertFound(settings, resolver, "#A;1.0");
}
Also used : EventManager(org.apache.ivy.core.event.EventManager) IvySettings(org.apache.ivy.core.settings.IvySettings) IOException(java.io.IOException) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) File(java.io.File) FileSystemResolver(org.apache.ivy.plugins.resolver.FileSystemResolver) Test(org.junit.Test)

Example 22 with DefaultModuleDescriptor

use of org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor in project ant-ivy by apache.

the class TestPerformance method generateModules.

private void generateModules(int nbModules, int minDependencies, int maxDependencies, int minVersions, int maxVersions) throws IOException {
    int nb = 0;
    int curDep = 1;
    int varDeps = maxDependencies - minDependencies;
    int varVersions = maxVersions - minVersions;
    Random r = new Random(System.currentTimeMillis());
    while (nb < nbModules) {
        int deps = minDependencies + r.nextInt(varDeps + 1);
        int versions = minVersions + r.nextInt(varVersions + 1);
        int prevCurDep = curDep;
        for (int ver = 0; ver < versions; ver++) {
            DefaultModuleDescriptor md = new DefaultModuleDescriptor(ModuleRevisionId.newInstance("apache", "mod" + nb, "1." + ver), "integration", new Date());
            curDep = prevCurDep;
            for (int i = 0; i < deps && curDep < nbModules; i++) {
                int d;
                if (i % 2 == 1) {
                    d = nb + i;
                    if (d >= prevCurDep) {
                        d = curDep;
                        curDep++;
                    }
                } else {
                    d = curDep;
                    curDep++;
                }
                DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, ModuleRevisionId.newInstance("apache", "mod" + d, "latest.integration"), false, false, true);
                dd.addDependencyConfiguration("default", "default");
                md.addDependency(dd);
            }
            XmlModuleDescriptorWriter.write(md, new File("build/test/perf/mod" + nb + "/ivy-1." + ver + ".xml"));
            FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), new File("build/test/perf/mod" + nb + "/mod" + nb + "-1." + ver + ".jar"), null);
        }
        nb++;
    }
}
Also used : Random(java.util.Random) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) File(java.io.File) Date(java.util.Date)

Example 23 with DefaultModuleDescriptor

use of org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor in project ant-ivy by apache.

the class AbstractOSGiResolver method buildResolvedCapabilityMd.

private MDResolvedResource buildResolvedCapabilityMd(DependencyDescriptor dd, ModuleDescriptor md) {
    String org = dd.getDependencyRevisionId().getOrganisation();
    String name = dd.getDependencyRevisionId().getName();
    String rev = md.getExtraInfoContentByTagName(BundleInfoAdapter.EXTRA_INFO_EXPORT_PREFIX + name);
    ModuleRevisionId capabilityRev = ModuleRevisionId.newInstance(org, name, rev, Collections.singletonMap(CAPABILITY_EXTRA_ATTR, md.getModuleRevisionId().toString()));
    DefaultModuleDescriptor capabilityMd = new DefaultModuleDescriptor(capabilityRev, getSettings().getStatusManager().getDefaultStatus(), new Date());
    String useConf = BundleInfoAdapter.CONF_USE_PREFIX + dd.getDependencyRevisionId().getName();
    capabilityMd.addConfiguration(BundleInfoAdapter.CONF_DEFAULT);
    capabilityMd.addConfiguration(BundleInfoAdapter.CONF_OPTIONAL);
    capabilityMd.addConfiguration(BundleInfoAdapter.CONF_TRANSITIVE_OPTIONAL);
    capabilityMd.addConfiguration(new Configuration(useConf));
    DefaultDependencyDescriptor capabilityDD = new DefaultDependencyDescriptor(md.getModuleRevisionId(), false);
    capabilityDD.addDependencyConfiguration(BundleInfoAdapter.CONF_NAME_DEFAULT, BundleInfoAdapter.CONF_NAME_DEFAULT);
    capabilityDD.addDependencyConfiguration(BundleInfoAdapter.CONF_NAME_OPTIONAL, BundleInfoAdapter.CONF_NAME_OPTIONAL);
    capabilityDD.addDependencyConfiguration(BundleInfoAdapter.CONF_NAME_TRANSITIVE_OPTIONAL, BundleInfoAdapter.CONF_NAME_TRANSITIVE_OPTIONAL);
    capabilityDD.addDependencyConfiguration(useConf, useConf);
    capabilityMd.addDependency(capabilityDD);
    MetadataArtifactDownloadReport report = new MetadataArtifactDownloadReport(null);
    report.setDownloadStatus(DownloadStatus.NO);
    report.setSearched(true);
    ResolvedModuleRevision rmr = new ResolvedModuleRevision(this, this, capabilityMd, report);
    return new MDResolvedResource(null, capabilityMd.getRevision(), rmr);
}
Also used : MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) Configuration(org.apache.ivy.core.module.descriptor.Configuration) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) Date(java.util.Date) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource)

Example 24 with DefaultModuleDescriptor

use of org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor in project ant-ivy by apache.

the class BundleInfoAdapter method toModuleDescriptor.

/**
 * @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;
}
Also used : Configuration(org.apache.ivy.core.module.descriptor.Configuration) ArtifactId(org.apache.ivy.core.module.id.ArtifactId) ExtraInfoHolder(org.apache.ivy.core.module.descriptor.ExtraInfoHolder) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) URI(java.net.URI) Date(java.util.Date) DefaultExcludeRule(org.apache.ivy.core.module.descriptor.DefaultExcludeRule) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) HashMap(java.util.HashMap) Map(java.util.Map) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) HashSet(java.util.HashSet)

Example 25 with DefaultModuleDescriptor

use of org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor in project ant-ivy by apache.

the class TestHelper method parseMicroIvyDescriptor.

/**
 * Parses a string representation of a module descriptor in micro ivy format.
 * <p>
 * Examples:
 * </p>
 * <pre>
 * #A;1
 * </pre>
 * <hr>
 * <pre>
 * #A;2-&gt; #B;[1.0,1.5]
 * </pre>
 * <hr>
 * <pre>
 * #A;3-&gt; { #B;[1.0,1.5] #C;[2.0,2.5] }
 * </pre>
 *
 * @param microIvy
 *            the micro ivy description of the module descriptor
 * @return the parsed module descriptor
 */
public static ModuleDescriptor parseMicroIvyDescriptor(String microIvy) {
    Pattern mridPattern = ModuleRevisionId.NON_CAPTURING_PATTERN;
    Matcher m = mridPattern.matcher(microIvy);
    if (m.matches()) {
        return DefaultModuleDescriptor.newBasicInstance(ModuleRevisionId.parse(microIvy), new Date());
    }
    Pattern oneDependencyPattern = Pattern.compile(String.format("(%s)\\s*->\\s*(%s)", mridPattern.pattern(), mridPattern.pattern()));
    m = oneDependencyPattern.matcher(microIvy);
    if (m.matches()) {
        DefaultModuleDescriptor md = DefaultModuleDescriptor.newBasicInstance(ModuleRevisionId.parse(m.group(1)), new Date());
        md.addDependency(new DefaultDependencyDescriptor(ModuleRevisionId.parse(m.group(2)), false));
        return md;
    }
    String p = String.format("(%s)\\s*->\\s*\\{\\s*((?:%s,?\\s+)*%s)?\\s*\\}", mridPattern.pattern(), mridPattern.pattern(), mridPattern.pattern());
    Pattern multipleDependenciesPattern = Pattern.compile(p);
    m = multipleDependenciesPattern.matcher(microIvy);
    if (m.matches()) {
        DefaultModuleDescriptor md = DefaultModuleDescriptor.newBasicInstance(ModuleRevisionId.parse(m.group(1)), new Date());
        String mrids = m.group(2);
        if (mrids != null) {
            for (ModuleRevisionId dep : parseMrids(mrids)) {
                md.addDependency(new DefaultDependencyDescriptor(dep, false));
            }
        }
        return md;
    }
    throw new IllegalArgumentException("invalid micro ivy format: " + microIvy);
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) Date(java.util.Date)

Aggregations

DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)30 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)17 Date (java.util.Date)10 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)9 File (java.io.File)7 Configuration (org.apache.ivy.core.module.descriptor.Configuration)7 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)6 ResolveReport (org.apache.ivy.core.report.ResolveReport)6 IvySettings (org.apache.ivy.core.settings.IvySettings)6 Test (org.junit.Test)6 MetadataArtifactDownloadReport (org.apache.ivy.core.report.MetadataArtifactDownloadReport)5 ResolveOptions (org.apache.ivy.core.resolve.ResolveOptions)5 ParseException (java.text.ParseException)4 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)4 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)4 BufferedReader (java.io.BufferedReader)3 IOException (java.io.IOException)3 Map (java.util.Map)3 Artifact (org.apache.ivy.core.module.descriptor.Artifact)3 ModuleId (org.apache.ivy.core.module.id.ModuleId)3