Skip to content

Commit

Permalink
Merge branch 'release/1.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jesse-gallagher committed Jan 27, 2023
2 parents 0fccb1c + 04e60a7 commit e9aa52e
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 57 deletions.
9 changes: 9 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
P2 Maven Resolver
Copyright 2019-2023 Jesse Gallagher and others
https://github.com/OpenNTF/p2-layout-provider/graphs/contributors

This product is licensed under the terms of the Apache 2.0 license.

The project contains the following third-party code:

1) Portions of IBM Commons, available from https://github.com/OpenNTF/SocialSDK and licensed under the Apache 2.0 license
30 changes: 25 additions & 5 deletions p2-layout-resolver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.openntf.maven</groupId>
<artifactId>p2-layout-resolver</artifactId>
<version>1.5.0</version>
<version>1.6.0</version>
<packaging>maven-plugin</packaging>

<name>p2 Repository Resolver</name>
Expand Down Expand Up @@ -62,9 +62,9 @@

<!-- General utilities -->
<dependency>
<groupId>com.ibm.sbt</groupId>
<artifactId>com.ibm.commons</artifactId>
<version>9.0.0</version>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>

<!-- OSGi processing -->
Expand Down Expand Up @@ -92,6 +92,26 @@
<artifactId>xz</artifactId>
<version>1.9</version>
</dependency>

