use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.
the class AbstractFileBasedRepository method getContainedFiles.
@Override
public SortedSet<RepositoryFileReference> getContainedFiles(GenericId id) {
Path dir = this.id2AbsolutePath(id);
SortedSet<RepositoryFileReference> res = new TreeSet<>();
if (!Files.exists(dir)) {
return res;
}
assert (Files.isDirectory(dir));
final OnlyNonHiddenFiles onlyNonHiddenFiles = new OnlyNonHiddenFiles();
try {
Files.walk(dir).filter(f -> {
try {
return onlyNonHiddenFiles.accept(f);
} catch (IOException e) {
LOGGER.debug("Error during crawling", e);
return false;
}
}).map(f -> {
final Path relativePath = dir.relativize(f.getParent());
if (relativePath.toString().isEmpty()) {
return new RepositoryFileReference(id, f.getFileName().toString());
} else {
return new RepositoryFileReference(id, relativePath, f.getFileName().toString());
}
}).forEach(res::add);
} catch (IOException e1) {
LOGGER.debug("Error during crawling", e1);
}
return res;
}
use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.
the class ImportUtils method getTheImport.
/**
* SIDE EFFECT: persists the import when something is changed
*/
public static Optional<TImport> getTheImport(IRepository repository, GenericImportId id) {
Objects.requireNonNull(id);
TImport theImport;
boolean needsPersistence = false;
final TDefinitions definitions = repository.getDefinitions(id);
if (!repository.exists(id)) {
return Optional.empty();
}
if (definitions.getServiceTemplateOrNodeTypeOrNodeTypeImplementation().isEmpty()) {
// definitions exist
// we have to manually assign our import right
theImport = definitions.getImport().get(0);
} else {
// someone created a new import
// store it locally
theImport = (TImport) definitions.getElement();
// undo the side effect of adding it at the wrong place at TDefinitions
definitions.getServiceTemplateOrNodeTypeOrNodeTypeImplementation().clear();
// add import at the right place
definitions.getImport().add(theImport);
// Super class has persisted the definitions
// We have to persist the new variant
needsPersistence = true;
}
if (theImport.getLocation() == null) {
// invalid import -- try to synchronize with storage
SortedSet<RepositoryFileReference> containedFiles = repository.getContainedFiles(id);
// we are only interested in the non-.definitions
for (RepositoryFileReference ref : containedFiles) {
if (!ref.getFileName().endsWith(".definitions")) {
// associated file found
// set the filename of the import to the found xsd
// TODO: no more validity checks are done currently. In the case of XSD: targetNamespace matches, not more than one xsd
theImport.setLocation(ref.getFileName());
needsPersistence = true;
break;
}
}
}
if (needsPersistence) {
try {
BackendUtils.persist(repository, id, definitions);
} catch (IOException e) {
LOGGER.error("Could not persist changes", e);
}
}
return Optional.of(theImport);
}
use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.
the class Utils method compressTarBallAndAddToArtifact.
public static void compressTarBallAndAddToArtifact(Path tempDirectory, IRepository repository, ArtifactTemplateId generatedArtifactTemplateId, String tarball) throws IOException {
Path compressedFile = Paths.get(Utils.compressTarFile(tempDirectory.resolve(tarball).toFile()));
ArtifactTemplateFilesDirectoryId filesDirectoryId = new ArtifactTemplateFilesDirectoryId(generatedArtifactTemplateId);
try (FileInputStream inputStream = new FileInputStream(compressedFile.toFile())) {
repository.putContentToFile(new RepositoryFileReference(filesDirectoryId, compressedFile.getFileName().toString()), inputStream, MediaType.parse("application/x-gzip"));
}
BackendUtils.synchronizeReferences(repository, generatedArtifactTemplateId);
}
use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.
the class GitBasedRepository method hasChangesInFile.
@Override
public boolean hasChangesInFile(DefinitionsChildId id) {
RepositoryFileReference ref = BackendUtils.getRefOfDefinitions(id);
try (Git git = getGit()) {
if (!git.status().call().isClean()) {
List<DiffEntry> diffEntries = git.diff().call();
List<DiffEntry> entries = diffEntries.stream().filter(item -> item.getNewPath().startsWith(BackendUtils.getPathInsideRepo(ref.getParent()))).collect(Collectors.toList());
git.getRepository().close();
return entries.size() > 0;
}
} catch (GitAPIException e) {
LOGGER.trace(e.getMessage(), e);
} catch (IOException e) {
LOGGER.error("Error initializing Git.", e);
}
return false;
}
use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.
the class RepositoryBasedXsdImportManager method getMapFromLocalNameToXSD.
@Override
public Map<String, RepositoryFileReference> getMapFromLocalNameToXSD(final Namespace namespace, final boolean getTypes) {
Set<XSDImportId> importsOfNamespace = this.getImportsOfNamespace(namespace);
Map<String, RepositoryFileReference> result = new HashMap<>();
for (XSDImportId imp : importsOfNamespace) {
final List<String> allDefinedLocalNames = this.getAllDefinedLocalNames(namespace, getTypes);
Optional<RepositoryFileReference> ref = getXsdFileReference(imp);
if (!ref.isPresent()) {
LOGGER.error("Ref is not defined");
} else {
for (String localName : allDefinedLocalNames) {
result.put(localName, ref.get());
}
}
}
return result;
}
Aggregations