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

Unify Constants and modernize CollectAction #501

Merged
merged 1 commit into from
Apr 23, 2024
Merged
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
Expand Up @@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
*
* Contributors:
* IBM Corporation - initial API and implementation
* WindRiver - https://bugs.eclipse.org/bugs/show_bug.cgi?id=227372
Expand All @@ -25,6 +25,7 @@ public abstract class InstallableUnitPhase extends Phase {
public static final String PARM_ARTIFACT = "artifact"; //$NON-NLS-1$
public static final String PARM_IU = "iu"; //$NON-NLS-1$
public static final String PARM_INSTALL_FOLDER = "installFolder"; //$NON-NLS-1$
public static final String PARM_ARTIFACT_REQUESTS = "artifactRequests"; //$NON-NLS-1$

protected InstallableUnitPhase(String phaseId, int weight, boolean forced) {
super(phaseId, weight, forced);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* The goal of the collect phase is to ask the touchpoints if the artifacts associated with an IU need to be downloaded.
*/
public class Collect extends InstallableUnitPhase {
public static final String PARM_ARTIFACT_REQUESTS = "artifactRequests"; //$NON-NLS-1$

public static final String NO_ARTIFACT_REPOSITORIES_AVAILABLE = "noArtifactRepositoriesAvailable"; //$NON-NLS-1$
private static final String PARM_IUS = "ius"; //$NON-NLS-1$
private IProvisioningAgent agent = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected String getProblemMessage() {
@Override
protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map<String, Object> parameters) {
@SuppressWarnings("unchecked")
List<IArtifactRequest[]> artifactRequests = (List<IArtifactRequest[]>) parameters.get(Collect.PARM_ARTIFACT_REQUESTS);
List<IArtifactRequest[]> artifactRequests = (List<IArtifactRequest[]>) parameters.get(PARM_ARTIFACT_REQUESTS);
ProvisioningContext context = (ProvisioningContext) parameters.get(PARM_CONTEXT);
int statusCode = 0;

Expand Down Expand Up @@ -131,7 +131,7 @@ protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map<

@Override
protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map<String, Object> parameters) {
parameters.put(Collect.PARM_ARTIFACT_REQUESTS, new ArrayList<>());
parameters.put(PARM_ARTIFACT_REQUESTS, new ArrayList<>());
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.List;
import java.util.Map;
import org.eclipse.equinox.internal.p2.engine.InstallableUnitOperand;
import org.eclipse.equinox.internal.p2.engine.phases.Collect;
import org.eclipse.equinox.internal.p2.engine.InstallableUnitPhase;
import org.eclipse.equinox.internal.p2.touchpoint.eclipse.EclipseTouchpoint;
import org.eclipse.equinox.internal.p2.touchpoint.eclipse.Util;
import org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.ActionConstants;
Expand Down Expand Up @@ -69,15 +69,16 @@ public void testExecuteUndo() throws Exception {
Map<String, Object> parameters = new HashMap<>();
parameters.put(ActionConstants.PARM_AGENT, getAgent());
parameters.put(ActionConstants.PARM_PROFILE, profile);
parameters.put(Collect.PARM_ARTIFACT_REQUESTS, new ArrayList<>());
parameters.put(InstallableUnitPhase.PARM_ARTIFACT_REQUESTS, new ArrayList<>());
EclipseTouchpoint touchpoint = new EclipseTouchpoint();
touchpoint.initializePhase(null, profile, "test", parameters);
InstallableUnitOperand operand = new InstallableUnitOperand(null, iu);
parameters.put("iu", operand.second());
touchpoint.initializeOperand(profile, parameters);
parameters = Collections.unmodifiableMap(parameters);

List<IArtifactRequest[]> requests = (List<IArtifactRequest[]>) parameters.get(Collect.PARM_ARTIFACT_REQUESTS);
List<IArtifactRequest[]> requests = (List<IArtifactRequest[]>) parameters
.get(InstallableUnitPhase.PARM_ARTIFACT_REQUESTS);
assertFalse(hasRequest(requests, key));
CollectAction action = new CollectAction();
action.execute(parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.equinox.internal.p2.engine.phases.Collect;
import org.eclipse.equinox.internal.p2.engine.InstallableUnitPhase;
import org.eclipse.equinox.internal.p2.touchpoint.natives.NativeTouchpoint;
import org.eclipse.equinox.internal.p2.touchpoint.natives.actions.ActionConstants;
import org.eclipse.equinox.internal.p2.touchpoint.natives.actions.CollectAction;
Expand Down Expand Up @@ -63,14 +63,15 @@ public void testExecuteUndo() {
Map<String, Object> parameters = new HashMap<>();
parameters.put(ActionConstants.PARM_AGENT, getAgent());
parameters.put(ActionConstants.PARM_PROFILE, profile);
parameters.put(Collect.PARM_ARTIFACT_REQUESTS, new ArrayList<>());
parameters.put(InstallableUnitPhase.PARM_ARTIFACT_REQUESTS, new ArrayList<>());
NativeTouchpoint touchpoint = new NativeTouchpoint();
touchpoint.initializePhase(null, profile, "test", parameters);
parameters.put("iu", iu);
touchpoint.initializeOperand(profile, parameters);
parameters = Collections.unmodifiableMap(parameters);

List<IArtifactRequest[]> requests = (List<IArtifactRequest[]>) parameters.get(Collect.PARM_ARTIFACT_REQUESTS);
List<IArtifactRequest[]> requests = (List<IArtifactRequest[]>) parameters
.get(InstallableUnitPhase.PARM_ARTIFACT_REQUESTS);
assertFalse(hasRequest(requests, key));
CollectAction action = new CollectAction();
action.execute(parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class ActionConstants {
public static final String PARM_IU = "iu"; //$NON-NLS-1$
public static final String PIPE = "|"; //$NON-NLS-1$
public static final String PARM_AT_ARTIFACT = "@artifact"; //$NON-NLS-1$
public static final String PARM_ARTIFACT_REQUESTS = "artifactRequests"; //$NON-NLS-1$
public static final String PARM_PROFILE = "profile"; //$NON-NLS-1$
public static final String PARM_LINK_NAME = "linkName"; //$NON-NLS-1$
public static final String PARM_LINK_TARGET = "linkTarget"; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.touchpoint.natives.actions;

import java.util.Collection;
import java.util.Map;
import java.util.*;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.engine.InstallableUnitPhase;
import org.eclipse.equinox.internal.p2.touchpoint.natives.Util;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRequest;
import org.eclipse.equinox.p2.repository.artifact.*;

public class CollectAction extends ProvisioningAction {

Expand All @@ -37,10 +36,13 @@ public IStatus execute(Map<String, Object> parameters) {
IProvisioningAgent agent = (IProvisioningAgent) parameters.get(ActionConstants.PARM_AGENT);
IInstallableUnit iu = (IInstallableUnit) parameters.get(ActionConstants.PARM_IU);
try {
IArtifactRequest[] requests = collect(agent, iu, profile);
@SuppressWarnings("unchecked")
Collection<IArtifactRequest[]> artifactRequests = (Collection<IArtifactRequest[]>) parameters.get(ActionConstants.PARM_ARTIFACT_REQUESTS);
artifactRequests.add(requests);
List<IArtifactRequest> requests = collect(agent, iu, profile);
if (!requests.isEmpty()) {
@SuppressWarnings("unchecked")
Collection<IArtifactRequest[]> artifactRequests = (Collection<IArtifactRequest[]>) parameters
.get(InstallableUnitPhase.PARM_ARTIFACT_REQUESTS);
artifactRequests.add(requests.toArray(IArtifactRequest[]::new));
}
} catch (ProvisionException e) {
return e.getStatus();
}
Expand All @@ -53,22 +55,22 @@ public IStatus undo(Map<String, Object> parameters) {
return Status.OK_STATUS;
}

IArtifactRequest[] collect(IProvisioningAgent agent, IInstallableUnit installableUnit, IProfile profile) throws ProvisionException {
private List<IArtifactRequest> collect(IProvisioningAgent agent, IInstallableUnit installableUnit, IProfile profile)
throws ProvisionException {
Collection<IArtifactKey> toDownload = installableUnit.getArtifacts();
if (toDownload == null)
return new IArtifactRequest[0];
if (toDownload == null || toDownload.isEmpty()) {
return List.of();
}
IArtifactRepository destination = Util.getDownloadCacheRepo(agent);
IArtifactRequest[] requests = new IArtifactRequest[toDownload.size()];
int count = 0;
IArtifactRepositoryManager manager = Util.getArtifactRepositoryManager(agent);
List<IArtifactRequest> requests = new ArrayList<>(toDownload.size());
for (IArtifactKey key : toDownload) {
//TODO Here there are cases where the download is not necessary again because what needs to be done is just a configuration step
requests[count++] = Util.getArtifactRepositoryManager(agent).createMirrorRequest(key, destination, null, null, profile.getProperty(IProfile.PROP_STATS_PARAMETERS));
// TODO Here there are cases where the download is not necessary again because
// what needs to be done is just a configuration step
requests.add(manager.createMirrorRequest(key, destination, null, null,
profile.getProperty(IProfile.PROP_STATS_PARAMETERS)));
}

if (requests.length == count)
return requests;
IArtifactRequest[] result = new IArtifactRequest[count];
System.arraycopy(requests, 0, result, 0, count);
return result;
return requests;
}
}
Loading