Skip to content
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
198 changes: 198 additions & 0 deletions resources/javaTemplates/InvalidLicenseExpressionTemplate.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 Source Auditor Inc.
* SPDX-FileType: SOURCE
* SPDX-License-Identifier: Apache-2.0
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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}}.simplelicensing;

import org.spdx.core.DefaultModelStore;
import org.spdx.core.IModelCopyManager;
import org.spdx.core.IndividualUriValue;
import org.spdx.core.InvalidSPDXAnalysisException;
import org.spdx.library.model.{{versionSuffix}}.SpdxConstantsV3;
import org.spdx.library.model.{{versionSuffix}}.core.CreationInfo;
import org.spdx.storage.IModelStore;
import org.spdx.storage.PropertyDescriptor;

import javax.annotation.Nullable;

import java.util.*;
import java.util.regex.Pattern;

import static org.spdx.library.model.{{versionSuffix}}.SpdxConstantsV3.SIMPLE_LICENSING_NAMESPACE;

/**
* DO NOT EDIT - this file is generated by the Owl to Java Utility
* See: <a href="https://github.com/spdx/tools-java">tools-java</a>
* <p>
* Represents a license expression that can not be parsed
*/
public class InvalidLicenseExpression extends LicenseExpression {

public static final PropertyDescriptor MESSAGE_PROPERTY = new PropertyDescriptor("SimpleLicensing.invalidLicenseMessage", SIMPLE_LICENSING_NAMESPACE);
public static final String INVALID_LICENSE_EXPRESSION_TYPE = "SimpleLicensing.InvalidLicenseExpression";

/**
* Create the InvalidLicenseExpression with default model store and generated anonymous ID
* @throws InvalidSPDXAnalysisException when unable to create the LicenseExpression
*/
public InvalidLicenseExpression() throws InvalidSPDXAnalysisException {
super();
}

/**
* @param objectUri URI or anonymous ID for the LicenseExpression
* @throws InvalidSPDXAnalysisException when unable to create the LicenseExpression
*/
public InvalidLicenseExpression(String objectUri) throws InvalidSPDXAnalysisException {
this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(),
true, DefaultModelStore.getDefaultDocumentUri() + "#");
}

/**
* @param modelStore Model store where the LicenseExpression is to be stored
* @param objectUri URI or anonymous ID for the LicenseExpression
* @param copyManager Copy manager for the LicenseExpression - can be null if copying is not required
* @param create true if LicenseExpression is to be created
* @param idPrefix - prefix to be used when generating new SPDX IDs
* @throws InvalidSPDXAnalysisException when unable to create the LicenseExpression
*/
public InvalidLicenseExpression(IModelStore modelStore, String objectUri, @Nullable IModelCopyManager copyManager,
boolean create, String idPrefix) throws InvalidSPDXAnalysisException {
super(modelStore, objectUri, copyManager, create, idPrefix);
}

@Override
public String getType() {
return INVALID_LICENSE_EXPRESSION_TYPE;
}


// Getters and Setters

/**
* @param creationInfo the creationInfo to set
* @return this to chain setters
* @throws InvalidSPDXAnalysisException on model store exceptions
*/
@Override
public InvalidLicenseExpression setCreationInfo(@Nullable CreationInfo creationInfo) throws InvalidSPDXAnalysisException {
super.setCreationInfo(creationInfo);
return this;
}
/**
* @param summary the summary to set
* @return this to chain setters
* @throws InvalidSPDXAnalysisException on model store exceptions
*/
@Override
public InvalidLicenseExpression setSummary(@Nullable String summary) throws InvalidSPDXAnalysisException {
super.setSummary(summary);
return this;
}
/**
* @param description the description to set
* @return this to chain setters
* @throws InvalidSPDXAnalysisException on model store exceptions
*/
@Override
public InvalidLicenseExpression setDescription(@Nullable String description) throws InvalidSPDXAnalysisException {
super.setDescription(description);
return this;
}

/**
* @param licenseExpression the licenseExpression to set
* @return this to chain setters
* @throws InvalidSPDXAnalysisException on model store exceptions
*/
public InvalidLicenseExpression setLicenseExpression(@Nullable String licenseExpression) throws InvalidSPDXAnalysisException {
if (isStrict() && Objects.isNull(licenseExpression)) {
throw new InvalidSPDXAnalysisException("licenseExpression is a required property");
}
setPropertyValue(SpdxConstantsV3.PROP_LICENSE_EXPRESSION, licenseExpression);
return this;
}

/**
* @param licenseListVersion the licenseListVersion to set
* @return this to chain setters
* @throws InvalidSPDXAnalysisException on model store exceptions
*/
public InvalidLicenseExpression setLicenseListVersion(@Nullable String licenseListVersion) throws InvalidSPDXAnalysisException {
if (isStrict() && Objects.nonNull(licenseListVersion) && !Pattern.matches("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$", licenseListVersion)) {
throw new InvalidSPDXAnalysisException("licenseListVersion value '" + licenseListVersion +
"' does not match the pattern '^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$'");
}
setPropertyValue(SpdxConstantsV3.PROP_LICENSE_LIST_VERSION, licenseListVersion);
return this;
}
/**
* @param comment the comment to set
* @return this to chain setters
* @throws InvalidSPDXAnalysisException on model store exceptions
*/
@Override
public InvalidLicenseExpression setComment(@Nullable String comment) throws InvalidSPDXAnalysisException {
super.setComment(comment);
return this;
}
/**
* @param name the name to set
* @return this to chain setters
* @throws InvalidSPDXAnalysisException on model store exceptions
*/
@Override
public InvalidLicenseExpression setName(@Nullable String name) throws InvalidSPDXAnalysisException {
super.setName(name);
return this;
}

