Search in sources :

Example 31 with Artifact

use of io.fabric8.patch.management.Artifact in project fabric8 by jboss-fuse.

the class GitPatchManagementServiceImpl method unzipFabric8Distro.

/**
 * Unzips <code>bin</code> and <code>etc</code> everything we need from org.apache.karaf.admin.core.
 * @param rootDir
 * @param artifact
 * @param version
 * @param fork
 * @return branch name where the distro should be tracked, or <code>null</code> if it's already tracked
 * @throws IOException
 */
private String unzipFabric8Distro(String rootDir, File artifact, String version, Git fork) throws IOException, GitAPIException {
    ZipFile zf = new ZipFile(artifact);
    try {
        // first pass - what's this distro?
        boolean officialFabric8 = true;
        for (Enumeration<ZipArchiveEntry> e = zf.getEntries(); e.hasMoreElements(); ) {
            ZipArchiveEntry entry = e.nextElement();
            String name = entry.getName();
            if (name.startsWith(rootDir + "/")) {
                name = name.substring(rootDir.length() + 1);
            }
            if ("etc/startup.properties".equals(name)) {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                IOUtils.copyLarge(zf.getInputStream(entry), baos);
                Properties props = new Properties();
                props.load(new ByteArrayInputStream(baos.toByteArray()));
                for (String p : props.stringPropertyNames()) {
                    if (p.startsWith("org/jboss/fuse/shared-commands/")) {
                        // we have Fuse!
                        officialFabric8 = false;
                        break;
                    }
                }
            }
        }
        // checkout correct branch
        if (officialFabric8) {
            if (gitPatchRepository.containsTag(fork, String.format("baseline-ssh-fabric8-%s", version))) {
                return null;
            }
            gitPatchRepository.checkout(fork).setName(gitPatchRepository.getFabric8SSHContainerPatchBranchName()).call();
        } else {
            if (gitPatchRepository.containsTag(fork, String.format("baseline-ssh-fuse-%s", version))) {
                return null;
            }
            gitPatchRepository.checkout(fork).setName(gitPatchRepository.getFuseSSHContainerPatchBranchName()).call();
        }
        for (String managedDirectory : MANAGED_DIRECTORIES) {
            FileUtils.deleteDirectory(new File(fork.getRepository().getWorkTree(), managedDirectory));
        }
        // second pass - unzip what we need
        for (Enumeration<ZipArchiveEntry> e = zf.getEntries(); e.hasMoreElements(); ) {
            ZipArchiveEntry entry = e.nextElement();
            String name = entry.getName();
            if (name.startsWith(rootDir + "/")) {
                name = name.substring(rootDir.length() + 1);
            }
            if (!(name.startsWith("bin") || name.startsWith("etc") || name.startsWith("fabric") || name.startsWith("lib") || name.startsWith("licenses") || name.startsWith("metatype"))) {
                continue;
            }
            if (!entry.isDirectory() && !entry.isUnixSymlink()) {
                File file = new File(fork.getRepository().getWorkTree(), name);
                file.getParentFile().mkdirs();
                FileOutputStream output = new EOLFixingFileOutputStream(fork.getRepository().getWorkTree(), file);
                IOUtils.copyLarge(zf.getInputStream(entry), output);
                IOUtils.closeQuietly(output);
                if (Files.getFileAttributeView(file.toPath(), PosixFileAttributeView.class) != null) {
                    if (name.startsWith("bin/") && !name.endsWith(".bat")) {
                        Files.setPosixFilePermissions(file.toPath(), getPermissionsFromUnixMode(file, 0775));
                    }
                }
            }
        }
        return officialFabric8 ? gitPatchRepository.getFabric8SSHContainerPatchBranchName() : gitPatchRepository.getFuseSSHContainerPatchBranchName();
    } finally {
        if (zf != null) {
            zf.close();
        }
    }
}
Also used : ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) ByteArrayInputStream(java.io.ByteArrayInputStream) EOLFixingFileOutputStream(io.fabric8.patch.management.io.EOLFixingFileOutputStream) FileOutputStream(java.io.FileOutputStream) ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) EOLFixingFileOutputStream(io.fabric8.patch.management.io.EOLFixingFileOutputStream) Properties(java.util.Properties) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) PosixFileAttributeView(java.nio.file.attribute.PosixFileAttributeView)

