blob: 62389739638df94cdd1ca88017c611248f5db9e9 (
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
|
/*******************************************************************************
* Copyright (c) 2009, 2017 EclipseSource and others.
*
* This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License 2.0 which accompanies this distribution, and is
* available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* EclipseSource - initial API and implementation
* Red Hat Inc. - Bug 460967
******************************************************************************/
package org.eclipse.equinox.p2.internal.repository.tools;
import java.net.URI;
import java.net.URISyntaxException;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
public class RepositoryAnalyzerApplication implements IApplication {
private URI uri = null;
@Override
public Object start(IApplicationContext context) throws Exception {
long start = System.currentTimeMillis();
processArguments((String[]) context.getArguments().get("application.args"));
IProvisioningAgent agent = ServiceHelper.getService(Activator.getBundleContext(), IProvisioningAgent.class);
IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
IMetadataRepository repository = manager.loadRepository(uri, new NullProgressMonitor());
RepositoryAnalyzer repositoryAnalyzer = new RepositoryAnalyzer(new IMetadataRepository[] {repository});
IStatus status = repositoryAnalyzer.analyze(new NullProgressMonitor());
IStatus[] children = status.getChildren();
long time = (System.currentTimeMillis()) - start;
if (status.isOK())
System.out.println("Repository Analyzer Finished succesfuly in " + time + " ms.");
else
System.out.println("Repository Analyzer Finished in " + time + " ms with status with errors.");
for (int i = 0; i < children.length; i++) {
if (children[i].isOK())
System.out.print("[OK] ");
else
System.out.print("[Error] ");
System.out.println(children[i].getMessage());
if (children[i].isMultiStatus() && children[i].getChildren() != null && children[i].getChildren().length > 0) {
IStatus[] subChildren = children[i].getChildren();
for (int j = 0; j < subChildren.length; j++) {
System.out.println(" " + subChildren[j].getMessage());
}
}
}
return IApplication.EXIT_OK;
}
private void processArguments(String[] args) throws CoreException, URISyntaxException {
for (int i = 0; i < args.length; i++) {
if ("-m".equals(args[i]) || "-metadataRepository".equals(args[i])) { //$NON-NLS-1$ //$NON-NLS-2$
if (i + 1 < args.length)
uri = new URI(args[i + 1]);
}
}
validateLaunch();
}
private void validateLaunch() throws CoreException {
if (uri == null)
throw new CoreException(new Status(IStatus.ERROR, Activator.ID, "-metadataRepository <metadataURI> must be specified"));
}
@Override
public void stop() {
// TODO Auto-generated method stub
}
}
|