/
ConfigureArchiveTypes.java
79 lines (63 loc) · 2.85 KB
/
ConfigureArchiveTypes.java
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
package org.jboss.windup.config.operation.ruleelement;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.jboss.forge.furnace.services.Imported;
import org.jboss.windup.config.GraphRewrite;
import org.jboss.windup.config.selectables.SelectionFactory;
import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.graph.GraphUtil;
import org.jboss.windup.graph.model.ArchiveModel;
import org.jboss.windup.graph.model.ArchiveModelPointer;
import org.jboss.windup.graph.model.WindupVertexFrame;
import org.ocpsoft.rewrite.context.EvaluationContext;
public class ConfigureArchiveTypes extends AbstractIterationOperator<ArchiveModel>
{
//@Inject
private Imported<ArchiveModelPointer> archiveModelPointers;
private HashMap<String, Class> suffixToModelClass;
public ConfigureArchiveTypes(String variableName, Imported<ArchiveModelPointer> archiveModelPointers)
{
super(ArchiveModel.class, variableName);
this.archiveModelPointers = archiveModelPointers;
}
public static ConfigureArchiveTypes forVar(String variableName, Imported<ArchiveModelPointer> archiveModelPointers)
{
return new ConfigureArchiveTypes(variableName, archiveModelPointers);
}
@Override
public void perform(GraphRewrite event, EvaluationContext context, ArchiveModel archiveModel)
{
GraphContext graphContext = event.getGraphContext();
String filename = archiveModel.getArchiveName();
WindupVertexFrame newFrame = null;
for( Map.Entry<String, Class> entry : suffixToModelClass.entrySet() ) {
if( StringUtils.endsWith( filename, entry.getKey() ) ){
newFrame = GraphUtil.addTypeToModel(graphContext, archiveModel, entry.getValue());
}
}
/*
if (StringUtils.endsWith(filename, ".jar"))
{
newFrame = GraphUtil.addTypeToModel(graphContext, archiveModel, JarArchiveModel.class);
}
else if (StringUtils.endsWith(filename, ".war"))
{
newFrame = GraphUtil.addTypeToModel(graphContext, archiveModel, WarArchiveModel.class);
}
else if (StringUtils.endsWith(filename, ".ear"))
{
newFrame = GraphUtil.addTypeToModel(graphContext, archiveModel, EarArchiveModel.class);
}/**/
if (newFrame != null)
{
SelectionFactory.instance(event).setCurrentPayload(getVariableName(), newFrame);
}
}
private void initTypes() {
//Imported<ArchiveModelPointer> pointers = FurnaceHolder.getFurnace().getAddonRegistry().getServices(ArchiveModelPointer.class);
for( ArchiveModelPointer ptr : this.archiveModelPointers ) {
this.suffixToModelClass.put( ptr.getArchiveFileSuffix(), ptr.getModelClass() );
}
}
}