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();
}
}
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();
}
}
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);
}
Aggregations