Skip to content

Commit d8db0dd

Browse files
Adopt FileLike for more pipeline APIs (#394)
1 parent b5baa83 commit d8db0dd

File tree

12 files changed

+53
-41
lines changed

12 files changed

+53
-41
lines changed

SequenceAnalysis/src/org/labkey/sequenceanalysis/pipeline/AlignmentInitTask.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.labkey.sequenceanalysis.pipeline;
22

3+
import org.jetbrains.annotations.NotNull;
34
import org.labkey.api.pipeline.PipelineJob;
45
import org.labkey.api.pipeline.PipelineJobException;
56
import org.labkey.api.pipeline.RecordedAction;
@@ -98,7 +99,7 @@ private SequenceAlignmentJob getPipelineJob()
9899
}
99100

100101
@Override
101-
public RecordedActionSet run() throws PipelineJobException
102+
public @NotNull RecordedActionSet run() throws PipelineJobException
102103
{
103104
_taskHelper = new SequenceTaskHelper(getPipelineJob(), _wd);
104105

SequenceAnalysis/src/org/labkey/sequenceanalysis/pipeline/ImportFastaSequencesTask.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.labkey.sequenceanalysis.pipeline;
1717

1818
import org.apache.commons.lang3.StringUtils;
19+
import org.jetbrains.annotations.NotNull;
1920
import org.labkey.api.pipeline.AbstractTaskFactory;
2021
import org.labkey.api.pipeline.AbstractTaskFactorySettings;
2122
import org.labkey.api.pipeline.PipelineJob;
@@ -84,7 +85,7 @@ public boolean isJobComplete(PipelineJob job)
8485
}
8586

8687
@Override
87-
public RecordedActionSet run() throws PipelineJobException
88+
public @NotNull RecordedActionSet run() throws PipelineJobException
8889
{
8990
getJob().getLogger().info("Importing sequences from file(s): ");
9091
for (File f : getPipelineJob().getFastas())

SequenceAnalysis/src/org/labkey/sequenceanalysis/pipeline/ImportGenomeTrackTask.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.apache.commons.io.FileUtils;
3333
import org.apache.commons.lang3.StringUtils;
3434
import org.apache.commons.lang3.SystemUtils;
35+
import org.jetbrains.annotations.NotNull;
3536
import org.jetbrains.annotations.Nullable;
3637
import org.labkey.api.collections.CaseInsensitiveHashMap;
3738
import org.labkey.api.data.CompareType;
@@ -136,7 +137,7 @@ public boolean isJobComplete(PipelineJob job)
136137
}
137138

138139
@Override
139-
public RecordedActionSet run() throws PipelineJobException
140+
public @NotNull RecordedActionSet run() throws PipelineJobException
140141
{
141142
getJob().getLogger().info("Importing tracks from file(s): ");
142143
RecordedAction action = new RecordedAction(ACTION_NAME);

SequenceAnalysis/src/org/labkey/sequenceanalysis/pipeline/SequenceJob.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,9 @@ protected void addCustomParams(JSONObject params)
161161
params.put("labkeyFolderPath", getContainer().isWorkbook() ? getContainer().getParent().getPath() : getContainer().getPath());
162162
}
163163

164-
private Path _getLogFile()
164+
private FileLike _getLogFile()
165165
{
166-
var file = FileUtil.findUniqueFileName((FileUtil.makeLegalName(_jobName) + ".log"), getDataDirectoryFileObject());
167-
return file.toNioPathForWrite();
166+
return FileUtil.findUniqueFileName((FileUtil.makeLegalName(_jobName) + ".log"), getDataDirectoryFileObject());
168167
}
169168

170169
@Override
@@ -342,9 +341,9 @@ public String getBaseNameForFileType(FileType fileType)
342341
}
343342

344343
@Override
345-
public File getDataDirectory()
344+
public FileLike getDataDirectoryFileLike()
346345
{
347-
return _webserverJobDir.toNioPathForWrite().toFile();
346+
return _webserverJobDir;
348347
}
349348

350349
public FileLike getDataDirectoryFileObject()
@@ -397,13 +396,6 @@ public File getParametersFile()
397396
return FileUtil.appendName(dir.toNioPathForWrite().toFile(),_folderPrefix + ".json");
398397
}
399398

400-
@Nullable
401-
@Override
402-
public File getJobInfoFile()
403-
{
404-
return FileUtil.appendName(_webserverJobDir.toNioPathForWrite().toFile(), FileUtil.makeLegalName(_jobName) + ".job.json");
405-
}
406-
407399
@Override
408400
public FileType.gzSupportLevel getGZPreference()
409401
{

SequenceAnalysis/src/org/labkey/sequenceanalysis/pipeline/SequenceOutputHandlerFinalTask.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.labkey.sequenceanalysis.pipeline;
22

3+
import org.jetbrains.annotations.NotNull;
34
import org.jetbrains.annotations.Nullable;
45
import org.labkey.api.data.CompareType;
56
import org.labkey.api.data.SimpleFilter;
@@ -85,7 +86,7 @@ private SequenceOutputHandlerJob getPipelineJob()
8586
}
8687

