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
|
package org.openslx.taskmanager.tasks;
import java.util.ArrayList;
import java.util.List;
import org.openslx.satserver.util.Exec;
import org.openslx.satserver.util.Util;
import org.openslx.satserver.util.Exec.ExecCallback;
import org.openslx.taskmanager.api.SystemCommandTask;
import com.google.gson.annotations.Expose;
public class IpxeVersion extends SystemCommandTask
{
/* FOR COMMIT PICKING
* git log --pretty=format:"%H %at" --first-parent a58276abdd..openslx
*/
@Expose
private Action action;
@Expose
private String ref;
private Status status = new Status();
@Override
protected String[] initCommandLine()
{
List<String> args = new ArrayList<>();
args.add( "git" );
args.add( "-C" );
args.add( "/opt/openslx/ipxe" );
switch ( action ) {
case CHECKOUT:
args.add( "checkout" );
args.add( ref );
break;
case LIST:
EC vec = new EC();
Exec.syncAt( 1, vec, "/", "gcc", "-dumpversion" );
String start;
if ( vec.version >= 10 ) {
// Versions before this commit won't build with gcc 10
start = "a098f40893";
} else {
start = "a58276abdd";
}
args.add( "log" );
args.add( "--pretty=format:%H %at" );
args.add( "--first-parent" );
args.add( start + "..origin/openslx" );
status.versions = new ArrayList<Version>();
break;
case FETCH:
args.add( "fetch" );
break;
case RESET:
args.add( "reset" );
args.add( "--hard" );
break;
}
return args.toArray( new String[ args.size() ] );
}
@Override
protected boolean processEnded( int exitCode )
{
if ( exitCode != 0 && status.error == null ) {
status.error = "Exit code: " + exitCode;
}
return exitCode == 0;
}
@Override
protected void processStdOut( String line )
{
if ( action == Action.LIST ) {
String[] parts = line.split( " " );
if ( parts.length == 2 && parts[0].length() == 40 && parts[1].length() == 10 ) {
long d = Util.parseLong( parts[1], 0 );
if ( d != 0 ) {
status.versions.add( new Version( parts[0], d ) );
}
}
} else {
processStdErr( line );
}
}
@Override
protected void processStdErr( String line )
{
if ( status.error == null ) {
status.error = line;
} else {
status.error += "\n" + line;
}
}
@Override
protected boolean initTask()
{
setStatusObject( status );
if ( action == null || ( action == Action.CHECKOUT && ref == null ) ) {
status.error = "action or commit is null";
return false;
}
status.ref = ref;
return true;
}
static class EC implements ExecCallback
{
public int version = 0;
@Override
public void processStdOut( String line )
{
if ( line.matches( "[0-9].*" ) ) {
version = Util.parseInt( line.replaceAll( "[^0-9].*$", "" ), 0 );
}
}
@Override
public void processStdErr( String line )
{
}
}
static enum Action
{
FETCH, RESET, CHECKOUT, LIST;
}
static class Version
{
public String hash;
public long date;
public Version( String hash, long date )
{
this.date = date;
this.hash = hash;
}
}
static class Status
{
public String error;
public List<Version> versions;
public String ref;
}
}
|