use of org.eclipse.winery.repository.backend.filebased.OnlyNonHiddenDirectories in project winery by eclipse.
the class YamlRepository method getDefinitionsChildIds.
/**
* Creates Set of Definitions Child Id Mapps xml definition to compatible yaml definition
*
* @param inputIdClass requested id class
* @param omitDevelopmentVersions omit development versions
* @return set of definitions child id
*/
@Override
public <T extends DefinitionsChildId> SortedSet<T> getDefinitionsChildIds(Class<T> inputIdClass, boolean omitDevelopmentVersions) {
SortedSet<T> res = new TreeSet<>();
List<Class<T>> idClasses = new ArrayList<>();
idClasses.add(inputIdClass);
idClasses = convertDefinitionsChildIdIfNeeded(idClasses);
for (Class<T> idClass : idClasses) {
String rootPathFragment = IdUtil.getRootPathFragment(idClass);
Path dir = this.getRepositoryRoot().resolve(rootPathFragment);
if (!Files.exists(dir)) {
// return empty list if no ids are available
return res;
}
assert (Files.isDirectory(dir));
final OnlyNonHiddenDirectories onhdf = new OnlyNonHiddenDirectories();
// list all directories contained in this directory
try (DirectoryStream<Path> ds = Files.newDirectoryStream(dir, onhdf)) {
for (Path nsP : ds) {
// the current path is the namespace
Namespace ns = new Namespace(nsP.getFileName().toString(), true);
try (DirectoryStream<Path> idDS = Files.newDirectoryStream(nsP, onhdf)) {
for (Path idP : idDS) {
List<XmlId> xmlIds = new ArrayList<>();
if (ArtifactTemplateId.class.isAssignableFrom(inputIdClass)) {
List<String> artifactNames = getAllArtifactNamesFromType(idP, idClass, ns.getDecoded());
for (String artifactName : artifactNames) {
xmlIds.add(new XmlId(artifactName + "@" + IdUtil.getFolderName(idClass), true));
}
} else {
xmlIds.add(new XmlId(idP.getFileName().toString(), true));
}
for (XmlId xmlId : xmlIds) {
if (omitDevelopmentVersions) {
WineryVersion version = VersionUtils.getVersion(xmlId.getDecoded());
if (version.toString().length() > 0 && version.getWorkInProgressVersion() > 0) {
continue;
}
}
Constructor<T> constructor;
try {
constructor = inputIdClass.getConstructor(Namespace.class, XmlId.class);
} catch (Exception e) {
LOGGER.debug("Internal error at determining id constructor", e);
// abort everything, return invalid result
return res;
}
T id;
try {
id = constructor.newInstance(ns, xmlId);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
LOGGER.debug("Internal error at invocation of id constructor", e);
// abort everything, return invalid result
return res;
}
res.add(id);
}
}
}
}
} catch (IOException e) {
LOGGER.debug("Cannot close ds", e);
}
}
return res;
}
use of org.eclipse.winery.repository.backend.filebased.OnlyNonHiddenDirectories in project winery by eclipse.
the class XmlRepository method getDefinitionsChildIds.
public <T extends DefinitionsChildId> SortedSet<T> getDefinitionsChildIds(Class<T> idClass, boolean omitDevelopmentVersions) {
SortedSet<T> res = new TreeSet<>();
String rootPathFragment = IdUtil.getRootPathFragment(idClass);
Path dir = makeAbsolute(Paths.get(rootPathFragment));
if (!Files.exists(dir)) {
// return empty list if no ids are available
return res;
}
assert (Files.isDirectory(dir));
final OnlyNonHiddenDirectories hiddenDirectories = new OnlyNonHiddenDirectories();
// list all directories contained in this directory
try (DirectoryStream<Path> ds = Files.newDirectoryStream(dir, hiddenDirectories)) {
for (Path nsP : ds) {
// the current path is the namespace
Namespace ns = new Namespace(nsP.getFileName().toString(), true);
try (DirectoryStream<Path> idDS = Files.newDirectoryStream(nsP, hiddenDirectories)) {
for (Path idP : idDS) {
XmlId xmlId = new XmlId(idP.getFileName().toString(), true);
if (omitDevelopmentVersions) {
WineryVersion version = VersionUtils.getVersion(xmlId.getDecoded());
if (version.toString().length() > 0 && version.getWorkInProgressVersion() > 0) {
continue;
}
}
Constructor<T> constructor;
try {
constructor = idClass.getConstructor(Namespace.class, XmlId.class);
} catch (Exception e) {
LOGGER.debug("Internal error at determining id constructor", e);
// abort everything, return invalid result
return res;
}
T id;
try {
id = constructor.newInstance(ns, xmlId);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
LOGGER.debug("Internal error at invocation of id constructor", e);
// abort everything, return invalid result
return res;
}
res.add(id);
}
}
}
} catch (IOException e) {
LOGGER.debug("Cannot close ds", e);
}
return res;
}
Aggregations