├── .github ├── FUNDING.yml └── workflows │ ├── build_master.yml │ ├── build_standard.yml │ └── release.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── buildSrc ├── bnd-platform │ ├── build.gradle │ ├── gradle.properties │ └── src │ │ └── main │ │ ├── groovy │ │ └── org │ │ │ └── standardout │ │ │ └── gradle │ │ │ └── plugin │ │ │ └── platform │ │ │ ├── PlatformPlugin.groovy │ │ │ ├── PlatformPluginExtension.groovy │ │ │ └── internal │ │ │ ├── ArtifactsMatch.java │ │ │ ├── BundleArtifact.java │ │ │ ├── BundlesAction.groovy │ │ │ ├── DefaultFeature.groovy │ │ │ ├── DependencyArtifact.java │ │ │ ├── Feature.java │ │ │ ├── FileBundleArtifact.groovy │ │ │ ├── MergeBundleArtifact.groovy │ │ │ ├── ResolvedBundleArtifact.groovy │ │ │ ├── SourceBundleArtifact.groovy │ │ │ ├── config │ │ │ ├── ArtifactFeature.groovy │ │ │ ├── BndConfig.groovy │ │ │ ├── BundleDependency.groovy │ │ │ ├── Configurations.groovy │ │ │ ├── ImportsConfig.groovy │ │ │ ├── MergeConfig.groovy │ │ │ ├── SourceFeature.groovy │ │ │ ├── StoredConfig.groovy │ │ │ ├── StoredConfigImpl.groovy │ │ │ └── UnmodifiableStoredConfig.java │ │ │ ├── osdetect │ │ │ ├── Arch.java │ │ │ ├── OS.java │ │ │ └── SwtPlatform.java │ │ │ └── util │ │ │ ├── DefaultQualifierMap.groovy │ │ │ ├── FeatureUtil.groovy │ │ │ ├── VersionQualifierMap.java │ │ │ ├── VersionUtil.groovy │ │ │ ├── bnd │ │ │ ├── BndHelper.java │ │ │ ├── BundleHelper.groovy │ │ │ ├── ByteArrayResource.groovy │ │ │ └── JarInfo.groovy │ │ │ ├── gradle │ │ │ ├── DependencyHelper.groovy │ │ │ └── DummyDependency.groovy │ │ │ └── groovy │ │ │ ├── IgnoreMethodDecorator.groovy │ │ │ ├── IgnoreSetPropertyDecorator.groovy │ │ │ └── LaxPropertyDecorator.groovy │ │ └── resources │ │ └── META-INF │ │ └── gradle-plugins │ │ └── org.standardout.bnd-platform.properties ├── build.gradle ├── p2-plugin │ ├── LICENSE │ ├── build.gradle │ ├── gradle.properties │ └── src │ │ └── main │ │ ├── groovy │ │ ├── com │ │ │ └── github │ │ │ │ └── missedone │ │ │ │ └── gradle │ │ │ │ ├── AbstractPublishTask.groovy │ │ │ │ ├── ArtifactPublishTask.groovy │ │ │ │ ├── ArtifactoryClient.groovy │ │ │ │ ├── ArtifactoryP2Extension.groovy │ │ │ │ ├── ArtifactoryP2Plugin.groovy │ │ │ │ ├── PublishArtifactRemoveTask.groovy │ │ │ │ └── PublishP2RepoPublishTask.groovy │ │ └── org │ │ │ └── osgi │ │ │ └── framework │ │ │ └── Version.groovy │ │ └── resources │ │ └── META-INF │ │ └── gradle-plugins │ │ └── p2-plugin.properties └── settings.gradle ├── examples ├── context-map-example-1.png ├── context-map-example-2.png ├── context-map-example-3.png ├── team-map-example-1.png └── team-map-example-2.png ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── graphviz-test-example ├── ex1.png ├── ex1i.png ├── ex1m.png ├── ex2.png ├── ex3.png ├── ex4-1.png ├── ex4-2.png ├── ex5.svg ├── ex5b.png ├── ex5p.pdf ├── ex5s.png ├── ex6a.png ├── ex6d.png ├── ex7.png ├── ex8.png └── graphviz.png ├── settings.gradle └── src ├── main ├── java │ ├── guru │ │ └── nidi │ │ │ └── graphviz │ │ │ ├── NonnullApi.java │ │ │ ├── attribute │ │ │ ├── Arrow.java │ │ │ ├── Attributed.java │ │ │ ├── Attributes.java │ │ │ ├── Color.java │ │ │ ├── EndLabel.java │ │ │ ├── Font.java │ │ │ ├── For.java │ │ │ ├── ForAll.java │ │ │ ├── ForGraph.java │ │ │ ├── ForLink.java │ │ │ ├── ForNode.java │ │ │ ├── GraphAttr.java │ │ │ ├── Image.java │ │ │ ├── Label.java │ │ │ ├── LinkAttr.java │ │ │ ├── MapAttributes.java │ │ │ ├── NodeAttr.java │ │ │ ├── Rank.java │ │ │ ├── Records.java │ │ │ ├── Shape.java │ │ │ ├── SimpleLabel.java │ │ │ ├── SingleAttributes.java │ │ │ ├── Size.java │ │ │ ├── Style.java │ │ │ └── package-info.java │ │ │ ├── engine │ │ │ ├── AbstractGraphvizEngine.java │ │ │ ├── AbstractJsGraphvizEngine.java │ │ │ ├── BuiltInRasterizer.java │ │ │ ├── Communicator.java │ │ │ ├── Engine.java │ │ │ ├── EngineResult.java │ │ │ ├── Format.java │ │ │ ├── Graphviz.java │ │ │ ├── GraphvizCmdLineEngine.java │ │ │ ├── GraphvizEngine.java │ │ │ ├── GraphvizException.java │ │ │ ├── GraphvizJdkEngine.java │ │ │ ├── GraphvizNashornEngine.java │ │ │ ├── GraphvizServer.java │ │ │ ├── GraphvizServerEngine.java │ │ │ ├── IOFunction.java │ │ │ ├── IoUtils.java │ │ │ ├── Options.java │ │ │ ├── Rasterizer.java │ │ │ ├── Renderer.java │ │ │ ├── ResultHandler.java │ │ │ ├── SalamanderRasterizer.java │ │ │ ├── SvgRasterizer.java │ │ │ └── package-info.java │ │ │ ├── model │ │ │ ├── Compass.java │ │ │ ├── CreationContext.java │ │ │ ├── Factory.java │ │ │ ├── Graph.java │ │ │ ├── ImmutableGraph.java │ │ │ ├── ImmutableNode.java │ │ │ ├── ImmutablePortNode.java │ │ │ ├── Link.java │ │ │ ├── LinkList.java │ │ │ ├── LinkSource.java │ │ │ ├── LinkTarget.java │ │ │ ├── MutableAttributed.java │ │ │ ├── MutableGraph.java │ │ │ ├── MutableNode.java │ │ │ ├── Node.java │ │ │ ├── Port.java │ │ │ ├── PortNode.java │ │ │ ├── PortSource.java │ │ │ ├── Serializer.java │ │ │ ├── SimpleMutableAttributed.java │ │ │ ├── ThrowingBiConsumer.java │ │ │ ├── ThrowingFunction.java │ │ │ └── package-info.java │ │ │ ├── parse │ │ │ ├── Lexer.java │ │ │ ├── Parser.java │ │ │ ├── ParserException.java │ │ │ ├── Position.java │ │ │ ├── Token.java │ │ │ └── package-info.java │ │ │ ├── service │ │ │ ├── CommandBuilder.java │ │ │ ├── CommandLineExecutor.java │ │ │ ├── CommandRunner.java │ │ │ ├── SystemUtils.java │ │ │ └── package-info.java │ │ │ └── use │ │ │ └── FontTools.java │ └── org │ │ └── contextmapper │ │ └── contextmap │ │ └── generator │ │ ├── ContextMapGenerator.java │ │ └── model │ │ ├── AbstractRelationship.java │ │ ├── BoundedContext.java │ │ ├── BoundedContextType.java │ │ ├── ContextMap.java │ │ ├── DownstreamPatterns.java │ │ ├── Partnership.java │ │ ├── Relationship.java │ │ ├── SharedKernel.java │ │ ├── UpstreamDownstreamRelationship.java │ │ ├── UpstreamPatterns.java │ │ └── exception │ │ ├── BoundedContextAlreadyPartOfContextMapException.java │ │ ├── BoundedContextIsNotATeamException.java │ │ ├── BoundedContextNotPartOfContextMapException.java │ │ └── TeamCannotImplementTeamException.java └── resources │ └── team-icon.png └── test ├── java ├── guru │ └── nidi │ │ └── graphviz │ │ ├── PerformanceTest.java │ │ ├── attribute │ │ ├── ArrowTest.java │ │ ├── ColorTest.java │ │ ├── EndLabelTest.java │ │ ├── FontTest.java │ │ ├── LabelTest.java │ │ ├── RankTest.java │ │ ├── RecordsTest.java │ │ ├── ShapeTest.java │ │ └── SimpleLabelTest.java │ │ ├── engine │ │ ├── AbstractGraphvizEngineTest.java │ │ ├── EngineTest.java │ │ ├── FormatTest.java │ │ ├── GraphvizTest.java │ │ ├── OptionsTest.java │ │ ├── RendererTest.java │ │ └── SvgRasterizerTest.java │ │ ├── model │ │ ├── ContextTest.java │ │ ├── ExampleTest.java │ │ ├── ReadmeTest.java │ │ ├── SerializerTest.java │ │ └── SimpleTest.java │ │ ├── parse │ │ ├── LexerTest.java │ │ └── ParserTest.java │ │ └── service │ │ ├── CommandRunnerTest.java │ │ └── CommandRunnerWhichTest.java └── org │ └── contextmapper │ └── contextmap │ └── generator │ ├── ContextMapGeneratorLabelsTest.java │ ├── ContextMapGeneratorTest.java │ └── model │ ├── BoundedContextTest.java │ ├── ContextMapTest.java │ └── RelationshipTests.java └── resources ├── color.dot ├── g1.dot ├── laurent.png ├── logback.xml ├── outfile1.svg ├── simplelogger.properties └── test1.dot /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: stefan-ka 2 | 3 | -------------------------------------------------------------------------------- /.github/workflows/build_master.yml: -------------------------------------------------------------------------------- 1 | name: Build (master) 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | tags-ignore: 8 | - '**' 9 | 10 | jobs: 11 | build_and_publish_snapshot: 12 | runs-on: ubuntu-18.04 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | with: 17 | fetch-depth: 0 18 | - name: Set up JDK 11 19 | uses: actions/setup-java@v1 20 | with: 21 | java-version: 11 22 | - name: Install Graphviz 23 | run: sudo apt-get -y install graphviz 24 | - name: Gradle caches 25 | uses: actions/cache@v2 26 | with: 27 | path: | 28 | ~/.gradle/caches 29 | ~/.gradle/wrapper 30 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} 31 | restore-keys: | 32 | ${{ runner.os }}-gradle- 33 | - name: Configure GPG Key 34 | run: | 35 | mkdir -p ~/.gnupg/ 36 | printf "$GPG_SIGNING_KEY" | base64 --decode > ~/.gnupg/private.key 37 | gpg --import --batch ~/.gnupg/private.key 38 | env: 39 | GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }} 40 | - name: Grant execute permission for gradlew 41 | run: chmod +x gradlew 42 | - name: Build with Gradle 43 | run: ./gradlew clean build snapshot publish -Psigning.keyId=${GPG_KEY_ID} -Psigning.password=${GPG_KEY_PASSPHRASE} -Psigning.secretKeyRingFile=/home/runner/.gnupg/private.key 44 | env: 45 | GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} 46 | GPG_KEY_PASSPHRASE: ${{ secrets.GPG_KEY_PASSPHRASE }} 47 | OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} 48 | OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} 49 | ARTIFACTORY_API_KEY: ${{ secrets.ARTIFACTORY_API_KEY }} 50 | ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }} 51 | - name: Upload coverage to Codecov 52 | uses: codecov/codecov-action@v1 53 | 54 | -------------------------------------------------------------------------------- /.github/workflows/build_standard.yml: -------------------------------------------------------------------------------- 1 | name: Build (standard) 2 | 3 | on: 4 | push: 5 | branches-ignore: 6 | - master 7 | pull_request: 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-18.04 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | with: 16 | fetch-depth: 0 17 | - name: Set up JDK 11 18 | uses: actions/setup-java@v1 19 | with: 20 | java-version: 11 21 | - name: Install Graphviz 22 | run: sudo apt-get -y install graphviz 23 | - name: Gradle caches 24 | uses: actions/cache@v2 25 | with: 26 | path: | 27 | ~/.gradle/caches 28 | ~/.gradle/wrapper 29 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} 30 | restore-keys: | 31 | ${{ runner.os }}-gradle- 32 | - name: Grant execute permission for gradlew 33 | run: chmod +x gradlew 34 | - name: Build with Gradle 35 | run: ./gradlew clean build snapshot 36 | - name: Upload coverage to Codecov 37 | uses: codecov/codecov-action@v1 38 | 39 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release Context Map Generator 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*' 7 | 8 | jobs: 9 | release: 10 | runs-on: ubuntu-18.04 11 | 12 | steps: 13 | - uses: actions/checkout@v2 14 | with: 15 | fetch-depth: 0 16 | - name: Set up JDK 11 17 | uses: actions/setup-java@v1 18 | with: 19 | java-version: 11 20 | - name: Install Graphviz 21 | run: sudo apt-get -y install graphviz 22 | - name: Gradle caches 23 | uses: actions/cache@v2 24 | with: 25 | path: | 26 | ~/.gradle/caches 27 | ~/.gradle/wrapper 28 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} 29 | restore-keys: | 30 | ${{ runner.os }}-gradle- 31 | - name: Configure GPG Key 32 | run: | 33 | mkdir -p ~/.gnupg/ 34 | printf "$GPG_SIGNING_KEY" | base64 --decode > ~/.gnupg/private.key 35 | gpg --import --batch ~/.gnupg/private.key 36 | env: 37 | GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }} 38 | - name: Grant execute permission for gradlew 39 | run: chmod +x gradlew 40 | - name: Release with Gradle 41 | run: ./gradlew clean build publish -Prelease.useLastTag=true -Psigning.keyId=${GPG_KEY_ID} -Psigning.password=${GPG_KEY_PASSPHRASE} -Psigning.secretKeyRingFile=/home/runner/.gnupg/private.key 42 | env: 43 | GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} 44 | GPG_KEY_PASSPHRASE: ${{ secrets.GPG_KEY_PASSPHRASE }} 45 | OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} 46 | OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} 47 | ARTIFACTORY_API_KEY: ${{ secrets.ARTIFACTORY_API_KEY }} 48 | ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }} 49 | - name: Upload coverage to Codecov 50 | uses: codecov/codecov-action@v1 51 | 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Gradle 5 | .gradle 6 | build 7 | target 8 | 9 | # IntelliJ 10 | .idea 11 | out/ 12 | 13 | # Generated sources 14 | src-gen 15 | 16 | # Log file 17 | *.log 18 | 19 | # BlueJ files 20 | *.ctxt 21 | 22 | # Mobile Tools for Java (J2ME) 23 | .mtj.tmp/ 24 | 25 | # Package Files # 26 | *.jar 27 | *.war 28 | *.nar 29 | *.ear 30 | *.zip 31 | *.tar.gz 32 | *.rar 33 | 34 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 35 | hs_err_pid* 36 | -------------------------------------------------------------------------------- /buildSrc/bnd-platform/gradle.properties: -------------------------------------------------------------------------------- 1 | # override in gradle user home 2 | bintrayUser= 3 | bintrayApiKey= 4 | -------------------------------------------------------------------------------- /buildSrc/bnd-platform/src/main/groovy/org/standardout/gradle/plugin/platform/internal/ArtifactsMatch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | package org.standardout.gradle.plugin.platform.internal; 19 | 20 | /** 21 | * Interface marking objects that match specific bundle artifacts. 22 | * Used to determine which artifacts to add to a feature. 23 | * 24 | * @author Simon Templer 25 | */ 26 | public interface ArtifactsMatch { 27 | 28 | /** 29 | * @return if the given artifact is a match 30 | */ 31 | public boolean acceptArtifact(BundleArtifact artifact); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /buildSrc/bnd-platform/src/main/groovy/org/standardout/gradle/plugin/platform/internal/BundleArtifact.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.standardout.gradle.plugin.platform.internal; 18 | 19 | import java.io.File; 20 | 21 | import org.standardout.gradle.plugin.platform.internal.config.BndConfig; 22 | 23 | /** 24 | * Represents a bundle artifact represented by a single file. 25 | */ 26 | public interface BundleArtifact { 27 | 28 | /** 29 | * The associated file. 30 | */ 31 | File getFile(); 32 | 33 | /** 34 | * The original version. 35 | */ 36 | String getVersion(); 37 | 38 | /** 39 | * If the bundle is a source bundle. 40 | */ 41 | boolean isSource(); 42 | 43 | /** 44 | * The bundle name. 45 | */ 46 | String getBundleName(); 47 | 48 | /** 49 | * The bundle symbolic name. 50 | */ 51 | String getSymbolicName(); 52 | 53 | /** 54 | * The modified bundle version to use. 55 | */ 56 | String getModifiedVersion(); 57 | 58 | /** 59 | * Target OS of the bundle. 60 | */ 61 | String getOs(); 62 | 63 | /** 64 | * Target Architecture of the bundle. 65 | */ 66 | String getArch(); 67 | 68 | /** 69 | * Allowed window subsystem of the bundle. 70 | */ 71 | String getWs(); 72 | 73 | /** 74 | * Should the bundle be wrapped using bnd? 75 | */ 76 | boolean isWrap(); 77 | 78 | /** 79 | * The reason why it should not be wrapped 80 | */ 81 | String getNoWrapReason(); 82 | 83 | /** 84 | * The associated bnd configuration, if any 85 | */ 86 | BndConfig getBndConfig(); 87 | 88 | /** 89 | * The unique identifier. 90 | */ 91 | String getId(); 92 | 93 | /** 94 | * The name of the target file. 95 | */ 96 | String getTargetFileName(); 97 | 98 | /** 99 | * The associated source bundle, if any. 100 | */ 101 | BundleArtifact getSourceBundle(); 102 | 103 | /** 104 | * Set the associated source bundle, may be null. 105 | */ 106 | void setSourceBundle(BundleArtifact sourceBundle); 107 | 108 | } 109 | -------------------------------------------------------------------------------- /buildSrc/bnd-platform/src/main/groovy/org/standardout/gradle/plugin/platform/internal/DefaultFeature.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.standardout.gradle.plugin.platform.internal 18 | 19 | import org.gradle.api.Project 20 | import org.standardout.gradle.plugin.platform.internal.util.VersionUtil; 21 | 22 | 23 | class DefaultFeature implements Feature { 24 | 25 | String id 26 | String label 27 | String version 28 | String providerName 29 | List bundles = [] 30 | List includedFeatures = [] 31 | Project project 32 | 33 | private String finalVersion 34 | 35 | @Override 36 | public String getVersion() { 37 | if (!finalVersion) { 38 | finalVersion = VersionUtil.addQualifier(version?:'0.0.0', this, project) 39 | } 40 | finalVersion 41 | } 42 | 43 | void setVersion(String version) { 44 | this.version = VersionUtil.toOsgiVersion(version).toString() 45 | } 46 | 47 | String getProviderName() { 48 | providerName?:'Generated with bnd-platform' 49 | } 50 | 51 | @Override 52 | public Iterable getBundles() { 53 | bundles == null ? [] : bundles 54 | } 55 | 56 | @Override 57 | public Iterable getIncludedFeatures() { 58 | includedFeatures == null ? [] : includedFeatures 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /buildSrc/bnd-platform/src/main/groovy/org/standardout/gradle/plugin/platform/internal/DependencyArtifact.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.standardout.gradle.plugin.platform.internal; 18 | 19 | import java.util.Set; 20 | 21 | import org.gradle.api.Project; 22 | import org.gradle.api.artifacts.ResolvedArtifact; 23 | import org.gradle.api.artifacts.ResolvedDependency; 24 | 25 | public interface DependencyArtifact { 26 | 27 | /** 28 | * @return the direct dependencies of this artifact 29 | */ 30 | Set getDirectDependencies(Project project); 31 | 32 | /** 33 | * @return the resolved dependencies the artifact represents 34 | * (no transitive dependencies) 35 | */ 36 | Iterable getRepresentedDependencies(); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /buildSrc/bnd-platform/src/main/groovy/org/standardout/gradle/plugin/platform/internal/Feature.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.standardout.gradle.plugin.platform.internal; 18 | 19 | /** 20 | * Represents an Eclipse Update Site Feature. 21 | * 22 | * The version, bundles and includedFeatures properties may only be accessed 23 | * after the feature configuration is complete. 24 | */ 25 | public interface Feature { 26 | 27 | public String getId(); 28 | 29 | public String getLabel(); 30 | 31 | public String getVersion(); 32 | 33 | public String getProviderName(); 34 | 35 | public Iterable getBundles(); 36 | 37 | public Iterable getIncludedFeatures(); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /buildSrc/bnd-platform/src/main/groovy/org/standardout/gradle/plugin/platform/internal/MergeBundleArtifact.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.standardout.gradle.plugin.platform.internal 18 | 19 | import java.io.File; 20 | import java.util.Set; 21 | 22 | import org.gradle.api.Project; 23 | import org.gradle.api.artifacts.ResolvedArtifact; 24 | import org.gradle.api.artifacts.ResolvedDependency; 25 | import org.standardout.gradle.plugin.platform.internal.config.BndConfig; 26 | import org.standardout.gradle.plugin.platform.internal.config.StoredConfig; 27 | 28 | class MergeBundleArtifact extends FileBundleArtifact implements DependencyArtifact { 29 | 30 | private final Iterable representedDependencies 31 | 32 | private final Set directDependencies 33 | 34 | /** 35 | * Create a bundle artifact represented by a Jar. 36 | */ 37 | MergeBundleArtifact(File artifactFile, Project project, StoredConfig config, 38 | String customId, Set directDependencies, 39 | Iterable representedDependencies) { 40 | super(artifactFile, project, config, customId, 'mergedBundle') 41 | this.directDependencies = directDependencies.asImmutable() 42 | this.representedDependencies = representedDependencies 43 | } 44 | 45 | @Override 46 | public Set getDirectDependencies(Project project) { 47 | directDependencies 48 | } 49 | 50 | @Override 51 | public Iterable getRepresentedDependencies() { 52 | representedDependencies 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /buildSrc/bnd-platform/src/main/groovy/org/standardout/gradle/plugin/platform/internal/SourceBundleArtifact.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.standardout.gradle.plugin.platform.internal 18 | 19 | import org.gradle.api.Project 20 | import org.gradle.api.artifacts.ResolvedArtifact 21 | import org.standardout.gradle.plugin.platform.internal.config.BndConfig; 22 | 23 | class SourceBundleArtifact extends ResolvedBundleArtifact { 24 | 25 | BundleArtifact parentBundle 26 | 27 | public SourceBundleArtifact(ResolvedArtifact artifact, Project project) { 28 | super(artifact, null, project); 29 | } 30 | 31 | @Override 32 | public String getBundleName() { 33 | if (parentBundle) { 34 | parentBundle.bundleName + ' Sources' 35 | } 36 | else { 37 | super.getBundleName() + ' ' + classifier 38 | } 39 | } 40 | 41 | @Override 42 | public String getSymbolicName() { 43 | if (parentBundle) { 44 | parentBundle.symbolicName + '.source' 45 | } 46 | else { 47 | super.getSymbolicName() + ".$classifier" 48 | } 49 | } 50 | 51 | String getModifiedVersion() { 52 | if (parentBundle) { 53 | // return the parent bundles version to prevent issues 54 | // with cached source bundles referencing outdated bundle 55 | // versions, e.g. if hash qualifiers are used 56 | parentBundle.modifiedVersion 57 | } 58 | else { 59 | super.getModifiedVersion() 60 | } 61 | } 62 | 63 | @Override 64 | public boolean isSource() { 65 | true 66 | } 67 | 68 | @Override 69 | public BndConfig getBndConfig() { 70 | // no bnd configuration applicable 71 | null 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /buildSrc/bnd-platform/src/main/groovy/org/standardout/gradle/plugin/platform/internal/config/ImportsConfig.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.standardout.gradle.plugin.platform.internal.config 18 | 19 | import org.gradle.api.Project; 20 | 21 | /** 22 | * Represents the configuration of a library concerning the import of packages to other bundles. 23 | */ 24 | class ImportsConfig { 25 | 26 | /** 27 | * Constructor. 28 | * 29 | * @param project the gradle project 30 | */ 31 | ImportsConfig(Project project, String group, String name, String version) { 32 | this.project = project 33 | 34 | this.group = group 35 | this.name = name 36 | this.version = version 37 | } 38 | 39 | final Project project 40 | 41 | final String group 42 | 43 | final String name 44 | 45 | final String version 46 | 47 | Closure versionStrategy 48 | 49 | } 50 | -------------------------------------------------------------------------------- /buildSrc/bnd-platform/src/main/groovy/org/standardout/gradle/plugin/platform/internal/config/SourceFeature.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.standardout.gradle.plugin.platform.internal.config 18 | 19 | import org.gradle.api.Project; 20 | import org.standardout.gradle.plugin.platform.internal.BundleArtifact 21 | import org.standardout.gradle.plugin.platform.internal.Feature; 22 | import org.standardout.gradle.plugin.platform.internal.util.VersionUtil; 23 | 24 | class SourceFeature implements Feature { 25 | 26 | private final @Delegate Feature feature 27 | 28 | private final Project project 29 | 30 | private String finalVersion 31 | 32 | public SourceFeature(Feature feature, Project project) { 33 | super(); 34 | this.feature = feature; 35 | this.project = project; 36 | } 37 | 38 | @Override 39 | public String getId() { 40 | feature.id + '.source' 41 | } 42 | 43 | @Override 44 | public String getLabel() { 45 | feature.label + ' sources' 46 | } 47 | 48 | @Override 49 | public Iterable getBundles() { 50 | // source bundles 51 | feature.bundles.collect { BundleArtifact ba -> 52 | def bundle = ba.isSource() ? ba : ba.sourceBundle 53 | // only accept bundle if it still exists in the artifact map 54 | // if it has been removed from there, it was an empty source bundle 55 | (bundle && project.platform.artifacts[bundle.id]) ? bundle : null 56 | }.findAll() 57 | } 58 | 59 | @Override 60 | public Iterable getIncludedFeatures() { 61 | def features = feature.includedFeatures 62 | features.collect { 63 | project.platform.features["${it.id}.source"] 64 | }.findAll() 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /buildSrc/bnd-platform/src/main/groovy/org/standardout/gradle/plugin/platform/internal/config/StoredConfig.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.standardout.gradle.plugin.platform.internal.config 18 | 19 | import groovy.lang.Closure; 20 | 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | import org.codehaus.groovy.runtime.InvokerHelper; 25 | import org.gradle.api.Project; 26 | import org.gradle.api.artifacts.Dependency; 27 | import java.io.File 28 | 29 | /** 30 | * Stores the configuration of a bundle concerning bnd. 31 | */ 32 | interface StoredConfig { 33 | 34 | List getBndClosures() 35 | 36 | List getImportsClosures() 37 | 38 | BndConfig evaluate(Project project, File file, Map initialProperties) 39 | 40 | BndConfig evaluate(Project project, String group, String name, String version, Map initialProperties) 41 | 42 | BndConfig evaluate(Project project, String group, String name, String version, File file, Map initialProperties) 43 | 44 | /** 45 | * @return the imports configuration, may be null 46 | */ 47 | ImportsConfig importsConfig(Project project, String group, String name, String version) 48 | 49 | /** 50 | * Append the given configuration. 51 | */ 52 | void leftShift(StoredConfig other) 53 | 54 | /** 55 | * Prepend the own configuration to the given configuration object. 56 | */ 57 | void rightShift(StoredConfig other) 58 | 59 | /** 60 | * @return if the configuration is empty 61 | */ 62 | boolean isEmpty() 63 | 64 | } 65 | -------------------------------------------------------------------------------- /buildSrc/bnd-platform/src/main/groovy/org/standardout/gradle/plugin/platform/internal/config/UnmodifiableStoredConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.standardout.gradle.plugin.platform.internal.config; 18 | 19 | import groovy.lang.Closure; 20 | 21 | import java.io.File; 22 | import java.util.Collections; 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | import org.gradle.api.Project; 27 | 28 | public class UnmodifiableStoredConfig implements StoredConfig { 29 | 30 | private final StoredConfig decoratee; 31 | 32 | public UnmodifiableStoredConfig(StoredConfig decoratee) { 33 | super(); 34 | this.decoratee = decoratee; 35 | } 36 | 37 | @SuppressWarnings("rawtypes") 38 | public List getBndClosures() { 39 | return Collections.unmodifiableList(decoratee.getBndClosures()); 40 | } 41 | 42 | @SuppressWarnings("rawtypes") 43 | public List getImportsClosures() { 44 | return Collections.unmodifiableList(decoratee.getImportsClosures()); 45 | } 46 | 47 | public BndConfig evaluate(Project project, File file, Map initialProperties) { 48 | return decoratee.evaluate(project, file, initialProperties); 49 | } 50 | 51 | public BndConfig evaluate(Project project, String group, String name, 52 | String version, Map initialProperties) { 53 | return decoratee.evaluate(project, group, name, version, initialProperties); 54 | } 55 | 56 | public BndConfig evaluate(Project project, String group, String name, 57 | String version, File file, Map initialProperties) { 58 | return decoratee.evaluate(project, group, name, version, file, initialProperties); 59 | } 60 | 61 | @Override 62 | public ImportsConfig importsConfig(Project project, String group, 63 | String name, String version) { 64 | return decoratee.importsConfig(project, group, name, version); 65 | } 66 | 67 | public void leftShift(StoredConfig other) { 68 | throw new UnsupportedOperationException("Immutable configuration"); 69 | } 70 | 71 | public void rightShift(StoredConfig other) { 72 | decoratee.rightShift(other); 73 | } 74 | 75 | public boolean isEmpty() { 76 | return decoratee.isEmpty(); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /buildSrc/bnd-platform/src/main/groovy/org/standardout/gradle/plugin/platform/internal/osdetect/Arch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copied from DurianSwt 3 | * 4 | * Copyright 2016 DiffPlug 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.standardout.gradle.plugin.platform.internal.osdetect; 19 | 20 | /** Enum for handling different processor architectures supported by SWT. */ 21 | public enum Arch { 22 | x86, x64; 23 | 24 | /** Returns the appropriate value depending on the arch. */ 25 | public T x86x64(T val86, T val64) { 26 | switch (this) { 27 | case x86: 28 | return val86; 29 | case x64: 30 | return val64; 31 | default: 32 | throw unsupportedException(this); 33 | } 34 | } 35 | 36 | /** Returns the Arch for the native platform: 32-bit JVM on 64-bit Windows returns Arch.x64. */ 37 | public static Arch getNative() { 38 | return OS.getNative().getArch(); 39 | } 40 | 41 | /** Returns the Arch for the native platform: 32-bit JVM on 64-bit Windows returns Arch.x86. */ 42 | public static Arch getRunning() { 43 | return OS.getRunning().getArch(); 44 | } 45 | 46 | /** Returns an UnsupportedOperationException for the given arch. */ 47 | public static UnsupportedOperationException unsupportedException(Arch arch) { 48 | return new UnsupportedOperationException("Arch '" + arch + "' is unsupported."); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /buildSrc/bnd-platform/src/main/groovy/org/standardout/gradle/plugin/platform/internal/util/VersionQualifierMap.java: -------------------------------------------------------------------------------- 1 | package org.standardout.gradle.plugin.platform.internal.util; 2 | 3 | import org.osgi.framework.Version; 4 | 5 | public interface VersionQualifierMap { 6 | 7 | /** 8 | * Get the qualifier to use for a specific artifact. 9 | * 10 | * @param type the artifact type, e.g. bundle or feature 11 | * @param name the artifact name 12 | * @param version the artifact version 13 | * @param ident the identifier for a specific instance of the artifact, e.g. the bnd configuration hash 14 | * @return the qualifier to use 15 | */ 16 | public String getQualifier(String type, String name, Version version, String ident); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /buildSrc/bnd-platform/src/main/groovy/org/standardout/gradle/plugin/platform/internal/util/bnd/ByteArrayResource.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.standardout.gradle.plugin.platform.internal.util.bnd 18 | 19 | import java.io.IOException 20 | import java.io.InputStream; 21 | import java.io.OutputStream; 22 | import java.nio.ByteBuffer 23 | 24 | import org.apache.commons.io.IOUtils; 25 | 26 | import aQute.bnd.osgi.Resource; 27 | 28 | class ByteArrayResource implements Resource { 29 | 30 | final byte[] data 31 | final long lastMod 32 | String extra 33 | ByteBuffer buffer 34 | 35 | ByteArrayResource(Resource resource) { 36 | data = resource.openInputStream().withStream { 37 | InputStream input -> 38 | IOUtils.toByteArray(input) 39 | } 40 | lastMod = resource.lastModified() 41 | extra = resource.extra 42 | } 43 | 44 | ByteArrayResource(byte[] data, long lastMod, String extra = null) { 45 | this.data = data 46 | this.lastMod = lastMod 47 | this.extra = extra 48 | } 49 | 50 | @Override 51 | public InputStream openInputStream() throws Exception { 52 | return new ByteArrayInputStream(data); 53 | } 54 | 55 | @Override 56 | public void write(OutputStream out) throws Exception { 57 | out.write(data) 58 | } 59 | 60 | @Override 61 | public long lastModified() { 62 | return lastMod; 63 | } 64 | 65 | @Override 66 | public long size() throws Exception { 67 | return data.length; 68 | } 69 | 70 | @Override 71 | public void close() throws IOException { 72 | 73 | } 74 | 75 | @Override 76 | public ByteBuffer buffer() throws Exception { 77 | if (buffer != null) { 78 | return buffer; 79 | } 80 | return buffer = ByteBuffer.wrap(data); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /buildSrc/bnd-platform/src/main/groovy/org/standardout/gradle/plugin/platform/internal/util/bnd/JarInfo.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.standardout.gradle.plugin.platform.internal.util.bnd 18 | 19 | import java.util.jar.JarFile; 20 | 21 | import aQute.bnd.osgi.Analyzer; 22 | 23 | class JarInfo { 24 | 25 | /** 26 | * Instruction properties - properties to retain as instructions when 27 | * wrapping an existing bundle. 28 | */ 29 | private static final Set INSTRUCTION_PROPERTIES = ([ 30 | Analyzer.BUNDLE_SYMBOLICNAME, 31 | Analyzer.BUNDLE_VERSION, 32 | Analyzer.BUNDLE_NAME, 33 | Analyzer.EXPORT_PACKAGE, 34 | Analyzer.IMPORT_PACKAGE, 35 | Analyzer.BUNDLE_LICENSE, 36 | Analyzer.BUNDLE_VENDOR, 37 | 'Eclipse-PlatformFilter', 38 | 'Eclipse-SourceBundle' // to be able to identify a source bundle 39 | ] as Set).asImmutable() 40 | 41 | final Map instructions 42 | 43 | final String symbolicName 44 | 45 | final String bundleName 46 | 47 | final String platformFilter; 48 | 49 | final String version 50 | 51 | JarInfo(File file) { 52 | JarFile jar = new JarFile(file) 53 | 54 | def manifest = jar.manifest 55 | Map properties = [:] 56 | 57 | if (manifest != null) { 58 | def main = manifest.mainAttributes 59 | INSTRUCTION_PROPERTIES.each { 60 | String value = main.getValue(it) 61 | if (value) { 62 | properties[it] = value 63 | } 64 | } 65 | 66 | bundleName = main.getValue(Analyzer.BUNDLE_NAME) 67 | version = main.getValue(Analyzer.BUNDLE_VERSION) 68 | symbolicName = extractSymbolicName(main.getValue(Analyzer.BUNDLE_SYMBOLICNAME)) 69 | platformFilter = main.getValue('Eclipse-PlatformFilter') 70 | } 71 | else { 72 | // the Jar has no manifest 73 | bundleName = null 74 | version = null 75 | symbolicName = null 76 | platformFilter = null 77 | } 78 | 79 | instructions = properties.asImmutable() 80 | } 81 | 82 | public static String extractSymbolicName(String name) { 83 | if (name == null) { 84 | return name 85 | } 86 | 87 | int end = name.indexOf(';') 88 | if (end > 0) { 89 | // remove all additional instructions 90 | name[0..(end - 1)] 91 | } 92 | else { 93 | name 94 | } 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /buildSrc/bnd-platform/src/main/groovy/org/standardout/gradle/plugin/platform/internal/util/gradle/DummyDependency.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.standardout.gradle.plugin.platform.internal.util.gradle 18 | 19 | import groovy.transform.EqualsAndHashCode 20 | 21 | import org.gradle.api.artifacts.Dependency 22 | import org.gradle.internal.HasInternalProtocol 23 | 24 | /** 25 | * Dummy dependency class (that may have a null name). 26 | * 27 | * @author Simon Templer 28 | */ 29 | @EqualsAndHashCode 30 | class DummyDependency implements Dependency { 31 | 32 | private final String group 33 | private final String name 34 | private final String version 35 | private final String classifier 36 | private String because 37 | 38 | DummyDependency(String group, String name, String version, String classifier = null) { 39 | super() 40 | this.group = group 41 | this.name = name 42 | this.version = version 43 | this.classifier = classifier 44 | } 45 | 46 | DummyDependency(Map properties) { 47 | this(properties.group, properties.name, properties.version, properties.classifier) 48 | } 49 | 50 | @Override 51 | public String getGroup() { 52 | group 53 | } 54 | 55 | @Override 56 | public String getName() { 57 | name 58 | } 59 | 60 | @Override 61 | public String getVersion() { 62 | version 63 | } 64 | 65 | public String getClassifier() { 66 | classifier 67 | } 68 | 69 | @Override 70 | public boolean contentEquals(Dependency paramDependency) { 71 | equals(paramDependency) 72 | } 73 | 74 | @Override 75 | public Dependency copy() { 76 | this 77 | } 78 | 79 | @Override 80 | public void because(String because) { 81 | this.because = because 82 | } 83 | 84 | @Override 85 | public String getReason() { 86 | because 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /buildSrc/bnd-platform/src/main/groovy/org/standardout/gradle/plugin/platform/internal/util/groovy/IgnoreMethodDecorator.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.standardout.gradle.plugin.platform.internal.util.groovy 18 | 19 | import org.codehaus.groovy.runtime.InvokerHelper; 20 | 21 | /** 22 | * Decorator for a class that ignores method invocations. 23 | */ 24 | class IgnoreMethodDecorator { 25 | 26 | private final def decoratee 27 | 28 | IgnoreMethodDecorator(def decoratee) { 29 | this.decoratee = decoratee 30 | } 31 | 32 | @Override 33 | def invokeMethod(String name, def args) { 34 | // ignore 35 | } 36 | 37 | @Override 38 | def getProperty(String name) { 39 | decoratee."$name" 40 | } 41 | 42 | @Override 43 | void setProperty(String name, def value) { 44 | decoratee."$name" = value 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /buildSrc/bnd-platform/src/main/groovy/org/standardout/gradle/plugin/platform/internal/util/groovy/IgnoreSetPropertyDecorator.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.standardout.gradle.plugin.platform.internal.util.groovy 18 | 19 | import org.codehaus.groovy.runtime.InvokerHelper; 20 | 21 | /** 22 | * Decorator for a class that doesn't fail on accessing missing properties. 23 | */ 24 | class IgnoreSetPropertyDecorator { 25 | 26 | private final def decoratee 27 | 28 | IgnoreSetPropertyDecorator(def decoratee) { 29 | this.decoratee = decoratee 30 | } 31 | 32 | @Override 33 | def getProperty(String name) { 34 | decoratee."$name" 35 | } 36 | 37 | @Override 38 | void setProperty(String name, def value) { 39 | // ignore 40 | } 41 | 42 | @Override 43 | def invokeMethod(String name, def args) { 44 | InvokerHelper.invokeMethod(decoratee, name, args) 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /buildSrc/bnd-platform/src/main/groovy/org/standardout/gradle/plugin/platform/internal/util/groovy/LaxPropertyDecorator.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.standardout.gradle.plugin.platform.internal.util.groovy 18 | 19 | import org.codehaus.groovy.runtime.InvokerHelper; 20 | 21 | /** 22 | * Decorator for a class that doesn't fail on accessing missing properties. 23 | */ 24 | class LaxPropertyDecorator { 25 | 26 | private final def decoratee 27 | 28 | LaxPropertyDecorator(def decoratee) { 29 | this.decoratee = decoratee 30 | } 31 | 32 | def invokeMethod(String name, def args) { 33 | InvokerHelper.invokeMethod(decoratee, name, args) 34 | } 35 | 36 | def getProperty(String name) { 37 | try { 38 | decoratee."$name" 39 | } catch (MissingPropertyException e) { 40 | null 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /buildSrc/bnd-platform/src/main/resources/META-INF/gradle-plugins/org.standardout.bnd-platform.properties: -------------------------------------------------------------------------------- 1 | implementation-class=org.standardout.gradle.plugin.platform.PlatformPlugin -------------------------------------------------------------------------------- /buildSrc/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | maven { 5 | url "https://plugins.gradle.org/m2/" 6 | } 7 | } 8 | } 9 | 10 | repositories { 11 | jcenter() 12 | } 13 | 14 | dependencies { 15 | runtime subprojects.findAll { it.getTasksByName("jar", false) } 16 | } 17 | -------------------------------------------------------------------------------- /buildSrc/p2-plugin/gradle.properties: -------------------------------------------------------------------------------- 1 | pluginName=p2-plugin 2 | pluginDesc=The Gradle plugin to publish P2 repo to Artifactory (originally bintray; adjusted here) 3 | projectUrl=https://github.com/missedone/gradle-bintray-p2-plugin 4 | 5 | projectVersion=1.2.0 6 | 7 | bintrayPluginVersion=1.7.3 8 | publishPluginVersion=0.9.6 9 | httpBuilderVersion=0.7.2 10 | -------------------------------------------------------------------------------- /buildSrc/p2-plugin/src/main/groovy/com/github/missedone/gradle/AbstractPublishTask.groovy: -------------------------------------------------------------------------------- 1 | package com.github.missedone.gradle 2 | 3 | import org.gradle.api.DefaultTask 4 | import org.gradle.api.GradleException 5 | import org.gradle.api.tasks.Input 6 | import org.gradle.api.tasks.Optional 7 | import org.gradle.api.tasks.TaskAction 8 | 9 | abstract class AbstractPublishTask extends DefaultTask { 10 | static final String DEFAULT_API_URL = 'https://api.bintray.com' 11 | 12 | @Input 13 | @Optional 14 | String apiUrl = DEFAULT_API_URL 15 | 16 | @Input 17 | String user 18 | 19 | @Input 20 | String apiKey 21 | 22 | @Input 23 | String repoOwner 24 | 25 | @Input 26 | String repoName 27 | 28 | @Input 29 | @Optional 30 | String packageVersion 31 | 32 | @TaskAction 33 | void start() { 34 | withExceptionHandling { 35 | executeAction() 36 | } 37 | } 38 | 39 | private void withExceptionHandling(Closure c) { 40 | try { 41 | c() 42 | } 43 | catch (Exception e) { 44 | logger.error "Failed to execute Bintray P2 task", e 45 | throw new GradleException(e.message) 46 | } 47 | } 48 | 49 | abstract void executeAction() 50 | } 51 | -------------------------------------------------------------------------------- /buildSrc/p2-plugin/src/main/groovy/com/github/missedone/gradle/ArtifactPublishTask.groovy: -------------------------------------------------------------------------------- 1 | package com.github.missedone.gradle 2 | 3 | import org.gradle.api.tasks.Input 4 | import org.gradle.api.tasks.InputFile 5 | import org.gradle.api.tasks.Optional 6 | 7 | class ArtifactPublishTask extends AbstractPublishTask { 8 | 9 | @InputFile 10 | File artifactFile 11 | 12 | @Input 13 | String packageName 14 | 15 | @Input 16 | @Optional 17 | String targetPath 18 | 19 | @Input 20 | @Optional 21 | boolean override 22 | 23 | ArtifactPublishTask() { 24 | this.description = 'Publishes artifact to bintray.com.' 25 | this.group = 'publishing' 26 | } 27 | 28 | @Override 29 | void executeAction() { 30 | ArtifactoryClient client = new ArtifactoryClient(apiUrl, user, apiKey) 31 | client.uploadContent(artifactFile, repoOwner, repoName, targetPath, packageName, packageVersion, override) 32 | } 33 | } -------------------------------------------------------------------------------- /buildSrc/p2-plugin/src/main/groovy/com/github/missedone/gradle/ArtifactoryP2Extension.groovy: -------------------------------------------------------------------------------- 1 | package com.github.missedone.gradle 2 | 3 | class ArtifactoryP2Extension { 4 | 5 | // 6 | // common properties for the tasks 7 | // 8 | 9 | String apiUrl 10 | 11 | String user 12 | 13 | String apiKey 14 | 15 | String repoOwner 16 | 17 | String repoName 18 | 19 | String packageVersion 20 | 21 | 22 | // 23 | // for artifact publish 24 | // 25 | 26 | File artifactFile 27 | 28 | String packageName 29 | 30 | String targetPath 31 | 32 | boolean override 33 | 34 | // 35 | // for p2 repo publish 36 | // 37 | 38 | File repoDir 39 | File zippedRepoFile 40 | String compositePackage 41 | String zipSitePackage 42 | String updateSitePackage 43 | String subCompositeStrategy 44 | String mainFeatureId 45 | } 46 | -------------------------------------------------------------------------------- /buildSrc/p2-plugin/src/main/groovy/com/github/missedone/gradle/ArtifactoryP2Plugin.groovy: -------------------------------------------------------------------------------- 1 | package com.github.missedone.gradle 2 | 3 | import org.gradle.api.* 4 | 5 | class ArtifactoryP2Plugin implements Plugin { 6 | static final String EXTENSION_NAME = 'p2-plugin' 7 | 8 | @Override 9 | void apply(Project project) { 10 | ArtifactoryP2Extension extension = project.extensions.create(EXTENSION_NAME, ArtifactoryP2Extension) 11 | addTasks(project, extension) 12 | } 13 | 14 | private void addTasks(Project project, ArtifactoryP2Extension extension) { 15 | project.tasks.withType(AbstractPublishTask) { 16 | conventionMapping.apiUrl = { getApiUrl(project, extension) } 17 | conventionMapping.user = { getBintrayUser(project, extension) } 18 | conventionMapping.apiKey = { getApiKey(project, extension) } 19 | conventionMapping.repoOwner = { extension.repoOwner } 20 | conventionMapping.repoName = { extension.repoName } 21 | conventionMapping.packageVersion = { extension.packageVersion } 22 | } 23 | 24 | project.task('publishArtifact', type: ArtifactPublishTask) { 25 | conventionMapping.packageName = { extension.packageName } 26 | conventionMapping.artifactFile = { extension.artifactFile } 27 | conventionMapping.targetPath = { extension.targetPath } 28 | conventionMapping.override = { extension.override } 29 | } 30 | 31 | project.task('removeArtifact', type: PublishArtifactRemoveTask) { 32 | conventionMapping.targetPath = { extension.targetPath } 33 | } 34 | 35 | project.task('publishP2Repo', type: PublishP2RepoPublishTask) { 36 | conventionMapping.repoDir = { extension.repoDir } 37 | conventionMapping.zippedRepoFile = { extension.zippedRepoFile } 38 | conventionMapping.override = { extension.override } 39 | conventionMapping.compositePackage = { extension.compositePackage } 40 | conventionMapping.zipSitePackage = { extension.zipSitePackage } 41 | conventionMapping.updateSitePackage = { extension.updateSitePackage } 42 | conventionMapping.subCompositeStrategy = { extension.subCompositeStrategy } 43 | conventionMapping.mainFeatureId = { extension.mainFeatureId } 44 | } 45 | } 46 | 47 | private String getApiUrl(Project project, ArtifactoryP2Extension extension) { 48 | def apiUrl = extension.apiUrl ?: AbstractPublishTask.DEFAULT_API_URL 49 | return apiUrl 50 | } 51 | 52 | private String getBintrayUser(Project project, ArtifactoryP2Extension extension) { 53 | def user = extension.user ?: System.getProperty('BINTRAY_USER') 54 | user = user ?: System.getenv('BINTRAY_USER') 55 | return user 56 | } 57 | 58 | private String getApiKey(Project project, ArtifactoryP2Extension extension) { 59 | def apiKey = extension.apiKey ?: System.getProperty('BINTRAY_API_KEY') 60 | apiKey = apiKey ?: System.getenv('BINTRAY_API_KEY') 61 | return apiKey 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /buildSrc/p2-plugin/src/main/groovy/com/github/missedone/gradle/PublishArtifactRemoveTask.groovy: -------------------------------------------------------------------------------- 1 | package com.github.missedone.gradle 2 | 3 | import org.gradle.api.tasks.Input 4 | 5 | class PublishArtifactRemoveTask extends AbstractPublishTask { 6 | 7 | @Input 8 | String targetPath 9 | 10 | PublishArtifactRemoveTask() { 11 | this.description = 'Remove the artifact from Bintray' 12 | } 13 | 14 | @Override 15 | void executeAction() { 16 | ArtifactoryClient client = new ArtifactoryClient(apiUrl, user, apiKey) 17 | client.deleteContent(repoOwner, repoName, targetPath) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /buildSrc/p2-plugin/src/main/resources/META-INF/gradle-plugins/p2-plugin.properties: -------------------------------------------------------------------------------- 1 | implementation-class=com.github.missedone.gradle.ArtifactoryP2Plugin -------------------------------------------------------------------------------- /buildSrc/settings.gradle: -------------------------------------------------------------------------------- 1 | include 'bnd-platform' 2 | include 'p2-plugin' 3 | 4 | -------------------------------------------------------------------------------- /examples/context-map-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/examples/context-map-example-1.png -------------------------------------------------------------------------------- /examples/context-map-example-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/examples/context-map-example-2.png -------------------------------------------------------------------------------- /examples/context-map-example-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/examples/context-map-example-3.png -------------------------------------------------------------------------------- /examples/team-map-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/examples/team-map-example-1.png -------------------------------------------------------------------------------- /examples/team-map-example-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/examples/team-map-example-2.png -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Publication repos 2 | ossSnapshotRepository=https://oss.sonatype.org/content/repositories/snapshots/ 3 | ossReleaseStagingRepository=https://oss.sonatype.org/service/local/staging/deploy/maven2/ 4 | 5 | # dependency versions 6 | jUnitVersion=5.5.2 7 | commonsLangVersion=3.9 8 | graphvizVersion=0.11.0 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Oct 07 17:41:06 CEST 2019 2 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip 3 | distributionBase=GRADLE_USER_HOME 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS="-Xmx64m" 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /graphviz-test-example/ex1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/graphviz-test-example/ex1.png -------------------------------------------------------------------------------- /graphviz-test-example/ex1i.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/graphviz-test-example/ex1i.png -------------------------------------------------------------------------------- /graphviz-test-example/ex1m.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/graphviz-test-example/ex1m.png -------------------------------------------------------------------------------- /graphviz-test-example/ex2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/graphviz-test-example/ex2.png -------------------------------------------------------------------------------- /graphviz-test-example/ex3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/graphviz-test-example/ex3.png -------------------------------------------------------------------------------- /graphviz-test-example/ex4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/graphviz-test-example/ex4-1.png -------------------------------------------------------------------------------- /graphviz-test-example/ex4-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/graphviz-test-example/ex4-2.png -------------------------------------------------------------------------------- /graphviz-test-example/ex5.svg: -------------------------------------------------------------------------------- 1 | 3 | 4 | example5 5 | 6 | 7 | 8 | abc 9 | 10 | abc 11 | 12 | 13 | 14 | xyz 15 | 16 | xyz 17 | 18 | 19 | 20 | abc->xyz 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /graphviz-test-example/ex5b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/graphviz-test-example/ex5b.png -------------------------------------------------------------------------------- /graphviz-test-example/ex5p.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/graphviz-test-example/ex5p.pdf -------------------------------------------------------------------------------- /graphviz-test-example/ex5s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/graphviz-test-example/ex5s.png -------------------------------------------------------------------------------- /graphviz-test-example/ex6a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/graphviz-test-example/ex6a.png -------------------------------------------------------------------------------- /graphviz-test-example/ex6d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/graphviz-test-example/ex6d.png -------------------------------------------------------------------------------- /graphviz-test-example/ex7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/graphviz-test-example/ex7.png -------------------------------------------------------------------------------- /graphviz-test-example/ex8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/graphviz-test-example/ex8.png -------------------------------------------------------------------------------- /graphviz-test-example/graphviz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/graphviz-test-example/graphviz.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'context-map-generator' 2 | 3 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/NonnullApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz; 17 | 18 | import java.lang.annotation.*; 19 | 20 | @Documented 21 | @Retention(RetentionPolicy.CLASS) 22 | @Target(ElementType.PACKAGE) 23 | public @interface NonnullApi { 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/attribute/Attributed.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | import java.util.List; 19 | 20 | import static guru.nidi.graphviz.attribute.Attributes.attr; 21 | import static guru.nidi.graphviz.attribute.Attributes.attrs; 22 | 23 | public interface Attributed extends Attributes { 24 | default T with(String name, Object value) { 25 | return with(attr(name, value)); 26 | } 27 | 28 | default T with(Attributes attr1, Attributes attr2) { 29 | return with(attrs(attr1, attr2)); 30 | } 31 | 32 | default T with(Attributes attr1, Attributes attr2, Attributes attr3) { 33 | return with(attrs(attr1, attr2, attr3)); 34 | } 35 | 36 | default T with(Attributes attr1, Attributes attr2, 37 | Attributes attr3, Attributes attr4) { 38 | return with(attrs(attr1, attr2, attr3, attr4)); 39 | } 40 | 41 | //cannot use @SafeVarargs here, that's why we have the specializations for 2..4 attrs 42 | default T with(Attributes... attributes) { 43 | return with(attrs(attributes)); 44 | } 45 | 46 | default T with(List> attributes) { 47 | return with(attrs(attributes)); 48 | } 49 | 50 | T with(Attributes attribute); 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/attribute/Attributes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | import java.util.Iterator; 19 | import java.util.List; 20 | import java.util.Map.Entry; 21 | 22 | import static java.util.Arrays.asList; 23 | 24 | public interface Attributes extends Iterable> { 25 | Attributes applyTo(MapAttributes attrs); 26 | 27 | default Attributes applyTo(Attributes attrs) { 28 | if (!(attrs instanceof MapAttributes)) { 29 | throw new UnsupportedOperationException("attributes must be a MapAttributes"); 30 | } 31 | @SuppressWarnings("unchecked") final MapAttributes as = (MapAttributes) attrs; 32 | return applyTo(as); 33 | } 34 | 35 | default Attributes copy() { 36 | @SuppressWarnings("unchecked") final Attributes copy = (Attributes) applyTo(attrs()); 37 | return copy; 38 | } 39 | 40 | static Attributes attr(String key,Object value) { 41 | return new MapAttributes().add(key, value); 42 | } 43 | 44 | static Attributes attrs() { 45 | return new MapAttributes<>(); 46 | } 47 | 48 | @SafeVarargs 49 | static Attributes attrs(Attributes... attributes) { 50 | return attrs(asList(attributes)); 51 | } 52 | 53 | static Attributes attrs(List> attributes) { 54 | final MapAttributes res = new MapAttributes<>(); 55 | for (Attributes attribute : attributes) { 56 | attribute.applyTo(res); 57 | } 58 | return res; 59 | } 60 | 61 | default Object get(String key) { 62 | return applyTo(new MapAttributes<>()).get(key); 63 | } 64 | 65 | @Override 66 | default Iterator> iterator() { 67 | return applyTo(new MapAttributes<>()).iterator(); 68 | } 69 | 70 | default boolean isEmpty() { 71 | return applyTo(new MapAttributes<>()).isEmpty(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/attribute/EndLabel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | import java.util.Objects; 19 | 20 | public final class EndLabel extends SimpleLabel implements Attributes { 21 | private final String key; 22 | private final Double angle; 23 | private final Double distance; 24 | 25 | private EndLabel(String key, String value, boolean html, Double angle, Double distance) { 26 | super(value, html); 27 | this.key = key; 28 | this.angle = angle; 29 | this.distance = distance; 30 | } 31 | 32 | public static EndLabel head(SimpleLabel label, Double angle, Double distance) { 33 | return new EndLabel("headlabel", label.value, label.html, angle, distance); 34 | } 35 | 36 | public static EndLabel tail(SimpleLabel label, Double angle, Double distance) { 37 | return new EndLabel("taillabel", label.value, label.html, angle, distance); 38 | } 39 | 40 | @Override 41 | public Attributes applyTo(MapAttributes attributes) { 42 | attributes.add(key, this); 43 | if (angle != null) { 44 | attributes.add("labelangle", angle); 45 | } 46 | if (distance != null) { 47 | attributes.add("labeldistance", distance); 48 | } 49 | return attributes; 50 | } 51 | 52 | @Override 53 | public boolean equals(Object o) { 54 | if (this == o) { 55 | return true; 56 | } 57 | if (o == null || getClass() != o.getClass()) { 58 | return false; 59 | } 60 | if (!super.equals(o)) { 61 | return false; 62 | } 63 | final EndLabel endLabel = (EndLabel) o; 64 | return Objects.equals(key, endLabel.key) 65 | && Objects.equals(angle, endLabel.angle) 66 | && Objects.equals(distance, endLabel.distance); 67 | } 68 | 69 | @Override 70 | public int hashCode() { 71 | return Objects.hash(super.hashCode(), key, angle, distance); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/attribute/Font.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | import static guru.nidi.graphviz.attribute.Attributes.attr; 19 | import static guru.nidi.graphviz.attribute.Attributes.attrs; 20 | 21 | public final class Font { 22 | private Font() { 23 | } 24 | 25 | public static Attributes config(String name, int size) { 26 | return attrs(name(name), size(size)); 27 | } 28 | 29 | public static Attributes name(String name) { 30 | return attr("fontname", name); 31 | } 32 | 33 | public static Attributes size(int size) { 34 | return attr("fontsize", size); 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/attribute/For.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | /** 19 | * Marker to define which elements (graph, node, link) an Attribute can be used for. 20 | */ 21 | public interface For { 22 | } 23 | 24 | interface ForGraphLink extends ForGraph, ForLink { 25 | } 26 | 27 | interface ForGraphNode extends ForGraph, ForNode { 28 | } 29 | 30 | interface ForNodeLink extends ForNode, ForLink { 31 | } 32 | 33 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/attribute/ForAll.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | /** 19 | * Marker for Attributes that can be used for all types of elements. 20 | */ 21 | public interface ForAll extends ForGraph, ForNode, ForLink { 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/attribute/ForGraph.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | /** 19 | * Marker for Attributes that can be used for graphs. 20 | */ 21 | public interface ForGraph extends For { 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/attribute/ForLink.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | /** 19 | * Marker for Attributes that can be used for links. 20 | */ 21 | public interface ForLink extends For { 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/attribute/ForNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | /** 19 | * Marker for Attributes that can be used for nodes. 20 | */ 21 | public interface ForNode extends For { 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/attribute/GraphAttr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | import static java.util.Locale.ENGLISH; 19 | 20 | public final class GraphAttr { 21 | private static final String SIZE = "size"; 22 | 23 | public static final Attributes 24 | CENTER = new SingleAttributes<>("center", true), 25 | COMPOUND = new SingleAttributes<>("compound", true), 26 | CONCENTRATE = new SingleAttributes<>("concentrate", true), 27 | FORCE_LABELS_NOT = new SingleAttributes<>("forcelabels", false), 28 | LANDSCAPE = new SingleAttributes<>("orientation", "L"); 29 | 30 | private GraphAttr() { 31 | } 32 | 33 | public static Attributes dpi(int dpi) { 34 | return new SingleAttributes<>("dpi", dpi); 35 | } 36 | 37 | public static Attributes sizeMax(double size) { 38 | return new SingleAttributes<>(SIZE, size); 39 | } 40 | 41 | public static Attributes sizeMax(double sizeX, double sizeY) { 42 | return new SingleAttributes<>(SIZE, sizeX + "," + sizeY); 43 | } 44 | 45 | public static Attributes sizePreferred(double size) { 46 | return new SingleAttributes<>(SIZE, size + "!"); 47 | } 48 | 49 | public static Attributes sizePreferred(double sizeX, double sizeY) { 50 | return new SingleAttributes<>(SIZE, sizeX + "," + sizeY + "!"); 51 | } 52 | 53 | public enum SplineMode { 54 | LINE, SPLINE, POLYLINE, ORTHO, CURVED, NONE 55 | } 56 | 57 | public static Attributes splines(SplineMode mode) { 58 | return new SingleAttributes<>("splines", mode.toString().toLowerCase(ENGLISH)); 59 | } 60 | 61 | public static Attributes pad(double pad) { 62 | return new SingleAttributes<>("pad", pad); 63 | } 64 | 65 | public static Attributes pad(double padX, double padY) { 66 | return new SingleAttributes<>("pad", padX + "," + padY); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/attribute/Image.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | public final class Image implements Attributes { 19 | public enum Position { 20 | TOP_LEFT("tl"), 21 | TOP_CENTER("tc"), 22 | TOP_RIGHT("tr"), 23 | MIDDLE_LEFT("ml"), 24 | MIDDLE_CENTER("mc"), 25 | MIDDLE_RIGHT("mr"), 26 | BOTTOM_LEFT("bl"), 27 | BOTTOM_CENTER("bc"), 28 | BOTTOM_RIGHT("br"); 29 | 30 | String value; 31 | 32 | Position(String value) { 33 | this.value = value; 34 | } 35 | } 36 | 37 | public enum Scale { 38 | NONE("false"), 39 | FIT("true"), 40 | WIDTH("width"), 41 | HEIGHT("height"), 42 | BOTH("both"); 43 | 44 | String value; 45 | 46 | Scale(String value) { 47 | this.value = value; 48 | } 49 | } 50 | 51 | private final String path; 52 | private final Position position; 53 | private final Scale scale; 54 | 55 | private Image(String path, Position position, Scale scale) { 56 | this.path = path; 57 | this.position = position; 58 | this.scale = scale; 59 | } 60 | 61 | public static Image of(String path) { 62 | return new Image(path, Position.MIDDLE_CENTER, Scale.NONE); 63 | } 64 | 65 | public Image position(Position position) { 66 | return new Image(path, position, scale); 67 | } 68 | 69 | public Image scale(Scale scale) { 70 | return new Image(path, position, scale); 71 | } 72 | 73 | @Override 74 | public Attributes applyTo(MapAttributes attrs) { 75 | attrs.add("image", path); 76 | if (position != Position.MIDDLE_CENTER) { 77 | attrs.add("imagepos", position.value); 78 | } 79 | if (scale != Scale.NONE) { 80 | attrs.add("imagescale", scale.value); 81 | } 82 | return attrs; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/attribute/LinkAttr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | public final class LinkAttr { 19 | public static final Attributes 20 | CONSTRAINT_NOT = new SingleAttributes<>("constraint", false); 21 | 22 | private LinkAttr() { 23 | } 24 | 25 | public static Attributes weight(double weight) { 26 | return new SingleAttributes<>("weight", weight); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/attribute/MapAttributes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | import java.util.*; 19 | import java.util.Map.Entry; 20 | 21 | public class MapAttributes implements Attributes, Iterable> { 22 | protected final Map attributes; 23 | 24 | public MapAttributes() { 25 | attributes = new HashMap<>(); 26 | } 27 | 28 | public Attributes applyTo(MapAttributes attrs) { 29 | attrs.attributes.putAll(attributes); 30 | return attrs; 31 | } 32 | 33 | public MapAttributes add(String key, Object value) { 34 | if (value == null) { 35 | attributes.remove(key); 36 | } else { 37 | attributes.put(key, value); 38 | } 39 | @SuppressWarnings("unchecked") final MapAttributes map = (MapAttributes) this; 40 | return map; 41 | } 42 | 43 | public MapAttributes add(MapAttributes attributes) { 44 | this.attributes.putAll(attributes.attributes); 45 | return this; 46 | } 47 | 48 | public boolean isEmpty() { 49 | return attributes.isEmpty(); 50 | } 51 | 52 | @Override 53 | public Object get(String key) { 54 | return attributes.get(key); 55 | } 56 | 57 | @Override 58 | public Iterator> iterator() { 59 | return attributes.entrySet().iterator(); 60 | } 61 | 62 | @Override 63 | public boolean equals(Object o) { 64 | if (this == o) { 65 | return true; 66 | } 67 | if (o == null || getClass() != o.getClass()) { 68 | return false; 69 | } 70 | final MapAttributes entries = (MapAttributes) o; 71 | return Objects.equals(attributes, entries.attributes); 72 | } 73 | 74 | @Override 75 | public int hashCode() { 76 | return Objects.hash(attributes); 77 | } 78 | 79 | @Override 80 | public String toString() { 81 | return attributes.toString(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/attribute/NodeAttr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | import static guru.nidi.graphviz.attribute.Attributes.attr; 19 | 20 | public final class NodeAttr { 21 | 22 | private NodeAttr() { 23 | } 24 | 25 | public static Attributes group(String group) { 26 | return new SingleAttributes<>("group", group); 27 | } 28 | 29 | static Attributes nodeAttr(String key, Object value) { 30 | return attr(key, value); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/attribute/Records.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | import static guru.nidi.graphviz.attribute.Attributes.attr; 19 | import static guru.nidi.graphviz.attribute.Attributes.attrs; 20 | 21 | public final class Records { 22 | private static final String 23 | SHAPE = "shape", 24 | RECORD = "record", 25 | LABEL = "label"; 26 | 27 | private Records() { 28 | } 29 | 30 | public static Attributes label(String label) { 31 | return attrs(attr(SHAPE, RECORD), attr(LABEL, label)); 32 | } 33 | 34 | public static Attributes mLabel(String label) { 35 | return attrs(attr(SHAPE, "Mrecord"), attr(LABEL, label)); 36 | } 37 | 38 | public static Attributes of(String... recs) { 39 | return attrs(attr(SHAPE, RECORD), attr(LABEL, String.join("|", recs))); 40 | } 41 | 42 | public static Attributes mOf(String... recs) { 43 | return attrs(attr(SHAPE, "Mrecord"), attr(LABEL, String.join("|", recs))); 44 | } 45 | 46 | public static String rec(String tag, String label) { 47 | return "<" + tag + ">" + rec(label); 48 | } 49 | 50 | public static String rec(String label) { 51 | return label.replace("{", "\\{").replace("}", "\\}") 52 | .replace("<", "\\<").replace(">", "\\>") 53 | .replace("|", "\\|").replace(" ", "\\ "); 54 | } 55 | 56 | public static String turn(String... records) { 57 | return "{" + String.join("|", records) + "}"; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/attribute/SimpleLabel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | import java.util.Objects; 19 | 20 | public class SimpleLabel { 21 | final String value; 22 | final boolean html; 23 | 24 | SimpleLabel(String value, boolean html) { 25 | this.value = value; 26 | this.html = html; 27 | } 28 | 29 | public static SimpleLabel of(String value) { 30 | return new SimpleLabel(value, false); 31 | } 32 | 33 | public static SimpleLabel of(Object value) { 34 | return value instanceof SimpleLabel ? (SimpleLabel) value : of(value.toString()); 35 | } 36 | 37 | public String serialized() { 38 | return html 39 | ? ("<" + value + ">") 40 | : ("\"" + value.replace("\"", "\\\"").replace("\n", "\\n") + "\""); 41 | } 42 | 43 | public String value() { 44 | return value; 45 | } 46 | 47 | public boolean isHtml() { 48 | return html; 49 | } 50 | 51 | @Override 52 | public boolean equals(Object o) { 53 | if (this == o) { 54 | return true; 55 | } 56 | if (o == null || getClass() != o.getClass()) { 57 | return false; 58 | } 59 | final SimpleLabel that = (SimpleLabel) o; 60 | return html == that.html 61 | && Objects.equals(value, that.value); 62 | } 63 | 64 | @Override 65 | public int hashCode() { 66 | return Objects.hash(value, html); 67 | } 68 | 69 | @Override 70 | public String toString() { 71 | return value; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/attribute/SingleAttributes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | import java.lang.reflect.Constructor; 19 | import java.lang.reflect.ParameterizedType; 20 | 21 | class SingleAttributes implements Attributes { 22 | protected final String key; 23 | protected final T value; 24 | 25 | protected SingleAttributes(String key, T value) { 26 | this.key = key; 27 | this.value = value; 28 | } 29 | 30 | public E key(String key) { 31 | return newInstance(key, value); 32 | } 33 | 34 | public E value(T value) { 35 | return newInstance(key, value); 36 | } 37 | 38 | private E newInstance(String key, T value) { 39 | try { 40 | final ParameterizedType superclass = (ParameterizedType) getClass().getGenericSuperclass(); 41 | final Class type = (Class) superclass.getActualTypeArguments()[0]; 42 | final Constructor cons = getClass().getDeclaredConstructor(String.class, type); 43 | cons.setAccessible(true); 44 | return (E) cons.newInstance(key, value); 45 | } catch (ReflectiveOperationException e) { 46 | throw new AssertionError(e); 47 | } 48 | } 49 | 50 | @Override 51 | public Attributes applyTo(MapAttributes attrs) { 52 | return attrs.add(key, value); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/attribute/Size.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | import static guru.nidi.graphviz.attribute.NodeAttr.nodeAttr; 19 | 20 | public final class Size implements Attributes { 21 | public enum Mode { 22 | FIXED("true"), MINIMUM("false"), SHAPE("shape"); 23 | 24 | final String value; 25 | 26 | Mode(String value) { 27 | this.value = value; 28 | } 29 | } 30 | 31 | private final Mode mode; 32 | private final Double width; 33 | private final Double height; 34 | private final Double marginX; 35 | private final Double marginY; 36 | 37 | private Size(Mode mode, Double width, Double height, 38 | Double marginX, Double marginY) { 39 | this.mode = mode; 40 | this.width = width; 41 | this.height = height; 42 | this.marginX = marginX; 43 | this.marginY = marginY; 44 | } 45 | 46 | public static Size mode(Mode mode) { 47 | return new Size(mode, null, null, null, null); 48 | } 49 | 50 | public static Size std() { 51 | return new Size(null, null, null, null, null); 52 | } 53 | 54 | public Size size(double width, double height) { 55 | return new Size(mode, width, height, marginX, marginY); 56 | } 57 | 58 | public Size margin(double marginX, double marginY) { 59 | return new Size(mode, width, height, marginX, marginY); 60 | } 61 | 62 | @Override 63 | public Attributes applyTo(MapAttributes attrs) { 64 | if (mode != null) { 65 | nodeAttr("fixedsize", mode.value).applyTo(attrs); 66 | } 67 | if (width != null) { 68 | nodeAttr("width", width).applyTo(attrs); 69 | nodeAttr("height", height).applyTo(attrs); 70 | } 71 | if (marginX != null) { 72 | nodeAttr("margin", marginX + "," + marginY).applyTo(attrs); 73 | } 74 | return attrs; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/attribute/Style.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | public class Style extends SingleAttributes { 19 | public static final Style 20 | DASHED = new Style("dashed"), 21 | DOTTED = new Style("dotted"), 22 | SOLID = new Style("solid"), 23 | INVIS = new Style("invis"), 24 | BOLD = new Style("bold"), 25 | FILLED = new Style("filled"), 26 | RADIAL = new Style("radial"), 27 | DIAGONALS = new Style("diagonals"), 28 | ROUNDED = new Style("rounded"); 29 | 30 | public Style(String value) { 31 | super("style", value); 32 | } 33 | 34 | public static Style lineWidth(int width) { 35 | return new Style("setlinewidth(" + width + ")"); 36 | } 37 | 38 | public Style and(Style style) { 39 | return new Style(value + "," + style.value); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/attribute/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | @NonnullApi 17 | package guru.nidi.graphviz.attribute; 18 | 19 | import guru.nidi.graphviz.NonnullApi; 20 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/engine/AbstractGraphvizEngine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.engine; 17 | 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | 21 | import java.io.File; 22 | import java.util.function.Consumer; 23 | import java.util.function.Function; 24 | import java.util.regex.Matcher; 25 | import java.util.regex.Pattern; 26 | 27 | public abstract class AbstractGraphvizEngine implements GraphvizEngine { 28 | private static final Logger LOG = LoggerFactory.getLogger(AbstractGraphvizEngine.class); 29 | protected static final Pattern IMG_SRC = Pattern.compile(" onOk, Consumer onError) { 39 | if (sync) { 40 | initTask(onOk, onError); 41 | } else { 42 | new Thread(() -> initTask(onOk, onError)).start(); 43 | } 44 | } 45 | 46 | private void initTask(Consumer onOk, Consumer onError) { 47 | try { 48 | doInit(); 49 | onOk.accept(this); 50 | } catch (Exception e) { 51 | LOG.info("Could not initialize {}", this, e); 52 | close(); 53 | onError.accept(this); 54 | } 55 | } 56 | 57 | protected String replacePaths(String src, Pattern pattern, Function replacer) { 58 | final Matcher matcher = pattern.matcher(src); 59 | final StringBuilder s = new StringBuilder(); 60 | int last = 0; 61 | while (matcher.find()) { 62 | final String attr = matcher.group(1); 63 | s.append(src, last, matcher.start(1)); 64 | s.append(replacer.apply(attr)); 65 | last = matcher.end(1); 66 | } 67 | return s.append(src.substring(last)).toString(); 68 | } 69 | 70 | protected String replacePath(String path, File basedir) { 71 | return path.startsWith("http://") || path.startsWith("https://") || new File(path).isAbsolute() 72 | ? path 73 | : new File(basedir, path).getAbsolutePath(); 74 | } 75 | 76 | @Override 77 | public void close() { 78 | } 79 | 80 | protected abstract void doInit() throws Exception; 81 | 82 | @Override 83 | public String toString() { 84 | return getClass().getName(); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/engine/BuiltInRasterizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.engine; 17 | 18 | import java.awt.*; 19 | import java.awt.image.BufferedImage; 20 | import java.util.function.Consumer; 21 | 22 | class BuiltInRasterizer implements Rasterizer { 23 | final String format; 24 | final String renderer; 25 | final String formatter; 26 | 27 | BuiltInRasterizer(String format, String renderer, String formatter) { 28 | this.format = format; 29 | this.renderer = renderer; 30 | this.formatter = formatter; 31 | } 32 | 33 | @Override 34 | public Format format() { 35 | return Format.PNG; 36 | } 37 | 38 | @Override 39 | public BufferedImage rasterize(Graphviz graphviz, Consumer graphicsConfigurer, String input) { 40 | return null; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/engine/Communicator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.engine; 17 | 18 | import java.io.*; 19 | import java.net.Socket; 20 | import java.nio.charset.StandardCharsets; 21 | 22 | import static guru.nidi.graphviz.engine.IoUtils.closeQuietly; 23 | 24 | class Communicator implements Closeable { 25 | private final Socket socket; 26 | private final BufferedReader in; 27 | private final BufferedWriter out; 28 | 29 | public Communicator(Socket socket, int timeout) throws IOException { 30 | socket.setSoTimeout(timeout); 31 | this.socket = socket; 32 | this.in = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8)); 33 | this.out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.UTF_8)); 34 | } 35 | 36 | public int readLen() throws IOException { 37 | final String line = in.readLine(); 38 | return line == null ? 0 : Integer.parseInt(line); 39 | } 40 | 41 | public String readStatus() throws IOException { 42 | return in.readLine(); 43 | } 44 | 45 | public String readContent(int len) throws IOException { 46 | final char[] buf = new char[len]; 47 | in.read(buf); 48 | return new String(buf); 49 | } 50 | 51 | public void writeStatus(String status) throws IOException { 52 | out.write(status); 53 | out.newLine(); 54 | } 55 | 56 | public void writeLen(int len) throws IOException { 57 | out.write(Integer.toString(len)); 58 | out.newLine(); 59 | out.flush(); 60 | } 61 | 62 | public void writeContent(String content) throws IOException { 63 | writeLen(content.length()); 64 | out.write(content); 65 | out.newLine(); 66 | out.flush(); 67 | } 68 | 69 | @Override 70 | public void close() { 71 | closeQuietly(in); 72 | closeQuietly(out); 73 | closeQuietly(socket); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/engine/Engine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.engine; 17 | 18 | public enum Engine { 19 | CIRCO, DOT, NEATO, OSAGE, TWOPI, FDP 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/engine/EngineResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.engine; 17 | 18 | import java.io.File; 19 | import java.io.IOException; 20 | import java.util.Objects; 21 | import java.util.function.Consumer; 22 | import java.util.function.Function; 23 | 24 | public final class EngineResult { 25 | private final File file; 26 | private final String string; 27 | 28 | private EngineResult(File file, String string) { 29 | this.file = file; 30 | this.string = string; 31 | } 32 | 33 | public static EngineResult fromFile(File file) { 34 | return new EngineResult(file, null); 35 | } 36 | 37 | public static EngineResult fromString(String string) { 38 | return new EngineResult(null, string); 39 | } 40 | 41 | public EngineResult mapString(Function mapper) { 42 | return string == null ? this : fromString(mapper.apply(string)); 43 | } 44 | 45 | public void consume(Consumer fileConsumer, Consumer stringConsumer) { 46 | if (string == null) { 47 | fileConsumer.accept(file); 48 | } else { 49 | stringConsumer.accept(string); 50 | } 51 | close(); 52 | } 53 | 54 | public T map(Function fileMapper, Function stringMapper) { 55 | final T res = string == null ? fileMapper.apply(file) : stringMapper.apply(string); 56 | close(); 57 | return res; 58 | } 59 | 60 | T mapIO(IOFunction fileMapper, IOFunction stringMapper) throws IOException { 61 | final T res = string == null ? fileMapper.apply(file) : stringMapper.apply(string); 62 | close(); 63 | return res; 64 | } 65 | 66 | private void close() { 67 | if (file != null) { 68 | file.delete(); 69 | } 70 | } 71 | 72 | @Override 73 | public boolean equals(Object o) { 74 | if (this == o) { 75 | return true; 76 | } 77 | if (o == null || getClass() != o.getClass()) { 78 | return false; 79 | } 80 | final EngineResult that = (EngineResult) o; 81 | return Objects.equals(file, that.file) && Objects.equals(string, that.string); 82 | } 83 | 84 | @Override 85 | public int hashCode() { 86 | return Objects.hash(file, string); 87 | } 88 | 89 | @Override 90 | public String toString() { 91 | return "EngineResult{" 92 | + "file=" + file 93 | + ", string='" + string + '\'' 94 | + '}'; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/engine/GraphvizEngine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.engine; 17 | 18 | import java.util.function.Consumer; 19 | 20 | public interface GraphvizEngine extends AutoCloseable { 21 | void init(Consumer onOk, Consumer onError); 22 | 23 | EngineResult execute(String src, Options options, Rasterizer rasterizer); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/engine/GraphvizException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.engine; 17 | 18 | public class GraphvizException extends RuntimeException { 19 | public GraphvizException(String message) { 20 | super(message); 21 | } 22 | 23 | public GraphvizException(String message, Throwable cause) { 24 | super(message, cause); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/engine/GraphvizJdkEngine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.engine; 17 | 18 | public class GraphvizJdkEngine extends AbstractGraphvizEngine { 19 | private final AbstractGraphvizEngine engine; 20 | 21 | public GraphvizJdkEngine() { 22 | super(false); 23 | engine = newEngine(); 24 | } 25 | 26 | private AbstractGraphvizEngine newEngine() { 27 | return new GraphvizNashornEngine(); 28 | } 29 | 30 | @Override 31 | protected void doInit() throws Exception { 32 | engine.doInit(); 33 | } 34 | 35 | @Override 36 | public EngineResult execute(String src, Options options, Rasterizer rasterizer) { 37 | return engine.execute(src, options, rasterizer); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/engine/GraphvizNashornEngine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.engine; 17 | 18 | import javax.script.*; 19 | import java.io.InputStream; 20 | import java.util.regex.Matcher; 21 | import java.util.regex.Pattern; 22 | 23 | import static guru.nidi.graphviz.engine.IoUtils.readStream; 24 | 25 | class GraphvizNashornEngine extends AbstractJsGraphvizEngine { 26 | private static final ScriptEngine ENGINE = new ScriptEngineManager().getEngineByExtension("js"); 27 | private static final ThreadLocal HANDLER = new ThreadLocal<>(); 28 | private static final Pattern JAVA_18_PATTERN = Pattern.compile("1.8.0_(\\d+).*"); 29 | 30 | GraphvizNashornEngine() { 31 | super(false); 32 | final String version = System.getProperty("java.version"); 33 | final Matcher matcher = JAVA_18_PATTERN.matcher(version); 34 | if (matcher.matches() && Integer.parseInt(matcher.group(1)) < 40) { 35 | throw new GraphvizException("You are using an old version of java 1.8. Please update it."); 36 | } 37 | } 38 | 39 | @Override 40 | protected String jsExecute(String jsCall) { 41 | try { 42 | if (HANDLER.get() == null) { 43 | HANDLER.set(new ResultHandler()); 44 | } 45 | ENGINE.getBindings(ScriptContext.ENGINE_SCOPE).put("handler", HANDLER.get()); 46 | ENGINE.eval(jsCall); 47 | return HANDLER.get().waitFor(); 48 | } catch (ScriptException e) { 49 | throw new GraphvizException("Problem executing graphviz", e); 50 | } 51 | } 52 | 53 | @Override 54 | protected void doInit() throws Exception { 55 | try (final InputStream api = getClass().getResourceAsStream("/net/arnx/nashorn/lib/promise.js")) { 56 | ENGINE.eval(readStream(api)); 57 | } 58 | ENGINE.eval(jsVizCode()); 59 | ENGINE.eval("var graphviz = Java.type('guru.nidi.graphviz.engine.GraphvizJdkEngine');" 60 | + "function result(r){ handler.setResult(r); }" 61 | + "function error(r){ handler.setError(r); }"); 62 | ENGINE.eval(jsInitEnv()); 63 | execute("digraph g { a -> b; }", Options.create(), null); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/engine/IOFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.engine; 17 | 18 | import java.io.IOException; 19 | 20 | @FunctionalInterface 21 | interface IOFunction { 22 | R apply(T t) throws IOException; 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/engine/IoUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.engine; 17 | 18 | import java.io.*; 19 | import java.nio.charset.StandardCharsets; 20 | 21 | final class IoUtils { 22 | private IoUtils() { 23 | } 24 | 25 | static String readStream(InputStream in) throws IOException { 26 | final byte[] buf = new byte[in.available()]; 27 | int read, total = 0; 28 | while ((read = in.read(buf, total, Math.min(100000, buf.length - total))) > 0) { 29 | total += read; 30 | } 31 | return new String(buf, StandardCharsets.UTF_8); 32 | } 33 | 34 | static boolean isOnClasspath(String clazz) { 35 | try { 36 | Class.forName(clazz); 37 | return true; 38 | } catch (ClassNotFoundException e) { 39 | return false; 40 | } 41 | } 42 | 43 | static void closeQuietly(Closeable c) { 44 | try { 45 | c.close(); 46 | } catch (IOException e) { 47 | //ignore 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/engine/Rasterizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.engine; 17 | 18 | import java.awt.*; 19 | import java.awt.image.BufferedImage; 20 | import java.util.function.Consumer; 21 | 22 | import static guru.nidi.graphviz.engine.IoUtils.isOnClasspath; 23 | 24 | public interface Rasterizer { 25 | 26 | Rasterizer SALAMANDER = isOnClasspath("com.kitfox.svg.SVGDiagram") ? new SalamanderRasterizer() : null; 27 | Rasterizer DEFAULT = SALAMANDER; 28 | 29 | static Rasterizer builtIn(String format) { 30 | return new BuiltInRasterizer(format, null, null); 31 | } 32 | 33 | static Rasterizer builtIn(String format, String renderer) { 34 | return new BuiltInRasterizer(format, renderer, null); 35 | } 36 | 37 | static Rasterizer builtIn(String format, String renderer, String formatter) { 38 | return new BuiltInRasterizer(format, renderer, formatter); 39 | } 40 | 41 | Format format(); 42 | 43 | BufferedImage rasterize(Graphviz graphviz, Consumer graphicsConfigurer, String input); 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/engine/ResultHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.engine; 17 | 18 | import java.util.concurrent.ArrayBlockingQueue; 19 | import java.util.concurrent.BlockingQueue; 20 | 21 | //public because of nashorn 22 | public class ResultHandler { 23 | private final BlockingQueue value = new ArrayBlockingQueue<>(1); 24 | private boolean ok; 25 | 26 | public void setResult(String result) { 27 | ok = true; 28 | value.add(result); 29 | } 30 | 31 | public void setError(String error) { 32 | ok = false; 33 | value.add(error); 34 | } 35 | 36 | public String waitFor() { 37 | try { 38 | final String v = value.take(); 39 | if (ok) { 40 | return v; 41 | } 42 | throw new GraphvizException(v); 43 | } catch (InterruptedException e) { 44 | throw new GraphvizException("Waiting for result interrupted", e); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/engine/SalamanderRasterizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.engine; 17 | 18 | import com.kitfox.svg.*; 19 | 20 | import java.awt.*; 21 | import java.awt.image.BufferedImage; 22 | import java.io.StringReader; 23 | import java.net.URI; 24 | import java.util.function.Consumer; 25 | 26 | import static java.awt.RenderingHints.*; 27 | 28 | class SalamanderRasterizer extends SvgRasterizer { 29 | @Override 30 | public BufferedImage doRasterize(Graphviz graphviz, Consumer graphicsConfigurer, String svg) { 31 | final SVGDiagram diagram = createDiagram(svg); 32 | final BufferedImage image = new BufferedImage( 33 | (int) diagram.getWidth(), (int) diagram.getHeight(), BufferedImage.TYPE_INT_ARGB); 34 | final Graphics2D graphics = image.createGraphics(); 35 | configGraphics(graphics); 36 | if (graphicsConfigurer != null) { 37 | graphicsConfigurer.accept(graphics); 38 | } 39 | renderDiagram(diagram, graphics); 40 | return image; 41 | } 42 | 43 | private SVGDiagram createDiagram(String svg) { 44 | final SVGUniverse universe = new SVGUniverse(); 45 | final URI uri = universe.loadSVG(new StringReader(svg), "//graph/"); 46 | final SVGDiagram diagram = universe.getDiagram(uri); 47 | diagram.setIgnoringClipHeuristic(true); 48 | return diagram; 49 | } 50 | 51 | private void renderDiagram(SVGDiagram diagram, Graphics2D graphics) { 52 | try { 53 | diagram.render(graphics); 54 | } catch (SVGException e) { 55 | throw new GraphvizException("Problem rendering SVG", e); 56 | } 57 | } 58 | 59 | private void configGraphics(Graphics2D graphics) { 60 | graphics.setRenderingHint(KEY_ALPHA_INTERPOLATION, VALUE_ALPHA_INTERPOLATION_QUALITY); 61 | graphics.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON); 62 | graphics.setRenderingHint(KEY_COLOR_RENDERING, VALUE_COLOR_RENDER_QUALITY); 63 | graphics.setRenderingHint(KEY_INTERPOLATION, VALUE_INTERPOLATION_BICUBIC); 64 | graphics.setRenderingHint(KEY_RENDERING, VALUE_RENDER_QUALITY); 65 | graphics.setRenderingHint(KEY_TEXT_ANTIALIASING, VALUE_TEXT_ANTIALIAS_ON); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/engine/SvgRasterizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.engine; 17 | 18 | import java.awt.*; 19 | import java.awt.image.BufferedImage; 20 | import java.io.File; 21 | import java.util.function.Consumer; 22 | 23 | abstract class SvgRasterizer implements Rasterizer { 24 | @Override 25 | public Format format() { 26 | return Format.SVG; 27 | } 28 | 29 | @Override 30 | public BufferedImage rasterize(Graphviz graphviz, Consumer graphicsConfigurer, String input) { 31 | String svg = input 32 | .replace("xlink:href=\"", "xlink:href=\"file://") 33 | .replace("stroke=\"transparent\"", "stroke=\"#fff\" stroke-opacity=\"0.0\"") 34 | .replace("fill=\"transparent\"", "fill=\"#fff\" fill-opacity=\"0.0\""); 35 | 36 | String baseDirStringOrig = graphviz.getOptions().basedir.getAbsolutePath() + File.separator; 37 | String baseDirString = baseDirStringOrig.replace("\\", "/"); 38 | if(System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) 39 | svg = svg.replace("xlink:href=\"file://" + baseDirStringOrig, "xlink:href=\"file:///" + baseDirString); 40 | 41 | return doRasterize(graphviz, graphicsConfigurer, svg); 42 | } 43 | 44 | abstract BufferedImage doRasterize(Graphviz graphviz, Consumer graphicsConfigurer, String svg); 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/engine/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | @NonnullApi 17 | package guru.nidi.graphviz.engine; 18 | 19 | import guru.nidi.graphviz.NonnullApi; 20 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/model/Compass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.model; 17 | 18 | import java.util.Optional; 19 | import java.util.stream.Stream; 20 | 21 | public enum Compass { 22 | NORTH("n"), NORTH_EAST("ne"), EAST("e"), SOUTH_EAST("se"), 23 | SOUTH("s"), SOUTH_WEST("sw"), WEST("w"), NORTH_WEST("nw"), 24 | CENTER("c"); 25 | 26 | final String value; 27 | 28 | Compass(String value) { 29 | this.value = value; 30 | } 31 | 32 | public static Optional of(String value) { 33 | return Stream.of(values()).filter(c -> c.value.equals(value)).findFirst(); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/model/Factory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.model; 17 | 18 | import guru.nidi.graphviz.attribute.*; 19 | 20 | public final class Factory { 21 | private Factory() { 22 | } 23 | 24 | public static Graph graph() { 25 | return graph(""); 26 | } 27 | 28 | public static Graph graph(String name) { 29 | return new ImmutableGraph().named(name); 30 | } 31 | 32 | public static Node node(String name) { 33 | return node(Label.of(name)); 34 | } 35 | 36 | public static Node node(Label name) { 37 | return CreationContext.createNode(name); 38 | } 39 | 40 | public static Port port(String record) { 41 | return new Port(record, null); 42 | } 43 | 44 | public static Port port(Compass compass) { 45 | return new Port(null, compass); 46 | } 47 | 48 | public static Port port(String record, Compass compass) { 49 | return new Port(record, compass); 50 | } 51 | 52 | 53 | public static MutableGraph mutGraph() { 54 | return CreationContext.createMutGraph(); 55 | } 56 | 57 | public static MutableGraph mutGraph(String name) { 58 | return mutGraph().setName(name); 59 | } 60 | 61 | public static MutableNode mutNode(String name) { 62 | return mutNode(name, false); 63 | } 64 | 65 | public static MutableNode mutNode(String name, boolean raw) { 66 | return mutNode(raw ? Label.raw(name) : Label.of(name)); 67 | } 68 | 69 | public static MutableNode mutNode(Label name) { 70 | return CreationContext.createMutNode(name); 71 | } 72 | 73 | 74 | public static Link to(Node node) { 75 | return Link.to(node); 76 | } 77 | 78 | public static Link to(LinkTarget node) { 79 | return Link.to(node); 80 | } 81 | 82 | public static Link between(Port port, LinkTarget to) { 83 | return Link.between(port, to); 84 | } 85 | 86 | 87 | public static MutableAttributed nodeAttrs() { 88 | return CreationContext.get().nodeAttrs(); 89 | } 90 | 91 | public static MutableAttributed linkAttrs() { 92 | return CreationContext.get().linkAttrs(); 93 | } 94 | 95 | public static MutableAttributed graphAttrs() { 96 | return CreationContext.get().graphAttrs(); 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/model/Graph.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.model; 17 | 18 | import guru.nidi.graphviz.attribute.*; 19 | 20 | import java.util.List; 21 | 22 | public interface Graph extends LinkSource, LinkTarget { 23 | Graph strict(); 24 | 25 | Graph directed(); 26 | 27 | Graph cluster(); 28 | 29 | Graph named(String name); 30 | 31 | Graph link(LinkTarget... targets); 32 | 33 | Graph with(LinkSource... sources); 34 | 35 | Graph with(List sources); 36 | 37 | Attributed nodeAttr(); 38 | 39 | Attributed linkAttr(); 40 | 41 | Attributed graphAttr(); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/model/ImmutableNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.model; 17 | 18 | import guru.nidi.graphviz.attribute.*; 19 | 20 | import java.util.*; 21 | 22 | class ImmutableNode extends MutableNode implements Node { 23 | ImmutableNode(Label name) { 24 | this(name, new ArrayList<>(), Attributes.attrs()); 25 | } 26 | 27 | private ImmutableNode(Label name, List links, Attributes attributes) { 28 | super(name, links, attributes); 29 | } 30 | 31 | public ImmutableNode link(LinkTarget target) { 32 | return (ImmutableNode) copyOfMut().addLink(target); 33 | } 34 | 35 | public ImmutableNode link(LinkTarget... targets) { 36 | return (ImmutableNode) copyOfMut().addLink(targets); 37 | } 38 | 39 | public ImmutableNode link(List targets) { 40 | return (ImmutableNode) copyOfMut().addLink(targets); 41 | } 42 | 43 | public ImmutableNode link(String node) { 44 | return (ImmutableNode) copyOfMut().addLink(node); 45 | } 46 | 47 | public ImmutableNode link(String... nodes) { 48 | return (ImmutableNode) copyOfMut().addLink(nodes); 49 | } 50 | 51 | public ImmutableNode with(Attributes attrs) { 52 | return (ImmutableNode) copyOfMut().add(attrs); 53 | } 54 | 55 | private ImmutableNode copyOfMut() { 56 | return new ImmutableNode(name, new ArrayList<>(links), attributes.copy()); 57 | } 58 | 59 | @Override 60 | public List links() { 61 | return Collections.unmodifiableList(super.links()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/model/LinkList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.model; 17 | 18 | import java.util.*; 19 | 20 | import static java.util.stream.Collectors.toList; 21 | 22 | class LinkList extends ArrayList { 23 | private final LinkSource owner; 24 | 25 | LinkList(LinkSource owner, List links) { 26 | super(links); 27 | this.owner = owner; 28 | } 29 | 30 | @Override 31 | public Link set(int index, Link element) { 32 | return super.set(index, owner.linkTo(element)); 33 | } 34 | 35 | @Override 36 | public boolean add(Link link) { 37 | return super.add(owner.linkTo(link)); 38 | } 39 | 40 | @Override 41 | public void add(int index, Link element) { 42 | super.add(index, owner.linkTo(element)); 43 | } 44 | 45 | @Override 46 | public boolean addAll(Collection c) { 47 | return super.addAll(c.stream().map(owner::linkTo).collect(toList())); 48 | } 49 | 50 | @Override 51 | public boolean addAll(int index, Collection c) { 52 | return super.addAll(index, c.stream().map(owner::linkTo).collect(toList())); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/model/LinkSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.model; 17 | 18 | import java.util.List; 19 | 20 | public interface LinkSource { 21 | List links(); 22 | 23 | Link linkTo(LinkTarget target); 24 | 25 | void addTo(MutableGraph graph); 26 | 27 | LinkTarget asLinkTarget(); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/model/LinkTarget.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.model; 17 | 18 | public interface LinkTarget { 19 | Link linkTo(); 20 | 21 | LinkSource asLinkSource(); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/model/MutableAttributed.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.model; 17 | 18 | import guru.nidi.graphviz.attribute.Attributes; 19 | import guru.nidi.graphviz.attribute.For; 20 | 21 | import static guru.nidi.graphviz.attribute.Attributes.attr; 22 | import static guru.nidi.graphviz.attribute.Attributes.attrs; 23 | 24 | public interface MutableAttributed extends Attributes { 25 | default T add(String name, Object value) { 26 | return add(attr(name, value)); 27 | } 28 | 29 | default T add(Attributes attr1, Attributes attr2) { 30 | return add(attrs(attr1, attr2)); 31 | } 32 | 33 | default T add(Attributes attr1, Attributes attr2, Attributes attr3) { 34 | return add(attrs(attr1, attr2, attr3)); 35 | } 36 | 37 | default T add(Attributes attr1, Attributes attr2, 38 | Attributes attr3, Attributes attr4) { 39 | return add(attrs(attr1, attr2, attr3, attr4)); 40 | } 41 | 42 | //cannot use @SafeVarargs here, that's why we have the specializations for 2..4 attrs 43 | default T add(Attributes... attributes) { 44 | return add(attrs(attributes)); 45 | } 46 | 47 | T add(Attributes attributes); 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/model/Node.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.model; 17 | 18 | import guru.nidi.graphviz.attribute.*; 19 | 20 | import java.util.List; 21 | 22 | public interface Node extends Attributed, LinkSource, LinkTarget { 23 | Label name(); 24 | 25 | PortNode port(String record); 26 | 27 | PortNode port(Compass compass); 28 | 29 | PortNode port(String record, Compass compass); 30 | 31 | Node link(LinkTarget... targets); 32 | 33 | Node link(List targets); 34 | 35 | Node link(String node); 36 | 37 | Node link(String... nodes); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/model/Port.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.model; 17 | 18 | import java.util.Objects; 19 | 20 | public class Port { 21 | private final String record; 22 | private final Compass compass; 23 | 24 | Port(String record, Compass compass) { 25 | this.record = record; 26 | this.compass = compass; 27 | } 28 | 29 | public String record() { 30 | return record; 31 | } 32 | 33 | public Compass compass() { 34 | return compass; 35 | } 36 | 37 | @Override 38 | public boolean equals(Object o) { 39 | if (this == o) { 40 | return true; 41 | } 42 | if (o == null || getClass() != o.getClass()) { 43 | return false; 44 | } 45 | final Port port = (Port) o; 46 | return Objects.equals(record, port.record) 47 | && compass == port.compass; 48 | } 49 | 50 | @Override 51 | public int hashCode() { 52 | return Objects.hash(record, compass); 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return ":" + (record == null ? "" : record) + ":" + (compass == null ? "" : compass); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/model/PortNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.model; 17 | 18 | import guru.nidi.graphviz.attribute.Label; 19 | 20 | public interface PortNode extends LinkSource, LinkTarget { 21 | N node(); 22 | 23 | Label name(); 24 | 25 | PortNode port(String record); 26 | 27 | PortNode port(Compass compass); 28 | 29 | PortNode port(String record, Compass compass); 30 | 31 | Port port(); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/model/PortSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.model; 17 | 18 | import java.util.List; 19 | 20 | class PortSource implements LinkSource { 21 | final Port port; 22 | 23 | PortSource(Port port) { 24 | this.port = port; 25 | } 26 | 27 | @Override 28 | public List links() { 29 | return null; 30 | } 31 | 32 | @Override 33 | public Link linkTo(LinkTarget target) { 34 | return null; 35 | } 36 | 37 | @Override 38 | public void addTo(MutableGraph graph) { 39 | } 40 | 41 | @Override 42 | public LinkTarget asLinkTarget() { 43 | return null; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/model/SimpleMutableAttributed.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.model; 17 | 18 | import guru.nidi.graphviz.attribute.*; 19 | 20 | import java.util.Objects; 21 | 22 | class SimpleMutableAttributed implements MutableAttributed { 23 | private final T target; 24 | private final MapAttributes attributes = new MapAttributes<>(); 25 | 26 | public SimpleMutableAttributed(T target) { 27 | this.target = target; 28 | } 29 | 30 | public SimpleMutableAttributed(T target, Attributes attributes) { 31 | this.target = target; 32 | if (attributes != null) { 33 | attributes.applyTo(this.attributes); 34 | } 35 | } 36 | 37 | @Override 38 | public Attributes applyTo(MapAttributes attrs) { 39 | return attrs.add(attributes); 40 | } 41 | 42 | @Override 43 | public Object get(String key) { 44 | return attributes.get(key); 45 | } 46 | 47 | @Override 48 | public T add(Attributes attributes) { 49 | attributes.applyTo(this.attributes); 50 | return target; 51 | } 52 | 53 | @Override 54 | public boolean equals(Object o) { 55 | if (this == o) { 56 | return true; 57 | } 58 | if (o == null || getClass() != o.getClass()) { 59 | return false; 60 | } 61 | final SimpleMutableAttributed that = (SimpleMutableAttributed) o; 62 | return Objects.equals(attributes, that.attributes); 63 | } 64 | 65 | @Override 66 | public int hashCode() { 67 | return Objects.hash(attributes); 68 | } 69 | 70 | @Override 71 | public String toString() { 72 | return attributes.toString(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/model/ThrowingBiConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.model; 17 | 18 | @FunctionalInterface 19 | public interface ThrowingBiConsumer { 20 | void accept(T t, S s) throws Exception; 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/model/ThrowingFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.model; 17 | 18 | @FunctionalInterface 19 | public interface ThrowingFunction { 20 | R apply(T t) throws Exception; 21 | 22 | default R applyNotThrowing(T t) { 23 | try { 24 | return apply(t); 25 | } catch (RuntimeException e) { 26 | throw e; 27 | } catch (Exception e) { 28 | throw new RuntimeException(e); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/model/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | @NonnullApi 17 | package guru.nidi.graphviz.model; 18 | 19 | import guru.nidi.graphviz.NonnullApi; 20 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/parse/ParserException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.parse; 17 | 18 | public class ParserException extends RuntimeException { 19 | private final Position position; 20 | 21 | ParserException(Position position, String message) { 22 | super(message); 23 | this.position = position; 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return position.toString() + " " + getMessage(); 29 | } 30 | 31 | public Position getPosition() { 32 | return position; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/parse/Position.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.parse; 17 | 18 | public class Position { 19 | private final String name; 20 | private int line; 21 | private int col; 22 | 23 | Position(String name) { 24 | this.name = name; 25 | line = col = 1; 26 | } 27 | 28 | void newLine() { 29 | col = 1; 30 | line++; 31 | } 32 | 33 | void newChar() { 34 | col++; 35 | } 36 | 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | public int getLine() { 42 | return line; 43 | } 44 | 45 | public int getCol() { 46 | return col; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return name + ":" + line + ":" + col; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/parse/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | @NonnullApi 17 | package guru.nidi.graphviz.parse; 18 | 19 | import guru.nidi.graphviz.NonnullApi; 20 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/service/CommandBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.service; 17 | 18 | 19 | /** 20 | * Build a CommandRunner. 21 | * 22 | * @author toon 23 | */ 24 | public class CommandBuilder { 25 | private boolean shellWrapper; 26 | private CommandLineExecutor cmdExec; 27 | 28 | public CommandBuilder withShellWrapper(boolean shellWrapper) { 29 | this.shellWrapper = shellWrapper; 30 | return this; 31 | } 32 | 33 | public CommandBuilder withCommandExecutor(CommandLineExecutor cmdExec) { 34 | this.cmdExec = cmdExec; 35 | return this; 36 | } 37 | 38 | public CommandRunner build() { 39 | return new CommandRunner( 40 | SystemUtils.getShellWrapperOrDefault(shellWrapper), 41 | getCmdExecutorOrDefault(cmdExec)); 42 | } 43 | 44 | private static CommandLineExecutor getCmdExecutorOrDefault(CommandLineExecutor cmdExec) { 45 | return cmdExec == null ? new CommandLineExecutor() : cmdExec; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/service/CommandLineExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.service; 17 | 18 | import org.apache.commons.exec.*; 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | 22 | import java.io.*; 23 | 24 | /** 25 | * Execute a CommandLine. 26 | * 27 | * @author toon 28 | */ 29 | public class CommandLineExecutor { 30 | private static final Logger LOG = LoggerFactory.getLogger(CommandLineExecutor.class); 31 | 32 | public void execute(CommandLine cmd, File workingDirectory) throws InterruptedException, IOException { 33 | LOG.info("executing command {}", cmd.toString()); 34 | 35 | final ExecuteWatchdog watchdog = new ExecuteWatchdog(60 * 1000); 36 | final Executor executor = new DefaultExecutor(); 37 | 38 | executor.setWatchdog(watchdog); 39 | if (workingDirectory != null) { 40 | executor.setWorkingDirectory(workingDirectory); 41 | } 42 | LOG.debug("workdir: {}", executor.getWorkingDirectory()); 43 | 44 | final DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); 45 | final ByteArrayOutputStream out = new ByteArrayOutputStream(); 46 | final ByteArrayOutputStream err = new ByteArrayOutputStream(); 47 | executor.setStreamHandler(new PumpStreamHandler(out, err)); 48 | executor.execute(cmd, resultHandler); 49 | resultHandler.waitFor(); 50 | 51 | final int exitCode = resultHandler.getExitValue(); 52 | if (out.size() > 0) { 53 | LOG.info(out.toString()); 54 | } 55 | if (exitCode != 0) { 56 | throw new IOException(err.size() == 0 ? "command '" + cmd + "' didn't succeed" : err.toString()); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/service/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | @NonnullApi 17 | package guru.nidi.graphviz.service; 18 | 19 | import guru.nidi.graphviz.NonnullApi; 20 | -------------------------------------------------------------------------------- /src/main/java/guru/nidi/graphviz/use/FontTools.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.use; 17 | 18 | import guru.nidi.graphviz.attribute.Font; 19 | import guru.nidi.graphviz.attribute.Label; 20 | import guru.nidi.graphviz.attribute.Shape; 21 | import guru.nidi.graphviz.engine.Graphviz; 22 | import guru.nidi.graphviz.model.Node; 23 | 24 | import java.awt.*; 25 | import java.io.File; 26 | import java.io.IOException; 27 | import java.util.Arrays; 28 | import java.util.List; 29 | 30 | import static guru.nidi.graphviz.engine.Format.PNG; 31 | import static guru.nidi.graphviz.model.Factory.graph; 32 | import static guru.nidi.graphviz.model.Factory.node; 33 | 34 | public final class FontTools { 35 | private FontTools() { 36 | } 37 | 38 | public static List availableFontNames() { 39 | return Arrays.asList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()); 40 | } 41 | 42 | public static void createFontTest(String name, double adjust, File output) throws IOException { 43 | final Node width = node("If text is too narrow, increase fontAdjust. If it's too wide, decrease it."); 44 | final Node center = node(Label.html("A very long node label that should be centered inside the border
" 45 | + "If text is too much left, increase fontAdjust.
" 46 | + "If it's too much right, decrease it.")); 47 | Graphviz.fromGraph(graph() 48 | .nodeAttr().with(Font.name(name), Shape.RECTANGLE) 49 | .with(width.link(center))) 50 | .fontAdjust(adjust) 51 | .render(PNG) 52 | .toFile(output); 53 | } 54 | 55 | public static void main(String[] args) throws IOException { 56 | System.out.println("Available fonts: " + availableFontNames()); 57 | if (args.length < 2) { 58 | System.out.println("Usage: FontTools "); 59 | System.exit(0); 60 | } 61 | try { 62 | final double adjust = Double.parseDouble(args[1]); 63 | final String filename = "font-test.png"; 64 | System.out.println("Creating test image '" + filename 65 | + "' with font=" + args[0] + " and font adjust=" + adjust); 66 | createFontTest(args[0], adjust, new File(filename)); 67 | } catch (NumberFormatException e) { 68 | System.out.println("Illegal number " + args[1]); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/org/contextmapper/contextmap/generator/model/AbstractRelationship.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 The Context Mapper Project Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.contextmapper.contextmap.generator.model; 17 | 18 | /** 19 | * Represents a DDD relationship (that can have a name and an implementation technology). 20 | * 21 | * @author Stefan Kapferer 22 | */ 23 | public abstract class AbstractRelationship implements Relationship { 24 | 25 | private String name = ""; 26 | private String implementationTechnology = ""; 27 | 28 | public AbstractRelationship setName(String name) { 29 | this.name = name; 30 | return this; 31 | } 32 | 33 | public AbstractRelationship setImplementationTechnology(String implementationTechnology) { 34 | this.implementationTechnology = implementationTechnology; 35 | return this; 36 | } 37 | 38 | @Override 39 | public String getName() { 40 | return name; 41 | } 42 | 43 | @Override 44 | public String getImplementationTechnology() { 45 | return implementationTechnology; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/contextmapper/contextmap/generator/model/BoundedContextType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 The Context Mapper Project Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.contextmapper.contextmap.generator.model; 17 | 18 | /** 19 | * Used to indicate whether a Bounded Context is a generic context or a team. 20 | * 21 | * @author Stefan Kapferer 22 | */ 23 | public enum BoundedContextType { 24 | 25 | GENERIC, TEAM; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/contextmapper/contextmap/generator/model/DownstreamPatterns.java: -------------------------------------------------------------------------------- 1 | package org.contextmapper.contextmap.generator.model; 2 | 3 | /** 4 | * The DDD relationship patterns allowed on the downstream side. 5 | * 6 | * @author Stefan Kapferer 7 | */ 8 | public enum DownstreamPatterns { 9 | 10 | ANTICORRUPTION_LAYER("ACL"), CONFORMIST("CF"); 11 | 12 | private String patternAbbreviation; 13 | 14 | DownstreamPatterns(String patternAbbreviation) { 15 | this.patternAbbreviation = patternAbbreviation; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return patternAbbreviation; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/contextmapper/contextmap/generator/model/Partnership.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Context Mapper Project Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.contextmapper.contextmap.generator.model; 17 | 18 | /** 19 | * Represents a DDD Partnership relationship on a Context Map. 20 | * 21 | * @author Stefan Kapferer 22 | */ 23 | public class Partnership extends AbstractRelationship implements Relationship { 24 | 25 | private BoundedContext bc1; 26 | private BoundedContext bc2; 27 | 28 | public Partnership(BoundedContext bc1, BoundedContext bc2) { 29 | this.bc1 = bc1; 30 | this.bc2 = bc2; 31 | } 32 | 33 | /** 34 | * Gets the first participant of the Partnership. 35 | * 36 | * @return the first participant of the Partnership 37 | */ 38 | public BoundedContext getFirstParticipant() { 39 | return bc1; 40 | } 41 | 42 | /** 43 | * Gets the second participant of the Partnership. 44 | * 45 | * @return the second participant of the Partnership 46 | */ 47 | public BoundedContext getSecondParticipant() { 48 | return bc2; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/contextmapper/contextmap/generator/model/Relationship.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 The Context Mapper Project Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.contextmapper.contextmap.generator.model; 17 | 18 | /** 19 | * Represents a relationship on a Context Map. 20 | * 21 | * @author Stefan Kapferer 22 | */ 23 | public interface Relationship { 24 | 25 | BoundedContext getFirstParticipant(); 26 | 27 | BoundedContext getSecondParticipant(); 28 | 29 | String getName(); 30 | 31 | String getImplementationTechnology(); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/contextmapper/contextmap/generator/model/SharedKernel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Context Mapper Project Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.contextmapper.contextmap.generator.model; 17 | 18 | /** 19 | * Represents a DDD Shared Kernel relationship on a Context Map. 20 | * 21 | * @author Stefan Kapferer 22 | */ 23 | public class SharedKernel extends AbstractRelationship implements Relationship { 24 | 25 | private BoundedContext bc1; 26 | private BoundedContext bc2; 27 | 28 | public SharedKernel(BoundedContext bc1, BoundedContext bc2) { 29 | this.bc1 = bc1; 30 | this.bc2 = bc2; 31 | } 32 | 33 | /** 34 | * Gets the first participant of the Shared Kernel. 35 | * 36 | * @return the first participant of the Shared Kernel 37 | */ 38 | public BoundedContext getFirstParticipant() { 39 | return bc1; 40 | } 41 | 42 | /** 43 | * Gets the second participant of the Shared Kernel. 44 | * 45 | * @return the second participant of the Shared Kernel 46 | */ 47 | public BoundedContext getSecondParticipant() { 48 | return bc2; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/contextmapper/contextmap/generator/model/UpstreamPatterns.java: -------------------------------------------------------------------------------- 1 | package org.contextmapper.contextmap.generator.model; 2 | 3 | /** 4 | * The DDD relationship patterns allowed on the upstream side. 5 | * 6 | * @author Stefan Kapferer 7 | */ 8 | public enum UpstreamPatterns { 9 | 10 | OPEN_HOST_SERVICE("OHS"), PUBLISHED_LANGUAGE("PL"); 11 | 12 | private String patternAbbreviation; 13 | 14 | UpstreamPatterns(String patternAbbreviation) { 15 | this.patternAbbreviation = patternAbbreviation; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return patternAbbreviation; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/contextmapper/contextmap/generator/model/exception/BoundedContextAlreadyPartOfContextMapException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Context Mapper Project Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.contextmapper.contextmap.generator.model.exception; 17 | 18 | public class BoundedContextAlreadyPartOfContextMapException extends RuntimeException { 19 | 20 | public BoundedContextAlreadyPartOfContextMapException(String boundedContextName) { 21 | super("The Bounded Context '" + boundedContextName + "' is already part of this Context Map."); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/contextmapper/contextmap/generator/model/exception/BoundedContextIsNotATeamException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 The Context Mapper Project Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.contextmapper.contextmap.generator.model.exception; 17 | 18 | public class BoundedContextIsNotATeamException extends RuntimeException { 19 | 20 | public BoundedContextIsNotATeamException(String boundedContextName) { 21 | super("The Bounded Context '" + boundedContextName + "' is not a team and can therefore not implement another Bounded Context"); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/contextmapper/contextmap/generator/model/exception/BoundedContextNotPartOfContextMapException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 The Context Mapper Project Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.contextmapper.contextmap.generator.model.exception; 17 | 18 | import org.contextmapper.contextmap.generator.model.BoundedContext; 19 | 20 | public class BoundedContextNotPartOfContextMapException extends RuntimeException { 21 | 22 | public BoundedContextNotPartOfContextMapException(BoundedContext boundedContext) { 23 | super("The Bounded Context '" + boundedContext.getName() + "' is not part of the Context Map!"); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/contextmapper/contextmap/generator/model/exception/TeamCannotImplementTeamException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 The Context Mapper Project Team 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.contextmapper.contextmap.generator.model.exception; 17 | 18 | public class TeamCannotImplementTeamException extends RuntimeException { 19 | 20 | public TeamCannotImplementTeamException(String implementedContextName) { 21 | super("The Bounded Context '" + implementedContextName + "' is a team. A team cannot realize another team. Use a Bounded Context of the type GENERIC"); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/resources/team-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/src/main/resources/team-icon.png -------------------------------------------------------------------------------- /src/test/java/guru/nidi/graphviz/attribute/ArrowTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import static guru.nidi.graphviz.attribute.Attributes.attr; 21 | import static guru.nidi.graphviz.attribute.Attributes.attrs; 22 | import static org.junit.jupiter.api.Assertions.assertEquals; 23 | 24 | class ArrowTest { 25 | @Test 26 | void simple() { 27 | assertArrow("dot", Arrow.DOT); 28 | } 29 | 30 | @Test 31 | void and() { 32 | assertArrow("boxdot", Arrow.DOT.and(Arrow.BOX)); 33 | } 34 | 35 | @Test 36 | void left() { 37 | assertArrow("lbox", Arrow.BOX.left()); 38 | } 39 | 40 | @Test 41 | void right() { 42 | assertArrow("rbox", Arrow.BOX.right()); 43 | } 44 | 45 | @Test 46 | void rightAfterLeft() { 47 | assertArrow("rbox", Arrow.BOX.left().right()); 48 | } 49 | 50 | @Test 51 | void open() { 52 | assertArrow("obox", Arrow.BOX.open()); 53 | } 54 | 55 | @Test 56 | void openAfterOpen() { 57 | assertArrow("obox", Arrow.BOX.open().open()); 58 | } 59 | 60 | @Test 61 | void openAfterLeft() { 62 | assertArrow("olbox", Arrow.BOX.left().open()); 63 | } 64 | 65 | @Test 66 | void leftAfterOpen() { 67 | assertArrow("olbox", Arrow.BOX.open().left()); 68 | } 69 | 70 | @Test 71 | void leftAfterOpenRight() { 72 | assertArrow("olbox", Arrow.BOX.open().right().left()); 73 | } 74 | 75 | @Test 76 | void tail() { 77 | assertEquals("arrowtail", Arrow.BOX.tail().key); 78 | } 79 | 80 | @Test 81 | void size() { 82 | assertEquals(attrs(attr("arrowhead", "box"), attr("arrowsize", 2d)), 83 | Arrow.BOX.size(2)); 84 | } 85 | 86 | @Test 87 | void dir() { 88 | assertEquals(attrs(attr("arrowhead", "box"), attr("dir", "back")), 89 | Arrow.BOX.dir(Arrow.DirType.BACK)); 90 | } 91 | 92 | @Test 93 | void config() { 94 | assertEquals(attrs(attr("arrowhead", "box"), attr("arrowsize", 2d), attr("dir", "back")), 95 | Arrow.BOX.config(2, Arrow.DirType.BACK)); 96 | } 97 | 98 | private void assertArrow(String value, Arrow arrow) { 99 | assertEquals("arrowhead", arrow.key); 100 | assertEquals(value, arrow.value); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/test/java/guru/nidi/graphviz/attribute/EndLabelTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import static guru.nidi.graphviz.attribute.Attributes.attr; 21 | import static guru.nidi.graphviz.attribute.Attributes.attrs; 22 | import static org.junit.jupiter.api.Assertions.assertEquals; 23 | 24 | class EndLabelTest { 25 | @Test 26 | void simpleHead() { 27 | final EndLabel head = EndLabel.head(SimpleLabel.of("hula"), null, null); 28 | assertEquals(attr("headlabel", head), attrs(head)); 29 | } 30 | 31 | @Test 32 | void simpleTail() { 33 | final EndLabel tail = EndLabel.tail(SimpleLabel.of("hula"), null, null); 34 | assertEquals(attr("taillabel", tail), attrs(tail)); 35 | } 36 | 37 | @Test 38 | void ofHtml() { 39 | final EndLabel tail = EndLabel.tail(Label.html("hula"), null, null); 40 | assertEquals(attr("taillabel", tail), attrs(tail)); 41 | } 42 | 43 | @Test 44 | void attrHead() { 45 | final EndLabel head = EndLabel.head(Label.of("hula"), 1d, 2d); 46 | assertEquals(attrs(attr("headlabel", head), attr("labelangle", 1d), attr("labeldistance", 2d)), 47 | attrs(head)); 48 | } 49 | 50 | @Test 51 | void attrTail() { 52 | final EndLabel tail = EndLabel.tail(Label.of("hula"), 1d, 2d); 53 | assertEquals(attrs(attr("taillabel", tail), attr("labelangle", 1d), attr("labeldistance", 2d)), 54 | attrs(tail)); 55 | } 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/guru/nidi/graphviz/attribute/FontTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import static guru.nidi.graphviz.attribute.Attributes.attr; 21 | import static guru.nidi.graphviz.attribute.Attributes.attrs; 22 | import static org.junit.jupiter.api.Assertions.assertEquals; 23 | 24 | class FontTest { 25 | @Test 26 | void name() { 27 | assertEquals(attr("fontname", "Arial"), Font.name("Arial")); 28 | } 29 | 30 | @Test 31 | void size() { 32 | assertEquals(attr("fontsize", 12), Font.size(12)); 33 | } 34 | 35 | @Test 36 | void config() { 37 | assertEquals(attrs(attr("fontname", "Arial"), attr("fontsize", 12)), Font.config("Arial", 12)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/guru/nidi/graphviz/attribute/LabelTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import static guru.nidi.graphviz.attribute.Attributes.attr; 21 | import static guru.nidi.graphviz.attribute.Attributes.attrs; 22 | import static guru.nidi.graphviz.attribute.Label.Justification.*; 23 | import static guru.nidi.graphviz.attribute.Label.Location.*; 24 | import static org.junit.jupiter.api.Assertions.assertEquals; 25 | 26 | class LabelTest { 27 | private final Label label = Label.of("hula"); 28 | 29 | @Test 30 | void simple() { 31 | assertEquals(attrs(attr("label", label)), attrs(label)); 32 | } 33 | 34 | @Test 35 | void decorated() { 36 | assertEquals(attrs(attr("label", label.decorated()), attr("decorate", true)), attrs(label.decorated())); 37 | } 38 | 39 | @Test 40 | void external() { 41 | assertEquals(attrs(attr("xlabel", label.external())), attrs(label.external())); 42 | } 43 | 44 | @Test 45 | void floating() { 46 | assertEquals(attrs(attr("label", label.floating()), attr("labelfloat", true)), attrs(label.floating())); 47 | } 48 | 49 | @Test 50 | void justify() { 51 | assertEquals(attrs(attr("label", label.justify(LEFT)), attr("labeljust", "l")), attrs(label.justify(LEFT))); 52 | assertEquals(attrs(attr("label", label.justify(MIDDLE))), attrs(label.justify(MIDDLE))); 53 | assertEquals(attrs(attr("label", label.justify(RIGHT)), attr("labeljust", "r")), attrs(label.justify(RIGHT))); 54 | } 55 | 56 | @Test 57 | void locate() { 58 | assertEquals(attrs(attr("label", label.locate(TOP)), attr("labelloc", "t")), attrs(label.locate(TOP))); 59 | assertEquals(attrs(attr("label", label.locate(CENTER))), attrs(label.locate(CENTER))); 60 | assertEquals(attrs(attr("label", label.locate(BOTTOM)), attr("labelloc", "b")), attrs(label.locate(BOTTOM))); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/guru/nidi/graphviz/attribute/RankTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import static guru.nidi.graphviz.attribute.Attributes.attr; 21 | import static guru.nidi.graphviz.attribute.Attributes.attrs; 22 | import static guru.nidi.graphviz.attribute.Rank.RankDir.LEFT_TO_RIGHT; 23 | import static guru.nidi.graphviz.attribute.Rank.RankDir.TOP_TO_BOTTOM; 24 | import static guru.nidi.graphviz.attribute.Rank.RankType.SAME; 25 | import static org.junit.jupiter.api.Assertions.assertEquals; 26 | 27 | class RankTest { 28 | @Test 29 | void rank() { 30 | assertEquals(attrs(attr("rank", "same")), attrs(Rank.inSubgraph(SAME))); 31 | } 32 | 33 | @Test 34 | void dir() { 35 | assertEquals(attrs(attr("rankdir", "LR")), attrs(Rank.dir(LEFT_TO_RIGHT))); 36 | } 37 | 38 | @Test 39 | void sep() { 40 | assertEquals(attrs(attr("ranksep", "2.0")), attrs(Rank.sep(2))); 41 | assertEquals(attrs(attr("ranksep", "2.0 equally")), attrs(Rank.sepEqually(2))); 42 | } 43 | 44 | @Test 45 | void newRank() { 46 | assertEquals(attrs(attr("newrank", true)), attrs(Rank.newRank())); 47 | } 48 | 49 | @Test 50 | void combine() { 51 | assertEquals(attrs(attr("newrank", true), attr("clusterrank", "global"), 52 | attr("rankdir", "TB"), attr("ranksep", "3.0 equally")), 53 | attrs(Rank.sepEqually(2).newRank(true).noCluster().dir(TOP_TO_BOTTOM).sep(3))); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/guru/nidi/graphviz/attribute/RecordsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import static guru.nidi.graphviz.attribute.Attributes.attr; 21 | import static guru.nidi.graphviz.attribute.Attributes.attrs; 22 | import static org.junit.jupiter.api.Assertions.assertEquals; 23 | 24 | class RecordsTest { 25 | @Test 26 | void label() { 27 | assertEquals(attrs(attr("shape", "record"), attr("label", "label")), Records.label("label")); 28 | } 29 | 30 | @Test 31 | void mlabel() { 32 | assertEquals(attrs(attr("shape", "Mrecord"), attr("label", "label")), Records.mLabel("label")); 33 | } 34 | 35 | @Test 36 | void of() { 37 | assertEquals(attrs(attr("shape", "record"), attr("label", "a|b|c")), Records.of("a", "b", "c")); 38 | } 39 | 40 | @Test 41 | void mof() { 42 | assertEquals(attrs(attr("shape", "Mrecord"), attr("label", "a|b|c")), Records.mOf("a", "b", "c")); 43 | } 44 | 45 | @Test 46 | void rec() { 47 | assertEquals("l\\\\ \\{b\\}\\ \\|\\ el", Records.rec("l {b} | el")); 48 | } 49 | 50 | @Test 51 | void tagRec() { 52 | assertEquals("label", Records.rec("tag", "label")); 53 | } 54 | 55 | @Test 56 | void turn() { 57 | assertEquals("{label|hula}", Records.turn(Records.rec("tag", "label"), "hula")); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/guru/nidi/graphviz/attribute/ShapeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import static guru.nidi.graphviz.attribute.Attributes.attr; 21 | import static guru.nidi.graphviz.attribute.Attributes.attrs; 22 | import static org.junit.jupiter.api.Assertions.assertEquals; 23 | 24 | class ShapeTest { 25 | @Test 26 | void simple() { 27 | assertEquals(attr("shape", "house"), attrs(Shape.HOUSE)); 28 | } 29 | 30 | @Test 31 | void mDiamond() { 32 | assertEquals(attrs(attr("shape", "Mdiamond"), attr("toplabel", "top"), attr("bottomlabel", "bottom")), 33 | Shape.mDiamond("top", "bottom")); 34 | } 35 | 36 | @Test 37 | void mSquare() { 38 | assertEquals(attrs(attr("shape", "Msquare"), attr("toplabel", "top"), attr("bottomlabel", "bottom")), 39 | Shape.mSquare("top", "bottom")); 40 | } 41 | 42 | @Test 43 | void mCircle() { 44 | assertEquals(attrs(attr("shape", "Mcircle"), attr("toplabel", "top"), attr("bottomlabel", "bottom")), 45 | Shape.mCircle("top", "bottom")); 46 | } 47 | 48 | @Test 49 | void polygon() { 50 | assertEquals(attrs(attr("sides", 4), attr("shape", "polygon"), attr("skew", 2.5), attr("distortion", .66)), 51 | Shape.polygon(4).skew(2.5).distortion(.66).applyTo(attrs())); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/guru/nidi/graphviz/attribute/SimpleLabelTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.attribute; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; 21 | 22 | class SimpleLabelTest { 23 | @Test 24 | void simple() { 25 | assertEquals("\"hula\"", SimpleLabel.of("hula").serialized()); 26 | } 27 | 28 | @Test 29 | void html() { 30 | assertEquals("", new SimpleLabel("hula", true).serialized()); 31 | 32 | } 33 | 34 | @Test 35 | void ofSimpleLabel() { 36 | assertEquals("\"hula\"", SimpleLabel.of(SimpleLabel.of("hula")).serialized()); 37 | } 38 | 39 | @Test 40 | void ofObject() { 41 | assertEquals("\"1\"", SimpleLabel.of(1).serialized()); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/guru/nidi/graphviz/engine/AbstractGraphvizEngineTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.engine; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import java.io.File; 21 | 22 | import static org.hamcrest.MatcherAssert.assertThat; 23 | import static org.hamcrest.core.Is.is; 24 | 25 | class AbstractGraphvizEngineTest { 26 | 27 | static class GraphvizEngineDummy extends AbstractJsGraphvizEngine { 28 | GraphvizEngineDummy() { 29 | super(true); 30 | } 31 | 32 | @Override 33 | protected void doInit() { 34 | // nothing 35 | } 36 | 37 | @Override 38 | protected String jsExecute(String call) { 39 | return call; 40 | } 41 | } 42 | 43 | @Test 44 | void vizExecWithOptions() { 45 | final GraphvizEngineDummy engineUnderTest = new GraphvizEngineDummy(); 46 | final Options options = Options.create().format(Format.SVG).totalMemory(320000).yInvert(true); 47 | 48 | final String vizResult = engineUnderTest.jsVizExec("digraph{ a -> b}", options); 49 | 50 | assertThat(vizResult, is("totalMemory=320000;render('digraph{ a -> b}',{format:'svg',engine:'dot',totalMemory:'320000'," 51 | + "yInvert:true,basedir:'" + new File(".").getAbsolutePath() + "',images:[]});")); 52 | } 53 | 54 | @Test 55 | void vizExecWithoutOptions() { 56 | final GraphvizEngineDummy engineUnderTest = new GraphvizEngineDummy(); 57 | final Options options = Options.create().format(Format.SVG); 58 | 59 | final String vizResult = engineUnderTest.jsVizExec("digraph{ a -> b}", options); 60 | 61 | assertThat(vizResult, is("render('digraph{ a -> b}',{format:'svg',engine:'dot'," 62 | + "basedir:'" + new File(".").getAbsolutePath() + "',images:[]});")); 63 | } 64 | } -------------------------------------------------------------------------------- /src/test/java/guru/nidi/graphviz/engine/FormatTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.engine; 17 | 18 | import org.junit.jupiter.params.ParameterizedTest; 19 | import org.junit.jupiter.params.provider.MethodSource; 20 | 21 | import java.util.*; 22 | import java.util.Map.Entry; 23 | 24 | import static guru.nidi.graphviz.engine.Format.SVG; 25 | import static org.junit.jupiter.api.Assertions.assertEquals; 26 | 27 | class FormatTest { 28 | static final String START1_7 = 29 | "\n" + 30 | "\n" + 32 | "\n" + 34 | "\n" + 35 | "\n" + 39 | "\n" + 40 | "a\n" + 41 | ""); 42 | private static final String AFTER = quote( 43 | "\n" + 44 | "\n" + 45 | "a\n" + 46 | ""); 47 | 48 | @ParameterizedTest 49 | @MethodSource 50 | void postProcess(Entry values) { 51 | assertEquals(EngineResult.fromString(values.getValue()), SVG.postProcess( 52 | Graphviz.fromString("graph {dpi=96}").fontAdjust(.5), 53 | EngineResult.fromString(START1_7 + values.getKey()))); 54 | } 55 | 56 | static Set> postProcess() { 57 | final Map map = new HashMap<>(); 58 | map.put(BEFORE, AFTER); 59 | map.put(BEFORE.replace("\n", "\r\n"), AFTER.replace("\n", "\r\n")); 60 | return map.entrySet(); 61 | } 62 | 63 | private static String quote(String s) { 64 | return s.replace("'", "\""); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/guru/nidi/graphviz/engine/SvgRasterizerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.engine; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import javax.annotation.Nullable; 21 | import java.awt.*; 22 | import java.awt.image.BufferedImage; 23 | import java.util.function.Consumer; 24 | 25 | import static org.junit.jupiter.api.Assertions.assertEquals; 26 | 27 | class SvgRasterizerTest { 28 | @Test 29 | void preProcess() { 30 | final DummyRasterizer rasterizer = new DummyRasterizer(); 31 | rasterizer.rasterize(Graphviz.fromString(""), null, quote( 32 | "" + 33 | "\n" + 34 | "a\n" + 35 | "a\n" + 36 | "")); 37 | assertEquals(quote( 38 | "" + 39 | "\n" + 40 | "a\n" + 41 | "a\n" + 42 | ""), 43 | rasterizer.svg); 44 | } 45 | 46 | private static String quote(String s) { 47 | return s.replace("'", "\""); 48 | } 49 | 50 | private static class DummyRasterizer extends SvgRasterizer { 51 | String svg = ""; 52 | 53 | @Override 54 | BufferedImage doRasterize(Graphviz graphviz, @Nullable Consumer graphicsConfigurer, String svg) { 55 | this.svg = svg; 56 | return new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/guru/nidi/graphviz/model/ContextTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.model; 17 | 18 | import guru.nidi.graphviz.attribute.Color; 19 | import guru.nidi.graphviz.engine.*; 20 | import org.junit.jupiter.api.*; 21 | 22 | import java.util.List; 23 | 24 | import static guru.nidi.graphviz.model.Factory.*; 25 | import static java.util.Arrays.asList; 26 | import static org.junit.jupiter.api.Assertions.assertEquals; 27 | 28 | class ContextTest { 29 | @BeforeAll 30 | static void init() { 31 | Graphviz.useEngine(new GraphvizJdkEngine()); 32 | } 33 | 34 | @AfterAll 35 | static void end() { 36 | Graphviz.releaseEngine(); 37 | } 38 | 39 | @Test 40 | void overwriteNode() { 41 | final MutableGraph g = CreationContext.use(ctx -> { 42 | ctx.nodeAttrs().add(Color.RED); 43 | return mutGraph().add( 44 | node("a").with(Color.BLUE), 45 | node("b")); 46 | }); 47 | assertEquals(mutGraph().add( 48 | node("a").with(Color.BLUE), 49 | node("b").with(Color.RED)), 50 | g); 51 | } 52 | 53 | @Test 54 | void overwriteLink() { 55 | final MutableGraph g = CreationContext.use(ctx -> { 56 | ctx.linkAttrs().add(Color.RED); 57 | return mutGraph().add( 58 | node("a").link(to(node("b")).with(Color.BLUE)), 59 | node("b").link(node("c"))); 60 | }); 61 | assertEquals(mutGraph().add( 62 | node("a").link(to(node("b")).with(Color.BLUE)), 63 | node("b").link(to(node("c")).with(Color.RED))), 64 | g); 65 | } 66 | 67 | @Test 68 | void overwriteGraph() { 69 | final List gs = CreationContext.use(ctx -> { 70 | ctx.graphAttrs().add(Color.RED); 71 | return asList( 72 | mutGraph().graphAttrs().add(Color.BLUE), 73 | mutGraph()); 74 | }); 75 | assertEquals(asList( 76 | mutGraph().graphAttrs().add(Color.BLUE), 77 | mutGraph().graphAttrs().add(Color.RED)), 78 | gs); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/test/java/guru/nidi/graphviz/model/SimpleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.model; 17 | 18 | import guru.nidi.graphviz.engine.*; 19 | import org.junit.jupiter.api.*; 20 | 21 | import static guru.nidi.graphviz.engine.Format.SVG; 22 | import static org.hamcrest.CoreMatchers.containsString; 23 | import static org.hamcrest.MatcherAssert.assertThat; 24 | import static org.junit.jupiter.api.Assertions.assertNotNull; 25 | import static org.junit.jupiter.api.Assertions.fail; 26 | 27 | class SimpleTest { 28 | @BeforeAll 29 | static void init() { 30 | Graphviz.useEngine(new GraphvizCmdLineEngine()); 31 | } 32 | 33 | @AfterAll 34 | static void end() { 35 | Graphviz.releaseEngine(); 36 | } 37 | 38 | @Test 39 | void simple() { 40 | final Graphviz viz = Graphviz.fromString("digraph g { \"a\\b'c\" -> b; }"); 41 | assertNotNull(viz.render(SVG).toString()); 42 | } 43 | 44 | @Test 45 | void dotError() { 46 | try { 47 | System.out.println("Try error..."); 48 | Graphviz.fromString("g { a -> b; }").render(SVG).toString(); 49 | fail("Wrong dot file should throw"); 50 | } catch (GraphvizException e) { 51 | assertThat(e.getMessage(), containsString("syntax error in line 1 near 'g'")); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/guru/nidi/graphviz/service/CommandRunnerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.service; 17 | 18 | import org.apache.commons.exec.CommandLine; 19 | import org.junit.jupiter.api.BeforeEach; 20 | import org.junit.jupiter.api.Test; 21 | import org.mockito.*; 22 | 23 | import javax.annotation.Nullable; 24 | import java.io.File; 25 | import java.io.IOException; 26 | import java.util.Arrays; 27 | 28 | import static org.junit.jupiter.api.Assertions.assertEquals; 29 | import static org.mockito.Matchers.isNull; 30 | import static org.mockito.Mockito.verify; 31 | 32 | /** 33 | * @author mhgam 34 | */ 35 | class CommandRunnerTest { 36 | 37 | @Captor 38 | @Nullable 39 | private ArgumentCaptor runEchoCaptor; 40 | 41 | @BeforeEach 42 | void init() { 43 | MockitoAnnotations.initMocks(this); 44 | } 45 | 46 | @Test 47 | void testRunEchoHelloWorld() throws IOException, InterruptedException { 48 | final CommandLine expected = System.getProperty("os.name").contains("Windows") 49 | ? CommandLine.parse("cmd /C echo hello world") 50 | : CommandLine.parse("/bin/sh -c").addArgument("echo hello world", false); 51 | 52 | final CommandLineExecutor cmdExecMock = Mockito.mock(CommandLineExecutor.class); 53 | final CommandRunner cmdRunner = new CommandBuilder() 54 | .withShellWrapper(true) 55 | .withCommandExecutor(cmdExecMock) 56 | .build(); 57 | 58 | cmdRunner.exec(CommandLine.parse("echo hello world"), null); 59 | 60 | verify(cmdExecMock).execute(runEchoCaptor.capture(), (File) isNull()); 61 | assertEquals(expected.toString(), runEchoCaptor.getValue().toString()); 62 | } 63 | 64 | @Test 65 | void testResultCode() throws IOException, InterruptedException { 66 | final CommandRunner cmdRunner = new CommandBuilder() 67 | .withShellWrapper(true) 68 | .build(); 69 | 70 | cmdRunner.exec("echo", Arrays.asList("hello", "world")); 71 | } 72 | 73 | @Test 74 | void testEnv() throws IOException, InterruptedException { 75 | final CommandRunner cmdRunner = new CommandBuilder() 76 | .withShellWrapper(true) 77 | .build(); 78 | 79 | cmdRunner.exec("env"); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/test/java/guru/nidi/graphviz/service/CommandRunnerWhichTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package guru.nidi.graphviz.service; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import java.nio.file.Path; 21 | import java.util.List; 22 | import java.util.stream.Collectors; 23 | 24 | import static org.hamcrest.MatcherAssert.assertThat; 25 | import static org.hamcrest.Matchers.*; 26 | 27 | /** 28 | * @author toon 29 | */ 30 | class CommandRunnerWhichTest { 31 | private final static String CMD_EXISTS = System.getProperty("os.name").contains("Windows") ? "notepad.exe" : "ls"; 32 | private final static String CMD_NOT_EXISTS = "foobeebaabeloo"; // crosses fingers 33 | 34 | @Test 35 | void whichTest() { 36 | final List paths = CommandRunner.which(CMD_EXISTS).collect(Collectors.toList()); 37 | assertThat(paths, is(not(empty()))); 38 | } 39 | 40 | @Test 41 | void whichTestEmpty() { 42 | final List paths = CommandRunner.which(CMD_NOT_EXISTS).collect(Collectors.toList()); 43 | assertThat(paths, is(empty())); 44 | } 45 | 46 | @Test 47 | void isExecutableFound() { 48 | assertThat(CommandRunner.isExecutableFound(CMD_EXISTS), is(true)); 49 | } 50 | 51 | @Test 52 | void isExecutableNotFound() { 53 | assertThat(CommandRunner.isExecutableFound(CMD_NOT_EXISTS), is(false)); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/test/resources/color.dot: -------------------------------------------------------------------------------- 1 | graph { 2 | { rank=same; white} 3 | { rank=same; cyan; yellow; pink} 4 | { rank=same; red; green; blue} 5 | { rank=same; black} 6 | 7 | white -- cyan -- blue 8 | white -- yellow -- green 9 | white -- pink -- red 10 | 11 | cyan -- green -- black 12 | yellow -- red -- black 13 | pink -- blue -- black 14 | } -------------------------------------------------------------------------------- /src/test/resources/g1.dot: -------------------------------------------------------------------------------- 1 | graph { 2 | layout=neato; 3 | overlap=scalexy; 4 | sep="+1"; // 0.1, +1 5 | 6 | node[label="Large node", width=2, height=2]; 7 | l1; l2; l3; 8 | node[label="\N", width=0.5, height=0.3]; 9 | 1 -- l1; 10 | 2 -- l1; 11 | 3 -- l1; 12 | 4 -- l1; 13 | 5 -- l1; 14 | 5 -- l2; 15 | 6 -- l2; 16 | 7 -- l2; 17 | 8 -- l2; 18 | 8 -- l3; 19 | 9 -- l3; 20 | 10 -- l3; 21 | } -------------------------------------------------------------------------------- /src/test/resources/laurent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ContextMapper/context-map-generator/a5b751032c6f80a5be35f6a1f4982a8bf06547cc/src/test/resources/laurent.png -------------------------------------------------------------------------------- /src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/test/resources/outfile1.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | 9 | g 10 | 11 | 12 | a 13 | 14 | a 15 | 16 | 17 | b 18 | 19 | b 20 | 21 | 22 | a--b 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/test/resources/simplelogger.properties: -------------------------------------------------------------------------------- 1 | org.slf4j.simpleLogger.defaultLogLevel=info 2 | -------------------------------------------------------------------------------- /src/test/resources/test1.dot: -------------------------------------------------------------------------------- 1 | graph { 2 | a -- b -- d -- c -- f[color=red,penwidth=3.0]; 3 | b -- c; 4 | d -- e; 5 | e -- f; 6 | a -- d; 7 | } --------------------------------------------------------------------------------