Search in sources :

Example 1 with GitPatchRepositoryImpl

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

the class GitPatchRepositoryIT method init.

@Before
public void init() throws IOException, GitAPIException {
    karafHome = new File("target/karaf-" + (new Date()).getTime());
    karafData = new File(karafHome, "data");
    FileUtils.deleteQuietly(karafHome);
    patchesHome = new File(karafHome, "patches");
    File patchRepositoryLocation = new File(patchesHome, GitPatchRepositoryImpl.MAIN_GIT_REPO_LOCATION);
    repository = new GitPatchRepositoryImpl(EnvType.STANDALONE, patchRepositoryLocation, karafHome, karafHome, karafData, patchesHome);
    repository.open();
}
Also used : GitPatchRepositoryImpl(io.fabric8.patch.management.impl.GitPatchRepositoryImpl) File(java.io.File) Date(java.util.Date) Before(org.junit.Before)

Example 2 with GitPatchRepositoryImpl

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

the class GitPatchManagementServiceImpl method alignTo.

@Override
public boolean alignTo(Map<String, String> versions, List<String> urls, File localMavenRepository, Runnable callback) throws PatchException {
    if (aligning.getAndSet(true)) {
        return false;
    }
    try {
        if (!env.isFabric()) {
            try {
                // we probably survived fabric:create without refreshing patch-management bundle
                env = envService.determineEnvironmentType();
                File patchRepositoryLocation = new File(patchesDir, GitPatchRepositoryImpl.MAIN_GIT_REPO_LOCATION);
                getGitPatchRepository().close();
                GitPatchRepositoryImpl repository = new GitPatchRepositoryImpl(env, patchRepositoryLocation, karafHome, karafBase, karafData, patchesDir);
                setGitPatchRepository(repository);
                start();
                // let's tweak the configuration when entering fabric mode
                // this way we will track other kinds of baselines
                ensurePatchManagementInitialized();
                if (master) {
                    // let the caller know that we've configured patch management in "master" container
                    // this is mainly to push the changes from local to cluster git repository
                    // so child/ssh containers created in fabric can fetch correct baselines
                    callback.run();
                }
            } catch (Exception e) {
                throw new PatchException(e.getMessage(), e);
            }
        }
        if (env.isFabric()) {
            Git fork = null;
            try {
                ensuringLock.lock();
                String version = versions.get(env.getProductId());
                String tagName = String.format(env.getBaselineTagFormat(), version);
                // we have to be at that tag
                Git mainRepository = gitPatchRepository.findOrCreateMainGitRepository();
                fetchFabricPatchData(mainRepository);
                fork = gitPatchRepository.cloneRepository(mainRepository, true);
                gitPatchRepository.checkout(fork).setName(gitPatchRepository.getMainBranchName()).call();
                RevTag tag = gitPatchRepository.findCurrentBaseline(fork);
                if (tag != null && tagName.equals(tag.getTagName())) {
                    if (master) {
                        // and then to data/git/servlet
                        try {
                            gitPatchRepository.pushPatchBranches();
                            callback.run();
                        } catch (Exception e) {
                            Activator.log(LogService.LOG_WARNING, null, e.getMessage(), e, false);
                        } catch (Error e) {
                            // in case newer patch management calls agent which is still wired to old patch management
                            Activator.log(LogService.LOG_WARNING, null, e.getMessage(), e, false);
                        }
                    }
                    return false;
                }
                boolean baselineSwitched = handleNonCurrentBaseline(fork, version, tagName, false, true);
                if (localMavenRepository != null) {
                    try {
                        File systemRepo = getSystemRepository(karafHome, systemContext);
                        // let's copy artifacts referenced in etc/startup.properties from localMavenRepository to system
                        File etcStartupProperties = new File(karafBase, "etc/startup.properties");
                        try (FileInputStream fis = new FileInputStream(etcStartupProperties)) {
                            Properties props = new Properties();
                            props.load(fis);
                            for (String artifact : props.stringPropertyNames()) {
                                File target = new File(systemRepo, artifact);
                                File src = new File(localMavenRepository, artifact);
                                if (!target.exists() && src.isFile()) {
                                    FileUtils.copyFile(src, target);
                                }
                            }
                        }
                        // now the URLs from the passed lis
                        for (String url : urls) {
                            String path = Utils.mvnurlToPath(url);
                            if (path != null) {
                                File target = new File(systemRepo, path);
                                File src = new File(localMavenRepository, path);
                                if (!target.exists() && src.isFile()) {
                                    FileUtils.copyFile(src, target);
                                }
                            }
                        }
                    } catch (Exception e) {
                        Activator.log(LogService.LOG_ERROR, null, e.getMessage(), e, false);
                    }
                }
                return baselineSwitched;
            } catch (Exception e) {
                throw new PatchException(e.getMessage(), e);
            } finally {
                ensuringLock.unlock();
                if (fork != null) {
                    gitPatchRepository.closeRepository(fork, true);
                }
            }
        }
        return false;
    } finally {
        aligning.set(false);
    }
}
Also used : Git(org.eclipse.jgit.api.Git) RevTag(org.eclipse.jgit.revwalk.RevTag) PatchException(io.fabric8.patch.management.PatchException) Properties(java.util.Properties) 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) FileInputStream(java.io.FileInputStream)

Aggregations

File (java.io.File)2 PatchException (io.fabric8.patch.management.PatchException)1 GitPatchRepositoryImpl (io.fabric8.patch.management.impl.GitPatchRepositoryImpl)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Date (java.util.Date)1 Properties (java.util.Properties)1 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)1 Git (org.eclipse.jgit.api.Git)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 RevTag (org.eclipse.jgit.revwalk.RevTag)1 Before (org.junit.Before)1