8788
@Override
88-
public RecordedActionSet run() throws PipelineJobException
89+
public @NotNull RecordedActionSet run() throws PipelineJobException
8990
{
9091
Long runId = SequenceTaskHelper.getExpRunIdForJob(getJob());
9192
getPipelineJob().setExperimentRunRowId(runId);

SequenceAnalysis/src/org/labkey/sequenceanalysis/pipeline/SequenceReadsetHandlerFinalTask.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.labkey.sequenceanalysis.pipeline;
22

3+
import org.jetbrains.annotations.NotNull;
34
import org.labkey.api.pipeline.AbstractTaskFactory;
45
import org.labkey.api.pipeline.AbstractTaskFactorySettings;
56
import org.labkey.api.pipeline.PipelineJob;
@@ -69,7 +70,7 @@ private SequenceReadsetHandlerJob getPipelineJob()
6970
}
7071

7172
@Override
72-
public RecordedActionSet run() throws PipelineJobException
73+
public @NotNull RecordedActionSet run() throws PipelineJobException
7374
{
7475
Long runId = SequenceTaskHelper.getExpRunIdForJob(getJob());
7576
getPipelineJob().setExperimentRunRowId(runId);

SequenceAnalysis/src/org/labkey/sequenceanalysis/pipeline/VariantProcessingJob.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import org.labkey.api.writer.PrintWriters;
3838
import org.labkey.sequenceanalysis.util.ScatterGatherUtils;
3939
import org.labkey.sequenceanalysis.util.SequenceUtil;
40+
import org.labkey.vfs.FileLike;
41+
import org.labkey.vfs.FileSystemLike;
4042

4143
import java.io.File;
4244
import java.io.IOException;
@@ -408,9 +410,9 @@ public void intervalSerializeTest() throws Exception
408410
{
409411
VariantProcessingJob job1 = new VariantProcessingJob(){
410412
@Override
411-
public File getDataDirectory()
413+
public FileLike getDataDirectoryFileLike()
412414
{
413-
return new File(System.getProperty("java.io.tmpdir"));
415+
return FileSystemLike.wrapFile(new File(System.getProperty("java.io.tmpdir")));
414416
}
415417
};
416418

SequenceAnalysis/test/src/org/labkey/test/tests/external/labModules/SequenceTest.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.junit.Assert;
2424
import org.junit.Test;
2525
import org.junit.experimental.categories.Category;
26+
import org.labkey.api.util.FileUtil;
2627
import org.labkey.remoteapi.CommandException;
2728
import org.labkey.remoteapi.Connection;
2829
import org.labkey.remoteapi.query.Filter;
@@ -295,13 +296,22 @@ private void createIlluminaSampleSheet()
295296
assertTextPresent(fileSearcher, prop_name + "," + prop_value);
296297

297298
File fileRoot = TestFileUtils.getDefaultFileRoot(getProjectName());
298-
File importTemplate = new File(fileRoot, ILLUMINA_CSV);
299+
File importTemplate = FileUtil.appendName(fileRoot, ILLUMINA_CSV);
299300
if (importTemplate.exists())
300301
importTemplate.delete();
301302

302303

303304
//NOTE: use the text generated directly using JS
304-
TestFileUtils.saveFile(importTemplate.getParentFile(), importTemplate.getName(), outputTable);
305+
File tsvFile = FileUtil.appendName(importTemplate.getParentFile(), importTemplate.getName());
306+
307+
try
308+
{
309+
TestFileUtils.writeFile(tsvFile, outputTable);
310+
}
311+
catch (IOException e)
312+
{
313+
e.printStackTrace(System.err);
314+
}
305315
goToProjectHome();
306316
}
307317

@@ -330,7 +340,7 @@ private void importIlluminaTest() throws Exception
330340
File fileRoot = TestFileUtils.getDefaultFileRoot(getProjectName());
331341
for (String fn : Arrays.asList("Illumina-F.fastq.gz", "Illumina-R.fastq.gz", "SkipMe.fastq.gz"))
332342
{
333-
File target = new File(fileRoot, fn);
343+
File target = FileUtil.appendName(fileRoot, fn);
334344
if (target.exists())
335345
{
336346
target.delete();
@@ -749,7 +759,7 @@ private void alignmentImportPanelTest(boolean sequencePipelineEnabled) throws Ex
749759
File fileRoot = TestFileUtils.getDefaultFileRoot(getProjectName());
750760
log("file root: " + fileRoot.getPath());
751761

752-
File inputBam = new File(fileRoot, "test.bam");
762+
File inputBam = FileUtil.appendName(fileRoot, "test.bam");
753763
File inputBamIdx = new File(inputBam.getPath() + ".bai");
754764
if (inputBam.exists())
755765
{
@@ -763,8 +773,8 @@ private void alignmentImportPanelTest(boolean sequencePipelineEnabled) throws Ex
763773
inputBamIdx.delete();
764774
}
765775

766-
FileUtils.copyFile(new File(_sampleData, "test.bam"), inputBam);
767-
FileUtils.copyFile(new File(_sampleData, "test.bam.bai"), inputBamIdx);
776+
FileUtils.copyFile(FileUtil.appendName(_sampleData, "test.bam"), inputBam);
777+
FileUtils.copyFile(FileUtil.appendName(_sampleData, "test.bam.bai"), inputBamIdx);
768778

769779
_helper.initiatePipelineJob(_alignmentImportPipelineName, List.of(inputBam.getName()), getProjectName());
770780
waitForText("Job Name");

Studies/src/org/labkey/studies/StudiesServiceImpl.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
import org.labkey.api.util.Path;
2626
import org.labkey.api.util.logging.LogHelper;
2727
import org.labkey.studies.query.StudiesTableCustomizer;
28+
import org.labkey.vfs.FileLike;
2829

2930
import java.io.FileNotFoundException;
3031
import java.io.IOException;
3132
import java.io.InputStream;
3233
import java.io.OutputStream;
33-
import java.nio.file.Files;
3434
import java.sql.SQLException;
3535
import java.util.HashMap;
3636
import java.util.List;
@@ -56,28 +56,28 @@ public void importFolderDefinition(Container container, User user, Module m, Pat
5656
{
5757
Resource root = m.getModuleResource(sourceFolderDirPath);
5858
PipeRoot pipeRoot = PipelineService.get().findPipelineRoot(container);
59-
java.nio.file.Path pipeRootPath = pipeRoot.getRootNioPath();
59+
FileLike pipeRootPath = pipeRoot.getRootFileLike();
6060

61-
java.nio.file.Path folderXmlPath;
61+
FileLike folderXmlPath;
6262

63-
if (root instanceof DirectoryResource && ((DirectoryResource)root).getDir().equals(pipeRootPath.toFile()))
63+
if (root instanceof DirectoryResource dir && dir.getDir().equals(pipeRootPath.toNioPathForRead().toFile()))
6464
{
6565
// The pipeline root is already pointed at the folder definition, like it might be on a dev machine.
6666
// No need to copy, especially since copying can cause infinite recursion when the paths are nested
67-
folderXmlPath = pipeRootPath.resolve("folder.xml");
67+
folderXmlPath = pipeRootPath.resolveChild("folder.xml");
6868
}
6969
else
7070
{
71-
java.nio.file.Path folderPath = pipeRootPath.resolve("moduleFolderImport");
72-
folderXmlPath = folderPath.resolve("folder.xml");
73-
if (Files.exists(folderPath))
71+
FileLike folderPath = pipeRootPath.resolveChild("moduleFolderImport");
72+
folderXmlPath = folderPath.resolveChild("folder.xml");
73+
if (folderPath.exists())
7474
{
7575
FileUtil.deleteDir(folderPath);
7676
}
7777
copyResourceToPath(root, folderPath);
7878
}
7979

80-
if (!Files.exists(folderXmlPath))
80+
if (!folderXmlPath.exists())
8181
{
8282
throw new FileNotFoundException("Couldn't find an extracted " + folderXmlPath);
8383
}
@@ -87,21 +87,21 @@ public void importFolderDefinition(Container container, User user, Module m, Pat
8787
PipelineService.get().runFolderImportJob(container, user, null, folderXmlPath, "folder.xml", pipeRoot, options);
8888
}
8989

90-
private void copyResourceToPath(Resource resource, java.nio.file.Path target) throws IOException
90+
private void copyResourceToPath(Resource resource, FileLike target) throws IOException
9191
{
9292
if (resource.isCollection())
9393
{
94-
Files.createDirectory(target);
94+
FileUtil.createDirectory(target);
9595
for (Resource child : resource.list())
9696
{
97-
java.nio.file.Path childTarget = target.resolve(child.getName());
97+
FileLike childTarget = target.resolveChild(child.getName());
9898
copyResourceToPath(child, childTarget);
9999
}
100100
}
101101
else
102102
{
103103
try (InputStream in = resource.getInputStream();
104-
OutputStream out = Files.newOutputStream(target))
104+
OutputStream out = target.openOutputStream())
105105
{
106106
FileUtil.copyData(in, out);
107107
}

blast/src/org/labkey/blast/pipeline/BlastDatabaseTask.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.labkey.blast.pipeline;
1717

18+
import org.jetbrains.annotations.NotNull;
1819
import org.labkey.api.pipeline.AbstractTaskFactory;
1920
import org.labkey.api.pipeline.AbstractTaskFactorySettings;
2021
import org.labkey.api.pipeline.PipelineJob;
@@ -88,7 +89,7 @@ public boolean isJobComplete(PipelineJob job)
8889
}
8990

9091
@Override
91-
public RecordedActionSet run() throws PipelineJobException
92+
public @NotNull RecordedActionSet run() throws PipelineJobException
9293
{
9394
getJob().getLogger().info("creating BLAST database for library: " + getPipelineJob().getLibraryId());
9495

0 commit comments

Comments
 (0)