Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8667f3628aa43e6a6908dcb3521c4624557b2840 (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
/*******************************************************************************
 * Copyright (c) 2008, 2017 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.pde.internal.build.publisher;

import java.io.File;
import java.util.LinkedHashMap;
import java.util.Set;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.equinox.internal.p2.core.helpers.FileUtils.IPathComputer;

public class GatheringComputer implements IPathComputer {
	private static final String PROVIDED_PATH = ":PROVIDED:"; //$NON-NLS-1$
	private final LinkedHashMap<File, String> filesMap = new LinkedHashMap<>();

	@Override
	public IPath computePath(File source) {
		String prefix = filesMap.get(source);

		IPath result = null;
		if (prefix.startsWith(PROVIDED_PATH)) {
			// the desired path is provided in the map
			result = new Path(prefix.substring(10));
		} else {
			//else the map contains a prefix which must be stripped from the path
			result = new Path(source.getAbsolutePath());
			IPath rootPath = new Path(prefix);
			result = result.removeFirstSegments(rootPath.matchingFirstSegments(result));
		}
		return result.setDevice(null);
	}

	@Override
	public void reset() {
		// nothing

	}

	public void addAll(GatheringComputer computer) {
		filesMap.putAll(computer.filesMap);
	}

	public void addFiles(String prefix, String[] files) {
		for (int i = 0; i < files.length; i++) {
			filesMap.put(new File(prefix, files[i]), prefix);
		}
	}

	public void addFile(String prefix, String file) {
		filesMap.put(new File(prefix, file), prefix);
	}

	public void addFile(String computedPath, File file) {
		filesMap.put(file, PROVIDED_PATH + computedPath);
	}

	public File[] getFiles() {
		Set<File> keys = filesMap.keySet();
		return keys.toArray(new File[keys.size()]);
	}

	public int size() {
		return filesMap.size();
	}
}

Back to the top