-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
105 additions
and
32 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
59 changes: 59 additions & 0 deletions
59
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,59 @@ | ||
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) { | ||
|
||
if (Files.exists(update)) { | ||
copy(update, workspace); | ||
} else if (Files.exists(setup) && !Files.exists(workspace)) { | ||
copy(setup, workspace); | ||
} | ||
|
||
StringBuilder inputBuffer = new StringBuilder(); | ||
try (BufferedReader reader = Files.newBufferedReader(update)) { | ||
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) { | ||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
${IDE_HOME} - main | ||
test |
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,2 @@ | ||
${IDE_HOME} - main | ||
test |