88import de .peeeq .wurstio .gui .AboutDialog ;
99import de .peeeq .wurstio .gui .WurstGuiImpl ;
1010import de .peeeq .wurstio .languageserver .LanguageServerStarter ;
11- import de .peeeq .wurstio .languageserver .ProjectConfigBuilder ;
1211import de .peeeq .wurstio .languageserver .WFile ;
12+ import de .peeeq .wurstio .languageserver .requests .CliBuildMap ;
1313import de .peeeq .wurstio .map .importer .ImportFile ;
1414import de .peeeq .wurstio .mpq .MpqEditor ;
1515import de .peeeq .wurstio .mpq .MpqEditorFactory ;
16- import de .peeeq .wurstio .utils .W3InstallationData ;
1716import de .peeeq .wurstscript .CompileTimeInfo ;
1817import de .peeeq .wurstscript .ErrorReporting ;
1918import de .peeeq .wurstscript .RunArgs ;
3130import java .lang .management .RuntimeMXBean ;
3231import java .nio .file .Path ;
3332import java .nio .file .Paths ;
34- import java .nio .file .StandardCopyOption ;
35- import java .util .LinkedList ;
33+ import java .util .ArrayList ;
3634import java .util .List ;
3735import java .util .Optional ;
3836
@@ -110,35 +108,42 @@ public static void main(String[] args) {
110108 }
111109
112110 try {
113- WurstProjectConfigData projectConfig = null ;
114- Path buildDir = null ;
115- Optional <Path > target = Optional .empty ();
116111 String workspaceroot = runArgs .getWorkspaceroot ();
112+ RunArgs compileArgs = runArgs ;
113+ List <String > mergedArgs = new ArrayList <>(asList (args ));
114+ if (workspaceroot != null ) {
115+ WLogger .info ("workspaceroot: " + workspaceroot );
116+ List <String > argsList = getCompileArgs (WFile .create (workspaceroot ));
117+ WLogger .info ("workspaceroot: " + (argsList == null ));
118+ mergedArgs .addAll (argsList );
119+ compileArgs = new RunArgs (mergedArgs );
120+ }
121+
117122 if (runArgs .isBuild () && runArgs .getInputmap () != null && workspaceroot != null ) {
118123 Path root = Paths .get (workspaceroot );
119124 Path inputMap = root .resolve (runArgs .getInputmap ());
120- projectConfig = WurstProjectConfig .INSTANCE .loadProject (root .resolve (FILE_NAME ));
121-
125+ WurstProjectConfigData projectConfig = WurstProjectConfig .INSTANCE .loadProject (root .resolve (FILE_NAME ));
122126 if (java .nio .file .Files .exists (inputMap ) && projectConfig != null ) {
123- buildDir = root .resolve ("_build" );
124- java .nio .file .Files .createDirectories (buildDir );
125- target = Optional .of (buildDir .resolve (projectConfig .getBuildMapData ().getFileName () + ".w3x" ));
126- java .nio .file .Files .copy (inputMap , target .get (), StandardCopyOption .REPLACE_EXISTING );
127- runArgs .setMapFile (target .get ().toAbsolutePath ().toString ());
127+ CliBuildMap cliBuildMap = new CliBuildMap (
128+ WFile .create (root .toFile ()),
129+ Optional .of (inputMap .toFile ()),
130+ mergedArgs ,
131+ Optional .empty (),
132+ gui
133+ );
134+ de .peeeq .wurstio .languageserver .ModelManager modelManager =
135+ new de .peeeq .wurstio .languageserver .ModelManagerImpl (root .toFile (), new de .peeeq .wurstio .languageserver .BufferManager ());
136+ modelManager .buildProject ();
137+ Object result = cliBuildMap .execute (modelManager );
138+ WLogger .info ("map build success" );
139+ System .out .println ("Build succeeded. Output file: <" + result + ">" );
140+ gui .sendProgress ("Finished!" );
141+ return ;
128142 }
129143 }
130144
131145 String mapFilePath = runArgs .getMapFile ();
132146
133- RunArgs compileArgs = runArgs ;
134- if (workspaceroot != null ) {
135- WLogger .info ("workspaceroot: " + workspaceroot );
136- List <String > argList = new LinkedList <>(asList (args ));
137- List <String > argsList = getCompileArgs (WFile .create (workspaceroot ));
138- WLogger .info ("workspaceroot: " + (argsList == null ));
139- argList .addAll (argsList );
140- compileArgs = new RunArgs (argList );
141- }
142147 CompilationProcess compilationProcess = new CompilationProcess (gui , compileArgs );
143148 @ Nullable CharSequence compiledScript ;
144149
@@ -161,14 +166,6 @@ public static void main(String[] args) {
161166 if (compiledScript != null ) {
162167 File scriptFile = new File ("compiled.j.txt" );
163168 Files .write (compiledScript .toString ().getBytes (Charsets .UTF_8 ), scriptFile );
164-
165- if (projectConfig != null && target .isPresent ()) {
166- ProjectConfigBuilder .apply (projectConfig , target .get ().toFile (), scriptFile , buildDir .toFile (),
167- runArgs , new W3InstallationData (null , Paths .get (workspaceroot ).toFile (), false ));
168-
169- WLogger .info ("map build success" );
170- System .out .println ("Build succeeded. Output file: <" + target .get ().toAbsolutePath () + ">" );
171- }
172169 }
173170
174171 gui .sendProgress ("Finished!" );
0 commit comments