Skip to content

Commit

Permalink
Fix eclipse-tycho#658 - preserve p2 artifact properties (eg PGP, mave…
Browse files Browse the repository at this point in the history
…n info...)

Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
  • Loading branch information
laeubi committed Feb 18, 2022
1 parent d2f7dbf commit f04ac80
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/*******************************************************************************
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* 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;

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,6 +9,7 @@
*
* Contributors:
* Tobias Oberlies (SAP SE) - initial API and implementation
* Christoph Läubrich - API adjust
*******************************************************************************/
package org.eclipse.tycho.repository.local;

Expand Down Expand Up @@ -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();

Expand All @@ -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) {
Expand All @@ -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();

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,6 +9,7 @@
*
* Contributors:
* SAP SE - initial API and implementation
* Christoph Läubrich - API adjust
*******************************************************************************/
package org.eclipse.tycho.repository.local;

Expand All @@ -27,6 +28,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.equinox.p2.repository.artifact.spi.ArtifactDescriptor;
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;
Expand Down Expand Up @@ -145,7 +147,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);
}

}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.local;

Expand All @@ -28,6 +29,7 @@
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.core.shared.MavenLogger;
import org.eclipse.tycho.core.shared.MultiLineLogger;
import org.eclipse.tycho.repository.p2base.artifact.provider.IRawArtifactFileProvider;
Expand Down Expand Up @@ -59,6 +61,11 @@
*/
public class MirroringArtifactProvider implements IRawArtifactFileProvider {

/**
* this allows to bypass the cache and always download the artifact from the remote
*/
private boolean ignoreLocalCache = Boolean.getBoolean("tycho.p2.ignoreLocalCache");

protected final MavenLogger logger;
protected final MavenLogger splittingLogger;

Expand Down Expand Up @@ -208,7 +215,7 @@ private boolean makeLocallyAvailable(IArtifactKey key) throws MirroringFailedExc
protected boolean makeOneFormatLocallyAvailable(IArtifactKey key)
throws MirroringFailedException, ProvisionException, ArtifactSinkException {

if (localArtifactRepository.contains(key)) {
if (localArtifactRepository.contains(key) && !ignoreLocalCache) {
return true;
} else if (remoteProviders.contains(key)) {
Lock downloadLock = localArtifactRepository.getLockForDownload(key);
Expand Down Expand Up @@ -251,7 +258,16 @@ 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[] descriptors = remoteProviders.getArtifactDescriptors(key);
if (descriptors != null && descriptors.length > 0) {
IArtifactDescriptor remoteDescriptor = descriptors[0];
remoteDescriptor.getProperties().forEach(localDescriptor::setProperty);
}
}
IArtifactSink localSink = localArtifactRepository.newAddingArtifactSink(descriptor);
return remoteProviders.getArtifact(localSink, monitorForDownload());
}

Expand All @@ -273,7 +289,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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit f04ac80

Please sign in to comment.