Skip to main content
summaryrefslogtreecommitdiffstats
blob: 402e06f61a6caa0130189d90e0e40b151fce0715 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*******************************************************************************
 * Copyright (c) 2000, 2013 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.debug.core.sourcelookup.containers;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;

/**
 * Archive source container for an archive in the workspace. Returns instances
 * of <code>ZipEntryStorage</code> as source elements.
 * <p>
 * Clients may instantiate this class.
 * </p>
 * @since 3.0
 * @noextend This class is not intended to be subclassed by clients.
 */
public class ArchiveSourceContainer extends AbstractSourceContainer {

	private IFile fFile;
	private boolean fDetectRoot;
	private ExternalArchiveSourceContainer fDelegateContainer;

	/**
	 * Unique identifier for the archive source container type
	 * (value <code>org.eclipse.debug.core.containerType.archive</code>).
	 */
	public static final String TYPE_ID = DebugPlugin.getUniqueIdentifier() + ".containerType.archive";	 //$NON-NLS-1$

	/**
	 * Creates an archive source container on the given file.
	 *
	 * @param archive archive in the workspace
	 * @param detectRootPath whether a root path should be detected. When
	 *   <code>true</code>, searching is performed relative to a root path
	 *   within the archive based on fully qualified file names. The root
	 *   path is automatically determined when the first successful search
	 *   is performed. For example, when searching for a file named
	 *   <code>a/b/c.d</code>, and an entry in the archive named
	 *   <code>r/a/b/c.d</code> exists, the root path is set to <code>r</code>.
	 *   From that point on, searching is performed relative to <code>r</code>.
	 *   When <code>false</code>, searching is performed by
	 *   matching file names as suffixes to the entries in the archive.
	 */
	public ArchiveSourceContainer(IFile archive, boolean detectRootPath) {
		fFile = archive;
		fDetectRoot = detectRootPath;
		if (archive.exists() && archive.getLocation() != null) {
		    fDelegateContainer = new ExternalArchiveSourceContainer(archive.getLocation().toOSString(), detectRootPath);
		}
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getName()
	 */
	@Override
	public String getName() {
		return fFile.getName();
	}

	/**
	 * Returns the associated file in the workspace.
	 *
	 * @return associated file in the workspace
	 */
	public IFile getFile() {
		return fFile;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getType()
	 */
	@Override
	public ISourceContainerType getType() {
		return getSourceContainerType(TYPE_ID);
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		return obj instanceof ArchiveSourceContainer &&
			((ArchiveSourceContainer)obj).getName().equals(getName());
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return getName().hashCode();
	}

    /* (non-Javadoc)
     * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#findSourceElements(java.lang.String)
     */
    @Override
	public Object[] findSourceElements(String name) throws CoreException {
        ExternalArchiveSourceContainer container = getDelegateContainer();
        if (container != null) {
            return container.findSourceElements(name);
        }
        return EMPTY;
    }

    /**
     * Returns the underlying external archive source container.
     *
     * @return underlying external archive source container
     * @since 3.0.1.1
     */
    private ExternalArchiveSourceContainer getDelegateContainer() {
        return fDelegateContainer;
    }
    /* (non-Javadoc)
     * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#init(org.eclipse.debug.core.sourcelookup.ISourceLookupDirector)
     */
    @Override
	public void init(ISourceLookupDirector director) {
        super.init(director);
        if (fDelegateContainer != null) {
            fDelegateContainer.init(director);
        }
    }
    /* (non-Javadoc)
     * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#dispose()
     */
    @Override
	public void dispose() {
        super.dispose();
        if (fDelegateContainer != null) {
            fDelegateContainer.dispose();
        }
    }

	/**
	 * Returns whether root paths are automatically detected in this
	 * archive source container.
	 *
	 * @return whether root paths are automatically detected in this
	 * archive source container
	 * @since 3.0.1.1
	 */
	public boolean isDetectRoot() {
		return fDetectRoot;
	}
}

Back to the top