├── .DS_Store ├── .gitignore ├── LICENSE ├── NOTICE ├── README.md ├── bdio-protobuf ├── .DS_Store ├── build.gradle └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── blackducksoftware │ │ │ └── bdio │ │ │ └── proto │ │ │ ├── BdioConstants.java │ │ │ ├── BdioEntryType.java │ │ │ ├── ProtobufBdioReader.java │ │ │ ├── ProtobufBdioWriter.java │ │ │ ├── api │ │ │ ├── BdioAnnotationNode.java │ │ │ ├── BdioBdbaFileNode.java │ │ │ ├── BdioChunk.java │ │ │ ├── BdioComponentNode.java │ │ │ ├── BdioContainerLayerNode.java │ │ │ ├── BdioContainerNode.java │ │ │ ├── BdioDependencyNode.java │ │ │ ├── BdioFileNode.java │ │ │ ├── BdioHeader.java │ │ │ ├── BdioValidationException.java │ │ │ ├── IBdioNode.java │ │ │ ├── IProtobufBdioValidator.java │ │ │ ├── IProtobufBdioVersionReader.java │ │ │ └── IProtobufBdioVersionWriter.java │ │ │ ├── domain │ │ │ └── ProtoChunk.java │ │ │ └── impl │ │ │ ├── AbstractProtobufBdioValidator.java │ │ │ ├── AbstractProtobufBdioVersionReader.java │ │ │ ├── AbstractProtobufBdioVersionWriter.java │ │ │ ├── ProtoChunkBuilder.java │ │ │ ├── ProtobufBdioConverter.java │ │ │ ├── ProtobufBdioServiceProvider.java │ │ │ ├── ProtobufBdioV1Reader.java │ │ │ ├── ProtobufBdioV1Validator.java │ │ │ ├── ProtobufBdioV1Writer.java │ │ │ ├── ProtobufBdioV2Reader.java │ │ │ ├── ProtobufBdioV2Validator.java │ │ │ └── ProtobufBdioV2Writer.java │ └── proto │ │ ├── bdba_scan_nodes_v2.proto │ │ ├── file_node_v1.proto │ │ └── scan_header_v1.proto │ └── test │ ├── java │ └── com │ │ └── blackducksoftware │ │ └── bdio │ │ └── proto │ │ ├── ProtobufBdioConverterTest.java │ │ ├── ProtobufBdioV1ValidatorTest.java │ │ ├── ProtobufBdioV1WriterReaderTest.java │ │ ├── ProtobufBdioV2ValidatorTest.java │ │ ├── ProtobufBdioV2WriterReaderTest.java │ │ ├── ProtobufBdioWriterReaderTest.java │ │ └── ProtobufTestUtils.java │ └── resources │ └── scan_data │ └── dummy.txt ├── bdio-reactor ├── build.gradle └── src │ ├── main │ └── java │ │ └── com │ │ └── blackducksoftware │ │ └── bdio2 │ │ └── reactor │ │ ├── ReactorBdioDocument.java │ │ ├── ReactorJsonLdProcessing.java │ │ └── package-info.java │ └── test │ └── java │ └── com │ └── blackducksoftware │ └── bdio2 │ └── reactor │ └── BdioDocumentFromModelTest.java ├── bdio-rxjava ├── build.gradle └── src │ ├── main │ └── java │ │ └── com │ │ └── blackducksoftware │ │ └── bdio2 │ │ └── rxjava │ │ ├── RxJavaBdioDocument.java │ │ ├── RxJavaJsonLdProcessing.java │ │ └── package-info.java │ └── test │ └── java │ └── com │ └── blackducksoftware │ └── bdio2 │ └── rxjava │ └── BdioDocumentFromModelTest.java ├── bdio-test ├── build.gradle └── src │ ├── main │ └── java │ │ └── com │ │ └── blackducksoftware │ │ └── bdio2 │ │ └── test │ │ ├── BdioTest.java │ │ └── GraphRunner.java │ └── test │ └── java │ └── com │ └── blackducksoftware │ └── bdio2 │ └── test │ └── BdioTestTest.java ├── bdio-tinkerpop-db └── Dockerfile ├── bdio-tinkerpop ├── build.gradle └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── blackducksoftware │ │ │ └── bdio2 │ │ │ └── tinkerpop │ │ │ ├── BlackDuckIo.java │ │ │ ├── BlackDuckIoMapper.java │ │ │ ├── BlackDuckIoNormalization.java │ │ │ ├── BlackDuckIoOptions.java │ │ │ ├── BlackDuckIoReadGraphException.java │ │ │ ├── BlackDuckIoReader.java │ │ │ ├── BlackDuckIoVersion.java │ │ │ ├── BlackDuckIoWriter.java │ │ │ ├── package-info.java │ │ │ ├── spi │ │ │ ├── AbstractBlackDuckIoSpi.java │ │ │ ├── BlackDuckIoNormalizationSpi.java │ │ │ ├── BlackDuckIoReaderSpi.java │ │ │ ├── BlackDuckIoSpi.java │ │ │ ├── BlackDuckIoWriterSpi.java │ │ │ ├── DefaultBlackDuckIo.java │ │ │ ├── DefaultBlackDuckIoNormalization.java │ │ │ ├── DefaultBlackDuckIoReader.java │ │ │ ├── DefaultBlackDuckIoWriter.java │ │ │ └── package-info.java │ │ │ ├── sqlg │ │ │ ├── PostgresPlugin.java │ │ │ ├── SqlgBlackDuckIo.java │ │ │ ├── SqlgBlackDuckIoNormalization.java │ │ │ ├── SqlgBlackDuckIoReader.java │ │ │ ├── SqlgQueryBuilder.java │ │ │ ├── flyway │ │ │ │ ├── BaseSqlgMigration.java │ │ │ │ ├── BdioCallback.java │ │ │ │ ├── FlywayBackport.java │ │ │ │ ├── JdbcUrlDataSource.java │ │ │ │ ├── R__Create_aggregate_functions.java │ │ │ │ ├── SqlgCallback.java │ │ │ │ ├── SqlgFlywayExecutor.java │ │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ ├── step │ │ │ │ ├── AbstractSimpleSqlgOptimizationStep.java │ │ │ │ ├── SqlgGraphAddPropertyStep.java │ │ │ │ ├── SqlgGraphCountStep.java │ │ │ │ ├── SqlgGraphDropPropertyStep.java │ │ │ │ └── package-info.java │ │ │ └── strategy │ │ │ │ ├── SqlgSimpleQueryStrategy.java │ │ │ │ └── package-info.java │ │ │ ├── strategy │ │ │ ├── PropertyConstantStrategy.java │ │ │ └── package-info.java │ │ │ ├── tinkergraph │ │ │ ├── TinkerGraphBlackDuckIo.java │ │ │ ├── TinkerGraphBlackDuckIoNormalization.java │ │ │ ├── TinkerGraphBlackDuckIoReader.java │ │ │ └── package-info.java │ │ │ └── util │ │ │ ├── UnknownProperties.java │ │ │ ├── VertexProperties.java │ │ │ └── package-info.java │ └── resources │ │ └── META-INF │ │ └── services │ │ └── org.umlg.sqlg.SqlgPlugin │ └── test │ ├── java │ └── com │ │ └── blackducksoftware │ │ └── bdio2 │ │ └── tinkerpop │ │ ├── BaseTest.java │ │ ├── BlackDuckIoNormalizationTest.java │ │ ├── BlackDuckIoReaderTest.java │ │ ├── BlackDuckIoWriterTest.java │ │ ├── sqlg │ │ ├── SqlgBlackDuckIoNormalizationTest.java │ │ ├── SqlgBlackDuckIoReaderTest.java │ │ ├── SqlgCoreTests.java │ │ └── strategy │ │ │ └── OptimizationTest.java │ │ ├── strategy │ │ └── PropertyConstantStrategyTest.java │ │ ├── test │ │ └── NamedGraphBuilder.java │ │ ├── tinkergraph │ │ └── TinkerGraphCoreTests.java │ │ └── util │ │ └── VertexPropertiesTest.java │ └── resources │ ├── sqlg-core.properties │ ├── sqlg.properties │ ├── tinkergraph-core.properties │ └── tinkergraph.properties ├── bdio-tool ├── build.gradle └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── blackducksoftware │ │ │ └── bdio2 │ │ │ └── tool │ │ │ ├── AbstractFileTool.java │ │ │ ├── AbstractGraphTool.java │ │ │ ├── BdioMain.java │ │ │ ├── ConcatenateTool.java │ │ │ ├── ContextTool.java │ │ │ ├── DependenciesTool.java │ │ │ ├── EntriesTool.java │ │ │ ├── FilterTool.java │ │ │ ├── GraphTool.java │ │ │ ├── HeadTool.java │ │ │ ├── HidTool.java │ │ │ ├── JsonLdTool.java │ │ │ ├── LintTool.java │ │ │ ├── SpdxDocumentTool.java │ │ │ ├── SpecificationTool.java │ │ │ ├── Tool.java │ │ │ ├── TreeFormat.java │ │ │ ├── TreeTool.java │ │ │ ├── VizTool.java │ │ │ ├── linter │ │ │ ├── DataPropertyRange.java │ │ │ ├── Domain.java │ │ │ ├── FileTree.java │ │ │ ├── ImpliedFileSystemTypeConflict.java │ │ │ ├── Linter.java │ │ │ ├── Metadata.java │ │ │ ├── MissingFilePath.java │ │ │ ├── MissingProjectName.java │ │ │ ├── Namespace.java │ │ │ ├── ObjectPropertyRange.java │ │ │ ├── SemanticRules.java │ │ │ ├── SingleRoot.java │ │ │ ├── UnreferencedNode.java │ │ │ ├── UriSchemes.java │ │ │ ├── ValidFilePath.java │ │ │ ├── ValidIdentifier.java │ │ │ └── package-info.java │ │ │ └── package-info.java │ └── resources │ │ ├── META-INF │ │ └── mime.types │ │ └── com │ │ └── blackducksoftware │ │ └── bdio2 │ │ └── tool │ │ ├── spdx │ │ └── licenses.json │ │ └── www_viz │ │ ├── bdio.css │ │ ├── bdio.js │ │ └── index.html │ └── test │ └── java │ └── com │ └── blackducksoftware │ └── bdio2 │ └── tool │ └── ToolTest.java ├── bdio2 ├── build.gradle └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── blackducksoftware │ │ │ └── bdio2 │ │ │ ├── Bdio.java │ │ │ ├── BdioContext.java │ │ │ ├── BdioDocument.java │ │ │ ├── BdioEmitter.java │ │ │ ├── BdioFrame.java │ │ │ ├── BdioMetadata.java │ │ │ ├── BdioObject.java │ │ │ ├── BdioReader.java │ │ │ ├── BdioSubscriber.java │ │ │ ├── BdioValueMapper.java │ │ │ ├── BdioWriter.java │ │ │ ├── Emitter.java │ │ │ ├── EmitterFactory.java │ │ │ ├── EntrySizeViolationException.java │ │ │ ├── LegacyBdio1xEmitter.java │ │ │ ├── LegacyJsonParserEmitter.java │ │ │ ├── LegacyScanContainerEmitter.java │ │ │ ├── LegacyStreamingScanContainerEmitter.java │ │ │ ├── LegacyUtilities.java │ │ │ ├── NodeDoesNotExistException.java │ │ │ ├── StandardJavaValueMapper.java │ │ │ ├── model │ │ │ ├── Annotation.java │ │ │ ├── Component.java │ │ │ ├── Container.java │ │ │ ├── Dependency.java │ │ │ ├── File.java │ │ │ ├── FileCollection.java │ │ │ ├── License.java │ │ │ ├── LicenseGroup.java │ │ │ ├── Note.java │ │ │ ├── Project.java │ │ │ ├── Repository.java │ │ │ ├── Vulnerability.java │ │ │ └── package-info.java │ │ │ └── package-info.java │ └── resources │ │ └── com │ │ └── blackducksoftware │ │ └── bdio2 │ │ ├── bdio-context-1.0.jsonld │ │ ├── bdio-context-1.1.1.jsonld │ │ ├── bdio-context-1.1.jsonld │ │ ├── bdio-context-2.0.jsonld │ │ └── bdio-context-2.1.jsonld │ └── test │ └── java │ └── com │ └── blackducksoftware │ └── bdio2 │ ├── BdioContextTest.java │ ├── BdioDataModelSortOrderTest.java │ ├── BdioDataModelTest.java │ ├── BdioEmitterTest.java │ ├── BdioMetadataTest.java │ ├── BdioObjectTest.java │ ├── BdioReaderTest.java │ ├── BdioTest.java │ ├── BdioWriterTest.java │ ├── LegacyBdio1xEmitterTest.java │ ├── LegacyScanContainerEmitterTest.java │ └── LegacyUtilitiesTest.java ├── build.gradle ├── dependencies.properties ├── docs └── spec │ ├── 00.Abstract.txt │ ├── 01.Introduction.txt │ ├── 02.Model.txt │ ├── 03.SemanticRules.txt │ ├── 04.DocumentFormat.txt │ ├── AA.NamespaceRecommendations.txt │ ├── AB.IdentifierGuidelines.txt │ ├── AC.FileData.txt │ └── AD.ContentTypes.txt ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blackducksoftware/bdio/cb631d8b49b992d9ad73a9d3e5262d8c7b789901/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle cache 2 | /.gradle/ 3 | 4 | # Build output 5 | build/ 6 | 7 | # Eclipse 8 | .settings/ 9 | .classpath 10 | .project 11 | bin/ 12 | 13 | # Eclipse TestNG plugin output 14 | test-output/ 15 | 16 | # IntelliJ files 17 | /.idea/ 18 | *.iml 19 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Black Duck I/O 2 | Copyright 2015-2016 Black Duck Software, Inc. 3 | 4 | This product includes software developed at 5 | Black Duck Software, Inc. (http://www.blackducksoftware.com/). -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Black Duck I/O 2 | 3 | [![Build Status](https://travis-ci.org/blackducksoftware/bdio.svg?branch=master)](https://travis-ci.org/blackducksoftware/bdio) 4 | [![Download](https://api.bintray.com/packages/bds/oss/bdio/images/download.svg)](https://bintray.com/bds/oss/bdio/_latestVersion) 5 | 6 | Black Duck I/O is a specification for how to transfer data between Black Duck products, specifically Bill of Material (BOM) and scan related data. It is also an API for producing and consuming data conforming to the specification. The specification leverages [JSON-LD][json-ld] to represent data. You can find some simple examples of using the API to generate data on the [wiki][wiki]. 7 | 8 | ## Requirements 9 | 10 | The Black Duck I/O API requires Java 8 or later. The formatted data must conform to the [BDIO][bdio2_1] specification. 11 | 12 | 13 | ## Dependency Information 14 | 15 | Gradle 16 | ```` 17 | compile 'com.blackducksoftware.bdio:bdio-rxjava:x.y.z' 18 | ```` 19 | 20 | Maven 21 | ```` 22 | 23 | com.blackducksoftware.bdio 24 | bdio-rxjava 25 | x.y.z 26 | 27 | ```` 28 | 29 | ## Documentation 30 | 31 | Please refer to the [project wiki][wiki]. 32 | 33 | ## Build 34 | 35 | ```` 36 | $ git clone git@github.com:blackducksoftware/bdio.git bdio-libraries 37 | $ cd bdio-libraries/ 38 | $ docker build -t blackducksoftware/bdio-tinkerpop-db bdio-tinkerpop-db/ 39 | $ docker run -d -e POSTGRES_HOST_AUTH_METHOD=trust -p 5432:5432 blackducksoftware/bdio-tinkerpop-db 40 | $ ./gradlew build 41 | ```` 42 | 43 | ## License 44 | 45 | Licensed to the Apache Software Foundation (ASF) under one 46 | or more contributor license agreements. See the NOTICE file 47 | distributed with this work for additional information 48 | regarding copyright ownership. The ASF licenses this file 49 | to you under the Apache License, Version 2.0 (the 50 | "License"); you may not use this file except in compliance 51 | with the License. You may obtain a copy of the License at 52 | 53 | http://www.apache.org/licenses/LICENSE-2.0 54 | 55 | Unless required by applicable law or agreed to in writing, 56 | software distributed under the License is distributed on an 57 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 58 | KIND, either express or implied. See the License for the 59 | specific language governing permissions and limitations 60 | under the License. 61 | 62 | [json-ld]: http://json-ld.org 63 | [bdio2_0]: https://blackducksoftware.github.io/bdio/specification/2.0 64 | [bdio2_1]: https://blackducksoftware.github.io/bdio/specification/2.1 65 | [wiki]: https://github.com/blackducksoftware/bdio/wiki 66 | 67 | -------------------------------------------------------------------------------- /bdio-protobuf/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blackducksoftware/bdio/cb631d8b49b992d9ad73a9d3e5262d8c7b789901/bdio-protobuf/.DS_Store -------------------------------------------------------------------------------- /bdio-protobuf/build.gradle: -------------------------------------------------------------------------------- 1 | description = 'Black Duck I/O protobuf format definitions' 2 | 3 | apply plugin: 'com.google.protobuf' 4 | 5 | dependencies { 6 | compile 'com.google.protobuf:protobuf-java' 7 | compile 'com.google.guava:guava' 8 | compile 'commons-lang:commons-lang' 9 | 10 | testCompile 'junit:junit' 11 | testCompile 'org.mockito:mockito-core' 12 | testCompile 'commons-lang:commons-lang' 13 | testCompile 'com.google.truth:truth' 14 | } 15 | 16 | protobuf { 17 | protoc { 18 | artifact = 'com.google.protobuf:protoc:3.20.1' 19 | } 20 | 21 | generateProtoTasks { 22 | all().each { task -> 23 | task.builtins { 24 | // Generates Python code in the output folder: 25 | python { } 26 | } 27 | } 28 | } 29 | } 30 | 31 | sourceSets { 32 | generated { 33 | java { 34 | srcDir 'build/generated/source/proto/main/java' 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/java/com/blackducksoftware/bdio/proto/BdioConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Synopsys Inc. 3 | * http://www.synopsys.com/ 4 | * All rights reserved. 5 | * 6 | * This software is the confidential and proprietary information of 7 | * Synopsys ("Confidential Information"). You shall not 8 | * disclose such Confidential Information and shall use it only in 9 | * accordance with the terms of the license agreement you entered into 10 | * with Synopsys. 11 | */ 12 | package com.blackducksoftware.bdio.proto; 13 | 14 | public class BdioConstants { 15 | 16 | /** 17 | * version of data model, currently (till 2023.1.0 inclusive) used by signature 18 | * scans 19 | */ 20 | public static final short VERSION_1 = 1; 21 | 22 | /** 23 | * version of data model in bdio entry, that will be used for SIGNATURE, BINARY and CONTAINER scan types 24 | */ 25 | public static final short VERSION_2 = 2; 26 | 27 | /** 28 | * current version of data model 29 | */ 30 | public static final short CURRENT_VERSION = VERSION_2; 31 | 32 | /** 33 | * name of header entry in bdio archive 34 | */ 35 | public static final String HEADER_FILE_NAME = "bdio-header.pb"; 36 | 37 | /** 38 | * name of entry in bdio archive 39 | */ 40 | public static final String ENTRY_FILE_NAME_TEMPLATE = "bdio-entry-%02d.pb"; 41 | 42 | /** 43 | * maximum size of bdio archive entry 44 | */ 45 | public static final long MAX_CHUNK_SIZE = Math.multiplyExact(16, 1024 * 1024); // 16 Mb 46 | 47 | } 48 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/java/com/blackducksoftware/bdio/proto/BdioEntryType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Synopsys Inc. 3 | * http://www.synopsys.com/ 4 | * All rights reserved. 5 | * 6 | * This software is the confidential and proprietary information of 7 | * Synopsys ("Confidential Information"). You shall not 8 | * disclose such Confidential Information and shall use it only in 9 | * accordance with the terms of the license agreement you entered into 10 | * with Synopsys. 11 | */ 12 | package com.blackducksoftware.bdio.proto; 13 | 14 | /** 15 | * Enum defining bdio entry type. 16 | *

