Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Arthorne2010-04-27 20:27:14 +0000
committerJohn Arthorne2010-04-27 20:27:14 +0000
commit4700c08d5ac6811888c8130ee2a53764d77ce39a (patch)
tree3aea7fe6ee5f5a121423268d3dce5716925a6f03
parent6bc6a073d82dbf3ff9792c102a18b246b04b9762 (diff)
downloadrt.equinox.p2-4700c08d5ac6811888c8130ee2a53764d77ce39a.tar.gz
rt.equinox.p2-4700c08d5ac6811888c8130ee2a53764d77ce39a.tar.xz
rt.equinox.p2-4700c08d5ac6811888c8130ee2a53764d77ce39a.zip
*** empty log message ***
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestLicenseConsistency.java108
1 files changed, 108 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestLicenseConsistency.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestLicenseConsistency.java
new file mode 100644
index 000000000..dfd9b041d
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestLicenseConsistency.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.equinox.p2.tests;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.*;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.equinox.p2.core.ProvisionException;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.ILicense;
+import org.eclipse.equinox.p2.query.IQueryResult;
+import org.eclipse.equinox.p2.query.QueryUtil;
+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
+
+/**
+ * Tests that licenses in the helios repository are consistent with the platform feature license.
+ * Note this test isn't intended to be included in automated tests. It produces a report
+ * on stdout that can be used to identify features with inconsistent feature licenses.
+ */
+public class TestLicenseConsistency extends AbstractProvisioningTest {
+ public void testLicenses() throws URISyntaxException, ProvisionException, OperationCanceledException {
+ URI repoLocation = new URI("http://download.eclipse.org/releases/helios");
+ IMetadataRepository repo = getMetadataRepositoryManager().loadRepository(repoLocation, null);
+ IQueryResult<IInstallableUnit> allFeatures = repo.query(QueryUtil.createIUGroupQuery(), null);
+ IQueryResult<IInstallableUnit> platform = allFeatures.query(QueryUtil.createIUQuery("org.eclipse.platform.feature.group"), null);
+ assertFalse(allFeatures.isEmpty());
+ assertFalse(platform.isEmpty());
+ IInstallableUnit platformFeature = platform.iterator().next();
+ ILicense platformLicense = platformFeature.getLicenses(null).iterator().next();
+
+ List<IInstallableUnit> noLicense = new ArrayList<IInstallableUnit>();
+ List<IInstallableUnit> extraLicense = new ArrayList<IInstallableUnit>();
+ List<IInstallableUnit> goodLicense = new ArrayList<IInstallableUnit>();
+ List<IInstallableUnit> badLicense = new ArrayList<IInstallableUnit>();
+ checkLicenses(platformLicense, allFeatures, goodLicense, badLicense, noLicense, extraLicense);
+
+ printReport(goodLicense, badLicense, noLicense, extraLicense);
+
+ }
+
+ private void printReport(List<IInstallableUnit> goodLicense, List<IInstallableUnit> badLicense, List<IInstallableUnit> noLicense, List<IInstallableUnit> extraLicense) {
+ String SPACER = "\n=======================";
+ System.out.println("\n\nSummary:" + SPACER);
+ System.out.println("Features with conforming license: " + goodLicense.size());
+ System.out.println("Features with different license: " + badLicense.size());
+ System.out.println("Features with no license: " + noLicense.size());
+ System.out.println("Features with extra licenses: " + extraLicense.size());
+ System.out.println("=======================");
+
+ System.out.println("\n\nDetails:" + SPACER);
+
+ System.out.println("Features with no license:" + SPACER);
+ for (IInstallableUnit unit : sort(noLicense)) {
+ System.out.println(unit.getId());
+ }
+
+ System.out.println("\n\nFeatures with different license:" + SPACER);
+ for (IInstallableUnit unit : sort(badLicense)) {
+ System.out.println(unit.getId());
+ }
+
+ System.out.println("\n\nFeatures with matching license:" + SPACER);
+ for (IInstallableUnit unit : sort(goodLicense)) {
+ System.out.println(unit.getId());
+ }
+
+ }
+
+ private List<IInstallableUnit> sort(List<IInstallableUnit> noLicense) {
+ Collections.sort(noLicense);
+ return noLicense;
+ }
+
+ private void checkLicenses(ILicense platformLicense, IQueryResult<IInstallableUnit> allFeatures, List<IInstallableUnit> goodLicense, List<IInstallableUnit> badLicense, List<IInstallableUnit> noLicense, List<IInstallableUnit> extraLicense) {
+ for (IInstallableUnit feature : allFeatures.toUnmodifiableSet()) {
+ //ignore groups that are not features
+ if (!feature.getId().endsWith(".feature.group"))
+ continue;
+ Collection<ILicense> licenses = feature.getLicenses(null);
+ if (licenses.isEmpty()) {
+ noLicense.add(feature);
+ continue;
+ }
+ if (licenses.size() != 1) {
+ extraLicense.add(feature);
+ continue;
+ }
+ ILicense featureLicense = licenses.iterator().next();
+ if (!platformLicense.getUUID().equals(featureLicense.getUUID())) {
+ badLicense.add(feature);
+ // if (featureLicense.getBody().length() < 100) {
+ // System.out.println(feature.getId() + " license: " + featureLicense.getBody());
+ // }
+ continue;
+ }
+ goodLicense.add(feature);
+ }
+ }
+}

Back to the top