Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8820600bdf4c963f74ce5243adb78947eb35f28f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*******************************************************************************
 * Copyright (c) 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.ui.internal.intro.universal.contentdetect;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.Platform;
import org.eclipse.ui.intro.IntroContentDetector;

public class ContentDetector extends IntroContentDetector {

	private static Set<String> newContributors;
	private static boolean detectorCalled = false;

	public ContentDetector() {
	}

	@Override
	public boolean isNewContentAvailable() {
		try {
			detectorCalled = true;
			// If we have previously found new content no need to recompute
			if (newContributors != null && !newContributors.isEmpty()) {
				return true;
			}
			IExtension[] extensions = Platform
					.getExtensionRegistry()
					.getExtensionPoint("org.eclipse.ui.intro.configExtension").getExtensions(); //$NON-NLS-1$
			int numIntroExtensions = extensions.length;

			ContentDetectHelper helper = new ContentDetectHelper();
			int previous = helper.getExtensionCount();
			if (numIntroExtensions != previous) {
				helper.saveExtensionCount(numIntroExtensions);
				Set<String> contributors = new HashSet<>();
				for (int i = 0; i < extensions.length; i++) {
					contributors.add(extensions[i].getContributor().getName());
				}
				if (numIntroExtensions > previous && previous != ContentDetectHelper.NO_STATE) {
					Set<String> previousContributors = helper.getContributors();
					newContributors = helper.findNewContributors(contributors, previousContributors);
					helper.saveContributors(contributors);
					return true;
				}
				helper.saveContributors(contributors);
			}
		} catch (Exception e) {
			return false;
		}
		newContributors = new HashSet<>();
		return false;
	}

	/**
	 * @return The set of the ids of config extensions which are new since the last time
	 * intro was opened. May be null if there are no contributors.
	 */
	public static Set<String> getNewContributors() {
		if (!detectorCalled) {
		    detectorCalled = true;
		    new ContentDetector().isNewContentAvailable();
	    }
		return newContributors;
	}

	/**
	 * Test to see if this contribution was newly installed
	 * @param contributionId
	 * @return
	 */
	public static boolean isNew(String contributionId) {
		if (!detectorCalled) {
			detectorCalled = true;
			new ContentDetector().isNewContentAvailable();
		}
		return newContributors != null && newContributors.contains(contributionId);
	}

}

Back to the top