use of org.apache.ivy.core.module.descriptor.DefaultArtifact in project ant-ivy by apache.
the class PackagingManager method unpackArtifact.
public Artifact unpackArtifact(Artifact artifact, File localFile, File archiveFile) throws IOException {
String packaging = artifact.getExtraAttribute("packaging");
if (packaging == null) {
// not declared as packed, nothing to do
return null;
}
String ext = artifact.getExt();
String[] packings = packaging.split(",");
InputStream in = null;
try {
in = new FileInputStream(localFile);
for (int i = packings.length - 1; i >= 1; i--) {
ArchivePacking packing = settings.getPackingRegistry().get(packings[i]);
if (packing == null) {
throw new IllegalStateException("Unknown packing type '" + packings[i] + "' in the packing chain: " + packaging);
}
if (!(packing instanceof StreamPacking)) {
throw new IllegalStateException("Unsupported archive only packing type '" + packings[i] + "' in the streamed chain: " + packaging);
}
in = ((StreamPacking) packing).unpack(in);
ext = packing.getUnpackedExtension(ext);
}
ArchivePacking packing = settings.getPackingRegistry().get(packings[0]);
if (packing == null) {
throw new IllegalStateException("Unknown packing type '" + packings[0] + "' in the packing chain: " + packaging);
}
packing.unpack(in, archiveFile);
ext = packing.getUnpackedExtension(ext);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
// ignore
}
}
}
return new DefaultArtifact(artifact.getModuleRevisionId(), artifact.getPublicationDate(), artifact.getName(), artifact.getType() + "_unpacked", ext);
}
use of org.apache.ivy.core.module.descriptor.DefaultArtifact in project ant-ivy by apache.
the class ResolveTest method getArchiveFileInCache.
private File getArchiveFileInCache(Ivy ivy, String organisation, String module, String branch, String revision, String artifactName, String type, String ext, Map<String, String> extraAttrs) {
ModuleRevisionId mrid = ModuleRevisionId.newInstance(organisation, module, branch, revision);
DefaultArtifact artifact = new DefaultArtifact(mrid, new Date(), artifactName, type, ext, extraAttrs);
return TestHelper.getRepositoryCacheManager(ivy, mrid).getArchiveFileInCache(artifact);
}
use of org.apache.ivy.core.module.descriptor.DefaultArtifact in project ant-ivy by apache.
the class DefaultRepositoryCacheManagerTest method createArtifact.
private static DefaultArtifact createArtifact(String org, String module, String rev, String name, String type, String ext) {
ModuleId mid = new ModuleId(org, module);
ModuleRevisionId mrid = new ModuleRevisionId(mid, rev);
return new DefaultArtifact(mrid, new Date(), name, type, ext);
}
use of org.apache.ivy.core.module.descriptor.DefaultArtifact 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.DefaultArtifact in project ant-ivy by apache.
the class PackagerResolver method findArtifactRef.
// @Override
public synchronized ResolvedResource findArtifactRef(Artifact artifact, Date date) {
// For our special packager.xml file, defer to superclass
if (PACKAGER_ARTIFACT_NAME.equals(artifact.getName()) && PACKAGER_ARTIFACT_TYPE.equals(artifact.getType()) && PACKAGER_ARTIFACT_EXT.equals(artifact.getExt())) {
return super.findArtifactRef(artifact, date);
}
// Check the cache
ModuleRevisionId mr = artifact.getModuleRevisionId();
PackagerCacheEntry entry = packagerCache.get(mr);
// Ignore invalid entries
if (entry != null && !entry.isBuilt()) {
packagerCache.remove(mr);
entry.cleanup();
entry = null;
}
// Build the artifacts (if not done already)
if (entry == null) {
ResolvedResource packager = findArtifactRef(new DefaultArtifact(mr, null, PACKAGER_ARTIFACT_NAME, PACKAGER_ARTIFACT_TYPE, PACKAGER_ARTIFACT_EXT), date);
if (packager == null) {
return null;
}
entry = new PackagerCacheEntry(mr, this.buildRoot, this.resourceCache, this.resourceURL, this.validate, this.preserve, this.restricted, this.verbose, this.quiet);
try {
entry.build(packager.getResource(), properties);
} catch (IOException e) {
throw new RuntimeException("can't build artifact " + artifact, e);
}
packagerCache.put(mr, entry);
}
// Return reference to desired artifact
return entry.getBuiltArtifact(artifact);
}
Aggregations