1 /******************************************************************************* 2 * Copyright (c) 2008, 2017 Code 9 and others. 3 * 4 * This 5 * program and the accompanying materials are made available under the terms of 6 * the Eclipse Public License 2.0 which accompanies this distribution, and is 7 * available at 8 * https://www.eclipse.org/legal/epl-2.0/ 9 * 10 * SPDX-License-Identifier: EPL-2.0 11 * 12 * Contributors: 13 * Code 9 - initial API and implementation 14 * IBM - ongoing development 15 ******************************************************************************/ 16 package org.eclipse.equinox.p2.publisher.eclipse; 17 18 import java.io.File; 19 import java.util.*; 20 import org.eclipse.core.runtime.*; 21 import org.eclipse.equinox.internal.p2.publisher.eclipse.ExecutablesDescriptor; 22 import org.eclipse.equinox.p2.metadata.IVersionedId; 23 import org.eclipse.equinox.p2.metadata.Version; 24 import org.eclipse.equinox.p2.publisher.*; 25 import org.eclipse.equinox.p2.publisher.actions.*; 26 27 public class EclipseInstallAction extends AbstractPublisherAction { 28 protected String source; 29 protected String id; 30 protected Version version; 31 protected String name; 32 protected String executableName; 33 protected String flavor; 34 protected IVersionedId[] topLevel; 35 protected String[] nonRootFiles; 36 protected boolean start = false; 37 EclipseInstallAction()38 protected EclipseInstallAction() { 39 //hidden 40 } 41 EclipseInstallAction(String source, String id, Version version, String name, String executableName, String flavor, IVersionedId[] topLevel, String[] nonRootFiles, boolean start)42 public EclipseInstallAction(String source, String id, Version version, String name, String executableName, String flavor, IVersionedId[] topLevel, String[] nonRootFiles, boolean start) { 43 this.source = source; 44 this.id = id; 45 this.version = version; 46 this.name = name == null ? id : name; 47 this.executableName = executableName == null ? "eclipse" : executableName; //$NON-NLS-1$ 48 this.flavor = flavor; 49 this.topLevel = topLevel; 50 this.nonRootFiles = nonRootFiles; 51 this.start = start; 52 } 53 54 @Override perform(IPublisherInfo publisherInfo, IPublisherResult results, IProgressMonitor monitor)55 public IStatus perform(IPublisherInfo publisherInfo, IPublisherResult results, IProgressMonitor monitor) { 56 monitor = SubMonitor.convert(monitor); 57 this.info = publisherInfo; 58 IPublisherAction[] actions = createActions(); 59 MultiStatus finalStatus = new MultiStatus(EclipseInstallAction.class.getName(), 0, "publishing result", null); //$NON-NLS-1$ 60 for (IPublisherAction action : actions) { 61 if (monitor.isCanceled()) 62 return Status.CANCEL_STATUS; 63 finalStatus.merge(action.perform(publisherInfo, results, monitor)); 64 } 65 if (!finalStatus.isOK()) 66 return finalStatus; 67 return Status.OK_STATUS; 68 } 69 createActions()70 protected IPublisherAction[] createActions() { 71 createAdvice(); 72 ArrayList<IPublisherAction> actions = new ArrayList<>(); 73 // create an action that just publishes the raw bundles and features 74 IPublisherAction action = new MergeResultsAction(new IPublisherAction[] {createFeaturesAction(), createBundlesAction()}, IPublisherResult.MERGE_ALL_ROOT); 75 actions.add(action); 76 actions.add(createApplicationExecutableAction(info.getConfigurations())); 77 actions.add(createRootFilesAction()); 78 actions.addAll(createAccumulateConfigDataActions(info.getConfigurations())); 79 actions.add(createJREAction()); 80 actions.add(createConfigCUsAction()); 81 actions.add(createDefaultCUsAction()); 82 actions.add(createRootIUAction()); 83 return actions.toArray(new IPublisherAction[actions.size()]); 84 } 85 createAdvice()86 private void createAdvice() { 87 createRootFilesAdvice(); 88 createRootAdvice(); 89 } 90 createRootAdvice()91 protected void createRootAdvice() { 92 if (topLevel != null) 93 info.addAdvice(new RootIUAdvice(getTopLevel())); 94 info.addAdvice(new RootIUResultFilterAdvice(null)); 95 } 96 createDefaultCUsAction()97 protected IPublisherAction createDefaultCUsAction() { 98 return new DefaultCUsAction(info, flavor, 4, start); 99 } 100 createRootIUAction()101 protected IPublisherAction createRootIUAction() { 102 return new RootIUAction(id, version, name); 103 } 104 getTopLevel()105 protected Collection<IVersionedId> getTopLevel() { 106 return Arrays.asList(topLevel); 107 } 108 createJREAction()109 protected IPublisherAction createJREAction() { 110 return new JREAction((File) null); 111 } 112 createApplicationExecutableAction(String[] configSpecs)113 protected IPublisherAction createApplicationExecutableAction(String[] configSpecs) { 114 return new ApplicationLauncherAction(id, version, flavor, executableName, getExecutablesLocation(), configSpecs); 115 } 116 createAccumulateConfigDataActions(String[] configs)117 protected Collection<IPublisherAction> createAccumulateConfigDataActions(String[] configs) { 118 File configuration = new File(source, "configuration/config.ini"); //$NON-NLS-1$ 119 if (!configuration.exists()) 120 configuration = null; 121 122 Collection<IPublisherAction> result = new ArrayList<>(configs.length); 123 for (String configSpec : configs) { 124 String os = AbstractPublisherAction.parseConfigSpec(configSpec)[1]; 125 File executable = ExecutablesDescriptor.findExecutable(os, computeExecutableLocation(configSpec), "eclipse"); //$NON-NLS-1$ 126 if (!executable.exists()) 127 executable = null; 128 IPublisherAction action = new AccumulateConfigDataAction(info, configSpec, configuration, executable); 129 result.add(action); 130 } 131 132 return result; 133 } 134 createConfigCUsAction()135 protected IPublisherAction createConfigCUsAction() { 136 return new ConfigCUsAction(info, flavor, id, version); 137 } 138 createFeaturesAction()139 protected IPublisherAction createFeaturesAction() { 140 return new FeaturesAction(new File[] {new File(source, "features")}); //$NON-NLS-1$ 141 } 142 createExecutablesActions(String[] configSpecs)143 protected Collection<IPublisherAction> createExecutablesActions(String[] configSpecs) { 144 Collection<IPublisherAction> result = new ArrayList<>(configSpecs.length); 145 for (String configSpec : configSpecs) { 146 ExecutablesDescriptor executables = computeExecutables(configSpec); 147 IPublisherAction action = new EquinoxExecutableAction(executables, configSpec, id, version, flavor); 148 result.add(action); 149 } 150 return result; 151 } 152 createRootFilesAction()153 protected IPublisherAction createRootFilesAction() { 154 return new RootFilesAction(info, id, version, flavor); 155 } 156 createRootFilesAdvice()157 protected void createRootFilesAdvice() { 158 File[] baseExclusions = computeRootFileExclusions(); 159 if (baseExclusions != null) 160 info.addAdvice(new RootFilesAdvice(null, null, baseExclusions, null)); 161 String[] configs = info.getConfigurations(); 162 for (String config : configs) { 163 info.addAdvice(computeRootFileAdvice(config)); 164 } 165 } 166 computeRootFileAdvice(String configSpec)167 protected IPublisherAdvice computeRootFileAdvice(String configSpec) { 168 File root = computeRootFileRoot(configSpec); 169 File[] inclusions = computeRootFileInclusions(configSpec); 170 File[] exclusions = computeRootFileExclusions(configSpec); 171 return new RootFilesAdvice(root, inclusions, exclusions, configSpec); 172 } 173 computeRootFileExclusions(String configSpec)174 protected File[] computeRootFileExclusions(String configSpec) { 175 ExecutablesDescriptor executables = computeExecutables(configSpec); 176 File[] files = executables.getFiles(); 177 File[] result = new File[files.length + 1]; 178 System.arraycopy(files, 0, result, 0, files.length); 179 result[files.length] = executables.getIniLocation(); 180 return result; 181 } 182 computeRootFileExclusions()183 protected File[] computeRootFileExclusions() { 184 if (nonRootFiles == null || nonRootFiles.length == 0) 185 return null; 186 ArrayList<File> result = new ArrayList<>(); 187 for (String filename : nonRootFiles) { 188 File file = new File(filename); 189 if (file.isAbsolute()) 190 result.add(file); 191 else 192 result.add(new File(source, filename)); 193 } 194 return result.toArray(new File[result.size()]); 195 } 196 computeExecutables(String configSpec)197 protected ExecutablesDescriptor computeExecutables(String configSpec) { 198 String os = AbstractPublisherAction.parseConfigSpec(configSpec)[1]; 199 // TODO here we should not assume that the executable is called "eclipse" 200 return ExecutablesDescriptor.createDescriptor(os, "eclipse", computeExecutableLocation(configSpec)); //$NON-NLS-1$ 201 } 202 computeRootFileRoot(String configSpec)203 protected File computeRootFileRoot(String configSpec) { 204 return new File(source); 205 } 206 computeRootFileInclusions(String configSpec)207 protected File[] computeRootFileInclusions(String configSpec) { 208 return new File[] {new File(source)}; 209 } 210 computeExecutableLocation(String configSpec)211 protected File computeExecutableLocation(String configSpec) { 212 return new File(source); 213 } 214 getExecutablesLocation()215 protected File getExecutablesLocation() { 216 return new File(source); 217 } 218 createBundlesAction()219 protected IPublisherAction createBundlesAction() { 220 // TODO need to add in the simple configorator and reconciler bundle descriptions. 221 // TODO bundles action needs to take bundleDescriptions directly rather than just files. 222 return new BundlesAction(new File[] {new File(source, "plugins")}); //$NON-NLS-1$ 223 } 224 } 225