Search in sources :

Example 16 with Element

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);
        }
    }
}
Also used : Arrays(java.util.Arrays) OutputBuilder(org.ndx.agile.architecture.base.OutputBuilder) StringUtils(org.apache.commons.lang3.StringUtils) Component(com.structurizr.model.Component) TreeSet(java.util.TreeSet) ConfigProperty(org.apache.deltaspike.core.api.config.ConfigProperty) ModelElementKeys(org.ndx.agile.architecture.base.enhancers.ModelElementKeys) Inject(javax.inject.Inject) StructurizrUtils(org.ndx.agile.architecture.base.utils.StructurizrUtils) Map(java.util.Map) Model(com.structurizr.model.Model) Container(com.structurizr.model.Container) EnumMap(java.util.EnumMap) Set(java.util.Set) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) ModelEnhancer(org.ndx.agile.architecture.base.ModelEnhancer) SoftwareSystem(com.structurizr.model.SoftwareSystem) AgileArchitectureSection(org.ndx.agile.architecture.base.AgileArchitectureSection) Collectors(java.util.stream.Collectors) File(java.io.File) Workspace(com.structurizr.Workspace) Stream(java.util.stream.Stream) TreeMap(java.util.TreeMap) Comparator(java.util.Comparator) Element(com.structurizr.model.Element) TreeSet(java.util.TreeSet) AgileArchitectureSection(org.ndx.agile.architecture.base.AgileArchitectureSection) File(java.io.File)

Example 17 with Element

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;
    });
}
Also used : Arrays(java.util.Arrays) URL(java.net.URL) BiFunction(java.util.function.BiFunction) Dependency(org.apache.maven.model.Dependency) OutputBuilder(org.ndx.agile.architecture.base.OutputBuilder) ModelElementAdapter(org.ndx.agile.architecture.base.enhancers.ModelElementAdapter) Component(com.structurizr.model.Component) TreeSet(java.util.TreeSet) Parent(org.apache.maven.model.Parent) ModelElementKeys(org.ndx.agile.architecture.base.enhancers.ModelElementKeys) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Inject(javax.inject.Inject) MavenProject(org.apache.maven.project.MavenProject) Map(java.util.Map) LinkedList(java.util.LinkedList) Path(java.nio.file.Path) IssueManagement(org.apache.maven.model.IssueManagement) StaticStructureElement(com.structurizr.model.StaticStructureElement) LinkedHashSet(java.util.LinkedHashSet) Container(com.structurizr.model.Container) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) Collection(java.util.Collection) Set(java.util.Set) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) ModelEnhancer(org.ndx.agile.architecture.base.ModelEnhancer) SoftwareSystem(com.structurizr.model.SoftwareSystem) FileSystem(java.nio.file.FileSystem) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Profile(org.apache.maven.model.Profile) File(java.io.File) Scm(org.apache.maven.model.Scm) List(java.util.List) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) Optional(java.util.Optional) FileSystems(java.nio.file.FileSystems) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) Element(com.structurizr.model.Element) InputStream(java.io.InputStream) Scm(org.apache.maven.model.Scm)

Example 18 with Element

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);
}
Also used : Arrays(java.util.Arrays) URL(java.net.URL) BiFunction(java.util.function.BiFunction) Dependency(org.apache.maven.model.Dependency) OutputBuilder(org.ndx.agile.architecture.base.OutputBuilder) ModelElementAdapter(org.ndx.agile.architecture.base.enhancers.ModelElementAdapter) Component(com.structurizr.model.Component) TreeSet(java.util.TreeSet) Parent(org.apache.maven.model.Parent) ModelElementKeys(org.ndx.agile.architecture.base.enhancers.ModelElementKeys) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Inject(javax.inject.Inject) MavenProject(org.apache.maven.project.MavenProject) Map(java.util.Map) LinkedList(java.util.LinkedList) Path(java.nio.file.Path) IssueManagement(org.apache.maven.model.IssueManagement) StaticStructureElement(com.structurizr.model.StaticStructureElement) LinkedHashSet(java.util.LinkedHashSet) Container(com.structurizr.model.Container) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) Collection(java.util.Collection) Set(java.util.Set) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) ModelEnhancer(org.ndx.agile.architecture.base.ModelEnhancer) SoftwareSystem(com.structurizr.model.SoftwareSystem) FileSystem(java.nio.file.FileSystem) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Profile(org.apache.maven.model.Profile) File(java.io.File) Scm(org.apache.maven.model.Scm) List(java.util.List) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) Optional(java.util.Optional) FileSystems(java.nio.file.FileSystems) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) Element(com.structurizr.model.Element) InputStream(java.io.InputStream) Path(java.nio.file.Path) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException)

Example 19 with Element

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");
    }
}
Also used : Element(com.structurizr.model.Element) Relationship(com.structurizr.model.Relationship)

Example 20 with Element

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;
}
Also used : Element(com.structurizr.model.Element) SoftwareSystem(com.structurizr.model.SoftwareSystem) Workspace(com.structurizr.Workspace) DeploymentView(com.structurizr.view.DeploymentView)

Aggregations

Element (com.structurizr.model.Element)27 SoftwareSystem (com.structurizr.model.SoftwareSystem)8 Workspace (com.structurizr.Workspace)7 Relationship (com.structurizr.model.Relationship)7 Collectors (java.util.stream.Collectors)7 Container (com.structurizr.model.Container)6 File (java.io.File)6 IOException (java.io.IOException)6 StaticStructureElement (com.structurizr.model.StaticStructureElement)5 ArrayList (java.util.ArrayList)5 LinkedHashSet (java.util.LinkedHashSet)5 Map (java.util.Map)5 Inject (javax.inject.Inject)5 OutputBuilder (org.ndx.agile.architecture.base.OutputBuilder)5 Component (com.structurizr.model.Component)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 Optional (java.util.Optional)4 Set (java.util.Set)4 Logger (java.util.logging.Logger)4