diff --git a/core/src/main/java/org/jboss/galleon/Constants.java b/core/src/main/java/org/jboss/galleon/Constants.java index e991a5b11..e559c206d 100644 --- a/core/src/main/java/org/jboss/galleon/Constants.java +++ b/core/src/main/java/org/jboss/galleon/Constants.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 Red Hat, Inc. and/or its affiliates + * Copyright 2016-2023 Red Hat, Inc. and/or its affiliates * and other contributors as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -64,6 +64,7 @@ public interface Constants { // SYSTEM PROPERTIES String PROP_CONFIG_ARRANGER = "galleon.config.arranger"; + String PROP_LINUX_LINE_ENDINGS = "galleon.config.use_linux_line_endings"; // CONFIG ARRANGERS String CONFIG_ARRANGER_SPEC_ONLY = "spec-only"; diff --git a/core/src/main/java/org/jboss/galleon/ProvisioningManager.java b/core/src/main/java/org/jboss/galleon/ProvisioningManager.java index 87105b2e8..3012698de 100644 --- a/core/src/main/java/org/jboss/galleon/ProvisioningManager.java +++ b/core/src/main/java/org/jboss/galleon/ProvisioningManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 Red Hat, Inc. and/or its affiliates + * Copyright 2016-2023 Red Hat, Inc. and/or its affiliates * and other contributors as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -66,6 +66,8 @@ */ public class ProvisioningManager implements AutoCloseable { + private final boolean useLinuxLineEndings = Boolean.getBoolean(Constants.PROP_LINUX_LINE_ENDINGS); + public static class Builder extends UniverseResolverBuilder { private Path installationHome; private ProvisioningLayoutFactory layoutFactory; @@ -874,9 +876,9 @@ private void persistChildHashes(Path hashes, FsEntry entry, List dirs, writer = Files.newBufferedWriter(target.resolve(Constants.HASHES)); } writer.write(child.getName()); - writer.newLine(); + newLine(writer); writer.write(HashUtils.bytesToHexString(child.getHash())); - writer.newLine(); + newLine(writer); } else { dirs.add(child); ++dirsTotal; @@ -898,4 +900,12 @@ private void persistChildHashes(Path hashes, FsEntry entry, List dirs, --dirsTotal; } } + + private void newLine(BufferedWriter writer) throws IOException { + if (useLinuxLineEndings) { + writer.write("\n"); + } else { + writer.newLine(); + } + } } diff --git a/core/src/main/java/org/jboss/galleon/xml/util/FormattingXmlStreamWriter.java b/core/src/main/java/org/jboss/galleon/xml/util/FormattingXmlStreamWriter.java index 54f0d287d..4c381479d 100644 --- a/core/src/main/java/org/jboss/galleon/xml/util/FormattingXmlStreamWriter.java +++ b/core/src/main/java/org/jboss/galleon/xml/util/FormattingXmlStreamWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 Red Hat, Inc. and/or its affiliates + * Copyright 2016-2023 Red Hat, Inc. and/or its affiliates * and other contributors as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,6 +17,8 @@ package org.jboss.galleon.xml.util; +import org.jboss.galleon.Constants; + import java.util.ArrayDeque; import java.util.Iterator; import java.util.NoSuchElementException; @@ -35,6 +37,7 @@ */ public final class FormattingXmlStreamWriter implements XMLStreamWriter, XMLStreamConstants, AutoCloseable { private static final String NO_NAMESPACE = new String(); + private final boolean useLinuxLineEndings = Boolean.getBoolean(Constants.PROP_LINUX_LINE_ENDINGS); private final XMLStreamWriter delegate; private int level; private int state = START_DOCUMENT; @@ -48,7 +51,11 @@ public FormattingXmlStreamWriter(final XMLStreamWriter delegate) { } private void nl() throws XMLStreamException { - delegate.writeCharacters(System.lineSeparator()); + if (useLinuxLineEndings) { + delegate.writeCharacters("\n"); + } else { + delegate.writeCharacters(System.lineSeparator()); + } } private void indent() throws XMLStreamException {