Search in sources :

Example 81 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class ProvisionSupport method profileAvailable.

public static Boolean profileAvailable(String profile, String version, Long timeout) throws Exception {
    FabricService fabricService = ServiceLocator.awaitService(FabricService.class);
    ProfileRegistry profileRegistry = fabricService.adapt(ProfileRegistry.class);
    for (long t = 0; (!profileRegistry.hasProfile(version, profile) && t < timeout); t += 2000L) {
        Thread.sleep(2000L);
    }
    return profileRegistry.hasProfile(version, profile);
}
Also used : FabricService(io.fabric8.api.FabricService) ProfileRegistry(io.fabric8.api.ProfileRegistry)

Example 82 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class Log4jLogQuery method loadCoords.

protected String loadCoords(String coords, String filePath, String classifier) throws IOException {
    String[] split = coords.split("/");
    if (split != null && split.length > 2) {
        String groupId = split[0];
        String artifactId = split[1];
        String version = split[2];
        if (resolver == null) {
            Properties defaultProperties = getDefaultProperties();
            Properties systemProperties = System.getProperties();
            if (config == null) {
                Properties combined = new Properties();
                combined.putAll(defaultProperties);
                combined.putAll(systemProperties);
                if (properties != null) {
                    combined.putAll(properties);
                }
                config = new MavenConfigurationImpl(new PropertiesPropertyResolver(combined), ServiceConstants.PID);
            }
            resolver = new AetherBasedResolver(config);
        }
        File file = resolver.resolveFile(groupId, artifactId, classifier, "jar", version);
        if (file.exists() && file.isFile()) {
            if (isRoot(filePath)) {
                return jarIndex(file);
            }
            String fileUri = file.toURI().toString();
            URL url = new URL("jar:" + fileUri + "!" + filePath);
            return loadString(url);
        }
    }
    return null;
}
Also used : MavenConfigurationImpl(io.fabric8.maven.util.MavenConfigurationImpl) PropertiesPropertyResolver(org.ops4j.util.property.PropertiesPropertyResolver) Properties(java.util.Properties) File(java.io.File) URL(java.net.URL) AetherBasedResolver(io.fabric8.maven.url.internal.AetherBasedResolver)

Example 83 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class AbstractProfileManagementTest method testCreateVersionFrom.

@Test
public void testCreateVersionFrom() throws Exception {
    // [FABRIC-1169] Profile version attributes leak to other versions
    // VersionState v12 = getProxy().createVersion("1.0", "1.2", Collections.singletonMap("keyA", "valA"));
    VersionState v12 = getProxy().createVersionFrom("1.0", "1.2", null);
    try {
        Assert.assertEquals("1.2", v12.getId());
        // Assert.assertEquals("valA", v12.getAttributes().get("keyA"));
        List<String> profiles = v12.getProfiles();
        Assert.assertTrue(profiles.contains("default"));
        Assert.assertTrue(profiles.contains("fabric"));
    } finally {
        getProxy().deleteVersion("1.2");
    }
}
Also used : VersionState(io.fabric8.api.mxbean.VersionState) Test(org.junit.Test)

Example 84 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class GitPatchManagementServiceImpl method trackBaselinesForChildContainers.

/**
 * Tracks all baselines for child containers that weren't tracked already. These are looked up inside
 * <code>system/org/apache/karaf/admin/org.apache.karaf.admin.core/**</code>
 * @param fork
 */