17 | * NOTE: Order matters here, only append new types to the end. 18 | * 19 | * @author sharapov 20 | */ 21 | public enum BdioEntryType { 22 | HEADER, CHUNK 23 | } 24 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/java/com/blackducksoftware/bdio/proto/api/BdioAnnotationNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Synopsys Inc. 3 | * http://www.synopsys.com/ 4 | * All rights reserved. 5 | * 6 | * This software is the confidential and proprietary information of 7 | * Synopsys ("Confidential Information"). You shall not 8 | * disclose such Confidential Information and shall use it only in 9 | * accordance with the terms of the license agreement you entered into 10 | * with Synopsys. 11 | */ 12 | package com.blackducksoftware.bdio.proto.api; 13 | 14 | import java.util.Objects; 15 | 16 | /** 17 | * 18 | * @author sharapov 19 | * 20 | */ 21 | public class BdioAnnotationNode implements IBdioNode { 22 | 23 | private String id; 24 | 25 | private String comment; 26 | 27 | public BdioAnnotationNode(String id, String comment) { 28 | this.id = id; 29 | this.comment = comment; 30 | } 31 | 32 | public String getId() { 33 | return id; 34 | } 35 | 36 | public String getComment() { 37 | return comment; 38 | } 39 | 40 | @Override 41 | public int hashCode() { 42 | return Objects.hash(getId(), getComment()); 43 | } 44 | 45 | @Override 46 | public boolean equals(Object other) { 47 | if (this == other) { 48 | return true; 49 | } else if (other instanceof BdioAnnotationNode) { 50 | BdioAnnotationNode annotationNode = (BdioAnnotationNode) other; 51 | return Objects.equals(getId(), annotationNode.getId()) 52 | && Objects.equals(getComment(), annotationNode.getComment()); 53 | } 54 | 55 | return false; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/java/com/blackducksoftware/bdio/proto/api/BdioBdbaFileNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Black Duck Software Inc. 3 | * http://www.blackducksoftware.com/ 4 | * All rights reserved. 5 | * 6 | * This software is the confidential and proprietary information of 7 | * Black Duck Software ("Confidential Information"). You shall not 8 | * disclose such Confidential Information and shall use it only in 9 | * accordance with the terms of the license agreement you entered into 10 | * with Black Duck Software. 11 | */ 12 | package com.blackducksoftware.bdio.proto.api; 13 | 14 | import java.time.Instant; 15 | import java.util.Map; 16 | import java.util.Objects; 17 | import java.util.Optional; 18 | 19 | import com.google.common.collect.ImmutableMap; 20 | 21 | /** 22 | * 23 | * @author sharapov 24 | * 25 | */ 26 | public class BdioBdbaFileNode implements IBdioNode { 27 | 28 | private final String id; 29 | 30 | private final String uri; 31 | 32 | private final long size; 33 | 34 | private final Instant lastModifiedDateTime; 35 | 36 | private final String fileSystemType; 37 | 38 | private final Map signatures; 39 | 40 | public BdioBdbaFileNode(String id, String uri, long size, Instant lastModifiedDateTime, String fileSystemType, 41 | Map signatures) { 42 | this.id = id; 43 | this.uri = uri; 44 | this.size = size; 45 | this.lastModifiedDateTime = lastModifiedDateTime; 46 | this.fileSystemType = fileSystemType; 47 | this.signatures = (signatures == null) ? ImmutableMap.of() : ImmutableMap.copyOf(signatures); 48 | } 49 | 50 | public String getId() { 51 | return id; 52 | } 53 | 54 | public String getUri() { 55 | return uri; 56 | } 57 | 58 | public long getSize() { 59 | return size; 60 | } 61 | 62 | public Instant getLastModifiedDateTime() { 63 | return lastModifiedDateTime; 64 | } 65 | 66 | public Optional getFileSystemType() { 67 | return Optional.ofNullable(fileSystemType); 68 | } 69 | 70 | public Map getSignatures() { 71 | return signatures; 72 | } 73 | 74 | @Override 75 | public int hashCode() { 76 | return Objects.hash(getId(), getUri(), getSize(), getLastModifiedDateTime(), 77 | getFileSystemType(), getSignatures()); 78 | } 79 | 80 | @Override 81 | public boolean equals(final Object other) { 82 | if (this == other) { 83 | return true; 84 | } else if (other instanceof BdioBdbaFileNode) { 85 | BdioBdbaFileNode bdbaFileNode = (BdioBdbaFileNode) other; 86 | return Objects.equals(getId(), bdbaFileNode.getId()) 87 | && Objects.equals(getUri(), bdbaFileNode.getUri()) 88 | && Objects.equals(getSize(), bdbaFileNode.getSize()) 89 | && Objects.equals(getLastModifiedDateTime(), bdbaFileNode.getLastModifiedDateTime()) 90 | && Objects.equals(getFileSystemType(), bdbaFileNode.getFileSystemType()) 91 | && Objects.equals(getSignatures(), bdbaFileNode.getSignatures()); 92 | } 93 | 94 | return false; 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/java/com/blackducksoftware/bdio/proto/api/BdioComponentNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Synopsys Inc. 3 | * http://www.synopsys.com/ 4 | * All rights reserved. 5 | * 6 | * This software is the confidential and proprietary information of 7 | * Synopsys ("Confidential Information"). You shall not 8 | * disclose such Confidential Information and shall use it only in 9 | * accordance with the terms of the license agreement you entered into 10 | * with Synopsys. 11 | */ 12 | package com.blackducksoftware.bdio.proto.api; 13 | 14 | import java.util.Objects; 15 | import java.util.Optional; 16 | 17 | /** 18 | * 19 | * @author sharapov 20 | * 21 | */ 22 | public class BdioComponentNode implements IBdioNode { 23 | 24 | private String id; 25 | 26 | private String namespace; 27 | 28 | private String identifier; 29 | 30 | private String descriptionId; 31 | 32 | public BdioComponentNode(String id, String namespace, String identifier, String descriptionId) { 33 | this.id = id; 34 | this.namespace = namespace; 35 | this.identifier = identifier; 36 | this.descriptionId = descriptionId; 37 | } 38 | 39 | public String getId() { 40 | return id; 41 | } 42 | 43 | public String getNamespace() { 44 | return namespace; 45 | } 46 | 47 | public String getIdentifier() { 48 | return identifier; 49 | } 50 | 51 | public Optional getDescriptionId() { 52 | return Optional.ofNullable(descriptionId); 53 | } 54 | 55 | @Override 56 | public int hashCode() { 57 | return Objects.hash(getId(), getNamespace(), getIdentifier(), getDescriptionId()); 58 | } 59 | 60 | @Override 61 | public boolean equals(Object other) { 62 | if (this == other) { 63 | return true; 64 | } else if (other instanceof BdioComponentNode) { 65 | BdioComponentNode componentNode = (BdioComponentNode) other; 66 | return Objects.equals(getId(), componentNode.getId()) 67 | && Objects.equals(getNamespace(), componentNode.getNamespace()) 68 | && Objects.equals(getIdentifier(), componentNode.getIdentifier()) 69 | && Objects.equals(getDescriptionId(), componentNode.getDescriptionId()); 70 | } 71 | 72 | return false; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/java/com/blackducksoftware/bdio/proto/api/BdioContainerLayerNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Synopsys Inc. 3 | * http://www.synopsys.com/ 4 | * All rights reserved. 5 | * 6 | * This software is the confidential and proprietary information of 7 | * Synopsys ("Confidential Information"). You shall not 8 | * disclose such Confidential Information and shall use it only in 9 | * accordance with the terms of the license agreement you entered into 10 | * with Synopsys. 11 | */ 12 | package com.blackducksoftware.bdio.proto.api; 13 | 14 | import java.time.Instant; 15 | import java.util.Objects; 16 | import java.util.Optional; 17 | 18 | /** 19 | * 20 | * @author sharapov 21 | * 22 | */ 23 | public class BdioContainerLayerNode implements IBdioNode { 24 | 25 | private String id; 26 | 27 | private String layer; 28 | 29 | private long size; 30 | 31 | private String command; 32 | 33 | private Instant createdAt; 34 | 35 | private String comment; 36 | 37 | public BdioContainerLayerNode(String id, String layer, long size, String command, Instant createdAt, 38 | String comment) { 39 | this.id = id; 40 | this.layer = layer; 41 | this.size = size; 42 | this.command = command; 43 | this.createdAt = createdAt; 44 | this.comment = comment; 45 | } 46 | 47 | public String getId() { 48 | return id; 49 | } 50 | 51 | public String getLayer() { 52 | return layer; 53 | } 54 | 55 | public long getSize() { 56 | return size; 57 | } 58 | 59 | public Optional getCommand() { 60 | return Optional.ofNullable(command); 61 | } 62 | 63 | public Optional getCreatedAt() { 64 | return Optional.ofNullable(createdAt); 65 | } 66 | 67 | public Optional getComment() { 68 | return Optional.ofNullable(comment); 69 | } 70 | 71 | @Override 72 | public int hashCode() { 73 | return Objects.hash(getId(), getLayer(), getSize(), getCommand(), getCreatedAt(), getComment()); 74 | } 75 | 76 | @Override 77 | public boolean equals(Object other) { 78 | if (this == other) { 79 | return true; 80 | } else if (other instanceof BdioContainerLayerNode) { 81 | BdioContainerLayerNode containerLayerNode = (BdioContainerLayerNode) other; 82 | return getSize() == containerLayerNode.getSize() && Objects.equals(getId(), containerLayerNode.getId()) 83 | && Objects.equals(getLayer(), containerLayerNode.getLayer()) 84 | && Objects.equals(getCommand(), containerLayerNode.getCommand()) 85 | && Objects.equals(getCreatedAt(), containerLayerNode.getCreatedAt()) 86 | && Objects.equals(getComment(), containerLayerNode.getComment()); 87 | } 88 | 89 | return false; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/java/com/blackducksoftware/bdio/proto/api/BdioDependencyNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Synopsys Inc. 3 | * http://www.synopsys.com/ 4 | * All rights reserved. 5 | * 6 | * This software is the confidential and proprietary information of 7 | * Synopsys ("Confidential Information"). You shall not 8 | * disclose such Confidential Information and shall use it only in 9 | * accordance with the terms of the license agreement you entered into 10 | * with Synopsys. 11 | */ 12 | package com.blackducksoftware.bdio.proto.api; 13 | 14 | import java.util.List; 15 | import java.util.Objects; 16 | import java.util.Optional; 17 | 18 | import com.google.common.collect.ImmutableList; 19 | 20 | /** 21 | * 22 | * @author sharapov 23 | * 24 | */ 25 | public class BdioDependencyNode implements IBdioNode { 26 | 27 | private String componentId; 28 | 29 | private String evidenceId; 30 | 31 | private String containerLayer; 32 | 33 | private String whiteoutLayer; 34 | 35 | private String descriptionId; 36 | 37 | private List matchTypes; 38 | 39 | public BdioDependencyNode(String componentId, String evidenceId, String containerLayer, String whiteoutLayer, 40 | String descriptionId, List matchTypes) { 41 | this.componentId = componentId; 42 | this.evidenceId = evidenceId; 43 | this.containerLayer = containerLayer; 44 | this.whiteoutLayer = whiteoutLayer; 45 | this.descriptionId = descriptionId; 46 | this.matchTypes = ImmutableList.copyOf(matchTypes); 47 | } 48 | 49 | public String getComponentId() { 50 | return componentId; 51 | } 52 | 53 | public Optional getEvidenceId() { 54 | return Optional.ofNullable(evidenceId); 55 | } 56 | 57 | public Optional getContainerLayer() { 58 | return Optional.ofNullable(containerLayer); 59 | } 60 | 61 | public Optional getWhiteoutLayer() { 62 | return Optional.ofNullable(whiteoutLayer); 63 | } 64 | 65 | public Optional getDescriptionId() { 66 | return Optional.ofNullable(descriptionId); 67 | } 68 | 69 | public List getMatchTypes() { 70 | return matchTypes; 71 | } 72 | 73 | @Override 74 | public int hashCode() { 75 | return Objects.hash(getComponentId(), getEvidenceId(), getContainerLayer(), getWhiteoutLayer(), 76 | getDescriptionId(), getMatchTypes()); 77 | } 78 | 79 | @Override 80 | public boolean equals(final Object other) { 81 | if (this == other) { 82 | return true; 83 | } else if (other instanceof BdioDependencyNode) { 84 | BdioDependencyNode dependencyNode = (BdioDependencyNode) other; 85 | return Objects.equals(getComponentId(), dependencyNode.getComponentId()) 86 | && Objects.equals(getEvidenceId(), dependencyNode.getEvidenceId()) 87 | && Objects.equals(getContainerLayer(), dependencyNode.getContainerLayer()) 88 | && Objects.equals(getWhiteoutLayer(), dependencyNode.getWhiteoutLayer()) 89 | && Objects.equals(getDescriptionId(), dependencyNode.getDescriptionId()) 90 | && Objects.equals(getMatchTypes(), dependencyNode.getMatchTypes()); 91 | } 92 | 93 | return false; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/java/com/blackducksoftware/bdio/proto/api/BdioValidationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Synopsys Inc. 3 | * http://www.synopsys.com/ 4 | * All rights reserved. 5 | * 6 | * This software is the confidential and proprietary information of 7 | * Synopsys ("Confidential Information"). You shall not 8 | * disclose such Confidential Information and shall use it only in 9 | * accordance with the terms of the license agreement you entered into 10 | * with Synopsys. 11 | */ 12 | package com.blackducksoftware.bdio.proto.api; 13 | 14 | /** 15 | * 16 | * @author sharapov 17 | * 18 | */ 19 | public class BdioValidationException extends RuntimeException { 20 | 21 | private static final long serialVersionUID = 3528312351351639125L; 22 | 23 | public BdioValidationException(String message) { 24 | super(message); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/java/com/blackducksoftware/bdio/proto/api/IBdioNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Synopsys Inc. 3 | * http://www.synopsys.com/ 4 | * All rights reserved. 5 | * 6 | * This software is the confidential and proprietary information of 7 | * Synopsys ("Confidential Information"). You shall not 8 | * disclose such Confidential Information and shall use it only in 9 | * accordance with the terms of the license agreement you entered into 10 | * with Synopsys. 11 | */ 12 | package com.blackducksoftware.bdio.proto.api; 13 | 14 | /** 15 | * Marker interface for all bdio data classes that can be serialized 16 | * 17 | * @author sharapov 18 | * 19 | */ 20 | public interface IBdioNode { 21 | 22 | } 23 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/java/com/blackducksoftware/bdio/proto/api/IProtobufBdioValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Synopsys Inc. 3 | * http://www.synopsys.com/ 4 | * All rights reserved. 5 | * 6 | * This software is the confidential and proprietary information of 7 | * Synopsys ("Confidential Information"). You shall not 8 | * disclose such Confidential Information and shall use it only in 9 | * accordance with the terms of the license agreement you entered into 10 | * with Synopsys. 11 | */ 12 | package com.blackducksoftware.bdio.proto.api; 13 | 14 | import com.google.protobuf.Message; 15 | 16 | /** 17 | * Api for validation of protobuf message before serialization or after deserialization 18 | * 19 | * @author sharapov 20 | * 21 | */ 22 | public interface IProtobufBdioValidator { 23 | 24 | /** 25 | * Validate single protobuf data node 26 | * 27 | * @param message 28 | * node to validate 29 | * @throws BdioValidationException 30 | */ 31 | void validate(Message message); 32 | } 33 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/java/com/blackducksoftware/bdio/proto/api/IProtobufBdioVersionReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Synopsys Inc. 3 | * http://www.synopsys.com/ 4 | * All rights reserved. 5 | * 6 | * This software is the confidential and proprietary information of 7 | * Synopsys ("Confidential Information"). You shall not 8 | * disclose such Confidential Information and shall use it only in 9 | * accordance with the terms of the license agreement you entered into 10 | * with Synopsys. 11 | */ 12 | package com.blackducksoftware.bdio.proto.api; 13 | 14 | import java.io.IOException; 15 | import java.io.InputStream; 16 | 17 | import com.blackducksoftware.bdio.proto.domain.ProtoChunk; 18 | import com.blackducksoftware.bdio.proto.domain.ProtoScanHeader; 19 | 20 | /** 21 | * Api for reading bdio data 22 | * 23 | * @author sharapov 24 | * 25 | */ 26 | public interface IProtobufBdioVersionReader { 27 | 28 | /** 29 | * Reads header chunk represented by input stream 30 | * 31 | * @param in 32 | * input stream 33 | * @return ProtoScanHeader 34 | * @throws IOException 35 | */ 36 | ProtoScanHeader readHeaderChunk(InputStream in) throws IOException; 37 | 38 | /** 39 | * Reads the bdio entry (chunk) represented by input stream. 40 | * 41 | * @param in 42 | * input stream 43 | * @return ProtoChunk deserialized bdio entry (chunk) 44 | * @throws IOException 45 | */ 46 | ProtoChunk readProtoChunk(InputStream in) throws IOException; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/java/com/blackducksoftware/bdio/proto/api/IProtobufBdioVersionWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Synopsys Inc. 3 | * http://www.synopsys.com/ 4 | * All rights reserved. 5 | * 6 | * This software is the confidential and proprietary information of 7 | * Synopsys ("Confidential Information"). You shall not 8 | * disclose such Confidential Information and shall use it only in 9 | * accordance with the terms of the license agreement you entered into 10 | * with Synopsys. 11 | */ 12 | package com.blackducksoftware.bdio.proto.api; 13 | 14 | import java.io.IOException; 15 | import java.util.zip.ZipOutputStream; 16 | 17 | import com.google.protobuf.Message; 18 | 19 | /** 20 | * Api for writing bdio data 21 | * 22 | * @author sharapov 23 | * 24 | */ 25 | public interface IProtobufBdioVersionWriter { 26 | 27 | /** 28 | * Write header data to bdio header in provided zip archive stream 29 | * 30 | * @param bdioArchive 31 | * @param header 32 | * @throws IOException 33 | */ 34 | void writeToHeader(ZipOutputStream bdioArchive, Message header) throws IOException; 35 | 36 | /** 37 | * Write node to bdio entry in provided zip archive stream 38 | * 39 | * @param bdioArchive 40 | * @param node 41 | * @throws IOException 42 | */ 43 | void writeToEntry(ZipOutputStream bdioArchive, Message node) throws IOException; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/java/com/blackducksoftware/bdio/proto/impl/AbstractProtobufBdioVersionReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Black Duck Software Inc. 3 | * http://www.blackducksoftware.com/ 4 | * All rights reserved. 5 | * 6 | * This software is the confidential and proprietary information of 7 | * Black Duck Software ("Confidential Information"). You shall not 8 | * disclose such Confidential Information and shall use it only in 9 | * accordance with the terms of the license agreement you entered into 10 | * with Black Duck Software. 11 | */ 12 | package com.blackducksoftware.bdio.proto.impl; 13 | 14 | import java.io.IOException; 15 | import java.io.InputStream; 16 | import java.util.List; 17 | import java.util.Objects; 18 | import java.util.Optional; 19 | 20 | import com.blackducksoftware.bdio.proto.api.IProtobufBdioValidator; 21 | import com.blackducksoftware.bdio.proto.api.IProtobufBdioVersionReader; 22 | import com.blackducksoftware.bdio.proto.domain.ProtoChunk; 23 | import com.blackducksoftware.bdio.proto.domain.ProtoScanHeader; 24 | import com.google.protobuf.Any; 25 | import com.google.protobuf.Message; 26 | 27 | /** 28 | * Abstract protobuf bdio reader 29 | * 30 | * @author sharapov 31 | * 32 | */ 33 | public abstract class AbstractProtobufBdioVersionReader implements IProtobufBdioVersionReader { 34 | 35 | protected final IProtobufBdioValidator validator; 36 | 37 | public AbstractProtobufBdioVersionReader(IProtobufBdioValidator validator) { 38 | this.validator = Objects.requireNonNull(validator); 39 | } 40 | 41 | /** 42 | * Get list of message type classes representing data model for specific version 43 | * 44 | * @return List> 45 | */ 46 | abstract List> getClassesList(); 47 | 48 | @Override 49 | public ProtoScanHeader readHeaderChunk(InputStream in) throws IOException { 50 | Any any = Any.parseFrom(in); 51 | if (any.is(ProtoScanHeader.class)) { 52 | return any.unpack(ProtoScanHeader.class); 53 | } 54 | 55 | throw new RuntimeException("Unknown type for header data: " + any.getTypeUrl()); 56 | } 57 | 58 | @Override 59 | public ProtoChunk readProtoChunk(InputStream in) throws IOException { 60 | ProtoChunkBuilder protoChunkBuilder = new ProtoChunkBuilder(); 61 | 62 | while (true) { 63 | Any any = Any.parseDelimitedFrom(in); 64 | 65 | if (any == null) { 66 | // the end of the steam 67 | break; 68 | } 69 | 70 | Optional> clz = getClassesList().stream() 71 | .filter(cl -> any.is(cl)).findFirst(); 72 | 73 | if (clz.isEmpty()) { 74 | throw new RuntimeException("Object of unknown class is found: " + any.getTypeUrl()); 75 | } 76 | 77 | Message message = any.unpack(clz.get()); 78 | validator.validate(message); 79 | protoChunkBuilder.add(message); 80 | } 81 | 82 | return protoChunkBuilder.build(); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/java/com/blackducksoftware/bdio/proto/impl/AbstractProtobufBdioVersionWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Black Duck Software Inc. 3 | * http://www.blackducksoftware.com/ 4 | * All rights reserved. 5 | * 6 | * This software is the confidential and proprietary information of 7 | * Black Duck Software ("Confidential Information"). You shall not 8 | * disclose such Confidential Information and shall use it only in 9 | * accordance with the terms of the license agreement you entered into 10 | * with Black Duck Software. 11 | */ 12 | package com.blackducksoftware.bdio.proto.impl; 13 | 14 | import java.io.IOException; 15 | import java.util.Objects; 16 | import java.util.zip.ZipEntry; 17 | import java.util.zip.ZipOutputStream; 18 | 19 | import com.blackducksoftware.bdio.proto.BdioConstants; 20 | import com.blackducksoftware.bdio.proto.BdioEntryType; 21 | import com.blackducksoftware.bdio.proto.api.IProtobufBdioValidator; 22 | import com.blackducksoftware.bdio.proto.api.IProtobufBdioVersionWriter; 23 | import com.google.common.primitives.Shorts; 24 | import com.google.protobuf.Message; 25 | 26 | /** 27 | * Provides common methods for writing bdio data 28 | * 29 | * @author sharapov 30 | * 31 | */ 32 | public abstract class AbstractProtobufBdioVersionWriter implements IProtobufBdioVersionWriter { 33 | 34 | private long bytesRemaining = 0L; 35 | 36 | private int entryCount = 0; 37 | 38 | protected final IProtobufBdioValidator validator; 39 | 40 | public AbstractProtobufBdioVersionWriter(IProtobufBdioValidator validator) { 41 | this.validator = Objects.requireNonNull(validator); 42 | } 43 | 44 | protected abstract short getVersion(); 45 | 46 | protected abstract void writeHeaderNode(ZipOutputStream bdioArchive, Message header) throws IOException; 47 | 48 | protected abstract void writeDataNode(ZipOutputStream bdioArchive, Message protoNode) throws IOException; 49 | 50 | @Override 51 | public void writeToHeader(ZipOutputStream bdioArchive, Message header) throws IOException { 52 | bdioArchive.putNextEntry(new ZipEntry(BdioConstants.HEADER_FILE_NAME)); 53 | bdioArchive.write(Shorts.toByteArray((short) BdioEntryType.HEADER.ordinal())); // bdio entry type 54 | bdioArchive.write(Shorts.toByteArray(getVersion())); // format version 55 | 56 | writeHeaderNode(bdioArchive, header); 57 | } 58 | 59 | @Override 60 | public void writeToEntry(ZipOutputStream bdioArchive, Message protoNode) throws IOException { 61 | boolean newEntry = (bytesRemaining - protoNode.getSerializedSize() - 4) <= 0; 62 | bytesRemaining = newEntry ? BdioConstants.MAX_CHUNK_SIZE : bytesRemaining; // reset remaining bytes for new 63 | // entry 64 | bytesRemaining -= protoNode.getSerializedSize() + 4; 65 | 66 | if (newEntry) { 67 | createNewArchiveEntry(bdioArchive); 68 | entryCount++; 69 | } 70 | 71 | validator.validate(protoNode); 72 | 73 | writeDataNode(bdioArchive, protoNode); 74 | } 75 | 76 | private void createNewArchiveEntry(ZipOutputStream bdioArchive) throws IOException { 77 | bdioArchive.putNextEntry(new ZipEntry(String.format(BdioConstants.ENTRY_FILE_NAME_TEMPLATE, entryCount))); 78 | bdioArchive.write(Shorts.toByteArray((short) BdioEntryType.CHUNK.ordinal())); // bdio entry type 79 | bdioArchive.write(Shorts.toByteArray(getVersion())); // format version 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/java/com/blackducksoftware/bdio/proto/impl/ProtoChunkBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Black Duck Software Inc. 3 | * http://www.blackducksoftware.com/ 4 | * All rights reserved. 5 | * 6 | * This software is the confidential and proprietary information of 7 | * Black Duck Software ("Confidential Information"). You shall not 8 | * disclose such Confidential Information and shall use it only in 9 | * accordance with the terms of the license agreement you entered into 10 | * with Black Duck Software. 11 | */ 12 | package com.blackducksoftware.bdio.proto.impl; 13 | 14 | import java.util.HashSet; 15 | import java.util.Set; 16 | 17 | import com.blackducksoftware.bdio.proto.domain.ProtoAnnotationNode; 18 | import com.blackducksoftware.bdio.proto.domain.ProtoBdbaFileNode; 19 | import com.blackducksoftware.bdio.proto.domain.ProtoChunk; 20 | import com.blackducksoftware.bdio.proto.domain.ProtoComponentNode; 21 | import com.blackducksoftware.bdio.proto.domain.ProtoContainerLayerNode; 22 | import com.blackducksoftware.bdio.proto.domain.ProtoContainerNode; 23 | import com.blackducksoftware.bdio.proto.domain.ProtoDependencyNode; 24 | import com.blackducksoftware.bdio.proto.domain.ProtoFileNode; 25 | import com.google.protobuf.Message; 26 | 27 | /** 28 | * Builder for bdio chunk 29 | * 30 | * @author sharapov 31 | * 32 | */ 33 | public class ProtoChunkBuilder { 34 | 35 | private final Set fileNodes = new HashSet<>(); 36 | 37 | private final Set dependencyNodes = new HashSet<>(); 38 | 39 | private final Set componentNodes = new HashSet<>(); 40 | 41 | private final Set annotationNodes = new HashSet<>(); 42 | 43 | private final Set containerNodes = new HashSet<>(); 44 | 45 | private final Set containerLayerNodes = new HashSet<>(); 46 | 47 | private final Set bdbaFileNodes = new HashSet<>(); 48 | 49 | public ProtoChunkBuilder add(Message node) { 50 | if (node instanceof ProtoDependencyNode) { 51 | dependencyNodes.add((ProtoDependencyNode) node); 52 | } else if (node instanceof ProtoComponentNode) { 53 | componentNodes.add((ProtoComponentNode) node); 54 | } else if (node instanceof ProtoFileNode) { 55 | fileNodes.add((ProtoFileNode) node); 56 | } else if (node instanceof ProtoAnnotationNode) { 57 | annotationNodes.add((ProtoAnnotationNode) node); 58 | } else if (node instanceof ProtoContainerNode) { 59 | containerNodes.add((ProtoContainerNode) node); 60 | } else if (node instanceof ProtoContainerLayerNode) { 61 | containerLayerNodes.add((ProtoContainerLayerNode) node); 62 | } else if (node instanceof ProtoBdbaFileNode) { 63 | bdbaFileNodes.add((ProtoBdbaFileNode) node); 64 | } else { 65 | throw new RuntimeException("Unknown type: " + node.getClass().getName()); 66 | } 67 | 68 | return this; 69 | } 70 | 71 | public ProtoChunk build() { 72 | return new ProtoChunk( 73 | fileNodes, 74 | dependencyNodes, 75 | componentNodes, 76 | annotationNodes, 77 | containerNodes, 78 | containerLayerNodes, 79 | bdbaFileNodes); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/java/com/blackducksoftware/bdio/proto/impl/ProtobufBdioServiceProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Black Duck Software Inc. 3 | * http://www.blackducksoftware.com/ 4 | * All rights reserved. 5 | * 6 | * This software is the confidential and proprietary information of 7 | * Black Duck Software ("Confidential Information"). You shall not 8 | * disclose such Confidential Information and shall use it only in 9 | * accordance with the terms of the license agreement you entered into 10 | * with Black Duck Software. 11 | */ 12 | package com.blackducksoftware.bdio.proto.impl; 13 | 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | 17 | import com.blackducksoftware.bdio.proto.BdioConstants; 18 | import com.blackducksoftware.bdio.proto.api.IProtobufBdioValidator; 19 | import com.blackducksoftware.bdio.proto.api.IProtobufBdioVersionReader; 20 | import com.blackducksoftware.bdio.proto.api.IProtobufBdioVersionWriter; 21 | 22 | /** 23 | * Provides service for specific version 24 | * 25 | * @author sharapov 26 | * 27 | */ 28 | public class ProtobufBdioServiceProvider { 29 | 30 | private final Map protobufValidators = new HashMap<>(); 31 | 32 | private final Map protobufReaders = new HashMap<>(); 33 | 34 | private final Map protobufWriters = new HashMap<>(); 35 | 36 | public ProtobufBdioServiceProvider() { 37 | 38 | ProtobufBdioV1Validator v1Validator = new ProtobufBdioV1Validator(); 39 | ProtobufBdioV1Reader v1Reader = new ProtobufBdioV1Reader(v1Validator); 40 | IProtobufBdioVersionWriter v1Writer = new ProtobufBdioV1Writer(v1Validator); 41 | 42 | protobufValidators.put(BdioConstants.VERSION_1, v1Validator); 43 | protobufReaders.put(BdioConstants.VERSION_1, v1Reader); 44 | protobufWriters.put(BdioConstants.VERSION_1, v1Writer); 45 | 46 | ProtobufBdioV2Validator v2Validator = new ProtobufBdioV2Validator(); 47 | ProtobufBdioV2Reader v2Reader = new ProtobufBdioV2Reader(v2Validator); 48 | IProtobufBdioVersionWriter v2Writer = new ProtobufBdioV2Writer(v2Validator); 49 | 50 | protobufValidators.put(BdioConstants.VERSION_2, v2Validator); 51 | protobufReaders.put(BdioConstants.VERSION_2, v2Reader); 52 | protobufWriters.put(BdioConstants.VERSION_2, v2Writer); 53 | 54 | } 55 | 56 | public IProtobufBdioValidator getProtobufBdioValidator(short version) { 57 | 58 | IProtobufBdioValidator validator = protobufValidators.get(version); 59 | 60 | if (validator == null) { 61 | throw new RuntimeException("Unknow version is detected: " + version); 62 | } 63 | 64 | return validator; 65 | } 66 | 67 | public IProtobufBdioVersionReader getProtobufBdioReader(short version) { 68 | 69 | IProtobufBdioVersionReader reader = protobufReaders.get(version); 70 | 71 | if (reader == null) { 72 | throw new RuntimeException("Unknow version is detected: " + version); 73 | } 74 | 75 | return reader; 76 | } 77 | 78 | public IProtobufBdioVersionWriter getProtobufBdioWriter(short version) { 79 | 80 | IProtobufBdioVersionWriter writer = protobufWriters.get(version); 81 | 82 | if (writer == null) { 83 | throw new RuntimeException("Unknow version is detected: " + version); 84 | } 85 | 86 | return writer; 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/java/com/blackducksoftware/bdio/proto/impl/ProtobufBdioV1Reader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Black Duck Software Inc. 3 | * http://www.blackducksoftware.com/ 4 | * All rights reserved. 5 | * 6 | * This software is the confidential and proprietary information of 7 | * Black Duck Software ("Confidential Information"). You shall not 8 | * disclose such Confidential Information and shall use it only in 9 | * accordance with the terms of the license agreement you entered into 10 | * with Black Duck Software. 11 | */ 12 | package com.blackducksoftware.bdio.proto.impl; 13 | 14 | import java.io.IOException; 15 | import java.io.InputStream; 16 | import java.util.HashSet; 17 | import java.util.List; 18 | import java.util.Set; 19 | 20 | import com.blackducksoftware.bdio.proto.api.IProtobufBdioValidator; 21 | import com.blackducksoftware.bdio.proto.domain.ProtoChunk; 22 | import com.blackducksoftware.bdio.proto.domain.ProtoFileNode; 23 | import com.blackducksoftware.bdio.proto.domain.ProtoScanHeader; 24 | import com.google.common.collect.ImmutableList; 25 | 26 | /** 27 | * Reads the protobuf bdio data of version 1 28 | * 29 | * @author sharapov 30 | * 31 | */ 32 | public class ProtobufBdioV1Reader extends AbstractProtobufBdioVersionReader { 33 | 34 | public ProtobufBdioV1Reader(IProtobufBdioValidator validator) { 35 | super(validator); 36 | } 37 | 38 | @Override 39 | public ProtoScanHeader readHeaderChunk(InputStream in) throws IOException { 40 | return ProtoScanHeader.parseFrom(in); 41 | } 42 | 43 | @Override 44 | public List> getClassesList() { 45 | return ImmutableList.of(ProtoFileNode.class); 46 | } 47 | 48 | @Override 49 | public ProtoChunk readProtoChunk(InputStream in) throws IOException { 50 | Set fileNodes = new HashSet<>(); 51 | 52 | ProtoFileNode node; 53 | 54 | // in version 1 only file nodes may be present 55 | while ((node = ProtoFileNode.parseDelimitedFrom(in)) != null) { 56 | validator.validate(node); 57 | fileNodes.add(node); 58 | } 59 | 60 | return new ProtoChunk(fileNodes); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/java/com/blackducksoftware/bdio/proto/impl/ProtobufBdioV1Validator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Black Duck Software Inc. 3 | * http://www.blackducksoftware.com/ 4 | * All rights reserved. 5 | * 6 | * This software is the confidential and proprietary information of 7 | * Black Duck Software ("Confidential Information"). You shall not 8 | * disclose such Confidential Information and shall use it only in 9 | * accordance with the terms of the license agreement you entered into 10 | * with Black Duck Software. 11 | */ 12 | package com.blackducksoftware.bdio.proto.impl; 13 | 14 | import com.blackducksoftware.bdio.proto.api.BdioValidationException; 15 | import com.blackducksoftware.bdio.proto.domain.ProtoFileNode; 16 | import com.google.protobuf.Message; 17 | 18 | /** 19 | * Validate version 1 bdio data 20 | * 21 | * @author sharapov 22 | * 23 | */ 24 | public class ProtobufBdioV1Validator extends AbstractProtobufBdioValidator { 25 | 26 | @Override 27 | public void validate(Message message) { 28 | if (message instanceof ProtoFileNode) { 29 | validate((ProtoFileNode) message); 30 | } else { 31 | throw new BdioValidationException("Unknown message type in version 1: " + message.getClass().getName()); 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/java/com/blackducksoftware/bdio/proto/impl/ProtobufBdioV1Writer.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) 2023 Black Duck Software Inc. 4 | * http://www.blackducksoftware.com/ 5 | * All rights reserved. 6 | * 7 | * This software is the confidential and proprietary information of 8 | * Black Duck Software ("Confidential Information"). You shall not 9 | * disclose such Confidential Information and shall use it only in 10 | * accordance with the terms of the license agreement you entered into 11 | * with Black Duck Software. 12 | */ 13 | package com.blackducksoftware.bdio.proto.impl; 14 | 15 | import java.io.IOException; 16 | import java.util.zip.ZipOutputStream; 17 | 18 | import com.blackducksoftware.bdio.proto.BdioConstants; 19 | import com.blackducksoftware.bdio.proto.api.IProtobufBdioValidator; 20 | import com.google.protobuf.Message; 21 | 22 | /** 23 | * Implements methods to write version 1 bdio data 24 | * 25 | * @author sharapov 26 | * 27 | */ 28 | public class ProtobufBdioV1Writer extends AbstractProtobufBdioVersionWriter { 29 | 30 | public ProtobufBdioV1Writer(IProtobufBdioValidator validator) { 31 | super(validator); 32 | } 33 | 34 | @Override 35 | public short getVersion() { 36 | return BdioConstants.VERSION_1; 37 | } 38 | 39 | @Override 40 | protected void writeHeaderNode(ZipOutputStream bdioArchive, Message header) throws IOException { 41 | header.writeTo(bdioArchive); 42 | } 43 | 44 | @Override 45 | public void writeDataNode(ZipOutputStream bdioArchive, Message node) throws IOException { 46 | node.writeDelimitedTo(bdioArchive); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/java/com/blackducksoftware/bdio/proto/impl/ProtobufBdioV2Reader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Black Duck Software Inc. 3 | * http://www.blackducksoftware.com/ 4 | * All rights reserved. 5 | * 6 | * This software is the confidential and proprietary information of 7 | * Black Duck Software ("Confidential Information"). You shall not 8 | * disclose such Confidential Information and shall use it only in 9 | * accordance with the terms of the license agreement you entered into 10 | * with Black Duck Software. 11 | */ 12 | package com.blackducksoftware.bdio.proto.impl; 13 | 14 | import java.util.List; 15 | 16 | import com.blackducksoftware.bdio.proto.api.IProtobufBdioValidator; 17 | import com.blackducksoftware.bdio.proto.domain.ProtoAnnotationNode; 18 | import com.blackducksoftware.bdio.proto.domain.ProtoBdbaFileNode; 19 | import com.blackducksoftware.bdio.proto.domain.ProtoComponentNode; 20 | import com.blackducksoftware.bdio.proto.domain.ProtoContainerLayerNode; 21 | import com.blackducksoftware.bdio.proto.domain.ProtoContainerNode; 22 | import com.blackducksoftware.bdio.proto.domain.ProtoDependencyNode; 23 | import com.blackducksoftware.bdio.proto.domain.ProtoFileNode; 24 | import com.google.common.collect.ImmutableList; 25 | import com.google.protobuf.Message; 26 | 27 | /** 28 | * Reads the protobuf bdio data of version 2 29 | * 30 | * @author sharapov 31 | * 32 | */ 33 | public class ProtobufBdioV2Reader extends AbstractProtobufBdioVersionReader { 34 | 35 | public ProtobufBdioV2Reader(IProtobufBdioValidator validator) { 36 | super(validator); 37 | } 38 | 39 | @Override 40 | public List> getClassesList() { 41 | return ImmutableList.of( 42 | ProtoDependencyNode.class, 43 | ProtoComponentNode.class, 44 | ProtoFileNode.class, 45 | ProtoAnnotationNode.class, 46 | ProtoContainerNode.class, 47 | ProtoContainerLayerNode.class, 48 | ProtoBdbaFileNode.class); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/java/com/blackducksoftware/bdio/proto/impl/ProtobufBdioV2Validator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Black Duck Software Inc. 3 | * http://www.blackducksoftware.com/ 4 | * All rights reserved. 5 | * 6 | * This software is the confidential and proprietary information of 7 | * Black Duck Software ("Confidential Information"). You shall not 8 | * disclose such Confidential Information and shall use it only in 9 | * accordance with the terms of the license agreement you entered into 10 | * with Black Duck Software. 11 | */ 12 | package com.blackducksoftware.bdio.proto.impl; 13 | 14 | import com.blackducksoftware.bdio.proto.domain.ProtoAnnotationNode; 15 | import com.blackducksoftware.bdio.proto.domain.ProtoBdbaFileNode; 16 | import com.blackducksoftware.bdio.proto.domain.ProtoComponentNode; 17 | import com.blackducksoftware.bdio.proto.domain.ProtoContainerLayerNode; 18 | import com.blackducksoftware.bdio.proto.domain.ProtoContainerNode; 19 | import com.blackducksoftware.bdio.proto.domain.ProtoDependencyNode; 20 | import com.blackducksoftware.bdio.proto.domain.ProtoFileNode; 21 | import com.google.protobuf.Message; 22 | 23 | /** 24 | * Validate version 2 bdio data 25 | * 26 | * @author sharapov 27 | * 28 | */ 29 | public class ProtobufBdioV2Validator extends AbstractProtobufBdioValidator { 30 | 31 | @Override 32 | public void validate(Message message) { 33 | 34 | if (message instanceof ProtoDependencyNode) { 35 | validate((ProtoDependencyNode) message); 36 | } else if (message instanceof ProtoComponentNode) { 37 | validate((ProtoComponentNode) message); 38 | } else if (message instanceof ProtoFileNode) { 39 | validate((ProtoFileNode) message); 40 | } else if (message instanceof ProtoAnnotationNode) { 41 | validate((ProtoAnnotationNode) message); 42 | } else if (message instanceof ProtoContainerNode) { 43 | validate((ProtoContainerNode) message); 44 | } else if (message instanceof ProtoContainerLayerNode) { 45 | validate((ProtoContainerLayerNode) message); 46 | } else if (message instanceof ProtoBdbaFileNode) { 47 | validate((ProtoBdbaFileNode) message); 48 | } else { 49 | throw new RuntimeException("Unknown type: " + message.getClass().getName()); 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/java/com/blackducksoftware/bdio/proto/impl/ProtobufBdioV2Writer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Black Duck Software Inc. 3 | * http://www.blackducksoftware.com/ 4 | * All rights reserved. 5 | * 6 | * This software is the confidential and proprietary information of 7 | * Black Duck Software ("Confidential Information"). You shall not 8 | * disclose such Confidential Information and shall use it only in 9 | * accordance with the terms of the license agreement you entered into 10 | * with Black Duck Software. 11 | */ 12 | package com.blackducksoftware.bdio.proto.impl; 13 | 14 | import java.io.IOException; 15 | import java.util.zip.ZipOutputStream; 16 | 17 | import com.blackducksoftware.bdio.proto.BdioConstants; 18 | import com.blackducksoftware.bdio.proto.api.IProtobufBdioValidator; 19 | import com.google.protobuf.Any; 20 | import com.google.protobuf.Message; 21 | 22 | /** 23 | * Implements methods to write version 2 bdio data 24 | * 25 | * @author sharapov 26 | * 27 | */ 28 | public class ProtobufBdioV2Writer extends AbstractProtobufBdioVersionWriter { 29 | 30 | public ProtobufBdioV2Writer(IProtobufBdioValidator validator) { 31 | super(validator); 32 | } 33 | 34 | @Override 35 | protected short getVersion() { 36 | return BdioConstants.VERSION_2; 37 | } 38 | 39 | @Override 40 | protected void writeHeaderNode(ZipOutputStream bdioArchive, Message header) throws IOException { 41 | Any any = Any.pack(header); 42 | any.writeTo(bdioArchive); 43 | } 44 | 45 | @Override 46 | public void writeDataNode(ZipOutputStream bdioArchive, Message node) throws IOException { 47 | Any any = Any.pack(node); 48 | any.writeDelimitedTo(bdioArchive); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /bdio-protobuf/src/main/proto/file_node_v1.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 Synopsys Inc. 3 | * http://www.synopsys.com/ 4 | * All rights reserved. 5 | * 6 | * This software is the confidential and proprietary information of 7 | * Synopsys ("Confidential Information"). You shall not 8 | * disclose such Confidential Information and shall use it only in 9 | * accordance with the terms of the license agreement you entered into 10 | * with Synopsys. 11 | */ 12 | syntax = "proto3"; 13 | 14 | package bdio.v1; 15 | 16 | option java_multiple_files = true; 17 | option java_package = "com.blackducksoftware.bdio.proto.domain"; 18 | option java_outer_classname = "FileNodeProto"; 19 | 20 | /** 21 | * See here for guidelines on avoiding breaking changes to message formats: https://developers.google.com/protocol-buffers/docs/proto#updating 22 | * If those are not possible, or the message is sufficiently different, a new version should be created. 23 | */ 24 | message ProtoFileNode { 25 | 26 | // The numeric ID of this file node. 27 | int64 id = 1; 28 | 29 | // The full URI of this file. 30 | // Example: file:///Users/hjoe/dev/bdio/bdio-reactor/src/test/java/com/blackducksoftware/bdio2 31 | string uri = 2; 32 | 33 | // The path to this file relative to the root node of this scan. 34 | // Example: bdio-reactor/src/test/java/com/blackducksoftware/bdio2/ 35 | string path = 3; 36 | 37 | // The name of this file/directory/archive. 38 | // Example: bdio2 39 | string name = 4; 40 | 41 | // The size of this file in bytes. 42 | int64 size = 5; 43 | 44 | // The file system type of this node. 45 | // See com.blackducksoftware.scan.api.NodeType for possible values. 46 | string file_system_type = 6; 47 | 48 | // The ID of this node's parent. Root node does not have parent, but in this case parent id is set to -1 49 | int64 parent_id = 7; 50 | 51 | // The path of archive that this file is contained in, if any. Archive context is not set for file nodes 52 | // that are present outside the context of any archive 53 | // Example: gradle/wrapper/gradle-wrapper.jar!/ 54 | optional string archive_context = 8; 55 | 56 | // The number of directories that are immediate children of this node. This is not set for usual files, 57 | // since they don't have any children. 58 | optional int64 shallow_directory_count = 9; 59 | 60 | // The number of all directories that are descendents of this node. This is not set for usual files, 61 | // since they don't have any children. 62 | optional int64 deep_directory_count = 10; 63 | 64 | // The number of all files that are descendents of this node. This is not set for usual files, 65 | // since they don't have any children. 66 | optional int64 deep_file_count = 11; 67 | 68 | // The distance from the root node of this scan 69 | optional int64 distance_from_root = 12; 70 | 71 | // The distance from the inner root 72 | optional int64 distance_from_inner_root = 13; 73 | 74 | // A map of signature type to signature value for all signatures generated for this node. 75 | // Signature type key must be in the interval [0,6] (inclusive), with the following meaning: 76 | // 0 - sha1 signature 77 | // 1 - clean sha1 signature 78 | // 2 - deep with size signature 79 | // 3 - deep no size signature 80 | // 4 - structure only signature 81 | // 5 - shallow with size 82 | // 6 - shallow no size 83 | map signatures = 14; 84 | } 85 | -------------------------------------------------------------------------------- /bdio-protobuf/src/test/resources/scan_data/dummy.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blackducksoftware/bdio/cb631d8b49b992d9ad73a9d3e5262d8c7b789901/bdio-protobuf/src/test/resources/scan_data/dummy.txt -------------------------------------------------------------------------------- /bdio-reactor/build.gradle: -------------------------------------------------------------------------------- 1 | description = 'Black Duck I/O for Project Reactor' 2 | 3 | dependencyRecommendations { 4 | mavenBom module: 'io.projectreactor:reactor-bom:Bismuth-SR8' 5 | } 6 | 7 | dependencies { 8 | compile project(':bdio2') 9 | compile 'com.blackducksoftware.magpie:magpie' 10 | compile 'com.github.jsonld-java:jsonld-java' 11 | compile 'com.google.code.findbugs:jsr305' 12 | compile 'com.google.guava:guava' 13 | compile 'io.projectreactor:reactor-core' 14 | compile 'org.reactivestreams:reactive-streams' 15 | 16 | testCompile project(':bdio-test') 17 | testCompile 'com.google.truth:truth' 18 | testCompile 'junit:junit' 19 | } 20 | -------------------------------------------------------------------------------- /bdio-reactor/src/main/java/com/blackducksoftware/bdio2/reactor/ReactorBdioDocument.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.reactor; 17 | 18 | import java.io.InputStream; 19 | 20 | import org.reactivestreams.Publisher; 21 | import org.reactivestreams.Subscriber; 22 | 23 | import com.blackducksoftware.bdio2.BdioContext; 24 | import com.blackducksoftware.bdio2.BdioDocument; 25 | import com.blackducksoftware.bdio2.BdioMetadata; 26 | import com.blackducksoftware.bdio2.BdioSubscriber; 27 | import com.blackducksoftware.bdio2.BdioWriter.StreamSupplier; 28 | import com.blackducksoftware.bdio2.Emitter; 29 | import com.blackducksoftware.bdio2.EmitterFactory; 30 | 31 | import reactor.core.publisher.EmitterProcessor; 32 | import reactor.core.publisher.Flux; 33 | 34 | /** 35 | * Project Reactor implementation of the BDIO document API. 36 | * 37 | * @author jgustie 38 | */ 39 | public class ReactorBdioDocument extends BdioDocument { 40 | 41 | public ReactorBdioDocument(BdioContext context) { 42 | super(context); 43 | } 44 | 45 | @Override 46 | public Flux read(InputStream in) { 47 | return Flux.generate( 48 | () -> EmitterFactory.newEmitter(context(), in), 49 | (parser, emitter) -> { 50 | parser.emit(emitter::next, emitter::error, emitter::complete); 51 | return parser; 52 | }, 53 | Emitter::dispose); 54 | } 55 | 56 | @Override 57 | public Subscriber write(BdioMetadata metadata, StreamSupplier entryStreams) { 58 | EmitterProcessor data = EmitterProcessor.create(); 59 | 60 | jsonLd(data) 61 | .expand() 62 | .flatMapIterable(BdioDocument::toGraphNodes) 63 | .subscribe(new BdioSubscriber(metadata, entryStreams, t -> {})); // TODO Generic error handler? 64 | 65 | return data; 66 | } 67 | 68 | @Override 69 | public ReactorJsonLdProcessing jsonLd(Publisher inputs) { 70 | return new ReactorJsonLdProcessing(Flux.from(inputs), context().jsonLdOptions()); 71 | } 72 | 73 | @Override 74 | public Flux metadata(Publisher inputs) { 75 | return jsonLd(Flux.from(inputs).map(BdioDocument::toMetadata)) 76 | .expand().flatMapIterable(BdioDocument::unfoldExpand) 77 | .onErrorResume(t -> Flux.just(new BdioMetadata(t))) 78 | .reduce(new BdioMetadata(), BdioMetadata::merge) 79 | .flux(); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /bdio-reactor/src/main/java/com/blackducksoftware/bdio2/reactor/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | package com.blackducksoftware.bdio2.reactor; 3 | 4 | import javax.annotation.ParametersAreNonnullByDefault; 5 | -------------------------------------------------------------------------------- /bdio-reactor/src/test/java/com/blackducksoftware/bdio2/reactor/BdioDocumentFromModelTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.reactor; 17 | 18 | import static com.blackducksoftware.common.test.JsonSubject.assertThatJson; 19 | import static com.google.common.truth.Truth.assertThat; 20 | 21 | import java.util.List; 22 | 23 | import org.junit.Test; 24 | 25 | import com.blackducksoftware.bdio2.BdioContext; 26 | import com.blackducksoftware.bdio2.BdioMetadata; 27 | import com.blackducksoftware.bdio2.BdioWriter; 28 | import com.blackducksoftware.bdio2.model.File; 29 | import com.blackducksoftware.bdio2.test.BdioTest; 30 | import com.blackducksoftware.common.io.HeapOutputStream; 31 | 32 | import reactor.core.publisher.Flux; 33 | 34 | /** 35 | * Tests verifying we can generate BDIO documents from model objects. 36 | * 37 | * @author jgustie 38 | */ 39 | public class BdioDocumentFromModelTest { 40 | 41 | @Test 42 | public void singleNode() { 43 | BdioMetadata metadata = BdioMetadata.createRandomUUID(); 44 | HeapOutputStream out = new HeapOutputStream(); 45 | ReactorBdioDocument doc = new ReactorBdioDocument(new BdioContext.Builder().build()); 46 | 47 | Flux.just(new File("http://example.com/files/1")) 48 | .buffer(1) 49 | .subscribe(doc.write(metadata, new BdioWriter.BdioFile(out))); 50 | 51 | List entries = BdioTest.zipEntries(out.getInputStream()); 52 | assertThat(entries).hasSize(2); 53 | assertThatJson(entries.get(1)).at("/@graph/0/@id").isEqualTo("http://example.com/files/1"); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /bdio-rxjava/build.gradle: -------------------------------------------------------------------------------- 1 | description = 'Black Duck I/O for RxJava2' 2 | 3 | dependencies { 4 | compile project(':bdio2') 5 | compile 'com.blackducksoftware.magpie:magpie' 6 | compile 'com.github.jsonld-java:jsonld-java' 7 | compile 'com.google.code.findbugs:jsr305' 8 | compile 'com.google.guava:guava' 9 | compile 'io.reactivex.rxjava3:rxjava' 10 | compile 'org.reactivestreams:reactive-streams' 11 | 12 | testCompile project(':bdio-test') 13 | testCompile 'com.google.truth:truth' 14 | testCompile 'junit:junit' 15 | } 16 | -------------------------------------------------------------------------------- /bdio-rxjava/src/main/java/com/blackducksoftware/bdio2/rxjava/RxJavaBdioDocument.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.rxjava; 17 | 18 | import java.io.InputStream; 19 | 20 | import org.reactivestreams.Publisher; 21 | import org.reactivestreams.Subscriber; 22 | 23 | import com.blackducksoftware.bdio2.BdioContext; 24 | import com.blackducksoftware.bdio2.BdioDocument; 25 | import com.blackducksoftware.bdio2.BdioMetadata; 26 | import com.blackducksoftware.bdio2.BdioSubscriber; 27 | import com.blackducksoftware.bdio2.BdioWriter.StreamSupplier; 28 | import com.blackducksoftware.bdio2.Emitter; 29 | import com.blackducksoftware.bdio2.EmitterFactory; 30 | 31 | import io.reactivex.rxjava3.core.Flowable; 32 | import io.reactivex.rxjava3.plugins.RxJavaPlugins; 33 | import io.reactivex.rxjava3.processors.PublishProcessor; 34 | 35 | /** 36 | * RxJava implementation of the BDIO document API. 37 | * 38 | * @author jgustie 39 | */ 40 | public class RxJavaBdioDocument extends BdioDocument { 41 | 42 | public RxJavaBdioDocument(BdioContext context) { 43 | super(context); 44 | } 45 | 46 | @Override 47 | public Flowable read(InputStream in) { 48 | return Flowable.generate( 49 | () -> EmitterFactory.newEmitter(context(), in), 50 | (parser, emitter) -> { 51 | parser.emit(emitter::onNext, emitter::onError, emitter::onComplete); 52 | }, 53 | Emitter::dispose); 54 | } 55 | 56 | @Override 57 | public Subscriber write(BdioMetadata metadata, StreamSupplier entryStreams) { 58 | PublishProcessor data = PublishProcessor.create(); 59 | 60 | jsonLd(data) 61 | .expand() 62 | .flatMapIterable(BdioDocument::toGraphNodes) 63 | .subscribe(new BdioSubscriber(metadata, entryStreams, RxJavaPlugins::onError)); 64 | 65 | // TODO How can we use FlowableHide.HideSubscriber? 66 | return data; 67 | } 68 | 69 | @Override 70 | public RxJavaJsonLdProcessing jsonLd(Publisher inputs) { 71 | return new RxJavaJsonLdProcessing(Flowable.fromPublisher(inputs), context().jsonLdOptions()); 72 | } 73 | 74 | @Override 75 | public Flowable metadata(Publisher inputs) { 76 | return jsonLd(Flowable.fromPublisher(inputs).map(BdioDocument::toMetadata)) 77 | .expand().flatMapIterable(BdioDocument::unfoldExpand) 78 | .onErrorReturn((throwable) -> { 79 | throw new RuntimeException("Parsing failed with error", throwable); 80 | }) 81 | .reduce(new BdioMetadata(), BdioMetadata::merge) 82 | .toFlowable(); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /bdio-rxjava/src/main/java/com/blackducksoftware/bdio2/rxjava/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | package com.blackducksoftware.bdio2.rxjava; 3 | 4 | import javax.annotation.ParametersAreNonnullByDefault; -------------------------------------------------------------------------------- /bdio-test/build.gradle: -------------------------------------------------------------------------------- 1 | description = 'Black Duck I/O Test' 2 | 3 | dependencies { 4 | compile 'com.blackducksoftware.magpie:magpie' 5 | compile 'com.blackducksoftware.magpie:magpie-test' 6 | compile 'com.google.code.findbugs:jsr305' 7 | compile 'com.google.guava:guava' 8 | compile 'org.apache.tinkerpop:gremlin-core' 9 | compile 'org.slf4j:slf4j-simple' 10 | } 11 | -------------------------------------------------------------------------------- /bdio-test/src/test/java/com/blackducksoftware/bdio2/test/BdioTestTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.test; 17 | 18 | import org.junit.Test; 19 | 20 | public class BdioTestTest { 21 | 22 | // Right now, this is just here to make Jacoco not freak out. 23 | 24 | @Test 25 | public void doNothing() { 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /bdio-tinkerpop-db/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM postgres:9.6-alpine 2 | 3 | ENV POSTGRES_DB="bdio" \ 4 | POSTGRES_USER="bdio" \ 5 | POSTGRES_INITDB_ARGS="--no-locale" \ 6 | PAGER="" 7 | -------------------------------------------------------------------------------- /bdio-tinkerpop/build.gradle: -------------------------------------------------------------------------------- 1 | description = 'Black Duck I/O for TinkerPop' 2 | 3 | dependencies { 4 | compile project(':bdio-rxjava') 5 | compile 'com.blackducksoftware.magpie:magpie' 6 | compile 'org.apache.tinkerpop:gremlin-core' 7 | compile 'org.flywaydb:flyway-core' 8 | compile 'org.umlg:sqlg-postgres' 9 | 10 | testCompile project(':bdio-test') 11 | testCompile 'com.google.truth:truth' 12 | testCompile 'com.google.truth.extensions:truth-java8-extension' 13 | testCompile 'junit:junit' 14 | testCompile 'org.apache.tinkerpop:tinkergraph-gremlin' 15 | } 16 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/main/java/com/blackducksoftware/bdio2/tinkerpop/BlackDuckIoNormalization.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Synopsys, Inc. 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 com.blackducksoftware.bdio2.tinkerpop; 17 | 18 | import static java.util.Collections.emptyList; 19 | 20 | import java.util.List; 21 | import java.util.Objects; 22 | 23 | import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy; 24 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; 25 | import org.apache.tinkerpop.gremlin.structure.Graph; 26 | import org.apache.tinkerpop.gremlin.structure.io.Mapper; 27 | 28 | import com.blackducksoftware.bdio2.BdioFrame; 29 | import com.blackducksoftware.bdio2.tinkerpop.spi.BlackDuckIoNormalizationSpi; 30 | import com.blackducksoftware.bdio2.tinkerpop.spi.BlackDuckIoSpi; 31 | 32 | public class BlackDuckIoNormalization { 33 | 34 | private final BlackDuckIoOptions options; 35 | 36 | private final BdioFrame frame; 37 | 38 | private BlackDuckIoNormalization(Builder builder) { 39 | options = Objects.requireNonNull(builder.options); 40 | frame = builder.mapper.createMapper(); 41 | } 42 | 43 | public void normalize(List> strategies, Graph graph) { 44 | GraphTraversalSource g = graph.traversal().withStrategies(strategies.toArray(new TraversalStrategy[strategies.size()])); 45 | BlackDuckIoNormalizationSpi spi = BlackDuckIoSpi.getForGraph(graph).normalization(g, options, frame); 46 | 47 | spi.identifyRoot(); 48 | spi.addMissingFileParents(); 49 | spi.addMissingProjectDependencies(); 50 | spi.implyFileSystemTypes(); 51 | } 52 | 53 | public void normalize(Graph graph) { 54 | normalize(emptyList(), graph); 55 | } 56 | 57 | public static Builder build() { 58 | return new Builder(); 59 | } 60 | 61 | public static class Builder { 62 | 63 | private Mapper mapper; 64 | 65 | private BlackDuckIoOptions options; 66 | 67 | private Builder() { 68 | mapper = BlackDuckIoMapper.build().create(); 69 | options = BlackDuckIoOptions.build().create(); 70 | } 71 | 72 | public Builder mapper(Mapper mapper) { 73 | this.mapper = Objects.requireNonNull(mapper); 74 | return this; 75 | } 76 | 77 | public Builder options(BlackDuckIoOptions options) { 78 | this.options = Objects.requireNonNull(options); 79 | return this; 80 | } 81 | 82 | public BlackDuckIoNormalization create() { 83 | return new BlackDuckIoNormalization(this); 84 | } 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/main/java/com/blackducksoftware/bdio2/tinkerpop/BlackDuckIoReadGraphException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Synopsys, Inc. 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 com.blackducksoftware.bdio2.tinkerpop; 17 | 18 | import java.io.IOException; 19 | 20 | /** 21 | * Thrown to indicate a checked exception occurred while reading a graph. 22 | * 23 | * @author jgustie 24 | */ 25 | public class BlackDuckIoReadGraphException extends IOException { 26 | 27 | private static final long serialVersionUID = 2630216768362522709L; 28 | 29 | public BlackDuckIoReadGraphException(String message, Throwable cause) { 30 | super(message, cause); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/main/java/com/blackducksoftware/bdio2/tinkerpop/BlackDuckIoVersion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Synopsys, Inc. 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 com.blackducksoftware.bdio2.tinkerpop; 17 | 18 | import com.blackducksoftware.bdio2.Bdio; 19 | 20 | /** 21 | * Available versions of BDIO. Note that the version is can only be used to control reading into the graph, the default 22 | * version is always used for writing. 23 | * 24 | * @author jgustie 25 | */ 26 | public enum BlackDuckIoVersion { 27 | V1_0, 28 | V1_1, 29 | V1_1_1, 30 | V2_0, 31 | V2_1 32 | ; 33 | 34 | /** 35 | * Returns the explicit JSON-LD expansion context required for this version, or empty no such context exists. 36 | */ 37 | Object expandContext() { 38 | switch (this) { 39 | case V1_0: 40 | return Bdio.Context.VERSION_1_0; 41 | case V1_1: 42 | return Bdio.Context.VERSION_1_1; 43 | case V1_1_1: 44 | return Bdio.Context.VERSION_1_1_1; 45 | case V2_0: 46 | return Bdio.Context.VERSION_2_0; 47 | case V2_1: 48 | // This is the version returned by "defaultVersion()" so it should actually return DEFAULT 49 | return Bdio.Context.DEFAULT; 50 | default: 51 | throw new IllegalStateException("unknown version: " + this); 52 | } 53 | } 54 | 55 | /** 56 | * Returns the current default version to use when an explicit version number is not provided. 57 | */ 58 | static BlackDuckIoVersion defaultVersion() { 59 | return V2_1; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/main/java/com/blackducksoftware/bdio2/tinkerpop/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | package com.blackducksoftware.bdio2.tinkerpop; 3 | 4 | import javax.annotation.ParametersAreNonnullByDefault; -------------------------------------------------------------------------------- /bdio-tinkerpop/src/main/java/com/blackducksoftware/bdio2/tinkerpop/spi/AbstractBlackDuckIoSpi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Synopsys, Inc. 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 com.blackducksoftware.bdio2.tinkerpop.spi; 17 | 18 | import java.util.Objects; 19 | import java.util.function.BiConsumer; 20 | 21 | import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy; 22 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; 23 | import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.PartitionStrategy; 24 | import org.apache.tinkerpop.gremlin.structure.Graph; 25 | 26 | import com.blackducksoftware.bdio2.BdioFrame; 27 | import com.blackducksoftware.bdio2.tinkerpop.BlackDuckIoOptions; 28 | import com.blackducksoftware.bdio2.tinkerpop.strategy.PropertyConstantStrategy; 29 | 30 | public abstract class AbstractBlackDuckIoSpi { 31 | 32 | private final GraphTraversalSource traversal; 33 | 34 | private final BlackDuckIoOptions options; 35 | 36 | private final BdioFrame frame; 37 | 38 | protected AbstractBlackDuckIoSpi(GraphTraversalSource traversal, BlackDuckIoOptions options, BdioFrame frame) { 39 | this.traversal = Objects.requireNonNull(traversal); 40 | this.options = Objects.requireNonNull(options); 41 | this.frame = Objects.requireNonNull(frame); 42 | } 43 | 44 | protected final GraphTraversalSource traversal() { 45 | return traversal; 46 | } 47 | 48 | protected final BlackDuckIoOptions options() { 49 | return options; 50 | } 51 | 52 | protected final BdioFrame frame() { 53 | return frame; 54 | } 55 | 56 | protected Graph graph() { 57 | return traversal.getGraph(); 58 | } 59 | 60 | protected void getTraversalProperties(BiConsumer properties, boolean includeConstants) { 61 | for (TraversalStrategy strategy : traversal.getStrategies().toList()) { 62 | if (strategy instanceof PartitionStrategy && ((PartitionStrategy) strategy).getWritePartition() != null) { 63 | properties.accept(((PartitionStrategy) strategy).getPartitionKey(), ((PartitionStrategy) strategy).getWritePartition()); 64 | } else if (strategy instanceof PropertyConstantStrategy) { 65 | ((PropertyConstantStrategy) strategy).getPropertyMap().forEach(properties); 66 | } 67 | } 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/main/java/com/blackducksoftware/bdio2/tinkerpop/spi/DefaultBlackDuckIo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Synopsys, Inc. 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 com.blackducksoftware.bdio2.tinkerpop.spi; 17 | 18 | final class DefaultBlackDuckIo extends BlackDuckIoSpi { 19 | 20 | private static final DefaultBlackDuckIo INSTANCE = new DefaultBlackDuckIo(); 21 | 22 | public static DefaultBlackDuckIo getInstance() { 23 | return INSTANCE; 24 | } 25 | 26 | private DefaultBlackDuckIo() { 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/main/java/com/blackducksoftware/bdio2/tinkerpop/spi/DefaultBlackDuckIoNormalization.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Synopsys, Inc. 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 com.blackducksoftware.bdio2.tinkerpop.spi; 17 | 18 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; 19 | 20 | import com.blackducksoftware.bdio2.BdioFrame; 21 | import com.blackducksoftware.bdio2.tinkerpop.BlackDuckIoOptions; 22 | 23 | final class DefaultBlackDuckIoNormalization extends BlackDuckIoNormalizationSpi { 24 | 25 | /** 26 | * Cached transaction support flag. 27 | */ 28 | private final boolean supportsTransactions; 29 | 30 | public DefaultBlackDuckIoNormalization(GraphTraversalSource traversal, BlackDuckIoOptions options, BdioFrame frame) { 31 | super(traversal, options, frame); 32 | this.supportsTransactions = graph().features().graph().supportsTransactions(); 33 | } 34 | 35 | @Override 36 | public void identifyRoot() { 37 | tx(() -> super.identifyRoot()); 38 | } 39 | 40 | @Override 41 | public void addMissingFileParents() { 42 | tx(() -> super.addMissingFileParents()); 43 | } 44 | 45 | @Override 46 | public void addMissingProjectDependencies() { 47 | tx(() -> super.addMissingProjectDependencies()); 48 | } 49 | 50 | @Override 51 | public void implyFileSystemTypes() { 52 | tx(() -> super.implyFileSystemTypes()); 53 | } 54 | 55 | private void tx(Runnable task) { 56 | if (supportsTransactions) { 57 | graph().tx().open(); 58 | try { 59 | task.run(); 60 | graph().tx().commit(); 61 | } catch (RuntimeException | Error e) { 62 | graph().tx().rollback(); 63 | throw e; 64 | } 65 | } else { 66 | task.run(); 67 | } 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/main/java/com/blackducksoftware/bdio2/tinkerpop/spi/DefaultBlackDuckIoWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Synopsys, Inc. 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 com.blackducksoftware.bdio2.tinkerpop.spi; 17 | 18 | import static org.apache.tinkerpop.gremlin.process.traversal.P.within; 19 | 20 | import java.util.LinkedHashMap; 21 | import java.util.Map; 22 | 23 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; 24 | import org.apache.tinkerpop.gremlin.structure.Direction; 25 | import org.apache.tinkerpop.gremlin.structure.Vertex; 26 | import org.reactivestreams.Publisher; 27 | 28 | import com.blackducksoftware.bdio2.BdioFrame; 29 | import com.blackducksoftware.bdio2.BdioMetadata; 30 | import com.blackducksoftware.bdio2.tinkerpop.BlackDuckIoOptions; 31 | 32 | import io.reactivex.rxjava3.core.Flowable; 33 | 34 | final class DefaultBlackDuckIoWriter extends BlackDuckIoWriterSpi { 35 | 36 | public DefaultBlackDuckIoWriter(GraphTraversalSource traversal, BlackDuckIoOptions options, BdioFrame frame) { 37 | super(traversal, options, frame); 38 | } 39 | 40 | @Override 41 | public BdioMetadata retrieveMetadata() { 42 | // TODO Make sure we don't leak a transaction! 43 | return super.retrieveMetadata(); 44 | } 45 | 46 | @Override 47 | public Publisher> retrieveCompactedNodes() { 48 | // TODO Make sure we don't leak a transaction! 49 | GraphTraversalSource g = traversal(); 50 | return Flowable.fromIterable(() -> g.V().hasLabel(within(includedLabels())).map(t -> convertVertexToNode(t.get()))); 51 | } 52 | 53 | /** 54 | * Creates a JSON-LD node from a vertex (or multiple vertices in the case of embedded objects). 55 | */ 56 | private Map convertVertexToNode(Vertex vertex) { 57 | Map result = new LinkedHashMap<>(); 58 | getVertexFields(vertex, result::put); 59 | vertex.edges(Direction.OUT).forEachRemaining(e -> getEdgeFields(e, this::convertVertexToNode, result::put)); 60 | return result; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/main/java/com/blackducksoftware/bdio2/tinkerpop/spi/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | package com.blackducksoftware.bdio2.tinkerpop.spi; 3 | 4 | import javax.annotation.ParametersAreNonnullByDefault; 5 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/main/java/com/blackducksoftware/bdio2/tinkerpop/sqlg/PostgresPlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Synopsys, Inc. 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 com.blackducksoftware.bdio2.tinkerpop.sqlg; 17 | 18 | import java.sql.Connection; 19 | 20 | import org.umlg.sqlg.sql.dialect.PostgresDialect; 21 | import org.umlg.sqlg.sql.dialect.SqlDialect; 22 | 23 | /** 24 | * A workaround for Sqlg #251 for versions prior to 2.0.0. 25 | *

