22
22
23
23
package msBuildTask ;
24
24
25
- import java .util .concurrent .Callable ;
26
- import java .util .logging .Level ;
27
- import java .util .logging .Logger ;
25
+ import java .nio .file .Paths ;
28
26
29
27
import discUtils .iso9660 .BootDeviceEmulation ;
30
28
import discUtils .iso9660 .CDBuilder ;
31
29
import dotnet4j .io .FileAccess ;
32
30
import dotnet4j .io .FileMode ;
33
31
import dotnet4j .io .FileStream ;
34
32
import dotnet4j .io .Stream ;
33
+ import org .apache .maven .plugin .MojoExecutionException ;
34
+ import org .apache .maven .plugin .MojoFailureException ;
35
+ import org .apache .maven .plugin .logging .Log ;
36
+ import org .apache .maven .plugins .annotations .LifecyclePhase ;
37
+ import org .apache .maven .plugins .annotations .Mojo ;
35
38
36
39
37
- public class CreateIso implements Callable {
38
- static final Logger logger = Logger .getLogger (CreateIso .class .getName ());
40
+ @ Mojo (name = "discutil-plugin-create-iso" , defaultPhase = LifecyclePhase .GENERATE_RESOURCES )
41
+ public class CreateIso implements org .apache .maven .plugin .Mojo {
42
+
43
+ private Log log ;
39
44
40
45
public CreateIso () {
41
- setUseJoliet ( true ) ;
46
+ useJoliet = true ;
42
47
}
43
48
44
49
/**
45
50
* The name of the ISO file to create.
46
51
*/
47
- private ITaskItem fileName ;
52
+ private String fileName ;
48
53
49
- public ITaskItem getFileName () {
54
+ public String getFileName () {
50
55
return fileName ;
51
56
}
52
57
53
- public void setFileName (ITaskItem value ) {
58
+ public void setFileName (String value ) {
54
59
fileName = value ;
55
60
}
56
61
@@ -83,26 +88,26 @@ public void setVolumeLabel(String value) {
83
88
/**
84
89
* The files to add to the ISO.
85
90
*/
86
- private ITaskItem [] sourceFiles ;
91
+ private String [] sourceFiles ;
87
92
88
- public ITaskItem [] getSourceFiles () {
93
+ public String [] getSourceFiles () {
89
94
return sourceFiles ;
90
95
}
91
96
92
- public void setSourceFiles (ITaskItem [] value ) {
97
+ public void setSourceFiles (String [] value ) {
93
98
sourceFiles = value ;
94
99
}
95
100
96
101
/**
97
102
* The boot image to add to the ISO.
98
103
*/
99
- private ITaskItem bootImage ;
104
+ private String bootImage ;
100
105
101
- public ITaskItem getBootImage () {
106
+ public String getBootImage () {
102
107
return bootImage ;
103
108
}
104
109
105
- public void setBootImage (ITaskItem value ) {
110
+ public void setBootImage (String value ) {
106
111
bootImage = value ;
107
112
}
108
113
@@ -127,18 +132,34 @@ public void setUpdateIsolinuxBootTable(boolean value) {
127
132
* If the source file is C:\MyDir\MySubDir\file.txt, and RemoveRoot is C:\MyDir, the ISO will
128
133
* contain \MySubDir\file.txt. If not specified, the file would be named \MyDir\MySubDir\file.txt.
129
134
*/
130
- private ITaskItem [] removeRoots = new ITaskItem [1 ];
135
+ private String [] removeRoots = new String [1 ];
131
136
132
- public ITaskItem [] getRemoveRoots () {
137
+ public String [] getRemoveRoots () {
133
138
return removeRoots ;
134
139
}
135
140
136
- public void setRemoveRoots (ITaskItem [] value ) {
141
+ public void setRemoveRoots (String [] value ) {
137
142
removeRoots = value ;
138
143
}
139
144
140
- public Boolean call () {
141
- logger .info ("Creating ISO file: '%s'" , getFileName ().ItemSpec );
145
+ private String getDestinationPath (String sourceFile ) {
146
+ String fullPath = Paths .get (sourceFile ).toAbsolutePath ().toString ();
147
+ if (getRemoveRoots () != null ) {
148
+ for (String root : getRemoveRoots ()) {
149
+ String rootPath = Paths .get (root ).toAbsolutePath ().toString ();
150
+ if (fullPath .startsWith (rootPath )) {
151
+ return fullPath .substring (rootPath .length ());
152
+ }
153
+ }
154
+ }
155
+
156
+ // Not under a known root - so full path (minus drive)...
157
+ return sourceFile ;
158
+ }
159
+
160
+ @ Override
161
+ public void execute () throws MojoExecutionException , MojoFailureException {
162
+ log .info (String .format ("Creating ISO file: '%s'" , fileName ));
142
163
try {
143
164
CDBuilder builder = new CDBuilder ();
144
165
builder .setUseJoliet (getUseJoliet ());
@@ -148,42 +169,33 @@ public Boolean call() {
148
169
149
170
Stream bootImageStream = null ;
150
171
if (getBootImage () != null ) {
151
- bootImageStream = new FileStream (getBootImage (). GetMetadata ( "FullPath" ), FileMode .Open , FileAccess .Read );
172
+ bootImageStream = new FileStream (Paths . get ( bootImage ). toAbsolutePath (). toString ( ), FileMode .Open , FileAccess .Read );
152
173
builder .setBootImage (bootImageStream , BootDeviceEmulation .NoEmulation , 0 );
153
174
builder .setUpdateIsolinuxBootTable (getUpdateIsolinuxBootTable ());
154
175
}
155
176
156
- for (ITaskItem sourceFile : getSourceFiles ()) {
157
- builder .addFile (GetDestinationPath (sourceFile ), sourceFile . getMetadata ( "FullPath" ));
177
+ for (String sourceFile : getSourceFiles ()) {
178
+ builder .addFile (getDestinationPath (sourceFile ), Paths . get ( sourceFile ). toAbsolutePath (). toString ( ));
158
179
}
159
180
try {
160
- builder .Build ( getFileName (). ItemSpec );
181
+ builder .build ( fileName );
161
182
} finally {
162
183
if (bootImageStream != null ) {
163
184
bootImageStream .close ();
164
185
}
165
-
166
186
}
167
187
} catch (Exception e ) {
168
- logger .log (Level .SEVERE , e .getMessage (), e );
169
- return false ;
188
+ log .error (e .getMessage (), e );
170
189
}
171
-
172
- return !logger .HasLoggedErrors ;
173
190
}
174
191
175
- private String getDestinationPath (ITaskItem sourceFile ) {
176
- String fullPath = sourceFile .GetMetadata ("FullPath" );
177
- if (getRemoveRoots () != null ) {
178
- for (Callable root : getRemoveRoots ()) {
179
- String rootPath = root .getMetadata ("FullPath" );
180
- if (fullPath .startsWith (rootPath )) {
181
- return fullPath .substring (rootPath .length ());
182
- }
183
- }
184
- }
192
+ @ Override
193
+ public void setLog (Log log ) {
194
+ this .log = log ;
195
+ }
185
196
186
- // Not under a known root - so full path (minus drive)...
187
- return sourceFile .getMetadata ("Directory" ) + sourceFile .getMetadata ("FileName" ) + sourceFile .getMetadata ("Extension" );
197
+ @ Override
198
+ public Log getLog () {
199
+ return log ;
188
200
}
189
201
}
0 commit comments