-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
118d9be
commit eb9f9d0
Showing
10 changed files
with
164 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
cli/src/main/java/com/devonfw/tools/ide/merge/TextMerger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.devonfw.tools.ide.merge; | ||
|
||
import com.devonfw.tools.ide.context.IdeContext; | ||
import com.devonfw.tools.ide.environment.EnvironmentVariables; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
/** | ||
* Implementation of {@link FileMerger} for Text files. | ||
*/ | ||
public class TextMerger extends FileMerger { | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param context the {@link #context}. | ||
*/ | ||
public TextMerger(IdeContext context) { | ||
|
||
super(context); | ||
} | ||
|
||
@Override | ||
public void merge(Path setup, Path update, EnvironmentVariables variables, Path workspace) { | ||
|
||
Path template = update; | ||
if (!Files.exists(template)) { | ||
template = setup; | ||
assert Files.exists(template); | ||
if (Files.exists(workspace)) { | ||
return; // setup is only applied for initial setup if workspace file does not yet exist | ||
} | ||
} | ||
StringBuilder inputBuffer = new StringBuilder(); | ||
try (BufferedReader reader = Files.newBufferedReader(template)) { | ||
String line; | ||
String resolvedValue; | ||
while ((line = reader.readLine()) != null) { | ||
resolvedValue = variables.resolve(line, workspace.getFileName()); | ||
inputBuffer.append(resolvedValue); | ||
inputBuffer.append('\n'); | ||
} | ||
} catch (IOException e) { | ||
throw new IllegalStateException("Could not read text file: " + workspace, e); | ||
} | ||
try { | ||
Files.write(workspace, inputBuffer.toString().getBytes()); | ||
} catch (IOException e) { | ||
throw new IllegalStateException("Could not write to text file: " + workspace, e); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void inverseMerge(Path workspace, EnvironmentVariables variables, boolean addNewProperties, Path update) { | ||
|
||
} | ||
} |
Oops, something went wrong.