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

Add an ArtifactManager to allows unified managing of artifacts #590

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dsVersion=V1_4
eclipse.preferences.version=1
enabled=true
generateBundleActivationPolicyLazy=true
path=OSGI-INF
validationErrorLevel=error
validationErrorLevel.missingImplicitUnbindMethod=error
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ Import-Package: javax.xml.parsers,
org.osgi.service.prefs;version="1.1.1",
org.w3c.dom,
org.xml.sax;resolution:=optional
Service-Component: OSGI-INF/repositoryManager.xml
Service-Component: OSGI-INF/org.eclipse.equinox.internal.p2.artifact.repository.DefaultArtifactManagerServiceFactory.xml,
OSGI-INF/repositoryManager.xml
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-17
Automatic-Module-Name: org.eclipse.equinox.p2.artifact.repository
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/org.eclipse.equinox.*.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*******************************************************************************
* Copyright (c) 2025 Christoph Läubrich 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
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.internal.p2.artifact.repository;

import java.io.OutputStream;
import java.net.URI;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.internal.p2.repository.DownloadStatus;
import org.eclipse.equinox.internal.provisional.p2.repository.IStateful;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
import org.osgi.annotation.versioning.ProviderType;

/**
* The artifact manager is responsible for managing artifacts on a per agent
* basis. It possibly caches the data from previous requests to improve
* performance or knows alternative locations to fetch the artifacts.
*/
@ProviderType
public interface ArtifactManager {

/**
* Service name for the artifact manager service.
*/
String SERVICE_NAME = "org.eclipse.equinox.internal.p2.repository.ArtifactManager"; //$NON-NLS-1$

/**
* Acquire the artifact described by the given artifact descriptor and writing
* it into the target output stream. Progress is reported on the monitor. If the
* <code>target</code> is an instance of {@link IStateful} the resulting status
* is also reported on the target.
*
* @return IStatus that is a {@link DownloadStatus} if the artifact was
* downloaded from a remote server, or a plain status in other cases
* (including errors).
* @param source An URI of file to download from a remote, this might be a
* mirror of the actual artifact repository
* @param target the {@link OutputStream} where result is written
* @param descriptor the descriptor of the artifact that is about to be
* downloaded
* @param monitor where progress should be reported, might be
* <code>null</code> if no progress reporting is desired
*/
IStatus getArtifact(URI source, OutputStream target, IArtifactDescriptor descriptor, IProgressMonitor monitor);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*******************************************************************************
* Copyright (c) 2025 Christoph Läubrich 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
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.internal.p2.artifact.repository;

import java.io.OutputStream;
import java.net.URI;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.repository.Transport;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.spi.AgentServiceName;
import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
import org.osgi.service.component.annotations.Component;

/**
* The default implementation of a {@link ArtifactManager} simply delegates to
* the transport.
*/
@Component(service = IAgentServiceFactory.class)
@AgentServiceName(ArtifactManager.class)
public class DefaultArtifactManagerServiceFactory implements IAgentServiceFactory {

@Override
public Object createService(IProvisioningAgent agent) {
return new DefaultArtifactManager(agent);
}

private static final class DefaultArtifactManager implements ArtifactManager {
private IProvisioningAgent agent;

public DefaultArtifactManager(IProvisioningAgent agent) {
this.agent = agent;
}

@Override
public IStatus getArtifact(URI source, OutputStream target, IArtifactDescriptor descriptor,
IProgressMonitor monitor) {
Transport transport = agent.getService(Transport.class);
if (transport == null) {
return Status.CANCEL_STATUS;
}
return transport.downloadArtifact(source, target, descriptor, monitor);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ private IStatus downloadArtifact(IArtifactDescriptor descriptor, URI mirrorLocat
if (SimpleArtifactRepositoryFactory.PROTOCOL_FILE.equals(mirrorLocation.getScheme()))
result = copyFileToStream(new File(mirrorLocation), destination, monitor);
else
result = getTransport().downloadArtifact(mirrorLocation, destination, descriptor, monitor);
result = getArtifactManger().getArtifact(mirrorLocation, destination, descriptor, monitor);
if (mirrors != null)
mirrors.reportResult(mirrorLocation.toString(), result);
if (result.isOK() || result.getSeverity() == IStatus.CANCEL)
Expand Down Expand Up @@ -1142,6 +1142,12 @@ private Transport getTransport() {
return getProvisioningAgent().getService(Transport.class);
}

private ArtifactManager getArtifactManger() {
IProvisioningAgent agent = getProvisioningAgent();
return Objects.requireNonNull(agent.getService(ArtifactManager.class),
"No ArtifactManager present in p2 agent " + agent); //$NON-NLS-1$
}

// use this method to setup any transient fields etc after the object has been restored from a stream
public synchronized void initializeAfterLoad(URI repoLocation) {
this.initializeAfterLoad(repoLocation, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (c) 2025 Christoph Läubrich 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
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.p2.core.spi;

import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.CLASS;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import org.osgi.service.component.annotations.ComponentPropertyType;

/**
* This component property type can be used to annotate a declarative service
* component that provides an {@link IAgentServiceFactory} to provides the
* required {@link IAgentServiceFactory#PROP_AGENT_SERVICE_NAME}.
*
* @since 2.13
*/
@Retention(CLASS)
@Target(TYPE)
@ComponentPropertyType
public @interface AgentServiceName {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the change is reasonable, I just wanted to mention that renamings that just change the case of some letters in a file name cause funny side-effects on Windows because the file-system is case-insensitive and then git gets confused.
But one just has to get along with that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the class is actually new (I just renamed it in the PR for the sake of testing) it hopefully do not confuses windows to much :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the improved name. It looks like a typo before. 😕


public static final String PREFIX_ = "p2."; //$NON-NLS-1$

Class<?> value();

}
Loading