Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SPDX file info header #14

Merged
merged 2 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# spdx-model-to-java
Generates Java source files from the SPDX spec version 3+ suitable for inclusion in the SPDX Java Library

Generates Java source files from the [SPDX spec version 3+][spdx-spec]
suitable for inclusion in the SPDX Java Library

[spdx-spec]: https://spdx.dev/use/specifications/

## Usage CLI

To run the utility as a command line interface, execute the main method `ShaclToJavaCli` with 2 parameters:

- model file in turtle format
- output directory


## Usage Library

To use the code as a library, the main entry point is the `ShaclToJava` class which takes a single parameter of the SPDX Ontology model.
Expand All @@ -18,4 +22,5 @@ The `generate(dir)` method will generate the Java files in the dir directory.

This is a utility specifically built and tested for use in the SPDX Java Library.
It is relatively stable for that purpose.
There are still a few items marked as TODO in the code and some of the generated code will produce warnings in Java linter (e.g. unused import statements).

There are still a few items marked as TODO in the code and some of the generated code will produce warnings in Java linter (e.g. unused import statements).
22 changes: 11 additions & 11 deletions resources/javaTemplates/BaseModelObjectTemplate.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* SPDX-FileCopyrightText: Copyright (c) {{{year}}} Source Auditor Inc.
* SPDX-FileType: SOURCE
* SPDX-License-Identifier: Apache-2.0
* Copyright (c) 2024 Source Auditor Inc.
*/
package org.spdx.library.model.{{versionSuffix}};

Expand Down Expand Up @@ -29,8 +30,9 @@ import org.spdx.storage.PropertyDescriptor;