26 | * Note that this workaround is at the mercy of the {@code ServiceLoader}; more specifically, in order for this to work, 27 | * the {@code META-INF/services/org.umlg.sqlg.SqlgPlugin} resource from this JAR must be found by the class loader 28 | * of the {@code SqlgGraph} class before the real resource in the Sqlg Postgres dialect JAR. 29 | * 30 | * @author jgustie 31 | */ 32 | public class PostgresPlugin extends org.umlg.sqlg.PostgresPlugin { 33 | @Override 34 | public SqlDialect instantiateDialect() { 35 | class PostgresDialect251 extends PostgresDialect { 36 | @Override 37 | public void prepareDB(Connection conn) { 38 | try { 39 | super.prepareDB(conn); 40 | } catch (Exception e) { 41 | // This is the behavior used in Sqlg 2.x 42 | } 43 | } 44 | } 45 | return new PostgresDialect251(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/main/java/com/blackducksoftware/bdio2/tinkerpop/sqlg/flyway/BaseSqlgMigration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Synopsys, Inc. 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 com.blackducksoftware.bdio2.tinkerpop.sqlg.flyway; 17 | 18 | import org.umlg.sqlg.structure.SqlgGraph; 19 | 20 | import com.blackducksoftware.bdio2.tinkerpop.sqlg.flyway.FlywayBackport.BaseJavaMigration; 21 | import com.blackducksoftware.bdio2.tinkerpop.sqlg.flyway.FlywayBackport.Context; 22 | 23 | /** 24 | * A base class for implementing Flyway migrations against a Sqlg graph. 25 | * 26 | * @author jgustie 27 | */ 28 | public abstract class BaseSqlgMigration extends BaseJavaMigration { 29 | 30 | @Override 31 | public final boolean canExecuteInTransaction() { 32 | // Need to rely on Sqlg transactions, not the Flyway managed transaction 33 | return false; 34 | } 35 | 36 | @Override 37 | public final void migrate(Context context) throws Exception { 38 | new SqlgFlywayExecutor(context.getConfiguration()).execute(this::migrate); 39 | } 40 | 41 | /** 42 | * Execute a migration within a transaction using the Sqlg graph. 43 | */ 44 | protected abstract void migrate(SqlgGraph sqlgGraph) throws Exception; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/main/java/com/blackducksoftware/bdio2/tinkerpop/sqlg/flyway/R__Create_aggregate_functions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Synopsys, Inc. 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 com.blackducksoftware.bdio2.tinkerpop.sqlg.flyway; 17 | 18 | import java.sql.Connection; 19 | import java.sql.Statement; 20 | 21 | import org.flywaydb.core.api.migration.jdbc.BaseJdbcMigration; 22 | 23 | /** 24 | * One of the optimizations groups rows by their "@id" value, then takes the first value from each group using custom 25 | * aggregate functions. This migration creates those functions. 26 | * 27 | * @author jgustie 28 | */ 29 | public class R__Create_aggregate_functions extends BaseJdbcMigration { 30 | 31 | @Override 32 | public void migrate(Connection connection) throws Exception { 33 | try (Statement statement = connection.createStatement()) { 34 | statement.executeUpdate("CREATE OR REPLACE FUNCTION public.first_agg ( anyelement, anyelement )" 35 | + "\nRETURNS anyelement LANGUAGE SQL IMMUTABLE STRICT AS $$" 36 | + "\n\tSELECT $1;" 37 | + "\n$$;"); 38 | statement.executeUpdate("DROP AGGREGATE IF EXISTS public.first ( anyelement );"); 39 | statement.executeUpdate("CREATE AGGREGATE public.first( sfunc = first_agg, stype = anyelement, basetype = anyelement );"); 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/main/java/com/blackducksoftware/bdio2/tinkerpop/sqlg/flyway/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | package com.blackducksoftware.bdio2.tinkerpop.sqlg.flyway; 3 | 4 | import javax.annotation.ParametersAreNonnullByDefault; 5 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/main/java/com/blackducksoftware/bdio2/tinkerpop/sqlg/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | package com.blackducksoftware.bdio2.tinkerpop.sqlg; 3 | 4 | import javax.annotation.ParametersAreNonnullByDefault; 5 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/main/java/com/blackducksoftware/bdio2/tinkerpop/sqlg/step/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | package com.blackducksoftware.bdio2.tinkerpop.sqlg.step; 3 | 4 | import javax.annotation.ParametersAreNonnullByDefault; 5 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/main/java/com/blackducksoftware/bdio2/tinkerpop/sqlg/strategy/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | package com.blackducksoftware.bdio2.tinkerpop.sqlg.strategy; 3 | 4 | import javax.annotation.ParametersAreNonnullByDefault; 5 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/main/java/com/blackducksoftware/bdio2/tinkerpop/strategy/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | package com.blackducksoftware.bdio2.tinkerpop.strategy; 3 | 4 | import javax.annotation.ParametersAreNonnullByDefault; 5 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/main/java/com/blackducksoftware/bdio2/tinkerpop/tinkergraph/TinkerGraphBlackDuckIo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Synopsys, Inc. 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 com.blackducksoftware.bdio2.tinkerpop.tinkergraph; 17 | 18 | import java.util.Collections; 19 | import java.util.Optional; 20 | import java.util.Set; 21 | 22 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; 23 | import org.apache.tinkerpop.gremlin.structure.Graph; 24 | import org.apache.tinkerpop.gremlin.structure.Vertex; 25 | 26 | import com.blackducksoftware.bdio2.Bdio; 27 | import com.blackducksoftware.bdio2.BdioFrame; 28 | import com.blackducksoftware.bdio2.tinkerpop.BlackDuckIoOptions; 29 | import com.blackducksoftware.bdio2.tinkerpop.spi.BlackDuckIoNormalizationSpi; 30 | import com.blackducksoftware.bdio2.tinkerpop.spi.BlackDuckIoReaderSpi; 31 | import com.blackducksoftware.bdio2.tinkerpop.spi.BlackDuckIoSpi; 32 | 33 | public class TinkerGraphBlackDuckIo extends BlackDuckIoSpi { 34 | 35 | private static final TinkerGraphBlackDuckIo INSTANCE = new TinkerGraphBlackDuckIo(); 36 | 37 | public static TinkerGraphBlackDuckIo getInstance() { 38 | return INSTANCE; 39 | } 40 | 41 | private TinkerGraphBlackDuckIo() { 42 | } 43 | 44 | @Override 45 | protected Optional providerReader(GraphTraversalSource traversal, BlackDuckIoOptions options, BdioFrame frame, int batchSize) { 46 | return Optional.of(new TinkerGraphBlackDuckIoReader(traversal, options, frame)); 47 | } 48 | 49 | @Override 50 | protected Optional providerNormalization(GraphTraversalSource traversal, BlackDuckIoOptions options, BdioFrame frame) { 51 | // Check if the path is indexed, if it is then we can optimize 52 | boolean isPathIndexed = frame.context() 53 | .lookupTerm(Bdio.DataProperty.path.toString()) 54 | .filter(getIndexedKeys(traversal.getGraph())::contains) 55 | .isPresent(); 56 | 57 | return isPathIndexed 58 | ? Optional.of(new TinkerGraphBlackDuckIoNormalization(traversal, options, frame)) 59 | : Optional.empty(); 60 | } 61 | 62 | /** 63 | * Reflective workaround for not being able to have a compile time dependency on the TinkerGraph. 64 | */ 65 | @SuppressWarnings("unchecked") 66 | private static Set getIndexedKeys(Graph graph) { 67 | try { 68 | return (Set) graph.getClass().getMethod("getIndexedKeys", Class.class).invoke(graph, Vertex.class); 69 | } catch (ReflectiveOperationException e) { 70 | return Collections.emptySet(); 71 | } 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/main/java/com/blackducksoftware/bdio2/tinkerpop/tinkergraph/TinkerGraphBlackDuckIoNormalization.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Synopsys, Inc. 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 com.blackducksoftware.bdio2.tinkerpop.tinkergraph; 17 | 18 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; 19 | 20 | import com.blackducksoftware.bdio2.Bdio; 21 | import com.blackducksoftware.bdio2.BdioFrame; 22 | import com.blackducksoftware.bdio2.tinkerpop.BlackDuckIoOptions; 23 | import com.blackducksoftware.bdio2.tinkerpop.spi.BlackDuckIoNormalizationSpi; 24 | 25 | /** 26 | * BDIO normalization implementation optimized for the TinkerGraph. 27 | * 28 | * @author jgustie 29 | */ 30 | final class TinkerGraphBlackDuckIoNormalization extends BlackDuckIoNormalizationSpi { 31 | 32 | public TinkerGraphBlackDuckIoNormalization(GraphTraversalSource traversal, BlackDuckIoOptions options, BdioFrame frame) { 33 | super(traversal, options, frame); 34 | } 35 | 36 | @Override 37 | protected void createParentEdges() { 38 | GraphTraversalSource g = traversal(); 39 | 40 | g.V().hasLabel(Bdio.Class.File.name()).has(options().fileParentKey().get()).as("child") 41 | . values(options().fileParentKey().get()) 42 | // The flat map here forces the use of the index on path 43 | .flatMap(t -> g.V().hasLabel(Bdio.Class.File.name()).has(Bdio.DataProperty.path.name(), t.get())) 44 | .addE(Bdio.ObjectProperty.parent.name()) 45 | .from("child") 46 | .iterate(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/main/java/com/blackducksoftware/bdio2/tinkerpop/tinkergraph/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | package com.blackducksoftware.bdio2.tinkerpop.tinkergraph; 3 | 4 | import javax.annotation.ParametersAreNonnullByDefault; 5 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/main/java/com/blackducksoftware/bdio2/tinkerpop/util/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | package com.blackducksoftware.bdio2.tinkerpop.util; 3 | 4 | import javax.annotation.ParametersAreNonnullByDefault; 5 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/main/resources/META-INF/services/org.umlg.sqlg.SqlgPlugin: -------------------------------------------------------------------------------- 1 | com.blackducksoftware.bdio2.tinkerpop.sqlg.PostgresPlugin 2 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/test/java/com/blackducksoftware/bdio2/tinkerpop/sqlg/SqlgCoreTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Synopsys, Inc. 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 com.blackducksoftware.bdio2.tinkerpop.sqlg; 17 | 18 | import org.junit.runner.RunWith; 19 | import org.junit.runners.Suite.SuiteClasses; 20 | 21 | import com.blackducksoftware.bdio2.test.GraphRunner; 22 | import com.blackducksoftware.bdio2.test.GraphRunner.GraphConfiguration; 23 | import com.blackducksoftware.bdio2.tinkerpop.BlackDuckIoNormalizationTest; 24 | import com.blackducksoftware.bdio2.tinkerpop.BlackDuckIoReaderTest; 25 | import com.blackducksoftware.bdio2.tinkerpop.BlackDuckIoWriterTest; 26 | 27 | /** 28 | * This test just runs the core group of tests with a different graph. 29 | * 30 | * @author jgustie 31 | */ 32 | @RunWith(GraphRunner.class) 33 | @GraphConfiguration("/sqlg.properties") 34 | @SuiteClasses({ 35 | BlackDuckIoNormalizationTest.class, 36 | BlackDuckIoReaderTest.class, 37 | BlackDuckIoWriterTest.class, 38 | }) 39 | public class SqlgCoreTests { 40 | } 41 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/test/java/com/blackducksoftware/bdio2/tinkerpop/strategy/PropertyConstantStrategyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Synopsys, Inc. 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 com.blackducksoftware.bdio2.tinkerpop.strategy; 17 | 18 | import static com.google.common.truth.Truth.assertThat; 19 | 20 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; 21 | import org.apache.tinkerpop.gremlin.structure.Graph; 22 | import org.apache.tinkerpop.gremlin.structure.VertexProperty; 23 | import org.junit.Test; 24 | 25 | import com.blackducksoftware.bdio2.test.GraphRunner.GraphConfiguration; 26 | import com.blackducksoftware.bdio2.tinkerpop.BaseTest; 27 | 28 | /** 29 | * Tests for {@code PropertyConstantStrategy} 30 | * 31 | * @author jgustie 32 | */ 33 | @GraphConfiguration("/tinkergraph-core.properties") 34 | @GraphConfiguration("/sqlg-core.properties") 35 | public class PropertyConstantStrategyTest extends BaseTest { 36 | 37 | public PropertyConstantStrategyTest(Graph graph) { 38 | super(graph); 39 | } 40 | 41 | @Test 42 | public void noProperty() { 43 | GraphTraversalSource g = graph.traversal().withStrategies(PropertyConstantStrategy.build().create()); 44 | VertexProperty a = g.addV().next().property("a"); 45 | assertThat(a.isPresent()).isFalse(); 46 | } 47 | 48 | @Test 49 | public void nullProperty() { 50 | GraphTraversalSource g = graph.traversal().withStrategies(PropertyConstantStrategy.build().addProperty("a", null).create()); 51 | VertexProperty a = g.addV().next().property("a"); 52 | assertThat(a.isPresent()).isFalse(); 53 | } 54 | 55 | @Test 56 | public void singleProperty() { 57 | GraphTraversalSource g = graph.traversal().withStrategies(PropertyConstantStrategy.build().addProperty("a", "AAA").create()); 58 | VertexProperty a = g.addV().next().property("a"); 59 | assertThat(a.isPresent()).isTrue(); 60 | assertThat(a.value()).isEqualTo("AAA"); 61 | } 62 | 63 | @Test 64 | public void twoProperties() { 65 | GraphTraversalSource g = graph.traversal().withStrategies(PropertyConstantStrategy.build().addProperty("a", "AAA").addProperty("b", "BBB").create()); 66 | VertexProperty a = g.addV().next().property("a"); 67 | VertexProperty b = g.addV().next().property("b"); 68 | assertThat(a.isPresent()).isTrue(); 69 | assertThat(a.value()).isEqualTo("AAA"); 70 | assertThat(b.isPresent()).isTrue(); 71 | assertThat(b.value()).isEqualTo("BBB"); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/test/java/com/blackducksoftware/bdio2/tinkerpop/tinkergraph/TinkerGraphCoreTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Synopsys, Inc. 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 com.blackducksoftware.bdio2.tinkerpop.tinkergraph; 17 | 18 | import org.junit.runner.RunWith; 19 | import org.junit.runners.Suite.SuiteClasses; 20 | 21 | import com.blackducksoftware.bdio2.test.GraphRunner; 22 | import com.blackducksoftware.bdio2.test.GraphRunner.GraphConfiguration; 23 | import com.blackducksoftware.bdio2.tinkerpop.BlackDuckIoNormalizationTest; 24 | import com.blackducksoftware.bdio2.tinkerpop.BlackDuckIoReaderTest; 25 | import com.blackducksoftware.bdio2.tinkerpop.BlackDuckIoWriterTest; 26 | 27 | /** 28 | * This test just runs the core group of tests with a different graph. 29 | * 30 | * @author jgustie 31 | */ 32 | @RunWith(GraphRunner.class) 33 | @GraphConfiguration("/tinkergraph.properties") 34 | @SuiteClasses({ 35 | BlackDuckIoNormalizationTest.class, 36 | BlackDuckIoReaderTest.class, 37 | BlackDuckIoWriterTest.class, 38 | }) 39 | public class TinkerGraphCoreTests { 40 | } 41 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/test/java/com/blackducksoftware/bdio2/tinkerpop/util/VertexPropertiesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.tinkerpop.util; 17 | 18 | import static com.google.common.truth.Truth8.assertThat; 19 | 20 | import org.apache.tinkerpop.gremlin.structure.VertexProperty; 21 | import org.apache.tinkerpop.gremlin.structure.util.star.StarGraph; 22 | import org.junit.Test; 23 | 24 | import com.blackducksoftware.bdio2.tinkerpop.util.VertexProperties; 25 | 26 | /** 27 | * Tests for {@code GraphMapper}. 28 | * 29 | * @author jgustie 30 | */ 31 | public class VertexPropertiesTest { 32 | 33 | @Test 34 | public void streamVertexPropertyStringArray() { 35 | VertexProperty vp = StarGraph.open().addVertex("test").property("test", new String[] { "foo", "bar" }); 36 | assertThat(VertexProperties.streamValue(vp)).containsExactly("foo", "bar"); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/test/resources/sqlg-core.properties: -------------------------------------------------------------------------------- 1 | gremlin.graph=org.umlg.sqlg.structure.SqlgGraph 2 | jdbc.url=jdbc:postgresql://localhost:5432/bdio 3 | jdbc.username=bdio 4 | jdbc.password= 5 | jdbc.acquireRetryAttempts=1 6 | cache.vertices=true 7 | bdio.allowProviderImplementation=false 8 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/test/resources/sqlg.properties: -------------------------------------------------------------------------------- 1 | gremlin.graph=org.umlg.sqlg.structure.SqlgGraph 2 | jdbc.url=jdbc:postgresql://localhost:5432/bdio 3 | jdbc.username=bdio 4 | jdbc.password= 5 | jdbc.acquireRetryAttempts=1 6 | cache.vertices=true 7 | -------------------------------------------------------------------------------- /bdio-tinkerpop/src/test/resources/tinkergraph-core.properties: -------------------------------------------------------------------------------- 1 | gremlin.graph=org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph 2 | bdio.allowProviderImplementation=false -------------------------------------------------------------------------------- /bdio-tinkerpop/src/test/resources/tinkergraph.properties: -------------------------------------------------------------------------------- 1 | gremlin.graph=org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph 2 | -------------------------------------------------------------------------------- /bdio-tool/build.gradle: -------------------------------------------------------------------------------- 1 | description = 'Black Duck I/O Tooling' 2 | 3 | import org.gradle.plugins.ide.eclipse.model.AccessRule 4 | apply plugin: 'application' 5 | 6 | applicationName = 'bdio' 7 | mainClassName = 'com.blackducksoftware.bdio2.tool.BdioMain' 8 | 9 | dependencies { 10 | compile project(':bdio-tinkerpop') 11 | compile 'com.squareup.okhttp3:okhttp' 12 | compile 'org.apache.tinkerpop:tinkergraph-gremlin' 13 | compile 'org.slf4j:slf4j-nop' 14 | compile 'javax.activation:javax.activation-api' 15 | 16 | testCompile 'junit:junit' 17 | } 18 | 19 | jar { 20 | from("${rootDir}/docs/spec") { 21 | include '0*' 22 | include 'A*' 23 | into 'com/blackducksoftware/bdio2/tool/spec' 24 | } 25 | } 26 | 27 | // Pre-Gradle 4.9, see https://stackoverflow.com/a/29382636/481015 28 | run { 29 | if (project.hasProperty('appArgs')) { 30 | args Eval.me(appArgs) 31 | } 32 | } 33 | 34 | distributions { 35 | main { 36 | contents { 37 | from("${rootDir}/LICENSE", "${rootDir}/NOTICE") 38 | } 39 | } 40 | } 41 | 42 | eclipse { 43 | classpath { 44 | file { 45 | whenMerged { 46 | def jre = entries.find { it.path.contains 'org.eclipse.jdt.launching.JRE_CONTAINER' } 47 | jre.accessRules.add(new AccessRule('0', 'com/sun/net/httpserver/**')) 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /bdio-tool/src/main/java/com/blackducksoftware/bdio2/tool/SpecificationTool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.tool; 17 | 18 | import static java.nio.charset.StandardCharsets.UTF_8; 19 | 20 | import java.io.IOException; 21 | import java.io.UncheckedIOException; 22 | import java.util.ArrayDeque; 23 | import java.util.Deque; 24 | import java.util.stream.Collectors; 25 | 26 | import com.google.common.collect.ImmutableList; 27 | import com.google.common.io.Resources; 28 | 29 | /** 30 | * Outputs the BDIO specification. 31 | * 32 | * @author jgustie 33 | */ 34 | public class SpecificationTool extends Tool { 35 | 36 | // TODO How do we generate this list dynamically? 37 | private static ImmutableList SECTIONS = ImmutableList. builder() 38 | .add("00.Abstract.txt") 39 | .add("01.Introduction.txt") 40 | .add("02.Model.txt") 41 | .add("03.SemanticRules.txt") 42 | .add("04.DocumentFormat.txt") 43 | .add("AA.NamespaceRecommendations.txt") 44 | .add("AB.IdentifierGuidelines.txt") 45 | .add("AC.FileData.txt") 46 | .add("AD.ContentTypes.txt") 47 | .build(); 48 | 49 | public static void main(String[] args) { 50 | new SpecificationTool(null).parseArgs(args).run(); 51 | } 52 | 53 | // TODO Multiple version support (e.g. old wiki content?) 54 | // TODO How can we generate the specification using Javadoc comments? 55 | // TODO Generate a TOC between sections 00 and 01? 56 | // TODO Can we have a separate "sample" tool that generates the sample output? 57 | // TODO Offer an HTML output version that formats the Markdown 58 | 59 | public SpecificationTool(String name) { 60 | super(name); 61 | } 62 | 63 | @Override 64 | protected void execute() throws Exception { 65 | Deque references = new ArrayDeque<>(); 66 | SECTIONS.stream().sorted().map(resourceName -> { 67 | String section = loadResource(resourceName); 68 | 69 | int start = section.lastIndexOf("\n["); 70 | while (start >= 0) { 71 | references.push(section.substring(start + 1)); 72 | section = section.substring(0, start); 73 | start = section.lastIndexOf("\n["); 74 | } 75 | 76 | return section; 77 | }).forEachOrdered(section -> printOutput("%s%n", section)); 78 | 79 | printOutput("%s", references.stream().collect(Collectors.joining(System.lineSeparator(), System.lineSeparator(), ""))); 80 | } 81 | 82 | private static String loadResource(String resourceName) { 83 | try { 84 | return Resources.toString(Resources.getResource(SpecificationTool.class, "spec/" + resourceName), UTF_8); 85 | } catch (IOException e) { 86 | throw new UncheckedIOException(e); 87 | } 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /bdio-tool/src/main/java/com/blackducksoftware/bdio2/tool/TreeFormat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.tool; 17 | 18 | import java.util.function.IntPredicate; 19 | 20 | /** 21 | * Utilities for helping format trees. 22 | * 23 | * @author jgustie 24 | */ 25 | final class TreeFormat { 26 | 27 | /** 28 | * Appends an ASCII indentation prefix to the supplied line. 29 | * 30 | * @param buffer 31 | * the buffer to append to 32 | * @param depth 33 | * the depth (distance from the root) of the node 34 | * @param childrenAtDepths 35 | * a set indicating which ancestors have outstanding lineage 36 | * @param hasMoreSiblings 37 | * flag indicating if this is the last sibling 38 | */ 39 | public static void appendAsciiIndent(StringBuilder buffer, int depth, IntPredicate childrenAtDepths, boolean hasMoreSiblings) { 40 | if (depth > 0) { 41 | for (int i = 0; i < depth - 1; ++i) { 42 | if (childrenAtDepths.test(i)) { 43 | buffer.append('|'); 44 | } else { 45 | buffer.append(' '); 46 | } 47 | buffer.append(" "); 48 | } 49 | buffer.append(hasMoreSiblings ? '|' : '`').append("-- "); 50 | } 51 | } 52 | 53 | private TreeFormat() { 54 | assert false; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /bdio-tool/src/main/java/com/blackducksoftware/bdio2/tool/linter/DataPropertyRange.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.tool.linter; 17 | 18 | import java.nio.charset.Charset; 19 | import java.util.Collection; 20 | import java.util.Collections; 21 | import java.util.Map; 22 | import java.util.stream.Stream; 23 | 24 | import com.blackducksoftware.bdio2.Bdio; 25 | import com.blackducksoftware.bdio2.Bdio.FileSystemType; 26 | import com.blackducksoftware.bdio2.BdioContext; 27 | import com.blackducksoftware.bdio2.tool.linter.Linter.RawNodeRule; 28 | import com.blackducksoftware.bdio2.tool.linter.Linter.Violation; 29 | import com.blackducksoftware.bdio2.tool.linter.Linter.ViolationBuilder; 30 | import com.blackducksoftware.common.value.HID; 31 | 32 | public class DataPropertyRange implements RawNodeRule { 33 | 34 | @Override 35 | public Stream validate(Map input) { 36 | ViolationBuilder result = new ViolationBuilder(this, input); 37 | 38 | BdioContext context = BdioContext.getDefault(); 39 | for (Bdio.DataProperty dataProperty : Bdio.DataProperty.values()) { 40 | String key = dataProperty.toString(); 41 | try { 42 | // Use the value object mapper to validate data properties 43 | Object rawValue = context.fromFieldValue(key, input.get(key)); 44 | 45 | Collection values; 46 | if (rawValue instanceof Collection) { 47 | values = (Collection) rawValue; 48 | } else if (rawValue != null) { 49 | values = Collections.singleton(rawValue); 50 | } else { 51 | values = Collections.emptyList(); 52 | } 53 | 54 | // TODO How do we detect invalid reference or embedded objects? 55 | 56 | // Check other fields which may have more restrictive rules 57 | for (Object value : values) { 58 | if (key.equals(Bdio.DataProperty.fileSystemType.toString())) { 59 | FileSystemType.from(value); 60 | } else if (key.equals(Bdio.DataProperty.path.toString()) 61 | || key.equals(Bdio.DataProperty.linkPath.toString())) { 62 | HID.from(value); 63 | } else if (key.equals(Bdio.DataProperty.encoding.toString())) { 64 | if (value instanceof String && !Charset.isSupported((String) value)) { 65 | result.warning("UnsupportedCharset"); 66 | } 67 | } 68 | } 69 | } catch (Exception e) { 70 | result.error("Invalid", e, key, input.get(key)); 71 | } 72 | } 73 | 74 | // TODO Can we detect object properties used as data properties (e.g. "description") 75 | 76 | return result.build(); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /bdio-tool/src/main/java/com/blackducksoftware/bdio2/tool/linter/Domain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.tool.linter; 17 | 18 | import java.util.Map; 19 | import java.util.stream.Stream; 20 | 21 | import com.blackducksoftware.bdio2.Bdio; 22 | import com.blackducksoftware.bdio2.tool.linter.Linter.RawNodeRule; 23 | import com.blackducksoftware.bdio2.tool.linter.Linter.Violation; 24 | import com.blackducksoftware.bdio2.tool.linter.Linter.ViolationBuilder; 25 | import com.google.common.base.Enums; 26 | import com.google.common.collect.ImmutableMultimap; 27 | import com.google.common.collect.ImmutableSet; 28 | import com.google.common.collect.ImmutableSetMultimap; 29 | 30 | public class Domain implements RawNodeRule { 31 | 32 | private final ImmutableSet knownProperties; 33 | 34 | private final ImmutableMultimap allowedProperties; 35 | 36 | public Domain() { 37 | // Build a map of type strings to property keys 38 | ImmutableSet.Builder known = ImmutableSet.builder(); 39 | ImmutableSetMultimap.Builder allowed = ImmutableSetMultimap.builder(); 40 | for (Bdio.ObjectProperty objectProperty : Bdio.ObjectProperty.values()) { 41 | known.add(objectProperty.toString()); 42 | for (Bdio.Class domain : Enums.getField(objectProperty).getAnnotation(Bdio.Domain.class).value()) { 43 | allowed.put(domain.toString(), objectProperty.toString()); 44 | } 45 | } 46 | for (Bdio.DataProperty dataProperty : Bdio.DataProperty.values()) { 47 | known.add(dataProperty.toString()); 48 | for (Bdio.Class domain : Enums.getField(dataProperty).getAnnotation(Bdio.Domain.class).value()) { 49 | allowed.put(domain.toString(), dataProperty.toString()); 50 | } 51 | } 52 | knownProperties = known.build(); 53 | allowedProperties = allowed.build(); 54 | } 55 | 56 | @Override 57 | public Stream validate(Map input) { 58 | ViolationBuilder result = new ViolationBuilder(this, input); 59 | 60 | RawNodeRule.types(input).forEach(type -> { 61 | for (String key : input.keySet()) { 62 | if (knownProperties.contains(key) && !allowedProperties.containsEntry(type, key)) { 63 | result.error("PropertyNotAllowed", type, key); 64 | } 65 | } 66 | }); 67 | 68 | return result.build(); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /bdio-tool/src/main/java/com/blackducksoftware/bdio2/tool/linter/ImpliedFileSystemTypeConflict.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.tool.linter; 17 | 18 | import static org.apache.tinkerpop.gremlin.process.traversal.P.neq; 19 | import static org.apache.tinkerpop.gremlin.process.traversal.P.without; 20 | 21 | import java.util.stream.Stream; 22 | 23 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; 24 | 25 | import com.blackducksoftware.bdio2.Bdio; 26 | import com.blackducksoftware.bdio2.tool.linter.Linter.CompletedGraphRule; 27 | import com.blackducksoftware.bdio2.tool.linter.Linter.Violation; 28 | import com.blackducksoftware.bdio2.tool.linter.Linter.ViolationBuilder; 29 | 30 | public class ImpliedFileSystemTypeConflict implements CompletedGraphRule { 31 | 32 | @Override 33 | public Stream validate(GraphTraversalSource input) { 34 | ViolationBuilder result = new ViolationBuilder(this); 35 | 36 | // If you have children you should be a directory 37 | input.V().hasLabel(Bdio.Class.File.name()) 38 | .out(Bdio.ObjectProperty.parent.name()) 39 | .has(Bdio.DataProperty.fileSystemType.name(), without( 40 | Bdio.FileSystemType.DIRECTORY.toString(), 41 | Bdio.FileSystemType.DIRECTORY_ARCHIVE.toString())) 42 | .forEachRemaining(v -> result.target(v).error("Parent")); 43 | 44 | // If you have a byte count you should be a regular file or an archive 45 | input.V().hasLabel(Bdio.Class.File.name()) 46 | .has(Bdio.DataProperty.byteCount.name()) 47 | .has(Bdio.DataProperty.fileSystemType.name(), without( 48 | Bdio.FileSystemType.REGULAR.toString(), 49 | Bdio.FileSystemType.REGULAR_BINARY.toString(), 50 | Bdio.FileSystemType.REGULAR_TEXT.toString(), 51 | Bdio.FileSystemType.DIRECTORY_ARCHIVE.toString())) 52 | .forEachRemaining(v -> result.target(v).error("ByteCount")); 53 | 54 | // If you have a link path, you should have a type of symlink 55 | input.V().hasLabel(Bdio.Class.File.name()) 56 | .has(Bdio.DataProperty.linkPath.name()) 57 | .has(Bdio.DataProperty.fileSystemType.name(), neq(Bdio.FileSystemType.SYMLINK.toString())) 58 | .forEachRemaining(v -> result.target(v).error("LinkPath")); 59 | 60 | // If you have an encoding, you should have a type of regular/text 61 | input.V().hasLabel(Bdio.Class.File.name()) 62 | .has(Bdio.DataProperty.encoding.name()) 63 | .has(Bdio.DataProperty.fileSystemType.name(), neq(Bdio.FileSystemType.REGULAR_TEXT.toString())) 64 | .forEachRemaining(v -> result.target(v).error("Encoding")); 65 | 66 | return result.build(); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /bdio-tool/src/main/java/com/blackducksoftware/bdio2/tool/linter/MissingFilePath.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.tool.linter; 17 | 18 | import java.util.stream.Stream; 19 | 20 | import org.apache.tinkerpop.gremlin.structure.Vertex; 21 | 22 | import com.blackducksoftware.bdio2.Bdio; 23 | import com.blackducksoftware.bdio2.tool.linter.Linter.LoadedGraphRule; 24 | import com.blackducksoftware.bdio2.tool.linter.Linter.Violation; 25 | import com.blackducksoftware.bdio2.tool.linter.Linter.ViolationBuilder; 26 | 27 | public class MissingFilePath implements LoadedGraphRule { 28 | 29 | @Override 30 | public Stream validate(Vertex input) { 31 | ViolationBuilder result = new ViolationBuilder(this, input); 32 | 33 | if (input.label().equals(Bdio.Class.File.name()) 34 | && !input.property(Bdio.DataProperty.path.name()).isPresent()) { 35 | result.error("PathNotPresent"); 36 | } 37 | 38 | return result.build(); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /bdio-tool/src/main/java/com/blackducksoftware/bdio2/tool/linter/MissingProjectName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.tool.linter; 17 | 18 | import java.util.stream.Stream; 19 | 20 | import org.apache.tinkerpop.gremlin.structure.Vertex; 21 | 22 | import com.blackducksoftware.bdio2.Bdio; 23 | import com.blackducksoftware.bdio2.tool.linter.Linter.LoadedGraphRule; 24 | import com.blackducksoftware.bdio2.tool.linter.Linter.Violation; 25 | import com.blackducksoftware.bdio2.tool.linter.Linter.ViolationBuilder; 26 | 27 | public class MissingProjectName implements LoadedGraphRule { 28 | 29 | @Override 30 | public Stream validate(Vertex input) { 31 | ViolationBuilder result = new ViolationBuilder(this, input); 32 | 33 | if (input.label().equals(Bdio.Class.Project.name()) 34 | && !input.property(Bdio.DataProperty.name.name()).isPresent()) { 35 | if (input.property(Bdio.DataProperty.version.name()).isPresent()) { 36 | result.error("HasVersion"); 37 | } else { 38 | result.error("NameNotPresent"); 39 | } 40 | } 41 | 42 | return result.build(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /bdio-tool/src/main/java/com/blackducksoftware/bdio2/tool/linter/Namespace.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.tool.linter; 17 | 18 | import java.util.stream.Stream; 19 | 20 | import org.apache.tinkerpop.gremlin.structure.Vertex; 21 | 22 | import com.blackducksoftware.bdio2.tool.linter.Linter.LoadedGraphRule; 23 | import com.blackducksoftware.bdio2.tool.linter.Linter.Violation; 24 | 25 | public class Namespace implements LoadedGraphRule { 26 | 27 | @Override 28 | public Stream validate(Vertex input) { 29 | // TODO Use namespace rules to: 30 | // 1. Ensure the namespace is known 31 | // 2. Ensure the identifier, version, requestedVersion, scope are valid for the namespace 32 | return Stream.empty(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /bdio-tool/src/main/java/com/blackducksoftware/bdio2/tool/linter/ObjectPropertyRange.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.tool.linter; 17 | 18 | import static com.blackducksoftware.common.base.ExtraEnums.tryByName; 19 | import static java.util.Collections.emptySet; 20 | 21 | import java.util.Set; 22 | import java.util.stream.Stream; 23 | 24 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; 25 | 26 | import com.blackducksoftware.bdio2.Bdio; 27 | import com.blackducksoftware.bdio2.tool.linter.Linter.CompletedGraphRule; 28 | import com.blackducksoftware.bdio2.tool.linter.Linter.Violation; 29 | import com.blackducksoftware.bdio2.tool.linter.Linter.ViolationBuilder; 30 | import com.google.common.base.Enums; 31 | import com.google.common.collect.ImmutableSet; 32 | 33 | public class ObjectPropertyRange implements CompletedGraphRule { 34 | 35 | @Override 36 | public Stream validate(GraphTraversalSource g) { 37 | ViolationBuilder result = new ViolationBuilder(this); 38 | 39 | // Validate EVERY EDGE 40 | g.E().forEachRemaining(e -> { 41 | Set range = tryByName(Bdio.ObjectProperty.class, e.label()).map(ObjectPropertyRange::range).orElse(emptySet()); 42 | if (!range.isEmpty() && !tryByName(Bdio.Class.class, e.inVertex().label()).filter(range::contains).isPresent()) { 43 | result.target(e).error("InvalidRange"); 44 | } 45 | }); 46 | 47 | return result.build(); 48 | } 49 | 50 | private static Set range(Bdio.ObjectProperty objectProperty) { 51 | return ImmutableSet.copyOf(Enums.getField(objectProperty).getAnnotation(Bdio.ObjectPropertyRange.class).value()); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /bdio-tool/src/main/java/com/blackducksoftware/bdio2/tool/linter/SemanticRules.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.tool.linter; 17 | 18 | import java.util.stream.Stream; 19 | 20 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; 21 | 22 | import com.blackducksoftware.bdio2.tool.linter.Linter.CompletedGraphRule; 23 | import com.blackducksoftware.bdio2.tool.linter.Linter.Violation; 24 | import com.blackducksoftware.bdio2.tool.linter.Linter.ViolationBuilder; 25 | 26 | public class SemanticRules implements CompletedGraphRule { 27 | 28 | @Override 29 | public Stream validate(GraphTraversalSource input) { 30 | // TODO Check the semantic rules from the specification 31 | ViolationBuilder result = new ViolationBuilder(this); 32 | 33 | return result.build(); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /bdio-tool/src/main/java/com/blackducksoftware/bdio2/tool/linter/SingleRoot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.tool.linter; 17 | 18 | import java.util.Collections; 19 | import java.util.Iterator; 20 | import java.util.List; 21 | import java.util.stream.Stream; 22 | 23 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; 24 | import org.apache.tinkerpop.gremlin.structure.Direction; 25 | import org.apache.tinkerpop.gremlin.structure.Edge; 26 | import org.apache.tinkerpop.gremlin.structure.Vertex; 27 | 28 | import com.blackducksoftware.bdio2.tool.linter.Linter.CompletedGraphRule; 29 | import com.blackducksoftware.bdio2.tool.linter.Linter.LT; 30 | import com.blackducksoftware.bdio2.tool.linter.Linter.Violation; 31 | import com.blackducksoftware.bdio2.tool.linter.Linter.ViolationBuilder; 32 | 33 | public class SingleRoot implements CompletedGraphRule { 34 | 35 | @Override 36 | public Stream validate(GraphTraversalSource g) { 37 | ViolationBuilder result = new ViolationBuilder(this); 38 | 39 | List metadata = g.V().hasLabel(LT._Metadata.name()).toList(); 40 | if (metadata.isEmpty()) { 41 | result.target(Collections.emptyMap()).error("MissingMetadata"); 42 | } else if (metadata.size() > 1) { 43 | result.target(metadata.get(1)).error("MultipleMetadata"); 44 | } else { 45 | Iterator roots = metadata.get(0).edges(Direction.OUT, LT._root.name()); 46 | if (roots.hasNext()) { 47 | roots.next(); 48 | if (roots.hasNext()) { 49 | result.target(roots.next().inVertex()).error("MultipleRoots"); 50 | } 51 | } else { 52 | result.target(metadata.get(0)).error("MissingRoot"); 53 | } 54 | } 55 | 56 | return result.build(); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /bdio-tool/src/main/java/com/blackducksoftware/bdio2/tool/linter/UnreferencedNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.tool.linter; 17 | 18 | import static org.apache.tinkerpop.gremlin.process.traversal.P.neq; 19 | import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.bothE; 20 | 21 | import java.util.stream.Stream; 22 | 23 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; 24 | 25 | import com.blackducksoftware.bdio2.tool.linter.Linter.CompletedGraphRule; 26 | import com.blackducksoftware.bdio2.tool.linter.Linter.Violation; 27 | import com.blackducksoftware.bdio2.tool.linter.Linter.ViolationBuilder; 28 | 29 | public class UnreferencedNode implements CompletedGraphRule { 30 | 31 | @Override 32 | public Stream validate(GraphTraversalSource input) { 33 | ViolationBuilder result = new ViolationBuilder(this); 34 | input.V().hasLabel(neq(Linter.LT._Metadata.name())) 35 | .where(bothE().count().is(0)) 36 | .forEachRemaining(v -> result.target(v).warning("UnreferencedNode", v.label())); 37 | return result.build(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /bdio-tool/src/main/java/com/blackducksoftware/bdio2/tool/linter/UriSchemes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Synopsys, Inc. 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 com.blackducksoftware.bdio2.tool.linter; 17 | 18 | import com.google.common.base.Ascii; 19 | 20 | /** 21 | * Various filters for URI schemes. 22 | */ 23 | final class UriSchemes { 24 | 25 | /** 26 | * Accepts for "base" schemes, i.e. non-archive schemes that can be used at the base of the HID. 27 | */ 28 | public static boolean isBaseScheme(CharSequence scheme) { 29 | return isSchemeEquals(scheme, "file") 30 | || isSchemeEquals(scheme, "http") 31 | || isSchemeEquals(scheme, "https") 32 | || isSchemeEquals(scheme, "ftp"); 33 | } 34 | 35 | /** 36 | * Accepts schemes that should include an authority. 37 | *

38 | * IMPORTANT: This includes {@code file}. 39 | */ 40 | public static boolean isAuthorityScheme(CharSequence scheme) { 41 | return isSchemeEquals(scheme, "file") 42 | || isSchemeEquals(scheme, "http") 43 | || isSchemeEquals(scheme, "https") 44 | || isSchemeEquals(scheme, "ftp"); 45 | } 46 | 47 | /** 48 | * Accepts schemes that are not suitable for use as an identifier. 49 | */ 50 | public static boolean isDegradedScheme(CharSequence scheme) { 51 | return isSchemeEquals(scheme, "about") 52 | || isSchemeEquals(scheme, "chrome") 53 | || isSchemeEquals(scheme, "data") 54 | || isSchemeEquals(scheme, "mailto"); 55 | } 56 | 57 | /** 58 | * Internal ignore case helper. 59 | */ 60 | private static boolean isSchemeEquals(CharSequence scheme1, CharSequence scheme2) { 61 | return Ascii.equalsIgnoreCase(scheme1, scheme2); 62 | } 63 | 64 | private UriSchemes() { 65 | assert false; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /bdio-tool/src/main/java/com/blackducksoftware/bdio2/tool/linter/ValidFilePath.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.tool.linter; 17 | 18 | import java.util.Map; 19 | import java.util.function.Predicate; 20 | import java.util.stream.Stream; 21 | 22 | import com.blackducksoftware.bdio2.Bdio; 23 | import com.blackducksoftware.bdio2.BdioContext; 24 | import com.blackducksoftware.bdio2.tool.linter.Linter.RawNodeRule; 25 | import com.blackducksoftware.bdio2.tool.linter.Linter.Violation; 26 | import com.blackducksoftware.bdio2.tool.linter.Linter.ViolationBuilder; 27 | import com.blackducksoftware.common.value.HID; 28 | 29 | public class ValidFilePath implements RawNodeRule { 30 | 31 | /** 32 | * On PostgreSQL the path is indexed and is therefore limited to a function of the database buffer page size. With 33 | * the default configuration this is the limit. 34 | */ 35 | private static final int MAX_PATH_LENGTH = 2712; 36 | 37 | @Override 38 | public Stream validate(Map input) { 39 | ViolationBuilder result = new ViolationBuilder(this, input); 40 | 41 | if (RawNodeRule.types(input).anyMatch(Predicate.isEqual(Bdio.Class.File.toString()))) { 42 | BdioContext context = BdioContext.getDefault(); 43 | Object path = context.fromFieldValue(Bdio.DataProperty.path.toString(), input.get(Bdio.DataProperty.path.toString())); 44 | if (path instanceof String) { 45 | HID hid = HID.from(path); 46 | 47 | // Make sure the path is in normal form 48 | if (!path.equals(hid.toUriString())) { 49 | // TODO Should we force normalize everything and make this a warning? 50 | result.error("PathNotNormalized", hid.toUriString()); 51 | } 52 | 53 | // Path length, just a warning because this really only applies to PostgreSQL 54 | int length = ((String) path).length(); 55 | if (length > MAX_PATH_LENGTH) { 56 | result.warning("PathLength", length, MAX_PATH_LENGTH, path); 57 | } 58 | 59 | // Sanity check the schemes 60 | HID container = hid; 61 | while (container.hasContainer()) { 62 | if (UriSchemes.isBaseScheme(container.getScheme())) { 63 | result.error("NestedBaseScheme", container.getScheme()); 64 | } 65 | container = container.getContainer(); 66 | } 67 | if (!UriSchemes.isBaseScheme(container.getScheme())) { 68 | result.warning("UnknownBaseScheme", container.getScheme()); 69 | } 70 | } else if (path != null) { 71 | result.error("String"); 72 | } 73 | } 74 | 75 | return result.build(); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /bdio-tool/src/main/java/com/blackducksoftware/bdio2/tool/linter/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | package com.blackducksoftware.bdio2.tool.linter; 3 | 4 | import javax.annotation.ParametersAreNonnullByDefault; 5 | -------------------------------------------------------------------------------- /bdio-tool/src/main/java/com/blackducksoftware/bdio2/tool/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | package com.blackducksoftware.bdio2.tool; 3 | 4 | import javax.annotation.ParametersAreNonnullByDefault; -------------------------------------------------------------------------------- /bdio-tool/src/main/resources/META-INF/mime.types: -------------------------------------------------------------------------------- 1 | # Additional MIME types needed for the visualization web server 2 | text/css css 3 | application/javascript js 4 | -------------------------------------------------------------------------------- /bdio-tool/src/main/resources/com/blackducksoftware/bdio2/tool/www_viz/bdio.css: -------------------------------------------------------------------------------- 1 | #bdio-graph { 2 | height: 600px; 3 | } 4 | -------------------------------------------------------------------------------- /bdio-tool/src/main/resources/com/blackducksoftware/bdio2/tool/www_viz/bdio.js: -------------------------------------------------------------------------------- 1 | var network; 2 | 3 | var nodes = new vis.DataSet(); 4 | var edges = new vis.DataSet(); 5 | var gephiImported; 6 | 7 | var detailsElement = document.getElementById('bdio-details'); 8 | var container = document.getElementById('bdio-graph'); 9 | 10 | loadJSON('data/graph.json' + window.location.search, redrawAll, function(err) { 11 | detailsElement.innerHTML = "Failed to load graph."; 12 | }); 13 | 14 | var data = { 15 | nodes: nodes, 16 | edges: edges 17 | }; 18 | var options = { 19 | nodes: { 20 | shape: 'dot', 21 | font: { 22 | face: 'Tahoma' 23 | } 24 | }, 25 | edges: { 26 | width: 0.15, 27 | arrows: { 28 | to: { 29 | scaleFactor: 0.5 30 | } 31 | }, 32 | smooth: { 33 | type: 'continuous' 34 | } 35 | }, 36 | interaction: { 37 | tooltipDelay: 200, 38 | hideEdgesOnDrag: true 39 | }, 40 | physics: { 41 | stabilization: false, 42 | barnesHut: { 43 | gravitationalConstant: -10000, 44 | springConstant: 0.002, 45 | springLength: 150 46 | } 47 | } 48 | }; 49 | 50 | network = new vis.Network(container, data, options); 51 | network.on('click', function (params) { 52 | if (params.nodes.length > 0) { 53 | var data = nodes.get(params.nodes[0]); // get the data from selected node 54 | detailsElement.innerHTML = JSON.stringify(data.attributes, undefined, 3); // show the data in the div 55 | } else if (params.edges.length > 0) { 56 | var data = edges.get(params.edges[0]); 57 | detailsElement.innerHTML = JSON.stringify(data.attributes, undefined, 3); 58 | } else { 59 | detailsElement.innerHTML = "Click a node or edge to view details"; 60 | } 61 | }) 62 | 63 | /** 64 | * https://raw.githubusercontent.com/almende/vis/v4.17.0/examples/network/exampleUtil.js 65 | */ 66 | function loadJSON(path, success, error) { 67 | var xhr = new XMLHttpRequest(); 68 | xhr.onreadystatechange = function () { 69 | if (xhr.readyState === 4) { 70 | if (xhr.status === 200) { 71 | success(JSON.parse(xhr.responseText)); 72 | } else { 73 | error(xhr); 74 | } 75 | } 76 | }; 77 | xhr.open('GET', path, true); 78 | xhr.send(); 79 | } 80 | 81 | /** 82 | * This function fills the DataSets. These DataSets will update the network. 83 | */ 84 | function redrawAll(gephiJSON) { 85 | if (gephiJSON.nodes === undefined) { 86 | gephiJSON = gephiImported; 87 | } else { 88 | gephiImported = gephiJSON; 89 | } 90 | 91 | nodes.clear(); 92 | edges.clear(); 93 | 94 | detailsElement.innerHTML = "Click a node or edge to view details"; 95 | 96 | // TODO Disable edge smoothing if the gephiJSON.nodes is too large and add a warning to the details text 97 | 98 | var parsed = vis.network.gephiParser.parseGephi(gephiJSON, { 99 | fixed: false, 100 | parseColor: false 101 | }); 102 | 103 | nodes.add(parsed.nodes); 104 | edges.add(parsed.edges); 105 | network.fit(); 106 | } 107 | -------------------------------------------------------------------------------- /bdio-tool/src/main/resources/com/blackducksoftware/bdio2/tool/www_viz/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Black Duck I/O Visualizer 8 | 9 | 10 | 11 | 12 | 13 |

14 | 17 |
18 |
19 |
20 |
21 |
22 |

23 |         
24 |
25 |
26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /bdio-tool/src/test/java/com/blackducksoftware/bdio2/tool/ToolTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.tool; 17 | 18 | import org.junit.Test; 19 | 20 | public class ToolTest { 21 | 22 | // Right now, this is just here to make Jacoco not freak out. 23 | 24 | @Test 25 | public void doNothing() { 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /bdio2/build.gradle: -------------------------------------------------------------------------------- 1 | description = 'Black Duck I/O API' 2 | 3 | dependencies { 4 | compile 'com.blackducksoftware.magpie:magpie' 5 | compile 'com.fasterxml.jackson.core:jackson-annotations' 6 | compile 'com.fasterxml.jackson.core:jackson-core' 7 | compile 'com.fasterxml.jackson.core:jackson-databind' 8 | compile 'com.google.code.findbugs:jsr305' 9 | compile 'com.google.guava:guava' 10 | compile 'com.github.jsonld-java:jsonld-java' 11 | compile 'org.reactivestreams:reactive-streams' 12 | 13 | testCompile project(':bdio-test') 14 | testCompile 'com.blackducksoftware.magpie:magpie-test' 15 | testCompile 'com.google.truth:truth' 16 | testCompile 'com.google.truth.extensions:truth-java8-extension' 17 | testCompile 'junit:junit' 18 | testCompile 'org.mockito:mockito-core' 19 | } 20 | 21 | -------------------------------------------------------------------------------- /bdio2/src/main/java/com/blackducksoftware/bdio2/BdioSubscriber.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2; 17 | 18 | import java.io.IOException; 19 | import java.util.Map; 20 | import java.util.Objects; 21 | import java.util.function.Consumer; 22 | 23 | import org.reactivestreams.Subscriber; 24 | import org.reactivestreams.Subscription; 25 | 26 | import com.blackducksoftware.bdio2.BdioWriter.StreamSupplier; 27 | 28 | /** 29 | * A subscriber for serializing BDIO nodes to a byte stream. 30 | * 31 | * @author jgustie 32 | * @see BdioWriter 33 | */ 34 | public class BdioSubscriber implements Subscriber> { 35 | 36 | private final BdioWriter writer; 37 | 38 | private final Consumer onError; 39 | 40 | private Subscription subscription; 41 | 42 | public BdioSubscriber(BdioMetadata metadata, StreamSupplier entryStreams, Consumer onError) { 43 | writer = new BdioWriter(metadata, entryStreams); 44 | this.onError = Objects.requireNonNull(onError); 45 | } 46 | 47 | private void validateSubscription(Subscription s) { 48 | Objects.requireNonNull(s, "subscription is null"); 49 | if (subscription != null) { 50 | subscription.cancel(); 51 | throw new IllegalStateException("subscription was already set"); 52 | } else { 53 | subscription = s; 54 | } 55 | } 56 | 57 | @Override 58 | public void onSubscribe(Subscription s) { 59 | validateSubscription(s); 60 | 61 | try { 62 | writer.start(); 63 | subscription.request(Long.MAX_VALUE); 64 | } catch (IOException e) { 65 | onError(e); 66 | } 67 | } 68 | 69 | @Override 70 | public void onNext(Map node) { 71 | try { 72 | writer.next(node); 73 | } catch (IOException e) { 74 | onError(e); 75 | } 76 | } 77 | 78 | @Override 79 | public void onComplete() { 80 | try { 81 | writer.close(); 82 | } catch (IOException e) { 83 | // Don't call `onError(e)` here (even though `writer.close()` is idempotent?!) 84 | onError.accept(e); 85 | } 86 | } 87 | 88 | @Override 89 | public void onError(Throwable e) { 90 | // Make sure we try to close the writer so the Zip isn't corrupted 91 | try { 92 | writer.close(); 93 | } catch (IOException | RuntimeException suppressed) { 94 | e.addSuppressed(suppressed); 95 | } 96 | onError.accept(e); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /bdio2/src/main/java/com/blackducksoftware/bdio2/BdioValueMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Synopsys, Inc. 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 com.blackducksoftware.bdio2; 17 | 18 | import java.util.Map; 19 | import java.util.function.Predicate; 20 | import java.util.stream.Collector; 21 | import java.util.stream.Stream; 22 | 23 | import javax.annotation.Nullable; 24 | 25 | public interface BdioValueMapper { 26 | 27 | /** 28 | * Converts a JSON-LD field value into a typed representation. 29 | */ 30 | Object fromFieldValue(Map fieldValue); 31 | 32 | /** 33 | * Converts a typed representation into something that can be handled by the JSON-LD serialization. 34 | *

35 | * The output of this method is passed to a Jackson ObjectMapper created with the default configuration. 36 | */ 37 | Object toFieldValue(@Nullable Object definedType, Object value, Predicate isEmbeddedType); 38 | 39 | // TODO We may need a `fromLiteralFieldValue(Object)` and `isLiteralFieldValue` 40 | 41 | /** 42 | * Returns the JSON-LD container specific collector used when multiple values are present. 43 | */ 44 | Collector getCollector(@Nullable String container); 45 | 46 | /** 47 | * Splits the supplied value, this is the inverse of what container specific collector did. 48 | */ 49 | Stream split(Object value); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /bdio2/src/main/java/com/blackducksoftware/bdio2/Emitter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2; 17 | 18 | import java.util.Spliterators; 19 | import java.util.concurrent.atomic.AtomicBoolean; 20 | import java.util.function.Consumer; 21 | import java.util.stream.Stream; 22 | import java.util.stream.StreamSupport; 23 | 24 | import com.google.common.base.Throwables; 25 | 26 | /** 27 | * Abstraction of what will eventually become a reactive producer. 28 | * 29 | * @author jgustie 30 | */ 31 | public interface Emitter { 32 | 33 | /** 34 | * Emits a single element. Implementations must interact with only one parameter one time per call. 35 | */ 36 | void emit(Consumer onNext, Consumer onError, Runnable onComplete); 37 | 38 | /** 39 | * Releases any resources held by this emitter. 40 | */ 41 | default void dispose() { 42 | } 43 | 44 | /** 45 | * Stream the contents of this emitter. 46 | */ 47 | default Stream stream() { 48 | return StreamSupport.stream(new Spliterators.AbstractSpliterator(Long.MAX_VALUE, 0) { 49 | private final AtomicBoolean hasNext = new AtomicBoolean(true); 50 | 51 | @Override 52 | public boolean tryAdvance(Consumer action) { 53 | emit(action, t -> { 54 | Throwables.throwIfUnchecked(t); 55 | throw new RuntimeException(t); 56 | }, () -> { 57 | if (hasNext.compareAndSet(true, false)) { 58 | dispose(); 59 | } 60 | }); 61 | return hasNext.get(); 62 | } 63 | }, false).onClose(this::dispose); 64 | } 65 | 66 | /** 67 | * Returns an emitter that does not produce any content. 68 | */ 69 | public static Emitter empty() { 70 | return new Emitter() { 71 | @Override 72 | public void emit(Consumer onNext, Consumer onError, Runnable onComplete) { 73 | onComplete.run(); 74 | } 75 | 76 | @Override 77 | public Stream stream() { 78 | return Stream.empty(); 79 | } 80 | }; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /bdio2/src/main/java/com/blackducksoftware/bdio2/EntrySizeViolationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2; 17 | 18 | import java.io.IOException; 19 | 20 | import javax.annotation.Nullable; 21 | 22 | /** 23 | * Thrown when a BDIO entry exceeds the maximum allowable size. 24 | * 25 | * @author jgustie 26 | */ 27 | public class EntrySizeViolationException extends IOException { 28 | 29 | private static final long serialVersionUID = 1627540107517253512L; 30 | 31 | /** 32 | * The name of the entry that exceeded the maximum length. 33 | */ 34 | @Nullable 35 | private final String name; 36 | 37 | /** 38 | * The estimated total size of the entry in bytes or -1 if it is not known. 39 | */ 40 | private final long estimatedSize; 41 | 42 | /** 43 | * Creates a new exception for when an entry is too large. 44 | */ 45 | public EntrySizeViolationException(@Nullable String name, long estimatedSize) { 46 | super("Entry length violation"); 47 | this.name = name; 48 | this.estimatedSize = estimatedSize; 49 | } 50 | 51 | /** 52 | * Returns the name of the entry that caused the violation. This might be {@code null} if the violation occurred 53 | * while reading a plain JSON file or while writing a BDIO file where the entry name has not yet been computed. 54 | */ 55 | @Nullable 56 | public String getName() { 57 | return name; 58 | } 59 | 60 | /** 61 | * Returns the estimated size of the entry that caused the violation (or -1 if the size is unknown). This should be 62 | * greater then the maximum entry size, however the Zip metadata may misrepresent the size of the entry. 63 | */ 64 | public long getEstimatedSize() { 65 | return estimatedSize; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /bdio2/src/main/java/com/blackducksoftware/bdio2/LegacyJsonParserEmitter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Synopsys, Inc. 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 com.blackducksoftware.bdio2; 17 | 18 | import java.io.IOException; 19 | import java.io.InputStream; 20 | import java.io.UncheckedIOException; 21 | import java.util.Objects; 22 | import java.util.concurrent.Callable; 23 | import java.util.function.Consumer; 24 | 25 | import javax.annotation.Nullable; 26 | 27 | import com.fasterxml.jackson.core.JsonFactory; 28 | import com.fasterxml.jackson.core.JsonParser; 29 | 30 | /** 31 | * Base class for legacy emitters based on a (streaming) JSON parser. 32 | * 33 | * @author jgustie 34 | */ 35 | abstract class LegacyJsonParserEmitter implements Emitter { 36 | 37 | /** 38 | * Factory for creating the JSON parser. Using callable allows us to defer execution of code that may throw an 39 | * exception until we have a consumer to accept the failure. 40 | */ 41 | private final Callable parserSupplier; 42 | 43 | /** 44 | * The JSON parser (which wraps an input stream). Initially {@code null} until the first {@link #emit} call. 45 | */ 46 | private JsonParser jp; 47 | 48 | /** 49 | * Creates a new emitter using the supplied factory to create a parser. 50 | */ 51 | protected LegacyJsonParserEmitter(JsonFactory jsonFactory, InputStream inputStream) { 52 | Objects.requireNonNull(jsonFactory); 53 | Objects.requireNonNull(inputStream); 54 | parserSupplier = () -> { 55 | return jsonFactory.createParser(inputStream); 56 | }; 57 | } 58 | 59 | @Override 60 | public final void emit(Consumer onNext, Consumer onError, Runnable onComplete) { 61 | Objects.requireNonNull(onNext); 62 | Objects.requireNonNull(onError); 63 | Objects.requireNonNull(onComplete); 64 | try { 65 | if (jp == null) { 66 | jp = parserSupplier.call(); 67 | } 68 | Object next = next(jp); 69 | if (next != null) { 70 | onNext.accept(next); 71 | } else { 72 | onComplete.run(); 73 | } 74 | } catch (Exception e) { 75 | onError.accept(e); 76 | } 77 | } 78 | 79 | @Override 80 | public final void dispose() { 81 | if (jp != null) { 82 | try { 83 | jp.close(); 84 | } catch (IOException e) { 85 | throw new UncheckedIOException(e); 86 | } 87 | } 88 | } 89 | 90 | /** 91 | * Extracts the next BDIO 2.x entry from the supplied JSON parser, returning {@code null} if no more entries are 92 | * available and throwing if a failure occurs during parsing. 93 | */ 94 | @Nullable 95 | protected abstract Object next(JsonParser jp) throws IOException; 96 | 97 | } 98 | -------------------------------------------------------------------------------- /bdio2/src/main/java/com/blackducksoftware/bdio2/NodeDoesNotExistException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2; 17 | 18 | import java.util.Objects; 19 | 20 | /** 21 | * Exception thrown when an attempt is made to reference a node that does not exist. 22 | * 23 | * @author jgustie 24 | */ 25 | public class NodeDoesNotExistException extends Exception { 26 | 27 | private static final long serialVersionUID = 3567608177686947138L; 28 | 29 | private final Object nodeIdentifier; 30 | 31 | private final String objectPropertyName; 32 | 33 | private final Object missingNodeIdentifier; 34 | 35 | private static String message(Object nodeIdentifier, String objectPropertyName, Object missingNodeIdentifier) { 36 | return String.format("'%s' references non-existent '%s': %s", nodeIdentifier, objectPropertyName, missingNodeIdentifier); 37 | } 38 | 39 | public NodeDoesNotExistException(Object nodeIdentifier, String objectPropertyName, Object missingNodeIdentifier) { 40 | super(message(nodeIdentifier, objectPropertyName, missingNodeIdentifier)); 41 | this.nodeIdentifier = Objects.requireNonNull(nodeIdentifier); 42 | this.objectPropertyName = Objects.requireNonNull(objectPropertyName); 43 | this.missingNodeIdentifier = Objects.requireNonNull(missingNodeIdentifier); 44 | } 45 | 46 | /** 47 | * Returns the identifier of the node referencing a non-existent node. 48 | */ 49 | public Object getNodeIdentifier() { 50 | return nodeIdentifier; 51 | } 52 | 53 | /** 54 | * Returns the name of the object property on the node which references a non-existent node. 55 | */ 56 | public String getObjectPropertyName() { 57 | return objectPropertyName; 58 | } 59 | 60 | /** 61 | * Returns the bad identifier. 62 | */ 63 | public Object getMissingNodeIdentifier() { 64 | return missingNodeIdentifier; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /bdio2/src/main/java/com/blackducksoftware/bdio2/model/Annotation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.model; 17 | 18 | import java.time.ZonedDateTime; 19 | 20 | import javax.annotation.Nullable; 21 | 22 | import com.blackducksoftware.bdio2.Bdio; 23 | import com.blackducksoftware.bdio2.BdioObject; 24 | 25 | public class Annotation extends BdioObject { 26 | 27 | public Annotation() { 28 | super(Bdio.Class.Annotation); 29 | } 30 | 31 | public Annotation comment(@Nullable String comment) { 32 | putFieldValue(Bdio.DataProperty.comment, comment); 33 | return this; 34 | } 35 | 36 | public Annotation creator(@Nullable String creator) { 37 | putFieldValue(Bdio.DataProperty.creator, creator); 38 | return this; 39 | } 40 | 41 | public Annotation creationDateTime(@Nullable ZonedDateTime creationDateTime) { 42 | putFieldValue(Bdio.DataProperty.creationDateTime, creationDateTime); 43 | return this; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /bdio2/src/main/java/com/blackducksoftware/bdio2/model/Container.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.model; 17 | 18 | import javax.annotation.Nullable; 19 | 20 | import com.blackducksoftware.bdio2.Bdio; 21 | import com.blackducksoftware.bdio2.BdioObject; 22 | import com.blackducksoftware.common.value.ProductList; 23 | 24 | public final class Container extends BdioObject { 25 | 26 | public Container(String id) { 27 | super(id, Bdio.Class.Container); 28 | } 29 | 30 | public Container base(@Nullable File base) { 31 | putFieldValue(Bdio.ObjectProperty.base, base); 32 | return this; 33 | } 34 | 35 | public Container dependency(Dependency dependency) { 36 | putFieldValue(Bdio.ObjectProperty.dependency, dependency); 37 | return this; 38 | } 39 | 40 | public Container description(@Nullable Annotation description) { 41 | putFieldValue(Bdio.ObjectProperty.description, description); 42 | return this; 43 | } 44 | 45 | public Container license(@Nullable Object license) { 46 | putFieldValue(Bdio.ObjectProperty.license, license); 47 | return this; 48 | } 49 | 50 | public Container licenseConjunctive(@Nullable Object license) { 51 | putFieldValue(Bdio.ObjectProperty.licenseConjunctive, license); 52 | return this; 53 | } 54 | 55 | public Container licenseDisjunctive(@Nullable Object license) { 56 | putFieldValue(Bdio.ObjectProperty.licenseDisjunctive, license); 57 | return this; 58 | } 59 | 60 | public Container licenseOrLater(@Nullable Object license) { 61 | putFieldValue(Bdio.ObjectProperty.licenseOrLater, license); 62 | return this; 63 | } 64 | 65 | public Container namespace(@Nullable String namespace) { 66 | putFieldValue(Bdio.DataProperty.namespace, namespace); 67 | return this; 68 | } 69 | 70 | public Container platform(@Nullable ProductList platform) { 71 | putFieldValue(Bdio.DataProperty.platform, platform); 72 | return this; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /bdio2/src/main/java/com/blackducksoftware/bdio2/model/Dependency.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.model; 17 | 18 | import javax.annotation.Nullable; 19 | 20 | import com.blackducksoftware.bdio2.Bdio; 21 | import com.blackducksoftware.bdio2.BdioObject; 22 | 23 | public final class Dependency extends BdioObject { 24 | 25 | public Dependency() { 26 | super(Bdio.Class.Dependency); 27 | } 28 | 29 | public Dependency dependsOn(@Nullable Object component) { 30 | putFieldValue(Bdio.ObjectProperty.dependsOn, component); 31 | return this; 32 | } 33 | 34 | public Dependency declaredBy(@Nullable File file) { 35 | putFieldValue(Bdio.ObjectProperty.declaredBy, file); 36 | return this; 37 | } 38 | 39 | public Dependency description(@Nullable Annotation description) { 40 | putFieldValue(Bdio.ObjectProperty.description, description); 41 | return this; 42 | } 43 | 44 | public Dependency dependencyType(@Nullable Object dependencyType) { 45 | putFieldValue(Bdio.DataProperty.dependencyType, dependencyType); 46 | return this; 47 | } 48 | 49 | public Dependency evidence(@Nullable File file) { 50 | putFieldValue(Bdio.ObjectProperty.evidence, file); 51 | return this; 52 | } 53 | 54 | public Dependency license(@Nullable Object license) { 55 | putFieldValue(Bdio.ObjectProperty.license, license); 56 | return this; 57 | } 58 | 59 | public Dependency licenseConjunctive(@Nullable Object license) { 60 | putFieldValue(Bdio.ObjectProperty.licenseConjunctive, license); 61 | return this; 62 | } 63 | 64 | public Dependency licenseDisjunctive(@Nullable Object license) { 65 | putFieldValue(Bdio.ObjectProperty.licenseDisjunctive, license); 66 | return this; 67 | } 68 | 69 | public Dependency licenseOrLater(@Nullable Object license) { 70 | putFieldValue(Bdio.ObjectProperty.licenseOrLater, license); 71 | return this; 72 | } 73 | 74 | public Dependency namespace(@Nullable String namespace) { 75 | putFieldValue(Bdio.DataProperty.namespace, namespace); 76 | return this; 77 | } 78 | 79 | public Dependency range(@Nullable String range) { 80 | putFieldValue(Bdio.DataProperty.range, range); 81 | return this; 82 | } 83 | 84 | public Dependency requestedVersion(@Nullable String requestedVersion) { 85 | putFieldValue(Bdio.DataProperty.requestedVersion, requestedVersion); 86 | return this; 87 | } 88 | 89 | public Dependency scope(@Nullable String scope) { 90 | putFieldValue(Bdio.DataProperty.scope, scope); 91 | return this; 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /bdio2/src/main/java/com/blackducksoftware/bdio2/model/FileCollection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.model; 17 | 18 | import javax.annotation.Nullable; 19 | 20 | import com.blackducksoftware.bdio2.Bdio; 21 | import com.blackducksoftware.bdio2.BdioObject; 22 | 23 | public final class FileCollection extends BdioObject { 24 | 25 | public FileCollection(String id) { 26 | super(id, Bdio.Class.FileCollection); 27 | } 28 | 29 | public FileCollection base(@Nullable File base) { 30 | putFieldValue(Bdio.ObjectProperty.base, base); 31 | return this; 32 | } 33 | 34 | public FileCollection dependency(Dependency dependency) { 35 | putFieldValue(Bdio.ObjectProperty.dependency, dependency); 36 | return this; 37 | } 38 | 39 | public FileCollection description(@Nullable Annotation description) { 40 | putFieldValue(Bdio.ObjectProperty.description, description); 41 | return this; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /bdio2/src/main/java/com/blackducksoftware/bdio2/model/License.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.model; 17 | 18 | import javax.annotation.Nullable; 19 | 20 | import com.blackducksoftware.bdio2.Bdio; 21 | import com.blackducksoftware.bdio2.BdioObject; 22 | import com.blackducksoftware.common.value.ProductList; 23 | 24 | public final class License extends BdioObject { 25 | 26 | public License(String id) { 27 | super(id, Bdio.Class.License); 28 | } 29 | 30 | public License canonical(@Nullable License canonical) { 31 | putFieldValue(Bdio.ObjectProperty.canonical, canonical); 32 | return this; 33 | } 34 | 35 | public License description(@Nullable Annotation description) { 36 | putFieldValue(Bdio.ObjectProperty.description, description); 37 | return this; 38 | } 39 | 40 | public License licenseException(@Nullable License license) { 41 | putFieldValue(Bdio.ObjectProperty.licenseException, license); 42 | return this; 43 | } 44 | 45 | public License name(@Nullable String name) { 46 | putFieldValue(Bdio.DataProperty.name, name); 47 | return this; 48 | } 49 | 50 | public License namespace(@Nullable String namespace) { 51 | putFieldValue(Bdio.DataProperty.namespace, namespace); 52 | return this; 53 | } 54 | 55 | public License identifier(@Nullable String locator) { 56 | putFieldValue(Bdio.DataProperty.identifier, locator); 57 | return this; 58 | } 59 | 60 | public License context(@Nullable String context) { 61 | putFieldValue(Bdio.DataProperty.context, context); 62 | return this; 63 | } 64 | 65 | public License resolver(@Nullable ProductList resolver) { 66 | putFieldValue(Bdio.DataProperty.resolver, resolver); 67 | return this; 68 | } 69 | 70 | public License homepage(@Nullable String homepage) { 71 | putFieldValue(Bdio.DataProperty.homepage, homepage); 72 | return this; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /bdio2/src/main/java/com/blackducksoftware/bdio2/model/LicenseGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.model; 17 | 18 | import javax.annotation.Nullable; 19 | 20 | import com.blackducksoftware.bdio2.Bdio; 21 | import com.blackducksoftware.bdio2.BdioObject; 22 | 23 | public class LicenseGroup extends BdioObject { 24 | 25 | public LicenseGroup() { 26 | super(Bdio.Class.LicenseGroup); 27 | } 28 | 29 | public LicenseGroup description(@Nullable Annotation description) { 30 | putFieldValue(Bdio.ObjectProperty.description, description); 31 | return this; 32 | } 33 | 34 | public LicenseGroup license(@Nullable License license) { 35 | putFieldValue(Bdio.ObjectProperty.license, license); 36 | return this; 37 | } 38 | 39 | public LicenseGroup licenseConjunctive(@Nullable License license) { 40 | putFieldValue(Bdio.ObjectProperty.licenseConjunctive, license); 41 | return this; 42 | } 43 | 44 | public LicenseGroup licenseDisjunctive(@Nullable License license) { 45 | putFieldValue(Bdio.ObjectProperty.licenseDisjunctive, license); 46 | return this; 47 | } 48 | 49 | public LicenseGroup licenseOrLater(@Nullable License license) { 50 | putFieldValue(Bdio.ObjectProperty.licenseOrLater, license); 51 | return this; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /bdio2/src/main/java/com/blackducksoftware/bdio2/model/Note.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.model; 17 | 18 | import javax.annotation.Nullable; 19 | 20 | import com.blackducksoftware.bdio2.Bdio; 21 | import com.blackducksoftware.bdio2.BdioObject; 22 | 23 | public final class Note extends BdioObject { 24 | 25 | public Note() { 26 | super(Bdio.Class.Note); 27 | } 28 | 29 | public Note range(@Nullable String range) { 30 | putFieldValue(Bdio.DataProperty.range, range); 31 | return this; 32 | } 33 | 34 | public Note rights(@Nullable String rights) { 35 | putFieldValue(Bdio.DataProperty.rights, rights); 36 | return this; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /bdio2/src/main/java/com/blackducksoftware/bdio2/model/Repository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.model; 17 | 18 | import javax.annotation.Nullable; 19 | 20 | import com.blackducksoftware.bdio2.Bdio; 21 | import com.blackducksoftware.bdio2.BdioObject; 22 | import com.blackducksoftware.common.value.ProductList; 23 | 24 | public final class Repository extends BdioObject { 25 | 26 | public Repository(String id) { 27 | super(id, Bdio.Class.Repository); 28 | } 29 | 30 | public Repository description(@Nullable Annotation description) { 31 | putFieldValue(Bdio.ObjectProperty.description, description); 32 | return this; 33 | } 34 | 35 | public Repository name(@Nullable String name) { 36 | putFieldValue(Bdio.DataProperty.name, name); 37 | return this; 38 | } 39 | 40 | public Repository base(@Nullable File base) { 41 | putFieldValue(Bdio.ObjectProperty.base, base); 42 | return this; 43 | } 44 | 45 | public Repository dependency(Dependency dependency) { 46 | putFieldValue(Bdio.ObjectProperty.dependency, dependency); 47 | return this; 48 | } 49 | 50 | public Repository namespace(@Nullable String namespace) { 51 | putFieldValue(Bdio.DataProperty.namespace, namespace); 52 | return this; 53 | } 54 | 55 | public Repository context(@Nullable String context) { 56 | putFieldValue(Bdio.DataProperty.context, context); 57 | return this; 58 | } 59 | 60 | public Repository resolver(@Nullable ProductList resolver) { 61 | putFieldValue(Bdio.DataProperty.resolver, resolver); 62 | return this; 63 | } 64 | 65 | public Repository platform(@Nullable ProductList platform) { 66 | putFieldValue(Bdio.DataProperty.platform, platform); 67 | return this; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /bdio2/src/main/java/com/blackducksoftware/bdio2/model/Vulnerability.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2.model; 17 | 18 | import java.time.ZonedDateTime; 19 | 20 | import javax.annotation.Nullable; 21 | 22 | import com.blackducksoftware.bdio2.Bdio; 23 | import com.blackducksoftware.bdio2.BdioObject; 24 | import com.blackducksoftware.common.value.ProductList; 25 | 26 | public final class Vulnerability extends BdioObject { 27 | 28 | public Vulnerability(String id) { 29 | super(id, Bdio.Class.Vulnerability); 30 | } 31 | 32 | public Vulnerability affected(@Nullable Object affected) { 33 | putFieldValue(Bdio.ObjectProperty.affected, affected); 34 | return this; 35 | } 36 | 37 | public Vulnerability canonical(@Nullable Vulnerability canonical) { 38 | putFieldValue(Bdio.ObjectProperty.canonical, canonical); 39 | return this; 40 | } 41 | 42 | public Vulnerability description(@Nullable Annotation description) { 43 | putFieldValue(Bdio.ObjectProperty.description, description); 44 | return this; 45 | } 46 | 47 | public Vulnerability name(@Nullable String name) { 48 | putFieldValue(Bdio.DataProperty.name, name); 49 | return this; 50 | } 51 | 52 | public Vulnerability namespace(@Nullable String namespace) { 53 | putFieldValue(Bdio.DataProperty.namespace, namespace); 54 | return this; 55 | } 56 | 57 | public Vulnerability creationDateTime(@Nullable ZonedDateTime creationDateTime) { 58 | putFieldValue(Bdio.DataProperty.creationDateTime, creationDateTime); 59 | return this; 60 | } 61 | 62 | public Vulnerability lastModifiedDateTime(ZonedDateTime lastModifiedDateTime) { 63 | putFieldValue(Bdio.DataProperty.lastModifiedDateTime, lastModifiedDateTime); 64 | return this; 65 | } 66 | 67 | public Vulnerability identifier(@Nullable String identifier) { 68 | putFieldValue(Bdio.DataProperty.identifier, identifier); 69 | return this; 70 | } 71 | 72 | public Vulnerability context(@Nullable String context) { 73 | putFieldValue(Bdio.DataProperty.context, context); 74 | return this; 75 | } 76 | 77 | public Vulnerability resolver(@Nullable ProductList resolver) { 78 | putFieldValue(Bdio.DataProperty.resolver, resolver); 79 | return this; 80 | } 81 | 82 | public Vulnerability platform(@Nullable ProductList platform) { 83 | putFieldValue(Bdio.DataProperty.platform, platform); 84 | return this; 85 | } 86 | 87 | public Vulnerability homepage(@Nullable String homepage) { 88 | putFieldValue(Bdio.DataProperty.homepage, homepage); 89 | return this; 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /bdio2/src/main/java/com/blackducksoftware/bdio2/model/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | package com.blackducksoftware.bdio2.model; 3 | 4 | import javax.annotation.ParametersAreNonnullByDefault; -------------------------------------------------------------------------------- /bdio2/src/main/java/com/blackducksoftware/bdio2/package-info.java: -------------------------------------------------------------------------------- 1 | @ParametersAreNonnullByDefault 2 | package com.blackducksoftware.bdio2; 3 | 4 | import javax.annotation.ParametersAreNonnullByDefault; -------------------------------------------------------------------------------- /bdio2/src/main/resources/com/blackducksoftware/bdio2/bdio-context-1.0.jsonld: -------------------------------------------------------------------------------- 1 | { 2 | "@context" : { 3 | "@vocab" : "http://blackducksoftware.com/rdf/terms#", 4 | "spdx" : "http://spdx.org/rdf/terms#", 5 | "doap" : "http://usefulinc.com/ns/doap#", 6 | "rdfs" : "http://www.w3.org/2000/01/rdf-schema#", 7 | "xsd" : "http://www.w3.org/2001/XMLSchema#", 8 | "size" : { 9 | "@type" : "xsd:long" 10 | }, 11 | "externalIdentifier" : { 12 | "@type" : "ExternalIdentifier" 13 | }, 14 | "externalSystemTypeId" : { 15 | "@type" : "@id" 16 | }, 17 | "matchDetail" : { 18 | "@type" : "MatchDetail" 19 | }, 20 | "matchType" : { 21 | "@type" : "@id" 22 | }, 23 | "name" : "doap:name", 24 | "homepage" : "doap:homepage", 25 | "revision" : "doap:revision", 26 | "licence" : { 27 | "@id" : "doap:license", 28 | "@type" : "@id" 29 | }, 30 | "fileName" : "spdx:fileName", 31 | "fileType" : { 32 | "@id" : "spdx:fileType", 33 | "@type" : "@id", 34 | "@container" : "@set" 35 | }, 36 | "checksumValue" : "spdx:checksumValue", 37 | "checksum" : { 38 | "@id" : "spdx:checksum", 39 | "@type" : "spdx:Checksum" 40 | }, 41 | "algorithm" : { 42 | "@id" : "spdx:algorithm", 43 | "@type" : "@id" 44 | }, 45 | "artifactOf" : { 46 | "@id" : "spdx:artifactOf", 47 | "@type" : "@id" 48 | }, 49 | "licenseConcluded" : { 50 | "@id" : "spdx:licenseConcluded", 51 | "@type" : "@id" 52 | }, 53 | "creationInfo" : { 54 | "@id" : "spdx:creationInfo", 55 | "@type" : "spdx:CreationInfo" 56 | }, 57 | "BD-Hub" : "externalIdentifier:_BD-Hub", 58 | "BD-Suite" : "externalIdentifier:_BD-Suite", 59 | "DEPENDENCY" : "matchType:_dependency", 60 | "PARTIAL" : "matchType:_partial", 61 | "DIRECTORY" : "fileType_directory", 62 | "ARCHIVE" : "fileType:_archive", 63 | "BINARY" : "fileType:_binary", 64 | "OTHER" : "fileType:_other", 65 | "SOURCE" : "fileType:_source", 66 | "sha1" : "checksum:Algorithm_sha1", 67 | "md5" : "checksum:Algorithm_md5" 68 | } 69 | } -------------------------------------------------------------------------------- /bdio2/src/main/resources/com/blackducksoftware/bdio2/bdio-context-1.1.1.jsonld: -------------------------------------------------------------------------------- 1 | { 2 | "@context" : { 3 | "@vocab" : "http://blackducksoftware.com/rdf/terms#", 4 | "spdx" : "http://spdx.org/rdf/terms#", 5 | "doap" : "http://usefulinc.com/ns/doap#", 6 | "rdfs" : "http://www.w3.org/2000/01/rdf-schema#", 7 | "xsd" : "http://www.w3.org/2001/XMLSchema#", 8 | "size" : { 9 | "@type" : "xsd:long" 10 | }, 11 | "externalIdentifier" : { 12 | "@type" : "ExternalIdentifier" 13 | }, 14 | "externalSystemTypeId" : { 15 | "@type" : "@id" 16 | }, 17 | "matchDetail" : { 18 | "@type" : "MatchDetail" 19 | }, 20 | "matchType" : { 21 | "@type" : "@id" 22 | }, 23 | "name" : "doap:name", 24 | "homepage" : "doap:homepage", 25 | "revision" : "doap:revision", 26 | "fileName" : "spdx:fileName", 27 | "fileType" : { 28 | "@id" : "spdx:fileType", 29 | "@type" : "@id", 30 | "@container" : "@set" 31 | }, 32 | "checksumValue" : "spdx:checksumValue", 33 | "checksum" : { 34 | "@id" : "spdx:checksum", 35 | "@type" : "spdx:Checksum" 36 | }, 37 | "algorithm" : { 38 | "@id" : "spdx:algorithm", 39 | "@type" : "@id" 40 | }, 41 | "artifactOf" : { 42 | "@id" : "spdx:artifactOf", 43 | "@type" : "@id" 44 | }, 45 | "licenseConcluded" : { 46 | "@id" : "spdx:licenseConcluded", 47 | "@type" : "@id" 48 | }, 49 | "creationInfo" : { 50 | "@id" : "spdx:creationInfo", 51 | "@type" : "spdx:CreationInfo" 52 | }, 53 | "DEPENDENCY" : "matchType:_dependency", 54 | "PARTIAL" : "matchType:_partial", 55 | "DIRECTORY" : "fileType_directory", 56 | "ARCHIVE" : "fileType:_archive", 57 | "BINARY" : "fileType:_binary", 58 | "OTHER" : "fileType:_other", 59 | "SOURCE" : "fileType:_source", 60 | "sha1" : "checksum:Algorithm_sha1", 61 | "md5" : "checksum:Algorithm_md5", 62 | "relationshipType" : { 63 | "@id" : "spdx:relationshipType", 64 | "@type" : "@id" 65 | }, 66 | "relationship" : { 67 | "@id" : "spdx:relationship", 68 | "@type" : "spdx:Relationship" 69 | }, 70 | "related" : { 71 | "@id" : "spdx:relatedSpdxElement", 72 | "@type" : "@id" 73 | }, 74 | "DYNAMIC_LINK" : "relationshipType:_dynamicLink", 75 | "anaconda" : "externalIdentifier:_anaconda", 76 | "bower" : "externalIdentifier:_bower", 77 | "cocoapods" : "externalIdentifier:_cocoapods", 78 | "cpan" : "externalIdentifier:_cpan", 79 | "goget" : "externalIdentifier:_goget", 80 | "maven" : "externalIdentifier:_maven", 81 | "npm" : "externalIdentifier:_npm", 82 | "nuget" : "externalIdentifier:_nuget", 83 | "rubygems" : "externalIdentifier:_rubygems", 84 | "bdhub" : "externalIdentifier:_bdhub", 85 | "bdsuite" : "externalIdentifier:_bdsuite", 86 | "license" : { 87 | "@id" : "doap:license", 88 | "@type" : "@id" 89 | } 90 | } 91 | } -------------------------------------------------------------------------------- /bdio2/src/main/resources/com/blackducksoftware/bdio2/bdio-context-1.1.jsonld: -------------------------------------------------------------------------------- 1 | { 2 | "@context" : { 3 | "@vocab" : "http://blackducksoftware.com/rdf/terms#", 4 | "spdx" : "http://spdx.org/rdf/terms#", 5 | "doap" : "http://usefulinc.com/ns/doap#", 6 | "rdfs" : "http://www.w3.org/2000/01/rdf-schema#", 7 | "xsd" : "http://www.w3.org/2001/XMLSchema#", 8 | "size" : { 9 | "@type" : "xsd:long" 10 | }, 11 | "externalIdentifier" : { 12 | "@type" : "ExternalIdentifier" 13 | }, 14 | "externalSystemTypeId" : { 15 | "@type" : "@id" 16 | }, 17 | "matchDetail" : { 18 | "@type" : "MatchDetail" 19 | }, 20 | "matchType" : { 21 | "@type" : "@id" 22 | }, 23 | "name" : "doap:name", 24 | "homepage" : "doap:homepage", 25 | "revision" : "doap:revision", 26 | "fileName" : "spdx:fileName", 27 | "fileType" : { 28 | "@id" : "spdx:fileType", 29 | "@type" : "@id", 30 | "@container" : "@set" 31 | }, 32 | "checksumValue" : "spdx:checksumValue", 33 | "checksum" : { 34 | "@id" : "spdx:checksum", 35 | "@type" : "spdx:Checksum" 36 | }, 37 | "algorithm" : { 38 | "@id" : "spdx:algorithm", 39 | "@type" : "@id" 40 | }, 41 | "artifactOf" : { 42 | "@id" : "spdx:artifactOf", 43 | "@type" : "@id" 44 | }, 45 | "licenseConcluded" : { 46 | "@id" : "spdx:licenseConcluded", 47 | "@type" : "@id" 48 | }, 49 | "creationInfo" : { 50 | "@id" : "spdx:creationInfo", 51 | "@type" : "spdx:CreationInfo" 52 | }, 53 | "DEPENDENCY" : "matchType:_dependency", 54 | "PARTIAL" : "matchType:_partial", 55 | "DIRECTORY" : "fileType_directory", 56 | "ARCHIVE" : "fileType:_archive", 57 | "BINARY" : "fileType:_binary", 58 | "OTHER" : "fileType:_other", 59 | "SOURCE" : "fileType:_source", 60 | "sha1" : "checksum:Algorithm_sha1", 61 | "md5" : "checksum:Algorithm_md5", 62 | "relationshipType" : { 63 | "@id" : "spdx:relationshipType", 64 | "@type" : "@id" 65 | }, 66 | "relationship" : { 67 | "@id" : "spdx:relationship", 68 | "@type" : "spdx:Relationship" 69 | }, 70 | "related" : { 71 | "@id" : "spdx:relatedSpdxElement", 72 | "@type" : "@id" 73 | }, 74 | "DYNAMIC_LINK" : "relationshipType:_dynamicLink", 75 | "anaconda" : "externalIdentifier:_anaconda", 76 | "bower" : "externalIdentifier:_bower", 77 | "cpan" : "externalIdentifier:_cpan", 78 | "goget" : "externalIdentifier:_goget", 79 | "maven" : "externalIdentifier:_maven", 80 | "npm" : "externalIdentifier:_npm", 81 | "nuget" : "externalIdentifier:_nuget", 82 | "rubygems" : "externalIdentifier:_rubygems", 83 | "bdhub" : "externalIdentifier:_bdhub", 84 | "bdsuite" : "externalIdentifier:_bdsuite", 85 | "license" : { 86 | "@id" : "doap:license", 87 | "@type" : "@id" 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /bdio2/src/test/java/com/blackducksoftware/bdio2/BdioDataModelSortOrderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2; 17 | 18 | import static com.blackducksoftware.common.base.ExtraStreams.stream; 19 | import static com.google.common.truth.Truth.assertThat; 20 | import static java.util.stream.Collectors.toList; 21 | 22 | import java.util.stream.Stream; 23 | 24 | import org.junit.Test; 25 | 26 | import com.google.common.base.Enums; 27 | 28 | /** 29 | * Try keeping the code clean by keeping things sorted alphabetically. 30 | * 31 | * @author jgustie 32 | */ 33 | public class BdioDataModelSortOrderTest { 34 | 35 | @Test 36 | public void bdioClassOrdering() { 37 | assertThat(stream(Bdio.Class.class).map(Bdio.Class::name).collect(toList())).isOrdered(); 38 | } 39 | 40 | @Test 41 | public void bdioObjectPropertyOrdering() { 42 | assertThat(stream(Bdio.ObjectProperty.class).map(Bdio.ObjectProperty::name).collect(toList())).isOrdered(); 43 | } 44 | 45 | @Test 46 | public void bdioDataPropertyOrdering() { 47 | assertThat(stream(Bdio.DataProperty.class).map(Bdio.DataProperty::name).collect(toList())).isOrdered(); 48 | } 49 | 50 | @Test 51 | public void bdioDatatypeOrdering() { 52 | assertThat(stream(Bdio.Datatype.class).map(Bdio.Datatype::name).collect(toList())).isOrdered(); 53 | } 54 | 55 | @Test 56 | public void bdioObjectPropertyAllowOnOrdering() { 57 | for (Bdio.ObjectProperty objectProperty : Bdio.ObjectProperty.values()) { 58 | assertThat(Stream.of(Enums.getField(objectProperty).getAnnotation(Bdio.Domain.class).value()).map(Bdio.Class::name).collect(toList())) 59 | .named(objectProperty.name()).isOrdered(); 60 | } 61 | } 62 | 63 | @Test 64 | public void bdioDataPropertyAllowOnOrdering() { 65 | for (Bdio.DataProperty dataProperty : Bdio.DataProperty.values()) { 66 | assertThat(Stream.of(Enums.getField(dataProperty).getAnnotation(Bdio.Domain.class).value()).map(Bdio.Class::name).collect(toList())) 67 | .named(dataProperty.name()).isOrdered(); 68 | } 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /bdio2/src/test/java/com/blackducksoftware/bdio2/BdioEmitterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2; 17 | 18 | import static com.blackducksoftware.bdio2.test.BdioTest.zipBytes; 19 | import static org.mockito.Matchers.any; 20 | import static org.mockito.Mockito.verify; 21 | import static org.mockito.Mockito.verifyNoMoreInteractions; 22 | 23 | import org.junit.Before; 24 | import org.junit.Test; 25 | import org.mockito.Mock; 26 | import org.mockito.MockitoAnnotations; 27 | import org.reactivestreams.Subscriber; 28 | 29 | import com.fasterxml.jackson.core.JsonParseException; 30 | import com.google.common.collect.Lists; 31 | 32 | /** 33 | * Tests for {@link BdioEmitter}. 34 | * 35 | * @author jgustie 36 | */ 37 | public class BdioEmitterTest { 38 | 39 | @Mock 40 | private Subscriber subscriber; 41 | 42 | @Before 43 | public void initMocks() { 44 | MockitoAnnotations.initMocks(this); 45 | } 46 | 47 | @Test 48 | public void readOne() { 49 | BdioEmitter emitter = new BdioEmitter(zipBytes("[ \"test\" ]")); 50 | try { 51 | emitter.emit(subscriber::onNext, subscriber::onError, subscriber::onComplete); 52 | verify(subscriber).onNext(Lists.newArrayList("test")); 53 | verifyNoMoreInteractions(subscriber); 54 | 55 | emitter.emit(subscriber::onNext, subscriber::onError, subscriber::onComplete); 56 | verify(subscriber).onComplete(); 57 | verifyNoMoreInteractions(subscriber); 58 | } finally { 59 | emitter.dispose(); 60 | } 61 | } 62 | 63 | @Test 64 | public void readSyntaxError() { 65 | BdioEmitter emitter = new BdioEmitter(zipBytes("I'm not JSON")); 66 | try { 67 | emitter.emit(subscriber::onNext, subscriber::onError, subscriber::onComplete); 68 | verify(subscriber).onError(any(JsonParseException.class)); 69 | verifyNoMoreInteractions(subscriber); 70 | } finally { 71 | emitter.dispose(); 72 | } 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /bdio2/src/test/java/com/blackducksoftware/bdio2/BdioTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Synopsys, Inc. 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 com.blackducksoftware.bdio2; 17 | 18 | import static com.google.common.truth.Truth.assertThat; 19 | 20 | import org.junit.Test; 21 | 22 | /** 23 | * Tests for {@code Bdio}. 24 | * 25 | * @author jgustie 26 | */ 27 | public class BdioTest { 28 | 29 | @Test 30 | public void contentType_forMediaType() { 31 | assertThat(Bdio.ContentType.forMediaType("application/ld+json")).isEqualTo(Bdio.ContentType.JSONLD); 32 | assertThat(Bdio.ContentType.forMediaType("application/json")).isEqualTo(Bdio.ContentType.JSON); 33 | assertThat(Bdio.ContentType.forMediaType("application/vnd.blackducksoftware.bdio+json")).isEqualTo(Bdio.ContentType.BDIO_JSON); 34 | assertThat(Bdio.ContentType.forMediaType("application/vnd.blackducksoftware.bdio+zip")).isEqualTo(Bdio.ContentType.BDIO_ZIP); 35 | } 36 | 37 | @Test 38 | public void contentType_forMediaType_charset_utf8() { 39 | assertThat(Bdio.ContentType.forMediaType("application/json; charset=UTF-8")).isEqualTo(Bdio.ContentType.JSON); 40 | } 41 | 42 | @Test(expected = IllegalArgumentException.class) 43 | public void contentType_forMediaType_charset_ascii() { 44 | Bdio.ContentType.forMediaType("application/json; charset=ASCII"); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /bdio2/src/test/java/com/blackducksoftware/bdio2/LegacyUtilitiesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Black Duck Software, Inc. 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 com.blackducksoftware.bdio2; 17 | 18 | import static com.google.common.truth.Truth.assertThat; 19 | 20 | import org.junit.Test; 21 | 22 | /** 23 | * Tests for {@code LegacyUtilities}. 24 | * 25 | * @author jgustie 26 | */ 27 | public class LegacyUtilitiesTest { 28 | 29 | @Test 30 | public void guessScheme() { 31 | // It would be nice to have parameterized tests :) 32 | String[][] data = new String[][] { 33 | { "Simple ZIP", "foobar.zip", "zip" }, 34 | { "Inner ZIP extension", "foobar.zip.foo", "zip" }, 35 | { "Case insensitive ZIP", "foobar.ZIP", "zip" }, 36 | { "Compressed TAR, separate extension", "foobar.tar.gz", "tar" }, 37 | { "Compressed TAR, combined extension", "foobar.tgz", "tar" }, 38 | { "Dot-dot", "foobar.zip..foo", "zip" }, 39 | { "Ignore file name", "zip.foo", "unknown" }, 40 | { "Ignore path", "foo.zip/bar.foo", "unknown" }, 41 | }; 42 | for (String[] testCase : data) { 43 | assertThat(LegacyUtilities.guessScheme(testCase[1])).named(testCase[0]).isEqualTo(testCase[2]); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { maven { url 'https://plugins.gradle.org/m2/' } } 3 | dependencies { 4 | classpath 'com.netflix.nebula:nebula-dependency-recommender:5.1.0' 5 | classpath 'com.netflix.nebula:nebula-publishing-plugin:17.3.2' 6 | classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.29.2' 7 | classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.18' 8 | } 9 | } 10 | 11 | allprojects { 12 | apply plugin: 'eclipse' 13 | apply plugin: 'nebula.dependency-recommender' 14 | apply plugin: "nebula.maven-publish" 15 | apply plugin: 'maven-publish' 16 | apply plugin: 'com.jfrog.artifactory' 17 | 18 | repositories { 19 | // jcenter() 20 | maven { 21 | url 'https://repo1.maven.org/maven2/' 22 | } 23 | maven { 24 | url 'https://jitpack.io' 25 | } 26 | maven { 27 | url 'https://artifactory.tools.duckutil.net/artifactory/jcenter-cache' 28 | } 29 | } 30 | 31 | dependencyRecommendations { 32 | strategy OverrideTransitives 33 | propertiesFile file: file("$rootDir/dependencies.properties") 34 | } 35 | } 36 | 37 | ext { 38 | productionBuild = System.properties['productionBuild'] == 'true' ? true : false 39 | uploadRepoKey = System.properties['uploadRepoKey'] ?: 'bds-bdio-snapshot' 40 | buildName = 'bdio' 41 | } 42 | 43 | subprojects { 44 | apply plugin: 'java' 45 | apply plugin: 'nebula.source-jar' 46 | 47 | sourceCompatibility = JavaVersion.VERSION_1_8 48 | 49 | tasks.withType(JavaCompile) { 50 | options.compilerArgs << '-Xlint:all' 51 | } 52 | 53 | tasks.withType(AbstractArchiveTask) { 54 | preserveFileTimestamps = false 55 | reproducibleFileOrder = true 56 | } 57 | 58 | jar { 59 | manifest { 60 | attributes('Implementation-Title': "${-> project.description}", 61 | 'Implementation-Version': "${-> project.version}", 62 | 'Specification-Title': specTitle, 63 | 'Specification-Version': specVersion, 64 | 'Specification-Vendor': specVendor) 65 | } 66 | } 67 | 68 | publishing{ 69 | publications{ 70 | maven(MavenPublication){ 71 | from components.java 72 | artifact sourceJar 73 | } 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /dependencies.properties: -------------------------------------------------------------------------------- 1 | com.blackducksoftware.magpie:magpie = 0.6.0 2 | com.blackducksoftware.magpie:magpie-test = 0.6.0 3 | com.fasterxml.jackson.core:jackson-annotations = 2.15.0 4 | com.fasterxml.jackson.core:jackson-core = 2.15.0 5 | com.fasterxml.jackson.core:jackson-databind = 2.15.0 6 | com.github.jsonld-java:jsonld-java = 0.12.3 7 | com.google.code.findbugs:jsr305 = 2.0.3 8 | com.google.guava:guava=30.1.1-jre 9 | com.google.jimfs:jimfs = 1.1 10 | com.google.truth:truth = 0.40 11 | com.google.truth.extensions:truth-java8-extension = 0.40 12 | com.squareup.okhttp3:okhttp = 3.11.0 13 | # io.reactivex.rxjava2:rxjava = 2.1.9 14 | io.reactivex.rxjava3:rxjava = 3.1.8 15 | junit:junit = 4.12 16 | org.apache.tinkerpop:gremlin-core = 3.3.3 17 | org.apache.tinkerpop:tinkergraph-gremlin = 3.3.3 18 | org.apache.tinkerpop:gremlin-shaded=3.5.1 19 | org.flywaydb:flyway-core = 4.2.0 20 | org.mockito:mockito-core = 1.9.5 21 | org.reactivestreams:reactive-streams = 1.0.2 22 | org.slf4j:jcl-over-slf4j = 1.7.7 23 | org.slf4j:slf4j-api = 1.7.7 24 | org.slf4j:slf4j-log4j12 = 1.7.7 25 | org.slf4j:slf4j-nop = 1.7.7 26 | org.slf4j:slf4j-simple = 1.7.21 27 | org.umlg:sqlg-postgres = 1.5.2 28 | javax.activation:javax.activation-api=1.2.0 29 | commons-lang:commons-lang=2.6 30 | com.google.protobuf:protobuf-java=3.25.5 31 | -------------------------------------------------------------------------------- /docs/spec/00.Abstract.txt: -------------------------------------------------------------------------------- 1 | # 2.1 SPECIFICATION 2 | 3 | # Abstract 4 | Black Duck I/O defines a vocabulary and mechanism by which information about software can be transferred between solutions inside and outside of the Black Duck ecosystem. 5 | -------------------------------------------------------------------------------- /docs/spec/01.Introduction.txt: -------------------------------------------------------------------------------- 1 | # Introduction 2 | TODO 3 | 4 | ## Actors 5 | The actors in a BDIO system are the "producers", "publishers", "consumers" and "processors". Producers and consumers are concerned with the syntactical structure (e.g. "is the document well formatted according to the specification?"); while publishers and processors are concerned with the semantics of the data itself (e.g. "are all the file nodes connected to a project?"). 6 | -------------------------------------------------------------------------------- /docs/spec/AA.NamespaceRecommendations.txt: -------------------------------------------------------------------------------- 1 | # Appendix A: Namespace Recommendations 2 | It is impractical for this specification to absolutely define all of the available namespaces and their rules, they constantly change as new tools are introduced and as people remember how to use old tools. The following non-normative recommendations for publishers and processors serve only as a guideline to what could be implemented. These recommendations are subject to change and ultimately it is the responsibility of the publishers and processors to agree on the namespace values and the interpretation of the field values. 3 | 4 | TODO This section is under development in the Proposed Namespace Values area. 5 | -------------------------------------------------------------------------------- /docs/spec/AB.IdentifierGuidelines.txt: -------------------------------------------------------------------------------- 1 | # Appendix B: Identifier Guidelines 2 | Selection of proper identifiers is imperative to the proper construction of a BDIO data set. 3 | 4 | TODO Suggest identifiers to use in specific situations, include use of "mvn:" and "urn:uuid:" URIs; avoid "data:" and "about:"... 5 | -------------------------------------------------------------------------------- /docs/spec/AC.FileData.txt: -------------------------------------------------------------------------------- 1 | # Appendix C: File Data 2 | 3 | ## File System Types 4 | 5 | This section is normative. 6 | 7 | | File System Type | Description | 8 | |--------------------------|-------------| 9 | | `regular` | A regular file, typically of unknown content. | 10 | | `regular/binary` | A regular file with executable content. | 11 | | `regular/text` | A regular file with known text content. Should be accompanied by an encoding. | 12 | | `directory` | A directory entry which may or may not contain children. | 13 | | `directory/archive` | An archive which may or may not contain children. Can also be treated as a regular file. | 14 | | `symlink` | A symbolic link. Should be accompanied by a link target. | 15 | | `other/device/block` | A block device, like a drive. | 16 | | `other/device/character` | A character device, like a terminal. | 17 | | `other/door` | A door used for interprocess communication. | 18 | | `other/pipe` | A named pipe. | 19 | | `other/socket` | A socket. | 20 | | `other/whiteout` | A whiteout, or file removal in a layered file system. | 21 | 22 | NOTE: File system types are compared case-insensitively. 23 | 24 | 25 | ## Recommended Fingerprint Digest Algorithms 26 | 27 | | Algorithm | Expected Hex String Length | Description | 28 | |-----------|-----------------------------|-------------| 29 | | md5 | 32 | MD5 | 30 | | sha1 | 40 | SHA-1 | 31 | | sha256 | 64 | SHA-2, SHA-256 | 32 | 33 | NOTE: Algorithms are compared case-insensitively. 34 | 35 | 36 | ## Recommended File Path Archive Schemes 37 | 38 | | Scheme | Slash Required | Description | 39 | |-----------|----------------|-------------| 40 | | `zip` | No | ZIP | 41 | | `jar` | No | Java Archive | 42 | | `tar` | No | Tape Archive | 43 | | `rpm` | No | RPM Package Manager | 44 | | `ar` | No | Unix archiver | 45 | | `arj` | No | ARJ archives | 46 | | `cpio` | No | Copy in and out | 47 | | `dump` | No | Unix dump | 48 | | `sevenz` | No | 7-Zip | 49 | | `rar` | Yes | Roshal Archive | 50 | | `xar` | Yes | Extensible Archive | 51 | | `phar` | Yes | PHP Archive | 52 | | `cab` | Yes | Cabinet | 53 | | `unknown` | Yes | Used when the actual scheme is not known | 54 | 55 | NOTE: File extensions and/or compression formats are not accounted for using the scheme, e.g. a file with the extension ".tgz" or ".tar.gz" still has a scheme of "tar". 56 | 57 | -------------------------------------------------------------------------------- /docs/spec/AD.ContentTypes.txt: -------------------------------------------------------------------------------- 1 | # Appendix D: Content Types 2 | 3 | | Content Type | Extension | Description | 4 | |-----------------------------------------------|-----------|-------------| 5 | | `application/ld+json` | `jsonld` | The content type used when BDIO data is represented using JSON-LD. The context will either be referenced as a remote document or will be explicitly included in the content body. Note that only UTF-8 character encoding is allowed. | 6 | | `application/json` | `json` | The content type used when BDIO data is represented using plain JSON and the context is specified externally (e.g. using the `Link` header). Note that only UTF-8 character encoding is allowed. | 7 | | `application/vnd.blackducksoftware.bdio+json` | `json` | The content type used when BDIO data is represented using plain JSON that should be interpreted using the default BDIO context. | 8 | | `application/vnd.blackducksoftware.bdio+zip` | `bdio` | The content type used when BDIO data is represented as self-contained JSON-LD stored in a ZIP archive. | 9 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | group=com.blackducksoftware.bdio 2 | version=4.0.1-SNAPSHOT 3 | description=Black Duck I/O Project 4 | 5 | specVersion=2.1.0-beta 6 | specTitle=Black Duck I/O 7 | specVendor=Synopsys, Inc. 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blackducksoftware/bdio/cb631d8b49b992d9ad73a9d3e5262d8c7b789901/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip 6 | -------------------------------------------------------------------------------- /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= 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 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'bdio' 2 | include 'bdio2', 'bdio-reactor', 'bdio-rxjava', 'bdio-tinkerpop', 'bdio-tool', 'bdio-test', 'bdio-protobuf' 3 | --------------------------------------------------------------------------------