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
|
/*******************************************************************************
* Copyright (c) 2004, 2007 Boeing.
* 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:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.define.traceability.operations;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileInfo;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.osee.define.traceability.TraceUnitExtensionManager;
import org.eclipse.osee.define.traceability.TraceUnitExtensionManager.TraceHandler;
import org.eclipse.osee.framework.core.data.BranchId;
import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Collections;
import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
/**
* @author Roberto E. Escobar
*/
public class TraceUnitFromResourceOperation {
public static Set<String> getTraceUnitHandlerIds() throws OseeCoreException {
return TraceUnitExtensionManager.getInstance().getTraceUnitHandlerIds();
}
private static ResourceToTraceUnit getResourceToTestUnit(Iterable<URI> sources, boolean isRecursive, boolean isFileWithMultiplePaths, boolean addGuidToSourceFile, boolean includeImpd, String... testUnitTraceIds) throws OseeCoreException {
checkSourceArgument(sources);
checkTraceUnitHandlerIdsArgument(testUnitTraceIds);
ResourceToTraceUnit operation =
new ResourceToTraceUnit(sources, isRecursive, isFileWithMultiplePaths, includeImpd);
TraceUnitExtensionManager traceManager = TraceUnitExtensionManager.getInstance();
for (String traceUnitHandlerId : testUnitTraceIds) {
TraceHandler handler = traceManager.getTraceUnitHandlerById(traceUnitHandlerId);
if (handler != null) {
operation.addTraceUnitHandler(handler.getLocator(), handler.getParser());
}
}
return operation;
}
public static void printTraceFromTestUnits(IProgressMonitor monitor, Iterable<URI> sources, boolean isRecursive, boolean isFileWithMultiplePaths, boolean addGuidToSourceFile, boolean includeImpd, String... traceUnitHandlerIds) throws OseeCoreException {
ResourceToTraceUnit operation = getResourceToTestUnit(sources, isRecursive, isFileWithMultiplePaths,
addGuidToSourceFile, includeImpd, traceUnitHandlerIds);
if (monitor == null) {
monitor = new NullProgressMonitor();
}
operation.addTraceProcessor(new TraceUnitReportProcessor());
operation.execute(monitor);
}
public static void importTraceFromTestUnits(IProgressMonitor monitor, Iterable<URI> sources, boolean isRecursive, boolean isFileWithMultiplePaths, BranchId importToBranch, boolean addGuidToSourceFile, boolean includeImpd, String... traceUnitHandlerIds) throws OseeCoreException {
checkBranchArguments(importToBranch);
ResourceToTraceUnit operation = getResourceToTestUnit(sources, isRecursive, isFileWithMultiplePaths,
addGuidToSourceFile, includeImpd, traceUnitHandlerIds);
if (monitor == null) {
monitor = new NullProgressMonitor();
}
operation.addTraceProcessor(new TraceUnitToArtifactProcessor(importToBranch, addGuidToSourceFile));
operation.execute(monitor);
}
private static void checkTraceUnitHandlerIdsArgument(String... traceUnitHandlerIds) throws OseeCoreException {
if (traceUnitHandlerIds == null) {
throw new OseeArgumentException("Test unit trace ids was null");
}
if (traceUnitHandlerIds.length == 0) {
throw new OseeArgumentException("Test unit trace ids was empty");
}
try {
Set<String> ids = getTraceUnitHandlerIds();
List<String> notFound = Collections.setComplement(Arrays.asList(traceUnitHandlerIds), ids);
if (!notFound.isEmpty()) {
throw new OseeArgumentException("Invalid test unit trace id(s) [%s]", notFound);
}
} catch (Exception ex) {
OseeCoreException.wrapAndThrow(ex);
}
}
private static void checkSourceArgument(Iterable<URI> sources) throws OseeArgumentException {
if (sources == null) {
throw new OseeArgumentException("Source was null");
}
try {
for (URI source : sources) {
IFileStore fileStore = EFS.getStore(source);
IFileInfo fileInfo = fileStore.fetchInfo();
if (!fileInfo.exists()) {
throw new OseeArgumentException("Unable to access source: [%s]", source);
}
}
} catch (CoreException ex) {
throw new OseeArgumentException(ex);
}
}
private static void checkBranchArguments(BranchId importToBranch) throws OseeCoreException {
if (importToBranch == null) {
throw new OseeArgumentException("Branch to import into was null");
}
if (!BranchManager.getType(importToBranch).isWorkingBranch()) {
throw new OseeArgumentException("Branch to import into was not a working branch: [%s]", importToBranch);
}
}
}
|