| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2008, 2017 IBM Corporation and others. |
| 3 |
* |
| 4 |
* This |
| 5 |
* program and the accompanying materials are made available under the terms of |
| 6 |
* the Eclipse Public License 2.0 which accompanies this distribution, and is |
| 7 |
* available at |
| 8 |
* https://www.eclipse.org/legal/epl-2.0/ |
| 9 |
* |
| 10 |
* SPDX-License-Identifier: EPL-2.0 |
| 11 |
* |
| 12 |
* Contributors: IBM Corporation - initial API and implementation |
| 13 |
******************************************************************************/ |
| 14 |
package org.eclipse.pde.internal.build.publisher; |
| 15 |
|
| 16 |
import java.io.File; |
| 17 |
import java.util.LinkedHashMap; |
| 18 |
import java.util.Set; |
| 19 |
import org.eclipse.core.runtime.IPath; |
| 20 |
import org.eclipse.equinox.internal.p2.core.helpers.FileUtils.IPathComputer; |
| 21 |
|
| 22 |
public class GatheringComputer implements IPathComputer { |
| 23 |
private static final String PROVIDED_PATH = ":PROVIDED:"; //$NON-NLS-1$ |
| 24 |
private final LinkedHashMap<File, String> filesMap = new LinkedHashMap<>(); |
| 25 |
|
| 26 |
@Override |
| 27 |
public IPath computePath(File source) { |
| 28 |
String prefix = filesMap.get(source); |
| 29 |
|
| 30 |
IPath result = null; |
| 31 |
if (prefix.startsWith(PROVIDED_PATH)) { |
| 32 |
// the desired path is provided in the map |
| 33 |
result = IPath.fromOSString(prefix.substring(10)); |
| 34 |
} else { |
| 35 |
//else the map contains a prefix which must be stripped from the path |
| 36 |
result = IPath.fromOSString(source.getAbsolutePath()); |
| 37 |
IPath rootPath = IPath.fromOSString(prefix); |
| 38 |
result = result.removeFirstSegments(rootPath.matchingFirstSegments(result)); |
| 39 |
} |
| 40 |
return result.setDevice(null); |
| 41 |
} |
| 42 |
|
| 43 |
@Override |
| 44 |
public void reset() { |
| 45 |
// nothing |
| 46 |
|
| 47 |
} |
| 48 |
|
| 49 |
public void addAll(GatheringComputer computer) { |
| 50 |
filesMap.putAll(computer.filesMap); |
| 51 |
} |
| 52 |
|
| 53 |
public void addFiles(String prefix, String[] files) { |
| 54 |
for (String file : files) { |
| 55 |
filesMap.put(new File(prefix, file), prefix); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
public void addFile(String prefix, String file) { |
| 60 |
filesMap.put(new File(prefix, file), prefix); |
| 61 |
} |
| 62 |
|
| 63 |
public void addFile(String computedPath, File file) { |
| 64 |
filesMap.put(file, PROVIDED_PATH + computedPath); |
| 65 |
} |
| 66 |
|
| 67 |
public File[] getFiles() { |
| 68 |
Set<File> keys = filesMap.keySet(); |
| 69 |
return keys.toArray(new File[keys.size()]); |
| 70 |
} |
| 71 |
|
| 72 |
public int size() { |
| 73 |
return filesMap.size(); |
| 74 |
} |
| 75 |
} |