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

DD-1492. Moved VersionProvider from dd-data-vault-cli. #15

Merged
merged 2 commits into from
Apr 15, 2024
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<relativePath />
</parent>
<artifactId>dans-java-utils</artifactId>
<version>0.11.1-SNAPSHOT</version>
<version>0.12.0-SNAPSHOT</version>
<name>DANS Java Utility Classes</name>
<inceptionYear>2021</inceptionYear>
<scm>
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/nl/knaw/dans/lib/util/CliVersionProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (C) 2021 DANS - Data Archiving and Networked Services (info@dans.knaw.nl)
*
* 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 nl.knaw.dans.lib.util;

import picocli.CommandLine.IVersionProvider;

public class CliVersionProvider implements IVersionProvider {
@Override
public String[] getVersion() throws Exception {
return new String[] { new VersionProvider().getVersion() };
}
}
18 changes: 17 additions & 1 deletion src/main/java/nl/knaw/dans/lib/util/UrnUuid.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,23 @@ public static UrnUuid fromString(String s) {
UUID.fromString(s.substring("urn:uuid:".length())); // throws IllegalArgumentException if not a valid UUID
return new UrnUuid(URI.create(s));
}


public static UrnUuid fromUri(URI uri) {
if (!uri.getScheme().equals("urn") || !uri.getSchemeSpecificPart().startsWith("uuid:")) {
throw new IllegalArgumentException("Not a URN UUID: " + uri);
}

// Check that the remainder is a valid UUID
try {
UUID.fromString(uri.getSchemeSpecificPart().substring("uuid:".length()));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Not a URN UUID: " + uri);
}

return new UrnUuid(uri);
}


@Override
public String toString() {
return urn.toString();
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/nl/knaw/dans/lib/util/VersionProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2021 DANS - Data Archiving and Networked Services (info@dans.knaw.nl)
*
* 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 nl.knaw.dans.lib.util;

import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

public class VersionProvider {
public String getVersion() throws IOException {
try (InputStream inputStream = getClass().getResourceAsStream("/version.txt")) {
if (inputStream != null) {
return IOUtils.toString(inputStream, StandardCharsets.UTF_8);
}
else {
throw new IllegalStateException("Version file not found");
}
}
}
}
Loading