Example 32 with Artifact

use of io.fabric8.patch.management.Artifact in project fabric8 by jboss-fuse.

the class ServiceImplTest method bundle.

/**
 * Helper method for {@link #bundleUpdatesInPatch()} test
 * @param location
 * @return
 */
private Bundle bundle(String location) {
    BundleStartLevel bsl = createMock(BundleStartLevel.class);
    expect(bsl.getStartLevel()).andReturn(42);
    replay(bsl);
    Bundle b = createMock(Bundle.class);
    Artifact a = Utils.mvnurlToArtifact(location, false);
    expect(b.getSymbolicName()).andReturn(a.getArtifactId()).anyTimes();
    expect(b.getVersion()).andReturn(new Version(a.getVersion())).anyTimes();
    expect(b.getLocation()).andReturn(location).anyTimes();
    expect(b.adapt(BundleStartLevel.class)).andReturn(bsl);
    expect(b.getState()).andReturn(Bundle.ACTIVE);
    replay(b);
    return b;
}
Also used : BundleStartLevel(org.osgi.framework.startlevel.BundleStartLevel) Version(org.osgi.framework.Version) Bundle(org.osgi.framework.Bundle) Artifact(io.fabric8.patch.management.Artifact)

Example 33 with Artifact

use of io.fabric8.patch.management.Artifact in project fabric8 by jboss-fuse.

the class ArchetypeInfoAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    // try artifact first
    Archetype archetype = archetypeService.getArchetypeByArtifact(archetypeGAV);
    if (archetype == null) {
        // then by coordinate
        archetypeService.getArchetype(archetypeGAV);
    }
    if (archetype != null) {
        System.out.println(String.format(FORMAT, "GroupId:", archetype.groupId));
        System.out.println(String.format(FORMAT, "ArtifactId:", archetype.artifactId));
        System.out.println(String.format(FORMAT, "Version:", archetype.version));
        System.out.println(String.format(FORMAT, "Coordinate:", toMavenCoordinate(archetype)));
        System.out.println(String.format(FORMAT, "Description:", emptyIfNull(archetype.description)));
        System.out.println(String.format(FORMAT, "Repository:", emptyIfNull(archetype.repository)));
    } else {
        System.err.println("No archetype found for: " + archetypeGAV);
    }
    return null;
}
Also used : Archetype(io.fabric8.tooling.archetype.catalog.Archetype)

Example 34 with Artifact

use of io.fabric8.patch.management.Artifact in project fabric8 by jboss-fuse.

the class AgentUtils method downloadRepositories.

public static Callable<Map<String, Repository>> downloadRepositories(DownloadManager manager, Set<String> uris) throws MultiException, InterruptedException, MalformedURLException {
    final Map<String, Repository> repositories = new HashMap<>();
    final Downloader downloader = manager.createDownloader();
    final File targetLocation = getDefaultKarafRepository();
    for (String uri : uris) {
        downloader.download(uri, new DownloadCallback() {

            @Override
            public void downloaded(StreamProvider provider) throws Exception {
                String uri = provider.getUrl();
                Repository repository = new Repository(URI.create(uri));
                repository.load(new FileInputStream(provider.getFile()), true);
                synchronized (repositories) {
                    repositories.put(uri, repository);
                }
                for (URI repo : repository.getRepositories()) {
                    downloader.download(repo.toASCIIString(), this);
                }
                Artifact artifact = Utils.mvnurlToArtifact(uri, true);
                if (artifact == null || artifact.getVersion() == null || !artifact.getVersion().endsWith("-SNAPSHOT")) {
                    // we need a feature repository to be available in ${karaf.home}/${karaf.default.repository}
                    // it makes patching much easier
                    // ENTESB-6931: don't store SNAPSHOT feature repositories in ${karaf.home}/${karaf.default.repository}
                    storeInDefaultKarafRepository(targetLocation, provider.getFile(), uri);
                }
            }
        });
    }
    return new Callable<Map<String, Repository>>() {

        @Override
        public Map<String, Repository> call() throws Exception {
            downloader.await();
            return repositories;
        }
    };
}
Also used : StreamProvider(io.fabric8.agent.download.StreamProvider) HashMap(java.util.HashMap) DownloadCallback(io.fabric8.agent.download.DownloadCallback) Downloader(io.fabric8.agent.download.Downloader) URI(java.net.URI) MalformedURLException(java.net.MalformedURLException) MultiException(io.fabric8.common.util.MultiException) FileInputStream(java.io.FileInputStream) Artifact(io.fabric8.patch.management.Artifact) Callable(java.util.concurrent.Callable) Repository(io.fabric8.agent.model.Repository) File(java.io.File)

