001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.core.plugin;
011:
012: import java.io.File;
013: import java.net.MalformedURLException;
014: import java.net.URL;
015:
016: import org.eclipse.core.runtime.IPath;
017: import org.eclipse.core.runtime.Path;
018: import org.eclipse.osgi.service.resolver.BundleDescription;
019: import org.eclipse.pde.core.build.IBuildModel;
020: import org.eclipse.pde.internal.core.NLResourceHelper;
021: import org.eclipse.pde.internal.core.PDEManager;
022: import org.eclipse.pde.internal.core.PDEState;
023:
024: public abstract class ExternalPluginModelBase extends
025: AbstractPluginModelBase {
026:
027: private String fInstallLocation;
028:
029: private String fLocalization;
030:
031: public ExternalPluginModelBase() {
032: super ();
033: }
034:
035: protected NLResourceHelper createNLResourceHelper() {
036: return (fLocalization == null) ? null : new NLResourceHelper(
037: fLocalization, PDEManager.getNLLookupLocations(this )); //$NON-NLS-1$
038: }
039:
040: public URL getNLLookupLocation() {
041: try {
042: if (fInstallLocation != null
043: && new File(fInstallLocation).isDirectory()
044: && !fInstallLocation.endsWith("/")) //$NON-NLS-1$
045: return new URL("file:" + fInstallLocation + "/"); //$NON-NLS-1$ //$NON-NLS-2$
046: return new URL("file:" + fInstallLocation); //$NON-NLS-1$
047: } catch (MalformedURLException e) {
048: return null;
049: }
050: }
051:
052: public IBuildModel getBuildModel() {
053: return null;
054: }
055:
056: public String getInstallLocation() {
057: return fInstallLocation;
058: }
059:
060: public boolean isEditable() {
061: return false;
062: }
063:
064: public void load() {
065: }
066:
067: public void load(BundleDescription description, PDEState state) {
068: IPath path = new Path(description.getLocation());
069: String device = path.getDevice();
070: if (device != null)
071: path = path.setDevice(device.toUpperCase());
072: setInstallLocation(path.toOSString());
073: fLocalization = state.getBundleLocalization(description
074: .getBundleId());
075: super .load(description, state);
076: }
077:
078: public boolean isInSync() {
079: return isInSync(getLocalFile());
080: }
081:
082: private File getLocalFile() {
083: File file = new File(getInstallLocation());
084: if (file.isFile())
085: return file;
086:
087: file = new File(file, "META-INF/MANIFEST.MF"); //$NON-NLS-1$
088: if (!file.exists()) {
089: String manifest = isFragmentModel() ? "fragment.xml" : "plugin.xml"; //$NON-NLS-1$ //$NON-NLS-2$
090: file = new File(getInstallLocation(), manifest);
091: }
092: return file;
093: }
094:
095: protected void updateTimeStamp() {
096: updateTimeStamp(getLocalFile());
097: }
098:
099: public void setInstallLocation(String newInstallLocation) {
100: fInstallLocation = newInstallLocation;
101: }
102:
103: public String getLocalization() {
104: return fLocalization;
105: }
106: }
|