private void trackBaselinesForChildContainers(Git fork) throws IOException, GitAPIException {
    if (fork.getRepository().getRef("refs/heads/" + gitPatchRepository.getChildBranchName()) == null) {
        // checkout patches-child branch - it'll track baselines for fabric:container-create-child containers
        String startPoint = "patch-management^{commit}";
        if (fork.getRepository().getRef("refs/remotes/origin/" + gitPatchRepository.getChildBranchName()) != null) {
            startPoint = "refs/remotes/origin/" + gitPatchRepository.getChildBranchName();
        }
        gitPatchRepository.checkout(fork).setName(gitPatchRepository.getChildBranchName()).setStartPoint(startPoint).setCreateBranch(true).setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK).call();
    } else {
        gitPatchRepository.checkout(fork).setName(gitPatchRepository.getChildBranchName()).call();
    }
    File systemRepo = getSystemRepository(karafHome, systemContext);
    File[] versionDirs = new File(systemRepo, "org/apache/karaf/admin/org.apache.karaf.admin.core").listFiles();
    Set<Version> versions = new TreeSet<>();
    if (versionDirs != null) {
        for (File version : versionDirs) {
            if (version.isDirectory()) {
                versions.add(Utils.getOsgiVersion(version.getName()));
            }
        }
    }
    for (Version v : versions) {
        String karafVersion = v.toString();
        String tagName = String.format(EnvType.FABRIC_CHILD.getBaselineTagFormat(), karafVersion);
        if (gitPatchRepository.containsTag(fork, tagName)) {
            continue;
        }
        File baselineDistribution = null;
        String location = String.format(systemRepo.getCanonicalPath() + "/org/apache/karaf/admin/org.apache.karaf.admin.core/%1$s/org.apache.karaf.admin.core-%1$s.jar", karafVersion);
        if (new File(location).isFile()) {
            baselineDistribution = new File(location);
            Activator.log(LogService.LOG_INFO, "Found child baseline distribution: " + baselineDistribution.getCanonicalPath());
        }
        if (baselineDistribution != null) {
            try {
                unzipKarafAdminJar(baselineDistribution, fork.getRepository().getWorkTree());
                fork.add().addFilepattern(".").call();
                RevCommit commit = gitPatchRepository.prepareCommit(fork, String.format(MARKER_BASELINE_CHILD_COMMIT_PATTERN, karafVersion)).call();
                // and we'll tag the child baseline
                fork.tag().setName(tagName).setObjectId(commit).call();
            } catch (Exception e) {
                Activator.log(LogService.LOG_ERROR, null, e.getMessage(), e, true);
            }
        }
    }
    gitPatchRepository.push(fork, gitPatchRepository.getChildBranchName());
}
Also used : Version(org.osgi.framework.Version) Artifact.isSameButVersion(io.fabric8.patch.management.Artifact.isSameButVersion) TreeSet(java.util.TreeSet) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) PatchException(io.fabric8.patch.management.PatchException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 85 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class GitPatchManagementServiceImpl method gatherOverrides.

/**
 * Returns list of bundle updates (maven coordinates) from HF/P patch that should be preserved during
 * installation of R patch
 * @param hfPatchId ID of patch that was detected to be HF patch
 * @param patch currently installed R patch
 * @return
 */
private List<String> gatherOverrides(String hfPatchId, Patch patch) {
    Patch hf = loadPatch(new PatchDetailsRequest(hfPatchId));
    List<String> result = new LinkedList<>();
    if (hf != null && hf.getPatchData() != null) {
        result.addAll(hf.getPatchData().getBundles());
        // leave only these artifacts that are in newer version than in R patch being installed
        if (patch != null && patch.getPatchData() != null) {
            Map<String, Artifact> cache = new HashMap<>();
            for (String bu : patch.getPatchData().getBundles()) {
                Artifact rPatchArtifact = Utils.mvnurlToArtifact(bu, true);
                if (rPatchArtifact != null) {
                    cache.put(String.format("%s:%s", rPatchArtifact.getGroupId(), rPatchArtifact.getArtifactId()), rPatchArtifact);
                }
            }
            for (String bu : hf.getPatchData().getBundles()) {
                Artifact hfPatchArtifact = Utils.mvnurlToArtifact(bu, true);
                String key = String.format("%s:%s", hfPatchArtifact.getGroupId(), hfPatchArtifact.getArtifactId());
                if (cache.containsKey(key)) {
                    Version hfVersion = Utils.getOsgiVersion(hfPatchArtifact.getVersion());
                    Version rVersion = Utils.getOsgiVersion(cache.get(key).getVersion());
                    if (rVersion.compareTo(hfVersion) >= 0) {
                        result.remove(bu);
                    }
                }
            }
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Version(org.osgi.framework.Version) Artifact.isSameButVersion(io.fabric8.patch.management.Artifact.isSameButVersion) ManagedPatch(io.fabric8.patch.management.ManagedPatch) Patch(io.fabric8.patch.management.Patch) PatchDetailsRequest(io.fabric8.patch.management.PatchDetailsRequest) LinkedList(java.util.LinkedList) Artifact(io.fabric8.patch.management.Artifact)

Aggregations

Version (io.fabric8.api.Version)74 Profile (io.fabric8.api.Profile)70 File (java.io.File)52 Test (org.junit.Test)46 IOException (java.io.IOException)41 ArrayList (java.util.ArrayList)36 Container (io.fabric8.api.Container)35 HashMap (java.util.HashMap)34 ProfileService (io.fabric8.api.ProfileService)27 Map (java.util.Map)25 Git (org.eclipse.jgit.api.Git)22 FabricService (io.fabric8.api.FabricService)21 Version (org.osgi.framework.Version)21 ProfileBuilder (io.fabric8.api.ProfileBuilder)18 GitVersion (io.fabric8.api.commands.GitVersion)18 PatchException (io.fabric8.patch.management.PatchException)15 HashSet (java.util.HashSet)15 TreeMap (java.util.TreeMap)14 LinkedList (java.util.LinkedList)13 GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)12