Search in sources :

Example 21 with DefaultArtifact

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);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact)

Example 22 with DefaultArtifact

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);
}
Also used : ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Date(java.util.Date)

Example 23 with DefaultArtifact

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);
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Date(java.util.Date)

Example 24 with DefaultArtifact

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;
}
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 DefaultArtifact

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);
}
Also used : ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) IOException(java.io.IOException) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact)

Aggregations

DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)38 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)33 Test (org.junit.Test)27 Artifact (org.apache.ivy.core.module.descriptor.Artifact)25 Date (java.util.Date)24 File (java.io.File)21 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)13 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)12 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)10 DownloadReport (org.apache.ivy.core.report.DownloadReport)10 GregorianCalendar (java.util.GregorianCalendar)5 IOException (java.io.IOException)3 Locale (java.util.Locale)3 DefaultRepositoryCacheManager (org.apache.ivy.core.cache.DefaultRepositoryCacheManager)3 ModuleId (org.apache.ivy.core.module.id.ModuleId)3 PackagerResolver (org.apache.ivy.plugins.resolver.packager.PackagerResolver)3 ResolvedResource (org.apache.ivy.plugins.resolver.util.ResolvedResource)3 MalformedURLException (java.net.MalformedURLException)2 ParseException (java.text.ParseException)2 HashMap (java.util.HashMap)2