blob: 6d6ae8bb2e4b5de13031cbc4b57aaa891f2ca806 (
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
|
/*******************************************************************************
* Copyright (c) 2008 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.internal.p2.touchpoint.eclipse;
import org.eclipse.equinox.internal.provisional.p2.metadata.Version;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.*;
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
import org.eclipse.equinox.internal.provisional.p2.engine.IProfile;
import org.eclipse.equinox.internal.simpleconfigurator.manipulator.SimpleConfiguratorManipulatorImpl;
//This class deals with source bundles and how their addition to the source.info
public class SourceManipulator {
private List sourceBundles;
private IProfile profile;
boolean changed = false;
private SimpleConfiguratorManipulatorImpl manipulator;
public SourceManipulator(IProfile profile) {
this.profile = profile;
this.manipulator = new SimpleConfiguratorManipulatorImpl();
}
public BundleInfo[] getBundles() throws IOException {
if (sourceBundles == null)
load();
return (BundleInfo[]) sourceBundles.toArray(new BundleInfo[sourceBundles.size()]);
}
public void addBundle(File bundleFile, String bundleId, Version bundleVersion) throws IOException {
if (sourceBundles == null)
load();
BundleInfo sourceInfo = new BundleInfo(bundleFile.toURI());
sourceInfo.setSymbolicName(bundleId);
sourceInfo.setVersion(bundleVersion.toString());
sourceBundles.add(sourceInfo);
}
public void removeBundle(File bundleFile, String bundleId, Version bundleVersion) throws MalformedURLException, IOException {
if (sourceBundles == null)
load();
BundleInfo sourceInfo = new BundleInfo();
if (bundleFile != null)
sourceInfo.setLocation(bundleFile.toURI());
sourceInfo.setSymbolicName(bundleId);
sourceInfo.setVersion(bundleVersion.toString());
sourceBundles.remove(sourceInfo);
}
public void save() throws IOException {
if (sourceBundles != null)
manipulator.saveConfiguration((BundleInfo[]) sourceBundles.toArray(new BundleInfo[sourceBundles.size()]), getFileLocation(), getLauncherLocation());
}
private void load() throws MalformedURLException, IOException {
if (getFileLocation().exists())
sourceBundles = new ArrayList(Arrays.asList(manipulator.loadConfiguration(getFileLocation().toURL(), getLauncherLocation())));
else
sourceBundles = new ArrayList();
}
private File getFileLocation() {
return new File(Util.getConfigurationFolder(profile), "org.eclipse.equinox.source/source.info"); //$NON-NLS-1$
}
private File getLauncherLocation() {
return Util.getInstallFolder(profile);
}
}
|