33
33
import com .devonfw .tools .ide .io .FileAccessImpl ;
34
34
import com .devonfw .tools .ide .log .IdeLogLevel ;
35
35
import com .devonfw .tools .ide .log .IdeLogger ;
36
- import com .devonfw .tools .ide .log .IdeLoggerImpl ;
37
36
import com .devonfw .tools .ide .log .IdeSubLogger ;
38
37
import com .devonfw .tools .ide .merge .DirectoryMerger ;
39
38
import com .devonfw .tools .ide .network .ProxyContext ;
51
50
import com .devonfw .tools .ide .step .Step ;
52
51
import com .devonfw .tools .ide .step .StepImpl ;
53
52
import com .devonfw .tools .ide .url .model .UrlMetadata ;
53
+ import com .devonfw .tools .ide .variable .IdeVariables ;
54
54
55
55
/**
56
56
* Abstract base implementation of {@link IdeContext}.
@@ -59,7 +59,7 @@ public abstract class AbstractIdeContext implements IdeContext {
59
59
60
60
private static final String IDE_URLS_GIT = "https://github.com/devonfw/ide-urls.git" ;
61
61
62
- private final IdeLoggerImpl logger ;
62
+ private final IdeStartContextImpl startContext ;
63
63
64
64
private Path ideHome ;
65
65
@@ -115,16 +115,6 @@ public abstract class AbstractIdeContext implements IdeContext {
115
115
116
116
private DirectoryMerger workspaceMerger ;
117
117
118
- private boolean offlineMode ;
119
-
120
- private boolean forceMode ;
121
-
122
- private boolean batchMode ;
123
-
124
- private boolean quietMode ;
125
-
126
- private Locale locale ;
127
-
128
118
private UrlMetadata urlMetadata ;
129
119
130
120
private Path defaultExecutionDirectory ;
@@ -134,15 +124,15 @@ public abstract class AbstractIdeContext implements IdeContext {
134
124
/**
135
125
* The constructor.
136
126
*
137
- * @param logger the {@link IdeLogger}.
127
+ * @param startContext the {@link IdeLogger}.
138
128
* @param userDir the optional {@link Path} to current working directory.
139
129
* @param toolRepository @param toolRepository the {@link ToolRepository} of the context. If it is set to {@code null} {@link DefaultToolRepository} will
140
130
* be used.
141
131
*/
142
- public AbstractIdeContext (IdeLoggerImpl logger , Path userDir , ToolRepository toolRepository ) {
132
+ public AbstractIdeContext (IdeStartContextImpl startContext , Path userDir , ToolRepository toolRepository ) {
143
133
144
134
super ();
145
- this .logger = logger ;
135
+ this .startContext = startContext ;
146
136
this .systemInfo = SystemInfoImpl .INSTANCE ;
147
137
this .commandletManager = new CommandletManagerImpl (this );
148
138
this .fileAccess = new FileAccessImpl (this );
@@ -205,27 +195,25 @@ public AbstractIdeContext(IdeLoggerImpl logger, Path userDir, ToolRepository too
205
195
}
206
196
207
197
private Path findIdeRoot (Path ideHomePath ) {
208
- final Path ideRoot ;
198
+
209
199
Path ideRootPath = null ;
210
200
if (ideHomePath != null ) {
211
201
ideRootPath = ideHomePath .getParent ();
202
+ } else if (!isTest ()) {
203
+ ideRootPath = getIdeRootPathFromEnv ();
212
204
}
205
+ return ideRootPath ;
206
+ }
213
207
214
- if (!isTest ()) {
215
- String root = System .getenv ("IDE_ROOT" );
216
- if (root != null ) {
217
- Path rootPath = Path .of (root );
218
- if ((ideRootPath == null )) {
219
- if (Files .isDirectory (rootPath )) {
220
- ideRootPath = rootPath ;
221
- }
222
- } else if (!ideRootPath .equals (rootPath )) {
223
- warning ("Variable IDE_ROOT is set to '{}' but for your project '{}' the path '{}' would have been expected." , rootPath ,
224
- (ideHomePath == null ) ? "undefined" : ideHomePath .getFileName (), ideRootPath );
225
- }
208
+ private static Path getIdeRootPathFromEnv () {
209
+ String root = System .getenv (IdeVariables .IDE_ROOT .getName ());
210
+ if (root != null ) {
211
+ Path rootPath = Path .of (root );
212
+ if (Files .isDirectory (rootPath )) {
213
+ return rootPath ;
226
214
}
227
215
}
228
- return ideRootPath ;
216
+ return null ;
229
217
}
230
218
231
219
@ Override
@@ -546,57 +534,25 @@ public UrlMetadata getUrls() {
546
534
@ Override
547
535
public boolean isQuietMode () {
548
536
549
- return this .quietMode ;
550
- }
551
-
552
- /**
553
- * @param quietMode new value of {@link #isQuietMode()}.
554
- */
555
- public void setQuietMode (boolean quietMode ) {
556
-
557
- this .quietMode = quietMode ;
537
+ return this .startContext .isQuietMode ();
558
538
}
559
539
560
540
@ Override
561
541
public boolean isBatchMode () {
562
542
563
- return this .batchMode ;
564
- }
565
-
566
- /**
567
- * @param batchMode new value of {@link #isBatchMode()}.
568
- */
569
- public void setBatchMode (boolean batchMode ) {
570
-
571
- this .batchMode = batchMode ;
543
+ return this .startContext .isBatchMode ();
572
544
}
573
545
574
546
@ Override
575
547
public boolean isForceMode () {
576
548
577
- return this .forceMode ;
578
- }
579
-
580
- /**
581
- * @param forceMode new value of {@link #isForceMode()}.
582
- */
583
- public void setForceMode (boolean forceMode ) {
584
-
585
- this .forceMode = forceMode ;
549
+ return this .startContext .isForceMode ();
586
550
}
587
551
588
552
@ Override
589
553
public boolean isOfflineMode () {
590
554
591
- return this .offlineMode ;
592
- }
593
-
594
- /**
595
- * @param offlineMode new value of {@link #isOfflineMode()}.
596
- */
597
- public void setOfflineMode (boolean offlineMode ) {
598
-
599
- this .offlineMode = offlineMode ;
555
+ return this .startContext .isOfflineMode ();
600
556
}
601
557
602
558
@ Override
@@ -621,18 +577,11 @@ public boolean isOnline() {
621
577
@ Override
622
578
public Locale getLocale () {
623
579
624
- if (this .locale == null ) {
625
- return Locale .getDefault ();
580
+ Locale locale = this .startContext .getLocale ();
581
+ if (locale == null ) {
582
+ locale = Locale .getDefault ();
626
583
}
627
- return this .locale ;
628
- }
629
-
630
- /**
631
- * @param locale new value of {@link #getLocale()}.
632
- */
633
- public void setLocale (Locale locale ) {
634
-
635
- this .locale = locale ;
584
+ return locale ;
636
585
}
637
586
638
587
@ Override
@@ -694,7 +643,7 @@ protected ProcessContext createProcessContext() {
694
643
@ Override
695
644
public IdeSubLogger level (IdeLogLevel level ) {
696
645
697
- return this .logger .level (level );
646
+ return this .startContext .level (level );
698
647
}
699
648
700
649
@ Override
@@ -885,12 +834,26 @@ private boolean applyAndRun(CliArguments arguments, Commandlet cmd) {
885
834
throw new CliException (getMessageIdeRootNotFound (), ProcessResult .NO_IDE_ROOT );
886
835
}
887
836
if (cmd .isProcessableOutput ()) {
888
- for (IdeLogLevel level : IdeLogLevel .values ()) {
889
- if (level != IdeLogLevel .INFO ) {
890
- this .logger .setLogLevel (level , false );
837
+ if (!debug ().isEnabled ()) {
838
+ // unless --debug or --trace was supplied, processable output commandlets will disable all log-levels except INFO to prevent other logs interfere
839
+ for (IdeLogLevel level : IdeLogLevel .values ()) {
840
+ if (level != IdeLogLevel .INFO ) {
841
+ this .startContext .setLogLevel (level , false );
842
+ }
891
843
}
892
844
}
893
845
} else {
846
+ if (!isTest ()) {
847
+ if (this .ideRoot == null ) {
848
+ warning ("Variable IDE_ROOT is undefined. Please check your installation or run setup script again." );
849
+ } else if (this .ideHome != null ) {
850
+ Path ideRootPath = getIdeRootPathFromEnv ();
851
+ if (!this .ideRoot .equals (ideRootPath )) {
852
+ warning ("Variable IDE_ROOT is set to '{}' but for your project '{}' the path '{}' would have been expected." , ideRootPath ,
853
+ this .ideHome .getFileName (), this .ideRoot );
854
+ }
855
+ }
856
+ }
894
857
if (cmd .isIdeHomeRequired ()) {
895
858
debug (getMessageIdeHomeFound ());
896
859
}
@@ -1085,4 +1048,12 @@ public void setPathSyntax(WindowsPathSyntax pathSyntax) {
1085
1048
1086
1049
this .pathSyntax = pathSyntax ;
1087
1050
}
1051
+
1052
+ /**
1053
+ * @return the {@link IdeStartContextImpl}.
1054
+ */
1055
+ public IdeStartContextImpl getStartContext () {
1056
+
1057
+ return startContext ;
1058
+ }
1088
1059
}
0 commit comments