From 56ce9ed1e612b38b2fce53a7adcd4562c783087c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Thu, 17 Feb 2022 19:18:51 +0100 Subject: [PATCH] Fix #658 - preserve p2 artifact properties (eg PGP, maven info...) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christoph Läubrich --- .../org/eclipse/tycho/TychoConstants.java | 7 +- .../LocalArtifactRepositoryP2APITest.java | 11 +-- .../MirroringArtifactProviderErrorTest.java | 5 +- ...rtifactProviderPack200CornerCasesTest.java | 17 +++-- .../local/MirroringArtifactProviderTest.java | 9 ++- .../local/MirroringArtifactProvider.java | 73 +++++++++++++++---- ...PackedFormatMirroringArtifactProvider.java | 8 +- .../AbstractArtifactRepository2.java | 9 ++- .../ArtifactRepositoryBaseImpl.java | 7 +- .../ProviderOnlyArtifactRepository.java | 4 +- .../impl/publisher/MavenPropertiesAdvice.java | 23 ++++-- .../MavenTargetDefinitionContent.java | 4 +- .../p2/target/TargetPlatformFactoryImpl.java | 4 +- 13 files changed, 127 insertions(+), 54 deletions(-) diff --git a/tycho-bundles/org.eclipse.tycho.embedder.shared/src/main/java/org/eclipse/tycho/TychoConstants.java b/tycho-bundles/org.eclipse.tycho.embedder.shared/src/main/java/org/eclipse/tycho/TychoConstants.java index beb030d1ed..ba9ed386dc 100644 --- a/tycho-bundles/org.eclipse.tycho.embedder.shared/src/main/java/org/eclipse/tycho/TychoConstants.java +++ b/tycho-bundles/org.eclipse.tycho.embedder.shared/src/main/java/org/eclipse/tycho/TychoConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2021 Sonatype Inc. and others. + * Copyright (c) 2008, 2022 Sonatype Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Sonatype Inc. - initial API and implementation + * Christoph Läubrich - Issue #658 - Tycho strips p2 artifact properties (eg PGP, maven info...) *******************************************************************************/ package org.eclipse.tycho; @@ -49,6 +50,10 @@ public interface TychoConstants { String PROP_REPOSITORY = "maven-repository"; + String PROP_PGP_KEYS = "pgp.publicKeys"; + + String PROP_PGP_SIGNATURES = "pgp.signatures"; + /** * @deprecated this is deprecated but can't be removed as we otherwise loose compatibility for * older repository format, this should never be used in new code and usage should diff --git a/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/LocalArtifactRepositoryP2APITest.java b/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/LocalArtifactRepositoryP2APITest.java index 43eb9af913..22af9c3617 100644 --- a/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/LocalArtifactRepositoryP2APITest.java +++ b/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/LocalArtifactRepositoryP2APITest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2013 SAP SE and others. + * Copyright (c) 2012, 2022 SAP SE and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * * Contributors: * Tobias Oberlies (SAP SE) - initial API and implementation + * Christoph Läubrich - API adjust *******************************************************************************/ package org.eclipse.tycho.repository.local; @@ -508,7 +509,7 @@ public void testGetRawArtifactOfNonContainedFormatToStream() { @Test public void testWriteArtifact() throws Exception { - IArtifactSink addSink = subject.newAddingArtifactSink(NEW_KEY); + IArtifactSink addSink = subject.newAddingArtifactSink(new ArtifactDescriptor(NEW_KEY)); addSink.beginWrite().write(new byte[33]); addSink.commitWrite(); @@ -522,7 +523,7 @@ public void testReWriteArtifactFails() throws Exception { // LocalArtifactRepository doesn't allow overwrites -> this may be different in other IArtifactRepository implementations ProvisionException expectedException = null; try { - IArtifactSink addSink = subject.newAddingArtifactSink(ARTIFACT_A_KEY); + IArtifactSink addSink = subject.newAddingArtifactSink(new ArtifactDescriptor(ARTIFACT_A_KEY)); addSink.beginWrite(); addSink.commitWrite(); } catch (ProvisionException e) { @@ -535,7 +536,7 @@ public void testReWriteArtifactFails() throws Exception { @Test public void testWriteArtifactAndCancel() throws Exception { - IArtifactSink addSink = subject.newAddingArtifactSink(NEW_KEY); + IArtifactSink addSink = subject.newAddingArtifactSink(new ArtifactDescriptor(NEW_KEY)); addSink.beginWrite().write(new byte[33]); addSink.abortWrite(); @@ -545,7 +546,7 @@ public void testWriteArtifactAndCancel() throws Exception { @Test public void testWriteArtifactOnSecondAttempt() throws Exception { - IArtifactSink addSink = subject.newAddingArtifactSink(NEW_KEY); + IArtifactSink addSink = subject.newAddingArtifactSink(new ArtifactDescriptor(NEW_KEY)); addSink.beginWrite().write(new byte[11]); addSink.beginWrite().write(new byte[22]); addSink.commitWrite(); diff --git a/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/MirroringArtifactProviderErrorTest.java b/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/MirroringArtifactProviderErrorTest.java index f60e86e8e9..c3adb82f33 100644 --- a/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/MirroringArtifactProviderErrorTest.java +++ b/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/MirroringArtifactProviderErrorTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 SAP SE and others. + * Copyright (c) 2013, 2022 SAP SE and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -20,6 +20,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.tycho.core.shared.MockMavenContext; import org.eclipse.tycho.p2.maven.repository.tests.TestRepositoryContent; import org.eclipse.tycho.repository.local.MirroringArtifactProvider.MirroringFailedException; import org.eclipse.tycho.repository.local.testutil.TemporaryLocalMavenRepository; @@ -57,7 +58,7 @@ public void before() throws Exception { subject = MirroringArtifactProvider.createInstance(localRepository, new RepositoryArtifactProvider(singletonList(TestRepositoryContent.REPO_BUNLDE_AB_PACK_CORRUPT), ArtifactTransferPolicies.forRemoteArtifacts(), p2Context.getAgent()), - false, logVerifier.getLogger()); + false, new MockMavenContext(null, logVerifier.getLogger())); } @Test(expected = MirroringFailedException.class) diff --git a/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/MirroringArtifactProviderPack200CornerCasesTest.java b/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/MirroringArtifactProviderPack200CornerCasesTest.java index 6311c6b51e..0e30daf957 100644 --- a/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/MirroringArtifactProviderPack200CornerCasesTest.java +++ b/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/MirroringArtifactProviderPack200CornerCasesTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 SAP SE and others. + * Copyright (c) 2013, 2022 SAP SE and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * * Contributors: * SAP SE - initial API and implementation + * Christoph Läubrich - API adjust *******************************************************************************/ package org.eclipse.tycho.repository.local; @@ -27,6 +28,8 @@ import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.equinox.p2.metadata.IArtifactKey; import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; +import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor; +import org.eclipse.tycho.core.shared.MockMavenContext; import org.eclipse.tycho.p2.maven.repository.tests.TestRepositoryContent; import org.eclipse.tycho.repository.local.MirroringArtifactProvider.MirroringFailedException; import org.eclipse.tycho.repository.local.testutil.TemporaryLocalMavenRepository; @@ -73,7 +76,8 @@ public void expectNoWarningsInLog() throws Exception { @Test public void testIgnoreIfPackedArtifactNotAvailableRemotely() throws Exception { subject = MirroringArtifactProvider.createInstance(localRepository, - providerFor(TestRepositoryContent.REPO_BUNDLE_A), true, logVerifier.getLogger()); + providerFor(TestRepositoryContent.REPO_BUNDLE_A), true, + new MockMavenContext(null, logVerifier.getLogger())); IArtifactDescriptor[] mirroredDescriptors = subject.getArtifactDescriptors(BUNDLE_A_KEY); @@ -84,7 +88,8 @@ public void testIgnoreIfPackedArtifactNotAvailableRemotely() throws Exception { @Test public void testErrorIfPackedArtifactIsAvailableButCorrupt() throws Exception { subject = MirroringArtifactProvider.createInstance(localRepository, - providerFor(TestRepositoryContent.REPO_BUNLDE_AB_PACK_CORRUPT), true, logVerifier.getLogger()); + providerFor(TestRepositoryContent.REPO_BUNLDE_AB_PACK_CORRUPT), true, + new MockMavenContext(null, logVerifier.getLogger())); logVerifier.expectError(containsString(BUNDLE_A_KEY.toString())); @@ -102,7 +107,7 @@ public void testPackedArtifactMirroredEvenIfCanonicalArtifactPresent() throws Ex assertThat(isCanonicalFormat(localRepository.getArtifactDescriptors(BUNDLE_A_KEY)[0]), is(true)); // self-test subject = MirroringArtifactProvider.createInstance(localRepository, remoteProvider, true, - logVerifier.getLogger()); + new MockMavenContext(null, logVerifier.getLogger())); assertThat(subject.getArtifactDescriptors(BUNDLE_A_KEY).length, is(2)); assertThat(localRepository.getArtifactDescriptors(BUNDLE_A_KEY).length, is(2)); @@ -128,7 +133,7 @@ public void testCanonicalArtifactCreatedIfPackedArtifactAlreadyMirrored(Boolean // also expect this for the non-pack200 mirroring implementation (so that it doesn't fail if a different build left the local Maven repository in this state) subject = MirroringArtifactProvider.createInstance(localRepository, emptyProvider, mirrorPacked, - logVerifier.getLogger()); + new MockMavenContext(null, logVerifier.getLogger())); assertThat(subject.getArtifactDescriptors(BUNDLE_A_KEY).length, is(2)); assertThat(localRepository.getArtifactDescriptors(BUNDLE_A_KEY).length, is(2)); @@ -145,7 +150,7 @@ private static void prefillLocalRepositoryWithPackedArtifact(LocalArtifactReposi private static void prefillLocalRepositoryWithCanonicalArtifact(LocalArtifactRepository localRepository, IRawArtifactProvider provider, IArtifactKey artifactKey) throws Exception { - provider.getArtifact(localRepository.newAddingArtifactSink(artifactKey), null); + provider.getArtifact(localRepository.newAddingArtifactSink(new ArtifactDescriptor(artifactKey)), null); } } diff --git a/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/MirroringArtifactProviderTest.java b/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/MirroringArtifactProviderTest.java index 729f3bfcc4..7a0451cf04 100644 --- a/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/MirroringArtifactProviderTest.java +++ b/tycho-bundles/org.eclipse.tycho.p2.maven.repository.tests/src/test/java/org/eclipse/tycho/repository/local/MirroringArtifactProviderTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2013 SAP SE and others. + * Copyright (c) 2012, 2022 SAP SE and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -42,6 +42,7 @@ import org.eclipse.equinox.p2.metadata.Version; import org.eclipse.equinox.p2.query.IQueryResult; import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; +import org.eclipse.tycho.core.shared.MockMavenContext; import org.eclipse.tycho.p2.maven.repository.tests.ResourceUtil; import org.eclipse.tycho.p2.maven.repository.tests.TestRepositoryContent; import org.eclipse.tycho.repository.local.testutil.TemporaryLocalMavenRepository; @@ -77,7 +78,9 @@ public class MirroringArtifactProviderTest { private static final IArtifactKey BUNDLE_L_KEY = new ArtifactKey("osgi.bundle", "org.eclipse.core.jobs", Version.parseVersion("3.4.1.R34x_v20081128")); private static final Set BUNDLE_L_CONTENT_FILES = new HashSet<>( - Arrays.asList("META-INF/", "META-INF/MANIFEST.MF", "org/", "org/eclipse/", "org/eclipse/core/", "org/eclipse/core/internal/", "org/eclipse/core/internal/jobs/", "org/eclipse/core/runtime/", "org/eclipse/core/runtime/jobs/", "plugin.properties")); + Arrays.asList("META-INF/", "META-INF/MANIFEST.MF", "org/", "org/eclipse/", "org/eclipse/core/", + "org/eclipse/core/internal/", "org/eclipse/core/internal/jobs/", "org/eclipse/core/runtime/", + "org/eclipse/core/runtime/jobs/", "plugin.properties")); // not available bundle private static final IArtifactKey OTHER_KEY = TestRepositoryContent.NOT_CONTAINED_ARTIFACT_KEY; @@ -122,7 +125,7 @@ public void initSubject() throws Exception { localRepository = localRepositoryManager.getLocalArtifactRepository(); subject = MirroringArtifactProvider.createInstance(localRepository, remoteProvider, mirrorPacked, - logVerifier.getLogger()); + new MockMavenContext(null, logVerifier.getLogger())); } @Before diff --git a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/local/MirroringArtifactProvider.java b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/local/MirroringArtifactProvider.java index e6a0584585..aaaaca13da 100644 --- a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/local/MirroringArtifactProvider.java +++ b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/local/MirroringArtifactProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2021 SAP SE and others. + * Copyright (c) 2012, 2022 SAP SE and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -9,12 +9,15 @@ * * Contributors: * Tobias Oberlies (SAP SE) - initial API and implementation + * Christoph Läubrich - Issue #658 - Tycho strips p2 artifact properties (eg PGP, maven info...) *******************************************************************************/ package org.eclipse.tycho.repository.local; import static org.eclipse.tycho.repository.util.internal.BundleConstants.BUNDLE_ID; import java.io.File; +import java.util.Map; +import java.util.Objects; import java.util.concurrent.locks.Lock; import org.eclipse.core.runtime.IProgressMonitor; @@ -28,6 +31,10 @@ import org.eclipse.equinox.p2.query.IQueryResult; import org.eclipse.equinox.p2.query.IQueryable; import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; +import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor; +import org.eclipse.tycho.PackagingType; +import org.eclipse.tycho.TychoConstants; +import org.eclipse.tycho.core.shared.MavenContext; import org.eclipse.tycho.core.shared.MavenLogger; import org.eclipse.tycho.core.shared.MultiLineLogger; import org.eclipse.tycho.repository.p2base.artifact.provider.IRawArtifactFileProvider; @@ -66,6 +73,7 @@ public class MirroringArtifactProvider implements IRawArtifactFileProvider { protected final LocalArtifactRepository localArtifactRepository; protected final IProgressMonitor monitor; + private MavenContext mavenContext; /** * Creates a new {@link MirroringArtifactProvider} instance. @@ -83,21 +91,22 @@ public class MirroringArtifactProvider implements IRawArtifactFileProvider { * a logger for progress output */ public static MirroringArtifactProvider createInstance(LocalArtifactRepository localArtifactRepository, - IRawArtifactProvider remoteProviders, boolean mirrorPacked, MavenLogger logger) { + IRawArtifactProvider remoteProviders, boolean mirrorPacked, MavenContext mavenContext) { if (!mirrorPacked) { - return new MirroringArtifactProvider(localArtifactRepository, remoteProviders, logger); + return new MirroringArtifactProvider(localArtifactRepository, remoteProviders, mavenContext); } else { - return new PackedFormatMirroringArtifactProvider(localArtifactRepository, remoteProviders, logger); + return new PackedFormatMirroringArtifactProvider(localArtifactRepository, remoteProviders, mavenContext); } } MirroringArtifactProvider(LocalArtifactRepository localArtifactRepository, IRawArtifactProvider remoteProviders, - MavenLogger logger) { + MavenContext mavenContext) { this.remoteProviders = remoteProviders; this.localArtifactRepository = localArtifactRepository; - this.logger = logger; - this.splittingLogger = new MultiLineLogger(logger); - this.monitor = new LoggingProgressMonitor(logger); + this.mavenContext = mavenContext; + this.logger = mavenContext.getLogger(); + this.splittingLogger = new MultiLineLogger(this.logger); + this.monitor = new LoggingProgressMonitor(this.logger); } // pass through methods @@ -208,13 +217,16 @@ private boolean makeLocallyAvailable(IArtifactKey key) throws MirroringFailedExc protected boolean makeOneFormatLocallyAvailable(IArtifactKey key) throws MirroringFailedException, ProvisionException, ArtifactSinkException { - if (localArtifactRepository.contains(key)) { + if (isFileAlreadyAvailable(key)) { return true; } else if (remoteProviders.contains(key)) { Lock downloadLock = localArtifactRepository.getLockForDownload(key); downloadLock.lock(); try { - if (!localArtifactRepository.contains(key)) { // check again within lock + if (!isFileAlreadyAvailable(key)) { // check again within lock + if (localArtifactRepository.contains(key)) { + localArtifactRepository.removeDescriptor(key); + } downloadArtifact(key); } } finally { @@ -251,7 +263,22 @@ protected IStatus downloadMostSpecificNeededFormatOfArtifact(IArtifactKey key) protected final IStatus downloadCanonicalArtifact(IArtifactKey key) throws ProvisionException, ArtifactSinkException { // TODO 397355 ignore ProvisionException.ARTIFACT_EXISTS - artifact may have been added by other thread in the meantime - IArtifactSink localSink = localArtifactRepository.newAddingArtifactSink(key); + IArtifactDescriptor descriptor = localArtifactRepository.createArtifactDescriptor(key); + if (descriptor instanceof ArtifactDescriptor) { + ArtifactDescriptor localDescriptor = (ArtifactDescriptor) descriptor; + IArtifactDescriptor remoteDescriptor = findCanonicalDescriptor(remoteProviders.getArtifactDescriptors(key)); + if (remoteDescriptor != null) { + remoteDescriptor.getProperties().forEach(localDescriptor::setProperty); + //fix bad metadata in p2... + if (TychoConstants.PACK200_CLASSIFIER + .equals(localDescriptor.getProperty(TychoConstants.PROP_CLASSIFIER))) { + localDescriptor.setProperty(TychoConstants.PROP_CLASSIFIER, ""); + localDescriptor.setProperty(TychoConstants.PROP_EXTENSION, "jar"); + localDescriptor.setProperty(TychoConstants.PROP_TYPE, PackagingType.TYPE_ECLIPSE_PLUGIN); + } + } + } + IArtifactSink localSink = localArtifactRepository.newAddingArtifactSink(descriptor); return remoteProviders.getArtifact(localSink, monitorForDownload()); } @@ -273,7 +300,9 @@ private void createCanonicalArtifactFromLocalPackedArtifact(IArtifactKey key) logger.info("Unpacking " + key.getId() + "_" + key.getVersion() + "..."); // TODO 397355 ignore ProvisionException.ARTIFACT_EXISTS - IArtifactSink sink = localArtifactRepository.newAddingArtifactSink(key); + + IArtifactSink sink = localArtifactRepository + .newAddingArtifactSink(localArtifactRepository.createArtifactDescriptor(key)); localArtifactRepository.getArtifact(sink, monitor); } @@ -329,6 +358,24 @@ public static class MirroringFailedException extends RuntimeException { @Override public boolean isFileAlreadyAvailable(IArtifactKey artifactKey) { - return localArtifactRepository.contains(artifactKey); + if (localArtifactRepository.contains(artifactKey)) { + if (mavenContext.isOffline()) { + return true; + } + if (remoteProviders.contains(artifactKey)) { + //we must compare remote versus local! + IArtifactDescriptor remoteDescriptor = findCanonicalDescriptor( + remoteProviders.getArtifactDescriptors(artifactKey)); + IArtifactDescriptor localDescriptor = findCanonicalDescriptor( + localArtifactRepository.getArtifactDescriptors(artifactKey)); + if (remoteDescriptor != null && localDescriptor != null) { + Map remoteProperties = remoteDescriptor.getProperties(); + Map localProperties = localDescriptor.getProperties(); + return Objects.equals(remoteProperties, localProperties); + } + } + return true; + } + return false; } } diff --git a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/local/PackedFormatMirroringArtifactProvider.java b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/local/PackedFormatMirroringArtifactProvider.java index 97e307f8f3..e0c4fcdca0 100644 --- a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/local/PackedFormatMirroringArtifactProvider.java +++ b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/local/PackedFormatMirroringArtifactProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2021 SAP SE and others. + * Copyright (c) 2013, 2022 SAP SE and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -18,7 +18,7 @@ import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.equinox.p2.metadata.IArtifactKey; import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; -import org.eclipse.tycho.core.shared.MavenLogger; +import org.eclipse.tycho.core.shared.MavenContext; import org.eclipse.tycho.repository.p2base.artifact.provider.IRawArtifactProvider; import org.eclipse.tycho.repository.p2base.artifact.provider.streaming.ArtifactSinkException; import org.eclipse.tycho.repository.p2base.artifact.provider.streaming.IRawArtifactSink; @@ -27,8 +27,8 @@ final class PackedFormatMirroringArtifactProvider extends MirroringArtifactProvider { PackedFormatMirroringArtifactProvider(LocalArtifactRepository localArtifactRepository, - IRawArtifactProvider remoteProviders, MavenLogger logger) { - super(localArtifactRepository, remoteProviders, logger); + IRawArtifactProvider remoteProviders, MavenContext mavenContext) { + super(localArtifactRepository, remoteProviders, mavenContext); } @Override diff --git a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/p2base/artifact/repository/AbstractArtifactRepository2.java b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/p2base/artifact/repository/AbstractArtifactRepository2.java index 0e301e1221..591075719f 100644 --- a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/p2base/artifact/repository/AbstractArtifactRepository2.java +++ b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/p2base/artifact/repository/AbstractArtifactRepository2.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2013 SAP SE and others. + * Copyright (c) 2012, 2022 SAP SE and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * * Contributors: * Tobias Oberlies (SAP SE) - initial API and implementation + * Christoph Läubrich - Issue #658 - Tycho strips p2 artifact properties (eg PGP, maven info...) *******************************************************************************/ package org.eclipse.tycho.repository.p2base.artifact.repository; @@ -199,7 +200,7 @@ public final void removeAll(IProgressMonitor monitor) { * if the artifact is already stored in the repository (in canonical format) */ // TODO this method should be exposed via an interface - public abstract IArtifactSink newAddingArtifactSink(final IArtifactKey key) throws ProvisionException; + public abstract IArtifactSink newAddingArtifactSink(final IArtifactDescriptor descriptor) throws ProvisionException; /** * Returns a new {@link IRawArtifactSink} instance that adds the received artifact to this @@ -227,8 +228,8 @@ public final OutputStream getOutputStream(IArtifactDescriptor descriptor) throws IArtifactSink artifactSink = newAddingRawArtifactSink(descriptor); return new CommittingArtifactOutputStream(artifactSink); } catch (ArtifactSinkException e) { - throw new ProvisionException(new Status(IStatus.ERROR, BUNDLE_ID, "Error while writing to artifact sink: " - + e.getMessage(), e)); + throw new ProvisionException( + new Status(IStatus.ERROR, BUNDLE_ID, "Error while writing to artifact sink: " + e.getMessage(), e)); } } diff --git a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/p2base/artifact/repository/ArtifactRepositoryBaseImpl.java b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/p2base/artifact/repository/ArtifactRepositoryBaseImpl.java index 5d86f805f7..ef1126d85e 100644 --- a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/p2base/artifact/repository/ArtifactRepositoryBaseImpl.java +++ b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/p2base/artifact/repository/ArtifactRepositoryBaseImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2013 SAP SE and others. + * Copyright (c) 2012, 2022 SAP SE and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * * Contributors: * Tobias Oberlies (SAP SE) - initial API and implementation + * Christoph Läubrich - Issue #658 - Tycho strips p2 artifact properties (eg PGP, maven info...) *******************************************************************************/ package org.eclipse.tycho.repository.p2base.artifact.repository; @@ -370,8 +371,8 @@ private static void closeSinkAccordingToStatus(IArtifactSink sink, IStatus statu } @Override - public final IArtifactSink newAddingArtifactSink(final IArtifactKey key) throws ProvisionException { - ArtifactDescriptorT newDescriptor = getInternalDescriptorForAdding(createArtifactDescriptor(key)); + public final IArtifactSink newAddingArtifactSink(final IArtifactDescriptor descriptor) throws ProvisionException { + ArtifactDescriptorT newDescriptor = getInternalDescriptorForAdding(descriptor); return internalNewAddingArtifactSink(newDescriptor); } diff --git a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/p2base/artifact/repository/ProviderOnlyArtifactRepository.java b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/p2base/artifact/repository/ProviderOnlyArtifactRepository.java index 5e87da813f..d191f076ae 100644 --- a/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/p2base/artifact/repository/ProviderOnlyArtifactRepository.java +++ b/tycho-bundles/org.eclipse.tycho.p2.maven.repository/src/main/java/org/eclipse/tycho/repository/p2base/artifact/repository/ProviderOnlyArtifactRepository.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2013 SAP SE and others. + * Copyright (c) 2012, 2022 SAP SE and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -146,7 +146,7 @@ protected void internalStore(IProgressMonitor monitor) { } @Override - public IArtifactSink newAddingArtifactSink(IArtifactKey key) throws ProvisionException { + public IArtifactSink newAddingArtifactSink(IArtifactDescriptor descriptor) throws ProvisionException { throw new UnsupportedOperationException(); } diff --git a/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/impl/publisher/MavenPropertiesAdvice.java b/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/impl/publisher/MavenPropertiesAdvice.java index 82ff376d6b..92721e6b24 100644 --- a/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/impl/publisher/MavenPropertiesAdvice.java +++ b/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/impl/publisher/MavenPropertiesAdvice.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Sonatype Inc. and others. + * Copyright (c) 2008, 2022 Sonatype Inc. and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * * Contributors: * Sonatype Inc. - initial API and implementation + * Christoph Läubrich - Issue #658 - preserve p2 artifact properties (eg PGP, maven info...) *******************************************************************************/ package org.eclipse.tycho.p2.impl.publisher; @@ -66,16 +67,22 @@ public MavenPropertiesAdvice(String groupId, String artifactId, String version, @Override public Map getArtifactProperties(IInstallableUnit iu, IArtifactDescriptor descriptor) { - // workaround Bug 539672 - // TODO this is a nasty hack, and it doesn't even work; see org.eclipse.equinox.p2.publisher.AbstractPublisherAction.processArtifactPropertiesAdvice(IInstallableUnit, IArtifactDescriptor, IPublisherInfo) - for (Map.Entry entry : properties.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - ((ArtifactDescriptor) descriptor).setProperty(key, value); - } + // TODO this is a nasty hack, workaround for Bug 539672 + setDescriptorProperties(descriptor); return null; } + public void setDescriptorProperties(IArtifactDescriptor descriptor) { + if (descriptor instanceof ArtifactDescriptor) { + ArtifactDescriptor artifactDescriptor = (ArtifactDescriptor) descriptor; + for (Map.Entry entry : properties.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + artifactDescriptor.setProperty(key, value); + } + } + } + @Override public Map getInstallableUnitProperties(InstallableUnitDescription iu) { return properties; diff --git a/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/resolver/MavenTargetDefinitionContent.java b/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/resolver/MavenTargetDefinitionContent.java index db0a094367..687e1b8b23 100644 --- a/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/resolver/MavenTargetDefinitionContent.java +++ b/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/resolver/MavenTargetDefinitionContent.java @@ -366,14 +366,16 @@ private IInstallableUnit publish(BundleDescription bundleDescription, File bundl IArtifactFacade mavenArtifact) { IArtifactKey key = BundlesAction.createBundleArtifactKey(bundleDescription.getSymbolicName(), bundleDescription.getVersion().toString()); + IArtifactDescriptor descriptor = FileArtifactRepository.forFile(bundleLocation, key); PublisherInfo publisherInfo = new PublisherInfo(); if (mavenArtifact != null) { MavenPropertiesAdvice advice = new MavenPropertiesAdvice(mavenArtifact, mavenContext); publisherInfo.addAdvice(advice); + advice.setDescriptorProperties(descriptor); } publisherInfo.setArtifactOptions(IPublisherInfo.A_INDEX); IInstallableUnit iu = BundlesAction.createBundleIU(bundleDescription, key, publisherInfo); - repositoryContent.put(FileArtifactRepository.forFile(bundleLocation, key), iu); + repositoryContent.put(descriptor, iu); return iu; } diff --git a/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/target/TargetPlatformFactoryImpl.java b/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/target/TargetPlatformFactoryImpl.java index b86cbd4f4d..e421185727 100644 --- a/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/target/TargetPlatformFactoryImpl.java +++ b/tycho-bundles/org.eclipse.tycho.p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/target/TargetPlatformFactoryImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2020 Sonatype Inc. and others. + * Copyright (c) 2008, 2022 Sonatype Inc. and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -349,7 +349,7 @@ private IRawArtifactFileProvider createExternalArtifactProvider(Set