Search in sources :

Example 1 with FileSystemLock

use of org.uberfire.java.nio.fs.jgit.FileSystemLock in project kie-wb-common by kiegroup.

the class ArchetypeServiceImpl method checkKieTemplates.

void checkKieTemplates() {
    final URL zipResource = getClass().getClassLoader().getResource(KIE_TEMPLATES_ZIP);
    if (zipResource == null) {
        LOGGER.warn("Kie templates could not be found at: {}", KIE_TEMPLATES_ZIP);
        return;
    }
    final Path kieTemplatesPath = createTempDirectory(KIE_TEMPLATES);
    final File kieTemplatesDirectory = new File(kieTemplatesPath.toString());
    final FileSystemLock physicalLock = createLock(kieTemplatesDirectory);
    try {
        physicalLock.lock();
        final boolean unzipSucceeded = unzipFile(zipResource, kieTemplatesDirectory);
        if (unzipSucceeded) {
            try (final DirectoryStream<Path> directoryStream = ioService.newDirectoryStream(kieTemplatesPath, Files::isDirectory)) {
                directoryStream.forEach(path -> {
                    final org.uberfire.backend.vfs.Path templatePomPath = pathUtil.convert(path.resolve(POMServiceImpl.POM_XML));
                    final GAV templateGav = pomService.load(templatePomPath).getGav();
                    addInternalTemplate(path, templateGav);
                });
            }
        }
    } finally {
        physicalLock.unlock();
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) FileSystemLock(org.uberfire.java.nio.fs.jgit.FileSystemLock) Files(org.uberfire.java.nio.file.Files) File(java.io.File) GAV(org.guvnor.common.services.project.model.GAV) URL(java.net.URL)

Example 2 with FileSystemLock

use of org.uberfire.java.nio.fs.jgit.FileSystemLock in project kie-wb-common by kiegroup.

the class ArchetypeServiceImpl method add.

@Override
public void add(final GAV archetypeGav, final GAV templateGav) {
    checkNotNull("archetypeGav", archetypeGav);
    checkNotNull("templateGav", templateGav);
    appendTemplateSuffix(templateGav);
    checkArchetypeAlreadyAdded(templateGav);
    final Path workingDirectoryPath = createTempDirectory(templateGav.getArtifactId());
    final File workingDirectory = new File(workingDirectoryPath.toString());
    final FileSystemLock physicalLock = createLock(workingDirectory);
    try {
        physicalLock.lock();
        executeMaven(new ArchetypeGenerateCommand(workingDirectoryPath.toString(), archetypeGav, templateGav));
        checkModuleValid(workingDirectoryPath.resolve(templateGav.getArtifactId()));
        finishAddExternalArchetype(templateGav, workingDirectory);
    } catch (GitAPIException | MavenEmbedderException e) {
        LOGGER.error(String.format("Failed to add the archetype %s", templateGav), e);
    } finally {
        physicalLock.unlock();
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) FileSystemLock(org.uberfire.java.nio.fs.jgit.FileSystemLock) MavenEmbedderException(org.appformer.maven.integration.embedder.MavenEmbedderException) ArchetypeGenerateCommand(org.kie.workbench.common.screens.archetype.mgmt.backend.maven.ArchetypeGenerateCommand) File(java.io.File)

Example 3 with FileSystemLock

use of org.uberfire.java.nio.fs.jgit.FileSystemLock in project kie-wb-common by kiegroup.

the class ExamplesServiceImpl method initPlaygroundRepository.

@PostConstruct
public void initPlaygroundRepository() {
    URL resource = getClass().getClassLoader().getResource(KIE_WB_PLAYGROUND_ZIP);
    if (resource == null) {
        logger.warn("Playground repository jar not found on classpath.");
        return;
    }
    String userDir = System.getProperty("user.dir");
    md5 = calculateMD5(resource);
    playgroundRootDirectory = new File(userDir, PLAYGROUND_DIRECTORY);
    // .kie-wb-playground/md5number
    File playgroundDirectory = new File(playgroundRootDirectory, md5);
    File doneMarker = new File(playgroundDirectory, DONE_MARKER_NAME);
    this.playgroundSpaceName = PREFIX + md5;
    String repositoryUrl = resolveRepositoryUrl(playgroundDirectory.getAbsolutePath());
    if (!playgroundDirectory.exists()) {
        playgroundDirectory.mkdirs();
    }
    FileSystemLock physicalLock = createLock();
    try {
        physicalLock.lock();
        if (!doneMarker.exists()) {
            // unzip folder if is not uncompressed
            unzipPlayground(resource, playgroundDirectory);
            doneMarker.createNewFile();
        }
        if (!this.existSpace(playgroundSpaceName)) {
            // create space
            this.createPlaygroundHiddenSpace(md5);
            spaceConfigStorageRegistry.getBatch(playgroundSpaceName).run(spaceConfigStorageBatchContext -> {
                // Delete old folders;
                this.deleteOldPlaygrounds(md5);
                // Mark for deletion old playground spaces
                this.deleteOldHiddenSpaces(md5);
                this.cloneRepository(repositoryUrl);
                return null;
            });
        }
    } catch (Exception e) {
        String message = "Can't create examples playground";
        logger.error(message);
        throw new ImportExamplesException(message, e);
    } finally {
        physicalLock.unlock();
    }
    playgroundRepository = new ExampleRepository(repositoryUrl);
}
Also used : ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) FileSystemLock(org.uberfire.java.nio.fs.jgit.FileSystemLock) File(java.io.File) URL(java.net.URL) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) PostConstruct(javax.annotation.PostConstruct)

Aggregations

File (java.io.File)3 FileSystemLock (org.uberfire.java.nio.fs.jgit.FileSystemLock)3 URL (java.net.URL)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 Path (org.uberfire.java.nio.file.Path)2 PostConstruct (javax.annotation.PostConstruct)1 MavenEmbedderException (org.appformer.maven.integration.embedder.MavenEmbedderException)1 GAV (org.guvnor.common.services.project.model.GAV)1 ArchetypeGenerateCommand (org.kie.workbench.common.screens.archetype.mgmt.backend.maven.ArchetypeGenerateCommand)1 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)1 Files (org.uberfire.java.nio.file.Files)1