diff options
| author | Ed Merks | 2016-08-18 11:58:18 +0000 |
|---|---|---|
| committer | Ed Merks | 2016-08-18 11:58:58 +0000 |
| commit | 6b8afcf45a14c07ec831774ba668ff1bf3cd7e73 (patch) | |
| tree | e00d074b9d537b20bb606566e8016ea0a84f9a0b | |
| parent | b269b2a1b6179c9569cd52554e43dfc7d4c0c715 (diff) | |
| download | org.eclipse.oomph-6b8afcf45a14c07ec831774ba668ff1bf3cd7e73.tar.gz org.eclipse.oomph-6b8afcf45a14c07ec831774ba668ff1bf3cd7e73.tar.xz org.eclipse.oomph-6b8afcf45a14c07ec831774ba668ff1bf3cd7e73.zip | |
[463967] Oomph should not use cGit resources
https://bugs.eclipse.org/bugs/show_bug.cgi?id=463967
22 files changed, 308 insertions, 166 deletions
diff --git a/plugins/org.eclipse.oomph.p2.core/src/org/eclipse/oomph/p2/internal/core/CachingRepositoryManager.java b/plugins/org.eclipse.oomph.p2.core/src/org/eclipse/oomph/p2/internal/core/CachingRepositoryManager.java index ce21d20a8..a05721c37 100644 --- a/plugins/org.eclipse.oomph.p2.core/src/org/eclipse/oomph/p2/internal/core/CachingRepositoryManager.java +++ b/plugins/org.eclipse.oomph.p2.core/src/org/eclipse/oomph/p2/internal/core/CachingRepositoryManager.java @@ -39,6 +39,7 @@ import org.eclipse.equinox.internal.p2.repository.helpers.LocationProperties; import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus; import org.eclipse.equinox.internal.provisional.p2.core.eventbus.SynchronousProvisioningListener; import org.eclipse.equinox.internal.provisional.p2.repository.RepositoryEvent; +import org.eclipse.equinox.p2.core.IAgentLocation; import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.equinox.p2.metadata.IArtifactKey; @@ -116,6 +117,20 @@ public class CachingRepositoryManager<T> public CachingRepositoryManager(AbstractRepositoryManager<T> delegate, int repositoryType, CachingTransport transport) { this.delegate = delegate; + + IAgentLocation agentLocation = ReflectUtil.getValue("agentLocation", delegate); + if (agentLocation != null) + { + URI rootLocation = agentLocation.getRootLocation(); + if (rootLocation != null) + { + if (!LazyProfileRegistryComponent.OsgiHelper.canWrite(new File(rootLocation.getPath()))) + { + ReflectUtil.setValue("agentLocation", delegate, null); + } + } + } + this.repositoryType = repositoryType; if (transport == null) diff --git a/plugins/org.eclipse.oomph.p2.core/src/org/eclipse/oomph/p2/internal/core/LazyProfileRegistry.java b/plugins/org.eclipse.oomph.p2.core/src/org/eclipse/oomph/p2/internal/core/LazyProfileRegistry.java index eed773732..9c226ea66 100644 --- a/plugins/org.eclipse.oomph.p2.core/src/org/eclipse/oomph/p2/internal/core/LazyProfileRegistry.java +++ b/plugins/org.eclipse.oomph.p2.core/src/org/eclipse/oomph/p2/internal/core/LazyProfileRegistry.java @@ -70,6 +70,8 @@ public class LazyProfileRegistry extends SimpleProfileRegistry private final String self; + private final boolean canWrite; + private boolean updateSelfProfile; private final Map<String, ProfileLock> profileLocks; @@ -83,6 +85,8 @@ public class LazyProfileRegistry extends SimpleProfileRegistry this.provisioningAgent = provisioningAgent; this.store = store; + canWrite = LazyProfileRegistryComponent.OsgiHelper.canWrite(store); + Field selfField = ReflectUtil.getField(SimpleProfileRegistry.class, "self"); self = (String)ReflectUtil.getValue(selfField, this); @@ -259,14 +263,14 @@ public class LazyProfileRegistry extends SimpleProfileRegistry Object parser = ReflectUtil.newInstance(parserConstructor, this, EngineActivator.getContext(), EngineActivator.ID); ProfileLock lock = profileLocks.get(profileId); - if (lock == null) + if (lock == null && canWrite) { lock = new ProfileLock(this, profileDirectory); profileLocks.put(profileId, lock); } boolean locked = false; - if (lock.processHoldsLock() || (locked = lock.lock())) + if (lock == null || lock.processHoldsLock() || (locked = lock.lock())) { try { diff --git a/plugins/org.eclipse.oomph.setup.core/plugin.xml b/plugins/org.eclipse.oomph.setup.core/plugin.xml index e0adbbadb..bfff1c90d 100644 --- a/plugins/org.eclipse.oomph.setup.core/plugin.xml +++ b/plugins/org.eclipse.oomph.setup.core/plugin.xml @@ -15,4 +15,17 @@ <extension-point id="stringFilters" name="String Filters" schema="schema/stringFilters.exsd"/> + <extension + id="SetupArchiver" + point="org.eclipse.core.runtime.applications"> + <application + cardinality="singleton-global" + thread="main" + visible="true"> + <run + class="org.eclipse.oomph.setup.internal.core.SetupArchiver"> + </run> + </application> + </extension> + </plugin> diff --git a/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/SetupArchiver.java b/plugins/org.eclipse.oomph.setup.core/src/org/eclipse/oomph/setup/internal/core/SetupArchiver.java index 1cd78d752..a14b981fd 100644 --- a/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/SetupArchiver.java +++ b/plugins/org.eclipse.oomph.setup.core/src/org/eclipse/oomph/setup/internal/core/SetupArchiver.java @@ -8,15 +8,13 @@ * Contributors: * Ed Merks - initial API and implementation */ -package org.eclipse.oomph.setup.internal.installer; +package org.eclipse.oomph.setup.internal.core; import org.eclipse.oomph.base.util.EAnnotations; -import org.eclipse.oomph.setup.internal.core.SetupContext; import org.eclipse.oomph.setup.internal.core.util.ECFURIHandlerImpl; import org.eclipse.oomph.setup.internal.core.util.ECFURIHandlerImpl.CacheHandling; import org.eclipse.oomph.setup.internal.core.util.ResourceMirror; import org.eclipse.oomph.setup.internal.core.util.SetupCoreUtil; -import org.eclipse.oomph.setup.ui.wizards.SetupWizard; import org.eclipse.oomph.util.IORuntimeException; import org.eclipse.oomph.util.IOUtil; import org.eclipse.oomph.util.OS; @@ -38,6 +36,7 @@ import java.io.InputStream; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; import java.util.zip.ZipEntry; @@ -52,14 +51,36 @@ public class SetupArchiver implements IApplication { String[] arguments = (String[])context.getArguments().get(IApplicationContext.APPLICATION_ARGS); - File file = new File(System.getProperty("java.io.tmpdir"), "setups.zip"); + // The default target file is the cache location of the local setup archive. + final ResourceSet resourceSet = SetupCoreUtil.createResourceSet(); + final URIConverter uriConverter = resourceSet.getURIConverter(); + URI archiveLocation = uriConverter.normalize(SetupContext.INDEX_SETUP_ARCHIVE_LOCATION_URI); + File file = new File(ECFURIHandlerImpl.getCacheFile(archiveLocation).toFileString()); + Set<URI> uris = new LinkedHashSet<URI>(); + uris.add(SetupContext.INDEX_SETUP_URI); + + boolean expectURIs = false; for (int i = 0; i < arguments.length; ++i) { - if ("-target".equals(arguments[i])) + String argument = arguments[i]; + if (argument.startsWith("-")) + { + expectURIs = false; + } + + if (expectURIs) + { + uris.add(URI.createURI(argument)); + } + else if ("-target".equals(argument)) { file = new File(arguments[++i]); } + else if ("-uris".equals(argument)) + { + expectURIs = true; + } } String url = file.getAbsolutePath(); @@ -112,19 +133,6 @@ public class SetupArchiver implements IApplication URI archiveEntry = URI.createURI("archive:" + URI.createFileURI(file.toString()) + "!/" + path); System.out.println("Previously mirrored " + uri + " -> " + archiveEntry); - - // if (path.toString().contains("SmartHome")) - // { - // ByteArrayOutputStream out = new ByteArrayOutputStream(); - // - // ResourceSet resourceSet = SetupCoreUtil.createResourceSet(); - // Resource resource = resourceSet.getResource(archiveEntry, true); - // resource.save(out, null); - // - // System.out.println(); - // System.out.println(new String(out.toByteArray())); - // System.out.println(); - // } } } catch (IOException ex) @@ -153,10 +161,9 @@ public class SetupArchiver implements IApplication } } - final ResourceSet resourceSet = SetupCoreUtil.createResourceSet(); resourceSet.getLoadOptions().put(ECFURIHandlerImpl.OPTION_CACHE_HANDLING, CacheHandling.CACHE_IGNORE); - ResourceMirror resourceMirror = new SetupWizard.IndexLoader.ResourceMirrorWithProductImages(resourceSet) + ResourceMirror resourceMirror = new ResourceMirror.WithProductImages(resourceSet) { @Override protected void visit(EObject eObject) @@ -178,13 +185,12 @@ public class SetupArchiver implements IApplication } }; - resourceMirror.perform(SetupContext.INDEX_SETUP_URI); + resourceMirror.perform(uris); resourceMirror.dispose(); EcoreUtil.resolveAll(resourceSet); ECFURIHandlerImpl.clearExpectedETags(); - final URIConverter uriConverter = resourceSet.getURIConverter(); Map<URI, URI> uriMap = uriConverter.getURIMap(); Map<Object, Object> options = new HashMap<Object, Object>(); if (lastModified != 0) diff --git a/plugins/org.eclipse.oomph.setup.core/src/org/eclipse/oomph/setup/internal/core/SetupContext.java b/plugins/org.eclipse.oomph.setup.core/src/org/eclipse/oomph/setup/internal/core/SetupContext.java index 7fcae31dc..8f2f9f748 100644 --- a/plugins/org.eclipse.oomph.setup.core/src/org/eclipse/oomph/setup/internal/core/SetupContext.java +++ b/plugins/org.eclipse.oomph.setup.core/src/org/eclipse/oomph/setup/internal/core/SetupContext.java @@ -374,7 +374,12 @@ public class SetupContext } } - private static void associate(ResourceSet resourceSet, Installation installation, Workspace workspace) + public static LocationCatalog getLocationCatalog(ResourceSet resourceSet) + { + return associate(resourceSet, null, null); + } + + private static LocationCatalog associate(ResourceSet resourceSet, Installation installation, Workspace workspace) { URIConverter uriConverter = resourceSet.getURIConverter(); @@ -463,6 +468,8 @@ public class SetupContext { SetupCorePlugin.INSTANCE.log(ex); } + + return locationCatalog; } private static <K extends EObject, V extends EObject> void removeProxies(EMap<K, EList<V>> map) diff --git a/plugins/org.eclipse.oomph.setup.core/src/org/eclipse/oomph/setup/internal/core/util/ECFURIHandlerImpl.java b/plugins/org.eclipse.oomph.setup.core/src/org/eclipse/oomph/setup/internal/core/util/ECFURIHandlerImpl.java index 3031cbb93..df1b34220 100644 --- a/plugins/org.eclipse.oomph.setup.core/src/org/eclipse/oomph/setup/internal/core/util/ECFURIHandlerImpl.java +++ b/plugins/org.eclipse.oomph.setup.core/src/org/eclipse/oomph/setup/internal/core/util/ECFURIHandlerImpl.java @@ -16,10 +16,13 @@ import org.eclipse.oomph.preferences.util.PreferencesUtil; import org.eclipse.oomph.setup.internal.core.SetupContext; import org.eclipse.oomph.setup.internal.core.SetupCorePlugin; import org.eclipse.oomph.setup.internal.core.util.ECFURIHandlerImpl.AuthorizationHandler.Authorization; +import org.eclipse.oomph.setup.util.SetupUtil; import org.eclipse.oomph.util.IOExceptionWithCause; import org.eclipse.oomph.util.IORuntimeException; import org.eclipse.oomph.util.IOUtil; +import org.eclipse.oomph.util.OS; import org.eclipse.oomph.util.PropertiesUtil; +import org.eclipse.oomph.util.StringUtil; import org.eclipse.oomph.util.WorkerPool; import org.eclipse.emf.common.util.URI; @@ -61,6 +64,8 @@ import org.eclipse.equinox.p2.core.UIServices.AuthenticationInfo; import org.eclipse.equinox.security.storage.ISecurePreferences; import org.eclipse.equinox.security.storage.StorageException; +import org.osgi.framework.Version; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -97,15 +102,43 @@ public class ECFURIHandlerImpl extends URIHandlerImpl private static final boolean TEST_SLOW_NETWORK = false; - private static final boolean TRACE = PropertiesUtil.isProperty(SetupProperties.PROJP_SETUP_ECF_TRACE); + private static final boolean TRACE = PropertiesUtil.isProperty(SetupProperties.PROP_SETUP_ECF_TRACE); private static final String API_GITHUB_HOST = "api.github.com"; private static final String CONTENT_TAG = "\"content\":\""; - private static int CONNECT_TIMEOUT = PropertiesUtil.getProperty(SetupProperties.PROJP_SETUP_ECF_CONNECT_TIMEOUT, 10000); + private static final int CONNECT_TIMEOUT = PropertiesUtil.getProperty(SetupProperties.PROP_SETUP_ECF_CONNECT_TIMEOUT, 10000); + + private static final int READ_TIMEOUT = PropertiesUtil.getProperty(SetupProperties.PROP_SETUP_ECF_READ_TIMEOUT, 10000); + + private static boolean loggedBlockedURI; - private static int READ_TIMEOUT = PropertiesUtil.getProperty(SetupProperties.PROJP_SETUP_ECF_READ_TIMEOUT, 10000); + private static final String USER_AGENT; + static + { + String userAgentProperty = PropertiesUtil.getProperty(SetupProperties.PROP_SETUP_USER_AGENT); + if (userAgentProperty == null) + { + StringBuilder userAgent = new StringBuilder("eclipse/oomph/"); + if (SetupUtil.INSTALLER_PRODUCT) + { + userAgent.append("installer/"); + } + else if (SetupUtil.SETUP_ARCHIVER_APPLICATION) + { + userAgent.append("installer/"); + } + + Version oomphVersion = SetupCorePlugin.INSTANCE.getBundle().getVersion(); + userAgent.append(oomphVersion); + USER_AGENT = userAgent.toString(); + } + else + { + USER_AGENT = userAgentProperty; + } + } private AuthorizationHandler defaultAuthorizationHandler; @@ -169,6 +202,12 @@ public class ECFURIHandlerImpl extends URIHandlerImpl } } + String host = getHost(uri); + if ("git.eclipse.org".equals(host)) + { + return Collections.emptyMap(); + } + String username; String password; @@ -481,6 +520,15 @@ public class ECFURIHandlerImpl extends URIHandlerImpl System.out.println(tracePrefix + " expectedETag=" + expectedETag); } + // To prevent Eclipse's Git server from being overload, because it can't scale to thousands of users, we block all access. + String host = getHost(uri); + boolean isBlockedEclipseGitURI = !SetupUtil.SETUP_ARCHIVER_APPLICATION && "git.eclipse.org".equals(host); + if (isBlockedEclipseGitURI && uriConverter.exists(cacheURI, options)) + { + // If the file is in the cache, it's okay to use that cached version, so try that first. + cacheHandling = CacheHandling.CACHE_ONLY; + } + if (expectedETag != null || cacheHandling == CacheHandling.CACHE_ONLY || cacheHandling == CacheHandling.CACHE_WITHOUT_ETAG_CHECKING) { if (cacheHandling == CacheHandling.CACHE_ONLY || cacheHandling == CacheHandling.CACHE_WITHOUT_ETAG_CHECKING ? eTag != null : expectedETag.equals(eTag)) @@ -499,8 +547,7 @@ public class ECFURIHandlerImpl extends URIHandlerImpl catch (IOException ex) { // Perhaps another JVM is busy writing this file. - // Proceed as if it doesn't exit. - + // Proceed as if it doesn't exist. if (TRACE) { System.out.println(tracePrefix + " unable to load cached content"); @@ -509,6 +556,35 @@ public class ECFURIHandlerImpl extends URIHandlerImpl } } + // In general all Eclipse-hosted setups should be in the Eclipse project or product catalog and therefore should be in + // SetupContext.INDEX_SETUP_ARCHIVE_LOCATION_URI or should already be in the cache from running the setup archiver application. + if (isBlockedEclipseGitURI) + { + synchronized (this) + { + if (!loggedBlockedURI) + { + String launcher = OS.getCurrentLauncher(true); + if (launcher == null) + { + launcher = "eclipse"; + } + + // We'll log a single warning for this case. + SetupCorePlugin.INSTANCE.log( + "The Eclipse Git-hosted URI '" + uri + "' is blocked for direct access." + StringUtil.NL + // + "Please open a Bugzilla to add it to an official Oomph catalog." + StringUtil.NL + // + "For initial testing, use the file system local version of the resource." + StringUtil.NL + // + "Alternatively, run the setup archiver application as follows:" + StringUtil.NL + // + " " + launcher + " -application org.eclipse.oomph.setup.core.SetupArchiver -consoleLog -noSplash -uris " + uri, // + IStatus.WARNING); + loggedBlockedURI = true; + } + } + + throw new IOException("Eclipse Git access blocked: " + uri); + } + String username; String password; @@ -578,6 +654,13 @@ public class ECFURIHandlerImpl extends URIHandlerImpl requestOptions.put(IRetrieveFileTransferOptions.REQUEST_HEADERS, Collections.singletonMap("Authorization", authorization.getAuthorization())); } + if (!StringUtil.isEmpty(USER_AGENT) && host != null && host.endsWith(".eclipse.org")) + { + Map<String, String> requestHeaders = new HashMap<String, String>(); + requestOptions.put(IRetrieveFileTransferOptions.REQUEST_HEADERS, requestHeaders); + requestHeaders.put("User-Agent", USER_AGENT); + } + fileTransfer.sendRetrieveRequest(fileTransferID, transferListener, requestOptions); } catch (IncomingFileTransferException ex) @@ -659,7 +742,8 @@ public class ECFURIHandlerImpl extends URIHandlerImpl if (!CacheHandling.CACHE_IGNORE.equals(cacheHandling) && uriConverter.exists(cacheURI, options) && (!(transferListener.exception instanceof IncomingFileTransferException) - || ((IncomingFileTransferException)transferListener.exception).getErrorCode() != HttpURLConnection.HTTP_NOT_FOUND)) + || ((IncomingFileTransferException)transferListener.exception).getErrorCode() != HttpURLConnection.HTTP_NOT_FOUND) + || uri.equals(SetupContext.INDEX_SETUP_ARCHIVE_LOCATION_URI)) { setExpectedETag(uri, transferListener.eTag == null ? eTag : transferListener.eTag); if (TRACE) diff --git a/plugins/org.eclipse.oomph.setup.core/src/org/eclipse/oomph/setup/internal/core/util/ResourceMirror.java b/plugins/org.eclipse.oomph.setup.core/src/org/eclipse/oomph/setup/internal/core/util/ResourceMirror.java index fad2fa375..a7e819bc1 100644 --- a/plugins/org.eclipse.oomph.setup.core/src/org/eclipse/oomph/setup/internal/core/util/ResourceMirror.java +++ b/plugins/org.eclipse.oomph.setup.core/src/org/eclipse/oomph/setup/internal/core/util/ResourceMirror.java @@ -10,6 +10,8 @@ */ package org.eclipse.oomph.setup.internal.core.util; +import org.eclipse.oomph.base.util.BytesResourceFactoryImpl; +import org.eclipse.oomph.setup.Scope; import org.eclipse.oomph.util.IOExceptionWithCause; import org.eclipse.oomph.util.WorkerPool; @@ -299,4 +301,41 @@ public abstract class ResourceMirror extends WorkerPool<ResourceMirror, URI, Res } } } + + /** + * @author Ed Merks + */ + public static class WithProductImages extends ResourceMirror + { + public WithProductImages(ResourceSet resourceSet) + { + super(resourceSet); + + BytesResourceFactoryImpl bytesResourceFactory = new BytesResourceFactoryImpl(); + Map<String, Object> extensionToFactoryMap = resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap(); + extensionToFactoryMap.put("gif", bytesResourceFactory); + extensionToFactoryMap.put("png", bytesResourceFactory); + extensionToFactoryMap.put("jpeg", bytesResourceFactory); + extensionToFactoryMap.put("jpg", bytesResourceFactory); + } + + @Override + protected void visit(EObject eObject) + { + if (eObject instanceof Scope) + { + Scope scope = (Scope)eObject; + URI uri = SetupCoreUtil.getBrandingImageURI(scope); + if (uri != null) + { + if (getResourceSet().getResourceFactoryRegistry().getExtensionToFactoryMap().containsKey(uri.fileExtension())) + { + schedule(uri, true); + } + } + } + + super.visit(eObject); + } + } } diff --git a/plugins/org.eclipse.oomph.setup.core/src/org/eclipse/oomph/setup/internal/core/util/SetupCoreUtil.java b/plugins/org.eclipse.oomph.setup.core/src/org/eclipse/oomph/setup/internal/core/util/SetupCoreUtil.java index 482004f6f..4f409fd16 100644 --- a/plugins/org.eclipse.oomph.setup.core/src/org/eclipse/oomph/setup/internal/core/util/SetupCoreUtil.java +++ b/plugins/org.eclipse.oomph.setup.core/src/org/eclipse/oomph/setup/internal/core/util/SetupCoreUtil.java @@ -26,6 +26,7 @@ import org.eclipse.oomph.setup.internal.core.SetupContext; import org.eclipse.oomph.setup.internal.core.SetupCorePlugin; import org.eclipse.oomph.setup.internal.core.util.ECFURIHandlerImpl.AuthorizationHandler; import org.eclipse.oomph.setup.internal.core.util.ECFURIHandlerImpl.AuthorizationHandlerImpl; +import org.eclipse.oomph.setup.util.SetupUtil; import org.eclipse.oomph.util.IOUtil; import org.eclipse.oomph.util.OS; import org.eclipse.oomph.util.PropertiesUtil; @@ -369,8 +370,7 @@ public final class SetupCoreUtil } } - if (SetupContext.INDEX_SETUP_ARCHIVE_LOCATION_URI != null && !PropertiesUtil.isProperty(SetupProperties.PROP_REDIRECTION_BASE + "mirror.nothing") - && SetupContext.INDEX_SETUP_LOCATION_URI.equals(uriConverter.normalize(SetupContext.INDEX_SETUP_LOCATION_URI))) + if (!SetupUtil.SETUP_ARCHIVER_APPLICATION) { handleArchiveRedirection(uriConverter); } @@ -378,7 +378,8 @@ public final class SetupCoreUtil private static void handleArchiveRedirection(URIConverter uriConverter) { - if (archiveExpectedETag == null || !archiveExpectedETag.equals(ECFURIHandlerImpl.getExpectedETag(SetupContext.INDEX_SETUP_ARCHIVE_LOCATION_URI))) + if (archiveExpectedETag == null + || !archiveExpectedETag.equals(ECFURIHandlerImpl.getExpectedETag(uriConverter.normalize(SetupContext.INDEX_SETUP_ARCHIVE_LOCATION_URI)))) { // long start = System.currentTimeMillis(); @@ -1076,4 +1077,38 @@ public final class SetupCoreUtil return result; } } + + public static URI getEclipseBrandingImage() + { + return URI.createPlatformPluginURI("org.eclipse.oomph.setup.ui/icons/committers.png", true); + } + + public static URI getBrandingImageURI(Scope scope) + { + URI imageURI = null; + + if (scope != null) + { + Annotation annotation = scope.getAnnotation(AnnotationConstants.ANNOTATION_BRANDING_INFO); + if (annotation == null) + { + return getBrandingImageURI(scope.getParentScope()); + } + + String detail = annotation.getDetails().get(AnnotationConstants.KEY_IMAGE_URI); + if (detail == null) + { + return getBrandingImageURI(scope.getParentScope()); + } + + imageURI = URI.createURI(detail); + } + + if (imageURI == null) + { + imageURI = getEclipseBrandingImage(); + } + + return imageURI; + } } diff --git a/plugins/org.eclipse.oomph.setup.installer/SetupArchiver.launch b/plugins/org.eclipse.oomph.setup.installer/SetupArchiver.launch index 960e3e369..ffbaae944 100644 --- a/plugins/org.eclipse.oomph.setup.installer/SetupArchiver.launch +++ b/plugins/org.eclipse.oomph.setup.installer/SetupArchiver.launch @@ -2,7 +2,7 @@ <launchConfiguration type="org.eclipse.pde.ui.RuntimeWorkbench"> <setAttribute key="additional_plugins"/> <booleanAttribute key="append.args" value="true"/> -<stringAttribute key="application" value="org.eclipse.oomph.setup.installer.SetupArchiver"/> +<stringAttribute key="application" value="org.eclipse.oomph.setup.core.SetupArchiver"/> <booleanAttribute key="askclear" value="false"/> <booleanAttribute key="automaticAdd" value="false"/> <booleanAttribute key="automaticValidate" value="true"/> diff --git a/plugins/org.eclipse.oomph.setup.installer/plugin.xml b/plugins/org.eclipse.oomph.setup.installer/plugin.xml index 1d886af86..bb7b49cad 100644 --- a/plugins/org.eclipse.oomph.setup.installer/plugin.xml +++ b/plugins/org.eclipse.oomph.setup.installer/plugin.xml @@ -25,19 +25,6 @@ </run> </application> </extension> - - <extension - id="SetupArchiver" - point="org.eclipse.core.runtime.applications"> - <application - cardinality="singleton-global" - thread="main" - visible="true"> - <run - class="org.eclipse.oomph.setup.internal.installer.SetupArchiver"> - </run> - </application> - </extension> <extension id="application" diff --git a/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/InstallerApplication.java b/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/InstallerApplication.java index 8a95cf7c2..7fcea905b 100644 --- a/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/InstallerApplication.java +++ b/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/InstallerApplication.java @@ -21,6 +21,7 @@ import org.eclipse.oomph.setup.ui.wizards.SetupWizard.SelectionMemento; import org.eclipse.oomph.ui.ErrorDialog; import org.eclipse.oomph.ui.UIUtil; import org.eclipse.oomph.util.IOUtil; +import org.eclipse.oomph.util.OS; import org.eclipse.oomph.util.OomphPlugin.Preference; import org.eclipse.oomph.util.PropertiesUtil; @@ -232,7 +233,7 @@ public class InstallerApplication implements IApplication //$FALL-THROUGH$ } - String launcher = getLauncher(); + String launcher = OS.getCurrentLauncher(false); if (launcher != null) { try @@ -422,25 +423,6 @@ public class InstallerApplication implements IApplication // Do nothing. } - public static String getLauncher() - { - try - { - String launcher = PropertiesUtil.getProperty("eclipse.launcher"); - if (launcher != null && new File(launcher).isFile()) - { - return launcher; - } - } - catch (Throwable ex) - { - ex.printStackTrace(); - //$FALL-THROUGH$ - } - - return null; - } - /** * @author Eike Stepper */ diff --git a/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/KeepInstallerDialog.java b/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/KeepInstallerDialog.java index 1cb2b62b0..e17b54225 100644 --- a/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/KeepInstallerDialog.java +++ b/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/KeepInstallerDialog.java @@ -12,6 +12,7 @@ package org.eclipse.oomph.setup.internal.installer; import org.eclipse.oomph.setup.ui.AbstractSetupDialog; +import org.eclipse.oomph.util.OS; import org.eclipse.oomph.util.PropertiesUtil; import org.eclipse.oomph.util.StringUtil; @@ -194,7 +195,7 @@ public final class KeepInstallerDialog extends AbstractSetupDialog @Override protected void okPressed() { - final String launcher = InstallerApplication.getLauncher(); + final String launcher = OS.getCurrentLauncher(false); if (launcher != null) { final boolean startMenu = startMenuButton == null ? false : startMenuButton.getSelection(); diff --git a/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/KeepInstallerUtil.java b/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/KeepInstallerUtil.java index da03f07a4..9c942f5a4 100644 --- a/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/KeepInstallerUtil.java +++ b/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/KeepInstallerUtil.java @@ -105,7 +105,7 @@ public final class KeepInstallerUtil { if (!isInstallerKept() && OS.INSTANCE.isWin()) { - String launcher = InstallerApplication.getLauncher(); + String launcher = OS.getCurrentLauncher(false); return launcher != null && launcher.startsWith(PropertiesUtil.getTmpDir()); } diff --git a/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/SetupInstallerPlugin.java b/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/SetupInstallerPlugin.java index d6e90f1d3..952f99eae 100644 --- a/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/SetupInstallerPlugin.java +++ b/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/SetupInstallerPlugin.java @@ -15,6 +15,7 @@ import org.eclipse.oomph.internal.setup.SetupProperties; import org.eclipse.oomph.setup.internal.core.util.ECFURIHandlerImpl.AuthorizationHandler.Authorization; import org.eclipse.oomph.setup.internal.core.util.SetupCoreUtil; import org.eclipse.oomph.setup.ui.SetupUIPlugin; +import org.eclipse.oomph.setup.util.SetupUtil; import org.eclipse.oomph.ui.OomphUIPlugin; import org.eclipse.oomph.ui.UIUtil; import org.eclipse.oomph.util.IORuntimeException; @@ -131,7 +132,7 @@ public final class SetupInstallerPlugin extends OomphUIPlugin System.setProperty("user.home", new File(PropertiesUtil.getUserHome()).getCanonicalPath()); } - if (!PropertiesUtil.isProperty(SetupUIPlugin.PREF_HEADLESS)) + if (!PropertiesUtil.isProperty(SetupUIPlugin.PREF_HEADLESS) && !SetupUtil.SETUP_ARCHIVER_APPLICATION) { UIUtil.syncExec(new Runnable() { diff --git a/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/SimpleKeepInstallerPage.java b/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/SimpleKeepInstallerPage.java index 4913a8f1d..36cb17e99 100644 --- a/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/SimpleKeepInstallerPage.java +++ b/plugins/org.eclipse.oomph.setup.installer/src/org/eclipse/oomph/setup/internal/installer/SimpleKeepInstallerPage.java @@ -15,6 +15,7 @@ import org.eclipse.oomph.internal.ui.FlatButton; import org.eclipse.oomph.internal.ui.ImageHoverButton; import org.eclipse.oomph.setup.internal.installer.SimpleMessageOverlay.Type; import org.eclipse.oomph.ui.UIUtil; +import org.eclipse.oomph.util.OS; import org.eclipse.oomph.util.PropertiesUtil; import org.eclipse.oomph.util.StringUtil; @@ -194,7 +195,7 @@ public class SimpleKeepInstallerPage extends SimpleInstallerPage @Override public void widgetSelected(SelectionEvent e) { - final String launcher = InstallerApplication.getLauncher(); + final String launcher = OS.getCurrentLauncher(false); if (launcher != null) { final boolean startMenu = startMenuButton == null ? false : startMenuButton.isChecked(); diff --git a/plugins/org.eclipse.oomph.setup.ui.questionnaire/src/org/eclipse/oomph/setup/ui/questionnaire/QuestionnaireImpl.java b/plugins/org.eclipse.oomph.setup.ui.questionnaire/src/org/eclipse/oomph/setup/ui/questionnaire/QuestionnaireImpl.java index e62b44e5e..ec74ae35f 100644 --- a/plugins/org.eclipse.oomph.setup.ui.questionnaire/src/org/eclipse/oomph/setup/ui/questionnaire/QuestionnaireImpl.java +++ b/plugins/org.eclipse.oomph.setup.ui.questionnaire/src/org/eclipse/oomph/setup/ui/questionnaire/QuestionnaireImpl.java @@ -16,8 +16,8 @@ import org.eclipse.oomph.preferences.util.PreferencesUtil.PreferenceProperty; import org.eclipse.oomph.setup.SetupTaskContainer; import org.eclipse.oomph.setup.User; import org.eclipse.oomph.setup.ui.Questionnaire; -import org.eclipse.oomph.setup.ui.SetupUIPlugin; import org.eclipse.oomph.setup.ui.recorder.RecorderTransaction; +import org.eclipse.oomph.setup.util.SetupUtil; import org.eclipse.oomph.ui.UIUtil; import org.eclipse.oomph.util.Pair; @@ -80,13 +80,12 @@ public class QuestionnaireImpl extends Questionnaire if (!preferences.isEmpty()) { - boolean inIDE = !SetupUIPlugin.isInstallerProduct(); for (final Entry<URI, Pair<String, String>> entry : preferences.entrySet()) { final String path = PreferencesFactory.eINSTANCE.convertURI(entry.getKey()); transaction.setPolicy(path, true); - if (inIDE) + if (!SetupUtil.INSTALLER_PRODUCT) { UIUtil.syncExec(new Runnable() { diff --git a/plugins/org.eclipse.oomph.setup.ui.questionnaire/src/org/eclipse/oomph/setup/ui/questionnaire/QuestionnairePlugin.java b/plugins/org.eclipse.oomph.setup.ui.questionnaire/src/org/eclipse/oomph/setup/ui/questionnaire/QuestionnairePlugin.java index 312af13d7..16f9792a2 100644 --- a/plugins/org.eclipse.oomph.setup.ui.questionnaire/src/org/eclipse/oomph/setup/ui/questionnaire/QuestionnairePlugin.java +++ b/plugins/org.eclipse.oomph.setup.ui.questionnaire/src/org/eclipse/oomph/setup/ui/questionnaire/QuestionnairePlugin.java @@ -15,8 +15,8 @@ import org.eclipse.oomph.preferences.util.PreferencesUtil; import org.eclipse.oomph.preferences.util.PreferencesUtil.PreferenceProperty; import org.eclipse.oomph.setup.SetupTaskContainer; import org.eclipse.oomph.setup.User; -import org.eclipse.oomph.setup.ui.SetupUIPlugin; import org.eclipse.oomph.setup.ui.recorder.RecorderTransaction; +import org.eclipse.oomph.setup.util.SetupUtil; import org.eclipse.oomph.ui.OomphUIPlugin; import org.eclipse.oomph.ui.UIUtil; import org.eclipse.oomph.util.Pair; @@ -89,13 +89,12 @@ public final class QuestionnairePlugin extends OomphUIPlugin if (!preferences.isEmpty()) { - boolean inIDE = !SetupUIPlugin.isInstallerProduct(); for (Entry<URI, Pair<String, String>> entry : preferences.entrySet()) { String path = PreferencesFactory.eINSTANCE.convertURI(entry.getKey()); transaction.setPolicy(path, true); - if (inIDE) + if (!SetupUtil.INSTALLER_PRODUCT) { PreferenceProperty property = new PreferencesUtil.PreferenceProperty(path); property.set(entry.getValue().getElement2()); diff --git a/plugins/org.eclipse.oomph.setup.ui/src/org/eclipse/oomph/setup/ui/SetupUIPlugin.java b/plugins/org.eclipse.oomph.setup.ui/src/org/eclipse/oomph/setup/ui/SetupUIPlugin.java index 89946678f..97ba4e737 100644 --- a/plugins/org.eclipse.oomph.setup.ui/src/org/eclipse/oomph/setup/ui/SetupUIPlugin.java +++ b/plugins/org.eclipse.oomph.setup.ui/src/org/eclipse/oomph/setup/ui/SetupUIPlugin.java @@ -135,12 +135,6 @@ public final class SetupUIPlugin extends OomphUIPlugin return plugin; } - public static boolean isInstallerProduct() - { - String productID = PropertiesUtil.getProperty("eclipse.product"); - return SetupUtil.INSTALLER_PRODUCT_ID.equals(productID); - } - public static void initialStart(File ws, boolean offline, boolean mirrors) { Annotation annotation = BaseFactory.eINSTANCE.createAnnotation(); @@ -192,7 +186,7 @@ public final class SetupUIPlugin extends OomphUIPlugin static void performStartup() { - if (!PropertiesUtil.isProperty(PREF_HEADLESS)) + if (!PropertiesUtil.isProperty(PREF_HEADLESS) && !SetupUtil.SETUP_ARCHIVER_APPLICATION) { // These are only to force class loading on a background thread. SynchronizerManager.INSTANCE.toString(); @@ -204,7 +198,7 @@ public final class SetupUIPlugin extends OomphUIPlugin { public void run() { - if (!isInstallerProduct()) + if (!SetupUtil.INSTALLER_PRODUCT) { SetupPropertyTester.setStarting(true); diff --git a/plugins/org.eclipse.oomph.setup.ui/src/org/eclipse/oomph/setup/ui/wizards/SetupWizard.java b/plugins/org.eclipse.oomph.setup.ui/src/org/eclipse/oomph/setup/ui/wizards/SetupWizard.java index 755265956..48a61e5ee 100644 --- a/plugins/org.eclipse.oomph.setup.ui/src/org/eclipse/oomph/setup/ui/wizards/SetupWizard.java +++ b/plugins/org.eclipse.oomph.setup.ui/src/org/eclipse/oomph/setup/ui/wizards/SetupWizard.java @@ -12,7 +12,6 @@ package org.eclipse.oomph.setup.ui.wizards; import org.eclipse.oomph.base.Annotation; import org.eclipse.oomph.base.provider.BaseEditUtil; -import org.eclipse.oomph.base.util.BytesResourceFactoryImpl; import org.eclipse.oomph.internal.setup.SetupProperties; import org.eclipse.oomph.p2.internal.core.CacheUsageConfirmer; import org.eclipse.oomph.p2.internal.ui.CacheUsageConfirmerUI; @@ -693,40 +692,11 @@ public abstract class SetupWizard extends Wizard implements IPageChangedListener return null; } - public static URI getBrandingImageURI(Scope scope) - { - URI imageURI = null; - - if (scope != null) - { - Annotation annotation = scope.getAnnotation(AnnotationConstants.ANNOTATION_BRANDING_INFO); - if (annotation == null) - { - return getBrandingImageURI(scope.getParentScope()); - } - - String detail = annotation.getDetails().get(AnnotationConstants.KEY_IMAGE_URI); - if (detail == null) - { - return getBrandingImageURI(scope.getParentScope()); - } - - imageURI = URI.createURI(detail); - } - - if (imageURI == null) - { - imageURI = getEclipseBrandingImage(); - } - - return imageURI; - } - public static String getLocalBrandingImageURI(Scope scope) { try { - URI imageURI = getBrandingImageURI(scope); + URI imageURI = SetupCoreUtil.getBrandingImageURI(scope); return getImageURI(imageURI); } catch (Exception ex) @@ -734,7 +704,7 @@ public abstract class SetupWizard extends Wizard implements IPageChangedListener SetupUIPlugin.INSTANCE.log(ex, IStatus.WARNING); } - URI imageURI = getEclipseBrandingImage(); + URI imageURI = SetupCoreUtil.getEclipseBrandingImage(); return getImageURI(imageURI); } @@ -742,7 +712,7 @@ public abstract class SetupWizard extends Wizard implements IPageChangedListener { try { - URI imageURI = getBrandingImageURI(scope); + URI imageURI = SetupCoreUtil.getBrandingImageURI(scope); return getImage(imageURI); } catch (Exception ex) @@ -750,7 +720,7 @@ public abstract class SetupWizard extends Wizard implements IPageChangedListener SetupUIPlugin.INSTANCE.log(ex, IStatus.WARNING); } - URI imageURI = getEclipseBrandingImage(); + URI imageURI = SetupCoreUtil.getEclipseBrandingImage(); return getImage(imageURI); } @@ -766,11 +736,6 @@ public abstract class SetupWizard extends Wizard implements IPageChangedListener return ExtendedImageRegistry.INSTANCE.getImage(image); } - private static URI getEclipseBrandingImage() - { - return URI.createPlatformPluginURI(SetupUIPlugin.INSTANCE.getSymbolicName() + "/icons/committers.png", true); - } - private static boolean hasModalChild(Shell parentShell, Shell excludedShell) { if (!parentShell.isDisposed()) @@ -842,7 +807,7 @@ public abstract class SetupWizard extends Wizard implements IPageChangedListener { loading = true; - ResourceMirror resourceMirror = new ResourceMirrorWithProductImages(resourceSet) + ResourceMirror resourceMirror = new ResourceMirror.WithProductImages(resourceSet) { @Override protected void run(String taskName, IProgressMonitor monitor) @@ -1143,43 +1108,6 @@ public abstract class SetupWizard extends Wizard implements IPageChangedListener //$FALL-THROUGH$ } } - - /** - * @author Ed Merks - */ - public static class ResourceMirrorWithProductImages extends ResourceMirror - { - public ResourceMirrorWithProductImages(ResourceSet resourceSet) - { - super(resourceSet); - - BytesResourceFactoryImpl bytesResourceFactory = new BytesResourceFactoryImpl(); - Map<String, Object> extensionToFactoryMap = resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap(); - extensionToFactoryMap.put("gif", bytesResourceFactory); - extensionToFactoryMap.put("png", bytesResourceFactory); - extensionToFactoryMap.put("jpeg", bytesResourceFactory); - extensionToFactoryMap.put("jpg", bytesResourceFactory); - } - - @Override - protected void visit(EObject eObject) - { - if (eObject instanceof Scope) - { - Scope scope = (Scope)eObject; - URI uri = getBrandingImageURI(scope); - if (uri != null) - { - if (getResourceSet().getResourceFactoryRegistry().getExtensionToFactoryMap().containsKey(uri.fileExtension())) - { - schedule(uri, true); - } - } - } - - super.visit(eObject); - } - } } /** diff --git a/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/internal/setup/SetupProperties.java b/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/internal/setup/SetupProperties.java index e43235f8e..aad8db5c3 100644 --- a/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/internal/setup/SetupProperties.java +++ b/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/internal/setup/SetupProperties.java @@ -55,11 +55,13 @@ public interface SetupProperties public static final String PROP_SETUP_JRE_CHOICE = "oomph.setup.jre.choice"; - public static final String PROJP_SETUP_ECF_TRACE = "oomph.setup.ecf.trace"; + public static final String PROP_SETUP_ECF_TRACE = "oomph.setup.ecf.trace"; - public static final String PROJP_SETUP_ECF_CONNECT_TIMEOUT = "oomph.setup.ecf.connect.timeout"; + public static final String PROP_SETUP_ECF_CONNECT_TIMEOUT = "oomph.setup.ecf.connect.timeout"; - public static final String PROJP_SETUP_ECF_READ_TIMEOUT = "oomph.setup.ecf.read.timeout"; + public static final String PROP_SETUP_ECF_READ_TIMEOUT = "oomph.setup.ecf.read.timeout"; public static final String PROP_INSTALLER_UPDATE_URL = "oomph.installer.update.url"; + + public static final String PROP_SETUP_USER_AGENT = "oomph.userAgent"; } diff --git a/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/setup/util/SetupUtil.java b/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/setup/util/SetupUtil.java index dc5627778..215b39f93 100644 --- a/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/setup/util/SetupUtil.java +++ b/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/setup/util/SetupUtil.java @@ -32,6 +32,11 @@ public final class SetupUtil public static final String INSTALLER_PRODUCT_ID = "org.eclipse.oomph.setup.installer.product"; + public static final boolean INSTALLER_PRODUCT = PropertiesUtil.getProperty("eclipse.product").equals(INSTALLER_PRODUCT_ID); + + public static final boolean SETUP_ARCHIVER_APPLICATION = "org.eclipse.oomph.setup.core.SetupArchiver" + .equals(PropertiesUtil.getProperty("eclipse.application")); + private SetupUtil() { } diff --git a/plugins/org.eclipse.oomph.util/src/org/eclipse/oomph/util/OS.java b/plugins/org.eclipse.oomph.util/src/org/eclipse/oomph/util/OS.java index 506b9afae..9ddfa0637 100644 --- a/plugins/org.eclipse.oomph.util/src/org/eclipse/oomph/util/OS.java +++ b/plugins/org.eclipse.oomph.util/src/org/eclipse/oomph/util/OS.java @@ -232,6 +232,46 @@ public abstract class OS return launcherName; } + public static String getCurrentLauncher(boolean console) + { + try + { + String launcher = PropertiesUtil.getProperty("eclipse.launcher"); + if (launcher != null) + { + File launcherFile = new File(launcher); + if (launcherFile.isFile()) + { + File result = IOUtil.getCanonicalFile(launcherFile); + if (INSTANCE.isWin()) + { + // If we don't need a console, but actually ended up here with eclipsec.exe, we don't try to find the product-specifically named executable. + if (console) + { + File parentFolder = result.getParentFile(); + if (parentFolder != null) + { + File consoleLauncher = new File(parentFolder, "eclipsec.exe"); + if (consoleLauncher.isFile()) + { + return consoleLauncher.getPath(); + } + } + } + } + + return result.getPath(); + } + } + } + catch (Throwable ex) + { + //$FALL-THROUGH$ + } + + return null; + } + public abstract String getGitPrefix(); public abstract String getJREsRoot(); |
