├── .gitignore
├── org.eclipse.equinox.p2.engine
├── META-INF
│ └── ECLIPSE_.RSA
├── src
│ └── main
│ │ ├── resources
│ │ ├── .options
│ │ ├── OSGI-INF
│ │ │ ├── engine.xml
│ │ │ └── profileRegistry.xml
│ │ ├── plugin.properties
│ │ └── plugin.xml
│ │ └── java
│ │ └── org
│ │ └── eclipse
│ │ └── equinox
│ │ ├── p2
│ │ └── engine
│ │ │ ├── query
│ │ │ ├── package.html
│ │ │ ├── UserVisibleRootQuery.java
│ │ │ └── IUProfilePropertyQuery.java
│ │ │ ├── spi
│ │ │ ├── package.html
│ │ │ ├── Value.java
│ │ │ ├── ProvisioningAction.java
│ │ │ └── Memento.java
│ │ │ ├── package.html
│ │ │ ├── ISizingPhaseSet.java
│ │ │ ├── IPhaseSet.java
│ │ │ ├── IProfileEvent.java
│ │ │ ├── IEngine.java
│ │ │ ├── ProfileScope.java
│ │ │ └── PhaseSetFactory.java
│ │ └── internal
│ │ └── p2
│ │ └── engine
│ │ ├── AssignVariableAction.java
│ │ ├── Operand.java
│ │ ├── BeginOperationEvent.java
│ │ ├── CommitOperationEvent.java
│ │ ├── RollbackOperationEvent.java
│ │ ├── TransactionEvent.java
│ │ ├── ISurrogateProfileHandler.java
│ │ ├── SizingPhaseSet.java
│ │ ├── PhaseEvent.java
│ │ ├── ProfileRegistryComponent.java
│ │ ├── EngineComponent.java
│ │ ├── ProfileMetadataRepositoryFactory.java
│ │ ├── ProfileXMLConstants.java
│ │ ├── InstallableUnitOperand.java
│ │ ├── MissingAction.java
│ │ ├── InstallableUnitPropertyOperand.java
│ │ ├── PropertyOperand.java
│ │ ├── MissingActionsException.java
│ │ ├── ProfileEvent.java
│ │ ├── EngineActivator.java
│ │ ├── CollectEvent.java
│ │ ├── SlashEncode.java
│ │ ├── ProfileWriter.java
│ │ ├── InstallableUnitEvent.java
│ │ ├── SharedProfilePreferences.java
│ │ ├── phases
│ │ ├── CheckTrust.java
│ │ ├── Configure.java
│ │ ├── Unconfigure.java
│ │ ├── Uninstall.java
│ │ ├── Install.java
│ │ ├── Sizing.java
│ │ ├── Collect.java
│ │ └── Property.java
│ │ ├── ProfileLock.java
│ │ ├── ParameterizedProvisioningAction.java
│ │ ├── InstructionParser.java
│ │ ├── InstallableUnitPhase.java
│ │ ├── ProvisioningPlan.java
│ │ ├── ActionManager.java
│ │ ├── Engine.java
│ │ ├── Messages.java
│ │ ├── ProfileParser.java
│ │ ├── DownloadManager.java
│ │ ├── PhaseSet.java
│ │ ├── messages.properties
│ │ └── TouchpointManager.java
└── pom.xml
├── issue_template.md
└── pull_request_template.md
/.gitignore:
--------------------------------------------------------------------------------
1 | target
2 | .classpath
3 | .settings
4 | .project
5 | *.i??
6 | .idea
7 | .DS_Store
8 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/META-INF/ECLIPSE_.RSA:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wso2/wso2-eclipse-p2-plugins/HEAD/org.eclipse.equinox.p2.engine/META-INF/ECLIPSE_.RSA
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/resources/.options:
--------------------------------------------------------------------------------
1 | org.eclipse.equinox.p2.engine/profileregistry/debug = false
2 | org.eclipse.equinox.p2.engine/engine/debug = false
3 | org.eclipse.equinox.p2.engine/enginesession/debug = false
4 | org.eclipse.equinox.p2.engine/certificatechecker/unsigned = false
5 | org.eclipse.equinox.p2.engine/certificatechecker/untrusted = false
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/p2/engine/query/package.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Package-level Javadoc
6 |
7 |
8 | Provides queries specific to profiles
9 |
10 | Package Specification
11 |
12 | This package specifies API for querying the profile.
13 |
14 | @since 2.0
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/resources/OSGI-INF/engine.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/resources/OSGI-INF/profileRegistry.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/p2/engine/spi/package.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Package-level Javadoc
6 |
7 |
8 | Provides support for registering new provisioning actions and touchpoints.
9 |
10 | Package Specification
11 |
12 | This package specifies SPI for registering new actions and new touchpoints to the engine.
13 |
14 | @since 2.0
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/AssignVariableAction.java:
--------------------------------------------------------------------------------
1 | package org.eclipse.equinox.internal.p2.engine;
2 |
3 | import java.util.Map;
4 | import org.eclipse.core.runtime.IStatus;
5 | import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
6 |
7 | public class AssignVariableAction extends ProvisioningAction {
8 |
9 | @Override
10 | public IStatus execute(Map parameters) {
11 | // TODO Auto-generated method stub
12 | return null;
13 | }
14 |
15 | @Override
16 | public IStatus undo(Map parameters) {
17 | // TODO Auto-generated method stub
18 | return null;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/resources/plugin.properties:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Copyright (c) 2007, 2009 IBM Corporation and others.
3 | # All rights reserved. This program and the accompanying materials
4 | # are made available under the terms of the Eclipse Public License v1.0
5 | # which accompanies this distribution, and is available at
6 | # http://www.eclipse.org/legal/epl-v10.html
7 | #
8 | # Contributors:
9 | # IBM Corporation - initial API and implementation
10 | ###############################################################################
11 | pluginName = Equinox Provisioning Engine
12 | providerName = Eclipse.org - Equinox
13 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/Operand.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2008, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 |
14 | /**
15 | * The common base class for engine operands.
16 | *
17 | * @since 2.0
18 | */
19 | public class Operand {
20 | // marker class
21 | }
22 |
--------------------------------------------------------------------------------
/issue_template.md:
--------------------------------------------------------------------------------
1 | **Description:**
2 |
3 |
4 | **Suggested Labels:**
5 |
6 |
7 | **Suggested Assignees:**
8 |
9 |
10 | **Affected Product Version:**
11 |
12 | **OS, DB, other environment details and versions:**
13 |
14 | **Steps to reproduce:**
15 |
16 |
17 | **Related Issues:**
18 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/resources/plugin.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
10 |
12 |
13 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/p2/engine/package.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Package-level Javadoc
6 |
7 |
8 | Provides support for interacting with the p2 provisioning engine
9 |
10 | Package Specification
11 |
12 | This package specifies API for interacting with the p2 provisioning engine. The engine
13 | is a naive service that blindly performs a set of requested changes to a provisioned
14 | system. No attempt is made to resolve dependencies or determine whether the
15 | resulting system is valid or consistent. It is assumed that the engine client has
16 | crafted a valid provisioning plan for the engine to perform, typically by using a planner
17 | service.
18 |
19 | @since 2.0
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/p2/engine/ISizingPhaseSet.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.p2.engine;
12 |
13 | /**
14 | * @noextend This interface is not intended to be extended by clients.
15 | * @noimplement This interface is not intended to be implemented by clients.
16 | * @since 2.0
17 | */
18 | public interface ISizingPhaseSet extends IPhaseSet {
19 |
20 | public long getDiskSize();
21 |
22 | public long getDownloadSize();
23 | }
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/BeginOperationEvent.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import org.eclipse.equinox.p2.engine.IEngine;
14 | import org.eclipse.equinox.p2.engine.IProfile;
15 |
16 |
17 | /**
18 | * @since 2.0
19 | */
20 | public class BeginOperationEvent extends TransactionEvent {
21 |
22 | private static final long serialVersionUID = 6389318375739324865L;
23 |
24 | public BeginOperationEvent(IProfile profile, PhaseSet phaseSet, Operand[] operands, IEngine engine) {
25 | super(profile, phaseSet, operands, engine);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/CommitOperationEvent.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import org.eclipse.equinox.p2.engine.IEngine;
14 | import org.eclipse.equinox.p2.engine.IProfile;
15 |
16 |
17 | /**
18 | * @since 2.0
19 | */
20 | public class CommitOperationEvent extends TransactionEvent {
21 | private static final long serialVersionUID = -523967775426133720L;
22 |
23 | public CommitOperationEvent(IProfile profile, PhaseSet phaseSet, Operand[] operands, IEngine engine) {
24 | super(profile, phaseSet, operands, engine);
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/p2/engine/IPhaseSet.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2009, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.p2.engine;
12 |
13 | /**
14 | * Describes a set of provisioning phases to be performed by an {@link IEngine}.
15 | *
16 | * @noimplement This interface is not intended to be implemented by clients.
17 | * @noextend This interface is not intended to be extended by clients.
18 | * @since 2.0
19 | */
20 | public interface IPhaseSet {
21 |
22 | /**
23 | * Returns the ids of the phases to be performed by this phase set. The order
24 | * of the returned ids indicates the order in which the phases will be run.
25 | * @return The phase ids.
26 | */
27 | public String[] getPhaseIds();
28 | }
29 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/p2/engine/spi/Value.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012, 2013 Landmark Graphics Corporation and others
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Landmark Graphics Corporation - initial API and implementation
10 | * IBM Corporation - ongoing maintenance
11 | *******************************************************************************/
12 | package org.eclipse.equinox.p2.engine.spi;
13 |
14 | /**
15 | * An object that encapsulates the result of performing a provisioning action.
16 | *
17 | * @see ProvisioningAction#getResult()
18 | * @since 2.3
19 | */
20 | public class Value {
21 | public static final Value NO_VALUE = new Value(null);
22 | private T value;
23 | private Class clazz;
24 |
25 | public Value(T val) {
26 | value = val;
27 | }
28 |
29 | public T getValue() {
30 | return value;
31 | }
32 |
33 | public Class getClazz() {
34 | return clazz;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/RollbackOperationEvent.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import org.eclipse.equinox.p2.engine.IEngine;
14 | import org.eclipse.equinox.p2.engine.IProfile;
15 |
16 | import org.eclipse.core.runtime.IStatus;
17 |
18 | /**
19 | * @since 2.0
20 | */
21 | public class RollbackOperationEvent extends TransactionEvent {
22 |
23 | private static final long serialVersionUID = -2076492953949691215L;
24 | private IStatus cause;
25 |
26 | public RollbackOperationEvent(IProfile profile, PhaseSet phaseSet, Operand[] operands, IEngine engine, IStatus cause) {
27 | super(profile, phaseSet, operands, engine);
28 | this.cause = cause;
29 | }
30 |
31 | public IStatus getStatus() {
32 | return cause;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/TransactionEvent.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import org.eclipse.equinox.p2.engine.IEngine;
14 | import org.eclipse.equinox.p2.engine.IProfile;
15 |
16 | import java.util.EventObject;
17 |
18 | /**
19 | * @since 2.0
20 | */
21 | public abstract class TransactionEvent extends EventObject {
22 | private static final long serialVersionUID = 6278706971855493984L;
23 | protected IProfile profile;
24 | protected PhaseSet phaseSet;
25 | protected Operand[] operands;
26 |
27 | public TransactionEvent(IProfile profile, PhaseSet phaseSet, Operand[] operands, IEngine engine) {
28 | super(engine);
29 | this.profile = profile;
30 | this.phaseSet = phaseSet;
31 | this.operands = operands;
32 | }
33 |
34 | public IProfile getProfile() {
35 | return profile;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/ISurrogateProfileHandler.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2008, 2013 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | * Ericsson AB - Bug 400011 - [shared] Cleanup the SurrogateProfileHandler code
11 | *******************************************************************************/
12 | package org.eclipse.equinox.internal.p2.engine;
13 |
14 | import org.eclipse.core.runtime.IProgressMonitor;
15 | import org.eclipse.equinox.p2.engine.IProfile;
16 | import org.eclipse.equinox.p2.metadata.IInstallableUnit;
17 | import org.eclipse.equinox.p2.query.IQuery;
18 | import org.eclipse.equinox.p2.query.IQueryResult;
19 |
20 | /**
21 | * @since 2.0
22 | */
23 | public interface ISurrogateProfileHandler {
24 |
25 | public abstract IProfile createProfile(String id);
26 |
27 | public abstract boolean isSurrogate(IProfile profile);
28 |
29 | public abstract IQueryResult queryProfile(IProfile profile, IQuery query, IProgressMonitor monitor);
30 |
31 | }
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/SizingPhaseSet.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 |
12 | package org.eclipse.equinox.internal.p2.engine;
13 |
14 | import org.eclipse.equinox.internal.p2.engine.phases.Sizing;
15 | import org.eclipse.equinox.p2.engine.ISizingPhaseSet;
16 |
17 | public class SizingPhaseSet extends PhaseSet implements ISizingPhaseSet {
18 |
19 | private static Sizing sizing;
20 |
21 | public SizingPhaseSet() {
22 | super(new Phase[] {sizing = new Sizing(100)});
23 | }
24 |
25 | /* (non-Javadoc)
26 | * @see org.eclipse.equinox.p2.engine.ISizingPhaseSet#getDiskSize()
27 | */
28 | public long getDiskSize() {
29 | return sizing.getDiskSize();
30 | }
31 |
32 | /* (non-Javadoc)
33 | * @see org.eclipse.equinox.p2.engine.ISizingPhaseSet#getDownloadSize()
34 | */
35 | public long getDownloadSize() {
36 | return sizing.getDownloadSize();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/PhaseEvent.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012 Wind River and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Wind River - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import java.util.EventObject;
14 |
15 | public class PhaseEvent extends EventObject {
16 |
17 | private static final long serialVersionUID = 8971345257149340658L;
18 |
19 | public static final int TYPE_START = 1;
20 | public static final int TYPE_END = 2;
21 |
22 | private int type;
23 |
24 | private String phaseId;
25 |
26 | private Operand[] operands;
27 |
28 | public PhaseEvent(String phaseId, Operand[] operands, int type) {
29 | super(operands);
30 | this.phaseId = phaseId;
31 | this.type = type;
32 | this.operands = operands;
33 | }
34 |
35 | public String getPhaseId() {
36 | return phaseId;
37 | }
38 |
39 | public int getType() {
40 | return type;
41 | }
42 |
43 | public Operand[] getOperands() {
44 | return operands;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/ProfileRegistryComponent.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2009, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus;
14 | import org.eclipse.equinox.p2.core.IAgentLocation;
15 | import org.eclipse.equinox.p2.core.IProvisioningAgent;
16 | import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory;
17 | import org.eclipse.equinox.p2.engine.IProfileRegistry;
18 |
19 | /**
20 | * Instantiates default instances of {@link IProfileRegistry}.
21 | */
22 | public class ProfileRegistryComponent implements IAgentServiceFactory {
23 |
24 | public Object createService(IProvisioningAgent agent) {
25 | IAgentLocation location = (IAgentLocation) agent.getService(IAgentLocation.SERVICE_NAME);
26 | SimpleProfileRegistry registry = new SimpleProfileRegistry(agent, SimpleProfileRegistry.getDefaultRegistryDirectory(location));
27 | registry.setEventBus((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME));
28 | return registry;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/EngineComponent.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2009, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import org.eclipse.equinox.p2.core.IProvisioningAgent;
14 | import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory;
15 | import org.eclipse.equinox.p2.engine.IEngine;
16 |
17 | /**
18 | * Component that provides a factory that can create and initialize
19 | * {@link IEngine} instances.
20 | */
21 | public class EngineComponent implements IAgentServiceFactory {
22 |
23 | /*(non-Javadoc)
24 | * @see org.eclipse.equinox.p2.core.spi.IAgentServiceFactory#createService(org.eclipse.equinox.p2.core.IProvisioningAgent)
25 | */
26 | public Object createService(IProvisioningAgent agent) {
27 | //ensure there is a garbage collector created for this agent if available
28 | agent.getService("org.eclipse.equinox.internal.p2.garbagecollector.GarbageCollector"); //$NON-NLS-1$
29 | //various parts of the engine may need an open-ended set of services, so we pass the agent to the engine directly
30 | return new Engine(agent);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/ProfileMetadataRepositoryFactory.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2008, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import java.net.URI;
14 | import java.util.Map;
15 | import org.eclipse.core.runtime.IProgressMonitor;
16 | import org.eclipse.equinox.p2.core.ProvisionException;
17 | import org.eclipse.equinox.p2.repository.IRepositoryManager;
18 | import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
19 | import org.eclipse.equinox.p2.repository.metadata.spi.MetadataRepositoryFactory;
20 |
21 | public class ProfileMetadataRepositoryFactory extends MetadataRepositoryFactory {
22 |
23 | /**
24 | * @throws ProvisionException
25 | * documenting to avoid warning
26 | */
27 | public IMetadataRepository create(URI location, String name, String type, Map properties) throws ProvisionException {
28 | return null;
29 | }
30 |
31 | public IMetadataRepository load(URI location, int flags, IProgressMonitor monitor) throws ProvisionException {
32 | //return null if the caller wanted a modifiable repo
33 | if ((flags & IRepositoryManager.REPOSITORY_HINT_MODIFIABLE) > 0) {
34 | return null;
35 | }
36 | return new ProfileMetadataRepository(getAgent(), location, monitor);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/ProfileXMLConstants.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import org.eclipse.equinox.internal.p2.persistence.XMLConstants;
14 | import org.eclipse.equinox.p2.metadata.Version;
15 | import org.eclipse.equinox.p2.metadata.VersionRange;
16 |
17 | /**
18 | * Constants defining the structure of the XML for a Profile
19 | */
20 | public interface ProfileXMLConstants extends XMLConstants {
21 |
22 | // A format version number for profile XML.
23 | public static final Version CURRENT_VERSION = Version.createOSGi(1, 0, 0);
24 | public static final Version COMPATIBLE_VERSION = Version.createOSGi(0, 0, 1);
25 | public static final VersionRange XML_TOLERANCE = new VersionRange(COMPATIBLE_VERSION, true, Version.createOSGi(2, 0, 0), false);
26 |
27 | // Constants for profile elements
28 |
29 | public static final String PROFILE_ELEMENT = "profile"; //$NON-NLS-1$
30 | public static final String TIMESTAMP_ATTRIBUTE = "timestamp"; //$NON-NLS-1$
31 | public static final String IUS_PROPERTIES_ELEMENT = "iusProperties"; //$NON-NLS-1$
32 | public static final String IU_PROPERTIES_ELEMENT = "iuProperties"; //$NON-NLS-1$
33 | public static final String PROFILE_TARGET = "profile"; //$NON-NLS-1$
34 | }
35 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/p2/engine/IProfileEvent.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.p2.engine;
12 |
13 | import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus;
14 |
15 | /**
16 | * An event indicating that a profile has been added, removed, or changed.
17 | * @see IProvisioningEventBus
18 | * @since 2.0
19 | */
20 | public interface IProfileEvent {
21 |
22 | /**
23 | * Event constant (value 0) indicating that a profile has been added to a profile registry.
24 | */
25 | public static final int ADDED = 0;
26 | /**
27 | * Event constant (value 1) indicating that a profile has been removed from a profile registry.
28 | */
29 | public static final int REMOVED = 1;
30 | /**
31 | * Event constant (value 0) indicating that a profile has been changed in a profile registry.
32 | */
33 | public static final int CHANGED = 2;
34 |
35 | /**
36 | * Returns the reason for the event. The reason will be one of the event constants
37 | * {@link #ADDED}, {@link #REMOVED}, or {@link #CHANGED}.
38 | * @return the reason for the event
39 | */
40 | public int getReason();
41 |
42 | /**
43 | * Returns the id of the profile that changed.
44 | * @return the id of the profile that changed
45 | */
46 | public String getProfileId();
47 |
48 | }
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/p2/engine/query/UserVisibleRootQuery.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2009, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | * Cloudsmith Inc. - converted into expression based query
11 | *******************************************************************************/
12 | package org.eclipse.equinox.p2.engine.query;
13 |
14 | import org.eclipse.equinox.p2.engine.IProfile;
15 | import org.eclipse.equinox.p2.metadata.IInstallableUnit;
16 |
17 | /**
18 | * A query matching all the {@link IInstallableUnit}s that are marked visible to the user.
19 | * @since 2.0
20 | */
21 | public class UserVisibleRootQuery extends IUProfilePropertyQuery {
22 |
23 | /**
24 | * Creates a new query that will match all installable units marked visible to the user.
25 | */
26 | public UserVisibleRootQuery() {
27 | super(IProfile.PROP_PROFILE_ROOT_IU, Boolean.TRUE.toString());
28 | }
29 |
30 | /**
31 | * Test if the {@link IInstallableUnit}, in the context of a {@link IProfile} is visible to the user
32 | * @param iu the element being tested.
33 | * @param profile the context in which the iu is tested
34 | * @return true if the element is visible to the user.
35 | */
36 | public static boolean isUserVisible(IInstallableUnit iu, IProfile profile) {
37 | String value = profile.getInstallableUnitProperty(iu, IProfile.PROP_PROFILE_ROOT_IU);
38 | return Boolean.valueOf(value).booleanValue();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/InstallableUnitOperand.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import org.eclipse.core.runtime.Assert;
14 | import org.eclipse.equinox.p2.metadata.IInstallableUnit;
15 |
16 | /**
17 | * @since 2.0
18 | */
19 | public class InstallableUnitOperand extends Operand {
20 | private final IInstallableUnit first;
21 | private final IInstallableUnit second;
22 |
23 | /**
24 | * Creates a new operand that represents replacing an installable unit
25 | * with another. At least one of the provided installable units must be
26 | * non-null.
27 | *
28 | * @param first The installable unit being removed, or null
29 | * @param second The installable unit being added, or null
30 | */
31 | public InstallableUnitOperand(IInstallableUnit first, IInstallableUnit second) {
32 | //the operand must have at least one non-null units
33 | Assert.isTrue(first != null || second != null);
34 | this.first = first;
35 | this.second = second;
36 | }
37 |
38 | public IInstallableUnit first() {
39 | return first;
40 | }
41 |
42 | public IInstallableUnit second() {
43 | return second;
44 | }
45 |
46 | public String toString() {
47 | return first + " --> " + second; //$NON-NLS-1$
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/MissingAction.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2009, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import java.util.Map;
14 | import org.eclipse.core.runtime.IStatus;
15 | import org.eclipse.core.runtime.Status;
16 | import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
17 | import org.eclipse.equinox.p2.metadata.VersionRange;
18 | import org.eclipse.osgi.util.NLS;
19 |
20 | /**
21 | * @since 2.0
22 | */
23 | public class MissingAction extends ProvisioningAction {
24 |
25 | private String actionId;
26 | private VersionRange versionRange;
27 |
28 | public MissingAction(String actionId, VersionRange versionRange) {
29 | this.actionId = actionId;
30 | this.versionRange = versionRange;
31 | }
32 |
33 | public String getActionId() {
34 | return actionId;
35 | }
36 |
37 | public VersionRange getVersionRange() {
38 | return versionRange;
39 | }
40 |
41 | public IStatus execute(Map parameters) {
42 | throw new IllegalArgumentException(NLS.bind(Messages.action_not_found, actionId + (versionRange == null ? "" : "/" + versionRange.toString()))); //$NON-NLS-1$ //$NON-NLS-2$
43 | }
44 |
45 | public IStatus undo(Map parameters) {
46 | // do nothing as we want this action to undo successfully
47 | return Status.OK_STATUS;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/InstallableUnitPropertyOperand.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2008, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import org.eclipse.core.runtime.Assert;
14 | import org.eclipse.equinox.p2.metadata.IInstallableUnit;
15 |
16 | /**
17 | * @since 2.0
18 | */
19 | public class InstallableUnitPropertyOperand extends PropertyOperand {
20 | private final IInstallableUnit iu;
21 |
22 | /**
23 | * Creates a new operand that represents replacing a property value associated
24 | * with an IU with another. At least one of the provided property values must be
25 | * non-null.
26 | *
27 | * @param iu The IInstallableUnit with which the property is associated
28 | * @param key The key of the property being modified
29 | * @param first The property value being removed, or null
30 | * @param second The property value being added, or null
31 | */
32 | public InstallableUnitPropertyOperand(IInstallableUnit iu, String key, Object first, Object second) {
33 | super(key, first, second);
34 | //the iu must be specified.
35 | Assert.isTrue(iu != null);
36 | this.iu = iu;
37 | }
38 |
39 | public IInstallableUnit getInstallableUnit() {
40 | return iu;
41 | }
42 |
43 | public String toString() {
44 | return "[IInstallableUnit property for " + iu.toString() + "] " + super.toString(); //$NON-NLS-1$ //$NON-NLS-2$
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/PropertyOperand.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2008, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import org.eclipse.core.runtime.Assert;
14 |
15 | /**
16 | * @since 2.0
17 | */
18 | public class PropertyOperand extends Operand {
19 | private final Object first;
20 | private final Object second;
21 | private final String key;
22 |
23 | /**
24 | * Creates a new operand that represents replacing a property value
25 | * with another. At least one of the provided property values must be
26 | * non-null.
27 | *
28 | * @param key The key of the property being modified
29 | * @param first The property value being removed, or null
30 | * @param second The property value being added, or null
31 | */
32 | public PropertyOperand(String key, Object first, Object second) {
33 | //the operand must specify have a key and have at least one non-null value
34 | Assert.isTrue(key != null && (first != null || second != null));
35 | this.first = first;
36 | this.second = second;
37 | this.key = key;
38 | }
39 |
40 | public Object first() {
41 | return first;
42 | }
43 |
44 | public Object second() {
45 | return second;
46 | }
47 |
48 | public String getKey() {
49 | return key;
50 | }
51 |
52 | public String toString() {
53 | return key + " = " + first + " --> " + second; //$NON-NLS-1$ //$NON-NLS-2$
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/MissingActionsException.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2009, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import org.eclipse.equinox.p2.core.ProvisionException;
14 | import org.eclipse.osgi.util.NLS;
15 |
16 | /**
17 | * @since 2.0
18 | */
19 | public class MissingActionsException extends ProvisionException {
20 |
21 | private static final long serialVersionUID = 8617693596359747490L;
22 | private final MissingAction[] missingActions;
23 |
24 | public MissingActionsException(MissingAction[] missingActions) {
25 | super(getMissingActionsMessage(missingActions));
26 | this.missingActions = missingActions;
27 | }
28 |
29 | private static String getMissingActionsMessage(MissingAction[] missingActions) {
30 |
31 | if (missingActions.length == 0)
32 | throw new IllegalArgumentException("Bad exception: No missing actions"); //$NON-NLS-1$
33 |
34 | StringBuffer buffer = new StringBuffer();
35 | for (int i = 0; i < missingActions.length; i++) {
36 | MissingAction missingAction = missingActions[i];
37 | buffer.append(missingAction.getActionId());
38 | if (missingAction.getVersionRange() != null) {
39 | buffer.append("/"); //$NON-NLS-1$
40 | buffer.append(missingAction.getVersionRange().toString());
41 | }
42 | if (i + 1 != missingActions.length)
43 | buffer.append(", "); //$NON-NLS-1$
44 | }
45 |
46 | return NLS.bind(Messages.actions_not_found, buffer.toString());
47 | }
48 |
49 | public MissingAction[] getMissingActions() {
50 | return missingActions;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/ProfileEvent.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import java.util.EventObject;
14 | import org.eclipse.equinox.p2.engine.IProfileEvent;
15 |
16 | /**
17 | * @noextend This class is not intended to be subclassed by clients.
18 | * @since 2.0
19 | */
20 | public class ProfileEvent extends EventObject implements IProfileEvent {
21 | private static final long serialVersionUID = 3082402920617281765L;
22 |
23 | private int reason;
24 |
25 | public ProfileEvent(String profileId, int reason) {
26 | super(profileId);
27 | this.reason = reason;
28 | }
29 |
30 | /* (non-Javadoc)
31 | * @see org.eclipse.equinox.p2.engine.IProfileEvent#getReason()
32 | */
33 | public int getReason() {
34 | return reason;
35 | }
36 |
37 | /* (non-Javadoc)
38 | * @see org.eclipse.equinox.p2.engine.IProfileEvent#getProfileId()
39 | */
40 | public String getProfileId() {
41 | return (String) getSource();
42 | }
43 |
44 | /*
45 | * (non-Javadoc)
46 | * @see java.util.EventObject#toString()
47 | */
48 | public String toString() {
49 | StringBuffer buffer = new StringBuffer();
50 | buffer.append("ProfileEvent["); //$NON-NLS-1$
51 | buffer.append(getProfileId());
52 | buffer.append("-->"); //$NON-NLS-1$
53 | switch (reason) {
54 | case IProfileEvent.ADDED :
55 | buffer.append("ADDED"); //$NON-NLS-1$
56 | break;
57 | case IProfileEvent.REMOVED :
58 | buffer.append("REMOVED"); //$NON-NLS-1$
59 | break;
60 | case IProfileEvent.CHANGED :
61 | buffer.append("CHANGED"); //$NON-NLS-1$
62 | break;
63 | }
64 | buffer.append("] "); //$NON-NLS-1$
65 | return buffer.toString();
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/p2/engine/spi/ProvisioningAction.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2013 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | * Landmark Graphics Corporation - bug 397183
11 | *******************************************************************************/
12 | package org.eclipse.equinox.p2.engine.spi;
13 |
14 | import java.util.Map;
15 | import org.eclipse.core.runtime.IStatus;
16 |
17 | /**
18 | * An action that performs one step of a provisioning operation for a particular
19 | * {@link Touchpoint}.
20 | * @since 2.0
21 | */
22 | public abstract class ProvisioningAction {
23 |
24 | private Memento memento;
25 | private Touchpoint touchpoint;
26 |
27 | protected Memento getMemento() {
28 | if (memento == null)
29 | memento = new Memento();
30 | return memento;
31 | }
32 |
33 | /**
34 | * Performs the provisioning action.
35 | * @param parameters The action parameters
36 | * @return A status indicating whether the action was successful
37 | */
38 | public abstract IStatus execute(Map parameters);
39 |
40 | /**
41 | * Performs the inverse of this provisioning action. This should reverse
42 | * any effects from a previous invocation of the {@link #execute(Map)} method.
43 | * @param parameters The action parameters
44 | * @return A status indicating whether the action was successful
45 | */
46 | public abstract IStatus undo(Map parameters);
47 |
48 | /**
49 | * This method is meant for provisioning actions that need to communicate the result of their execution
50 | * to subsequent actions.
51 | * This method is only invoked by p2 once execute() has been executed.
52 | * @return the result of the action execution.
53 | * @since 2.3
54 | */
55 | public Value> getResult() {
56 | return Value.NO_VALUE;
57 | }
58 |
59 | // TODO: these probably should not be visible
60 | public void setTouchpoint(Touchpoint touchpoint) {
61 | this.touchpoint = touchpoint;
62 | }
63 |
64 | /**
65 | * Returns the touchpoint that this action is operating under.
66 | * @return the touchpoint
67 | */
68 | public Touchpoint getTouchpoint() {
69 | return touchpoint;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/p2/engine/query/IUProfilePropertyQuery.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | * Cloudsmith Inc. - converted into expression based query
11 | *******************************************************************************/
12 | package org.eclipse.equinox.p2.engine.query;
13 |
14 | import org.eclipse.equinox.p2.metadata.IInstallableUnit;
15 | import org.eclipse.equinox.p2.metadata.expression.*;
16 | import org.eclipse.equinox.p2.query.ExpressionMatchQuery;
17 |
18 | /**
19 | * A query that searches for {@link IInstallableUnit} instances that have
20 | * a property associated with the specified profile, whose value matches the provided value.
21 | * @since 2.0
22 | */
23 | public class IUProfilePropertyQuery extends ExpressionMatchQuery {
24 | /**
25 | * A property value constant that will match any defined property value.
26 | * @see #IUProfilePropertyQuery(String, String)
27 | */
28 | public static final String ANY = "*"; //$NON-NLS-1$
29 |
30 | private static final IExpression matchValue = ExpressionUtil.parse("profileProperties[$0] == $1"); //$NON-NLS-1$
31 | private static final IExpression matchAny = ExpressionUtil.parse("profileProperties[$0] != null"); //$NON-NLS-1$
32 |
33 | private static IMatchExpression createMatch(String propertyName, String propertyValue) {
34 | IExpressionFactory factory = ExpressionUtil.getFactory();
35 | return ANY.equals(propertyValue) ? factory. matchExpression(matchAny, propertyName) : factory. matchExpression(matchValue, propertyName, propertyValue);
36 | }
37 |
38 | /**
39 | * Creates a new query on the given property name and value.
40 | * Because the queryable for this query is typically the profile
41 | * instance, we use a reference to the profile rather than the
42 | * profile id for performance reasons.
43 | * @param propertyName The name of the property to match
44 | * @param propertyValue The value to compare to. A value of {@link #ANY} will match any value.
45 | */
46 | public IUProfilePropertyQuery(String propertyName, String propertyValue) {
47 | super(IInstallableUnit.class, createMatch(propertyName, propertyValue));
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/EngineActivator.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import org.osgi.framework.BundleActivator;
14 | import org.osgi.framework.BundleContext;
15 |
16 | public class EngineActivator implements BundleActivator {
17 | private static BundleContext context;
18 | public static final String ID = "org.eclipse.equinox.p2.engine"; //$NON-NLS-1$
19 |
20 | /**
21 | * System property describing the profile registry file format
22 | */
23 | public static final String PROP_PROFILE_FORMAT = "eclipse.p2.profileFormat"; //$NON-NLS-1$
24 |
25 | /**
26 | * Value for the PROP_PROFILE_FORMAT system property specifying raw XML file
27 | * format (used in p2 until and including 3.5.0 release).
28 | */
29 | public static final String PROFILE_FORMAT_UNCOMPRESSED = "uncompressed"; //$NON-NLS-1$
30 |
31 | /**
32 | * System property specifying how the engine should handle unsigned artifacts.
33 | * If this property is undefined, the default value is assumed to be "prompt".
34 | */
35 | public static final String PROP_UNSIGNED_POLICY = "eclipse.p2.unsignedPolicy"; //$NON-NLS-1$
36 |
37 | /**
38 | * System property value specifying that the engine should prompt for confirmation
39 | * when installing unsigned artifacts.
40 | */
41 | public static final String UNSIGNED_PROMPT = "prompt"; //$NON-NLS-1$
42 |
43 | /**
44 | * System property value specifying that the engine should fail when an attempt
45 | * is made to install unsigned artifacts.
46 | */
47 | public static final String UNSIGNED_FAIL = "fail"; //$NON-NLS-1$
48 |
49 | /**
50 | * System property value specifying that the engine should silently allow unsigned
51 | * artifacts to be installed.
52 | */
53 | public static final String UNSIGNED_ALLOW = "allow"; //$NON-NLS-1$
54 |
55 | public static BundleContext getContext() {
56 | return context;
57 | }
58 |
59 | public void start(BundleContext aContext) throws Exception {
60 | EngineActivator.context = aContext;
61 | }
62 |
63 | public void stop(BundleContext aContext) throws Exception {
64 | EngineActivator.context = null;
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/CollectEvent.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012 Wind River and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Wind River - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import java.util.EventObject;
14 | import org.eclipse.equinox.p2.engine.ProvisioningContext;
15 | import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
16 | import org.eclipse.equinox.p2.repository.artifact.IArtifactRequest;
17 |
18 | public class CollectEvent extends EventObject {
19 |
20 | private static final long serialVersionUID = 5782796765127875200L;
21 | /**
22 | * It means the overall collecting requests are started.
23 | */
24 | public static final int TYPE_OVERALL_START = 1;
25 | /**
26 | * It means the overall collecting requests are finished.
27 | */
28 | public static final int TYPE_OVERALL_END = 2;
29 | /**
30 | * It means the collecting requests related to a special repository are started.
31 | * See {@link CollectEvent#getRepository()}
32 | */
33 | public static final int TYPE_REPOSITORY_START = 3;
34 | /**
35 | * It means the collecting requests related to a special repository are end.
36 | * See {@link CollectEvent#getRepository()}
37 | */
38 | public static final int TYPE_REPOSITORY_END = 4;
39 |
40 | private IArtifactRepository artifactRepo;
41 | private IArtifactRequest[] requests;
42 |
43 | private ProvisioningContext context;
44 |
45 | private int type;
46 |
47 | public CollectEvent(int type, IArtifactRepository artifactRepo, ProvisioningContext context, IArtifactRequest[] requests) {
48 | super(requests);
49 | this.type = type;
50 | this.artifactRepo = artifactRepo;
51 | this.context = context;
52 | this.requests = requests;
53 | }
54 |
55 | public int getType() {
56 | return type;
57 | }
58 |
59 | /**
60 | * Return the associated repository if the downloading requests are related to a special repository
61 | * @return the associated repository or null if the repository is unknown
62 | */
63 | public IArtifactRepository getRepository() {
64 | return artifactRepo;
65 | }
66 |
67 | public IArtifactRequest[] getDownloadRequests() {
68 | return requests;
69 | }
70 |
71 | public ProvisioningContext getContext() {
72 | return context;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/pull_request_template.md:
--------------------------------------------------------------------------------
1 | ## Purpose
2 | > Describe the problems, issues, or needs driving this feature/fix and include links to related issues in the following format: Resolves issue1, issue2, etc.
3 |
4 | ## Goals
5 | > Describe the solutions that this feature/fix will introduce to resolve the problems described above
6 |
7 | ## Approach
8 | > Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email documentation@wso2.com to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here.
9 |
10 | ## User stories
11 | > Summary of user stories addressed by this change>
12 |
13 | ## Release note
14 | > Brief description of the new feature or bug fix as it will appear in the release notes
15 |
16 | ## Documentation
17 | > Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact
18 |
19 | ## Training
20 | > Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable
21 |
22 | ## Certification
23 | > Type “Sent” when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type “N/A” and explain why.
24 |
25 | ## Marketing
26 | > Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable
27 |
28 | ## Automation tests
29 | - Unit tests
30 | > Code coverage information
31 | - Integration tests
32 | > Details about the test cases and coverage
33 |
34 | ## Security checks
35 | - Followed secure coding standards in http://wso2.com/technical-reports/wso2-secure-engineering-guidelines? yes/no
36 | - Ran FindSecurityBugs plugin and verified report? yes/no
37 | - Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets? yes/no
38 |
39 | ## Samples
40 | > Provide high-level details about the samples related to this feature
41 |
42 | ## Related PRs
43 | > List any other related PRs
44 |
45 | ## Migrations (if applicable)
46 | > Describe migration steps and platforms on which migration has been tested
47 |
48 | ## Test environment
49 | > List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested
50 |
51 | ## Learning
52 | > Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem.
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/p2/engine/spi/Memento.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2011 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.p2.engine.spi;
12 |
13 | import java.util.*;
14 |
15 | /**
16 | * @since 2.0
17 | */
18 | public final class Memento {
19 | private static final Collection> simples = Arrays.> asList(String.class, Integer.class, Long.class, Float.class, Double.class, Byte.class, Short.class, Character.class, Boolean.class);
20 | private static final Collection> simpleArrays = Arrays.> asList(String[].class, Integer[].class, Long[].class, Float[].class, Double[].class, Byte[].class, Short[].class, Character[].class, Boolean[].class);
21 | private static final Collection> primitiveArrays = Arrays.> asList(long[].class, int[].class, short[].class, char[].class, byte[].class, double[].class, float[].class, boolean[].class);
22 |
23 | Map mementoMap = new HashMap();
24 |
25 | public Object remove(String key) {
26 | if (key == null)
27 | throw new NullPointerException();
28 |
29 | // TODO: persist change
30 | return mementoMap.remove(key);
31 | }
32 |
33 | public Object put(String key, Object value) {
34 | if (key == null)
35 | throw new NullPointerException();
36 |
37 | validateValue(value);
38 |
39 | // TODO: persist change
40 | return mementoMap.put(key, value);
41 | }
42 |
43 | public Object get(String key) {
44 | if (key == null)
45 | throw new NullPointerException();
46 |
47 | return mementoMap.get(key);
48 | }
49 |
50 | public Enumeration getKeys() {
51 | return new Enumeration() {
52 | Iterator keysIterator = mementoMap.keySet().iterator();
53 |
54 | public boolean hasMoreElements() {
55 | return keysIterator.hasNext();
56 | }
57 |
58 | public String nextElement() {
59 | return keysIterator.next();
60 | }
61 | };
62 | }
63 |
64 | private static void validateValue(Object value) {
65 | if (value == null)
66 | return;
67 |
68 | Class extends Object> clazz = value.getClass();
69 |
70 | if (simples.contains(clazz))
71 | return;
72 |
73 | if (simpleArrays.contains(clazz) || primitiveArrays.contains(clazz))
74 | return;
75 |
76 | throw new IllegalArgumentException(clazz.getName());
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/SlashEncode.java:
--------------------------------------------------------------------------------
1 | package org.eclipse.equinox.internal.p2.engine;
2 |
3 | /**
4 | * Utility class to encode forward slash characters so that strings containing
5 | * forward slashes can be used as node names with secure preferences. It is
6 | * the responsibility of the consumer to manually encode such strings before
7 | * attempting to obtain corresponding nodes from secure preferences.
8 | *
9 | * Internally, the class uses a subset of JIT encoding. The forward slashes
10 | * and backward slashes are encoded.
11 | *
12 | * This class is not intended to be instantiated or subclassed by users.
13 | *
14 | */
15 | final public class SlashEncode {
16 |
17 | final private static char SLASH = '/';
18 | final private static char BACK_SLASH = '\\';
19 |
20 | final private static String ENCODED_SLASH = "\\2f"; //$NON-NLS-1$
21 | final private static String ENCODED_BACK_SLASH = "\\5c"; //$NON-NLS-1$
22 |
23 | static public String decode(String str) {
24 | if (str == null)
25 | return null;
26 | int size = str.length();
27 | if (size == 0)
28 | return str;
29 |
30 | StringBuffer processed = new StringBuffer(size);
31 | int processedPos = 0;
32 |
33 | for (int i = 0; i < size; i++) {
34 | char c = str.charAt(i);
35 | if (c == BACK_SLASH) {
36 | if (i + 2 >= size)
37 | continue;
38 | String encoded = str.substring(i, i + 3);
39 | char decoded = 0;
40 | if (ENCODED_SLASH.equals(encoded))
41 | decoded = SLASH;
42 | else if (ENCODED_BACK_SLASH.equals(encoded))
43 | decoded = BACK_SLASH;
44 | if (decoded == 0)
45 | continue;
46 | if (i > processedPos)
47 | processed.append(str.substring(processedPos, i));
48 | processed.append(decoded);
49 | processedPos = i + 3;
50 | i += 2; // skip over remaining encoded portion
51 | }
52 | }
53 | if (processedPos == 0)
54 | return str;
55 | if (processedPos < size)
56 | processed.append(str.substring(processedPos));
57 | return new String(processed);
58 | }
59 |
60 | static public String encode(String str) {
61 | if (str == null)
62 | return null;
63 | int size = str.length();
64 | if (size == 0)
65 | return str;
66 |
67 | StringBuffer processed = new StringBuffer(size);
68 | int processedPos = 0;
69 |
70 | for (int i = 0; i < size; i++) {
71 | char c = str.charAt(i);
72 | if (c == SLASH || c == BACK_SLASH) {
73 | if (i > processedPos)
74 | processed.append(str.substring(processedPos, i));
75 | if (c == SLASH)
76 | processed.append(ENCODED_SLASH);
77 | else if (c == BACK_SLASH)
78 | processed.append(ENCODED_BACK_SLASH);
79 | processedPos = i + 1;
80 | }
81 | }
82 | if (processedPos == 0)
83 | return str;
84 | if (processedPos < size)
85 | processed.append(str.substring(processedPos));
86 | return new String(processed);
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/ProfileWriter.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import org.eclipse.equinox.p2.query.QueryUtil;
14 |
15 | import java.io.IOException;
16 | import java.io.OutputStream;
17 | import java.util.*;
18 | import org.eclipse.equinox.internal.p2.metadata.repository.io.MetadataWriter;
19 | import org.eclipse.equinox.p2.engine.IProfile;
20 | import org.eclipse.equinox.p2.metadata.IInstallableUnit;
21 |
22 | public class ProfileWriter extends MetadataWriter implements ProfileXMLConstants {
23 |
24 | public ProfileWriter(OutputStream output, ProcessingInstruction[] processingInstructions) throws IOException {
25 | super(output, processingInstructions);
26 | }
27 |
28 | public void writeProfile(IProfile profile) {
29 | start(PROFILE_ELEMENT);
30 | attribute(ID_ATTRIBUTE, profile.getProfileId());
31 | attribute(TIMESTAMP_ATTRIBUTE, Long.toString(profile.getTimestamp()));
32 | writeProperties(profile.getProperties());
33 | ArrayList ius = new ArrayList(profile.query(QueryUtil.createIUAnyQuery(), null).toUnmodifiableSet());
34 | Collections.sort(ius, new Comparator() {
35 | public int compare(IInstallableUnit iu1, IInstallableUnit iu2) {
36 | int IdCompare = iu1.getId().compareTo(iu2.getId());
37 | if (IdCompare != 0)
38 | return IdCompare;
39 |
40 | return iu1.getVersion().compareTo(iu2.getVersion());
41 | }
42 | });
43 | writeInstallableUnits(ius.iterator(), ius.size());
44 | writeInstallableUnitsProperties(ius.iterator(), ius.size(), profile);
45 | end(PROFILE_ELEMENT);
46 | flush();
47 | }
48 |
49 | private void writeInstallableUnitsProperties(Iterator it, int size, IProfile profile) {
50 | if (size == 0)
51 | return;
52 | start(IUS_PROPERTIES_ELEMENT);
53 | attribute(COLLECTION_SIZE_ATTRIBUTE, size);
54 | while (it.hasNext()) {
55 | IInstallableUnit iu = it.next();
56 | Map properties = profile.getInstallableUnitProperties(iu);
57 | if (properties.isEmpty())
58 | continue;
59 |
60 | start(IU_PROPERTIES_ELEMENT);
61 | attribute(ID_ATTRIBUTE, iu.getId());
62 | attribute(VERSION_ATTRIBUTE, iu.getVersion().toString());
63 | writeProperties(properties);
64 | end(IU_PROPERTIES_ELEMENT);
65 | }
66 | end(IUS_PROPERTIES_ELEMENT);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/p2/engine/IEngine.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2008, 2010 Band XI International, LLC and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Band XI - initial API and implementation
10 | * IBM - ongoing development
11 | *******************************************************************************/
12 | package org.eclipse.equinox.p2.engine;
13 |
14 | import org.eclipse.core.runtime.IProgressMonitor;
15 | import org.eclipse.core.runtime.IStatus;
16 |
17 | /**
18 | * The engine is a service that naively performs a set of requested changes to a provisioned
19 | * system. No attempt is made to determine whether the requested changes or the
20 | * resulting system are valid or consistent. It is assumed that the engine client has
21 | * crafted a valid provisioning plan for the engine to perform, typically by using a planner
22 | * service.
23 | *
24 | * The engine operates by executing a series of installation phases. The client can
25 | * customize the set of phases that are executed, or else the engine will execute
26 | * a default set of phases. During each phase the changes described by the provisioning
27 | * plan are performed against the profile being provisioned.
28 | *
29 | * @noimplement This interface is not intended to be implemented by clients.
30 | * @noextend This interface is not intended to be extended by clients.
31 | * @since 2.0
32 | */
33 | public interface IEngine {
34 | /**
35 | * Service name constant for the engine service.
36 | */
37 | public static final String SERVICE_NAME = IEngine.class.getName();
38 |
39 | /**
40 | * Creates a provisioning plan whose methods can be use to provide pre-validated changes.
41 | * This is an advanced method for clients that know they are creating changes that do
42 | * not require validation by a planner. Most clients should instead obtain a validated plan
43 | * from a planner.
44 | *
45 | * @param profile The profile to operate against
46 | * @param context The provisioning context for the plan
47 | * @return A provisioning plan
48 | */
49 |
50 | public IProvisioningPlan createPlan(IProfile profile, ProvisioningContext context);
51 |
52 | /**
53 | * Executes a provisioning plan.
54 | *
55 | * @param plan The plan describing the changes to be made
56 | * @param phaseSet The phases to run, or null to run default phases
57 | * @param monitor A progress monitor, or null if progress reporting is not required
58 | * @return The result of executing the plan
59 | */
60 | public IStatus perform(IProvisioningPlan plan, IPhaseSet phaseSet, IProgressMonitor monitor);
61 |
62 | /**
63 | * Executes a provisioning plan with a default phase set and context.
64 | *
65 | * @param plan The plan describing the changes to be made
66 | * @param monitor A progress monitor, or null if progress reporting is not required
67 | * @return The result of executing the plan
68 | */
69 | public IStatus perform(IProvisioningPlan plan, IProgressMonitor monitor);
70 | }
71 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/InstallableUnitEvent.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2012 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | * Wind River - ongoing development
11 | *******************************************************************************/
12 | package org.eclipse.equinox.internal.p2.engine;
13 |
14 | import java.util.EventObject;
15 | import org.eclipse.core.runtime.IStatus;
16 | import org.eclipse.core.runtime.Status;
17 | import org.eclipse.equinox.p2.engine.IProfile;
18 | import org.eclipse.equinox.p2.engine.spi.Touchpoint;
19 | import org.eclipse.equinox.p2.metadata.IInstallableUnit;
20 |
21 | /**
22 | * @since 2.0
23 | */
24 | public class InstallableUnitEvent extends EventObject {
25 | public static final int UNINSTALL = 0;
26 | public static final int INSTALL = 1;
27 | public static final int UNCONFIGURE = 2;
28 | public static final int CONFIGURE = 3;
29 | private static final long serialVersionUID = 3318712818811459886L;
30 |
31 | private String phaseId;
32 | private boolean prePhase;
33 |
34 | private IProfile profile;
35 | private IInstallableUnit iu;
36 | private Touchpoint touchpoint;
37 | private IStatus result;
38 | private int type;
39 |
40 | public InstallableUnitEvent(String phaseId, boolean prePhase, IProfile profile, IInstallableUnit iu, int type, Touchpoint touchpoint) {
41 | this(phaseId, prePhase, profile, iu, type, touchpoint, null);
42 | }
43 |
44 | public InstallableUnitEvent(String phaseId, boolean prePhase, IProfile profile, IInstallableUnit iu, int type, Touchpoint touchpoint, IStatus result) {
45 | super(profile);
46 | this.phaseId = phaseId;
47 | this.prePhase = prePhase;
48 | this.profile = profile;
49 | this.iu = iu;
50 | if (type != UNINSTALL && type != INSTALL && type != UNCONFIGURE && type != CONFIGURE)
51 | throw new IllegalArgumentException(Messages.InstallableUnitEvent_type_not_install_or_uninstall_or_configure);
52 | this.type = type;
53 | this.result = result;
54 | this.touchpoint = touchpoint;
55 |
56 | }
57 |
58 | public Touchpoint getTouchpoint() {
59 | return touchpoint;
60 | }
61 |
62 | public IProfile getProfile() {
63 | return profile;
64 | }
65 |
66 | public IInstallableUnit getInstallableUnit() {
67 | return iu;
68 | }
69 |
70 | public String getPhase() {
71 | return phaseId;
72 | }
73 |
74 | public boolean isPre() {
75 | return prePhase;
76 | }
77 |
78 | public boolean isPost() {
79 | return !prePhase;
80 | }
81 |
82 | public IStatus getResult() {
83 | return (result != null ? result : Status.OK_STATUS);
84 | }
85 |
86 | public boolean isInstall() {
87 | return type == INSTALL;
88 | }
89 |
90 | public boolean isUninstall() {
91 | return type == UNINSTALL;
92 | }
93 |
94 | public boolean isConfigure() {
95 | return type == CONFIGURE;
96 | }
97 |
98 | public boolean isUnConfigure() {
99 | return type == UNCONFIGURE;
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/SharedProfilePreferences.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2012 Ericsson AB and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * Ericsson AB - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import org.eclipse.core.internal.preferences.EclipsePreferences;
14 | import org.eclipse.core.runtime.preferences.IEclipsePreferences;
15 | import org.eclipse.equinox.p2.core.IProvisioningAgent;
16 | import org.osgi.service.prefs.BackingStoreException;
17 |
18 | /**
19 | * A preference implementation that stores preferences in the engine's profile
20 | * data area. There is one preference file per profile, with an additional file
21 | * that is used when there is no currently running profile.
22 | */
23 | public class SharedProfilePreferences extends ProfilePreferences {
24 | public SharedProfilePreferences() {
25 | this(null, null);
26 | }
27 |
28 | public SharedProfilePreferences(EclipsePreferences nodeParent, String nodeName) {
29 | super(nodeParent, nodeName);
30 |
31 | //path is /profile/shared/{agent location}/{profile id}/qualifier
32 |
33 | // cache the segment count
34 | String path = absolutePath();
35 | segmentCount = getSegmentCount(path);
36 |
37 | if (segmentCount <= 3)
38 | return;
39 |
40 | if (segmentCount == 4)
41 | profileLock = new Object();
42 |
43 | if (segmentCount < 5)
44 | return;
45 | // cache the qualifier
46 | qualifier = getQualifierSegment();
47 | }
48 |
49 | protected IProvisioningAgent getAgent(String segment) throws BackingStoreException {
50 | IProvisioningAgent agent = super.getAgent(segment);
51 | return (IProvisioningAgent) agent.getService(IProvisioningAgent.SHARED_BASE_AGENT);
52 | }
53 |
54 | protected void doSave(IProvisioningAgent agent) throws BackingStoreException {
55 | throw new BackingStoreException("Can't store in shared install"); //$NON-NLS-1$
56 | }
57 |
58 | protected EclipsePreferences internalCreate(EclipsePreferences nodeParent, String nodeName, Object context) {
59 | return new SharedProfilePreferences(nodeParent, nodeName);
60 | }
61 |
62 | protected IEclipsePreferences getLoadLevel() {
63 | if (loadLevel == null) {
64 | if (qualifier == null)
65 | return null;
66 | // Make it relative to this node rather than navigating to it from the root.
67 | // Walk backwards up the tree starting at this node.
68 | // This is important to avoid a chicken/egg thing on startup.
69 | IEclipsePreferences node = this;
70 | for (int i = 5; i < segmentCount; i++)
71 | node = (EclipsePreferences) node.parent();
72 | loadLevel = node;
73 | }
74 | return loadLevel;
75 | }
76 |
77 | protected synchronized void save() throws BackingStoreException {
78 | throw new BackingStoreException("Can't store in shared install");
79 | }
80 |
81 | protected String getQualifierSegment() {
82 | return getSegment(absolutePath(), 4);
83 | }
84 |
85 | protected String getProfileIdSegment() {
86 | return getSegment(absolutePath(), 3);
87 | }
88 |
89 | protected String getAgentLocationSegment() {
90 | return getSegment(absolutePath(), 2);
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/phases/CheckTrust.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2008, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine.phases;
12 |
13 | import java.io.File;
14 | import java.util.*;
15 | import org.eclipse.core.runtime.IProgressMonitor;
16 | import org.eclipse.core.runtime.IStatus;
17 | import org.eclipse.equinox.internal.p2.engine.InstallableUnitOperand;
18 | import org.eclipse.equinox.internal.p2.engine.InstallableUnitPhase;
19 | import org.eclipse.equinox.p2.core.IProvisioningAgent;
20 | import org.eclipse.equinox.p2.engine.PhaseSetFactory;
21 | import org.eclipse.equinox.p2.engine.IProfile;
22 | import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
23 | import org.eclipse.equinox.p2.metadata.IInstallableUnit;
24 | import org.eclipse.equinox.p2.metadata.ITouchpointType;
25 |
26 | /**
27 | * An install phase that checks if the certificates used to sign the artifacts
28 | * being installed are from a trusted source.
29 | */
30 | public class CheckTrust extends InstallableUnitPhase {
31 |
32 | public static final String PARM_ARTIFACT_FILES = "artifactFiles"; //$NON-NLS-1$
33 |
34 | public CheckTrust(int weight) {
35 | super(PhaseSetFactory.PHASE_CHECK_TRUST, weight);
36 | }
37 |
38 | protected boolean isApplicable(InstallableUnitOperand op) {
39 | return (op.second() != null);
40 | }
41 |
42 | protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map parameters) {
43 | @SuppressWarnings("unchecked")
44 | Collection artifactRequests = (Collection) parameters.get(PARM_ARTIFACT_FILES);
45 | IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT);
46 |
47 | // Instantiate a check trust manager
48 | CertificateChecker certificateChecker = new CertificateChecker(agent);
49 | certificateChecker.add(artifactRequests.toArray());
50 | IStatus status = certificateChecker.start();
51 |
52 | return status;
53 | }
54 |
55 | protected List getActions(InstallableUnitOperand operand) {
56 | IInstallableUnit unit = operand.second();
57 | List parsedActions = getActions(unit, phaseId);
58 | if (parsedActions != null)
59 | return parsedActions;
60 |
61 | ITouchpointType type = unit.getTouchpointType();
62 | if (type == null || type == ITouchpointType.NONE)
63 | return null;
64 |
65 | String actionId = getActionManager().getTouchpointQualifiedActionId(phaseId, type);
66 | ProvisioningAction action = getActionManager().getAction(actionId, null);
67 | if (action == null) {
68 | return null;
69 | }
70 | return Collections.singletonList(action);
71 | }
72 |
73 | protected IStatus initializeOperand(IProfile profile, InstallableUnitOperand operand, Map parameters, IProgressMonitor monitor) {
74 | IInstallableUnit iu = operand.second();
75 | parameters.put(PARM_IU, iu);
76 |
77 | return super.initializeOperand(profile, operand, parameters, monitor);
78 | }
79 |
80 | protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map parameters) {
81 | parameters.put(PARM_ARTIFACT_FILES, new ArrayList());
82 | return super.initializePhase(monitor, profile, parameters);
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/p2/engine/ProfileScope.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2009, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.p2.engine;
12 |
13 | import org.eclipse.core.internal.preferences.PreferencesService;
14 | import org.eclipse.core.runtime.Assert;
15 | import org.eclipse.core.runtime.IPath;
16 | import org.eclipse.core.runtime.preferences.IEclipsePreferences;
17 | import org.eclipse.core.runtime.preferences.IScopeContext;
18 | import org.eclipse.equinox.internal.p2.engine.SlashEncode;
19 | import org.eclipse.equinox.p2.core.IAgentLocation;
20 |
21 | /**
22 | * A profile scope contains the preferences associated with a particular profile
23 | * in a provisioned system.
24 | * @see IProfile
25 | * @since 2.0
26 | */
27 | public final class ProfileScope implements IScopeContext {
28 |
29 | /**
30 | * String constant (value of "profile") used for the
31 | * scope name for this preference scope.
32 | */
33 | public static final String SCOPE = "profile"; //$NON-NLS-1$
34 |
35 | private String profileId;
36 |
37 | private IAgentLocation location;
38 |
39 | /**
40 | * Creates and returns a profile scope for the given profile id and agent.
41 | * @param agentLocation The location of the provisioning agent to obtain profile preferences for
42 | * @param profileId The id of the profile to obtain preferences for
43 | */
44 | public ProfileScope(IAgentLocation agentLocation, String profileId) {
45 | super();
46 | Assert.isNotNull(agentLocation);
47 | Assert.isNotNull(profileId);
48 | this.profileId = profileId;
49 | this.location = agentLocation;
50 | }
51 |
52 | /*(non-Javadoc)
53 | * @see org.eclipse.core.runtime.preferences.IScopeContext#getLocation()
54 | */
55 | public IPath getLocation() {
56 | // Null returned as the location should only be used when the profile is locked
57 | return null;
58 | }
59 |
60 | /*(non-Javadoc)
61 | * @see org.eclipse.core.runtime.preferences.IScopeContext#getName()
62 | */
63 | public String getName() {
64 | return SCOPE;
65 | }
66 |
67 | /*
68 | * Default path hierarchy for profile nodes is /profile//.
69 | *
70 | * @see org.eclipse.core.runtime.preferences.IScopeContext#getNode(java.lang.String)
71 | */
72 | public IEclipsePreferences getNode(String qualifier) {
73 | if (qualifier == null)
74 | throw new IllegalArgumentException();
75 | String locationString = SlashEncode.encode(location.getRootLocation().toString());
76 | //format is /profile/{agentLocationURI}/{profileId}/qualifier
77 | return (IEclipsePreferences) PreferencesService.getDefault().getRootNode().node(getName()).node(locationString).node(profileId).node(qualifier);
78 | }
79 |
80 | /* (non-Javadoc)
81 | * @see java.lang.Object#equals(java.lang.Object)
82 | */
83 | public boolean equals(Object obj) {
84 | if (this == obj)
85 | return true;
86 | if (!super.equals(obj))
87 | return false;
88 | if (!(obj instanceof ProfileScope))
89 | return false;
90 | ProfileScope other = (ProfileScope) obj;
91 | return profileId.equals(other.profileId);
92 | }
93 |
94 | /* (non-Javadoc)
95 | * @see java.lang.Object#hashCode()
96 | */
97 | public int hashCode() {
98 | return super.hashCode() + profileId.hashCode();
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/ProfileLock.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2009 IBM Corporation and others. All rights reserved. This
3 | * program and the accompanying materials are made available under the terms of
4 | * the Eclipse Public License v1.0 which accompanies this distribution, and is
5 | * available at http://www.eclipse.org/legal/epl-v10.html
6 | *
7 | * Contributors: IBM Corporation - initial API and implementation
8 | ******************************************************************************/
9 | package org.eclipse.equinox.internal.p2.engine;
10 |
11 | import java.io.File;
12 | import java.io.IOException;
13 | import java.net.MalformedURLException;
14 | import java.net.URL;
15 | import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
16 | import org.eclipse.osgi.service.datalocation.Location;
17 | import org.eclipse.osgi.util.NLS;
18 |
19 | /**
20 | * The purpose of this class is to enable cross process locking.
21 | * See 257654 for more details.
22 | */
23 | public class ProfileLock {
24 | private static final String LOCK_FILENAME = ".lock"; //$NON-NLS-1$
25 |
26 | private final Location location;
27 | private final Object lock;
28 | private Thread lockHolder;
29 | private int waiting;
30 |
31 | public ProfileLock(Object lock, File profileDirectory) {
32 | this.lock = lock;
33 | location = createLockLocation(profileDirectory);
34 | }
35 |
36 | private static Location createLockLocation(File parent) {
37 | Location anyLoc = (Location) ServiceHelper.getService(EngineActivator.getContext(), Location.class.getName());
38 | try {
39 | final URL url = parent.toURL();
40 | Location location = anyLoc.createLocation(null, url, false);
41 | location.set(url, false, LOCK_FILENAME);
42 | return location;
43 | } catch (MalformedURLException e) {
44 | throw new IllegalArgumentException(NLS.bind(Messages.SimpleProfileRegistry_Bad_profile_location, e.getLocalizedMessage()));
45 | } catch (IllegalStateException e) {
46 | throw e;
47 | } catch (IOException e) {
48 | throw new IllegalStateException(e.getLocalizedMessage());
49 | }
50 | }
51 |
52 | /**
53 | * Asserts that this thread currently holds the profile lock.
54 | * @throws IllegalStateException If this thread does not currently hold the profile lock
55 | */
56 | public void checkLocked() {
57 | synchronized (lock) {
58 | if (lockHolder == null)
59 | throw new IllegalStateException(Messages.SimpleProfileRegistry_Profile_not_locked);
60 |
61 | Thread current = Thread.currentThread();
62 | if (lockHolder != current)
63 | throw new IllegalStateException(Messages.thread_not_owner);
64 | }
65 | }
66 |
67 | /**
68 | * Attempts to obtain an exclusive write lock on a profile. The profile lock must be
69 | * owned by any process and thread that wants to modify a profile. If the lock
70 | * is currently held by another thread in this process, this method will block until
71 | * the lock becomes available. If the lock is currently held by another process,
72 | * this method returns false. Re-entrant attempts to acquire the
73 | * same profile lock multiple times in the same thread is not allowed.
74 | *
75 | * @return true if the lock was successfully obtained by this thread,
76 | * and false if another process is currently holding the lock.
77 | */
78 | public boolean lock() {
79 | synchronized (lock) {
80 | Thread current = Thread.currentThread();
81 | if (lockHolder == current)
82 | throw new IllegalStateException(Messages.profile_lock_not_reentrant);
83 |
84 | boolean locationLocked = (waiting != 0);
85 | while (lockHolder != null) {
86 | locationLocked = true;
87 | waiting++;
88 | boolean interrupted = false;
89 | try {
90 | lock.wait();
91 | } catch (InterruptedException e) {
92 | interrupted = true;
93 | } finally {
94 | waiting--;
95 | // if interrupted restore interrupt to thread state
96 | if (interrupted)
97 | current.interrupt();
98 | }
99 | }
100 | try {
101 | if (!locationLocked && !location.lock())
102 | return false;
103 |
104 | lockHolder = current;
105 | } catch (IOException e) {
106 | throw new IllegalStateException(NLS.bind(Messages.SimpleProfileRegistry_Profile_not_locked_due_to_exception, e.getLocalizedMessage()));
107 | }
108 | return true;
109 | }
110 | }
111 |
112 | /**
113 | * Releases the exclusive write lock on a profile. This method must only be called
114 | * by a thread that currently owns the lock.
115 | */
116 | public void unlock() {
117 | synchronized (lock) {
118 | if (lockHolder == null)
119 | throw new IllegalStateException(Messages.SimpleProfileRegistry_Profile_not_locked);
120 |
121 | Thread current = Thread.currentThread();
122 | if (lockHolder != current)
123 | throw new IllegalStateException(Messages.thread_not_owner);
124 |
125 | lockHolder = null;
126 | if (waiting == 0)
127 | location.release();
128 | else
129 | lock.notify();
130 | }
131 | }
132 |
133 | /**
134 | * Returns whether a thread in this process currently holds the profile lock.
135 | *
136 | * @return true if a thread in this process owns the profile lock,
137 | * and false otherwise
138 | */
139 | public boolean processHoldsLock() {
140 | synchronized (lock) {
141 | return lockHolder != null;
142 | }
143 | }
144 | }
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/ParameterizedProvisioningAction.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2005, 2012 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | * Landmark Graphics Corporation - bug 397183
11 | *******************************************************************************/
12 | package org.eclipse.equinox.internal.p2.engine;
13 |
14 | import java.util.*;
15 | import java.util.Map.Entry;
16 | import org.eclipse.core.runtime.IStatus;
17 | import org.eclipse.equinox.p2.engine.spi.*;
18 |
19 | public class ParameterizedProvisioningAction extends ProvisioningAction {
20 | private ProvisioningAction action;
21 | private Map actionParameters;
22 | //ActualParameter is used to keep values to which variables have been resolved.
23 | //This is especially useful when undoing in the presence of variables that change (e.g. lastResult)
24 | private Map actualParameters;
25 | private String actionText;
26 |
27 | public ParameterizedProvisioningAction(ProvisioningAction action, Map actionParameters, String actionText) {
28 | if (action == null || actionParameters == null)
29 | throw new IllegalArgumentException(Messages.ParameterizedProvisioningAction_action_or_parameters_null);
30 | this.action = action;
31 | this.actionParameters = actionParameters;
32 | this.actualParameters = new HashMap(actionParameters.size());
33 | this.actionText = actionText;
34 | }
35 |
36 | public IStatus execute(Map parameters) {
37 | parameters = processActionParameters(parameters);
38 | return action.execute(parameters);
39 | }
40 |
41 | public IStatus undo(Map parameters) {
42 | parameters = processActionParameters(parameters);
43 | return action.undo(parameters);
44 | }
45 |
46 | private Map processActionParameters(Map parameters) {
47 | Map result = new HashMap(parameters);
48 | for (Entry entry : actionParameters.entrySet()) {
49 | String name = entry.getKey();
50 | Object value = processVariables(entry.getValue(), parameters, false);
51 | result.put(name, value);
52 | }
53 | return Collections.unmodifiableMap(result);
54 | }
55 |
56 | //allowInfixReplacement triggers the replacement of the variables found in the middle of a string (e.g. abc${var}def)
57 | private Object processVariables(String parameterValue, Map parameters, boolean allowInfixReplacement) {
58 | int variableBeginIndex = parameterValue.indexOf("${"); //$NON-NLS-1$
59 | if (variableBeginIndex == -1)
60 | return parameterValue;
61 |
62 | int variableEndIndex = parameterValue.indexOf('}', variableBeginIndex + 2);
63 | if (variableEndIndex == -1)
64 | return parameterValue;
65 |
66 | String preVariable = parameterValue.substring(0, variableBeginIndex);
67 | String variableName = parameterValue.substring(variableBeginIndex + 2, variableEndIndex);
68 |
69 | //replace the internal name by the user visible name
70 | if (Phase.LAST_RESULT_PUBLIC_NAME.equals(variableName)) {
71 | variableName = Phase.LAST_RESULT_INTERNAL_NAME;
72 | }
73 | Object valueUsed = actualParameters.get(variableName);
74 | Object value = valueUsed == null ? parameters.get(variableName) : valueUsed;
75 | actualParameters.put(variableName, value);
76 |
77 | if (value instanceof Value) {
78 | if (allowInfixReplacement == false && variableBeginIndex == 0 && variableEndIndex == parameterValue.length() - 1) {
79 | return ((Value>) value).getValue();
80 | }
81 |
82 | Value> result = (Value>) value;
83 | if (result.getClazz() == String.class) {
84 | value = result.getValue();
85 | } else
86 | throw new RuntimeException("The type of the variable is expected to be a String"); //$NON-NLS-1$
87 | }
88 |
89 | // try to replace this parameter with a character
90 | if (value == null && variableName.charAt(0) == '#') {
91 | try {
92 | int code = Integer.parseInt(variableName.substring(1));
93 | if (code >= 0 && code < 65536)
94 | value = Character.toString((char) code);
95 | } catch (Throwable t) {
96 | // ignore and leave value as null
97 | }
98 | }
99 |
100 | String variableValue = value == null ? "" : value.toString(); //$NON-NLS-1$ //TODO This is where we replace the values
101 | String postVariable = (String) processVariables(parameterValue.substring(variableEndIndex + 1), parameters, true);
102 | return preVariable + variableValue + postVariable;
103 | }
104 |
105 | public ProvisioningAction getAction() {
106 | return action;
107 | }
108 |
109 | public Map getParameters() {
110 | return actionParameters;
111 | }
112 |
113 | public String getActionText() {
114 | return actionText;
115 | }
116 |
117 | public Touchpoint getTouchpoint() {
118 | return action.getTouchpoint();
119 | }
120 |
121 | public void setTouchpoint(Touchpoint touchpoint) {
122 | throw new UnsupportedOperationException();
123 | }
124 |
125 | @Override
126 | public Value> getResult() {
127 | return action.getResult();
128 | }
129 |
130 | }
131 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/InstructionParser.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2005, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import java.util.*;
14 | import org.eclipse.core.runtime.Assert;
15 | import org.eclipse.equinox.internal.p2.core.helpers.CollectionUtils;
16 | import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
17 | import org.eclipse.equinox.p2.metadata.*;
18 | import org.eclipse.osgi.util.NLS;
19 |
20 | public class InstructionParser {
21 |
22 | public class ActionEntry {
23 |
24 | protected final VersionRange versionRange;
25 | protected final String actionId;
26 |
27 | public ActionEntry(String actionId, VersionRange versionRange) {
28 | this.actionId = actionId;
29 | this.versionRange = versionRange;
30 | }
31 | }
32 |
33 | private static final String VERSION_EQUALS = "version="; //$NON-NLS-1$
34 | private ActionManager actionManager;
35 |
36 | public InstructionParser(ActionManager actionManager) {
37 | Assert.isNotNull(actionManager);
38 | this.actionManager = actionManager;
39 | }
40 |
41 | public List parseActions(ITouchpointInstruction instruction, ITouchpointType touchpointType) {
42 | List actions = new ArrayList();
43 | Map importMap = parseImportAttribute(instruction.getImportAttribute());
44 | StringTokenizer tokenizer = new StringTokenizer(instruction.getBody(), ";"); //$NON-NLS-1$
45 | while (tokenizer.hasMoreTokens()) {
46 | actions.add(parseAction(tokenizer.nextToken(), importMap, touchpointType));
47 | }
48 | return actions;
49 | }
50 |
51 | private Map parseImportAttribute(String importAttribute) {
52 | if (importAttribute == null)
53 | return CollectionUtils.emptyMap();
54 |
55 | Map result = new HashMap();
56 | StringTokenizer tokenizer = new StringTokenizer(importAttribute, ","); //$NON-NLS-1$
57 | while (tokenizer.hasMoreTokens()) {
58 | StringTokenizer actionTokenizer = new StringTokenizer(tokenizer.nextToken(), ";"); //$NON-NLS-1$
59 | String actionId = actionTokenizer.nextToken().trim();
60 | int lastDot = actionId.lastIndexOf('.');
61 | String actionKey = (lastDot == -1) ? actionId : actionId.substring(lastDot + 1);
62 | VersionRange actionVersionRange = null;
63 | while (actionTokenizer.hasMoreTokens()) {
64 | String actionAttribute = actionTokenizer.nextToken().trim();
65 | if (actionAttribute.startsWith(VERSION_EQUALS))
66 | actionVersionRange = new VersionRange(actionAttribute.substring(VERSION_EQUALS.length() + 1));
67 | }
68 | result.put(actionKey, new ActionEntry(actionId, actionVersionRange));
69 | result.put(actionId, new ActionEntry(actionId, actionVersionRange));
70 | }
71 | return result;
72 | }
73 |
74 | private ProvisioningAction parseAction(String statement, Map qualifier, ITouchpointType touchpointType) {
75 | int openBracket = statement.indexOf('(');
76 | int closeBracket = statement.lastIndexOf(')');
77 | if (openBracket == -1 || closeBracket == -1 || openBracket > closeBracket)
78 | throw new IllegalArgumentException(NLS.bind(Messages.action_syntax_error, statement));
79 | String actionName = statement.substring(0, openBracket).trim();
80 | ProvisioningAction action = lookupAction(actionName, qualifier, touchpointType);
81 | if (action instanceof MissingAction)
82 | return action;
83 |
84 | String nameValuePairs = statement.substring(openBracket + 1, closeBracket);
85 | if (nameValuePairs.length() == 0)
86 | return new ParameterizedProvisioningAction(action, CollectionUtils. emptyMap(), statement);
87 |
88 | StringTokenizer tokenizer = new StringTokenizer(nameValuePairs, ","); //$NON-NLS-1$
89 | Map parameters = new HashMap();
90 | while (tokenizer.hasMoreTokens()) {
91 | String nameValuePair = tokenizer.nextToken();
92 | int colonIndex = nameValuePair.indexOf(":"); //$NON-NLS-1$
93 | if (colonIndex == -1)
94 | throw new IllegalArgumentException(NLS.bind(Messages.action_syntax_error, statement));
95 | String name = nameValuePair.substring(0, colonIndex).trim();
96 | String value = nameValuePair.substring(colonIndex + 1).trim();
97 | parameters.put(name, value);
98 | }
99 | return new ParameterizedProvisioningAction(action, parameters, statement);
100 | }
101 |
102 | private ProvisioningAction lookupAction(String actionId, Map importMap, ITouchpointType touchpointType) {
103 | VersionRange versionRange = null;
104 | ActionEntry actionEntry = importMap.get(actionId);
105 | if (actionEntry != null) {
106 | actionId = actionEntry.actionId;
107 | versionRange = actionEntry.versionRange;
108 | }
109 |
110 | actionId = actionManager.getTouchpointQualifiedActionId(actionId, touchpointType);
111 | ProvisioningAction action = actionManager.getAction(actionId, versionRange);
112 | if (action == null)
113 | action = new MissingAction(actionId, versionRange);
114 |
115 | return action;
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/InstallableUnitPhase.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | * WindRiver - https://bugs.eclipse.org/bugs/show_bug.cgi?id=227372
11 | *******************************************************************************/
12 | package org.eclipse.equinox.internal.p2.engine;
13 |
14 | import java.util.*;
15 | import org.eclipse.core.runtime.*;
16 | import org.eclipse.equinox.internal.p2.core.helpers.CollectionUtils;
17 | import org.eclipse.equinox.p2.engine.IProfile;
18 | import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
19 | import org.eclipse.equinox.p2.engine.spi.Touchpoint;
20 | import org.eclipse.equinox.p2.metadata.*;
21 |
22 | public abstract class InstallableUnitPhase extends Phase {
23 | public static final String PARM_ARTIFACT = "artifact"; //$NON-NLS-1$
24 | public static final String PARM_IU = "iu"; //$NON-NLS-1$
25 | public static final String PARM_INSTALL_FOLDER = "installFolder"; //$NON-NLS-1$
26 |
27 | protected InstallableUnitPhase(String phaseId, int weight, boolean forced) {
28 | super(phaseId, weight, forced);
29 | }
30 |
31 | protected InstallableUnitPhase(String phaseId, int weight) {
32 | this(phaseId, weight, false);
33 | }
34 |
35 | protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map parameters) {
36 | parameters.put(PARM_INSTALL_FOLDER, profile.getProperty(IProfile.PROP_INSTALL_FOLDER));
37 | return super.initializePhase(monitor, profile, parameters);
38 | }
39 |
40 | protected IStatus initializeOperand(IProfile profile, Operand operand, Map parameters, IProgressMonitor monitor) {
41 | InstallableUnitOperand iuOperand = (InstallableUnitOperand) operand;
42 | MultiStatus status = new MultiStatus(EngineActivator.ID, IStatus.OK, null, null);
43 | mergeStatus(status, initializeOperand(profile, iuOperand, parameters, monitor));
44 | IInstallableUnit unit = (IInstallableUnit) parameters.get(PARM_IU);
45 | if (unit != null) {
46 | Touchpoint touchpoint = getActionManager().getTouchpointPoint(unit.getTouchpointType());
47 | if (touchpoint != null) {
48 | parameters.put(PARM_TOUCHPOINT, touchpoint);
49 | }
50 | }
51 | mergeStatus(status, super.initializeOperand(profile, operand, parameters, monitor));
52 | return status;
53 | }
54 |
55 | protected IStatus initializeOperand(IProfile profile, InstallableUnitOperand operand, Map parameters, IProgressMonitor monitor) {
56 | return Status.OK_STATUS;
57 | }
58 |
59 | protected IStatus completeOperand(IProfile profile, Operand operand, Map parameters, IProgressMonitor monitor) {
60 | InstallableUnitOperand iuOperand = (InstallableUnitOperand) operand;
61 |
62 | MultiStatus status = new MultiStatus(EngineActivator.ID, IStatus.OK, null, null);
63 | mergeStatus(status, super.completeOperand(profile, iuOperand, parameters, monitor));
64 | mergeStatus(status, completeOperand(profile, iuOperand, parameters, monitor));
65 | return status;
66 | }
67 |
68 | protected IStatus completeOperand(IProfile profile, InstallableUnitOperand operand, Map parameters, IProgressMonitor monitor) {
69 | return Status.OK_STATUS;
70 | }
71 |
72 | final protected List getActions(Operand operand) {
73 | if (!(operand instanceof InstallableUnitOperand))
74 | return null;
75 |
76 | InstallableUnitOperand iuOperand = (InstallableUnitOperand) operand;
77 | return getActions(iuOperand);
78 | }
79 |
80 | protected abstract List getActions(InstallableUnitOperand operand);
81 |
82 | final public boolean isApplicable(Operand operand) {
83 | if (!(operand instanceof InstallableUnitOperand))
84 | return false;
85 |
86 | InstallableUnitOperand iuOperand = (InstallableUnitOperand) operand;
87 | return isApplicable(iuOperand);
88 | }
89 |
90 | protected boolean isApplicable(InstallableUnitOperand operand) {
91 | return true;
92 | }
93 |
94 | protected final List getActions(IInstallableUnit unit, String key) {
95 | List instructions = getInstructions(unit, key);
96 | int instrSize = instructions.size();
97 | if (instrSize == 0)
98 | return null;
99 |
100 | List actions = new ArrayList();
101 | InstructionParser instructionParser = new InstructionParser(getActionManager());
102 | for (int i = 0; i < instrSize; i++) {
103 | actions.addAll(instructionParser.parseActions(instructions.get(i), unit.getTouchpointType()));
104 | }
105 | return actions;
106 | }
107 |
108 | private final static List getInstructions(IInstallableUnit unit, String key) {
109 | Collection data = unit.getTouchpointData();
110 | int dataSize = data.size();
111 | if (dataSize == 0)
112 | return CollectionUtils.emptyList();
113 |
114 | ArrayList matches = new ArrayList(dataSize);
115 | for (ITouchpointData td : data) {
116 | ITouchpointInstruction instructions = td.getInstruction(key);
117 | if (instructions != null)
118 | matches.add(instructions);
119 | }
120 | return matches;
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/ProvisioningPlan.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import java.util.*;
14 | import org.eclipse.core.runtime.*;
15 | import org.eclipse.equinox.p2.engine.*;
16 | import org.eclipse.equinox.p2.metadata.IInstallableUnit;
17 | import org.eclipse.equinox.p2.query.*;
18 |
19 | /**
20 | * @since 2.0
21 | */
22 | public class ProvisioningPlan implements IProvisioningPlan {
23 |
24 | final IProfile profile;
25 | final List operands = new ArrayList();
26 | final ProvisioningContext context;
27 | IQueryable futureState;
28 | IStatus status;
29 | private IProvisioningPlan installerPlan;
30 |
31 | public ProvisioningPlan(IProfile profile, Operand[] operands, ProvisioningContext context) {
32 | this(Status.OK_STATUS, profile, operands, context, null);
33 | }
34 |
35 | public ProvisioningPlan(IStatus status, IProfile profile, ProvisioningContext context, IProvisioningPlan installerPlan) {
36 | this(status, profile, null, context, installerPlan);
37 | }
38 |
39 | public ProvisioningPlan(IStatus status, IProfile profile, Operand[] operands, ProvisioningContext context, IProvisioningPlan installerPlan) {
40 | Assert.isNotNull(profile);
41 | this.status = status;
42 | this.profile = profile;
43 | if (operands != null)
44 | this.operands.addAll(Arrays.asList(operands));
45 | this.context = (context == null) ? new ProvisioningContext(profile.getProvisioningAgent()) : context;
46 | this.installerPlan = installerPlan;
47 | }
48 |
49 | /* (non-Javadoc)
50 | * @see org.eclipse.equinox.p2.engine.IProvisioningPlan#getStatus()
51 | */
52 | public IStatus getStatus() {
53 | return status;
54 | }
55 |
56 | public void setStatus(IStatus status) {
57 | this.status = status;
58 | }
59 |
60 | /* (non-Javadoc)
61 | * @see org.eclipse.equinox.p2.engine.IProvisioningPlan#getProfile()
62 | */
63 | public IProfile getProfile() {
64 | return profile;
65 | }
66 |
67 | public Operand[] getOperands() {
68 | return operands.toArray(new Operand[operands.size()]);
69 | }
70 |
71 | /* (non-Javadoc)
72 | * @see org.eclipse.equinox.p2.engine.IProvisioningPlan#getRemovals()
73 | */
74 | public IQueryable getRemovals() {
75 | return new QueryablePlan(false);
76 | }
77 |
78 | /* (non-Javadoc)
79 | * @see org.eclipse.equinox.p2.engine.IProvisioningPlan#getAdditions()
80 | */
81 | public IQueryable getAdditions() {
82 | return new QueryablePlan(true);
83 | }
84 |
85 | private class QueryablePlan implements IQueryable {
86 | private boolean addition;
87 |
88 | public QueryablePlan(boolean add) {
89 | this.addition = add;
90 | }
91 |
92 | public IQueryResult query(IQuery query, IProgressMonitor monitor) {
93 | if (operands == null || status.getSeverity() == IStatus.ERROR)
94 | return Collector.emptyCollector();
95 | Collection list = new ArrayList();
96 | for (Operand operand : operands) {
97 | if (!(operand instanceof InstallableUnitOperand))
98 | continue;
99 | InstallableUnitOperand op = ((InstallableUnitOperand) operand);
100 | IInstallableUnit iu = addition ? op.second() : op.first();
101 | if (iu != null)
102 | list.add(iu);
103 | }
104 | return query.perform(list.iterator());
105 | }
106 | }
107 |
108 | /* (non-Javadoc)
109 | * @see org.eclipse.equinox.p2.engine.IProvisioningPlan#getInstallerPlan()
110 | */
111 | public IProvisioningPlan getInstallerPlan() {
112 | return installerPlan;
113 | }
114 |
115 | public ProvisioningContext getContext() {
116 | return context;
117 | }
118 |
119 | public void setInstallerPlan(IProvisioningPlan p) {
120 | installerPlan = p;
121 | }
122 |
123 | public void addInstallableUnit(IInstallableUnit iu) {
124 | operands.add(new InstallableUnitOperand(null, iu));
125 | }
126 |
127 | public void removeInstallableUnit(IInstallableUnit iu) {
128 | operands.add(new InstallableUnitOperand(iu, null));
129 | }
130 |
131 | public void updateInstallableUnit(IInstallableUnit iu1, IInstallableUnit iu2) {
132 | operands.add(new InstallableUnitOperand(iu1, iu2));
133 | }
134 |
135 | public void setProfileProperty(String name, String value) {
136 | String currentValue = profile.getProperty(name);
137 | if (value == null && currentValue == null)
138 | return;
139 | operands.add(new PropertyOperand(name, currentValue, value));
140 | }
141 |
142 | public void setInstallableUnitProfileProperty(IInstallableUnit iu, String name, String value) {
143 | String currentValue = profile.getInstallableUnitProperty(iu, name);
144 | if (value == null && currentValue == null)
145 | return;
146 | operands.add(new InstallableUnitPropertyOperand(iu, name, currentValue, value));
147 | }
148 |
149 | public IQueryable getFutureState() {
150 | return futureState;
151 | }
152 |
153 | public void setFuturePlan(IQueryable futureState) {
154 | this.futureState = futureState;
155 | }
156 | }
157 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/ActionManager.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2008, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import java.util.HashMap;
14 | import java.util.Map;
15 | import org.eclipse.core.runtime.*;
16 | import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
17 | import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
18 | import org.eclipse.equinox.p2.engine.spi.Touchpoint;
19 | import org.eclipse.equinox.p2.metadata.ITouchpointType;
20 | import org.eclipse.equinox.p2.metadata.VersionRange;
21 | import org.eclipse.osgi.util.NLS;
22 |
23 | public class ActionManager implements IRegistryChangeListener {
24 |
25 | private static final String PT_ACTIONS = "actions"; //$NON-NLS-1$
26 | private static final String ELEMENT_ACTION = "action"; //$NON-NLS-1$
27 | private static final String ATTRIBUTE_CLASS = "class"; //$NON-NLS-1$
28 | private static final String ATTRIBUTE_NAME = "name"; //$NON-NLS-1$
29 | private static final String TOUCHPOINT_TYPE = "touchpointType"; //$NON-NLS-1$
30 | private static final String TOUCHPOINT_VERSION = "touchpointVersion"; //$NON-NLS-1$
31 | /**
32 | * Service name constant for the action manager service. This service is used internally
33 | * by the engine implementation and should not be referenced directly by clients.
34 | */
35 | public static final String SERVICE_NAME = ActionManager.class.getName();
36 |
37 | private HashMap actionMap;
38 | private TouchpointManager touchpointManager;
39 |
40 | public ActionManager() {
41 | this.touchpointManager = new TouchpointManager();
42 | RegistryFactory.getRegistry().addRegistryChangeListener(this, EngineActivator.ID);
43 | }
44 |
45 | public Touchpoint getTouchpointPoint(ITouchpointType type) {
46 | if (type == null || type == ITouchpointType.NONE)
47 | return null;
48 | return touchpointManager.getTouchpoint(type);
49 | }
50 |
51 | public String getTouchpointQualifiedActionId(String actionId, ITouchpointType type) {
52 | if (actionId.indexOf('.') == -1) {
53 | if (type == null || type == ITouchpointType.NONE)
54 | return actionId;
55 |
56 | Touchpoint touchpoint = touchpointManager.getTouchpoint(type);
57 | if (touchpoint == null)
58 | throw new IllegalArgumentException(NLS.bind(Messages.ActionManager_Required_Touchpoint_Not_Found, type.toString(), actionId));
59 | actionId = touchpoint.qualifyAction(actionId);
60 | }
61 | return actionId;
62 | }
63 |
64 | public ProvisioningAction getAction(String actionId, VersionRange versionRange) {
65 | IConfigurationElement actionElement = getActionMap().get(actionId);
66 | if (actionElement != null && actionElement.isValid()) {
67 | try {
68 | ProvisioningAction action = (ProvisioningAction) actionElement.createExecutableExtension(ATTRIBUTE_CLASS);
69 |
70 | String touchpointType = actionElement.getAttribute(TOUCHPOINT_TYPE);
71 | if (touchpointType != null) {
72 | String touchpointVersion = actionElement.getAttribute(TOUCHPOINT_VERSION);
73 | Touchpoint touchpoint = touchpointManager.getTouchpoint(touchpointType, touchpointVersion);
74 | if (touchpoint == null)
75 | throw new IllegalArgumentException(NLS.bind(Messages.ActionManager_Required_Touchpoint_Not_Found, touchpointType, actionId));
76 | action.setTouchpoint(touchpoint);
77 | }
78 | return action;
79 | } catch (InvalidRegistryObjectException e) {
80 | // skip
81 | } catch (CoreException e) {
82 | throw new IllegalArgumentException(NLS.bind(Messages.ActionManager_Exception_Creating_Action_Extension, actionId));
83 | }
84 | }
85 | return null;
86 | }
87 |
88 | private synchronized Map getActionMap() {
89 | if (actionMap != null)
90 | return actionMap;
91 | IExtensionPoint point = RegistryFactory.getRegistry().getExtensionPoint(EngineActivator.ID, PT_ACTIONS);
92 | IExtension[] extensions = point.getExtensions();
93 | actionMap = new HashMap(extensions.length);
94 | for (int i = 0; i < extensions.length; i++) {
95 | try {
96 | IConfigurationElement[] elements = extensions[i].getConfigurationElements();
97 | for (int j = 0; j < elements.length; j++) {
98 | IConfigurationElement actionElement = elements[j];
99 | if (!actionElement.getName().equals(ELEMENT_ACTION))
100 | continue;
101 |
102 | String actionId = actionElement.getAttribute(ATTRIBUTE_NAME);
103 | if (actionId == null)
104 | continue;
105 |
106 | if (actionId.indexOf('.') == -1)
107 | actionId = actionElement.getNamespaceIdentifier() + "." + actionId; //$NON-NLS-1$
108 |
109 | actionMap.put(actionId, actionElement);
110 | }
111 | } catch (InvalidRegistryObjectException e) {
112 | // skip
113 | }
114 | }
115 | return actionMap;
116 | }
117 |
118 | public synchronized void registryChanged(IRegistryChangeEvent event) {
119 | actionMap = null;
120 | }
121 |
122 | static void reportError(String errorMsg) {
123 | Status errorStatus = new Status(IStatus.ERROR, EngineActivator.ID, 1, errorMsg, null);
124 | LogHelper.log(errorStatus);
125 | }
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/phases/Configure.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2012 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | * Wind River - ongoing development
11 | *******************************************************************************/
12 | package org.eclipse.equinox.internal.p2.engine.phases;
13 |
14 | import java.util.*;
15 | import org.eclipse.core.runtime.*;
16 | import org.eclipse.equinox.internal.p2.engine.*;
17 | import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus;
18 | import org.eclipse.equinox.p2.core.IProvisioningAgent;
19 | import org.eclipse.equinox.p2.engine.IProfile;
20 | import org.eclipse.equinox.p2.engine.PhaseSetFactory;
21 | import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
22 | import org.eclipse.equinox.p2.engine.spi.Touchpoint;
23 | import org.eclipse.equinox.p2.metadata.IArtifactKey;
24 | import org.eclipse.equinox.p2.metadata.IInstallableUnit;
25 | import org.eclipse.equinox.p2.query.QueryUtil;
26 | import org.eclipse.osgi.util.NLS;
27 |
28 | public class Configure extends InstallableUnitPhase {
29 |
30 | final static class BeforeConfigureEventAction extends ProvisioningAction {
31 |
32 | public IStatus execute(Map parameters) {
33 | IProfile profile = (IProfile) parameters.get(PARM_PROFILE);
34 | String phaseId = (String) parameters.get(PARM_PHASE_ID);
35 | IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU);
36 | IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT);
37 | ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, true, profile, iu, InstallableUnitEvent.CONFIGURE, getTouchpoint()));
38 | return null;
39 | }
40 |
41 | public IStatus undo(Map parameters) {
42 | Profile profile = (Profile) parameters.get(PARM_PROFILE);
43 | String phaseId = (String) parameters.get(PARM_PHASE_ID);
44 | IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU);
45 | IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT);
46 | ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, false, profile, iu, InstallableUnitEvent.UNCONFIGURE, getTouchpoint()));
47 | return null;
48 | }
49 | }
50 |
51 | final static class AfterConfigureEventAction extends ProvisioningAction {
52 |
53 | public IStatus execute(Map parameters) {
54 | Profile profile = (Profile) parameters.get(PARM_PROFILE);
55 | String phaseId = (String) parameters.get(PARM_PHASE_ID);
56 | IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU);
57 | IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT);
58 | ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, false, profile, iu, InstallableUnitEvent.CONFIGURE, getTouchpoint()));
59 | return null;
60 | }
61 |
62 | public IStatus undo(Map parameters) {
63 | IProfile profile = (IProfile) parameters.get(PARM_PROFILE);
64 | String phaseId = (String) parameters.get(PARM_PHASE_ID);
65 | IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU);
66 | IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT);
67 | ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, true, profile, iu, InstallableUnitEvent.UNCONFIGURE, getTouchpoint()));
68 | return null;
69 | }
70 | }
71 |
72 | public Configure(int weight) {
73 | super(PhaseSetFactory.PHASE_CONFIGURE, weight);
74 | }
75 |
76 | protected boolean isApplicable(InstallableUnitOperand op) {
77 | return (op.second() != null);
78 | }
79 |
80 | protected List getActions(InstallableUnitOperand currentOperand) {
81 | IInstallableUnit unit = currentOperand.second();
82 |
83 | ProvisioningAction beforeAction = new BeforeConfigureEventAction();
84 | ProvisioningAction afterAction = new AfterConfigureEventAction();
85 | Touchpoint touchpoint = getActionManager().getTouchpointPoint(unit.getTouchpointType());
86 | if (touchpoint != null) {
87 | beforeAction.setTouchpoint(touchpoint);
88 | afterAction.setTouchpoint(touchpoint);
89 | }
90 | ArrayList actions = new ArrayList();
91 | actions.add(beforeAction);
92 | if (!QueryUtil.isFragment(unit)) {
93 | List parsedActions = getActions(unit, phaseId);
94 | if (parsedActions != null)
95 | actions.addAll(parsedActions);
96 | }
97 | actions.add(afterAction);
98 | return actions;
99 | }
100 |
101 | protected String getProblemMessage() {
102 | return Messages.Phase_Configure_Error;
103 | }
104 |
105 | protected IStatus initializeOperand(IProfile profile, InstallableUnitOperand operand, Map parameters, IProgressMonitor monitor) {
106 | IInstallableUnit iu = operand.second();
107 | monitor.subTask(NLS.bind(Messages.Phase_Configure_Task, iu.getId()));
108 | parameters.put(PARM_IU, iu);
109 |
110 | Collection artifacts = iu.getArtifacts();
111 | if (artifacts != null && artifacts.size() > 0)
112 | parameters.put(PARM_ARTIFACT, artifacts.iterator().next());
113 |
114 | return Status.OK_STATUS;
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/phases/Unconfigure.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2012 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | * Wind River - ongoing development
11 | *******************************************************************************/
12 | package org.eclipse.equinox.internal.p2.engine.phases;
13 |
14 | import java.util.*;
15 | import org.eclipse.core.runtime.*;
16 | import org.eclipse.equinox.internal.p2.engine.*;
17 | import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus;
18 | import org.eclipse.equinox.p2.core.IProvisioningAgent;
19 | import org.eclipse.equinox.p2.engine.IProfile;
20 | import org.eclipse.equinox.p2.engine.PhaseSetFactory;
21 | import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
22 | import org.eclipse.equinox.p2.engine.spi.Touchpoint;
23 | import org.eclipse.equinox.p2.metadata.IArtifactKey;
24 | import org.eclipse.equinox.p2.metadata.IInstallableUnit;
25 | import org.eclipse.equinox.p2.query.QueryUtil;
26 |
27 | public class Unconfigure extends InstallableUnitPhase {
28 |
29 | final static class BeforeUnConfigureEventAction extends ProvisioningAction {
30 |
31 | public IStatus execute(Map parameters) {
32 | IProfile profile = (IProfile) parameters.get(PARM_PROFILE);
33 | String phaseId = (String) parameters.get(PARM_PHASE_ID);
34 | IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU);
35 | IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT);
36 | ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, true, profile, iu, InstallableUnitEvent.UNCONFIGURE, getTouchpoint()));
37 | return null;
38 | }
39 |
40 | public IStatus undo(Map parameters) {
41 | Profile profile = (Profile) parameters.get(PARM_PROFILE);
42 | String phaseId = (String) parameters.get(PARM_PHASE_ID);
43 | IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU);
44 | IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT);
45 | ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, false, profile, iu, InstallableUnitEvent.CONFIGURE, getTouchpoint()));
46 | return null;
47 | }
48 | }
49 |
50 | final static class AfterUnConfigureEventAction extends ProvisioningAction {
51 |
52 | public IStatus execute(Map parameters) {
53 | Profile profile = (Profile) parameters.get(PARM_PROFILE);
54 | String phaseId = (String) parameters.get(PARM_PHASE_ID);
55 | IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU);
56 | IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT);
57 | ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, false, profile, iu, InstallableUnitEvent.UNCONFIGURE, getTouchpoint()));
58 | return null;
59 | }
60 |
61 | public IStatus undo(Map parameters) {
62 | IProfile profile = (IProfile) parameters.get(PARM_PROFILE);
63 | String phaseId = (String) parameters.get(PARM_PHASE_ID);
64 | IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU);
65 | IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT);
66 | ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, true, profile, iu, InstallableUnitEvent.CONFIGURE, getTouchpoint()));
67 | return null;
68 | }
69 | }
70 |
71 | public Unconfigure(int weight, boolean forced) {
72 | super(PhaseSetFactory.PHASE_UNCONFIGURE, weight, forced);
73 | }
74 |
75 | public Unconfigure(int weight) {
76 | this(weight, false);
77 | }
78 |
79 | protected boolean isApplicable(InstallableUnitOperand op) {
80 | return (op.first() != null);
81 | }
82 |
83 | protected List getActions(InstallableUnitOperand currentOperand) {
84 | //TODO: monitor.subTask(NLS.bind(Messages.Engine_Unconfiguring_IU, unit.getId()));
85 |
86 | IInstallableUnit unit = currentOperand.first();
87 |
88 | ProvisioningAction beforeAction = new BeforeUnConfigureEventAction();
89 | ProvisioningAction afterAction = new AfterUnConfigureEventAction();
90 | Touchpoint touchpoint = getActionManager().getTouchpointPoint(unit.getTouchpointType());
91 | if (touchpoint != null) {
92 | beforeAction.setTouchpoint(touchpoint);
93 | afterAction.setTouchpoint(touchpoint);
94 | }
95 | ArrayList actions = new ArrayList();
96 | actions.add(beforeAction);
97 | if (!QueryUtil.isFragment(unit)) {
98 | List parsedActions = getActions(unit, phaseId);
99 | if (parsedActions != null)
100 | actions.addAll(parsedActions);
101 | }
102 | actions.add(afterAction);
103 | return actions;
104 | }
105 |
106 | protected String getProblemMessage() {
107 | return Messages.Phase_Unconfigure_Error;
108 | }
109 |
110 | protected IStatus initializeOperand(IProfile profile, InstallableUnitOperand operand, Map parameters, IProgressMonitor monitor) {
111 | IInstallableUnit iu = operand.first();
112 | parameters.put(PARM_IU, iu);
113 |
114 | Collection artifacts = iu.getArtifacts();
115 | if (artifacts != null && artifacts.size() > 0)
116 | parameters.put(PARM_ARTIFACT, artifacts.iterator().next());
117 |
118 | return Status.OK_STATUS;
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/phases/Uninstall.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine.phases;
12 |
13 | import java.util.*;
14 | import org.eclipse.core.runtime.*;
15 | import org.eclipse.equinox.internal.p2.engine.*;
16 | import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus;
17 | import org.eclipse.equinox.p2.core.IProvisioningAgent;
18 | import org.eclipse.equinox.p2.engine.PhaseSetFactory;
19 | import org.eclipse.equinox.p2.engine.IProfile;
20 | import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
21 | import org.eclipse.equinox.p2.engine.spi.Touchpoint;
22 | import org.eclipse.equinox.p2.metadata.IArtifactKey;
23 | import org.eclipse.equinox.p2.metadata.IInstallableUnit;
24 | import org.eclipse.equinox.p2.query.QueryUtil;
25 |
26 | public class Uninstall extends InstallableUnitPhase {
27 |
28 | final static class BeforeUninstallEventAction extends ProvisioningAction {
29 | public IStatus execute(Map parameters) {
30 | IProfile profile = (IProfile) parameters.get(PARM_PROFILE);
31 | String phaseId = (String) parameters.get(PARM_PHASE_ID);
32 | IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU);
33 | IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT);
34 | ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, true, profile, iu, InstallableUnitEvent.UNINSTALL, getTouchpoint()));
35 | return null;
36 | }
37 |
38 | public IStatus undo(Map parameters) {
39 | Profile profile = (Profile) parameters.get(PARM_PROFILE);
40 | String phaseId = (String) parameters.get(PARM_PHASE_ID);
41 | IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU);
42 | profile.addInstallableUnit(iu);
43 | IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT);
44 | ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, false, profile, iu, InstallableUnitEvent.INSTALL, getTouchpoint()));
45 | return null;
46 | }
47 | }
48 |
49 | final static class AfterUninstallEventAction extends ProvisioningAction {
50 | public IStatus execute(Map parameters) {
51 | Profile profile = (Profile) parameters.get(PARM_PROFILE);
52 | String phaseId = (String) parameters.get(PARM_PHASE_ID);
53 | IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU);
54 | profile.removeInstallableUnit(iu);
55 | IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT);
56 | ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, false, profile, iu, InstallableUnitEvent.UNINSTALL, getTouchpoint()));
57 | return null;
58 | }
59 |
60 | public IStatus undo(Map parameters) {
61 | IProfile profile = (IProfile) parameters.get(PARM_PROFILE);
62 | String phaseId = (String) parameters.get(PARM_PHASE_ID);
63 | IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU);
64 | IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT);
65 | ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, true, profile, iu, InstallableUnitEvent.INSTALL, getTouchpoint()));
66 | return null;
67 | }
68 | }
69 |
70 | public Uninstall(int weight, boolean forced) {
71 | super(PhaseSetFactory.PHASE_UNINSTALL, weight, forced);
72 | }
73 |
74 | public Uninstall(int weight) {
75 | this(weight, false);
76 | }
77 |
78 | protected boolean isApplicable(InstallableUnitOperand op) {
79 | return (op.first() != null && !op.first().equals(op.second()));
80 | }
81 |
82 | protected List getActions(InstallableUnitOperand currentOperand) {
83 | //TODO: monitor.subTask(NLS.bind(Messages.Engine_Uninstalling_IU, unit.getId()));
84 |
85 | ProvisioningAction beforeAction = new BeforeUninstallEventAction();
86 | ProvisioningAction afterAction = new AfterUninstallEventAction();
87 |
88 | IInstallableUnit unit = currentOperand.first();
89 | Touchpoint touchpoint = getActionManager().getTouchpointPoint(unit.getTouchpointType());
90 | if (touchpoint != null) {
91 | beforeAction.setTouchpoint(touchpoint);
92 | afterAction.setTouchpoint(touchpoint);
93 | }
94 |
95 | ArrayList actions = new ArrayList();
96 | actions.add(beforeAction);
97 |
98 | if (QueryUtil.isFragment(unit)) {
99 | actions.add(afterAction);
100 | return actions;
101 | }
102 |
103 | List parsedActions = getActions(unit, phaseId);
104 | if (parsedActions != null)
105 | actions.addAll(parsedActions);
106 | actions.add(afterAction);
107 | return actions;
108 | }
109 |
110 | protected String getProblemMessage() {
111 | return Messages.Phase_Uninstall_Error;
112 | }
113 |
114 | protected IStatus initializeOperand(IProfile profile, InstallableUnitOperand operand, Map parameters, IProgressMonitor monitor) {
115 | IInstallableUnit iu = operand.first();
116 | parameters.put(PARM_IU, iu);
117 |
118 | Collection artifacts = iu.getArtifacts();
119 | if (artifacts != null && artifacts.size() > 0)
120 | parameters.put(PARM_ARTIFACT, artifacts.iterator().next());
121 |
122 | return Status.OK_STATUS;
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/Engine.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import org.eclipse.core.runtime.*;
14 | import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
15 | import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus;
16 | import org.eclipse.equinox.p2.core.IProvisioningAgent;
17 | import org.eclipse.equinox.p2.engine.*;
18 |
19 | /**
20 | * Concrete implementation of the {@link IEngine} API.
21 | */
22 | public class Engine implements IEngine {
23 |
24 | private static final String ENGINE = "engine"; //$NON-NLS-1$
25 | private IProvisioningAgent agent;
26 |
27 | public Engine(IProvisioningAgent agent) {
28 | this.agent = agent;
29 | agent.registerService(ActionManager.SERVICE_NAME, new ActionManager());
30 | }
31 |
32 | private void checkArguments(IProfile iprofile, PhaseSet phaseSet, Operand[] operands, ProvisioningContext context, IProgressMonitor monitor) {
33 | if (iprofile == null)
34 | throw new IllegalArgumentException(Messages.null_profile);
35 |
36 | if (phaseSet == null)
37 | throw new IllegalArgumentException(Messages.null_phaseset);
38 |
39 | if (operands == null)
40 | throw new IllegalArgumentException(Messages.null_operands);
41 | }
42 |
43 | public IStatus perform(IProvisioningPlan plan, IPhaseSet phaseSet, IProgressMonitor monitor) {
44 | return perform(plan.getProfile(), phaseSet, ((ProvisioningPlan) plan).getOperands(), plan.getContext(), monitor);
45 | }
46 |
47 | public IStatus perform(IProvisioningPlan plan, IProgressMonitor monitor) {
48 | return perform(plan, PhaseSetFactory.createDefaultPhaseSet(), monitor);
49 | }
50 |
51 | public IStatus perform(IProfile iprofile, IPhaseSet phases, Operand[] operands, ProvisioningContext context, IProgressMonitor monitor) {
52 | PhaseSet phaseSet = (PhaseSet) phases;
53 | checkArguments(iprofile, phaseSet, operands, context, monitor);
54 | if (operands.length == 0)
55 | return Status.OK_STATUS;
56 | SimpleProfileRegistry profileRegistry = (SimpleProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
57 | IProvisioningEventBus eventBus = (IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME);
58 |
59 | if (context == null)
60 | context = new ProvisioningContext(agent);
61 |
62 | if (monitor == null)
63 | monitor = new NullProgressMonitor();
64 |
65 | Profile profile = profileRegistry.validate(iprofile);
66 |
67 | profileRegistry.lockProfile(profile);
68 | try {
69 | eventBus.publishEvent(new BeginOperationEvent(profile, phaseSet, operands, this));
70 | if (DebugHelper.DEBUG_ENGINE)
71 | DebugHelper.debug(ENGINE, "Beginning engine operation for profile=" + profile.getProfileId() + " [" + profile.getTimestamp() + "]:" + DebugHelper.LINE_SEPARATOR + DebugHelper.formatOperation(phaseSet, operands, context)); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
72 |
73 | EngineSession session = new EngineSession(agent, profile, context);
74 |
75 | MultiStatus result = phaseSet.perform(session, operands, monitor);
76 | if (result.isOK() || result.matches(IStatus.INFO | IStatus.WARNING)) {
77 | if (DebugHelper.DEBUG_ENGINE)
78 | DebugHelper.debug(ENGINE, "Preparing to commit engine operation for profile=" + profile.getProfileId()); //$NON-NLS-1$
79 | result.merge(session.prepare(monitor));
80 | }
81 | if (result.matches(IStatus.ERROR | IStatus.CANCEL)) {
82 | if (DebugHelper.DEBUG_ENGINE)
83 | DebugHelper.debug(ENGINE, "Rolling back engine operation for profile=" + profile.getProfileId() + ". Reason was: " + result.toString()); //$NON-NLS-1$ //$NON-NLS-2$
84 | IStatus status = session.rollback(monitor, result.getSeverity());
85 | if (status.matches(IStatus.ERROR))
86 | LogHelper.log(status);
87 | eventBus.publishEvent(new RollbackOperationEvent(profile, phaseSet, operands, this, result));
88 | } else {
89 | if (DebugHelper.DEBUG_ENGINE)
90 | DebugHelper.debug(ENGINE, "Committing engine operation for profile=" + profile.getProfileId()); //$NON-NLS-1$
91 | if (profile.isChanged())
92 | profileRegistry.updateProfile(profile);
93 | IStatus status = session.commit(monitor);
94 | if (status.matches(IStatus.ERROR))
95 | LogHelper.log(status);
96 | eventBus.publishEvent(new CommitOperationEvent(profile, phaseSet, operands, this));
97 | }
98 | //if there is only one child status, return that status instead because it will have more context
99 | IStatus[] children = result.getChildren();
100 | return children.length == 1 ? children[0] : result;
101 | } finally {
102 | profileRegistry.unlockProfile(profile);
103 | profile.setChanged(false);
104 | }
105 | }
106 |
107 | protected IStatus validate(IProfile iprofile, PhaseSet phaseSet, Operand[] operands, ProvisioningContext context, IProgressMonitor monitor) {
108 | checkArguments(iprofile, phaseSet, operands, context, monitor);
109 |
110 | if (context == null)
111 | context = new ProvisioningContext(agent);
112 |
113 | if (monitor == null)
114 | monitor = new NullProgressMonitor();
115 |
116 | ActionManager actionManager = (ActionManager) agent.getService(ActionManager.SERVICE_NAME);
117 | return phaseSet.validate(actionManager, iprofile, operands, context, monitor);
118 | }
119 |
120 | public IProvisioningPlan createPlan(IProfile profile, ProvisioningContext context) {
121 | return new ProvisioningPlan(profile, null, context);
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/phases/Install.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine.phases;
12 |
13 | import java.util.*;
14 | import org.eclipse.core.runtime.*;
15 | import org.eclipse.equinox.internal.p2.engine.*;
16 | import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus;
17 | import org.eclipse.equinox.p2.core.IProvisioningAgent;
18 | import org.eclipse.equinox.p2.engine.PhaseSetFactory;
19 | import org.eclipse.equinox.p2.engine.IProfile;
20 | import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
21 | import org.eclipse.equinox.p2.engine.spi.Touchpoint;
22 | import org.eclipse.equinox.p2.metadata.IArtifactKey;
23 | import org.eclipse.equinox.p2.metadata.IInstallableUnit;
24 | import org.eclipse.equinox.p2.query.QueryUtil;
25 | import org.eclipse.osgi.util.NLS;
26 |
27 | public class Install extends InstallableUnitPhase {
28 |
29 | final static class BeforeInstallEventAction extends ProvisioningAction {
30 |
31 | public IStatus execute(Map parameters) {
32 | IProfile profile = (IProfile) parameters.get(PARM_PROFILE);
33 | String phaseId = (String) parameters.get(PARM_PHASE_ID);
34 | IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU);
35 | IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT);
36 | ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, true, profile, iu, InstallableUnitEvent.INSTALL, getTouchpoint()));
37 | return null;
38 | }
39 |
40 | public IStatus undo(Map parameters) {
41 | Profile profile = (Profile) parameters.get(PARM_PROFILE);
42 | String phaseId = (String) parameters.get(PARM_PHASE_ID);
43 | IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU);
44 | profile.removeInstallableUnit(iu);
45 | IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT);
46 | ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, false, profile, iu, InstallableUnitEvent.UNINSTALL, getTouchpoint()));
47 | return null;
48 | }
49 | }
50 |
51 | final static class AfterInstallEventAction extends ProvisioningAction {
52 |
53 | public IStatus execute(Map parameters) {
54 | Profile profile = (Profile) parameters.get(PARM_PROFILE);
55 | String phaseId = (String) parameters.get(PARM_PHASE_ID);
56 | IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU);
57 | profile.addInstallableUnit(iu);
58 | IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT);
59 | ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, false, profile, iu, InstallableUnitEvent.INSTALL, getTouchpoint()));
60 | return null;
61 | }
62 |
63 | public IStatus undo(Map parameters) {
64 | IProfile profile = (IProfile) parameters.get(PARM_PROFILE);
65 | String phaseId = (String) parameters.get(PARM_PHASE_ID);
66 | IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU);
67 | IProvisioningAgent agent = (IProvisioningAgent) parameters.get(PARM_AGENT);
68 | ((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)).publishEvent(new InstallableUnitEvent(phaseId, true, profile, iu, InstallableUnitEvent.UNINSTALL, getTouchpoint()));
69 | return null;
70 | }
71 | }
72 |
73 | public Install(int weight) {
74 | super(PhaseSetFactory.PHASE_INSTALL, weight);
75 | }
76 |
77 | protected boolean isApplicable(InstallableUnitOperand op) {
78 | return (op.second() != null && !op.second().equals(op.first()));
79 | }
80 |
81 | protected List getActions(InstallableUnitOperand currentOperand) {
82 | //TODO: monitor.subTask(NLS.bind(Messages.Engine_Installing_IU, unit.getId()));
83 |
84 | ProvisioningAction beforeAction = new BeforeInstallEventAction();
85 | ProvisioningAction afterAction = new AfterInstallEventAction();
86 |
87 | IInstallableUnit unit = currentOperand.second();
88 | Touchpoint touchpoint = getActionManager().getTouchpointPoint(unit.getTouchpointType());
89 | if (touchpoint != null) {
90 | beforeAction.setTouchpoint(touchpoint);
91 | afterAction.setTouchpoint(touchpoint);
92 | }
93 |
94 | ArrayList actions = new ArrayList();
95 | actions.add(beforeAction);
96 |
97 | if (QueryUtil.isFragment(unit)) {
98 | actions.add(afterAction);
99 | return actions;
100 | }
101 |
102 | List parsedActions = getActions(unit, phaseId);
103 | if (parsedActions != null)
104 | actions.addAll(parsedActions);
105 | actions.add(afterAction);
106 | return actions;
107 | }
108 |
109 | protected String getProblemMessage() {
110 | return Messages.Phase_Install_Error;
111 | }
112 |
113 | protected IStatus initializeOperand(IProfile profile, InstallableUnitOperand operand, Map parameters, IProgressMonitor monitor) {
114 | IInstallableUnit iu = operand.second();
115 | monitor.subTask(NLS.bind(Messages.Phase_Install_Task, iu.getId()));
116 | parameters.put(PARM_IU, iu);
117 |
118 | Collection artifacts = iu.getArtifacts();
119 | if (artifacts != null && artifacts.size() > 0)
120 | parameters.put(PARM_ARTIFACT, artifacts.iterator().next());
121 |
122 | return Status.OK_STATUS;
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/Messages.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2012 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import org.eclipse.osgi.util.NLS;
14 |
15 | public class Messages extends NLS {
16 | public static String action_not_found;
17 |
18 | public static String action_syntax_error;
19 | public static String action_undo_error;
20 |
21 | public static String ActionManager_Exception_Creating_Action_Extension;
22 | public static String ActionManager_Required_Touchpoint_Not_Found;
23 |
24 | public static String actions_not_found;
25 | private static final String BUNDLE_NAME = "org.eclipse.equinox.internal.p2.engine.messages"; //$NON-NLS-1$
26 |
27 | public static String CertificateChecker_CertificateError;
28 | public static String CertificateChecker_CertificateRejected;
29 | public static String CertificateChecker_KeystoreConnectionError;
30 |
31 | public static String CertificateChecker_SignedContentError;
32 | public static String CertificateChecker_SignedContentIOError;
33 | public static String CertificateChecker_UnsignedNotAllowed;
34 |
35 | public static String committing;
36 | public static String download_artifact;
37 | public static String download_no_repository;
38 | public static String Engine_Operation_Canceled_By_User;
39 | public static String error_parsing_profile;
40 | public static String error_persisting_profile;
41 | public static String forced_action_execute_error;
42 | public static String InstallableUnitEvent_type_not_install_or_uninstall_or_configure;
43 | public static String io_FailedRead;
44 | public static String io_NotFound;
45 | public static String not_current_operand;
46 | public static String not_current_phase;
47 | public static String null_action;
48 |
49 | public static String null_operand;
50 | public static String null_operands;
51 | public static String null_phase;
52 | public static String null_phases;
53 | public static String null_phaseset;
54 | public static String null_profile;
55 | public static String operand_not_started;
56 |
57 | public static String operand_started;
58 |
59 | public static String ParameterizedProvisioningAction_action_or_parameters_null;
60 | public static String phase_error;
61 | public static String phase_not_started;
62 | public static String phase_started;
63 | public static String phase_undo_error;
64 | public static String phase_undo_operand_error;
65 |
66 | public static String Phase_Collect_Error;
67 | public static String Phase_Install_Error;
68 | public static String Phase_Configure_Error;
69 | public static String Phase_Configure_Task;
70 | public static String Phase_Install_Task;
71 | public static String Phase_Sizing_Error;
72 | public static String Phase_Sizing_Warning;
73 |
74 | public static String phase_thread_interrupted_error;
75 | public static String Phase_Unconfigure_Error;
76 | public static String Phase_Uninstall_Error;
77 |
78 | public static String phaseid_not_positive;
79 | public static String phaseid_not_set;
80 | public static String preparing;
81 | public static String profile_does_not_exist;
82 | public static String Profile_Duplicate_Root_Profile_Id;
83 | public static String profile_lock_not_reentrant;
84 | public static String profile_not_current;
85 | public static String profile_changed;
86 | public static String profile_not_registered;
87 | public static String Profile_Null_Profile_Id;
88 | public static String Profile_Parent_Not_Found;
89 | public static String ProfilePreferences_saving;
90 | public static String reg_dir_not_available;
91 | public static String rollingback_cancel;
92 | public static String rollingback_error;
93 | public static String session_commit_error;
94 | public static String session_context;
95 | public static String session_prepare_error;
96 | public static String shared_profile_not_found;
97 | public static String Shared_Profile;
98 |
99 | public static String SimpleProfileRegistry_Bad_profile_location;
100 | public static String SimpleProfileRegistry_CannotRemoveCurrentSnapshot;
101 | public static String SimpleProfileRegistry_Parser_Error_Parsing_Registry;
102 | public static String SimpleProfileRegistry_Parser_Has_Incompatible_Version;
103 | public static String SimpleProfileRegistry_Profile_in_use;
104 | public static String SimpleProfileRegistry_Profile_not_locked;
105 | public static String SimpleProfileRegistry_Profile_not_locked_due_to_exception;
106 | public static String SimpleProfileRegistry_States_Error_Reading_File;
107 | public static String SimpleProfileRegistry_States_Error_Writing_File;
108 | public static String SimpleProfileRegistry_state_not_found;
109 |
110 | public static String thread_not_owner;
111 | public static String touchpoint_commit_error;
112 | public static String touchpoint_prepare_error;
113 | public static String touchpoint_rollback_error;
114 |
115 | public static String TouchpointManager_Attribute_Not_Specified;
116 | public static String TouchpointManager_Conflicting_Touchpoint_Types;
117 | public static String TouchpointManager_Exception_Creating_Touchpoint_Extension;
118 | public static String TouchpointManager_Incorrectly_Named_Extension;
119 | public static String TouchpointManager_Null_Creating_Touchpoint_Extension;
120 | public static String TouchpointManager_Null_Touchpoint_Type_Argument;
121 |
122 | static {
123 | // initialize resource bundles
124 | NLS.initializeMessages(BUNDLE_NAME, Messages.class);
125 | }
126 |
127 | private Messages() {
128 | // Do not instantiate
129 | }
130 |
131 | }
132 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/p2/engine/PhaseSetFactory.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.p2.engine;
12 |
13 | import java.util.*;
14 | import org.eclipse.equinox.internal.p2.engine.*;
15 | import org.eclipse.equinox.internal.p2.engine.phases.*;
16 |
17 | /**
18 | * @since 2.0
19 | * @noextend This class is not intended to be subclassed by clients.
20 | */
21 | public class PhaseSetFactory {
22 |
23 | private static final boolean forcedUninstall = Boolean.valueOf(EngineActivator.getContext().getProperty("org.eclipse.equinox.p2.engine.forcedUninstall")).booleanValue(); //$NON-NLS-1$
24 |
25 | /**
26 | * A phase id (value "checkTrust") describing the certificate trust check phase.
27 | * This phase examines the code signing certificates of the artifacts being installed
28 | * to ensure they are signed and trusted by the running system.
29 | */
30 | public static String PHASE_CHECK_TRUST = "checkTrust"; //$NON-NLS-1$
31 | /**
32 | * A phase id (value "collect") describing the collect phase.
33 | * This phase gathers all the artifacts to be installed, typically by copying them
34 | * from some repository into a suitable local location for the application being installed.
35 | */
36 | public static String PHASE_COLLECT = "collect"; //$NON-NLS-1$
37 | /**
38 | * A phase id (value "configure") describing the configuration phase.
39 | * This phase writes configuration data related to the software being provisioned.
40 | * Until configuration occurs the end user of the software will be have access to
41 | * the installed functionality.
42 | */
43 | public static String PHASE_CONFIGURE = "configure"; //$NON-NLS-1$
44 | /**
45 | * A phase id (value "install") describing the install phase.
46 | * This phase performs any necessary transformations on the downloaded
47 | * artifacts to put them in the correct shape for the running application, such
48 | * as decompressing or moving content, setting file permissions, etc).
49 | */
50 | public static String PHASE_INSTALL = "install"; //$NON-NLS-1$
51 | /**
52 | * A phase id (value "property") describing the property modification phase.
53 | * This phase performs changes to profile properties.
54 | */
55 | public static String PHASE_PROPERTY = "property"; //$NON-NLS-1$
56 | /**
57 | * A phase id (value "unconfigure") describing the unconfigure phase.
58 | * This phase removes configuration data related to the software being removed.
59 | * This phase is the inverse of the changes performed in the configure phase.
60 | */
61 | public static String PHASE_UNCONFIGURE = "unconfigure"; //$NON-NLS-1$
62 | /**
63 | * A phase id (value "uninstall") describing the uninstall phase.
64 | * This phase removes artifacts from the system being provisioned that are
65 | * no longer required in the new profile.
66 | */
67 | public static String PHASE_UNINSTALL = "uninstall"; //$NON-NLS-1$
68 |
69 | private static final List ALL_PHASES_LIST = Arrays.asList(new String[] {PHASE_COLLECT, PHASE_UNCONFIGURE, PHASE_UNINSTALL, PHASE_PROPERTY, PHASE_CHECK_TRUST, PHASE_INSTALL, PHASE_CONFIGURE});
70 |
71 | /**
72 | * Creates a default phase set that covers all the provisioning operations.
73 | * Phases can be specified for exclusion.
74 | *
75 | * @param exclude - A set of bit options that specify the phases to exclude.
76 | * See {@link PhaseSetFactory} for possible options
77 | * @return the {@link PhaseSet}
78 | */
79 | public static final IPhaseSet createDefaultPhaseSetExcluding(String[] exclude) {
80 | if (exclude == null || exclude.length == 0)
81 | return createDefaultPhaseSet();
82 | List excludeList = Arrays.asList(exclude);
83 | List includeList = new ArrayList(ALL_PHASES_LIST);
84 | includeList.removeAll(excludeList);
85 | return createPhaseSetIncluding(includeList.toArray(new String[includeList.size()]));
86 | }
87 |
88 | /**
89 | * Creates a default phase set that covers all the provisioning operations.
90 | * Phases can be specified for inclusion.
91 | *
92 | * @param include - A set of bit options that specify the phases to include.
93 | * See {@link PhaseSetFactory} for possible options
94 | * @return the {@link PhaseSet}
95 | */
96 | public static final IPhaseSet createPhaseSetIncluding(String[] include) {
97 | if (include == null || include.length == 0)
98 | return new PhaseSet(new Phase[0]);
99 | List includeList = Arrays.asList(include);
100 | ArrayList phases = new ArrayList();
101 | if (includeList.contains(PHASE_COLLECT))
102 | phases.add(new Collect(100));
103 | if (includeList.contains(PHASE_CHECK_TRUST))
104 | phases.add(new CheckTrust(10));
105 | if (includeList.contains(PHASE_UNCONFIGURE))
106 | phases.add(new Unconfigure(10, forcedUninstall));
107 | if (includeList.contains(PHASE_UNINSTALL))
108 | phases.add(new Uninstall(50, forcedUninstall));
109 | if (includeList.contains(PHASE_PROPERTY))
110 | phases.add(new Property(1));
111 | if (includeList.contains(PHASE_INSTALL))
112 | phases.add(new Install(50));
113 | if (includeList.contains(PHASE_CONFIGURE))
114 | phases.add(new Configure(10));
115 | return new PhaseSet(phases.toArray(new Phase[phases.size()]));
116 | }
117 |
118 | public static IPhaseSet createDefaultPhaseSet() {
119 | return createPhaseSetIncluding(ALL_PHASES_LIST.toArray(new String[ALL_PHASES_LIST.size()]));
120 | }
121 |
122 | public static ISizingPhaseSet createSizingPhaseSet() {
123 | return new SizingPhaseSet();
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/phases/Sizing.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine.phases;
12 |
13 | import java.util.*;
14 | import org.eclipse.core.runtime.*;
15 | import org.eclipse.equinox.internal.p2.engine.*;
16 | import org.eclipse.equinox.p2.core.ProvisionException;
17 | import org.eclipse.equinox.p2.engine.IProfile;
18 | import org.eclipse.equinox.p2.engine.ProvisioningContext;
19 | import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
20 | import org.eclipse.equinox.p2.metadata.IInstallableUnit;
21 | import org.eclipse.equinox.p2.metadata.ITouchpointType;
22 | import org.eclipse.equinox.p2.metadata.expression.ExpressionUtil;
23 | import org.eclipse.equinox.p2.query.*;
24 | import org.eclipse.equinox.p2.repository.artifact.*;
25 |
26 | public class Sizing extends InstallableUnitPhase {
27 | private static final String PHASE_ID = "sizing"; //$NON-NLS-1$
28 | private static final String COLLECT_PHASE_ID = "collect"; //$NON-NLS-1$
29 |
30 | private long sizeOnDisk;
31 | private long dlSize;
32 |
33 | public Sizing(int weight) {
34 | super(PHASE_ID, weight);
35 | }
36 |
37 | protected boolean isApplicable(InstallableUnitOperand op) {
38 | return (op.second() != null && !op.second().equals(op.first()));
39 | }
40 |
41 | public long getDiskSize() {
42 | return sizeOnDisk;
43 | }
44 |
45 | public long getDownloadSize() {
46 | return dlSize;
47 | }
48 |
49 | protected List getActions(InstallableUnitOperand operand) {
50 | IInstallableUnit unit = operand.second();
51 | List parsedActions = getActions(unit, COLLECT_PHASE_ID);
52 | if (parsedActions != null)
53 | return parsedActions;
54 |
55 | ITouchpointType type = unit.getTouchpointType();
56 | if (type == null || type == ITouchpointType.NONE)
57 | return null;
58 |
59 | String actionId = getActionManager().getTouchpointQualifiedActionId(COLLECT_PHASE_ID, type);
60 | ProvisioningAction action = getActionManager().getAction(actionId, null);
61 | if (action == null) {
62 | return null;
63 | }
64 | return Collections.singletonList(action);
65 | }
66 |
67 | protected String getProblemMessage() {
68 | return Messages.Phase_Sizing_Error;
69 | }
70 |
71 | protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map parameters) {
72 | @SuppressWarnings("unchecked")
73 | List artifactRequests = (List) parameters.get(Collect.PARM_ARTIFACT_REQUESTS);
74 | ProvisioningContext context = (ProvisioningContext) parameters.get(PARM_CONTEXT);
75 | int statusCode = 0;
76 |
77 | Set artifactsToObtain = new HashSet(artifactRequests.size());
78 |
79 | for (IArtifactRequest[] requests : artifactRequests) {
80 | if (requests == null)
81 | continue;
82 | for (int i = 0; i < requests.length; i++) {
83 | artifactsToObtain.add(requests[i]);
84 | }
85 | }
86 |
87 | if (monitor.isCanceled())
88 | return Status.CANCEL_STATUS;
89 |
90 | SubMonitor sub = SubMonitor.convert(monitor, 1000);
91 | IQueryable repoQueryable = context.getArtifactRepositories(sub.newChild(500));
92 | IQuery all = new ExpressionMatchQuery(IArtifactRepository.class, ExpressionUtil.TRUE_EXPRESSION);
93 | IArtifactRepository[] repositories = repoQueryable.query(all, sub.newChild(500)).toArray(IArtifactRepository.class);
94 |
95 | for (IArtifactRequest artifactRequest : artifactsToObtain) {
96 | if (sub.isCanceled())
97 | break;
98 | boolean found = false;
99 | for (int i = 0; i < repositories.length; i++) {
100 | IArtifactRepository repo = repositories[i];
101 | if (sub.isCanceled())
102 | return Status.CANCEL_STATUS;
103 | IArtifactDescriptor[] descriptors = repo.getArtifactDescriptors(artifactRequest.getArtifactKey());
104 | if (descriptors.length > 0) {
105 | if (descriptors[0].getProperty(IArtifactDescriptor.ARTIFACT_SIZE) != null)
106 | sizeOnDisk += Long.parseLong(descriptors[0].getProperty(IArtifactDescriptor.ARTIFACT_SIZE));
107 | else
108 | statusCode = ProvisionException.ARTIFACT_INCOMPLETE_SIZING;
109 | if (descriptors[0].getProperty(IArtifactDescriptor.DOWNLOAD_SIZE) != null)
110 | dlSize += Long.parseLong(descriptors[0].getProperty(IArtifactDescriptor.DOWNLOAD_SIZE));
111 | else
112 | statusCode = ProvisionException.ARTIFACT_INCOMPLETE_SIZING;
113 | found = true;
114 | break;
115 | }
116 | }
117 | if (!found)
118 | // The artifact wasn't present in any repository
119 | return new Status(IStatus.ERROR, EngineActivator.ID, ProvisionException.ARTIFACT_NOT_FOUND, Messages.Phase_Sizing_Error, null);
120 | }
121 | if (statusCode != 0)
122 | return new Status(IStatus.WARNING, EngineActivator.ID, statusCode, Messages.Phase_Sizing_Warning, null);
123 | return null;
124 | }
125 |
126 | protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map parameters) {
127 | parameters.put(Collect.PARM_ARTIFACT_REQUESTS, new ArrayList());
128 | return null;
129 | }
130 |
131 | protected IStatus initializeOperand(IProfile profile, InstallableUnitOperand operand, Map parameters, IProgressMonitor monitor) {
132 | IStatus status = super.initializeOperand(profile, operand, parameters, monitor);
133 | // defer setting the IU until after the super method to avoid triggering touchpoint initialization
134 | IInstallableUnit iu = operand.second();
135 | parameters.put(PARM_IU, iu);
136 | return status;
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | org.wso2.eclipse.equinox
4 | eclipse-p2-plugins
5 | 1.0.1-SNAPSHOT
6 | ../pom.xml
7 |
8 |
9 | 4.0.0
10 | org.eclipse.equinox
11 | org.eclipse.equinox.p2.engine
12 | jar
13 | 2.3.0.v20130526-2122-wso2v2-SNAPSHOT
14 | Eclipse P2 engine
15 | Patched to fix bundle pool location issue with carbon
16 |
17 |
18 |
19 | org.eclipse.osgi
20 | org.eclipse.osgi
21 |
22 |
23 | org.eclipse.osgi
24 | org.eclipse.osgi.services
25 |
26 |
27 | org.eclipse.core
28 | org.eclipse.core.jobs
29 |
30 |
31 | org.eclipse.core
32 | org.eclipse.core.runtime
33 |
34 |
35 | org.eclipse.equinox
36 | org.eclipse.equinox.util
37 |
38 |
39 | org.eclipse.equinox
40 | org.eclipse.equinox.security
41 |
42 |
43 | org.eclipse.equinox
44 | org.eclipse.equinox.registry
45 |
46 |
47 | org.eclipse.equinox
48 | org.eclipse.equinox.p2.publisher.eclipse
49 |
50 |
51 | org.eclipse.equinox
52 | org.eclipse.equinox.p2.publisher.pdepublishing
53 |
54 |
55 | org.eclipse.equinox
56 | org.eclipse.equinox.p2.director
57 |
58 |
59 | org.eclipse.equinox
60 | org.eclipse.equinox.p2.garbagecollector
61 |
62 |
63 | org.eclipse.equinox
64 | org.eclipse.equinox.p2.publisher
65 |
66 |
67 | org.eclipse.equinox
68 | org.eclipse.equinox.preferences
69 |
70 |
71 | org.eclipse.equinox
72 | org.eclipse.equinox.p2.repository
73 |
74 |
75 | org.eclipse.equinox
76 | org.eclipse.equinox.p2.metadata
77 |
78 |
79 | org.eclipse.equinox
80 | org.eclipse.equinox.p2.core
81 |
82 |
83 | org.eclipse.equinox
84 | org.eclipse.equinox.common
85 |
86 |
87 | org.eclipse.equinox
88 | org.eclipse.equinox.simpleconfigurator
89 |
90 |
91 | org.eclipse.equinox
92 | org.eclipse.equinox.simpleconfigurator.manipulator
93 |
94 |
95 | org.eclipse.equinox
96 | org.eclipse.equinox.p2.metadata.repository
97 |
98 |
99 | org.eclipse.equinox
100 | org.eclipse.equinox.frameworkadmin
101 |
102 |
103 |
104 |
105 |
106 |
107 | org.apache.maven.wagon
108 | wagon-ssh
109 | 2.1
110 |
111 |
112 |
113 |
114 | org.jvnet.maven.incrementalbuild
115 | incremental-build-plugin
116 | 1.3
117 |
118 |
119 |
120 | incremental-build
121 |
122 |
123 |
124 |
125 |
126 | org.apache.maven.plugins
127 | maven-compiler-plugin
128 |
129 | 1.7
130 | 1.7
131 |
132 |
133 |
134 | maven-jar-plugin
135 |
136 |
137 | META-INF/MANIFEST.MF
138 |
139 |
140 |
141 |
142 |
143 |
144 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/phases/Collect.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2012 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | * WindRiver - https://bugs.eclipse.org/bugs/show_bug.cgi?id=227372
11 | *******************************************************************************/
12 | package org.eclipse.equinox.internal.p2.engine.phases;
13 |
14 | import java.util.*;
15 | import org.eclipse.core.runtime.*;
16 | import org.eclipse.equinox.internal.p2.engine.*;
17 | import org.eclipse.equinox.internal.p2.repository.DownloadPauseResumeEvent;
18 | import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus;
19 | import org.eclipse.equinox.p2.core.IProvisioningAgent;
20 | import org.eclipse.equinox.p2.engine.*;
21 | import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
22 | import org.eclipse.equinox.p2.metadata.IInstallableUnit;
23 | import org.eclipse.equinox.p2.metadata.ITouchpointType;
24 | import org.eclipse.equinox.p2.repository.artifact.IArtifactRequest;
25 | import org.eclipse.osgi.util.NLS;
26 |
27 | /**
28 | * The goal of the collect phase is to ask the touchpoints if the artifacts associated with an IU need to be downloaded.
29 | */
30 | public class Collect extends InstallableUnitPhase {
31 | public static final String PARM_ARTIFACT_REQUESTS = "artifactRequests"; //$NON-NLS-1$
32 | public static final String NO_ARTIFACT_REPOSITORIES_AVAILABLE = "noArtifactRepositoriesAvailable"; //$NON-NLS-1$
33 | private IProvisioningAgent agent = null;
34 |
35 | public Collect(int weight) {
36 | super(PhaseSetFactory.PHASE_COLLECT, weight);
37 | //re-balance work since postPerform will do almost all the time-consuming work
38 | prePerformWork = 0;
39 | mainPerformWork = 100;
40 | postPerformWork = 1000;
41 | }
42 |
43 | protected boolean isApplicable(InstallableUnitOperand op) {
44 | return (op.second() != null && !op.second().equals(op.first()));
45 | }
46 |
47 | protected List getActions(InstallableUnitOperand operand) {
48 | IInstallableUnit unit = operand.second();
49 | List parsedActions = getActions(unit, phaseId);
50 | if (parsedActions != null)
51 | return parsedActions;
52 |
53 | ITouchpointType type = unit.getTouchpointType();
54 | if (type == null || type == ITouchpointType.NONE)
55 | return null;
56 |
57 | String actionId = getActionManager().getTouchpointQualifiedActionId(phaseId, type);
58 | ProvisioningAction action = getActionManager().getAction(actionId, null);
59 | if (action == null) {
60 | return null;
61 | }
62 | return Collections.singletonList(action);
63 | }
64 |
65 | protected String getProblemMessage() {
66 | return Messages.Phase_Collect_Error;
67 | }
68 |
69 | protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map parameters) {
70 | // do nothing for rollback if the provisioning has been cancelled
71 | if (monitor.isCanceled())
72 | return Status.OK_STATUS;
73 | @SuppressWarnings("unchecked")
74 | List artifactRequests = (List) parameters.get(PARM_ARTIFACT_REQUESTS);
75 | // it happens when rollbacking
76 | if (artifactRequests.size() == 0)
77 | return Status.OK_STATUS;
78 | ProvisioningContext context = (ProvisioningContext) parameters.get(PARM_CONTEXT);
79 | synchronized (this) {
80 | agent = (IProvisioningAgent) parameters.get(PARM_AGENT);
81 | }
82 |
83 | if (isPaused) {
84 | try {
85 | Thread.sleep(1000);
86 | } catch (InterruptedException e) {
87 | return new Status(IStatus.ERROR, EngineActivator.ID, NLS.bind(Messages.phase_thread_interrupted_error, phaseId), e);
88 | }
89 | if (monitor.isCanceled())
90 | return Status.CANCEL_STATUS;
91 | }
92 |
93 | List totalArtifactRequests = new ArrayList(artifactRequests.size());
94 | DownloadManager dm = new DownloadManager(context, agent);
95 | for (IArtifactRequest[] requests : artifactRequests) {
96 | for (int i = 0; i < requests.length; i++) {
97 | dm.add(requests[i]);
98 | totalArtifactRequests.add(requests[i]);
99 | }
100 | }
101 | IProvisioningEventBus bus = (IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME);
102 | if (bus != null)
103 | bus.publishEvent(new CollectEvent(CollectEvent.TYPE_OVERALL_START, null, context, totalArtifactRequests.toArray(new IArtifactRequest[totalArtifactRequests.size()])));
104 | IStatus downloadStatus = dm.start(monitor);
105 | try {
106 | return downloadStatus;
107 | } finally {
108 | if (downloadStatus.isOK() && bus != null)
109 | bus.publishEvent(new CollectEvent(CollectEvent.TYPE_OVERALL_END, null, context, totalArtifactRequests.toArray(new IArtifactRequest[totalArtifactRequests.size()])));
110 | synchronized (this) {
111 | agent = null;
112 | }
113 | }
114 | }
115 |
116 | protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map parameters) {
117 | parameters.put(PARM_ARTIFACT_REQUESTS, new ArrayList());
118 | return null;
119 | }
120 |
121 | @Override
122 | protected void setPaused(boolean isPaused) {
123 | super.setPaused(isPaused);
124 | firePauseEventToDownloadJobs();
125 | }
126 |
127 | private void firePauseEventToDownloadJobs() {
128 | synchronized (this) {
129 | if (agent != null) {
130 | IProvisioningEventBus bus = (IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME);
131 | if (bus != null)
132 | bus.publishEvent(new DownloadPauseResumeEvent(isPaused ? DownloadPauseResumeEvent.TYPE_PAUSE : DownloadPauseResumeEvent.TYPE_RESUME));
133 | }
134 | }
135 | }
136 |
137 | protected IStatus initializeOperand(IProfile profile, InstallableUnitOperand operand, Map parameters, IProgressMonitor monitor) {
138 | IStatus status = super.initializeOperand(profile, operand, parameters, monitor);
139 | // defer setting the IU until after the super method to avoid triggering touchpoint initialization
140 | IInstallableUnit iu = operand.second();
141 | parameters.put(PARM_IU, iu);
142 | return status;
143 | }
144 |
145 | }
146 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/ProfileParser.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import java.util.LinkedHashMap;
14 | import java.util.Map;
15 | import org.eclipse.equinox.internal.p2.metadata.repository.io.MetadataParser;
16 | import org.eclipse.equinox.p2.metadata.IInstallableUnit;
17 | import org.eclipse.equinox.p2.metadata.Version;
18 | import org.osgi.framework.BundleContext;
19 | import org.xml.sax.Attributes;
20 |
21 | /**
22 | * An abstract XML parser class for parsing profiles as written by the ProfileWriter.
23 | */
24 | public abstract class ProfileParser extends MetadataParser implements ProfileXMLConstants {
25 |
26 | public ProfileParser(BundleContext context, String bundleId) {
27 | super(context, bundleId);
28 | }
29 |
30 | protected class ProfileHandler extends RootHandler {
31 |
32 | private final String[] required = new String[] {ID_ATTRIBUTE};
33 |
34 | private String profileId;
35 | private String parentId;
36 | private String timestamp;
37 | private PropertiesHandler propertiesHandler;
38 | private InstallableUnitsHandler unitsHandler;
39 | private IUsPropertiesHandler iusPropertiesHandler;
40 |
41 | public ProfileHandler() {
42 | // default
43 | }
44 |
45 | protected ProfileHandler(String profileId) {
46 | this.profileId = profileId;
47 | }
48 |
49 | protected void handleRootAttributes(Attributes attributes) {
50 | profileId = parseRequiredAttributes(attributes, required)[0];
51 | parentId = parseOptionalAttribute(attributes, PARENT_ID_ATTRIBUTE);
52 | timestamp = parseOptionalAttribute(attributes, TIMESTAMP_ATTRIBUTE);
53 |
54 | }
55 |
56 | public void startElement(String name, Attributes attributes) {
57 | if (PROPERTIES_ELEMENT.equals(name)) {
58 | if (propertiesHandler == null) {
59 | propertiesHandler = new PropertiesHandler(this, attributes);
60 | } else {
61 | duplicateElement(this, name, attributes);
62 | }
63 | } else if (INSTALLABLE_UNITS_ELEMENT.equals(name)) {
64 | if (unitsHandler == null) {
65 | unitsHandler = new InstallableUnitsHandler(this, attributes);
66 | } else {
67 | duplicateElement(this, name, attributes);
68 | }
69 | } else if (IUS_PROPERTIES_ELEMENT.equals(name)) {
70 | if (iusPropertiesHandler == null) {
71 | iusPropertiesHandler = new IUsPropertiesHandler(this, attributes);
72 | } else {
73 | duplicateElement(this, name, attributes);
74 | }
75 | } else {
76 | invalidElement(name, attributes);
77 | }
78 | }
79 |
80 | public String getProfileId() {
81 | return profileId;
82 | }
83 |
84 | public String getParentId() {
85 | return parentId;
86 | }
87 |
88 | public long getTimestamp() {
89 | if (timestamp != null) {
90 | try {
91 | return Long.parseLong(timestamp);
92 | } catch (NumberFormatException e) {
93 | // TODO: log
94 | }
95 | }
96 | return 0;
97 | }
98 |
99 | public Map getProperties() {
100 | if (propertiesHandler == null)
101 | return null;
102 | return propertiesHandler.getProperties();
103 | }
104 |
105 | public IInstallableUnit[] getInstallableUnits() {
106 | if (unitsHandler == null)
107 | return null;
108 | return unitsHandler.getUnits();
109 | }
110 |
111 | public Map getIUProperties(IInstallableUnit iu) {
112 | if (iusPropertiesHandler == null)
113 | return null;
114 |
115 | Map> iusPropertiesMap = iusPropertiesHandler.getIUsPropertiesMap();
116 | if (iusPropertiesMap == null)
117 | return null;
118 |
119 | String iuIdentity = iu.getId() + "_" + iu.getVersion().toString(); //$NON-NLS-1$
120 | return iusPropertiesMap.get(iuIdentity);
121 | }
122 | }
123 |
124 | protected class IUPropertiesHandler extends AbstractHandler {
125 |
126 | private final String[] required = new String[] {ID_ATTRIBUTE, VERSION_ATTRIBUTE};
127 |
128 | private String iuIdentity;
129 | private Map> iusPropertiesMap;
130 | private PropertiesHandler propertiesHandler;
131 |
132 | public IUPropertiesHandler(AbstractHandler parentHandler, Attributes attributes, Map> iusPropertiesMap) {
133 | super(parentHandler, IU_PROPERTIES_ELEMENT);
134 | this.iusPropertiesMap = iusPropertiesMap;
135 |
136 | String values[] = parseRequiredAttributes(attributes, required);
137 | String id = values[0];
138 | Version version = checkVersion(IU_PROPERTIES_ELEMENT, VERSION_ATTRIBUTE, values[1]);
139 | iuIdentity = id + "_" + version.toString(); //$NON-NLS-1$
140 | }
141 |
142 | protected void finished() {
143 | if (isValidXML() && iuIdentity != null && propertiesHandler != null) {
144 | iusPropertiesMap.put(iuIdentity, propertiesHandler.getProperties());
145 | }
146 | }
147 |
148 | public void startElement(String name, Attributes attributes) {
149 | if (name.equals(PROPERTIES_ELEMENT)) {
150 | propertiesHandler = new PropertiesHandler(this, attributes);
151 | } else {
152 | invalidElement(name, attributes);
153 | }
154 | }
155 | }
156 |
157 | protected class IUsPropertiesHandler extends AbstractHandler {
158 |
159 | private Map> iusPropertiesMap;
160 |
161 | public IUsPropertiesHandler(AbstractHandler parentHandler, Attributes attributes) {
162 | super(parentHandler, IUS_PROPERTIES_ELEMENT);
163 | String sizeStr = parseOptionalAttribute(attributes, COLLECTION_SIZE_ATTRIBUTE);
164 | int size = (sizeStr != null ? new Integer(sizeStr).intValue() : 4);
165 | iusPropertiesMap = new LinkedHashMap>(size);
166 | }
167 |
168 | public Map> getIUsPropertiesMap() {
169 | return iusPropertiesMap;
170 | }
171 |
172 | public void startElement(String name, Attributes attributes) {
173 | if (name.equals(IU_PROPERTIES_ELEMENT)) {
174 | new IUPropertiesHandler(this, attributes, iusPropertiesMap);
175 | } else {
176 | invalidElement(name, attributes);
177 | }
178 | }
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/phases/Property.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2008, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine.phases;
12 |
13 | import java.util.*;
14 | import org.eclipse.core.runtime.IStatus;
15 | import org.eclipse.equinox.internal.p2.engine.*;
16 | import org.eclipse.equinox.p2.engine.PhaseSetFactory;
17 | import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
18 | import org.eclipse.equinox.p2.metadata.IInstallableUnit;
19 |
20 | public class Property extends Phase {
21 |
22 | public class ProfilePropertyAction extends ProvisioningAction {
23 |
24 | public IStatus execute(Map parameters) {
25 | Profile profile = (Profile) parameters.get(PARM_PROFILE);
26 | PropertyOperand propertyOperand = (PropertyOperand) parameters.get(PARM_OPERAND);
27 |
28 | if (propertyOperand.second() == null)
29 | removeProfileProperty(profile, propertyOperand);
30 | else
31 | setProfileProperty(profile, propertyOperand, false);
32 |
33 | return null;
34 | }
35 |
36 | public IStatus undo(Map parameters) {
37 | Profile profile = (Profile) parameters.get(PARM_PROFILE);
38 | PropertyOperand propertyOperand = (PropertyOperand) parameters.get(PARM_OPERAND);
39 |
40 | if (propertyOperand.first() == null)
41 | removeProfileProperty(profile, propertyOperand);
42 | else
43 | setProfileProperty(profile, propertyOperand, true);
44 |
45 | return null;
46 | }
47 |
48 | private void setProfileProperty(Profile profile, PropertyOperand propertyOperand, boolean undo) {
49 |
50 | String value = (String) (undo ? propertyOperand.first() : propertyOperand.second());
51 |
52 | if (propertyOperand instanceof InstallableUnitPropertyOperand) {
53 | InstallableUnitPropertyOperand iuPropertyOperand = (InstallableUnitPropertyOperand) propertyOperand;
54 | profile.setInstallableUnitProperty(iuPropertyOperand.getInstallableUnit(), iuPropertyOperand.getKey(), value);
55 | } else {
56 | profile.setProperty(propertyOperand.getKey(), value);
57 | }
58 | }
59 |
60 | private void removeProfileProperty(Profile profile, PropertyOperand propertyOperand) {
61 | if (propertyOperand instanceof InstallableUnitPropertyOperand) {
62 | InstallableUnitPropertyOperand iuPropertyOperand = (InstallableUnitPropertyOperand) propertyOperand;
63 | profile.removeInstallableUnitProperty(iuPropertyOperand.getInstallableUnit(), iuPropertyOperand.getKey());
64 | } else {
65 | profile.removeProperty(propertyOperand.getKey());
66 | }
67 | }
68 | }
69 |
70 | public class UpdateInstallableUnitProfilePropertiesAction extends ProvisioningAction {
71 |
72 | // we do not need to use a memento here since the profile is not persisted unless the operation is successful
73 | Map originalSourceProperties;
74 | Map originalTargetProperties;
75 |
76 | public IStatus execute(Map parameters) {
77 | Profile profile = (Profile) parameters.get(PARM_PROFILE);
78 | InstallableUnitOperand iuOperand = (InstallableUnitOperand) parameters.get(PARM_OPERAND);
79 |
80 | IInstallableUnit source = iuOperand.first();
81 | originalSourceProperties = profile.getInstallableUnitProperties(source);
82 |
83 | IInstallableUnit target = iuOperand.second();
84 | originalTargetProperties = profile.getInstallableUnitProperties(target);
85 |
86 | profile.addInstallableUnitProperties(target, originalSourceProperties);
87 | profile.clearInstallableUnitProperties(source);
88 |
89 | return null;
90 | }
91 |
92 | public IStatus undo(Map parameters) {
93 | Profile profile = (Profile) parameters.get(PARM_PROFILE);
94 | InstallableUnitOperand iuOperand = (InstallableUnitOperand) parameters.get(PARM_OPERAND);
95 |
96 | IInstallableUnit source = iuOperand.first();
97 | profile.clearInstallableUnitProperties(source);
98 | profile.addInstallableUnitProperties(source, originalSourceProperties);
99 |
100 | IInstallableUnit target = iuOperand.second();
101 | profile.clearInstallableUnitProperties(target);
102 | profile.addInstallableUnitProperties(target, originalTargetProperties);
103 |
104 | return null;
105 | }
106 | }
107 |
108 | public class RemoveInstallableUnitProfilePropertiesAction extends ProvisioningAction {
109 |
110 | // we do not need to use a memento here since the profile is not persisted unless the operation is successful
111 | Map originalSourceProperties;
112 | Map originalTargetProperties;
113 |
114 | public IStatus execute(Map parameters) {
115 | Profile profile = (Profile) parameters.get(PARM_PROFILE);
116 | InstallableUnitOperand iuOperand = (InstallableUnitOperand) parameters.get(PARM_OPERAND);
117 |
118 | IInstallableUnit source = iuOperand.first();
119 | originalSourceProperties = profile.getInstallableUnitProperties(source);
120 | profile.clearInstallableUnitProperties(source);
121 |
122 | return null;
123 | }
124 |
125 | public IStatus undo(Map parameters) {
126 | Profile profile = (Profile) parameters.get(PARM_PROFILE);
127 | InstallableUnitOperand iuOperand = (InstallableUnitOperand) parameters.get(PARM_OPERAND);
128 |
129 | IInstallableUnit source = iuOperand.first();
130 | profile.clearInstallableUnitProperties(source);
131 | profile.addInstallableUnitProperties(source, originalSourceProperties);
132 |
133 | return null;
134 | }
135 | }
136 |
137 | public Property(int weight) {
138 | super(PhaseSetFactory.PHASE_PROPERTY, weight);
139 | }
140 |
141 | protected List getActions(Operand operand) {
142 | if (operand instanceof PropertyOperand)
143 | return Collections. singletonList(new ProfilePropertyAction());
144 |
145 | if (operand instanceof InstallableUnitOperand) {
146 | InstallableUnitOperand iuOperand = (InstallableUnitOperand) operand;
147 | if (iuOperand.first() != null) {
148 | if (iuOperand.second() != null) {
149 | return Collections. singletonList(new UpdateInstallableUnitProfilePropertiesAction());
150 | }
151 | return Collections. singletonList(new RemoveInstallableUnitProfilePropertiesAction());
152 | }
153 | }
154 | return null;
155 | }
156 | }
157 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/DownloadManager.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2012 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | * WindRiver - https://bugs.eclipse.org/bugs/show_bug.cgi?id=227372
11 | *******************************************************************************/
12 | package org.eclipse.equinox.internal.p2.engine;
13 |
14 | import java.util.*;
15 | import org.eclipse.core.runtime.*;
16 | import org.eclipse.equinox.internal.p2.engine.phases.Collect;
17 | import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus;
18 | import org.eclipse.equinox.p2.core.IProvisioningAgent;
19 | import org.eclipse.equinox.p2.engine.ProvisioningContext;
20 | import org.eclipse.equinox.p2.metadata.expression.ExpressionUtil;
21 | import org.eclipse.equinox.p2.query.*;
22 | import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
23 | import org.eclipse.equinox.p2.repository.artifact.IArtifactRequest;
24 |
25 | public class DownloadManager {
26 | private ProvisioningContext provContext = null;
27 | ArrayList requestsToProcess = new ArrayList();
28 | private IProvisioningAgent agent = null;
29 |
30 | /**
31 | * This Comparator sorts the repositories such that local repositories are first.
32 | * TODO: This is copied from the ProvisioningContext class. Can we combine them?
33 | * See https://bugs.eclipse.org/335153.
34 | */
35 | private static final Comparator LOCAL_FIRST_COMPARATOR = new Comparator() {
36 | private static final String FILE_PROTOCOL = "file"; //$NON-NLS-1$
37 |
38 | public int compare(IArtifactRepository arg0, IArtifactRepository arg1) {
39 | String protocol0 = arg0.getLocation().getScheme();
40 | String protocol1 = arg1.getLocation().getScheme();
41 | if (FILE_PROTOCOL.equals(protocol0) && !FILE_PROTOCOL.equals(protocol1))
42 | return -1;
43 | if (!FILE_PROTOCOL.equals(protocol0) && FILE_PROTOCOL.equals(protocol1))
44 | return 1;
45 | return 0;
46 | }
47 | };
48 |
49 | public DownloadManager(ProvisioningContext context, IProvisioningAgent agent) {
50 | provContext = context;
51 | this.agent = agent;
52 | }
53 |
54 | /*
55 | * Add the given artifact to the download queue. When it
56 | * is downloaded, put it in the specified location.
57 | */
58 | public void add(IArtifactRequest toAdd) {
59 | Assert.isNotNull(toAdd);
60 | requestsToProcess.add(toAdd);
61 | }
62 |
63 | public void add(IArtifactRequest[] toAdd) {
64 | Assert.isNotNull(toAdd);
65 | for (int i = 0; i < toAdd.length; i++) {
66 | add(toAdd[i]);
67 | }
68 | }
69 |
70 | private void filterUnfetched() {
71 | for (Iterator iterator = requestsToProcess.iterator(); iterator.hasNext();) {
72 | IArtifactRequest request = iterator.next();
73 | if (request.getResult() != null && request.getResult().isOK()) {
74 | iterator.remove();
75 | }
76 | }
77 | }
78 |
79 | /*
80 | * Start the downloads. Return a status message indicating success or failure of the overall operation
81 | */
82 | public IStatus start(IProgressMonitor monitor) {
83 | SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.download_artifact, 1000);
84 | try {
85 | if (requestsToProcess.isEmpty())
86 | return Status.OK_STATUS;
87 |
88 | if (provContext == null)
89 | provContext = new ProvisioningContext(agent);
90 |
91 | IQueryable repoQueryable = provContext.getArtifactRepositories(subMonitor.newChild(250));
92 | IQuery all = new ExpressionMatchQuery(IArtifactRepository.class, ExpressionUtil.TRUE_EXPRESSION);
93 | IArtifactRepository[] repositories = repoQueryable.query(all, subMonitor.newChild(250)).toArray(IArtifactRepository.class);
94 | if (repositories.length == 0)
95 | return new Status(IStatus.ERROR, EngineActivator.ID, Messages.download_no_repository, new Exception(Collect.NO_ARTIFACT_REPOSITORIES_AVAILABLE));
96 | // Although we get a sorted list back from the ProvisioningContext above, it
97 | // gets unsorted when we convert the queryable into an array so we must re-sort it.
98 | // See https://bugs.eclipse.org/335153.
99 | Arrays.sort(repositories, LOCAL_FIRST_COMPARATOR);
100 | fetch(repositories, subMonitor.newChild(500));
101 | return overallStatus(monitor);
102 | } finally {
103 | subMonitor.done();
104 | }
105 | }
106 |
107 | private void fetch(IArtifactRepository[] repositories, IProgressMonitor mon) {
108 | SubMonitor monitor = SubMonitor.convert(mon, requestsToProcess.size());
109 | for (int i = 0; i < repositories.length && !requestsToProcess.isEmpty() && !monitor.isCanceled(); i++) {
110 | IArtifactRequest[] requests = getRequestsForRepository(repositories[i]);
111 | publishDownloadEvent(new CollectEvent(CollectEvent.TYPE_REPOSITORY_START, repositories[i], provContext, requests));
112 | IStatus dlStatus = repositories[i].getArtifacts(requests, monitor.newChild(requests.length));
113 | publishDownloadEvent(new CollectEvent(CollectEvent.TYPE_REPOSITORY_END, repositories[i], provContext, requests));
114 | if (dlStatus.getSeverity() == IStatus.CANCEL)
115 | return;
116 | filterUnfetched();
117 | monitor.setWorkRemaining(requestsToProcess.size());
118 | }
119 | }
120 |
121 | private void publishDownloadEvent(CollectEvent event) {
122 | IProvisioningEventBus bus = (IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME);
123 | if (bus != null)
124 | bus.publishEvent(event);
125 | }
126 |
127 | private IArtifactRequest[] getRequestsForRepository(IArtifactRepository repository) {
128 | ArrayList applicable = new ArrayList();
129 | for (IArtifactRequest request : requestsToProcess) {
130 | if (repository.contains(request.getArtifactKey()))
131 | applicable.add(request);
132 | }
133 | return applicable.toArray(new IArtifactRequest[applicable.size()]);
134 | }
135 |
136 | // private void notifyFetched() {
137 | // ProvisioningEventBus bus = (ProvisioningEventBus) ServiceHelper.getService(DownloadActivator.context, ProvisioningEventBus.class);
138 | // bus.publishEvent();
139 | // }
140 |
141 | private IStatus overallStatus(IProgressMonitor monitor) {
142 | if (monitor != null && monitor.isCanceled())
143 | return Status.CANCEL_STATUS;
144 |
145 | if (requestsToProcess.size() == 0)
146 | return Status.OK_STATUS;
147 |
148 | MultiStatus result = new MultiStatus(EngineActivator.ID, IStatus.OK, null, null);
149 | for (IArtifactRequest request : requestsToProcess) {
150 | IStatus failed = request.getResult();
151 | if (failed != null && !failed.isOK())
152 | result.add(failed);
153 | }
154 | return result;
155 | }
156 | }
157 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/PhaseSet.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2012 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import java.util.*;
14 | import org.eclipse.core.runtime.*;
15 | import org.eclipse.equinox.p2.engine.*;
16 | import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
17 | import org.eclipse.osgi.util.NLS;
18 |
19 | public class PhaseSet implements IPhaseSet {
20 |
21 | private final Phase[] phases;
22 | private boolean isRunning = false;
23 | private boolean isPaused = false;
24 |
25 | public PhaseSet(Phase[] phases) {
26 | if (phases == null)
27 | throw new IllegalArgumentException(Messages.null_phases);
28 |
29 | this.phases = phases;
30 | }
31 |
32 | public final MultiStatus perform(EngineSession session, Operand[] operands, IProgressMonitor monitor) {
33 | MultiStatus status = new MultiStatus(EngineActivator.ID, IStatus.OK, null, null);
34 | int[] weights = getProgressWeights(operands);
35 | int totalWork = getTotalWork(weights);
36 | SubMonitor pm = SubMonitor.convert(monitor, totalWork);
37 | try {
38 | isRunning = true;
39 | for (int i = 0; i < phases.length; i++) {
40 | if (pm.isCanceled()) {
41 | status.add(Status.CANCEL_STATUS);
42 | return status;
43 | }
44 | Phase phase = phases[i];
45 | phase.actionManager = (ActionManager) session.getAgent().getService(ActionManager.SERVICE_NAME);
46 | try {
47 | phase.perform(status, session, operands, pm.newChild(weights[i]));
48 | } catch (OperationCanceledException e) {
49 | // propagate operation cancellation
50 | status.add(new Status(IStatus.CANCEL, EngineActivator.ID, e.getMessage(), e));
51 | } catch (RuntimeException e) {
52 | // "perform" calls user code and might throw an unchecked exception
53 | // we catch the error here to gather information on where the problem occurred.
54 | status.add(new Status(IStatus.ERROR, EngineActivator.ID, e.getMessage(), e));
55 | } catch (LinkageError e) {
56 | // Catch linkage errors as these are generally recoverable but let other Errors propagate (see bug 222001)
57 | status.add(new Status(IStatus.ERROR, EngineActivator.ID, e.getMessage(), e));
58 | } finally {
59 | phase.actionManager = null;
60 | }
61 | if (status.matches(IStatus.CANCEL)) {
62 | MultiStatus result = new MultiStatus(EngineActivator.ID, IStatus.CANCEL, Messages.Engine_Operation_Canceled_By_User, null);
63 | result.merge(status);
64 | return result;
65 | } else if (status.matches(IStatus.ERROR)) {
66 | MultiStatus result = new MultiStatus(EngineActivator.ID, IStatus.ERROR, phase.getProblemMessage(), null);
67 | result.add(new Status(IStatus.ERROR, EngineActivator.ID, session.getContextString(), null));
68 | result.merge(status);
69 | return result;
70 | }
71 | }
72 | } finally {
73 | pm.done();
74 | isRunning = false;
75 | }
76 | return status;
77 | }
78 |
79 | public synchronized boolean pause() {
80 | if (isRunning && !isPaused) {
81 | isPaused = true;
82 | for (Phase phase : phases) {
83 | phase.setPaused(isPaused);
84 | }
85 | return true;
86 | }
87 | return false;
88 | }
89 |
90 | public synchronized boolean resume() {
91 | if (isRunning && isPaused) {
92 | isPaused = false;
93 | for (Phase phase : phases) {
94 | phase.setPaused(isPaused);
95 | }
96 | return true;
97 | }
98 | return false;
99 | }
100 |
101 | public final IStatus validate(ActionManager actionManager, IProfile profile, Operand[] operands, ProvisioningContext context, IProgressMonitor monitor) {
102 | Set missingActions = new HashSet();
103 | for (int i = 0; i < phases.length; i++) {
104 | Phase phase = phases[i];
105 | phase.actionManager = actionManager;
106 | try {
107 | for (int j = 0; j < operands.length; j++) {
108 | Operand operand = operands[j];
109 | try {
110 | if (!phase.isApplicable(operand))
111 | continue;
112 |
113 | List actions = phase.getActions(operand);
114 | if (actions == null)
115 | continue;
116 | for (int k = 0; k < actions.size(); k++) {
117 | ProvisioningAction action = actions.get(k);
118 | if (action instanceof MissingAction)
119 | missingActions.add((MissingAction) action);
120 | }
121 | } catch (RuntimeException e) {
122 | // "perform" calls user code and might throw an unchecked exception
123 | // we catch the error here to gather information on where the problem occurred.
124 | return new Status(IStatus.ERROR, EngineActivator.ID, e.getMessage() + " " + getContextString(profile, phase, operand), e); //$NON-NLS-1$
125 | } catch (LinkageError e) {
126 | // Catch linkage errors as these are generally recoverable but let other Errors propagate (see bug 222001)
127 | return new Status(IStatus.ERROR, EngineActivator.ID, e.getMessage() + " " + getContextString(profile, phase, operand), e); //$NON-NLS-1$
128 | }
129 | }
130 | } finally {
131 | phase.actionManager = null;
132 | }
133 | }
134 | if (!missingActions.isEmpty()) {
135 | MissingAction[] missingActionsArray = missingActions.toArray(new MissingAction[missingActions.size()]);
136 | MissingActionsException exception = new MissingActionsException(missingActionsArray);
137 | return (new Status(IStatus.ERROR, EngineActivator.ID, exception.getMessage(), exception));
138 | }
139 | return Status.OK_STATUS;
140 | }
141 |
142 | private String getContextString(IProfile profile, Phase phase, Operand operand) {
143 | return NLS.bind(Messages.session_context, new Object[] {profile.getProfileId(), phase.getClass().getName(), operand.toString(), ""}); //$NON-NLS-1$
144 | }
145 |
146 | private int getTotalWork(int[] weights) {
147 | int sum = 0;
148 | for (int i = 0; i < weights.length; i++)
149 | sum += weights[i];
150 | return sum;
151 | }
152 |
153 | private int[] getProgressWeights(Operand[] operands) {
154 | int[] weights = new int[phases.length];
155 | for (int i = 0; i < phases.length; i += 1) {
156 | if (operands.length > 0)
157 | //alter weights according to the number of operands applicable to that phase
158 | weights[i] = (phases[i].weight * countApplicable(phases[i], operands) / operands.length);
159 | else
160 | weights[i] = phases[i].weight;
161 | }
162 | return weights;
163 | }
164 |
165 | private int countApplicable(Phase phase, Operand[] operands) {
166 | int count = 0;
167 | for (int i = 0; i < operands.length; i++) {
168 | if (phase.isApplicable(operands[i]))
169 | count++;
170 | }
171 | return count;
172 | }
173 |
174 | public String[] getPhaseIds() {
175 | String[] ids = new String[phases.length];
176 | for (int i = 0; i < ids.length; i++) {
177 | ids[i] = phases[i].phaseId;
178 | }
179 | return ids;
180 | }
181 |
182 | public Phase[] getPhases() {
183 | return phases;
184 | }
185 | }
186 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/messages.properties:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Copyright (c) 2007, 2012 IBM Corporation and others.
3 | # All rights reserved. This program and the accompanying materials
4 | # are made available under the terms of the Eclipse Public License v1.0
5 | # which accompanies this distribution, and is available at
6 | # http://www.eclipse.org/legal/epl-v10.html
7 | #
8 | # Contributors:
9 | # IBM Corporation - initial API and implementation
10 | ###############################################################################
11 |
12 | ActionManager_Exception_Creating_Action_Extension=Error creating action with id: {0}.
13 | ActionManager_Required_Touchpoint_Not_Found=The required {0} touchpoint for the {1} action is not included in the installation manager configuration.
14 | action_syntax_error=Invalid action syntax: {0}.
15 | download_artifact=Downloading artifacts
16 | download_no_repository=No artifact repository available.
17 |
18 | error_parsing_profile=Error parsing profile {0}.
19 | error_persisting_profile=Error persisting profile {0}.
20 | io_FailedRead=Failed to read profile repository at {0}
21 | io_NotFound=No repository found at {0}
22 |
23 | TouchpointManager_Null_Touchpoint_Type_Argument=A null or empty string was passed as the type of a touchpoint.
24 | TouchpointManager_Incorrectly_Named_Extension=A touchpoint extension is incorrectly named {0} instead of {1}.
25 | TouchpointManager_Attribute_Not_Specified=The required attribute {0} is not specified for the touchpoints extension point.
26 | TouchpointManager_Conflicting_Touchpoint_Types=Two or more touchpoint extensions of type {0} are defined.
27 | TouchpointManager_Exception_Creating_Touchpoint_Extension=An exception was thrown and caught when creating the extension point instance for the {0} touchpoint.
28 | TouchpointManager_Null_Creating_Touchpoint_Extension=A null object was returned when creating the extension point instance for the {0} touchpoint.
29 |
30 | ParameterizedProvisioningAction_action_or_parameters_null=Both action and action parameters must not be null.
31 | Profile_Null_Profile_Id=A profile must have an non-empty id.
32 | Profile_Duplicate_Root_Profile_Id=Adding a profile with duplicate id: {0}.
33 | Profile_Parent_Not_Found=Parent profile not found: {0}.
34 |
35 | SimpleProfileRegistry_Parser_Error_Parsing_Registry=\
36 | Error parsing the profile registry.
37 | SimpleProfileRegistry_Parser_Has_Incompatible_Version=\
38 | The profile registry has incompatible version {0}; expected {1}.
39 | SimpleProfileRegistry_Profile_in_use=The profile is currently in use.
40 | SimpleProfileRegistry_Profile_not_locked=The profile is not locked.
41 | SimpleProfileRegistry_Profile_not_locked_due_to_exception=Profile not locked due to exception: {0}
42 | SimpleProfileRegistry_Bad_profile_location=Bad profile location: {0}
43 | SimpleProfileRegistry_CannotRemoveCurrentSnapshot=Cannot remove the current profile timestamp
44 | SimpleProfileRegistry_States_Error_Reading_File=Error reading profile state properties.
45 | SimpleProfileRegistry_States_Error_Writing_File=Error writing profile state properties.
46 | SimpleProfileRegistry_state_not_found=State {0} for profile {1} not found.
47 | profile_does_not_exist=Profile to be updated does not exist: {0}.
48 | profile_not_current=Profile {0} is not current. Expected timestamp {1} but was {2}.
49 | profile_changed=Profile {0} is marked as changed.
50 | profile_not_registered=Profile {0} not registered.
51 | reg_dir_not_available=Registry Directory not available: {0}.
52 | thread_not_owner=Thread not lock owner.
53 | profile_lock_not_reentrant=Lock failed. Profile does not permit reentrant locking.
54 | Shared_Profile=Shared profile
55 | shared_profile_not_found=Shared profile {0} not found.
56 |
57 | ProfilePreferences_saving=Saving profile preferences
58 | phase_error=An error occurred during the {0} phase.
59 | action_undo_error=An error occurred while rolling back the engine operation while undoing the {0} action.
60 | forced_action_execute_error=An error occurred while performing the engine operation while executing the {0} action in forced mode. The operation will continue.
61 | phaseid_not_positive=Phase weight must be positive.
62 | phaseid_not_set=Phase id must be set.
63 | action_not_found=No action found for: {0}.
64 | actions_not_found=No actions found for: {0}.
65 | not_current_phase=Current phase does not match argument.
66 | null_operands=Operands must not be null.
67 | null_phase=Phase must not be null.
68 | null_phases=Phases must not be null
69 | null_phaseset=PhaseSet must not be null.
70 | null_profile=Profile must not be null.
71 | touchpoint_prepare_error=An error occurred while preparing the engine operation for the {0} touchpoint.
72 | touchpoint_commit_error=An error occurred while committing the engine operation for the {0} touchpoint.
73 | touchpoint_rollback_error=An error occurred while rolling back the engine operation for the {0} touchpoint.
74 | phase_undo_error=An error occurred while undoing the {0} phase.
75 | phase_undo_operand_error=An error occurred while undoing the {0} phase for operand {1}.
76 | phase_not_started=There is no phase to end.
77 | phase_started=A phase is already started.
78 |
79 | session_prepare_error=An error occurred while preparing the engine session for profile: {0}.
80 | session_commit_error=An error occurred while committing the engine session for profile: {0}.
81 | null_operand=Operand must not be null.
82 | operand_started=An operand is already started.
83 | operand_not_started=There is no operand to end.
84 | not_current_operand=Current operand does not match argument.
85 | null_action=Action must not be null
86 | session_context=session context was:(profile={0}, phase={1}, operand={2}, action={3}).
87 | preparing=Preparing to commit the provisioning operation.
88 | committing=Committing the provisioning operation.
89 | rollingback_error=An error was detected while performing the engine operation and the changes are being rolled back. See the log for details.
90 | rollingback_cancel=The engine operation was cancelled and the changes are being rolled back.
91 |
92 | Engine_Operation_Canceled_By_User=Operation canceled by the user.
93 | InstallableUnitEvent_type_not_install_or_uninstall_or_configure=type must be either UNINSTALL(0) or INSTALL(1) or UNCONFIGURE(2) or CONFIGURE(3)
94 | CertificateChecker_CertificateError=An invalid certificate was found.
95 | CertificateChecker_CertificateRejected=One or more certificates rejected. Cannot proceed with installation.
96 | CertificateChecker_KeystoreConnectionError=Cannot connect to keystore.
97 | CertificateChecker_SignedContentError=Error with signed content.
98 | CertificateChecker_SignedContentIOError=Error reading signed content.
99 | CertificateChecker_UnsignedNotAllowed=Installing unsigned artifacts is not permitted: {0}
100 |
101 | Phase_Collect_Error=An error occurred while collecting items to be installed
102 | Phase_Configure_Error=An error occurred while configuring the installed items
103 | Phase_Configure_Task=Configuring {0}
104 | Phase_Install_Error=An error occurred while installing the items
105 | Phase_Install_Task=Installing {0}
106 | Phase_Sizing_Error=Error computing the size. Some of the items to be installed could not be found.
107 | Phase_Sizing_Warning=The size may not be accurate. Some of the items did not report a size.
108 | phase_thread_interrupted_error=Phase({0}) is interrupted.
109 | Phase_Unconfigure_Error=An error occurred while unconfiguring the items to uninstall
110 | Phase_Uninstall_Error=An error occurred while uninstalling
111 |
--------------------------------------------------------------------------------
/org.eclipse.equinox.p2.engine/src/main/java/org/eclipse/equinox/internal/p2/engine/TouchpointManager.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2007, 2010 IBM Corporation and others.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * IBM Corporation - initial API and implementation
10 | *******************************************************************************/
11 | package org.eclipse.equinox.internal.p2.engine;
12 |
13 | import java.util.HashMap;
14 | import java.util.Map;
15 | import org.eclipse.core.runtime.*;
16 | import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
17 | import org.eclipse.equinox.p2.engine.spi.Touchpoint;
18 | import org.eclipse.equinox.p2.metadata.*;
19 | import org.eclipse.osgi.util.NLS;
20 |
21 | //TODO This needs to support multiple version of each touchpoint and have a lookup that supports version semantics
22 | public class TouchpointManager implements IRegistryChangeListener {
23 |
24 | private static final String PT_TOUCHPOINTS = "touchpoints"; //$NON-NLS-1$
25 | private static final String ELEMENT_TOUCHPOINT = "touchpoint"; //$NON-NLS-1$
26 | private static final String ATTRIBUTE_CLASS = "class"; //$NON-NLS-1$
27 | private static final String ATTRIBUTE_TYPE = "type"; //$NON-NLS-1$
28 | private static final String ATTRIBUTE_VERSION = "version"; //$NON-NLS-1$
29 |
30 | private class TouchpointEntry {
31 |
32 | private IConfigurationElement element;
33 | private boolean createdExtension = false;
34 | private Touchpoint touchpoint = null;
35 |
36 | public TouchpointEntry(IConfigurationElement element) {
37 | this.element = element;
38 | }
39 |
40 | public Touchpoint getTouchpoint() {
41 | if (!createdExtension) {
42 | String id = getType();
43 | try {
44 | Touchpoint touchpointInstance = (Touchpoint) element.createExecutableExtension(ATTRIBUTE_CLASS);
45 | if (touchpointInstance != null) {
46 | this.touchpoint = touchpointInstance;
47 | } else {
48 | String errorMsg = NLS.bind(Messages.TouchpointManager_Null_Creating_Touchpoint_Extension, id);
49 | throw new CoreException(new Status(IStatus.ERROR, EngineActivator.ID, 1, errorMsg, null));
50 | }
51 | } catch (CoreException cexcpt) {
52 | LogHelper.log(new Status(IStatus.ERROR, EngineActivator.ID, NLS.bind(Messages.TouchpointManager_Exception_Creating_Touchpoint_Extension, id), cexcpt));
53 | } catch (ClassCastException ccexcpt) {
54 | LogHelper.log(new Status(IStatus.ERROR, EngineActivator.ID, NLS.bind(Messages.TouchpointManager_Exception_Creating_Touchpoint_Extension, id), ccexcpt));
55 | }
56 | // Mark as created even in error cases,
57 | // so exceptions are not logged multiple times
58 | createdExtension = true;
59 | }
60 | return this.touchpoint;
61 | }
62 |
63 | public Version getVersion() {
64 | try {
65 | return Version.create(element.getAttribute(ATTRIBUTE_VERSION));
66 | } catch (InvalidRegistryObjectException e) {
67 | return null;
68 | }
69 | }
70 |
71 | public String getType() {
72 | try {
73 | return element.getAttribute(ATTRIBUTE_TYPE);
74 | } catch (InvalidRegistryObjectException e) {
75 | return null;
76 | }
77 | }
78 |
79 | public String toString() {
80 | StringBuffer result = new StringBuffer(element.toString());
81 | if (createdExtension) {
82 | String touchpointString = touchpoint != null ? touchpoint.toString() : "not created"; //$NON-NLS-1$
83 | result.append(" => " + touchpointString); //$NON-NLS-1$
84 | }
85 | return result.toString();
86 | }
87 | }
88 |
89 | // TODO: Do we really want to store the touchpoints? The danger is
90 | // that if two installations are performed simultaneously, then...
91 | // TODO: Figure out locking, concurrency requirements for touchpoints.
92 | private Map touchpointEntries;
93 |
94 | public TouchpointManager() {
95 | RegistryFactory.getRegistry().addRegistryChangeListener(this, EngineActivator.ID);
96 | }
97 |
98 | /*
99 | * Return the touchpoint which is registered for the given type,
100 | * or null if none are registered.
101 | */
102 | public synchronized Touchpoint getTouchpoint(ITouchpointType type) {
103 | if (type == null)
104 | throw new IllegalArgumentException(Messages.TouchpointManager_Null_Touchpoint_Type_Argument);
105 | return getTouchpoint(type.getId(), type.getVersion().toString());
106 | }
107 |
108 | /*
109 | * Return the touchpoint which is registered for the given type and optionally version,
110 | * or null if none are registered.
111 | */
112 | public Touchpoint getTouchpoint(String typeId, String versionRange) {
113 | if (typeId == null || typeId.length() == 0)
114 | throw new IllegalArgumentException(Messages.TouchpointManager_Null_Touchpoint_Type_Argument);
115 |
116 | TouchpointEntry entry = getTouchpointEntries().get(typeId);
117 | if (entry == null)
118 | return null;
119 | if (versionRange != null) {
120 | VersionRange range = new VersionRange(versionRange);
121 | if (!range.isIncluded(entry.getVersion()))
122 | return null;
123 | }
124 |
125 | return entry.getTouchpoint();
126 | }
127 |
128 | /*
129 | * Construct a map of the extensions that implement the touchpoints extension point.
130 | */
131 | private synchronized Map getTouchpointEntries() {
132 | if (touchpointEntries != null)
133 | return touchpointEntries;
134 |
135 | IExtensionPoint point = RegistryFactory.getRegistry().getExtensionPoint(EngineActivator.ID, PT_TOUCHPOINTS);
136 | IExtension[] extensions = point.getExtensions();
137 | touchpointEntries = new HashMap(extensions.length);
138 | for (int i = 0; i < extensions.length; i++) {
139 | try {
140 | IConfigurationElement[] elements = extensions[i].getConfigurationElements();
141 | for (int j = 0; j < elements.length; j++) {
142 | String elementName = elements[j].getName();
143 | if (!ELEMENT_TOUCHPOINT.equalsIgnoreCase(elementName)) {
144 | reportError(NLS.bind(Messages.TouchpointManager_Incorrectly_Named_Extension, elements[j].getName(), ELEMENT_TOUCHPOINT));
145 | continue;
146 | }
147 | String id = elements[j].getAttribute(ATTRIBUTE_TYPE);
148 | if (id == null) {
149 | reportError(NLS.bind(Messages.TouchpointManager_Attribute_Not_Specified, ATTRIBUTE_TYPE));
150 | continue;
151 | }
152 | if (touchpointEntries.get(id) == null) {
153 | touchpointEntries.put(id, new TouchpointEntry(elements[j]));
154 | } else {
155 | reportError(NLS.bind(Messages.TouchpointManager_Conflicting_Touchpoint_Types, id));
156 | }
157 | }
158 | } catch (InvalidRegistryObjectException e) {
159 | //skip this extension
160 | }
161 | }
162 | return touchpointEntries;
163 | }
164 |
165 | static void reportError(String errorMsg) {
166 | Status errorStatus = new Status(IStatus.ERROR, EngineActivator.ID, 1, errorMsg, null);
167 | LogHelper.log(errorStatus);
168 | }
169 |
170 | /* (non-Javadoc)
171 | * @see org.eclipse.core.runtime.IRegistryChangeListener#registryChanged(org.eclipse.core.runtime.IRegistryChangeEvent)
172 | */
173 | public synchronized void registryChanged(IRegistryChangeEvent event) {
174 | // just flush the cache when something changed. It will be recomputed on demand.
175 | touchpointEntries = null;
176 | }
177 | }
178 |
--------------------------------------------------------------------------------