Example 35 with Artifact

use of io.fabric8.patch.management.Artifact in project fabric8 by jboss-fuse.

the class AgentUtils method getProfileArtifacts.

/**
 * Returns the location and parser map (i.e. the location and the parsed maven coordinates and artifact locations) of each bundle and feature
 */
public static Map<String, Parser> getProfileArtifacts(FabricService fabricService, Profile profile, Iterable<String> bundles, Iterable<Feature> features, Callback<String> nonMavenLocationCallback) {
    Set<String> locations = new HashSet<>();
    for (Feature feature : features) {
        List<BundleInfo> bundleList = feature.getBundles();
        if (bundleList == null) {
            LOGGER.warn("No bundles for feature " + feature);
        } else {
            for (BundleInfo bundle : bundleList) {
                locations.add(bundle.getLocation());
            }
        }
    }
    for (String bundle : bundles) {
        locations.add(bundle);
    }
    Map<String, Parser> artifacts = new HashMap<>();
    for (String location : locations) {
        try {
            if (location.contains("$")) {
                ProfileService profileService = fabricService.adapt(ProfileService.class);
                Profile overlay = profileService.getOverlayProfile(profile);
                location = VersionPropertyPointerResolver.replaceVersions(fabricService, overlay.getConfigurations(), location);
            }
            if (location.startsWith("mvn:") || location.contains(":mvn:")) {
                Parser parser = Parser.parsePathWithSchemePrefix(location);
                artifacts.put(location, parser);
            } else {
                if (nonMavenLocationCallback != null) {
                    nonMavenLocationCallback.call(location);
                }
            }
        } catch (MalformedURLException e) {
            LOGGER.error("Failed to parse bundle URL: " + location + ". " + e, e);
        }
    }
    return artifacts;
}
Also used : MalformedURLException(java.net.MalformedURLException) BundleInfo(io.fabric8.agent.model.BundleInfo) ProfileService(io.fabric8.api.ProfileService) HashMap(java.util.HashMap) Feature(io.fabric8.agent.model.Feature) Profile(io.fabric8.api.Profile) HashSet(java.util.HashSet) Parser(io.fabric8.maven.util.Parser)

Aggregations

File (java.io.File)22 Artifact (io.fabric8.patch.management.Artifact)11 Test (org.junit.Test)10 IOException (java.io.IOException)9 HashMap (java.util.HashMap)8 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)8 FileInputStream (java.io.FileInputStream)6 MavenResolver (io.fabric8.maven.MavenResolver)5 PatchException (io.fabric8.patch.management.PatchException)5 ArrayList (java.util.ArrayList)5 LinkedList (java.util.LinkedList)5 FileOutputStream (java.io.FileOutputStream)4 MalformedURLException (java.net.MalformedURLException)4 Git (org.eclipse.jgit.api.Git)4 Version (org.osgi.framework.Version)4 DeployResults (io.fabric8.deployer.dto.DeployResults)3 Artifact.isSameButVersion (io.fabric8.patch.management.Artifact.isSameButVersion)3 Patch (io.fabric8.patch.management.Patch)3 Utils.mvnurlToArtifact (io.fabric8.patch.management.Utils.mvnurlToArtifact)3 HashSet (java.util.HashSet)3