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

[GAL-352] Add system property to control line endings #332

Merged
merged 1 commit into from
Oct 12, 2023
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
3 changes: 2 additions & 1 deletion core/src/main/java/org/jboss/galleon/Constants.java
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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";
Expand Down
16 changes: 13 additions & 3 deletions core/src/main/java/org/jboss/galleon/ProvisioningManager.java
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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<Builder> {
private Path installationHome;
private ProvisioningLayoutFactory layoutFactory;
Expand Down Expand Up @@ -874,9 +876,9 @@ private void persistChildHashes(Path hashes, FsEntry entry, List<FsEntry> 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;
Expand All @@ -898,4 +900,12 @@ private void persistChildHashes(Path hashes, FsEntry entry, List<FsEntry> dirs,
--dirsTotal;
}
}

private void newLine(BufferedWriter writer) throws IOException {
if (useLinuxLineEndings) {
writer.write("\n");
} else {
writer.newLine();
}
}
}
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand Down