KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > build > ExternalBuildModel


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core.build;
12
13 import java.io.File JavaDoc;
14 import java.io.IOException JavaDoc;
15 import java.io.InputStream JavaDoc;
16 import java.net.URL JavaDoc;
17
18 import org.eclipse.core.runtime.IPath;
19
20 public class ExternalBuildModel extends BuildModel {
21
22     private static final long serialVersionUID = 1L;
23     private String JavaDoc fInstallLocation;
24
25     public ExternalBuildModel(String JavaDoc installLocation) {
26         fInstallLocation = installLocation;
27     }
28
29     public String JavaDoc getInstallLocation() {
30         return fInstallLocation;
31     }
32
33     public boolean isEditable() {
34         return false;
35     }
36
37     public void load() {
38         try {
39             URL JavaDoc url = null;
40             File JavaDoc file = new File JavaDoc(getInstallLocation());
41             if (file.isFile() && file.getName().endsWith(".jar")) { //$NON-NLS-1$
42
url = new URL JavaDoc("jar:file:" + file.getAbsolutePath() + "!/build.properties"); //$NON-NLS-1$ //$NON-NLS-2$
43
} else {
44                 url = new URL JavaDoc("file:" + file.getAbsolutePath() + IPath.SEPARATOR + "build.properties"); //$NON-NLS-1$ //$NON-NLS-2$
45
}
46             InputStream JavaDoc stream = url.openStream();
47             load(stream, false);
48             stream.close();
49         } catch (IOException JavaDoc e) {
50             fBuild = new Build();
51             fBuild.setModel(this);
52             setLoaded(true);
53         }
54     }
55
56     protected void updateTimeStamp() {
57         updateTimeStamp(getLocalFile());
58     }
59
60     private File JavaDoc getLocalFile() {
61         File JavaDoc file = new File JavaDoc(getInstallLocation());
62         return (file.isFile()) ? file : new File JavaDoc(file, "build.properties"); //$NON-NLS-1$
63
}
64
65     public boolean isInSync() {
66         return true;
67     }
68 }
69
Popular Tags