/**
* @author Gary O'Neall
* Model object for SPDX 3
*
* @author Gary O'Neall
*/
public abstract class ModelObjectV3 extends CoreModelObject {

Expand All @@ -56,7 +58,7 @@ public abstract class ModelObjectV3 extends CoreModelObject {
* @param objectUri
* @param copyManager
* @param create
* @param idPrefix - prefix to be used when generating new SPDX IDs
* @param idPrefix prefix to be used when generating new SPDX IDs
* @throws InvalidSPDXAnalysisException
*/
public ModelObjectV3(IModelStore modelStore, String objectUri,
Expand All @@ -74,7 +76,6 @@ public abstract class ModelObjectV3 extends CoreModelObject {
super(builder, SpdxConstantsV3.MODEL_SPEC_VERSION);
}


/**
* @param specVersion Version of the SPDX spec to verify against
* @param verifiedElementUris list of all element object URIs which have already been verified - prevents infinite recursion
Expand Down Expand Up @@ -179,8 +180,7 @@ public abstract class ModelObjectV3 extends CoreModelObject {
throw new SpdxInvalidTypeException("Invalid type for ExtendableLicense property: "+result.get().getClass().toString());
}
}



/**
* Converts property values to an ExtendableLicense if possible
* @param propertyDescriptor descriptor for the property
Expand All @@ -207,7 +207,7 @@ public abstract class ModelObjectV3 extends CoreModelObject {
throw new SpdxInvalidTypeException("Invalid type for LicenseAddition property: "+result.get().getClass().toString());
}
}

/**
* Converts property values to an SpdxElement if possible - if individual value, convert to the appropriate SpdxElement
* @param propertyDescriptor Descriptor for the property
Expand All @@ -234,20 +234,20 @@ public abstract class ModelObjectV3 extends CoreModelObject {
throw new SpdxInvalidTypeException("Invalid type for SpdxElement property: "+result.get().getClass().toString());
}
}

/**
* @param propertyDescriptor property descriptor for the object in question
* @return true if the object is "to" part of a relationship
*/
public boolean isRelatedElement(PropertyDescriptor propertyDescriptor) {
return SpdxConstantsV3.PROP_TO.equals(propertyDescriptor);
}

{{#createBuilder}}
{{{.}}}

{{/createBuilder}}

public static class ModelObjectV3Builder extends CoreModelObjectBuilder {

/**
Expand Down
2 changes: 1 addition & 1 deletion resources/javaTemplates/CreateClassTemplate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
public {{{className}}}.{{{className}}}Builder create{{{className}}}(String objectUri) throws InvalidSPDXAnalysisException {
Objects.requireNonNull(objectUri, "objectUri can not be null");
return new {{{className}}}.{{{className}}}Builder(this, objectUri);
}
}
32 changes: 16 additions & 16 deletions resources/javaTemplates/ElementToStringTemplate.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
try {
StringBuilder sb = new StringBuilder();
Optional<String> name = getName();
if (name.isPresent()) {
sb.append(name.get());
} else {
sb.append("[Name Missing]");
}
sb.append(":");
sb.append(getType());
sb.append('(');
sb.append(getObjectUri());
sb.append(')');
return sb.toString();
} catch (InvalidSPDXAnalysisException e) {
return "Error: "+e.getMessage();
}
StringBuilder sb = new StringBuilder();
Optional<String> name = getName();
if (name.isPresent()) {
sb.append(name.get());
} else {
sb.append("[Name Missing]");
}
sb.append(":");
sb.append(getType());
sb.append('(');
sb.append(getObjectUri());
sb.append(')');
return sb.toString();
} catch (InvalidSPDXAnalysisException e) {
return "Error: "+e.getMessage();
}
17 changes: 2 additions & 15 deletions resources/javaTemplates/EnumTemplate.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
/**
* Copyright (c) {{{year}}} Source Auditor Inc.
*
* SPDX-FileCopyrightText: Copyright (c) {{{year}}} Source Auditor Inc.
* SPDX-FileType: SOURCE
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package {{{pkgName}}};

import org.spdx.core.IndividualUriValue;
Expand Down
19 changes: 3 additions & 16 deletions resources/javaTemplates/ExternalJavaClassTemplate.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
/**
* Copyright (c) {{{year}}} Source Auditor Inc.
*
* SPDX-FileCopyrightText: Copyright (c) {{{year}}} Source Auditor Inc.
* SPDX-FileType: SOURCE
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package {{{pkgName}}};

import org.spdx.storage.NullModelStore;
Expand All @@ -28,7 +15,7 @@ import org.spdx.core.IndividualUriValue;
* This is an external representation of {{{className}}} - nothing can be set and properties returned
* are not valid
*
**/
*/
public class External{{{className}}} extends {{{className}}} implements IndividualUriValue {

{{#objectPropertyValueCollection}}
Expand Down
17 changes: 2 additions & 15 deletions resources/javaTemplates/IndividualClassTemplate.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
/**
* Copyright (c) {{{year}}} Source Auditor Inc.
*
* SPDX-FileCopyrightText: Copyright (c) {{{year}}} Source Auditor Inc.
* SPDX-FileType: SOURCE
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package {{{pkgName}}};

{{#imports}}
Expand Down
17 changes: 2 additions & 15 deletions resources/javaTemplates/JavaClassTemplate.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
/**
* Copyright (c) {{{year}}} Source Auditor Inc.
*
* SPDX-FileCopyrightText: Copyright (c) {{{year}}} Source Auditor Inc.
* SPDX-FileType: SOURCE
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package {{{pkgName}}};

{{#imports}}
Expand Down
4 changes: 3 additions & 1 deletion resources/javaTemplates/LicenseSetEqualsOverrideTemplate.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/**
* Get flatten license set
*
* License sets can contain other conjunctive license sets as members. Logically,
* the members of these "sub-conjunctive license sets" could be direct members and have the same
* meaning.
Expand Down Expand Up @@ -121,4 +123,4 @@
}
}
return true;
}
}
3 changes: 2 additions & 1 deletion resources/javaTemplates/MockCopyManagerTemplate.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* SPDX-FileCopyrightText: Copyright (c) {{{year}}} Source Auditor Inc.
* SPDX-FileType: SOURCE
* SPDX-License-Identifier: Apache-2.0
* Copyright (c) 2024 Source Auditor Inc.
*/
package org.spdx.library.model.{{versionSuffix}};

Expand Down
3 changes: 2 additions & 1 deletion resources/javaTemplates/MockModelStoreTemplate.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* SPDX-FileCopyrightText: Copyright (c) {{{year}}} Source Auditor Inc.
* SPDX-FileType: SOURCE
* SPDX-License-Identifier: Apache-2.0
* Copyright (c) 2024 Source Auditor Inc.
*/
package org.spdx.library.model.{{versionSuffix}};

Expand Down
20 changes: 3 additions & 17 deletions resources/javaTemplates/ModelClassFactoryTemplate.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
/**
* Copyright (c) 2023 Source Auditor Inc.
*
* SPDX-FileCopyrightText: Copyright (c) {{{year}}} Source Auditor Inc.
* SPDX-FileType: SOURCE
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.spdx.library.model.{{versionSuffix}};
package org.spdx.library.model.{{versionSuffix}};

import org.spdx.core.IModelCopyManager;
import org.spdx.core.InvalidSPDXAnalysisException;
Expand Down Expand Up @@ -45,7 +32,6 @@ import javax.annotation.Nullable;
* The <code>getModelObject</code> method will fetch or create a model object based on the URI for the class
*
* @author Gary O'Neall
*
*/
public class SpdxModelClassFactoryV3 {

Expand Down
3 changes: 2 additions & 1 deletion resources/javaTemplates/ModelInfoTemplate.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* SPDX-FileCopyrightText: Copyright (c) {{{year}}} Source Auditor Inc.
* SPDX-FileType: SOURCE
* SPDX-License-Identifier: Apache-2.0
* Copyright (c) 2024 Source Auditor Inc.
*/
package org.spdx.library.model.{{versionSuffix}};

Expand Down
12 changes: 6 additions & 6 deletions resources/javaTemplates/OrLaterToStringTemplate.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
try {
String subjectLicense = Objects.nonNull(this.{{{subjectLicenseGetter}}}()) ?
this.{{{subjectLicenseGetter}}}().toString() : "[Missing Subject License]";
return subjectLicense + "+";
} catch (InvalidSPDXAnalysisException e) {
return "Error: "+e.getMessage();
}
String subjectLicense = Objects.nonNull(this.{{{subjectLicenseGetter}}}()) ?
this.{{{subjectLicenseGetter}}}().toString() : "[Missing Subject License]";
return subjectLicense + "+";
} catch (InvalidSPDXAnalysisException e) {
return "Error: " + e.getMessage();
}
7 changes: 4 additions & 3 deletions resources/javaTemplates/PackageInfoTemplate.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/**
* SPDX-FileCopyrightText: Copyright (c) {{{year}}} Source Auditor Inc.
* SPDX-FileType: SOURCE
* SPDX-License-Identifier: Apache-2.0
* Copyright (c) 2024 Source Auditor Inc.
*/

/**
* @author Gary O'Neall
*
* Version {{versionSemVer}} of the SPDX model
*
*/
package org.spdx.library.model.{{versionSuffix}};
package org.spdx.library.model.{{versionSuffix}};
17 changes: 2 additions & 15 deletions resources/javaTemplates/SpdxConstantsTemplate.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
/**
* Copyright (c) 2023 Source Auditor Inc.
*
* SPDX-FileCopyrightText: Copyright (c) {{{year}}} Source Auditor Inc.
* SPDX-FileType: SOURCE
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.spdx.library.model.{{versionSuffix}};

Expand All @@ -22,7 +10,6 @@ import org.spdx.storage.PropertyDescriptor;
/**
* Constants which map to the SPDX specifications
* @author Gary O'Neall
*
*/
public class SpdxConstantsV3 {

Expand Down
Loading