Skip to content

Commit

Permalink
Merge pull request #332 from spyrkob/line_endings_5.1
Browse files Browse the repository at this point in the history
[GAL-352] Add system property to control line endings
  • Loading branch information
jfdenise authored Oct 12, 2023
2 parents 83a826b + 882c410 commit 25cc992
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
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

0 comments on commit 25cc992

Please sign in to comment.