use of com.structurizr.model.Element in project agile-architecture-documentation-system by Riduidel.
the class DocumentsCollector method collect.
/**
* Collect elements of all sections produced for the given component
* @param element the element for which we want the output
* @param builder output generator used
*/
public void collect(Element element, OutputBuilder builder) {
for (AgileArchitectureSection section : AgileArchitectureSection.values()) {
File sectionFolderFor = builder.outputDirectoryFor(section, element);
File[] filesArray = sectionFolderFor.listFiles((dir, name) -> name.toLowerCase().endsWith(".adoc"));
if (filesArray != null && filesArray.length > 0) {
Set<File> files = Stream.of(filesArray).map(file -> file.getAbsoluteFile()).collect(Collectors.toCollection(() -> new TreeSet<File>()));
hierarchy.get(section).put(element, files);
}
}
}
use of com.structurizr.model.Element in project agile-architecture-documentation-system by Riduidel.
the class MavenDetailsInfererEnhancer method decorateScmUrl.
void decorateScmUrl(Element element, MavenProject mavenProject) {
decorateRecursively(mavenProject, (project, children) -> {
if (project.getScm() != null) {
Scm scm = project.getScm();
if (scm.getUrl() != null) {
String url = scm.getUrl();
// We're not in our project, but in some parent. To go back to our project, we must add to that url
// all the children paths
url = url + children.stream().map(p -> p.getArtifactId()).collect(Collectors.joining("/"));
element.addProperty(ModelElementKeys.SCM_PROJECT, url);
return false;
}
}
// We need to go deeper
return true;
});
}
use of com.structurizr.model.Element in project agile-architecture-documentation-system by Riduidel.
the class MavenDetailsInfererEnhancer method decorateJavaSource.
private void decorateJavaSource(Element element, MavenProject mavenProject) {
String mavenPomUrl = mavenProject.getProperties().get(MAVEN_MODULE_DIR).toString();
List<String> mavenSourceRoots = Optional.ofNullable((List<String>) mavenProject.getCompileSourceRoots()).stream().filter(list -> !list.isEmpty()).findAny().orElse(Arrays.asList("src/main/java"));
String sourcePaths = mavenSourceRoots.stream().map(relativeFolder -> mavenPomUrl + "/" + relativeFolder).map(relativeFolder -> {
if (relativeFolder.startsWith("file")) {
try {
Path file = Paths.get(new URL(relativeFolder).toURI()).normalize();
return file.toFile().toURI().toString();
} catch (Exception e) {
return relativeFolder;
}
} else {
return relativeFolder;
}
}).filter(sourceFolder -> {
if (sourceFolder.startsWith("file")) {
try {
Path file = Paths.get(new URL(sourceFolder).toURI()).normalize();
return file.toFile().exists();
} catch (Exception e) {
return false;
}
} else {
return true;
}
}).collect(Collectors.joining(";"));
if (!sourcePaths.isEmpty())
element.addProperty(ModelElementKeys.JAVA_SOURCES, sourcePaths);
}
use of com.structurizr.model.Element in project dsl by structurizr.
the class IdentifiersRegister method register.
void register(String identifier, Element element) {
if (StringUtils.isNullOrEmpty(identifier)) {
identifier = UUID.randomUUID().toString();
}
identifier = identifier.toLowerCase();
if (identifierScope == IdentifierScope.Hierarchical) {
identifier = calculateHierarchicalIdentifier(identifier, element);
}
// check whether this element has already been registered with another identifier
for (String id : elementsByIdentifier.keySet()) {
Element e = elementsByIdentifier.get(id);
if (e.equals(element) && !id.equals(identifier)) {
if (id.matches("[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}")) {
throw new RuntimeException("Please assign an identifier to \"" + element.getCanonicalName() + "\" before using it with !ref");
} else {
throw new RuntimeException("The element is already registered with an identifier of \"" + id + "\"");
}
}
}
Element e = elementsByIdentifier.get(identifier);
Relationship r = relationshipsByIdentifier.get(identifier);
if ((e == null && r == null) || (e == element)) {
elementsByIdentifier.put(identifier, element);
} else {
throw new RuntimeException("The identifier \"" + identifier + "\" is already in use");
}
}
use of com.structurizr.model.Element in project dsl by structurizr.
the class DeploymentViewParser method parse.
DeploymentView parse(DslContext context, Tokens tokens) {
if (tokens.hasMoreThan(DESCRIPTION_INDEX)) {
throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
}
if (!tokens.includes(ENVIRONMENT_INDEX)) {
throw new RuntimeException("Expected: " + GRAMMAR);
}
Workspace workspace = context.getWorkspace();
String key = "";
String scopeIdentifier = tokens.get(SCOPE_IDENTIFIER_INDEX);
String environment = tokens.get(ENVIRONMENT_INDEX);
if (context.getElement(environment) != null && context.getElement(environment) instanceof DeploymentEnvironment) {
environment = context.getElement(environment).getName();
}
// check that the deployment environment exists in the model
final String env = environment;
if (context.getWorkspace().getModel().getDeploymentNodes().stream().noneMatch(dn -> dn.getEnvironment().equals(env))) {
throw new RuntimeException("The environment \"" + environment + "\" does not exist");
}
String description = "";
if (tokens.includes(DESCRIPTION_INDEX)) {
description = tokens.get(DESCRIPTION_INDEX);
}
DeploymentView view;
if ("*".equals(scopeIdentifier)) {
if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = removeNonWordCharacters(environment) + "-" + VIEW_TYPE;
}
validateViewKey(key);
view = workspace.getViews().createDeploymentView(key, description);
} else {
Element element = context.getElement(scopeIdentifier);
if (element == null) {
throw new RuntimeException("The software system \"" + scopeIdentifier + "\" does not exist");
}
if (element instanceof SoftwareSystem) {
if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = removeNonWordCharacters(element.getName()) + "-" + removeNonWordCharacters(environment) + "-" + VIEW_TYPE;
}
validateViewKey(key);
view = workspace.getViews().createDeploymentView((SoftwareSystem) element, key, description);
} else {
throw new RuntimeException("The element \"" + scopeIdentifier + "\" is not a software system");
}
}
view.setEnvironment(environment);
return view;
}
Aggregations