Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMengxin Zhu2012-01-17 03:30:54 +0000
committerMengxin Zhu2012-01-17 03:30:54 +0000
commit4529de7e84cc27de8774adf3ab8302cacbe7eb25 (patch)
tree44fefb7a24a8129da40cfbf259a7a674d9a21b3a /bundles
parent04549b1dd45c808514d61d55185d55a7a8b7fb63 (diff)
downloadrt.equinox.p2-4529de7e84cc27de8774adf3ab8302cacbe7eb25.tar.gz
rt.equinox.p2-4529de7e84cc27de8774adf3ab8302cacbe7eb25.tar.xz
rt.equinox.p2-4529de7e84cc27de8774adf3ab8302cacbe7eb25.zip
364929 support customizable download statisticsv20120117-1140v20120117-0330
Signed-off-by: Mengxin Zhu <kane.zhu@windriver.com>
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java8
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorRequest.java16
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/RawMirrorRequest.java9
-rw-r--r--bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IProfile.java8
-rw-r--r--bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Repo2Runnable.java10
-rw-r--r--bundles/org.eclipse.equinox.p2.repository/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IArtifactRepositoryManager.java19
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/StatsTest.java176
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/AllTestServerTests.java4
-rw-r--r--bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/Activator.java5
-rw-r--r--bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/Stats.java113
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/CollectAction.java4
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CollectAction.java4
14 files changed, 364 insertions, 16 deletions
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java
index e75e6b40e..97b1f60f1 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 IBM Corporation and others.
+ * Copyright (c) 2007, 2012 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
@@ -42,7 +42,11 @@ public class ArtifactRepositoryManager extends AbstractRepositoryManager<IArtifa
}
public IArtifactRequest createMirrorRequest(IArtifactKey key, IArtifactRepository destination, Map<String, String> destinationDescriptorProperties, Map<String, String> destinationRepositoryProperties) {
- return new MirrorRequest(key, destination, destinationDescriptorProperties, destinationRepositoryProperties, getTransport());
+ return createMirrorRequest(key, destination, destinationDescriptorProperties, destinationRepositoryProperties, null);
+ }
+
+ public IArtifactRequest createMirrorRequest(IArtifactKey key, IArtifactRepository destination, Map<String, String> destinationDescriptorProperties, Map<String, String> destinationRepositoryProperties, String downloadStatsParameters) {
+ return new MirrorRequest(key, destination, destinationDescriptorProperties, destinationRepositoryProperties, getTransport(), downloadStatsParameters);
}
public IArtifactRepository createRepository(URI location, String name, String type, Map<String, String> properties) throws ProvisionException {
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorRequest.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorRequest.java
index 499830240..20da9aee9 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorRequest.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorRequest.java
@@ -55,6 +55,10 @@ public class MirrorRequest extends ArtifactRequest {
* for reporting download statistics for that artifact.
*/
private static final String PROP_DOWNLOAD_STATS = "download.stats"; //$NON-NLS-1$
+ /**
+ * The additional parameters for downloading statistics
+ */
+ private String downloadStatsParamters;
protected final IArtifactRepository target;
@@ -63,6 +67,10 @@ public class MirrorRequest extends ArtifactRequest {
protected IArtifactDescriptor descriptor;
public MirrorRequest(IArtifactKey key, IArtifactRepository targetRepository, Map<String, String> targetDescriptorProperties, Map<String, String> targetRepositoryProperties, Transport transport) {
+ this(key, targetRepository, targetDescriptorProperties, targetRepositoryProperties, transport, null);
+ }
+
+ public MirrorRequest(IArtifactKey key, IArtifactRepository targetRepository, Map<String, String> targetDescriptorProperties, Map<String, String> targetRepositoryProperties, Transport transport, String statsParameters) {
super(key, transport);
target = targetRepository;
if (targetDescriptorProperties == null || targetDescriptorProperties.isEmpty()) {
@@ -78,6 +86,7 @@ public class MirrorRequest extends ArtifactRequest {
this.targetRepositoryProperties = new HashMap<String, String>();
this.targetRepositoryProperties.putAll(targetRepositoryProperties);
}
+ this.downloadStatsParamters = statsParameters;
}
public void perform(IArtifactRepository sourceRepository, IProgressMonitor monitor) {
@@ -218,6 +227,13 @@ public class MirrorRequest extends ArtifactRequest {
URI statsURI;
try {
statsURI = URIUtil.append(new URI(statsRoot), statsProperty);
+ if (downloadStatsParamters != null) {
+ try {
+ statsURI = new URI(statsURI.getScheme(), statsURI.getUserInfo(), statsURI.getHost(), statsURI.getPort(), statsURI.getPath(), statsURI.getQuery() == null ? downloadStatsParamters : downloadStatsParamters + "&" + statsURI.getQuery(), statsURI.getFragment()); //$NON-NLS-1$
+ } catch (URISyntaxException e) {
+ LogHelper.log(new Status(IStatus.WARNING, Activator.ID, "Unable to create download statistics due to invalid URL query: " + statsRoot + " suffix: " + statsProperty + " query: " + downloadStatsParamters)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ }
} catch (URISyntaxException e) {
LogHelper.log(new Status(IStatus.WARNING, Activator.ID, "Unable to report download statistics due to invalid URL: " + statsRoot + " suffix: " + statsProperty)); //$NON-NLS-1$ //$NON-NLS-2$
return;
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/RawMirrorRequest.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/RawMirrorRequest.java
index 74f18b11c..f4f7dcec9 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/RawMirrorRequest.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/RawMirrorRequest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 IBM Corporation and others.
+ * Copyright (c) 2009, 2012 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
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Sonatype, Inc. - transport split
+ * Wind River - continue development
*******************************************************************************/
package org.eclipse.equinox.internal.p2.artifact.repository;
@@ -26,7 +27,11 @@ public class RawMirrorRequest extends MirrorRequest {
protected IArtifactDescriptor sourceDescriptor, targetDescriptor;
public RawMirrorRequest(IArtifactDescriptor sourceDescriptor, IArtifactDescriptor targetDescriptor, IArtifactRepository targetRepository, Transport transport) {
- super(sourceDescriptor.getArtifactKey(), targetRepository, null, null, transport);
+ this(sourceDescriptor, targetDescriptor, targetRepository, transport, null);
+ }
+
+ public RawMirrorRequest(IArtifactDescriptor sourceDescriptor, IArtifactDescriptor targetDescriptor, IArtifactRepository targetRepository, Transport transport, String statsParameters) {
+ super(sourceDescriptor.getArtifactKey(), targetRepository, null, null, transport, statsParameters);
this.sourceDescriptor = sourceDescriptor;
this.targetDescriptor = targetDescriptor;
}
diff --git a/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF
index 720280b0e..92d919815 100644
--- a/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF
@@ -14,7 +14,7 @@ Export-Package: org.eclipse.equinox.internal.p2.engine;
org.eclipse.pde.build,
org.eclipse.equinox.p2.repository.tools",
org.eclipse.equinox.internal.p2.engine.phases;x-friends:="org.eclipse.equinox.p2.director.app,org.eclipse.equinox.p2.repository.tools,org.eclipse.equinox.p2.ui.sdk.scheduler",
- org.eclipse.equinox.p2.engine;version="2.0.0",
+ org.eclipse.equinox.p2.engine;version="2.2.0",
org.eclipse.equinox.p2.engine.query;version="2.0.0",
org.eclipse.equinox.p2.engine.spi;version="2.0.0"
Require-Bundle: org.eclipse.equinox.common,
diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IProfile.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IProfile.java
index 79655db23..1f8de7645 100644
--- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IProfile.java
+++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IProfile.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 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
@@ -146,6 +146,12 @@ public interface IProfile extends IQueryable<IInstallableUnit> {
public static final String STATE_PROP_TAG = "org.eclipse.equinox.p2.state.tag"; //$NON-NLS-1$
/**
+ * Profile property constant for additional parameters of the downloading stats(e.g., package=jee&os=linux).
+ * @since 2.2
+ */
+ public static final String PROP_STATS_PARAMETERS = "org.eclipse.equinox.p2.stats.parameters"; //$NON-NLS-1$
+
+ /**
* Returns the provisioning agent that manages this profile
* @return A provisioning agent.
*/
diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Repo2Runnable.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Repo2Runnable.java
index 57818e5ce..e814e9fbc 100644
--- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Repo2Runnable.java
+++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Repo2Runnable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 IBM Corporation and others.
+ * Copyright (c) 2009, 2012 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
@@ -43,6 +43,7 @@ public class Repo2Runnable extends AbstractApplication implements IApplication {
private static final String NATIVE_ARTIFACTS = "nativeArtifacts"; //$NON-NLS-1$
private static final String NATIVE_TYPE = "org.eclipse.equinox.p2.native"; //$NON-NLS-1$
private static final String PARM_OPERAND = "operand"; //$NON-NLS-1$
+ private static final String PARM_PROFILE = "profile"; //$NON-NLS-1$
protected class CollectNativesAction extends ProvisioningAction {
public IStatus execute(Map<String, Object> parameters) {
@@ -57,8 +58,13 @@ public class Repo2Runnable extends AbstractApplication implements IApplication {
@SuppressWarnings("unchecked")
List<IArtifactRequest> artifactRequests = (List<IArtifactRequest>) parameters.get(NATIVE_ARTIFACTS);
+ IProfile profile = (IProfile) parameters.get(PARM_PROFILE);
+ String statsParameter = null;
+ if (profile != null)
+ statsParameter = profile.getProperty(IProfile.PROP_STATS_PARAMETERS);
+
for (IArtifactKey keyToDownload : toDownload) {
- IArtifactRequest request = manager.createMirrorRequest(keyToDownload, destinationArtifactRepository, null, null);
+ IArtifactRequest request = manager.createMirrorRequest(keyToDownload, destinationArtifactRepository, null, null, statsParameter);
artifactRequests.add(request);
}
return Status.OK_STATUS;
diff --git a/bundles/org.eclipse.equinox.p2.repository/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.repository/META-INF/MANIFEST.MF
index 524be7d70..d681c08be 100644
--- a/bundles/org.eclipse.equinox.p2.repository/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.repository/META-INF/MANIFEST.MF
@@ -28,7 +28,7 @@ Export-Package: org.eclipse.equinox.internal.p2.persistence;
org.eclipse.equinox.p2.updatesite",
org.eclipse.equinox.internal.provisional.p2.repository,
org.eclipse.equinox.p2.repository;version="2.0.0",
- org.eclipse.equinox.p2.repository.artifact;version="2.0.0",
+ org.eclipse.equinox.p2.repository.artifact;version="2.1.0",
org.eclipse.equinox.p2.repository.artifact.spi;version="2.0.0",
org.eclipse.equinox.p2.repository.metadata;version="2.0.0",
org.eclipse.equinox.p2.repository.metadata.spi;version="2.0.0",
diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IArtifactRepositoryManager.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IArtifactRepositoryManager.java
index c11690bed..595f7ca74 100644
--- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IArtifactRepositoryManager.java
+++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IArtifactRepositoryManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 IBM Corporation and others.
+ * Copyright (c) 2007, 2012 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
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Wind River - continuing development
*******************************************************************************/
package org.eclipse.equinox.p2.repository.artifact;
@@ -60,6 +61,22 @@ public interface IArtifactRepositoryManager extends IRepositoryManager<IArtifact
public IArtifactRequest createMirrorRequest(IArtifactKey key, IArtifactRepository destination, Map<String, String> destinationDescriptorProperties, Map<String, String> destinationRepositoryProperties);
/**
+ * Return a new request to mirror the given artifact into the destination repository.
+ * @param key the artifact to mirror
+ * @param destination the destination where the artifact will be mirrored
+ * @param destinationDescriptorProperties additional properties for use in creating the repository's ArtifactDescriptor,
+ * or <code>null</code> to indicate no additional properties are needed
+ * @param destinationRepositoryProperties additional repository specific properties for use in creating the repositor's ArtifactDescriptor,
+ * , or <code>null</code> to indicate no additional properties are needed
+ * @param downloadStatsParameters additional customizable parameters for downloading statistics
+ * , or <code>null</code> to indicate no additional customizable stats parameters
+ * @return the newly created request object
+ * @see IArtifactRepositoryManager#createMirrorRequest(IArtifactKey, IArtifactRepository, Map, Map)
+ * @since 2.1
+ */
+ public IArtifactRequest createMirrorRequest(IArtifactKey key, IArtifactRepository destination, Map<String, String> destinationDescriptorProperties, Map<String, String> destinationRepositoryProperties, String downloadStatsParameters);
+
+ /**
* Creates and returns a new empty artifact repository of the given type at
* the given location.
* <p>
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/StatsTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/StatsTest.java
new file mode 100644
index 000000000..be7ef817e
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/StatsTest.java
@@ -0,0 +1,176 @@
+/*******************************************************************************
+ * Copyright (c) 2012 WindRiver 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:
+ * Wind River Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.artifact.repository;
+
+import java.io.*;
+import java.net.URI;
+import java.util.*;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.equinox.internal.p2.artifact.repository.MirrorRequest;
+import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository;
+import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest;
+import org.eclipse.equinox.internal.p2.engine.Profile;
+import org.eclipse.equinox.internal.p2.metadata.ArtifactKey;
+import org.eclipse.equinox.internal.p2.repository.AuthenticationFailedException;
+import org.eclipse.equinox.internal.p2.repository.Transport;
+import org.eclipse.equinox.p2.engine.*;
+import org.eclipse.equinox.p2.metadata.*;
+import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription;
+import org.eclipse.equinox.p2.planner.IPlanner;
+import org.eclipse.equinox.p2.query.QueryUtil;
+import org.eclipse.equinox.p2.repository.IRepository;
+import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
+import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
+import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor;
+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
+import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
+import org.eclipse.equinox.p2.tests.testserver.helper.AbstractTestServerClientCase;
+import org.eclipse.equinox.spi.p2.publisher.PublisherHelper;
+
+public class StatsTest extends AbstractTestServerClientCase {
+
+ private File repositoryFile;
+ private URI repositoryURI;
+ private SimpleArtifactRepository sourceRepo;
+ private File targetLocation;
+ private SimpleArtifactRepository targetRepository;
+ private URI statsURL;
+ private IMetadataRepository metaRepo;
+ private File testInstall;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ IArtifactRepositoryManager artifactRepositoryManager = (IArtifactRepositoryManager) getAgent().getService(IArtifactRepositoryManager.SERVICE_NAME);
+ String tempDir = System.getProperty("java.io.tmpdir");
+ repositoryFile = new File(tempDir, "SimpleArtifactRepositoryTest");
+ AbstractProvisioningTest.delete(repositoryFile);
+ repositoryURI = repositoryFile.toURI();
+ Map properties = new HashMap();
+ properties.put(IRepository.PROP_COMPRESSED, "true");
+ statsURL = URI.create(getBaseURL() + "/stats");
+ properties.put("p2.statsURI", statsURL.toString());
+ sourceRepo = (SimpleArtifactRepository) artifactRepositoryManager.createRepository(repositoryURI, "artifact name", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties);
+
+ IArtifactDescriptor[] descriptors = new IArtifactDescriptor[2];
+ IArtifactKey key = PublisherHelper.createBinaryArtifactKey("testKeyId", Version.create("1.2.3"));
+ descriptors[0] = PublisherHelper.createArtifactDescriptor(key, null);
+ ((ArtifactDescriptor) descriptors[0]).setProperty("download.stats", "testKeyId");
+ key = PublisherHelper.createBinaryArtifactKey("testKeyId2", Version.create("1.2.3"));
+ descriptors[1] = PublisherHelper.createArtifactDescriptor(key, null);
+ ((ArtifactDescriptor) descriptors[1]).setProperty("download.stats", "testKeyId2");
+ sourceRepo.addDescriptors(descriptors, null);
+
+ IMetadataRepositoryManager manager = (IMetadataRepositoryManager) getAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
+ properties = new HashMap();
+ properties.put(IRepository.PROP_COMPRESSED, "true");
+ metaRepo = manager.createRepository(repositoryURI, "TestRepo", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties);
+
+ InstallableUnitDescription descriptor = new MetadataFactory.InstallableUnitDescription();
+ descriptor.setId("testIuId");
+ descriptor.setVersion(Version.create("1.0.0"));
+ descriptor.setArtifacts(new IArtifactKey[] {key});
+ Collection providedCaps = new ArrayList();
+ providedCaps.add(MetadataFactory.createProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, descriptor.getId(), descriptor.getVersion()));
+ descriptor.addProvidedCapabilities(providedCaps);
+ descriptor.setMetaRequirements(new IRequirement[] {MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, descriptor.getId(), new VersionRange(descriptor.getVersion(), true, Version.MAX_VERSION, false), null, false, false)});
+ descriptor.setTouchpointType(PublisherHelper.TOUCHPOINT_NATIVE);
+ IInstallableUnit iu = MetadataFactory.createInstallableUnit(descriptor);
+ metaRepo.addInstallableUnits(Arrays.asList(iu));
+
+ for (int i = 0; i < descriptors.length; i++) {
+ File artifactFile = new File(sourceRepo.getLocation(descriptors[i]));
+ artifactFile.getParentFile().mkdirs();
+ assertTrue("Failed to create binary artifact file.", artifactFile.createNewFile());
+ }
+
+ targetLocation = File.createTempFile("target", ".repo");
+ AbstractProvisioningTest.delete(targetLocation);
+ targetLocation.mkdirs();
+ targetRepository = new SimpleArtifactRepository(getAgent(), "TargetRepo", targetLocation.toURI(), null);
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ //repository location is not used by all tests
+ if (repositoryURI != null) {
+ ((IArtifactRepositoryManager) getAgent().getService(IArtifactRepositoryManager.SERVICE_NAME)).removeRepository(repositoryURI);
+ ((IMetadataRepositoryManager) getAgent().getService(IMetadataRepositoryManager.SERVICE_NAME)).removeRepository(repositoryURI);
+ repositoryURI = null;
+ }
+ if (repositoryFile != null) {
+ AbstractProvisioningTest.delete(repositoryFile);
+ repositoryFile = null;
+ }
+ if (targetLocation != null) {
+ ((IArtifactRepositoryManager) getAgent().getService(IArtifactRepositoryManager.SERVICE_NAME)).removeRepository(targetLocation.toURI());
+ AbstractProvisioningTest.delete(targetLocation);
+ targetLocation = null;
+ }
+ if (testInstall != null) {
+ AbstractProvisioningTest.delete(testInstall);
+ testInstall = null;
+ }
+ }
+
+ public void testCustomizedDownloadStats() throws CoreException, IOException {
+ IArtifactKey key = new ArtifactKey(PublisherHelper.BINARY_ARTIFACT_CLASSIFIER, "testKeyId", Version.parseVersion("1.2.3"));
+ MirrorRequest request = new MirrorRequest(key, targetRepository, null, null, (Transport) getAgent().getService(Transport.SERVICE_NAME), "package=test");
+ request.perform(sourceRepo, new NullProgressMonitor());
+ assertTrue("Failed on mirroring artifact.", request.getResult().isOK());
+
+ checkStatsResult("test download number: 1");
+ }
+
+ protected void checkStatsResult(final String checkpoint) throws FileNotFoundException, CoreException, AuthenticationFailedException, IOException {
+ final Transport transport = (Transport) getAgent().getService(Transport.SERVICE_NAME);
+ BufferedReader statsResult = new BufferedReader(new InputStreamReader(transport.stream(statsURL, null)));
+ try {
+ String line = statsResult.readLine();
+ while (line != null) {
+ if (line.startsWith(checkpoint))
+ return;
+ line = statsResult.readLine();
+ }
+ fail("Didn't get expected stats result.");
+ } finally {
+ statsResult.close();
+ }
+ }
+
+ public void testDownloadStatsWhileInstall() throws AuthenticationFailedException, FileNotFoundException, CoreException, IOException {
+ IProfileRegistry registry = (IProfileRegistry) getAgent().getService(IProfileRegistry.SERVICE_NAME);
+ final String profileName = "downloadStats";
+ Map properties = new HashMap();
+ properties.put(IProfile.PROP_STATS_PARAMETERS, "os=linux&ws=gtk&package=jee");
+ String tempDir = System.getProperty("java.io.tmpdir");
+ testInstall = new File(tempDir, "statsTestInstall");
+ testInstall.mkdirs();
+ properties.put(IProfile.PROP_INSTALL_FOLDER, testInstall.toString());
+ Profile profile = (Profile) registry.addProfile(profileName, properties);
+ ProfileChangeRequest req = new ProfileChangeRequest(profile);
+ req.addInstallableUnits(metaRepo.query(QueryUtil.ALL_UNITS, null).toArray(IInstallableUnit.class));
+ IPlanner planner = (IPlanner) getAgent().getService(IPlanner.SERVICE_NAME);
+ ProvisioningContext context = new ProvisioningContext(getAgent());
+ context.setArtifactRepositories(new URI[] {repositoryURI});
+ context.setMetadataRepositories(new URI[] {repositoryURI});
+ IProvisioningPlan plan = planner.getProvisioningPlan(req, context, null);
+ IEngine engine = (IEngine) getAgent().getService(IEngine.SERVICE_NAME);
+ assertTrue("Failed on install test iu.", engine.perform(plan, null).isOK());
+ profile = (Profile) registry.getProfile(profileName);
+ assertEquals("Didn't install iu.", 1, profile.query(QueryUtil.ALL_UNITS, null).toUnmodifiableSet().size());
+ registry.removeProfile(profileName);
+ checkStatsResult("jee download number: 1");
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/AllTestServerTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/AllTestServerTests.java
index e55100947..1ef02ade5 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/AllTestServerTests.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/AllTestServerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Cloudsmith Inc and others.
+ * Copyright (c) 2009, 2012 Cloudsmith Inc 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
@@ -14,6 +14,7 @@ package org.eclipse.equinox.p2.tests.repository;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.equinox.p2.tests.artifact.repository.MirrorRequestTest2;
+import org.eclipse.equinox.p2.tests.artifact.repository.StatsTest;
import org.eclipse.equinox.p2.tests.testserver.helper.AbstractTestServerSuite;
public class AllTestServerTests extends AbstractTestServerSuite {
@@ -35,6 +36,7 @@ public class AllTestServerTests extends AbstractTestServerSuite {
suite.addTestSuite(FileReaderTest.class);
suite.addTestSuite(NTLMTest.class);
suite.addTestSuite(MirrorRequestTest2.class);
+ suite.addTestSuite(StatsTest.class);
suite.addTest(new AbstractTestServerSuite("stopServer"));
}
diff --git a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/Activator.java b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/Activator.java
index 90cbd16ac..2a3b43c2d 100644
--- a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/Activator.java
+++ b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/Activator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, Cloudsmith Inc and others.
+ * Copyright (c) 2009, 2012 Cloudsmith Inc 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
@@ -20,6 +20,7 @@ import org.eclipse.equinox.p2.testserver.servlets.FileMolester;
import org.eclipse.equinox.p2.testserver.servlets.IntermittentTimeout;
import org.eclipse.equinox.p2.testserver.servlets.LastModifiedLier;
import org.eclipse.equinox.p2.testserver.servlets.Redirector;
+import org.eclipse.equinox.p2.testserver.servlets.Stats;
import org.eclipse.equinox.p2.testserver.servlets.StatusCodeResponse;
import org.eclipse.equinox.p2.testserver.servlets.TimeOut;
import org.eclipse.equinox.p2.testserver.servlets.Truncator;
@@ -88,6 +89,7 @@ public class Activator implements BundleActivator, ServiceTrackerCustomizer {
httpService.registerServlet("/proxy3/aprivate", new BasicResourceDelivery("/proxy3/aprivate", URI.create(SITE2)), null, artifactSecuredHttpContext); //$NON-NLS-1$//$NON-NLS-2$
httpService.registerServlet("/proxy4/aprivate", new BasicResourceDelivery("/proxy4/aprivate", URI.create(SITE3)), null, artifactSecuredHttpContext); //$NON-NLS-1$//$NON-NLS-2$
+ httpService.registerServlet("/stats", new Stats(), null, null); //$NON-NLS-1$
} catch (NamespaceException e) {
// TODO Auto-generated catch block
@@ -147,6 +149,7 @@ public class Activator implements BundleActivator, ServiceTrackerCustomizer {
httpService = (HttpService) service;
httpService.unregister("/public"); //$NON-NLS-1$
httpService.unregister("/private"); //$NON-NLS-1$
+ httpService.unregister("/stats"); //$NON-NLS-1$
}
}
diff --git a/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/Stats.java b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/Stats.java
new file mode 100644
index 000000000..5d8f47316
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.testserver/src/org/eclipse/equinox/p2/testserver/servlets/Stats.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Wind River 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:
+ * Wind River - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.testserver.servlets;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+import java.util.TimeZone;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.eclipse.equinox.p2.testserver.HttpConstants;
+
+public class Stats extends HttpServlet {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -3209768955270841029L;
+ private static final String UnkownPackage = "unkown"; //$NON-NLS-1$
+ private static final String PACKAGE = "package"; //$NON-NLS-1$
+ private Map downloadStats = new HashMap();
+
+ public Stats() {
+ downloadStats.put(UnkownPackage, new Integer(0));
+ }
+
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ responseHeaderAndStatus(response);
+
+ final String result = getStatsResult();
+ response.setContentLength(result.length());
+ response.setContentType("text/plain"); //$NON-NLS-1$
+
+ BufferedReader reader = new BufferedReader(new StringReader(result));
+ PrintWriter writer = response.getWriter();
+ try {
+ writer.flush(); /* write the headers and unbuffer the output */
+ char buffer[] = new char[4096];
+ int read;
+ while ((read = reader.read(buffer, 0, buffer.length)) != -1) {
+ writer.write(buffer, 0, read);
+ }
+ } finally {
+ reader.close();
+ writer.close();
+ }
+ }
+
+ private void responseHeaderAndStatus(HttpServletResponse response) {
+ // set when the resource was modified
+ DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US); //$NON-NLS-1$
+ // must always be GMT
+ df.setTimeZone(TimeZone.getTimeZone("GMT")); //$NON-NLS-1$
+ response.setHeader(HttpConstants.LAST_MODIFIED, df.format(new Date()));
+ response.setStatus(HttpServletResponse.SC_OK);
+ }
+
+ private String getStatsResult() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("It's a page to count the downloading times when heading this page with query 'package=<package name>'.\n"); //$NON-NLS-1$
+ for (Iterator iter = downloadStats.keySet().iterator(); iter.hasNext();) {
+ String packageName = (String) iter.next();
+ sb.append(packageName).append(" download number: ").append(downloadStats.get(packageName)).append("\n"); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ return sb.toString();
+ }
+
+ protected void doHead(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ String queryString = request.getQueryString();
+
+ responseHeaderAndStatus(response);
+
+ boolean found = false;
+ if (queryString != null) {
+ String[] parameters = queryString.split("&"); //$NON-NLS-1$
+ for (int i = 0; i < parameters.length; i++) {
+ String[] paraPair = parameters[i].split("=", 2); //$NON-NLS-1$
+ if (paraPair.length == 2 && PACKAGE.equals(paraPair[0])) {
+ found = true;
+ Integer count = (Integer) downloadStats.get(paraPair[1]);
+ if (count == null) {
+ count = new Integer(1);
+ } else
+ count = new Integer(1 + count.intValue());
+ downloadStats.put(paraPair[1], count);
+ break;
+ }
+ }
+ }
+ if (!found) {
+ Integer count = (Integer) downloadStats.get(UnkownPackage);
+ downloadStats.put(UnkownPackage, new Integer(1 + count.intValue()));
+ }
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/CollectAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/CollectAction.java
index 5fe41c296..a66683cf6 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/CollectAction.java
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/CollectAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2008, 2012 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
@@ -80,7 +80,7 @@ public class CollectAction extends ProvisioningAction {
for (IArtifactKey key : toDownload) {
if (!aggregatedRepositoryView.contains(key)) {
Map<String, String> repositoryProperties = CollectAction.createArtifactDescriptorProperties(installableUnit);
- requests.add(Util.getArtifactRepositoryManager(agent).createMirrorRequest(key, bundlePool, null, repositoryProperties));
+ requests.add(Util.getArtifactRepositoryManager(agent).createMirrorRequest(key, bundlePool, null, repositoryProperties, profile.getProperty(IProfile.PROP_STATS_PARAMETERS)));
}
}
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CollectAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CollectAction.java
index 7dd742b62..a205965dc 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CollectAction.java
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CollectAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 IBM Corporation and others.
+ * Copyright (c) 2008, 2012 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
@@ -57,7 +57,7 @@ public class CollectAction extends ProvisioningAction {
int count = 0;
for (IArtifactKey key : toDownload) {
//TODO Here there are cases where the download is not necessary again because what needs to be done is just a configuration step
- requests[count++] = Util.getArtifactRepositoryManager(agent).createMirrorRequest(key, destination, null, null);
+ requests[count++] = Util.getArtifactRepositoryManager(agent).createMirrorRequest(key, destination, null, null, profile.getProperty(IProfile.PROP_STATS_PARAMETERS));
}
if (requests.length == count)

Back to the top