<!-- Testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -167,7 +187,7 @@
<exclude>**/odp/**</exclude>
</excludes>
<properties>
<owner>Jesse Gallagher</owner>
<owner>Contributors to the P2 Layout Resolver Project</owner>
<copyrightYear>2023</copyrightYear>
</properties>
<mapping>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright © 2019-2023 Jesse Gallagher
* Copyright © 2019-2023 Contributors to the P2 Layout Resolver Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright © 2019-2023 Jesse Gallagher
* Copyright © 2019-2023 Contributors to the P2 Layout Resolver Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,6 +34,7 @@
import java.util.concurrent.TimeUnit;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.spi.connector.ArtifactDownload;
Expand All @@ -52,8 +53,6 @@
import org.openntf.maven.p2.layout.P2RepositoryLayout;
import org.openntf.maven.p2.util.P2Util;

import com.ibm.commons.util.StringUtil;

public class P2RepositoryConnector implements RepositoryConnector {
private final Logger log;

Expand Down Expand Up @@ -199,7 +198,7 @@ private void verifyChecksum(Path artifactPath, Path checksumPath, String algorit
String checksum = new String(Files.readAllBytes(checksumPath));
DigestUtils digest = new DigestUtils(algorithm);
String fileChecksum = digest.digestAsHex(artifactPath.toFile());
if(!StringUtil.equals(checksum, fileChecksum)) {
if(!StringUtils.equals(checksum, fileChecksum)) {
throw new ChecksumFailureException(MessageFormat.format(
Messages.getString("P2RepositoryConnector.checksumMismatch"), artifactPath, //$NON-NLS-1$
algorithm, checksum, fileChecksum));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright © 2019-2023 Jesse Gallagher
* Copyright © 2019-2023 Contributors to the P2 Layout Resolver Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright © 2019-2023 Jesse Gallagher
* Copyright © 2019-2023 Contributors to the P2 Layout Resolver Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,6 +40,7 @@

import javax.xml.parsers.ParserConfigurationException;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.metadata.Metadata;
import org.eclipse.aether.spi.connector.layout.RepositoryLayout;
Expand All @@ -56,8 +57,6 @@
import org.osgi.framework.VersionRange;
import org.xml.sax.SAXException;

import com.ibm.commons.util.StringUtil;

public class P2RepositoryLayout implements RepositoryLayout, Closeable {
private final Logger log;

Expand Down Expand Up @@ -102,7 +101,7 @@ public URI getLocation(Artifact artifact, boolean upload) {
}
case "jar": { //$NON-NLS-1$
// Check for classifier
switch(StringUtil.toString(artifact.getClassifier())) {
switch(StringUtils.defaultString(artifact.getClassifier())) {
case "sources": { //$NON-NLS-1$
return findBundle(artifact.getArtifactId(), artifact.getVersion())
.map(bundle -> bundle.getUri("source")) //$NON-NLS-1$
Expand Down Expand Up @@ -162,7 +161,7 @@ public List<Checksum> getChecksums(Artifact artifact, boolean upload, URI locati
return null;
}
return this.checksums.computeIfAbsent(artifact, key -> {
if(!"jar".equals(key.getExtension()) || StringUtil.isNotEmpty(artifact.getClassifier())) { //$NON-NLS-1$
if(!"jar".equals(key.getExtension()) || StringUtils.isNotEmpty(artifact.getClassifier())) { //$NON-NLS-1$
return Collections.emptyList();
}

Expand Down Expand Up @@ -293,36 +292,36 @@ private Path getPom(Artifact artifact) {
private static void addBundleMetadata(XMLNode project, P2BundleManifest manifest) {
XMLDocument xml = project.getOwnerDocument();
String bundleName = manifest.get("Bundle-Name"); //$NON-NLS-1$
if(StringUtil.isNotEmpty(bundleName)) {
if(StringUtils.isNotEmpty(bundleName)) {
project.addChildElement("name").setTextContent(bundleName); //$NON-NLS-1$
}
String bundleDescription = manifest.get("Bundle-Description"); //$NON-NLS-1$
if(StringUtil.isNotEmpty(bundleDescription)) {
if(StringUtils.isNotEmpty(bundleDescription)) {
project.addChildElement("description").setTextContent(bundleDescription); //$NON-NLS-1$
}
String bundleLicense = manifest.get("Bundle-License"); //$NON-NLS-1$
if(StringUtil.isNotEmpty(bundleLicense)) {
if(StringUtils.isNotEmpty(bundleLicense)) {
XMLNode licenses = project.addChildElement("licenses"); //$NON-NLS-1$
XMLNode license = licenses.addChildElement("license"); //$NON-NLS-1$
license.addChildElement("url").setTextContent(bundleLicense); //$NON-NLS-1$
}
String bundleVendor = manifest.get("Bundle-Vendor"); //$NON-NLS-1$
if(StringUtil.isNotEmpty(bundleVendor)) {
if(StringUtils.isNotEmpty(bundleVendor)) {
XMLNode organization = project.addChildElement("organization"); //$NON-NLS-1$
organization.addChildElement("name").setTextContent(bundleVendor); //$NON-NLS-1$
}
String bundleCopyright = manifest.get("Bundle-Copyright"); //$NON-NLS-1$
if(StringUtil.isNotEmpty(bundleCopyright)) {
if(StringUtils.isNotEmpty(bundleCopyright)) {
project.appendChild(xml.createComment(MessageFormat.format(Messages.getString("P2RepositoryLayout.copyrightComment"), bundleCopyright))); //$NON-NLS-1$
}
String bundleDocUrl = manifest.get("Bundle-DocURL"); //$NON-NLS-1$
if(StringUtil.isNotEmpty(bundleDocUrl)) {
if(StringUtils.isNotEmpty(bundleDocUrl)) {
project.addChildElement("url").setTextContent(bundleDocUrl); //$NON-NLS-1$
}
String sourceRef = manifest.get("Eclipse-SourceReferences"); //$NON-NLS-1$
if(StringUtil.isNotEmpty(sourceRef)) {
if(StringUtils.isNotEmpty(sourceRef)) {
// Only use the first
sourceRef = StringUtil.splitString(sourceRef, ',')[0];
sourceRef = StringUtils.split(sourceRef, ',')[0];
XMLNode scm = project.addChildElement("scm"); //$NON-NLS-1$
scm.addChildElement("url").setTextContent(sourceRef); //$NON-NLS-1$
}
Expand All @@ -332,17 +331,17 @@ private void addBundleDependencies(XMLNode project, Artifact artifact, P2BundleM
XMLNode dependencies = null;

String requireBundle = manifest.get("Require-Bundle"); //$NON-NLS-1$
if(StringUtil.isNotEmpty(requireBundle)) {
if(StringUtils.isNotEmpty(requireBundle)) {
dependencies = project.addChildElement("dependencies"); //$NON-NLS-1$

try {
for(ManifestElement el : ManifestElement.parseHeader("Require-Bundle", requireBundle)) { //$NON-NLS-1$
String bundleName = el.getValue();
String v = el.getAttribute("bundle-version"); //$NON-NLS-1$
VersionRange versionRange = StringUtil.isEmpty(v) ? null : new VersionRange(v);
VersionRange versionRange = StringUtils.isEmpty(v) ? null : new VersionRange(v);

P2Bundle dep = this.p2Repo.getBundles().stream()
.filter(bundle -> StringUtil.equals(bundleName, bundle.getId()))
.filter(bundle -> StringUtils.equals(bundleName, bundle.getId()))
.filter(bundle -> versionRange == null || versionRange.includes(new Version(bundle.getVersion())))
.findFirst()
.orElse(null);
Expand All @@ -361,14 +360,14 @@ private void addBundleDependencies(XMLNode project, Artifact artifact, P2BundleM
Path localJar = getLocalJar(artifact, true).orElse(null);
if(localJar != null) {
String bundleClassPath = manifest.get("Bundle-ClassPath"); //$NON-NLS-1$
if(StringUtil.isNotEmpty(bundleClassPath)) {
if(StringUtils.isNotEmpty(bundleClassPath)) {
if(dependencies == null) {
dependencies = project.addChildElement("dependencies"); //$NON-NLS-1$
}
try {
for(ManifestElement el : ManifestElement.parseHeader("Bundle-ClassPath", bundleClassPath)) { //$NON-NLS-1$
String cpName = el.getValue();
if(StringUtil.isEmpty(cpName) || ".".equals(cpName)) { //$NON-NLS-1$
if(StringUtils.isEmpty(cpName) || ".".equals(cpName)) { //$NON-NLS-1$
continue;
}

Expand Down Expand Up @@ -436,13 +435,13 @@ private Path getMetadata(Metadata metadata) {

private List<P2Bundle> findBundles(String artifactId) {
return this.p2Repo.getBundles().stream()
.filter(bundle -> StringUtil.equals(bundle.getId(), artifactId))
.filter(bundle -> StringUtils.equals(bundle.getId(), artifactId))
.collect(Collectors.toList());
}

private Optional<P2Bundle> findBundle(String artifactId, String version) {
return this.p2Repo.getBundles().stream()
.filter(bundle -> StringUtil.equals(bundle.getId(), artifactId))
.filter(bundle -> StringUtils.equals(bundle.getId(), artifactId))
.filter(bundle -> version == null || version.equals(bundle.getVersion()))
.findFirst();
}
Expand Down Expand Up @@ -470,7 +469,7 @@ private Optional<Path> getLocalJar(Artifact artifact, boolean ignoreClassifier)
private String toFileName(Artifact artifact, boolean ignoreClassifier) {
StringBuilder builder = new StringBuilder();
builder.append(artifact.getArtifactId());
if(!ignoreClassifier && StringUtil.isNotEmpty(artifact.getClassifier())) {
if(!ignoreClassifier && StringUtils.isNotEmpty(artifact.getClassifier())) {
builder.append("."); //$NON-NLS-1$
if("sources".equals(artifact.getClassifier())) { //$NON-NLS-1$
builder.append("source"); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright © 2019-2023 Jesse Gallagher
* Copyright © 2019-2023 Contributors to the P2 Layout Resolver Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright © 2019-2023 Jesse Gallagher
* Copyright © 2019-2023 Contributors to the P2 Layout Resolver Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,10 +20,9 @@
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.openntf.maven.p2.util.xml.XMLNode;

import com.ibm.commons.util.StringUtil;

/**
* Represents a bundle entry inside of a P2 repository, based on the containing
* artifacts.xml.
Expand Down Expand Up @@ -77,7 +76,7 @@ public URI getUri(String classifier) {
result.append(this.id);
if("sources".equals(classifier)) { //$NON-NLS-1$
result.append(".source"); //$NON-NLS-1$
} else if(StringUtil.isNotEmpty(classifier)) {
} else if(StringUtils.isNotEmpty(classifier)) {
result.append('.');
result.append(classifier);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright © 2019-2023 Jesse Gallagher
* Copyright © 2019-2023 Contributors to the P2 Layout Resolver Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,7 +26,7 @@
import java.util.jar.JarFile;
import java.util.jar.Manifest;

import com.ibm.commons.util.StringUtil;
import org.apache.commons.lang3.StringUtils;

/**
* Basic representation of a bundle manifest from a provided {@link Path}, including
Expand Down Expand Up @@ -56,13 +56,13 @@ public P2BundleManifest(Path path) {

// Check for a Bundle-Localization header
String locHeader = this.manifest.getMainAttributes().getValue("Bundle-Localization"); //$NON-NLS-1$
if(StringUtil.isEmpty(locHeader)) {
if(StringUtils.isEmpty(locHeader)) {
locHeader = "OSGI-INF/l10n/bundle"; // default when not otherwise specified //$NON-NLS-1$
}
Set<String> localeVariants = buildLocaleVariants();
for(String locale : localeVariants) {
String entryName;
if(StringUtil.isEmpty(locale)) {
if(StringUtils.isEmpty(locale)) {
entryName = locHeader + ".properties"; //$NON-NLS-1$
} else {
entryName = locHeader + "_" + locale + ".properties"; //$NON-NLS-1$ //$NON-NLS-2$
Expand All @@ -85,7 +85,7 @@ public P2BundleManifest(Path path) {

public String get(String headerName) {
String headerValue = this.manifest.getMainAttributes().getValue(headerName);
if(StringUtil.isNotEmpty(headerValue) && headerValue.startsWith("%") && headerValue.length() > 1) { //$NON-NLS-1$
if(StringUtils.isNotEmpty(headerValue) && headerValue.startsWith("%") && headerValue.length() > 1) { //$NON-NLS-1$
String localeProp = headerValue.substring(1);
return this.localization.getProperty(localeProp, localeProp);
} else {
Expand Down
Loading

0 comments on commit e9aa52e

Please sign in to comment.