1 /*******************************************************************************
2 * Copyright (c) 2012 SAP AG.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License 2.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-2.0/
8 * SPDX-License-Identifier: EPL-2.0
11 * Stefan Lay (SAP AG) - initial implementation
12 *******************************************************************************/
13 package org
.eclipse
.egit
.ui
.internal
.clone
;
15 import java
.util
.ArrayList
;
16 import java
.util
.List
;
18 import org
.eclipse
.core
.runtime
.CoreException
;
19 import org
.eclipse
.core
.runtime
.IConfigurationElement
;
20 import org
.eclipse
.core
.runtime
.IExtensionRegistry
;
21 import org
.eclipse
.core
.runtime
.Platform
;
22 import org
.eclipse
.egit
.ui
.Activator
;
23 import org
.eclipse
.egit
.ui
.internal
.UIIcons
;
24 import org
.eclipse
.egit
.ui
.internal
.UIText
;
25 import org
.eclipse
.egit
.ui
.internal
.provisional
.wizards
.IRepositorySearchResult
;
26 import org
.eclipse
.egit
.ui
.internal
.provisional
.wizards
.IRepositoryServerProvider
;
27 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
28 import org
.eclipse
.jface
.wizard
.WizardPage
;
29 import org
.osgi
.framework
.Bundle
;
32 * Provides access to the extensions of the cloneSourceProvider extension point
34 public class GitCloneSourceProviderExtension
{
36 private static final String CLONE_SOURCE_PROVIDER_ID
= "org.eclipse.egit.ui.cloneSourceProvider"; //$NON-NLS-1$
39 * @return the list of {@code CloneSourceProvider} read from the extension
42 public static List
<CloneSourceProvider
> getCloneSourceProvider() {
43 List
<CloneSourceProvider
> cloneSourceProvider
= new ArrayList
<>();
45 IExtensionRegistry registry
= Platform
.getExtensionRegistry();
46 IConfigurationElement
[] config
= registry
47 .getConfigurationElementsFor(CLONE_SOURCE_PROVIDER_ID
);
48 if (config
.length
> 0)
49 addCloneSourceProvider(cloneSourceProvider
, config
, 0);
51 return cloneSourceProvider
;
54 private static void addCloneSourceProvider(
55 List
<CloneSourceProvider
> cloneSourceProvider
,
56 IConfigurationElement
[] config
, int index
) {
59 String label
= config
[myIndex
].getAttribute("label"); //$NON-NLS-1$
60 boolean hasFixLocation
= Boolean
.valueOf(
61 config
[myIndex
].getAttribute("hasFixLocation")).booleanValue(); //$NON-NLS-1$
64 String iconPath
= config
[myIndex
].getAttribute("icon"); //$NON-NLS-1$
65 ImageDescriptor icon
= null;
66 if (iconPath
!= null) {
67 Bundle declaringBundle
= Platform
.getBundle(config
[myIndex
]
68 .getDeclaringExtension().getContributor().getName());
69 if (declaringBundle
!= null) {
70 icon
= ImageDescriptor
.createFromURL(
71 declaringBundle
.getResource(iconPath
));
75 IConfigurationElement serverProviderElement
= null;
76 if (myIndex
< config
.length
77 && config
[myIndex
].getName().equals("repositoryServerProvider")) { //$NON-NLS-1$
78 serverProviderElement
= config
[myIndex
];
81 IConfigurationElement pageElement
= null;
82 if (myIndex
< config
.length
83 && config
[myIndex
].getName().equals("repositorySearchPage")) { //$NON-NLS-1$
84 pageElement
= config
[myIndex
];
87 cloneSourceProvider
.add(new CloneSourceProvider(label
,
88 serverProviderElement
, pageElement
, hasFixLocation
, icon
));
89 if (myIndex
== config
.length
)
91 addCloneSourceProvider(cloneSourceProvider
, config
, myIndex
);
92 } catch (Exception e
) {
93 Activator
.logError("Could not create extension provided by " + //$NON-NLS-1$
94 Platform
.getBundle(config
[index
].getDeclaringExtension()
95 .getContributor().getName()),
101 * Encapsulates a clone source provided by an extension of the extension
102 * point "org.eclipse.egit.ui.cloneSourceProvider"
104 public static class CloneSourceProvider
{
107 * The constant provider used for local repositories
109 public static final CloneSourceProvider LOCAL
= new CloneSourceProvider(
110 UIText
.GitCloneSourceProviderExtension_Local
, null, null, true, UIIcons
.REPOSITORY
);
112 private static final ImageDescriptor defaultImage
= UIIcons
.REPOSITORY
;
114 private final String label
;
116 private final IConfigurationElement repositoryServerProviderElement
;
118 private final IConfigurationElement repositorySearchPageELement
;
120 private boolean hasFixLocation
= false;
122 private ImageDescriptor image
= UIIcons
.REPOSITORY
;
124 private CloneSourceProvider(String label
,
125 IConfigurationElement repositoryServerProviderElement
,
126 IConfigurationElement repositorySearchPageElement
,
127 boolean hasFixLocation
,
128 ImageDescriptor image
) {
130 this.repositoryServerProviderElement
= repositoryServerProviderElement
;
131 this.repositorySearchPageELement
= repositorySearchPageElement
;
132 this.hasFixLocation
= hasFixLocation
;
137 * @return label the human readable name of a type of servers which
138 * contain repositories
140 public String
getLabel() {
147 public ImageDescriptor
getImage() {
148 return image
!= null ? image
: defaultImage
;
152 * @return a class which provides a list of servers which host git
153 * repositories. This class is newly created on each invocation
154 * of this method. Clients are responsible to cache this
156 * @throws CoreException
158 public IRepositoryServerProvider
getRepositoryServerProvider()
159 throws CoreException
{
160 if (repositoryServerProviderElement
== null)
162 Object object
= repositoryServerProviderElement
163 .createExecutableExtension("class"); //$NON-NLS-1$
164 IRepositoryServerProvider provider
= null;
165 if (object
instanceof IRepositoryServerProvider
)
166 provider
= (IRepositoryServerProvider
) object
;
171 * @return A wizard page which can return information of a git
172 * repository. This class is newly created on each invocation of
173 * this method. Clients are responsible to cache this
175 * @throws CoreException
177 public WizardPage
getRepositorySearchPage() throws CoreException
{
178 if (repositorySearchPageELement
== null)
180 Object object
= repositorySearchPageELement
181 .createExecutableExtension("class"); //$NON-NLS-1$
182 WizardPage page
= null;
183 if (object
instanceof WizardPage
184 && object
instanceof IRepositorySearchResult
)
185 page
= (WizardPage
) object
;
190 * @return true if there will be no ability to add different servers of
191 * this type. The provided repositoryImportPage has to know
192 * where to look for the repositories.
194 public boolean hasFixLocation() {
195 return hasFixLocation
;