/**
* @return the licenseExpression
*/
public @Nullable String getMessage() throws InvalidSPDXAnalysisException {
Optional<String> retval = getStringPropertyValue(MESSAGE_PROPERTY);
return retval.orElse(null);
}
/**
* @param message the message to set
* @return this to chain setters
* @throws InvalidSPDXAnalysisException on invalid message
*/
public LicenseExpression setMessage(@Nullable String message) throws InvalidSPDXAnalysisException {
if (isStrict() && Objects.isNull(message)) {
throw new InvalidSPDXAnalysisException("Message is a required property");
}
setPropertyValue(MESSAGE_PROPERTY, message);
return this;
}

/* (non-Javadoc)
* @see org.spdx.library.model.v3.ModelObjectV3#_verify(java.util.List)
*/
@Override
public List<String> _verify(Set<String> verifiedIds, String specVersionForVerify, List<IndividualUriValue> profiles) {
List<String> retval = new ArrayList<>();
try {
retval.add(String.format("Invalid license expression '%s': %s",
getLicenseExpression(), getMessage()));
} catch(Exception e) {
retval.add(String.format("Error getting properties: %s", e.getMessage()));
}
return retval;
}
}
1 change: 1 addition & 0 deletions resources/javaTemplates/ModelClassFactoryTemplate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class SpdxModelClassFactoryV3 {
{{#typeToClass}}
typeToClassV3.put(SpdxConstantsV3.{{{classConstant}}}, {{{classPath}}}.class);
{{/typeToClass}}
typeToClassV3.put(org.spdx.library.model.{{versionSuffix}}.simplelicensing.InvalidLicenseExpression.INVALID_LICENSE_EXPRESSION_TYPE, org.spdx.library.model.{{versionSuffix}}.simplelicensing.InvalidLicenseExpression.class);

SPDX_TYPE_TO_CLASS_V3 = Collections.unmodifiableMap(typeToClassV3);

Expand Down
4 changes: 2 additions & 2 deletions resources/javaTemplates/PomTemplate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.spdx</groupId>
<artifactId>spdx-java-model-3_0</artifactId>
<version>1.0.0-RC2</version>
<version>1.0.1</version>
<name>spdx-java-model-3</name>
<description>Generated java model source code</description>
<url>https://github.com/spdx/spdx-java-model-3_0</url>
Expand Down Expand Up @@ -107,7 +107,7 @@
<dependency>
<groupId>org.spdx</groupId>
<artifactId>spdx-java-core</artifactId>
<version>1.0.0-RC2</version>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/org/spdx/tools/model2java/ShaclToJava.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ public List<String> generate(File dir) throws IOException, ShaclToJavaException
generateIndividualFactory(dir);
//TODO: Get the version from the SHACL file
generateMockFiles(dir);
generateInvalidLicenseExpression(dir);
return warnings;
}

Expand Down Expand Up @@ -474,6 +475,25 @@ private void generatePomFile(File dir) throws IOException {
writeMustacheFile(ShaclToJavaConstants.POM_TEMPLATE, file, new HashMap<>());
}

/**
* @param dir
* @throws IOException
*/
private void generateInvalidLicenseExpression(File dir) throws IOException {
Path path = dir.toPath().resolve("src").resolve("main").resolve("java").resolve("org")
.resolve("spdx").resolve("library").resolve("model").resolve(versionSuffix)
.resolve("simplelicensing");
Files.createDirectories(path);
File file = path.resolve("InvalidLicenseExpression.java").toFile();
if (!file.createNewFile()) {
throw new IOException(String.format("Unable to create %s", file.toString()));
}
Map<String, Object> mustacheMap = new HashMap<>();
mustacheMap.put("versionSuffix", versionSuffix);
mustacheMap.put("versionSemVer", versionSemVer);
writeMustacheFile(ShaclToJavaConstants.INVALID_LICENSE_EXPRESSION_TEMPLATE, file, mustacheMap);
}

/**
* @param dir
* @throws IOException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class ShaclToJavaConstants {
public static final String UNIT_TEST_HELPER_TEMPLATE = "UnitTestHelperTemplate.txt";
public static final String TEST_VALUES_GENERATOR_TEMPLATE = "TestValuesGeneratorTemplate.txt";
public static final String TEST_MODEL_INFO_TEMPLATE = "TestModelInfoTemplate.txt";
public static final String INVALID_LICENSE_EXPRESSION_TEMPLATE = "InvalidLicenseExpressionTemplate.txt";

public static Set<String> INTEGER_TYPES = new HashSet<>();
static {
Expand Down
Loading