Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

G2-1648 Implement & use file extensions as paths #39

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@

import com.g2forge.alexandria.java.core.helpers.HCollection;
import com.g2forge.alexandria.java.function.IFunction1;
import com.g2forge.alexandria.java.io.Filename;
import com.g2forge.alexandria.java.io.HPath;
import com.g2forge.alexandria.java.io.dataaccess.PathDataSink;
import com.g2forge.alexandria.java.io.dataaccess.PathDataSource;
import com.g2forge.alexandria.java.text.escape.IEscaper;
import com.g2forge.alexandria.java.text.escape.SequenceEscaper;
import com.g2forge.alexandria.media.MediaType;
import com.g2forge.alexandria.path.path.filename.Filename;
import com.g2forge.joint.core.IConversion;
import com.g2forge.joint.core.IConversionContext;
import com.g2forge.joint.core.copy.FileConversion;
Expand Down Expand Up @@ -124,8 +125,8 @@ protected String convertToTargetURI(final URI uri, final String path) {
@Override
public Path computeOutputRelative(FileConversion conversion) {
final Path inputRelative = conversion.getInputRelative();
if (new Filename(inputRelative).getFullName().equals("README")) return Filename.modifyFilename(inputRelative, "index." + MediaType.HTML.getFileExtensions().getDefaultExtension());
else return Filename.replaceLastExtension(inputRelative, MediaType.HTML.getFileExtensions().getDefaultExtension());
if (Filename.fromPath(inputRelative).getPrefix().toString().equals("README")) return HPath.replaceFilename(inputRelative, "index." + MediaType.HTML.getFileExtensions().getDefaultExtension());
else return Filename.replaceExtension(inputRelative, MediaType.HTML.getFileExtensions().getDefaultExtension());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import org.junit.rules.TestName;

import com.g2forge.alexandria.java.function.IFunction1;
import com.g2forge.alexandria.java.io.Filename;
import com.g2forge.alexandria.media.IMediaType;
import com.g2forge.alexandria.media.MediaType;
import com.g2forge.alexandria.path.path.filename.Filename;
import com.g2forge.alexandria.test.HAssert;
import com.g2forge.joint.core.ExtendedMediaType;

Expand All @@ -28,7 +28,7 @@ public class TestMD2HTMLConversionType {
if (inputMediaType == MediaType.Markdown) outputMediaType = MediaType.HTML;
else if (inputMediaType == ExtendedMediaType.PlantUML) outputMediaType = MediaType.PNG;
else outputMediaType = inputMediaType;
return (outputMediaType == null) ? path : Filename.replaceLastExtension(path, outputMediaType.getFileExtensions().getDefaultExtension());
return (outputMediaType == null) ? path : Filename.replaceExtension(path, outputMediaType.getFileExtensions().getDefaultExtension());
};

@Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

import com.g2forge.alexandria.java.core.helpers.HStream;
import com.g2forge.alexandria.java.core.marker.ISingleton;
import com.g2forge.alexandria.java.io.Filename;
import com.g2forge.alexandria.java.io.HPath;
import com.g2forge.alexandria.java.io.HTextIO;
import com.g2forge.alexandria.path.path.filename.Filename;
import com.g2forge.joint.core.IConversionContext;
import com.g2forge.joint.core.copy.FileConversion;
import com.g2forge.joint.core.copy.IFileConversionType;
Expand All @@ -33,14 +34,14 @@ protected PlantUMLConversionType() {}
@Override
public Path computeOutputRelative(FileConversion conversion) {
final Path inputRelative = conversion.getInputRelative();
final Filename filename = new Filename(inputRelative);
if (filename.getComponents().size() > 2) return Filename.modifyFilename(inputRelative, filename.getFullName());
else return Filename.modifyFilename(inputRelative, filename.getFirstName() + FileFormat.PNG.getFileSuffix());
final Filename filename = Filename.fromPath(inputRelative);
if (filename.size() > 2) return HPath.replaceFilename(inputRelative, filename.getPrefix().toString());
else return HPath.replaceFilename(inputRelative, filename.getFirst() + FileFormat.PNG.getFileSuffix());
}

@Override
public void convert(IConversionContext context, FileConversion conversion, Path input, Path output) throws IOException {
final String extension = "." + new Filename(output).getLastExtension();
final String extension = "." + Filename.fromPath(output).getLast();
final FileFormat format = HStream.findOne(Stream.of(FileFormat.values()).filter(f -> f.getFileSuffix().toLowerCase().equals(extension)));

if (!Files.isRegularFile(output) || (Files.getLastModifiedTime(output).compareTo(Files.getLastModifiedTime(input)) <= 0)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import com.g2forge.alexandria.annotations.note.NoteType;
import com.g2forge.alexandria.java.core.helpers.HCollection;
import com.g2forge.alexandria.java.function.IConsumer1;
import com.g2forge.alexandria.java.io.Filename;
import com.g2forge.alexandria.media.IMediaType;
import com.g2forge.alexandria.path.path.filename.Filename;
import com.g2forge.joint.core.IComponent;
import com.g2forge.joint.core.IConversion;
import com.g2forge.joint.core.copy.CopyComponent;
Expand Down Expand Up @@ -123,7 +123,7 @@ public void map(IConsumer1<? super IConversion> consumer) {

break;
default:
final IMediaType mediaType = getConfiguration().getRegistry().computeMediaType(new Filename(entry.getRelative()));
final IMediaType mediaType = getConfiguration().getRegistry().computeMediaType(Filename.fromPath(entry.getRelative()));
retVal.conversionType(getConfiguration().getTypes().getOrDefault(mediaType, CopyConversionType.create()));
break;
}
Expand Down
Loading