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

[tycho-4.0.x] Add workaround for multiple calls of repo mojo using wrong URL #2699

Merged
merged 1 commit into from
Aug 3, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*******************************************************************************/
package org.eclipse.tycho.repository.plugin;

import static aQute.bnd.osgi.Constants.MIME_TYPE_BUNDLE;

import java.io.File;
import java.io.IOException;
import java.net.URI;
Expand All @@ -27,10 +29,13 @@
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.eclipse.tycho.MavenArtifactNamespace;
import org.eclipse.tycho.packaging.RepositoryGenerator;
import org.osgi.resource.Resource;

import aQute.bnd.osgi.Domain;
import aQute.bnd.osgi.repository.XMLResourceGenerator;
import aQute.bnd.osgi.resource.CapReqBuilder;
import aQute.bnd.osgi.resource.ResourceBuilder;
import aQute.libg.cryptography.SHA256;

@Component(role = RepositoryGenerator.class, hint = OSGiRepositoryGenerator.HINT)
public class OSGiRepositoryGenerator implements RepositoryGenerator {
Expand All @@ -44,8 +49,7 @@ public File createRepository(List<MavenProject> projects, RepositoryConfiguratio
resourceGenerator.name(repoConfig.getRepositoryName());
File folder;
PlexusConfiguration generatorConfig = repoConfig.getConfiguration();
String repositoryFileName = generatorConfig.getChild("repositoryFileName")
.getValue("repository.xml");
String repositoryFileName = generatorConfig.getChild("repositoryFileName").getValue("repository.xml");
if (repoConfig.getLayout() == RepositoryLayout.local) {
String folderName = generatorConfig.getChild("repositoryFolderName")
.getValue(FilenameUtils.getBaseName(repositoryFileName));
Expand All @@ -67,14 +71,17 @@ public File createRepository(List<MavenProject> projects, RepositoryConfiguratio
} else {
uri = new File(folder, file.getName()).toURI();
}
if (rb.addFile(project.getArtifact().getFile(), uri)) {

Resource resource = getResourceFromFile(file, uri);
if (resource != null) {
log.info("Adding " + project.getId());
rb.addResource(resource);
CapReqBuilder identity = new CapReqBuilder(MavenArtifactNamespace.MAVEN_ARTIFACT_NAMESPACE)
.addAttribute(MavenArtifactNamespace.CAPABILITY_GROUP_ATTRIBUTE, project.getGroupId())
.addAttribute(MavenArtifactNamespace.MAVEN_ARTIFACT_NAMESPACE, project.getArtifactId())
.addAttribute(MavenArtifactNamespace.CAPABILITY_VERSION_ATTRIBUTE, project.getVersion());
rb.addCapability(identity);
resourceGenerator.resource(rb.build());
log.info("Adding " + project.getId());
if (folder != null) {
FileUtils.copyFileToDirectory(file, folder);
}
Expand All @@ -96,4 +103,14 @@ public File createRepository(List<MavenProject> projects, RepositoryConfiguratio
}
}

private Resource getResourceFromFile(File file, URI uri) throws Exception {
ResourceBuilder rb = new ResourceBuilder();
Domain manifest = Domain.domain(file);
if (manifest != null && rb.addManifest(manifest)) {
rb.addContentCapability(uri, SHA256.digest(file).asHex(), file.length(), MIME_TYPE_BUNDLE);
return rb.build();
}
return null;
}

}