Exemple #1
0
        public override void Execute(IAbsolutePath path, AbsoluteFilePath project, IEnumerable <string> arguments)
        {
            var file = path as AbsoluteFilePath;

            if (file == null)
            {
                throw new ImportFailed("'" + path + "' does not appear to be a file");
            }

            var outputDir = project.ContainingDirectory.Combine(SketchImportUtils.OutputDirName);

            try
            {
                Directory.CreateDirectory(outputDir.NativePath);
            }
            catch (Exception e)
            {
                _reportLogger.Error("Sketch importer error: " + e.Message);
            }

            if (SketchImportUtils.IsSketchFile(file))
            {
                TryConvert(new[] { file.NativePath }, outputDir.NativePath);
            }
            else if (SketchImportUtils.IsSketchFilesFile(file))
            {
                // load sketch file paths from the json-file
                var sketchFiles = SketchImportUtils.MakeAbsolute(
                    SketchImportUtils.SketchFilePaths(SketchImportUtils.SketchListFilePath(project), _reportLogger),
                    project.ContainingDirectory).Select(f => f.NativePath).ToArray();

                TryConvert(sketchFiles, outputDir.NativePath);
            }
        }
        public void SketchListFilePathGetsCorrectPath()
        {
            var projectFilePath = _projectRoot / new FileName("Project.unoproj");
            var sketchPath      = SketchImportUtils.SketchListFilePath(projectFilePath);

            Assert.That(sketchPath, Is.EqualTo(_projectRoot / new FileName("Project.sketchFiles")));
        }
        public void SketchListFilePath_OnlyReplacesAtEnd()
        {
            var stupidProjectRoot = AbsoluteDirectoryPath.Parse(Platform.OperatingSystem == OS.Windows ? @"c:\Project.unoproj" : "/Project.unoproj");
            var projectFilePath   = stupidProjectRoot / new FileName("Project.unoproj");
            var sketchPath        = SketchImportUtils.SketchListFilePath(projectFilePath);

            Assert.That(sketchPath, Is.EqualTo(stupidProjectRoot / new FileName("Project.sketchFiles")));
        }
Exemple #4
0
        public override bool CanExecute(IAbsolutePath path, AbsoluteFilePath project)
        {
            var file = path as AbsoluteFilePath;

            if (file == null)
            {
                return(false);
            }

            return(_fileSystem.Exists(file) && _fileSystem.Exists(project) &&
                   (SketchImportUtils.IsSketchFile(file) || file.Name.HasExtension(SketchImportUtils.SketchFilesExtension)));
        }
        public void SketchFilePaths_MakePathsAbsolute()
        {
            var relPathFile = Platform.OperatingSystem == OS.Windows ? @"SketchFiles\\File1.sketch" : "SketchFiles/File1.sketch";
            var absPathFile = Platform.OperatingSystem == OS.Windows ? @"C:\\File2.sketch" : @"/File2.sketch";
            var content     = "[\"" + relPathFile + "\",\"" + absPathFile + "\"]";

            File.WriteAllText(_sketchListFile.NativePath, content);


            var report      = Substitute.For <IReport>();
            var fs          = Substitute.For <IFileSystem>();
            var sketchFiles = SketchImportUtils.MakeAbsolute(
                new SketchWatcher(report, fs).SketchFilePaths(_sketchListFile),
                _sketchListFile.ContainingDirectory);

            var expected = new List <AbsoluteFilePath>
            {
                _sketchListFile.ContainingDirectory / "SketchFiles" / new FileName("File1.sketch"),
                AbsoluteFilePath.Parse(absPathFile)
            };

            Assert.That(sketchFiles, Is.EqualTo(expected));
        }
        public void SketchListFilePath_FailsIfDoesntEndWithUnoProj()
        {
            var projectFilePath = _projectRoot / new FileName("Project.unicorn");

            Assert.That(() => SketchImportUtils.SketchListFilePath(projectFilePath), Throws.ArgumentException.With.Message.Contains("does not seem to be a .unoproj"));
        }