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");
}
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++;
}
}
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);
}
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;
}
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-> #B;[1.0,1.5]
* </pre>
* <hr>
* <pre>
* #A;3-> { #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);
}
Aggregations