Skip to content

Commit f779b08

Browse files
laeubiChristoph Läubrich
and
Christoph Läubrich
authored
Use a TreeSet instead of HashSet to get consistent ordering of results (#352)
Currently a HashSet is used to collect the source files, this means that the order returned is unspecified and in the worst case even random across machines/jvms. In some rare cases it could happen that this even has a slight influence on the produced class files if sources are processed in different order and therefore threat reproducible builds. This now uses a TreeSet instead of a HashSet so the results are always in a deterministic order using the String#compare contract. Co-authored-by: Christoph Läubrich <[email protected]>
1 parent b59dc4c commit f779b08

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/AbstractCompiler.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
import java.io.File;
2727
import java.io.IOException;
2828
import java.util.Collections;
29-
import java.util.HashSet;
3029
import java.util.List;
3130
import java.util.Set;
31+
import java.util.TreeSet;
3232

3333
import org.codehaus.plexus.util.DirectoryScanner;
3434
import org.slf4j.Logger;
@@ -99,18 +99,22 @@ protected org.codehaus.plexus.logging.Logger getLogger() {
9999

100100
public abstract String getCompilerId();
101101

102+
@Override
102103
public CompilerResult performCompile(CompilerConfiguration configuration) throws CompilerException {
103104
throw new CompilerNotImplementedException("The performCompile method has not been implemented.");
104105
}
105106

107+
@Override
106108
public CompilerOutputStyle getCompilerOutputStyle() {
107109
return compilerOutputStyle;
108110
}
109111

112+
@Override
110113
public String getInputFileEnding(CompilerConfiguration configuration) throws CompilerException {
111114
return inputFileEnding;
112115
}
113116

117+
@Override
114118
public String getOutputFileEnding(CompilerConfiguration configuration) throws CompilerException {
115119
if (compilerOutputStyle != CompilerOutputStyle.ONE_OUTPUT_FILE_PER_INPUT_FILE) {
116120
throw new RuntimeException("This compiler implementation doesn't have one output file per input file.");
@@ -119,6 +123,7 @@ public String getOutputFileEnding(CompilerConfiguration configuration) throws Co
119123
return outputFileEnding;
120124
}
121125

126+
@Override
122127
public String getOutputFile(CompilerConfiguration configuration) throws CompilerException {
123128
if (compilerOutputStyle != CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES) {
124129
throw new RuntimeException("This compiler implementation doesn't have one output file for all files.");
@@ -127,6 +132,7 @@ public String getOutputFile(CompilerConfiguration configuration) throws Compiler
127132
return outputFile;
128133
}
129134

135+
@Override
130136
public boolean canUpdateTarget(CompilerConfiguration configuration) throws CompilerException {
131137
return true;
132138
}
@@ -174,7 +180,7 @@ protected static Set<String> getSourceFilesForSourceRoot(CompilerConfiguration c
174180

175181
String[] sourceDirectorySources = scanner.getIncludedFiles();
176182

177-
Set<String> sources = new HashSet<>();
183+
Set<String> sources = new TreeSet<>();
178184

179185
for (String sourceDirectorySource : sourceDirectorySources) {
180186
File f = new File(sourceLocation, sourceDirectorySource);
@@ -186,7 +192,7 @@ protected static Set<String> getSourceFilesForSourceRoot(CompilerConfiguration c
186192
}
187193

188194
protected static String[] getSourceFiles(CompilerConfiguration config) {
189-
Set<String> sources = new HashSet<>();
195+
Set<String> sources = new TreeSet<>();
190196

191197
Set<File> sourceFiles = config.getSourceFiles();
192198

0 commit comments

Comments
 (0)