25
25
import java .io .File ;
26
26
import java .io .IOException ;
27
27
import java .io .StringWriter ;
28
+ import java .net .URI ;
28
29
import java .nio .file .Files ;
29
30
import java .nio .file .Path ;
31
+ import java .nio .file .Paths ;
30
32
import java .util .ArrayList ;
33
+ import java .util .Arrays ;
31
34
import java .util .HashMap ;
32
35
import java .util .Iterator ;
33
36
import java .util .List ;
@@ -211,7 +214,7 @@ public Workflow parseWorkflowNative(Path workflowFile, String packedWorkflowId)
211
214
212
215
// Construct the rest of the workflow model
213
216
Workflow workflowModel = new Workflow (label , extractDoc (cwlFile ), getInputs (cwlFile ),
214
- getOutputs (cwlFile ), getSteps (cwlFile ), null );
217
+ getOutputs (cwlFile ), getSteps (cwlFile ));
215
218
216
219
workflowModel .setCwltoolVersion (cwlTool .getVersion ());
217
220
@@ -251,7 +254,7 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel,
251
254
// Get paths to workflow
252
255
String url = basicModel .getIdentifier ();
253
256
String workflowFileURI = workflowFile .toAbsolutePath ().toUri ().toString ();
254
- String workTreeUri = workTree .toAbsolutePath ().toUri (). toString ();
257
+ URI workTreeUri = workTree .toAbsolutePath ().toUri ();
255
258
String localPath = workflowFileURI ;
256
259
String gitPath = gitDetails .getPath ();
257
260
if (packedWorkflowID != null ) {
@@ -268,7 +271,7 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel,
268
271
String rdf = cwlTool .getRDF (localPath );
269
272
// Replace /tmp/123123 with permalink base
270
273
// NOTE: We do not just replace workflowFileURI, all referenced files will also get rewritten
271
- rdf = rdf .replace (workTreeUri ,
274
+ rdf = rdf .replace (workTreeUri . toString () ,
272
275
"https://w3id.org/cwl/view/git/" + latestCommit + "/" );
273
276
// Workaround for common-workflow-language/cwltool#427
274
277
rdf = rdf .replace ("<rdfs:>" , "<http://www.w3.org/2000/01/rdf-schema#>" );
@@ -419,6 +422,22 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel,
419
422
wfSteps .put (rdfService .labelFromName (uri ), wfStep );
420
423
}
421
424
}
425
+ // Try to determine license
426
+ ResultSet licenseResult = rdfService .getLicense (url );
427
+ String licenseLink = null ;
428
+ if (licenseResult .hasNext ()) {
429
+ licenseLink = licenseResult .next ().get ("license" ).toString ();
430
+ } else {
431
+ // Check for "LICENSE"-like files in root of git repo
432
+ for (String licenseCandidate : new String []{"LICENSE" , "LICENSE.txt" , "LICENSE.md" }) {
433
+ // FIXME: This might wrongly match lower-case "license.txt" in case-insensitive file systems
434
+ // but the URL would not work
435
+ if (Files .isRegularFile (workTree .resolve (licenseCandidate ))) {
436
+ // Link to it by raw URL
437
+ licenseLink = basicModel .getRetrievedFrom ().getRawUrl (null , licenseCandidate );
438
+ }
439
+ }
440
+ }
422
441
423
442
// Docker link
424
443
ResultSet dockerResult = rdfService .getDockerLink (url );
@@ -434,7 +453,8 @@ public Workflow parseWorkflowWithCwltool(Workflow basicModel,
434
453
435
454
// Create workflow model
436
455
Workflow workflowModel = new Workflow (label , doc ,
437
- wfInputs , wfOutputs , wfSteps , dockerLink );
456
+ wfInputs , wfOutputs , wfSteps ,
457
+ dockerLink , licenseLink );
438
458
439
459
// Generate DOT graph
440
460
StringWriter graphWriter = new StringWriter ();
0 commit comments